Exemplo n.º 1
0
  void checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate)
  {
    using namespace base;
    using namespace net;

    std::string url = UPDATE_URL;
    if (!uuid.empty()) {
      url += "&uuid=";
      url += uuid;
    }
    if (!extraParams.empty()) {
      url += "&";
      url += extraParams;
    }

    HttpRequest request(url);
    HttpHeaders headers;
    headers.setHeader("User-Agent", getUserAgent());
    request.setHeaders(headers);

    std::stringstream body;
    HttpResponse response(&body);
    request.send(response);

    CheckUpdateResponse data(body.str());
    delegate->onResponse(data);
  }
Exemplo n.º 2
0
  void checkNewVersion(const Uuid& uuid, const std::string& extraParams, CheckUpdateDelegate* delegate)
  {
    using namespace base;
    using namespace net;

#ifndef UPDATE_URL
#define UPDATE_URL ""
#endif
#pragma message("warning: Define UPDATE_URL macro")

    std::string url = UPDATE_URL;
    if (!uuid.empty()) {
      url += "&uuid=";
      url += uuid;
    }
    if (!extraParams.empty()) {
      url += "&";
      url += extraParams;
    }

    HttpRequest request(url);
    HttpHeaders headers;
    headers.setHeader("User-Agent", getUserAgent());
    request.setHeaders(headers);

    std::stringstream body;
    HttpResponse response(&body);
    request.send(response);

    TRACE("Checking updates: %s (User-Agent: %s)\n", url.c_str(), getUserAgent().c_str());
    TRACE("Response:\n--\n%s--\n", body.str().c_str());

    CheckUpdateResponse data(body.str());
    delegate->onResponse(data);
  }
Exemplo n.º 3
0
Response* FakeConnection::getDocument(const std::string& uri) {
  TIMED_FUNC(FakeConnection_getDocument);
  LOG(DEBUG) << "  Entering FakeConnection::getDocument";

  LOG(DEBUG) << "    Fetching document with URI: " << uri;
  std::map<std::string,IDocumentContent*>::iterator it;
  it = mImpl->documents.find(uri);
  std::string ct("");
  std::string mime("");
  if (mImpl->documents.end() != it) {
    LOG(DEBUG) << "    Found document with URI: " << uri;
    IDocumentContent* docPtr = it->second;
    ct = docPtr->getContent();
    mime = docPtr->getMimeType();
  }
  //IDocumentContent& value = mImpl->documents[uri.c_str()];

  //LOG(DEBUG) << "    pointer value: " << value;

  Response* response = new Response;
  LOG(DEBUG) << "  Setting response code";


  LOG(DEBUG) << "  Setting response content ptr";
  //std::unique_ptr<std::string> content(new std::string(ct));
  //response->setContent(std::move(content));
  response->setContent(new std::string(ct));
  LOG(DEBUG) << "  Setting response headers";
  if (0 == ct.compare("")) {
    // not found
    response->setResponseCode(ResponseCode::NOT_FOUND);
    response->setResponseType(ResponseType::UNKNOWN_TYPE);
  } else {
    // found
    HttpHeaders headers;
    headers.setHeader("Content-type",mime);
    response->setResponseHeaders(headers);
    response->setResponseCode(ResponseCode::OK);
    if (0 == mime.compare("application/json")) {
      response->setResponseType(ResponseType::JSON);
    } else if (0 == mime.compare("application/xml") ) {
      response->setResponseType(ResponseType::XML);
    } else if (0 == mime.compare("text/plain")) {
      response->setResponseType(ResponseType::TEXT);
    } else {
      response->setResponseType(ResponseType::BINARY);
    }
  }

  LOG(DEBUG) << "  returning response ";
  return response;
}
Exemplo n.º 4
0
Response* FakeConnection::search(const SearchDescription& desc) {
  TIMED_FUNC(FakeConnection_search);
  LOG(DEBUG) << "  Entering FakeConnection::search";

  Response* response = new Response;

  response->setResponseCode(ResponseCode::OK);
  HttpHeaders headers;
  headers.setHeader("Content-type","application/json");
  response->setResponseHeaders(headers);
  std::ostringstream cos;
  cos <<
      "{\"response\": {" <<
        "\"start\": 1, \"page-length\": ";

  // return 10 or documents.length, whichever is smaller
  if (mImpl->documents.size() < 10) {
    cos << mImpl->documents.size();
  } else {
    cos << 10;
  }
  cos << ", \"results\": [";

  // loop over documents in map
  std::map<std::string,IDocumentContent*>::iterator it;
  int count = 0;
  for (it = mImpl->documents.begin();it != mImpl->documents.end() && count < 10;++it) {
    ++count; // iterate first as MarkLogic responses are 1 indexed, not 0 indexed
    if (count > 1) {
      cos << ",";
    }
    cos << "{\"index\": " << count << " , \"uri\": \"" << (it->first)
        << "\", \"score\": \"43648\" \"confidence\":\"0.418356\" \"fitness\":\"0.50947\"}";
  }

  cos << "] } }";
  //std::unique_ptr<std::string> cPtr(new std::string(cos.str()));
  //response->setContent(std::move(cPtr));
  response->setContent(new std::string(cos.str()));
  response->setResponseType(ResponseType::JSON);

  return response;
}