ae644b6c3246c8403da8971f3cd81727d36f5ffd kate Thu Apr 12 15:54:32 2012 -0700 Minimal lib for shared functions for API programs diff --git src/hg/lib/api.c src/hg/lib/api.c new file mode 100644 index 0000000..a9ca59b --- /dev/null +++ src/hg/lib/api.c @@ -0,0 +1,32 @@ +/* Utility functions for web API programs */ + +#include "common.h" +#include "stdio.h" +#include "api.h" + +void apiOut(char *text, char *jsonp) +/* Output content header and text to stdout */ +{ +// It's debatable whether the type should be text/plain, text/javascript or application/javascript; +// text/javascript works with all our supported browsers, so we are using that one. +puts("Content-Type:text/javascript\n"); + +if (jsonp) + { + printf("%s(%s)", jsonp, text); + } +else + { + puts(text); + } +} + +void apiWarnAbortHandler(char *format, va_list args) +/* warnAbort handler that aborts with an HTTP 400 status code. */ +{ +puts("Status: 400\n\n"); +vfprintf(stdout, format, args); +puts("\n"); +exit(-1); +} +