-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjshn.c
186 lines (145 loc) · 3.94 KB
/
jshn.c
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
/*
* 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.
*
* Copyright (C) 2013-2019 iopsys Software Solutions AB
* Author Mohamed Kallel <[email protected]>
* Author Ahmed Zribi <[email protected]>
* Copyright (C) 2012 Luka Perkov <[email protected]>
*/
#include <unistd.h>
#include <libubus.h>
#include <json-c/json.h>
#include "cwmp.h"
#include "external.h"
#include "log.h"
#include "jshn.h"
static json_object *jshn_obj = NULL;
static int jshn_message_parse(char **policy, int size, char **tb, char *msg)
{
int i;
json_object *obj;
jshn_obj = json_tokener_parse(msg);
if (jshn_obj == NULL || is_error(jshn_obj) ||
json_object_get_type(jshn_obj) != json_type_object)
{
jshn_obj = NULL;
return -1;
}
for (i=0; i<size; i++)
{
obj = json_object_object_get(jshn_obj, policy[i]);
if (obj == NULL || is_error(obj) ||
json_object_get_type(obj) != json_type_string)
continue;
tb[i] = (char *)json_object_get_string(obj);
}
return 0;
}
static inline void jshn_message_delete()
{
if(jshn_obj != NULL)
json_object_put(jshn_obj);
}
enum download_fault {
DOWNLOAD_FAULT,
__DOWNLOAD_MAX
};
char *download_fault_policy[] = {
[DOWNLOAD_FAULT] = "fault_code"
};
int
cwmp_handle_downloadFault(char *msg)
{
int tmp;
char *tb[__DOWNLOAD_MAX] = {0};
jshn_message_parse(download_fault_policy, ARRAYSIZEOF(download_fault_policy), tb, msg);
if (!tb[DOWNLOAD_FAULT])
goto error;
DD(INFO,"triggered handle download fault %s", tb[DOWNLOAD_FAULT]);
external_downloadFaultResp (tb[DOWNLOAD_FAULT]);
jshn_message_delete();
return 0;
error:
jshn_message_delete();
return -1;
}
enum upload_fault {
UPLOAD_FAULT,
__UPLOAD_MAX
};
char *upload_fault_policy[] = {
[UPLOAD_FAULT] = "fault_code"
};
int
cwmp_handle_uploadFault(char *msg)
{
int tmp;
char *tb[__UPLOAD_MAX] = {0};
jshn_message_parse(upload_fault_policy, ARRAYSIZEOF(upload_fault_policy), tb, msg);
if (!tb[UPLOAD_FAULT])
goto error;
DD(INFO,"triggered handle upload fault %s", tb[UPLOAD_FAULT]);
external_uploadFaultResp (tb[UPLOAD_FAULT]);
jshn_message_delete();
return 0;
error:
jshn_message_delete();
return -1;
}
enum dustatechange_fault {
DUState_Change_FAULT,
DUState_Change_VERSION,
DUState_Change_NAME,
DUState_Change_UUID,
DUState_Change_ENV,
__DUSTATE_MAX
};
char *dustatechange_fault_policy[] = {
[DUState_Change_FAULT] = "fault_code",
[DUState_Change_VERSION] = "package_version",
[DUState_Change_NAME] = "package_name",
[DUState_Change_UUID] = "package_uuid",
[DUState_Change_ENV] = "package_env"
};
int
cwmp_handle_dustate_changeFault(char *msg)
{
int tmp;
char *tb[__DUSTATE_MAX] = {0};
jshn_message_parse(dustatechange_fault_policy, ARRAYSIZEOF(dustatechange_fault_policy), tb, msg);
if (!tb[DUState_Change_FAULT])
goto error;
DD(INFO,"triggered handle dustate_change fault:%s version:%s name:%s", tb[DUState_Change_FAULT], tb[DUState_Change_VERSION], tb[DUState_Change_NAME], tb[DUState_Change_UUID], tb[DUState_Change_ENV]);
external_du_change_stateFaultResp (tb[DUState_Change_FAULT], tb[DUState_Change_VERSION], tb[DUState_Change_NAME], tb[DUState_Change_UUID], tb[DUState_Change_ENV]);
jshn_message_delete();
return 0;
error:
jshn_message_delete();
return -1;
}
enum uninstall_fault {
UNINSTALL_FAULT,
__UNINSTALL_MAX
};
char *uninstall_fault_policy[] = {
[UNINSTALL_FAULT] = "fault_code"
};
int
cwmp_handle_uninstallFault(char *msg)
{
int tmp;
char *tb[__UNINSTALL_MAX] = {0};
jshn_message_parse(uninstall_fault_policy, ARRAYSIZEOF(uninstall_fault_policy), tb, msg);
if (!tb[UNINSTALL_FAULT])
goto error;
DD(INFO,"triggered handle upload fault %s", tb[UNINSTALL_FAULT]);
external_uninstallFaultResp (tb[UNINSTALL_FAULT]);
jshn_message_delete();
return 0;
error:
jshn_message_delete();
return -1;
}