SshClient.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include <QString>
  20. class QProcess;
  21. class QDateTime;
  22. class QStringList;
  23. class App;
  24. class SshClient : public QObject
  25. {
  26. Q_OBJECT
  27. public:
  28. enum Error { NoError, ConnectionTimedOutError };
  29. explicit SshClient(App* app, QObject *parent = 0);
  30. ~SshClient();
  31. bool connectToHost(const QString& user, const QString &host);
  32. bool isConnected() const;
  33. void disconnectFromHost();
  34. void write(const QString& data);
  35. signals:
  36. void error(Error errorCode);
  37. void connected();
  38. protected:
  39. void timerEvent(QTimerEvent *e);
  40. private slots:
  41. void read();
  42. void exited(int exitCode);
  43. private:
  44. App* myApp;
  45. QProcess* myProcess;
  46. QRegExp* myCommandRegex;
  47. bool myConnectedFlag;
  48. int myConnectionTimerID;
  49. int myPingTimerID;
  50. int myPongTimerID;
  51. QStringList* myClients;
  52. QString myUsername;
  53. QString myHostname;
  54. void parse(const QDateTime& time, const QString& command, const QString& commandData);
  55. void ping();
  56. void pong();
  57. void reconnect();
  58. };
  59. #endif // SSHCLIENT_H