2817c6f81dd844b54f6232d688c001e6a12f9ebb hiram Wed Feb 13 11:17:54 2019 -0800 beginning to partition the code out to files refs #18869 diff --git src/hg/hubApi/apiUtils.c src/hg/hubApi/apiUtils.c new file mode 100644 index 0000000..6b16d31 --- /dev/null +++ src/hg/hubApi/apiUtils.c @@ -0,0 +1,33 @@ +/* utility functions for data API business */ + +#include "dataApi.h" + +void jsonErrAbort(char *format, ...) +/* Issue an error message in json format, and exit(0) */ +{ +char errMsg[2048]; +va_list args; +va_start(args, format); +vsnprintf(errMsg, sizeof(errMsg), format, args); +struct jsonWrite *jw = jsonStartOutput(); +jsonWriteString(jw, "error", errMsg); +jsonWriteObjectEnd(jw); +fputs(jw->dy->string,stdout); +exit(0); +} + +struct jsonWrite *jsonStartOutput() +/* begin json output with standard header information for all requests */ +{ +time_t timeNow = time(NULL); +// struct tm tm; +// gmtime_r(&timeNow, &tm); +struct jsonWrite *jw = jsonWriteNew(); +jsonWriteObjectStart(jw, NULL); +jsonWriteString(jw, "apiVersion", "0.1"); +jsonWriteString(jw, "source", "UCSantaCruz"); +jsonWriteDateFromUnix(jw, "downloadTime", (long long) timeNow); +jsonWriteNumber(jw, "downloadTimeStamp", (long long) timeNow); +return jw; +} +