phrocker commented on a change in pull request #482: Minificpp 658 - Port Raw 
Site to Site to C
URL: https://github.com/apache/nifi-minifi-cpp/pull/482#discussion_r259815551
 
 

 ##########
 File path: nanofi/include/sitetosite/CPeer.h
 ##########
 @@ -0,0 +1,134 @@
+/**
+ *
+ * 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.
+ */
+#ifndef LIBMINIFI_INCLUDE_CSITETOSITE_CPEER_H_
+#define LIBMINIFI_INCLUDE_CSITETOSITE_CPEER_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <uuid/uuid.h>
+#include "core/cstream.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static const char MAGIC_BYTES[] = { 'N', 'i', 'F', 'i' };
+
+struct SiteToSiteCPeer;
+
+// open connection to the peer
+int openPeer(struct SiteToSiteCPeer * peer);
+
+// close connection to the peer
+void closePeer(struct SiteToSiteCPeer * peer);
+
+// Site2SitePeer Class
+struct SiteToSiteCPeer {
+
+  cstream * stream_;
+
+  // URL
+  char * url_;
+
+  char * host_;
+
+  uint16_t port_;
+
+  enum Bool owns_socket_;
+
+  //io::NetworkInterface local_network_interface_;
+
+  // Logger
+  //std::shared_ptr<logging::Logger> logger_;
+};
+
+static const char * getURL(const struct SiteToSiteCPeer * peer) {
+  return peer->url_;
+}
+
+static void setHostName(struct SiteToSiteCPeer * peer, const char * hostname) {
+  if(peer->host_) {
+    free(peer->host_);
+  }
+  if(peer->url_) {
+    free(peer->url_);
+  }
+  if(hostname == NULL || strlen(hostname) == 0) {
+    peer->host_ = NULL;
+    peer->url_ = NULL;
+    return;
+  }
+  size_t host_len = strlen(hostname);
+  peer->host_ = (char*)malloc(host_len + 1); // +1 for trailing zero
+  peer->url_ = (char*)malloc(host_len + 14); // +1 for trailing zero, 1 for 
':', at most 5 for port, 7 for "nifi://" suffix
+  memset(peer->url_, 0, host_len + 14); // make sure to have zero padding no 
matter the length of the port
+  strncpy(peer->host_, hostname, host_len);
+  strncpy(peer->url_, "nifi://", 7);
+  strncpy(peer->url_ + 7, hostname, host_len);
+  peer->host_[host_len] = '\0';
+  peer->url_[host_len + 7] = ':';
+  if(peer->port_ != 0) {
 
 Review comment:
   Not sure it's ever appropriate to ever have an empty port, unless using 
HTTP,  in which case the scheme above would be incorrect. Further, why not just 
use a single snprintf versus strncpy(s). Further, what limits port to 5 digits? 
Is that done elsewhere?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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