Beispiel #1
0
bool WiFiNode::scan() {
	if (!wpaCtrl) {
		DBGMSG_ERR("iface is closed");
		return false;
	}
	char reply[1024] = {0};
	size_t replyLen = sizeof(reply) - 1;

	int res = makeRequest("SCAN", reply, &replyLen);
	if (res || !strstr(reply, "OK")) {
		DBGMSG_ERR("Failed to start scanning [%d]", res);
		return false;
	}
	if (waitFor(WPA_EVENT_SCAN_RESULTS, 5000)) {
		DBGMSG_ERR("scanning failed");
		return false;
	}

	replyLen = sizeof(reply) - 1;
	res = makeRequest("SCAN_RESULTS", reply, &replyLen);
	if (res) {
		DBGMSG_ERR("Failed to get scanning results [%d]", res);
		return false;
	}

//	TODO: parse scan result here

	return true;
}
Beispiel #2
0
void WiFiNode::removeAllNetworks() {
	if (!wpaCtrl) {
		DBGMSG_ERR("iface is closed");
		return;
	}
	char reply[1024] = {0};
	size_t replyLen = sizeof(reply) - 1;
	int reqRes = makeRequest("LIST_NETWORKS", reply, &replyLen);
	if (reqRes) {
		DBGMSG_ERR("Failed to list networks [%d]", reqRes);
	} else {
		int linesCount = 0;
		char *ptr = reply;
		bool active = strstr(reply, "CURRENT");
		while (ptr && (ptr = strstr(ptr+1, "\n"))) {
			linesCount++;
		}
		DBGMSG_M("Found [%d] networks", linesCount-1);
		if (linesCount > 1) {
			reqRes = makeRequest("REMOVE_NETWORK ALL", reply, &replyLen);
			if (active) {
				waitFor(WPA_EVENT_DISCONNECTED, 1000);
			}
		}
	}
}
/**
 * Get folder details. If no folder given then default folder returned.
 */
FoldersReply* ElisaNetworkService::folderListing(const QString& folderId, const QString& destination)
{
    if(!destination.isEmpty()){        
        return new FoldersReply(makeRequest(QString(FOLDERS_LIST_POS).arg(folderId).arg(destination)));
    }
    else{
        return new FoldersReply(makeRequest(QString(FOLDERS_LIST).arg(folderId)));
    }
}
int LsHelper::loadChecks(const QString& hostgroupFilter, ChecksT& checks)
{
  checks.clear();

  if (makeRequest(prepareRequestData(hostgroupFilter, LsHelper::Host), checks) != 0)
    return -1;

  return makeRequest(prepareRequestData(hostgroupFilter, LsHelper::Service), checks);
}
Beispiel #5
0
bool WiFiNode::conect(const char *ssid, const char *psk) {
	if (!wpaCtrl) {
		DBGMSG_ERR("iface is closed");
		return false;
	}
	if (!ssid || !psk) {
		DBGMSG_ERR("Credential is Null");
		return false;
	}
//	removeAllNetworks();
	char reply[1024] = {0};
	size_t replyLen = sizeof(reply) - 1;
	int reqRes = makeRequest("ADD_NETWORK", reply, &replyLen);
	if (reqRes) {
		DBGMSG_ERR("Failed to add network [%d]", reqRes);
		return false;
	}
	char *tmp;
	int networkId = strtol(reply, &tmp, 10);
	DBGMSG_M("New Network id is [%d]", networkId);

	char requestBuffer[1024];
	const size_t requestBufferSize = sizeof(requestBuffer) - 1;

	snprintf(requestBuffer, requestBufferSize, "SET_NETWORK %d ssid \"%s\"", networkId, ssid);
	reqRes = makeRequest(requestBuffer, reply, &replyLen);
	if (reqRes || !strstr(reply, "OK")) {
		DBGMSG_ERR("Failed to set ssid [%d]", reqRes);
		return false;
	}

	snprintf(requestBuffer, requestBufferSize, "SET_NETWORK %d psk \"%s\"", networkId, psk);
	reqRes = makeRequest(requestBuffer, reply, &replyLen);
	if (reqRes || !strstr(reply, "OK")) {
		DBGMSG_ERR("Failed to set psk [%d]", reqRes);
		return false;
	}

	snprintf(requestBuffer, requestBufferSize, "ENABLE_NETWORK %d", networkId);
	reqRes = makeRequest(requestBuffer, reply, &replyLen);
	if (reqRes || !strstr(reply, "OK")) {
		DBGMSG_ERR("Failed to enable network %d [%d]", networkId, reqRes);
		return false;
	}

	if (waitFor(WPA_EVENT_CONNECTED, 15000)) {
		DBGMSG_ERR("Connection Failed");
		return false;
	}
	DBGMSG_H("Connected to <%s>", ssid);
	int obt = obtainIp();
	DBGMSG_H("obtain ip  <%d>", obt);

	return true;
}
Beispiel #6
0
bool AWebservice::getUserList (const QString& last_row_version, AUserInfoList& list, QString& row_version)
{
	QString data;
	data += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
	data += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
	data += "  <soap:Body>\r\n";
	data += "    <GetNewUsers xmlns=\"http://rsdn.ru/Janus/\">\r\n";
	data += "      <userRequest>\r\n";
	data += (QString)"        <userName>"       + m_rsdn_login     + "</userName>\r\n";
	data += (QString)"        <password>"       + m_rsdn_password  + "</password>\r\n";
	data += (QString)"        <lastRowVersion>" + last_row_version + "</lastRowVersion>\r\n";
	data += "        <maxOutput>0</maxOutput>\r\n";
	data += "      </userRequest>\r\n";
	data += "    </GetNewUsers>\r\n";
	data += "  </soap:Body>\r\n";
	data += "</soap:Envelope>\r\n";

	QNetworkRequest request;
	prepareRequest(request, m_rsdn_proto, "GetNewUsers", data.toUtf8().size());

	if (makeRequest(request, data) == false)
		return false;

	QString result = parseUserList(m_body, list, row_version);
	if (result.length() > 0)
	{
		m_error = result;
		return false;
	}

	return true;
}
Beispiel #7
0
bool AWebservice::getForumList (AForumGroupInfoList& list)
{
	QString data;
	data += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
	data += "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\r\n";
	data += "  <soap:Body>\r\n";
	data += "    <GetForumList xmlns=\"http://rsdn.ru/Janus/\">\r\n";
	data += "      <forumRequest>\r\n";
	data += (QString)"        <userName>" + m_rsdn_login    + "</userName>\r\n";
	data += (QString)"        <password>" + m_rsdn_password + "</password>\r\n";
	data += "        <forumsRowVersion>AAAAAAAAAAA=</forumsRowVersion>\r\n";
	data += "      </forumRequest>\r\n";
	data += "    </GetForumList>\r\n";
	data += "  </soap:Body>\r\n";
	data += "</soap:Envelope>\r\n";

	QNetworkRequest request;
	prepareRequest(request, m_rsdn_proto, "GetForumList", data.toUtf8().size());

	if (makeRequest(request, data) == false)
		return false;

	parseForumList(m_body, list);

	return true;
}
Beispiel #8
0
FileClient::FileClient(int gnutella_sockfd, int file_sockfd, string localpath, string filename, int index) {
	// store
	this->gnutella_sockfd = gnutella_sockfd;
	this->file_sockfd = file_sockfd;
	this->localpath = localpath;
	this->filename = filename;
	this->index = index;

	// fork
	this->child = fork();
	if (child < 0) { // could not fork on this socket
		return;
	} else if (child > 0) { // parent
		return;
	}

	// child
	printf("Hello from Child, socket constructor\n");

	// download
	if (! makeRequest(constructRequest())) {
		fprintf(stderr, "Failed to send request\n");
		exit(EXIT_FAILURE);
	}
	download();

	exit(EXIT_SUCCESS);
}
bool P2pNode::fetchPeerList(ContextPtr connection) {
  try {
    COMMAND_HANDSHAKE::request request{ getNodeData(), getGenesisPayload() };
    COMMAND_HANDSHAKE::response response;

    OperationTimeout<P2pContext> timeout(m_dispatcher, *connection, m_cfg.getHandshakeTimeout());

    connection->writeMessage(makeRequest(COMMAND_HANDSHAKE::ID, LevinProtocol::encode(request)));

    LevinProtocol::Command cmd;
    if (!connection->readCommand(cmd)) {
      throw std::runtime_error("Connection closed unexpectedly");
    }

    if (!cmd.isResponse || cmd.command != COMMAND_HANDSHAKE::ID) {
      throw std::runtime_error("Received unexpected reply");
    }

    if (!LevinProtocol::decode(cmd.buf, response)) {
      throw std::runtime_error("Invalid reply format");
    }

    if (response.node_data.network_id != request.node_data.network_id) {
      logger(ERROR) << *connection << "COMMAND_HANDSHAKE failed, wrong network: " << response.node_data.network_id;
      return false;
    }

    return handleRemotePeerList(response.local_peerlist, response.node_data.local_time);
  } catch (std::exception& e) {
    logger(INFO) << *connection << "Failed to obtain peer list: " << e.what();
  }

  return false;
}
Beispiel #10
0
Response Session::Impl::Put() {
    auto curl = curl_->handle;
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_NOBODY, 0L);
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
    }

    return makeRequest(curl);
}
Beispiel #11
0
Response Session::Impl::Head() {
    auto curl = curl_->handle;
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_HTTPGET, 0L);
        curl_easy_setopt(curl, CURLOPT_POST, 0L);
        curl_easy_setopt(curl, CURLOPT_NOBODY, 1L);
    }

    return makeRequest(curl);
}
Beispiel #12
0
Response Session::Impl::Options() {
    auto curl = curl_->handle;
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_HTTPGET, 0L);
        curl_easy_setopt(curl, CURLOPT_POST, 0L);
        curl_easy_setopt(curl, CURLOPT_NOBODY, 0L);
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "OPTIONS");
    }

    return makeRequest(curl);
}
Beispiel #13
0
NetworkProgram::NetworkProgram(ScriptCache* cache, const QUrl& url) :
    _cache(cache),
    _request(url),
    _reply(NULL),
    _attempts(0) {
    
    if (!url.isValid()) {
        return;
    }
    _request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
    makeRequest();
}
	void HTTPServiceTestObject::test<8>()
	{
		// test the OPTIONS http method -- the default implementation
		// should return the X-Documentation-URL
		std::ostringstream http_request;
		http_request << "OPTIONS /  HTTP/1.0\r\nHost: localhost\r\n\r\n";
		bool timeout = false;
		std::string result = makeRequest("/", http_request.str(), timeout);
		ensure_starts_with("OPTIONS verb ok", result, "HTTP/1.0 200 OK\r\n");
		ensure_contains(
			"Doc url header exists",
			result,
			"X-Documentation-URL: http://localhost");
	}
		std::string httpPOST(const std::string& uri,
			const std::string& body,
			bool timeout,
			const std::string& evilExtra = "")
		{
			std::ostringstream httpRequest;
			httpRequest << "POST " + uri + " HTTP/1.0\r\n";
			httpRequest << "Content-Length: " << body.size() << "\r\n";
			httpRequest << "\r\n";
			httpRequest << body;
			httpRequest << evilExtra;
				
			return makeRequest(uri, httpRequest.str(), timeout);
		}
Beispiel #16
0
void NetworkProgram::handleReplyError() {
    QDebug debug = qDebug() << _reply->errorString();
    
    _reply->disconnect(this);
    _reply->deleteLater();
    _reply = NULL;
    
    // retry with increasing delays
    const int MAX_ATTEMPTS = 8;
    const int BASE_DELAY_MS = 1000;
    if (++_attempts < MAX_ATTEMPTS) {
        QTimer::singleShot(BASE_DELAY_MS * (int)pow(2.0, _attempts), this, SLOT(makeRequest()));
        debug << " -- retrying...";
    }
}
void OneDriveListDirectoryRequest::listNextDirectory() {
	if (_directoriesQueue.empty()) {
		finishListing(_files);
		return;
	}

	_currentDirectory = _directoriesQueue.back();
	_directoriesQueue.pop_back();

	if (_currentDirectory != "" && _currentDirectory.lastChar() != '/' && _currentDirectory.lastChar() != '\\')
		_currentDirectory += '/';

	Common::String dir = _currentDirectory;
	dir.deleteLastChar();
	Common::String url = Common::String::format(ONEDRIVE_API_SPECIAL_APPROOT_CHILDREN, ConnMan.urlEncode(dir).c_str());
	makeRequest(url);
}
void P2pConnectionProxy::writeHandshake(const P2pMessage &message) {
  CORE_SYNC_DATA coreSync;
  LevinProtocol::decode(message.data, coreSync);

  if (m_context.isIncoming()) {
    // response
    COMMAND_HANDSHAKE::response res;
    res.node_data = m_node.getNodeData();
    res.payload_data = coreSync;
    res.local_peerlist = m_node.getLocalPeerList();
    m_context.writeMessage(makeReply(COMMAND_HANDSHAKE::ID, LevinProtocol::encode(res), LEVIN_PROTOCOL_RETCODE_SUCCESS));
    m_node.tryPing(m_context);
  } else {
    // request
    COMMAND_HANDSHAKE::request req;
    req.node_data = m_node.getNodeData();
    req.payload_data = coreSync;
    m_context.writeMessage(makeRequest(COMMAND_HANDSHAKE::ID, LevinProtocol::encode(req)));
  }
}
Beispiel #19
0
void
ConnectAttempt::onHandshake (error_code ec)
{
    cancelTimer();
    if(! stream_.next_layer().is_open())
        return;
    if(ec == boost::asio::error::operation_aborted)
        return;
    endpoint_type local_endpoint;
    if (! ec)
        local_endpoint = stream_.next_layer().local_endpoint(ec);
    if(ec)
        return fail("onHandshake", ec);
    JLOG(journal_.trace()) <<
        "onHandshake";

    if (! overlay_.peerFinder().onConnected (slot_,
            beast::IPAddressConversion::from_asio (local_endpoint)))
        return fail("Duplicate connection");

    auto sharedValue = makeSharedValue(
        stream_.native_handle(), journal_);
    if (! sharedValue)
        return close(); // makeSharedValue logs

    req_ = makeRequest(! overlay_.peerFinder().config().peerPrivate,
        remote_endpoint_.address());
    auto const hello = buildHello (
        *sharedValue,
        overlay_.setup().public_ip,
        beast::IPAddressConversion::from_asio(remote_endpoint_),
        app_);
    appendHello (req_, hello);

    setTimer();
    boost::beast::http::async_write(stream_, req_,
        strand_.wrap (std::bind (&ConnectAttempt::onWrite,
            shared_from_this(), std::placeholders::_1)));
}
std::string KartinaTVClient::requestStreamUrl(const PVR_CHANNEL &channel)
{
    XBMC->Log(ADDON::LOG_DEBUG, "void KartinaTVClient::requestStreamUrl()");

    bool isProtected = false;
    for (const auto &c: channelsCache) {
        if (c.id == channel.iUniqueId && c.isProtected)
            isProtected = true;
    }
    PostFields parameters;
    parameters.insert(std::make_pair("cid", std::to_string(channel.iUniqueId)));
    if (isProtected)
        parameters.insert(std::make_pair("protect_code", protectCode));

    std::string reply = makeRequest("get_url", parameters);
    XBMC->Log(ADDON::LOG_DEBUG, KTV_FUNC_INFO ": data: %s", reply.c_str());

    KTVError ktvError;
    if (reply.size() != 0 && (ktvError = checkForError(reply)).code == 0) {
        Json::Reader json;
        Json::Value root;
        json.parse(reply, root);
        const char *urlData = root["url"].asCString();

        std::vector<std::string> urlParams;
        std::stringstream stream(urlData);
        std::string param;
        while (stream >> param) {
            XBMC->Log(ADDON::LOG_DEBUG, "Extracted: %d %s", urlParams.size(), param.data());
            urlParams.push_back(param);
        }

        std::string url = urlParams.front();
        // http/ts
        url = url.replace(0, 7, "http");

        return url;
    } else {
Beispiel #21
0
FileClient::FileClient(int gnutella_sockfd, string hostname, int port, string localpath, string filename, int index) {
	// store
	this->hostname = hostname;
	this->port = port;
	this->localpath = localpath;
	this->filename = filename;
	this->index = index;

	// fork
	this->child = fork();
	if (child < 0) { // could not fork on this socket
		return;
	} else if (child > 0) { // parent
		return;
	}

	// child
	printf("Hello from Child, hostname constructor\n");

	// connect
	this->connected = this->Connect();
	if (!this->connected) {
		printf("Failed to connect\n");
		exit(EXIT_FAILURE);
	}
	printf("Connected to %s on port %d\n",hostname.c_str(),port);

	// download
	if (! makeRequest(constructRequest())) {
		fprintf(stderr, "Failed to send request\n");
		exit(EXIT_FAILURE);
	}
	download();

	exit(EXIT_SUCCESS);	// connect to socket
}
/**
 * Request detailed information on a program.  
 */
ProgramReply* ElisaNetworkService::programInfo(const QString& programId)
{
    return new ProgramReply(makeRequest(QString(PROGRAM_INFO).arg(programId)));
}
Beispiel #23
0
Response Session::Impl::Post() {
    return makeRequest(curl_->handle);
}
BooleanReply* ElisaNetworkService::removeRecording(const QString& id)
{
    return new BooleanReply(makeRequest(QString(REMOVE_RECORDING).arg(id)));
}
BooleanReply* ElisaNetworkService::removeProgram(const QString& id)
{
    return new BooleanReply(makeRequest(QString(REMOVE_PROGRAM).arg(id)));
}
/**
 * Sends a login request to the server. Returns a BooleanReply object which will provide
 * the response.
 */
BooleanReply* ElisaNetworkService::login(const QString& userName, const QString& passWord)
{    
    return new BooleanReply(makeRequest(QString(LOGIN_URI).arg(userName).arg(passWord)));
}
RecordingsReply* ElisaNetworkService::topList()
{
    return new RecordingsReply(makeRequest(QString(TOP_URI)), RecordingsReply::TOP);
}
/**
 * Request recordings. Caller responsible for deletion.
 * Call is asynchronous so wait for epg signal.
 */
RecordingsReply* ElisaNetworkService::recordings()
{
    return new RecordingsReply(makeRequest(QString(REC_URI)), RecordingsReply::REC);
}
/**
 * Get program info for week.
 */
EpgReply* ElisaNetworkService::epgWeek()
{
    return new EpgReply(makeRequest(EPG_URI));
}
/**
 * Request channels list.
 */
ChannelsReply* ElisaNetworkService::channelList()
{    
    return new ChannelsReply(makeRequest(CHANNELS_URI));
}