From: Bill Erickson Date: Fri, 28 Feb 2014 19:51:46 +0000 (-0500) Subject: C max_chunk_size server bits continued X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=6ec45d7dbda49b69debff31a3e7db326604df288;p=working%2FOpenSRF.git C max_chunk_size server bits continued Signed-off-by: Bill Erickson --- diff --git a/src/libopensrf/osrf_application.c b/src/libopensrf/osrf_application.c index 2bda572..cbd9371 100644 --- a/src/libopensrf/osrf_application.c +++ b/src/libopensrf/osrf_application.c @@ -753,8 +753,10 @@ static int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int ); // see how long this chunk is. If this is the last - // chunk, it will likely not be equal to chunk_size + // chunk, it will likely be less than chunk_size int partial_size = strlen(&data_str[i]); + if (partial_size > chunk_size) + partial_size = chunk_size; // substr(data_str, i, partial_size) char partial_buf[partial_size + 1]; @@ -766,10 +768,17 @@ static int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int osrf_message_set_result(msg, partial_obj); jsonObjectFree(partial_obj); - // Serialize the OSRF message as JSON for delivery - char* json = jsonObjectToJSON(osrfMessageToJSON(msg)); + // package the osrf message within an array then + // serialize to json for delivery + jsonObject* arr = jsonNewObject(NULL); + + // msg json freed when arr is freed + jsonObjectPush(arr, osrfMessageToJSON(msg)); + char* json = jsonObjectToJSON(arr); + osrfSendTransportPayload(ctx->session, json); osrfMessageFree(msg); + jsonObjectFree(arr); free(json); } @@ -782,9 +791,12 @@ static int _osrfAppRespond( osrfMethodContext* ctx, const jsonObject* data, int OSRF_STATUS_NOCONTENT ); - char* json = jsonObjectToJSON(osrfMessageToJSON(msg)); + jsonObject* arr = jsonNewObject(NULL); + jsonObjectPush(arr, osrfMessageToJSON(msg)); + char* json = jsonObjectToJSON(arr); osrfSendTransportPayload(ctx->session, json); osrfMessageFree(msg); + jsonObjectFree(arr); free(json);