1 /*****
2 *
3 * Copyright (C) 2009-2015 CS-SI. All Rights Reserved.
4 * Author: Yoann Vandoorselaere <yoannv@gmail.com>
5 *
6 * This file is part of the Prelude library.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 *****/
23 
24 #ifndef _LIBPRELUDE_PRELUDE_CLIENT_HXX
25 #define _LIBPRELUDE_PRELUDE_CLIENT_HXX
26 
27 #include "idmef.hxx"
28 #include "prelude-connection-pool.hxx"
29 #include "prelude-client-profile.hxx"
30 
31 
32 namespace Prelude {
33         class IDMEF;
34 
35         class Client : public ClientProfile {
36             private:
37                 prelude_client_t *_client;
38                 ConnectionPool _pool;
39 
40             protected:
41                 int _recv_timeout;
42 
43             public:
44                 enum ClientFlagsEnum {
45                         ASYNC_SEND  = PRELUDE_CLIENT_FLAGS_ASYNC_SEND,
46                         FLAGS_ASYNC_SEND   = PRELUDE_CLIENT_FLAGS_ASYNC_SEND,
47                         ASYNC_TIMER = PRELUDE_CLIENT_FLAGS_ASYNC_TIMER,
48                         FLAGS_ASYNC_TIMER  = PRELUDE_CLIENT_FLAGS_ASYNC_TIMER,
49                         HEARTBEAT   = PRELUDE_CLIENT_FLAGS_HEARTBEAT,
50                         FLAGS_HEARTBEAT   = PRELUDE_CLIENT_FLAGS_HEARTBEAT,
51                         CONNECT     = PRELUDE_CLIENT_FLAGS_CONNECT,
52                         FLAGS_CONNECT     = PRELUDE_CLIENT_FLAGS_CONNECT,
53                         AUTOCONFIG  = PRELUDE_CLIENT_FLAGS_AUTOCONFIG,
54                         FLAGS_AUTOCONFIG = PRELUDE_CLIENT_FLAGS_AUTOCONFIG,
55                 };
56 
57                 enum ConnectionPermissionEnum {
58                         IDMEF_READ  = PRELUDE_CONNECTION_PERMISSION_IDMEF_READ,
59                         PERMISSION_IDMEF_READ = PRELUDE_CONNECTION_PERMISSION_IDMEF_READ,
60                         ADMIN_READ  = PRELUDE_CONNECTION_PERMISSION_ADMIN_READ,
61                         PERMISSION_ADMIN_READ  = PRELUDE_CONNECTION_PERMISSION_ADMIN_READ,
62                         IDMEF_WRITE = PRELUDE_CONNECTION_PERMISSION_IDMEF_WRITE,
63                         PERMISSION_IDMEF_WRITE  = PRELUDE_CONNECTION_PERMISSION_IDMEF_WRITE,
64                         ADMIN_WRITE = PRELUDE_CONNECTION_PERMISSION_ADMIN_WRITE,
65                         PERMISSION_ADMIN_WRITE  = PRELUDE_CONNECTION_PERMISSION_ADMIN_WRITE,
66                 };
67 
68                 ~Client();
69                 Client(const char *profile);
70                 Client(const Client &client);
71 
72                 void start();
73                 void init();
74 
75                 prelude_client_t *getClient() const;
76 
77                 void sendIDMEF(const Prelude::IDMEF &message);
78                 int recvIDMEF(Prelude::IDMEF &idmef, int timeout=-1);
79 
80                 int getFlags() const;
81                 void setFlags(int flags);
82 
83                 int getRequiredPermission() const;
84                 void setRequiredPermission(int permission);
85 
86                 const char *getConfigFilename() const;
87                 void setConfigFilename(const char *name);
88 
89                 Prelude::ConnectionPool &getConnectionPool();
90                 void setConnectionPool(Prelude::ConnectionPool pool);
91 
92                 Client &operator << (Prelude::IDMEF &idmef);
93                 Client &operator >> (Prelude::IDMEF &idmef);
94                 Client &operator=(const Client &p);
95 
96                 static Client &setRecvTimeout(Client &c, int timeout);
97         };
98 };
99 
100 #endif
101