X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=perl%2Famglue%2Fghashtable.c;h=09dbfb79b292fdb244ba372aab255e75819a3fdd;hb=2627875b7d18858bc1f9f7652811e4d8c15a23eb;hp=61a02891918caca2bff1ac942a1804f4f446c9a6;hpb=fb2bd066c2f8b34addafe48d62550e3033a59431;p=debian%2Famanda diff --git a/perl/amglue/ghashtable.c b/perl/amglue/ghashtable.c index 61a0289..09dbfb7 100644 --- a/perl/amglue/ghashtable.c +++ b/perl/amglue/ghashtable.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005 Zmanda, Inc. All Rights Reserved. + * Copyright (c) 2005-2008 Zmanda Inc. All Rights Reserved. * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 2.1 as @@ -14,11 +14,12 @@ * along with this library; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * Contact information: Zmanda Inc., 505 N Mathlida Ave, Suite 120 - * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com + * Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300 + * Sunnyvale, CA 94086, USA, or: http://www.zmanda.com */ #include "amglue.h" +#include "conffile.h" static void foreach_fn(gpointer key_p, gpointer value_p, gpointer user_data_p) @@ -38,3 +39,60 @@ g_hash_table_to_hashref(GHashTable *hash) return newRV((SV *)hv); } + +static void +foreach_fn_gslist(gpointer key_p, gpointer value_p, gpointer user_data_p) +{ + char *key = key_p; + GSList *value_s = value_p; + GSList *value; + HV *hv = user_data_p; + AV *list = newAV(); + + for(value=value_s; value != NULL; value = value->next) { + av_push(list, newSVpv(value->data, 0)); + } + + hv_store(hv, key, strlen(key), newRV_noinc((SV*)list), 0); +} + +SV * +g_hash_table_to_hashref_gslist(GHashTable *hash) +{ + HV *hv = (HV *)sv_2mortal((SV *)newHV()); + + g_hash_table_foreach(hash, foreach_fn_gslist, hv); + + return newRV((SV *)hv); +} + +static void +foreach_fn_property(gpointer key_p, gpointer value_p, gpointer user_data_p) +{ + char *key = key_p; + property_t *property = value_p; + GSList *value; + HV *hv = user_data_p; + AV *list = newAV(); + HV *property_hv = newHV(); + + hv_store(property_hv, "append", strlen("append"), newSViv(property->append), 0); + hv_store(property_hv, "priority", strlen("priority"), newSViv(property->priority), 0); + for(value=property->values; value != NULL; value = value->next) { + av_push(list, newSVpv(value->data, 0)); + } + hv_store(property_hv, "values", strlen("values"), newRV_noinc((SV*)list), 0); + + hv_store(hv, key, strlen(key), newRV_noinc((SV*)property_hv), 0); +} + +SV * +g_hash_table_to_hashref_property(GHashTable *hash) +{ + HV *hv = (HV *)sv_2mortal((SV *)newHV()); + + g_hash_table_foreach(hash, foreach_fn_property, hv); + + return newRV((SV *)hv); +} +