SshClient.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. GNU General Public License version 3 notice
  3. Copyright (C) 2012 Mihawk <luiz@netdome.biz>. All rights reserved.
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see < http://www.gnu.org/licenses/ >.
  14. */
  15. /* SSH client for connecting to QWNET central */
  16. #ifndef SSHCLIENT_H
  17. #define SSHCLIENT_H
  18. #include <QObject>
  19. class QProcess;
  20. class QDateTime;
  21. class QStringList;
  22. class SshClient : public QObject
  23. {
  24. Q_OBJECT
  25. public:
  26. enum Error { NoError, ConnectionTimedOutError };
  27. explicit SshClient(QObject *parent = 0);
  28. ~SshClient();
  29. bool connectToHost(const QString& user, const QString &host);
  30. bool isConnected() const;
  31. void disconnectFromHost();
  32. signals:
  33. void error(Error errorCode);
  34. void connected();
  35. protected:
  36. void timerEvent(QTimerEvent *e);
  37. private slots:
  38. void read();
  39. void exited(int exitCode);
  40. private:
  41. QProcess* myProcess;
  42. QRegExp* myCommandRegex;
  43. bool myConnectedFlag;
  44. int myConnectionTimerID;
  45. int myPingTimerID;
  46. int myPongTimerID;
  47. QStringList* myClients;
  48. void parse(const QDateTime& time, const QString& command, const QString& commandData);
  49. void write(const QString& data);
  50. void ping();
  51. void pong();
  52. };
  53. #endif // SSHCLIENT_H