Imported Upstream version 3.3.3
[debian/amanda] / common-src / amxml.c
index fedf5cc985d2e87c1f6729cd1938b211cdc43c28..ba7f951923af8dbaee4fe20f3eeca60b836253aa 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  * Copyright (c) 1991-1998 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -60,7 +61,7 @@ typedef struct amgxml_s {
     property_t *property_data;
     proplist_t  property;
     script_t   *script;
-    level_t    *alevel;
+    am_level_t    *alevel;
     char       *encoding;
     char       *raw;
 } amgxml_t;
@@ -86,7 +87,7 @@ free_dle(
     amfree(dle->device);
     amfree(dle->program);
     g_slist_free(dle->estimatelist);
-    g_slist_free_full(dle->levellist);
+    slist_free_full(dle->levellist, g_free);
     amfree(dle->dumpdate);
     amfree(dle->compprog);
     amfree(dle->srv_encrypt);
@@ -94,18 +95,21 @@ free_dle(
     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->property)
+       g_hash_table_destroy(dle->property);
     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);
     }
-    g_slist_free_full(dle->scriptlist);
-    g_slist_free_full(dle->directtcp_list);
+    slist_free_full(dle->scriptlist, g_free);
+    slist_free_full(dle->directtcp_list, g_free);
     amfree(dle);
 }
 
@@ -114,6 +118,7 @@ free_script_data(
     script_t *script)
 {
     amfree(script->plugin);
+    amfree(script->client_name);
     if (script->property)
        g_hash_table_destroy(script->property);
 }
@@ -147,10 +152,12 @@ init_dle(
     dle->include_list = NULL;
     dle->exclude_optional = 0;
     dle->include_optional = 0;
+    dle->property = NULL;
     dle->application_property = NULL;
     dle->scriptlist = NULL;
     dle->data_path = DATA_PATH_AMANDA;
     dle->directtcp_list = NULL;
+    dle->application_client_name = NULL;
     dle->next = NULL;
 }
 
@@ -247,9 +254,11 @@ amstart_element(
        data_user->has_optional = 0;
        data_user->property_name = NULL;
        data_user->property_data = NULL;
-       data_user->property = NULL;
+       data_user->property =
+                   g_hash_table_new_full(g_str_hash, g_str_equal, &g_free, &free_property_t);
        data_user->script = NULL;
        data_user->alevel = NULL;
+       data_user->dle->property = data_user->property;
        data_user->encoding = NULL;
        data_user->raw = NULL;
     } else if(strcmp(element_name, "disk"          ) == 0 ||
@@ -308,7 +317,7 @@ amstart_element(
        if (strcmp(element_name, "exclude") == 0 || strcmp(element_name, "include") == 0)
           data_user->has_optional = 0;
        if (strcmp(element_name, "level") == 0) {
-           data_user->alevel = g_new0(level_t, 1);
+           data_user->alevel = g_new0(am_level_t, 1);
        }
     } else if (strcmp(element_name, "server") == 0) {
        if (strcmp(last_element_name, "level") != 0) {
@@ -360,8 +369,10 @@ amstart_element(
            return;
        }
     } else if(strcmp(element_name, "property") == 0) {
-       if (strcmp(last_element_name, "backup-program") != 0 &&
-           strcmp(last_element_name, "script") != 0) {
+       if (!last_element ||
+           (strcmp(last_element_name, "backup-program") != 0 &&
+            strcmp(last_element_name, "script") != 0 &&
+            strcmp(last_element_name, "dle") != 0)) {
            g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
                        "XML: Invalid %s element", element_name);
            return;
@@ -428,6 +439,7 @@ amstart_element(
        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) {
@@ -438,6 +450,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);
@@ -490,6 +503,7 @@ amend_element(
        if (dle->estimatelist == NULL)
            dle->estimatelist = g_slist_append(dle->estimatelist, ES_CLIENT);
 /* Add check of required field */
+       data_user->property = NULL;
        data_user->dle = NULL;
     } else if (strcmp(element_name, "backup-program") == 0) {
        if (dle->program == NULL) {
@@ -498,7 +512,7 @@ amend_element(
            return;
        }
        dle->application_property = data_user->property;
-       data_user->property = NULL;
+       data_user->property = dle->property;
     } else if (strcmp(element_name, "script") == 0) {
        if (data_user->script->plugin == NULL) {
            g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
@@ -506,7 +520,7 @@ amend_element(
            return;
        }
        data_user->script->property = data_user->property;
-       data_user->property = NULL;
+       data_user->property = dle->property;
        dle->scriptlist = g_slist_append(dle->scriptlist, data_user->script);
        data_user->script = NULL;
     } else if (strcmp(element_name, "level") == 0) {
@@ -535,7 +549,6 @@ amtext(
     GSList   *last_element2;
     char     *last_element2_name;
     dle_t    *dle = data_user->dle;
-    int       i;
 
     if (!last_element) {
        g_set_error(gerror, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
@@ -544,7 +557,7 @@ amtext(
     }
     last_element_name = last_element->data;
 
-    tt = malloc(text_len + 1);
+    tt = malloc(text_len + 8 + 1);
     strncpy(tt,text,text_len);
     tt[text_len] = '\0';
 
@@ -855,7 +868,6 @@ amtext(
            error("bad list");
        }
     } else if(strcmp(last_element_name, "optional") == 0) {
-       i = atoi(tt);
        last_element2 = g_slist_nth(data_user->element_names, 1);
        if (!last_element2) {
            error("XML: optional");
@@ -879,26 +891,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)
@@ -938,6 +962,21 @@ 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);