From 0c751ba6ef2318de90244ae896aff1e85017b9ee Mon Sep 17 00:00:00 2001 From: Thomas Porzelt Date: Sun, 4 Apr 2010 22:51:27 +0200 Subject: [PATCH] [mod_progress] Fix JSON format (double quotes instead of single quotes...), fix wrong default recognized http method (GET instead of POST) and a minor compile warning --- src/modules/mod_progress.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/modules/mod_progress.c b/src/modules/mod_progress.c index 1c59410..3933356 100644 --- a/src/modules/mod_progress.c +++ b/src/modules/mod_progress.c @@ -24,17 +24,17 @@ * * Examples responses: * - legacy format - * new Object({'state': 'running', 'received': 123456, 'sent': 0, 'request_size': 200000, 'response_size': 0}) + * new Object({"state": "running"", "received": 123456, "sent": 0, "request_size": 200000, "response_size": 0}) * - json format - * {'state': 'running', 'received': 123456, 'sent': 0, 'request_size': 200000, 'response_size': 0} + * {"state": "running", "received": 123456, "sent": 0, "request_size": 200000, "response_size": 0} * - jsonp format (function name specified via X-Progress-Callback querystring key, defaults to "progress") - * progress({'state': 'running', 'received': 123456, 'sent': 0, 'request_size': 200000, 'response_size': 0}) + * progress({"state": "running", "received": 123456, "sent": 0, "request_size": 200000, "response_size": 0}) * * Possible response objects: - * - {'state': 'unknown'} - * - {'state': 'running', 'received': , 'sent': , 'request_size': , 'response_size': } - * - {'state': 'done', 'received': , 'sent': , 'request_size': , 'response_size': } - * - {'state': 'error', 'status': } + * - {"state": "unknown"} + * - {"state": "running", "received": , "sent": , "request_size": , "response_size": } + * - {"state": "done", "received": , "sent": , "request_size": , "response_size": } + * - {"state": "error", "status": } * * Example config: * if req.path == "/upload.php" { @@ -286,7 +286,7 @@ static void progress_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *resu if (debug) VR_DEBUG(vr, "progress.show: progress id \"%s\" unknown", id); - g_string_append_len(output, CONST_STR_LEN("{'state': 'unknown'}")); + g_string_append_len(output, CONST_STR_LEN("{\"state\": \"unknown\"}")); } else { if (debug) VR_DEBUG(vr, "progress.show: progress id \"%s\" found", id); @@ -294,19 +294,19 @@ static void progress_collect_cb(gpointer cbdata, gpointer fdata, GPtrArray *resu if (node->vr) { /* still in progress */ g_string_append_printf(output, - "{'state': 'running', 'received': %"G_GUINT64_FORMAT", 'sent': %"G_GUINT64_FORMAT", 'request_size': %"G_GUINT64_FORMAT", 'response_size': %"G_GUINT64_FORMAT"}", + "{\"state\": \"running\", \"received\": %"G_GUINT64_FORMAT", \"sent\": %"G_GUINT64_FORMAT", \"request_size\": %"G_GUINT64_FORMAT", \"response_size\": %"G_GUINT64_FORMAT"}", node->bytes_in, node->bytes_out, node->request_size, node->response_size ); } else if (node->status_code == 200) { /* done, success */ g_string_append_printf(output, - "{'state': 'done', 'received': %"G_GUINT64_FORMAT", 'sent': %"G_GUINT64_FORMAT", 'request_size': %"G_GUINT64_FORMAT", 'response_size': %"G_GUINT64_FORMAT"}", + "{\"state\": \"done\", \"received\": %"G_GUINT64_FORMAT", \"sent\": %"G_GUINT64_FORMAT", \"request_size\": %"G_GUINT64_FORMAT", \"response_size\": %"G_GUINT64_FORMAT"}", node->bytes_in, node->bytes_out, node->request_size, node->response_size ); } else { /* done, error */ g_string_append_printf(output, - "{'state': 'error', 'status': %d}", + "{\"state\": \"error\", \"status\": %d}", node->status_code ); } @@ -386,7 +386,7 @@ static void progress_show_free(liServer *srv, gpointer param) { static liAction* progress_show_create(liServer *srv, liPlugin* p, liValue *val, gpointer userdata) { mod_progress_show_param *psp; - mod_progress_format format; + mod_progress_format format = PROGRESS_FORMAT_JSON; UNUSED(srv); UNUSED(userdata); @@ -403,9 +403,12 @@ static liAction* progress_show_create(liServer *srv, liPlugin* p, liValue *val, format = PROGRESS_FORMAT_JSONP; } if (g_str_equal(str, "dump")) { format = PROGRESS_FORMAT_DUMP; + } else { + ERROR(srv, "progress.show: unknown format \"%s\"", str); + return NULL; } } else { - ERROR(srv, "%s", "progress.track expects an optional string as parameter"); + ERROR(srv, "%s", "progress.show expects an optional string as parameter"); return NULL; } @@ -494,7 +497,7 @@ static void progress_prepare_worker(liServer *srv, liPlugin *p, liWorker *wrk) { static const liPluginOption options[] = { { "progress.debug", LI_VALUE_BOOLEAN, 0, NULL }, - { "progress.methods", LI_VALUE_LIST, (1 << LI_HTTP_METHOD_GET), progress_methods_parse }, + { "progress.methods", LI_VALUE_LIST, (1 << LI_HTTP_METHOD_POST), progress_methods_parse }, { NULL, 0, 0, NULL } };