// take the command field in target_host and substitute away any string of type {key with}
// the actual value of the key if it is defined. if not defined, null will be placed
gboolean perform_cmd_substition(struct host* target_host, gchar** resultant_cmd, int var_len, ...) {
GList *key_node = target_host->keys;
gchar* s;
gchar* key = NULL;
gchar* value = NULL;
gchar* ret = g_strdup(target_host->cmd);
va_list ap;
va_start(ap, var_len);
while (var_len--) {
gchar *temp;
s = va_arg(ap, gchar *);
key = str_unpack_key(s);
value = str_unpack_value(s);
if (key == NULL || value == NULL) {
if (key) free(key);
if (value) free(value);
g_warning("perform_cmd_substition:malformed substition\n");
continue;
}
// case sensitive string replace
temp = str_replace(ret, key, value);
g_assert(temp != NULL);
// dump the old return string and replace it with the replaced string
free(ret);
free(key);
free(value);
ret = temp;
}
va_end(ap);