#include "cgi.h"
@@ -23,27 +22,6 @@ djbhash(char const *buf, size_t buflen)
return h;
}
-void
-page(char *title, char *fmt, ...)
-{
- FILE *p;
- va_list ap;
-
- printf("Content-type: text/html\r\n\r\n");
- fflush(stdout);
- p = popen("./template", "w");
- if (NULL == p) {
- printf("%s
\n", title);
- p = stdout;
- } else {
- fprintf(p, "Title: %s\n", title);
- }
- va_start(ap, fmt);
- vfprintf(p, fmt, ap);
- va_end(ap);
- fclose(p);
-}
-
int
main(int argc, char *argv[])
{
@@ -60,10 +38,10 @@ main(int argc, char *argv[])
size_t len;
char key[20];
- len = read_item(key, sizeof(key));
+ len = cgi_item(key, sizeof(key));
if (0 == len) break;
if ((1 == len) && ('t' == key[0])) {
- teamlen = read_item(team, sizeof(team));
+ teamlen = cgi_item(team, sizeof(team));
}
}
@@ -80,34 +58,29 @@ main(int argc, char *argv[])
"%s/%s",
BASE_PATH, hash);
if (sizeof(filename) == ret) {
- printf(("500 Server screwed up\n"
- "Content-type: text/plain\n"
- "\n"
- "The full path to the team hash file is too long.\n"));
- return 0;
+ cgi_error("The full path to the team hash file is too long.");
}
fd = open(filename, 0444, O_WRONLY | O_CREAT | O_EXCL);
if (-1 == fd) {
- page("Bad team name",
- ("Either that team name is already in use, or you "
- "found a hash collision (way to go). "
- "In any case, you're going to "
- "have to pick something else.
"
- "If you're just trying to find your team hash again,"
- "it's %s.
"),
- hash);
- return 0;
+ cgi_page("Bad team name",
+ ("Either that team name is already in use, or you "
+ "found a hash collision (way to go). "
+ "In any case, you're going to "
+ "have to pick something else.
"
+ "If you're just trying to find your team hash again,"
+ "it's %s.
"),
+ hash);
}
write(fd, team, teamlen);
close(fd);
}
/* Let them know what their hash is. */
- page("Team registered",
- ("Team hash: %s
"
- "Save your team hash somewhere!. You will need it "
- "to claim points.
"),
- hash);
+ cgi_page("Team registered",
+ ("Team hash: %s
"
+ "Save your team hash somewhere!. You will need it "
+ "to claim points.
"),
+ hash);
return 0;
}