8139b17a3a352f252ec0257d28f180fde615731f
[sim/o1-interface.git] / ntsimulator / ntsim-ng / features / web_cut_through / web_cut_through.c
1 /*************************************************************************
2 *
3 * Copyright 2020 highstreet technologies GmbH and others
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 ***************************************************************************/
17
18 #define _GNU_SOURCE
19
20 #include "web_cut_through.h"
21 #include "utils/log_utils.h"
22 #include "utils/sys_utils.h"
23 #include "utils/rand_utils.h"
24 #include "utils/http_client.h"
25 #include "utils/nts_utils.h"
26 #include <stdio.h>
27 #include <assert.h>
28
29 #include "core/session.h"
30 #include "core/framework.h"
31
32 #define SYSTEM_NAME_SCHEMA_XPATH                "/ietf-system:system/onap-system:name"
33 #define SYSTEM_WEB_UI_SCHEMA_XPATH              "/ietf-system:system/onap-system:web-ui"
34
35
36 int web_cut_through_feature_start(sr_session_ctx_t *current_session) {
37     assert(current_session);
38     assert_session();
39
40     int rc = 0;
41
42     //update ietf-system details
43     rc = sr_set_item_str(current_session, SYSTEM_NAME_SCHEMA_XPATH, framework_environment.hostname, 0, 0);
44     if(rc != SR_ERR_OK) {
45         log_error("sr_set_item_str failed");
46         return NTS_ERR_FAILED;
47     }
48
49     controller_details_t *controller_details = controller_details_get(current_session);
50     if(controller_details == 0) {
51         log_error("controller_details_get failed");
52         return NTS_ERR_FAILED;
53     }
54
55     char *web_ui = 0;
56     asprintf(&web_ui, "%s/odlux/index.html#/about", controller_details->base_url);
57     controller_details_free(controller_details);
58
59     if(web_ui == 0) {
60         log_error("asprintf failed");
61         return NTS_ERR_FAILED;
62     }
63
64     rc = sr_set_item_str(current_session, SYSTEM_WEB_UI_SCHEMA_XPATH, web_ui, 0, 0);
65     free(web_ui);
66     if(rc != SR_ERR_OK) {
67         log_error("sr_set_item_str failed");
68         return NTS_ERR_FAILED;
69     }
70
71     rc = sr_apply_changes(current_session, 0, 0);
72     if(rc != SR_ERR_OK) {
73         log_error("could not apply changes on datastore");
74         return NTS_ERR_FAILED;
75     }
76
77     return NTS_ERR_OK;
78 }