34
static URL CreateURL(std::string service, int entryPerMessage, int skipOffset) {
35
std::string::size_type pos1 = service.find("://");
36
if (pos1 == std::string::npos) {
37
service = "http://" + service;
38
pos1 = service.find("://");
40
std::string proto = lower(service.substr(0,pos1));
41
if((proto != "http") && (proto != "https")) return URL();
44
* URL structure and response format:
45
* * in JSON: http[s]://<host_name>:<port>/services?limit=<nr_of_entries_per_message>[&skip=<offset>]
47
* * in XML: http[s]://<host_name>:<port>/services/query.xml?limit=<nr_of_entries_per_message>[&skip=<offset>]
49
std::string::size_type pos2 = service.find(":", pos1 + 3);
50
std::string::size_type pos3 = service.find("/", pos1 + 3);
51
if (pos2 == std::string::npos && pos3 == std::string::npos) {
52
service += ":9126"; // Default port seems to be 9126.
54
if (pos3 == std::string::npos || pos3 == service.size()-1) {
55
service += "/services/query.xml";
57
URL serviceURL(service);
59
if (entryPerMessage > 0) serviceURL.AddHTTPOption("limit", tostring(entryPerMessage));
60
if (skipOffset > 0) serviceURL.AddHTTPOption("skip", tostring(skipOffset));
64
34
EndpointQueryingStatus ServiceEndpointRetrieverPluginEMIR::Query(const UserConfig& uc,
65
35
const Endpoint& rEndpoint,
66
36
std::list<Endpoint>& seList,
72
42
uc.ApplyToConfig(cfg);
44
if (isEndpointNotSupported(rEndpoint)) {
45
return EndpointQueryingStatus::FAILED;
47
URL url((rEndpoint.URLString.find("://") == std::string::npos ? "http://" : "") + rEndpoint.URLString, false, 9126, "/services/query.xml");
49
s = EndpointQueryingStatus::FAILED;
74
53
// Limitation: Max number of services the below loop will fetch, according to parameters:
75
54
// ServiceEndpointRetrieverPluginEMIR::maxEntries * 100 = 500.000 (currently)
76
55
for (int iAvoidInfiniteLoop = 0; iAvoidInfiniteLoop < 100; ++iAvoidInfiniteLoop) {
77
URL url(CreateURL(rEndpoint.URLString, maxEntries, currentSkip));
79
s = EndpointQueryingStatus::FAILED;
56
if (maxEntries > 0) url.AddHTTPOption("limit", tostring(maxEntries), true);
57
if (currentSkip > 0) url.AddHTTPOption("skip", tostring(currentSkip), true);
82
59
// increment the starting point of the fetched DB
83
60
currentSkip += maxEntries;