arpadboda 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_r320717714
########## File path: nanofi/src/core/flowfiles.c ########## @@ -0,0 +1,171 @@ +/** + * + * 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 "api/ecu.h" +#include "core/flowfiles.h" + +#include "utlist.h" +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> + +flow_file_list * add_flow_file_record(flow_file_list ** ff_list, flow_file_record * record) { + if (!record) { + return *ff_list; + } + + 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); + return new_node; +} + +void free_flow_file_list(flow_file_list ** ff_list) { + if (!*ff_list) { + return; + } + flow_file_list * head = *ff_list; + while (head) { + flow_file_list * tmp = head; + free_flowfile(tmp->ff_record); + head = head->next; + free(tmp); + } +} + +void add_attributes(flow_file_record * ffr, const char * file_path, uint64_t curr_offset) { + char offset_str[21]; + snprintf(offset_str, sizeof(offset_str), "%llu", curr_offset); + add_attribute(ffr, "current offset", offset_str, strlen(offset_str)); + char content_location[strlen(ffr->contentLocation) + 1]; + snprintf(content_location, sizeof(content_location), "%s", ffr->contentLocation); + add_attribute(ffr, "content location", content_location, strlen(content_location)); + add_attribute(ffr, "tailfile path", (char*)file_path, strlen(file_path)); +} + +void update_attributes(flow_file_record * ffr, const char * file_path, uint64_t curr_offset) { + char offset_str[21]; + snprintf(offset_str, sizeof(offset_str), "%llu", curr_offset); + update_attribute(ffr, "current offset", offset_str, strlen(offset_str)); + char content_location[strlen(ffr->contentLocation) + 1]; + snprintf(content_location, sizeof(content_location), "%s", ffr->contentLocation); + update_attribute(ffr, "content location", content_location, strlen(content_location)); + update_attribute(ffr, "tailfile path", (char*)file_path, strlen(file_path)); +} + +void transmit_flow_files(nifi_instance * instance, flow_file_list * ff_list, int complete) { + if (!instance || !ff_list) { + return; + } + flow_file_list * el = NULL; + LL_FOREACH(ff_list, el) { Review comment: ```el``` cannot be null by definition: ``` 361 #define LL_FOREACH(head,el) \ 362 for(el=head;el;el=el->next) ``` The body of the loop could be merged as well, resulting in: ``` LL_FOREACH(ff_list, el) { if ( !complete || el->complete) { transmit_flowfile(el->ff_record, instance); } } ``` ---------------------------------------------------------------- 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
