Skip to content

Commit bcdb7a4

Browse files
committed
err netconf UPDATE send all edit errors
1 parent aea3d5e commit bcdb7a4

File tree

1 file changed

+150
-128
lines changed

1 file changed

+150
-128
lines changed

src/err_netconf.c

Lines changed: 150 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -168,148 +168,170 @@ np_err_sr2nc_edit(sr_session_ctx_t *ev_sess, const sr_session_ctx_t *err_sess)
168168
{
169169
const sr_error_info_t *err_info;
170170
const sr_error_info_err_t *err;
171-
const char *ptr, *ptr2;
171+
const char *ptr, *ptr2, *etype, *etag, *eatag, *epath, *emsg, **einfoelems, **einfovals;
172172
char *path = NULL, *str = NULL, *str2 = NULL;
173+
uint32_t i, einfocount;
173174

174-
/* get the error */
175+
/* get the errors */
175176
sr_session_get_error((sr_session_ctx_t *)err_sess, &err_info);
176177
assert(err_info);
177-
err = &err_info->err[0];
178-
179-
/* get path */
180-
if ((ptr = strstr(err->message, "(path \""))) {
181-
ptr += 7;
182-
}
183-
if (ptr) {
184-
path = strndup(ptr, strchr(ptr, '\"') - ptr);
185-
}
186178

187-
if (!strncmp(err->message, "Unique data leaf(s)", 19)) {
188-
/* data-not-unique */
189-
assert(path);
190-
sr_session_set_netconf_error(ev_sess, "protocol", "operation-failed", "data-not-unique", NULL,
191-
"Unique constraint violated.", 1, "non-unique", path);
192-
} else if (!strncmp(err->message, "Too many", 8)) {
193-
/* too-many-elements */
194-
assert(path);
195-
sr_session_set_netconf_error(ev_sess, "protocol", "operation-failed", "too-many-elements", path,
196-
"Too many elements.", 0);
197-
} else if (!strncmp(err->message, "Too few", 7)) {
198-
/* too-few-elements */
199-
assert(path);
200-
sr_session_set_netconf_error(ev_sess, "protocol", "operation-failed", "too-few-elements", path,
201-
"Too few elements.", 0);
202-
} else if (!strncmp(err->message, "Must condition", 14)) {
203-
/* get the must condition error message */
204-
ptr = strrchr(err->message, '(');
205-
--ptr;
206-
str = strndup(err->message, ptr - err->message);
207-
208-
/* must-violation */
209-
assert(path);
210-
sr_session_set_netconf_error(ev_sess, "protocol", "operation-failed", "must-violation", path, str, 0);
211-
} else if (!strncmp(err->message, "Invalid leafref value", 21) && strstr(err->message, "no target instance")) {
212-
/* get the value */
213-
assert(err->message[22] == '\"');
214-
ptr = strchr(err->message + 23, '\"');
215-
216-
/* create error message */
217-
if (asprintf(&str, "Required leafref target with value \"%.*s\" missing.", (int)(ptr - (err->message + 23)),
218-
err->message + 23) == -1) {
219-
goto mem_error;
179+
for (i = 0; i < err_info->err_count; ++i) {
180+
err = &err_info->err[i];
181+
182+
if (err->error_format && !strcmp(err->error_format, "NETCONF")) {
183+
/* just copy the NETCONF error */
184+
if (sr_err_get_netconf_error(err, &etype, &etag, &eatag, &epath, &emsg, &einfoelems, &einfovals, &einfocount)) {
185+
goto mem_error;
186+
}
187+
sr_session_set_netconf_error2(ev_sess, etype, etag, eatag, epath, emsg, einfocount, einfoelems, einfovals);
188+
free(einfoelems);
189+
free(einfovals);
190+
continue;
220191
}
221192

222-
/* instance-required */
223-
assert(path);
224-
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", "instance-required", path, str, 0);
225-
} else if (!strncmp(err->message, "Invalid instance-identifier", 26) && strstr(err->message, "required instance not found")) {
226-
/* get the value */
227-
assert(err->message[28] == '\"');
228-
ptr = strchr(err->message + 29, '\"');
229-
230-
/* create error message */
231-
if (asprintf(&str, "Required instance-identifier \"%.*s\" missing.", (int)(ptr - (err->message + 29)),
232-
err->message + 29) == -1) {
233-
goto mem_error;
193+
/* get path */
194+
if ((ptr = strstr(err->message, "(path \""))) {
195+
ptr += 7;
234196
}
235-
236-
/* instance-required */
237-
assert(path);
238-
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", "instance-required", path, str, 0);
239-
} else if (!strncmp(err->message, "Mandatory choice", 16)) {
240-
/* get the choice */
241-
assert(path);
242-
assert(err->message[17] == '\"');
243-
ptr = err->message + 18;
244-
ptr2 = strchr(ptr, '\"');
245-
if (asprintf(&str, "%s/%.*s", path, (int)(ptr2 - ptr), ptr) == -1) {
246-
goto mem_error;
197+
if (ptr) {
198+
path = strndup(ptr, strchr(ptr, '\"') - ptr);
199+
if (!path) {
200+
goto mem_error;
201+
}
247202
}
248203

249-
/* missing-choice */
250-
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", "mandatory-choice", path,
251-
"Missing mandatory choice.", 1, "missing-choice", str);
252-
} else if (strstr(err->message, "instance to insert next to not found.")) {
253-
/* get the node name */
254-
assert(err->message[5] == '\"');
255-
ptr = strchr(err->message + 6, '\"');
256-
257-
/* create error message */
258-
if (asprintf(&str, "Missing insert anchor \"%.*s\" instance.", (int)(ptr - (err->message + 6)),
259-
err->message + 6) == -1) {
260-
goto mem_error;
204+
if (!strncmp(err->message, "Unique data leaf(s)", 19)) {
205+
/* data-not-unique */
206+
assert(path);
207+
sr_session_set_netconf_error(ev_sess, "protocol", "operation-failed", "data-not-unique", NULL,
208+
"Unique constraint violated.", 1, "non-unique", path);
209+
} else if (!strncmp(err->message, "Too many", 8)) {
210+
/* too-many-elements */
211+
assert(path);
212+
sr_session_set_netconf_error(ev_sess, "protocol", "operation-failed", "too-many-elements", path,
213+
"Too many elements.", 0);
214+
} else if (!strncmp(err->message, "Too few", 7)) {
215+
/* too-few-elements */
216+
assert(path);
217+
sr_session_set_netconf_error(ev_sess, "protocol", "operation-failed", "too-few-elements", path,
218+
"Too few elements.", 0);
219+
} else if (!strncmp(err->message, "Must condition", 14)) {
220+
/* get the must condition error message */
221+
ptr = strrchr(err->message, '(');
222+
--ptr;
223+
str = strndup(err->message, ptr - err->message);
224+
225+
/* must-violation */
226+
assert(path);
227+
sr_session_set_netconf_error(ev_sess, "protocol", "operation-failed", "must-violation", path, str, 0);
228+
} else if (!strncmp(err->message, "Invalid leafref value", 21) && strstr(err->message, "no target instance")) {
229+
/* get the value */
230+
assert(err->message[22] == '\"');
231+
ptr = strchr(err->message + 23, '\"');
232+
233+
/* create error message */
234+
if (asprintf(&str, "Required leafref target with value \"%.*s\" missing.", (int)(ptr - (err->message + 23)),
235+
err->message + 23) == -1) {
236+
goto mem_error;
237+
}
238+
239+
/* instance-required */
240+
assert(path);
241+
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", "instance-required", path, str, 0);
242+
} else if (!strncmp(err->message, "Invalid instance-identifier", 26) && strstr(err->message, "required instance not found")) {
243+
/* get the value */
244+
assert(err->message[28] == '\"');
245+
ptr = strchr(err->message + 29, '\"');
246+
247+
/* create error message */
248+
if (asprintf(&str, "Required instance-identifier \"%.*s\" missing.", (int)(ptr - (err->message + 29)),
249+
err->message + 29) == -1) {
250+
goto mem_error;
251+
}
252+
253+
/* instance-required */
254+
assert(path);
255+
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", "instance-required", path, str, 0);
256+
} else if (!strncmp(err->message, "Mandatory choice", 16)) {
257+
/* get the choice */
258+
assert(path);
259+
assert(err->message[17] == '\"');
260+
ptr = err->message + 18;
261+
ptr2 = strchr(ptr, '\"');
262+
if (asprintf(&str, "%s/%.*s", path, (int)(ptr2 - ptr), ptr) == -1) {
263+
goto mem_error;
264+
}
265+
266+
/* missing-choice */
267+
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", "mandatory-choice", path,
268+
"Missing mandatory choice.", 1, "missing-choice", str);
269+
} else if (strstr(err->message, "instance to insert next to not found.")) {
270+
/* get the node name */
271+
assert(err->message[5] == '\"');
272+
ptr = strchr(err->message + 6, '\"');
273+
274+
/* create error message */
275+
if (asprintf(&str, "Missing insert anchor \"%.*s\" instance.", (int)(ptr - (err->message + 6)),
276+
err->message + 6) == -1) {
277+
goto mem_error;
278+
}
279+
280+
/* missing-instance */
281+
sr_session_set_netconf_error(ev_sess, "protocol", "bad-attribute", "missing-instance", NULL, str, 0);
282+
} else if (strstr(err->message, "to be created already exists.")) {
283+
/* data-exists */
284+
sr_session_set_netconf_error(ev_sess, "protocol", "data-exists", NULL, NULL, err->message, 0);
285+
} else if (strstr(err->message, "to be deleted does not exist.")) {
286+
/* data-missing */
287+
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", NULL, NULL, err->message, 0);
288+
} else if (strstr(err->message, "does not exist.")) {
289+
/* data-missing */
290+
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", NULL, NULL, err->message, 0);
291+
} else if (!strncmp(err->message, "Invalid type", 12) || !strncmp(err->message, "Unsatisfied range", 17) ||
292+
!strncmp(err->message, "Unsatisfied pattern", 19) || strstr(err->message, "min/max bounds")) {
293+
/* create error message */
294+
str = strndup(err->message, (strrchr(err->message, '(') - 1) - err->message);
295+
296+
/* bad-element */
297+
assert(path);
298+
sr_session_set_netconf_error(ev_sess, "application", "bad-element", NULL, NULL, str, 1, "bad-element", path);
299+
} else if (!strncmp(err->message, "Node \"", 6) && strstr(err->message, " not found")) {
300+
/* get the node name */
301+
assert(err->message[5] == '\"');
302+
ptr = strchr(err->message + 6, '\"');
303+
str = strndup(err->message + 6, ptr - (err->message + 6));
304+
305+
/* unknown-element */
306+
sr_session_set_netconf_error(ev_sess, "application", "unknown-element", NULL, NULL, err->message, 1,
307+
"bad-element", str);
308+
} else if (!strncmp(err->message, "No (implemented) module with namespace", 38)) {
309+
/* get the namespace */
310+
ptr = strchr(err->message, '\"') + 1;
311+
ptr2 = strchr(ptr, '\"');
312+
str = strndup(ptr, ptr2 - ptr);
313+
314+
/* get the node name */
315+
ptr = strchr(ptr2 + 1, '\"') + 1;
316+
ptr2 = strchr(ptr, '\"');
317+
str2 = strndup(ptr, ptr2 - ptr);
318+
319+
/* unknown-namespace */
320+
sr_session_set_netconf_error(ev_sess, "application", "unknown-namespace", NULL, NULL,
321+
"An unexpected namespace is present.", 2, "bad-element", str2, "bad-namespace", str);
322+
} else {
323+
/* other error */
324+
np_err_operation_failed(ev_sess, err->message);
261325
}
262326

263-
/* missing-instance */
264-
sr_session_set_netconf_error(ev_sess, "protocol", "bad-attribute", "missing-instance", NULL, str, 0);
265-
} else if (strstr(err->message, "to be created already exists.")) {
266-
/* data-exists */
267-
sr_session_set_netconf_error(ev_sess, "protocol", "data-exists", NULL, NULL, err->message, 0);
268-
} else if (strstr(err->message, "to be deleted does not exist.")) {
269-
/* data-missing */
270-
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", NULL, NULL, err->message, 0);
271-
} else if (strstr(err->message, "does not exist.")) {
272-
/* data-missing */
273-
sr_session_set_netconf_error(ev_sess, "protocol", "data-missing", NULL, NULL, err->message, 0);
274-
} else if (!strncmp(err->message, "Invalid type", 12) || !strncmp(err->message, "Unsatisfied range", 17) ||
275-
!strncmp(err->message, "Unsatisfied pattern", 19) || strstr(err->message, "min/max bounds")) {
276-
/* create error message */
277-
str = strndup(err->message, (strrchr(err->message, '(') - 1) - err->message);
278-
279-
/* bad-element */
280-
assert(path);
281-
sr_session_set_netconf_error(ev_sess, "application", "bad-element", NULL, NULL, str, 1, "bad-element", path);
282-
} else if (!strncmp(err->message, "Node \"", 6) && strstr(err->message, " not found")) {
283-
/* get the node name */
284-
assert(err->message[5] == '\"');
285-
ptr = strchr(err->message + 6, '\"');
286-
str = strndup(err->message + 6, ptr - (err->message + 6));
287-
288-
/* unknown-element */
289-
sr_session_set_netconf_error(ev_sess, "application", "unknown-element", NULL, NULL, err->message, 1,
290-
"bad-element", str);
291-
} else if (!strncmp(err->message, "No (implemented) module with namespace", 38)) {
292-
/* get the namespace */
293-
ptr = strchr(err->message, '\"') + 1;
294-
ptr2 = strchr(ptr, '\"');
295-
str = strndup(ptr, ptr2 - ptr);
296-
297-
/* get the node name */
298-
ptr = strchr(ptr2 + 1, '\"') + 1;
299-
ptr2 = strchr(ptr, '\"');
300-
str2 = strndup(ptr, ptr2 - ptr);
301-
302-
/* unknown-namespace */
303-
sr_session_set_netconf_error(ev_sess, "application", "unknown-namespace", NULL, NULL,
304-
"An unexpected namespace is present.", 2, "bad-element", str2, "bad-namespace", str);
305-
} else {
306-
/* other error */
307-
sr_session_dup_error((sr_session_ctx_t *)err_sess, ev_sess);
327+
free(path);
328+
path = NULL;
329+
free(str);
330+
str = NULL;
331+
free(str2);
332+
str2 = NULL;
308333
}
309334

310-
free(path);
311-
free(str);
312-
free(str2);
313335
return;
314336

315337
mem_error:

0 commit comments

Comments
 (0)