C max_chunk_size server bits continued
authorBill Erickson <berick@esilibrary.com>
Fri, 28 Feb 2014 19:51:46 +0000 (14:51 -0500)
committerBill Erickson <berick@esilibrary.com>
Fri, 28 Feb 2014 19:51:46 +0000 (14:51 -0500)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
src/libopensrf/osrf_application.c

index 2bda572..cbd9371 100644 (file)
@@ -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);