mod_netconf: url-capability copy-config
add json parameters:
'uri_source' (needed when source is 'url')
'uri_target' (needed when target is 'url')
- refs #1362
diff --git a/src/README b/src/README
index 88fb080..71b62db 100644
--- a/src/README
+++ b/src/README
@@ -105,7 +105,12 @@
6) NETCONF <copy-config>
key: type (int), value: 9
key: session (string), value: unique session identifier
-key: target (string), value: running|startup|candidate
+key: source (string), value: running|startup|candidate|url
+key: target (string), value: running|startup|candidate|url
+Optional, required when "url" is used:
+key: uri_source (string), required when "source" is "url", value: uri
+key: uri_target (string), required when "target" is "url", value: uri
+
Alternating:
key: source (string), value: running|startup|candidate
diff --git a/src/mod_netconf.c b/src/mod_netconf.c
index 142ea0f..8e5b6bc 100644
--- a/src/mod_netconf.c
+++ b/src/mod_netconf.c
@@ -721,22 +721,34 @@
return (data);
}
-static json_object *netconf_copyconfig(const char* session_key, NC_DATASTORE source, NC_DATASTORE target, const char* config, const char *url)
+static json_object *netconf_copyconfig(const char* session_key, NC_DATASTORE source, NC_DATASTORE target, const char* config, const char *uri_src, const char *uri_trg)
{
nc_rpc* rpc;
json_object *res = NULL;
/* create requests */
- if ((source == NC_DATASTORE_CONFIG) || (source == NC_DATASTORE_URL)) {
+ if (source == NC_DATASTORE_CONFIG) {
if (target == NC_DATASTORE_URL) {
- rpc = nc_rpc_copyconfig(source, target, config, url);
+ /* config, url */
+ rpc = nc_rpc_copyconfig(source, target, config, uri_trg);
} else {
+ /* config, datastore */
rpc = nc_rpc_copyconfig(source, target, config);
}
+ } else if (source == NC_DATASTORE_URL) {
+ if (target == NC_DATASTORE_URL) {
+ /* url, url */
+ rpc = nc_rpc_copyconfig(source, target, uri_src, uri_trg);
+ } else {
+ /* url, datastore */
+ rpc = nc_rpc_copyconfig(source, target, uri_src);
+ }
} else {
if (target == NC_DATASTORE_URL) {
- rpc = nc_rpc_copyconfig(source, target, url);
+ /* datastore, url */
+ rpc = nc_rpc_copyconfig(source, target, uri_trg);
} else {
+ /* datastore, datastore */
rpc = nc_rpc_copyconfig(source, target);
}
}
@@ -1244,6 +1256,9 @@
const char *config = NULL;
const char *target = NULL;
const char *source = NULL;
+ const char *uri_src = NULL;
+ const char *uri_trg = NULL;
+
json_object *reply = NULL;
DEBUG("Request: copy-config (session %s)", session_key);
@@ -1269,15 +1284,28 @@
return create_error("Invalid target repository type requested.");
}
- if (source == NULL && config == NULL) {
- reply = create_error("invalid input parameters - one of source and config is required.");
- } else {
- reply = netconf_copyconfig(session_key, ds_type_s, ds_type_t, config, "");
- if (reply == NULL) {
- if (err_reply != NULL) {
- /* use filled err_reply from libnetconf's callback */
- reply = err_reply;
- }
+ if (source == NULL || config == NULL) {
+ reply = create_error("invalid input parameters - source and config is required.");
+ return reply;
+ }
+
+ if (ds_type_s == NC_DATASTORE_URL) {
+ uri_src = json_object_get_string(json_object_object_get(request, "uri_source"));
+ if (uri_src == NULL) {
+ uri_src = "";
+ }
+ }
+ if (ds_type_t == NC_DATASTORE_URL) {
+ uri_trg = json_object_get_string(json_object_object_get(request, "uri_target"));
+ if (uri_trg == NULL) {
+ uri_trg = "";
+ }
+ }
+ reply = netconf_copyconfig(session_key, ds_type_s, ds_type_t, config, uri_src, uri_trg);
+ if (reply == NULL) {
+ if (err_reply != NULL) {
+ /* use filled err_reply from libnetconf's callback */
+ reply = err_reply;
}
}
return reply;