Newer
Older
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
/*
* event.c: event handler
*
* Copyright (C) 2023 IOPSYS Software Solutions AB. All rights reserved.
*
* Author: Iryna Antsyferova <iryna.antsyferova@iopsys.eu>
*
* See LICENSE file for license related information.
*/
#include "libdmtree/dmcommon.h"
#include "event.h"
#include <unistd.h>
#define FIREWALL_RULE_DATA "Device.Services.VoiceService.%d.X_RDK_Firewall_Rule_Data"
#define FIREWALL_RULE_DATA_PATTERN "Device\\.Services\\.VoiceService\\.[0-9]+\\.X_RDK_Firewall_Rule_Data"
int subs_event_handler(const json_object *jmsg, int param_count, json_object *jreply)
{
int ret = RETURN_OK;
int param_index = 0;
hal_subscribe_event_request_t param_request;
if (jmsg == NULL || jreply == NULL) {
ERR("event handler: Invalid memory");
return RETURN_ERR;
}
memset(¶m_request, 0, sizeof(param_request));
for (param_index = 0; param_index < param_count; param_index++) {
/* Unpack the request parameter */
if (json_hal_get_subscribe_event_request((json_object *)jmsg,
param_index, ¶m_request) != RETURN_OK) {
INFO("Failed to get subscription data from the server");
return RETURN_ERR;
}
if (!match(param_request.name, FIREWALL_RULE_DATA_PATTERN, 0, NULL)) {
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
ret = RETURN_ERR;
WARNING("Unexpected event [%s][%d]", param_request.name, (int)param_request.type);
}
else
INFO("Subscribed [%s][%d]", param_request.name, (int)param_request.type);
}
ret = json_hal_add_result_status(jreply, ret == RETURN_OK ? RESULT_SUCCESS :
RESULT_FAILURE);
INFO("[%s] Replly msg = %s", __FUNCTION__,
json_object_to_json_string_ext(jreply, JSON_C_TO_STRING_PRETTY));
return ret;
}
/* Expected format of rule : enable/disable,protocol,port,ip;
Ex: 1,sip,5060,2a02:c69:fe02::4;
1,sip,5060,2a02:c69:fe02::4;1,rtp,50000,2a02:c69:fe02::4;
1,sip,5060,2a02:c69:fe02::4;0,rtp,50000,2a02:c69:fe02::4;1,rtp,50001,2a02:c69:fe02::4; */
static void create_fw_rule_payload(char **buf, bool enable, char *protocol, int port, char *ip)
{
dmasprintf(buf, "%d,%s,%d,%s;", enable, protocol, port, ip);
}
int send_fw_rule_event(bool enable, char *protocol, int port, char *ip, int voice_service_idx)
{
int ret = 0;
char *fw_rule_path = NULL;
char *fw_rule = NULL;
create_fw_rule_payload(&fw_rule, enable, protocol, port, ip);
dmasprintf(&fw_rule_path, FIREWALL_RULE_DATA, voice_service_idx);
ret = (json_hal_server_publish_event(fw_rule_path, fw_rule) == RETURN_OK) ? 0 : -1;
dmfree(fw_rule_path);
dmfree(fw_rule);
return ret;
}
int send_fw_rules_clear_event(int voice_service_idx)
{
int ret = 0;
char *fw_rule_path = NULL;
char fw_rule[] = {0};
dmasprintf(&fw_rule_path, FIREWALL_RULE_DATA, voice_service_idx);
ret = (json_hal_server_publish_event(fw_rule_path, fw_rule) == RETURN_OK) ? 0 : -1;
dmfree(fw_rule_path);
return ret;
}