bakaid commented on a change in pull request #613: Minificpp 927 Nanofi 
tailfile delimited processor
URL: https://github.com/apache/nifi-minifi-cpp/pull/613#discussion_r303882546
 
 

 ##########
 File path: nanofi/src/core/flowfiles.c
 ##########
 @@ -0,0 +1,98 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "api/nanofi.h"
+#include "core/flowfiles.h"
+
+#include "utlist.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+void add_flow_file_record(flow_file_list ** ff_list, flow_file_record * 
record) {
+    if (!record) return;
+
+    struct flow_file_list * new_node = (struct flow_file_list 
*)malloc(sizeof(struct flow_file_list));
+    new_node->ff_record = record;
+    LL_APPEND(*ff_list, new_node);
+}
+
+void free_flow_file_list(flow_file_list ** ff_list) {
+    if (!*ff_list) return;
+    flow_file_list * el = NULL;
+    LL_FOREACH(*ff_list, el) {
+        if (el) {
+            free_flowfile(el->ff_record);
+        }
+    }
+}
+
+flow_file_record * write_to_flow_file(char * buff, nifi_instance * instance, 
standalone_processor * proc) {
+    if (!buff || !instance || !proc) {
+        return NULL;
+    }
+
+    flow_file_record * ffr = generate_flow_file(instance, proc);
+    if (ffr == NULL) {
+        printf("Could not generate flow file\n");
+        return NULL;
+    }
+
+    FILE * ffp = fopen(ffr->contentLocation, "wb");
+    if (!ffp) {
+        printf("Cannot open flow file at path %s to write content to.\n", 
ffr->contentLocation);
+        free_flowfile(ffr);
+        return NULL;
+    }
+
+    int count = strlen(buff);
 
 Review comment:
   `strlen` returns `size_t`, `fwrite` expects and returns `size_t`. While it 
is unlikely that we will encounter buffer sizes (>2G) where this would cause a 
problem, it is not a good practice to convert (even narrow, in this case) types 
without a reason. Please review the other strlen usages as well.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to