ソースを参照

add intrabatch

master
Robin Thoni 10年前
コミット
f94256da36
6個のファイルの変更172行の追加1行の削除
  1. 2
    1
      epimafia.pro
  2. バイナリ
      intrabatch/intrabatch
  3. 26
    0
      intrabatch/intrabatch.pro
  4. 11
    0
      intrabatch/main.cpp
  5. 105
    0
      intrabatch/mainclass.cpp
  6. 28
    0
      intrabatch/mainclass.h

+ 2
- 1
epimafia.pro ファイルの表示

@@ -7,5 +7,6 @@ SUBDIRS += \
7 7
     ns_finder \
8 8
 	intrabocal \
9 9
 	usermgr \
10
-	netsoul #\
10
+	netsoul \ #\
11
+    intrabatch
11 12
 	#daemon

バイナリ
intrabatch/intrabatch ファイルの表示


+ 26
- 0
intrabatch/intrabatch.pro ファイルの表示

@@ -0,0 +1,26 @@
1
+#-------------------------------------------------
2
+#
3
+# Project created by QtCreator 2014-05-03T23:55:25
4
+#
5
+#-------------------------------------------------
6
+
7
+QT       += core gui network
8
+
9
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10
+
11
+TARGET = intrabatch
12
+TEMPLATE = app
13
+
14
+
15
+SOURCES += main.cpp \
16
+    mainclass.cpp
17
+
18
+HEADERS += \
19
+    mainclass.h
20
+
21
+win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../Epimafia/release/ -lEpimafia
22
+else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../Epimafia/debug/ -lEpimafia
23
+else:unix:!macx: LIBS += -L$$OUT_PWD/../Epimafia/ -lEpimafia
24
+
25
+INCLUDEPATH += $$PWD/../Epimafia
26
+DEPENDPATH += $$PWD/../Epimafia

+ 11
- 0
intrabatch/main.cpp ファイルの表示

@@ -0,0 +1,11 @@
1
+#include <QApplication>
2
+#include "mainclass.h"
3
+
4
+int main(int argc, char *argv[])
5
+{
6
+	QApplication a(argc, argv);
7
+
8
+	MainClass c;
9
+
10
+	return a.exec();
11
+}

+ 105
- 0
intrabatch/mainclass.cpp ファイルの表示

@@ -0,0 +1,105 @@
1
+#include "mainclass.h"
2
+#include <QApplication>
3
+#include <QFileInfo>
4
+#include <iostream>
5
+
6
+MainClass::MainClass(QObject* p) : QObject(p)
7
+{
8
+	if(qApp->argc() < 2)
9
+	{
10
+		qDebug()<<"Usage:"<<QFileInfo(qApp->applicationFilePath()).fileName().toStdString().c_str()<< "loginsFile";
11
+		qApp->exit(-1);
12
+	}
13
+
14
+	m_intra = new IntraBocal(this);
15
+	connect(m_intra, SIGNAL(error(IntraBocal::Error)), this, SLOT(intraError(IntraBocal::Error)));
16
+	connect(m_intra, SIGNAL(logged()), this, SLOT(intraLogged()));
17
+	connect(m_intra, SIGNAL(searchFinished(QList<QList<QString> >)), this, SLOT(intraSearchFinished(QList<QList<QString> >)));
18
+
19
+	m_users = Epimafia::loadUsers();
20
+	for(int i = 0; i < m_users.size(); ++i)
21
+	{
22
+		EpiUser usr = m_users.at(i);
23
+		if(!usr.hasLogin() || usr.isUnknown() || !usr.hasPwd_ppp())
24
+			m_users.removeAt(i--);
25
+	}
26
+	if(m_users.isEmpty())
27
+	{
28
+		qDebug()<<"No Logins";
29
+		qApp->exit(-1);
30
+	}
31
+	m_intra->login(m_users.at(0).getLogin(), m_users.at(0).getPwd_ppp());
32
+
33
+	QFile logins(qApp->arguments().at(1));
34
+	if(!logins.open(QIODevice::ReadOnly))
35
+	{
36
+		qDebug()<<"Unable to open "<<logins.fileName();
37
+		qApp->exit(-1);
38
+	}
39
+	while(!logins.atEnd())
40
+	{
41
+		QString str = logins.readLine();
42
+		str.replace("\n", "");
43
+		str.replace("\r", "");
44
+		if(!str.isEmpty())
45
+			m_logins.append(str);
46
+	}
47
+	logins.close();
48
+}
49
+
50
+MainClass::~MainClass()
51
+{
52
+}
53
+
54
+void MainClass::intraError(IntraBocal::Error e)
55
+{
56
+	if(e == IntraBocal::BadLogin)
57
+	{
58
+		if(!m_users.isEmpty())
59
+		{
60
+			m_users.removeFirst();
61
+			m_intra->login(m_users.at(0).getLogin(), m_users.at(0).getPwd_ppp());
62
+			return;
63
+		}
64
+		else
65
+			qDebug()<<"No Logins with valid password";
66
+	}
67
+	else if(e == IntraBocal::NetworkError)
68
+		qDebug()<<"Network Error";
69
+	else if(e == IntraBocal::ParseError)
70
+		qDebug()<<"Parse Error";
71
+	else if(e == IntraBocal::SslError)
72
+		qDebug()<<"Ssl Error";
73
+	qApp->exit(-1);
74
+}
75
+
76
+void MainClass::intraLogged()
77
+{
78
+	qDebug()<<"Logged in";
79
+	nextSearch();
80
+}
81
+
82
+void MainClass::intraSearchFinished(QList<QList<QString> > users)
83
+{
84
+	if(!users.isEmpty())
85
+	{
86
+		users.removeFirst();
87
+
88
+		if(users.size() > 0)
89
+			std::cout<<users.at(0).at(2).toStdString().c_str()<<"."<<users.at(0).at(1).toStdString().c_str()<<"@epita.fr"<<std::endl;
90
+	}
91
+	else
92
+		qDebug()<<"Users empty";
93
+	nextSearch();
94
+}
95
+
96
+void MainClass::nextSearch()
97
+{
98
+	if(m_logins.isEmpty())
99
+	{
100
+		qApp->exit();
101
+		return;
102
+	}
103
+	m_intra->searchUser("", "", m_logins.at(0));
104
+	m_logins.removeFirst();
105
+}

+ 28
- 0
intrabatch/mainclass.h ファイルの表示

@@ -0,0 +1,28 @@
1
+#ifndef MAINCLASS_H
2
+#define MAINCLASS_H
3
+#include "intrabocal.h"
4
+#include "epimafia.h"
5
+
6
+class MainClass : public QObject
7
+{
8
+	Q_OBJECT
9
+public:
10
+	MainClass(QObject* p = 0);
11
+	~MainClass();
12
+
13
+private slots:
14
+	void intraError(IntraBocal::Error e);
15
+
16
+	void intraLogged();
17
+
18
+	void intraSearchFinished(QList<QList<QString> > users);
19
+
20
+	void nextSearch();
21
+
22
+private:
23
+	IntraBocal* m_intra;
24
+	EpiUsers m_users;
25
+	QStringList m_logins;
26
+};
27
+
28
+#endif // MAINCLASS_H

読み込み中…
キャンセル
保存