+ record_opt = " <record>YES</record>\n";
+ }
+
+ if(dp->index) {
+ index_opt = " <index>YES</index>\n";
+ }
+
+ if (dp->kencrypt) {
+ kencrypt_opt = " <kencrypt>YES</kencrypt>\n";
+ }
+
+ if (am_has_feature(their_features, fe_xml_data_path)) {
+ switch(dp->data_path) {
+ case DATA_PATH_AMANDA:
+ 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;
+
+ 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(exclude);
+ amfree(exclude_list);
+ amfree(exclude_file);
+ amfree(include);
+ amfree(include_file);
+ amfree(include_list);
+ amfree(exc);
+ amfree(decrypt_opt);
+ amfree(encrypt_opt);
+
+ /* result contains at least 'auth=...' */
+ return 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)
+{
+ char *rval_dle_str;
+ char *hack1, *hack2;
+
+ if (!dle_str)
+ return NULL;
+
+ rval_dle_str = stralloc(dle_str);
+
+ /* Remove everything between " <encrypt>SERVER-CUSTOM" and "</encrypt>\n"
+ */
+#define SC "</encrypt>\n"
+#define SC_LEN strlen(SC)
+ hack1 = strstr(rval_dle_str, " <encrypt>SERVER-CUSTOM");
+ if (hack1) {
+ hack2 = strstr(hack1, SC);
+ /* +1 is to also move the trailing '\0' */
+ memmove(hack1, hack2 + SC_LEN, strlen(hack2 + SC_LEN) + 1);
+ }
+#undef SC
+#undef SC_LEN
+
+ return rval_dle_str;
+}
+
+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 *property_s = key_p;
+ char *b64property;
+ property_t *property = value_p;
+ char *b64value_data;
+ xml_app_t *xml_app = user_data_p;
+ GSList *value;
+
+ b64property = amxml_format_tag("name", property_s);
+ vstrextend(&xml_app->result, " <property>\n",
+ " ", b64property, "\n", NULL);
+ // TODO if client have fe_xml_property_priority
+ if (property->priority &&
+ am_has_feature(xml_app->features, fe_xml_property_priority)) {
+ vstrextend(&xml_app->result, " <priority>yes</priority>\n", NULL);
+ }
+ for(value = property->values; value != NULL; value = value->next) {
+ b64value_data = amxml_format_tag("value", value->data);
+ vstrextend(&xml_app->result, " ", b64value_data, "\n", NULL);
+ amfree(b64value_data);