gSOAP to implement an ONVIF device
Prerequisites
- gSOAP 2.8.62 or greater for ONVIF projects.
I used the 2.8.76 GPL version from SourceForge - Option
soapcpp2 -2forces SOAP 1.2, which is required by ONVIF. - Compilers and libraries
$ sudo apt-get install c++ gcc libssl-dev bison flex
Useful Knowledge
- The function you need to implement in C will be written in soapStub.h under "Externals" and "Server-Side Operations" section. If you don't you'll get undefined reference errors.
For example in soapStub.h :
SOAP_FMAC5 int SOAP_FMAC6 __trt__DeleteOSD(struct soap*, struct _trt__DeleteOSD *trt__DeleteOSD, struct _trt__DeleteOSDResponse *trt__DeleteOSDResponse);
Then you just need to drop the SOAP_FMACX notations and copy paste the function header in your C file :
int __trt__DeleteOSD(struct soap*, struct _trt__DeleteOSD *trt__DeleteOSD, struct _trt__DeleteOSDResponse *trt__DeleteOSDResponse); - When you have a SOAP server with gSOAP, you serve services objects. Those services classes are generated by soapcpp2 option `-j`
myService service; if (soap_invalid_socket(service.bind(NULL, port, 100))) ... // error for (;;) { if (!soap_valid_socket(service.accept())) { service.soap_stream_fault(std::cerr); exit(1); } if (soap_begin_serve(service.soap) == SOAP_OK) (...)
Helpers
/* generated/onvif.h:4775 */
#ifndef SOAP_TYPE_tds__Service
#define SOAP_TYPE_tds__Service (393)
/* complex XML schema type 'tds:Service': */
struct tds__Service {
/** Required element 'tds:Namespace' of XML schema type 'xsd:anyURI' */
char *Namespace;
/** Required element 'tds:XAddr' of XML schema type 'xsd:anyURI' */
char *XAddr;
/** Optional element 'tds:Capabilities' of XML schema type 'tds:Service-Capabilities' */
struct _tds__Service_Capabilities *Capabilities;
/** Required element 'tds:Version' of XML schema type 'tt:OnvifVersion' */
struct tt__OnvifVersion *Version;
/** Sequence of elements '-any' of XML schema type 'xsd:anyType' stored in dynamic array __any of length __size */
int __size;
struct soap_dom_element *__any;
/** XML DOM attribute list */
struct soap_dom_attribute __anyAttribute;
};
#endif
/* generated/onvif.h:4838 */
#ifndef SOAP_TYPE_tds__DeviceServiceCapabilities
#define SOAP_TYPE_tds__DeviceServiceCapabilities (398)
/* complex XML schema type 'tds:DeviceServiceCapabilities': */
struct tds__DeviceServiceCapabilities {
/** Required element 'tds:Network' of XML schema type 'tds:NetworkCapabilities' */
struct tds__NetworkCapabilities *Network;
/** Required element 'tds:Security' of XML schema type 'tds:SecurityCapabilities' */
struct tds__SecurityCapabilities *Security;
/** Required element 'tds:System' of XML schema type 'tds:SystemCapabilities' */
struct tds__SystemCapabilities *System;
/** Optional element 'tds:Misc' of XML schema type 'tds:MiscCapabilities' */
struct tds__MiscCapabilities *Misc;
};
#endif
Useful Command Lines
- To see what ports are open listening on the system
$ ss -nutlp
$ netstat -tulnp - To see what ports are open for listening by a PID
$ lsof -aPi -p 7366
Compile one of the Provided Sample First
wsdl2h -c -s -o xmas.wsdl-nostl.h xmas.wsdl
soapcpp2 -j -C -Iimport xmas.wsdl-nostl.h gmt.h calc.h env.h
The options comes from here https://www.genivia.com/doc/guide/html/index.html
Generate the ONVIF WSDL headers in C/C++
From https://www.genivia.com/examples/onvif/index.html#Converting_ONVIF_WSDLs_to_C/C++
wsdl2h -c -g -o wsdiscovery.h -t typemap.dat http://www.onvif.org/onvif/ver10/device/wsdl/devicemgmt.wsdl http://www.onvif.org/onvif/ver10/event/wsdl/event.wsdl https://www.onvif.org/ver20/ptz/wsdl/ptz.wsdl https://www.onvif.org/ver10/media/wsdl/media.wsdl https://raw.githubusercontent.com/crrlab/TND/master/data/onvif/ws-discovery.wsdl http://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl
Note: the -c option is for C output. For C++ omit this one.
Debug under GDB
sudo gdb --args onvif_srvd_debug --pid_file onvif_srvd_debug.pid --ifs enp7s0 --scope onvif://www.onvif.org/name/TestDevC --scope onvif://www.onvif.org/location/Unknow --scope onvif://www.onvif.org/Profile/Streaming --scope onvif://www.onvif.org/Profile/S --name RTSP --width 800 --height 600 --url rtsp://%s:554/unicast --type H264
Troubleshooting
Problem
ake[4]: Entering directory `/home/frank/onvif/gsoap-2.8/gsoap/src'
/bin/sh ../../ylwrap soapcpp2_yacc.y y.tab.c soapcpp2_yacc.c y.tab.h `echo soapcpp2_yacc.c | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output soapcpp2_yacc.output -- yacc -d -v
../../ylwrap: line 176: yacc: command not found
Solution
Install bison + flex, check the "Prerequisite" section above. You don't need yacc.
Run ./configure again so it detects it.
Problem
gcc -DHAVE_CONFIG_H -I. -I../.. -DWITH_YACC -DWITH_LEX -DSOAPCPP2_IMPORT_PATH="\"/usr/local/share/gsoap/import\"" -DLINUX -g -O2 -MT soapcpp2-soapcpp2_yacc.o -MD -MP -MF .deps/soapcpp2-soapcpp2_yacc.Tpo -c -o soapcpp2-soapcpp2_yacc.o `test -f 'soapcpp2_yacc.c' || echo './'`soapcpp2_yacc.c
mv -f .deps/soapcpp2-soapcpp2_yacc.Tpo .deps/soapcpp2-soapcpp2_yacc.Po
/bin/sh ../../ylwrap soapcpp2_lex.l .c soapcpp2_lex.c -- /bin/sh /home/frank/onvif/gsoap-2.8/missing flex
/home/frank/onvif/gsoap-2.8/missing: line 81: flex: command not found
WARNING: 'flex' is missing on your system.
Solution
Install bison + flex, check the "Prerequisite" section above.
Run ./configure again so it detects it.
Problem
[frank@blackberry link]$ cc -o xmasapp xmas.c soapC.c -lgsoap
xmas.c:53:18: fatal error: gmtH.h: No such file or directory
#include "gmtH.h"
^
compilation terminated.
Solution
Just run "make" instead of doing it manually. It will generate gmtH.h.
References
http://chihchengyang.github.io/2016/11/18/Onvif/
https://github.com/johnnywww/nvtonvifserverc/blob/master/onvifHandleDeviceManagement.c
https://github.com/shengjuntu/onvif-ipcam/blob/master/device_manage.c
http://shoaib-ahmed.com/onvif-gsoap-in-c-by-example/
https://github.com/mpromonet/v4l2onvif
https://github.com/shengjuntu/onvif-ipcam/blob/master/soapTester.c
http://albert-oma.blogspot.com/2013/09/onvif-ws-discovery-implementation.html
http://www.happytimesoft.com/products/onvif-server/index.html
https://www.lingodigit.com/onvif_nvc.html
http://www.idsprotect.com/index.php/download-video-surveillance/ip-surveillance/ip-cameras/item/onvif-test-tool
https://stackoverflow.com/questions/18998282/simulators-for-testing-onvif-webservice
http://pc-cctv.com/products/onvif-dialog-recorder/onvif-dialog-sample1/
https://carlrowan.wordpress.com/2018/12/23/ip-camera-control-using-python-via-onvif-for-opencv-image-processing/
http://cercis.org/software/creating-a-software-for-connecting-to-onvif-cameras.crcs
thank you for sharing. what\'s next?