From 86d0249e65472b0ff2612dacbac23e7cd06b7b3f Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Mon, 24 Aug 2015 19:36:28 +0200 Subject: [PATCH] Moved function ZakCgiTag::valist_to_ghashtable in ZakCgiCommons. --- src/Makefile.am | 4 +++- src/commons.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++ src/commons.h | 31 ++++++++++++++++++++++++++ src/tag.c | 47 +++++---------------------------------- 4 files changed, 99 insertions(+), 42 deletions(-) create mode 100644 src/commons.c create mode 100644 src/commons.h diff --git a/src/Makefile.am b/src/Makefile.am index 8dcaea6..73a91e2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,7 +5,9 @@ AM_CPPFLAGS = $(ZAKCGI_CFLAGS) \ lib_LTLIBRARIES = libzakcgi.la -libzakcgi_la_SOURCES = main.c \ +libzakcgi_la_SOURCES = commons.c \ + commons.h \ + main.c \ session.c \ tag.c \ url.c diff --git a/src/commons.c b/src/commons.c new file mode 100644 index 0000000..00018d0 --- /dev/null +++ b/src/commons.c @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#include "commons.h" + +GHashTable +*zak_cgi_commons_valist_to_ghashtable (va_list ap) +{ + GHashTable *ret; + + gchar *attr; + gchar *attr_val; + + ret = g_hash_table_new (g_str_hash, g_str_equal); + + do + { + attr = va_arg (ap, gchar *); + if (attr != NULL) + { + attr_val = va_arg (ap, gchar *); + if (attr_val != NULL) + { + g_hash_table_insert (ret, g_strdup (attr), g_strdup (attr_val)); + } + else + { + break; + } + } + else + { + break; + } + } while (TRUE); + + va_end (ap); + + return ret; +} diff --git a/src/commons.h b/src/commons.h new file mode 100644 index 0000000..721cf7d --- /dev/null +++ b/src/commons.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __ZAK_CGI_COMMONS_H__ +#define __ZAK_CGI_COMMONS_H__ + + +#include + +#include "main.h" + + +GHashTable *zak_cgi_commons_valist_to_ghashtable (va_list ap); + + +#endif /* __ZAK_CGI_COMMONS_H__ */ diff --git a/src/tag.c b/src/tag.c index 32be9ea..aa4d7de 100644 --- a/src/tag.c +++ b/src/tag.c @@ -20,44 +20,9 @@ #include #endif +#include "commons.h" #include "tag.h" -static GHashTable -*zak_cgi_tag_valist_to_ghashtable (va_list ap) -{ - GHashTable *ret; - - gchar *attr; - gchar *attr_val; - - ret = g_hash_table_new (g_str_hash, g_str_equal); - - do - { - attr = va_arg (ap, gchar *); - if (attr != NULL) - { - attr_val = va_arg (ap, gchar *); - if (attr_val != NULL) - { - g_hash_table_insert (ret, g_strdup (attr), g_strdup (attr_val)); - } - else - { - break; - } - } - else - { - break; - } - } while (TRUE); - - va_end (ap); - - return ret; -} - static gchar *zak_cgi_tag_tag_attrs (const gchar *name, const gchar *id, @@ -162,7 +127,7 @@ gchar va_start (ap, id); - return zak_cgi_tag_tag_attrs (name, id, zak_cgi_tag_valist_to_ghashtable (ap)); + return zak_cgi_tag_tag_attrs (name, id, zak_cgi_commons_valist_to_ghashtable (ap)); } /** @@ -179,7 +144,7 @@ gchar va_start (ap, id); - return zak_cgi_tag_tag_attrs ("img", id, zak_cgi_tag_valist_to_ghashtable (ap)); + return zak_cgi_tag_tag_attrs ("img", id, zak_cgi_commons_valist_to_ghashtable (ap)); } /** @@ -197,7 +162,7 @@ gchar va_start (ap, id); - ht = zak_cgi_tag_valist_to_ghashtable (ap); + ht = zak_cgi_commons_valist_to_ghashtable (ap); g_hash_table_insert (ht, "type", "text"); return zak_cgi_tag_tag_attrs ("input", id, ht); @@ -218,7 +183,7 @@ gchar va_start (ap, id); - ht = zak_cgi_tag_valist_to_ghashtable (ap); + ht = zak_cgi_commons_valist_to_ghashtable (ap); g_hash_table_insert (ht, "type", "file"); return zak_cgi_tag_tag_attrs ("input", id, ht); @@ -239,7 +204,7 @@ gchar va_start (ap, id); - ht = zak_cgi_tag_valist_to_ghashtable (ap); + ht = zak_cgi_commons_valist_to_ghashtable (ap); g_hash_table_insert (ht, "type", "submit"); return zak_cgi_tag_tag_attrs ("input", id, ht); -- 2.49.0