]> git.stg.codes - stg.git/blob - projects/sgauthstress/main.cpp
Add user list loading
[stg.git] / projects / sgauthstress / main.cpp
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21  /*
22  $Revision: 1.13 $
23  $Date: 2010/04/14 09:01:29 $
24  $Author: faust $
25  */
26
27 #include <unistd.h>
28
29 #include <csignal>
30 #include <iostream>
31
32 #include "stg/ia.h"
33 #include "stg/common.h"
34 #include "stg/store.h"
35
36 #include "settings.h"
37 #include "store_loader.h"
38
39 time_t stgTime;
40 bool running;
41
42 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
45 void Usage()
46 {
47 std::cout << "Usage:\n\nsgauth <path_to_config>" << std::endl;
48 }
49 //-----------------------------------------------------------------------------
50 void StatUpdate(const LOADSTAT &, void *)
51 {
52 }
53 //-----------------------------------------------------------------------------
54 void StatusChanged(int, void *)
55 {
56 }
57 //-----------------------------------------------------------------------------
58 void ShowMessage(const string &, int, int, int, void *)
59 {
60 }
61 //-----------------------------------------------------------------------------
62 void ShowError(const string &, int, void *)
63 {
64 }
65 //-----------------------------------------------------------------------------
66 void CatchTERM(int)
67 {
68 running = false;
69 }
70 //-----------------------------------------------------------------------------
71 static void SetSignalHandlers()
72 {
73 struct sigaction newsa, oldsa;
74 sigset_t sigmask;
75
76 sigemptyset(&sigmask);
77 sigaddset(&sigmask, SIGTERM);
78 newsa.sa_handler = CatchTERM;
79 newsa.sa_mask = sigmask;
80 newsa.sa_flags = 0;
81 sigaction(SIGTERM, &newsa, &oldsa);
82
83 sigemptyset(&sigmask);
84 sigaddset(&sigmask, SIGINT);
85 newsa.sa_handler = CatchTERM;
86 newsa.sa_mask = sigmask;
87 newsa.sa_flags = 0;
88 sigaction(SIGINT, &newsa, &oldsa);
89
90 return;
91 }
92 //-----------------------------------------------------------------------------
93 int main(int argc, char *argv[])
94 {
95 SETTINGS settings;
96
97 if (argc == 2)
98     {
99     settings.SetConfFile(argv[1]);
100     }
101
102 if (settings.ReadSettings())
103     {
104     std::cerr << "Failed to read settings: '"
105               << settings.GetStrError() << "'" << std::endl;
106     Usage();
107     return -1;
108     }
109
110 SetSignalHandlers();
111
112 STORE_LOADER storeLoader(settings.GetModulesPath(), settings.GetStoreModuleSettings());
113 if (storeLoader.Load())
114     {
115     std::cerr << "Failed to load storage plugin: '" << storeLoader.GetStrError() << "'" << std::endl;
116     return -1;
117     }
118
119 STORE * dataStore = storeLoader.GetStore();
120
121 std::vector<std::string> userList;
122 if (dataStore->GetUsersList(&userList))
123     {
124     std::cerr << "Failed to get user list: '" << dataStore->GetStrError() << "'" << std::endl;
125     return -1;
126     }
127
128 std::cout << "Successfully loaded " << userList.size() << " users" << std::endl;
129
130 IA_CLIENT_PROT proto(settings.GetServerName(), settings.GetServerPort(), settings.GetLocalPort());
131
132 proto.SetLogin(settings.GetLogin());
133 proto.SetPassword(settings.GetPassword());
134
135 proto.SetStatusChangedCb(StatusChanged, NULL);
136 proto.SetInfoCb(ShowMessage, NULL);
137 proto.SetErrorCb(ShowError, NULL);
138 proto.SetStatChangedCb(StatUpdate, NULL);
139
140 proto.Start();
141
142 proto.Connect();
143
144 running = true;
145 while (running)
146     {
147     usleep(200000);
148     }
149
150 proto.Disconnect();
151
152 proto.Stop();
153
154 storeLoader.Unload();
155
156 return 0;
157 }
158 //-----------------------------------------------------------------------------