mayu/mayu.h

90 lines
2.5 KiB
C
Raw Permalink Normal View History

2018-05-04 16:53:00 +02:00
/*****************************************************************************
* mayu Mate Are You Up
2019-04-14 17:22:45 +02:00
* Copyright (C) 2019 Syping
2018-05-04 16:53:00 +02:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#ifndef MAYU_H
#define MAYU_H
#include <QJsonDocument>
#include <QJsonObject>
#include <QStringList>
2018-05-15 08:10:24 +02:00
#include <QJsonArray>
2018-05-04 16:53:00 +02:00
#include <QObject>
2018-05-15 08:10:24 +02:00
#include <QList>
enum class mayuMode : int{Ping = 0, Resolve = 1};
struct mayuResult {
QString host;
QString result;
};
2018-05-04 16:53:00 +02:00
class mayu : public QObject
{
Q_OBJECT
public:
2018-05-15 08:10:24 +02:00
explicit mayu(const QString &hostsFile = QString(), const QString &jsonFile = QString(), QObject *parent = nullptr);
void setMayuMode(mayuMode mode);
2018-05-04 16:53:00 +02:00
void setHostsFile(const QString &fileName);
void setHosts(const QStringList &hostsList);
void setJsonFile(const QString &fileName);
2018-05-15 08:10:24 +02:00
void setPingTimeout(double timeout);
void setPingTries(int tries);
2018-05-15 08:46:11 +02:00
void setCleanUp(bool clean);
2018-05-15 08:10:24 +02:00
mayuMode getMayuMode();
2018-05-04 16:53:00 +02:00
const QString getHostsFile();
const QStringList getHosts();
const QString getJsonFile();
2018-05-15 08:10:24 +02:00
double getPingTimeout();
int getPingTries();
2018-05-15 08:46:11 +02:00
bool getCleanUp();
2018-05-04 16:53:00 +02:00
int getResult();
2018-05-15 08:10:24 +02:00
#ifdef MAYU_UNIX
2018-05-04 16:53:00 +02:00
static double ping(const QString &host, int tries, double timeout = 2.5);
2018-05-15 08:10:24 +02:00
#endif
2018-05-15 08:46:11 +02:00
static const QList<mayuResult> resolve(const QString &host, bool emptyWhenError = false);
2018-05-04 16:53:00 +02:00
public slots:
void parse_hosts();
void work();
private:
2018-05-15 08:10:24 +02:00
#ifdef PRIVILEGE_DROP_REQUIRED
bool p_dropPrivileges();
bool p_regainPrivileges();
#endif
2018-05-15 09:46:21 +02:00
void p_saveWork(const QJsonObject &jsonObject);
void p_workHosts(const QList<QByteArray> &hostsArray);
2018-05-15 08:10:24 +02:00
#ifdef MAYU_UNIX
void p_workPing();
#endif
void p_workResolve();
2018-05-04 16:53:00 +02:00
QStringList p_hostsList;
QString p_hostsFile;
QString p_jsonFile;
2018-05-15 08:10:24 +02:00
mayuMode p_mayuMode;
2018-05-04 16:53:00 +02:00
bool p_hostsParsed;
2018-05-15 08:10:24 +02:00
double p_timeout;
2018-05-04 16:53:00 +02:00
int p_return;
int p_tries;
2018-05-15 08:46:11 +02:00
bool p_clean;
2018-05-15 08:10:24 +02:00
#ifdef PRIVILEGE_DROP_REQUIRED
2018-05-09 22:47:45 +02:00
uid_t p_uid;
2019-04-14 17:22:45 +02:00
gid_t p_gid;
2018-05-15 08:10:24 +02:00
#endif
2018-05-04 16:53:00 +02:00
};
#endif // MAYU_H