Exemplo n.º 1
1
void QXmppSocksServer::slotReadyRead()
{
    QTcpSocket *socket = qobject_cast<QTcpSocket*>(sender());
    if (!socket || !m_states.contains(socket))
        return;

    if (m_states.value(socket) == ConnectState)
    {
        m_states.insert(socket, CommandState);

        // receive connect to server request
        QByteArray buffer = socket->readAll();
        if (buffer.size() < 3 ||
            buffer.at(0) != SocksVersion ||
            buffer.at(1) + 2 != buffer.size())
        {
            qWarning("QXmppSocksServer received invalid handshake");
            socket->close();
            return;
        }

        // check authentication method
        bool foundMethod = false;
        for (int i = 2; i < buffer.size(); i++)
        {
            if (buffer.at(i) == NoAuthentication)
            {
                foundMethod = true;
                break;
            }
        }
        if (!foundMethod)
        {
            qWarning("QXmppSocksServer received bad authentication method");
            socket->close();
            return;
        }

        // send connect to server response
        buffer.resize(2);
        buffer[0] = SocksVersion;
        buffer[1] = NoAuthentication;
        socket->write(buffer);

    } else if (m_states.value(socket) == CommandState) {
        m_states.insert(socket, ReadyState);

        // disconnect from signals
        disconnect(socket, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));

        // receive command
        QByteArray buffer = socket->readAll();
        if (buffer.size() < 4 ||
            buffer.at(0) != SocksVersion ||
            buffer.at(1) != ConnectCommand ||
            buffer.at(2) != 0x00)
        {
            qWarning("QXmppSocksServer received an invalid command");
            socket->close();
            return;
        }

        // parse host
        quint8 hostType;
        QByteArray hostName;
        quint16 hostPort;
        if (!parseHostAndPort(buffer.mid(3), hostType, hostName, hostPort))
        {
            qWarning("QXmppSocksServer could not parse type/host/port");
            socket->close();
            return;
        }

        // notify of connection
        emit newConnection(socket, hostName, hostPort);

        // send response
        buffer.resize(3);
        buffer[0] = SocksVersion;
        buffer[1] = Succeeded;
        buffer[2] = 0x00;
        buffer.append(encodeHostAndPort(
            DomainName,
            hostName,
            hostPort));
        socket->write(buffer);
    }
}
Exemplo n.º 2
0
void QXmppSocksClient::slotReadyRead()
{
    if (m_step == ConnectState)
    {
        m_step++;

        // receive connect to server response
        QByteArray buffer = readAll();
        if (buffer.size() != 2 || buffer.at(0) != SocksVersion || buffer.at(1) != NoAuthentication)
        {
            qWarning("QXmppSocksClient received an invalid response during handshake");
            close();
            return;
        }

        // send CONNECT command
        buffer.resize(3);
        buffer[0] = SocksVersion;
        buffer[1] = ConnectCommand;
        buffer[2] = 0x00; // reserved
        buffer.append(encodeHostAndPort(
            DomainName,
            m_hostName.toLatin1(),
            m_hostPort));
        write(buffer);

    } else if (m_step == CommandState) {
        m_step++;

        // disconnect from signal
        disconnect(this, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));

        // receive CONNECT response
        QByteArray buffer = readAll();
        if (buffer.size() < 6 ||
            buffer.at(0) != SocksVersion ||
            buffer.at(1) != Succeeded ||
            buffer.at(2) != 0)
        {
            qWarning("QXmppSocksClient received an invalid response to CONNECT command");
            close();
            return;
        }

        // parse host
        quint8 hostType;
        QByteArray hostName;
        quint16 hostPort;
        if (!parseHostAndPort(buffer.mid(3), hostType, hostName, hostPort))
        {
            qWarning("QXmppSocksClient could not parse type/host/port");
            close();
            return;
        }
        // FIXME : what do we do with the resulting name / port?

        // notify of connection
        emit ready();
    }
}
void executeCommandPort(ClientThreadResource * res , char * aRequest , int * result ) {

    char * hp = parseHostAndPort(aRequest , res->heapHandler);
    char * host = decodeHost(hp, res->heapHandler);
    char * port = decodePort(hp , res->heapHandler);

    validateAndCloseDataConnection(res);

    //res->dataSocket = openConnectionSocket(host , port);
    res->remoteHost = host;
    res->remotePort = port;
    res->mode = FTP_DATA_MODE_ACTIVE;

    doDataService(res);

    sendMessage(res->controlSocket , concat(res->heapHandler , 2 ,
                                            "200 modo activo iniciado " , CHARACTER_CRLF) , &result);
}
Exemplo n.º 4
0
void URI::parseAuthority(std::string::const_iterator& it, const std::string::const_iterator& end)
{
	std::string userInfo;
	std::string part;
	while (it != end && *it != '/' && *it != '?' && *it != '#')
	{
		if (*it == '@')
		{
			userInfo = part;
			part.clear();
		}
		else part += *it;
		++it;
	}
	std::string::const_iterator pbeg = part.begin();
	std::string::const_iterator pend = part.end();
	parseHostAndPort(pbeg, pend);
	_userInfo = userInfo;
}
Exemplo n.º 5
0
int hdfsGetConf(const char *&host, unsigned short &port, const char *&user, char *group[], int &group_size)
{
  jobject jConfiguration = NULL;
  JNIEnv *env = 0;
  jthrowable jExc = NULL;
  int ret = 0;

  env = getJNIEnv();
  if (env == NULL) {
    fprintf(stderr, "can't JNI Env\n");
    return -1;
  }

  jConfiguration =
    constructNewObjectOfClass(env, &jExc, HADOOP_CONF, "()V");
  if (jConfiguration == NULL) {
    fprintf(stderr, "Can't construct instance of class "
            "org.apache.hadoop.conf.Configuration\n");
    if (jExc != NULL) {
      env->ExceptionDescribe();
    }

    return -1;
  }

  jvalue jVal;
  jstring ugiStr = (env)->NewStringUTF(UGI_INFO);
  jstring fsStr = env->NewStringUTF(DEFAULT_FS);

  if (invokeMethod(env, &jVal, NULL, jConfiguration, HADOOP_CONF, "get", JMETHOD1(JPARAM(JAVA_STRING), JPARAM(JAVA_STRING)), ugiStr) != 0) {
    //set err return
    ret = -1;

    fprintf(stderr, "can't invoke method get ugi\n");
    if (env->ExceptionOccurred()) {
      env->ExceptionDescribe();
    }
  }

  //parse group and user info
  if (ret == 0) {
    if (jVal.l != NULL) {
      const char *ugi = (env)->GetStringUTFChars((jstring)jVal.l, NULL);

      if (ugi != NULL) {
        fprintf(stdout, "ugi string is %s\n", ugi);

        if (parseGroup(user, group, group_size, ugi)) {
          fprintf(stderr, "can't parse group info\n");
          ret = -1;
        }

        env->ReleaseStringUTFChars((jstring)jVal.l, ugi);
      }
    } else {
      fprintf(stdout, "can't find gui=%s\n", UGI_INFO);
    }
  }

  if (ret == 0) {                               /* get host and port info */
    if (invokeMethod(env, &jVal, NULL, jConfiguration, HADOOP_CONF, "get", JMETHOD1(JPARAM(JAVA_STRING), JPARAM(JAVA_STRING)), fsStr) != 0) {
      ret = -1;

      fprintf(stderr, "can't invoke method get default fs\n");
      if (env->ExceptionOccurred()) {
        env->ExceptionDescribe();
      }
    } else {
      if (jVal.l != NULL) {
        const char *str = (env)->GetStringUTFChars((jstring)jVal.l, NULL);

        if (str != NULL) {
          fprintf(stdout, "fs string is %s\n", str);
          if (parseHostAndPort(host, port, str)) {
            fprintf(stderr, "can't parse host and port info\n");
            ret = -1;
          }

          env->ReleaseStringUTFChars((jstring)jVal.l, str);
        }
      } else {
        fprintf(stdout, "can't find gui=%s\n", UGI_INFO);
      }
    }
  }

  destroyLocalReference(env, ugiStr);
  destroyLocalReference(env, jConfiguration);

  return ret;
}