#include #include #include #include #include #include #include #include #include int main(void) { struct kreq r; const char *page = "hw.cgi"; if (khttp_parse(&r, NULL, 0, &page, 1, 0) != KCGI_OK) return 1; khttp_head(&r, kresps[KRESP_STATUS], "%s", khttps[KHTTP_200]); khttp_head(&r, kresps[KRESP_CONTENT_TYPE], "%s", kmimetypes[KMIME_TEXT_HTML]); khttp_body(&r); int i; for (i = 0; i < 10; ++i) { khttp_printf(&r, "%d
", i); } char *query = getenv("QUERY_STRING"); if (query[0] != '\0') { khttp_printf(&r, "%s\n", query); } long unsigned int lenstr = atoi(getenv("CONTENT_LENGTH")); if (lenstr != 0) { khttp_printf(&r, "%ld\n", lenstr); int bufsize = 2 << 8, read; char *buffer = calloc(bufsize, 1); FILE *out = fopen("blue", "w"); if (out == NULL) { khttp_printf(&r, "%s\n", "Can't fopen."); } while ((read = fread(buffer, 1, bufsize, stdin)) > 0) { fwrite(buffer, 1, read, out); } khttp_printf(&r, "%s\n", "All done."); } khttp_printf(&r, "
" "" "" "
"); khttp_free(&r); return(EXIT_SUCCESS); }