Browse Source

Merge branch 'master' of github.com:acplt/open62541

Julius Pfrommer 11 years ago
parent
commit
495cab608b
8 changed files with 59 additions and 54 deletions
  1. 1 1
      Makefile.am
  2. 18 0
      README.md
  3. 8 29
      configure.ac
  4. 3 2
      doc/Makefile.am
  5. 3 3
      include/ua_basictypes.h
  6. 24 17
      src/ua_basictypes.c
  7. 1 1
      tests/check_builtin.c
  8. 1 1
      tests/check_memory.c

+ 1 - 1
Makefile.am

@@ -17,7 +17,7 @@ if HAVE_CHECK
 	SUBS+= tests
 endif
 
-if USE_DOXYGEN
+if ENABLE_DOXYGEN
 	SUBS+= doc
 endif
 SUBDIRS = $(SUBS) examples/src	

+ 18 - 0
README.md

@@ -22,6 +22,19 @@ $ make
 $ sudo make install
 $ sudo ldconfig
 ```
+##### Getting and using Doxygen
+* install the needed packages
+```bash
+sudo apt-get install graphviz doxygen:
+```
+* configure autotools, clean and build:
+```bash
+$ ./configure --enable-doxygen
+$ make clean
+$ make all
+```
+* the output is generated in doc/html/index.htm
+* configure the output of Doxygen with doc/Doxygen.in file
 
 ### Windows
 ##### Getting MinGW and MSYS:
@@ -66,3 +79,8 @@ $ ./configure --enable-debug=yes
 $ make
 $ make check
 ```
+### Configure Options 
+* --enable-debug=(yes|no|verbose) - omit/include debug code
+* --enable-multithreading - enable pthreads (for examples/src/opcuaServerMT)
+* --enable-doxygen - make documentation as well
+* --enable-coverage - profiling with gcov,lcov, make check will generate reports in tests/coverage 

+ 8 - 29
configure.ac

@@ -69,6 +69,7 @@ AM_CONDITIONAL(COVERAGE, test x"$coverage" = x"true")
 AM_COND_IF([COVERAGE],
     AC_DEFINE([COVERAGE])) #define MULTITHREADING is accessible from pre-processor
 
+#doxygen start
 AC_ARG_ENABLE(doxygen,
 AS_HELP_STRING([--enable-doxygen],
                [enable doxygen, default: no]),
@@ -80,37 +81,15 @@ AS_HELP_STRING([--enable-doxygen],
 
 AM_CONDITIONAL(ENABLE_DOXYGEN, test x"$enabledoxygen" = x"true")
 AC_CHECK_PROGS([DOXYGEN], [doxygen])
-AM_CONDITIONAL([HAVE_DOXYGEN],[test -n "$DOXYGEN"])
 
-AM_COND_IF([ENABLE_DOXYGEN],[AM_COND_IF([HAVE_DOXYGEN],[usedoxygen=true],[usedoxygen=false])],[usedoxygen=false])
-
-#if ENABLE_DOXYGEN;then
-   # if HAVE_DOXYGEN;then
-   #     usedoxygen = true
-   # else
-  #      usedoxygen = false
- #  fi
-#else
- #  usedoxygen = false
-#fi
-AM_CONDITIONAL([USE_DOXYGEN], test x"$usedoxygen" = x"true")
-
-AM_COND_IF([USE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
-
-
-
-
-
-    
-if test -z "$DOXYGEN";then 
-    AC_MSG_WARN([Doxygen not found - continuing without Doxygen support])
+#break if doxygen enabled but not present
+if test x"$enabledoxygen" = x"true"; then    
+	if test -z "$DOXYGEN"; then 
+    		AC_MSG_ERROR([Doxygen not found])
+	fi
 fi
-
-
-
-
-
-
+AM_COND_IF([ENABLE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
+#doxygen end
 
    
 AC_LIBTOOL_WIN32_DLL

+ 3 - 2
doc/Makefile.am

@@ -1,4 +1,4 @@
-if USE_DOXYGEN
+if ENABLE_DOXYGEN
 directory = $(top_srcdir)/doc/man/man3/
 
 dist_man_MANS = $(directory)/man_page_1.3 $(directory)/man_page_2.3
@@ -14,5 +14,6 @@ CLEANFILES = doxyfile.stamp
 all-local: doxyfile.stamp
 clean-local:
 	rm -rf $(top_srcdir)/docs/man
-
+	rm -rf html
+	rm -rf latex
 endif

+ 3 - 3
include/ua_basictypes.h

@@ -221,9 +221,9 @@ UA_Int32 UA_String_copy(UA_String const * src, UA_String* dst);
 UA_Int32 UA_String_copycstring(char const * src, UA_String* dst);
 UA_Int32 UA_String_copyprintf(char const * fmt, UA_String* dst, ...);
 UA_Int32 UA_String_compare(const UA_String *string1, const UA_String *string2);
-void UA_String_printf(char* label, const UA_String* string);
-void UA_String_printx(char* label, const UA_String* string);
-void UA_String_printx_hex(char* label, const UA_String* string);
+void UA_String_printf(char const * label, const UA_String* string);
+void UA_String_printx(char const * label, const UA_String* string);
+void UA_String_printx_hex(char const * label, const UA_String* string);
 
 /* ByteString - Part: 6, Chapter: 5.2.2.7, Page: 17 */
 UA_TYPE_METHOD_PROTOTYPES (UA_ByteString)

+ 24 - 17
src/ua_basictypes.c

@@ -119,16 +119,16 @@ UA_Int32 UA_memcpy(void * dst, void const * src, int size){
 #define UA_TYPE_START_ENCODEBINARY(TYPE) \
 UA_Int32 TYPE##_encodeBinary(TYPE const * src, UA_Int32* pos, UA_ByteString * dst) { \
 	UA_Int32 retval = UA_SUCCESS; \
-	if ( *pos+TYPE##_calcSize(src) > dst->length ) { \
-		return UA_ERR_NO_MEMORY; \
+	if ( *pos < 0 || *pos+TYPE##_calcSize(src) > dst->length ) { \
+		return UA_ERR_INVALID_VALUE; \
 	} else {
 
 // Attention! this macro works only for TYPEs with storageSize = encodingSize
 #define UA_TYPE_START_DECODEBINARY(TYPE) \
 UA_Int32 TYPE##_decodeBinary(UA_ByteString const * src, UA_Int32* pos, TYPE * dst) { \
 	UA_Int32 retval = UA_SUCCESS; \
-	if ( *pos+TYPE##_calcSize(UA_NULL) > src->length ) { \
-		return UA_ERR_NO_MEMORY; \
+	if ( *pos < 0 || *pos+TYPE##_calcSize(UA_NULL) > src->length ) { \
+		return UA_ERR_INVALID_VALUE; \
 	} else {
 
 #define UA_TYPE_END_XXCODEBINARY \
@@ -379,8 +379,8 @@ UA_Int32 UA_String_encodeBinary(UA_String const * src, UA_Int32* pos, UA_ByteStr
 	UA_Int32 retval = UA_SUCCESS;
 	if (src == UA_NULL) {
 		return UA_ERR_INVALID_VALUE;
-	} else if (*pos + UA_String_calcSize(src) > dst->length) {
-		return UA_ERR_NO_MEMORY;
+	} else if (*pos < 0 || *pos + UA_String_calcSize(src) > dst->length) {
+		return UA_ERR_INVALID_VALUE;
 	} else {
 		retval = UA_Int32_encodeBinary(&(src->length),pos,dst);
 		if (src->length > 0) {
@@ -393,11 +393,18 @@ UA_Int32 UA_String_encodeBinary(UA_String const * src, UA_Int32* pos, UA_ByteStr
 UA_Int32 UA_String_decodeBinary(UA_ByteString const * src, UA_Int32* pos, UA_String * dst) {
 	UA_Int32 retval = UA_SUCCESS;
 	retval |= UA_Int32_decodeBinary(src,pos,&(dst->length));
-	if (dst->length > 0) {
-		retval |= UA_alloc((void**)&(dst->data),dst->length);
-		retval |= UA_memcpy(dst->data,&(src->data[*pos]),dst->length);
-		*pos += dst->length;
+	if (retval == UA_SUCCESS && dst->length > 0) {
+		if (*pos >= 0 && (dst->length <= (src->length - *pos))) { // read beyond end of src is assumed to be an error
+			retval |= UA_alloc((void**)&(dst->data),dst->length);
+			retval |= UA_memcpy(dst->data,&(src->data[*pos]),dst->length);
+			*pos += dst->length;
+		} else {
+			dst->data = UA_NULL;
+			dst->length = -1;
+			retval = UA_ERR_INVALID_VALUE;
+		}
 	} else {
+		dst->length = -1;
 		dst->data = UA_NULL;
 	}
 	return retval;
@@ -475,17 +482,17 @@ UA_Int32 UA_String_compare(const UA_String* string1, const UA_String* string2) {
 	} else if (string1->length != string2->length) {
 		retval = UA_NOT_EQUAL;
 	} else {
-		// casts to overcome signed warnings
-		// FIXME: map return of strncmp to UA_EQUAL/UA_NOT_EQUAL
-		retval = strncmp((char const*)string1->data,(char const*)string2->data,string1->length);
+		// casts are needed to overcome signed warnings
+		UA_Int32 is = strncmp((char const*)string1->data,(char const*)string2->data,string1->length);
+		retval = (is == 0) ? UA_EQUAL : UA_NOT_EQUAL;
 	}
 	return retval;
 }
-void UA_String_printf(char* label, const UA_String* string) {
+void UA_String_printf(char const * label, const UA_String* string) {
 	printf("%s {Length=%d, Data=%.*s}\n", label, string->length,
 			string->length, (char*)string->data);
 }
-void UA_String_printx(char* label, const UA_String* string) {
+void UA_String_printx(char const * label, const UA_String* string) {
 	int i;
 	if (string == UA_NULL) { printf("%s {NULL}\n", label); return; }
 	printf("%s {Length=%d, Data=", label, string->length);
@@ -499,7 +506,7 @@ void UA_String_printx(char* label, const UA_String* string) {
 	}
 	printf("}}\n");
 }
-void UA_String_printx_hex(char* label, const UA_String* string) {
+void UA_String_printx_hex(char const * label, const UA_String* string) {
 	int i;
 	printf("%s {Length=%d, Data=", label, string->length);
 	if (string->length > 0) {
@@ -513,7 +520,7 @@ void UA_String_printx_hex(char* label, const UA_String* string) {
 }
 
 
-// TODO: should we really handle UA_String and UA_ByteString the same way?
+// TODO: should we really want to handle UA_String and UA_ByteString the same way?
 UA_TYPE_METHOD_PROTOTYPES_AS(UA_ByteString, UA_String)
 UA_TYPE_METHOD_NEW_DEFAULT(UA_ByteString)
 UA_Int32 UA_ByteString_compare(const UA_ByteString *string1, const UA_ByteString *string2) {

+ 1 - 1
tests/check_builtin.c

@@ -864,7 +864,7 @@ START_TEST(UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr)
 	UA_Int32 retval = UA_String_decodeBinary(&src, &pos, &dst);
 	// then
 	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_int_eq(dst.length,0);
+	ck_assert_int_eq(dst.length,-1); // shall we keep zero?
 	ck_assert_ptr_eq(dst.data,UA_NULL);
 }
 END_TEST

+ 1 - 1
tests/check_memory.c

@@ -85,7 +85,7 @@ int main() {
 	suite_add_tcase(s,tc);
 
 	sr = srunner_create(s);
-	//for debugging puposes only
+	//for debugging puposes only, will break make check
 	//srunner_set_fork_status(sr,CK_NOFORK);
 	srunner_run_all(sr,CK_NORMAL);
 	number_failed += srunner_ntests_failed(sr);