Esempio n. 1
0
void
test_tmpl_url_for_with_script_name(void)
{
    g_setenv("PATH_INFO", "/", TRUE);
    g_setenv("REQUEST_METHOD", "GET", TRUE);
    g_setenv("SCRIPT_NAME", "/foo/bar", TRUE);
    // FIXME: this thing is too weak :(
    balde_app_t *app = balde_app_init();
    balde_request_t *request = balde_make_request(app, balde_sapi_cgi_parse_request(app));
    balde_app_add_url_rule(app, "arcoiro", "/arcoiro/<bola>/<guda>/",
        BALDE_HTTP_GET, arcoiro_view);
    balde_app_add_url_rule(app, "arcoiro2", "/arco/<iro>", BALDE_HTTP_GET,
        arcoiro_view);
    gchar *url = balde_tmpl_url_for(app, request, "arcoiro", FALSE, "chunda", "guto");
    g_assert_cmpstr(url, ==, "/foo/bar/arcoiro/chunda/guto/");
    g_free(url);
    url = balde_tmpl_url_for(app, request, "arcoiro2", FALSE, "bola");
    g_assert_cmpstr(url, ==, "/foo/bar/arco/bola");
    g_free(url);
    url = balde_tmpl_url_for(app, request, "static", FALSE, "foo/jquery-min.js");
    g_assert_cmpstr(url, ==, "/foo/bar/static/foo/jquery-min.js");
    g_free(url);
    balde_request_free(request);
    balde_app_free(app);
    g_unsetenv("SCRIPT_NAME");
    g_unsetenv("REQUEST_METHOD");
    g_unsetenv("PATH_INFO");
}
Esempio n. 2
0
void
test_app_url_for(void)
{
    g_setenv("PATH_INFO", "/", TRUE);
    g_setenv("REQUEST_METHOD", "GET", TRUE);
    // FIXME: this thing is too weak :(
    balde_app_t *app = balde_app_init();
    balde_request_t *request = balde_make_request(app, NULL);
    balde_app_add_url_rule(app, "arcoiro", "/arcoiro/<bola>/<guda>/",
        BALDE_HTTP_GET, arcoiro_view);
    balde_app_add_url_rule(app, "arcoiro2", "/arco/<iro>", BALDE_HTTP_GET,
        arcoiro_view);
    gchar *url = balde_app_url_for(app, request, "arcoiro", FALSE, "chunda", "guto");
    g_assert_cmpstr(url, ==, "/arcoiro/chunda/guto/");
    g_free(url);
    url = balde_app_url_for(app, request, "arcoiro2", FALSE, "bola");
    g_assert_cmpstr(url, ==, "/arco/bola");
    g_free(url);
    url = balde_app_url_for(app, request, "arcoiro2", FALSE, "bo\"la");
    g_assert_cmpstr(url, ==, "/arco/bo%22la");
    g_free(url);
    url = balde_app_url_for(app, request, "static", FALSE, "foo/jquery-min.js");
    g_assert_cmpstr(url, ==, "/static/foo/jquery-min.js");
    g_free(url);
    balde_request_free(request);
    balde_app_free(app);
    g_unsetenv("REQUEST_METHOD");
    g_unsetenv("PATH_INFO");
}
Esempio n. 3
0
int
main(int argc, char **argv)
{
    balde_app_t *app = balde_app_init();
    balde_app_add_url_rule(app, "home", "/", BALDE_HTTP_GET, home);
    balde_app_add_url_rule(app, "profile", "/profile/<name>/", BALDE_HTTP_GET, profile);
    balde_app_run(app, argc, argv);
    balde_app_free(app);
    return 0;
}
Esempio n. 4
0
void
test_app_add_url_rule(void)
{
    balde_app_t *app = balde_app_init();
    balde_app_add_url_rule(app, "arcoiro", "/arcoiro/", BALDE_HTTP_POST,
        arcoiro_view);
    g_assert(g_slist_length(app->priv->views) == 2);
    balde_view_t *view = app->priv->views->next->data;
    g_assert(view != NULL);
    g_assert(view->url_rule != NULL);
    g_assert_cmpstr(view->url_rule->endpoint, ==, "arcoiro");
    g_assert_cmpstr(view->url_rule->rule, ==, "/arcoiro/");
    g_assert_cmpstr(g_regex_get_pattern(view->url_rule->match->regex), ==,
        "^/arcoiro/$");
    g_assert(view->url_rule->method & BALDE_HTTP_POST);
    g_assert(view->url_rule->method & BALDE_HTTP_OPTIONS);
    g_assert(!(view->url_rule->method & BALDE_HTTP_GET));
    g_assert(!(view->url_rule->method & BALDE_HTTP_HEAD));
    g_assert(!(view->url_rule->method & BALDE_HTTP_PUT));
    g_assert(!(view->url_rule->method & BALDE_HTTP_DELETE));
    i = 0;
    view->view_func(app, NULL);
    g_assert(i == 1);
    balde_app_free(app);
}
Esempio n. 5
0
int
main(int argc, char **argv)
{
    curl_global_init(CURL_GLOBAL_ALL);
    balde_app_t *app = balde_app_init();
    balde_resources_load(app, resources_get_resource());
    balde_app_set_user_data_destroy_func(app, (GDestroyNotify) bluster_gist_ctx_free);
    balde_app_add_before_request(app, bluster_before_request);
    balde_app_add_url_rule(app, "main", "/", BALDE_HTTP_GET, main_view);
    balde_app_add_url_rule(app, "content", "/<slug>/", BALDE_HTTP_GET, main_view);
    balde_app_set_config_from_envvar(app, "oauth_token", "BLUSTER_OAUTH_TOKEN", TRUE);
    balde_app_set_config_from_envvar(app, "gist_id", "BLUSTER_GIST_ID", FALSE);
    balde_app_set_config_from_envvar(app, "gist_ttl", "BLUSTER_GIST_TTL", TRUE);
    balde_app_run(app, argc, argv);
    balde_app_free(app);
    curl_global_cleanup();
    return 0;
}
Esempio n. 6
0
int
main(int argc, char **argv)
{
    balde_app_t *app = balde_app_init();
    balde_app_add_url_rule(app, "hello", "/", BALDE_HTTP_GET, hello);
    balde_app_run(app, argc, argv);
    balde_app_free(app);
    return 0;
}
Esempio n. 7
0
void
test_app_get_view_from_endpoint_not_found(void)
{
    balde_app_t *app = balde_app_init();
    balde_app_add_url_rule(app, "arcoiro", "/arcoiro/", BALDE_HTTP_GET,
        arcoiro_view);
    balde_view_t *view = balde_app_get_view_from_endpoint(app, "bola");
    g_assert(view == NULL);
    balde_app_free(app);
}
Esempio n. 8
0
File: app.c Progetto: GnLWeB/balde
BALDE_API balde_app_t*
balde_app_init(void)
{
    balde_app_t *app = g_new(balde_app_t, 1);
    app->priv = g_new(struct _balde_app_private_t, 1);
    app->priv->views = NULL;
    app->priv->before_requests = NULL;
    app->priv->static_resources = NULL;
    app->priv->user_data = NULL;
    app->priv->user_data_destroy_func = NULL;
    app->priv->config = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
    app->copy = FALSE;
    app->error = NULL;
    balde_app_add_url_rule(app, "static", "/static/<path:file>", BALDE_HTTP_GET,
        balde_resource_view);
    return app;
}