2 * Copyright (c) 2007,2008,2009 Zmanda, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 as published
6 * by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
24 /* PERL_MAGIC_tied is not defined in perl 5.6 */
25 #if !defined PERL_MAGIC_tied
26 #define PERL_MAGIC_tied 'P'
30 foreach_fn(gpointer key_p, gpointer value_p, gpointer user_data_p)
33 char *value = value_p;
35 hv_store(hv, key, strlen(key), newSVpv(value, 0), 0);
39 g_hash_table_to_hashref(GHashTable *hash)
41 HV *hv = (HV *)sv_2mortal((SV *)newHV());
43 g_hash_table_foreach(hash, foreach_fn, hv);
45 return newRV((SV *)hv);
49 foreach_fn_gslist(gpointer key_p, gpointer value_p, gpointer user_data_p)
52 GSList *value_s = value_p;
57 for(value=value_s; value != NULL; value = value->next) {
58 av_push(list, newSVpv(value->data, 0));
61 hv_store(hv, key, strlen(key), newRV_noinc((SV*)list), 0);
65 g_hash_table_to_hashref_gslist(GHashTable *hash)
67 HV *hv = (HV *)sv_2mortal((SV *)newHV());
69 g_hash_table_foreach(hash, foreach_fn_gslist, hv);
71 return newRV((SV *)hv);
75 foreach_fn_property(gpointer key_p, gpointer value_p, gpointer user_data_p)
78 property_t *property = value_p;
82 HV *property_hv = newHV();
85 hv_store(property_hv, "append", strlen("append"), newSViv(property->append), 0);
86 hv_store(property_hv, "priority", strlen("priority"), newSViv(property->priority), 0);
87 for(value=property->values; value != NULL; value = value->next) {
88 av_push(list, newSVpv(value->data, 0));
90 hv_store(property_hv, "values", strlen("values"), newRV_noinc((SV*)list), 0);
92 val = newRV_noinc((SV*)property_hv);
93 hv_store(hv, key, strlen(key), val, 0);
99 g_hash_table_to_hashref_property(GHashTable *hash)
106 tie = newRV_noinc((SV*)newHV());
107 stash = gv_stashpv("Amanda::Config::FoldingHash", GV_ADD);
108 sv_bless(tie, stash);
109 hv_magic(hv, (GV*)tie, PERL_MAGIC_tied);
111 hv = (HV *)sv_2mortal((SV *)hv);
112 g_hash_table_foreach(hash, foreach_fn_property, hv);
114 return newRV((SV *)hv);