gval = (GValue *)g_hash_table_lookup (ht, parts[0]);
if (gval != NULL)
{
- if (!G_VALUE_HOLDS (gval, G_TYPE_BOXED))
+ if (!G_VALUE_HOLDS (gval, G_TYPE_PTR_ARRAY))
{
/* convert to GPtrArray */
ar = g_ptr_array_new ();
b = g_slice_new (ZakCgiFile);
b->name = g_strdup (file->name);
- b->content = g_strdup (file->content);
+ b->content = g_memdup (file->content, file->size);
b->size = file->size;
return b;
guint file_l;
GValue *gval;
+ GValue *gval_tmp;
ZakCgiFile *zgfile;
+ GPtrArray *ar;
+
content_disposition = zak_cgi_main_read_line (buf, l, &i, TRUE, &bytesread);
v_content = g_strsplit (content_disposition, ";", -1);
param_value = zak_cgi_main_read_line (buf, l, &i, TRUE, &bytesread);
}
- gval = g_new0 (GValue, 1);
-
+ gval_tmp = g_new0 (GValue, 1);
if (l_v_content == 3)
{
zgfile = (ZakCgiFile *)g_new0 (ZakCgiFile, 1);
zgfile->content = g_memdup (param_value, file_l - 2);
zgfile->size = file_l - 2;
- g_value_init (gval, ZAK_CGI_TYPE_FILE);
- g_value_take_boxed (gval, zgfile);
+ g_value_init (gval_tmp, ZAK_CGI_TYPE_FILE);
+ g_value_take_boxed (gval_tmp, zgfile);
}
else
{
- g_value_init (gval, G_TYPE_STRING);
- g_value_set_string (gval, g_strdup (param_value));
+ g_value_init (gval_tmp, G_TYPE_STRING);
+ g_value_set_string (gval_tmp, g_strdup (param_value));
}
- g_hash_table_replace (ht, g_strdup (param_name), gval);
+ gval = g_hash_table_lookup (ht, param_name);
+ if (gval != NULL)
+ {
+ if (!G_VALUE_HOLDS (gval, G_TYPE_PTR_ARRAY))
+ {
+ GValue *g;
+
+ g = (GValue *)g_new0 (GValue, 1);
+ g_value_init (g, G_VALUE_TYPE (gval));
+ g_value_copy (gval, g);
+ g_value_unset (gval);
+
+ /* converto to GPtrArray */
+ ar = g_ptr_array_new ();
+
+ g_ptr_array_add (ar, g);
+
+ g_value_init (gval, G_TYPE_PTR_ARRAY);
+ g_value_take_boxed (gval, ar);
+ g_hash_table_replace (ht, g_strdup (param_name), gval);
+ }
+ else
+ {
+ ar = (GPtrArray *)g_value_get_boxed (gval);
+ }
+ g_ptr_array_add (ar, gval_tmp);
+ }
+ else
+ {
+ g_hash_table_replace (ht, g_strdup (param_name), gval_tmp);
+ }
g_free (param_name);
g_free (param_value);
#include <main.h>
+gchar
+*get_value (GValue *value)
+{
+ gchar *ret;
+
+ if (G_VALUE_HOLDS (value, ZAK_CGI_TYPE_FILE))
+ {
+ ZakCgiFile *zgfile = (ZakCgiFile *)g_value_get_boxed ((GValue *)value);
+
+ ret = g_strdup (zgfile->name);
+
+ if (g_strcmp0 (zgfile->name, "") != 0)
+ {
+ /* save the file to tmp */
+ GFile *gfile;
+ GFileIOStream *iostream;
+ GOutputStream *ostream;
+
+ iostream = NULL;
+ gfile = g_file_new_tmp (g_strdup_printf ("cgi-XXXXXX-%s", zgfile->name),
+ &iostream,
+ NULL);
+
+ ostream = g_io_stream_get_output_stream (G_IO_STREAM (iostream));
+ g_output_stream_write (ostream,
+ zgfile->content,
+ zgfile->size,
+ NULL,
+ NULL);
+ g_output_stream_close (ostream, NULL, NULL);
+
+ g_object_unref (ostream);
+ g_object_unref (gfile);
+ }
+ }
+ else if (G_VALUE_HOLDS (value, G_TYPE_STRING))
+ {
+ ret = g_strdup ((gchar *)g_value_get_string ((GValue *)value));
+ }
+ else
+ {
+ ret = g_strdup ("value of unknown type");
+ }
+
+ return ret;
+}
+
int
main (int argc, char *argv[])
{
gchar *env;
GString *str;
GHashTable *ht;
+ gchar *ret;
env = zak_cgi_main_dump_env (NULL);
g_hash_table_iter_init (&iter, ht);
while (g_hash_table_iter_next (&iter, &key, &value))
{
- if (G_VALUE_HOLDS (value, ZAK_CGI_TYPE_FILE))
+ if (G_VALUE_HOLDS (value, G_TYPE_PTR_ARRAY))
{
- ZakCgiFile *zgfile = (ZakCgiFile *)g_value_get_boxed ((GValue *)value);
-
- g_string_append_printf (str,
- "<tr><td>%s</td><td>%s</td></tr>\n",
- (gchar *)key, zgfile->name);
-
- if (g_strcmp0 (zgfile->name, "") != 0)
+ guint i;
+ GPtrArray *ar = (GPtrArray *)g_value_get_boxed (value);
+ for (i = 0; i < ar->len; i++)
{
- /* save the file to tmp */
- GFile *gfile;
- GFileIOStream *iostream;
- GOutputStream *ostream;
-
- iostream = NULL;
- gfile = g_file_new_tmp (g_strdup_printf ("cgi-XXXXXX-%s", zgfile->name),
- &iostream,
- NULL);
-
- ostream = g_io_stream_get_output_stream (G_IO_STREAM (iostream));
- g_output_stream_write (ostream,
- zgfile->content,
- zgfile->size,
- NULL,
- NULL);
- g_output_stream_close (ostream, NULL, NULL);
-
- g_object_unref (ostream);
- g_object_unref (gfile);
+ ret = get_value (g_ptr_array_index (ar, i));
+ g_string_append_printf (str,
+ "<tr><td>%s[%d]</td><td>%s</td></tr>\n",
+ (gchar *)key, i, ret);
+ g_free (ret);
}
}
- else if (G_VALUE_HOLDS (value, G_TYPE_STRING))
- {
- g_string_append_printf (str,
- "<tr><td>%s</td><td>%s</td></tr>\n",
- (gchar *)key, (gchar *)g_value_get_string ((GValue *)value));
- }
else
{
+ ret = get_value ((GValue *)value);
g_string_append_printf (str,
"<tr><td>%s</td><td>%s</td></tr>\n",
- (gchar *)key, "value of unknown type");
+ (gchar *)key, ret);
+ g_free (ret);
}
}
<form method="POST" action="/cgi-bin/env" enctype="multipart/form-data">
<!--<form method="POST" action="/cgi-bin/env" enctype="application/x-www-form-urlencoded">-->
<!--<form method="POST" action="/cgi-bin/env">-->
- <input name="pippo" />
- <input name="pluto" />
- <input name="paperino" />
- <input type="file" name="ilfile" />
- <input name="topolino" />
+ pippo: <input name="pippo" /><br/>
+ pluto: <input name="pluto" /><br/>
+ paperino: <input name="paperino" /><br/>
+ file: <input type="file" name="ilfile" /><br/>
+ file: <input type="file" name="ilfile" /><br/>
+ file: <input type="file" name="ilfile" /><br/>
+ topolino: <input name="topolino" /><br/>
+ multiple: <select name="multiple" multiple>
+ <option value="1">One</option>
+ <option value="2">Two</option>
+ <option value="3">Three</option>
+ <option value="4">For</option>
+ <option value="5">Five</option>
+ </select><br/>
<input type="submit" value="invia" />
</form>
</body>