// This C file, the Big Al API and the template file // generate this web page with dynamic content. #include #include #include #include #include #include #include #include #include void bork(char *fmt, ...) { char mesg[1024] = { 0 }; va_list ap; content_type("text/html"); va_start(ap, fmt); vsprintf(mesg, fmt, ap); printf("

Error: %s

\n", mesg); va_end(ap); exit(EXIT_FAILURE); } int main(int argc, char **argv, char **envp) { template_t data = template_init(); if (get_params() == NULL) goto GET; int i; // If get_params returns NULL we have no GET or POST data // so we don't use the param() function unless there is // data. // Getting parameters which are numeric string according // to the template; to make things easier and show the // use of the FOREACH loop off. for (i = 1; i <= 7; i++) { char p[2] = { 0 }; sprintf(p, "%d", i); template_input(data, "FRIEND", param(p)); } // We add some static data to placeholders for the template // NICK is the placeholder for "netstar" GET: template_input(data, "VERSION", "CGI API Version 0.3.1"); template_input(data, "COPYRIGHT", "(c) Copyright. Alastair Poole. All Rights Reserved."); cookie_t *get_a_cookie = cookie("Nameth"); if (get_a_cookie) template_input(data, "COOKIE", get_a_cookie->value); cookie_t *get_another_cookie = cookie("Jesus"); if (get_another_cookie) template_input(data, "LORD", get_another_cookie->value); // if (cookie_valid(get_a_cookie)) { // // } cookie_t *cookies = cookies_init(); cookie_t c; memset(&c, 0, sizeof(cookie_t)); c.name = "Nameth"; c.value = "Hamish"; c.expires = 3600; // one hour cookie_add(cookies, &c); cookie_t c2; memset(&c2, 0, sizeof(cookie_t)); c2.name = "Jesus"; c2.value = "Lamb of God"; cookie_add(cookies, &c2); content_type_cookies("text/html", cookies); // We output the data to be parsed against the template and outputted... template_output("templates/index.plate", data); // We free the data template_free(data); exit(EXIT_SUCCESS); }