+ return result;
+}
+
+typedef struct {
+ am_feature_t *features;
+ char *result;
+} xml_app_t;
+
+/* A GHFunc (callback for g_hash_table_foreach) */
+static void xml_property(
+ gpointer key_p,
+ gpointer value_p,
+ gpointer user_data_p)
+{
+ char *tmp;
+ property_t *property = value_p;
+ xml_app_t *xml_app = user_data_p;
+ GSList *value;
+ GString *strbuf;
+
+ strbuf = g_string_new(xml_app->result);
+
+ tmp = amxml_format_tag("name", (char *)key_p);
+ g_string_append_printf(strbuf, " <property>\n %s\n", tmp);
+ g_free(tmp);
+
+ // TODO if client have fe_xml_property_priority
+ if (property->priority
+ && am_has_feature(xml_app->features, fe_xml_property_priority))
+ g_string_append(strbuf, " <priority>yes</priority>\n");
+
+ for (value = property->values; value != NULL; value = value->next) {
+ tmp = amxml_format_tag("value", value->data);
+ g_string_append_printf(strbuf, " %s", tmp);
+ g_free(tmp);
+ }
+ g_string_append_printf(strbuf, "\n </property>\n");
+
+ g_free(xml_app->result);
+ xml_app->result = g_string_free(strbuf, FALSE);
+}
+
+char *
+xml_optionstr(
+ disk_t * dp,
+ int to_server)
+{
+ char *auth_opt;
+ char *kencrypt_opt;
+ char *compress_opt;
+ char *encrypt_opt = stralloc("");
+ char *decrypt_opt = stralloc("");
+ char *record_opt;
+ char *index_opt;
+ char *data_path_opt = stralloc("");
+ char *exclude = stralloc("");
+ char *exclude_file = NULL;
+ char *exclude_list = NULL;
+ char *include = stralloc("");
+ char *include_file = NULL;
+ char *include_list = NULL;
+ char *excl_opt = "";
+ char *incl_opt = "";
+ char *exc = NULL;
+ char *script_opt;
+ char *result = NULL;
+ sle_t *excl;
+ char *qdpname;
+ char *q64name;
+ am_feature_t *their_features = dp->host->features;
+
+ assert(dp != NULL);
+ assert(dp->host != NULL);
+
+ qdpname = quote_string(dp->name);
+ if (am_has_feature(their_features, fe_options_auth)) {
+ auth_opt = vstralloc(" <auth>", dp->auth, "</auth>\n", NULL);
+ } else {
+ auth_opt = stralloc("");
+ }
+
+ switch(dp->compress) {
+ case COMP_FAST:
+ compress_opt = stralloc(" <compress>FAST</compress>\n");
+ break;
+ case COMP_BEST:
+ compress_opt = stralloc(" <compress>BEST</compress>\n");
+ break;
+ case COMP_CUST:
+ compress_opt = vstralloc(" <compress>CUSTOM"
+ "<custom-compress-program>",
+ dp->clntcompprog,
+ "</custom-compress-program>\n"
+ " </compress>\n", NULL);
+ break;
+ case COMP_SERVER_FAST:
+ compress_opt = stralloc(" <compress>SERVER-FAST</compress>\n");
+ break;
+ case COMP_SERVER_BEST:
+ compress_opt = stralloc(" <compress>SERVER-BEST</compress>\n");
+ break;
+ case COMP_SERVER_CUST:
+ compress_opt = vstralloc(" <compress>SERVER-CUSTOM"
+ "<custom-compress-program>",
+ dp->srvcompprog,
+ "</custom-compress-program>\n"
+ " </compress>\n", NULL);
+ break;
+ default:
+ compress_opt = stralloc("");
+ }
+
+ switch(dp->encrypt) {
+ case ENCRYPT_CUST:
+ if (dp->clnt_decrypt_opt) {
+ decrypt_opt = newvstralloc(decrypt_opt,
+ " <decrypt-option>",
+ dp->clnt_decrypt_opt,
+ "</decrypt-option>\n", NULL);
+ }
+ if (decrypt_opt) {
+ encrypt_opt = newvstralloc(encrypt_opt,
+ " <encrypt>CUSTOM"
+ "<custom-encrypt-program>",
+ dp->clnt_encrypt,
+ "</custom-encrypt-program>\n",
+ decrypt_opt,
+ " </encrypt>\n", NULL);
+ }
+ break;
+ case ENCRYPT_SERV_CUST:
+ if (to_server) {
+ decrypt_opt = newvstralloc(decrypt_opt,
+ " <decrypt-option>",
+ dp->srv_decrypt_opt,
+ "</decrypt-option>\n", NULL);
+ encrypt_opt = newvstralloc(encrypt_opt,
+ " <encrypt>SERVER-CUSTOM"
+ "<custom-encrypt-program>",
+ dp->srv_encrypt,
+ "</custom-encrypt-program>\n",
+ decrypt_opt,
+ " </encrypt>\n", NULL);
+ }
+ break;
+ }
+
+ if (!dp->record) {
+ record_opt = " <record>NO</record>\n";
+ } else {
+ record_opt = " <record>YES</record>\n";
+ }
+
+ if(dp->index) {
+ index_opt = " <index>YES</index>\n";
+ } else {
+ index_opt = "";
+ }
+
+ if (dp->kencrypt) {
+ kencrypt_opt = " <kencrypt>YES</kencrypt>\n";
+ } else {
+ kencrypt_opt = "";
+ }
+
+ if (am_has_feature(their_features, fe_xml_data_path)) {
+ switch(dp->data_path) {
+ case DATA_PATH_AMANDA:
+ amfree(data_path_opt);
+ data_path_opt = stralloc(" <datapath>AMANDA</datapath>\n");
+ break;
+ case DATA_PATH_DIRECTTCP:
+ { /* dp->dataport_list is not set for selfcheck/sendsize */
+ if (am_has_feature(their_features, fe_xml_directtcp_list)) {
+ char *s, *sc;
+ char *value, *b64value;
+
+ amfree(data_path_opt);
+ data_path_opt = stralloc(" <datapath>DIRECTTCP");
+ if (dp->dataport_list) {
+ s = sc = stralloc(dp->dataport_list);
+ do {
+ value = s;
+ s = strchr(s, ';');
+ if (s) {
+ *s++ = '\0';
+ }
+
+ b64value = amxml_format_tag("directtcp", value);
+ vstrextend(&data_path_opt, "\n ", b64value, NULL);
+ amfree(b64value);
+ } while (s);
+ amfree(sc);
+ strappend(data_path_opt, "\n ");
+ }
+ strappend(data_path_opt, "</datapath>\n");
+ }
+ }
+ break;
+ }
+ }
+
+ exclude_file = stralloc("");
+ if (dp->exclude_file != NULL && dp->exclude_file->nb_element > 0) {
+ for(excl = dp->exclude_file->first; excl != NULL;
+ excl = excl->next) {
+ q64name = amxml_format_tag("file", excl->name);
+ exc = newvstralloc( exc, " ", q64name, "\n", NULL);
+ strappend(exclude_file, exc);
+ amfree(q64name);
+ }
+ }
+ exclude_list = stralloc("");
+ if (dp->exclude_list != NULL && dp->exclude_list->nb_element > 0) {
+ for(excl = dp->exclude_list->first; excl != NULL;
+ excl = excl->next) {
+ q64name = amxml_format_tag("list", excl->name);
+ exc = newvstralloc(exc, " ", q64name, "\n", NULL);
+ strappend(exclude_list, exc);
+ amfree(q64name);
+ }
+ }
+
+ include_file = stralloc("");
+ if (dp->include_file != NULL && dp->include_file->nb_element > 0) {
+ for(excl = dp->include_file->first; excl != NULL;
+ excl = excl->next) {
+ q64name = amxml_format_tag("file", excl->name);
+ exc = newvstralloc( exc, " ", q64name, "\n", NULL);
+ strappend(include_file, exc);
+ amfree(q64name);
+ }
+ }
+ include_list = stralloc("");
+ if (dp->include_list != NULL && dp->include_list->nb_element > 0) {
+ for(excl = dp->include_list->first; excl != NULL;
+ excl = excl->next) {
+ q64name = amxml_format_tag("list", excl->name);
+ exc = newvstralloc( exc, " ", q64name, "\n", NULL);
+ strappend(include_list, exc);
+ amfree(q64name);
+ }
+ }
+
+ if (dp->exclude_optional) {
+ excl_opt = " <optional>YES</optional>\n";
+ }
+ if (dp->include_optional) {
+ incl_opt = " <optional>YES</optional>\n";
+ }
+
+ if (dp->exclude_file || dp->exclude_list)
+ exclude = newvstralloc(exclude,
+ " <exclude>\n",
+ exclude_file,
+ exclude_list,
+ excl_opt,
+ " </exclude>\n", NULL);
+ if (dp->include_file || dp->include_list)
+ include = newvstralloc(include,
+ " <include>\n",
+ include_file,
+ include_list,
+ incl_opt,
+ " </include>\n", NULL);
+ script_opt = xml_scripts(dp->pp_scriptlist, their_features);
+ result = vstralloc(auth_opt,
+ kencrypt_opt,
+ compress_opt,
+ encrypt_opt,
+ record_opt,
+ index_opt,
+ data_path_opt,
+ exclude,
+ include,
+ script_opt,
+ NULL);
+
+ amfree(qdpname);
+ amfree(auth_opt);
+ amfree(data_path_opt);
+ amfree(compress_opt);
+ amfree(exclude);
+ amfree(exclude_list);
+ amfree(exclude_file);
+ amfree(include);
+ amfree(include_file);
+ amfree(include_list);
+ amfree(exc);
+ amfree(decrypt_opt);
+ amfree(encrypt_opt);
+ amfree(script_opt);
+
+ /* result contains at least 'auth=...' */
+ return result;
+}
+
+char *
+xml_dumptype_properties(
+ disk_t *dp)
+{
+ xml_app_t xml_dumptype;
+
+ xml_dumptype.result = g_strdup("");
+ xml_dumptype.features = NULL;
+ if (dp && dp->config) {
+ g_hash_table_foreach(dumptype_get_property(dp->config), xml_property,
+ &xml_dumptype);
+ }
+ return xml_dumptype.result;
+}
+
+char *
+xml_estimate(
+ estimatelist_t estimatelist,
+ am_feature_t *their_features)
+{
+ estimatelist_t el;
+ char *l = NULL;
+
+ if (am_has_feature(their_features, fe_xml_estimatelist)) {
+ vstrextend(&l, " <estimate>", NULL);
+ for (el=estimatelist; el != NULL; el = el->next) {
+ switch (GPOINTER_TO_INT(el->data)) {
+ case ES_CLIENT : vstrextend(&l, "CLIENT ", NULL); break;
+ case ES_SERVER : vstrextend(&l, "SERVER ", NULL); break;
+ case ES_CALCSIZE: vstrextend(&l, "CALCSIZE ", NULL); break;
+ }
+ }
+ vstrextend(&l, "</estimate>", NULL);
+ } else { /* add the first estimate only */
+ if (am_has_feature(their_features, fe_xml_estimate)) {
+ vstrextend(&l, " <estimate>", NULL);
+ switch (GPOINTER_TO_INT(estimatelist->data)) {
+ case ES_CLIENT : vstrextend(&l, "CLIENT", NULL); break;
+ case ES_SERVER : vstrextend(&l, "SERVER", NULL); break;
+ case ES_CALCSIZE: vstrextend(&l, "CALCSIZE", NULL); break;
+ }
+ }
+ vstrextend(&l, "</estimate>", NULL);
+ if (GPOINTER_TO_INT(estimatelist->data) == ES_CALCSIZE) {
+ vstrextend(&l, " <calcsize>YES</calcsize>", NULL);
+ }
+ }
+
+ return l;
+}
+
+char *
+clean_dle_str_for_client(
+ char *dle_str,
+ am_feature_t *their_features)
+{
+ char *rval_dle_str;
+ char *hack1, *hack2;
+ char *pend, *pscript, *pproperty, *eproperty;
+ int len;
+
+ if (!dle_str)