#include <iostream> #include <cstring> #include <vector> #include "../utils.cpp" // use this line to compile // g++ -I. -fPIC -shared -g -o nasa.gov.so nasa.gov.cpp // regex // http.*\.nasa\.gov.*(\.swf|\.jpg|\.png|\.mp4|\.flv) string get_filename(string url) { vector<string> resultado; if (url.find("?") != string::npos) { stringexplode(url, "?", &resultado); stringexplode(resultado.at(resultado.size()-2), "/", &resultado); return resultado.at(resultado.size()-1); } else { stringexplode(url, "/", &resultado); return resultado.at(resultado.size()-1); } } extern "C" resposta getmatch(const string url) { resposta r; if ( (url.find(".nasa.gov") != string::npos) ) { r.file = get_filename(url); if (!r.file.empty()) { r.match = true; r.domain = "NasaSitio"; } else { r.match = false; } } else { r.match = false; } return r; } |
#include <iostream>
#include <cstring>
#include <vector>
#include "../utils.cpp"
// use this line to compile
// g++ -I. -fPIC -shared -g -o nasa.gov.so nasa.gov.cpp
// regex
// http.*\.nasa\.gov.*(\.swf|\.jpg|\.png|\.mp4|\.flv)
string get_filename(string url) {
vector<string> resultado;
if (url.find("?") != string::npos) {
stringexplode(url, "?", &resultado);
stringexplode(resultado.at(resultado.size()-2), "/", &resultado);
return resultado.at(resultado.size()-3)+"_"+resultado.at(resultado.size()-2)+"_"+resultado.at(resultado.size()-1);
} else {
stringexplode(url, "/", &resultado);
return resultado.at(resultado.size()-3)+"_"+resultado.at(resultado.size()-2)+"_"+resultado.at(resultado.size()-1);
}
}
extern "C" resposta getmatch(const string url) {
resposta r;
if ( (url.find(".nasa.gov/") != string::npos)
) {
r.file = get_filename(url);
if (!r.file.empty()) {
r.match = true;
r.domain = "Nasa";
} else {
r.match = false;
}
} else {
r.match = false;
}
return r;
}