Explorar el Código

services: added init of response and error msg for not supported services

Leon Urbas hace 11 años
padre
commit
1cc8a4e430

+ 5 - 5
Makefile.am

@@ -1,16 +1,16 @@
-AM_CFLAGS = -std=c99 -pedantic -pipe -fPIC -fno-exceptions -fstack-protector -Wl,-z,relro -Wl,-z,now -fvisibility=hidden -W -Wall -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -Werror
+AM_CPPFLAGS = -std=c99 -pedantic -pipe -fPIC -fno-exceptions -fstack-protector -Wl,-z,relro -Wl,-z,now -fvisibility=hidden -W -Wall -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -Werror
 if DEBUG
-AM_CFLAGS += -g3 -O0
+AM_CPPFLAGS += -g3 -O0
 else
-AM_CFLAGS += -O2 
+AM_CPPFLAGS += -O2 
 endif
 
 if COVERAGE
-AM_CFLAGS += --coverage
+AM_CPPFLAGS += --coverage
 AM_LDFLAGS = --coverage
 endif
 
-export GLOBAL_AM_CFLAGS = $(AM_CFLAGS)
+export GLOBAL_AM_CFLAGS = $(AM_CPPFLAGS)
 
 SUBS=tool include src
 if HAVE_CHECK

+ 4 - 3
examples/src/networklayer.c

@@ -68,7 +68,7 @@ UA_Int32 NL_msgLoop(NL_data* nl, struct timeval *tv, UA_Int32(*worker)(void*), v
 		// determine the largest handle
 		nl->maxReaderHandle = 0;
 		UA_list_iteratePayload(&(nl->connections),NL_setFdSet);
-		DBG_VERBOSE(printf("UA_Stack_msgLoop - maxHandle=%d\n", nl->maxReaderHandle));
+		DBG_VERBOSE(printf("\n------------\nUA_Stack_msgLoop - maxHandle=%d\n", nl->maxReaderHandle));
 
 		// copy tv, some unixes do overwrite and return the remaining time
 		struct timeval tmptv;
@@ -171,7 +171,8 @@ UA_Int32 NL_TCP_writer(struct TL_Connection_T* c, const UA_ByteString** gather_b
 		iov[i].iov_base = gather_buf[i]->data;
 		iov[i].iov_len = gather_buf[i]->length;
 		total_len += gather_buf[i]->length;
-		DBG_VERBOSE(UA_ByteString_printx("NL_TCP_writer - msg=", gather_buf[i]));
+		DBG_VERBOSE(printf("NL_TCP_writer - gather_buf[%i]",i));
+		DBG_VERBOSE(UA_ByteString_printx("=", gather_buf[i]));
 	}
 
 	struct msghdr message;
@@ -189,7 +190,7 @@ UA_Int32 NL_TCP_writer(struct TL_Connection_T* c, const UA_ByteString** gather_b
 		do {
 			DBG_VERBOSE(printf("NL_TCP_writer - enter write\n"));
 			n = sendmsg(c->connectionHandle, &message, 0);
-			DBG_VERBOSE(printf("NL_TCP_writer - leave write with n=%d,errno={%d,%s}\n",n,errno,strerror(errno)));
+			DBG_VERBOSE(printf("NL_TCP_writer - leave write with n=%d,errno={%d,%s}\n",n,(n>0)?0:errno,(n>0)?"":strerror(errno)));
 		} while (n == -1L && errno == EINTR);
 		if (n >= 0) {
 			nWritten += n;

+ 2 - 2
src/ua_namespace.c

@@ -113,7 +113,7 @@ UA_Int32 insert_node(namespace *ns, UA_Node *node) {
 	return UA_SUCCESS;
 }
 
-UA_Int32 get_node(namespace *ns, const UA_NodeId *nodeid, UA_Node ** const result, ns_lock ** lock) {
+UA_Int32 get_node(namespace const *ns, const UA_NodeId *nodeid, UA_Node const ** result, ns_lock ** lock) {
 	ns_entry *slot;
 	if(find_slot(ns, &slot, nodeid) != UA_SUCCESS) return UA_ERROR;
 #ifdef MULTITHREADING
@@ -124,7 +124,7 @@ UA_Int32 get_node(namespace *ns, const UA_NodeId *nodeid, UA_Node ** const resul
 	return UA_SUCCESS;
 }
 
-UA_Int32 get_writable_node(namespace *ns, const UA_NodeId *nodeid, UA_Node **result, ns_lock ** lock) {
+UA_Int32 get_writable_node(const namespace *ns, const UA_NodeId *nodeid, UA_Node **result, ns_lock ** lock) {
 	ns_entry *slot;
 	if(find_slot(ns, &slot, nodeid) != UA_SUCCESS) return UA_ERROR;
 #ifdef MULTITHREADING

+ 2 - 2
src/ua_namespace.h

@@ -51,8 +51,8 @@ UA_Int32 create_ns(namespace **result, uint32_t size);
 void empty_ns(namespace *ns);
 void delete_ns(namespace *ns);
 UA_Int32 insert_node(namespace *ns, UA_Node *node);
-UA_Int32 get_node(namespace *ns, const UA_NodeId *nodeid, UA_Node ** const result, ns_lock ** lock);
-UA_Int32 get_writable_node(namespace *ns, const UA_NodeId *nodeid, UA_Node **result, ns_lock ** lock); // use only for _single_ writes.
+UA_Int32 get_node(namespace const *ns, const UA_NodeId *nodeid, UA_Node const ** result, ns_lock ** lock);
+UA_Int32 get_writable_node(namespace const *ns, const UA_NodeId *nodeid, UA_Node **result, ns_lock ** lock); // use only for _single_ writes.
 UA_Int32 get_tc_node(namespace *ns, transaction_context *tc, const UA_NodeId *nodeid, UA_Node ** const result, ns_lock ** lock);
 UA_Int32 get_tc_writable_node(namespace *ns, transaction_context *tc, const UA_NodeId *nodeid, UA_Node **result, ns_lock ** lock); // use only for _single_ writes.
 

+ 2 - 1
src/ua_services_attribute.c

@@ -39,7 +39,7 @@ static UA_DataValue * service_read_node(Application *app, const UA_ReadValueId *
 		return v;
 	}
 	
-	UA_Node *node = UA_NULL;
+	UA_Node const *node = UA_NULL;
 	ns_lock *lock = UA_NULL;
 	UA_Int32 result = get_node(ns, &id->nodeId, &node, &lock);
 	if(result != UA_SUCCESS) {
@@ -47,6 +47,7 @@ static UA_DataValue * service_read_node(Application *app, const UA_ReadValueId *
 		v->status = UA_STATUSCODE_BADNODEIDUNKNOWN;
 		return v;
 	}
+	DBG_VERBOSE(UA_NodeId_printf("service_read_node - found node=",&(node->nodeId)));
 
 	switch(id->attributeId) {
 	case UA_ATTRIBUTEID_NODEID:

+ 11 - 1
src/ua_transport_binary_secure.c

@@ -96,6 +96,7 @@ static void init_response_header(UA_RequestHeader const * p, UA_ResponseHeader *
 	UA_##TYPE##Request p; \
 	UA_##TYPE##Response r; \
 	UA_##TYPE##Request_decodeBinary(msg, pos, &p); \
+	UA_##TYPE##Response_init(&r); \
 	init_response_header(&p.requestHeader, &r.responseHeader); \
 	DBG_VERBOSE(printf("Invoke Service: %s\n", #TYPE)); \
 	Service_##TYPE(channel, &p, &r); \
@@ -149,7 +150,16 @@ UA_Int32 SL_handleRequest(SL_Channel *channel, const UA_ByteString* msg, UA_Int3
 	else {
 		printf("SL_processMessage - unknown request, namespace=%d, request=%d\n", serviceRequestType.namespace,serviceRequestType.identifier.numeric);
 		retval = UA_ERROR;
-		responsetype = 0; //FIXME
+		UA_RequestHeader p;
+		UA_ResponseHeader r;
+		UA_RequestHeader_decodeBinary(msg,pos,&p);
+		UA_ResponseHeader_init(&r);
+		r.requestHandle = p.requestHandle;
+		r.serviceResult = UA_STATUSCODE_BADSERVICEUNSUPPORTED;
+		*pos = 0;
+		UA_ByteString_newMembers(&response_msg, UA_ResponseHeader_calcSize(&r));
+		UA_ResponseHeader_encodeBinary(&r, pos, &response_msg);
+		responsetype = UA_RESPONSEHEADER_NS0;
 	}
 
 	SL_Send(channel, &response_msg, responsetype);

+ 2 - 2
tests/check_namespace.c

@@ -37,7 +37,7 @@ START_TEST(findNodeInNamespaceWithSingleEntry) {
 	namespace *ns;
 	create_ns(&ns, 512);
 	UA_Node* n1; createNode(&n1,0,2253); insert_node(ns,n1);
-	UA_Node* nr = UA_NULL;
+	const UA_Node* nr = UA_NULL;
 	ns_lock* nl = UA_NULL;
 	UA_Int32 retval;
 	// when
@@ -57,7 +57,7 @@ START_TEST(findNodeInNamespaceWithTwoEntries) {
 	UA_Node* n1; createNode(&n1,0,2253); insert_node(ns,n1);
 	UA_Node* n2; createNode(&n2,0,2255); insert_node(ns,n2);
 
-	UA_Node* nr = UA_NULL;
+	const UA_Node* nr = UA_NULL;
 	ns_lock* nl = UA_NULL;
 	UA_Int32 retval;
 	// when