update client and server readme files
[debian/amanda] / common-src / amxml.c
index 3402ae8b0406c2764f2a0f7a281040e3e92f39bf..28b88aeea27b57fdc424913c7f05dfbe42a5959b 100644 (file)
@@ -76,6 +76,50 @@ alloc_dle(void)
     return dle;
 }
 
+void
+free_dle(
+    dle_t *dle)
+{
+    scriptlist_t scriptlist;
+
+    amfree(dle->disk);
+    amfree(dle->device);
+    amfree(dle->program);
+    g_slist_free(dle->estimatelist);
+    slist_free_full(dle->levellist, g_free);
+    amfree(dle->dumpdate);
+    amfree(dle->compprog);
+    amfree(dle->srv_encrypt);
+    amfree(dle->clnt_encrypt);
+    amfree(dle->srv_decrypt_opt);
+    amfree(dle->clnt_decrypt_opt);
+    amfree(dle->auth);
+    amfree(dle->application_client_name);
+    free_sl(dle->exclude_file);
+    free_sl(dle->exclude_list);
+    free_sl(dle->include_file);
+    free_sl(dle->include_list);
+    if (dle->application_property)
+       g_hash_table_destroy(dle->application_property);
+    for(scriptlist = dle->scriptlist; scriptlist != NULL;
+                                     scriptlist = scriptlist->next) {
+       free_script_data((script_t *)scriptlist->data);
+    }
+    slist_free_full(dle->scriptlist, g_free);
+    slist_free_full(dle->directtcp_list, g_free);
+    amfree(dle);
+}
+
+void
+free_script_data(
+    script_t *script)
+{
+    amfree(script->plugin);
+    amfree(script->client_name);
+    if (script->property)
+       g_hash_table_destroy(script->property);
+}
+
 void
 init_dle(
     dle_t *dle)
@@ -109,6 +153,7 @@ init_dle(
     dle->scriptlist = NULL;
     dle->data_path = DATA_PATH_AMANDA;
     dle->directtcp_list = NULL;
+    dle->application_client_name = NULL;
     dle->next = NULL;
 }
 
@@ -375,17 +420,18 @@ amstart_element(
        } else {
            data_user->has_backup_program = 1;
            data_user->property =
-                   g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+                   g_hash_table_new_full(g_str_hash, g_str_equal, &g_free, &free_property_t);
            data_user->has_plugin = 0;
        }
     } else if (strcmp(element_name, "script") == 0) {
        data_user->property =
-                   g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+                   g_hash_table_new_full(g_str_hash, g_str_equal, &g_free, &free_property_t);
        data_user->script = malloc(sizeof(script_t));
        data_user->script->plugin = NULL;
        data_user->script->execute_on = 0;
        data_user->script->execute_where = ES_CLIENT;
        data_user->script->property = NULL;
+       data_user->script->client_name = NULL;
        data_user->script->result = NULL;
        data_user->has_plugin = 0;
     } else if (strcmp(element_name, "execute_on") == 0) {
@@ -396,6 +442,7 @@ amstart_element(
                        "XML: Invalid %s element", element_name);
            return;
        }
+    } else if (strcmp(element_name, "client_name") == 0) {
     } else {
        g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                    "XML: Invalid %s element", element_name);
@@ -537,11 +584,13 @@ amtext(
        strcmp(last_element_name, "include") == 0) {
        g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                    "XML: %s doesn't have text '%s'", last_element_name, tt);
+       amfree(tt);
        return;
     } else if(strcmp(last_element_name, "disk") == 0) {
        if (dle->disk != NULL) {
            g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                        "XML: multiple text in %s", last_element_name);
+           amfree(tt);
            return;
        }
        dle->disk = tt;
@@ -549,6 +598,7 @@ amtext(
        if (dle->device != NULL) {
            g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                        "XML: multiple text in %s", last_element_name);
+           amfree(tt);
            return;
        }
        dle->device = tt;
@@ -587,12 +637,15 @@ amtext(
        if (dle->program != NULL) {
            g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                        "XML: multiple text in %s", last_element_name);
+           amfree(tt);
            return;
        }
-       dle->program = tt;
        if (strcmp(tt, "APPLICATION") == 0) {
            dle->program_is_application_api = 1;
            dle->program = NULL;
+           amfree(tt);
+       } else {
+           dle->program = tt;
        }
     } else if(strcmp(last_element_name, "plugin") == 0) {
        last_element2 = g_slist_nth(data_user->element_names, 1);
@@ -632,6 +685,7 @@ amtext(
        } else {
            error("priority outside of property");
        }
+       amfree(tt);
     } else if(strcmp(last_element_name, "value") == 0) {
        last_element2 = g_slist_nth(data_user->element_names, 1);
        if (!last_element2) {
@@ -694,10 +748,13 @@ amtext(
        } else {
            g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                        "XML: Invalid %s (%s)", last_element_name, tt);
+           amfree(tt);
            return;
        }
+       amfree(tt);
     } else if(strcmp(last_element_name, "spindle") == 0) {
        dle->spindle = atoi(tt);
+       amfree(tt);
     } else if(strcmp(last_element_name, "compress") == 0) {
        if (strcmp(tt, "FAST") == 0) {
            dle->compress = COMP_FAST;
@@ -758,17 +815,24 @@ amtext(
            error("XML: optional");
        }
        last_element2_name = last_element2->data;
-       dle->clnt_encrypt = tt;
+       if (dle->encrypt == ENCRYPT_SERV_CUST)
+           dle->srv_encrypt = tt;
+       else
+           dle->clnt_encrypt = tt;
     } else if(strcmp(last_element_name, "decrypt-option") == 0) {
        last_element2 = g_slist_nth(data_user->element_names, 1);
        if (!last_element2) {
            error("XML: optional");
        }
        last_element2_name = last_element2->data;
-       dle->clnt_decrypt_opt = tt;
+       if (dle->encrypt == ENCRYPT_SERV_CUST)
+           dle->srv_decrypt_opt = tt;
+       else
+           dle->clnt_decrypt_opt = tt;
     } else if(strcmp(last_element_name, "exclude") == 0 ||
              strcmp(last_element_name, "include") == 0) {
        data_user->has_optional = 0;
+       amfree(tt);
     } else if(strcmp(last_element_name, "file") == 0) {
        last_element2 = g_slist_nth(data_user->element_names, 1);
        if (!last_element2) {
@@ -812,6 +876,7 @@ amtext(
        data_user->has_optional = 1;
        amfree(tt);
     } else if(strcmp(last_element_name, "script") == 0) {
+       amfree(tt);
     } else if(strcmp(last_element_name, "execute_on") == 0) {
        char *sep;
        char *tt1 = tt;
@@ -819,26 +884,38 @@ amtext(
            sep = strchr(tt1,',');
            if (sep)
                *sep = '\0';
-           if (strcmp(tt1,"PRE-DLE-AMCHECK") == 0)
+           if (strcmp(tt1,"PRE-AMCHECK") == 0)
+               data_user->script->execute_on |= EXECUTE_ON_PRE_AMCHECK;
+           else if (strcmp(tt1,"PRE-DLE-AMCHECK") == 0)
                data_user->script->execute_on |= EXECUTE_ON_PRE_DLE_AMCHECK;
            else if (strcmp(tt1,"PRE-HOST-AMCHECK") == 0)
                data_user->script->execute_on |= EXECUTE_ON_PRE_HOST_AMCHECK;
+           else if (strcmp(tt1,"POST-AMCHECK") == 0)
+               data_user->script->execute_on |= EXECUTE_ON_POST_AMCHECK;
            else if (strcmp(tt1,"POST-DLE-AMCHECK") == 0)
                data_user->script->execute_on |= EXECUTE_ON_POST_DLE_AMCHECK;
            else if (strcmp(tt1,"POST-HOST-AMCHECK") == 0)
                data_user->script->execute_on |= EXECUTE_ON_POST_HOST_AMCHECK;
+           else if (strcmp(tt1,"PRE-ESTIMATE") == 0)
+               data_user->script->execute_on |= EXECUTE_ON_PRE_ESTIMATE;
            else if (strcmp(tt1,"PRE-DLE-ESTIMATE") == 0)
                data_user->script->execute_on |= EXECUTE_ON_PRE_DLE_ESTIMATE;
            else if (strcmp(tt1,"PRE-HOST-ESTIMATE") == 0)
                data_user->script->execute_on |= EXECUTE_ON_PRE_HOST_ESTIMATE;
+           else if (strcmp(tt1,"POST-ESTIMATE") == 0)
+               data_user->script->execute_on |= EXECUTE_ON_POST_ESTIMATE;
            else if (strcmp(tt1,"POST-DLE-ESTIMATE") == 0)
                data_user->script->execute_on |= EXECUTE_ON_POST_DLE_ESTIMATE;
            else if (strcmp(tt1,"POST-HOST-ESTIMATE") == 0)
                data_user->script->execute_on |= EXECUTE_ON_POST_HOST_ESTIMATE;
+           else if (strcmp(tt1,"PRE-BACKUP") == 0)
+               data_user->script->execute_on |= EXECUTE_ON_PRE_BACKUP;
            else if (strcmp(tt1,"PRE-DLE-BACKUP") == 0)
                data_user->script->execute_on |= EXECUTE_ON_PRE_DLE_BACKUP;
            else if (strcmp(tt1,"PRE-HOST-BACKUP") == 0)
                data_user->script->execute_on |= EXECUTE_ON_PRE_HOST_BACKUP;
+           else if (strcmp(tt1,"POST-BACKUP") == 0)
+               data_user->script->execute_on |= EXECUTE_ON_POST_BACKUP;
            else if (strcmp(tt1,"POST-DLE-BACKUP") == 0)
                data_user->script->execute_on |= EXECUTE_ON_POST_DLE_BACKUP;
            else if (strcmp(tt1,"POST-HOST-BACKUP") == 0)
@@ -865,6 +942,7 @@ amtext(
        } else {
            data_user->script->execute_where = ES_SERVER;
        }
+       amfree(tt);
     } else if(strcmp(last_element_name, "datapath") == 0) {
        if (strcmp(tt, "AMANDA") == 0) {
            dle->data_path = DATA_PATH_AMANDA;
@@ -877,9 +955,25 @@ amtext(
        amfree(tt);
     } else if(strcmp(last_element_name, "directtcp") == 0) {
        dle->directtcp_list = g_slist_append(dle->directtcp_list, tt);
+    } else if(strcmp(last_element_name, "client_name") == 0) {
+       last_element2 = g_slist_nth(data_user->element_names, 1);
+       if (!last_element2) {
+           error("Invalid client_name text");
+       }
+       last_element2_name = last_element2->data;
+       if (strcmp(last_element2_name, "backup-program") == 0) {
+           dle->application_client_name = tt;
+g_debug("set dle->application_client_name: %s", dle->application_client_name);
+       } else if (strcmp(last_element2_name, "script") == 0) {
+           data_user->script->client_name = tt;
+g_debug("set data_user->script->client_name: %s", data_user->script->client_name);
+       } else {
+           error("client_name outside of script or backup-program");
+       }
     } else {
        g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                    "XML: amtext not defined for '%s'", last_element_name);
+       amfree(tt);
        return;
     }
 }