|
@@ -131,6 +131,9 @@ static bool_t ktpd_session_process_cmd(ktpd_session_t *ktpd, faux_msg_t *msg)
|
|
|
bool_t dry_run = BOOL_FALSE;
|
|
|
uint32_t status = KTP_STATUS_NONE;
|
|
|
bool_t ret = BOOL_TRUE;
|
|
|
+ kpath_levels_node_t *iter = NULL;
|
|
|
+ klevel_t *level = NULL;
|
|
|
+ char *prompt = NULL;
|
|
|
|
|
|
assert(ktpd);
|
|
|
assert(msg);
|
|
@@ -170,19 +173,56 @@ static bool_t ktpd_session_process_cmd(ktpd_session_t *ktpd, faux_msg_t *msg)
|
|
|
status |= KTP_STATUS_EXIT;
|
|
|
}
|
|
|
|
|
|
+ // Generate prompt
|
|
|
+ iter = kpath_iterr(ksession_path(ktpd->session));
|
|
|
+ while ((level = kpath_eachr(&iter))) {
|
|
|
+ const kentry_t *view = klevel_entry(level);
|
|
|
+ kentry_t *prompt_entry = kentry_nested_by_purpose(view,
|
|
|
+ KENTRY_PURPOSE_PROMPT);
|
|
|
+
|
|
|
+ if (!prompt_entry)
|
|
|
+ continue;
|
|
|
+
|
|
|
+ if (kentry_actions_len(prompt_entry) > 0) {
|
|
|
+ int rc = -1;
|
|
|
+ bool_t res = BOOL_FALSE;
|
|
|
+
|
|
|
+ res = ksession_exec_locally(ktpd->session,
|
|
|
+ prompt_entry, NULL, &rc, &prompt);
|
|
|
+ if (!res || (rc < 0) || !prompt) {
|
|
|
+ if (prompt)
|
|
|
+ faux_str_free(prompt);
|
|
|
+ prompt = NULL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!prompt) {
|
|
|
+ if (kentry_value(prompt_entry))
|
|
|
+ prompt = faux_str_dup(kentry_value(prompt_entry));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (prompt)
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ faux_msg_t *ack = ktp_msg_preform(cmd, status);
|
|
|
if (rc) {
|
|
|
uint8_t retcode8bit = 0;
|
|
|
- faux_msg_t *ack = ktp_msg_preform(cmd, status);
|
|
|
retcode8bit = (uint8_t)(retcode & 0xff);
|
|
|
faux_msg_add_param(ack, KTP_PARAM_RETCODE, &retcode8bit, 1);
|
|
|
- faux_msg_send_async(ack, ktpd->async);
|
|
|
- faux_msg_free(ack);
|
|
|
} else {
|
|
|
+ faux_msg_set_status(ack, KTP_STATUS_ERROR);
|
|
|
char *err = faux_error_cstr(error);
|
|
|
- ktp_send_error(ktpd->async, cmd, err);
|
|
|
+ faux_msg_add_param(ack, KTP_PARAM_ERROR, err, strlen(err));
|
|
|
faux_str_free(err);
|
|
|
ret = BOOL_FALSE;
|
|
|
}
|
|
|
+ if (prompt) {
|
|
|
+ faux_msg_add_param(ack, KTP_PARAM_PROMPT, prompt, strlen(prompt));
|
|
|
+ faux_str_free(prompt);
|
|
|
+ }
|
|
|
+ faux_msg_send_async(ack, ktpd->async);
|
|
|
+ faux_msg_free(ack);
|
|
|
|
|
|
faux_error_free(error);
|
|
|
|