1 Preparation
1.1 INTRODUCTION
- ONVIF has many modules, and each module corresponds to a different WSDL document. You can compile the specified WSDL document according to your needs;
- WSDL documents can be Protocol specification , select the corresponding wsdl and right-click the link to save as (local compilation is required, online compilation is not required);
- gSoap can compile WSDL documents to generate C/C + + source code;
- gSoap tool download address: gSoap Download
- gSoap usage guide: https://www.genivia.com/resources.html
1.2 download
- WSDL document: link: https://pan.baidu.com/s/1lpg3A3VmFt6jJ2NzWhEpSg Extraction code: w775
- gSoap tool: link: https://pan.baidu.com/s/13KOEu2cMThQIMRUjvfzuzQ Extraction code: cb2m
- Compile and generate C code:
- Compile and generate C + + Code:
1.3 installing and compiling OpenSSL
Download and compile OpenSSL to get the wsdl2h file that opens SSL/TLS
Address: https://www.openssl.org/source/
cd /openssl-1.0.2r ./config sudo make sudo make install
1.4 installing and compiling gSOAP
- Download and compile gsoap (download the open source version to GPLv2 Open Source Edition), address: http://www.cs.fsu.edu/~engelen/soap.html
- Compile and generate wsdl2h and soapcpp2 (there are compiled on mac and Windows, and you need to compile wsdl2h yourself under Linux):
cd gsoap-2.8 $ ./configure --with-openssl=/usr/local/ssl $ make $ make install
- error: invalid conversion from 'char*' to 'int' [-fpermissive] err = str
Find the error reporting corresponding function, add atoi and convert char * into int
- Check whether the compilation is successful
wsdl2h -h # check if successful whereis soapcpp2 # Query wsdl2h file location
2 compilation
- It can be configured locally (it is troublesome to change the file) or online (it needs Networking)
- /usr/local/bin/wsdl2h -h: you can view the meaning of each option
- /usr/local/bin/soapcpp2 -h: check the meaning of each option
- After wsdl2h and soapcpp2 are compiled, they can be found through sudo find / -name wsdl2h
- It is mainly divided into three scripts: wsdl2hOnvif_online.sh/wsdl2hOnvif_offline.sh,soapcpp2Onvif.sh and cp_other_file.sh
Online configuration
- Script wsdl2hOnvif_online.sh
- C++:
#!/bin/bash /usr/local/bin/wsdl2h -P -s -x -c++ -t /home/gsoap-2.8/gsoap/typemap.dat -o /home/nvidia/Downloads/ONVIF-C++/onvif.h \ https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl\ https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl\ https://www.onvif.org/ver10/media/wsdl/media.wsdl\ https://www.onvif.org/ver20/media/wsdl/media.wsdl\ https://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl
- C:
#!/bin/bash /usr/local/bin/wsdl2h -P -x -c -s -t /home/gsoap-2.8/gsoap/typemap.dat -o /home/nvidia/Downloads/ONVIF-C/onvif.h \ https://www.onvif.org/ver10/device/wsdl/devicemgmt.wsdl\ https://www.onvif.org/ver20/imaging/wsdl/imaging.wsdl\ https://www.onvif.org/ver10/media/wsdl/media.wsdl\ https://www.onvif.org/ver20/media/wsdl/media.wsdl\ https://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl
-P: Do not create an inheritance from XSD__ Polymorphic type of anytype
-x: Do not generate_ XML any / anyAttribute extensible element
-s: Do not generate STL code (no std::string and no std::vector),
- Authentication (add the following at the beginning of onvif.h)
#import "wsse.h"
- Modify gSOAP / import / wsa5 Soap in H_ ENV__ Fault is SOAP_ENV__Fault_WSA5
#import "wsdd10.h" // wsdd10.h and #import "wsa.h" #import "wsa5.h" // wsa.h and wsa5 H two files repeatedly define int SOAP_ENV__Fault
- Script soapcpp2onvif SH, generate cpp code and link module
- C++
#!/bin/bash /usr/local/bin/soapcpp2 -2 -x -L -C -c++ -d /home/nvidia/Downloads/ONVIF-C++/build \ -I /home/gsoap-2.8/gsoap \ -I /home/gsoap-2.8/gsoap/import \ -I /home/gsoap-2.8/gsoap/custom \ /home/nvidia/Downloads/ONVIF-C++/onvif.h
- C:
#!/bin/bash /usr/local/bin/soapcpp2 -2 -x -L -C -c -d /home/nvidia/Downloads/ONVIF-C/build\ -I /home/gsoap-2.8/gsoap \ -I /home/gsoap-2.8/gsoap/import \ -I /home/gsoap-2.8/gsoap/custom \ /home/nvidia/Downloads/ONVIF-C++/onvif.h
-
Generated file, reserved c/.cpp and h file, choose any one nsmap, all nsmap files are all the same namespace
-
Script cp_other_file.sh, copy other useful codes
cd /home/gsoap-2.8/gsoap sudo cp stdsoap2.cpp stdsoap2.h dom.cpp plugin/wsaapi.c plugin/wsaapi.h plugin/wsseapi.cpp plugin/wsseapi.h plugin/mecevp.c plugin/mecevp.h plugin/smdevp.c plugin/smdevp.h plugin/threads.c plugin/threads.h custom/duration.c custom/duration.h custom/struct_timeval.c custom/struct_timeval.h \ /home/nvidia/Downloads/ONVIF-C++
Local configuration
- On the official website https://www.onvif.org/profiles/specifications/ , right-click all WSDL files corresponding to Service definitions to save the WSDL file;
- Script wsdl2hOnvif_offline.sh
#!/bin/bash /usr/local/gSOAP/bin/wsdl2h -c++ -s -t typemap.dat -o samples/onvif/onvif.h \ samples/onvif/wsdl/devicemgmt.wsdl \ samples/onvif/wsdl/event.wsdl \ samples/onvif/wsdl/accesscontrol.wsdl \ samples/onvif/wsdl/accessrules.wsdl \ samples/onvif/wsdl/actionengine.wsdl \ samples/onvif/wsdl/analytics.wsdl \ samples/onvif/wsdl/appmgmt.wsdl \ samples/onvif/wsdl/authenticationbehavior.wsdl \ samples/onvif/wsdl/credential.wsdl \ samples/onvif/wsdl/deviceio.wsdl \ samples/onvif/wsdl/display.wsdl \ samples/onvif/wsdl/doorcontrol.wsdl \ samples/onvif/wsdl/imaging.wsdl \ samples/onvif/wsdl/media.wsdl \ samples/onvif/wsdl/media.wsdl \ samples/onvif/wsdl/provisioning.wsdl \ samples/onvif/wsdl/ptz.wsdl \ samples/onvif/wsdl/receiver.wsdl \ samples/onvif/wsdl/recording.wsdl \ samples/onvif/wsdl/search.wsdl \ samples/onvif/wsdl/replay.wsdl \ samples/onvif/wsdl/schedule.wsdl \ samples/onvif/wsdl/advancedsecurity.wsdl \ samples/onvif/wsdl/thermal.wsdl \ samples/onvif/wsdl/uplink.wsdl
- During compilation, the compilation may fail due to the path problem. You can modify the corresponding path. After successful compilation, an onvif will be automatically generated H documents.
- The rest are consistent with the online configuration steps
3 simple test
main:
#include <soapH.h> #include <soapStub.h> #include <wsseapi.h> #include "PTZBinding.nsmap" int main(){ struct soap *soap = NULL; soap = soap_new(); return 0; }
Makefile:
TARGET := KeyGoPTZCam SOURCE := $(wildcard ../src/*.c) $(wildcard ../src/*.cpp) $(wildcard ../third/ONVIF-C++/src/*.cpp) $(wildcard ../third/ONVIF-C++/src/*.c) OBJS := $(patsubst %.cpp,%.o,$(patsubst %.c,%.o, $(SOURCE))) CXX := g++ LIBS = /usr/local/lib/libssl.a\ /usr/local/lib/libcrypto.a LIBS += -lpthread -ldl LDFLAGS := DEFINES := -DWITH_OPENSSL -DWITH_DOM -DWITH_NONAMESPACES INCLUDE := -I/usr/include\ -I../third/ONVIF-C++/include\ -I/usr/local/include/openssl CFLAGS = -g -Wall -O3 $(DEFINES) $(INCLUDE) -fPIC CXXFLAGS:= $(CFLAGS) -std=c++11 -Wunused-function -Wunused-variable -Wfatal-errors .PHONY : everything objs clean veryclean rebuild everything : $(TARGET) all : $(TARGET) rebuild: veryclean everything clean : rm -fr ../src/*.so rm -fr ../src/*.o veryclean : clean rm -fr $(TARGET) %.o : %.cpp $(CXX) -c $(CXXFLAGS) $< -o $@ %.o : %.c $(CXX) -c $(CXXFLAGS) $< -o $@ $(TARGET) : $(OBJS) $(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(LIBS)