+ amfree(include_file);
+ amfree(include_list);
+ amfree(exc);
+ amfree(decrypt_opt);
+ amfree(encrypt_opt);
+
+ /* result contains at least 'auth=...' */
+ return result;
+}
+
+
+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);