From: Jeremy Tan Date: Tue, 17 Sep 2013 07:57:21 +0000 (+0800) Subject: Merge branch 'master' of https://github.com/szmoore/MCTX3420.git X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=5d57467589ecefdf5bb5985005705a1c8460c623;p=matches%2FMCTX3420.git Merge branch 'master' of https://github.com/szmoore/MCTX3420.git Conflicts: server/actuator.c --- 5d57467589ecefdf5bb5985005705a1c8460c623 diff --cc server/fastcgi.c index 05dae34,62978ea..b7a3e6b --- a/server/fastcgi.c +++ b/server/fastcgi.c @@@ -15,8 -15,9 +15,9 @@@ #include "actuator.h" #include "control.h" #include "options.h" + #include "image.h" -/**The time period (in seconds) before the control key expires @ */ +/**The time period (in seconds) before the control key expires */ #define CONTROL_TIMEOUT 180 /**Contextual information related to FCGI requests*/ @@@ -393,37 -434,17 +394,48 @@@ void FCGI_PrintRaw(const char *format, va_end(list); } + + /** + * Write binary data + * See fwrite + */ + void FCGI_WriteBinary(void * data, size_t size, size_t num_elem) + { + Log(LOGDEBUG,"Writing!"); + fwrite(data, size, num_elem, stdout); + } + +/** + * Escapes a string so it can be used safely. + * Currently escapes to ensure the validity for use as a JSON string + * Does not support unicode specifiers in the form of \uXXXX. + * @param buf The string to be escaped + * @return The escaped string (return value == buf) + */ +char *FCGI_EscapeText(char *buf) +{ + int length, i; + length = strlen(buf); + + //Escape special characters. Must count down to escape properly + for (i = length - 1; i >= 0; i--) { + if (buf[i] < 0x20) { //Control characters + buf[i] = ' '; + } else if (buf[i] == '"') { + if (i-1 >= 0 && buf[i-1] == '\\') + i--; + else + buf[i] = '\''; + } else if (buf[i] == '\\') { + if (i-1 >= 0 && buf[i-1] == '\'') + i--; + else + buf[i] = ' '; + } + } + return buf; +} + /** * Main FCGI request loop that receives/responds to client requests. * @param data Reserved. diff --cc server/fastcgi.h index af56301,adb1db9..8678a77 --- a/server/fastcgi.h +++ b/server/fastcgi.h @@@ -55,10 -54,12 +55,12 @@@ extern void FCGI_JSONBool(const char *k extern void FCGI_JSONKey(const char *key); extern void FCGI_PrintRaw(const char *format, ...); extern void FCGI_EndJSON(); -extern char *FCGI_EscapeJSON(char *buf); extern void FCGI_RejectJSONEx(FCGIContext *context, StatusCodes status, const char *description); +extern char *FCGI_EscapeText(char *buf); extern void *FCGI_RequestLoop (void *data); + extern void FCGI_WriteBinary(void * data, size_t size, size_t num_elem); + /** * Shortcut to calling FCGI_RejectJSONEx. Sets the error code * to STATUS_ERROR.