forked from Mirrors/privacore-open-source-search-engine
Merge branch 'master' into sqlite
This commit is contained in:
AdultCheck.cppAdultCheck.hConf.cppConf.hFxAdultCheck.cppFxAdultCheck.hFxAdultCheckList.cppFxAdultCheckList.hLICENSELanguageResultOverride.cppLanguageResultOverride.hMakefileMsg20.cppMsg20.hMsg25.cppMsg40.cppPageResults.cppParms.cppRobotsBlockedResultOverride.cppRobotsBlockedResultOverride.hSearchInput.cppSearchInput.hSpeller.cppSummary.cppSummary.hTitle.cppTitle.hTitleRecVersion.hUrl.cppUrlResultOverride.cppUrlResultOverride.hWords.hXmlDoc.cppadultphrases.txt.exampleadultwords.txt.examplemain.cppurlresultoverride.txt.example
825
AdultCheck.cpp
825
AdultCheck.cpp
@ -1,825 +0,0 @@
|
||||
#include "AdultCheck.h"
|
||||
#include "matches2.h"
|
||||
#include "Log.h"
|
||||
#include "Conf.h"
|
||||
#include "Speller.h" //g_speller for word split uses
|
||||
#include "Xml.h"
|
||||
#include <stddef.h>
|
||||
|
||||
// . an "id" of 2 means very indicative of a dirty doc
|
||||
// . an "id" of 1 means it must be joined with another dirty word to indicate
|
||||
// . taken mostly from Url.cpp
|
||||
// . see matches2.h for Needle class definition
|
||||
static const Needle s_dirtyWords [] = {
|
||||
{"upskirt" ,2,0},
|
||||
{"downblouse",2,0},
|
||||
{"shemale" ,1,0},
|
||||
{"spank" ,1,0},
|
||||
{"dildo" ,2,0},
|
||||
{"bdsm" ,2,0},
|
||||
{"voyeur" ,2,0},
|
||||
{"fisting" ,2,0},
|
||||
{"vibrator" ,2,0},
|
||||
{"ejaculat" ,2,0},
|
||||
{"rgasm" ,2,0},
|
||||
{"orgy" ,2,0},
|
||||
{"orgies" ,2,0},
|
||||
{"stripper" ,1,0},
|
||||
{"softcore" ,2,0},
|
||||
{"whore" ,2,0},
|
||||
// gary slutkin on ted.com. make this just 1 point.
|
||||
{"slut" ,1,0},
|
||||
{"smut" ,2,0},
|
||||
{"tits" ,2,0},
|
||||
{"lesbian" ,2,0},
|
||||
{"swinger" ,2,0},
|
||||
{"fetish" ,2,0},
|
||||
{"nude" ,1,0},
|
||||
{"centerfold",2,0},
|
||||
{"incest" ,2,0},
|
||||
{"pedophil" ,2,0},
|
||||
{"pedofil" ,2,0},
|
||||
{"horny" ,2,0}, // horny toad
|
||||
{"pussy" ,2,0}, // pussy willow pussy cat
|
||||
{"pussies" ,2,0},
|
||||
{"penis" ,2,0},
|
||||
{"vagina" ,2,0},
|
||||
{"phuck" ,2,0},
|
||||
{"blowjob" ,2,0},
|
||||
{"blow job" ,2,0},
|
||||
{"gangbang" ,2,0},
|
||||
{"xxx" ,1,0}, // yahoo.com has class="fz-xxxl"
|
||||
{"porn" ,2,0},
|
||||
{"felch" ,2,0},
|
||||
{"cunt" ,2,0},
|
||||
{"bestial" ,2,0},
|
||||
{"beastial" ,2,0},
|
||||
{"kink" ,2,0},
|
||||
// . "sex" is often substring in tagids.
|
||||
// . too many false positives, make "1" not "2"
|
||||
{"sex" ,1,0},
|
||||
{"anal" ,2,0},
|
||||
{"cum" ,2,0}, // often used for cumulative
|
||||
{"clit" ,2,0},
|
||||
{"fuck" ,2,0},
|
||||
{"boob" ,1,0},
|
||||
{"wank" ,2,0},
|
||||
{"fick" ,2,0},
|
||||
{"eroti" ,2,0},
|
||||
{"gay" ,1,0}, // make 1 pt. 'marvin gay'
|
||||
// new stuff not in Url.cpp
|
||||
{"thong" ,1,0},
|
||||
{"masturbat" ,2,0},
|
||||
{"bitch" ,1,0},
|
||||
{"hell" ,1,0},
|
||||
{"damn" ,1,0},
|
||||
{"rimjob" ,2,0},
|
||||
{"cunnilingu",2,0},
|
||||
{"felatio" ,2,0},
|
||||
{"fellatio" ,2,0},
|
||||
{"dick" ,1,0},
|
||||
{"cock" ,1,0},
|
||||
{"rape" ,2,0},
|
||||
{"raping" ,2,0},
|
||||
{"bukake" ,2,0},
|
||||
{"shit" ,2,0},
|
||||
{"naked" ,1,0},
|
||||
{"nympho" ,2,0},
|
||||
{"hardcore" ,1,0}, // hardcore gamer, count as 1
|
||||
{"sodom" ,2,0},
|
||||
{"titties" ,2,0}, // re-do
|
||||
{"twat" ,2,0},
|
||||
{"bastard" ,1,0},
|
||||
{"erotik" ,2,0},
|
||||
|
||||
// EXCEPTIONS
|
||||
|
||||
// smut
|
||||
{"transmut" ,-2,0},
|
||||
{"bismuth" ,-2,0},
|
||||
|
||||
// sex
|
||||
{"middlesex" ,-1,0},
|
||||
{"sussex" ,-1,0},
|
||||
{"essex" ,-1,0},
|
||||
{"deusex" ,-1,0},
|
||||
{"sexchange" ,-1,0},
|
||||
{"sexpress" ,-1,0},
|
||||
{"sexpert" ,-1,0},
|
||||
|
||||
|
||||
// EXCEPTIONS
|
||||
|
||||
// sex
|
||||
{"middlesex" ,-1,0},
|
||||
{"sussex" ,-1,0},
|
||||
{"essex" ,-1,0},
|
||||
{"deusex" ,-1,0},
|
||||
{"sexchange" ,-1,0},
|
||||
{"sexpress" ,-1,0},
|
||||
{"sexpert" ,-1,0},
|
||||
{"sexcel" ,-1,0},
|
||||
{"sexist" ,-1,0},
|
||||
{"sexile" ,-1,0},
|
||||
{"sexperi" ,-1,0},
|
||||
{"sexual" ,-1,0},
|
||||
{"sexpose" ,-1,0},
|
||||
{"sexclu" ,-1,0},
|
||||
{"sexo" ,-1,0},
|
||||
{"sexism" ,-1,0},
|
||||
{"sexpan" ,-1,0}, // buttonsexpanion
|
||||
{"same-sex" ,-1,0},
|
||||
{"opposite sex",-1,0},
|
||||
|
||||
// anal
|
||||
{"analog" ,-2,0},
|
||||
{"analy" ,-2,0},
|
||||
{"canal" ,-2,0},
|
||||
{"kanal" ,-2,0},
|
||||
{"banal" ,-2,0},
|
||||
{"ianalbert" ,-2,0}, // ian albert
|
||||
|
||||
// cum
|
||||
{"circum" ,-2,0},
|
||||
{"cum laude" ,-2,0},
|
||||
{"succum" ,-2,0},
|
||||
{"cumber" ,-2,0},
|
||||
{"docum" ,-2,0},
|
||||
{"cumul" ,-2,0},
|
||||
{"acumen" ,-2,0},
|
||||
{"incum" ,-2,0},
|
||||
{"capsicum" ,-2,0},
|
||||
{"modicum" ,-2,0},
|
||||
{"locum" ,-2,0},
|
||||
{"scum" ,-2,0},
|
||||
{"accum" ,-2,0},
|
||||
{"cumbre" ,-2,0},
|
||||
|
||||
{"swank" ,-2,0},
|
||||
{"fickle" ,-2,0},
|
||||
{"traffick" ,-2,0},
|
||||
{"scleroti" ,-2,0},
|
||||
{"gaylor" ,-2,0},
|
||||
{"gaynor" ,-2,0},
|
||||
{"gayner" ,-2,0},
|
||||
{"gayton" ,-2,0},
|
||||
{"dipthong" ,-1,0},
|
||||
|
||||
// hell
|
||||
{"hellen" ,-1,0},
|
||||
{"hellman" ,-1,0},
|
||||
{"shell" ,-1,0},
|
||||
{"mitchell" ,-1,0},
|
||||
{"chelle" ,-1,0}, // me/michelle
|
||||
{"hello" ,-1,0},
|
||||
{"moschella" ,-1,0},
|
||||
{"othello" ,-1,0},
|
||||
{"schelling" ,-1,0},
|
||||
{"seychelles" ,-1,0},
|
||||
{"wheller" ,-1,0},
|
||||
{"winchell" ,-1,0},
|
||||
|
||||
// dick
|
||||
{"dicker" ,-1,0},
|
||||
{"dickins" ,-1,0},
|
||||
{"dickies" ,-1,0},
|
||||
{"dickran" ,-1,0},
|
||||
|
||||
// cock
|
||||
{"babcock" ,-1,0},
|
||||
{"cocked" ,-1,0},
|
||||
{"cocking" ,-1,0},
|
||||
{"cockpit" ,-1,0},
|
||||
{"cockroach" ,-1,0},
|
||||
{"cocktail" ,-1,0},
|
||||
{"cocky" ,-1,0},
|
||||
{"hancock" ,-1,0},
|
||||
{"hitchcock" ,-1,0},
|
||||
{"peacock" ,-1,0},
|
||||
{"shuttlecock",-1,0},
|
||||
{"stopcock" ,-1,0},
|
||||
{"weathercock",-1,0},
|
||||
{"woodcock" ,-1,0},
|
||||
{"cockburn" ,-1,0},
|
||||
|
||||
// kink
|
||||
{"kinko" ,-2,0},
|
||||
{"ukink" ,-2,0}, // ink shop in uk
|
||||
|
||||
// naked
|
||||
{"snaked" ,-1,0},
|
||||
|
||||
// rape
|
||||
{"drape" ,-2,0},
|
||||
{"grape" ,-2,0},
|
||||
{"scrape" ,-2,0},
|
||||
{"therape" ,-2,0},
|
||||
{"trapez" ,-2,0},
|
||||
{"parapet" ,-2,0},
|
||||
{"scraping" ,-2,0},
|
||||
{"draping" ,-2,0},
|
||||
|
||||
// twat
|
||||
{"twatch" ,-2,0}, // courtwatch -- cspan.org
|
||||
|
||||
// clit
|
||||
{"heraclitus" ,-2,0},
|
||||
|
||||
// boob
|
||||
{"booboo" ,-1,0},
|
||||
|
||||
// shit
|
||||
{"shitak" ,-2,0},
|
||||
|
||||
// scunthorpe (north lincolnshire)
|
||||
{"scunthorpe" ,-2,0}
|
||||
};
|
||||
static const int32_t numDirty = sizeof(s_dirtyWords) / sizeof(s_dirtyWords[0]);
|
||||
|
||||
#if 0
|
||||
////
|
||||
//// New stuff from sex.com adult word list
|
||||
////
|
||||
////
|
||||
//// make it a 2nd part because of performance limits on matches2.cpp algo
|
||||
////
|
||||
static const Needle s_dirtyWordsPart2 [] = {
|
||||
{"amateurfoto" ,2,0},
|
||||
{"amateurhardcore" ,2,0},
|
||||
{"amateurindex",2,0},
|
||||
{"amateurnaked",2,0},
|
||||
{"amatuerhardcore" ,2,0},
|
||||
{"ampland" ,2,0},
|
||||
//{"animehentai" ,2,0}, dup
|
||||
{"anitablonde" ,2,0},
|
||||
{"asiacarrera" ,2,0},
|
||||
{"asshole" ,2,0},
|
||||
{"asslick" ,2,0},
|
||||
{"asspic" ,2,0},
|
||||
{"assworship" ,2,0},
|
||||
//{"badgirl" ,2,0}, not necessarily bad
|
||||
{"bareceleb" ,2,0},
|
||||
{"barenaked" ,2,0},
|
||||
{"beaverboy" ,2,0},
|
||||
{"beavershot" ,2,0}, // was beavershots
|
||||
//{"bigball" ,2,0}, // not necessarily bad
|
||||
{"bigbreast" ,2,0},
|
||||
//{"bigbutt" ,2,0}, // not necessarily bad
|
||||
{"bigcock" ,2,0},
|
||||
{"bigdick" ,2,0},
|
||||
{"biggestdick" ,2,0},
|
||||
{"biggesttit" ,2,0},
|
||||
{"bighairyball",2,0},
|
||||
{"bighooter" ,2,0},
|
||||
{"bignipple" ,2,0},
|
||||
{"bigtit" ,2,0},
|
||||
{"blackbooty" ,2,0},
|
||||
{"blackbutt" ,2,0},
|
||||
{"blackcock" ,2,0},
|
||||
{"blackdick" ,2,0},
|
||||
{"blackhardcore" ,2,0},
|
||||
{"blackonblonde" ,2,0},
|
||||
{"blacksonblonde" ,2,0},
|
||||
{"blacktit" ,2,0},
|
||||
{"blacktwat" ,2,0},
|
||||
{"boner" ,1,0}, // softcore, someone's lastname?
|
||||
{"bordello" ,2,0},
|
||||
{"braless" ,2,0},
|
||||
{"brothel" ,2,0},
|
||||
{"bukake" ,2,0},
|
||||
{"bukkake" ,2,0},
|
||||
{"bustyblonde" ,2,0},
|
||||
{"bustyceleb" ,2,0},
|
||||
{"butthole" ,2,0},
|
||||
{"buttman" ,2,0},
|
||||
{"buttpic" ,2,0},
|
||||
{"buttplug" ,2,0},
|
||||
{"buttthumbnails" ,2,0},
|
||||
{"callgirl" ,2,0},
|
||||
{"celebritiesnaked" ,2,0},
|
||||
{"celebritybush" ,2,0},
|
||||
{"celebritybutt" ,2,0},
|
||||
{"chaseylain" ,2,0},
|
||||
{"chickswithdick" ,2,0},
|
||||
{"christycanyon" ,2,0},
|
||||
{"cicciolina" ,2,0},
|
||||
//{"cunilingus" ,2,0},
|
||||
{"cunniling" ,2,0}, // abbreviate
|
||||
{"cyberlust" ,2,0},
|
||||
{"danniashe" ,2,0},
|
||||
{"dicksuck" ,2,0},
|
||||
{"dirtymind" ,2,0},
|
||||
{"dirtypicture",2,0},
|
||||
{"doggiestyle" ,2,0},
|
||||
{"doggystyle" ,2,0},
|
||||
{"domatrix" ,2,0},
|
||||
{"dominatrix" ,2,0},
|
||||
//{"dyke",2,0}, // dick van dyke!
|
||||
{"ejaculation" ,2,0},
|
||||
{"erosvillage" ,2,0},
|
||||
{"facesit" ,2,0},
|
||||
{"fatass" ,2,0},
|
||||
{"feetfetish" ,2,0},
|
||||
{"felatio" ,2,0},
|
||||
{"fellatio" ,2,0},
|
||||
{"femdom" ,2,0},
|
||||
{"fetishwear" ,2,0},
|
||||
{"fettegirl" ,2,0},
|
||||
{"fingerbang" ,2,0},
|
||||
{"fingering" ,1,0}, // fingering the keyboard? use 1
|
||||
{"flesh4free" ,2,0},
|
||||
{"footfetish" ,2,0},
|
||||
{"footjob" ,2,0},
|
||||
{"footlicking" ,2,0},
|
||||
{"footworship" ,2,0},
|
||||
{"fornication" ,2,0},
|
||||
{"freeass" ,2,0},
|
||||
{"freebigtit" ,2,0},
|
||||
{"freedick" ,2,0},
|
||||
{"freehardcore",2,0},
|
||||
//{"freehentai" ,2,0}, dup
|
||||
{"freehooter" ,2,0},
|
||||
{"freelargehooter" ,2,0},
|
||||
{"freenakedpic",2,0},
|
||||
{"freenakedwomen" ,2,0},
|
||||
{"freetit" ,2,0},
|
||||
{"freevoyeur" ,2,0},
|
||||
{"gratishardcoregalerie" ,2,0},
|
||||
{"hardcorecelebs" ,2,0},
|
||||
{"hardcorefree",2,0},
|
||||
{"hardcorehooter" ,2,0},
|
||||
{"hardcorejunkie" ,2,0},
|
||||
{"hardcorejunky" ,2,0},
|
||||
{"hardcoremovie" ,2,0},
|
||||
{"hardcorepic" ,2,0},
|
||||
{"hardcorepix" ,2,0},
|
||||
{"hardcoresample" ,2,0},
|
||||
{"hardcorestories" ,2,0},
|
||||
{"hardcorethumb" ,2,0},
|
||||
{"hardcorevideo" ,2,0},
|
||||
{"harddick" ,2,0},
|
||||
{"hardnipple" ,2,0},
|
||||
{"hardon" ,2,0},
|
||||
{"hentai" ,2,0},
|
||||
{"interacialhardcore" ,2,0},
|
||||
{"intercourseposition" ,2,0},
|
||||
{"interracialhardcore" ,2,0},
|
||||
{"ittybittytitty" ,2,0},
|
||||
{"jackoff" ,2,0},
|
||||
{"jennajameson",2,0},
|
||||
{"jennicam" ,2,0},
|
||||
{"jerkoff" ,2,0},
|
||||
{"jism",2,0},
|
||||
{"jiz" ,2,0},
|
||||
{"justhardcore",2,0},
|
||||
{"karasamateurs" ,2,0},
|
||||
{"kascha" ,2,0},
|
||||
{"kaylakleevage" ,2,0},
|
||||
{"kobetai" ,2,0},
|
||||
{"lapdance" ,2,0},
|
||||
{"largedick" ,2,0},
|
||||
{"largehooter" ,2,0},
|
||||
{"largestbreast" ,2,0},
|
||||
{"largetit" ,2,0},
|
||||
{"lesben" ,2,0},
|
||||
{"lesbo" ,2,0},
|
||||
{"lickadick" ,2,0},
|
||||
{"lindalovelace" ,2,0},
|
||||
{"longdick" ,2,0},
|
||||
{"lovedoll" ,2,0},
|
||||
{"makinglove" ,2,0},
|
||||
{"mangax" ,2,0},
|
||||
{"manpic" ,2,0},
|
||||
{"marilynchambers" ,2,0},
|
||||
{"massivecock" ,2,0},
|
||||
{"masterbating",2,0},
|
||||
{"mensdick" ,2,0},
|
||||
{"milf",2,0},
|
||||
{"minka" ,2,0},
|
||||
{"monstercock" ,2,0},
|
||||
{"monsterdick" ,2,0},
|
||||
{"muffdiving" ,2,0},
|
||||
{"nacktfoto" ,2,0},
|
||||
{"nakedblackwomen" ,2,0},
|
||||
{"nakedceleb" ,2,0},
|
||||
{"nakedcelebrity" ,2,0},
|
||||
{"nakedcheerleader" ,2,0},
|
||||
{"nakedchick" ,2,0},
|
||||
{"nakedgirl" ,2,0},
|
||||
{"nakedguy" ,2,0},
|
||||
{"nakedladies" ,2,0},
|
||||
{"nakedlady" ,2,0},
|
||||
{"nakedman" ,2,0},
|
||||
{"nakedmen" ,2,0},
|
||||
{"nakedness" ,2,0},
|
||||
{"nakedphoto" ,2,0},
|
||||
{"nakedpic" ,2,0},
|
||||
{"nakedstar" ,2,0},
|
||||
{"nakedwife" ,2,0},
|
||||
{"nakedwoman" ,2,0},
|
||||
{"nakedwomen" ,2,0},
|
||||
{"nastychat" ,2,0},
|
||||
{"nastythumb" ,2,0},
|
||||
{"naughtylink" ,2,0},
|
||||
{"naughtylinx" ,2,0},
|
||||
{"naughtylynx" ,2,0},
|
||||
{"naughtynurse",2,0},
|
||||
{"niceass" ,2,0},
|
||||
{"nikkinova" ,2,0},
|
||||
{"nikkityler" ,2,0},
|
||||
{"nylonfetish" ,2,0},
|
||||
{"nympho" ,2,0},
|
||||
{"openleg" ,2,0},
|
||||
{"oral4free" ,2,0},
|
||||
{"pantyhosefetish" ,2,0},
|
||||
{"peepcam" ,2,0},
|
||||
{"persiankitty",2,0},
|
||||
{"perverted" ,2,0},
|
||||
{"pimpserver" ,2,0},
|
||||
{"pissing" ,2,0},
|
||||
{"poontang" ,2,0},
|
||||
{"privatex" ,2,0},
|
||||
{"prono" ,2,0},
|
||||
{"publicnudity",2,0},
|
||||
{"puffynipple" ,2,0},
|
||||
{"racqueldarrian" ,2,0},
|
||||
//{"rape",2,0}, // dup!
|
||||
{"rawlink" ,2,0},
|
||||
{"realhardcore",2,0},
|
||||
{"rubberfetish",2,0},
|
||||
{"seka",2,0},
|
||||
{"sheboy" ,2,0},
|
||||
{"showcam" ,2,0},
|
||||
{"showercam" ,2,0},
|
||||
{"smallbreast" ,2,0},
|
||||
{"smalldick" ,2,0},
|
||||
{"spycamadult" ,2,0},
|
||||
{"strapon" ,2,0},
|
||||
{"stripclub" ,2,0},
|
||||
{"stripshow" ,2,0},
|
||||
{"striptease" ,2,0},
|
||||
{"strokeit" ,2,0},
|
||||
{"strokeme" ,2,0},
|
||||
{"suckdick" ,2,0},
|
||||
{"sylviasaint" ,2,0},
|
||||
{"teenhardcore",2,0},
|
||||
{"teenie" ,2,0},
|
||||
{"teenpic" ,2,0},
|
||||
{"teensuck" ,2,0},
|
||||
{"tgp" ,2,0},
|
||||
{"threesome" ,2,0},
|
||||
{"thumblord" ,2,0},
|
||||
{"thumbzilla" ,2,0},
|
||||
{"tiffanytowers" ,2,0},
|
||||
{"tinytitties" ,2,0},
|
||||
//{"tities" ,2,0}, // entities
|
||||
{"titman" ,2,0},
|
||||
{"titsandass" ,2,0},
|
||||
{"titties" ,2,0},
|
||||
{"titts" ,2,0},
|
||||
{"titty" ,2,0},
|
||||
{"tokyotopless",2,0},
|
||||
{"tommysbookmark" ,2,0},
|
||||
{"toplesswomen",2,0},
|
||||
{"trannies" ,2,0},
|
||||
{"twinks" ,2,0},
|
||||
{"ultradonkey" ,2,0},
|
||||
{"ultrahardcore" ,2,0},
|
||||
{"uncutcock" ,2,0},
|
||||
{"vividtv" ,2,0},
|
||||
{"wendywhoppers" ,2,0},
|
||||
{"wetdick" ,2,0},
|
||||
{"wetpanties" ,2,0},
|
||||
{"wifesharing" ,2,0},
|
||||
{"wifeswapping",2,0},
|
||||
{"xrated" ,2,0}
|
||||
};
|
||||
static const int32_t numDirty2 = sizeof(s_dirtyWordsPart2) / sizeof(s_dirtyWordsPart2[0]);
|
||||
static bool initDirtyWordsPart2 = initializeNeedle(s_dirtyWordsPart2, numDirty2);
|
||||
#endif
|
||||
|
||||
int32_t getAdultPoints ( char *s, int32_t slen, const char *url ) {
|
||||
NeedleMatch dirtyWordsMatches[numDirty];
|
||||
|
||||
// . use the matches function to get all the matches
|
||||
// . then check each match to see if it is actually a legit word
|
||||
// . actually match the dirty words, then match the clean words
|
||||
// then we can subtract counts.
|
||||
getMatches2(s_dirtyWords, dirtyWordsMatches, numDirty, s, slen, NULL, NULL);
|
||||
|
||||
int32_t points = 0;
|
||||
// each needle has an associated score
|
||||
for ( int32_t i = 0 ; i < numDirty ; i++ ) {
|
||||
// skip if no match
|
||||
if ( dirtyWordsMatches[i].m_count <= 0 ) continue;
|
||||
// . the "id", is positive for dirty words, - for clean
|
||||
// . uses +2/-2 for really dirty words
|
||||
// . uses +1/-1 for borderline dirty words
|
||||
points += s_dirtyWords[i].m_id;
|
||||
logDebug(g_conf.m_logDebugDirty, "dirty: %s %" PRId32" %s", s_dirtyWords[i].m_string, (int32_t) s_dirtyWords[i].m_id, url);
|
||||
}
|
||||
|
||||
////
|
||||
//
|
||||
// repeat for part2
|
||||
//
|
||||
// we have to do two separate parts otherwise the algo in
|
||||
// matches2.cpp gets really slow. it was not meant to match
|
||||
// so many needles in one haystack.
|
||||
//
|
||||
///
|
||||
|
||||
#if 0
|
||||
// . disable this for now. most of these are phrases and they
|
||||
// will not be detected.
|
||||
// . TODO: hash the dirty words and phrases and just lookup
|
||||
// words in that table like we do for isStopWord(), but use
|
||||
// isDirtyWord(). Then replace the code is Speller.cpp
|
||||
// with isDirtyUrl() which will split the string into words
|
||||
// and call isDirtyWord() on each one. also use bi and tri grams
|
||||
// in the hash table.
|
||||
|
||||
getMatches2 ( s_dirtyWordsPart2 ,
|
||||
numDirty2 ,
|
||||
s ,
|
||||
slen ,
|
||||
NULL , // linkPos
|
||||
NULL , // needleNum
|
||||
false , // stopAtFirstMatch?
|
||||
NULL , // hadPreMatch ptr
|
||||
true ); // saveQuickTables?
|
||||
|
||||
|
||||
// each needle has an associated score
|
||||
for ( int32_t i = 0 ; i < numDirty2 ; i++ ) {
|
||||
// skip if no match
|
||||
if ( s_dirtyWordsPart2[i].m_count <= 0 ) continue;
|
||||
// . the "id", is positive for dirty words, - for clean
|
||||
// . uses +2/-2 for really dirty words
|
||||
// . uses +1/-1 for borderline dirty words
|
||||
points += s_dirtyWordsPart2[i].m_id;
|
||||
// log debug
|
||||
if ( ! g_conf.m_logDebugDirty ) continue;
|
||||
// show it in the log
|
||||
log("dirty: %s %" PRId32" %s"
|
||||
,s_dirtyWordsPart2[i].m_string
|
||||
,(int32_t)s_dirtyWordsPart2[i].m_id
|
||||
,url
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// @todo ALC this is not a good way to check if it's adult or not
|
||||
// . these are going to be adult, in any language
|
||||
// . this seems only to be used by Speller.cpp when splitting up words
|
||||
// in the url domain.
|
||||
// . s/slen is a full word that is found in our "dictionary" so using
|
||||
// phrases like biglittlestuff probably should not go here.
|
||||
bool isAdult(const char *s, int32_t slen, const char **loc) {
|
||||
const char *a = NULL;
|
||||
const char **p = loc ? loc : &a;
|
||||
|
||||
// check for naughty words
|
||||
if ( ( *p = strnstr ( s, "upskirt", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "downblouse", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "adult", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "shemale", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "spank", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "dildo", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "shaved", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "bdsm", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "voyeur", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "shemale", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "fisting", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "escorts", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "vibrator", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "rgasm", slen ) ) ) return true; // 0rgasm
|
||||
if ( ( *p = strnstr ( s, "orgy", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "orgies", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "orgasm", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "masturbat", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "stripper", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "lolita", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "softcore", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "whore", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "slut", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "smut", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "tits", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "lesbian", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "swinger", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "housewife", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "housewive", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "nude", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "bondage", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "centerfold", slen) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "incest", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "pedophil", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "pedofil", slen ) ) ) return true;
|
||||
// hornyear.com
|
||||
if ( ( *p = strnstr ( s, "horny", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "pussy", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "pussies", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "penis", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "vagina", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "phuck", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "blowjob", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "gangbang", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "xxx", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "porn", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "felch", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "cunt", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "bestial", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "tranny", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "beastial", slen ) ) ) return true;
|
||||
if ( ( *p = strnstr ( s, "crotch", slen ) ) ) return true;
|
||||
|
||||
// these below may have legit meanings
|
||||
if ( ( *p = strnstr ( s, "kink", slen ) ) ) {
|
||||
if ( strnstr ( s, "kinko", slen ) ) return false;// the store
|
||||
return true;
|
||||
}
|
||||
if ( ( *p = strnstr ( s, "sex", slen ) ) ) {
|
||||
// sexton, sextant, sextuplet, sextet
|
||||
if ( strnstr ( s, "sext", slen ) ) return false;
|
||||
if ( strnstr ( s, "middlesex", slen ) ) return false;
|
||||
if ( strnstr ( s, "sussex", slen ) ) return false;
|
||||
if ( strnstr ( s, "essex", slen ) ) return false;
|
||||
if ( strnstr ( s, "deusex", slen ) )
|
||||
return false; // video game
|
||||
if ( strnstr ( s, "sexchange", slen ) )
|
||||
return false; // businessexh
|
||||
if ( strnstr ( s, "sexpress", slen ) )
|
||||
return false; // *express
|
||||
if ( strnstr ( s, "sexpert", slen ) )
|
||||
return false; // *expert
|
||||
if ( strnstr ( s, "sexcel", slen ) )
|
||||
return false; // *excellence
|
||||
if ( strnstr ( s, "sexist", slen ) )
|
||||
return false; // existence
|
||||
if ( strnstr ( s, "sexile", slen ) )
|
||||
return false; // existence
|
||||
if ( strnstr ( s, "harassm", slen ) )
|
||||
return false; // harassment
|
||||
if ( strnstr ( s, "sexperi", slen ) )
|
||||
return false; // experience
|
||||
if ( strnstr ( s, "transex", slen ) )
|
||||
return false; // transexual
|
||||
if ( strnstr ( s, "sexual", slen ) )
|
||||
return false; // abuse,health
|
||||
if ( strnstr ( s, "sexpo", slen ) )
|
||||
return false; // expo,expose
|
||||
if ( strnstr ( s, "exoti", slen ) )
|
||||
return false; // exotic(que)
|
||||
if ( strnstr ( s, "sexclu", slen ) )
|
||||
return false; // exclusive/de
|
||||
return true;
|
||||
}
|
||||
// www.losAnaLos.de
|
||||
// sanalcafe.net
|
||||
if ( ( *p = strnstr ( s, "anal", slen ) ) ) {
|
||||
if ( strnstr ( s, "analog", slen ) )
|
||||
return false; // analogy
|
||||
if ( strnstr ( s, "analy", slen ) )
|
||||
return false; // analysis
|
||||
if ( strnstr ( s, "canal", slen ) )
|
||||
return false;
|
||||
if ( strnstr ( s, "kanal", slen ) )
|
||||
return false; // german
|
||||
if ( strnstr ( s, "banal", slen ) )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if ( ( *p = strnstr ( s, "cum", slen ) ) ) {
|
||||
if ( strnstr ( s, "circum", slen ) )
|
||||
return false; // circumvent
|
||||
if ( strnstr ( s, "magn", slen ) )
|
||||
return false; // magna cum
|
||||
if ( strnstr ( s, "succu", slen ) )
|
||||
return false; // succumb
|
||||
if ( strnstr ( s, "cumber", slen ) )
|
||||
return false; // encumber
|
||||
if ( strnstr ( s, "docum", slen ) )
|
||||
return false; // document
|
||||
if ( strnstr ( s, "cumul", slen ) )
|
||||
return false; // accumulate
|
||||
if ( strnstr ( s, "acumen", slen ) )
|
||||
return false; // acumen
|
||||
if ( strnstr ( s, "cucum", slen ) )
|
||||
return false; // cucumber
|
||||
if ( strnstr ( s, "incum", slen ) )
|
||||
return false; // incumbent
|
||||
if ( strnstr ( s, "capsicum", slen ) ) return false;
|
||||
if ( strnstr ( s, "modicum", slen ) ) return false;
|
||||
if ( strnstr ( s, "locum", slen ) )
|
||||
return false; // slocum
|
||||
if ( strnstr ( s, "scum", slen ) ) return false;
|
||||
if ( strnstr ( s, "accu", slen ) )
|
||||
return false; // compounds!
|
||||
// arcum.de
|
||||
// cummingscove.com
|
||||
// cumchristo.org
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ( *p = strnstr ( s, "clit", slen ) ) &&
|
||||
! strnstr ( s, "heraclitus", slen ) )
|
||||
return true;
|
||||
// fuckedcompany.com is ok
|
||||
if ( ( *p = strnstr ( s, "fuck", slen ) ) &&
|
||||
! strnstr ( s, "fuckedcomp", slen ) )
|
||||
return true;
|
||||
if ( ( *p = strnstr ( s, "boob", slen ) ) &&
|
||||
! strnstr ( s, "booboo", slen ) )
|
||||
return true;
|
||||
if ( ( *p = strnstr ( s, "wank", slen ) )&&
|
||||
! strnstr ( s, "swank", slen ) )
|
||||
return true;
|
||||
// fick is german for fuck (fornication under consent of the king)
|
||||
if ( ( *p = strnstr ( s, "fick", slen ) )&&
|
||||
! strnstr ( s, "fickle", slen ) &&
|
||||
! strnstr ( s, "traffick", slen ) )return true;
|
||||
// sclerotic
|
||||
// buerotipp.de
|
||||
if ( ( *p = strnstr ( s, "eroti", slen ) ) &&
|
||||
! strnstr ( s, "sclero", slen ) )
|
||||
return true;
|
||||
// albaberlin.com
|
||||
// babelfish.altavista.com
|
||||
if ( ( *p = strnstr ( s, "babe", slen ) ) &&
|
||||
! strnstr ( s, "toyland", slen ) &&
|
||||
! strnstr ( s, "babel", slen ) )
|
||||
return true;
|
||||
// what is gaya.dk?
|
||||
if ( ( *p = strnstr ( s, "gay", slen ) ) &&
|
||||
! strnstr ( s, "gaylord", slen ) )
|
||||
return true;
|
||||
// url appears to be ok
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool isAdultUrl(const char *s, int32_t slen) {
|
||||
if(!isAdult(s,slen))
|
||||
return false;
|
||||
|
||||
// check for naughty words. Split words to deep check if we're surely
|
||||
// adult. Required because montanalinux.org is showing up as porn
|
||||
// because it has 'anal' in the hostname.
|
||||
// send each phrase seperately to be tested.
|
||||
// hotjobs.yahoo.com
|
||||
const char *a = s;
|
||||
const char *p = s;
|
||||
bool foundCleanSequence = false;
|
||||
char splitWords[1024];
|
||||
char *splitp = splitWords;
|
||||
while(p < s + slen) {
|
||||
while(p < s + slen && *p != '.' && *p != '-')
|
||||
p++;
|
||||
bool isPorn = false;
|
||||
// TODO: do not include "ult" in the dictionary, it is
|
||||
// always splitting "adult" as "ad ult". i'd say do not
|
||||
// allow it to split a dirty word into two words like that.
|
||||
if(g_speller.canSplitWords(a, p - a, &isPorn, splitp, langEnglish)) {
|
||||
if(isPorn) {
|
||||
log(LOG_DEBUG,"build: identified %s as porn after splitting words as %s",
|
||||
s, splitp);
|
||||
return true;
|
||||
}
|
||||
foundCleanSequence = true;
|
||||
// keep searching for some porn sequence
|
||||
}
|
||||
p++;
|
||||
a = p;
|
||||
splitp += strlen(splitp);
|
||||
}
|
||||
// if we found a clean sequence, its not porn
|
||||
if(foundCleanSequence) {
|
||||
log(LOG_INFO,"build: did not identify url %s as porn after splitting words as %s",
|
||||
s, splitWords);
|
||||
return false;
|
||||
}
|
||||
// we tried to get some seq of words but failed. Still report
|
||||
// this as porn, since isAdult() was true
|
||||
logf(LOG_DEBUG,"build: failed to find sequence of words to prove %s was not porn.", s );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool isAdultTLD(const char *tld, size_t tld_len) {
|
||||
if(tld) {
|
||||
if((tld_len==5 && memcmp(tld,"adult",5)==0) ||
|
||||
(tld_len==4 && memcmp(tld,"porn",4)==0) ||
|
||||
(tld_len==3 && memcmp(tld,"sex",3)==0) ||
|
||||
(tld_len==4 && memcmp(tld,"sexy",4)==0) ||
|
||||
(tld_len==3 && memcmp(tld,"xxx",3)==0))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
15
AdultCheck.h
15
AdultCheck.h
@ -1,15 +0,0 @@
|
||||
#ifndef ADULT_CHECK_H_
|
||||
#define ADULT_CHECK_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
|
||||
int32_t getAdultPoints ( char *s, int32_t slen, const char *url );
|
||||
|
||||
bool isAdult(const char *s, int32_t slen, const char **loc = nullptr);
|
||||
|
||||
bool isAdultUrl(const char *s, int32_t slen);
|
||||
|
||||
bool isAdultTLD(const char *tld, size_t tld_len);
|
||||
|
||||
#endif
|
3
Conf.cpp
3
Conf.cpp
@ -236,6 +236,7 @@ Conf::Conf ( ) {
|
||||
m_logTraceDnsCache = false;
|
||||
m_logTraceFile = false;
|
||||
m_logTraceHttpMime = false;
|
||||
m_logTraceLanguageResultOverride = false;
|
||||
m_logTraceMem = false;
|
||||
m_logTraceMsg0 = false;
|
||||
m_logTraceMsg4 = false;
|
||||
@ -254,7 +255,6 @@ Conf::Conf ( ) {
|
||||
m_logTraceRdbTree = false;
|
||||
m_logTraceRepairs = false;
|
||||
m_logTraceRobots = false;
|
||||
m_logTraceRobotsBlocked = false;
|
||||
m_logTraceRobotsCheckList = false;
|
||||
m_logTraceSpider = false;
|
||||
m_logTraceSpiderUrlCache = false;
|
||||
@ -266,6 +266,7 @@ Conf::Conf ( ) {
|
||||
m_logTracePhrases= false;
|
||||
m_logTraceUrlMatchList = false;
|
||||
m_logTraceUrlMatchHostList = false;
|
||||
m_logTraceUrlResultOverride = false;
|
||||
m_logTraceWordSpam=false;
|
||||
m_logTraceUrlClassification = false;
|
||||
m_logTimingAddurl = false;
|
||||
|
3
Conf.h
3
Conf.h
@ -386,6 +386,7 @@ class Conf {
|
||||
bool m_logTraceDnsCache;
|
||||
bool m_logTraceFile;
|
||||
bool m_logTraceHttpMime;
|
||||
bool m_logTraceLanguageResultOverride;
|
||||
bool m_logTraceMem;
|
||||
bool m_logTraceMsg0;
|
||||
bool m_logTraceMsg4;
|
||||
@ -405,7 +406,6 @@ class Conf {
|
||||
|
||||
bool m_logTraceRepairs;
|
||||
bool m_logTraceRobots;
|
||||
bool m_logTraceRobotsBlocked;
|
||||
bool m_logTraceRobotsCheckList;
|
||||
bool m_logTraceSpider;
|
||||
bool m_logTraceSpiderUrlCache;
|
||||
@ -417,6 +417,7 @@ class Conf {
|
||||
bool m_logTracePhrases;
|
||||
bool m_logTraceUrlMatchList;
|
||||
bool m_logTraceUrlMatchHostList;
|
||||
bool m_logTraceUrlResultOverride;
|
||||
bool m_logTraceWordSpam;
|
||||
bool m_logTraceUrlClassification;
|
||||
bool m_logTraceTopTree;
|
||||
|
467
FxAdultCheck.cpp
Normal file
467
FxAdultCheck.cpp
Normal file
@ -0,0 +1,467 @@
|
||||
//
|
||||
// Copyright (C) 2017 Privacore ApS - https://www.privacore.com
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// License TL;DR: If you change this file, you must publish your changes.
|
||||
//
|
||||
#include "FxAdultCheck.h"
|
||||
#include "Log.h"
|
||||
#include "Conf.h"
|
||||
#include "Mem.h"
|
||||
#include "termid_mask.h"
|
||||
#include "Phrases.h"
|
||||
#include "Words.h"
|
||||
#include "XmlDoc.h"
|
||||
#include <stddef.h>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
AdultCheck::AdultCheck(XmlDoc *xd, bool debug) {
|
||||
m_docAdultScore = 0;
|
||||
m_numUniqueDirtyWords = 0;
|
||||
m_numUniqueDirtyPhrases = 0;
|
||||
m_numWordsChecked = 0;
|
||||
m_emptyDocumentBody = false;
|
||||
m_result = false;
|
||||
m_resultValid = false;
|
||||
|
||||
if( xd ) {
|
||||
m_url = xd->getFirstUrl();
|
||||
if( m_url == (Url *)-1 ) {
|
||||
log(LOG_WARN, "XmlDoc::getFirstUrl() failed in AdultCheck::AdultCheck");
|
||||
m_url = NULL;
|
||||
}
|
||||
|
||||
m_xml = xd->getXml();
|
||||
if( m_xml == (Xml *)-1 ) {
|
||||
log(LOG_WARN, "XmlDoc::getXml() failed in AdultCheck::AdultCheck");
|
||||
m_xml = NULL;
|
||||
}
|
||||
|
||||
m_words = xd->getWords();
|
||||
if( m_words == (Words *)-1 ) {
|
||||
log(LOG_WARN, "XmlDoc::getWords() failed in AdultCheck::AdultCheck");
|
||||
m_words = NULL;
|
||||
}
|
||||
|
||||
m_phrases = xd->getPhrases();
|
||||
if( m_phrases == (Phrases *)-1 ) {
|
||||
log(LOG_WARN, "XmlDoc::getPhrases() failed in AdultCheck::AdultCheck");
|
||||
m_phrases = NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_url = NULL;
|
||||
m_xml = NULL;
|
||||
m_words = NULL;
|
||||
m_phrases = NULL;
|
||||
}
|
||||
|
||||
m_debbufSize = 0;
|
||||
m_debbufUsed = 0;
|
||||
m_debbuf = NULL;
|
||||
|
||||
if( debug ) {
|
||||
m_debbufSize = 2000;
|
||||
m_debbuf = (char *)mmalloc(m_debbufSize, "adultcheck");
|
||||
if( !m_debbuf ) {
|
||||
m_debbufSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
AdultCheck::~AdultCheck() {
|
||||
if( m_debbuf ) {
|
||||
mfree(m_debbuf, m_debbufSize, "adultcheck");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int32_t AdultCheck::getScore() {
|
||||
if( m_resultValid ) {
|
||||
return m_docAdultScore;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t AdultCheck::getNumUniqueDirtyWords() {
|
||||
if( m_resultValid ) {
|
||||
return m_numUniqueDirtyWords;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t AdultCheck::getNumUniqueDirtyPhrases() {
|
||||
if( m_resultValid ) {
|
||||
return m_numUniqueDirtyPhrases;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t AdultCheck::getNumWordsChecked() {
|
||||
if( m_resultValid ) {
|
||||
return m_numWordsChecked;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool AdultCheck::hasEmptyDocumentBody() {
|
||||
if( m_resultValid ) {
|
||||
return m_emptyDocumentBody;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *AdultCheck::getReason() {
|
||||
return m_reason.c_str();
|
||||
}
|
||||
|
||||
const char *AdultCheck::getDebugInfo() {
|
||||
if( m_debbuf ) {
|
||||
return m_debbuf;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
bool AdultCheck::hasAdultRatingTag() {
|
||||
if( !m_xml ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t mtlen;
|
||||
|
||||
// https://webmasters.googleblog.com/2012/04/1000-words-about-images.html
|
||||
// http://www.safelabeling.org/how.htm
|
||||
// http://www.rtalabel.org/index.php?content=howto
|
||||
char *mtag = m_xml->getMetaContentPointer( "rating", 6, "name", &mtlen );
|
||||
|
||||
if( !mtag || mtlen <= 0 ) {
|
||||
// http://www.billdietrich.me/Computers.html#ContentRating
|
||||
// https://en.wikipedia.org/wiki/User:ArneBab/Voluntary_Content_Rating
|
||||
mtag = m_xml->getMetaContentPointer( "voluntary content rating", 24, "name", &mtlen );
|
||||
}
|
||||
|
||||
switch( mtlen ) {
|
||||
case 5:
|
||||
if( strncasecmp(mtag, "adult", mtlen) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if( strncasecmp(mtag, "mature", mtlen) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
// non-standard, seen in the wild
|
||||
if( strncasecmp(mtag, "adulto", mtlen) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
// non-standard, seen in the wild
|
||||
if( strncasecmp(mtag, "restricted", mtlen) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 27:
|
||||
if( strncasecmp(mtag, "RTA-5042-1996-1400-1577-RTA", mtlen) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if( mtlen > 0 ) {
|
||||
// non-standard, seen in the wild
|
||||
if( strncasestr(mtag, "porn", mtlen) ||
|
||||
strncasestr(mtag, "porno", mtlen) ||
|
||||
strncasestr(mtag, "adult", mtlen) ||
|
||||
strncasestr(mtag, "fuck", mtlen) ||
|
||||
strncasestr(mtag, "sex", mtlen) ||
|
||||
strncasestr(mtag, "xxx", mtlen) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// YouTube
|
||||
mtag = m_xml->getMetaContentPointer( "isFamilyFriendly", 16, "itemprop", &mtlen );
|
||||
switch( mtlen ) {
|
||||
case 5:
|
||||
if( strncasecmp(mtag, "false", mtlen) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AdultCheck::hasAdultAds() {
|
||||
if( !m_xml ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t mtlen;
|
||||
|
||||
//
|
||||
// Adult ad networks verification tags
|
||||
//
|
||||
char *mtag = m_xml->getMetaContentPointer( "ero_verify", 10, "name", &mtlen );
|
||||
if( mtag && mtlen > 0 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
mtag = m_xml->getMetaContentPointer( "juicyads-site-verification", 26, "name", &mtlen );
|
||||
if( mtag && mtlen > 0 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
mtag = m_xml->getMetaContentPointer( "trafficjunky-site-verification", 30, "name", &mtlen );
|
||||
if( mtag && mtlen > 0 ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
mtag = m_xml->getMetaContentPointer( "adamo-site-verification", 23, "name", &mtlen );
|
||||
if( mtag && mtlen > 0 ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AdultCheck::isDocAdult() {
|
||||
// Hash table used to hold unique termIds to make sure we only count each unique word once
|
||||
HashTableX uniqueTermIds;
|
||||
|
||||
if( m_resultValid ) {
|
||||
return m_result;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for adult TLDs
|
||||
//
|
||||
if( m_url && m_url->isAdult() ) {
|
||||
m_reason = "adultTLD";
|
||||
m_docAdultScore += 1000;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for adult content meta tags
|
||||
//
|
||||
if( !m_docAdultScore ) {
|
||||
if( hasAdultRatingTag() ) {
|
||||
m_reason = "adultRatingTag";
|
||||
m_docAdultScore += 1000;
|
||||
}
|
||||
|
||||
if( !m_docAdultScore &&
|
||||
hasAdultAds() ) {
|
||||
m_reason = "adultAds";
|
||||
m_docAdultScore += 1000;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// If not blocked by the cheaper checks, do the hard work and check document content
|
||||
//
|
||||
if( !m_docAdultScore ) {
|
||||
//
|
||||
// Score words and phrases from the document body text
|
||||
//
|
||||
|
||||
if( m_words ) {
|
||||
if (!uniqueTermIds.set(sizeof(int64_t), 0, m_words->getNumWords()+5000, NULL, 0, false, "uniquetermids", false, 0)) {
|
||||
log(LOG_ERROR,"Could not initialize uniqueTermIds hash table");
|
||||
}
|
||||
|
||||
if( !m_words->getNumWords() ) {
|
||||
// No words in document body
|
||||
m_emptyDocumentBody = true;
|
||||
}
|
||||
else {
|
||||
g_adultCheckList.getDirtyScore(m_words, m_phrases, &uniqueTermIds, &m_docAdultScore, &m_numUniqueDirtyWords, &m_numUniqueDirtyPhrases, m_debbuf, m_debbufUsed, m_debbufSize);
|
||||
m_numWordsChecked += m_words->getNumWords();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// No words in document body
|
||||
m_emptyDocumentBody = true;
|
||||
}
|
||||
|
||||
//
|
||||
// Score words and phrases from the document meta tags
|
||||
//
|
||||
if( m_xml ) {
|
||||
Words metaw;
|
||||
Bits metab;
|
||||
Phrases metap;
|
||||
int32_t mtlen;
|
||||
|
||||
char *mtag = m_xml->getMetaContentPointer( "keywords", 8, "name", &mtlen );
|
||||
if( mtlen > 0 ) {
|
||||
metaw.set(mtag, mtlen, true);
|
||||
}
|
||||
mtag = m_xml->getMetaContentPointer( "description", 11, "name", &mtlen );
|
||||
if( mtlen > 0 ) {
|
||||
//log(LOG_ERROR, "SETTING DESCRIPTION WORDS");
|
||||
metaw.addWords(mtag, mtlen, true);
|
||||
}
|
||||
if( metaw.getNumWords() ) {
|
||||
if( !metab.set(&metaw) ) {
|
||||
log(LOG_ERROR,"COULD NOT SET BITS FOR META WORDS");
|
||||
}
|
||||
if( !metap.set(&metaw, &metab) ) {
|
||||
log(LOG_ERROR,"COULD NOT SET PHRASES FOR META WORDS");
|
||||
}
|
||||
g_adultCheckList.getDirtyScore(&metaw, &metap, &uniqueTermIds, &m_docAdultScore, &m_numUniqueDirtyWords, &m_numUniqueDirtyPhrases, m_debbuf, m_debbufUsed, m_debbufSize);
|
||||
m_numWordsChecked += metaw.getNumWords();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Score words and phrases from URL
|
||||
//
|
||||
if( m_url ) {
|
||||
Words urlw;
|
||||
Bits urlb;
|
||||
Phrases urlp;
|
||||
|
||||
urlw.set(m_url->getUrl(), m_url->getUrlLen(), true);
|
||||
if( !urlb.set(&urlw) ) {
|
||||
log(LOG_ERROR,"COULD NOT SET BITS FOR URL WORDS");
|
||||
}
|
||||
if( !urlp.set(&urlw, &urlb) ) {
|
||||
log(LOG_ERROR,"COULD NOT SET PHRASES FOR URL WORDS");
|
||||
}
|
||||
g_adultCheckList.getDirtyScore(&urlw, &urlp, &uniqueTermIds, &m_docAdultScore, &m_numUniqueDirtyWords, &m_numUniqueDirtyPhrases, m_debbuf, m_debbufUsed, m_debbufSize);
|
||||
m_numWordsChecked += urlw.getNumWords();
|
||||
}
|
||||
|
||||
if( m_docAdultScore > 0 ) {
|
||||
m_reason = "adultTerms";
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Additional check for adult content compliance statement
|
||||
//
|
||||
// "18 U.S.C. 2257 Record-Keeping Requirements Compliance Statement"
|
||||
// "18 USC. 2257 Record-Keeping Requirements Compliance Statement"
|
||||
int64_t hs18 = hash64Lower_utf8_nospaces("18", 2);
|
||||
int64_t hsu = hash64Lower_utf8_nospaces("u", 1);
|
||||
int64_t hss = hash64Lower_utf8_nospaces("s", 1);
|
||||
int64_t hsc = hash64Lower_utf8_nospaces("c", 1);
|
||||
int64_t hsusc = hash64Lower_utf8_nospaces("usc", 3);
|
||||
int64_t hs2257 = hash64Lower_utf8_nospaces("2257", 4);
|
||||
int64_t hsrecord = hash64Lower_utf8_nospaces("record", 6);
|
||||
int64_t hskeeping = hash64Lower_utf8_nospaces("keeping", 7);
|
||||
int64_t hsrequirements = hash64Lower_utf8_nospaces("requirements", 12);
|
||||
int64_t hscompliance = hash64Lower_utf8_nospaces("compliance", 10);
|
||||
|
||||
if( uniqueTermIds.getSlot(&hs18) >= 0 &&
|
||||
uniqueTermIds.getSlot(&hs2257) >= 0 &&
|
||||
uniqueTermIds.getSlot(&hsrecord) >= 0 &&
|
||||
uniqueTermIds.getSlot(&hskeeping) >= 0 &&
|
||||
uniqueTermIds.getSlot(&hsrequirements) >= 0 &&
|
||||
uniqueTermIds.getSlot(&hscompliance) >= 0 &&
|
||||
( (uniqueTermIds.getSlot(&hsu) >= 0 &&
|
||||
uniqueTermIds.getSlot(&hss) >= 0 &&
|
||||
uniqueTermIds.getSlot(&hsc) >= 0) ||
|
||||
uniqueTermIds.getSlot(&hsusc) >= 0
|
||||
)) {
|
||||
m_reason = "USC2257Disclaimer";
|
||||
m_docAdultScore+=1000;
|
||||
//log(LOG_ERROR,"@@@ USC 2257 compliance statement FOUND in %s: score=%" PRId32 "", url->getUrl(), m_docAdultScore);
|
||||
}
|
||||
|
||||
//TODO:
|
||||
//18 U.S.C. 2257
|
||||
//Title 18 U.S.C. 2257 Compliance Statement
|
||||
//Compliance with 18 U.S.C. § 2257
|
||||
|
||||
//<meta http-equiv="PICS-Label" content='(pics-1.1 "http://www.icra.org/ratingsv02.html" comment "ICRAonline EN v2.0" l gen true for "" r (nb 1 nc 1 nd 1 ne 1 nh 1 ni 1 vz 1 la 1 oz 1 cz 1) "http://www.rsac.org/ratingsv01.html" l gen true for "" r (n 3 s 3 v 0 l 4))' />
|
||||
|
||||
//Beskyt dine b<>rn mod erotiske sites med
|
||||
//Protect your children against Adult Content with
|
||||
//Eltern k<>nnen ihre Kinder vor ungeeigneten Inhalten sch<63>tzen mit
|
||||
//Prot<6F>gez vos enfants contre le Contenu pour adultes au moyen de
|
||||
//Skydda dina barn mot inneh<65>ll som endast <20>r avsett f<>r vuxna med hj<68>lp av
|
||||
//Beskytt barna dine mot voksent innhold med
|
||||
//Proteggete i vostri figli dal contenuto erotico di questo sito con
|
||||
//Los padres, protegen a sus menores del Contenido Adulto con
|
||||
//Os Pais devem usar um dos seguintes programas para salvaguardar os filhos do conte<74>do er<65>tico
|
||||
//Bescherm minderjarigen tegen expliciete beelden op internet met software als Netnanny, Cyberpatrol of Cybersitter.
|
||||
}
|
||||
|
||||
|
||||
bool adult = false;
|
||||
if( ( m_docAdultScore >= 30 || m_numUniqueDirtyWords > 7) ||
|
||||
( m_docAdultScore >= 30 || m_numUniqueDirtyPhrases >= 3) ) {
|
||||
adult = true;
|
||||
}
|
||||
|
||||
|
||||
m_result = adult;
|
||||
m_resultValid = true;
|
||||
|
||||
return m_result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Check for adult TLDs
|
||||
// https://tld-list.com/tld-categories/adult
|
||||
bool isAdultTLD(const char *tld, size_t tld_len) {
|
||||
switch(tld_len) {
|
||||
case 3:
|
||||
if( strncasecmp(tld, "cam", tld_len) == 0 ||
|
||||
strncasecmp(tld, "sex", tld_len) == 0 ||
|
||||
strncasecmp(tld, "xxx", tld_len) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if( strncasecmp(tld, "porn", tld_len) == 0 ||
|
||||
strncasecmp(tld, "sexy", tld_len) == 0 ||
|
||||
strncasecmp(tld, "tube", tld_len) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if( strncasecmp(tld, "adult", tld_len) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
if( strncasecmp(tld, "webcam", tld_len) == 0 ) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
70
FxAdultCheck.h
Normal file
70
FxAdultCheck.h
Normal file
@ -0,0 +1,70 @@
|
||||
//
|
||||
// Copyright (C) 2017 Privacore ApS - https://www.privacore.com
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// License TL;DR: If you change this file, you must publish your changes.
|
||||
//
|
||||
#ifndef FXADULTCHECK_H_
|
||||
#define FXADULTCHECK_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
#include "FxAdultCheckList.h"
|
||||
|
||||
|
||||
class AdultCheck {
|
||||
public:
|
||||
AdultCheck(XmlDoc *xd, bool debug=false);
|
||||
~AdultCheck();
|
||||
|
||||
bool init();
|
||||
bool isDocAdult();
|
||||
int32_t getScore();
|
||||
int32_t getNumUniqueDirtyWords();
|
||||
int32_t getNumUniqueDirtyPhrases();
|
||||
int32_t getNumWordsChecked();
|
||||
bool hasEmptyDocumentBody();
|
||||
const char *getReason();
|
||||
const char *getDebugInfo();
|
||||
|
||||
private:
|
||||
bool hasAdultRatingTag();
|
||||
bool hasAdultAds();
|
||||
|
||||
Url *m_url;
|
||||
Xml *m_xml;
|
||||
Words *m_words;
|
||||
Phrases *m_phrases;
|
||||
|
||||
char *m_debbuf;
|
||||
int m_debbufUsed;
|
||||
int m_debbufSize;
|
||||
|
||||
std::string m_reason;
|
||||
int32_t m_docAdultScore;
|
||||
int32_t m_numUniqueDirtyWords;
|
||||
int32_t m_numUniqueDirtyPhrases;
|
||||
int32_t m_numWordsChecked;
|
||||
bool m_emptyDocumentBody;
|
||||
bool m_resultValid;
|
||||
bool m_result;
|
||||
};
|
||||
|
||||
|
||||
bool isAdultTLD(const char *tld, size_t tld_len);
|
||||
|
||||
|
||||
#endif
|
264
FxAdultCheckList.cpp
Normal file
264
FxAdultCheckList.cpp
Normal file
@ -0,0 +1,264 @@
|
||||
//
|
||||
// Copyright (C) 2017 Privacore ApS - https://www.privacore.com
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// License TL;DR: If you change this file, you must publish your changes.
|
||||
//
|
||||
#include "FxAdultCheckList.h"
|
||||
#include "Log.h"
|
||||
#include "termid_mask.h"
|
||||
#include "Phrases.h"
|
||||
#include "Words.h"
|
||||
#include <stddef.h>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
AdultCheckList g_adultCheckList;
|
||||
|
||||
AdultCheckList::AdultCheckList() : m_initialized(false) {}
|
||||
|
||||
AdultCheckList::~AdultCheckList(){}
|
||||
|
||||
|
||||
bool AdultCheckList::init() {
|
||||
if( m_initialized ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
log(LOG_INFO, "Initializing AdultCheckList");
|
||||
if( load() ) {
|
||||
m_initialized = true;
|
||||
}
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
|
||||
bool AdultCheckList::load() {
|
||||
|
||||
//
|
||||
// Initialize dirty single words
|
||||
//
|
||||
int32_t need4 = 10000 * 4 + 5000;
|
||||
if (!m_dirtyTerms.set(sizeof(int64_t), 4, need4, NULL, 0, false, "dirty", false, 0)) {
|
||||
log(LOG_ERROR,"Could not initialize dirty word hashtable");
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !loadScoredTermList(&m_dirtyTerms, "adultwords.txt") ) {
|
||||
log(LOG_ERROR,"Could not load dirty word file");
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize dirty phrases (bigrams) - use same hash table as words
|
||||
//
|
||||
if( !loadScoredTermList(&m_dirtyTerms, "adultphrases.txt") ) {
|
||||
log(LOG_ERROR,"Could not load dirty phrase file");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AdultCheckList::loadScoredTermList(HashTableX *ht, const char *filename) {
|
||||
log(LOG_INFO, "Loading %s", filename);
|
||||
|
||||
struct stat st;
|
||||
if (stat(filename, &st) != 0) {
|
||||
// probably not found
|
||||
log(LOG_INFO, "loadScoredTermlist: Unable to stat %s", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ifstream file(filename);
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
// ignore comments & empty lines
|
||||
if (line.length() == 0 || line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
auto firstColEnd = line.find_first_of("|");
|
||||
size_t secondCol = line.find_first_not_of("|", firstColEnd);
|
||||
if( firstColEnd == std::string::npos || secondCol == std::string::npos) {
|
||||
// invalid format
|
||||
log(LOG_ERROR,"Invalid line read: %.*s", (int)line.length(), line.data());
|
||||
continue;
|
||||
}
|
||||
size_t secondColEnd = line.find_first_of("|", secondCol);
|
||||
size_t thirdCol = line.find_first_not_of("|", secondColEnd);
|
||||
if (thirdCol == std::string::npos) {
|
||||
// invalid format
|
||||
log(LOG_ERROR,"Invalid line read: %.*s", (int)line.length(), line.data());
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string lang = std::string(line, 0, firstColEnd);
|
||||
std::string col2(line, secondCol, secondColEnd - secondCol);
|
||||
std::string col3 = std::string(line, thirdCol);
|
||||
|
||||
int32_t dwscore = atoi(col3.data());
|
||||
|
||||
if( dwscore < 1 || col2.length() < 1 || col3.length() < 1 ) {
|
||||
log(LOG_ERROR,"Invalid line read: %.*s", (int)line.length(), line.data());
|
||||
continue;
|
||||
}
|
||||
|
||||
//log(LOG_ERROR,"read: %s [%" PRId32 "] [%s]", col2.c_str(), dwscore, lang.c_str());
|
||||
|
||||
int64_t dwid = hash64Lower_utf8_nospaces(col2.data(), col2.length());
|
||||
|
||||
if( !ht->addKey(&dwid, &dwscore) ) {
|
||||
log(LOG_ERROR,"COULD NOT ADD [%.*s] TO DIRTY WORD LIST", (int)col2.length(), col2.data());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
log(LOG_INFO, "Loaded %s", filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool AdultCheckList::getDirtyScore(Words *w, Phrases *p, HashTableX *uniqueTermIds, int32_t *docAdultScore, int32_t *numUniqueDirtyWords, int32_t *numUniqueDirtyPhrases, char *debbuf, int32_t &debbuf_used, int32_t debbuf_size) {
|
||||
|
||||
if( !w || !uniqueTermIds || !docAdultScore || !numUniqueDirtyWords || !numUniqueDirtyPhrases ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( debbuf ) {
|
||||
debbuf[debbuf_used] = '\0';
|
||||
}
|
||||
|
||||
int rc;
|
||||
bool debug=false;
|
||||
|
||||
const uint64_t *wids = reinterpret_cast<const uint64_t*>(w->getWordIds());
|
||||
int32_t nw = w->getNumWords();
|
||||
|
||||
// log(LOG_ERROR,"=== numWords=%" PRId32 ", debbuf=%p, debbuf_size=%" PRId32 " ===", nw, debbuf, debbuf_size);
|
||||
for(int32_t i=0; i < nw; i++) {
|
||||
if( !wids[i] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
char *s = w->getWord(i);
|
||||
if( !s ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t slen = w->getWordLen(i);
|
||||
int64_t termId = hash64Lower_utf8_nospaces( s , slen );
|
||||
|
||||
// only process if we haven't seen it before
|
||||
if ( uniqueTermIds->getSlot( &termId ) >= 0 ) {
|
||||
if(debug) log(LOG_ERROR,"ALREADY SEEN WORD %" PRId32 ": %.*s -> %" PRIu64 " (%" PRId64 ")", i, slen, s, (uint64_t)termId, (uint64_t)(termId & TERMID_MASK));
|
||||
}
|
||||
else {
|
||||
// add to hash table. return NULL and set g_errno on error
|
||||
if ( !uniqueTermIds->addKey(&termId)) {
|
||||
log(LOG_ERROR,"Could not add termId to uniqueTermIds hash table");
|
||||
}
|
||||
|
||||
int32_t *sc = (int32_t*)m_dirtyTerms.getValue64(termId);
|
||||
if( sc ) {
|
||||
if(debug) log(LOG_ERROR,"DIRTY WORD %" PRId32 ": %.*s -> %" PRIu64 " (%" PRId64 ") score %" PRId32 ". debbuf_used=%" PRId32 ", debbuf_size=%" PRId32 "", i, slen, s, (uint64_t)termId, (uint64_t)(termId & TERMID_MASK), *sc, debbuf_used, debbuf_size);
|
||||
(*docAdultScore) += *sc;
|
||||
(*numUniqueDirtyWords)++;
|
||||
|
||||
if( debbuf ) {
|
||||
// 2=", ", 2="w:"
|
||||
if( debbuf_used+slen+2+2+1 < debbuf_size ) {
|
||||
if(debbuf_used ) {
|
||||
rc = snprintf(&debbuf[debbuf_used], debbuf_size - debbuf_used, ", ");
|
||||
if( rc > 0 ) {
|
||||
debbuf_used += rc;
|
||||
}
|
||||
}
|
||||
|
||||
rc = snprintf(&debbuf[debbuf_used], debbuf_size - debbuf_used, "w:%.*s", slen, s);
|
||||
if( rc > 0 ) {
|
||||
debbuf_used += rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(debug) log(LOG_ERROR,"WORD %" PRId32 ": %.*s -> %" PRIu64 " (%" PRId64 ")", i, slen, s, (uint64_t)termId, (uint64_t)(termId & TERMID_MASK));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const uint64_t *pids = reinterpret_cast<const uint64_t*>(p->getPhraseIds2());
|
||||
|
||||
if( !pids[i] ) {
|
||||
// No phrases
|
||||
continue;
|
||||
}
|
||||
|
||||
int32_t plen;
|
||||
char pbuf[256];
|
||||
p->getPhrase(i, pbuf, sizeof(pbuf), &plen);
|
||||
|
||||
if( plen ) {
|
||||
int64_t phraseId = hash64Lower_utf8_nospaces( pbuf , plen );
|
||||
|
||||
if ( uniqueTermIds->getSlot ( &phraseId ) >= 0 ) {
|
||||
if(debug) log(LOG_ERROR,"ALREADY SEEN PHRASE %" PRId32 ": %.*s -> %" PRIu64 " (%" PRId64 ")", i, plen, pbuf, (uint64_t)phraseId, (uint64_t)(phraseId & TERMID_MASK));
|
||||
continue;
|
||||
}
|
||||
|
||||
// add to hash table. return NULL and set g_errno on error
|
||||
if ( !uniqueTermIds->addKey(&phraseId)) {
|
||||
log(LOG_ERROR,"Could not add phraseId to uniqueTermIds hash table");
|
||||
}
|
||||
|
||||
int32_t *sc = (int32_t*)m_dirtyTerms.getValue64(phraseId);
|
||||
if( sc ) {
|
||||
if(debug) log(LOG_ERROR,"DIRTY PHRASE %" PRId32 ": %.*s -> %" PRIu64 " (%" PRId64 ") score %" PRId32 ". debbuf_used=%" PRId32 ", debbuf_size=%" PRId32 "", i, plen, pbuf, (uint64_t)phraseId, (uint64_t)(phraseId & TERMID_MASK), *sc, debbuf_used, debbuf_size);
|
||||
(*docAdultScore) += *sc;
|
||||
(*numUniqueDirtyPhrases)++;
|
||||
|
||||
if( debbuf ) {
|
||||
// 2=", ", 2="p:"
|
||||
if( debbuf_used+plen+2+2+1 < debbuf_size ) {
|
||||
if(debbuf_used) {
|
||||
rc = snprintf(&debbuf[debbuf_used], debbuf_size-debbuf_used, ", ");
|
||||
if( rc > 0 ) {
|
||||
debbuf_used += rc;
|
||||
}
|
||||
}
|
||||
rc = snprintf(&debbuf[debbuf_used], debbuf_size-debbuf_used, "p:%.*s", plen, pbuf);
|
||||
if( rc > 0 ) {
|
||||
debbuf_used += rc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(debug) log(LOG_ERROR,"PHRASE %" PRId32 ": %.*s -> %" PRIu64 " (%" PRId64 ")", i, plen, pbuf, (uint64_t)phraseId, (uint64_t)(phraseId & TERMID_MASK));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( debbuf ) {
|
||||
debbuf[debbuf_used] = '\0';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
53
FxAdultCheckList.h
Normal file
53
FxAdultCheckList.h
Normal file
@ -0,0 +1,53 @@
|
||||
//
|
||||
// Copyright (C) 2017 Privacore ApS - https://www.privacore.com
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// License TL;DR: If you change this file, you must publish your changes.
|
||||
//
|
||||
#ifndef FXADULTCHECKLIST_H_
|
||||
#define FXADULTCHECKLIST_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
#include "HashTableX.h"
|
||||
|
||||
class Phrases;
|
||||
class Words;
|
||||
class Xml;
|
||||
class XmlDoc;
|
||||
class Url;
|
||||
|
||||
class AdultCheckList {
|
||||
public:
|
||||
AdultCheckList();
|
||||
~AdultCheckList();
|
||||
bool init();
|
||||
|
||||
bool getDirtyScore(Words *w, Phrases *p, HashTableX *uniqueTermIds, int32_t *docAdultScore, int32_t *numUniqueDirtyWords, int32_t *numUniqueDirtyPhrases, char *debbuf, int32_t &debbuf_used, int32_t debbuf_size);
|
||||
|
||||
protected:
|
||||
bool load();
|
||||
|
||||
private:
|
||||
bool loadScoredTermList(HashTableX *ht, const char *filename);
|
||||
|
||||
HashTableX m_dirtyTerms;
|
||||
bool m_initialized;
|
||||
};
|
||||
|
||||
extern AdultCheckList g_adultCheckList;
|
||||
|
||||
#endif
|
642
LICENSE
642
LICENSE
@ -1,3 +1,15 @@
|
||||
|
||||
IMPORTANT NOTICE: THIS IS A MIXED LICENSE PROJECT.
|
||||
|
||||
The original Gigablast project is covered by an Apache License with additional
|
||||
restrictions. All files not marked otherwise, are covered by this license.
|
||||
|
||||
Files developed entirely by Privacore ApS is covered by the GNU Affero General
|
||||
Public License. Bascially this means that you have to publish changes you make
|
||||
to these files, even if you only run the code on a server.
|
||||
|
||||
===============================================================================
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
@ -199,4 +211,632 @@ license that then you can arrange a licensing agreement with Matt Wells.
|
||||
Likewise, the Event datamining logic is in Events.cpp and must be separately licensed
|
||||
as well.
|
||||
|
||||
The companies ElasticSearch BV, LucidWorks and their subsidiaries or affiliates are excluded from this license.
|
||||
The companies ElasticSearch BV, LucidWorks and their subsidiaries or affiliates are
|
||||
excluded from this license.
|
||||
|
||||
|
||||
===============================================================================
|
||||
|
||||
|
||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
|
||||
|
||||
|
128
LanguageResultOverride.cpp
Normal file
128
LanguageResultOverride.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
//
|
||||
// Created by alc on 10/25/17.
|
||||
//
|
||||
|
||||
#include "LanguageResultOverride.h"
|
||||
#include "ResultOverride.h"
|
||||
#include "Url.h"
|
||||
#include "Log.h"
|
||||
#include "Conf.h"
|
||||
#include "GbUtil.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
|
||||
LanguageResultOverride::LanguageResultOverride(const char *filename)
|
||||
: m_filename(filename)
|
||||
, m_languageResultOverrideMap(new languageresultoverridemap_t)
|
||||
, m_lastModifiedTime(0) {
|
||||
}
|
||||
|
||||
LanguageResultOverride::LanguageResultOverride(languageresultoverridemap_ptr_t languageResultOverrideMap)
|
||||
: m_filename(nullptr)
|
||||
, m_languageResultOverrideMap(languageResultOverrideMap)
|
||||
, m_lastModifiedTime(0) {
|
||||
}
|
||||
|
||||
bool LanguageResultOverride::load() {
|
||||
// sanity check to make sure we don't call load with a null filename
|
||||
if (m_filename == nullptr) {
|
||||
gbshutdownLogicError();
|
||||
}
|
||||
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "Loading %s", m_filename);
|
||||
|
||||
struct stat st;
|
||||
if (stat(m_filename, &st) != 0) {
|
||||
// probably not found
|
||||
log(LOG_INFO, "RobotsBlockedResultOverride::load: Unable to stat %s", m_filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_lastModifiedTime != 0 && m_lastModifiedTime == st.st_mtime) {
|
||||
// not modified. assume successful
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "Not modified");
|
||||
return true;
|
||||
}
|
||||
|
||||
languageresultoverridemap_ptr_t tmpLanguageResultOverride(new languageresultoverridemap_t);
|
||||
|
||||
std::ifstream file(m_filename);
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
// ignore comments & empty lines
|
||||
if (line.length() == 0 || line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<std::string> tokens = split(line, '|');
|
||||
if (tokens.size() != 3) {
|
||||
logError("Invalid line found. Ignoring line='%s'", line.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
tmpLanguageResultOverride->emplace(tokens[0], ResultOverride(tokens[1], tokens[2]));
|
||||
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "Adding criteria '%s' to list", line.c_str());
|
||||
}
|
||||
|
||||
swapLanguageResultOverride(tmpLanguageResultOverride);
|
||||
m_lastModifiedTime = st.st_mtime;
|
||||
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "Loaded %s", m_filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string LanguageResultOverride::getTitle(const std::string &lang, const Url &url) const {
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "lang=%s url=%s", lang.c_str(), url.getUrl());
|
||||
|
||||
auto resultOverrideMap = getLanguageResultOverrideMap();
|
||||
auto it = resultOverrideMap->find(lang);
|
||||
if (it != resultOverrideMap->end()) {
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "found lang=%s", lang.c_str());
|
||||
return it->second.getTitle(url);
|
||||
}
|
||||
|
||||
// default to english
|
||||
if (lang.compare("en") != 0) {
|
||||
auto it = resultOverrideMap->find("en");
|
||||
if (it != resultOverrideMap->end()) {
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "found default lang=en");
|
||||
return it->second.getTitle(url);
|
||||
}
|
||||
}
|
||||
|
||||
// empty means no override
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string LanguageResultOverride::getSummary(const std::string &lang, const Url &url) const {
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "lang=%s url=%s", lang.c_str(), url.getUrl());
|
||||
|
||||
auto resultOverrideMap = getLanguageResultOverrideMap();
|
||||
auto it = resultOverrideMap->find(lang);
|
||||
if (it != resultOverrideMap->end()) {
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "found lang=%s", lang.c_str());
|
||||
return it->second.getSummary(url);
|
||||
}
|
||||
|
||||
// default to english
|
||||
if (lang.compare("en") != 0) {
|
||||
auto it = resultOverrideMap->find("en");
|
||||
if (it != resultOverrideMap->end()) {
|
||||
logTrace(g_conf.m_logTraceLanguageResultOverride, "found default lang=en");
|
||||
return it->second.getSummary(url);
|
||||
}
|
||||
}
|
||||
|
||||
// empty means no override
|
||||
return "";
|
||||
}
|
||||
|
||||
void LanguageResultOverride::swapLanguageResultOverride(languageresultoverridemapconst_ptr_t languageResultOverrideMap) {
|
||||
std::atomic_store(&m_languageResultOverrideMap, languageResultOverrideMap);
|
||||
}
|
||||
|
||||
languageresultoverridemapconst_ptr_t LanguageResultOverride::getLanguageResultOverrideMap() const {
|
||||
return m_languageResultOverrideMap;
|
||||
}
|
37
LanguageResultOverride.h
Normal file
37
LanguageResultOverride.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef LANGUAGERESULTOVERRIDE_H
|
||||
#define LANGUAGERESULTOVERRIDE_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
struct ResultOverride;
|
||||
|
||||
typedef std::map<std::string, ResultOverride> languageresultoverridemap_t;
|
||||
typedef std::shared_ptr<languageresultoverridemap_t> languageresultoverridemap_ptr_t;
|
||||
typedef std::shared_ptr<const languageresultoverridemap_t> languageresultoverridemapconst_ptr_t;
|
||||
|
||||
class Url;
|
||||
|
||||
class LanguageResultOverride {
|
||||
public:
|
||||
explicit LanguageResultOverride(const char *filename);
|
||||
explicit LanguageResultOverride(languageresultoverridemap_ptr_t languageResultOverrideMap);
|
||||
|
||||
std::string getTitle(const std::string &lang, const Url &url) const;
|
||||
std::string getSummary(const std::string &lang, const Url &url) const;
|
||||
|
||||
protected:
|
||||
bool load();
|
||||
|
||||
void swapLanguageResultOverride(languageresultoverridemapconst_ptr_t resultOverrideMap);
|
||||
languageresultoverridemapconst_ptr_t getLanguageResultOverrideMap() const;
|
||||
|
||||
const char *m_filename;
|
||||
languageresultoverridemapconst_ptr_t m_languageResultOverrideMap;
|
||||
time_t m_lastModifiedTime;
|
||||
};
|
||||
|
||||
|
||||
#endif //LANGUAGERESULTOVERRIDE_H
|
7
Makefile
7
Makefile
@ -11,12 +11,13 @@ export BASE_DIR
|
||||
unexport CONFIG_CPPFLAGS
|
||||
|
||||
OBJS_O0 = \
|
||||
Abbreviations.o AdultCheck.o \
|
||||
Abbreviations.o \
|
||||
BigFile.o \
|
||||
Clusterdb.o Collectiondb.o Conf.o CountryCode.o \
|
||||
DailyMerge.o Dir.o Dns.o Domains.o \
|
||||
Errno.o Entities.o \
|
||||
File.o \
|
||||
FxAdultCheckList.o FxAdultCheck.o\
|
||||
GbMutex.o \
|
||||
HashTable.o HighFrequencyTermShortcuts.o PageTemperatureRegistry.o Docid2Siteflags.o HttpMime.o HttpRequest.o HttpServer.o Hostdb.o \
|
||||
iana_charset.o Images.o ip.o \
|
||||
@ -62,7 +63,7 @@ OBJS_O2 = \
|
||||
OBJS_O3 = \
|
||||
DocDelete.o DnsBlockList.o \
|
||||
IPAddressChecks.o \
|
||||
Linkdb.o \
|
||||
LanguageResultOverride.o Linkdb.o \
|
||||
Msg40.o \
|
||||
Msg25.o \
|
||||
RdbBuckets.o RdbIndex.o RdbIndexQuery.o RdbList.o RdbMap.o ResultOverride.o RobotsBlockedResultOverride.o RobotsCheckList.o \
|
||||
@ -70,7 +71,7 @@ OBJS_O3 = \
|
||||
ScoringWeights.o \
|
||||
TopTree.o \
|
||||
UrlMatch.o UrlMatchList.o UrlMatchHostList.o UrlBlockCheck.o UrlComponent.o UrlParser.o UdpStatistic.o \
|
||||
UrlRealtimeClassification.o \
|
||||
UrlRealtimeClassification.o UrlResultOverride.o \
|
||||
WantedChecker.o \
|
||||
MergeSpaceCoordinator.o \
|
||||
GbMoveFile.o GbMoveFile2.o GbCopyFile.o GbMakePath.o \
|
||||
|
@ -744,6 +744,7 @@ int64_t Msg20Request::makeCacheKey() const
|
||||
hash_buffer.pushLong(m_getLinkInfo);
|
||||
hash_buffer.pushLong(m_onlyNeedGoodInlinks);
|
||||
hash_buffer.pushLong(m_getLinkText);
|
||||
hash_buffer.pushLong(m_prefferedResultLangId);
|
||||
hash_buffer.safeMemcpy(ptr_qbuf,size_qbuf);
|
||||
hash_buffer.safeMemcpy(ptr_ubuf,size_ubuf);
|
||||
hash_buffer.safeMemcpy(ptr_linkee,size_linkee);
|
||||
|
1
Msg20.h
1
Msg20.h
@ -51,6 +51,7 @@ class Msg20Request {
|
||||
|
||||
// language the query is in (ptr_qbuf)
|
||||
uint8_t m_langId;
|
||||
uint8_t m_prefferedResultLangId;
|
||||
// we now use the numeric collection # and not the ptr_coll
|
||||
collnum_t m_collnum;
|
||||
|
||||
|
@ -1272,6 +1272,7 @@ bool Msg25::sendRequests() {
|
||||
// buzz sets the query to see if inlinker has the query terms
|
||||
// so we can set <absScore2>
|
||||
r->m_langId = langUnknown; // no synonyms i guess
|
||||
r->m_prefferedResultLangId = langUnknown;
|
||||
r->ptr_qbuf = m_qbuf;
|
||||
r->size_qbuf = m_qbufSize;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "HttpServer.h"
|
||||
#include "PageResults.h"
|
||||
#include "HashTable.h"
|
||||
#include "AdultCheck.h"
|
||||
//#include "AdultCheck.h"
|
||||
#include "Process.h"
|
||||
#include "UrlRealtimeClassification.h"
|
||||
#include "UdpServer.h"
|
||||
@ -263,6 +263,8 @@ bool Msg40::prepareToGetDocIds ( ) {
|
||||
// . if query has dirty words and family filter is on, set
|
||||
// number of results to 0, and set the m_queryClen flag to true
|
||||
// . m_qbuf1 should be the advanced/composite query
|
||||
#if 0
|
||||
//@@@ TODO
|
||||
if ( m_si->m_familyFilter &&
|
||||
getAdultPoints ( m_si->m_sbuf1.getBufStart() ,
|
||||
m_si->m_sbuf1.length() ,
|
||||
@ -271,6 +273,7 @@ bool Msg40::prepareToGetDocIds ( ) {
|
||||
m_msg3a.reset();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return getDocIds( false );
|
||||
}
|
||||
@ -976,6 +979,7 @@ bool Msg40::launchMsg20s(bool recalled) {
|
||||
req.ptr_qbuf = const_cast<char*>(q->getQuery());
|
||||
req.size_qbuf = q->getQueryLen()+1;
|
||||
req.m_langId = m_si->m_queryLangId;
|
||||
req.m_prefferedResultLangId = getLangIdFromAbbr(m_si->getPreferredResultLanguage().c_str());
|
||||
|
||||
req.m_highlightQueryTerms = m_si->m_doQueryHighlighting;
|
||||
|
||||
|
@ -1871,18 +1871,6 @@ static bool printInlinkText ( SafeBuf *sb , Msg20Reply *mr , SearchInput *si ,
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string getPreferredResultLanguage(const SearchInput *si) {
|
||||
if (si->m_fx_qlang && strlen(si->m_fx_qlang) == 2) {
|
||||
return si->m_fx_qlang;
|
||||
}
|
||||
|
||||
if (si->m_fx_blang && strlen(si->m_fx_blang) >= 2) {
|
||||
return std::string(si->m_fx_blang, 2);
|
||||
}
|
||||
|
||||
return "en";
|
||||
}
|
||||
|
||||
// use this for xml as well as html
|
||||
bool printResult(State0 *st, int32_t ix , int32_t *numPrintedSoFar) {
|
||||
SafeBuf *sb = &st->m_sb;
|
||||
@ -2243,10 +2231,10 @@ bool printResult(State0 *st, int32_t ix , int32_t *numPrintedSoFar) {
|
||||
strLen = 0;
|
||||
}
|
||||
|
||||
std::string preferredResultLang = getPreferredResultLanguage(si);
|
||||
std::string preferredResultLang = si->getPreferredResultLanguage();
|
||||
std::string overriddenTitle;
|
||||
// override title
|
||||
if (mr->m_indexCode == EDOCDISALLOWEDROOT) {
|
||||
if (strLen == 0 && mr->m_indexCode == EDOCDISALLOWEDROOT) {
|
||||
overriddenTitle = g_robotsBlockedResultOverride.getTitle(preferredResultLang, uu);
|
||||
str = overriddenTitle.c_str();
|
||||
strLen = overriddenTitle.length();
|
||||
@ -2405,7 +2393,7 @@ bool printResult(State0 *st, int32_t ix , int32_t *numPrintedSoFar) {
|
||||
|
||||
// override summary
|
||||
std::string overriddenSummary;
|
||||
if (mr->m_indexCode == EDOCDISALLOWEDROOT) {
|
||||
if (strLen == 0 && mr->m_indexCode == EDOCDISALLOWEDROOT) {
|
||||
overriddenSummary = g_robotsBlockedResultOverride.getSummary(preferredResultLang, uu);
|
||||
str = overriddenSummary.c_str();
|
||||
strLen = overriddenSummary.length();
|
||||
|
22
Parms.cpp
22
Parms.cpp
@ -5402,7 +5402,7 @@ void Parms::init ( ) {
|
||||
m->m_group = false;
|
||||
m++;
|
||||
|
||||
m->m_title = "stable-summary cache max age";
|
||||
m->m_title = "unstable-summary cache max age";
|
||||
m->m_desc = "How long to cache unstable summaries.";
|
||||
m->m_cgi = "unstablesumcacheage";
|
||||
m->m_xml = "UnstableSummaryCacheAge";
|
||||
@ -8673,6 +8673,13 @@ void Parms::init ( ) {
|
||||
m->m_page = PAGE_LOG;
|
||||
m++;
|
||||
|
||||
m->m_title = "log trace info for LanguageResultOverride";
|
||||
m->m_cgi = "ltrc_langro";
|
||||
simple_m_set(Conf,m_logTraceLanguageResultOverride);
|
||||
m->m_def = "0";
|
||||
m->m_page = PAGE_LOG;
|
||||
m++;
|
||||
|
||||
m->m_title = "log trace info for Mem";
|
||||
m->m_cgi = "ltrc_mem";
|
||||
simple_m_set(Conf,m_logTraceMem);
|
||||
@ -8800,13 +8807,6 @@ void Parms::init ( ) {
|
||||
m->m_page = PAGE_LOG;
|
||||
m++;
|
||||
|
||||
m->m_title = "log trace info for RobotsBlockedMsg";
|
||||
m->m_cgi = "ltrc_robotsb";
|
||||
simple_m_set(Conf,m_logTraceRobotsBlocked);
|
||||
m->m_def = "0";
|
||||
m->m_page = PAGE_LOG;
|
||||
m++;
|
||||
|
||||
m->m_title = "log trace info for RobotsCheckList";
|
||||
m->m_cgi = "ltrc_robotscl";
|
||||
simple_m_set(Conf,m_logTraceRobotsCheckList);
|
||||
@ -8886,6 +8886,12 @@ void Parms::init ( ) {
|
||||
m->m_page = PAGE_LOG;
|
||||
m++;
|
||||
|
||||
m->m_title = "log trace info for UrlResultOverride";
|
||||
m->m_cgi = "ltrc_urlro";
|
||||
simple_m_set(Conf,m_logTraceUrlResultOverride);
|
||||
m->m_def = "0";
|
||||
m->m_page = PAGE_LOG;
|
||||
m++;
|
||||
|
||||
m->m_title = "log trace info for Word Spam detection";
|
||||
m->m_cgi = "ltrc_wordspam";
|
||||
|
@ -1,22 +1,16 @@
|
||||
#include "RobotsBlockedResultOverride.h"
|
||||
#include "ResultOverride.h"
|
||||
#include "Loop.h"
|
||||
#include "Url.h"
|
||||
#include "Log.h"
|
||||
#include "Conf.h"
|
||||
#include "Url.h"
|
||||
#include "GbUtil.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
|
||||
RobotsBlockedResultOverride g_robotsBlockedResultOverride;
|
||||
|
||||
static const char *s_resultoverride_filename = "robotsblockedresultoverride.txt";
|
||||
|
||||
RobotsBlockedResultOverride::RobotsBlockedResultOverride()
|
||||
: m_filename(s_resultoverride_filename)
|
||||
, m_resultOverrideMap(new resultoverridemap_t)
|
||||
, m_lastModifiedTime(0) {
|
||||
: LanguageResultOverride(s_resultoverride_filename) {
|
||||
}
|
||||
|
||||
bool RobotsBlockedResultOverride::init() {
|
||||
@ -35,80 +29,21 @@ void RobotsBlockedResultOverride::reload(int /*fd*/, void *state) {
|
||||
robotsBlockedResultOverride->load();
|
||||
}
|
||||
|
||||
bool RobotsBlockedResultOverride::load() {
|
||||
g_conf.m_logTraceRobotsBlocked = true;
|
||||
logTrace(g_conf.m_logTraceRobotsBlocked, "Loading %s", m_filename);
|
||||
|
||||
struct stat st;
|
||||
if (stat(m_filename, &st) != 0) {
|
||||
// probably not found
|
||||
log(LOG_INFO, "RobotsBlockedResultOverride::load: Unable to stat %s", m_filename);
|
||||
return false;
|
||||
std::string RobotsBlockedResultOverride::getTitle(const std::string &lang, const Url &url) const {
|
||||
std::string title = LanguageResultOverride::getTitle(lang, url);
|
||||
if (title.empty()) {
|
||||
// default title when nothing is configured
|
||||
title = std::string(url.getHost(), url.getHostLen());
|
||||
}
|
||||
|
||||
if (m_lastModifiedTime != 0 && m_lastModifiedTime == st.st_mtime) {
|
||||
// not modified. assume successful
|
||||
logTrace(g_conf.m_logTraceRobotsBlocked, "Not modified");
|
||||
return true;
|
||||
return title;
|
||||
}
|
||||
std::string RobotsBlockedResultOverride::getSummary(const std::string &lang, const Url &url) const {
|
||||
std::string summary = LanguageResultOverride::getSummary(lang, url);
|
||||
if (summary.empty()) {
|
||||
// default description when nothing is configured
|
||||
summary = "No description available";
|
||||
}
|
||||
|
||||
resultoverridemap_ptr_t tmpResultOverride(new resultoverridemap_t);
|
||||
|
||||
std::ifstream file(m_filename);
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
// ignore comments & empty lines
|
||||
if (line.length() == 0 || line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<std::string> tokens = split(line, '|');
|
||||
if (tokens.size() != 3) {
|
||||
logError("Invalid line found. Ignoring line='%s'", line.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
tmpResultOverride->emplace(tokens[0], ResultOverride(tokens[1], tokens[2]));
|
||||
logTrace(g_conf.m_logTraceRobotsBlocked, "Adding criteria '%s' to list", line.c_str());
|
||||
}
|
||||
|
||||
swapResultOverride(tmpResultOverride);
|
||||
m_lastModifiedTime = st.st_mtime;
|
||||
|
||||
logTrace(g_conf.m_logTraceRobotsBlocked, "Loaded %s", m_filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string RobotsBlockedResultOverride::getTitle(const std::string &lang, const Url &url) {
|
||||
logTrace(g_conf.m_logTraceRobotsBlocked, "lang=%s url=%s", lang.c_str(), url.getUrl());
|
||||
|
||||
auto resultOverrideMap = getResultOverrideMap();
|
||||
auto it = resultOverrideMap->find(lang);
|
||||
if (it != resultOverrideMap->end()) {
|
||||
return it->second.getTitle(url);
|
||||
}
|
||||
|
||||
// return as default
|
||||
return std::string(url.getHost(), url.getHostLen());
|
||||
}
|
||||
|
||||
std::string RobotsBlockedResultOverride::getSummary(const std::string &lang, const Url &url) {
|
||||
logTrace(g_conf.m_logTraceRobotsBlocked, "lang=%s url=%s", lang.c_str(), url.getUrl());
|
||||
|
||||
auto resultOverrideMap = getResultOverrideMap();
|
||||
auto it = resultOverrideMap->find(lang);
|
||||
if (it != resultOverrideMap->end()) {
|
||||
return it->second.getSummary(url);
|
||||
}
|
||||
|
||||
// return as default
|
||||
return "No description available";
|
||||
}
|
||||
|
||||
void RobotsBlockedResultOverride::swapResultOverride(resultoverridemapconst_ptr_t resultOverrideMap) {
|
||||
std::atomic_store(&m_resultOverrideMap, resultOverrideMap);
|
||||
}
|
||||
|
||||
resultoverridemapconst_ptr_t RobotsBlockedResultOverride::getResultOverrideMap() {
|
||||
return m_resultOverrideMap;
|
||||
}
|
||||
return summary;
|
||||
}
|
@ -1,19 +1,10 @@
|
||||
#ifndef ROBOTSBLOCKEDRESULTOVERRIDE_H
|
||||
#define ROBOTSBLOCKEDRESULTOVERRIDE_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include "LanguageResultOverride.h"
|
||||
|
||||
struct ResultOverride;
|
||||
|
||||
typedef std::map<std::string, ResultOverride> resultoverridemap_t;
|
||||
typedef std::shared_ptr<resultoverridemap_t> resultoverridemap_ptr_t;
|
||||
typedef std::shared_ptr<const resultoverridemap_t> resultoverridemapconst_ptr_t;
|
||||
|
||||
class Url;
|
||||
|
||||
class RobotsBlockedResultOverride {
|
||||
class RobotsBlockedResultOverride : public LanguageResultOverride {
|
||||
public:
|
||||
RobotsBlockedResultOverride();
|
||||
|
||||
@ -21,20 +12,8 @@ public:
|
||||
|
||||
static void reload(int /*fd*/, void *state);
|
||||
|
||||
std::string getTitle(const std::string &lang, const Url &url);
|
||||
std::string getSummary(const std::string &lang, const Url &url);
|
||||
|
||||
protected:
|
||||
bool load();
|
||||
|
||||
const char *m_filename;
|
||||
|
||||
private:
|
||||
void swapResultOverride(resultoverridemapconst_ptr_t resultOverrideMap);
|
||||
resultoverridemapconst_ptr_t getResultOverrideMap();
|
||||
|
||||
resultoverridemapconst_ptr_t m_resultOverrideMap;
|
||||
time_t m_lastModifiedTime;
|
||||
std::string getTitle(const std::string &lang, const Url &url) const;
|
||||
std::string getSummary(const std::string &lang, const Url &url) const;
|
||||
};
|
||||
|
||||
extern RobotsBlockedResultOverride g_robotsBlockedResultOverride;
|
||||
|
@ -751,3 +751,15 @@ bool SearchInput::setQueryBuffers ( HttpRequest *hr ) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string SearchInput::getPreferredResultLanguage() {
|
||||
if (m_fx_qlang && strlen(m_fx_qlang) == 2) {
|
||||
return m_fx_qlang;
|
||||
}
|
||||
|
||||
if (m_fx_blang && strlen(m_fx_blang) >= 2) {
|
||||
return std::string(m_fx_blang, 2);
|
||||
}
|
||||
|
||||
return "en";
|
||||
}
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "Query.h" // MAX_QUERY_LEN
|
||||
#include "HttpRequest.h"
|
||||
#include <string>
|
||||
|
||||
class CollectionRec;
|
||||
|
||||
@ -35,6 +36,8 @@ public:
|
||||
|
||||
void copy ( class SearchInput *si ) ;
|
||||
|
||||
std::string getPreferredResultLanguage();
|
||||
|
||||
///////////
|
||||
//
|
||||
// BEGIN COMPUTED THINGS
|
||||
|
233
Speller.cpp
233
Speller.cpp
@ -1,7 +1,6 @@
|
||||
#include "Speller.h"
|
||||
#include "Query.h"
|
||||
#include "StopWords.h"
|
||||
#include "AdultCheck.h"
|
||||
#include "Hostdb.h"
|
||||
#include "Process.h"
|
||||
#include "Conf.h"
|
||||
@ -531,238 +530,6 @@ int32_t Speller::getPhrasePopularity( const char *str, uint64_t h, unsigned char
|
||||
return max;
|
||||
}
|
||||
|
||||
// splits words and checks if they form a porn word or not. montanalinux.org
|
||||
// is showing up as porn because it has 'anal' in the hostname. So try to
|
||||
// find a combination of words such that they are NOT porn.
|
||||
// try this only after isAdult() succeeds.
|
||||
// Always tries to find longer words first. so 'montanalinux' is split as
|
||||
// 'montana' and 'linux' and not as 'mont', 'analinux'
|
||||
// if it finds a seq of words leading upto a porn word, then it returns true
|
||||
// eg. shall split montanalinux into 'mont', 'anal', and return true without
|
||||
// checking if 'inux' is a word. Need to do this because isAdult() cannot
|
||||
// define where an adult word has ended.
|
||||
// TODO: chatswingers.com NOT identified as porn because it is split as
|
||||
// 'chats' and 'wingers'.
|
||||
|
||||
bool Speller::canSplitWords(const char *s, int32_t slen, bool *isPorn, char *splitWords, unsigned char langId) {
|
||||
*isPorn = false;
|
||||
const char *index[1024];
|
||||
if ( slen == 0 )
|
||||
return true;
|
||||
*splitWords = '\0';
|
||||
|
||||
// this is the current word we're on
|
||||
int32_t curr = 0;
|
||||
index[curr++] = s;
|
||||
index[curr] = s + slen;
|
||||
while ( curr > 0 ){
|
||||
const char *nextWord = NULL;
|
||||
while (findNext( index[curr - 1], index[curr], &nextWord, isPorn, langId )){
|
||||
// next word in chain
|
||||
index[curr++] = nextWord;
|
||||
index[curr] = s + slen;
|
||||
// found a porn word OR
|
||||
// finished making a sequence of words
|
||||
if ( *isPorn || nextWord == s + slen ){
|
||||
char *p = splitWords;
|
||||
for ( int32_t k = 1; k < curr; k++ ){
|
||||
gbmemcpy (p, index[k - 1],
|
||||
index[k] - index[k - 1]);
|
||||
p += index[k] - index[k - 1];
|
||||
*p = ' ';
|
||||
p++;
|
||||
}
|
||||
*p = '\0';
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// did not find any word. reduce the current position
|
||||
while ( --curr > 0 ){
|
||||
if ( curr > 0 && index[curr] > index[curr-1] ){
|
||||
index[curr]--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Speller::findNext(const char *s, const char *send, const char **nextWord, bool *isPorn, unsigned char langId) {
|
||||
const char *loc = NULL;
|
||||
int32_t slen = send - s;
|
||||
// check if there is an adult word in there
|
||||
// NOTE: The word 'adult' gives a lot of false positives, so even
|
||||
// though it is in the isAdult() list, skip it.
|
||||
// s/slen constitues an individual word.
|
||||
if ( isAdult ( s, slen, &loc ) && strncmp ( s, "adult", 5 ) != 0 ){
|
||||
// if this string starts with the adult word, don't check
|
||||
// further
|
||||
if ( loc == s ){
|
||||
*isPorn = true;
|
||||
*nextWord = send;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for(const char *a = send; a > s; a--) {
|
||||
// a hack, if the word is only one letter long, check if it
|
||||
// is 'a' or 'i'. If not then continue
|
||||
if ( a - s == 1 && *s != 'a' && *s != 'i')
|
||||
continue;
|
||||
// another hack, the end word of the string cannot be 2 letters
|
||||
// or less. freesex was being split as 'frees ex'
|
||||
if ( a == send && a - s <= 2 )
|
||||
continue;
|
||||
|
||||
// do not allow "ult" to be a word because it always will
|
||||
// split "adult" into "ad+ult"
|
||||
if ( a - s == 3 && s[0]=='u' && s[1]=='l' && s[2]=='t' )
|
||||
continue;
|
||||
// adultsiteratings = "ad ul ts it era tings"
|
||||
if ( a - s == 2 && s[0]=='u' && s[1]=='l' )
|
||||
continue;
|
||||
// lashaxxxnothing = "lash ax xx nothing"
|
||||
if ( a - s == 2 && s[0]=='u' && s[1]=='l' )
|
||||
continue;
|
||||
// livesexasian = "lives ex asian"
|
||||
if ( a - s == 2 && s[0]=='e' && s[1]=='x' )
|
||||
continue;
|
||||
// fuckedtits = "fu ck edt its"
|
||||
if ( a - s == 2 && s[0]=='c' && s[1]=='k' )
|
||||
continue;
|
||||
// blogsexe = "blogs exe" ... many others
|
||||
// any 3 letter fucking word starting with "ex"
|
||||
if ( a - s == 3 && s[0]=='e' && s[1]=='x' )
|
||||
continue;
|
||||
// shemales = "*s hem ales"
|
||||
if ( a - s == 4 && s[0]=='a' &&s[1]=='l'&&s[2]=='e'&&s[3]=='s')
|
||||
continue;
|
||||
// grooverotica = "groove rot ica"
|
||||
if ( a - s == 3 && s[0]=='i' && s[1]=='c' && s[2]=='a' )
|
||||
continue;
|
||||
// dinerotik = dinero tik
|
||||
if ( a - s == 3 && s[0]=='t' && s[1]=='i' && s[2]=='k' )
|
||||
continue;
|
||||
// nudeslutpics = "nud esl ut pics"
|
||||
if ( a - s == 3 && s[0]=='n' && s[1]=='u' && s[2]=='d' )
|
||||
continue;
|
||||
// seepornos = "seep or nos"
|
||||
if ( a - s == 3 && s[0]=='n' && s[1]=='o' && s[2]=='s' )
|
||||
continue;
|
||||
// bookslut = "books lut"
|
||||
if ( a - s == 3 && s[0]=='l' && s[1]=='u' && s[2]=='t' )
|
||||
continue;
|
||||
// lesexegratuit = "lese xe gratuit"
|
||||
if ( a - s == 2 && s[0]=='x' && s[1]=='e' )
|
||||
continue;
|
||||
// mooiemensensexdating = "mens ense xd a ting"
|
||||
if ( a - s == 2 && s[0]=='x' && s[1]=='d' )
|
||||
continue;
|
||||
// mpornlinks = mpo rn links
|
||||
if ( a - s == 2 && s[0]=='r' && s[1]=='n' )
|
||||
continue;
|
||||
// ukpornbases = ukp or nba bes
|
||||
if ( a - s == 2 && s[0]=='o' && s[1]=='r' )
|
||||
continue;
|
||||
// slut
|
||||
if ( a - s == 2 && s[0]=='l' && s[1]=='u' )
|
||||
continue;
|
||||
// independentstockholmescorts = "tock holme sco rts"
|
||||
if ( a - s == 3 && s[0]=='s' && s[1]=='c' && s[2]=='o' )
|
||||
continue;
|
||||
// relatosexcitantes = relat ose xci tan tes
|
||||
if ( a - s == 3 && s[0]=='x' && s[1]=='c' && s[2]=='i' )
|
||||
continue;
|
||||
// babe = * bes
|
||||
if ( a - s == 3 && s[0]=='b' && s[1]=='e' && s[2]=='s' )
|
||||
continue;
|
||||
// xpornreviews "xp orn reviews "
|
||||
if ( a - s == 3 && s[0]=='o' && s[1]=='r' && s[2]=='n' )
|
||||
continue;
|
||||
// shemal fix
|
||||
if ( a - s == 3 && s[0]=='h' && s[1]=='e' && s[2]=='m' )
|
||||
continue;
|
||||
// adultswim = adults wim
|
||||
if ( a - s == 3 && s[0]=='w' && s[1]=='i' && s[2]=='m' )
|
||||
continue;
|
||||
// bdsm
|
||||
if ( a - s == 3 && s[0]=='d' && s[1]=='s' && s[2]=='m' )
|
||||
continue;
|
||||
// anal
|
||||
if ( a - s == 3 && s[0]=='n' && s[1]=='a' && s[2]=='l' )
|
||||
continue;
|
||||
// vibrator = bra
|
||||
if ( a - s == 3 && s[0]=='b' && s[1]=='r' && s[2]=='a' )
|
||||
continue;
|
||||
// sitiospornox = sitio spor nox
|
||||
if ( a - s == 4 && s[0]=='s' && s[1]=='p' && s[2]=='o' &&
|
||||
s[3] == 'r' )
|
||||
continue;
|
||||
// orn*
|
||||
if ( a - s == 4 && s[0]=='o' && s[1]=='r' && s[2]=='n' )
|
||||
continue;
|
||||
// hotescorts = hote scor
|
||||
if ( a - s == 4 && s[0]=='s' && s[1]=='c' && s[2]=='o' &&
|
||||
s[3] == 'r' )
|
||||
continue;
|
||||
// uniformsluts = uniformts lutz
|
||||
if ( a - s == 4 && s[0]=='l' && s[1]=='u' && s[2]=='t' &&
|
||||
s[3] == 'z' )
|
||||
continue;
|
||||
// free porn login = freep ornl
|
||||
if ( a - s == 5 && s[0]=='f' && s[1]=='r' && s[2]=='e' &&
|
||||
s[3] == 'e' && s[4] == 'p' )
|
||||
continue;
|
||||
// shemal fix
|
||||
if ( a - s == 5 && s[0]=='h' && s[1]=='e' && s[2]=='m' &&
|
||||
s[3] == 'a' && s[4] == 'l' )
|
||||
continue;
|
||||
// inbondage = inbond age
|
||||
if ( a - s == 6 &&
|
||||
s[0]=='i' && s[1]=='n' && s[2]=='b' &&
|
||||
s[3]=='o' && s[4]=='n' && s[5]=='d' )
|
||||
continue;
|
||||
// swingers = wingers
|
||||
if ( a - s == 7 &&
|
||||
s[0]=='w' && s[1]=='i' && s[2]=='n' &&
|
||||
s[3]=='g' && s[4]=='e' && s[5]=='r' &&
|
||||
s[6]=='s' )
|
||||
continue;
|
||||
// free sex contents = freese xc ont ents
|
||||
if ( a - s == 2 && s[0]=='x' && s[1]=='c' )
|
||||
continue;
|
||||
// mosexstore = mose xs tore
|
||||
if ( a - s == 2 && s[0]=='x' && s[1]=='s' )
|
||||
continue;
|
||||
// phonesexfootsies
|
||||
if ( a - s == 8 &&
|
||||
s[0]=='p' && s[1]=='h' && s[2]=='o' &&
|
||||
s[3]=='n' && s[4]=='e' && s[5]=='s' &&
|
||||
s[6]=='e' && s[7]=='x' )
|
||||
continue;
|
||||
// cybersex
|
||||
if ( a - s == 8 &&
|
||||
s[0]=='c' && s[1]=='y' && s[2]=='b' &&
|
||||
s[3]=='e' && s[4]=='r' && s[5]=='s' &&
|
||||
s[6]=='e' && s[7]=='x' )
|
||||
continue;
|
||||
// hotescorts
|
||||
|
||||
|
||||
// check if the word has popularity. if it is in the
|
||||
// unifiedDict, then it is considered to be a word
|
||||
uint64_t h = hash64d(s, a-s);//a - s, encodeType);
|
||||
int32_t pop = getPhrasePopularity( s, h, langId );
|
||||
|
||||
// continue if did not find it
|
||||
if ( pop <= 0 )
|
||||
continue;
|
||||
// this is our next word
|
||||
*nextWord = a;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// This isn't really much use except for the spider
|
||||
// language detection to keep from making 32 sequential
|
||||
|
@ -94,6 +94,14 @@ bool Summary::verifySummary(const char *titleBuf, int32_t titleBufLen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void Summary::setSummary(const std::string &summary) {
|
||||
m_summaryLen = summary.copy(m_summary, MAX_SUMMARY_LEN);
|
||||
m_summary[m_summaryLen] = '\0';
|
||||
m_summaryExcerptLen[0] = m_summaryLen;
|
||||
m_numExcerpts = 1;
|
||||
m_displayLen = m_summaryLen;
|
||||
}
|
||||
|
||||
// let's try to get a nicer summary by using what the website set as description
|
||||
// Use the following in priority order (highest first)
|
||||
// - itemprop = "description"
|
||||
|
@ -21,6 +21,7 @@
|
||||
#define GB_SUMMARY_H
|
||||
|
||||
#include "gb-include.h"
|
||||
#include <string>
|
||||
|
||||
#define MAX_SUMMARY_LEN (1024*20)
|
||||
#define MAX_SUMMARY_EXCERPTS 1024
|
||||
@ -39,6 +40,8 @@ public:
|
||||
Summary();
|
||||
~Summary();
|
||||
|
||||
void setSummary(const std::string &summary);
|
||||
|
||||
bool setSummary(const Xml *xml, const Words *words, const Sections *sections, Pos *pos, const Query *q,
|
||||
int32_t maxSummaryLen, int32_t numDisplayLines, int32_t maxNumLines, int32_t maxNumCharsPerLine,
|
||||
const Url *f, const Matches *matches, const char *titleBuf, int32_t titleBufLen);
|
||||
|
@ -61,6 +61,11 @@ void Title::reset() {
|
||||
m_titleTagEnd = -1;
|
||||
}
|
||||
|
||||
void Title::setTitle(const std::string &title) {
|
||||
m_titleLen = title.copy(m_title, MAX_TITLE_LEN);
|
||||
m_title[m_titleLen] = '\0';
|
||||
}
|
||||
|
||||
bool Title::setTitleFromTags( Xml *xml, int32_t maxTitleLen, uint8_t contentType ) {
|
||||
/// @todo cater for CT_DOC (when antiword is replaced)
|
||||
// only allow html & pdf documents for now
|
||||
|
3
Title.h
3
Title.h
@ -4,6 +4,7 @@
|
||||
#define GB_TITLE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
|
||||
#define MAX_TITLE_LEN 2048
|
||||
|
||||
@ -22,6 +23,8 @@ public:
|
||||
|
||||
void reset();
|
||||
|
||||
void setTitle(const std::string &title);
|
||||
|
||||
bool setTitle( Xml *xml, Words *words, int32_t maxTitleLen, Query *query, LinkInfo *linkInfo, Url *firstUrl,
|
||||
const char *filteredRootTitleBuf, int32_t filteredRootTitleBufSize, uint8_t contentType,
|
||||
uint8_t langId );
|
||||
|
@ -19,6 +19,9 @@
|
||||
|
||||
// strip ascii tab & newline from url
|
||||
// store m_indexCode in TitleRec
|
||||
#define TITLEREC_CURRENT_VERSION 125
|
||||
//#define TITLEREC_CURRENT_VERSION 125
|
||||
|
||||
// new adult detection
|
||||
#define TITLEREC_CURRENT_VERSION 126
|
||||
|
||||
#endif // GB_TITLERECVERSION_H
|
||||
|
11
Url.cpp
11
Url.cpp
@ -2,7 +2,7 @@
|
||||
#include "UrlParser.h"
|
||||
#include "Domains.h"
|
||||
#include "HashTable.h"
|
||||
#include "AdultCheck.h"
|
||||
#include "FxAdultCheck.h"
|
||||
#include "ip.h" // atoip ( s,len)
|
||||
#include "Punycode.h"
|
||||
#include "Unicode.h"
|
||||
@ -1670,8 +1670,13 @@ bool Url::isHostWWW ( ) const {
|
||||
// . if you add a word here, add it to PageResults.cpp:isQueryDirty()
|
||||
bool Url::isAdult() const {
|
||||
//certain TLDs are clearly adult-oriented
|
||||
if(isAdultTLD(m_tld,m_tldLen))
|
||||
if( isAdultTLD(m_tld, m_tldLen))
|
||||
return true;
|
||||
|
||||
|
||||
#if 0
|
||||
//@@@
|
||||
|
||||
if(m_hlen<=0)
|
||||
return false; // Invalid URL (no hostname)
|
||||
if(m_tldLen<=0)
|
||||
@ -1716,10 +1721,10 @@ bool Url::isAdult() const {
|
||||
// point to next
|
||||
p = pend + 1;
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// . remove any session id
|
||||
// . i'm sick of these tihngs causing dup problems
|
||||
// . types:
|
||||
|
135
UrlResultOverride.cpp
Normal file
135
UrlResultOverride.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
#include "UrlResultOverride.h"
|
||||
#include "LanguageResultOverride.h"
|
||||
#include "ResultOverride.h"
|
||||
#include "Loop.h"
|
||||
#include "Log.h"
|
||||
#include "Conf.h"
|
||||
#include "Url.h"
|
||||
#include "GbUtil.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <fstream>
|
||||
|
||||
UrlResultOverride g_urlResultOverride;
|
||||
|
||||
static const char *s_resultoverride_filename = "urlresultoverride.txt";
|
||||
|
||||
UrlResultOverride::UrlResultOverride()
|
||||
: m_filename(s_resultoverride_filename)
|
||||
, m_urlResultOverrideMap(new urlresultoverridemap_t)
|
||||
, m_lastModifiedTime(0) {
|
||||
}
|
||||
|
||||
bool UrlResultOverride::init() {
|
||||
if (!g_loop.registerSleepCallback(60000, this, &reload, "UrlResultOverride::reload", 0)) {
|
||||
log(LOG_WARN, "UrlResultOverride::init: Failed to register callback.");
|
||||
return false;
|
||||
}
|
||||
|
||||
load();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void UrlResultOverride::reload(int /*fd*/, void *state) {
|
||||
UrlResultOverride *urlResultOverride = static_cast<UrlResultOverride*>(state);
|
||||
urlResultOverride->load();
|
||||
}
|
||||
|
||||
bool UrlResultOverride::load() {
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "Loading %s", m_filename);
|
||||
|
||||
struct stat st;
|
||||
if (stat(m_filename, &st) != 0) {
|
||||
// probably not found
|
||||
log(LOG_INFO, "UrlResultOverride::load: Unable to stat %s", m_filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_lastModifiedTime != 0 && m_lastModifiedTime == st.st_mtime) {
|
||||
// not modified. assume successful
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "Not modified");
|
||||
return true;
|
||||
}
|
||||
|
||||
urlresultoverridemap_ptr_t tmpUrlResultOverride(new urlresultoverridemap_t);
|
||||
languageresultoverridemap_ptr_t tmpLanguageResultOverride(new languageresultoverridemap_t);
|
||||
std::string prevUrl;
|
||||
|
||||
std::ifstream file(m_filename);
|
||||
std::string line;
|
||||
while (std::getline(file, line)) {
|
||||
// ignore comments & empty lines
|
||||
if (line.length() == 0 || line[0] == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::vector<std::string> tokens = split(line, '|');
|
||||
if (tokens.size() != 4) {
|
||||
logError("Invalid line found. Ignoring line='%s'", line.c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string currentUrl(tokens[0]);
|
||||
|
||||
if (!prevUrl.empty() && prevUrl.compare(currentUrl) != 0) {
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "Adding url '%s' to url map", prevUrl.c_str());
|
||||
tmpLanguageResultOverride = std::make_shared<languageresultoverridemap_t>();
|
||||
tmpUrlResultOverride->emplace(prevUrl, LanguageResultOverride(tmpLanguageResultOverride));
|
||||
}
|
||||
|
||||
tmpLanguageResultOverride->emplace(tokens[1], ResultOverride(tokens[2], tokens[3]));
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "Adding criteria '%s' to language map", line.c_str());
|
||||
|
||||
prevUrl = currentUrl;
|
||||
}
|
||||
|
||||
// add last item
|
||||
tmpUrlResultOverride->emplace(prevUrl, LanguageResultOverride(tmpLanguageResultOverride));
|
||||
|
||||
swapUrlResultOverride(tmpUrlResultOverride);
|
||||
m_lastModifiedTime = st.st_mtime;
|
||||
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "Loaded %s", m_filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string UrlResultOverride::getTitle(const std::string &lang, const Url &url) {
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "lang=%s url=%s", lang.c_str(), url.getUrl());
|
||||
|
||||
auto urlResultOverrideMap = getUrlResultOverrideMap();
|
||||
auto it = urlResultOverrideMap->find(url.getUrl());
|
||||
if (it != urlResultOverrideMap->end()) {
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "found url=%s", url.getUrl());
|
||||
return it->second.getTitle(lang, url);
|
||||
}
|
||||
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "lang=%s url=%s no override", lang.c_str(), url.getUrl());
|
||||
|
||||
// empty means no override
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string UrlResultOverride::getSummary(const std::string &lang, const Url &url) {
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "lang=%s url=%s", lang.c_str(), url.getUrl());
|
||||
|
||||
auto urlResultOverrideMap = getUrlResultOverrideMap();
|
||||
auto it = urlResultOverrideMap->find(url.getUrl());
|
||||
if (it != urlResultOverrideMap->end()) {
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "found url=%s", url.getUrl());
|
||||
return it->second.getSummary(lang, url);
|
||||
}
|
||||
|
||||
logTrace(g_conf.m_logTraceUrlResultOverride, "lang=%s url=%s no override", lang.c_str(), url.getUrl());
|
||||
|
||||
// empty means no override
|
||||
return "";
|
||||
}
|
||||
|
||||
void UrlResultOverride::swapUrlResultOverride(urlresultoverridemapconst_ptr_t resultOverrideMap) {
|
||||
std::atomic_store(&m_urlResultOverrideMap, resultOverrideMap);
|
||||
}
|
||||
|
||||
urlresultoverridemapconst_ptr_t UrlResultOverride::getUrlResultOverrideMap() {
|
||||
return m_urlResultOverrideMap;
|
||||
}
|
44
UrlResultOverride.h
Normal file
44
UrlResultOverride.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef URLRESULTOVERRIDE_H
|
||||
#define URLRESULTOVERRIDE_H
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
class LanguageResultOverride;
|
||||
|
||||
typedef std::map<std::string, LanguageResultOverride> urlresultoverridemap_t;
|
||||
typedef std::shared_ptr<urlresultoverridemap_t> urlresultoverridemap_ptr_t;
|
||||
typedef std::shared_ptr<const urlresultoverridemap_t> urlresultoverridemapconst_ptr_t;
|
||||
|
||||
class Url;
|
||||
|
||||
class UrlResultOverride {
|
||||
public:
|
||||
UrlResultOverride();
|
||||
|
||||
bool init();
|
||||
|
||||
static void reload(int /*fd*/, void *state);
|
||||
|
||||
std::string getTitle(const std::string &lang, const Url &url);
|
||||
std::string getSummary(const std::string &lang, const Url &url);
|
||||
|
||||
protected:
|
||||
bool load();
|
||||
|
||||
const char *m_filename;
|
||||
|
||||
private:
|
||||
void swapUrlResultOverride(urlresultoverridemapconst_ptr_t resultOverrideMap);
|
||||
urlresultoverridemapconst_ptr_t getUrlResultOverrideMap();
|
||||
|
||||
urlresultoverridemapconst_ptr_t m_urlResultOverrideMap;
|
||||
time_t m_lastModifiedTime;
|
||||
};
|
||||
|
||||
extern UrlResultOverride g_urlResultOverride;
|
||||
|
||||
|
||||
#endif //URLRESULTOVERRIDE_H
|
2
Words.h
2
Words.h
@ -49,7 +49,7 @@ class Words {
|
||||
// . use range (node1,node2] and if node2 is -1 that means the last one
|
||||
bool set( Xml *xml, bool computeIds, int32_t node1 = 0, int32_t node2 = -1 );
|
||||
|
||||
inline bool addWords( char *s, int32_t nodeLen, bool computeIds );
|
||||
bool addWords( char *s, int32_t nodeLen, bool computeIds );
|
||||
|
||||
// get the spam modified score of the ith word (baseScore is the
|
||||
// score if the word is not spammed)
|
||||
|
45
XmlDoc.cpp
45
XmlDoc.cpp
@ -27,7 +27,7 @@
|
||||
#include "Wiktionary.h"
|
||||
#include "Parms.h"
|
||||
#include "Domains.h"
|
||||
#include "AdultCheck.h"
|
||||
#include "FxAdultCheck.h"
|
||||
#include "Doledb.h"
|
||||
#include "IPAddressChecks.h"
|
||||
#include "PageRoot.h"
|
||||
@ -48,6 +48,7 @@
|
||||
#include "DnsBlockList.h"
|
||||
#include "GbDns.h"
|
||||
#include "RobotsCheckList.h"
|
||||
#include "UrlResultOverride.h"
|
||||
|
||||
|
||||
#ifdef _VALGRIND_
|
||||
@ -1157,6 +1158,12 @@ bool XmlDoc::set2 ( char *titleRec ,
|
||||
m_indexCode = 0;
|
||||
}
|
||||
|
||||
// adult detection code replaced. Invalidate old document versions.
|
||||
if( m_version < 126 ) {
|
||||
m_isAdultValid = false;
|
||||
}
|
||||
|
||||
|
||||
m_indexCodeValid = true;
|
||||
m_redirError = 0;
|
||||
m_redirErrorValid = true;
|
||||
@ -2172,6 +2179,7 @@ int32_t *XmlDoc::getIndexCode ( ) {
|
||||
|
||||
if ( cr->m_doUrlSpamCheck && ! m_check2 ) {
|
||||
m_check2 = true;
|
||||
|
||||
if ( m_firstUrl.isAdult() ) {
|
||||
m_indexCode = EDOCURLSPAM;
|
||||
m_indexCodeValid = true;
|
||||
@ -3137,6 +3145,11 @@ SafeBuf *XmlDoc::getTitleRecBuf ( ) {
|
||||
// . check content for adult words
|
||||
char *XmlDoc::getIsAdult ( ) {
|
||||
|
||||
// adult detection code replaced. Invalidate old document versions.
|
||||
if( m_version < 126 ) {
|
||||
m_isAdultValid = false;
|
||||
}
|
||||
|
||||
if ( m_isAdultValid ) return &m_isAdult2;
|
||||
|
||||
// call that
|
||||
@ -3150,9 +3163,8 @@ char *XmlDoc::getIsAdult ( ) {
|
||||
// time it
|
||||
int64_t start = gettimeofdayInMilliseconds();
|
||||
|
||||
// score that up
|
||||
int32_t total = getAdultPoints ( ptr_utf8Content, size_utf8Content - 1 , m_firstUrl.getUrl() );
|
||||
|
||||
AdultCheck achk(this);
|
||||
m_isAdult = achk.isDocAdult();
|
||||
|
||||
// debug msg
|
||||
int64_t took = gettimeofdayInMilliseconds() - start;
|
||||
@ -3161,9 +3173,6 @@ char *XmlDoc::getIsAdult ( ) {
|
||||
"build: Took %" PRId64" ms to check doc of %" PRId32" bytes for "
|
||||
"dirty words.",took,size_utf8Content-1);
|
||||
|
||||
m_isAdult = false;
|
||||
// adult?
|
||||
if ( total >= 2 ) m_isAdult = true;
|
||||
// set shadow member
|
||||
m_isAdult2 = (bool)m_isAdult;
|
||||
// validate
|
||||
@ -3171,7 +3180,7 @@ char *XmlDoc::getIsAdult ( ) {
|
||||
|
||||
// note it
|
||||
if ( m_isAdult2 && g_conf.m_logDebugDirty )
|
||||
log("dirty: %s points = %" PRId32,m_firstUrl.getUrl(),total);
|
||||
log("dirty: %s score = %" PRId32,m_firstUrl.getUrl(), achk.getScore());
|
||||
|
||||
// no dirty words found
|
||||
return &m_isAdult2;
|
||||
@ -16124,6 +16133,16 @@ Title *XmlDoc::getTitle() {
|
||||
return &m_title;
|
||||
}
|
||||
|
||||
// look for override
|
||||
if (m_req && m_req->m_prefferedResultLangId != langUnknown) {
|
||||
std::string title = g_urlResultOverride.getTitle(getLanguageAbbr(m_req->m_prefferedResultLangId), m_firstUrl);
|
||||
if (!title.empty()) {
|
||||
m_titleValid = true;
|
||||
m_title.setTitle(title);
|
||||
return &m_title;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *contentTypePtr = getContentType();
|
||||
if ( ! contentTypePtr || contentTypePtr == (void *)-1 ) {
|
||||
return (Title *)contentTypePtr;
|
||||
@ -16197,6 +16216,16 @@ Summary *XmlDoc::getSummary () {
|
||||
return &m_summary;
|
||||
}
|
||||
|
||||
// look for override
|
||||
if (m_req && m_req->m_prefferedResultLangId != langUnknown) {
|
||||
std::string summary = g_urlResultOverride.getSummary(getLanguageAbbr(m_req->m_prefferedResultLangId), m_firstUrl);
|
||||
if (!summary.empty()) {
|
||||
m_summaryValid = true;
|
||||
m_summary.setSummary(summary);
|
||||
return &m_summary;
|
||||
}
|
||||
}
|
||||
|
||||
// time cpu set time
|
||||
m_cpuSummaryStartTime = gettimeofdayInMilliseconds();
|
||||
|
||||
|
41
adultphrases.txt.example
Normal file
41
adultphrases.txt.example
Normal file
@ -0,0 +1,41 @@
|
||||
#
|
||||
# Format:
|
||||
#
|
||||
# language | phrase | score
|
||||
#
|
||||
# Language is currently unused. Even though a word must have a language specified, it may
|
||||
# be used in other languages as well.
|
||||
#
|
||||
# Score based on "would you want your 10 year old daughter to see and read this content?".
|
||||
#
|
||||
# scores
|
||||
# 1 as single term, the word can be considered OK in some situations (like "rape" in "rape conviction rate")
|
||||
# 5 likely adult content
|
||||
# 10 very likely adult content
|
||||
# 20 almost certainly adult content
|
||||
# 99 certainly adult content
|
||||
# 666 likely illegal content
|
||||
#
|
||||
# 5 matches or a score over 30 should be a clear adult content indicator. Phrase matches will use other,
|
||||
# higher scores.
|
||||
#
|
||||
# CAREFUL: "as seating" and "ass eating" results in the same term id...
|
||||
#
|
||||
#
|
||||
en|pussy gallery|99
|
||||
en|pussy galleries|99
|
||||
en|cumshot compilation|99
|
||||
en|teen porn|99
|
||||
en|sadomaso online|99
|
||||
en|bbw cams|99
|
||||
en|bbw porn|99
|
||||
en|bbw strippers|99
|
||||
en|bbw videos|99
|
||||
en|biggest cocks|20
|
||||
en|biggest cock|20
|
||||
en|biggest dicks|20
|
||||
en|biggest dick|20
|
||||
en|biggest tits|20
|
||||
#
|
||||
# .. etc. Filling this in is left as an exercise for the reader.
|
||||
#
|
39
adultwords.txt.example
Normal file
39
adultwords.txt.example
Normal file
@ -0,0 +1,39 @@
|
||||
#
|
||||
# language | word | score
|
||||
#
|
||||
# Language is currently unused. Even though a word must have a language specified, it may
|
||||
# be used in other languages as well.
|
||||
#
|
||||
# Score based on "would you want your 10 year old daughter to see and read this content?".
|
||||
#
|
||||
# scores
|
||||
# 1 as single term, the word can be considered OK in some situations (like "rape" in "rape conviction rate")
|
||||
# 5 likely adult content
|
||||
# 10 very likely adult content
|
||||
# 20 almost certainly adult content
|
||||
#
|
||||
# 5 matches or a score over 30 should be a clear adult content indicator. Phrase matches will use higher scores.
|
||||
#
|
||||
en|redtube|10
|
||||
en|porntube|20
|
||||
en|twats|5
|
||||
en|pantyhose|1
|
||||
en|3some|5
|
||||
en|4some|5
|
||||
en|analdildo|20
|
||||
en|anal|1
|
||||
en|assfucking|20
|
||||
en|assfuck|20
|
||||
en|bangbros|20
|
||||
en|banging|5
|
||||
en|bbw|20
|
||||
en|bdsm|2
|
||||
en|blowjobs|20
|
||||
en|blowjobx|20
|
||||
en|blowjob|20
|
||||
en|bondage|5
|
||||
en|boners|1
|
||||
en|boner|1
|
||||
#
|
||||
# .. etc. Filling this in is left as an exercise for the reader.
|
||||
#
|
188
main.cpp
188
main.cpp
@ -91,6 +91,9 @@
|
||||
#include "SpiderdbHostDelete.h"
|
||||
#include "ConvertSpiderdb.h"
|
||||
#include "RobotsBlockedResultOverride.h"
|
||||
#include "UrlResultOverride.h"
|
||||
#include "FxAdultCheck.h"
|
||||
|
||||
#include <sys/stat.h> //umask()
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
@ -123,6 +126,8 @@ static void dumpLinkdb(const char *coll, int32_t sfn, int32_t numFiles, bool inc
|
||||
|
||||
static void dumpUnwantedTitledbRecs(const char *coll, int32_t startFileNum, int32_t numFiles, bool includeTree);
|
||||
static void dumpWantedTitledbRecs(const char *coll, int32_t startFileNum, int32_t numFiles, bool includeTree);
|
||||
static void dumpAdultTitledbRecs(const char *coll, int32_t startFileNum, int32_t numFiles, bool includeTree);
|
||||
|
||||
//static void dumpUnwantedSpiderdbRecs(const char *coll, int32_t startFileNum, int32_t numFiles, bool includeTree);
|
||||
//
|
||||
//static int32_t verifySpiderdb(const char *coll, int32_t startFileNum, int32_t numFiles, bool includeTree, int32_t firstIp);
|
||||
@ -1340,8 +1345,10 @@ int main2 ( int argc , char *argv[] ) {
|
||||
dumpUnwantedTitledbRecs(coll, startFileNum, numFiles, includeTree);
|
||||
} else if (strcmp(argv[cmdarg+1], "wt") == 0) {
|
||||
dumpWantedTitledbRecs(coll, startFileNum, numFiles, includeTree);
|
||||
// } else if (strcmp(argv[cmdarg+1], "us") == 0) {
|
||||
// dumpUnwantedSpiderdbRecs(coll, startFileNum, numFiles, includeTree);
|
||||
} else if (strcmp(argv[cmdarg+1], "at") == 0) {
|
||||
dumpAdultTitledbRecs(coll, startFileNum, numFiles, includeTree);
|
||||
// } else if (strcmp(argv[cmdarg+1], "us") == 0) {
|
||||
// dumpUnwantedSpiderdbRecs(coll, startFileNum, numFiles, includeTree);
|
||||
} else {
|
||||
goto printHelp;
|
||||
}
|
||||
@ -1635,6 +1642,10 @@ int main2 ( int argc , char *argv[] ) {
|
||||
g_robotsCheckList.init();
|
||||
|
||||
g_robotsBlockedResultOverride.init();
|
||||
g_urlResultOverride.init();
|
||||
|
||||
// Initialize adult detection
|
||||
g_adultCheckList.init();
|
||||
|
||||
// initialize generate global index thread
|
||||
if (!RdbBase::initializeGlobalIndexThread()) {
|
||||
@ -3883,6 +3894,179 @@ static void dumpWantedTitledbRecs(const char *coll, int32_t startFileNum, int32_
|
||||
}
|
||||
|
||||
|
||||
static void dumpAdultTitledbRecs(const char *coll, int32_t startFileNum, int32_t numFiles, bool includeTree) {
|
||||
if(startFileNum!=0 && numFiles<0) {
|
||||
//this may apply to all files, but I haven't checked into hash-based ones yet
|
||||
fprintf(stderr,"If <startFileNum> is specified then <numFiles> must be too\n");
|
||||
return;
|
||||
}
|
||||
if (!ucInit(g_hostdb.m_dir)) {
|
||||
log("Unicode initialization failed!");
|
||||
return;
|
||||
}
|
||||
// init our table for doing zobrist hashing
|
||||
if ( ! hashinit() ) {
|
||||
log("db: Failed to init hashtable." );
|
||||
return;
|
||||
}
|
||||
|
||||
g_titledb.init ();
|
||||
g_titledb.getRdb()->addRdbBase1(coll);
|
||||
key96_t startKey ;
|
||||
key96_t endKey ;
|
||||
key96_t lastKey ;
|
||||
startKey.setMin();
|
||||
endKey.setMax();
|
||||
lastKey.setMin();
|
||||
startKey = Titledb::makeFirstKey(0);
|
||||
Msg5 msg5;
|
||||
RdbList list;
|
||||
|
||||
// make this
|
||||
XmlDoc *xd;
|
||||
try {
|
||||
xd = new (XmlDoc);
|
||||
}
|
||||
catch(std::bad_alloc&) {
|
||||
fprintf(stdout,"could not alloc for xmldoc\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
const CollectionRec *cr = g_collectiondb.getRec(coll);
|
||||
if(cr==NULL) {
|
||||
fprintf(stderr,"Unknown collection '%s'\n", coll);
|
||||
return;
|
||||
}
|
||||
|
||||
// initialize shlib & blacklist
|
||||
if (!WantedChecker::initialize()) {
|
||||
fprintf(stderr, "Unable to initialize WantedChecker");
|
||||
return;
|
||||
}
|
||||
g_urlBlackList.init();
|
||||
g_urlWhiteList.init();
|
||||
|
||||
g_adultCheckList.init();
|
||||
|
||||
for(;;) {
|
||||
// use msg5 to get the list, should ALWAYS block since no threads
|
||||
if ( ! msg5.getList ( RDB_TITLEDB ,
|
||||
cr->m_collnum ,
|
||||
&list ,
|
||||
&startKey ,
|
||||
&endKey ,
|
||||
commandLineDumpdbRecSize,
|
||||
includeTree ,
|
||||
startFileNum ,
|
||||
numFiles ,
|
||||
NULL , // state
|
||||
NULL , // callback
|
||||
0 , // niceness
|
||||
false , // err correction?
|
||||
-1 , // maxRetries
|
||||
false)) // isRealMerge
|
||||
{
|
||||
log(LOG_LOGIC,"db: getList did not block.");
|
||||
return;
|
||||
}
|
||||
// all done if empty
|
||||
if ( list.isEmpty() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// loop over entries in list
|
||||
for(list.resetListPtr(); !list.isExhausted(); list.skipCurrentRecord()) {
|
||||
key96_t k = list.getCurrentKey();
|
||||
char *rec = list.getCurrentRec();
|
||||
int32_t recSize = list.getCurrentRecSize();
|
||||
int64_t docId = Titledb::getDocIdFromKey(&k);
|
||||
|
||||
if ( k <= lastKey ) {
|
||||
log("key out of order. lastKey.n1=%" PRIx32" n0=%" PRIx64" currKey.n1=%" PRIx32" n0=%" PRIx64" ",
|
||||
lastKey.n1, lastKey.n0, k.n1, k.n0);
|
||||
}
|
||||
|
||||
lastKey = k;
|
||||
|
||||
if ( (k.n0 & 0x01) == 0) {
|
||||
// delete key
|
||||
continue;
|
||||
}
|
||||
|
||||
// free the mem
|
||||
xd->reset();
|
||||
|
||||
// uncompress the title rec
|
||||
if ( ! xd->set2 ( rec , recSize , coll ,NULL , 0 ) ) {
|
||||
//set2() may have logged something but not the docid
|
||||
log(LOG_WARN, "dbdump: XmlDoc::set2() failed for docid %" PRId64, docId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// extract the url
|
||||
Url *url = xd->getFirstUrl();
|
||||
if( url == (void *)-1 ) {
|
||||
log(LOG_WARN, "dbdump: XmlDoc::getFirstUrl() failed for docid %" PRId64, docId);
|
||||
continue;
|
||||
}
|
||||
|
||||
const char *reason = NULL;
|
||||
|
||||
// Don't dump unwanted URLs
|
||||
if( ! isUrlUnwanted(*url, &reason)) {
|
||||
Url **redirUrlPtr = xd->getRedirUrl();
|
||||
if (redirUrlPtr && *redirUrlPtr) {
|
||||
Url *redirUrl = *redirUrlPtr;
|
||||
if (isUrlUnwanted(*redirUrl, &reason)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Get adult flag including generating debug info.
|
||||
// Could just call xd->getIsAdult() to get the simple indicator
|
||||
// without debug information.
|
||||
AdultCheck achk(xd, true);
|
||||
bool newblocked = achk.isDocAdult();
|
||||
|
||||
|
||||
// Sanity check.
|
||||
bool gbadult = false;
|
||||
char *adultbit = xd->getIsAdult();
|
||||
if( adultbit ) {
|
||||
if( *adultbit != newblocked ) {
|
||||
// Mismatch - should never happen
|
||||
log(LOG_ERROR, "Adult check mismatch! docid=%" PRId64 ", url=%s, gbadult=%s, score=%" PRId32 ", newblock=%s",
|
||||
docId, url->getUrl(), gbadult?"true":"false", achk.getScore(), newblocked?"true":"false");
|
||||
gbshutdownLogicError();
|
||||
}
|
||||
}
|
||||
|
||||
if( newblocked ) {
|
||||
time_t idxtim = (time_t)xd->getIndexedTime();
|
||||
struct tm tm_buf;
|
||||
tm *tm1 = gmtime_r(&idxtim,&tm_buf);
|
||||
char idxtim_s[64];
|
||||
strftime(idxtim_s,64,"%Y%m%d-%H%M%S",tm1);
|
||||
|
||||
fprintf(stdout, "%" PRId64 "\t%s\t%s\t%s\tscore=%" PRId32 "\tunique dw=%" PRId32 "\tunique dp=%" PRId32 "\twords=%" PRId32 "\t%s\t%s\n",
|
||||
docId, url->getUrl(), idxtim_s, achk.getReason(),
|
||||
achk.getScore(), achk.getNumUniqueDirtyWords(), achk.getNumUniqueDirtyPhrases(),
|
||||
achk.getNumWordsChecked(), achk.hasEmptyDocumentBody()?"EMPTYDOC":"HASCONTENT", achk.getDebugInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
startKey = *(key96_t *)list.getLastKey();
|
||||
startKey++;
|
||||
|
||||
// watch out for wrap around
|
||||
if ( startKey < *(key96_t *)list.getLastKey() ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if 0
|
||||
static void dumpUnwantedSpiderdbRecs(const char *coll, int32_t startFileNum, int32_t numFiles, bool includeTree) {
|
||||
|
1
urlresultoverride.txt.example
Normal file
1
urlresultoverride.txt.example
Normal file
@ -0,0 +1 @@
|
||||
http://www.example.com/|en|Example Domain|This domain is established to be used for illustrative examples in documents. You may use this domain in examples without prior coordination or asking for permission.
|
Reference in New Issue
Block a user