[
https://issues.apache.org/jira/browse/MINIFICPP-558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16686739#comment-16686739
]
ASF GitHub Bot commented on MINIFICPP-558:
------------------------------------------
Github user arpadboda commented on a diff in the pull request:
https://github.com/apache/nifi-minifi-cpp/pull/437#discussion_r233500950
--- Diff: extensions/coap/nanofi/coap_functions.c ---
@@ -0,0 +1,175 @@
+/**
+ *
+ * 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 "coap_functions.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Initialize the API access. Not thread safe.
+ */
+void init_coap_api(void *rcvr, callback_pointers *ptrs) {
+ global_ptrs.data_received = ptrs->data_received;
+ global_ptrs.received_error = ptrs->received_error;
+ receiver = rcvr;
+}
+
+
+int create_session(coap_context_t **ctx, coap_session_t **session, const
char *node, const char *port, coap_address_t *dst_addr) {
+ int s;
+ struct addrinfo hints;
+ coap_proto_t proto = COAP_PROTO_UDP;
+ struct addrinfo *result, *rp;
+
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_UNSPEC; // ipv4 or ipv6
+ hints.ai_socktype = COAP_PROTO_RELIABLE(proto) ? SOCK_STREAM :
SOCK_DGRAM;
+ hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST | AI_NUMERICSERV | AI_ALL;
+
+ s = getaddrinfo(node, port, &hints, &result);
+ if (s != 0) {
+ fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
+ return -1;
+ }
+
+ for (rp = result; rp != NULL; rp = rp->ai_next) {
+ coap_address_t addr;
+
+ if (rp->ai_addrlen <= sizeof(addr.addr)) {
+ coap_address_init(&addr);
+ addr.size = rp->ai_addrlen;
+ memcpy(&addr.addr, rp->ai_addr, rp->ai_addrlen);
+
+ *ctx = coap_new_context(0x00);
+
+ *session = coap_new_client_session(*ctx, &addr, dst_addr, proto);
+ if (*ctx && *session) {
+ freeaddrinfo(result);
+ return 0;
+ }
+ }
+ }
+
+ fprintf(stderr, "no context available for interface '%s'\n", node);
+
+ freeaddrinfo(result);
+ return -1;
+}
+
+struct coap_pdu_t *create_request(struct coap_context_t *ctx,struct
coap_session_t *session,coap_optlist_t **optlist, unsigned char code,
coap_str_const_t *ptr) {
+ coap_pdu_t *pdu;
+
+ if (!(pdu = coap_new_pdu(session)))
+ return NULL;
+
+ pdu->type = COAP_MESSAGE_CON;
+ pdu->tid = coap_new_message_id(session);
+ pdu->code = code;
+
+ if (optlist){
+ coap_add_optlist_pdu(pdu, optlist);
+ }
+
+ int flags = 0;
+ coap_add_data(pdu, ptr->length, ptr->s);
+ return pdu;
+}
+
+int coap_event(struct coap_context_t *ctx, coap_event_t event, struct
coap_session_t *session){
+ if (event == COAP_EVENT_SESSION_FAILED && global_ptrs.received_error){
+ global_ptrs.received_error(receiver, ctx, -1);
+ }
+ return 0;
+}
+
+void no_acknowledgement(struct coap_context_t *ctx, coap_session_t
*session, coap_pdu_t *sent, coap_nack_reason_t reason, const coap_tid_t id){
+ if (global_ptrs.received_error){
+ global_ptrs.received_error(receiver, ctx, -1);
+ }
+}
+
+void response_handler(struct coap_context_t *ctx, struct coap_session_t
*session, coap_pdu_t *sent, coap_pdu_t *received, const coap_tid_t id) {
+ unsigned char* data;
+ size_t data_len;
+ coap_opt_iterator_t opt_iter;
+ coap_opt_t * block_opt = coap_check_option(received, COAP_OPTION_BLOCK1,
&opt_iter);
+ if (block_opt) {
--- End diff --
Why not
```
if(!block_opt)
```
?
> Move PayloadSerializer in preparation for Coap
> ----------------------------------------------
>
> Key: MINIFICPP-558
> URL: https://issues.apache.org/jira/browse/MINIFICPP-558
> Project: NiFi MiNiFi C++
> Issue Type: Bug
> Reporter: Mr TheSegfault
> Assignee: Mr TheSegfault
> Priority: Major
> Fix For: 0.6.0
>
>
> Move PayloadSerializer
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)