1 /*
2  * Copyright (c) 2020 One Identity
3  * Copyright (c) 2020 Laszlo Budai <laszlo.budai@outlook.com>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published
7  * by the Free Software Foundation, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  *
22  */
23 
24 #include "http-test-slots.h"
25 #include "modules/http/http-signals.h"
26 
27 #define HTTP_TEST_SLOTS_PLUGIN "http-test-slots"
28 
29 struct _HttpTestSlotsPlugin
30 {
31   LogDriverPlugin super;
32   gchar *header;
33 };
34 
35 void
http_test_slots_plugin_set_header(HttpTestSlotsPlugin * self,const gchar * header)36 http_test_slots_plugin_set_header(HttpTestSlotsPlugin *self, const gchar *header)
37 {
38   g_free(self->header);
39   self->header = g_strdup(header);
40 }
41 
42 static void
_slot_append_test_headers(HttpTestSlotsPlugin * self,HttpHeaderRequestSignalData * data)43 _slot_append_test_headers(HttpTestSlotsPlugin *self, HttpHeaderRequestSignalData *data)
44 {
45   list_append(data->request_headers, self->header);
46 }
47 
48 static gboolean
_attach(LogDriverPlugin * s,LogDriver * driver)49 _attach(LogDriverPlugin *s, LogDriver *driver)
50 {
51   SignalSlotConnector *ssc = driver->super.signal_slot_connector;
52 
53   msg_debug("HttpTestSlotsPlugin::attach()",
54             evt_tag_printf("SignalSlotConnector", "%p", ssc));
55 
56   /* DISCONNECT: the whole SignalSlotConnector is destroyed when the owner LogDriver is freed up, so DISCONNECT is not required */
57   CONNECT(ssc, signal_http_header_request, _slot_append_test_headers, s);
58 
59   return TRUE;
60 }
61 
62 static void
_free(LogDriverPlugin * s)63 _free(LogDriverPlugin *s)
64 {
65   msg_debug("HttpTestSlotsPlugin::free");
66   HttpTestSlotsPlugin *self = (HttpTestSlotsPlugin *)s;
67   g_free(self->header);
68   log_driver_plugin_free_method(s);
69 }
70 
71 HttpTestSlotsPlugin *
http_test_slots_plugin_new(void)72 http_test_slots_plugin_new(void)
73 {
74   HttpTestSlotsPlugin *self = g_new0(HttpTestSlotsPlugin, 1);
75 
76   log_driver_plugin_init_instance(&self->super, HTTP_TEST_SLOTS_PLUGIN);
77 
78   self->super.attach = _attach;
79   self->super.free_fn = _free;
80 
81   return self;
82 }
83