1 /*
2     pmacct (Promiscuous mode IP Accounting package)
3     pmacct is Copyright (C) 2003-2019 by Paolo Lucente
4 */
5 
6 /*
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21 
22 #ifndef AMQP_COMMON_H
23 #define AMQP_COMMON_H
24 
25 /* includes */
26 #include <amqp.h>
27 #include <amqp_tcp_socket.h>
28 #include "plugin_common.h"
29 
30 /* defines */
31 #define AMQP_DEFAULT_RETRY	60
32 #define PM_AMQP_MIN_FRAME_SIZE	4096
33 
34 /* structures */
35 struct p_amqp_host {
36   char *user;
37   char *passwd;
38   char *exchange;
39   char *exchange_type;
40   char *routing_key;
41   struct p_table_rr rk_rr;
42   char *host;
43   char *vhost;
44   int persistent_msg;
45   u_int8_t content_type;
46   u_int32_t frame_max;
47   int heartbeat_interval;
48 
49   amqp_connection_state_t conn;
50   amqp_socket_t *socket;
51   amqp_rpc_reply_t ret;
52   amqp_bytes_t queue;
53   struct amqp_basic_properties_t_ msg_props;
54   int status;
55 
56   struct p_broker_timers btimers;
57 };
58 
59 /* prototypes */
60 extern void p_amqp_init_host(struct p_amqp_host *);
61 extern void p_amqp_init_routing_key_rr(struct p_amqp_host *);
62 
63 extern void p_amqp_set_user(struct p_amqp_host *, char *);
64 extern void p_amqp_set_passwd(struct p_amqp_host *, char *);
65 extern void p_amqp_set_exchange(struct p_amqp_host *, char *);
66 extern void p_amqp_set_routing_key(struct p_amqp_host *, char *);
67 extern void p_amqp_set_routing_key_rr(struct p_amqp_host *, int);
68 extern void p_amqp_set_exchange_type(struct p_amqp_host *, char *);
69 extern void p_amqp_set_host(struct p_amqp_host *, char *);
70 extern void p_amqp_set_vhost(struct p_amqp_host *, char *);
71 extern void p_amqp_set_persistent_msg(struct p_amqp_host *, int);
72 extern void p_amqp_set_frame_max(struct p_amqp_host *, u_int32_t);
73 extern void p_amqp_set_heartbeat_interval(struct p_amqp_host *, int);
74 extern void p_amqp_set_content_type_json(struct p_amqp_host *);
75 extern void p_amqp_set_content_type_binary(struct p_amqp_host *);
76 
77 extern char *p_amqp_get_routing_key(struct p_amqp_host *);
78 extern int p_amqp_get_routing_key_rr(struct p_amqp_host *);
79 extern int p_amqp_get_sockfd(struct p_amqp_host *);
80 extern void p_amqp_get_version();
81 
82 extern void p_amqp_unset_routing_key(struct p_amqp_host *);
83 
84 extern int p_amqp_connect_to_publish(struct p_amqp_host *);
85 extern int p_amqp_publish_string(struct p_amqp_host *, char *);
86 extern int p_amqp_publish_binary(struct p_amqp_host *, void *, u_int32_t);
87 extern void p_amqp_close(struct p_amqp_host *, int);
88 extern int p_amqp_is_alive(struct p_amqp_host *);
89 
90 extern int write_and_free_json_amqp(void *, void *);
91 extern int write_binary_amqp(void *, void *, size_t);
92 extern int write_string_amqp(void *, char *);
93 
94 /* global vars */
95 extern struct p_amqp_host amqpp_amqp_host;
96 extern struct p_amqp_host bgp_daemon_msglog_amqp_host;
97 extern struct p_amqp_host bgp_table_dump_amqp_host;
98 extern struct p_amqp_host bmp_daemon_msglog_amqp_host;
99 extern struct p_amqp_host bmp_dump_amqp_host;
100 extern struct p_amqp_host sfacctd_counter_amqp_host;
101 extern struct p_amqp_host telemetry_daemon_msglog_amqp_host;
102 extern struct p_amqp_host telemetry_dump_amqp_host;
103 
104 extern char rabbitmq_user[];
105 extern char rabbitmq_pwd[];
106 extern char default_amqp_exchange[];
107 extern char default_amqp_exchange_type[];
108 extern char default_amqp_routing_key[];
109 extern char default_amqp_host[];
110 extern char default_amqp_vhost[];
111 
112 #endif //AMQP_COMMON_H
113