summaryrefslogtreecommitdiffstats
path: root/src/Daemon/MiddleWare.h
blob: bb845435d32ba093616511463938071bf01122c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
    MiddleWare.h - header file for MiddleWare library. It wraps plugins and
                   take case of them.

    Copyright (C) 2009  Zdenek Prikryl (zprikryl@redhat.com)
    Copyright (C) 2009  RedHat inc.

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along
    with this program; if not, write to the Free Software Foundation, Inc.,
    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
    */


#ifndef MIDDLEWARE_H_
#define MIDDLEWARE_H_

#include "PluginManager.h"
#include "CrashTypes.h"
#include "MiddleWareTypes.h"
#include "RPM.h"

/**
 * A very important class :-). It manages part of user demands like creating
 * reports, or reporting stuff somewhere etc.
 */
class CMiddleWare
{
    public:
        /**
         * An enum contains all return codes.
         */
        typedef enum {
            MW_ERROR,            /**< Common error.*/
            MW_OK,               /**< No error.*/
            MW_BLACKLISTED,      /**< Package is blacklisted.*/
            MW_CORRUPTED,        /**< Debugdump directory is corrupted.*/
            MW_PACKAGE_ERROR,    /**< Cannot determine package name.*/
            MW_GPG_ERROR,        /**< Package is not signed properly.*/
            MW_REPORTED,         /**< Crash is already reported.*/
            MW_OCCURED,          /**< Crash occurred in the past, but it is not reported yet.*/
            MW_IN_DB,            /**< Debugdump directory is already saved in a database.*/
            MW_IN_DB_ERROR,      /**< Error while working with a database.*/
            MW_FILE_ERROR        /**< Error when trying open debugdump directory or
                                      when trying open file in debug dump directory..*/
        } mw_result_t;

    private:
        typedef set_strings_t set_blacklist_t;
        typedef set_strings_t set_enabled_plugins_t;
        typedef std::vector<pair_string_string_t> vector_pairt_strings_t;
        typedef vector_pairt_strings_t vector_actions_and_reporters_t;
        typedef std::map<std::string, vector_actions_and_reporters_t> map_analyzer_actions_and_reporters_t;

        /**
         * An instance of CPluginManager. When MiddleWare wants to do something
         * with plugins, it calls the plugin manager.
         * @see PluginManager.h
         */
        CPluginManager* m_pPluginManager;
        /**
         * An instance of CRPM used for package checking.
         * @see RPM.h
         */
        CRPM m_RPM;
        /**
         * A set of blacklisted packages.
         */
        set_blacklist_t m_setBlackList;
        /**
         * A name of database plugin, which is used for metadata.
         */
        std::string m_sDatabase;
        /**
         * A map, which associates particular analyzer to one or more
         * action or reporter plugins. These are activated when a crash, which
         * is maintained by particular analyzer, occurs.
         */
        map_analyzer_actions_and_reporters_t m_mapAnalyzerActionsAndReporters;
        /**
         * A vector of one or more action or reporter plugins. These are
         * activated when any crash occurs.
         */
        vector_actions_and_reporters_t m_vectorActionsAndReporters;
        /**
         * Plugins configuration directory (e.g. /etc/abrt/plugins, ...).
         */
        std::string m_sPluginsConfDir;
        /**
         * Check GPG finger print?
         */
        bool m_bOpenGPGCheck;
        /**
         * A method, which gets a local UUID from particular analyzer plugin.
         * @param pAnalyzer A name of an analyzer plugin.
         * @param pDebugDumpDir A debugdump dir containing all necessary data.
         * @return A local UUID.
         */
        std::string GetLocalUUID(const std::string& pAnalyzer,
                                 const std::string& pDebugDumpDir);
        /**
         * A method, which gets a global UUID from particular analyzer plugin.
         * @param pAnalyzer A name of an analyzer plugin.
         * @param pDebugDumpDir A debugdump dir containing all necessary data.
         * @return A global UUID.
         */
        std::string GetGlobalUUID(const std::string& pAnalyzer,
                                  const std::string& pDebugDumpDir);
        /**
         * A method, which takes care of getting all additional data needed
         * for computing UUIDs and creating a report for particular analyzer
         * plugin. This report could be send somewhere afterwards.
         * @param pAnalyzer A name of an analyzer plugin.
         * @param pDebugDumpPath A debugdump dir containing all necessary data.
         */
        void CreateReport(const std::string& pAnalyzer,
                          const std::string& pDebugDumpDir);
        /**
         * A method, which executes all action plugins, which are associated to
         * particular analyzer plugin.
         * @param pAnalyzer A name of an analyzer plugin.
         * @param pDebugDumpPath A debugdump dir containing all necessary data.
         */
        void RunAnalyzerActions(const std::string& pAnalyzer,
                                const std::string& pDebugDumpDir);
        /**
         * A method, which transforms a debugdump direcortry to inner crash
         * report form. This form is used for later reporting.
         * @param pDebugDumpDir A debugdump dir containing all necessary data.
         * @param pCrashReport A created crash report.
         */
        void DebugDumpToCrashReport(const std::string& pDebugDumpDir,
                                    map_crash_report_t& pCrashReport);
        /**
         * A method, which checks is particular debugdump directory is saved
         * in database. This check is done together with an UID of an user.
         * @param pUID an UID of an user.
         * @param pDebugDumpDir A debugdump dir containing all necessary data.
         * @return It returns true if debugdump dir is already saved, otherwise
         * it returns false.
         */
        bool IsDebugDumpSaved(const std::string& pUID,
                              const std::string& pDebugDumpDir);
        /**
         * A method, which gets a package name from executable name and saves
         * package description to particular debugdump directory of a crash.
         * @param pExecutable A name of crashed application.
         * @param pDebugDumpDir A debugdump dir containing all necessary data.
         * @return It return results of operation. See mw_result_t.
         */
        mw_result_t SavePackageDescriptionToDebugDump(const std::string& pExecutable,
                                                      const std::string& pDebugDumpDir);
        /**
         * A method, which save a debugdump into database. If a saving is
         * successful, then a crash info is filled. Otherwise the crash info is
         * not changed.
         * @param pUUID A local UUID of a crash.
         * @param pUID An UID of an user.
         * @param pTime Time when a crash occurs.
         * @param pDebugDumpPath A debugdump path.
         * @param pCrashInfo A filled crash info.
         * @return It return results of operation. See mw_result_t.
         */
        mw_result_t SaveDebugDumpToDatabase(const std::string& pUUID,
                                            const std::string& pUID,
                                            const std::string& pTime,
                                            const std::string& pDebugDumpDir,
                                            map_crash_info_t& pCrashInfo);

    public:
        /**
         * A constructor.
         * @param pPluginsConfDir A plugins configuration directory.
         * @param pPluginsLibDir A plugins library directory.
         */
        CMiddleWare(const std::string& pPluginsConfDir,
                    const std::string& pPluginsLibDir);
        /**
         * A destructor.
         */
        ~CMiddleWare();
        /**
         * A method, which registers particular plugin.
         * @param pName A plugin name.
         */
        void RegisterPlugin(const std::string& pName);
        /**
         * A method, which unregister particular plugin.
         * @param pName A plugin name.
         */
        void UnRegisterPlugin(const std::string& pName);
        /**
         * A method, which sets up a plugin. The settings are also saved in home
         * directory of an user.
         * @param pName A plugin name.
         * @param pUID An uid of user.
         * @param pSettings A plugin's settings.
         */
        void SetPluginSettings(const std::string& pName,
                               const std::string& pUID,
                               const map_plugin_settings_t& pSettings);
        /**
         * A method, which returns plugin's settings according to user.
         * @param pName A plugin name.
         * @param pUID An uid of user.
         * @return Plugin's settings accorting to user.
         */
        map_plugin_settings_t GetPluginSettings(const std::string& pName,
                                                const std::string& pUID);
        /**
         * A method, which gets all plugins info (event those plugins which are
         * disabled). It can be send via DBus to GUI and displayed to an user.
         * Then a user can fill all needed informations like URLs etc.
         * @return A vector of maps <key, vaule>.
         */
        vector_map_string_string_t GetPluginsInfo();
        /**
         * A method, which takes care of getting all additional data needed
         * for computing UUIDs and creating a report for particular analyzer
         * plugin. This report could be send somewhere afterwards. If a creation
         * is successful, then  a crash report is filled.
         * @param pAnalyzer A name of an analyzer plugin.
         * @param pDebugDumpPath A debugdump dir containing all necessary data.
         * @param pCrashReport A filled crash report.
         * @return It return results of operation. See mw_result_t.
         */
        mw_result_t CreateCrashReport(const std::string& pUUID,
                                      const std::string& pUID,
                                      map_crash_report_t& pCrashReport);
        /**
         * A method, which activate particular action plugin.
         * @param pActionDir A directory, which is passed as working to a action plugin.
         * @param pPluginName An action plugin name.
         * @param pPluginArgs Action plugin's arguments.
         */
        void RunAction(const std::string& pActionDir,
                       const std::string& pPluginName,
                       const std::string& pPluginArgs);
        /**
         * A method, which activate all action and reporter plugins when any
         * crash occurs.
         * @param pDebugDumpDir A debugdump dir containing all necessary data.
         */
        void RunActionsAndReporters(const std::string& pDebugDumpDir);
        /**
         * A method, which reports a crash report to particular receiver. It
         * takes an user uid, tries to find user config file and load it. If it
         * fails, then default config is used. If pUID is emply string, default
         * config is used.
         * ...).
         * @param pCrashReport A crash report.
         * @param pUID An user uid
         */
        void Report(const map_crash_report_t& pCrashReport,
                    const std::string& pUID);
        /**
         * A method, which deletes particular debugdump directory.
         * @param pDebugDumpDir A debugdump directory.
         */
        void DeleteDebugDumpDir(const std::string& pDebugDumpDir);
        /**
         * A method, which delete a row from database. If a deleting is
         * successfull, it returns a debugdump directort, which is not
         * deleted. Otherwise, it returns empty string.
         * @param pUUID A local UUID of a crash.
         * @param pUID An UID of an user.
         * @return A debugdump directory.
         */
        std::string DeleteCrashInfo(const std::string& pUUID,
                                    const std::string& pUID);
        /**
         * A method, whis saves debugdump into database.
         * @param pDebugDumpDir A debugdump directory.
         * @return It return results of operation. See mw_result_t.
         */
        mw_result_t SaveDebugDump(const std::string& pDebugDumpDir);
        /**
         * A method, whis saves debugdump into database. If saving is sucessful
         * it fills crash info.
         * @param pDebugDumpDir A debugdump directory.
         * @param pCrashInfo A crash info.
         * @return It return results of operation. See mw_result_t.
         */
        mw_result_t SaveDebugDump(const std::string& pDebugDumpDir,
                                  map_crash_info_t& pCrashInfo);
        /**
         * A method, which gets one crash info. If a getting is successful,
         * then a crash info is filled.
         * @param pUUID A local UUID of a crash.
         * @param pUID An UID of an user.
         * @param pCrashInfo A crash info.
         * @return It return results of operation. See mw_result_t.
         */
        mw_result_t GetCrashInfo(const std::string& pUUID,
                                 const std::string& pUID,
                                 map_crash_info_t& pCrashInfo);
        /**
         * A method, which gets all local UUIDs and UIDs of crashes. These crashes
         * occurred when a particular user was logged in.
         * @param pUID an UID of an user.
         * @return A vector of pairs  (local UUID, UID).
         */
        vector_pair_string_string_t GetUUIDsOfCrash(const std::string& pUID);
        /**
         * A method, which set a GPG finger print check.
         * @param pCheck Is it enabled?
         */
        void SetOpenGPGCheck(bool pCheck);
        /**
         * A method, which sets a name of database.
         * @param pDatabase A database name.
         */
        void SetDatabase(const std::string& pDatabase);
        /**
         * A method, which adds one path to a GPG public key into MW's set.
         * @param pKey A path to a GPG public key.
         */
        void AddOpenGPGPublicKey(const std::string& pKey);
        /**
         * A method, which adds one blacklisted package.
         */
        void AddBlackListedPackage(const std::string& pPackage);
        /**
         * A method, which adds one association among alanyzer plugin and its
         * action and reporter plugins.
         * @param pAnalyzer A name of an analyzer plugin.
         * @param pActionOrReporter A name of an action or reporter plugin.
         * @param pArgs An arguments for action or reporter plugin.
         */
        void AddAnalyzerActionOrReporter(const std::string& pAnalyzer,
                                         const std::string& pActionOrReporter,
                                         const std::string& pArgs);
        /**
         * A method, which adds action and reporter plugins, which are activated
         * when any crash occurs.
         * @param pActionOrReporter A name of an action or reporter plugin.
         * @param pArgs An arguments for action or reporter plugin.
         */
        void AddActionOrReporter(const std::string& pActionOrReporter,
                                 const std::string& pArgs);
};

#endif /*MIDDLEWARE_H_*/