/*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2016 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
ZakCgiMain *zakcgimain;
GHashTable *ht_functions;
+ GPtrArray *ar_not_found;
gboolean remove_trailing_slashes;
};
priv->zakcgimain = NULL;
priv->ht_functions = g_hash_table_new (g_str_hash, g_str_equal);
+ priv->ar_not_found = NULL;
+
priv->remove_trailing_slashes = FALSE;
}
g_ptr_array_unref (ar);
}
+/**
+ * zak_cgi_url_connect_not_found:
+ * @url:
+ * @function:
+ * @user_data:
+ *
+ */
+void
+zak_cgi_url_connect_not_found (ZakCgiUrl *url,
+ ZakCgiUrlConnectedFunction function,
+ gpointer user_data)
+{
+ ZakCgiUrlPrivate *priv = ZAK_CGI_URL_GET_PRIVATE (url);
+
+ if (priv->ar_not_found != NULL)
+ {
+ g_ptr_array_unref (priv->ar_not_found);
+ priv->ar_not_found = NULL;
+ }
+
+ if (function != NULL)
+ {
+ priv->ar_not_found = g_ptr_array_new ();
+ g_ptr_array_add (priv->ar_not_found, function);
+ g_ptr_array_add (priv->ar_not_found, user_data);
+ }
+}
+
/**
* zak_cgi_url_set_remove_trailing_slashes:
* @url:
GPtrArray *ar;
ZakCgiUrlConnectedFunction function;
+ gboolean not_found;
+
ZakCgiUrlPrivate *priv = ZAK_CGI_URL_GET_PRIVATE (url);
ht_env = zak_cgi_main_get_parameters (priv->zakcgimain, NULL);
}
}
+ not_found = TRUE;
+
g_hash_table_iter_init (&iter, priv->ht_functions);
while (g_hash_table_iter_next (&iter, &key, &value))
{
ar = (GPtrArray *)value;
function = g_ptr_array_index (ar, 0);
(*function)(minfo, g_ptr_array_index (ar, 1));
+ not_found = FALSE;
}
}
+
+ if (not_found && priv->ar_not_found != NULL)
+ {
+ function = g_ptr_array_index (priv->ar_not_found, 0);
+ (*function)(NULL, g_ptr_array_index (priv->ar_not_found, 1));
+ }
}
g_string_free (_url, TRUE);
ZakCgiUrlConnectedFunction function,
gpointer user_data);
+void zak_cgi_url_connect_not_found (ZakCgiUrl *url,
+ ZakCgiUrlConnectedFunction function,
+ gpointer user_data);
+
void zak_cgi_url_set_remove_trailing_slashes (ZakCgiUrl *url, gboolean remove);
gboolean zak_cgi_url_get_remove_trailing_slashes (ZakCgiUrl *url);
}
}
+void
+hook_not_found (GMatchInfo *minfo, gpointer user_data)
+{
+ GString *str = (GString *)user_data;
+
+ g_string_append_printf (str, "NOT FOUND<br/><br/>\n");
+}
+
int
main (int argc, char *argv[])
{
url = zak_cgi_url_new (NULL);
- zak_cgi_url_connect (url, "/(?<controller>[a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)", (ZakCgiUrlConnectedFunction)hook, str);
+ zak_cgi_url_connect_not_found (url, (ZakCgiUrlConnectedFunction)hook_not_found, str);
+
+ zak_cgi_url_connect (url, "/(?<controller>[a-z][a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)", (ZakCgiUrlConnectedFunction)hook, str);
zak_cgi_url_set_remove_trailing_slashes (url, TRUE);