2 * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
19 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
25 /* PERL_MAGIC_tied is not defined in perl 5.6 */
26 #if !defined PERL_MAGIC_tied
27 #define PERL_MAGIC_tied 'P'
31 foreach_fn(gpointer key_p, gpointer value_p, gpointer user_data_p)
34 char *value = value_p;
36 hv_store(hv, key, strlen(key), newSVpv(value, 0), 0);
40 g_hash_table_to_hashref(GHashTable *hash)
42 HV *hv = (HV *)sv_2mortal((SV *)newHV());
44 g_hash_table_foreach(hash, foreach_fn, hv);
46 return newRV((SV *)hv);
50 foreach_fn_gslist(gpointer key_p, gpointer value_p, gpointer user_data_p)
53 GSList *value_s = value_p;
58 for(value=value_s; value != NULL; value = value->next) {
59 av_push(list, newSVpv(value->data, 0));
62 hv_store(hv, key, strlen(key), newRV_noinc((SV*)list), 0);
66 g_hash_table_to_hashref_gslist(GHashTable *hash)
68 HV *hv = (HV *)sv_2mortal((SV *)newHV());
70 g_hash_table_foreach(hash, foreach_fn_gslist, hv);
72 return newRV((SV *)hv);
76 foreach_fn_property(gpointer key_p, gpointer value_p, gpointer user_data_p)
79 property_t *property = value_p;
83 HV *property_hv = newHV();
86 hv_store(property_hv, "append", strlen("append"), newSViv(property->append), 0);
87 hv_store(property_hv, "priority", strlen("priority"), newSViv(property->priority), 0);
88 for(value=property->values; value != NULL; value = value->next) {
89 av_push(list, newSVpv(value->data, 0));
91 hv_store(property_hv, "values", strlen("values"), newRV_noinc((SV*)list), 0);
93 val = newRV_noinc((SV*)property_hv);
94 hv_store(hv, key, strlen(key), val, 0);
100 g_hash_table_to_hashref_property(GHashTable *hash)
107 tie = newRV_noinc((SV*)newHV());
108 stash = gv_stashpv("Amanda::Config::FoldingHash", GV_ADD);
109 sv_bless(tie, stash);
110 hv_magic(hv, (GV*)tie, PERL_MAGIC_tied);
112 hv = (HV *)sv_2mortal((SV *)hv);
113 g_hash_table_foreach(hash, foreach_fn_property, hv);
115 return newRV((SV *)hv);