client_R_2_3_6_1'.
Sprout from wms_chpt_patch_1251 2007-10-10 16:57:51 UTC Aleš Křenek <ljocha@ics.muni.cz> 'push version'
Delete:
org.glite.lb.server/.cvsignore
org.glite.lb.server/LICENSE
org.glite.lb.server/Makefile
org.glite.lb.server/build.xml
org.glite.lb.server/config/glite-lb-dbsetup-migrate2transactions.sql
org.glite.lb.server/config/glite-lb-dbsetup.sql
org.glite.lb.server/config/glite-lb-index.conf.template
org.glite.lb.server/config/startup
org.glite.lb.server/examples/stdsoap2_2.6.0.c
org.glite.lb.server/examples/stdsoap2_2.6.2.c
org.glite.lb.server/examples/stdsoap2_2.7.0c.c
org.glite.lb.server/examples/stdsoap2_2.7.0d.c
org.glite.lb.server/examples/ws_getversion.c
org.glite.lb.server/examples/ws_joblog.c
org.glite.lb.server/examples/ws_jobstat.c
org.glite.lb.server/examples/ws_query_ex.c
org.glite.lb.server/interface/index.h
org.glite.lb.server/interface/job-attrs.xsd
org.glite.lb.server/interface/job-record.xsd
org.glite.lb.server/interface/lb_authz.h
org.glite.lb.server/interface/lbs_db.h
org.glite.lb.server/interface/srv_perf.h
org.glite.lb.server/interface/store.h
org.glite.lb.server/project/.cvsignore
org.glite.lb.server/project/build.number
org.glite.lb.server/project/build.properties
org.glite.lb.server/project/configure.properties.xml
org.glite.lb.server/project/properties.xml
org.glite.lb.server/project/tar_exclude
org.glite.lb.server/project/version.properties
org.glite.lb.server/src/bkindex.c
org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/db_store.c
org.glite.lb.server/src/dump.c
org.glite.lb.server/src/get_events.c.T
org.glite.lb.server/src/get_events.h
org.glite.lb.server/src/il_lbproxy.c
org.glite.lb.server/src/il_lbproxy.h
org.glite.lb.server/src/il_notification.c
org.glite.lb.server/src/il_notification.h
org.glite.lb.server/src/index.c.T
org.glite.lb.server/src/index_lex.l
org.glite.lb.server/src/index_parse.y
org.glite.lb.server/src/jobstat.c
org.glite.lb.server/src/jobstat.h
org.glite.lb.server/src/jobstat_supp.c
org.glite.lb.server/src/jp_job_attrs.xsl
org.glite.lb.server/src/lb_authz.c
org.glite.lb.server/src/lb_html.c
org.glite.lb.server/src/lb_html.h
org.glite.lb.server/src/lb_http.c
org.glite.lb.server/src/lb_http.h
org.glite.lb.server/src/lb_plugin.c
org.glite.lb.server/src/lb_proto.c
org.glite.lb.server/src/lb_proto.h
org.glite.lb.server/src/lb_xml_parse.c.T
org.glite.lb.server/src/lb_xml_parse.h
org.glite.lb.server/src/lb_xml_parse_V21.c.T
org.glite.lb.server/src/lb_xml_parse_V21.h
org.glite.lb.server/src/lbs_db.c
org.glite.lb.server/src/lbs_db_supp.c
org.glite.lb.server/src/load.c
org.glite.lb.server/src/lock.c
org.glite.lb.server/src/lock.h
org.glite.lb.server/src/notif_match.c
org.glite.lb.server/src/notification.c
org.glite.lb.server/src/openserver.c
org.glite.lb.server/src/process_event.c
org.glite.lb.server/src/process_event_condor.c
org.glite.lb.server/src/process_event_pbs.c
org.glite.lb.server/src/purge.h
org.glite.lb.server/src/query.c
org.glite.lb.server/src/query.h
org.glite.lb.server/src/request.c
org.glite.lb.server/src/seqcode.c
org.glite.lb.server/src/server_state.c
org.glite.lb.server/src/server_state.h
org.glite.lb.server/src/srv_purge.c
org.glite.lb.server/src/stats.c
org.glite.lb.server/src/stats.h
org.glite.lb.server/src/store.c.T
org.glite.lb.server/src/stored_master.c
org.glite.lb.server/src/userjobs.c
org.glite.lb.server/src/write2rgma.c
org.glite.lb.server/src/ws_fault.c
org.glite.lb.server/src/ws_fault.h
org.glite.lb.server/src/ws_query.c
org.glite.lb.server/src/ws_typemap.dat
org.glite.lb.server/src/ws_typemap.h
org.glite.lb.server/src/ws_typeref.c.T
org.glite.lb.server/src/ws_typeref.h
org.glite.lb.server/test/oneJob.qry
org.glite.lb.server/test/test_query_events.cpp
org.glite.lb.server/test/test_soap_conv.cpp
org.glite.lb.server/test/test_xml.cpp.T
org.glite.lb/.cvsignore
org.glite.lb/LICENSE
org.glite.lb/build.xml
org.glite.lb/deployment/README
org.glite.lb/deployment/deploy_all.diff
org.glite.lb/deployment/deploy_jp.diff
org.glite.lb/deployment/deploy_lb.diff
org.glite.lb/doc/README.lb4vdt
org.glite.lb/doc/copyright.tex
org.glite.lb/doc/frontmatter.tex
org.glite.lb/doc/perf_clear_proxy
org.glite.lb/doc/perf_purge
org.glite.lb/doc/perf_reg_jobs
org.glite.lb/doc/perf_results/il_sci_09062006.txt
org.glite.lb/doc/perf_results/il_sci_09062006_01.txt
org.glite.lb/doc/perf_results/il_sci_12062006.txt
org.glite.lb/doc/perf_results/ll_michal_21062006.txt
org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_22062006.txt
org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_23062006.txt
org.glite.lb/doc/perf_results/proxy_sci_09062006.txt
org.glite.lb/doc/perf_run_interlogd
org.glite.lb/doc/perf_run_proxy
org.glite.lb/doc/perf_run_server
org.glite.lb/doc/perf_run_test
org.glite.lb/doc/perftest.tex
org.glite.lb/doc/testplan.tex
org.glite.lb/lb4vdt/LB_install.sh
org.glite.lb/lb4vdt/Makefile.inc
org.glite.lb/lb4vdt/scripts/org.gridsite.core.build
org.glite.lb/project/MultiStruct.pm
org.glite.lb/project/StructField.pm
org.glite.lb/project/at3
org.glite.lb/project/build.number
org.glite.lb/project/build.properties
org.glite.lb/project/check_version.pl
org.glite.lb/project/dependencies.properties
org.glite.lb/project/events.T
org.glite.lb/project/glite.lb.csf.xml
org.glite.lb/project/properties.xml
org.glite.lb/project/run-workspace
org.glite.lb/project/status.T
org.glite.lb/project/taskdefs.xml
org.glite.lb/project/types.T
org.glite.lb/project/version.properties
+++ /dev/null
-.project
-.cdtproject
\ No newline at end of file
+++ /dev/null
-LICENSE file for EGEE Middleware\r
-================================\r
-\r
-Copyright (c) 2004 on behalf of the EU EGEE Project: \r
-The European Organization for Nuclear Research (CERN), \r
-Istituto Nazionale di Fisica Nucleare (INFN), Italy\r
-Datamat Spa, Italy\r
-Centre National de la Recherche Scientifique (CNRS), France\r
-CS Systeme d'Information (CSSI), France\r
-Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden\r
-Universiteit van Amsterdam (UvA), Netherlands\r
-University of Helsinki (UH.HIP), Finlan\r
-University of Bergen (UiB), Norway\r
-Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom\r
-\r
-Redistribution and use in source and binary forms, with or without\r
-modification, are permitted provided that the following conditions are\r
-met: \r
-\r
-1. Redistributions of source code must retain the above copyright\r
-notice, this list of conditions and the following disclaimer.\r
-\r
-2. Redistributions in binary form must reproduce the above copyright\r
-notice, this list of conditions and the following disclaimer in the\r
-documentation and/or other materials provided with the distribution.\r
-\r
-3. The end-user documentation included with the redistribution, if\r
-any, must include the following acknowledgment: "This product includes\r
-software developed by The EU EGEE Project (http://cern.ch/eu-egee/)."\r
-Alternatively, this acknowledgment may appear in the software itself, if\r
-and wherever such third-party acknowledgments normally appear.\r
-\r
-4. The names EGEE and the EU EGEE Project must not be\r
-used to endorse or promote products derived from this software without\r
-prior written permission. For written permission, please contact\r
-<email address>.\r
-\r
-5. You are under no obligation whatsoever to provide anyone with any\r
-bug fixes, patches, or upgrades to the features, functionality or\r
-performance of the Software ("Enhancements") that you may develop over\r
-time; however, if you choose to provide your Enhancements to The EU\r
-EGEE Project, or if you choose to otherwise publish or distribute your\r
-Enhancements, in source code form without contemporaneously requiring\r
-end users of The EU EGEE Proejct to enter into a separate written license\r
-agreement for such Enhancements, then you hereby grant The EU EGEE Project\r
-a non-exclusive, royalty-free perpetual license to install, use, copy,\r
-modify, prepare derivative works, incorporate into the EGEE Middleware\r
-or any other computer software, distribute, and sublicense your\r
-Enhancements or derivative works thereof, in binary and source code\r
-form (if any), whether developed by The EU EGEE Project or third parties.\r
-\r
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED\r
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
-DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE\r
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\r
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\r
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\r
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-This software consists of voluntary contributions made by many\r
-individuals on behalf of the EU EGEE Prject. For more information on The\r
-EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on\r
-EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/\r
-\r
-\r
+++ /dev/null
-# defaults
-top_srcdir=.
-stagedir=.
-distdir=.
-globalprefix=glite
-lbprefix=lb
-package=glite-lb-server
-version=0.2.0
-PREFIX=/opt/glite
-
-glite_location=/opt/glite
-globus_prefix=/opt/globus
-nothrflavour=gcc32
-thrflavour=gcc32pthr
-expat_prefix=/opt/expat
-cares_prefix=/opt/c-ares
-gsoap_prefix=/opt/gsoap
-classads_prefix=/opt/classads
-voms_prefix=/opt/voms
-
--include Makefile.inc
--include ../project/version.properties
-
-version=${module.version}
-
-default all: compile
-
-# disable lb plugin in order to build also with 3.1 JP
-BUILD_PLUGIN=yes
-
-GLITE_LB_SERVER_WITH_WS=yes
-
-ifdef LB_STANDALONE
- LB_STANDALONE_FLAGS:=-DLB_STANDALONE
-# GLITE_LB_SERVER_WITH_WS=no
-endif
-
-ifdef LB_PERF
- STATIC_LIB_BK:=libglite_lb_bkserver_perf.a
- LB_PERF_FLAGS:=-DLB_PERF
-else
- STATIC_LIB_BK:=libglite_lb_bkserver.a
-endif
-
-# Use embrionic DAG registration implicitely
-LB_DAG_FLAGS:=-DLB_DAG_EMBRIONIC
-
-ifdef LB_BUF
- LB_BUF_FLAGS:=-DLB_BUF
-endif
-
-ifeq ($(GLITE_LB_SERVER_WITH_WS),yes)
- WS_CFLAGS=-DGLITE_LB_SERVER_WITH_WS
- NSMAP=LoggingAndBookkeeping.nsmap
-else
- WS_CFLAGS=
-endif
-
-GSOAP_FILES_PREFIX:= bk_ws_
-
-YACC=bison -y
-CC=gcc
-
-ifeq ($(gsoap_version),2.7.0)
- VPATH=${top_srcdir}/interface:${top_srcdir}/src:${top_srcdir}/test:${top_srcdir}/examples:${top_srcdir}/project:${gsoap_prefix}
-else
- VPATH=${top_srcdir}/interface:${top_srcdir}/src:${top_srcdir}/test:${top_srcdir}/examples:${top_srcdir}/project
-endif
-AT3=perl -I${top_srcdir}/project ${top_srcdir}/project/at3
-
-SUFFIXES = .T
-
-DEBUG:=-g -O0 -Wall
-
-GRIDSITE_CFLAGS = `xml2-config --cflags`
-GRIDSITE_LIBS = -lgridsite_globus `xml2-config --libs`
-
-CFLAGS:= \
- ${WS_CFLAGS} ${DEBUG} \
- -DVERSION=\"${version}\" \
- -I${gsoap_prefix}/include -I${gsoap_prefix}/ \
- -I${stagedir}/include -I${top_srcdir}/src -I. \
- -I${top_srcdir}/interface \
- -I${expat_prefix}/include \
- -I${cares_prefix}/include \
- -I${classads_prefix}/include \
- -I${voms_prefix}/include \
- ${COVERAGE_FLAGS} \
- -I${mysql_prefix}/include -I${mysql_prefix}/include/mysql \
- -I${globus_prefix}/include/${nothrflavour} \
- $(GRIDSITE_CFLAGS) \
- -D_GNU_SOURCE ${LB_STANDALONE_FLAGS} ${LB_PERF_FLAGS} ${LB_DAG_FLAGS} \
- ${LB_BUF_FLAGS}
-
-ifdef LB_PROF
- SRVBONES_LIB:= ${stagedir}/lib/libglite_lb_server_bones.la
- LB_COMMON_LIB:=${stagedir}/lib/libglite_lb_common_${nothrflavour}.la
- CFLAGS:=${CFLAGS} -pg -g
- LDFLAGS:=${LDFLAGS} -pg
-else
- SRVBONES_LIB:= -L${stagedir}/lib -lglite_lb_server_bones
- LB_COMMON_LIB:=-lglite_lb_common_${nothrflavour}
-endif
-
-ifdef LBS_DB_PROFILE
- CFLAGS:=${CFLAGS} -DLBS_DB_PROFILE
-endif
-
-TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit
-TEST_INC:=-I${cppunit_prefix}/include
-
-COMPILE:=libtool --mode=compile ${CC} ${CFLAGS}
-LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/lib ${LDFLAGS}
-SOLINK:=libtool --mode=link ${CC} -module ${LDFLAGS} -rpath ${stagedir}/lib
-LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS}
-INSTALL:=libtool --mode=install install
-LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/lib ${LDFLAGS}
-XSLTPROC:=xsltproc --novalid
-
-GLOBUS_LIBS:= -L${globus_prefix}/lib \
- -lglobus_common_${nothrflavour} \
- -lglobus_gssapi_gsi_${nothrflavour} \
-
-#ifeq ($(shell ls ${gsoap_prefix}/bin/soapcpp2),${gsoap_prefix}/bin/soapcpp2)
-# gsoap_bin_prefix := ${gsoap_prefix}/bin
-#else
-# gsoap_bin_prefix := ${gsoap_prefix}
-#endif
-
-gsoap_bin_prefix:=${shell if [ -x ${gsoap_prefix}/bin/soapcpp2 ]; then echo ${gsoap_prefix}/bin; else echo ${gsoap_prefix}; fi }
-
-archlib:=lib
-host_cpu:=${shell uname -m}
-ifeq (${host_cpu},x86_64)
- archlib:=lib64
-endif
-
-ifneq (${mysql_prefix},/usr)
- ifeq ($(shell echo ${mysql_version} | cut -d. -f1,2),4.1)
- mysqlib := -L${mysql_prefix}/${archlib}/mysql
- else
- mysqlib := -L${mysql_prefix}/${archlib}
- endif
-endif
-
-ifneq (${expat_prefix},/usr)
- expatlib := -L${expat_prefix}/lib
-endif
-
-vomsflavour := _${nothrflavour}
-ifeq (${nothrflavour},gcc32)
- vomsflavour :=
-endif
-ifeq (${nothrflavour},gcc32dbg)
- vomsflavour :=
-endif
-VOMS_LIBS:=-L${voms_prefix}/lib -lvomsc${vomsflavour}
-
-#EXT_LIBS:= \
-# ${mysqlib} -lmysqlclient -lz\
-# ${expatlib} -lexpat \
-# ${GRIDSITE_LIBS} \
-# -lvomsc${vomsflavour} \
-# ${GLOBUS_LIBS}
-
-ifneq (${classads_prefix},/usr)
- classadslib := -L${classads_prefix}/${archlib} -lclassad
-endif
-
-EXT_LIBS:= \
- ${mysqlib} -lmysqlclient -lz -lcares\
- ${GRIDSITE_LIBS} \
- ${classadslib} \
- ${VOMS_LIBS}
-
-COMMON_LIBS:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour} -lglite_security_gss_${nothrflavour}
-PLUGIN_LIBS:= -L${stagedir}/lib -lglite_lb_common_${nothrflavour}\
- ${classadslib} -lstdc++ ${expatlib} -lexpat\
-
-PLUGIN_LOBJS:= lb_plugin.lo jobstat_supp.lo process_event.lo lbs_db_supp.lo process_event_pbs.lo process_event_condor.lo
-
-BKSERVER_BASE_OBJS:= \
- bkserverd.o il_lbproxy.o get_events.o index.o jobstat.o jobstat_supp.o process_event.o process_event_pbs.o process_event_condor.o \
- seqcode.o write2rgma.o lbs_db.o lbs_db_supp.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \
- lb_xml_parse_V21.o \
- lock.o openserver.o query.o userjobs.o db_store.o request.o store.o \
- stored_master.o srv_purge.o server_state.o dump.o lb_authz.o load.o \
- notification.o il_notification.o notif_match.o stats.o
-
-dotless_gsoap_ver:=${shell echo ${gsoap_version} | tr -d . }
-GSOAP_LIB:=-L${stagedir}/lib -lglite_security_gsoap_plugin_${dotless_gsoap_ver}_${nothrflavour}
-
-ifeq ($(GLITE_LB_SERVER_WITH_WS),yes)
- BKSERVER_OBJS:= \
- ${BKSERVER_BASE_OBJS} \
- ${GSOAP_FILES_PREFIX}C.o ${GSOAP_FILES_PREFIX}Server.o \
- ws_query.o ws_fault.o ws_typeref.o
-
- BKSERVER_LIBS= \
- ${SRVBONES_LIB} \
- ${LB_COMMON_LIB} \
- ${GSOAP_LIB} \
- ${EXT_LIBS}
-else
- BKSERVER_OBJS:= ${BKSERVER_BASE_OBJS}
-
- BKSERVER_LIBS= \
- ${SRVBONES_LIB} \
- ${LB_COMMON_LIB} \
- -lglite_security_gss_${nothrflavour} \
- ${EXT_LIBS}
-endif
-
-INDEX_OBJS:= index.o index_parse.o jobstat_supp.o lbs_db.o lbs_db_supp.o openserver.o \
- jobstat.o process_event.o process_event_pbs.o process_event_condor.o query.o lock.o get_events.o write2rgma.o index_lex.o \
- lb_authz.o store.o bkindex.o stats.o\
- request.o db_store.o srv_purge.o notif_match.o il_lbproxy.o dump.o lb_xml_parse.o il_notification.o lb_proto.o server_state.o lb_xml_parse_V21.o lb_html.o notification.o seqcode.o userjobs.o load.o
-
-INDEX_LIBS:= ${SRVBONES_LIB} ${COMMON_LIBS} ${EXT_LIBS}
-
-WS_CLIENT_OBJS:= $(GSOAP_FILES_PREFIX)C.o $(GSOAP_FILES_PREFIX)Client.o ws_fault.o ws_typeref.o
-WS_CLIENT_LIBS:= ${GSOAP_LIB} -lglite_lb_common_${nothrflavour} \
- -lglite_lb_common_${nothrflavour}
-
-# WS_CLIENT_LIBS:= -L${stagedir}/lib \
-# -lglite_lb_client_${nothrflavour} \
-# -lglite_lb_common_${nothrflavour} \
-# -L${gsoap_prefix}/lib -lgsoap \
-# -lglite_security_gsoap_plugin_${nothrflavour} \
-# ${EXT_LIBS}
-#
-
-HDRS=index.h lb_authz.h lbs_db.h store.h
-
-LIB_OBJS_BK:= \
- il_lbproxy.o get_events.o index.o jobstat.o jobstat_supp.o process_event.o process_event_pbs.o process_event_condor.o \
- seqcode.o lbs_db.o lbs_db_supp.o lb_html.o lb_http.o lb_proto.o lb_xml_parse.o \
- lb_xml_parse_V21.o \
- lock.o openserver.o query.o userjobs.o db_store.o request.o store.o \
- stored_master.o srv_purge.o server_state.o dump.o lb_authz.o load.o \
- notification.o il_notification.o notif_match.o stats.o
-
-glite-lb-bkserverd: ${NSMAP} ${BKSERVER_OBJS}
- ${LINKXX} -o $@ ${BKSERVER_OBJS} ${BKSERVER_LIBS}
-
-glite-lb-bkindex: ${INDEX_OBJS}
- ${LINKXX} -o $@ ${INDEX_OBJS} ${INDEX_LIBS}
-
-glite_lb_plugin.la: ${PLUGIN_LOBJS}
- ${SOLINK} -o $@ ${PLUGIN_LOBJS} ${PLUGIN_LIBS}
-
-default all: compile
-
-ifdef LB_STANDALONE
- PLUGIN_LIB=
-else
-ifndef BUILD_PLUGIN
- PLUGIN_LIB=
-else
- PLUGIN_LIB=glite_lb_plugin.la
-endif
-endif
-
-compile: glite-lb-bkserverd glite-lb-bkindex ${STATIC_LIB_BK} ${PLUGIN_LIB} store.c index.c jp_job_attrs.h
-
-
-check: compile test.xml test.query
- -echo check.query not complete yet
-
-test_coverage:
- -mkdir coverage
- cd coverage && $(MAKE) -f ../Makefile top_srcdir=../../ COVERAGE_FLAGS="-fprofile-arcs -ftest-coverage" check
- cd coverage && for i in `echo ${INDEX_OBJS} ${BKSERVER_OBJS} | tr ' ' '\012' | sort -u`; do gcov $$i ; done
-
-lb_xml_parse.c: lb_xml_parse.c.T
- rm -f $@
- ${AT3} $< >$@ || rm -f $@
- chmod -w $@ >/dev/null
-
-${GSOAP_FILES_PREFIX}H.h ${GSOAP_FILES_PREFIX}C.c ${GSOAP_FILES_PREFIX}Server.c ${GSOAP_FILES_PREFIX}Client.c ${GSOAP_FILES_PREFIX}ServerLib.c ${GSOAP_FILES_PREFIX}ClientLib.c LoggingAndBookkeeping.nsmap: LB.xh
- ${gsoap_bin_prefix}/soapcpp2 -w -c -p ${GSOAP_FILES_PREFIX} LB.xh
-
-# try several times -- LB.wsdl downloads BaseFault.xsd from www.ibm.com which may be failing
-# not used right now but may be useful one day
-# LB.xh: ws_typemap.dat
-# ${gsoap_prefix}/bin/wsdl2h -c -t ${top_srcdir}/src/ws_typemap.dat -o $@ ${stagedir}/interface/LB.wsdl || \
-# { sleep 1 ; ${gsoap_prefix}/bin/wsdl2h -c -t ${top_srcdir}/src/ws_typemap.dat -o $@ ${stagedir}/interface/LB.wsdl; } || \
-# { sleep 4 ; ${gsoap_prefix}/bin/wsdl2h -c -t ${top_srcdir}/src/ws_typemap.dat -o $@ ${stagedir}/interface/LB.wsdl; } || \
-# { sleep 16 ; ${gsoap_prefix}/bin/wsdl2h -c -t ${top_srcdir}/src/ws_typemap.dat -o $@ ${stagedir}/interface/LB.wsdl; }
-
-LB.xh: ws_typemap.dat ${stagedir}/interface/LB.wsdl
- cp ${stagedir}/interface/LBTypes.wsdl .
- ${gsoap_bin_prefix}/wsdl2h -c -t ${top_srcdir}/src/ws_typemap.dat -o $@ ${stagedir}/interface/LB.wsdl
- rm -f LBTypes.wsdl
-
-test.xml: test_xml
-# ./test_xml
-
-test_xml: test_xml.cpp
- ${CXX} -c ${CFLAGS} ${TEST_INC} $<
- ${LINKXX} -o $@ test_xml.o lb_xml_parse.o ${COMMON_LIBS} ${TEST_LIBS} ${EXT_LIBS}
-
-test.query: test_query_events
- ./test_query_events
-
-#query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/lbs_db\.o//;s/lbs_db_supp\.o//;s/bkserverd\.o//;s/db_store\.o//;s/stored_master\.o//;s/store\.o//;s/srv_purge\.o//;s/load\.o//;s/dump\.o//;s/lb_proto\.o//;s/lb_html\.o//;s/lb_http\.o//;'`
-query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed 's/lbs_db\.o//;s/lbs_db_supp\.o//;s/bkserverd\.o//;'`
-
-test_query_events: test_query_events.o
- ${LINKXX} -o $@ test_query_events.o ${query_events_objs} \
- ${TEST_LIBS} ${COMMON_LIBS} ${EXT_LIBS}
-
-test.soapconv: test_soap_conv
- ./test_soap_conv
-
-test_soap_conv: test_soap_conv.cpp ${WS_CLIENT_OBJS}
- ${CXX} -c ${CFLAGS} ${TEST_INC} $<
- ${LINKXX} -o $@ test_soap_conv.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS} ${TEST_LIBS}
-
-examples: ws_getversion ws_jobstat ws_query_ex ws_joblog
-
-ws_getversion: ws_getversion.o ${WS_CLIENT_OBJS}
- ${LINK} -o $@ ws_getversion.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS}
-
-ws_jobstat: ws_jobstat.o ${WS_CLIENT_OBJS}
- ${LINK} -o $@ ws_jobstat.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS}
-
-ws_query_ex: ws_query_ex.o ${WS_CLIENT_OBJS}
- ${LINK} -o $@ ws_query_ex.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS}
-
-ws_joblog: ws_joblog.o ${WS_CLIENT_OBJS}
- ${LINK} -o $@ ws_joblog.o ${WS_CLIENT_OBJS} ${WS_CLIENT_LIBS}
-
-
-${STATIC_LIB_BK}: ${LIB_OBJS_BK}
- ar crv $@ ${LIB_OBJS_BK}
- ranlib $@
-
-jp_job_attrs.h: job-attrs.xsd jp_job_attrs.xsl
- ${XSLTPROC} ../src/jp_job_attrs.xsl $< >$@
-
-doc:
-
-stage: compile
- $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes
-
-dist: distsrc distbin
-
-distsrc:
- mkdir -p ${top_srcdir}/${package}-${version}
- cd ${top_srcdir} && GLOBIGNORE="${package}-${version}" && cp -Rf * ${package}-${version}
- cd ${top_srcdir} && tar -czf ${distdir}/${package}-${version}_src.tar.gz --exclude-from=project/tar_exclude ${package}-${version}
- rm -rf ${top_srcdir}/${package}-${version}
-
-distbin:
- $(MAKE) install PREFIX=`pwd`/tmpbuilddir${stagedir}
- save_dir=`pwd`; cd tmpbuilddir${stagedir} && tar -czf $$save_dir/${top_srcdir}/${distdir}/${package}-${version}_bin.tar.gz *; cd $$save_dir
- rm -rf tmpbuilddir
-
-install:
- -mkdir -p ${PREFIX}/bin ${PREFIX}/etc ${PREFIX}/etc/init.d ${PREFIX}/interface
- -mkdir -p ${PREFIX}/share/doc/${package}-${version}
- -mkdir -p ${PREFIX}/lib
- -mkdir -p ${PREFIX}/include/${globalprefix}/${lbprefix}
- ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version}
- for p in bkserverd bkindex; do \
- ${INSTALL} -m 755 "glite-lb-$$p" "${PREFIX}/bin/glite-lb-$$p"; \
- done
-
- for f in dbsetup.sql dbsetup-migrate2transactions.sql index.conf.template; do \
- ${INSTALL} -m 644 ${top_srcdir}/config/"glite-lb-$$f" ${PREFIX}/etc; \
- done
-
- ${INSTALL} -m 755 ${top_srcdir}/config/startup ${PREFIX}/etc/init.d/glite-lb-bkserverd
- ${INSTALL} -m 644 ${top_srcdir}/interface/job-attrs.xsd ${PREFIX}/interface
- ${INSTALL} -m 644 ${top_srcdir}/interface/job-record.xsd ${PREFIX}/interface
-
- if [ ${stagedir} != ${PREFIX} ]; then ${INSTALL} -m 755 ${stagedir}/bin/glite-lb-notif-interlogd ${PREFIX}/bin; fi
- mkdir -p ${PREFIX}/include/${globalprefix}/${lbprefix}
- (cd ${top_srcdir}/interface && install -m 644 ${HDRS} ${PREFIX}/include/${globalprefix}/${lbprefix})
- install -m 644 ${STATIC_LIB_BK} ${PREFIX}/lib
- if [ x${LB_STANDALONE} = x -a x${PLUGIN_LIB} != x ]; then \
- ${INSTALL} -m 755 ${PLUGIN_LIB} ${PREFIX}/lib; \
- ${INSTALL} -m 644 jp_job_attrs.h ${PREFIX}/include/${globalprefix}/${lbprefix} ; \
- fi
- ${INSTALL} -m 644 ${top_srcdir}/interface/srv_perf.h ${PREFIX}/include/${globalprefix}/${lbprefix}
-
-clean:
- rm -rf *.c *.h *.ch *.xh *.xml *.nsmap *.o *.lo .libs glite-lb-* ${STATIC_LIB_BK} test*
-
-%.c: %.c.T
- rm -f $@
- ${AT3} $< >$@ || rm -f $@
- chmod -w $@ >/dev/null
-
-%.o: %.y
- ${YACC} -d ${YFLAGS} $<
- mv y.tab.c $*.c
- mv y.tab.h $*.h
- ${CC} -c ${CFLAGS} $*.c
- rm $*.c
-
-%.cpp: %.cpp.T
- rm -f $@
- ${AT3} $< >$@ || rm -f $@
- chmod -w $@ >/dev/null
-
-%.o %.lo: %.c
- ${COMPILE} -c $<
-
-test_query_events.o: %.o: %.cpp
- ${CXX} -c ${CFLAGS} ${GLOBUSINC} ${TEST_INC} $<
-
-
-%.lo: %.c
- ${COMPILE} -o $@ -c $<
-
-lb_plugin.lo: lb_plugin.c jp_job_attrs.h
- ${COMPILE} -DPLUGIN_DEBUG -o $@ -c $<
-
-soap_version.h:
- ${gsoap_bin_prefix}/soapcpp2 /dev/null
- perl -ne '$$. == 2 && /.*([0-9])\.([0-9])\.([0-9]).*/ && printf "#define GSOAP_VERSION %d%02d%02d\n",$$1,$$2,$$3' soapH.h >$@
- -rm soapC.cpp soapH.h soapStub.h soapClient.cpp soapServer.cpp soapClientLib.cpp soapServerLib.cpp
-
-ifeq ($(GLITE_LB_SERVER_WITH_WS),yes)
-bkserverd.o ws_fault.o: soap_version.h
-endif
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- Copyright (c) 2004 on behalf of the EU EGEE Project:
- The European Organization for Nuclear Research (CERN),
- Istituto Nazionale di Fisica Nucleare (INFN), Italy
- Datamat Spa, Italy
- Centre National de la Recherche Scientifique (CNRS), France
- CS Systeme d'Information (CSSI), France
- Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
- Universiteit van Amsterdam (UvA), Netherlands
- University of Helsinki (UH.HIP), Finland
- University of Bergen (UiB), Norway
- Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
-
- Build file for the GLite LB Client module
-
- Authors: Ales Krenek <ljocha@ics.muni.cz>
- Version info: $Id$
- Release: $Name$
-
- Revision history:
- $Log$
- Revision 1.5 2005/05/26 15:13:55 zurek
- inserted module.build.file
-
- Revision 1.4.2.1 2005/02/12 01:39:21 glbuild
- Changed start time
-
- Revision 1.4 2004/10/18 19:16:09 zsalvet
- RPM descriptions
-
- Revision 1.3 2004/08/05 15:24:32 dimeglio
- Changed default target from compile to dist
-
- Revision 1.2 2004/07/07 12:07:41 akrenek
- - use nonthr common library
- - build without VOMS & GACL
-
- Revision 1.3 2004/07/06 17:45:30 flammer
- Update of classpath definitions, targets & configure file.
-
- Revision 1.2 2004/06/23 00:29:33 dimeglio
- Added standard comments and handling of support files
-
--->
-
-<project name="server" default="dist">
-
- <!-- =========================================
- Builds the GLite LB Client Module
- ========================================= -->
-
- <!-- =========================================
- Import properties (order is important)
- ========================================= -->
-
- <!-- import baseline & user properties -->
- <import file="../org.glite/project/baseline.properties.xml" />
-
- <!-- import component build properties,
- component properties &
- component common properties -->
- <import file="./project/properties.xml"/>
-
- <!-- import subsystem build properties,
- subsystem properties &
- subsystem common properties -->
- <import file="${subsystem.properties.file}"/>
-
- <!-- import global build properties &
- global properties -->
- <import file="${global.properties.file}" />
-
- <!-- =========================================
- Load dependency property files (order is important)
- ========================================= -->
- <property file="${user.dependencies.file}"/>
- <property file="${component.dependencies.file}" />
- <property file="${subsystem.dependencies.file}" />
- <property file="${global.dependencies.file}"/>
-
- <!-- =========================================
- Load configure options (order is important)
- ========================================= -->
- <import file="${global.configure.options.file}"/>
- <import file="${component.configure.options.file}"/>
-
- <!-- =========================================
- Import task definitions (order is important)
- ========================================= -->
- <import file="${subsystem.taskdefs.file}" />
- <import file="${global.taskdefs.file}" />
-
- <!-- =========================================
- Load common targets
- ========================================= -->
- <import file="${global.targets-simple_make.file}" />
-
- <!-- =========================================
- Load version file
- ========================================= -->
- <property file="${module.version.file}"/>
- <property file="${module.build.file}"/>
-
- <!-- ==============================================
- Local private targets
- ============================================== -->
-
- <target name="localinit"
- description="Module specific initialization tasks">
- <!-- Copy support files from the subsystem project to the component project-->
- <copy toDir="${module.project.dir}">
- <fileset dir="${subsystem.project.dir}">
- <include name="at3" />
- <include name="*.T" />
- <include name="*.pm" />
- </fileset>
- </copy>
- <antcall target="lbmakefiles" />
- </target>
-
- <target name="localcompile"
- description="Module specific compile tasks">
- </target>
-
- <target name="localclean"
- description="Module specific cleaning tasks">
- <delete>
- <fileset dir="${module.project.dir}">
- <include name="at3" />
- <include name="*.T" />
- <include name="*.pm" />
- </fileset>
- </delete>
- </target>
-
- <!-- =========================================
- RPM settings
- ========================================= -->
-
- <property name="build.package.summary" value="L&B bookkeeping server" />
- <property name="build.package.description" value=" The daemon
-installed at the Logging & Bookkeeping (L&B) server
-machine.
It is responsible for accepting events from locallogger,
-storing them in RDBMS,
and performing queries on client requests
-(job status, job log etc.).
Also includes purge utilities
-to remove (and optionally archive) inactive
data from
-the database and to change database index configuration." />
-
-</project>
+++ /dev/null
-alter table jobs engine=innodb;
-alter table users engine=innodb;
-alter table events engine=innodb;
-alter table short_fields engine=innodb;
-alter table long_fields engine=innodb;
-alter table states engine=innodb;
-alter table status_tags engine=innodb;
-alter table server_state engine=innodb;
-alter table acls engine=innodb;
-alter table notif_registrations engine=innodb;
-alter table notif_jobs engine=innodb;
+++ /dev/null
-create table jobs (
- jobid char(32) binary not null,
- dg_jobid varchar(255) binary not null,
- userid char(32) binary not null,
- aclid char(32) binary null,
-
- primary key (jobid),
- unique (dg_jobid),
- index (userid)
-) engine=innodb;
-
-create table grey_jobs (
- jobid char(32) binary not null,
- dg_jobid varchar(255) binary not null,
- time_stamp datetime not null,
-
- primary key (jobid),
- unique (dg_jobid)
-) engine=innodb;
-
-create table users (
- userid char(32) binary not null,
- cert_subj varchar(255) binary not null,
-
- primary key (userid),
- unique (cert_subj)
-) engine=innodb;
-
-create table events (
- jobid char(32) binary not null,
- event int not null,
- code int not null,
- prog varchar(255) binary not null,
- host varchar(255) binary not null,
- time_stamp datetime not null,
- userid char(32) binary null,
- usec int null,
- level int null,
-
- arrived datetime not null,
-
-
- primary key (jobid,event),
- index (time_stamp),
- index (host),
- index (arrived)
-) engine=innodb;
-
-create table short_fields (
- jobid char(32) binary not null,
- event int not null,
- name varchar(200) binary not null,
- value varchar(255) binary null,
-
- primary key (jobid,event,name)
-) engine=innodb;
-
-create table long_fields (
- jobid char(32) binary not null,
- event int not null,
- name varchar(200) binary not null,
- value mediumblob null,
-
- primary key (jobid,event,name)
-) engine=innodb;
-
-create table states (
- jobid char(32) binary not null,
- status int not null,
- seq int not null,
- int_status mediumblob not null,
- version varchar(32) not null,
- parent_job varchar(32) binary not null,
-
- primary key (jobid),
- index (parent_job)
-
-) engine=innodb;
-
-create table status_tags (
- jobid char(32) binary not null,
- seq int not null,
- name varchar(200) binary not null,
- value varchar(255) binary null,
-
- primary key (jobid,seq,name)
-) engine=innodb;
-
-create table server_state (
- prefix varchar(100) not null,
- name varchar(100) binary not null,
- value varchar(255) binary not null,
-
- primary key (prefix,name)
-) engine=innodb;
-
-create table acls (
- aclid char(32) binary not null,
- value mediumblob not null,
- refcnt int not null,
-
- primary key (aclid)
-) engine=innodb;
-
-create table notif_registrations (
- notifid char(32) binary not null,
- destination varchar(200) not null,
- valid datetime not null,
- userid char(32) binary not null,
- conditions mediumblob not null,
-
- primary key (notifid)
-) engine=innodb;
-
-create table notif_jobs (
- notifid char(32) binary not null,
- jobid char(32) binary not null,
-
- primary key (notifid,jobid),
- index (jobid)
-) engine=innodb;
+++ /dev/null
-[
- JobIndices = {
- [ type = "system"; name = "owner" ],
- [ type = "system"; name = "location" ],
- [ type = "system"; name = "destination" ]
- }
-]
+++ /dev/null
-#!/bin/sh
-
-GLITE_LOCATION=${GLITE_LOCATION:-/opt/glite}
-GLITE_LOCATION_VAR=${GLITE_LOCATION_VAR:-/var/glite}
-
-[ -f /etc/glite.conf ] && . /etc/glite.conf
-[ -f $GLITE_LOCATION/etc/glite-wms.conf ] && . $GLITE_LOCATION/etc/glite-wms.conf
-
-[ -f $GLITE_LOCATION/etc/lb.conf ] && . $GLITE_LOCATION/etc/lb.conf
-[ -f $GLITE_LOCATION_VAR/etc/lb.conf ] && . $GLITE_LOCATION_VAR/etc/lb.conf
-
-[ -f $HOME/.glite.conf ] && . $HOME/.glite.conf
-
-[ -n "$GLITE_LB_SERVER_PIDFILE" ] && pidfile=$GLITE_LB_SERVER_PIDFILE ||
- pidfile=$GLITE_LOCATION_VAR/glite-lb-bkserverd.pid
-[ -z "$GLITE_LB_NOTIF_SOCK" ] && GLITE_LB_NOTIF_SOCK="/tmp/glite-lb-notif.sock"
-
-unset creds port
-
-start()
-{
- if test -z "$GLITE_USER" ;then
- echo 'Error: GLITE_USER is not set'
- echo FAILED
- return 1
- fi
-
- [ -n "$GLITE_HOST_CERT" -a -n "$GLITE_HOST_KEY" ] &&
- creds="-c $GLITE_HOST_CERT -k $GLITE_HOST_KEY"
-
- if test -z "$creds"; then
- if su - $GLITE_USER -c "test -r /etc/grid-security/hostkey.pem -a -r /etc/grid-security/hostcert.pem"; then
- echo "$0: WARNING: /etc/grid-security/hostkey.pem readable by $GLITE_USER"
- creds="-c /etc/grid-security/hostcert.pem -k /etc/grid-security/hostkey.pem"
- fi
- fi
-
- [ -z "$GLITE_LB_EXPORT_DUMPDIR" ] && GLITE_LB_EXPORT_DUMPDIR=/tmp/dump
- dumpdir="--dump-prefix $GLITE_LB_EXPORT_DUMPDIR"
- [ -d "$GLITE_LB_EXPORT_DUMPDIR" ] || mkdir -p "$GLITE_LB_EXPORT_DUMPDIR" && chown $GLITE_USER:$GLITE_GROUP -R "$GLITE_LB_EXPORT_DUMPDIR"
-
- [ -z "$GLITE_LB_EXPORT_PURGEDIR" ] && GLITE_LB_EXPORT_PURGEDIR=/tmp/purge
- purgedir="--purge-prefix $GLITE_LB_EXPORT_PURGEDIR"
- [ -d "$GLITE_LB_EXPORT_PURGEDIR" ] || mkdir -p "$GLITE_LB_EXPORT_PURGEDIR" && chown $GLITE_USER:$GLITE_GROUP -R "$GLITE_LB_EXPORT_PURGEDIR"
-
- if [ x"$GLITE_LB_EXPORT_ENABLED" = x"true" ]; then
- [ -z "$GLITE_LB_EXPORT_JPREG_MAILDIR" ] && GLITE_LB_EXPORT_JPREG_MAILDIR=/tmp/jpreg
- [ -d "$GLITE_LB_EXPORT_JPREG_MAILDIR" ] || mkdir -p "$GLITE_LB_EXPORT_JPREG_MAILDIR" && chown $GLITE_USER:$GLITE_GROUP -R "$GLITE_LB_EXPORT_JPREG_MAILDIR"
- maildir="--jpreg-dir $GLITE_LB_EXPORT_JPREG_MAILDIR"
- fi
-
- if test -r "$GLITE_LOCATION/etc/LB-super-users"; then
- super="--super-users-file $GLITE_LOCATION/etc/LB-super-users"
- fi
-
- [ -z "$creds" ] && echo $0: WARNING: No credentials specified. Using default lookup which is dangerous. >&2
-
- [ -n "$GLITE_LB_SERVER_PORT" ] && port="-p $GLITE_LB_SERVER_PORT"
- [ -n "$GLITE_LB_SERVER_WPORT" ] && wport="-w $GLITE_LB_SERVER_WPORT"
- [ -z "$GLITE_LB_NOTIF_FPREFIX" ] && GLITE_LB_NOTIF_FPREFIX="/var/tmp/glite-lb-notif"
-
- echo -n Starting glite-lb-bkserver ...
- su - $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-bkserverd \
- --notif-il-sock=$GLITE_LB_NOTIF_SOCK \
- --notif-il-fprefix=$GLITE_LB_NOTIF_FPREFIX \
- -b 0 $GLITE_LB_BKSERVERD_ADDOPTS \
- $super $creds -i $pidfile $port $wport $dumpdir $purgedir $maildir" \
- && echo " done" || echo " FAILED"
-
- echo -n Starting glite-lb-notif-interlogd ...
- su - $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-notif-interlogd \
- -f $GLITE_LB_NOTIF_FPREFIX -s $GLITE_LB_NOTIF_SOCK \
- $creds" && echo " done" || echo " FAILED"
-}
-
-stop()
-{
- echo -n Stopping glite-lb-interlogd ...
- killall glite-lb-notif-interlogd
- echo done
- if [ -f $pidfile ]; then
- pid=`cat $pidfile`
- kill $pid
- echo -n Stopping glite-lb-bkserverd \($pid\) ...
- try=0
- while ps p $pid >/dev/null 2>&1; do
- sleep 1;
- try=`expr $try + 1`
- if [ $try = 20 ]; then
- echo " giving up after $try retries"
- return 1
- fi
- done
- echo " done"
- rm -f $pidfile
- else
- echo $pidfile does not exist - glite-lb-bkserverd not running? >&2
- return 1
- fi
-}
-
-status()
-{
- retval=0
-
- LC_ALL=C
- if netstat -an --unix | grep "^unix .* LISTEN.* ${GLITE_LB_NOTIF_SOCK}$" >/dev/null 2>&1 ;then
- echo glite-lb-notif-interlogd running
- else
- echo glite-lb-notif-interlogd not running
- retval=1
- fi
-
- if [ -f $pidfile ]; then
- pid=`cat $pidfile`
- if ps p $pid >/dev/null 2>&1; then
- echo glite-lb-bkserverd running as $pid
- else
- echo glite-lb-bkserverd not running
- retval=1
- fi
- else
- echo glite-lb-bkserverd not running
- retval=1
- fi
-
- return $retval
-}
-
-case x$1 in
- xstart) start;;
- xstop) stop;;
- xrestart) stop; start;;
- xstatus) status;;
- x*) echo usage: $0 start,stop,restart,status >&2
- exit 1;;
-esac
+++ /dev/null
-/*
-
-stdsoap2.c[pp] 2.6.0
-
-Runtime environment.
-
-gSOAP XML Web services tools
-Copyright (C) 2000-2004, Robert van Engelen, Genivia, Inc. All Rights Reserved.
-
-Contributors:
-
-Wind River Systems, Inc., for the following additions (marked WR[...]):
- - vxWorks compatible
- - Support for IPv6.
-
---------------------------------------------------------------------------------
-gSOAP public license.
-
-The contents of this file are subject to the gSOAP Public License Version 1.3
-(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.cs.fsu.edu/~engelen/soaplicense.html
-Software distributed under the License is distributed on an "AS IS" basis,
-WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-for the specific language governing rights and limitations under the License.
-
-The Initial Developer of the Original Code is Robert A. van Engelen.
-Copyright (C) 2000-2004 Robert A. van Engelen, Genivia inc. All Rights Reserved.
---------------------------------------------------------------------------------
-GPL license.
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307 USA
-
-Author contact information:
-engelen@genivia.com / engelen@acm.org
---------------------------------------------------------------------------------
-
-Installation note:
-
-Win32 build needs winsock.dll (Visual C++ "wsock32.lib")
-To do this in Visual C++ 6.0, go to "Project", "settings", select the "Link"
-tab (the project file needs to be selected in the file view) and add
-"wsock32.lib" to the "Object/library modules" entry
-
-*/
-
-#include "stdsoap2.h"
-
-#ifdef __cplusplus
-SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.6.0 2004-03-28 12:00:00 GMT")
-extern "C" {
-#else
-SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.6.0 2004-03-28 12:00:00 GMT")
-#endif
-
-/* EOF=-1 */
-#define LT (wchar)(-2) /* XML character '<' */
-#define TT (wchar)(-3) /* XML character '</' */
-#define GT (wchar)(-4) /* XML character '>' */
-#define QT (wchar)(-5) /* XML character '"' */
-#define AP (wchar)(-6) /* XML character ''' */
-
-#define soap_blank(c) ((c) >= 0 && (c) <= 32)
-#define soap_notblank(c) ((c) > 32)
-#define soap_hash_ptr(p) (((unsigned long)(p) >> 3) & (SOAP_PTRHASH - 1))
-
-static int soap_isxdigit(int);
-static wchar soap_char(struct soap*);
-static wchar soap_getchunkchar(struct soap*);
-static void soap_update_ptrs(struct soap*, char*, char*, long);
-static int soap_has_copies(struct soap*, char*, char*);
-static struct soap_ilist *soap_hlookup(struct soap*, const char*);
-static void soap_init_iht(struct soap*);
-static void soap_free_iht(struct soap*);
-static void soap_init_pht(struct soap*);
-static void soap_free_pht(struct soap*);
-static int soap_set_error(struct soap*, const char*, const char*, const char*, int);
-static int soap_copy_fault(struct soap*, const char*, const char*, const char*);
-static int soap_getattrval(struct soap*, char*, size_t, wchar);
-static void soap_set_local_namespaces(struct soap*);
-static size_t soap_begin_dime(struct soap*);
-static int soap_isnumeric(struct soap*, const char*);
-static void *fplugin(struct soap*, const char*);
-
-#ifndef WITH_LEAN
-static time_t soap_timegm(struct tm*);
-static void soap_init_logs(struct soap*);
-static void soap_close_logfile(struct soap*, int);
-static void soap_set_logfile(struct soap*, int, const char*);
-#endif
-
-#ifndef WITH_LEANER
-static int soap_putdimefield(struct soap*, const char*, size_t);
-static char *soap_getdimefield(struct soap*, size_t);
-#endif
-
-#ifdef WITH_GZIP
-static int soap_getgzipheader(struct soap*);
-#endif
-
-#ifdef WITH_OPENSSL
-static int ssl_auth_init(struct soap*);
-static int ssl_verify_callback(int, X509_STORE_CTX*);
-static int ssl_password(char*, int, int, void *);
-/* This callback is included for future references. It should not be deleted
-static DH *ssl_tmp_dh(SSL*, int, int);
-*/
-#endif
-
-static const char *soap_strerror(struct soap*);
-static const char *tcp_error(struct soap*);
-static const char *http_error(struct soap*, int);
-static int http_post(struct soap*, const char*, const char*, int, const char*, const char*, size_t);
-static int http_get(struct soap*);
-static int http_post_header(struct soap*, const char*, const char*);
-static int http_response(struct soap*, int, size_t);
-static int http_parse(struct soap*);
-static int http_parse_header(struct soap*, const char*, const char*);
-static int tcp_connect(struct soap*, const char*, const char*, int);
-static int tcp_accept(struct soap*, int, struct sockaddr*, int*);
-static int tcp_disconnect(struct soap*);
-static int fsend(struct soap*, const char*, size_t);
-static size_t frecv(struct soap*, char*, size_t);
-
-/* WR[ */
-#ifdef VXWORKS
-static int vx_nonblocking = TRUE; /* ioctl argument */
-#endif
-/* ]WR */
-
-#ifndef PALM_2
-static const char soap_env1[42] = "http://schemas.xmlsoap.org/soap/envelope/";
-static const char soap_enc1[42] = "http://schemas.xmlsoap.org/soap/encoding/";
-static const char soap_env2[40] = "http://www.w3.org/2003/05/soap-envelope";
-static const char soap_enc2[40] = "http://www.w3.org/2003/05/soap-encoding";
-static const char soap_rpc[35] = "http://www.w3.org/2003/05/soap-rpc";
-#endif
-
-#ifndef PALM_1
-const struct soap_double_nan soap_double_nan = {0xFFFFFFFF, 0xFFFFFFFF};
-static const char soap_base64o[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char soap_base64i[81] = "\76XXX\77\64\65\66\67\70\71\72\73\74\75XXXXXXX\00\01\02\03\04\05\06\07\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31XXXXXX\32\33\34\35\36\37\40\41\42\43\44\45\46\47\50\51\52\53\54\55\56\57\60\61\62\63";
-#endif
-
-static const char soap_padding[3] = "\0\0";
-#define SOAP_STR_PADDING (soap_padding)
-#define SOAP_STR_EOS (soap_padding)
-
-#ifndef WITH_LEAN
-static const struct soap_code_map html_entity_codes[] = /* entities for XHTML parsing */
-{ { 160, "nbsp" },
- { 161, "iexcl" },
- { 162, "cent" },
- { 163, "pound" },
- { 164, "curren" },
- { 165, "yen" },
- { 166, "brvbar" },
- { 167, "sect" },
- { 168, "uml" },
- { 169, "copy" },
- { 170, "ordf" },
- { 171, "laquo" },
- { 172, "not" },
- { 173, "shy" },
- { 174, "reg" },
- { 175, "macr" },
- { 176, "deg" },
- { 177, "plusmn" },
- { 178, "sup2" },
- { 179, "sup3" },
- { 180, "acute" },
- { 181, "micro" },
- { 182, "para" },
- { 183, "middot" },
- { 184, "cedil" },
- { 185, "sup1" },
- { 186, "ordm" },
- { 187, "raquo" },
- { 188, "frac14" },
- { 189, "frac12" },
- { 190, "frac34" },
- { 191, "iquest" },
- { 192, "Agrave" },
- { 193, "Aacute" },
- { 194, "Acirc" },
- { 195, "Atilde" },
- { 196, "Auml" },
- { 197, "Aring" },
- { 198, "AElig" },
- { 199, "Ccedil" },
- { 200, "Egrave" },
- { 201, "Eacute" },
- { 202, "Ecirc" },
- { 203, "Euml" },
- { 204, "Igrave" },
- { 205, "Iacute" },
- { 206, "Icirc" },
- { 207, "Iuml" },
- { 208, "ETH" },
- { 209, "Ntilde" },
- { 210, "Ograve" },
- { 211, "Oacute" },
- { 212, "Ocirc" },
- { 213, "Otilde" },
- { 214, "Ouml" },
- { 215, "times" },
- { 216, "Oslash" },
- { 217, "Ugrave" },
- { 218, "Uacute" },
- { 219, "Ucirc" },
- { 220, "Uuml" },
- { 221, "Yacute" },
- { 222, "THORN" },
- { 223, "szlig" },
- { 224, "agrave" },
- { 225, "aacute" },
- { 226, "acirc" },
- { 227, "atilde" },
- { 228, "auml" },
- { 229, "aring" },
- { 230, "aelig" },
- { 231, "ccedil" },
- { 232, "egrave" },
- { 233, "eacute" },
- { 234, "ecirc" },
- { 235, "euml" },
- { 236, "igrave" },
- { 237, "iacute" },
- { 238, "icirc" },
- { 239, "iuml" },
- { 240, "eth" },
- { 241, "ntilde" },
- { 242, "ograve" },
- { 243, "oacute" },
- { 244, "ocirc" },
- { 245, "otilde" },
- { 246, "ouml" },
- { 247, "divide" },
- { 248, "oslash" },
- { 249, "ugrave" },
- { 250, "uacute" },
- { 251, "ucirc" },
- { 252, "uuml" },
- { 253, "yacute" },
- { 254, "thorn" },
- { 255, "yuml" },
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEAN
-static const struct soap_code_map h_error_codes[] =
-{
-#ifdef HOST_NOT_FOUND
- { HOST_NOT_FOUND, "Host not found" },
-#endif
-#ifdef TRY_AGAIN
- { TRY_AGAIN, "Try Again" },
-#endif
-#ifdef NO_RECOVERY
- { NO_RECOVERY, "No Recovery" },
-#endif
-#ifdef NO_DATA
- { NO_DATA, "No Data" },
-#endif
-#ifdef NO_ADDRESS
- { NO_ADDRESS, "No Address" },
-#endif
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEAN
-static const struct soap_code_map h_http_error_codes[] =
-{ { 201, "Created" },
- { 202, "Accepted" },
- { 203, "Non-Authoritative Information" },
- { 204, "No Content" },
- { 205, "Reset Content" },
- { 206, "Partial Content" },
- { 300, "Multiple Choices" },
- { 301, "Moved Permanently" },
- { 302, "Found" },
- { 303, "See Other" },
- { 304, "Not Modified" },
- { 305, "Use Proxy" },
- { 307, "Temporary Redirect" },
- { 400, "Bad Request" },
- { 401, "Unauthorized" },
- { 402, "Payment Required" },
- { 403, "Forbidden" },
- { 404, "Not Found" },
- { 405, "Method Not Allowed" },
- { 406, "Not Acceptable" },
- { 407, "Proxy Authentication Required" },
- { 408, "Request Time-out" },
- { 409, "Conflict" },
- { 410, "Gone" },
- { 411, "Length Required" },
- { 412, "Precondition Failed" },
- { 413, "Request Entity Too Large" },
- { 414, "Request-URI Too Large" },
- { 415, "Unsupported Media Type" },
- { 416, "Requested range not satisfiable" },
- { 417, "Expectation Failed" },
- { 500, "Internal Server Error" },
- { 501, "Not Implemented" },
- { 502, "Bad Gateway" },
- { 503, "Service Unavailable" },
- { 504, "Gateway Time-out" },
- { 505, "HTTP Version not supported" },
- { 0, NULL }
-};
-#endif
-
-#ifdef WITH_OPENSSL
-static const struct soap_code_map h_ssl_error_codes[] =
-{
-#define _SSL_ERROR(e) { e, #e }
- _SSL_ERROR(SSL_ERROR_SSL),
- _SSL_ERROR(SSL_ERROR_ZERO_RETURN),
- _SSL_ERROR(SSL_ERROR_WANT_READ),
- _SSL_ERROR(SSL_ERROR_WANT_WRITE),
- _SSL_ERROR(SSL_ERROR_WANT_CONNECT),
- _SSL_ERROR(SSL_ERROR_WANT_X509_LOOKUP),
- _SSL_ERROR(SSL_ERROR_SYSCALL),
- { 0, NULL }
-};
-#endif
-
-#ifdef WIN32
-static int tcp_done = 0;
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-fsend(struct soap *soap, const char *s, size_t n)
-{ register int nwritten;
-#if defined(__cplusplus) && !defined(UNDER_CE)
- if (soap->os)
- { soap->os->write(s, n);
- if (soap->os->good())
- return SOAP_OK;
- return SOAP_EOF;
- }
-#endif
- while (n)
- { if (soap_valid_socket(soap->socket))
- {
-#ifndef WITH_LEAN
- if (soap->send_timeout)
- { struct timeval timeout;
- fd_set fd;
- if (soap->send_timeout > 0)
- { timeout.tv_sec = soap->send_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->send_timeout/1000000;
- timeout.tv_usec = -soap->send_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- for (;;)
- { register int r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- return SOAP_EOF;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- }
- }
-#endif
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- nwritten = SSL_write(soap->ssl, s, n);
- else
-#endif
-#ifndef PALM
- nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags);
-#else
- nwritten = send((SOAP_SOCKET)soap->socket, (void*)s, n, soap->socket_flags);
-#endif
- if (nwritten <= 0)
- {
-#ifdef WITH_OPENSSL
- int err;
- if (soap->ssl && (err = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- return SOAP_EOF;
-#endif
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EWOULDBLOCK && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- nwritten = 0; /* and call write() again */
- }
- }
- else
- {
-#ifdef WITH_FASTCGI
- nwritten = fwrite((void*)s, 1, n, stdout);
- fflush(stdout);
-#else
-#ifdef UNDER_CE
- nwritten = fwrite(s, 1, n, soap->sendfd);
-#else
-/* WR[ */
-#ifdef VXWORKS
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- {
- httpBlockPut(soap->rpmreqid, s, n);
- nwritten = n;
- }
- else
- {
- nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
- }
-#else
- nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
-#endif /* WMW_RPM_IO */
-#else
-/* ]WR */
- nwritten = write((SOAP_SOCKET)soap->sendfd, s, n);
-/* WR[ */
-#endif
-/* ]WR */
-#endif
-#endif
- if (nwritten <= 0)
- { if (soap_errno != SOAP_EINTR && soap_errno != SOAP_EWOULDBLOCK && soap_errno != SOAP_EAGAIN)
- { soap->errnum = soap_errno;
- return SOAP_EOF;
- }
- nwritten = 0; /* and call write() again */
- }
- }
- n -= nwritten;
- s += nwritten;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_flush_raw(struct soap *soap, const char *s, size_t n)
-{
-#ifndef WITH_LEAN
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- { char *t;
- if (!(t = (char*)soap_push_block(soap, n)))
- return soap->error = SOAP_EOM;
- memcpy(t, s, n);
- return SOAP_OK;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { char t[16];
- sprintf(t, "\r\n%lX\r\n" + (soap->chunksize ? 0 : 2), (unsigned long)n);
- DBGMSG(SENT, t, strlen(t));
- if ((soap->error = soap->fsend(soap, t, strlen(t))))
- return soap->error;
- soap->chunksize += n;
- }
-#endif
- DBGMSG(SENT, s, n);
- return soap->error = soap->fsend(soap, s, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_flush(struct soap *soap)
-{ if (soap->bufidx)
- {
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { soap->d_stream.next_in = (Byte*)soap->buf;
- soap->d_stream.avail_in = (unsigned int)soap->bufidx;
-#ifdef WITH_GZIP
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->bufidx);
-#endif
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating %u bytes\n", soap->d_stream.avail_in));
- if (deflate(&soap->d_stream, Z_NO_FLUSH) != Z_OK)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to deflate: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- if (!soap->d_stream.avail_out)
- { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN))
- return soap->error;
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- }
- } while (soap->d_stream.avail_in);
- }
- else
-#endif
- if (soap_flush_raw(soap, soap->buf, soap->bufidx))
- return soap->error;
- soap->bufidx = 0;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send_raw(struct soap *soap, const char *s, size_t n)
-{ if (!n)
- return SOAP_OK;
- if (soap->mode & SOAP_IO_LENGTH)
- { soap->count += n;
- if (soap->fprepare)
- return soap->fprepare(soap, s, n);
- return SOAP_OK;
- }
- if (soap->mode & SOAP_IO)
- { register size_t i = SOAP_BUFLEN - soap->bufidx;
- while (n >= i)
- { memcpy(soap->buf + soap->bufidx, s, i);
- soap->bufidx = SOAP_BUFLEN;
- if (soap_flush(soap))
- return soap->error;
- s += i;
- n -= i;
- i = SOAP_BUFLEN;
- }
- memcpy(soap->buf + soap->bufidx, s, n);
- soap->bufidx += n;
- return SOAP_OK;
- }
- return soap_flush_raw(soap, s, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send(struct soap *soap, const char *s)
-{ if (s)
- return soap_send_raw(soap, s, strlen(s));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static size_t
-frecv(struct soap *soap, char *s, size_t n)
-{ register int r;
- soap->errnum = 0;
-#if defined(__cplusplus) && !defined(UNDER_CE)
- if (soap->is)
- { if (soap->is->good())
- return soap->is->read(s, n).gcount();
- return 0;
- }
-#endif
- if (soap_valid_socket(soap->socket))
- { for (;;)
- {
-#ifndef WITH_LEAN
- struct timeval timeout;
- fd_set fd;
- if (soap->recv_timeout)
- { if (soap->recv_timeout > 0)
- { timeout.tv_sec = soap->recv_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->recv_timeout/1000000;
- timeout.tv_usec = -soap->recv_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- for (;;)
- { r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r > 0)
- break;
- if (r == 0)
- return 0;
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
- }
-#endif
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { int err;
- r = SSL_read(soap->ssl, s, n);
- if ((err = SSL_get_error(soap->ssl, r)) == SSL_ERROR_NONE)
- return (size_t)r;
- if (err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- return 0;
- }
- else
-#endif
- { r = recv((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags);
- if (r >= 0)
- return (size_t)r;
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
-#ifndef WITH_LEAN
- { struct timeval timeout;
- fd_set fd;
- timeout.tv_sec = 0;
- timeout.tv_usec = 10000;
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r < 0 && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
-#endif
- }
- }
-#ifdef WITH_FASTCGI
- return fread(s, 1, n, stdin);
-#else
-#ifdef UNDER_CE
- return fread(s, 1, n, soap->recvfd);
-#else
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- {
- r = httpBlockRead(soap->rpmreqid, s, n);
- }
- else
- {
- r = read(soap->recvfd, s, n);
- }
- if (r >= 0)
- {
- return r;
- }
- return 0;
-#else
-/* ]WR */
- r = read((SOAP_SOCKET)soap->recvfd, s, n);
- if (r >= 0)
- return (size_t)r;
- soap->errnum = soap_errno;
- return 0;
-/* WR[ */
-#endif
-/* ]WR */
-#endif
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static wchar
-soap_getchunkchar(struct soap *soap)
-{ if (soap->bufidx < soap->buflen)
- return soap->buf[soap->bufidx++];
- soap->bufidx = 0;
- soap->buflen = soap->chunkbuflen = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)soap->buflen));
- DBGMSG(RECV, soap->buf, soap->buflen);
- if (soap->buflen)
- return soap->buf[soap->bufidx++];
- return EOF;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_isxdigit(int c)
-{ switch (c)
- { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- return 1;
- }
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_raw(struct soap *soap)
-{ register size_t ret;
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { if (soap->d_stream.next_out == Z_NULL)
- return EOF;
- if (soap->d_stream.avail_in || !soap->d_stream.avail_out)
- { register int r;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflating\n"));
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- r = inflate(&soap->d_stream, Z_NO_FLUSH);
- if (r == Z_OK || r == Z_STREAM_END)
- { soap->bufidx = 0;
- soap->buflen = SOAP_BUFLEN - soap->d_stream.avail_out;
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen);
- if (r == Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out;
- soap->d_stream.next_out = Z_NULL;
- }
- if (soap->buflen)
- { soap->count += soap->buflen;
- return SOAP_OK;
- }
- }
- else if (r != Z_BUF_ERROR)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate error: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- soap->d_stream.next_out = Z_NULL;
- return EOF;
- }
- }
-zlib_again:
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK && !soap->chunksize)
- { memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
- soap->buflen = soap->z_buflen;
- }
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) /* read HTTP chunked transfer */
- {
-chunk_again:
- if (soap->chunksize)
- { soap->buflen = ret = soap->frecv(soap, soap->buf, soap->chunksize > SOAP_BUFLEN ? SOAP_BUFLEN : soap->chunksize);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk: read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- soap->bufidx = 0;
- soap->chunksize -= ret;
- }
- else
- { register wchar c;
- char tmp[8], *t;
- t = tmp;
- if (!soap->chunkbuflen)
- { soap->chunkbuflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- soap->bufidx = 0;
- if (!ret)
- return EOF;
- }
- else
- soap->bufidx = soap->buflen;
- soap->buflen = soap->chunkbuflen;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (%u %u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen));
- while (!soap_isxdigit((int)(c = soap_getchunkchar(soap))))
- if ((int)c == EOF)
- return EOF;
- do
- *t++ = (char)c;
- while (soap_isxdigit((int)(c = soap_getchunkchar(soap))) && t - tmp < 7);
- while ((int)c != EOF && c != '\n')
- c = soap_getchunkchar(soap);
- if ((int)c == EOF)
- return EOF;
- *t = '\0';
- soap->chunksize = soap_strtoul(tmp, &t, 16);
- if (!soap->chunksize)
- { soap->chunkbuflen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of chunked message\n"));
- while ((int)c != EOF && c != '\n')
- c = soap_getchunkchar(soap);
- return EOF;
- }
- soap->buflen = soap->bufidx + soap->chunksize;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to %u (%u %s)\n", (unsigned int)soap->buflen, (unsigned int)soap->bufidx, tmp));
- if (soap->buflen > soap->chunkbuflen)
- { soap->buflen = soap->chunkbuflen;
- soap->chunksize -= soap->buflen - soap->bufidx;
- soap->chunkbuflen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Passed end of buffer for chunked HTTP (%lu bytes left)\n", (unsigned long)(soap->buflen - soap->bufidx)));
- }
- else if (soap->chunkbuflen)
- soap->chunksize = 0;
- ret = soap->buflen - soap->bufidx;
- if (!ret)
- goto chunk_again;
- }
- }
- else
- { soap->bufidx = 0;
- soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- }
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { int r;
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = (unsigned int)ret;
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- r = inflate(&soap->d_stream, Z_NO_FLUSH);
- if (r == Z_OK || r == Z_STREAM_END)
- { soap->bufidx = 0;
- soap->z_buflen = soap->buflen;
- soap->buflen = ret = SOAP_BUFLEN - soap->d_stream.avail_out;
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %u bytes\n", (unsigned int)ret));
- if (!ret)
- goto zlib_again;
- if (r == Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out;
- soap->d_stream.next_out = Z_NULL;
- }
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to inflate: (%d) %s\n", r, soap->d_stream.msg?soap->d_stream.msg:""));
- soap->d_stream.next_out = Z_NULL;
- return EOF;
- }
- }
-#endif
- soap->count += ret;
- return !ret;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv(struct soap *soap)
-{
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- { if (soap->dime_buflen)
- { char *s;
- int i;
- unsigned char tmp[12];
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME hdr for chunked DIME is in buffer\n"));
- soap->count += soap->dime_buflen - soap->buflen;
- soap->buflen = soap->dime_buflen;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Skip padding (%ld bytes)\n", -(long)soap->dime_size&3));
- for (i = -(long)soap->dime_size&3; i > 0; i--)
- { soap->bufidx++;
- if (soap->bufidx >= soap->buflen)
- if (soap_recv_raw(soap))
- return EOF;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME hdr for next chunk\n"));
- s = (char*)tmp;
- for (i = 12; i > 0; i--)
- { *s++ = soap->buf[soap->bufidx++];
- if (soap->bufidx >= soap->buflen)
- if (soap_recv_raw(soap))
- return EOF;
- }
- soap->dime_flags = tmp[0] & 0x7;
- soap->dime_size = ((size_t)tmp[8] << 24) | ((size_t)tmp[9] << 16) | ((size_t)tmp[10] << 8) | ((size_t)tmp[11]);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME chunk (%u bytes)\n", (unsigned int)soap->dime_size));
- if (soap->dime_flags & SOAP_DIME_CF)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "More chunking\n"));
- soap->dime_chunksize = soap->dime_size;
- if (soap->buflen - soap->bufidx >= soap->dime_size)
- { soap->dime_buflen = soap->buflen;
- soap->buflen = soap->bufidx + soap->dime_chunksize;
- }
- else
- soap->dime_chunksize -= soap->buflen - soap->bufidx;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Last chunk\n"));
- soap->dime_buflen = 0;
- soap->dime_chunksize = 0;
- }
- soap->count = soap->buflen - soap->bufidx;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%u bytes remaining\n", (unsigned int)soap->count));
- return SOAP_OK;
- }
- if (soap->dime_chunksize)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get next DIME hdr for chunked DIME (%u bytes chunk)\n", (unsigned int)soap->dime_chunksize));
- if (soap_recv_raw(soap))
- return EOF;
- if (soap->buflen - soap->bufidx >= soap->dime_chunksize)
- { soap->dime_buflen = soap->buflen;
- soap->count -= soap->buflen - soap->bufidx - soap->dime_chunksize;
- soap->buflen = soap->bufidx + soap->dime_chunksize;
- }
- else
- soap->dime_chunksize -= soap->buflen - soap->bufidx;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%lu bytes remaining, count=%u\n", (unsigned long)(soap->buflen-soap->bufidx), (unsigned int)soap->count));
- return SOAP_OK;
- }
- }
-#endif
- return soap_recv_raw(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_getchar(struct soap *soap)
-{ register wchar c;
- if (soap->ahead)
- { c = soap->ahead;
- soap->ahead = 0;
- return c;
- }
- return soap_get1(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const struct soap_code_map*
-SOAP_FMAC2
-soap_code(const struct soap_code_map *map, const char *str)
-{ while (map->string)
- { if (!strcmp(str, map->string))
- return map;
- map++;
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_int_code(const struct soap_code_map *map, const char *str, long other)
-{ while (map->string)
- { if (!strcmp(str, map->string))
- return map->code;
- map++;
- }
- return other;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_str_code(const struct soap_code_map *map, long code)
-{ while (map->code != code && map->string)
- map++;
- return map->string;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static wchar
-soap_char(struct soap *soap)
-{ char tmp[8];
- register int i;
- register wchar c;
- register char *s = tmp;
- for (i = 0; i < 7; i++)
- { c = soap_get1(soap);
- if (c == ';' || (int)c == EOF)
- break;
- *s++ = (char)c;
- }
- *s = '\0';
- if (*tmp == '#')
- { if (tmp[1] == 'x' || tmp[1] == 'X')
- return soap_strtol(tmp + 2, NULL, 16);
- return atol(tmp + 1);
- }
- if (!strcmp(tmp, "lt"))
- return '<';
- if (!strcmp(tmp, "gt"))
- return '>';
- if (!strcmp(tmp, "amp"))
- return '&';
- if (!strcmp(tmp, "quot"))
- return '"';
- if (!strcmp(tmp, "apos"))
- return '\'';
-#ifndef WITH_LEAN
- return (wchar)soap_int_code(html_entity_codes, tmp, 127);
-#else
- return 127; /* use this to represent unknown code */
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_get(struct soap *soap)
-{ register wchar c;
- c = soap->ahead;
- if (c)
- soap->ahead = 0;
- else
- c = soap_get1(soap);
- for (;;)
- { if (soap->cdata)
- { if (c == ']')
- { c = soap_get1(soap);
- if (c == ']')
- { soap->cdata = 0;
- soap_get1(soap); /* skip > */
- c = soap_get1(soap);
- }
- else
- { soap_revget1(soap);
- return ']';
- }
- }
- else
- return c;
- }
- switch (c)
- { case '<':
- do c = soap_get1(soap);
- while (soap_blank(c));
- if (c == '!' || c == '?' || c == '%')
- { if (c == '!')
- { c = soap_get1(soap);
- if (c == '[')
- { do c = soap_get1(soap);
- while ((int)c != EOF && c != '[');
- if ((int)c == EOF)
- break;
- soap->cdata = 1;
- c = soap_get1(soap);
- continue;
- }
- if (c == '-' && (c = soap_get1(soap)) == '-')
- { do
- { c = soap_get1(soap);
- if (c == '-' && (c = soap_get1(soap)) == '-')
- break;
- } while ((int)c != EOF);
- }
- }
- while ((int)c != EOF && c != '>')
- c = soap_get1(soap);
- if ((int)c == EOF)
- break;
- c = soap_get1(soap);
- continue;
- }
- if (c == '/')
- return TT;
- soap_revget1(soap);
- return LT;
- case '>':
- return GT;
- case '"':
- return QT;
- case '\'':
- return AP;
- case '&':
- return soap_char(soap) | 0x80000000;
- }
- break;
- }
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_advance(struct soap *soap)
-{ register wchar c;
- while ((int)((c = soap_get(soap)) != EOF) && c != LT && c != TT)
- ;
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_skip(struct soap *soap)
-{ register wchar c;
- do c = soap_get(soap);
- while (soap_blank(c));
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_move(struct soap *soap, long n)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving %ld bytes forward\n", (long)n));
- for (; n > 0; n--)
- if ((int)soap_getchar(soap) == EOF)
- return SOAP_EOF;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_tell(struct soap *soap)
-{ return soap->count - soap->buflen + soap->bufidx - (soap->ahead != 0);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pututf8(struct soap *soap, register unsigned long c)
-{ char tmp[16];
- if (c > 0 && c < 0x80)
- { *tmp = (char)c;
- return soap_send_raw(soap, tmp, 1);
- }
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { register char *t = tmp;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- *t = '\0';
- }
- else
-#endif
- sprintf(tmp, "&#%lu;", c);
- return soap_send(soap, tmp);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_getutf8(struct soap *soap)
-{ register wchar c, c1, c2, c3, c4;
- c = soap_get(soap);
- if (c < 0x80)
- return c;
- c1 = soap_get(soap);
- if (c1 < 0x80)
- { soap_unget(soap, c1);
- return c;
- }
- c1 &= 0x3F;
- if (c < 0xE0)
- return ((wchar)(c & 0x1F) << 6) | c1;
- c2 = (wchar)soap_get1(soap) & 0x3F;
- if (c < 0xF0)
- return ((wchar)(c & 0x0F) << 12) | (c1 << 6) | c2;
- c3 = (wchar)soap_get1(soap) & 0x3F;
- if (c < 0xF8)
- return ((wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;
- c4 = (wchar)soap_get1(soap) & 0x3F;
- if (c < 0xFC)
- return ((wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4;
- return ((wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (wchar)(soap_get1(soap) & 0x3F);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_puthex(struct soap *soap, const unsigned char *s, int n)
-{ /* TODO: serialize to DOM (as an option) using new soap_s2hex() */
- char d[2];
- register int i;
- for (i = 0; i < n; i++)
- { register int m = *s++;
- d[0] = (char)((m >> 4) + (m > 159 ? '7' : '0'));
- m &= 0x0F;
- d[1] = (char)(m + (m > 9 ? '7' : '0'));
- if (soap_send_raw(soap, d, 2))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-unsigned char*
-SOAP_FMAC2
-soap_gethex(struct soap *soap, int *n)
-{ register wchar c;
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { register int i;
- register char *s = (char*)soap_push_block(soap, SOAP_BLKLEN);
- if (!s)
- { soap_end_block(soap);
- if (n)
- *n = 0;
- return NULL;
- }
- for (i = 0; i < SOAP_BLKLEN; i++)
- { register char d1, d2;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- { d1 = (char)c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- d2 = (char)c;
- else
- { soap_end_block(soap);
- soap->error = SOAP_TYPE;
- if (n)
- *n = 0;
- return NULL;
- }
- }
- else
- { unsigned char *p;
- soap_unget(soap, c);
- if (n)
- *n = (int)soap_size_block(soap, i);
- p = (unsigned char*)soap_save_block(soap, NULL);
- return p;
- }
- *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putbase64(struct soap *soap, const unsigned char *s, int n)
-{ register int i;
- register unsigned long m;
- char d[4];
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->data = (char*)soap_malloc(soap, (n + 2) / 3 * 4 + 1);
- return soap_s2base64(soap, s, soap->dom->data, n);
- }
-#endif
- if (!s)
- return SOAP_OK;
- for (; n > 2; n -= 3, s += 3)
- { m = ((unsigned long)((unsigned char*)s)[0] << 16) | ((unsigned long)((unsigned char*)s)[1] << 8) | (unsigned long)((unsigned char*)s)[2];
- for (i = 4; i > 0; m >>= 6)
- d[--i] = soap_base64o[m & 0x3F];
- if (soap_send_raw(soap, d, 4))
- return soap->error;
- }
- if (n > 0)
- { m = 0;
- for (i = 0; i < n; i++)
- m = (m << 8) | *s++;
- for (; i < 3; i++)
- m <<= 8;
- for (i++; i > 0; m >>= 6)
- d[--i] = soap_base64o[m & 0x3F];
- for (i = 3; i > n; i--)
- d[i] = '=';
- if (soap_send_raw(soap, d, 4))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-unsigned char*
-SOAP_FMAC2
-soap_getbase64(struct soap *soap, int *n, int malloc_flag)
-{ register wchar c;
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { register int i;
- register char *s = (char*)soap_push_block(soap, 3*SOAP_BLKLEN); /* must be multiple of 3 */
- if (!s)
- { soap_end_block(soap);
- if (n)
- *n = 0;
- return NULL;
- }
- for (i = 0; i < SOAP_BLKLEN; i++)
- { register unsigned long m = 0;
- register int j = 0;
- while (j < 4)
- { c = soap_get(soap);
- if (c == '=' || c < 0)
- { unsigned char *p;
- i *= 3;
- switch (j)
- { case 2:
- *s++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *s++ = (char)((m >> 10) & 0xFF);
- *s++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n = (int)soap_size_block(soap, i);
- p = (unsigned char*)soap_save_block(soap, NULL);
- if (c >= 0)
- { while ((int)((c = soap_get(soap)) != EOF) && c != LT && c != TT)
- ;
- }
- soap_unget(soap, c);
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- }
- *s++ = (char)((m >> 16) & 0xFF);
- *s++ = (char)((m >> 8) & 0xFF);
- *s++ = (char)(m & 0xFF);
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_strdup(struct soap *soap, const char *s)
-{ char *t = NULL;
- if (s && (t = (char*)soap_malloc(soap, strlen(s) + 1)))
- strcpy(t, s);
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_new_block(struct soap *soap)
-{ struct soap_blist *p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New block sequence (prev=%p)\n", soap->blist));
- if (!(p = (struct soap_blist*)SOAP_MALLOC(sizeof(struct soap_blist))))
- return SOAP_EOM;
- p->next = soap->blist;
- p->ptr = NULL;
- p->size = 0;
- soap->blist = p;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_push_block(struct soap *soap, size_t n)
-{ char *p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push block of %u bytes (%u bytes total)\n", (unsigned int)n, (unsigned int)soap->blist->size));
- if (!(p = (char*)SOAP_MALLOC(n + sizeof(char*) + sizeof(size_t))))
- { soap->error = SOAP_EOM;
- return NULL;
- }
- *(char**)p = soap->blist->ptr;
- *(size_t*)(p + sizeof(char*)) = n;
- soap->blist->ptr = p;
- soap->blist->size += n;
- return p + sizeof(char*) + sizeof(size_t);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_pop_block(struct soap *soap)
-{ char *p;
- if (!soap->blist->ptr)
- return;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pop block\n"));
- p = soap->blist->ptr;
- soap->blist->size -= *(size_t*)(p + sizeof(char*));
- soap->blist->ptr = *(char**)p;
- SOAP_FREE(p);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_update_ptrs(struct soap *soap, char *start, char *end, long offset)
-{ int i;
- register struct soap_ilist *ip;
- register void *p, **q;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr && (char*)ip->ptr >= start && (char*)ip->ptr < end)
- ip->ptr = (char*)ip->ptr + offset;
- for (q = &ip->link; q; q = (void**)p)
- { p = *q;
- if (p && (char*)p >= start && (char*)p < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Link update id='%s' %p\n", ip->id, p));
- *q = (char*)p + offset;
- }
- }
- for (q = &ip->copy; q; q = (void**)p)
- { p = *q;
- if (p && (char*)p >= start && (char*)p < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy update id='%s' %p\n", ip->id, p));
- *q = (char*)p + offset;
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_has_copies(struct soap *soap, register char *start, register char *end)
-{ int i;
- register struct soap_ilist *ip;
- register char *p;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- for (p = (char*)ip->copy; p; p = *(char**)p)
- if (p >= start && p < end)
- return SOAP_ERR;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_resolve(struct soap *soap)
-{ int i, flag1 = 0, flag2;
- register struct soap_ilist *ip;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr)
- soap_resolve_ptr(ip);
- else if (*ip->id == '#')
- flag1 = 1;
- }
- do
- { flag2 = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- if (ip->copy && ip->ptr && ip->size)
- if (!soap_has_copies(soap, (char*)ip->ptr, (char*)ip->ptr + ip->size))
- { register void *p, **q = (void**)ip->copy;
- DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing copy chain to resolve id='%s'\n", ip->id));
- ip->copy = NULL;
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... copy %p -> %p (%u bytes)\n", ip->ptr, q, (unsigned int)ip->size));
- p = *q;
- memcpy(q, ip->ptr, ip->size);
- q = (void**)p;
- } while (q);
- flag2 = 1;
- }
- } while (flag2);
- if (flag1)
- return soap->error = SOAP_MISSING_ID;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_resolve_ptr(struct soap_ilist *ip)
-{ register void *p, **q, *r;
- q = (void**)ip->link;
- ip->link = NULL;
- r = ip->ptr;
- while (q)
- { p = *q;
- *q = r;
- q = (void**)p;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_size_block(struct soap *soap, size_t n)
-{ if (soap->blist->ptr)
- { soap->blist->size -= *(size_t*)(soap->blist->ptr + sizeof(char*)) - n;
- *(size_t*)(soap->blist->ptr + sizeof(char*)) = n;
- }
- return soap->blist->size;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_first_block(struct soap *soap)
-{ char *p, *q, *r;
- p = soap->blist->ptr;
- if (!p)
- return NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "First block\n"));
- r = NULL;
- do
- { q = *(char**)p;
- *(char**)p = r;
- r = p;
- p = q;
- } while (p);
- soap->blist->ptr = r;
- return r + sizeof(char*) + sizeof(size_t);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_next_block(struct soap *soap)
-{ char *p;
- p = soap->blist->ptr;
- if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Next block\n"));
- soap->blist->ptr = *(char**)p;
- SOAP_FREE(p);
- if (soap->blist->ptr)
- return soap->blist->ptr + sizeof(char*) + sizeof(size_t);
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_block_size(struct soap *soap)
-{ return *(size_t*)(soap->blist->ptr + sizeof(char*));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_end_block(struct soap *soap)
-{ struct soap_blist *bp;
- char *p, *q;
- bp = soap->blist;
- if (bp)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of block sequence, free all remaining blocks\n"));
- for (p = bp->ptr; p; p = q)
- { q = *(char**)p;
- SOAP_FREE(p);
- }
- soap->blist = bp->next;
- SOAP_FREE(bp);
- }
- DBGLOG(TEST, if (soap->blist) SOAP_MESSAGE(fdebug, "Restore previous block sequence\n"));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_save_block(struct soap *soap, char *p)
-{ register size_t n;
- register char *q, *s;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Save all blocks in contiguous memory space of %u bytes (%p->%p)\n", (unsigned int)soap->blist->size, soap->blist->ptr, p));
- if (soap->blist->size)
- { if (!p)
- p = (char*)soap_malloc(soap, soap->blist->size);
- if (p)
- for (s = p, q = soap_first_block(soap); q; q = soap_next_block(soap))
- { n = soap_block_size(soap);
- soap_update_ptrs(soap, q, q + n, (long)s - (long)q); /* pointers s and q may or may not be related */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy %u bytes from %p to %p\n", (unsigned int)n, q, s));
- memcpy(s, q, n);
- s += n;
- }
- else
- soap->error = SOAP_EOM;
- }
- soap_end_block(soap);
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_store_block(struct soap *soap, char *p)
-{ p = soap_save_block(soap, p);
- if (!soap->blist)
- { struct soap_ilist *ip;
- int i;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- if (ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolve link chain to point to %p\n", ip->ptr));
- soap_resolve_ptr(ip);
- }
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsize(struct soap *soap, const char *type, int size)
-{ return soap_putsizes(soap, type, &size, 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsizes(struct soap *soap, const char *type, const int *size, int dim)
-{ return soap_putsizesoffsets(soap, type, size, NULL, dim);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsizesoffsets(struct soap *soap, const char *type, const int *size, const int *offset, int dim)
-{ int i;
- if (!type)
- return NULL;
- if (soap->version == 2)
- { sprintf(soap->type, "%s[%d", type, size[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), " %d", size[i]);
- }
- else
- { if (offset)
- { sprintf(soap->type, "%s[%d", type, size[0] + offset[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), ",%d", size[i] + offset[i]);
- }
- else
- { sprintf(soap->type, "%s[%d", type, size[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), ",%d", size[i]);
- }
- strcat(soap->type, "]");
- }
- return soap->type;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putoffset(struct soap *soap, int offset)
-{ return soap_putoffsets(soap, &offset, 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putoffsets(struct soap *soap, const int *offset, int dim)
-{ register int i;
- sprintf(soap->arrayOffset, "[%d", offset[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->arrayOffset + strlen(soap->arrayOffset), ",%d", offset[i]);
- strcat(soap->arrayOffset, "]");
- return soap->arrayOffset;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_size(const int *size, int dim)
-{ register int i, n = size[0];
- for (i = 1; i < dim; i++)
- n *= size[i];
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getoffsets(const char *attr, const int *size, int *offset, int dim)
-{ register int i, j = 0;
- if (offset)
- for (i = 0; i < dim && attr && *attr; i++)
- { attr++;
- j *= size[i];
- j += offset[i] = (int)atol(attr);
- attr = strchr(attr, ',');
- }
- else
- for (i = 0; i < dim && attr && *attr; i++)
- { attr++;
- j *= size[i];
- j += (int)atol(attr);
- attr = strchr(attr, ',');
- }
- return j;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getsize(const char *attr1, const char *attr2, int *j)
-{ register int n, k;
- char *s;
- *j = 0;
- if (!*attr1)
- return -1;
- n = 1;
- do
- { attr1++;
- k = (int)soap_strtol(attr1, &s, 10);
- n *= k;
- if (k < 0 || n > SOAP_MAXARRAYSIZE || s == attr1)
- return -1;
- attr1 = strchr(s, ',');
- if (!attr1)
- attr1 = strchr(s, ' ');
- if (attr2 && *attr2)
- { attr2++;
- *j *= k;
- k = (int)soap_strtol(attr2, &s, 10);
- *j += k;
- if (k < 0)
- return -1;
- attr2 = s;
- }
- } while (attr1 && *attr1 != ']');
- return n - *j;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getsizes(const char *attr, int *size, int dim)
-{ register int i, k, n;
- if (!*attr)
- return -1;
- i = strlen(attr);
- n = 1;
- do
- { for (i = i-1; i >= 0; i--)
- if (attr[i] == '[' || attr[i] == ',' || attr[i] == ' ')
- break;
- k = (int)atol(attr + i + 1);
- n *= size[--dim] = k;
- if (k < 0 || n > SOAP_MAXARRAYSIZE)
- return -1;
- } while (i >= 0 && attr[i] != '[');
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getposition(const char *attr, int *pos)
-{ register int i, n;
- if (!*attr)
- return -1;
- n = 0;
- i = 1;
- do
- { pos[n++] = (int)atol(attr + i);
- while (attr[i] && attr[i] != ',' && attr[i] != ']')
- i++;
- if (attr[i] == ',')
- i++;
- } while (n < SOAP_MAXDIMS && attr[i] && attr[i] != ']');
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_push_namespace(struct soap *soap, const char *id, const char *ns)
-{ register struct soap_nlist *np;
- register struct Namespace *p;
- np = (struct soap_nlist*)SOAP_MALLOC(sizeof(struct soap_nlist) + strlen(id));
- if (!np)
- return soap->error = SOAP_EOM;
- np->next = soap->nlist;
- soap->nlist = np;
- strcpy(np->id, id);
- np->level = soap->level;
- np->index = -1;
- np->ns = NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns));
- p = soap->local_namespaces;
- if (p)
- { register short i;
- for (i = 0; p->id; p++, i++)
- { if (p->ns)
- if (!soap_tag_cmp(ns, p->ns))
- break;
- if (p->in)
- if (!soap_tag_cmp(ns, p->in))
- { if (p->out)
- SOAP_FREE(p->out);
- if ((p->out = (char*)SOAP_MALLOC(strlen(ns) + 1)))
- strcpy(p->out, ns);
- if (i == 0)
- { if (!strcmp(ns, soap_env1))
- { soap->version = 1; /* and make sure we use SOAP 1.1 */
- if (p->out)
- SOAP_FREE(p[1].out);
- if ((p[1].out = (char*)SOAP_MALLOC(sizeof(soap_enc1))))
- strcpy(p[1].out, soap_enc1);
- }
- else
- { soap->version = 2; /* and make sure we use SOAP 1.2 */
- if (p[1].out)
- SOAP_FREE(p[1].out);
- if ((p[1].out = (char*)SOAP_MALLOC(sizeof(soap_enc2))))
- strcpy(p[1].out, soap_enc2);
- }
- }
- break;
- }
- }
- if (p && p->id)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id));
- np->index = i;
- }
- }
- if (!p || !p->id)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns));
- np->ns = (char*)SOAP_MALLOC(strlen(ns) + 1);
- if (!np->ns)
- return soap->error = SOAP_EOM;
- strcpy(np->ns, ns);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_push_default_namespace(struct soap *soap, const char *id, int n)
-{ register struct soap_nlist *np = soap->nlist;
- while (np && np->index >= -1)
- np = np->next;
- if (np && (!strncmp(np->id, id, n) && !np->id[n]))
- return SOAP_OK;
- np = (struct soap_nlist*)SOAP_MALLOC(sizeof(struct soap_nlist) + n);
- if (!np)
- return soap->error = SOAP_EOM;
- np->next = soap->nlist;
- soap->nlist = np;
- strncpy(np->id, id, n);
- np->id[n] = '\0';
- np->level = soap->level;
- np->index = -2;
- np->ns = NULL;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_pop_namespace(struct soap *soap)
-{ register struct soap_nlist *np;
- while (soap->nlist && soap->nlist->level >= soap->level)
- { np = soap->nlist->next;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Popped namespace binding (level=%u) '%s'\n", soap->level, soap->nlist->id));
- if (soap->nlist->ns)
- SOAP_FREE(soap->nlist->ns);
- SOAP_FREE(soap->nlist);
- soap->nlist = np;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_namespace(struct soap *soap, const char *id1, const char *id2, int n1, int n2)
-{ register struct soap_nlist *np = soap->nlist;
- while (np && (np->index == -2 || (strncmp(np->id, id1, n1) || np->id[n1])))
- np = np->next;
- if (np)
- { if (np->index < 0 || (np->index >= 0 && soap->local_namespaces[np->index].id && (strncmp(soap->local_namespaces[np->index].id, id2, n2) || soap->local_namespaces[np->index].id[n2])))
- return SOAP_NAMESPACE;
- return SOAP_OK;
- }
- if (n1 == 3 && n1 == n2 && !strcmp(id1, "xml") && !strcmp(id1, id2))
- return SOAP_OK;
- return SOAP_SYNTAX_ERROR;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_default_namespace(struct soap *soap)
-{ register struct soap_nlist *np = soap->nlist;
- while (np && np->index >= -1)
- np = np->next;
- if (np)
- return np->id;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_tag_cmp(register const char *s, register const char *t)
-{ for (; *s && *s != '"'; s++, t++)
- if (tolower(*s) != tolower(*t))
- if (*t != '-')
- { if (*t != '*')
- return 1;
- if (*++t)
- { register int c = tolower(*t);
- for (; *s && *s != '"'; s++)
- { if (tolower(*s) == c)
- if (!soap_tag_cmp(s + 1, t + 1))
- return 0;
- }
- break;
- }
- else
- return 0;
- }
- if (*t == '*' && !t[1])
- return 0;
- return *t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_tag(struct soap *soap, const char *tag1, const char *tag2)
-{ register const char *s, *t;
- if (!tag1 || !tag2 || !*tag2)
- return SOAP_OK;
- s = strchr(tag1, ':');
- t = strchr(tag2, ':');
- if (t)
- { if (s)
- { if (SOAP_STRCMP(s + 1, t + 1))
- return SOAP_TAG_MISMATCH;
- if (t != tag2 && soap_match_namespace(soap, tag1, tag2, s - tag1, t - tag2))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
- return SOAP_TAG_MISMATCH;
- }
- }
- else if (SOAP_STRCMP(tag1, t + 1))
- return SOAP_TAG_MISMATCH;
- else if (t != tag2 && soap_match_namespace(soap, tag1, tag2, 0, t - tag2))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
- return SOAP_TAG_MISMATCH;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags and (default) namespaces match: '%s' '%s'\n", tag1, tag2));
- return SOAP_OK;
- }
- if (s)
- { if (((soap->mode & SOAP_XML_STRICT) && soap->part != SOAP_IN_HEADER && soap->encodingStyle))
- return SOAP_TAG_MISMATCH;
- if (SOAP_STRCMP(s + 1, tag2))
- return SOAP_TAG_MISMATCH;
- if (!soap->encodingStyle)
- { t = soap_default_namespace(soap);
- if (!t || soap_match_namespace(soap, tag1, t, s - tag1, strlen(t)))
- return SOAP_TAG_MISMATCH;
- }
- }
- else if (SOAP_STRCMP(tag1, tag2))
- return SOAP_TAG_MISMATCH;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags match: '%s' '%s'\n", tag1, tag2));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_array(struct soap *soap, const char *type)
-{ if (*soap->arrayType)
- if (soap_match_tag(soap, soap->arrayType, type)
- && soap_match_tag(soap, soap->arrayType, "xsd:anyType")
- && soap_match_tag(soap, soap->arrayType, "xsd:ur-type")
- )
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array type mismatch: '%s' '%s'\n", soap->arrayType, type));
- return SOAP_TAG_MISMATCH;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-
-#ifdef WITH_OPENSSL
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid)
-{ int err;
- soap->keyfile = keyfile;
- soap->password = password;
- soap->cafile = cafile;
- soap->capath = capath;
- if (dhfile)
- { soap->dhfile = dhfile;
- soap->rsa = 0;
- }
- else
- { soap->dhfile = NULL;
- soap->rsa = 1;
- }
- soap->randfile = randfile;
- soap->require_client_auth = (flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION);
- if (!(err = soap->fsslauth(soap)))
- if (sid)
- SSL_CTX_set_session_id_context(soap->ctx, (unsigned char*)sid, strlen(sid));
- return err;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *randfile)
-{ soap->keyfile = keyfile;
- soap->password = password;
- soap->cafile = cafile;
- soap->capath = capath;
- soap->dhfile = NULL;
- soap->rsa = 0;
- soap->randfile = randfile;
- soap->require_server_auth = (flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION);
- return soap->fsslauth(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-ssl_init()
-{ static int done = 0;
- if (!done)
- { done = 1;
- SSL_library_init();
-#ifndef WITH_LEAN
- SSL_load_error_strings();
-#endif
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char *
-ssl_error(struct soap *soap, int ret)
-{ int err = SSL_get_error(soap->ssl, ret);
- const char *msg = soap_str_code(h_ssl_error_codes, err);
- if (msg)
- strcpy(soap->msgbuf, msg);
- else
- return ERR_error_string(err, soap->msgbuf);
- if (ERR_peek_error())
- { unsigned long r;
- strcat(soap->msgbuf, "\n");
- while ((r = ERR_get_error()))
- ERR_error_string_n(r, soap->msgbuf + strlen(soap->msgbuf), sizeof(soap->msgbuf) - strlen(soap->msgbuf));
- }
- else
- { switch (ret)
- { case 0:
- strcpy(soap->msgbuf, "EOF was observed that violates the protocol. The client probably provided invalid authentication information.");
- break;
- case -1:
- sprintf(soap->msgbuf, "Error observed by underlying BIO: %s", strerror(errno));
- break;
- }
- }
- return soap->msgbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_password(char *buf, int num, int rwflag, void *userdata)
-{ if (num < (int)strlen((char*)userdata) + 1)
- return 0;
- return strlen(strcpy(buf, (char*)userdata));
-}
-#endif
-
-/******************************************************************************/
-/* This callback is included for future references. It should not be deleted
-#ifndef PALM_1
-static DH *
-ssl_tmp_dh(SSL *ssl, int is_export, int keylength)
-{ static DH *dh512 = NULL;
- static DH *dh1024 = NULL;
- DH *dh;
- switch (keylength)
- { case 512:
- if (!dh512)
- { BIO *bio = BIO_new_file("dh512.pem", "r");
- if (bio)
- { dh512 = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- return dh512;
- }
- }
- else
- return dh512;
- default:
- if (!dh1024)
- { BIO *bio = BIO_new_file("dh1024.pem", "r");
- if (bio)
- { dh1024 = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- }
- }
- dh = dh1024;
- }
- return dh;
-}
-#endif
-*/
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_auth_init(struct soap *soap)
-{ ssl_init();
- if (!soap->ctx)
- if (!(soap->ctx = SSL_CTX_new(SSLv23_method())))
- return soap_set_receiver_error(soap, "SSL error", "Can't setup context", SOAP_SSL_ERROR);
- if (soap->randfile)
- { if (!RAND_load_file(soap->randfile, -1))
- return soap_set_receiver_error(soap, "SSL error", "Can't load randomness", SOAP_SSL_ERROR);
- }
- else if (!RAND_load_file("/dev/random", 1024))
- { int r;
-#ifdef HAVE_RAND_R
- unsigned int s = (unsigned int)time(NULL);
-#endif
- RAND_seed(soap->buf, sizeof(soap->buf));
- while (!RAND_status())
- {
-#ifdef HAVE_RAND_R
- r = rand_r(&s);
-#else
- r = rand();
-#endif
- RAND_seed(&r, sizeof(int));
- }
- }
- if (soap->cafile || soap->capath)
- if (!SSL_CTX_load_verify_locations(soap->ctx, soap->cafile, soap->capath))
- return soap_set_receiver_error(soap, "SSL error", "Can't read CA file and/or directory", SOAP_SSL_ERROR);
- if (!SSL_CTX_set_default_verify_paths(soap->ctx))
- return soap_set_receiver_error(soap, "SSL error", "Can't read default CA file and/or directory", SOAP_SSL_ERROR);
- if (soap->keyfile)
- { if (!SSL_CTX_use_certificate_chain_file(soap->ctx, soap->keyfile))
- return soap_set_receiver_error(soap, "SSL error", "Can't read certificate key file", SOAP_SSL_ERROR);
- if (soap->password)
- { SSL_CTX_set_default_passwd_cb_userdata(soap->ctx, (void*)soap->password);
- SSL_CTX_set_default_passwd_cb(soap->ctx, ssl_password);
- if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM))
- return soap_set_receiver_error(soap, "SSL error", "Can't read key file", SOAP_SSL_ERROR);
- }
- }
- if (soap->rsa)
- { RSA *rsa = RSA_generate_key(512, RSA_F4, NULL, NULL);
- if (!SSL_CTX_set_tmp_rsa(soap->ctx, rsa))
- { if (rsa)
- RSA_free(rsa);
- return soap_set_receiver_error(soap, "SSL error", "Can't set RSA key", SOAP_SSL_ERROR);
- }
- RSA_free(rsa);
- }
- else if (soap->dhfile)
- { DH *dh = 0;
- BIO *bio;
- bio = BIO_new_file(soap->dhfile, "r");
- if (!bio)
- return soap_set_receiver_error(soap, "SSL error", "Can't read DH file", SOAP_SSL_ERROR);
- dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- if (SSL_CTX_set_tmp_dh(soap->ctx, dh) < 0)
- { if (dh)
- DH_free(dh);
- return soap_set_receiver_error(soap, "SSL error", "Can't set DH parameters", SOAP_SSL_ERROR);
- }
- DH_free(dh);
- }
- SSL_CTX_set_options(soap->ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2);
- SSL_CTX_set_verify(soap->ctx, soap->require_client_auth ? (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT) : soap->require_server_auth ? SSL_VERIFY_PEER : SSL_VERIFY_NONE, soap->fsslverify);
-#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
- SSL_CTX_set_verify_depth(soap->ctx, 1);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_verify_callback(int ok, X509_STORE_CTX *store)
-{
-#ifdef SOAP_DEBUG
- if (!ok)
- { char data[256];
- X509 *cert = X509_STORE_CTX_get_current_cert(store);
- fprintf(stderr, "SSL Verify error with certificate at depth %d: %s\n", X509_STORE_CTX_get_error_depth(store), X509_verify_cert_error_string(X509_STORE_CTX_get_error(store)));
- X509_NAME_oneline(X509_get_issuer_name(cert), data, sizeof(data));
- fprintf(stderr, "certificate issuer %s\n", data);
- X509_NAME_oneline(X509_get_subject_name(cert), data, sizeof(data));
- fprintf(stderr, "certificate subject %s\n", data);
- }
-#endif
- return ok;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_accept(struct soap *soap)
-{ int i, r;
- if (!soap_valid_socket(soap->socket))
- return soap_set_receiver_error(soap, "SSL error", "No socket in soap_ssl_accept()", SOAP_SSL_ERROR);
- if (!soap->ssl)
- { soap->ssl = SSL_new(soap->ctx);
- if (!soap->ssl)
- return soap_set_receiver_error(soap, "SSL error", "SSL_new() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
- }
- else
- SSL_clear(soap->ssl);
- soap->imode |= SOAP_ENC_SSL;
- soap->omode |= SOAP_ENC_SSL;
-#ifdef WIN32
- u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &nonblocking);
-#else
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)|O_NONBLOCK);
-#endif
- soap->bio = BIO_new_socket((SOAP_SOCKET)soap->socket, BIO_NOCLOSE);
- SSL_set_bio(soap->ssl, soap->bio, soap->bio);
- i = 100;
- while ((r = SSL_accept(soap->ssl)) <= 0)
- { int err = SSL_get_error(soap->ssl, r);
- if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
- { struct timeval timeout;
- fd_set fd;
- if (i-- <= 0)
- break;
- timeout.tv_sec = 0;
- timeout.tv_usec = 100000;
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r < 0 && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- }
- else
- { soap->errnum = err;
- break;
- }
- }
-#ifdef WIN32
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking);
- }
-#else
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)&~O_NONBLOCK);
-#endif
- if (r <= 0)
- { soap_set_receiver_error(soap, ssl_error(soap, r), "SSL_accept() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
- soap_closesock(soap);
- return SOAP_SSL_ERROR;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#endif /* WITH_OPENSSL */
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-tcp_init(struct soap *soap)
-{ soap->errmode = 1;
-#ifdef WIN32
- if (tcp_done)
- return 0;
- tcp_done = 1;
- { WSADATA w;
- if (WSAStartup(MAKEWORD(1, 1), &w))
- { tcp_done = 0;
- return -1;
- }
- }
-#endif
-#ifdef PALM
- errno = 0;
- h_errno = 0;
- AppNetRefnum = 0;
- NetUInit();
- AppNetTimeout = 10000;
- NetLibOpen(AppNetRefnum, &h_errno);
-#endif
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_done(struct soap *soap)
-{
-#ifndef WITH_LEAN
- int i;
-#endif
- soap_free(soap);
- while (soap->clist)
- { struct soap_clist *p = soap->clist->next;
- SOAP_FREE(soap->clist);
- soap->clist = p;
- }
- soap->keep_alive = 0; /* to force close the socket */
- soap_closesock(soap);
-#ifdef WITH_COOKIES
- soap_free_cookies(soap);
-#endif
- while (soap->plugins)
- { register struct soap_plugin *p = soap->plugins->next;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Removing plugin '%s'\n", soap->plugins->id));
- if (soap->plugins->fcopy || !soap->copy)
- soap->plugins->fdelete(soap, soap->plugins);
- SOAP_FREE(soap->plugins);
- soap->plugins = p;
- }
- soap->fplugin = fplugin;
- soap->fpost = http_post;
- soap->fget = http_get;
- soap->fposthdr = http_post_header;
- soap->fresponse = http_response;
- soap->fparse = http_parse;
- soap->fparsehdr = http_parse_header;
-#ifndef MAC_CARBON
- soap->faccept = tcp_accept;
- soap->fopen = tcp_connect;
- soap->fclose = tcp_disconnect;
- soap->fsend = fsend;
- soap->frecv = frecv;
-#endif
- soap->fprepare = NULL;
- soap->fignore = NULL;
-#ifdef WITH_OPENSSL
- if (soap->session)
- { SSL_SESSION_free(soap->session);
- soap->session = NULL;
- }
-#endif
- if (!soap->copy)
- { if (soap_valid_socket(soap->master))
- { closesocket((SOAP_SOCKET)soap->master);
- soap->master = SOAP_INVALID_SOCKET;
- }
-#ifdef WITH_OPENSSL
- if (soap->ctx)
- { SSL_CTX_free(soap->ctx);
- soap->ctx = NULL;
- }
-#endif
- }
-#ifndef WITH_LEAN
- for (i = 0; i < SOAP_MAXLOGS; i++)
- { soap_close_logfile(soap, i);
- if (soap->logfile[i])
- { SOAP_FREE((void*)soap->logfile[i]);
- soap->logfile[i] = NULL;
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_cleanup(struct soap *soap)
-{ soap_done(soap);
-#ifdef WIN32
- if (!tcp_done)
- return;
- tcp_done = 0;
- WSACleanup();
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-tcp_error(struct soap *soap)
-{ register const char *msg = NULL;
- switch (soap->errmode)
- { case 0:
- msg = soap_strerror(soap);
- break;
- case 1:
- msg = "WSAStartup failed";
- break;
- case 2:
- {
-#ifndef WITH_LEAN
- msg = soap_str_code(h_error_codes, soap->errnum);
- if (!msg)
-#endif
- { sprintf(soap->msgbuf, "TCP error %d", soap->errnum);
- msg = soap->msgbuf;
- }
- }
- }
- return msg;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-http_error(struct soap *soap, int status)
-{ register const char *msg = NULL;
-#ifndef WITH_LEAN
- msg = soap_str_code(h_http_error_codes, status);
- if (!msg)
-#endif
- { sprintf(soap->msgbuf, "HTTP error %d", status);
- msg = soap->msgbuf;
- }
- return msg;
-}
-#endif
-
-/******************************************************************************/
-/* WR[ */
-#ifndef WITH_IPV6
-/* ]WR */
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-soap_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr)
-{ unsigned long iadd;
- struct hostent hostent, *host = &hostent;
-/* WR[ */
-#ifdef VXWORKS
- int hostint;
- char * addrcopy = (char*)malloc(strlen(addr) + 1); /*copy of addr. */
- /* inet_addr(), and hostGetByName() expect "char *"; addr is a "const char *". */
- strncpy(addrcopy, addr, strlen(addr)+1);
- iadd = inet_addr(addrcopy);
-#else
-/* ]WR */
-#if defined(_AIXVERSION_431) || defined(TRU64)
- struct hostent_data ht_data;
-#endif
- iadd = inet_addr(addr);
-/* WR[ */
-#endif
-/* ]WR */
- if ((int)iadd != -1)
- { memcpy(inaddr, &iadd, sizeof(iadd));
-/* WR[ */
-#ifdef VXWORKS
- free(addrcopy);
-#endif
-/* ]WR */
- return 0;
- }
-#if defined(__GLIBC__)
- if (gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &host, &soap->errnum) < 0)
- host = NULL;
-#elif defined(_AIXVERSION_431) || defined(TRU64)
- memset(&ht_data, 0, sizeof(ht_data));
- if (gethostbyname_r(addr, &hostent, &ht_data) < 0)
- { host = NULL;
- soap->errnum = h_errno;
- }
-#elif defined(HAVE_GETHOSTBYNAME_R)
- host = gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &soap->errnum);
-/* WR[ */
-#elif defined(VXWORKS)
- /* If the DNS resolver library resolvLib has been configured in the vxWorks
- * image, a query for the host IP address is sent to the DNS server, if the
- * name was not found in the local host table. */
- hostint = hostGetByName(addrcopy);
- if (hostint == ERROR)
- {
- host = NULL;
- soap->errnum = soap_errno;
- }
- free(addrcopy); /*free() is placed after the error checking to assure that
- * errno captured is that from hostGetByName() */
-/* ]WR */
-#else
- if (!(host = gethostbyname(addr)))
- soap->errnum = h_errno;
-#endif
- if (!host)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Host name not found\n"));
- return -1;
- }
-/* WR[ */
-#ifdef VXWORKS
- inaddr->s_addr = hostint;
-#else
-/* ]WR */
- memcpy(inaddr, host->h_addr, host->h_length);
-/* WR[ */
-#endif
-/* ]WR */
- return 0;
-}
-#endif
-#endif
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port)
-{ struct sockaddr_in sockaddr;
-/* WR[ */
-#ifdef WITH_IPV6
- struct addrinfo *addrinfo;
- struct addrinfo hints;
- struct addrinfo resaddr;
- struct sockaddr_storage addrstorage;
- int err;
-#endif /* WITH_IPV6 */
-/* ]WR */
- register int fd;
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- if (soap_valid_socket(soap->socket))
- closesocket((SOAP_SOCKET)soap->socket);
- soap->socket = SOAP_INVALID_SOCKET;
- if (tcp_init(soap))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP initialization failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- soap->errmode = 0;
-/* WR[ */
-#ifdef WITH_IPV6
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- soap->errmode = 2;
- if (soap->proxy_host)
- err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &addrinfo);
- else
- err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
- if (addrinfo)
- { resaddr = *addrinfo;
- addrstorage = *((struct sockaddr_storage *) addrinfo->ai_addr);
- resaddr.ai_addr = (struct sockaddr *) &addrstorage;
- freeaddrinfo(addrinfo);
- }
- if (err)
- { soap_set_sender_error(soap, gai_strerror(err),
- "TCP getaddrinfo on proxy host failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- fd = (int)socket(resaddr.ai_family, resaddr.ai_socktype, resaddr.ai_protocol); /* modified to use fd */
- soap->errmode = 0;
-#else /* WITH_IPV6 */
-/* ]WR */
- fd = (int)socket(AF_INET, SOCK_STREAM, 0);
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- if (fd < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP socket failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifndef WITH_LEAN
- if (soap->connect_flags & SO_LINGER)
- { struct linger linger;
- memset(&linger, 0, sizeof(struct linger));
- linger.l_onoff = 1;
- linger.l_linger = 0;
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- }
- if ((soap->connect_flags & ~SO_LINGER) && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, soap->connect_flags & ~SO_LINGER, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
-#endif
-#endif
-/* WR[ */
-#ifndef WITH_IPV6
-/* ]WR */
- memset(&sockaddr, 0, sizeof(sockaddr));
- sockaddr.sin_family = AF_INET;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Open socket %d to host='%s'\n", fd, host));
- soap->errmode = 2;
- if (soap->proxy_host)
- { if (soap_gethost(soap, soap->proxy_host, &sockaddr.sin_addr))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- sockaddr.sin_port = htons((short)soap->proxy_port);
- }
- else
- { if (soap_gethost(soap, host, &sockaddr.sin_addr))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP get host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- sockaddr.sin_port = htons((short)port);
- }
- soap->errmode = 0;
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#if defined(WIN32)
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- {
- vx_nonblocking = TRUE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK);
-#endif
- else
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- {
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- for (;;)
- {
-/* WR[ */
-#ifdef WITH_IPV6
- if (connect((SOAP_SOCKET)fd, resaddr.ai_addr, resaddr.ai_addrlen)) /* modified to use fd */
-#else /* WITH_IPV6 */
- if (connect((SOAP_SOCKET)fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)))
-#endif /* WITH_IPV6 */
-/* ]WR */
- {
-#ifndef WITH_LEAN
- if (soap->connect_timeout && (soap_socket_errno == SOAP_EINPROGRESS || soap_socket_errno == SOAP_EWOULDBLOCK))
- { struct timeval timeout;
-#if defined(SOCKLEN_T)
- SOCKLEN_T n = sizeof(struct sockaddr_in);
-#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN)
- socklen_t n = sizeof(struct sockaddr_in);
-#elif defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)
- int n = sizeof(struct sockaddr_in);
-#else
- size_t n = sizeof(struct sockaddr_in);
-#endif
- fd_set fds;
- if (soap->connect_timeout > 0)
- { timeout.tv_sec = soap->connect_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->connect_timeout/1000000;
- timeout.tv_usec = -soap->connect_timeout%1000000;
- }
- FD_ZERO(&fds);
- FD_SET((SOAP_SOCKET)fd, &fds);
- for (;;)
- { int r = select((SOAP_SOCKET)(fd + 1), NULL, &fds, NULL, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
- soap_set_sender_error(soap, "Timeout", "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- }
- n = sizeof(soap->errnum);
- if (!getsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &n) && !soap->errnum)
- break;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- else
-#endif
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- }
- else
- break;
- }
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- {
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- soap->socket = fd;
-#ifdef WITH_OPENSSL
- soap->imode &= ~SOAP_ENC_SSL;
- soap->omode &= ~SOAP_ENC_SSL;
- if (!strncmp(endpoint, "https:", 6))
- { int r;
- if (soap->proxy_host)
- { unsigned int k = soap->omode; /* make sure we only parse HTTP */
- size_t n = soap->count; /* save the content length */
- soap->omode &= ~0xFF; /* mask IO and ENC */
- soap->omode |= SOAP_IO_BUFFER;
- soap_begin_send(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to proxy server\n"));
- sprintf(soap->tmpbuf, "CONNECT %s:%d HTTP/%s", host, port, soap->http_version);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return -1;
-#ifndef WITH_LEAN
- if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((soap->error = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
- return soap->error;
- }
-#endif
- if ((soap->error = soap->fposthdr(soap, NULL, NULL))
- || soap_end_send(soap))
- return -1;
- soap->omode = k;
- k = soap->imode;
- soap->imode &= ~0xFF; /* mask IO and ENC */
- if (soap_begin_recv(soap))
- return -1;
- soap->imode = k;
- soap->count = n;
- soap_begin_send(soap);
- }
- if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
- { soap_set_sender_error(soap, "SSL error", "SSL authentication failed in tcp_connect(): check password, key file, and ca file.", SOAP_SSL_ERROR);
- return -1;
- }
- soap->ssl = SSL_new(soap->ctx);
- if (!soap->ssl)
- { soap->error = SOAP_SSL_ERROR;
- return -1;
- }
- if (soap->session)
- { if (!strcmp(soap->session_host, host) && soap->session_port == port)
- SSL_set_session(soap->ssl, soap->session);
- SSL_SESSION_free(soap->session);
- soap->session = NULL;
- }
- soap->imode |= SOAP_ENC_SSL;
- soap->omode |= SOAP_ENC_SSL;
- soap->bio = BIO_new_socket((SOAP_SOCKET)fd, BIO_NOCLOSE);
- SSL_set_bio(soap->ssl, soap->bio, soap->bio);
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#ifdef WIN32
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking);
- }
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK);
-#endif
-#endif
- for (;;)
- { if ((r = SSL_connect(soap->ssl)) <= 0)
- { int err = SSL_get_error(soap->ssl, r);
- if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- { soap_set_sender_error(soap, ssl_error(soap, r), "SSL connect failed in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- if (soap->connect_timeout)
- { struct timeval timeout;
- fd_set fds;
- if (soap->connect_timeout > 0)
- { timeout.tv_sec = soap->connect_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->connect_timeout/1000000;
- timeout.tv_usec = -soap->connect_timeout%1000000;
- }
- FD_ZERO(&fds);
- FD_SET((SOAP_SOCKET)(soap->socket), &fds);
- for (;;)
- { int r = select((SOAP_SOCKET)(soap->socket + 1), &fds, NULL, &fds, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
- soap_set_sender_error(soap, "Timeout", "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- continue;
- }
- }
- break;
- }
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#ifdef WIN32
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- if (soap->require_server_auth)
- { X509 *peer;
- int err;
- if ((err = SSL_get_verify_result(soap->ssl)) != X509_V_OK)
- { soap_set_sender_error(soap, X509_verify_cert_error_string(err), "SSL certificate cannot be verified in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- peer = SSL_get_peer_certificate(soap->ssl);
- if (!peer)
- { soap_set_sender_error(soap, "SSL error", "No SSL certificate was presented by the peer in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName, soap->msgbuf, sizeof(soap->msgbuf));
- X509_free(peer);
- if (soap_tag_cmp(soap->msgbuf, host))
- { soap_set_sender_error(soap, "SSL error", "SSL certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- }
- }
-#endif
- return fd;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_bind(struct soap *soap, const char *host, int port, int backlog)
-{ struct sockaddr_in sockaddr;
-/* WR[ */
-#ifdef WITH_IPV6
- struct addrinfo *addrinfo;
- struct addrinfo hints;
- struct addrinfo resaddr;
- struct sockaddr_storage addrstorage;
- int err;
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- if (soap_valid_socket(soap->master))
- { closesocket((SOAP_SOCKET)soap->master);
- soap->master = SOAP_INVALID_SOCKET;
- }
- soap->socket = SOAP_INVALID_SOCKET;
- soap->errmode = 1;
- if (tcp_init(soap))
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP init failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#ifdef WITH_IPV6
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_PASSIVE;
- soap->errmode = 2;
- if (host)
- err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
- else
- err = getaddrinfo(NULL, soap_int2s(soap, port), &hints, &addrinfo);
- if (NULL != addrinfo)
- {
- resaddr = *addrinfo;
- addrstorage = *((struct sockaddr_storage *) addrinfo->ai_addr);
- resaddr.ai_addr = (struct sockaddr *) &addrstorage;
- freeaddrinfo(addrinfo);
- }
- if (err)
- { soap_set_receiver_error(soap, gai_strerror(err), "TCP getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- soap->errmode = 0;
- if ((soap->master = socket(resaddr.ai_family, resaddr.ai_socktype, resaddr.ai_protocol)) < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP socket failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- soap->errmode = 0;
- if ((soap->master = (int)socket(AF_INET, SOCK_STREAM, 0)) < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP socket failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- if (soap->bind_flags && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, soap->bind_flags, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)soap->master, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#endif
-#endif
-/* WR[ */
-#ifdef WITH_IPV6
- soap->errmode = 0;
- if (bind(soap->master, resaddr.ai_addr, resaddr.ai_addrlen) || listen(soap->master, backlog))
- {
- soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
- soap_closesock(soap);
- soap_set_receiver_error(soap, tcp_error(soap), "TCP bind failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- memset(&sockaddr, 0, sizeof(sockaddr));
- sockaddr.sin_family = AF_INET;
- soap->errmode = 2;
- if (host)
- { if (soap_gethost(soap, host, &sockaddr.sin_addr))
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP get host by name failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- else
- sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
- sockaddr.sin_port = htons((short)port);
- soap->errmode = 0;
- if (bind((SOAP_SOCKET)soap->master, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) || listen((SOAP_SOCKET)soap->master, backlog))
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
- soap_closesock(soap);
- soap_set_receiver_error(soap, tcp_error(soap), "TCP bind failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifdef WITH_OPENSSL
- if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
- return -1;
-#endif
- return soap->master;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_poll(struct soap *soap)
-{
-#ifndef WITH_LEAN
- struct timeval timeout;
- fd_set sfd,rfd;
- int r;
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- FD_ZERO(&rfd);
- FD_ZERO(&sfd);
- if (soap->socket >= 0)
- { FD_SET(soap->socket, &rfd);
- FD_SET(soap->socket, &sfd);
- r = select(soap->socket + 1, &rfd, &sfd, NULL, &timeout);
- }
- else if (soap->master >= 0)
- { FD_SET(soap->master, &rfd);
- r = select(soap->master + 1, &rfd, &sfd, NULL, &timeout);
- }
- else
- { FD_SET(soap->sendfd, &sfd);
- FD_SET(soap->recvfd, &rfd);
- r = select((soap->sendfd > soap->recvfd ? soap->sendfd : soap->recvfd) + 1, &rfd, &sfd, NULL, &timeout);
- }
- if (r > 0)
- {
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { if ((soap->socket >= 0) && FD_ISSET(soap->socket, &rfd))
- { char buf = '\0';
- if (SSL_peek(soap->ssl, &buf, 1) <= 0)
- return SOAP_EOF;
- }
- }
-#endif
- return SOAP_OK;
- }
- if (r < 0 && (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "select failed in soap_poll()", SOAP_TCP_ERROR);
- return soap->error = SOAP_TCP_ERROR;
- }
- else
- soap->errnum = soap_errno;
- return SOAP_EOF;
-#else
- return SOAP_OK;
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_accept(struct soap *soap, int s, struct sockaddr *a, int *n)
-{
-#if defined(SOCKLEN_T)
- return (int)accept((SOAP_SOCKET)s, a, (SOCKLEN_T*)n);
-#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN)
- return (int)accept((SOAP_SOCKET)s, a, (socklen_t*)n);
-#elif defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)
- return (int)accept((SOAP_SOCKET)s, a, n);
-#else
- return (int)accept((SOAP_SOCKET)s, a, (size_t*)n);
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_accept(struct soap *soap)
-{
-/* WR[ */
-#ifdef WITH_IPV6
- struct sockaddr_storage sockaddr;
-#else /* WITH_IPV6 */
-/* ]WR */
- struct sockaddr_in sockaddr;
-/* WR[ */
-#endif
-/* ]WR */
- int n = (int)sizeof(struct sockaddr);
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- memset(&sockaddr, 0, sizeof(sockaddr));
- soap->socket = SOAP_INVALID_SOCKET;
- soap->errmode = 0;
- if (soap_valid_socket(soap->master))
- { for (;;)
- {
-#ifndef WITH_LEAN
- if (soap->accept_timeout)
- { struct timeval timeout;
- fd_set fd;
- if (soap->accept_timeout > 0)
- { timeout.tv_sec = soap->accept_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->accept_timeout/1000000;
- timeout.tv_usec = -soap->accept_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->master, &fd);
- for (;;)
- { int r = select((SOAP_SOCKET)(soap->master + 1), &fd, &fd, NULL, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- soap_set_receiver_error(soap, "Timeout", "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- soap_closesock(soap);
- soap_set_sender_error(soap, tcp_error(soap), "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
-#if defined(WIN32)
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &nonblocking);
- }
-#elif defined(VXWORKS)
- { vx_nonblocking = TRUE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- }
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)|O_NONBLOCK);
-#endif
- }
- else
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- {
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- if ((soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&sockaddr, &n)) >= 0)
- {
-/* WR[ */
-#ifdef WITH_IPV6
-/* Use soap->host to store the numeric form of the remote host */
- getnameinfo((struct sockaddr*)&sockaddr, n, soap->host, sizeof(soap->host), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV);
- soap->ip = 0; /* info stored in soap->host */
- soap->port = 0; /* info stored in soap->host */
-#else /* WITH_IPV6 */
-/* ]WR */
- soap->ip = ntohl(sockaddr.sin_addr.s_addr);
- soap->port = (int)ntohs(sockaddr.sin_port);
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- soap->keep_alive = ((soap->imode & SOAP_IO_KEEPALIVE) != 0);
-#ifndef WITH_LEAN
- if (soap->accept_flags & SO_LINGER)
- { struct linger linger;
- memset(&linger, 0, sizeof(struct linger));
- linger.l_onoff = 1;
- linger.l_linger = 0;
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- if ((soap->accept_flags & ~SO_LINGER) && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, soap->accept_flags & ~SO_LINGER, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-#endif
-#endif
- if (soap->accept_timeout)
- {
-#if defined(WIN32)
- u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &blocking);
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking);
-/* WR[ */
-#elif defined(VXWORKS)
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)(&vx_nonblocking));
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK);
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)&~O_NONBLOCK);
-#endif
- }
- return soap->socket;
- }
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- }
- else
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP no master socket in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_disconnect(struct soap *soap)
-{
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { int r, s = 0;
- if (soap->session)
- SSL_SESSION_free(soap->session);
- if (*soap->host)
- { soap->session = SSL_get1_session(soap->ssl);
- if (soap->session)
- { strcpy(soap->session_host, soap->host);
- soap->session_port = soap->port;
- }
- }
- r = SSL_shutdown(soap->ssl);
- if (r != 1)
- { s = ERR_get_error();
- if (s)
- { if (soap_valid_socket(soap->socket))
- { shutdown((SOAP_SOCKET)soap->socket, 1);
- soap->socket = SOAP_INVALID_SOCKET;
- }
- r = SSL_shutdown(soap->ssl);
- }
- }
- DBGLOG(TEST, if (s) SOAP_MESSAGE(fdebug, "Shutdown failed: %d\n", SSL_get_error(soap->ssl, r)));
- SSL_free(soap->ssl);
- soap->ssl = NULL;
- if (s)
- return SOAP_SSL_ERROR;
- ERR_remove_state(0);
- }
-#endif
- if (soap_valid_socket(soap->socket))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Closing socket %d\n", soap->socket));
- shutdown((SOAP_SOCKET)soap->socket, 2);
- closesocket((SOAP_SOCKET)soap->socket);
- soap->socket = SOAP_INVALID_SOCKET;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_closesock(struct soap *soap)
-{ register int status = soap->error;
-#ifndef MAC_CARBON
- if (status == SOAP_EOF || !soap->keep_alive)
- { if ((soap->error = soap->fclose(soap)))
- return soap->error;
- soap->socket = SOAP_INVALID_SOCKET;
- }
-#endif
-#ifdef WITH_ZLIB
- if (soap->zlib_state == SOAP_ZLIB_DEFLATE)
- deflateEnd(&soap->d_stream);
- else if (soap->zlib_state == SOAP_ZLIB_INFLATE)
- inflateEnd(&soap->d_stream);
- soap->zlib_state = SOAP_ZLIB_NONE;
-#endif
- return soap->error = status;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_hash(register const char *s)
-{ register int h = 0;
- while (*s)
- h += *s++ & 0x1F;
- return h % SOAP_IDHASH;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_init_pht(struct soap *soap)
-{ register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing pointer hashtable\n"));
- for (i = 0; i < SOAP_PTRHASH; i++)
- soap->pht[i] = NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new()
-{ struct soap *soap = (struct soap*)SOAP_MALLOC(sizeof(struct soap));
- if (soap)
- soap_init(soap);
- return soap;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new1(int mode)
-{ return soap_new2(mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new2(int imode, int omode)
-{ struct soap *soap = (struct soap*)SOAP_MALLOC(sizeof(struct soap));
- if (soap)
- soap_init2(soap, imode, omode);
- return soap;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-soap_free_pht(struct soap *soap)
-{ register struct soap_plist *pp, *next;
- register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n"));
- for (i = 0; i < SOAP_PTRHASH; i++)
- { for (pp = soap->pht[i]; pp; pp = next)
- { next = pp->next;
- SOAP_FREE(pp);
- }
- soap->pht[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embed_element(struct soap *soap, const void *p, const char *tag, int type)
-{ register int i;
- struct soap_plist *pp;
- if (soap->version != 1)
- soap->encoding = 1;
- if ((i = soap_pointer_lookup(soap, p, type, &pp)))
- { if (soap_is_embedded(soap, pp) || soap_is_single(soap, pp))
- return 0;
- soap_set_embedded(soap, pp);
- }
- return i;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embed_array(struct soap *soap, const void *p, const struct soap_array *a, int n, const char *tag, int type)
-{ register int i;
- struct soap_plist *pp;
- if (soap->version != 1)
- soap->encoding = 1;
- if ((i = soap_array_pointer_lookup(soap, p, a, n, type, &pp)))
- { if (soap_is_embedded(soap, pp) || soap_is_single(soap, pp))
- return 0;
- soap_set_embedded(soap, pp);
- }
- return i;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pointer_lookup(struct soap *soap, const void *p, int type, struct soap_plist **ppp)
-{ register struct soap_plist *pp;
- *ppp = NULL;
- if (p)
- for (pp = soap->pht[soap_hash_ptr(p)]; pp; pp = pp->next)
- if (pp->ptr == p && pp->type == type)
- { *ppp = pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d id=%d\n", p, type, pp->id));
- return pp->id;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d: not found\n", p, type));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_pointer_lookup(struct soap *soap, const void *p, const struct soap_array *a, int n, int type, struct soap_plist **ppp)
-{ struct soap_plist *pp;
- *ppp = NULL;
- if (!p || !a->__ptr)
- return 0;
- for (pp = soap->pht[soap_hash_ptr(a->__ptr)]; pp; pp = pp->next)
- if (pp->type == type && pp->array && pp->array->__ptr == a->__ptr && pp->array->__size == n)
- { *ppp = pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d id=%d\n", a->__ptr, type, pp->id));
- return pp->id;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d: not found\n", a->__ptr, type));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pointer_enter(struct soap *soap, const void *p, int type, struct soap_plist **ppp)
-{ register struct soap_plist *pp;
- if (!p)
- { *ppp = NULL;
- return 0;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enter location=%p type=%d id=%lu\n", p, type, soap->idnum+1));
- *ppp = pp = (struct soap_plist*)SOAP_MALLOC(sizeof(struct soap_plist));
- if (pp)
- { register int h = soap_hash_ptr(p);
- pp->next = soap->pht[h];
- pp->type = type;
- if ((soap->mode & SOAP_XML_TREE) || soap->part == SOAP_IN_HEADER)
- { pp->mark1 = 0;
- pp->mark2 = 0;
- }
- else
- { pp->mark1 = 1;
- pp->mark2 = 1;
- }
- pp->ptr = p;
- pp->array = NULL;
- soap->pht[h] = pp;
- return pp->id = ++soap->idnum;
- }
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_pointer_enter(struct soap *soap, const void *p, const struct soap_array *a, int type, struct soap_plist **ppp)
-{ struct soap_plist *pp;
- *ppp = NULL;
- if (!p || !a->__ptr)
- return 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array enter location=%p size=%d type=%d id=%lu\n", a->__ptr, a->__size, type, soap->idnum+1));
- *ppp = pp = (struct soap_plist*)SOAP_MALLOC(sizeof(struct soap_plist));
- if (pp)
- { register int h = soap_hash_ptr(a->__ptr);
- pp->next = soap->pht[h];
- pp->type = type;
- if ((soap->mode & SOAP_XML_TREE) || soap->part == SOAP_IN_HEADER)
- { pp->mark1 = 0;
- pp->mark2 = 0;
- }
- else
- { pp->mark1 = 1;
- pp->mark2 = 1;
- }
- pp->ptr = p;
- pp->array = a;
- soap->pht[h] = pp;
- return pp->id = ++soap->idnum;
- }
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_begin_count(struct soap *soap)
-{ soap_clr_attr(soap);
- soap_set_local_namespaces(soap);
- if (soap->mode & SOAP_ENC_DIME)
- soap->mode = soap->omode | SOAP_IO_LENGTH | SOAP_ENC_DIME;
- else
- { soap->mode = soap->omode;
- if (((soap->mode & (SOAP_IO_STORE | SOAP_IO_CHUNK)) || (soap->mode & SOAP_ENC_XML)) && !soap->fprepare)
- soap->mode &= ~SOAP_IO_LENGTH;
- else
- soap->mode |= SOAP_IO_LENGTH;
- }
- if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
- { if (!(soap->mode & SOAP_ENC_DIME))
- soap->mode &= ~SOAP_IO_LENGTH;
- if (soap->mode & SOAP_ENC_XML)
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- soap->count = 0;
- soap->ns = 0;
- soap->null = 0;
- soap->position = 0;
- soap->mustUnderstand = 0;
- soap->encoding = 0;
- soap->part = SOAP_BEGIN;
- soap->idnum = 0;
- soap->dime_count = 0; /* count # of attachments */
- soap->dime_size = 0; /* accumulate total size of attachments */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=%hd count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_begin_send(struct soap *soap)
-{ soap_clr_attr(soap);
- soap_set_local_namespaces(soap);
- soap->mode = (soap->omode & ~SOAP_IO_LENGTH) | (soap->mode & SOAP_ENC_DIME);
- if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
- { if (soap->mode & SOAP_ENC_XML)
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket))
- { if (soap->count || (soap->mode & SOAP_ENC_XML))
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- soap_new_block(soap);
- if (!(soap->mode & SOAP_IO_KEEPALIVE))
- soap->keep_alive = 0;
-#ifdef WIN32
-#ifndef UNDER_CE
-#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket)) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
-#ifdef __BORLANDC__
- setmode((SOAP_SOCKET)soap->sendfd, O_BINARY);
-#else
- _setmode((SOAP_SOCKET)soap->sendfd, _O_BINARY);
-#endif
-#endif
-#endif
-#endif
- if (soap->mode & SOAP_IO)
- { soap->bufidx = 0;
- soap->buflen = 0;
- }
- soap->chunksize = 0;
- soap->ns = 0;
- soap->null = 0;
- soap->position = 0;
- soap->mustUnderstand = 0;
- soap->encoding = 0;
- soap->part = SOAP_BEGIN;
- soap->idnum = 0;
- soap->level = 0;
-#ifdef WITH_ZLIB
- soap->z_ratio_out = 1.0;
- if ((soap->mode & SOAP_ENC_ZLIB) && soap->zlib_state != SOAP_ZLIB_DEFLATE)
- {
-#ifdef WITH_GZIP
- memcpy(soap->z_buf, "\37\213\10\0\0\0\0\0\0\377", 10);
- soap->d_stream.next_out = (Byte*)soap->z_buf + 10;
- soap->d_stream.avail_out = SOAP_BUFLEN - 10;
- soap->z_crc = crc32(0L, NULL, 0);
- if (deflateInit2(&soap->d_stream, soap->z_level, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK)
-#else
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- if (deflateInit(&soap->d_stream, soap->z_level) != Z_OK)
-#endif
- return soap->error = SOAP_ZLIB_ERROR;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflate initialized\n"));
- soap->zlib_state = SOAP_ZLIB_DEFLATE;
- }
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin send phase (socket=%d mode=%hd count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_embedded(struct soap *soap, const void *p, int t)
-{ struct soap_plist *pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded %p type=%d\n", p, t));
- if (soap_pointer_lookup(soap, p, t, &pp))
- { pp->mark1 = 1;
- pp->mark2 = 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded %p type=%d set to %d\n", p, t, (int)pp->mark1));
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_reference(struct soap *soap, const void *p, int t)
-{ register int i;
- struct soap_plist *pp;
- if (!p)
- return 1;
- i = soap_pointer_lookup(soap, p, t, &pp);
- if (i)
- { if (pp->mark1 == 0)
- { pp->mark1 = 2;
- pp->mark2 = 2;
- }
- }
- else
- { soap_pointer_enter(soap, p, t, &pp);
- pp->mark1 = 0;
- pp->mark2 = 0;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reference %p type = %d (%d %d)\n", p, t, (int)pp->mark1, (int)pp->mark2));
- return pp->mark1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_reference(struct soap *soap, const void *p, const struct soap_array *a, int n, int t)
-{ register int i;
- struct soap_plist *pp;
- if (!p)
- return 1;
- i = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
- if (i)
- { if (pp->mark1 == 0)
- { pp->mark1 = 2;
- pp->mark2 = 2;
- }
- }
- else if (!soap_array_pointer_enter(soap, p, a, t, &pp))
- return 1;
- pp->mark1 = 0;
- pp->mark2 = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array reference %p ptr=%p size=%d type = %d (%d %d)\n", p, a->__ptr, n, t, (int)pp->mark1, (int)pp->mark2));
- return pp->mark1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embedded_id(struct soap *soap, int id, const void *p, int t)
-{ struct soap_plist *pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id %p type=%d id=%d\n", p, t, id));
- if (soap->version == 1 && soap->encodingStyle && !(soap->mode & (SOAP_XML_TREE | SOAP_XML_GRAPH)) && soap->part != SOAP_IN_HEADER)
- { if (id < 0)
- { id = soap_pointer_lookup(soap, p, t, &pp);
- if (id > 0 && pp)
- { if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 2;
- else
- pp->mark2 = 2;
- }
- return -1;
- }
- return id;
- }
- if (id < 0)
- id = soap_pointer_lookup(soap, p, t, &pp);
- else
- soap_pointer_lookup(soap, p, t, &pp);
- if (id > 0 && pp)
- { if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 1;
- else
- pp->mark2 = 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id id=%d %p type=%d = (%d %d)\n", id, p, t, (int)pp->mark1, (int)pp->mark2));
- }
- return id;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_embedded(struct soap *soap, struct soap_plist *pp)
-{ if (!pp)
- return 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Is embedded? %d %d\n", (int)pp->mark1, (int)pp->mark2));
- if (soap->version == 1 && soap->encodingStyle && !(soap->mode & (SOAP_XML_TREE | SOAP_XML_GRAPH)) && soap->part != SOAP_IN_HEADER)
- { if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 != 0;
- return pp->mark2 != 0;
- }
- if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 1;
- return pp->mark2 == 1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_single(struct soap *soap, struct soap_plist *pp)
-{ if ((soap->mode & SOAP_XML_TREE) || soap->part == SOAP_IN_HEADER)
- return 1;
- if (!pp)
- return 0;
- if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 0;
- return pp->mark2 == 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_multi(struct soap *soap, struct soap_plist *pp)
-{ if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 2;
- return pp->mark2 == 2;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_embedded(struct soap *soap, struct soap_plist *pp)
-{ if (!pp)
- return;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 1;
- else
- pp->mark2 = 1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_attached(struct soap *soap, struct soap_plist *pp, const char *id, const char *type, const char *options, size_t size)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set attached id='%s' type='%s'\n", id?id:"", type?type:""));
- if (soap->mode & SOAP_IO_LENGTH)
- { if (pp->mark1 != 3)
- { pp->mark1 = 3;
- soap->dime_count++; /* one more attachment found */
- soap->dime_size += 12; /* increase total size (DIME fields) */
- if (id)
- soap->dime_size += (strlen(id)+3)&(~3);
- if (type)
- soap->dime_size += (strlen(type)+3)&(~3);
- if (options)
- soap->dime_size += 4 + (((((unsigned char)options[2] << 8 | (unsigned char)options[3]))+3)&(~3));
- soap->dime_size += (size+3)&(~3);
- }
- }
- else if (pp->mark2 != 3)
- pp->mark2 = 3;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_init_iht(struct soap *soap)
-{ register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing ID hashtable\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- soap->iht[i] = NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-soap_free_iht(struct soap *soap)
-{ register int i;
- register struct soap_ilist *ip, *p;
- register struct soap_clist *cp, *q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free ID hashtable\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = p)
- { for (cp = ip->clist; cp; cp = q)
- { q = cp->next;
- SOAP_FREE(cp);
- }
- p = ip->next;
- SOAP_FREE(ip);
- }
- soap->iht[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static struct soap_ilist *
-soap_hlookup(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- for (ip = soap->iht[soap_hash(id)]; ip; ip = ip->next)
- if (!strcmp(ip->id, id))
- return ip;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_ilist *
-SOAP_FMAC2
-soap_lookup(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- ip = soap_hlookup(soap, id);
-#ifndef WITH_LEANER
- if (!ip && *id != '#' && !strchr(id, ':')) /* try content id "cid:" with DIME attachments */
- { char cid[SOAP_TAGLEN];
- strcpy(cid, "cid:");
- strncat(cid + 4, id, sizeof(cid) - 5);
- cid[sizeof(cid) - 1] = '\0';
- ip = soap_hlookup(soap, cid);
- }
-#endif
- return ip;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_ilist *
-SOAP_FMAC2
-soap_enter(struct soap *soap, const char *id)
-{ register int h;
- register struct soap_ilist *ip;
- ip = (struct soap_ilist*)SOAP_MALLOC(sizeof(struct soap_ilist) + strlen(id));
- if (ip)
- { h = soap_hash(id);
- strcpy(ip->id, id);
- ip->next = soap->iht[h];
- soap->iht[h] = ip;
- return ip;
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_malloc(struct soap *soap, size_t n)
-{ register char *p;
- if (!n)
- return NULL;
- if (!soap)
- return SOAP_MALLOC(n);
- n += (-(long)n) & 7;
- if (!(p = (char*)SOAP_MALLOC(n + sizeof(void*) + sizeof(size_t))))
- { soap->error = SOAP_EOM;
- return NULL;
- }
- /* keep chain of alloced cells for later destruction */
- soap->alloced = 1;
- *(void**)(p + n) = soap->alist;
- *(size_t*)(p + n + sizeof(void*)) = n;
- soap->alist = p + n;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Malloc %u bytes at location %p\n", (unsigned int)n, p));
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_dealloc(struct soap *soap, void *p)
-{ if (!soap)
- return;
- if (p)
- { register char **q;
- for (q = (char**)&soap->alist; *q; q = *(char***)q)
- { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
- { *q = **(char***)q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Freed data at %p\n", p));
- SOAP_FREE(p);
- return;
- }
- }
- soap_delete(soap, p);
- }
- else
- { register char *q;
- while (soap->alist)
- { q = (char*)soap->alist;
- soap->alist = *(void**)q;
- q -= *(size_t*)(q + sizeof(void*));
- if (q == (char*)soap->fault)
- soap->fault = NULL; /* this was deallocated */
- else if (q == (char*)soap->header)
- soap->header = NULL; /* this was deallocated */
- SOAP_FREE(q);
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Dealloc all data done\n"));
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_delete(struct soap *soap, void *p)
-{ register struct soap_clist **cp = &soap->clist;
- if (p)
- { while (*cp)
- { if (p == (*cp)->ptr)
- { register struct soap_clist *q = *cp;
- *cp = q->next;
- q->fdelete(q);
- SOAP_FREE(q);
- return;
- }
- cp = &(*cp)->next;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: address not in list\n", p));
- }
- else
- { while (*cp)
- { register struct soap_clist *q = *cp;
- *cp = q->next;
- if (q->ptr == (void*)soap->fault)
- soap->fault = NULL; /* this was deallocated */
- else if (q->ptr == (void*)soap->header)
- soap->header = NULL; /* this was deallocated */
- q->fdelete(q);
- SOAP_FREE(q);
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_clist *
-SOAP_FMAC2
-soap_link(struct soap *soap, void *p, int t, int n, void (*fdelete)(struct soap_clist*))
-{ register struct soap_clist *cp;
- if ((cp = (struct soap_clist*)SOAP_MALLOC(sizeof(struct soap_clist))))
- { cp->next = soap->clist;
- cp->type = t;
- cp->size = n;
- cp->ptr = p;
- cp->fdelete = fdelete;
- soap->clist = cp;
- }
- return cp;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_unlink(struct soap *soap, const void *p)
-{ register char **q;
- register struct soap_clist **cp;
- if (!soap || !p)
- return;
- for (q = (char**)&soap->alist; *q; q = *(char***)q)
- { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
- { *q = **(char***)q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked data %p\n", p));
- return;
- }
- }
- for (cp = &soap->clist; *cp; cp = &(*cp)->next)
- { if (p == (*cp)->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked class instance %p\n", p));
- q = (char**)*cp;
- *cp = (*cp)->next;
- SOAP_FREE(q);
- return;
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_lookup_type(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- if (*id)
- { ip = soap_lookup(soap, id);
- if (ip)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup id='%s' type=%d\n", id, ip->type));
- return ip->type;
- }
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "lookup type id='%s' NOT FOUND! Need to get it from xsi:type\n", id));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_lookup(struct soap *soap, const char *id, void **p, int t, size_t n, unsigned int k)
-{ struct soap_ilist *ip;
- void *q;
- if (*id == '\0')
- return p;
- soap->alloced = 0;
- if (!p)
- p = (void**)soap_malloc(soap, sizeof(void*));
- ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
- if (!ip)
- { ip = soap_enter(soap, id); /* new hash table entry for string id */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding first href='%s' %p (%u bytes)\n", id, p, (unsigned int)n));
- ip->type = t;
- ip->size = n;
- ip->link = p;
- ip->copy = NULL;
- ip->clist = NULL;
- ip->ptr = NULL;
- ip->level = k;
- *p = NULL;
- }
- else if (!soap->blist && ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolved href='%s' type='%d' (%u bytes)\n", id, t, (unsigned int)n));
- if (ip->type != t)
- { soap->error = SOAP_HREF;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Object mismatch: id's type='%d' href's type='%d'\n", ip->type, t));
- return NULL;
- }
- while (ip->level < k)
- { q = soap_malloc(soap, sizeof(void*));
- *p = q;
- p = (void**)q;
- k--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- *p = ip->ptr;
- }
- else if (ip->level > k)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving level %u pointers to href='%s'\n", ip->level, id));
- while (ip->level > k)
- { void *s, **r = &ip->link;
- q = ip->link;
- while (q)
- { *r = soap_malloc(soap, sizeof(void*));
- s = *(void**)q;
- *(void**)q = *r;
- r = *(void***)q;
- q = s;
- }
- *r = NULL;
- ip->size = n;
- ip->copy = NULL;
- ip->level = ip->level - 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- q = ip->link;
- ip->link = p;
- *p = q;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarded href='%s' (%u bytes)\n", id, (unsigned int)n));
- while (ip->level < k)
- { q = soap_malloc(soap, sizeof(void*));
- *p = q;
- p = (void**)q;
- k--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- q = ip->link;
- ip->link = p;
- *p = q;
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_forward(struct soap *soap, const char *href, void *p, int t, size_t n)
-{ struct soap_ilist *ip;
- if (!p || !*href)
- return p;
- ip = soap_lookup(soap, soap->href); /* lookup pointer to hash table entry for string id */
- if (!ip)
- { if (n >= sizeof(void*))
- { ip = soap_enter(soap, href); /* new hash table entry for string id */
- ip->type = t;
- ip->size = n;
- ip->link = NULL;
- ip->copy = p;
- ip->clist = NULL;
- *(void**)p = NULL;
- ip->ptr = NULL;
- ip->level = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding first copying address %p for type %d href='%s'\n", p, t, href));
- return p;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding problem: copying location %p too small (%u) for href='%s'\n", p, (unsigned int)n, href));
- soap->error = SOAP_HREF;
- return NULL;
- }
- else if (ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying value from location %p to location %p to resolve href='%s'\n", ip->ptr, p, href));
- memcpy(p, ip->ptr, n);
- }
- else if (n >= sizeof(void*))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding copying address %p for type %d href='%s' (prev in chain = %p)\n", p, t, href, ip->copy));
- *(void**)p = ip->copy;
- ip->copy = p;
- return p;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding problem: copying location %p too small (%u) for href='%s'\n", p, (unsigned int)n, href));
- soap->error = SOAP_HREF; /* href to object too small to hold pointer */
- return NULL;
- }
- return ip->ptr;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_enter(struct soap *soap, const char *id, void *p, int t, size_t n, int k)
-{ struct soap_ilist *ip;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Enter id='%s' type=%d loc=%p size=%d level=%d\n", id, t, p, (int)n, k));
- soap->alloced = 0;
- if (*id == '\0')
- { if (!p)
- return soap_malloc(soap, n);
- else
- return p;
- }
- ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Lookup entry id='%s'\n", id));
- if (!ip)
- { ip = soap_enter(soap, id); /* new hash table entry for string id */
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "New entry id='%s' type=%d size=%u\n", id, t, (unsigned int)n));
- ip->type = t;
- ip->size = n;
- ip->link = NULL;
- ip->copy = NULL;
- ip->clist = NULL;
- if (!p)
- p = soap_malloc(soap, n);
- ip->ptr = p;
- ip->level = k;
- }
- else if (ip->ptr) /* storage address was forwarded */
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Multiply defined id='%s'\n", id));
- if (p)
- { soap->error = SOAP_MULTI_ID;
- return NULL;
- }
- }
- else
- { if (!p)
- p = soap_malloc(soap, n);
- ip->ptr = p;
- if (!soap->blist)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolve link chain to point to %p\n", ip->ptr));
- soap_resolve_ptr(ip);
- }
- }
- return ip->ptr;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_end_send(struct soap *soap)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End send\n"));
- if (soap->mode & SOAP_IO) /* need to flush the remaining data in buffer */
- { if (soap_flush(soap))
-#ifdef WITH_ZLIB
- { if (soap->mode & SOAP_ENC_ZLIB && soap->zlib_state == SOAP_ZLIB_DEFLATE)
- { soap->zlib_state = SOAP_ZLIB_NONE;
- deflateEnd(&soap->d_stream);
- }
- return soap->error;
- }
-#else
- return soap->error;
-#endif
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { int r;
- soap->d_stream.avail_in = 0;
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating remainder\n"));
- r = deflate(&soap->d_stream, Z_FINISH);
- if (soap->d_stream.avail_out != SOAP_BUFLEN)
- { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN - soap->d_stream.avail_out))
- { soap->zlib_state = SOAP_ZLIB_NONE;
- deflateEnd(&soap->d_stream);
- return soap->error;
- }
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- }
- } while (r == Z_OK);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_out = (float)soap->d_stream.total_out / (float)soap->d_stream.total_in;
- soap->mode &= ~SOAP_ENC_ZLIB;
- soap->zlib_state = SOAP_ZLIB_NONE;
- if (deflateEnd(&soap->d_stream) != Z_OK || r != Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to end deflate: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- return soap->error = SOAP_ZLIB_ERROR;
- }
-#ifdef WITH_GZIP
- soap->z_buf[0] = soap->z_crc & 0xFF;
- soap->z_buf[1] = (soap->z_crc >> 8) & 0xFF;
- soap->z_buf[2] = (soap->z_crc >> 16) & 0xFF;
- soap->z_buf[3] = (soap->z_crc >> 24) & 0xFF;
- soap->z_buf[4] = soap->d_stream.total_in & 0xFF;
- soap->z_buf[5] = (soap->d_stream.total_in >> 8) & 0xFF;
- soap->z_buf[6] = (soap->d_stream.total_in >> 16) & 0xFF;
- soap->z_buf[7] = (soap->d_stream.total_in >> 24) & 0xFF;
- if (soap_flush_raw(soap, soap->z_buf, 8))
- return soap->error;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip crc32=%lu\n", soap->z_crc));
-#endif
- }
-#endif
-#ifndef WITH_LEAN
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- { char *p;
- if (!(soap->mode & SOAP_ENC_XML))
- { soap->mode--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending buffered message of length %u\n", (unsigned int)soap->blist->size));
- if (soap->status >= SOAP_POST)
- soap->error = soap->fpost(soap, soap->endpoint, soap->host, soap->port, soap->path, soap->action, soap->blist->size);
- else if (soap->status != SOAP_STOP)
- soap->error = soap->fresponse(soap, soap->status, soap->blist->size);
- if (soap->error || soap_flush(soap))
- return soap->error;
- soap->mode++;
- }
- for (p = soap_first_block(soap); p; p = soap_next_block(soap))
- { DBGMSG(SENT, p, soap_block_size(soap));
- if ((soap->error = soap->fsend(soap, p, soap_block_size(soap))))
- { soap_end_block(soap);
- return soap->error;
- }
- }
- soap_end_block(soap);
- }
- else if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { DBGMSG(SENT, "\r\n0\r\n\r\n", 7);
- if ((soap->error = soap->fsend(soap, "\r\n0\r\n\r\n", 7)))
- return soap->error;
- }
-#endif
- }
-#ifdef WITH_OPENSSL
- if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive)
- shutdown((SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */
-#else
- if (soap_valid_socket(soap->socket) && !soap->keep_alive)
- shutdown((SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send message ok\n"));
- soap->part = SOAP_END;
- soap->count = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_end_recv(struct soap *soap)
-{ soap->part = SOAP_END;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "End of receive message ok\n"));
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { soap->mode &= ~SOAP_ENC_ZLIB;
- memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
- soap->bufidx = (char*)soap->d_stream.next_in - soap->z_buf;
- soap->buflen = soap->z_buflen;
- soap->zlib_state = SOAP_ZLIB_NONE;
- if (inflateEnd(&soap->d_stream) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
-#ifdef WITH_GZIP
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- { wchar c;
- short i;
- for (i = 0; i < 8; i++)
- { if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
- soap->z_buf[i] = (char)c;
- }
- if (soap->z_crc != ((unsigned char)soap->z_buf[0] | (unsigned long)((unsigned char)soap->z_buf[1] << 8) | (unsigned long)((unsigned char)soap->z_buf[2] << 16) | (unsigned long)((unsigned char)soap->z_buf[3] << 24)))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: crc check failed, message corrupted? (crc32=%lu)\n", soap->z_crc));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- if (soap->d_stream.total_out != ((unsigned char)soap->z_buf[4] | (unsigned long)((unsigned char)soap->z_buf[5] << 8) | (unsigned long)((unsigned char)soap->z_buf[6] << 16) | (unsigned long)((unsigned char)soap->z_buf[7] << 24)))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: incorrect message length\n"));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- }
-#endif
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- while ((int)soap_getchar(soap) != EOF) /* advance to last chunk */
- ;
- if (soap->fdisconnect)
- if ((soap->error = soap->fdisconnect(soap)))
- return soap->error;
- return soap_resolve(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_free(struct soap *soap)
-{ register struct soap_nlist *np;
- register struct soap_attribute *tp;
- register struct Namespace *ns;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n"));
- while (soap->nlist)
- { np = soap->nlist->next;
- if (soap->nlist->ns)
- SOAP_FREE(soap->nlist->ns);
- SOAP_FREE(soap->nlist);
- soap->nlist = np;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free any remaining temp blocks\n"));
- while (soap->blist)
- soap_end_block(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attributes\n"));
- while (soap->attributes)
- { tp = soap->attributes->next;
- if (soap->attributes->value)
- SOAP_FREE(soap->attributes->value);
- SOAP_FREE(soap->attributes);
- soap->attributes = tp;
- }
- soap_free_pht(soap);
- soap_free_iht(soap);
- ns = soap->local_namespaces;
- if (ns)
- { for (; ns->id; ns++)
- { if (ns->out)
- { SOAP_FREE(ns->out);
- if (soap->encodingStyle == ns->out)
- soap->encodingStyle = SOAP_STR_EOS;
- ns->out = NULL;
- }
- if (soap->encodingStyle == ns->ns)
- soap->encodingStyle = SOAP_STR_EOS;
- }
- SOAP_FREE(soap->local_namespaces);
- soap->local_namespaces = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static void
-soap_init_logs(struct soap *soap)
-{ int i;
- for (i = 0; i < SOAP_MAXLOGS; i++)
- { soap->logfile[i] = NULL;
- soap->fdebug[i] = NULL;
- }
-#ifdef SOAP_DEBUG
- soap_set_recv_logfile(soap, "RECV.log");
- soap_set_sent_logfile(soap, "SENT.log");
- soap_set_test_logfile(soap, "TEST.log");
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_open_logfile(struct soap *soap, int i)
-{ if (soap->logfile[i])
- soap->fdebug[i] = fopen(soap->logfile[i], i < 2 ? "ab" : "a");
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static void
-soap_close_logfile(struct soap *soap, int i)
-{ if (soap->fdebug[i])
- { fclose(soap->fdebug[i]);
- soap->fdebug[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_close_logfiles(struct soap *soap)
-{ int i;
- for (i = 0; i < SOAP_MAXLOGS; i++)
- soap_close_logfile(soap, i);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static void
-soap_set_logfile(struct soap *soap, int i, const char *logfile)
-{ char *s = NULL;
- soap_close_logfile(soap, i);
- if (soap->logfile[i])
- SOAP_FREE((void*)soap->logfile[i]);
- if (logfile)
- if ((s = (char*)SOAP_MALLOC(strlen(logfile) + 1)))
- strcpy(s, logfile);
- soap->logfile[i] = s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_recv_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_RECV, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_sent_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_SENT, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_test_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_TEST, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_copy(struct soap *soap)
-{ return soap_copy_context((struct soap*)SOAP_MALLOC(sizeof(struct soap)), soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_copy_context(struct soap *copy, struct soap *soap)
-{ if (copy)
- { register struct soap_plugin *p;
- memcpy(copy, soap, sizeof(struct soap));
- copy->copy = 1;
- copy->user = NULL;
- copy->userid = NULL;
- copy->passwd = NULL;
- copy->nlist = NULL;
- copy->blist = NULL;
- copy->clist = NULL;
- copy->alist = NULL;
- copy->attributes = NULL;
- copy->local_namespaces = NULL;
- soap_set_local_namespaces(copy);
- soap_init_iht(copy);
- soap_init_pht(copy);
- copy->header = NULL;
- copy->fault = NULL;
- copy->action = NULL;
- *copy->host = '\0';
-#ifndef WITH_LEAN
-#ifdef WITH_COOKIES
- copy->cookies = soap_copy_cookies(soap);
-#else
- copy->cookies = NULL;
-#endif
- soap_init_logs(copy);
-#endif
- copy->plugins = NULL;
- for (p = soap->plugins; p; p = p->next)
- { register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(sizeof(struct soap_plugin));
- if (!q)
- return NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying plugin '%s'\n", p->id));
- *q = *p;
- if (p->fcopy && (soap->error = p->fcopy(soap, q, p)))
- { SOAP_FREE(q);
- return NULL;
- }
- q->next = copy->plugins;
- copy->plugins = q;
- }
- }
- else
- soap->error = SOAP_EOM;
- return copy;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init(struct soap *soap)
-{ soap->version = 1; /* default SOAP 1.1 */
- soap_imode(soap, SOAP_IO_DEFAULT);
- soap_omode(soap, SOAP_IO_DEFAULT);
- soap->copy = 0;
- soap->plugins = NULL;
- soap->user = NULL;
- soap->userid = NULL;
- soap->passwd = NULL;
- soap->fpost = http_post;
- soap->fget = http_get;
- soap->fposthdr = http_post_header;
- soap->fresponse = http_response;
- soap->fparse = http_parse;
- soap->fparsehdr = http_parse_header;
- soap->fconnect = NULL;
- soap->fdisconnect = NULL;
-#ifndef MAC_CARBON
- soap->faccept = tcp_accept;
- soap->fopen = tcp_connect;
- soap->fclose = tcp_disconnect;
- soap->fsend = fsend;
- soap->frecv = frecv;
-#endif
- soap->fprepare = NULL;
- soap->fignore = NULL;
- soap->fplugin = fplugin;
- soap->fdimereadopen = NULL;
- soap->fdimewriteopen = NULL;
- soap->fdimereadclose = NULL;
- soap->fdimewriteclose = NULL;
- soap->fdimeread = NULL;
- soap->fdimewrite = NULL;
- soap->float_format = "%.9G"; /* .9G preserves single FP precision, but is not very efficient */
- soap->double_format = "%.18G"; /* .18G preserves double FP precision, but is not very efficient */
- soap->dime_id_format = "cid:id%d"; /* default DIME id format */
- soap->http_version = "1.1";
- soap->encodingStyle = SOAP_STR_EOS;
- soap->actor = NULL;
- soap->max_keep_alive = SOAP_MAXKEEPALIVE;
- soap->keep_alive = 0;
- soap->recv_timeout = 0;
- soap->send_timeout = 0;
- soap->connect_timeout = 0;
- soap->accept_timeout = 0;
- soap->socket_flags = 0;
- soap->connect_flags = 0;
- soap->bind_flags = 0;
- soap->accept_flags = 0;
- soap->ip = 0;
-#ifndef WITH_NONAMESPACES
- soap->namespaces = namespaces;
-#else
- soap->namespaces = NULL;
-#endif
- soap->local_namespaces = NULL;
- soap->nlist = NULL;
- soap->blist = NULL;
- soap->clist = NULL;
- soap->alist = NULL;
- soap->attributes = NULL;
- soap->header = NULL;
- soap->fault = NULL;
- soap->master = SOAP_INVALID_SOCKET;
- soap->socket = SOAP_INVALID_SOCKET;
- soap->os = NULL;
- soap->is = NULL;
- soap->dom = NULL;
-#ifndef UNDER_CE
- soap->recvfd = 0;
- soap->sendfd = 1;
-#else
- soap->recvfd = stdin;
- soap->sendfd = stdout;
-#endif
- soap->host[0] = '\0';
- soap->port = 0;
- soap->action = NULL;
- soap->proxy_host = NULL;
- soap->proxy_port = 8080;
- soap->proxy_userid = NULL;
- soap->proxy_passwd = NULL;
-#ifdef WITH_OPENSSL
- soap->fsslauth = ssl_auth_init;
- soap->fsslverify = ssl_verify_callback;
- soap->bio = NULL;
- soap->ssl = NULL;
- soap->ctx = NULL;
- soap->require_server_auth = 0;
- soap->require_client_auth = 0;
- soap->rsa = 0;
- soap->keyfile = NULL;
- soap->password = NULL;
- soap->dhfile = NULL;
- soap->cafile = NULL;
- soap->capath = NULL;
- soap->randfile = NULL;
- soap->session = NULL;
-#endif
-#ifdef WITH_ZLIB
- soap->zlib_state = SOAP_ZLIB_NONE;
- soap->zlib_in = SOAP_ZLIB_NONE;
- soap->zlib_out = SOAP_ZLIB_NONE;
- soap->d_stream.zalloc = NULL;
- soap->d_stream.zfree = NULL;
- soap->d_stream.opaque = NULL;
- soap->z_level = 6;
-#endif
-#ifndef WITH_LEAN
- soap->cookies = NULL;
- soap->cookie_domain = NULL;
- soap->cookie_path = NULL;
- soap->cookie_max = 32;
- soap_init_logs(soap);
-#endif
-/* WR[ */
-#ifdef WMW_RPM_IO
- soap->rpmreqid = NULL;
-#endif /* WMW_RPM_IO */
-/* ]WR */
- soap_init_iht(soap);
- soap_init_pht(soap);
- soap_begin(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init1(struct soap *soap, int mode)
-{ soap_init2(soap, mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init2(struct soap *soap, int imode, int omode)
-{ soap_init(soap);
- soap_imode(soap, imode);
- soap_omode(soap, omode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_begin(struct soap *soap)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing\n"));
- if (!soap->keep_alive)
- { soap->buflen = 0;
- soap->bufidx = 0;
- }
- soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0);
- soap->null = 0;
- soap->position = 0;
- soap->encoding = 0;
- soap->mustUnderstand = 0;
- soap->mode = 0;
- soap->ns = 0;
- soap->part = SOAP_BEGIN;
- soap->alloced = 0;
- soap->count = 0;
- soap->length = 0;
- soap->cdata = 0;
- soap->error = SOAP_OK;
- soap->peeked = 0;
- soap->ahead = 0;
- soap->idnum = 0;
- soap->level = 0;
- soap->endpoint[0] = '\0';
- soap->dime_chunksize = 0;
- soap->dime_buflen = 0;
- soap->dot_net_bug = 0;
- soap_free(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_end(struct soap *soap)
-{ register struct soap_clist *cp;
- soap_free(soap);
- soap_dealloc(soap, NULL);
- while (soap->clist)
- { cp = soap->clist->next;
- SOAP_FREE(soap->clist);
- soap->clist = cp;
- }
- soap_closesock(soap);
-#ifndef WITH_LEAN
- soap_close_logfiles(soap);
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_namespaces(struct soap *soap, struct Namespace *p)
-{ struct Namespace *ns = soap->local_namespaces;
- struct soap_nlist *np, *nq, *nr;
- unsigned int level = soap->level;
- soap->namespaces = p;
- soap->local_namespaces = NULL;
- soap_set_local_namespaces(soap);
- /* reverse the list */
- np = soap->nlist;
- soap->nlist = NULL;
- if (np)
- { nq = np->next;
- np->next = NULL;
- while (nq)
- { nr = nq->next;
- nq->next = np;
- np = nq;
- nq = nr;
- }
- }
- while (np)
- { soap->level = np->level; /* preserve element nesting level */
- if (np->ns)
- { if (soap_push_namespace(soap, np->id, np->ns))
- return soap->error;
- }
- else if (np->index >= 0 && ns)
- { if (ns[np->index].out)
- { if (soap_push_namespace(soap, np->id, ns[np->index].out))
- return soap->error;
- }
- else if (soap_push_namespace(soap, np->id, ns[np->index].ns))
- return soap->error;
- }
- if (np->ns)
- SOAP_FREE(np->ns);
- nq = np;
- np = np->next;
- SOAP_FREE(nq);
- }
- if (ns)
- { int i;
- for (i = 0; ns[i].id; i++)
- { if (ns[i].out)
- { SOAP_FREE(ns[i].out);
- ns[i].out = NULL;
- }
- }
- SOAP_FREE(ns);
- }
- soap->level = level; /* restore level */
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-soap_set_local_namespaces(struct soap *soap)
-{ if (soap->namespaces && !soap->local_namespaces)
- { register struct Namespace *ns;
- register size_t n = 1;
- for (ns = soap->namespaces; ns->id; ns++)
- n++;
- if (n > 3)
- { n *= sizeof(struct Namespace);
- ns = (struct Namespace*)SOAP_MALLOC(n);
- if (ns)
- { memcpy(ns, soap->namespaces, n);
- ns[0].id = "SOAP-ENV";
- ns[1].id = "SOAP-ENC";
- ns[2].id = "xsi";
- if (ns[0].ns)
- { if (!strcmp(ns[0].ns, soap_env1))
- soap->version = 1;
- else
- soap->version = 2;
- }
- soap->local_namespaces = ns;
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element(struct soap *soap, const char *tag, int id, const char *type)
-{ struct Namespace *ns = soap->local_namespaces;
- register const char *s;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' id='%d' type='%s'\n", tag, id, type?type:""));
-/**/
-#ifdef WITH_DOM
- if (soap->mode & SOAP_XML_DOM)
- { register struct soap_dom_element *p, *e = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element));
- e->next = NULL;
- e->prnt = soap->dom;
- e->nstr = NULL;
- e->name = soap_strdup(soap, tag); /* check EOM? */
- e->data = NULL;
- e->type = 0;
- e->node = NULL;
- e->elts = NULL;
- e->atts = NULL;
- if (soap->dom)
- { p = soap->dom->elts;
- if (p)
- { while (p->next)
- p = p->next;
- p->next = e;
- }
- else
- soap->dom->elts = e;
- }
- soap->dom = e;
- }
- else
-#endif
-{
- soap->level++;
- if (!soap->ns && !(soap->mode & SOAP_XML_CANONICAL))
- if (soap_send(soap, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"))
- return soap->error;
- if (soap_send_raw(soap, "<", 1))
- return soap->error;
- s = tag;
- if (ns && soap->part != SOAP_IN_ENVELOPE && (soap->part == SOAP_IN_HEADER || !soap->encodingStyle))
- { register const char *t = strchr(s, ':');
- if (t)
- { s = t + 1;
- for (ns++; ns->id; ns++)
- { if ((ns->out || ns->ns) && !strncmp(ns->id, tag, t - tag) && !ns->id[t - tag])
- { if (soap_send(soap, s) || soap_attribute(soap, "xmlns", ns->out ? ns->out : ns->ns))
- return soap->error;
- s = NULL;
- break;
- }
- }
- }
- }
- if (s)
- if (soap_send(soap, tag))
- return soap->error;
-}
-/**/
- if (!soap->ns)
- { for (ns = soap->local_namespaces; ns && ns->id; ns++)
- { if (*ns->id && (ns->out || ns->ns))
- { sprintf(soap->tmpbuf, "xmlns:%s", ns->id);
- if (soap_attribute(soap, soap->tmpbuf, ns->out ? ns->out : ns->ns))
- return soap->error;
- }
- }
- soap->ns = 1;
- }
- if (id > 0)
- { sprintf(soap->tmpbuf, "_%d", id);
- if (soap_attribute(soap, "id", soap->tmpbuf))
- return soap->error;
- }
- if (type && *type)
- { if (soap_attribute(soap, "xsi:type", type))
- return soap->error;
- }
- if (soap->null && soap->position > 0)
- { int i;
- sprintf(soap->tmpbuf, "[%d", soap->positions[0]);
- for (i = 1; i < soap->position; i++)
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), ",%d", soap->positions[i]);
- strcat(soap->tmpbuf, "]");
- if (soap_attribute(soap, "SOAP-ENC:position", soap->tmpbuf))
- return soap->error;
- }
- if (soap->mustUnderstand)
- { if (soap->actor && *soap->actor)
- { if (soap_attribute(soap, soap->version == 2 ? "SOAP-ENV:role" : "SOAP-ENV:actor", soap->actor))
- return soap->error;
- }
- if (soap_attribute(soap, "SOAP-ENV:mustUnderstand", soap->version == 2 ? "true" : "1"))
- return soap->error;
- soap->mustUnderstand = 0;
- }
- if (soap->encoding)
- { if (soap->encodingStyle)
- { if (!*soap->encodingStyle && soap->local_namespaces)
- { if (soap->local_namespaces[1].out)
- soap->encodingStyle = soap->local_namespaces[1].out;
- else
- soap->encodingStyle = soap->local_namespaces[1].ns;
- }
- if (soap_attribute(soap, "SOAP-ENV:encodingStyle", soap->encodingStyle))
- return soap->error;
- }
- soap->encoding = 0;
- }
- soap->null = 0;
- soap->position = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_begin_out(struct soap *soap, const char *tag, int id, const char *type)
-{ if (*tag == '-')
- return SOAP_OK;
- if (soap_element(soap, tag, id, type))
- return soap->error;
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRRCHR
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_strrchr(const char *s, int t)
-{ register char *r = NULL;
- while (*s)
- if (*s++ == t)
- r = (char*)s - 1;
- return r;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRTOL
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_strtol(const char *s, char **t, int b)
-{ register long n = 0;
- register int c;
- while (*s > 0 && *s <= 32)
- s++;
- if (b == 10)
- { short neg = 0;
- if (*s == '-')
- { s++;
- neg = 1;
- }
- else if (*s == '+')
- s++;
- while ((c = *s) && c >= '0' && c <= '9')
- { if (n > 214748364)
- break;
- n *= 10;
- n += c - '0';
- s++;
- }
- if (neg)
- n = -n;
- }
- else /* b == 16 and value is always positive */
- { while ((c = *s))
- { if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- if (n > 0x07FFFFFF)
- break;
- n <<= 4;
- n += c;
- s++;
- }
- }
- if (t)
- *t = (char*)s;
- return n;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRTOUL
-SOAP_FMAC1
-unsigned long
-SOAP_FMAC2
-soap_strtoul(const char *s, char **t, int b)
-{ unsigned long n = 0;
- register int c;
- while (*s > 0 && *s <= 32)
- s++;
- if (b == 10)
- { if (*s == '+')
- s++;
- while ((c = *s) && c >= '0' && c <= '9')
- { if (n > 429496729)
- break;
- n *= 10;
- n += c - '0';
- s++;
- }
- }
- else /* b == 16 */
- { while ((c = *s))
- { if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- if (n > 0x0FFFFFFF)
- break;
- n <<= 4;
- n += c;
- s++;
- }
- }
- if (t)
- *t = (char*)s;
- return n;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_begin_out(struct soap *soap, const char *tag, int id, const char *type, const char *offset)
-{ if (soap_element(soap, tag, id, "SOAP-ENC:Array"))
- return soap->error;
- if (soap->version == 2)
- { const char *s;
- s = soap_strrchr(type, '[');
- if ((size_t)(s - type) < sizeof(soap->tmpbuf))
- { strncpy(soap->tmpbuf, type, s - type);
- soap->tmpbuf[s - type] = '\0';
- if (type && *type && (soap_attribute(soap, "SOAP-ENC:itemType", soap->tmpbuf)))
- return soap->error;
- if (s && (soap_attribute(soap, "SOAP-ENC:arraySize", s + 1)))
- return soap->error;
- }
- }
- else
- { if (offset && (soap_attribute(soap, "SOAP-ENC:offset", offset)))
- return soap->error;
- if (type && *type && (soap_attribute(soap, "SOAP-ENC:arrayType", type)))
- return soap->error;
- }
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_start_end_out(struct soap *soap, const char *tag)
-{ register struct soap_attribute *tp;
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible)
- { register struct soap_dom_attribute *a = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
- a->next = soap->dom->atts;
- a->nstr = NULL;
- a->name = soap_strdup(soap, tp->name); /* check EOM */
- a->data = soap_strdup(soap, tp->value); /* check EOM */
- a->wide = NULL;
- soap->dom->atts = a;
- tp->visible = 0;
- }
- }
- return SOAP_OK;
- }
-#endif
-/**/
- for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible)
- { if (soap_send_raw(soap, " ", 1)
- || soap_send(soap, tp->name))
- return soap->error;
- if (tp->visible == 2 && tp->value)
- if (soap_send_raw(soap, "=\"", 2)
- || soap_string_out(soap, tp->value, 1)
- || soap_send_raw(soap, "\"", 1))
- return soap->error;
- tp->visible = 0;
- }
- }
- if (tag)
- { soap->level--;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { if (soap_send_raw(soap, ">", 1)
- || soap_element_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
- }
-#endif
- return soap_send_raw(soap, "/>", 2);
- }
- return soap_send_raw(soap, ">", 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_end_out(struct soap *soap, const char *tag)
-{ if (*tag == '-')
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element ending tag='%s'\n", tag));
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { if (soap->dom->prnt)
- soap->dom = soap->dom->prnt;
- return SOAP_OK;
- }
-#endif
-/**/
- if (soap->part != SOAP_IN_ENVELOPE && (soap->part == SOAP_IN_HEADER || !soap->encodingStyle) && soap->local_namespaces)
- { const char *s = strchr(tag, ':');
- if (s && strncmp(tag, "SOAP-ENV", s - tag))
- tag = s + 1;
- }
- soap->level--;
- if (soap_send_raw(soap, "</", 2)
- || soap_send(soap, tag)
- || soap_send_raw(soap, ">", 1))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_ref(struct soap *soap, const char *tag, int id, int href)
-{ int n = 0;
- if (soap_element(soap, tag, id, NULL))
- return soap->error;
- if (soap->version == 2)
- n = 1;
- sprintf(soap->tmpbuf, "#_%d", href);
- if (soap_attribute(soap, "href" + n, soap->tmpbuf + n)
- || soap_element_start_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_href(struct soap *soap, const char *tag, int id, const char *href)
-{ if (soap_element(soap, tag, id, NULL)
- || soap_attribute(soap, "href", href)
- || soap_element_start_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_null(struct soap *soap, const char *tag, int id, const char *type)
-{ struct soap_attribute *tp;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (tp->visible)
- break;
- if (tp || (soap->version == 2 && soap->position > 0) || id > 0 || (soap->mode & SOAP_XML_NIL))
- { if (soap_element(soap, tag, id, type))
- return soap->error;
- if (soap->part != SOAP_IN_HEADER && soap->encodingStyle)
- if (soap_attribute(soap, "xsi:nil", "true"))
- return soap->error;
- return soap_element_start_end_out(soap, tag);
- }
- soap->null = 1;
- soap->position = 0;
- soap->mustUnderstand = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_result(struct soap *soap, const char *tag)
-{ if (soap->version == 2 && soap->encodingStyle)
- if (soap_element(soap, "SOAP-RPC:result", 0, NULL)
- || soap_attribute(soap, "xmlns:SOAP-RPC", soap_rpc)
- || soap_element_start_end_out(soap, NULL)
- || soap_string_out(soap, tag, 0)
- || soap_element_end_out(soap, "SOAP-RPC:result"))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_attribute(struct soap *soap, const char *name, const char *value)
-{
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { register struct soap_dom_attribute *a = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
- a->next = soap->dom->atts;
- a->nstr = NULL;
- a->name = soap_strdup(soap, name); /* check EOM */
- a->data = soap_strdup(soap, value); /* check EOM */
- a->wide = NULL;
- soap->dom->atts = a;
- return SOAP_OK;
- }
-#endif
-/**/
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { if (soap_set_attr(soap, name, value))
- return soap->error;
- }
- else
-#endif
- { if (soap_send_raw(soap, " ", 1)
- || soap_send(soap, name))
- return soap->error;
- if (value)
- if (soap_send_raw(soap, "=\"", 2)
- || soap_string_out(soap, value, 1)
- || soap_send_raw(soap, "\"", 1))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_begin_in(struct soap *soap, const char *tag)
-{ if (tag && *tag == '-')
- return SOAP_OK;
- if (!soap_peek_element(soap))
- { if (soap->other)
- return soap->error = SOAP_TAG_MISMATCH;
- if (!(soap->error = soap_match_tag(soap, soap->tag, tag)))
- { if (tag && !soap->encodingStyle)
- { const char *s = strchr(tag, ':');
- if (s)
- soap_push_default_namespace(soap, tag, s - tag);
- }
- soap->peeked = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:"" ));
- if (soap->body)
- soap->level++;
- }
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_end_in(struct soap *soap, const char *tag)
-{ register wchar c;
- register char *s;
- register const char *t;
- if (tag && *tag == '-')
- return SOAP_OK;
- soap->level--;
- soap_pop_namespace(soap);
- if (soap->peeked)
- { if (*soap->tag == '\0')
- { soap->peeked = 0;
- soap->error = SOAP_OK;
- }
- else
- return soap->error = SOAP_SYNTAX_ERROR;
- }
- else
- { while (((c = soap_get(soap)) != TT))
- { if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (c == LT)
- return soap->error = SOAP_SYNTAX_ERROR;
- }
- }
- s = soap->tag;
- do c = soap_get(soap);
- while (soap_blank(c));
- do
- { *s++ = (char)c;
- c = soap_get(soap);
- } while (soap_notblank(c));
- *s = '\0';
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- while (soap_blank(c))
- c = soap_get(soap);
- if (c != GT)
- return soap->error = SOAP_SYNTAX_ERROR;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:""));
- if (!tag)
- return SOAP_OK;
- if ((s = strchr(soap->tag, ':')))
- s++;
- else
- s = soap->tag;
- if ((t = strchr(tag, ':')))
- t++;
- else
- t = tag;
- if (!SOAP_STRCMP(s, t))
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element does not match\n"));
- return soap->error = SOAP_SYNTAX_ERROR;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_attribute *
-SOAP_FMAC2
-soap_attr(struct soap *soap, const char *name)
-{ register struct soap_attribute *tp;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!soap_match_tag(soap, tp->name, name))
- return tp;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char *
-SOAP_FMAC2
-soap_attr_value(struct soap *soap, const char *name)
-{ register struct soap_attribute *tp = soap_attr(soap, name);
- if (tp && tp->visible == 2)
- return tp->value;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_attr(struct soap *soap, const char *name, const char *value)
-{ register struct soap_attribute *tp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set attribute %s='%s'\n", name, value?value:""));
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!strcmp(tp->name, name))
- break;
- if (!tp)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute %s\n", name));
- if (!(tp = (struct soap_attribute*)SOAP_MALLOC(sizeof(struct soap_attribute) + strlen(name))))
- return soap->error = SOAP_EOM;
- tp->ns = NULL;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { struct soap_attribute **tpp = &soap->attributes;
- const char *s = strchr(name, ':');
- if (!strncmp(name, "xmlns", 5))
- { for (; *tpp; tpp = &(*tpp)->next)
- if (strncmp((*tpp)->name, "xmlns", 5) || strcmp((*tpp)->name + 5, name + 5) > 0)
- break;
- }
- else if (!s)
- { for (; *tpp; tpp = &(*tpp)->next)
- if (strncmp((*tpp)->name, "xmlns", 5) && ((*tpp)->ns || strcmp((*tpp)->name, name) > 0))
- break;
- }
- else
- { int k;
- for (; *tpp; tpp = &(*tpp)->next)
- { if (!strncmp((*tpp)->name, "xmlns:", 6) && !strncmp((*tpp)->name + 6, name, s - name) && !(*tpp)->name[6 + s - name])
- { if (!tp->ns)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Canonicalization: prefix %s=%p(%s)\n", name, (*tpp)->ns, (*tpp)->ns));
- tp->ns = (*tpp)->ns;
- }
- }
- else if (strncmp((*tpp)->name, "xmlns", 5) && (*tpp)->ns && tp->ns && ((k = strcmp((*tpp)->ns, tp->ns)) > 0 || (!k && strcmp((*tpp)->name, name) > 0)))
- break;
- }
- }
- tp->next = *tpp;
- *tpp = tp;
- }
- else
-#endif
- { tp->next = soap->attributes;
- soap->attributes = tp;
- }
- strcpy(tp->name, name);
- tp->value = NULL;
- }
- else if (value && tp->value && tp->size <= strlen(value))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attribute value of %s (free %p)\n", name, tp->value));
- SOAP_FREE(tp->value);
- tp->value = NULL;
- tp->ns = NULL;
- }
- if (value)
- { if (!tp->value)
- { tp->size = strlen(value) + 1;
- if (!(tp->value = (char*)SOAP_MALLOC(tp->size)))
- return soap->error = SOAP_EOM;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute value of %s (%p)\n", tp->name, tp->value));
- }
- strcpy(tp->value, value);
- if (!strncmp(tp->name, "xmlns:", 6))
- tp->ns = tp->value;
- tp->visible = 2;
- }
- else
- tp->visible = 1;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_attr(struct soap *soap)
-{ register struct soap_attribute *tp;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { while (soap->attributes)
- { tp = soap->attributes->next;
- SOAP_FREE(soap->attributes->value);
- SOAP_FREE(soap->attributes);
- soap->attributes = tp;
- }
- }
- else
-#endif
- { for (tp = soap->attributes; tp; tp = tp->next)
- tp->visible = 0;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static int
-soap_getattrval(struct soap *soap, char *s, size_t n, wchar d)
-{ size_t i;
- wchar c;
- for (i = 0; i < n; i++)
- { c = soap_getutf8(soap);
- switch (c)
- {
- case TT:
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case LT:
- *s++ = '<';
- break;
- case GT:
- if (d == ' ')
- { soap_unget(soap, c);
- *s = '\0';
- return SOAP_OK;
- }
- *s++ = '>';
- break;
- case QT:
- if (c == d)
- { *s = '\0';
- return SOAP_OK;
- }
- *s++ = '"';
- break;
- case AP:
- if (c == d)
- { *s = '\0';
- return SOAP_OK;
- }
- *s++ = '\'';
- break;
- case '\t':
- case '\n':
- case '\r':
- case ' ':
- case '/':
- if (d == ' ')
- { soap_unget(soap, c);
- *s = '\0';
- return SOAP_OK;
- }
- default:
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- }
- return soap->error = SOAP_EOM;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_peek_element(struct soap *soap)
-{ struct soap_attribute *tp;
- const char *t;
- register char *s;
- register wchar c;
- register int i;
- if (soap->peeked)
- { if (*soap->tag == '\0')
- return soap->error = SOAP_NO_TAG;
- return SOAP_OK;
- }
- soap->peeked = 1;
- for (;;)
- { while (((c = soap_get(soap)) != LT) && c != TT)
- { if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- }
- if (c == TT)
- { *soap->tag = '\0';
- return soap->error = SOAP_NO_TAG; /* ending tag found */
- }
- s = soap->tag;
- do c = soap_get(soap);
- while (soap_blank(c));
- i = sizeof(soap->tag);
- while (c != '/' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- while (soap_blank(c))
- c = soap_get(soap);
- *s = '\0';
- if (*soap->tag != '?')
- break;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI <%s?>\n", soap->tag));
- while ((int)c != EOF && c != GT && c != '?')
- { s = soap->tmpbuf;
- i = sizeof(soap->tmpbuf) - 2;
- while (c != '=' && c != GT && c != '?' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- while (soap_blank(c))
- c = soap_get(soap);
- if (c == '=')
- { *s++ = '=';
- do c = soap_get(soap);
- while (soap_blank(c));
- if (c != QT && c != AP)
- { soap_unget(soap, c);
- c = ' '; /* blank delimiter */
- }
- if (soap_getattrval(soap, s, i, c) == SOAP_EOM)
- while (soap_getattrval(soap, soap->tmpbuf, sizeof(soap->tmpbuf), c) == SOAP_EOM)
- ;
- else if (!strcmp(soap->tag, "?xml") && (!soap_tag_cmp(soap->tmpbuf, "encoding=iso-8859-1") || !soap_tag_cmp(soap->tmpbuf, "encoding=latin1")))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML latin1 encoding\n"));
- soap->mode |= SOAP_C_LATIN;
- }
- }
- do c = soap_get(soap);
- while (soap_blank(c));
- }
- }
- soap->id[0] = '\0';
- soap->href[0] = '\0';
- soap->type[0] = '\0';
- soap->arrayType[0] = '\0';
- soap->arraySize[0] = '\0';
- soap->arrayOffset[0] = '\0';
- soap->other = 0;
- soap->root = -1;
- soap->position = 0;
- soap->null = 0;
- soap->mustUnderstand = 0;
- soap_clr_attr(soap);
- soap_pop_namespace(soap);
- while ((int)c != EOF && c != GT && c != '/')
- { s = soap->tmpbuf;
- i = sizeof(soap->tmpbuf);
- while (c != '=' && c != '/' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- *s = '\0';
- if (i == sizeof(soap->tmpbuf))
- return soap->error = SOAP_SYNTAX_ERROR;
- if (!strncmp(soap->tmpbuf, "xmlns:", 6))
- { soap->tmpbuf[5] = '\0';
- t = soap->tmpbuf + 6;
- }
- else if (!strcmp(soap->tmpbuf, "xmlns"))
- t = SOAP_STR_EOS;
- else
- t = NULL;
- tp = soap_attr(soap, soap->tmpbuf);
- if (!tp)
- { tp = (struct soap_attribute*)SOAP_MALLOC(sizeof(struct soap_attribute) + strlen(soap->tmpbuf));
- if (!tp)
- return soap->error = SOAP_EOM;
- strcpy(tp->name, soap->tmpbuf);
- tp->value = NULL;
- tp->size = 0;
- tp->next = soap->attributes;
- soap->attributes = tp;
- }
- while (soap_blank(c))
- c = soap_get(soap);
- if (c == '=')
- { do c = soap_get(soap);
- while (soap_blank(c));
- if (c != QT && c != AP)
- { soap_unget(soap, c);
- c = ' '; /* blank delimiter */
- }
- if (soap_getattrval(soap, tp->value, tp->size, c))
- { size_t size;
- if (soap->error == SOAP_EOM)
- soap->error = SOAP_OK;
- else
- return soap->error;
- if (soap_new_block(soap))
- return soap->error;
- for (;;)
- { if (!(s = (char*)soap_push_block(soap, SOAP_BLKLEN)))
- return soap->error;
- if (soap_getattrval(soap, s, SOAP_BLKLEN, c))
- { if (soap->error == SOAP_EOM)
- soap->error = SOAP_OK;
- else
- return soap->error;
- }
- else
- break;
- }
- size = tp->size + soap->blist->size;
- if (!(s = (char*)SOAP_MALLOC(size)))
- return soap->error = SOAP_EOM;
- soap_save_block(soap, s + tp->size);
- if (tp->value)
- { memcpy(s, tp->value, tp->size);
- SOAP_FREE(tp->value);
- }
- tp->value = s;
- tp->size = size;
- }
- do c = soap_get(soap);
- while (soap_blank(c));
- tp->visible = 2; /* seen this attribute w/ value */
- }
- else
- tp->visible = 1; /* seen this attribute w/o value */
- if (t && tp->value)
- { if (soap_push_namespace(soap, t, tp->value))
- return soap->error;
- tp->visible = 0;
- }
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible && tp->value)
- { if (!strcmp(tp->name, "id"))
- { if (soap->part != SOAP_IN_HEADER || !soap->dot_net_bug)
- { *soap->id = '#';
- strncpy(soap->id + 1, tp->value, sizeof(soap->id) - 2);
- }
- }
- else if (!strcmp(tp->name, "href"))
- strncpy(soap->href, tp->value, sizeof(soap->href) - 1);
- else if (soap->version == 2 && !strcmp(tp->name, "ref"))
- { *soap->href = '#';
- strncpy(soap->href + 1, tp->value, sizeof(soap->href) - 2);
- }
- else if (!soap_match_tag(soap, tp->name, "xsi:type"))
- strncpy(soap->type, tp->value, sizeof(soap->type) - 1);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:arrayType"))
- { s = soap_strrchr(tp->value, '[');
- if (s && (size_t)(s - tp->value) < sizeof(soap->arrayType))
- { strncpy(soap->arrayType, tp->value, s - tp->value);
- soap->arrayType[s - tp->value] = '\0';
- strncpy(soap->arraySize, s, sizeof(soap->arraySize) - 1);
- }
- else
- strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1);
- }
- else if (soap->version == 2 && !soap_match_tag(soap, tp->name, "SOAP-ENC:itemType"))
- strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1);
- else if (soap->version == 2 && !soap_match_tag(soap, tp->name, "SOAP-ENC:arraySize"))
- strncpy(soap->arraySize, tp->value, sizeof(soap->arraySize) - 1);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:offset"))
- strncpy(soap->arrayOffset, tp->value, sizeof(soap->arrayOffset));
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:position"))
- soap->position = soap_getposition(tp->value, soap->positions);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:root"))
- soap->root = ((!strcmp(tp->value, "1") || !strcmp(tp->value, "true")));
- else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:actor")
- || !soap_match_tag(soap, tp->name, "SOAP-ENV:role"))
- { if ((!soap->actor || strcmp(soap->actor, tp->value))
- && strcmp(tp->value, "http://schemas.xmlsoap.org/soap/actor/next")
- && strcmp(tp->value, "http://www.w3.org/2003/05/soap-envelope/role/next"))
- soap->other = 1;
- }
- else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:mustUnderstand")
- && (!strcmp(tp->value, "1") || !strcmp(tp->value, "true")))
- soap->mustUnderstand = 1;
- else if ((!soap_match_tag(soap, tp->name, "xsi:null")
- || !soap_match_tag(soap, tp->name, "xsi:nil"))
- && (!strcmp(tp->value, "1")
- || !strcmp(tp->value, "true")))
- soap->null = 1;
- }
- }
- if (!(soap->body = (c != '/')))
- do c = soap_get(soap);
- while (soap_blank(c));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_retry(struct soap *soap)
-{ soap->peeked = 1;
- soap->error = SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_revert(struct soap *soap)
-{ soap->peeked = 1;
- if (soap->body)
- soap->level--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reverting last element (level=%u)\n", soap->level));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_string_out(struct soap *soap, const char *s, int flag)
-{ register const char *t;
- register wchar c;
- register wchar mask = 0x80000000;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->data = soap_strdup(soap, s); /* check EOM */
- return SOAP_OK;
- }
-#endif
- if (soap->mode & SOAP_C_UTFSTRING)
- mask = 0;
- t = s;
- while ((c = *t++))
- { switch (c)
- {
- case 9:
- if (flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "	", 5))
- return soap->error;
- s = t;
- }
- break;
- case 10:
- if (flag || !(soap->mode & SOAP_XML_CANONICAL))
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
- return soap->error;
- s = t;
- }
- break;
- case 13:
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
- return soap->error;
- s = t;
- break;
- case '&':
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "&", 5))
- return soap->error;
- s = t;
- break;
- case '<':
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "<", 4))
- return soap->error;
- s = t;
- break;
- case '>':
- if (!flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, ">", 4))
- return soap->error;
- s = t;
- }
- break;
- case '"':
- if (flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, """, 6))
- return soap->error;
- s = t;
- }
- break;
- default:
- if (c & mask)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, (unsigned char)c))
- return soap->error;
- s = t;
- }
- }
- }
- return soap_send_raw(soap, s, t - s - 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_string_in(struct soap *soap, int flag)
-{ register char *s;
- char *t = NULL;
- register int i, n = 0;
- register wchar c;
- char buf[8];
- if (soap_new_block(soap))
- return NULL;
-#ifdef WITH_CDATA
- if (!flag)
- { register int state = 0; /* 0 = normal, 1 = CDATA, 2 = comment, 3 = PI */
- for (;;)
- { if (!(s = (char*)soap_push_block(soap, SOAP_BLKLEN)))
- return NULL;
- for (i = 0; i < SOAP_BLKLEN; i++)
- { if (t)
- { *s++ = *t++;
- if (!*t)
- t = NULL;
- continue;
- }
- c = soap_getchar(soap);
- if ((int)c == EOF)
- goto end;
- if (c >= 0x80 && !(soap->mode & SOAP_C_LATIN))
- { soap_unget(soap, c);
- c = soap_getutf8(soap);
- if (soap->mode & SOAP_C_UTFSTRING)
- { if ((c & 0x80000000) && c >= -0x7FFFFF80 && c < AP)
- { c &= 0x7FFFFFFF;
- t = buf;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- *t = '\0';
- t = buf;
- *s++ = *t++;
- continue;
- }
- }
- }
- switch (state)
- { case 1:
- if (c == ']')
- state = 4;
- *s++ = c;
- continue;
- case 2:
- if (c == '-')
- state = 6;
- *s++ = c;
- continue;
- case 3:
- if (c == '?')
- state = 8;
- *s++ = c;
- continue;
- /* CDATA */
- case 4:
- if (c == ']')
- state = 5;
- else
- state = 1;
- *s++ = c;
- continue;
- case 5:
- if (c == '>')
- state = 0;
- else
- state = 1;
- *s++ = c;
- continue;
- /* comment */
- case 6:
- if (c == '-')
- state = 7;
- else
- state = 2;
- *s++ = c;
- continue;
- case 7:
- if (c == '>')
- state = 0;
- else
- state = 2;
- *s++ = c;
- continue;
- /* PI */
- case 8:
- if (c == '>')
- state = 0;
- else
- state = 3;
- *s++ = c;
- continue;
- }
- switch (c)
- {
- case '/':
- if (n > 0)
- { c = soap_get1(soap);
- if (c == '>')
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- c = soap_get1(soap);
- if (c == '/')
- { if (n == 0)
- { c = TT;
- goto end;
- }
- n--;
- }
- else if (c == '!')
- { c = soap_get1(soap);
- if (c == '[')
- { do c = soap_get1(soap);
- while ((int)c != EOF && c != '[');
- if ((int)c == EOF)
- goto end;
- t = (char*)"![CDATA[";
- state = 1;
- }
- else if (c == '-')
- { if ((c = soap_get1(soap)) == '-')
- state = 2;
- t = (char*)"!-";
- soap_unget(soap, c);
- }
- else
- { t = (char*)"!";
- soap_unget(soap, c);
- }
- *s++ = '<';
- break;
- }
- else if (c == '?')
- state = 3;
- else
- n++;
- soap_unget(soap, c);
- *s++ = '<';
- break;
- case '>':
- *s++ = '>';
- break;
- case '"':
- *s++ = '"';
- break;
- default:
- *s++ = (char)(c & 0xFF);
- }
- }
- }
- }
-#endif
- for (;;)
- { if (!(s = (char*)soap_push_block(soap, SOAP_BLKLEN)))
- return NULL;
- for (i = 0; i < SOAP_BLKLEN; i++)
- { if (t)
- { *s++ = *t++;
- if (!*t)
- t = NULL;
- continue;
- }
- if (soap->mode & SOAP_C_UTFSTRING)
- { if (((c = soap_get(soap)) & 0x80000000) && c >= -0x7FFFFF80 && c < AP)
- { c &= 0x7FFFFFFF;
- t = buf;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- *t = '\0';
- t = buf;
- *s++ = *t++;
- continue;
- }
- }
- else if (soap->mode & SOAP_C_LATIN)
- c = soap_get(soap);
- else
- c = soap_getutf8(soap);
- switch (c)
- {
- case TT:
- if (n == 0)
- goto end;
- n--;
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case LT:
- n++;
- *s++ = '<';
- break;
- case GT:
- *s++ = '>';
- break;
- case QT:
- *s++ = '"';
- break;
- case AP:
- *s++ = '\'';
- break;
- case '/':
- if (n > 0)
- { c = soap_get(soap);
- if (c == GT)
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- if (flag)
- *s++ = '<';
- else
- { *s++ = '&';
- t = (char*)"lt;";
- }
- break;
- case '>':
- if (flag)
- *s++ = '>';
- else
- { *s++ = '&';
- t = (char*)"gt;";
- }
- break;
- case '"':
- if (flag)
- *s++ = '"';
- else
- { *s++ = '&';
- t = (char*)"quot;";
- }
- break;
- default:
- if ((int)c == EOF)
- goto end;
- *s++ = (char)(c & 0xFF);
- }
- }
- }
-end:
- soap_unget(soap, c);
- *s = '\0';
- soap_size_block(soap, i+1);
- t = soap_save_block(soap, NULL);
- if (flag == 2)
- if (soap_s2QName(soap, t, &t))
- return NULL;
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_wstring_out(struct soap *soap, const wchar_t *s, int flag)
-{ const char *t;
- char tmp;
- register wchar c;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->wide = NULL; /* soap_malloc() ??? */
- return SOAP_OK;
- }
-#endif
- while ((c = *s++))
- { switch (c)
- {
- case 9:
- if (flag)
- t = "	";
- else
- t = "\t";
- break;
- case 10:
- if (flag || !(soap->mode & SOAP_XML_CANONICAL))
- t = "
";
- else
- t = "\n";
- break;
- case 13:
- t = "
";
- break;
- case '&':
- t = "&";
- break;
- case '<':
- t = "<";
- break;
- case '>':
- if (flag)
- t = ">";
- else
- t = ">";
- break;
- case '"':
- if (flag)
- t = """;
- else
- t = "\"";
- break;
- default:
- if (c > 0 && c < 0x80)
- { tmp = (char)c;
- if (soap_send_raw(soap, &tmp, 1))
- return soap->error;
- }
- else if (soap_pututf8(soap, (unsigned long)c))
- return soap->error;
- continue;
- }
- if (soap_send(soap, t))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t *
-SOAP_FMAC2
-soap_wstring_in(struct soap *soap, int flag)
-{ wchar_t *s;
- register int i, n = 0;
- register wchar c;
- const char *t = NULL;
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { if (!(s = (wchar_t*)soap_push_block(soap, sizeof(wchar_t)*SOAP_BLKLEN)))
- return NULL;
- for (i = 0; i < SOAP_BLKLEN; i++)
- { if (t)
- { *s++ = (wchar_t)*t++;
- if (!*t)
- t = NULL;
- continue;
- }
- if (soap->mode & SOAP_C_LATIN)
- c = soap_get(soap);
- else
- c = soap_getutf8(soap);
- switch (c)
- {
- case TT:
- if (n == 0)
- goto end;
- n--;
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case LT:
- n++;
- *s++ = '<';
- break;
- case GT:
- *s++ = '>';
- break;
- case QT:
- *s++ = '"';
- break;
- case AP:
- *s++ = '\'';
- break;
- case '/':
- if (n > 0)
- { c = soap_getutf8(soap);
- if (c == GT)
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- if (flag)
- *s++ = (wchar)'<';
- else
- { *s++ = (wchar)'&';
- t = "lt;";
- }
- break;
- case '>':
- if (flag)
- *s++ = (wchar)'>';
- else
- { *s++ = (wchar)'&';
- t = "gt;";
- }
- break;
- case '"':
- if (flag)
- *s++ = (wchar)'"';
- else
- { *s++ = (wchar)'&';
- t = "quot;";
- }
- break;
- default:
- if ((int)c == EOF)
- goto end;
- *s++ = (wchar_t)c & 0x7FFFFFFF;
- }
- }
- }
-end:
- soap_unget(soap, c);
- *s = '\0';
- soap_size_block(soap, sizeof(wchar_t) * (i + 1));
- return (wchar_t*)soap_save_block(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_int2s(struct soap *soap, int n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outint(struct soap *soap, const char *tag, int id, const int *p, const char *type, int n)
-{ long m = (long)*p;
- return soap_outlong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2int(struct soap *soap, const char *s, int *p)
-{ if (s)
- { char *r;
- *p = (int)soap_strtol(s, &r, 10);
- if (*r)
- return soap->error = SOAP_TYPE;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int *
-SOAP_FMAC2
-soap_inint(struct soap *soap, const char *tag, int *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (int*)soap_id_enter(soap, soap->id, p, t, sizeof(int), 0);
- if (!p || soap_s2int(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (int*)soap_id_forward(soap, soap->href, p, t, sizeof(int));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_long2s(struct soap *soap, long n)
-{ sprintf(soap->tmpbuf, "%ld", n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outlong(struct soap *soap, const char *tag, int id, const long *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2long(struct soap *soap, const char *s, long *p)
-{ if (s)
- { char *r;
- *p = soap_strtol(s, &r, 10);
- if (*r)
- return soap->error = SOAP_TYPE;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-long *
-SOAP_FMAC2
-soap_inlong(struct soap *soap, const char *tag, long *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (long*)soap_id_enter(soap, soap->id, p, t, sizeof(long), 0);
- if (!p || soap_s2long(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (long*)soap_id_forward(soap, soap->href, p, t, sizeof(long));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_LONG642s(struct soap *soap, LONG64 n)
-{ sprintf(soap->tmpbuf, SOAP_LONG_FORMAT, n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outLONG64(struct soap *soap, const char *tag, int id, const LONG64 *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_LONG642s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2LONG64(struct soap *soap, const char *s, LONG64 *p)
-{ if (s && sscanf(s, SOAP_LONG_FORMAT, p) != 1)
- return soap->error = SOAP_TYPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-LONG64 *
-SOAP_FMAC2
-soap_inLONG64(struct soap *soap, const char *tag, LONG64 *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":integer")
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":negativeInteger")
- && soap_match_tag(soap, soap->type, ":nonPositiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":long")
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (LONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(LONG64), 0);
- if (!p || soap_s2LONG64(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (LONG64*)soap_id_forward(soap, soap->href, p, t, sizeof(LONG64));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_byte2s(struct soap *soap, char n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outbyte(struct soap *soap, const char *tag, int id, const char *p, const char *type, int n)
-{ long m = (long)*p;
- return soap_outlong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2byte(struct soap *soap, const char *s, char *p)
-{ if (s)
- { long n;
- char *r;
- n = soap_strtol(s, &r, 10);
- if (*r || n < -128 || n > 127)
- return soap->error = SOAP_TYPE;
- *p = (char)n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_inbyte(struct soap *soap, const char *tag, char *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (char*)soap_id_enter(soap, soap->id, p, t, sizeof(char), 0);
- if (!p || soap_s2byte(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (char*)soap_id_forward(soap, soap->href, p, t, sizeof(char));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_short2s(struct soap *soap, short n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outshort(struct soap *soap, const char *tag, int id, const short *p, const char *type, int n)
-{ long m = (long)*p;
- return soap_outlong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2short(struct soap *soap, const char *s, short *p)
-{ if (s)
- { long n;
- char *r;
- n = soap_strtol(s, &r, 10);
- if (*r || n < -32768 || n > 32767)
- return soap->error = SOAP_TYPE;
- *p = (char)n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-short *
-SOAP_FMAC2
-soap_inshort(struct soap *soap, const char *tag, short *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (short*)soap_id_enter(soap, soap->id, p, t, sizeof(short), 0);
- if (!p || soap_s2short(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (short*)soap_id_forward(soap, soap->href, p, t, sizeof(short));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_float2s(struct soap *soap, float n)
-{ const char *s;
- if (isnan(n))
- s = "NaN";
- else if (n >= FLT_PINFTY)
- s = "INF";
- else if (n <= FLT_NINFTY)
- s = "-INF";
- else
- { sprintf(soap->tmpbuf, soap->float_format, n);
- s = soap->tmpbuf;
- }
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outfloat(struct soap *soap, const char *tag, int id, const float *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_float2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2float(struct soap *soap, const char *s, float *p)
-{ if (s)
- { if (!soap_tag_cmp(s, "INF"))
- *p = FLT_PINFTY;
- else if (!soap_tag_cmp(s, "+INF"))
- *p = FLT_PINFTY;
- else if (!soap_tag_cmp(s, "-INF"))
- *p = FLT_NINFTY;
- else if (!soap_tag_cmp(s, "NaN"))
- *p = FLT_NAN;
- else
- {
-#ifdef HAVE_STRTOD
- char *r;
- *p = (float)strtod(s, &r);
- if (*r)
-#endif
- if (sscanf(s, soap->float_format, p) != 1)
- return soap->error = SOAP_TYPE;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static int soap_isnumeric(struct soap *soap, const char *type)
-{ if (soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":float")
- && soap_match_tag(soap, soap->type, ":double")
- && soap_match_tag(soap, soap->type, ":decimal")
- && soap_match_tag(soap, soap->type, ":integer")
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":negativeInteger")
- && soap_match_tag(soap, soap->type, ":nonPositiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":long")
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte")
- && soap_match_tag(soap, soap->type, ":unsignedLong")
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return SOAP_ERR;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-float *
-SOAP_FMAC2
-soap_infloat(struct soap *soap, const char *tag, float *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type != '\0' && soap_isnumeric(soap, type))
- return NULL;
- if (soap->body && !*soap->href)
- { p = (float*)soap_id_enter(soap, soap->id, p, t, sizeof(float), 0);
- if (!p || soap_s2float(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (float*)soap_id_forward(soap, soap->href, p, t, sizeof(float));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_double2s(struct soap *soap, double n)
-{ const char *s;
- if (isnan(n))
- s = "NaN";
- else if (n >= DBL_PINFTY)
- s = "INF";
- else if (n <= DBL_NINFTY)
- s = "-INF";
- else
- { sprintf(soap->tmpbuf, soap->double_format, n);
- s = soap->tmpbuf;
- }
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outdouble(struct soap *soap, const char *tag, int id, const double *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_double2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2double(struct soap *soap, const char *s, double *p)
-{ if (s)
- { if (!soap_tag_cmp(s, "INF"))
- *p = DBL_PINFTY;
- else if (!soap_tag_cmp(s, "+INF"))
- *p = DBL_PINFTY;
- else if (!soap_tag_cmp(s, "-INF"))
- *p = DBL_NINFTY;
- else if (!soap_tag_cmp(s, "NaN"))
- *p = DBL_NAN;
- else
- {
-#ifdef HAVE_STRTOD
- char *r;
- *p = strtod(s, &r);
- if (*r)
-#endif
- if (sscanf(s, soap->double_format, p) != 1)
- return soap->error = SOAP_TYPE;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-double *
-SOAP_FMAC2
-soap_indouble(struct soap *soap, const char *tag, double *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type != '\0' && soap_isnumeric(soap, type))
- return NULL;
- if (soap->body && !*soap->href)
- { p = (double*)soap_id_enter(soap, soap->id, p, t, sizeof(double), 0);
- if (!p || soap_s2double(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (double*)soap_id_forward(soap, soap->href, p, t, sizeof(double));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedByte2s(struct soap *soap, unsigned char n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedByte(struct soap *soap, const char *tag, int id, const unsigned char *p, const char *type, int n)
-{ unsigned long m = (unsigned long)*p;
- return soap_outunsignedLong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedByte(struct soap *soap, const char *s, unsigned char *p)
-{ if (s)
- { unsigned long n;
- char *r;
- n = soap_strtoul(s, &r, 10);
- if (*r || n > 255)
- return soap->error = SOAP_TYPE;
- *p = (unsigned char)n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned char *
-SOAP_FMAC2
-soap_inunsignedByte(struct soap *soap, const char *tag, unsigned char *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (unsigned char*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned char), 0);
- if (!p || soap_s2unsignedByte(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (unsigned char*)soap_id_forward(soap, soap->href, p, t, sizeof(unsigned char));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedShort2s(struct soap *soap, unsigned short n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedShort(struct soap *soap, const char *tag, int id, const unsigned short *p, const char *type, int n)
-{ unsigned long m = (unsigned long)*p;
- return soap_outunsignedLong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedShort(struct soap *soap, const char *s, unsigned short *p)
-{ if (s)
- { unsigned long n;
- char *r;
- n = soap_strtoul(s, &r, 10);
- if (*r || n > 65535)
- return soap->error = SOAP_TYPE;
- *p = (unsigned short)n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-unsigned short *
-SOAP_FMAC2
-soap_inunsignedShort(struct soap *soap, const char *tag, unsigned short *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (unsigned short*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned short), 0);
- if (!p || soap_s2unsignedShort(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (unsigned short*)soap_id_forward(soap, soap->href, p, t, sizeof(unsigned short));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedInt2s(struct soap *soap, unsigned int n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedInt(struct soap *soap, const char *tag, int id, const unsigned int *p, const char *type, int n)
-{ unsigned long m = (unsigned long)*p;
- return soap_outunsignedLong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedInt(struct soap *soap, const char *s, unsigned int *p)
-{ if (s)
- { char *r;
- *p = (unsigned int)soap_strtoul(s, &r, 10);
- if (*r)
- return soap->error = SOAP_TYPE;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned int *
-SOAP_FMAC2
-soap_inunsignedInt(struct soap *soap, const char *tag, unsigned int *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (unsigned int*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned int), 0);
- if (!p || soap_s2unsignedInt(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (unsigned int*)soap_id_forward(soap, soap->href, p, t, sizeof(unsigned int));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedLong2s(struct soap *soap, unsigned long n)
-{ sprintf(soap->tmpbuf, "%lu", n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedLong(struct soap *soap, const char *tag, int id, const unsigned long *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedLong(struct soap *soap, const char *s, unsigned long *p)
-{ if (s)
- { char *r;
- *p = soap_strtoul(s, &r, 10);
- if (*r)
- return soap->error = SOAP_TYPE;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned long *
-SOAP_FMAC2
-soap_inunsignedLong(struct soap *soap, const char *tag, unsigned long *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (unsigned long*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned long), 0);
- if (!p || soap_s2unsignedLong(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (unsigned long*)soap_id_forward(soap, soap->href, p, t, sizeof(unsigned long));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_ULONG642s(struct soap *soap, ULONG64 n)
-{ sprintf(soap->tmpbuf, SOAP_ULONG_FORMAT, n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outULONG64(struct soap *soap, const char *tag, int id, const ULONG64 *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_ULONG642s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2ULONG64(struct soap *soap, const char *s, ULONG64 *p)
-{ if (s && sscanf(s, SOAP_ULONG_FORMAT, p) != 1)
- return soap->error = SOAP_TYPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-ULONG64 *
-SOAP_FMAC2
-soap_inULONG64(struct soap *soap, const char *tag, ULONG64 *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":unsignedLong")
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (ULONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(ULONG64), 0);
- if (!p || soap_s2ULONG64(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (ULONG64*)soap_id_forward(soap, soap->href, p, t, sizeof(ULONG64));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2string(struct soap *soap, const char *s, char **t)
-{ *t = NULL;
- if (s && !(*t = soap_strdup(soap, s)))
- return soap->error = SOAP_EOM;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2QName(struct soap *soap, const char *s, char **t)
-{ if (s)
- { struct soap_nlist *np = soap->nlist;
- const char *p = strchr(s, ':');
- if (p)
- { int n = p - s;
- while (np && (np->index == -2 || strncmp(np->id, s, n) || np->id[n]))
- np = np->next;
- p++;
- }
- else
- { while (np && *np->id)
- np = np->next;
- p = s;
- }
- if (np)
- { if (np->index >= 0 && soap->local_namespaces)
- { const char *q = soap->local_namespaces[np->index].id;
- if (q)
- { if ((*t = (char*)soap_malloc(soap, strlen(p) + strlen(q) + 2)))
- sprintf(*t, "%s:%s", q, p);
- return SOAP_OK;
- }
- }
- if (np->ns)
- { if ((*t = (char*)soap_malloc(soap, strlen(p) + strlen(np->ns) + 4)))
- sprintf(*t, "\"%s\":%s", np->ns, p);
- return SOAP_OK;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Namespace prefix of '%s' not defined (index=%d, URI=%s)\n", s, np->index, np->ns?np->ns:""));
- return soap->error = SOAP_NAMESPACE;
- }
- if (soap->mode & SOAP_XML_STRICT)
- return soap->error = SOAP_NAMESPACE;
- *t = soap_strdup(soap, s);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_QName2s(struct soap *soap, const char *s)
-{ struct Namespace *p;
- char *t;
- int i;
- if (!s || *s != '"')
- return s;
- s++;
- if ((p = soap->local_namespaces))
- { for (i = 0; p->id; p++, i++)
- { if (p->ns)
- if (!soap_tag_cmp(s, p->ns))
- break;
- if (p->in)
- if (!soap_tag_cmp(s, p->in))
- break;
- }
- if (p && p->id)
- { s = strchr(s, '"');
- if (s)
- { t = (char*)soap_malloc(soap, strlen(p->id) + strlen(s));
- strcpy(t, p->id);
- strcat(t, s + 1);
- return t;
- }
- }
- }
- t = (char*)strchr(s, '"');
- if (t)
- i = t - s;
- else
- i = 0;
- t = soap_strdup(soap, s);
- t[i] = '\0';
- sprintf(soap->tmpbuf, "xmlns:_%lu", soap->idnum++);
- soap_set_attr(soap, soap->tmpbuf, t);
- s = strchr(s, '"');
- if (s)
- { t = (char*)soap_malloc(soap, strlen(soap->tmpbuf) + strlen(s) - 6);
- strcpy(t, soap->tmpbuf + 6);
- strcat(t, s + 1);
- }
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outstring(struct soap *soap, const char *tag, int id, char *const*p, const char *type, int n)
-{ if (!*p)
- { if (soap_element_null(soap, tag, id, type))
- return soap->error;
- }
- else
- { struct soap_plist *pp;
- int i = soap_pointer_lookup(soap, *p, n, &pp);
- if (id > 0)
- { if (i)
- { if (soap_element_begin_out(soap, tag, id, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- soap_set_embedded(soap, pp);
- }
- else
- { i = soap_pointer_enter(soap, *p, n, &pp);
- if (soap_element_begin_out(soap, tag, id, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 0;
- else
- pp->mark2 = 0;
- }
- }
- else if (i)
- { if (soap_is_embedded(soap, pp))
- { if (soap_element_ref(soap, tag, 0, i))
- return soap->error;
- }
- else if (soap_is_single(soap, pp))
- { if (soap_element_begin_out(soap, tag, 0, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- }
- else
- { if (soap_element_begin_out(soap, tag, i, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- soap_set_embedded(soap, pp);
- }
- }
- else
- { soap_pointer_enter(soap, *p, n, &pp);
- if (soap_element_begin_out(soap, tag, id, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 0;
- else
- pp->mark2 = 0;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char **
-SOAP_FMAC2
-soap_instring(struct soap *soap, const char *tag, char **p, const char *type, int t, int flag)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { p = (char**)soap_id_enter(soap, soap->id, p, t, sizeof(char**), 0);
- if (p)
- *p = NULL;
- }
- else if (soap->body && !*soap->href)
- { if (soap_match_tag(soap, soap->type, "PointerTostring") == 0)
- { p = (char**)soap_id_enter(soap, soap->id, p, t, sizeof(char**), 0);
- p = (char**)soap_instring(soap, "string", p, type, t, flag);
- }
- else
- { if (!p)
- if ((p = (char**)soap_id_enter(soap, SOAP_STR_EOS, p, t, sizeof(char**), 0)) == NULL)
- return NULL;
- *p = (char*)soap_id_enter(soap, soap->id, soap_string_in(soap, flag), t, 0, 0);
- }
- }
- else
- p = (char**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(char*), 0);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outwstring(struct soap *soap, const char *tag, int id, wchar_t *const*p, const char *type, int n)
-{ if (!*p)
- { if (soap_element_null(soap, tag, id, type))
- return soap->error;
- }
- else
- { struct soap_plist *pp;
- int i = soap_pointer_lookup(soap, *p, n, &pp);
- if (id > 0)
- { if (i)
- { if (soap_element_begin_out(soap, tag, id, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- soap_set_embedded(soap, pp);
- }
- else
- { i = soap_pointer_enter(soap, *p, n, &pp);
- if (soap_element_begin_out(soap, tag, id, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 0;
- else
- pp->mark2 = 0;
- }
- }
- else if (i)
- { if (soap_is_embedded(soap, pp))
- { if (soap_element_ref(soap, tag, 0, i))
- return soap->error;
- }
- else if (soap_is_single(soap, pp))
- { if (soap_element_begin_out(soap, tag, 0, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- }
- else
- { if (soap_element_begin_out(soap, tag, i, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- soap_set_embedded(soap, pp);
- }
- }
- else
- { if (soap_element_begin_out(soap, tag, id, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 0;
- else
- pp->mark2 = 0;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t **
-SOAP_FMAC2
-soap_inwstring(struct soap *soap, const char *tag, wchar_t **p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { p = (wchar_t**)soap_id_enter(soap, soap->id, p, t, sizeof(wchar_t**), 0);
- if (p)
- *p = NULL;
- }
- else if (soap->body && !*soap->href)
- { if (soap_match_tag(soap, soap->type, "PointerTostring") == 0)
- p = (wchar_t**)soap_inwstring(soap, "string", (wchar_t**)soap_id_enter(soap, soap->id, p, t, sizeof(wchar_t**), 0), type, t);
- else
- { if (!p)
- if (!(p = (wchar_t**)soap_id_enter(soap, SOAP_STR_EOS, p, t, sizeof(wchar_t**), 0)))
- return NULL;
- *p = (wchar_t*)soap_id_enter(soap, soap->id, soap_wstring_in(soap, 1), t, 0, 0);
- }
- }
- else
- p = (wchar_t**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(wchar_t*), 0);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static time_t
-soap_timegm(struct tm *T)
-{
-#if defined(HAVE_TIMEGM)
- return timegm(T);
-#elif defined(HAVE_GETTIMEOFDAY)
- struct timezone t;
- gettimeofday(NULL, &t); /* doesn't work properly on Solaris */
- T->tm_min -= t.tz_minuteswest;
- T->tm_isdst = (t.tz_dsttime != 0);
- return mktime(T);
-/* WR[ */
- /* The following define was added for VxWorks*/
-#elif defined(HAVE_MKTIME)
- /* FOR VXWORKS:
- vxWorks does not seem to have any variable representation of time zones, but
- timezone information can be set in INSTALL_DIR/target/h/private/timeP.h header
- file, by setting the ZONEBUFFER define. The ZONEBUFFER define follows this
- format:
-
- name_of_zone:<(unused)>:time_in_minutes_from_UTC:daylight_start:daylight_end
-
- To calculate local time, the value of time_in_minutes_from_UTC is subtracted
- from UTC; time_in_minutes_from_UTC must be positive. Daylight information is
- expressed as mmddhh (month-day-hour), for example:
-
- UTC::0:040102:100102
-
- */
- return mktime(T);
-/* ]WR */
-#elif defined(HAVE_FTIME)
- struct timeb t;
- t.timezone = 0;
- t.dstflag = -1;
- ftime(&t);
- T->tm_min -= t.timezone;
- T->tm_isdst = t.dstflag; /* doesn't work properly on Solaris */
- return mktime(T);
-#else
-#warning "time_t (de)serialization is not MT safe on this platform"
- time_t t;
- char *tz = getenv("TZ");
- putenv("TZ=UTC");
- tzset();
- t = mktime(T);
- if (tz)
- { char tmp[16];
- strcpy(tmp, "TZ=");
- strncat(tmp, tz, 12);
- tmp[15] = '\0';
- putenv(tmp);
- }
- else
- putenv("TZ=");
- tzset();
- return t;
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_dateTime2s(struct soap *soap, time_t n)
-{ struct tm T;
- struct tm *pT = &T;
-#if defined(HAVE_GMTIME_R)
- if (gmtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PGMTIME_R)
- if (gmtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-#elif defined(HAVE_PGMTIME)
- if (gmtime(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-/* ]WR */
-#elif defined(HAVE_GMTIME)
- if ((pT = gmtime(&n)))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-#elif defined(HAVE_GETTIMEOFDAY)
- struct timezone t;
-#if defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- { gettimeofday(NULL, &t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.tz_minuteswest/60-(t.tz_dsttime!=0), abs(t.tz_minuteswest)%60);
- }
-#else
- if ((pT = localtime(&n)))
- { gettimeofday(NULL, &t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.tz_minuteswest/60-(t.tz_dsttime!=0), abs(t.tz_minuteswest)%60);
- }
-#endif
-#elif defined(HAVE_FTIME)
- struct timeb t;
-#if defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- { ftime(&t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60-(t.dstflag!=0), abs(t.timezone)%60);
- }
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PLOCALTIME_R)
- if (localtime_r(&n, pT))
- { strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf+strlen(soap->tmpbuf), "%+03d:%02d", t.timezone/60, abs(t.timezone)%60);
- }
-/* ]WR */
-#else
- if ((pT = localtime(&n)))
- { ftime(&t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60-(t.dstflag!=0), abs(t.timezone)%60);
- }
-#endif
-#elif defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PLOCALTIME_R)
- if (localtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-/* ]WR */
-#else
- if ((pT = localtime(&n)))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-#endif
- else
- strcpy(soap->tmpbuf, "1969-12-31T23:59:59Z");
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outdateTime(struct soap *soap, const char *tag, int id, const time_t *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_dateTime2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2dateTime(struct soap *soap, const char *s, time_t *p)
-{ if (s)
- { struct tm T;
- char zone[16];
- memset(&T, 0, sizeof(struct tm));
- zone[sizeof(zone)-1] = '\0';
- sscanf(s, "%d-%d-%dT%d:%d:%d%15s", &T.tm_year, &T.tm_mon, &T.tm_mday, &T.tm_hour, &T.tm_min, &T.tm_sec, zone);
- if (T.tm_year == 1)
- T.tm_year = 70;
- else
- T.tm_year -= 1900;
- T.tm_mon--;
- if (*zone)
- { if (*zone == '.')
- { for (s = zone + 1; *s; s++)
- if (*s < '0' || *s > '9')
- break;
- }
- else
- s = zone;
- if (*s != 'Z')
- { int h = 0, m = 0;
- sscanf(s, "%d:%d", &h, &m);
- T.tm_hour -= h;
- if (h >= 0)
- T.tm_min -= m;
- else
- T.tm_min += m;
- }
- *p = soap_timegm(&T);
- }
- else
- *p = mktime(&T); /* no time zone: suppose it is localtime? */
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-time_t *
-SOAP_FMAC2
-soap_indateTime(struct soap *soap, const char *tag, time_t *p, const char * type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":dateTime"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- if (soap->body && !*soap->href)
- { p = (time_t*)soap_id_enter(soap, soap->id, p, t, sizeof(time_t), 0);
- if (!p || soap_s2dateTime(soap, soap_value(soap), p))
- return NULL;
- }
- else
- p = (time_t*)soap_id_forward(soap, soap->href, p, t, sizeof(time_t));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outliteral(struct soap *soap, const char *tag, char *const*p)
-{ int i;
- const char *t = NULL;
- if (tag && *tag != '-')
- { if ((t = strchr(tag, ':')))
- { strncpy(soap->tmpbuf, tag, t-tag);
- soap->tmpbuf[t-tag] = '\0';
- for (i = 0; soap->local_namespaces[i].id; i++)
- if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
- break;
- t++;
- sprintf(soap->tmpbuf, "<%s xmlns=\"%s\">", t, soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS);
- }
- else
- { t = tag;
- sprintf(soap->tmpbuf, "<%s>", tag);
- }
- if (soap_send(soap, soap->tmpbuf))
- return soap->error;
- }
- if (p && *p)
- { if (soap_send(soap, *p))
- return soap->error;
- }
- if (t)
- { sprintf(soap->tmpbuf, "</%s>", t);
- return soap_send(soap, soap->tmpbuf);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char **
-SOAP_FMAC2
-soap_inliteral(struct soap *soap, const char *tag, char **p)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (!p)
- if (!(p = (char**)soap_malloc(soap, sizeof(char*))))
- return NULL;
- if (soap->null)
- *p = NULL;
- else if (soap->body)
- *p = soap_string_in(soap, 0);
- else
- *p = NULL;
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p)
-{ int i;
- const char *t = NULL;
- wchar_t c;
- const wchar_t *s;
- if (tag && *tag != '-')
- { if (tag && (t = strchr(tag, ':')))
- { strncpy(soap->tmpbuf, tag, t-tag);
- soap->tmpbuf[t-tag] = '\0';
- for (i = 0; soap->local_namespaces[i].id; i++)
- if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
- break;
- t++;
- sprintf(soap->tmpbuf, "<%s xmlns=\"%s\">", t, soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS);
- }
- else
- { t = tag;
- sprintf(soap->tmpbuf, "<%s>", tag);
- }
- if (soap_send(soap, soap->tmpbuf))
- return soap->error;
- }
- if (p)
- { s = *p;
- while ((c = *s++))
- if (soap_pututf8(soap, (unsigned char)c))
- return soap->error;
- }
- if (t)
- { sprintf(soap->tmpbuf, "</%s>", t);
- return soap_send(soap, soap->tmpbuf);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t **
-SOAP_FMAC2
-soap_inwliteral(struct soap *soap, const char *tag, wchar_t **p)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (!p)
- if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*))))
- return NULL;
- if (soap->null)
- *p = NULL;
- else if (soap->body)
- *p = soap_wstring_in(soap, 0);
- else
- *p = NULL;
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_value(struct soap *soap)
-{ size_t i;
- wchar c = 0;
- char *s;
- s = soap->tmpbuf;
- for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++)
- { c = soap_get(soap);
- if (c == TT || (int)c == EOF || soap_blank(c))
- break;
- *s++ = (char)c;
- }
- if ((int)c == EOF || c == TT)
- soap_unget(soap, c);
- *s = '\0';
- return soap->tmpbuf; /* return non-null pointer */
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getline(struct soap *soap, char *s, int len)
-{ int i = len;
- wchar c = 0;
- for (;;)
- { while (--i > 0)
- { c = soap_getchar(soap);
- if (c == '\r' || c == '\n' || (int)c == EOF)
- break;
- *s++ = (char)c;
- }
- *s = '\0';
- while (c != '\n' && (int)c != EOF)
- c = soap_getchar(soap);
- if ((int)c == EOF)
- return SOAP_EOF;
- if (i+1 == len) /* empty line: end of HTTP header */
- break;
- c = soap_unget(soap, soap_getchar(soap));
- if (c != ' ' && c != '\t') /* HTTP line continuation? */
- break;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static size_t
-soap_begin_dime(struct soap *soap)
-{
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- { size_t count;
- sprintf(soap->id, soap->dime_id_format, 0);
- soap->dime_id = soap->id;
- if (soap->local_namespaces)
- { if (soap->local_namespaces[0].out)
- soap->dime_type = (char*)soap->local_namespaces[0].out;
- else
- soap->dime_type = (char*)soap->local_namespaces[0].ns;
- }
- soap->dime_options = NULL;
- count = soap->dime_size + 12 + ((soap->count+3)&(~3)) + ((strlen(soap->dime_id)+3)&(~3)) + ((strlen(soap->dime_type)+3)&(~3));
- soap->dime_size = soap->count;
- if (soap->dime_count)
- soap->dime_flags = SOAP_DIME_MB | SOAP_DIME_ABSURI;
- else
- soap->dime_flags = SOAP_DIME_MB | SOAP_DIME_ME | SOAP_DIME_ABSURI;
- return count;
- }
-#endif
- return soap->count;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static int
-soap_putdimefield(struct soap *soap, const char *s, size_t n)
-{ if (soap_send_raw(soap, s, n))
- return soap->error;
- return soap_send_raw(soap, SOAP_STR_PADDING, -(long)n&3);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_dime_option(struct soap *soap, unsigned short type, const char *option)
-{ size_t n;
- char *s = NULL;
- if (option)
- { n = strlen(option);
- s = (char*)soap_malloc(soap, n + 5);
- if (s)
- { s[0] = type >> 8;
- s[1] = type & 0xFF;
- s[2] = n >> 8;
- s[3] = n & 0xFF;
- strcpy(s + 4, option);
- }
- }
- return s;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putdimehdr(struct soap *soap)
-{ unsigned char tmp[12];
- size_t optlen = 0, idlen = 0, typelen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Put DIME header id='%s'\n", soap->dime_id?soap->dime_id:""));
- if (soap->dime_options)
- optlen = (((unsigned char)soap->dime_options[2] << 8) | ((unsigned char)soap->dime_options[3])) + 4;
- if (soap->dime_id)
- idlen = strlen(soap->dime_id);
- if (soap->dime_type)
- typelen = strlen(soap->dime_type);
- tmp[0] = SOAP_DIME_VERSION | (soap->dime_flags & 0x7);
- tmp[1] = soap->dime_flags & 0xF0;
- tmp[2] = optlen >> 8;
- tmp[3] = optlen & 0xFF;
- tmp[4] = idlen >> 8;
- tmp[5] = idlen & 0xFF;
- tmp[6] = typelen >> 8;
- tmp[7] = typelen & 0xFF;
- tmp[8] = soap->dime_size >> 24;
- tmp[9] = (soap->dime_size >> 16) & 0xFF;
- tmp[10] = (soap->dime_size >> 8) & 0xFF;
- tmp[11] = soap->dime_size & 0xFF;
- if (soap_send_raw(soap, (char*)tmp, 12)
- || soap_putdimefield(soap, soap->dime_options, optlen)
- || soap_putdimefield(soap, soap->dime_id, idlen)
- || soap_putdimefield(soap, soap->dime_type, typelen))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putdime(struct soap *soap, int i, char *id, char *type, char *options, void *ptr, size_t size)
-{ void *h;
- if (id)
- soap->dime_id = id;
- else
- { sprintf(soap->id, soap->dime_id_format, i);
- soap->dime_id = soap->id;
- }
- soap->dime_type = type;
- soap->dime_options = options;
- soap->dime_size = size;
- soap->dime_flags = SOAP_DIME_VERSION | SOAP_DIME_MEDIA;
- if (soap->fdimereadopen && ((h = soap->fdimereadopen(soap, (void*)ptr, soap->dime_id, type, options)) || soap->error))
- { size_t n;
- if (!h)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadopen failed\n"));
- return soap->error;
- }
- if (!size && ((soap->mode & SOAP_ENC_XML) || (soap->mode & SOAP_IO) == SOAP_IO_CHUNK || (soap->mode & SOAP_IO) == SOAP_IO_STORE))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked streaming DIME\n"));
- n = sizeof(soap->tmpbuf);
- do
- { size = soap->fdimeread(soap, h, soap->tmpbuf, n);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread returned %lu bytes\n", (unsigned long)size));
- if (size == n)
- soap->dime_flags |= SOAP_DIME_CF;
- else
- { soap->dime_flags &= ~SOAP_DIME_CF;
- if (--soap->dime_count == 0)
- soap->dime_flags |= SOAP_DIME_ME;
- }
- soap->dime_size = size;
- if (soap_putdimehdr(soap)
- || soap_send_raw(soap, soap->tmpbuf, size)
- || soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime_size&3))
- break;
- if (soap->dime_id)
- { soap->dime_flags &= ~(SOAP_DIME_MB | SOAP_DIME_MEDIA);
- soap->dime_id = NULL;
- soap->dime_type = NULL;
- soap->dime_options = NULL;
- }
- } while (size >= n);
- }
- else
- { if (--soap->dime_count == 0)
- soap->dime_flags |= SOAP_DIME_ME;
- if (soap_putdimehdr(soap))
- return soap->error;
- do
- { if (size < sizeof(soap->tmpbuf))
- n = size;
- else
- n = sizeof(soap->tmpbuf);
- if (!(n = soap->fdimeread(soap, h, soap->tmpbuf, n)))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)soap->dime_size));
- soap->error = SOAP_EOF;
- break;
- }
- if (soap_send_raw(soap, soap->tmpbuf, n))
- break;
- size -= n;
- } while (size);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
- soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime_size&3);
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
- if (soap->fdimereadclose)
- soap->fdimereadclose(soap, h);
- return soap->error;
- }
- if (--soap->dime_count == 0)
- soap->dime_flags |= SOAP_DIME_ME;
- if (soap_putdimehdr(soap))
- return soap->error;
- return soap_putdimefield(soap, (char*)ptr, size);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static char *
-soap_getdimefield(struct soap *soap, size_t n)
-{ register wchar c;
- register int i;
- register char *s;
- char *p = NULL;
- if (n)
- { p = (char*)soap_malloc(soap, n + 1);
- if (p)
- { s = p;
- for (i = n; i > 0; i--)
- { if ((int)(c = soap_get1(soap)) == EOF)
- { soap->error = SOAP_EOF;
- return NULL;
- }
- *s++ = (char)c;
- }
- *s = '\0';
- if ((soap->error = soap_move(soap, -(long)n&3)))
- return NULL;
- }
- else
- soap->error = SOAP_EOM;
- }
- return p;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getdimehdr(struct soap *soap)
-{ register wchar c;
- register char *s;
- register int i;
- unsigned char tmp[12];
- size_t optlen, idlen, typelen;
- if (!(soap->mode & SOAP_ENC_DIME))
- return soap->error = SOAP_EOD;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME header\n"));
- if (soap->dime_buflen || soap->dime_chunksize)
- { if (soap_move(soap, (long)(soap->dime_size - soap_tell(soap))))
- return soap->error = SOAP_EOF;
- soap_unget(soap, soap_getchar(soap)); /* skip padding and get hdr */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... From chunked\n"));
- return SOAP_OK;
- }
- s = (char*)tmp;
- for (i = 12; i > 0; i--)
- { if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- if ((tmp[0] & 0xF8) != SOAP_DIME_VERSION)
- return soap->error = SOAP_DIME_MISMATCH;
- soap->dime_flags = (tmp[0] & 0x7) | (tmp[1] & 0xF0);
- optlen = (tmp[2] << 8) | tmp[3];
- idlen = (tmp[4] << 8) | tmp[5];
- typelen = (tmp[6] << 8) | tmp[7];
- soap->dime_size = (tmp[8] << 24) | (tmp[9] << 16) | (tmp[10] << 8) | tmp[11];
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME size=%u flags=0x%X\n", (unsigned int)soap->dime_size, soap->dime_flags));
- if (!(soap->dime_options = soap_getdimefield(soap, optlen)) && soap->error)
- return soap->error;
- if (!(soap->dime_id = soap_getdimefield(soap, idlen)) && soap->error)
- return soap->error;
- if (!(soap->dime_type = soap_getdimefield(soap, typelen)) && soap->error)
- return soap->error;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME id=%s, type=%s, options=%s\n", soap->dime_id?soap->dime_id:"", soap->dime_type?soap->dime_type:"", soap->dime_options?soap->dime_options+4:""));
- if (soap->dime_flags & SOAP_DIME_ME)
- soap->mode &= ~SOAP_ENC_DIME;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getdime(struct soap *soap)
-{ if (soap_getdimehdr(soap))
- return soap->error;
- if (soap->fdimewriteopen && ((soap->dime_ptr = (char*)soap->fdimewriteopen(soap, soap->dime_id, soap->dime_type, soap->dime_options)) || soap->error))
- { char *id, *type, *options;
- size_t size, n;
- if (!soap->dime_ptr)
- return soap->error;
- id = soap->dime_id;
- type = soap->dime_type;
- options = soap->dime_options;
- for (;;)
- { size = soap->dime_size;
- for (;;)
- { n = soap->buflen - soap->bufidx;
- if (size < n)
- n = size;
- if ((soap->error = soap->fdimewrite(soap, (void*)soap->dime_ptr, soap->buf + soap->bufidx, n)))
- break;
- size -= n;
- if (!size)
- { soap->bufidx += n;
- break;
- }
- if (soap_recv(soap))
- { soap->error = SOAP_EOF;
- goto end;
- }
- }
- if (soap_move(soap, -(long)soap->dime_size&3))
- { soap->error = SOAP_EOF;
- break;
- }
- if (!(soap->dime_flags & SOAP_DIME_CF))
- break;
- if (soap_getdimehdr(soap))
- break;
- }
-end:
- if (soap->fdimewriteclose)
- soap->fdimewriteclose(soap, (void*)soap->dime_ptr);
- soap->dime_size = 0;
- soap->dime_id = id;
- soap->dime_type = type;
- soap->dime_options = options;
- }
- else if (soap->dime_flags & SOAP_DIME_CF)
- { char *id, *type, *options;
- register wchar c;
- register char *s;
- register int i;
- id = soap->dime_id;
- type = soap->dime_type;
- options = soap->dime_options;
- if (soap_new_block(soap))
- return SOAP_EOM;
- for (;;)
- { s = (char*)soap_push_block(soap, soap->dime_size);
- if (!s)
- return soap->error = SOAP_EOM;
- for (i = soap->dime_size; i > 0; i--)
- { if ((int)(c = soap_get1(soap)) == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- if (soap_move(soap, -(long)soap->dime_size&3))
- return soap->error = SOAP_EOF;
- if (!(soap->dime_flags & SOAP_DIME_CF))
- break;
- if (soap_getdimehdr(soap))
- return soap->error;
- }
- soap->dime_size = soap->blist->size++; /* allocate one more for '\0' */
- if (!(soap->dime_ptr = soap_save_block(soap, NULL)))
- return soap->error;
- soap->dime_ptr[soap->dime_size] = '\0'; /* make 0-terminated to enable string-based attachments */
- soap->dime_id = id;
- soap->dime_type = type;
- soap->dime_options = options;
- }
- else
- soap->dime_ptr = soap_getdimefield(soap, soap->dime_size);
- return soap->error;
-}
-#endif
-#endif
-
-/******************************************************************************/
-
-#ifdef WITH_COOKIES
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_encode_cookie(const char *s, char *t, int len)
-{ register int c;
- register int n = len;
- while ((c = *s++) && --n > 0)
- { if (c > ' ' && c < 128 && c != ';' && c != ',')
- *t++ = c;
- else if (n > 2)
- { *t++ = '%';
- *t++ = (c >> 4) + (c > 159 ? '7' : '0');
- c &= 0xF;
- *t++ = c + (c > 9 ? '7' : '0');
- n -= 2;
- }
- else
- break;
- }
- *t = '\0';
- return len - n;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_decode_cookie(char *buf, int len, const char *val)
-{ const char *s;
- char *t;
- for (s = val; *s; s++)
- if (*s != ' ' && *s != '=')
- break;
- if (*s == '"')
- { t = buf;
- s++;
- while (*s && *s != '"' && --len)
- *t++ = *s++;
- *t = '\0';
- do s++;
- while (*s && *s != ';' && *s != '=');
- }
- else
- { t = buf;
- while (*s && *s != ';' && *s != '=' && --len)
- switch (*s)
- { case ' ':
- s++;
- break;
- case '%':
- *t++ = ((s[1] >= 'A' ? (s[1] & 0x7) + 9 : s[1] - '0') << 4)
- + (s[2] >= 'A' ? (s[2] & 0x7) + 9 : s[2] - '0');
- s += 3;
- break;
- default:
- *t++ = *s++;
- }
- *t = '\0';
- }
- return s;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- size_t n;
- if (!domain)
- domain = soap->cookie_domain;
- if (!path)
- path = soap->cookie_path;
- if (*path == '/')
- path++;
- n = strlen(path);
- for (p = soap->cookies; p; p = p->next)
- if (!strcmp(p->name, name)
- && domain
- && p->domain
- && !strcmp(p->domain, domain)
- && !strncmp(p->path, path, n))
- break;
- return p;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_set_cookie(struct soap *soap, const char *name, const char *value, const char *domain, const char *path)
-{ struct soap_cookie **p, *q;
- int n;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie: %s=%s domain=%s path=%s\n", name, value?value:"", domain?domain:"", path?path:""));
- if (!domain)
- domain = soap->cookie_domain;
- if (!path)
- path = soap->cookie_path;
- if (!path)
- { soap_set_receiver_error(soap, "Cookie path not set", NULL, SOAP_HTTP_ERROR);
- return NULL;
- }
- if (*path == '/')
- path++;
- q = soap_cookie(soap, name, domain, path);
- if (!q)
- { if ((q = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- { if ((q->name = (char*)SOAP_MALLOC(strlen(name)+1)))
- strcpy(q->name, name);
- q->value = NULL;
- q->domain = NULL;
- q->path = NULL;
- q->expire = -1;
- q->version = 0;
- q->secure = 0;
- q->env = 0;
- q->modified = 0;
- for (p = &soap->cookies, n = soap->cookie_max; *p && n; p = &(*p)->next, n--)
- if (!strcmp((*p)->name, name) && (*p)->path && strcmp((*p)->path, path) < 0)
- break;
- if (n)
- { q->next = *p;
- *p = q;
- }
- else
- { SOAP_FREE(q->name);
- SOAP_FREE(q);
- q = NULL;
- }
- }
- }
- else
- q->modified = 1;
- if (q)
- { if (q->value)
- { SOAP_FREE(q->value);
- q->value = NULL;
- }
- if (q->domain)
- { SOAP_FREE(q->domain);
- q->domain = NULL;
- }
- if (q->path)
- { SOAP_FREE(q->path);
- q->path = NULL;
- }
- if (value && *value && (q->value = (char*)SOAP_MALLOC(strlen(value)+1)))
- strcpy(q->value, value);
- if (domain && *domain && (q->domain = (char*)SOAP_MALLOC(strlen(domain)+1)))
- strcpy(q->domain, domain);
- if (path && *path && (q->path = (char*)SOAP_MALLOC(strlen(path)+1)))
- strcpy(q->path, path);
- q->session = 1;
- }
- return q;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie **p, *q;
- if (!domain)
- domain = soap->cookie_domain;
- if (!domain)
- { soap_set_receiver_error(soap, "Cookie domain not set", SOAP_STR_EOS, SOAP_HTTP_ERROR);
- return;
- }
- if (!path)
- path = soap->cookie_path;
- if (!path)
- { soap_set_receiver_error(soap, "Cookie path not set", SOAP_STR_EOS, SOAP_HTTP_ERROR);
- return;
- }
- if (*path == '/')
- path++;
- for (p = &soap->cookies, q = *p; q; q = *p)
- if (!strcmp(q->name, name) && !strcmp(q->domain, domain) && !strncmp(q->path, path, strlen(q->path)))
- { if (q->value)
- SOAP_FREE(q->value);
- if (q->domain)
- SOAP_FREE(q->domain);
- if (q->path)
- SOAP_FREE(q->path);
- *p = q->next;
- SOAP_FREE(q);
- }
- else
- p = &q->next;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_cookie_value(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- return p->value;
- return NULL;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_cookie_expire(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- return p->expire;
- return -1;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_cookie_expire(struct soap *soap, const char *name, long expire, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->expire = expire;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->session = 1;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_clr_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->session = 0;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putsetcookies(struct soap *soap)
-{ struct soap_cookie *p;
- char *s, tmp[4096];
- const char *t;
- for (p = soap->cookies; p; p = p->next)
- if (p->modified || !p->env)
- { s = tmp;
- if (p->name)
- s += soap_encode_cookie(p->name, s, tmp-s+4064);
- if (p->value)
- { *s++ = '=';
- s += soap_encode_cookie(p->value, s, tmp-s+4064);
- }
- if (p->domain && (int)strlen(p->domain) < tmp-s+4064)
- sprintf(s, ";Domain=%s", p->domain);
- else if (soap->cookie_domain && (int)strlen(soap->cookie_domain) < tmp-s+4064)
- sprintf(s, ";Domain=%s", soap->cookie_domain);
- strcpy(s, ";Path=/");
- if (p->path)
- t = p->path;
- else
- t = soap->cookie_path;
- if (t)
- { if (*t == '/')
- t++;
- if ((int)strlen(t) < tmp-s+4064)
- strcat(s, t);
- }
- s += strlen(s);
- if (p->version > 0)
- { sprintf(s, ";Version=%u", p->version);
- s += strlen(s);
- }
- if (p->expire >= 0)
- { sprintf(s, ";Max-Age=%ld", p->expire);
- s += strlen(s);
- }
- if (p->secure)
- strcpy(s, ";Secure");
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set-Cookie: %s\n", tmp));
- if (soap->fposthdr(soap, "Set-Cookie", tmp))
- return soap->error;
- }
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putcookies(struct soap *soap, const char *domain, const char *path, int secure)
-{ struct soap_cookie **p, *q;
- unsigned int version = 0;
- time_t now = time(NULL);
- char *s, tmp[4096];
- p = &soap->cookies;
- while ((q = *p))
- { if (q->expire && now > q->expire)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name));
- SOAP_FREE(q->name);
- if (q->value)
- SOAP_FREE(q->value);
- if (q->domain)
- SOAP_FREE(q->domain);
- if (q->path)
- SOAP_FREE(q->path);
- *p = q->next;
- SOAP_FREE(q);
- }
- else if ((!q->domain || !strcmp(q->domain, domain))
- && (!q->path || !strncmp(q->path, path, strlen(q->path)))
- && (!q->secure || secure))
- { s = tmp;
- if (q->version != version)
- { sprintf(s, "$Version=%u;", q->version);
- version = q->version;
- }
- if (q->name)
- s += soap_encode_cookie(q->name, s, tmp-s+4080);
- if (q->value)
- { *s++ = '=';
- s += soap_encode_cookie(q->value, s, tmp-s+4080);
- }
- if (q->path && (int)strlen(q->path) < tmp-s+4080)
- { sprintf(s, ";$Path=/%s", q->path);
- s += strlen(s);
- }
- if (q->domain && (int)strlen(q->domain) < tmp-s+4080)
- sprintf(s, ";$Domain=%s", q->domain);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie: %s\n", tmp));
- if (soap->fposthdr(soap, "Cookie", tmp))
- return soap->error;
- p = &q->next;
- }
- else
- p = &q->next;
- }
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_getcookies(struct soap *soap, const char *val)
-{ struct soap_cookie *p = NULL, *q;
- const char *s;
- char *t, tmp[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
- char *domain = NULL;
- char *path = NULL;
- unsigned int version = 0;
- time_t now = time(NULL);
- if (!val)
- return;
- s = val;
- while (*s)
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (!soap_tag_cmp(tmp, "$Version"))
- { if ((s = soap_decode_cookie(tmp, sizeof(tmp), s)))
- { if (p)
- p->version = (int)atol(tmp);
- else
- version = (int)atol(tmp);
- }
- }
- else if (!soap_tag_cmp(tmp, "$Path"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((t = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(t, tmp);
- }
- else
- t = NULL;
- if (p)
- { if (p->path)
- SOAP_FREE(p->path);
- p->path = t;
- }
- else
- { if (path)
- SOAP_FREE(path);
- path = t;
- }
- }
- else if (!soap_tag_cmp(tmp, "$Domain"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((t = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(t, tmp);
- }
- else
- t = NULL;
- if (p)
- { if (p->domain)
- SOAP_FREE(p->domain);
- p->domain = t;
- }
- else
- { if (domain)
- SOAP_FREE(domain);
- domain = t;
- }
- }
- else if (p && !soap_tag_cmp(tmp, "Path"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (p->path)
- SOAP_FREE(p->path);
- if (*tmp)
- { if ((p->path = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(p->path, tmp);
- }
- else
- p->path = NULL;
- }
- else if (p && !soap_tag_cmp(tmp, "Domain"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (*tmp)
- { if ((p->domain = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(p->domain, tmp);
- }
- else
- p->domain = NULL;
- }
- else if (p && !soap_tag_cmp(tmp, "Version"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- p->version = (unsigned int)atol(tmp);
- }
- else if (p && !soap_tag_cmp(tmp, "Max-Age"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- p->expire = now + atol(tmp);
- }
- else if (p && !soap_tag_cmp(tmp, "Expires"))
- { struct tm T;
- char a[3];
- static const char mns[] = "anebarprayunulugepctovec";
- s = soap_decode_cookie(tmp, sizeof(tmp), s);
- memset(&T, 0, sizeof(struct tm));
- a[0] = tmp[4];
- a[1] = tmp[5];
- a[2] = '\0';
- T.tm_mday = (int)atol(a);
- a[0] = tmp[8];
- a[1] = tmp[9];
- T.tm_mon = (strstr(mns, a) - mns) / 2;
- a[0] = tmp[11];
- a[1] = tmp[12];
- T.tm_year = 100 + (int)atol(a);
- a[0] = tmp[13];
- a[1] = tmp[14];
- T.tm_hour = (int)atol(a);
- a[0] = tmp[16];
- a[1] = tmp[17];
- T.tm_min = (int)atol(a);
- a[0] = tmp[19];
- a[1] = tmp[20];
- T.tm_sec = (int)atol(a);
- p->expire = soap_timegm(&T);
- }
- else if (p && !soap_tag_cmp(tmp, "Secure"))
- p->secure = 1;
- else
- { if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"", p->domain?p->domain:"", p->path?p->path:"", p->expire, p->secure));
- if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
- { q->version = p->version;
- q->expire = p->expire;
- q->secure = p->secure;
- q->env = 1;
- }
- if (p->name)
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
- if ((p = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- { p->name = (char*)SOAP_MALLOC(strlen(tmp)+1);
- strcpy(p->name, tmp);
- s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (*tmp)
- { p->value = (char*)SOAP_MALLOC(strlen(tmp)+1);
- strcpy(p->value, tmp);
- }
- else
- p->value = NULL;
- p->domain = domain;
- p->path = path;
- p->expire = 0;
- p->secure = 0;
- p->version = version;
- }
- }
- if (*s == ';')
- s++;
- }
- if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"", p->domain?p->domain:"", p->path?p->path:"", p->expire, p->secure));
- if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
- { q->version = p->version;
- q->expire = p->expire;
- q->secure = p->secure;
- }
- if (p->name)
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
- if (domain)
- SOAP_FREE(domain);
- if (path)
- SOAP_FREE(path);
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getenv_cookies(struct soap *soap)
-{ struct soap_cookie *p;
- const char *s;
- char key[4096], val[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
- if (!(s = getenv("HTTP_COOKIE")))
- return SOAP_ERR;
- do
- { s = soap_decode_cookie(key, sizeof(key), s);
- s = soap_decode_cookie(val, sizeof(val), s);
- p = soap_set_cookie(soap, key, val, NULL, NULL);
- if (p)
- p->env = 1;
- if (*s == ';')
- s++;
- } while (*s);
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_copy_cookies(struct soap *soap)
-{ struct soap_cookie *p, **q, *r;
- q = &r;
- for (p = soap->cookies; p; p = p->next)
- { if (!(*q = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- return r;
- **q = *p;
- if (p->name)
- { if (((*q)->name = (char*)SOAP_MALLOC(strlen(p->name)+1)))
- strcpy((*q)->name, p->name);
- }
- if (p->value)
- { if (((*q)->value = (char*)SOAP_MALLOC(strlen(p->value)+1)))
- strcpy((*q)->value, p->value);
- }
- if (p->domain)
- { if (((*q)->domain = (char*)SOAP_MALLOC(strlen(p->domain)+1)))
- strcpy((*q)->domain, p->domain);
- }
- if (p->path)
- { if (((*q)->path = (char*)SOAP_MALLOC(strlen(p->path)+1)))
- strcpy((*q)->path, p->path);
- }
- q = &(*q)->next;
- }
- *q = NULL;
- return r;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_free_cookies(struct soap *soap)
-{ struct soap_cookie *p;
- for (p = soap->cookies; p; p = soap->cookies)
- { soap->cookies = p->next;
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
-}
-
-/******************************************************************************/
-#endif /* WITH_COOKIES */
-
-/******************************************************************************/
-#ifdef WITH_GZIP
-#ifndef PALM_2
-static int
-soap_getgzipheader(struct soap *soap)
-{ int i;
- wchar c, f = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get gzip header\n"));
- for (i = 0; i < 9; i++)
- { if ((int)(c = soap_get1(soap) == EOF))
- return soap->error = SOAP_EOF;
- if (i == 2)
- f = c;
- }
- if (f & 0x04) /* FEXTRA */
- { for (i = soap_get1(soap) | (soap_get1(soap) << 8); i; i--)
- if ((int)soap_get1(soap) == EOF)
- return soap->error = SOAP_EOF;
- }
- if (f & 0x08) /* FNAME */
- do
- c = soap_get1(soap);
- while (c && (int)c != EOF);
- if ((int)c != EOF && (f & 0x10)) /* FCOMMENT */
- do
- c = soap_get1(soap);
- while (c && (int)f != EOF);
- if ((int)c != EOF && (f & 0x01)) /* FHCRC */
- { if ((int)(c = soap_get1(soap)) != EOF)
- c = soap_get1(soap);
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_begin_recv(struct soap *soap)
-{ wchar c;
- soap_set_local_namespaces(soap);
- soap_free_iht(soap);
- if ((soap->imode & SOAP_IO) == SOAP_IO_CHUNK)
- soap->omode |= SOAP_IO_CHUNK;
- soap->imode &= ~SOAP_IO;
- soap->mode = soap->imode;
- if (!soap->keep_alive)
- { soap->buflen = 0;
- soap->bufidx = 0;
- }
- if (!(soap->mode & SOAP_IO_KEEPALIVE))
- soap->keep_alive = 0;
- soap->ahead = 0;
- soap->peeked = 0;
- soap->level = 0;
- soap->part = SOAP_BEGIN;
- soap->alloced = 0;
- soap->count = 0;
- soap->length = 0;
- soap->cdata = 0;
- *soap->endpoint = '\0';
- soap->userid = NULL;
- soap->passwd = NULL;
- soap->action = NULL;
- soap->dime_chunksize = 0;
- soap->dime_buflen = 0;
-#ifdef WIN32
-#ifndef UNDER_CE
-#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket))
-#ifdef __BORLANDC__
- setmode((SOAP_SOCKET)soap->recvfd, O_BINARY);
-#else
- _setmode((SOAP_SOCKET)soap->recvfd, _O_BINARY);
-#endif
-#endif
-#endif
-#endif
-#ifdef WITH_ZLIB
- soap->mode &= ~SOAP_ENC_ZLIB;
- soap->zlib_in = SOAP_ZLIB_NONE;
- soap->zlib_out = SOAP_ZLIB_NONE;
- soap->d_stream.next_in = Z_NULL;
- soap->d_stream.avail_in = 0;
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- soap->z_ratio_in = 1.0;
-#endif
- c = soap_getchar(soap);
- if ((c & 0xFFFC) == (SOAP_DIME_VERSION | SOAP_DIME_MB) && (soap_get0(soap) & 0xFFF0) == 0x20)
- soap->mode |= SOAP_ENC_DIME;
-#ifdef WITH_GZIP
- else if (c == 0x1F)
- { if (soap_getgzipheader(soap))
- return soap->error;
- if (inflateInit2(&soap->d_stream, -MAX_WBITS) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- soap->mode |= SOAP_ENC_ZLIB;
- soap->zlib_in = SOAP_ZLIB_GZIP;
- soap->z_crc = crc32(0L, NULL, 0);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- /* should not chunk over plain transport, so why bother to check? */
- /* if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) */
- /* soap->z_buflen = soap->bufidx; */
- /* else */
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = soap->buflen - soap->bufidx;
- soap->z_buflen = soap->buflen;
- soap->buflen = soap->bufidx;
- }
-#endif
- else
- { if (c == 0xEF && !(soap->mode & SOAP_C_LATIN))
- { soap_unget(soap, c);
- c = soap_getutf8(soap);
- if (c == 0xFEFF)
- c = soap_getchar(soap);
- }
- while (soap_blank(c))
- c = soap_getchar(soap);
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- soap_unget(soap, c);
- if (c != '<' && !(soap->mode & (SOAP_ENC_DIME | SOAP_ENC_ZLIB)))
- { soap->mode &= ~SOAP_IO;
- if ((soap->error = soap->fparse(soap)))
- { if (soap->error == 307) /* HTTP redirect */
- { soap_getline(soap, soap->endpoint, sizeof(soap->endpoint));
- soap->keep_alive = 0; /* force close when soap_closesock() */
- }
- return soap->error;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { soap->chunkbuflen = soap->buflen;
- soap->buflen = soap->bufidx;
- soap->chunksize = 0;
- }
-#ifdef WITH_ZLIB
- if (soap->zlib_in)
- { /* fparse should not use soap_unget */
-#ifdef WITH_GZIP
- c = soap_get1(soap);
- if (c == 0x1F)
- { if (soap_getgzipheader(soap))
- return soap->error;
- if (inflateInit2(&soap->d_stream, -MAX_WBITS) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- soap->z_crc = crc32(0L, NULL, 0);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
- }
- else
- { soap_revget1(soap);
-#else
- {
-#endif
- if (inflateInit(&soap->d_stream) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate initialized\n"));
- }
- soap->mode |= SOAP_ENC_ZLIB;
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = soap->buflen - soap->bufidx;
- soap->z_buflen = soap->buflen;
- soap->buflen = soap->bufidx;
- }
-#endif
- }
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- { if (soap_getdimehdr(soap))
- return soap->error;
- if (soap->dime_flags & SOAP_DIME_CF)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked DIME SOAP message\n"));
- soap->dime_chunksize = soap->dime_size;
- if (soap->buflen - soap->bufidx >= soap->dime_chunksize)
- { soap->dime_buflen = soap->buflen;
- soap->buflen = soap->bufidx + soap->dime_chunksize;
- }
- else
- soap->dime_chunksize -= soap->buflen - soap->bufidx;
- }
- soap->count = soap->buflen - soap->bufidx;
- }
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_parse(struct soap *soap)
-{ char header[SOAP_HDRLEN], *s;
- unsigned short g = 0, k;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for response...\n"));
- *soap->endpoint = '\0';
- soap->length = 0;
- do
- { if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
- return SOAP_EOF;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP status: %s\n", soap->msgbuf));
- for (;;)
- { if (soap_getline(soap, header, SOAP_HDRLEN))
- return SOAP_EOF;
- if (!*header)
- break;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP header: %s\n", header));
- s = strchr(header, ':');
- if (s)
- { *s = '\0';
- do s++;
- while (*s && *s <= 32);
- if ((soap->error = soap->fparsehdr(soap, header, s)))
- return soap->error;
- }
- }
- if ((s = strchr(soap->msgbuf, ' ')))
- k = (unsigned short)soap_strtoul(s, NULL, 10);
- else
- k = 0;
- } while (k == 100);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Finished HTTP header parsing\n"));
- s = strstr(soap->msgbuf, "HTTP/");
- if (s && s[7] != '1')
- { if (soap->keep_alive == 1)
- soap->keep_alive = 0;
- if (k == 0 && (soap->omode & SOAP_IO) == SOAP_IO_CHUNK) /* k == 0 for HTTP request */
- { soap->imode |= SOAP_IO_CHUNK;
- soap->omode = (soap->omode & ~SOAP_IO) | SOAP_IO_STORE;
- }
- }
- if (soap->keep_alive < 0)
- soap->keep_alive = 1;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Keep alive connection = %d\n", soap->keep_alive));
- if (s && (((g = !strncmp(soap->msgbuf, "GET ", 4))) || !strncmp(soap->msgbuf, "POST ", 5)))
- { size_t m = strlen(soap->endpoint);
- size_t n = m + (s - soap->msgbuf) - 5 - (!g);
- if (n >= sizeof(soap->endpoint))
- n = sizeof(soap->endpoint) - 1;
- strncpy(soap->path, soap->msgbuf + 4 + (!g), n - m);
- soap->path[n - m] = '\0';
- strcat(soap->endpoint, soap->path);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint));
- if (g)
- { soap->error = soap->fget(soap);
- if (soap->error == SOAP_OK)
- soap->error = SOAP_STOP; /* prevents further processing */
- return soap->error;
- }
- return SOAP_OK;
- }
- if (k == 0 || (k >= 200 && k <= 299) || k == 400 || k == 500)
- return SOAP_OK;
- return soap_set_receiver_error(soap, "HTTP error", soap->msgbuf, k);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_parse_header(struct soap *soap, const char *key, const char *val)
-{ if (!soap_tag_cmp(key, "Host"))
- {
-#ifdef WITH_OPENSSL
- if (soap->imode & SOAP_ENC_SSL)
- strcpy(soap->endpoint, "https://");
- else
-#endif
- strcpy(soap->endpoint, "http://");
- strncat(soap->endpoint, val, sizeof(soap->endpoint) - 8);
- soap->endpoint[sizeof(soap->endpoint) - 1] = '\0';
- }
- else if (!soap_tag_cmp(key, "Content-Type"))
- { if (!soap_tag_cmp(val, "*application/dime*"))
- soap->mode |= SOAP_ENC_DIME;
- }
- else if (!soap_tag_cmp(key, "Content-Length"))
- soap->length = soap_strtoul(val, NULL, 10);
- else if (!soap_tag_cmp(key, "Content-Encoding"))
- { if (!soap_tag_cmp(val, "deflate*"))
-#ifdef WITH_ZLIB
- soap->zlib_in = SOAP_ZLIB_DEFLATE;
-#else
- return SOAP_ZLIB_ERROR;
-#endif
- else if (!soap_tag_cmp(val, "gzip*"))
-#ifdef WITH_GZIP
- soap->zlib_in = SOAP_ZLIB_GZIP;
-#else
- return SOAP_ZLIB_ERROR;
-#endif
- }
-#ifdef WITH_ZLIB
- else if (!soap_tag_cmp(key, "Accept-Encoding"))
- {
-#ifdef WITH_GZIP
- if (strchr(val, '*') || !soap_tag_cmp(val, "*gzip*"))
- soap->zlib_out = SOAP_ZLIB_GZIP;
- else
-#endif
- if (strchr(val, '*') || !soap_tag_cmp(val, "*deflate*"))
- soap->zlib_out = SOAP_ZLIB_DEFLATE;
- else
- soap->zlib_out = SOAP_ZLIB_NONE;
- }
-#endif
- else if (!soap_tag_cmp(key, "Transfer-Encoding"))
- { soap->mode &= ~SOAP_IO;
- if (!soap_tag_cmp(val, "chunked*"))
- soap->mode |= SOAP_IO_CHUNK;
- }
- else if (!soap_tag_cmp(key, "Connection"))
- { if (!soap_tag_cmp(val, "keep-alive*"))
- soap->keep_alive = -soap->keep_alive;
- else if (!soap_tag_cmp(val, "close*"))
- soap->keep_alive = 0;
- }
-#ifndef WITH_LEAN
- else if (!soap_tag_cmp(key, "Authorization"))
- { if (!soap_tag_cmp(val, "basic *"))
- { size_t n;
- char *s;
- soap_base642s(soap, val + 6, soap->tmpbuf, sizeof(soap->tmpbuf) - 1, &n);
- soap->tmpbuf[n] = '\0';
- if ((s = strchr(soap->tmpbuf, ':')))
- { *s = '\0';
- soap->userid = soap_strdup(soap, soap->tmpbuf);
- soap->passwd = soap_strdup(soap, s + 1);
- }
- }
- }
-#endif
- else if (!soap_tag_cmp(key, "SOAPAction"))
- { if (val[0] && val[1])
- { soap->action = soap_strdup(soap, val + 1);
- soap->action[strlen(soap->action) - 1] = '\0';
- }
- }
-/* [ Deal with .NET bug (invalid XML id-ref) */
- else if (!soap_tag_cmp(key, "Server"))
- { if (!soap_tag_cmp(val, "Microsoft-IIS*"))
- soap->dot_net_bug = 1;
- }
- else if (!soap_tag_cmp(key, "User-Agent"))
- { if (!soap_tag_cmp(val, "*.NET CLR*") || !soap_tag_cmp(val, "*MS Web Services Client Protocol*"))
- soap->dot_net_bug = 1;
- }
-/* ] */
-#ifdef WITH_COOKIES
- else if (!soap_tag_cmp(key, "Cookie") || !soap_tag_cmp(key, "Set-Cookie"))
- soap_getcookies(soap, val);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_begin_out(struct soap *soap)
-{ soap->part = SOAP_IN_ENVELOPE;
- return soap_element_begin_out(soap, "SOAP-ENV:Envelope", 0, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_end_out(struct soap *soap)
-{ if (soap_element_end_out(soap, "SOAP-ENV:Envelope"))
- return soap->error;
- soap->part = SOAP_END_ENVELOPE;
-#ifndef WITH_LEANER
- if (!(soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME))
- return soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->count&3);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_begin_in(struct soap *soap)
-{ soap->part = SOAP_IN_ENVELOPE;
- if (soap_element_begin_in(soap, "SOAP-ENV:Envelope"))
- return soap->error = SOAP_VERSIONMISMATCH;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_end_in(struct soap *soap)
-{ if (soap_element_end_in(soap, "SOAP-ENV:Envelope"))
- return soap->error;
- soap->part = SOAP_END_ENVELOPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_begin_out(struct soap *soap)
-{ soap->part = SOAP_IN_BODY;
- if (soap->version == 1)
- soap->encoding = 1;
- if (soap_element(soap, "SOAP-ENV:Body", 0, NULL))
- return soap->error;
- if (soap_attribute(soap, "id", "_0"))
- return soap->error;
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_end_out(struct soap *soap)
-{ if (soap_element_end_out(soap, "SOAP-ENV:Body"))
- return soap->error;
- soap->part = SOAP_IN_BODY;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_begin_in(struct soap *soap)
-{ soap->part = SOAP_IN_BODY;
- return soap_element_begin_in(soap, "SOAP-ENV:Body");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_end_in(struct soap *soap)
-{ if (soap_element_end_in(soap, "SOAP-ENV:Body"))
- return soap->error;
- soap->part = SOAP_END_BODY;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_header(struct soap *soap)
-{ if (soap_getheader(soap) && soap->error == SOAP_TAG_MISMATCH)
- soap->error = SOAP_OK;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_endpoint(struct soap *soap, const char *endpoint)
-{ register const char *s;
- register size_t i, n;
- *soap->endpoint = '\0';
- *soap->host = '\0';
- *soap->path = '\0';
- soap->port = 80;
- if (!endpoint || !*endpoint)
- return;
-#ifdef WITH_OPENSSL
- if (!strncmp(endpoint, "https:", 6))
- soap->port = 443;
-#endif
- strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint) - 1);
- s = strchr(endpoint, ':');
- if (s && s[1] == '/' && s[2] == '/')
- s += 3;
- else
- s = endpoint;
- n = strlen(s);
- if (n >= sizeof(soap->host))
- n = sizeof(soap->host) - 1;
-/* WR[ */
-#ifdef WITH_IPV6
- if ('[' == s[0])
- {
- s++;
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (']' == s[i])
- {
- s++;
- break;
- }
- }
- }
- else
- {
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (s[i] == '/' || s[i] == ':')
- break;
- }
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (s[i] == '/' || s[i] == ':')
- break;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- soap->host[i] = '\0';
- if (s[i] == ':')
- { soap->port = (int)atol(s + i + 1);
- for (i++; i < n; i++)
- if (s[i] == '/')
- break;
- }
- if (s[i])
- { strncpy(soap->path, s + i + 1, sizeof(soap->path));
- soap->path[sizeof(soap->path) - 1] = '\0';
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_connect(struct soap *soap, const char *endpoint, const char *action)
-{ return soap_connect_command(soap, SOAP_POST, endpoint, action);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_connect_command(struct soap *soap, int http_command, const char *endpoint, const char *action)
-{ char host[sizeof(soap->host)];
- int port;
- size_t count;
- strcpy(host, soap->host); /* save to compare */
- port = soap->port; /* save to compare */
- soap_set_endpoint(soap, endpoint);
- if (action)
- soap->action = soap_strdup(soap, action);
- if (soap->fconnect)
- {
- if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port)))
- return soap->error;
- }
- else if (*soap->host)
- { soap->status = http_command;
- if (!soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port)
- { soap->keep_alive = 0; /* force close */
- soap_closesock(soap);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port));
- soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
- if (soap->error)
- return soap->error;
- soap->keep_alive = ((soap->omode & SOAP_IO_KEEPALIVE) != 0);
- }
- else if (!soap->keep_alive || soap_poll(soap))
- { soap->keep_alive = 0; /* force close */
- soap_closesock(soap);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port));
- soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
- if (soap->error)
- return soap->error;
- }
- }
- count = soap_begin_dime(soap);
- if (soap_begin_send(soap))
- return soap->error;
- if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML) && endpoint)
- { unsigned int k = soap->mode;
- soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
- if ((k & SOAP_IO) != SOAP_IO_FLUSH)
- soap->mode |= SOAP_IO_BUFFER;
- if ((soap->error = soap->fpost(soap, endpoint, soap->host, soap->port, soap->path, action, count)))
- return soap->error;
- if ((k & SOAP_IO) == SOAP_IO_CHUNK)
- { if (soap_flush(soap))
- return soap->error;
- }
- soap->mode = k;
- }
- if (http_command != SOAP_POST)
- return soap_end_send(soap);
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- return soap_putdimehdr(soap);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2base64(struct soap *soap, const unsigned char *s, char *t, size_t n)
-{ register size_t i;
- register unsigned long m;
- if (!t)
- return SOAP_EOM;
- t[0] = '\0';
- if (!s)
- return SOAP_OK;
- for (; n > 2; n -= 3, s += 3)
- { m = ((unsigned long)((unsigned char*)s)[0] << 16) | ((unsigned long)((unsigned char*)s)[1] << 8) | (unsigned long)((unsigned char*)s)[2];
- for (i = 4; i > 0; m >>= 6)
- t[--i] = soap_base64o[m & 0x3F];
- t += 4;
- }
- t[0] = '\0';
- if (n > 0)
- { m = 0;
- for (i = 0; i < n; i++)
- m = (m << 8) | *s++;
- for (; i < 3; i++)
- m <<= 8;
- for (i++; i > 0; m >>= 6)
- t[--i] = soap_base64o[m & 0x3F];
- for (i = 3; i > n; i--)
- t[i] = '=';
- t[4] = '\0';
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_base642s(struct soap *soap, const char *s, char *t, size_t l, size_t *n)
-{ register int i, j, c;
- register unsigned long m;
- char *p = t;
- if (n)
- *n = 0;
- for (;;)
- { for (i = 0; i < SOAP_BLKLEN; i++)
- { m = 0;
- j = 0;
- while (j < 4)
- { c = *s++;
- if (c == '=' || !c)
- { i *= 3;
- switch (j)
- { case 2:
- *t++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *t++ = (char)((m >> 10) & 0xFF);
- *t++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n += i;
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- }
- *t++ = (char)((m >> 16) & 0xFF);
- *t++ = (char)((m >> 8) & 0xFF);
- *t++ = (char)(m & 0xFF);
- if (l < 3)
- { if (n)
- *n += i;
- return p;
- }
- l -= 3;
- }
- if (n)
- *n += 3 * SOAP_BLKLEN;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_puthttphdr(struct soap *soap, int status, size_t count)
-{ const char *s;
- if (status == SOAP_FILE)
- s = soap->http_content;
- else if (status == SOAP_HTML)
- s = "text/html; charset=utf-8";
- else if (soap->mode & SOAP_ENC_DIME)
- s = "application/dime";
- else if (soap->version == 2)
- s = "application/soap+xml; charset=utf-8";
- else
- s = "text/xml; charset=utf-8";
- soap->error = soap->fposthdr(soap, "Content-Type", s);
- if (soap->error)
- return soap->error;
-#ifdef WITH_ZLIB
- if (soap->omode & SOAP_ENC_ZLIB)
-#ifdef WITH_GZIP
- soap->error = soap->fposthdr(soap, "Content-Encoding", "gzip");
-#else
- soap->error = soap->fposthdr(soap, "Content-Encoding", "deflate");
-#endif
-#endif
- if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)
- soap->error = soap->fposthdr(soap, "Transfer-Encoding", "chunked");
- else if (count > 0)
- { sprintf(soap->tmpbuf, "%lu", (unsigned long)count);
- soap->error = soap->fposthdr(soap, "Content-Length", soap->tmpbuf);
- }
- if (soap->error)
- return soap->error;
- return soap->error = soap->fposthdr(soap, "Connection", soap->keep_alive ? "keep-alive" : "close");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_get(struct soap *soap)
-{ return SOAP_GET_METHOD;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_post(struct soap *soap, const char *endpoint, const char *host, int port, const char *path, const char *action, size_t count)
-{ const char *s;
- if (soap->status == SOAP_GET)
- { s = "GET";
- count = 0;
- }
- else
- s = "POST";
-#ifndef PALM
- if (!endpoint || (strncmp(endpoint, "http:", 5) && strncmp(endpoint, "https:", 6) && strncmp(endpoint, "httpg:", 6)))
-#else
- if (!endpoint || (strncmp(endpoint, "http:", 5) && strncmp(endpoint, "https:", 6) && strncmp(endpoint, "httpg:", 6)) && strncmp(endpoint, "_beam:", 6) && strncmp(endpoint, "_local:", 7) && strncmp(endpoint, "_btobex:", 8))
-#endif
- return SOAP_OK;
- if (soap->proxy_host)
- sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version);
- else
- sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, path, soap->http_version);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return soap->error;
- if (port != 80)
- sprintf(soap->tmpbuf, "%s:%d", host, port);
- else
- strcpy(soap->tmpbuf, host);
- if ((soap->error = soap->fposthdr(soap, "Host", soap->tmpbuf))
- || (soap->error = soap->fposthdr(soap, "User-Agent", "gSOAP/2.6"))
- || (soap->error = soap_puthttphdr(soap, SOAP_OK, count)))
- return soap->error;
-#ifdef WITH_ZLIB
-#ifdef WITH_GZIP
- if ((soap->error = soap->fposthdr(soap, "Accept-Encoding", "gzip, deflate")))
-#else
- if ((soap->error = soap->fposthdr(soap, "Accept-Encoding", "deflate")))
-#endif
- return soap->error;
-#endif
-#ifndef WITH_LEAN
- if (soap->userid && soap->passwd && strlen(soap->userid) + strlen(soap->passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->userid, soap->passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((soap->error = soap->fposthdr(soap, "Authorization", soap->tmpbuf)))
- return soap->error;
- }
- if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((soap->error = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
- return soap->error;
- }
-#endif
-#ifdef WITH_COOKIES
-#ifdef WITH_OPENSSL
- if (soap_putcookies(soap, host, path, soap->ssl != NULL))
- return soap->error;
-#else
- if (soap_putcookies(soap, host, path, 0))
- return soap->error;
-#endif
-#endif
- if (action)
- { sprintf(soap->tmpbuf, "\"%s\"", action);
- if ((soap->error = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf)))
- return soap->error;
- }
- return soap->error = soap->fposthdr(soap, NULL, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_post_header(struct soap *soap, const char *key, const char *val)
-{ if (key)
- { if (soap_send(soap, key))
- return soap->error;
- if (val && (soap_send(soap, ": ") || soap_send(soap, val)))
- return soap->error;
- }
- return soap_send(soap, "\r\n");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_response(struct soap *soap, int status, size_t count)
-{
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- {
- httpOutputEnable(soap->rpmreqid);
- }
-#endif /* WMW_RPM_IO */
-/* ]WR */
- if (!status || status == SOAP_HTML || status == SOAP_FILE)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "OK 200\n"));
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
-#else
-/* ]WR */
- if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */
-/* WR[ */
-#endif /* WMW_RPM_IO */
-/* ]WR */
- { sprintf(soap->tmpbuf, "HTTP/%s 200 OK", soap->http_version);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return soap->error;
- }
- else if ((soap->error = soap->fposthdr(soap, "Status", "200 OK")))
- return soap->error;
- }
- else if (status > 200 && status < 600)
- { sprintf(soap->tmpbuf, "HTTP/%s %d %s", soap->http_version, status, http_error(soap, status));
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return soap->error;
- if (status == 401)
- if ((soap->error = soap->fposthdr(soap, "WWW-Authenticate", "Basic realm=\"gSOAP Service\"")))
- return soap->error;
- }
- else
- { const char *s = *soap_faultcode(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error\n"));
- if (soap->version == 2 && !strcmp(s, "SOAP-ENV:Sender"))
- s = "400 Bad Request";
- else
- s = "500 Internal Server Error";
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
-#else
-/* ]WR */
- if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */
-/* WR[ */
-#endif /* WMW_RPM_IO */
-/* ]WR */
- { sprintf(soap->tmpbuf, "HTTP/%s %s", soap->http_version, s);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return soap->error;
- }
- else if ((soap->error = soap->fposthdr(soap, "Status", s)))
- return soap->error;
- }
- if ((soap->error = soap->fposthdr(soap, "Server", "gSOAP/2.6"))
- || (soap->error = soap_puthttphdr(soap, status, count)))
- return soap->error;
-#ifdef WITH_COOKIES
- if (soap_putsetcookies(soap))
- return soap->error;
-#endif
- return soap->error = soap->fposthdr(soap, NULL, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_response(struct soap *soap, int status)
-{ register size_t count;
- if (!(soap->omode & (SOAP_ENC_XML | SOAP_IO_STORE /* this tests for chunking too */))
- && (status == SOAP_HTML || status == SOAP_FILE))
- { soap->omode &= ~SOAP_IO;
- soap->omode |= SOAP_IO_STORE;
- }
- soap->status = status;
- count = soap_begin_dime(soap);
- if (soap_begin_send(soap))
- return soap->error;
- if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML))
- { register int n = soap->mode;
- soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
- if ((n & SOAP_IO) != SOAP_IO_FLUSH)
- soap->mode |= SOAP_IO_BUFFER;
- if ((soap->error = soap->fresponse(soap, status, count)))
- return soap->error;
- if ((n & SOAP_IO) == SOAP_IO_CHUNK)
- { if (soap_flush(soap))
- return soap->error;
- }
- soap->mode = n;
- }
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- return soap_putdimehdr(soap);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_fault(struct soap *soap)
-{ const char **c = soap_faultcode(soap);
- const char **s = soap_faultstring(soap);
- if (!*c)
- { if (soap->version == 2)
- *c = "SOAP-ENV:Sender";
- else
- *c = "SOAP-ENV:Client";
- }
- if (*s)
- return;
- switch (soap->error)
- { case SOAP_CLI_FAULT:
- *s = "Client fault";
- break;
- case SOAP_SVR_FAULT:
- *s = "Server fault";
- break;
- case SOAP_TAG_MISMATCH:
- sprintf(soap->msgbuf, "Tag mismatch: element '%s' does not correspond to expected element", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_TYPE:
- sprintf(soap->msgbuf, "Data type '%s' mismatch in element '%s'", soap->type, soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_SYNTAX_ERROR:
- *s = "XML syntax error";
- break;
- case SOAP_NO_TAG:
- *s = "No XML element tag found";
- break;
- case SOAP_MUSTUNDERSTAND:
- *c = "SOAP-ENV:MustUnderstand";
- sprintf(soap->msgbuf, "The data in element '%s' must be understood but cannot be handled", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_VERSIONMISMATCH:
- *c = "SOAP-ENV:VersionMismatch";
- *s = "SOAP version mismatch or invalid SOAP message";
- break;
- case SOAP_DATAENCODINGUNKNOWN:
- *c = "SOAP-ENV:DataEncodingUnknown";
- *s = "Unsupported SOAP data encoding";
- break;
- case SOAP_DIME_MISMATCH:
- *s = "DIME version mismatch";
- break;
- case SOAP_NAMESPACE:
- sprintf(soap->msgbuf, "Namespace URI mismatch in element '%s'", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_OBJ_MISMATCH:
- *s = "Object mismatch";
- break;
- case SOAP_FATAL_ERROR:
- *s = "Fatal error";
- break;
- case SOAP_NO_METHOD:
- sprintf(soap->msgbuf, "Method '%s' not implemented", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_GET_METHOD:
- *s = "HTTP GET method not implemented";
- break;
- case SOAP_EOM:
- *s = "Out of memory";
- break;
- case SOAP_IOB:
- *s = "Array index out of bounds";
- break;
- case SOAP_NULL:
- sprintf(soap->msgbuf, "Cannot create nilable object for type '%s' in element '%s'", soap->type, soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_MULTI_ID:
- *s = "Non-unique id attribute";
- break;
- case SOAP_MISSING_ID:
- *s = "Missing id: referenced data is missing or had to be ignored";
- break;
- case SOAP_HREF:
- *s = "Invalid XML: object reference with href attribute is incompatible with actual object referred to";
- break;
- case SOAP_FAULT:
- break;
- case SOAP_TCP_ERROR:
- *s = tcp_error(soap);
- break;
- case SOAP_HTTP_ERROR:
- *s = "HTTP error";
- break;
- case SOAP_SSL_ERROR:
- *s = "SSL error";
- break;
- case SOAP_PLUGIN_ERROR:
- *s = "Plugin registry error";
- break;
- case SOAP_DIME_ERROR:
- *s = "DIME error";
- break;
- case SOAP_ZLIB_ERROR:
-#ifdef WITH_ZLIB
- sprintf(soap->msgbuf, "Zlib/gzip error: '%s'", soap->d_stream.msg?soap->d_stream.msg:"");
- *s = soap->msgbuf;
-#else
- *s = "Zlib not installed for required message (de)compression";
-#endif
- break;
- case SOAP_EOD:
- *s = "End of DIME error";
- break;
- case SOAP_REQUIRED:
- *s = "Validation failure: XML attribute required";
- break;
- case SOAP_OCCURS:
- *s = "Validation failure: XML element occurs count";
- break;
- case SOAP_EOF:
- sprintf(soap->msgbuf, "End of file or no input: '%s'", soap_strerror(soap));
- *s = soap->msgbuf;
- break;
- default:
- if (soap->error > 200 && soap->error < 600)
- { sprintf(soap->msgbuf, "HTTP Error: '%s'", http_error(soap, soap->error));
- *s = soap->msgbuf;
- }
- else
- *s = "Unknown error code";
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send_fault(struct soap *soap)
-{ register int status = soap->error;
- if (status == SOAP_STOP)
- return status;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Sending back fault struct for error code %d\n", soap->error));
- soap->keep_alive = 0; /* to terminate connection */
- soap_set_fault(soap);
- if ((status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) && soap_poll(soap) == SOAP_OK)
- { soap->error = SOAP_OK;
- soap_serializeheader(soap);
- soap_serializefault(soap);
- soap_begin_count(soap);
- if (soap->mode & SOAP_IO_LENGTH)
- { soap_envelope_begin_out(soap);
- soap_putheader(soap);
- soap_body_begin_out(soap);
- soap_putfault(soap);
- soap_body_end_out(soap);
- soap_envelope_end_out(soap);
- }
- if (soap_response(soap, status)
- || soap_envelope_begin_out(soap)
- || soap_putheader(soap)
- || soap_body_begin_out(soap)
- || soap_putfault(soap)
- || soap_body_end_out(soap)
- || soap_envelope_end_out(soap))
- return soap_closesock(soap);
- soap_end_send(soap);
- }
- soap_closesock(soap);
- return soap->error = status;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_fault(struct soap *soap)
-{ register int status = soap->error;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Receiving SOAP Fault\n"));
- soap->error = SOAP_OK;
- if (soap_getfault(soap))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Error: soap_get_soapfault() failed. Is this a SOAP message at all?\n"));
- *soap_faultcode(soap) = (soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client");
- soap->error = status;
- soap_set_fault(soap);
- }
- else
- { register const char *s = *soap_faultcode(soap);
- if (!soap_match_tag(soap, s, "SOAP-ENV:Server") || !soap_match_tag(soap, s, "SOAP-ENV:Receiver"))
- status = SOAP_SVR_FAULT;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:Client") || !soap_match_tag(soap, s, "SOAP-ENV:Sender"))
- status = SOAP_CLI_FAULT;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:MustUnderstand"))
- status = SOAP_MUSTUNDERSTAND;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:VersionMismatch"))
- status = SOAP_VERSIONMISMATCH;
- else
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Fault code %s\n", s));
- status = SOAP_FAULT;
- }
- if (soap_body_end_in(soap)
- || soap_envelope_end_in(soap)
- || soap_end_recv(soap))
- return soap_closesock(soap);
- soap->error = status;
- }
- return soap_closesock(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-soap_strerror(struct soap *soap)
-{ int err = soap->errnum;
- if (!err)
- err = soap_errno;
- if (err)
- {
-#ifndef UNDER_CE
- return strerror(err);
-#else
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)&soap->werrorstr, 256, NULL);
- wcstombs(soap->errorstr, soap->werrorstr, 256);
- return soap->errorstr;
-#endif
- }
- return "Operation interrupted or timed out";
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_set_error(struct soap *soap, const char *faultcode, const char *faultstring, const char *faultdetail, int soaperror)
-{ *soap_faultcode(soap) = faultcode;
- *soap_faultstring(soap) = faultstring;
- if (faultdetail && *faultdetail)
- { register const char **s = soap_faultdetail(soap);
- if (s)
- *s = faultdetail;
- }
- return soap->error = soaperror;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_sender_error(struct soap *soap, const char *faultstring, const char *faultdetail, int soaperror)
-{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultstring, faultdetail, soaperror);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_receiver_error(struct soap *soap, const char *faultstring, const char *faultdetail, int soaperror)
-{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultstring, faultdetail, soaperror);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultstring, const char *faultdetail)
-{ char *s = NULL, *t = NULL;
- if (faultstring)
- s = soap_strdup(soap, faultstring);
- if (faultdetail)
- t = soap_strdup(soap, faultdetail);
- return soap_set_error(soap, faultcode, s, t, SOAP_FAULT);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
-{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultstring, faultdetail);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
-{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultstring, faultdetail);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_print_fault(struct soap *soap, FILE *fd)
-{ if (soap->error)
- { const char **s;
- if (!*soap_faultcode(soap))
- soap_set_fault(soap);
- fprintf(fd, "SOAP FAULT: %s\n\"%s\"\n", *soap_faultcode(soap), *soap_faultstring(soap));
- s = soap_faultdetail(soap);
- if (s && *s)
- fprintf(fd, "Detail: %s\n", *s);
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_print_fault_location(struct soap *soap, FILE *fd)
-{
-#ifndef WITH_LEAN
- int c;
- if (soap->error && soap->buflen > 0)
- { if (soap->bufidx == 0)
- soap->bufidx = 1;
- c = soap->buf[soap->bufidx - 1];
- soap->buf[soap->bufidx - 1] = '\0';
- soap->buf[soap->buflen - 1] = '\0';
- if (soap->bufidx < soap->buflen)
- fprintf(fd, "%s%c\n** HERE **\n%s\n", soap->buf, c, soap->buf + soap->bufidx);
- else
- fprintf(fd, "%s%c\n** HERE **\n", soap->buf, c);
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_register_plugin_arg(struct soap *soap, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void *arg)
-{ register struct soap_plugin *p;
- register int r;
- if (!(p = (struct soap_plugin*)SOAP_MALLOC(sizeof(struct soap_plugin))))
- return soap->error = SOAP_EOM;
- p->id = NULL;
- p->data = NULL;
- p->fcopy = NULL;
- p->fdelete = NULL;
- r = fcreate(soap, p, arg);
- if (!r && p->fdelete)
- { p->next = soap->plugins;
- soap->plugins = p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Registered '%s' plugin\n", p->id));
- return SOAP_OK;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not register plugin '%s': plugin returned error %d (or fdelete callback not set)\n", p->id?p->id:"?", r));
- SOAP_FREE(p);
- return r;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void *
-fplugin(struct soap *soap, const char *id)
-{ register struct soap_plugin *p;
- for (p = soap->plugins; p; p = p->next)
- if (p->id == id || !strcmp(p->id, id))
- return p->data;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void *
-SOAP_FMAC2
-soap_lookup_plugin(struct soap *soap, const char *id)
-{ return soap->fplugin(soap, id);
-}
-#endif
-
-/******************************************************************************/
-#ifdef __cplusplus
-}
-#endif
-
+++ /dev/null
-/*
-
-stdsoap2.c[pp] 2.6.2
-
-Runtime environment.
-
-gSOAP XML Web services tools
-Copyright (C) 2000-2004, Robert van Engelen, Genivia, Inc. All Rights Reserved.
-
-Contributors:
-
-Wind River Systems, Inc., for the following additions (marked WR[...]):
- - vxWorks compatible
- - Support for IPv6.
-
---------------------------------------------------------------------------------
-gSOAP public license.
-
-The contents of this file are subject to the gSOAP Public License Version 1.3
-(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.cs.fsu.edu/~engelen/soaplicense.html
-Software distributed under the License is distributed on an "AS IS" basis,
-WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-for the specific language governing rights and limitations under the License.
-
-The Initial Developer of the Original Code is Robert A. van Engelen.
-Copyright (C) 2000-2004 Robert A. van Engelen, Genivia inc. All Rights Reserved.
---------------------------------------------------------------------------------
-GPL license.
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307 USA
-
-Author contact information:
-engelen@genivia.com / engelen@acm.org
---------------------------------------------------------------------------------
-
-Installation note:
-
-Win32 build needs winsock.dll (Visual C++ "wsock32.lib")
-To do this in Visual C++ 6.0, go to "Project", "settings", select the "Link"
-tab (the project file needs to be selected in the file view) and add
-"wsock32.lib" to the "Object/library modules" entry
-
-*/
-
-#include "stdsoap2.h"
-
-#ifdef __cplusplus
-SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.6.2 2004-06-12 12:00:00 GMT")
-extern "C" {
-#else
-SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.6.2 2004-06-12 12:00:00 GMT")
-#endif
-
-/* 8bit character representing unknown/nonrepresentable character data (not supported by current locale) */
-#ifndef SOAP_UNKNOWN_CHAR
-#define SOAP_UNKNOWN_CHAR (127)
-#endif
-
-/* EOF=-1 */
-#define LT (wchar)(-2) /* XML character '<' */
-#define TT (wchar)(-3) /* XML character '</' */
-#define GT (wchar)(-4) /* XML character '>' */
-#define QT (wchar)(-5) /* XML character '"' */
-#define AP (wchar)(-6) /* XML character ''' */
-
-#define soap_blank(c) ((c) >= 0 && (c) <= 32)
-#define soap_notblank(c) ((c) > 32)
-#define soap_hash_ptr(p) (((unsigned long)(p) >> 3) & (SOAP_PTRHASH - 1))
-
-static int soap_isxdigit(int);
-static wchar soap_char(struct soap*);
-static wchar soap_getchunkchar(struct soap*);
-static void soap_update_ptrs(struct soap*, char*, char*, long);
-static int soap_has_copies(struct soap*, char*, char*);
-static struct soap_ilist *soap_hlookup(struct soap*, const char*);
-static void soap_init_iht(struct soap*);
-static void soap_free_iht(struct soap*);
-static void soap_init_pht(struct soap*);
-static void soap_free_pht(struct soap*);
-static int soap_set_error(struct soap*, const char*, const char*, const char*, int);
-static int soap_copy_fault(struct soap*, const char*, const char*, const char*);
-static int soap_getattrval(struct soap*, char*, size_t, wchar);
-static void soap_set_local_namespaces(struct soap*);
-static size_t soap_begin_dime(struct soap*);
-static int soap_isnumeric(struct soap*, const char*);
-static void *fplugin(struct soap*, const char*);
-
-#ifndef WITH_LEAN
-static time_t soap_timegm(struct tm*);
-static void soap_init_logs(struct soap*);
-static void soap_close_logfile(struct soap*, int);
-static void soap_set_logfile(struct soap*, int, const char*);
-#endif
-
-#ifdef WITH_FAST
-/* Use look-aside buffers */
-static int soap_append_lab(struct soap*, const char*, size_t);
-#endif
-
-#ifndef WITH_LEANER
-static int soap_putdimefield(struct soap*, const char*, size_t);
-static char *soap_getdimefield(struct soap*, size_t);
-#endif
-
-#ifdef WITH_GZIP
-static int soap_getgzipheader(struct soap*);
-#endif
-
-#ifdef WITH_OPENSSL
-static int ssl_auth_init(struct soap*);
-static int ssl_verify_callback(int, X509_STORE_CTX*);
-static int ssl_password(char*, int, int, void *);
-/* This callback is included for future references. It should not be deleted
-static DH *ssl_tmp_dh(SSL*, int, int);
-*/
-#endif
-
-static const char *soap_strerror(struct soap*);
-static const char *tcp_error(struct soap*);
-static const char *http_error(struct soap*, int);
-static int http_post(struct soap*, const char*, const char*, int, const char*, const char*, size_t);
-static int http_get(struct soap*);
-static int http_post_header(struct soap*, const char*, const char*);
-static int http_response(struct soap*, int, size_t);
-static int http_parse(struct soap*);
-static int http_parse_header(struct soap*, const char*, const char*);
-static int tcp_connect(struct soap*, const char*, const char*, int);
-static int tcp_accept(struct soap*, int, struct sockaddr*, int*);
-static int tcp_disconnect(struct soap*);
-static int fsend(struct soap*, const char*, size_t);
-static size_t frecv(struct soap*, char*, size_t);
-
-/* WR[ */
-#ifdef VXWORKS
-static int vx_nonblocking = TRUE; /* ioctl argument */
-#endif
-/* ]WR */
-
-#ifndef PALM_2
-static const char soap_env1[42] = "http://schemas.xmlsoap.org/soap/envelope/";
-static const char soap_enc1[42] = "http://schemas.xmlsoap.org/soap/encoding/";
-static const char soap_env2[40] = "http://www.w3.org/2003/05/soap-envelope";
-static const char soap_enc2[40] = "http://www.w3.org/2003/05/soap-encoding";
-static const char soap_rpc[35] = "http://www.w3.org/2003/05/soap-rpc";
-#endif
-
-#ifndef PALM_1
-const struct soap_double_nan soap_double_nan = {0xFFFFFFFF, 0xFFFFFFFF};
-static const char soap_base64o[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char soap_base64i[81] = "\76XXX\77\64\65\66\67\70\71\72\73\74\75XXXXXXX\00\01\02\03\04\05\06\07\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31XXXXXX\32\33\34\35\36\37\40\41\42\43\44\45\46\47\50\51\52\53\54\55\56\57\60\61\62\63";
-#endif
-
-static const char soap_padding[3] = "\0\0";
-#define SOAP_STR_PADDING (soap_padding)
-#define SOAP_STR_EOS (soap_padding)
-
-#ifndef WITH_LEAN
-static const struct soap_code_map html_entity_codes[] = /* entities for XHTML parsing */
-{ { 160, "nbsp" },
- { 161, "iexcl" },
- { 162, "cent" },
- { 163, "pound" },
- { 164, "curren" },
- { 165, "yen" },
- { 166, "brvbar" },
- { 167, "sect" },
- { 168, "uml" },
- { 169, "copy" },
- { 170, "ordf" },
- { 171, "laquo" },
- { 172, "not" },
- { 173, "shy" },
- { 174, "reg" },
- { 175, "macr" },
- { 176, "deg" },
- { 177, "plusmn" },
- { 178, "sup2" },
- { 179, "sup3" },
- { 180, "acute" },
- { 181, "micro" },
- { 182, "para" },
- { 183, "middot" },
- { 184, "cedil" },
- { 185, "sup1" },
- { 186, "ordm" },
- { 187, "raquo" },
- { 188, "frac14" },
- { 189, "frac12" },
- { 190, "frac34" },
- { 191, "iquest" },
- { 192, "Agrave" },
- { 193, "Aacute" },
- { 194, "Acirc" },
- { 195, "Atilde" },
- { 196, "Auml" },
- { 197, "Aring" },
- { 198, "AElig" },
- { 199, "Ccedil" },
- { 200, "Egrave" },
- { 201, "Eacute" },
- { 202, "Ecirc" },
- { 203, "Euml" },
- { 204, "Igrave" },
- { 205, "Iacute" },
- { 206, "Icirc" },
- { 207, "Iuml" },
- { 208, "ETH" },
- { 209, "Ntilde" },
- { 210, "Ograve" },
- { 211, "Oacute" },
- { 212, "Ocirc" },
- { 213, "Otilde" },
- { 214, "Ouml" },
- { 215, "times" },
- { 216, "Oslash" },
- { 217, "Ugrave" },
- { 218, "Uacute" },
- { 219, "Ucirc" },
- { 220, "Uuml" },
- { 221, "Yacute" },
- { 222, "THORN" },
- { 223, "szlig" },
- { 224, "agrave" },
- { 225, "aacute" },
- { 226, "acirc" },
- { 227, "atilde" },
- { 228, "auml" },
- { 229, "aring" },
- { 230, "aelig" },
- { 231, "ccedil" },
- { 232, "egrave" },
- { 233, "eacute" },
- { 234, "ecirc" },
- { 235, "euml" },
- { 236, "igrave" },
- { 237, "iacute" },
- { 238, "icirc" },
- { 239, "iuml" },
- { 240, "eth" },
- { 241, "ntilde" },
- { 242, "ograve" },
- { 243, "oacute" },
- { 244, "ocirc" },
- { 245, "otilde" },
- { 246, "ouml" },
- { 247, "divide" },
- { 248, "oslash" },
- { 249, "ugrave" },
- { 250, "uacute" },
- { 251, "ucirc" },
- { 252, "uuml" },
- { 253, "yacute" },
- { 254, "thorn" },
- { 255, "yuml" },
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEAN
-static const struct soap_code_map h_error_codes[] =
-{
-#ifdef HOST_NOT_FOUND
- { HOST_NOT_FOUND, "Host not found" },
-#endif
-#ifdef TRY_AGAIN
- { TRY_AGAIN, "Try Again" },
-#endif
-#ifdef NO_RECOVERY
- { NO_RECOVERY, "No Recovery" },
-#endif
-#ifdef NO_DATA
- { NO_DATA, "No Data" },
-#endif
-#ifdef NO_ADDRESS
- { NO_ADDRESS, "No Address" },
-#endif
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEAN
-static const struct soap_code_map h_http_error_codes[] =
-{ { 201, "Created" },
- { 202, "Accepted" },
- { 203, "Non-Authoritative Information" },
- { 204, "No Content" },
- { 205, "Reset Content" },
- { 206, "Partial Content" },
- { 300, "Multiple Choices" },
- { 301, "Moved Permanently" },
- { 302, "Found" },
- { 303, "See Other" },
- { 304, "Not Modified" },
- { 305, "Use Proxy" },
- { 307, "Temporary Redirect" },
- { 400, "Bad Request" },
- { 401, "Unauthorized" },
- { 402, "Payment Required" },
- { 403, "Forbidden" },
- { 404, "Not Found" },
- { 405, "Method Not Allowed" },
- { 406, "Not Acceptable" },
- { 407, "Proxy Authentication Required" },
- { 408, "Request Time-out" },
- { 409, "Conflict" },
- { 410, "Gone" },
- { 411, "Length Required" },
- { 412, "Precondition Failed" },
- { 413, "Request Entity Too Large" },
- { 414, "Request-URI Too Large" },
- { 415, "Unsupported Media Type" },
- { 416, "Requested range not satisfiable" },
- { 417, "Expectation Failed" },
- { 500, "Internal Server Error" },
- { 501, "Not Implemented" },
- { 502, "Bad Gateway" },
- { 503, "Service Unavailable" },
- { 504, "Gateway Time-out" },
- { 505, "HTTP Version not supported" },
- { 0, NULL }
-};
-#endif
-
-#ifdef WITH_OPENSSL
-static const struct soap_code_map h_ssl_error_codes[] =
-{
-#define _SSL_ERROR(e) { e, #e }
- _SSL_ERROR(SSL_ERROR_SSL),
- _SSL_ERROR(SSL_ERROR_ZERO_RETURN),
- _SSL_ERROR(SSL_ERROR_WANT_READ),
- _SSL_ERROR(SSL_ERROR_WANT_WRITE),
- _SSL_ERROR(SSL_ERROR_WANT_CONNECT),
- _SSL_ERROR(SSL_ERROR_WANT_X509_LOOKUP),
- _SSL_ERROR(SSL_ERROR_SYSCALL),
- { 0, NULL }
-};
-#endif
-
-#ifdef WIN32
-static int tcp_done = 0;
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-fsend(struct soap *soap, const char *s, size_t n)
-{ register int nwritten;
-#if defined(__cplusplus) && !defined(UNDER_CE)
- if (soap->os)
- { soap->os->write(s, n);
- if (soap->os->good())
- return SOAP_OK;
- return SOAP_EOF;
- }
-#endif
- while (n)
- { if (soap_valid_socket(soap->socket))
- {
-#ifndef WITH_LEAN
- if (soap->send_timeout)
- { struct timeval timeout;
- fd_set fd;
- if (soap->send_timeout > 0)
- { timeout.tv_sec = soap->send_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->send_timeout/1000000;
- timeout.tv_usec = -soap->send_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- for (;;)
- { register int r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- return SOAP_EOF;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- }
- }
-#endif
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- nwritten = SSL_write(soap->ssl, s, n);
- else
-#endif
-#ifndef PALM
- nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags);
-#else
- nwritten = send((SOAP_SOCKET)soap->socket, (void*)s, n, soap->socket_flags);
-#endif
- if (nwritten <= 0)
- {
-#ifdef WITH_OPENSSL
- int err;
- if (soap->ssl && (err = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- return SOAP_EOF;
-#endif
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EWOULDBLOCK && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- nwritten = 0; /* and call write() again */
- }
- }
- else
- {
-#ifdef WITH_FASTCGI
- nwritten = fwrite((void*)s, 1, n, stdout);
- fflush(stdout);
-#else
-#ifdef UNDER_CE
- nwritten = fwrite(s, 1, n, soap->sendfd);
-#else
-/* WR[ */
-#ifdef VXWORKS
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- {
- httpBlockPut(soap->rpmreqid, s, n);
- nwritten = n;
- }
- else
- {
- nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
- }
-#else
- nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
-#endif /* WMW_RPM_IO */
-#else
-/* ]WR */
- nwritten = write((SOAP_SOCKET)soap->sendfd, s, n);
-/* WR[ */
-#endif
-/* ]WR */
-#endif
-#endif
- if (nwritten <= 0)
- { if (soap_errno != SOAP_EINTR && soap_errno != SOAP_EWOULDBLOCK && soap_errno != SOAP_EAGAIN)
- { soap->errnum = soap_errno;
- return SOAP_EOF;
- }
- nwritten = 0; /* and call write() again */
- }
- }
- n -= nwritten;
- s += nwritten;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_flush_raw(struct soap *soap, const char *s, size_t n)
-{
-#ifndef WITH_LEAN
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- { char *t;
- if (!(t = (char*)soap_push_block(soap, n)))
- return soap->error = SOAP_EOM;
- memcpy(t, s, n);
- return SOAP_OK;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { char t[16];
- sprintf(t, "\r\n%lX\r\n" + (soap->chunksize ? 0 : 2), (unsigned long)n);
- DBGMSG(SENT, t, strlen(t));
- if ((soap->error = soap->fsend(soap, t, strlen(t))))
- return soap->error;
- soap->chunksize += n;
- }
-#endif
- DBGMSG(SENT, s, n);
- return soap->error = soap->fsend(soap, s, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_flush(struct soap *soap)
-{ if (soap->bufidx)
- {
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { soap->d_stream.next_in = (Byte*)soap->buf;
- soap->d_stream.avail_in = (unsigned int)soap->bufidx;
-#ifdef WITH_GZIP
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->bufidx);
-#endif
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating %u bytes\n", soap->d_stream.avail_in));
- if (deflate(&soap->d_stream, Z_NO_FLUSH) != Z_OK)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to deflate: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- if (!soap->d_stream.avail_out)
- { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN))
- return soap->error;
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- }
- } while (soap->d_stream.avail_in);
- }
- else
-#endif
- if (soap_flush_raw(soap, soap->buf, soap->bufidx))
- return soap->error;
- soap->bufidx = 0;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send_raw(struct soap *soap, const char *s, size_t n)
-{ if (!n)
- return SOAP_OK;
- if (soap->mode & SOAP_IO_LENGTH)
- { soap->count += n;
- if (soap->fprepare)
- return soap->fprepare(soap, s, n);
- return SOAP_OK;
- }
- if (soap->mode & SOAP_IO)
- { register size_t i = SOAP_BUFLEN - soap->bufidx;
- while (n >= i)
- { memcpy(soap->buf + soap->bufidx, s, i);
- soap->bufidx = SOAP_BUFLEN;
- if (soap_flush(soap))
- return soap->error;
- s += i;
- n -= i;
- i = SOAP_BUFLEN;
- }
- memcpy(soap->buf + soap->bufidx, s, n);
- soap->bufidx += n;
- return SOAP_OK;
- }
- return soap_flush_raw(soap, s, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send(struct soap *soap, const char *s)
-{ if (s)
- return soap_send_raw(soap, s, strlen(s));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static size_t
-frecv(struct soap *soap, char *s, size_t n)
-{ register int r;
- soap->errnum = 0;
-#if defined(__cplusplus) && !defined(UNDER_CE)
- if (soap->is)
- { if (soap->is->good())
- return soap->is->read(s, n).gcount();
- return 0;
- }
-#endif
- if (soap_valid_socket(soap->socket))
- { for (;;)
- {
-#ifndef WITH_LEAN
- struct timeval timeout;
- fd_set fd;
- if (soap->recv_timeout)
- { if (soap->recv_timeout > 0)
- { timeout.tv_sec = soap->recv_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->recv_timeout/1000000;
- timeout.tv_usec = -soap->recv_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- for (;;)
- { r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r > 0)
- break;
- if (r == 0)
- return 0;
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
- }
-#endif
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { int err;
- r = SSL_read(soap->ssl, s, n);
- if ((err = SSL_get_error(soap->ssl, r)) == SSL_ERROR_NONE)
- return (size_t)r;
- if (err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- return 0;
- }
- else
-#endif
- { r = recv((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags);
- if (r >= 0)
- return (size_t)r;
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
-#ifndef WITH_LEAN
- { struct timeval timeout;
- fd_set fd;
- timeout.tv_sec = 0;
- timeout.tv_usec = 10000;
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r < 0 && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
-#endif
- }
- }
-#ifdef WITH_FASTCGI
- return fread(s, 1, n, stdin);
-#else
-#ifdef UNDER_CE
- return fread(s, 1, n, soap->recvfd);
-#else
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- {
- r = httpBlockRead(soap->rpmreqid, s, n);
- }
- else
- {
- r = read(soap->recvfd, s, n);
- }
- if (r >= 0)
- {
- return r;
- }
- return 0;
-#else
-/* ]WR */
- r = read((SOAP_SOCKET)soap->recvfd, s, n);
- if (r >= 0)
- return (size_t)r;
- soap->errnum = soap_errno;
- return 0;
-/* WR[ */
-#endif
-/* ]WR */
-#endif
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static wchar
-soap_getchunkchar(struct soap *soap)
-{ if (soap->bufidx < soap->buflen)
- return soap->buf[soap->bufidx++];
- soap->bufidx = 0;
- soap->buflen = soap->chunkbuflen = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)soap->buflen));
- DBGMSG(RECV, soap->buf, soap->buflen);
- if (soap->buflen)
- return soap->buf[soap->bufidx++];
- return EOF;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_isxdigit(int c)
-{ switch (c)
- { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- return 1;
- }
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_raw(struct soap *soap)
-{ register size_t ret;
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { if (soap->d_stream.next_out == Z_NULL)
- return EOF;
- if (soap->d_stream.avail_in || !soap->d_stream.avail_out)
- { register int r;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflating\n"));
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- r = inflate(&soap->d_stream, Z_NO_FLUSH);
- if (r == Z_OK || r == Z_STREAM_END)
- { soap->bufidx = 0;
- soap->buflen = SOAP_BUFLEN - soap->d_stream.avail_out;
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen);
- if (r == Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out;
- soap->d_stream.next_out = Z_NULL;
- }
- if (soap->buflen)
- { soap->count += soap->buflen;
- return SOAP_OK;
- }
- }
- else if (r != Z_BUF_ERROR)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate error: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- soap->d_stream.next_out = Z_NULL;
- return EOF;
- }
- }
-zlib_again:
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK && !soap->chunksize)
- { memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
- soap->buflen = soap->z_buflen;
- }
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) /* read HTTP chunked transfer */
- {
-chunk_again:
- if (soap->chunksize)
- { soap->buflen = ret = soap->frecv(soap, soap->buf, soap->chunksize > SOAP_BUFLEN ? SOAP_BUFLEN : soap->chunksize);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk: read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- soap->bufidx = 0;
- soap->chunksize -= ret;
- }
- else
- { register wchar c;
- char tmp[8], *t;
- t = tmp;
- if (!soap->chunkbuflen)
- { soap->chunkbuflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- soap->bufidx = 0;
- if (!ret)
- return EOF;
- }
- else
- soap->bufidx = soap->buflen;
- soap->buflen = soap->chunkbuflen;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (%u %u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen));
- while (!soap_isxdigit((int)(c = soap_getchunkchar(soap))))
- if ((int)c == EOF)
- return EOF;
- do
- *t++ = (char)c;
- while (soap_isxdigit((int)(c = soap_getchunkchar(soap))) && t - tmp < 7);
- while ((int)c != EOF && c != '\n')
- c = soap_getchunkchar(soap);
- if ((int)c == EOF)
- return EOF;
- *t = '\0';
- soap->chunksize = soap_strtoul(tmp, &t, 16);
- if (!soap->chunksize)
- { soap->chunkbuflen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of chunked message\n"));
- while ((int)c != EOF && c != '\n')
- c = soap_getchunkchar(soap);
- return EOF;
- }
- soap->buflen = soap->bufidx + soap->chunksize;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to %u (%u %s)\n", (unsigned int)soap->buflen, (unsigned int)soap->bufidx, tmp));
- if (soap->buflen > soap->chunkbuflen)
- { soap->buflen = soap->chunkbuflen;
- soap->chunksize -= soap->buflen - soap->bufidx;
- soap->chunkbuflen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Passed end of buffer for chunked HTTP (%lu bytes left)\n", (unsigned long)(soap->buflen - soap->bufidx)));
- }
- else if (soap->chunkbuflen)
- soap->chunksize = 0;
- ret = soap->buflen - soap->bufidx;
- if (!ret)
- goto chunk_again;
- }
- }
- else
- { soap->bufidx = 0;
- soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- }
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { int r;
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = (unsigned int)ret;
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- r = inflate(&soap->d_stream, Z_NO_FLUSH);
- if (r == Z_OK || r == Z_STREAM_END)
- { soap->bufidx = 0;
- soap->z_buflen = soap->buflen;
- soap->buflen = ret = SOAP_BUFLEN - soap->d_stream.avail_out;
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %u bytes\n", (unsigned int)ret));
- if (!ret)
- goto zlib_again;
- if (r == Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out;
- soap->d_stream.next_out = Z_NULL;
- }
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to inflate: (%d) %s\n", r, soap->d_stream.msg?soap->d_stream.msg:""));
- soap->d_stream.next_out = Z_NULL;
- return EOF;
- }
- }
-#endif
- soap->count += ret;
- return !ret;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv(struct soap *soap)
-{
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- { if (soap->dime_buflen)
- { char *s;
- int i;
- unsigned char tmp[12];
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME hdr for chunked DIME is in buffer\n"));
- soap->count += soap->dime_buflen - soap->buflen;
- soap->buflen = soap->dime_buflen;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Skip padding (%ld bytes)\n", -(long)soap->dime_size&3));
- for (i = -(long)soap->dime_size&3; i > 0; i--)
- { soap->bufidx++;
- if (soap->bufidx >= soap->buflen)
- if (soap_recv_raw(soap))
- return EOF;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME hdr for next chunk\n"));
- s = (char*)tmp;
- for (i = 12; i > 0; i--)
- { *s++ = soap->buf[soap->bufidx++];
- if (soap->bufidx >= soap->buflen)
- if (soap_recv_raw(soap))
- return EOF;
- }
- soap->dime_flags = tmp[0] & 0x7;
- soap->dime_size = ((size_t)tmp[8] << 24) | ((size_t)tmp[9] << 16) | ((size_t)tmp[10] << 8) | ((size_t)tmp[11]);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME chunk (%u bytes)\n", (unsigned int)soap->dime_size));
- if (soap->dime_flags & SOAP_DIME_CF)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "More chunking\n"));
- soap->dime_chunksize = soap->dime_size;
- if (soap->buflen - soap->bufidx >= soap->dime_size)
- { soap->dime_buflen = soap->buflen;
- soap->buflen = soap->bufidx + soap->dime_chunksize;
- }
- else
- soap->dime_chunksize -= soap->buflen - soap->bufidx;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Last chunk\n"));
- soap->dime_buflen = 0;
- soap->dime_chunksize = 0;
- }
- soap->count = soap->buflen - soap->bufidx;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%u bytes remaining\n", (unsigned int)soap->count));
- return SOAP_OK;
- }
- if (soap->dime_chunksize)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get next DIME hdr for chunked DIME (%u bytes chunk)\n", (unsigned int)soap->dime_chunksize));
- if (soap_recv_raw(soap))
- return EOF;
- if (soap->buflen - soap->bufidx >= soap->dime_chunksize)
- { soap->dime_buflen = soap->buflen;
- soap->count -= soap->buflen - soap->bufidx - soap->dime_chunksize;
- soap->buflen = soap->bufidx + soap->dime_chunksize;
- }
- else
- soap->dime_chunksize -= soap->buflen - soap->bufidx;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%lu bytes remaining, count=%u\n", (unsigned long)(soap->buflen-soap->bufidx), (unsigned int)soap->count));
- return SOAP_OK;
- }
- }
-#endif
- return soap_recv_raw(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_getchar(struct soap *soap)
-{ register wchar c;
- if (soap->ahead)
- { c = soap->ahead;
- soap->ahead = 0;
- return c;
- }
- return soap_get1(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const struct soap_code_map*
-SOAP_FMAC2
-soap_code(const struct soap_code_map *map, const char *str)
-{ while (map->string)
- { if (!strcmp(str, map->string))
- return map;
- map++;
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_int_code(const struct soap_code_map *map, const char *str, long other)
-{ while (map->string)
- { if (!strcmp(str, map->string))
- return map->code;
- map++;
- }
- return other;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_str_code(const struct soap_code_map *map, long code)
-{ while (map->code != code && map->string)
- map++;
- return map->string;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static wchar
-soap_char(struct soap *soap)
-{ char tmp[8];
- register int i;
- register wchar c;
- register char *s = tmp;
- for (i = 0; i < 7; i++)
- { c = soap_get1(soap);
- if (c == ';' || (int)c == EOF)
- break;
- *s++ = (char)c;
- }
- *s = '\0';
- if (*tmp == '#')
- { if (tmp[1] == 'x' || tmp[1] == 'X')
- return soap_strtol(tmp + 2, NULL, 16);
- return atol(tmp + 1);
- }
- if (!strcmp(tmp, "lt"))
- return '<';
- if (!strcmp(tmp, "gt"))
- return '>';
- if (!strcmp(tmp, "amp"))
- return '&';
- if (!strcmp(tmp, "quot"))
- return '"';
- if (!strcmp(tmp, "apos"))
- return '\'';
-#ifndef WITH_LEAN
- return (wchar)soap_int_code(html_entity_codes, tmp, 127);
-#else
- return SOAP_UNKNOWN_CHAR; /* use this to represent unknown code */
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_get(struct soap *soap)
-{ register wchar c;
- c = soap->ahead;
- if (c)
- soap->ahead = 0;
- else
- c = soap_get1(soap);
- for (;;)
- { if (soap->cdata)
- { if (c == ']')
- { c = soap_get1(soap);
- if (c == ']')
- { soap->cdata = 0;
- soap_get1(soap); /* skip > */
- c = soap_get1(soap);
- }
- else
- { soap_revget1(soap);
- return ']';
- }
- }
- else
- return c;
- }
- switch (c)
- { case '<':
- do c = soap_get1(soap);
- while (soap_blank(c));
- if (c == '!' || c == '?' || c == '%')
- { if (c == '!')
- { c = soap_get1(soap);
- if (c == '[')
- { do c = soap_get1(soap);
- while ((int)c != EOF && c != '[');
- if ((int)c == EOF)
- break;
- soap->cdata = 1;
- c = soap_get1(soap);
- continue;
- }
- if (c == '-' && (c = soap_get1(soap)) == '-')
- { do
- { c = soap_get1(soap);
- if (c == '-' && (c = soap_get1(soap)) == '-')
- break;
- } while ((int)c != EOF);
- }
- }
- while ((int)c != EOF && c != '>')
- c = soap_get1(soap);
- if ((int)c == EOF)
- break;
- c = soap_get1(soap);
- continue;
- }
- if (c == '/')
- return TT;
- soap_revget1(soap);
- return LT;
- case '>':
- return GT;
- case '"':
- return QT;
- case '\'':
- return AP;
- case '&':
- return soap_char(soap) | 0x80000000;
- }
- break;
- }
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_advance(struct soap *soap)
-{ register wchar c;
- while ((int)((c = soap_get(soap)) != EOF) && c != LT && c != TT)
- ;
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_skip(struct soap *soap)
-{ register wchar c;
- do c = soap_get(soap);
- while (soap_blank(c));
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_move(struct soap *soap, long n)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving %ld bytes forward\n", (long)n));
- for (; n > 0; n--)
- if ((int)soap_getchar(soap) == EOF)
- return SOAP_EOF;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_tell(struct soap *soap)
-{ return soap->count - soap->buflen + soap->bufidx - (soap->ahead != 0);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pututf8(struct soap *soap, register unsigned long c)
-{ char tmp[16];
- if (c > 0 && c < 0x80)
- { *tmp = (char)c;
- return soap_send_raw(soap, tmp, 1);
- }
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { register char *t = tmp;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- *t = '\0';
- }
- else
-#endif
- sprintf(tmp, "&#%lu;", c);
- return soap_send(soap, tmp);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-wchar
-SOAP_FMAC2
-soap_getutf8(struct soap *soap)
-{ register wchar c, c1, c2, c3, c4;
- c = soap_get(soap);
- if (c < 0x80)
- return c;
- c1 = soap_get(soap);
- if (c1 < 0x80)
- { soap_unget(soap, c1);
- return c;
- }
- c1 &= 0x3F;
- if (c < 0xE0)
- return ((wchar)(c & 0x1F) << 6) | c1;
- c2 = (wchar)soap_get1(soap) & 0x3F;
- if (c < 0xF0)
- return ((wchar)(c & 0x0F) << 12) | (c1 << 6) | c2;
- c3 = (wchar)soap_get1(soap) & 0x3F;
- if (c < 0xF8)
- return ((wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;
- c4 = (wchar)soap_get1(soap) & 0x3F;
- if (c < 0xFC)
- return ((wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4;
- return ((wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (wchar)(soap_get1(soap) & 0x3F);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_puthex(struct soap *soap, const unsigned char *s, int n)
-{ /* TODO: serialize to DOM (as an option) using new soap_s2hex() */
- char d[2];
- register int i;
- for (i = 0; i < n; i++)
- { register int m = *s++;
- d[0] = (char)((m >> 4) + (m > 159 ? '7' : '0'));
- m &= 0x0F;
- d[1] = (char)(m + (m > 9 ? '7' : '0'));
- if (soap_send_raw(soap, d, 2))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-unsigned char*
-SOAP_FMAC2
-soap_gethex(struct soap *soap, int *n)
-{
-#ifdef WITH_FAST
- soap->labidx = 0;
- for (;;)
- { register char *s;
- register int i, k;
- if (soap_append_lab(soap, NULL, 0))
- return NULL;
- s = soap->labbuf + soap->labidx;
- k = soap->lablen - soap->labidx;
- soap->labidx = soap->lablen;
- for (i = 0; i < k; i++)
- { register char d1, d2;
- register wchar c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- { d1 = (char)c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- d2 = (char)c;
- else
- { soap->error = SOAP_TYPE;
- return NULL;
- }
- }
- else
- { unsigned char *p;
- soap_unget(soap, c);
- if (n)
- *n = (int)(soap->lablen - k + i);
- p = (unsigned char*)soap_malloc(soap, soap->lablen - k + i);
- if (p)
- memcpy(p, soap->labbuf, soap->lablen - k + i);
- return p;
- }
- *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');
- }
- }
-#else
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { register int i;
- register char *s = (char*)soap_push_block(soap, SOAP_BLKLEN);
- if (!s)
- { soap_end_block(soap);
- return NULL;
- }
- for (i = 0; i < SOAP_BLKLEN; i++)
- { register char d1, d2;
- register wchar c = soap_get(soap);
- if (soap_isxdigit(c))
- { d1 = (char)c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- d2 = (char)c;
- else
- { soap_end_block(soap);
- soap->error = SOAP_TYPE;
- return NULL;
- }
- }
- else
- { unsigned char *p;
- soap_unget(soap, c);
- if (n)
- *n = soap_size_block(soap, i);
- p = (unsigned char*)soap_save_block(soap, NULL);
- return p;
- }
- *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putbase64(struct soap *soap, const unsigned char *s, int n)
-{ register int i;
- register unsigned long m;
- char d[4];
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->data = (char*)soap_malloc(soap, (n + 2) / 3 * 4 + 1);
- return soap_s2base64(soap, s, soap->dom->data, n);
- }
-#endif
- if (!s)
- return SOAP_OK;
- for (; n > 2; n -= 3, s += 3)
- { m = ((unsigned long)((unsigned char*)s)[0] << 16) | ((unsigned long)((unsigned char*)s)[1] << 8) | (unsigned long)((unsigned char*)s)[2];
- for (i = 4; i > 0; m >>= 6)
- d[--i] = soap_base64o[m & 0x3F];
- if (soap_send_raw(soap, d, 4))
- return soap->error;
- }
- if (n > 0)
- { m = 0;
- for (i = 0; i < n; i++)
- m = (m << 8) | *s++;
- for (; i < 3; i++)
- m <<= 8;
- for (i++; i > 0; m >>= 6)
- d[--i] = soap_base64o[m & 0x3F];
- for (i = 3; i > n; i--)
- d[i] = '=';
- if (soap_send_raw(soap, d, 4))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-unsigned char*
-SOAP_FMAC2
-soap_getbase64(struct soap *soap, int *n, int malloc_flag)
-{
-#ifdef WITH_FAST
- soap->labidx = 0;
- for (;;)
- { register int i, k;
- register char *s;
- if (soap_append_lab(soap, NULL, 2))
- return NULL;
- s = soap->labbuf + soap->labidx;
- k = 3 * ((soap->lablen - soap->labidx) / 3);
- soap->labidx = 3 * (soap->lablen / 3);
- if (!s)
- return NULL;
- for (i = 0; i < k; i += 3)
- { register unsigned long m = 0;
- register int j = 0;
- do
- { register wchar c = soap_get(soap);
- if (c == '=' || c < 0)
- { unsigned char *p;
- switch (j)
- { case 2:
- *s++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *s++ = (char)((m >> 10) & 0xFF);
- *s++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n = (int)(soap->lablen - k + i);
- p = (unsigned char*)soap_malloc(soap, soap->lablen - k + i);
- if (p)
- memcpy(p, soap->labbuf, soap->lablen - k + i);
- if (c >= 0)
- { while ((int)((c = soap_get(soap)) != EOF) && c != LT && c != TT)
- ;
- }
- soap_unget(soap, c);
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- } while (j < 4);
- *s++ = (char)((m >> 16) & 0xFF);
- *s++ = (char)((m >> 8) & 0xFF);
- *s++ = (char)(m & 0xFF);
- }
- }
-#else
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { register int i;
- register char *s = (char*)soap_push_block(soap, 3 * SOAP_BLKLEN); /* must be multiple of 3 */
- if (!s)
- { soap_end_block(soap);
- return NULL;
- }
- for (i = 0; i < SOAP_BLKLEN; i++)
- { register unsigned long m = 0;
- register int j = 0;
- do
- { register wchar c = soap_get(soap);
- if (c == '=' || c < 0)
- { unsigned char *p;
- i *= 3;
- switch (j)
- { case 2:
- *s++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *s++ = (char)((m >> 10) & 0xFF);
- *s++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n = (int)soap_size_block(soap, i);
- p = (unsigned char*)soap_save_block(soap, NULL);
- if (c >= 0)
- { while ((int)((c = soap_get(soap)) != EOF) && c != LT && c != TT)
- ;
- }
- soap_unget(soap, c);
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- } while (j < 4);
- *s++ = (char)((m >> 16) & 0xFF);
- *s++ = (char)((m >> 8) & 0xFF);
- *s++ = (char)(m & 0xFF);
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_strdup(struct soap *soap, const char *s)
-{ char *t = NULL;
- if (s && (t = (char*)soap_malloc(soap, strlen(s) + 1)))
- strcpy(t, s);
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_new_block(struct soap *soap)
-{ struct soap_blist *p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New block sequence (prev=%p)\n", soap->blist));
- if (!(p = (struct soap_blist*)SOAP_MALLOC(sizeof(struct soap_blist))))
- return SOAP_EOM;
- p->next = soap->blist;
- p->ptr = NULL;
- p->size = 0;
- soap->blist = p;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_push_block(struct soap *soap, size_t n)
-{ char *p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push block of %u bytes (%u bytes total)\n", (unsigned int)n, (unsigned int)soap->blist->size));
- if (!(p = (char*)SOAP_MALLOC(n + sizeof(char*) + sizeof(size_t))))
- { soap->error = SOAP_EOM;
- return NULL;
- }
- *(char**)p = soap->blist->ptr;
- *(size_t*)(p + sizeof(char*)) = n;
- soap->blist->ptr = p;
- soap->blist->size += n;
- return p + sizeof(char*) + sizeof(size_t);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_pop_block(struct soap *soap)
-{ char *p;
- if (!soap->blist->ptr)
- return;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pop block\n"));
- p = soap->blist->ptr;
- soap->blist->size -= *(size_t*)(p + sizeof(char*));
- soap->blist->ptr = *(char**)p;
- SOAP_FREE(p);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_update_ptrs(struct soap *soap, char *start, char *end, long offset)
-{ int i;
- register struct soap_ilist *ip;
- register void *p, **q;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr && (char*)ip->ptr >= start && (char*)ip->ptr < end)
- ip->ptr = (char*)ip->ptr + offset;
- for (q = &ip->link; q; q = (void**)p)
- { p = *q;
- if (p && (char*)p >= start && (char*)p < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Link update id='%s' %p\n", ip->id, p));
- *q = (char*)p + offset;
- }
- }
- for (q = &ip->copy; q; q = (void**)p)
- { p = *q;
- if (p && (char*)p >= start && (char*)p < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy update id='%s' %p\n", ip->id, p));
- *q = (char*)p + offset;
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_has_copies(struct soap *soap, register char *start, register char *end)
-{ int i;
- register struct soap_ilist *ip;
- register char *p;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- for (p = (char*)ip->copy; p; p = *(char**)p)
- if (p >= start && p < end)
- return SOAP_ERR;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_resolve(struct soap *soap)
-{ register int i;
- register struct soap_ilist *ip;
- short flag1 = 0, flag2;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr)
- soap_resolve_ptr(ip);
- else if (*ip->id == '#')
- flag1 = 1;
- }
- do
- { flag2 = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- if (ip->copy && ip->ptr && ip->size)
- if (!soap_has_copies(soap, (char*)ip->ptr, (char*)ip->ptr + ip->size))
- { register void *p, **q = (void**)ip->copy;
- DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing copy chain to resolve id='%s'\n", ip->id));
- ip->copy = NULL;
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... copy %p -> %p (%u bytes)\n", ip->ptr, q, (unsigned int)ip->size));
- p = *q;
- memcpy(q, ip->ptr, ip->size);
- q = (void**)p;
- } while (q);
- flag2 = 1;
- }
- } while (flag2);
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- { register struct soap_flist *fp;
- for (fp = ip->flist; fp; fp = fp->next)
- if (fp->finsert)
- { unsigned int k = fp->level;
- void *p = ip->ptr;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded container data type=%d location=%p level=%u,%u\n", fp->type, fp->ptr, ip->level, fp->level));
- while (ip->level < k)
- { void **q = (void**)soap_malloc(soap, sizeof(void*));
- if (!q)
- return SOAP_EOM;
- *q = p;
- p = (void*)q;
- k--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- fp->finsert(soap, fp->type, fp->ptr, p);
- }
- }
- if (flag1)
- return soap->error = SOAP_MISSING_ID;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_resolve_ptr(struct soap_ilist *ip)
-{ register void *p, **q, *r;
- q = (void**)ip->link;
- ip->link = NULL;
- r = ip->ptr;
- while (q)
- { p = *q;
- *q = r;
- q = (void**)p;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_size_block(struct soap *soap, size_t n)
-{ if (soap->blist->ptr)
- { soap->blist->size -= *(size_t*)(soap->blist->ptr + sizeof(char*)) - n;
- *(size_t*)(soap->blist->ptr + sizeof(char*)) = n;
- }
- return soap->blist->size;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_first_block(struct soap *soap)
-{ char *p, *q, *r;
- p = soap->blist->ptr;
- if (!p)
- return NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "First block\n"));
- r = NULL;
- do
- { q = *(char**)p;
- *(char**)p = r;
- r = p;
- p = q;
- } while (p);
- soap->blist->ptr = r;
- return r + sizeof(char*) + sizeof(size_t);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_next_block(struct soap *soap)
-{ char *p;
- p = soap->blist->ptr;
- if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Next block\n"));
- soap->blist->ptr = *(char**)p;
- SOAP_FREE(p);
- if (soap->blist->ptr)
- return soap->blist->ptr + sizeof(char*) + sizeof(size_t);
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_block_size(struct soap *soap)
-{ return *(size_t*)(soap->blist->ptr + sizeof(char*));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_end_block(struct soap *soap)
-{ struct soap_blist *bp;
- char *p, *q;
- bp = soap->blist;
- if (bp)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of block sequence, free all remaining blocks\n"));
- for (p = bp->ptr; p; p = q)
- { q = *(char**)p;
- SOAP_FREE(p);
- }
- soap->blist = bp->next;
- SOAP_FREE(bp);
- }
- DBGLOG(TEST, if (soap->blist) SOAP_MESSAGE(fdebug, "Restore previous block sequence\n"));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_save_block(struct soap *soap, char *p)
-{ register size_t n;
- register char *q, *s;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Save all blocks in contiguous memory space of %u bytes (%p->%p)\n", (unsigned int)soap->blist->size, soap->blist->ptr, p));
- if (soap->blist->size)
- { if (!p)
- p = (char*)soap_malloc(soap, soap->blist->size);
- if (p)
- for (s = p, q = soap_first_block(soap); q; q = soap_next_block(soap))
- { n = soap_block_size(soap);
- soap_update_ptrs(soap, q, q + n, (long)s - (long)q); /* pointers s and q may or may not be related */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy %u bytes from %p to %p\n", (unsigned int)n, q, s));
- memcpy(s, q, n);
- s += n;
- }
- else
- soap->error = SOAP_EOM;
- }
- soap_end_block(soap);
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_store_block(struct soap *soap, char *p)
-{ p = soap_save_block(soap, p);
- if (!soap->blist)
- { struct soap_ilist *ip;
- int i;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- if (ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolve link chain to point to %p\n", ip->ptr));
- soap_resolve_ptr(ip);
- }
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsize(struct soap *soap, const char *type, int size)
-{ return soap_putsizes(soap, type, &size, 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsizes(struct soap *soap, const char *type, const int *size, int dim)
-{ return soap_putsizesoffsets(soap, type, size, NULL, dim);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsizesoffsets(struct soap *soap, const char *type, const int *size, const int *offset, int dim)
-{ int i;
- if (!type)
- return NULL;
- if (soap->version == 2)
- { sprintf(soap->type, "%s[%d", type, size[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), " %d", size[i]);
- }
- else
- { if (offset)
- { sprintf(soap->type, "%s[%d", type, size[0] + offset[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), ",%d", size[i] + offset[i]);
- }
- else
- { sprintf(soap->type, "%s[%d", type, size[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), ",%d", size[i]);
- }
- strcat(soap->type, "]");
- }
- return soap->type;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putoffset(struct soap *soap, int offset)
-{ return soap_putoffsets(soap, &offset, 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putoffsets(struct soap *soap, const int *offset, int dim)
-{ register int i;
- sprintf(soap->arrayOffset, "[%d", offset[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->arrayOffset + strlen(soap->arrayOffset), ",%d", offset[i]);
- strcat(soap->arrayOffset, "]");
- return soap->arrayOffset;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_size(const int *size, int dim)
-{ register int i, n = size[0];
- for (i = 1; i < dim; i++)
- n *= size[i];
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getoffsets(const char *attr, const int *size, int *offset, int dim)
-{ register int i, j = 0;
- if (offset)
- for (i = 0; i < dim && attr && *attr; i++)
- { attr++;
- j *= size[i];
- j += offset[i] = (int)atol(attr);
- attr = strchr(attr, ',');
- }
- else
- for (i = 0; i < dim && attr && *attr; i++)
- { attr++;
- j *= size[i];
- j += (int)atol(attr);
- attr = strchr(attr, ',');
- }
- return j;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getsize(const char *attr1, const char *attr2, int *j)
-{ register int n, k;
- char *s;
- *j = 0;
- if (!*attr1)
- return -1;
- n = 1;
- do
- { attr1++;
- k = (int)soap_strtol(attr1, &s, 10);
- n *= k;
- if (k < 0 || n > SOAP_MAXARRAYSIZE || s == attr1)
- return -1;
- attr1 = strchr(s, ',');
- if (!attr1)
- attr1 = strchr(s, ' ');
- if (attr2 && *attr2)
- { attr2++;
- *j *= k;
- k = (int)soap_strtol(attr2, &s, 10);
- *j += k;
- if (k < 0)
- return -1;
- attr2 = s;
- }
- } while (attr1 && *attr1 != ']');
- return n - *j;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getsizes(const char *attr, int *size, int dim)
-{ register int i, k, n;
- if (!*attr)
- return -1;
- i = strlen(attr);
- n = 1;
- do
- { for (i = i-1; i >= 0; i--)
- if (attr[i] == '[' || attr[i] == ',' || attr[i] == ' ')
- break;
- k = (int)atol(attr + i + 1);
- n *= size[--dim] = k;
- if (k < 0 || n > SOAP_MAXARRAYSIZE)
- return -1;
- } while (i >= 0 && attr[i] != '[');
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getposition(const char *attr, int *pos)
-{ register int i, n;
- if (!*attr)
- return -1;
- n = 0;
- i = 1;
- do
- { pos[n++] = (int)atol(attr + i);
- while (attr[i] && attr[i] != ',' && attr[i] != ']')
- i++;
- if (attr[i] == ',')
- i++;
- } while (n < SOAP_MAXDIMS && attr[i] && attr[i] != ']');
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_push_namespace(struct soap *soap, const char *id, const char *ns)
-{ register struct soap_nlist *np;
- register struct Namespace *p;
- np = (struct soap_nlist*)SOAP_MALLOC(sizeof(struct soap_nlist) + strlen(id));
- if (!np)
- return soap->error = SOAP_EOM;
- np->next = soap->nlist;
- soap->nlist = np;
- strcpy(np->id, id);
- np->level = soap->level;
- np->index = -1;
- np->ns = NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns));
- p = soap->local_namespaces;
- if (p)
- { register short i = 0;
- if (!strcmp(ns, soap_env1))
- soap->version = 1; /* make sure we use SOAP 1.1 */
- else if (!strcmp(ns, soap_env2))
- soap->version = 2; /* make sure we use SOAP 1.2 */
- else
- { for (; p->id; p++, i++)
- { if (p->ns)
- if (!strcmp(ns, p->ns))
- break;
- if (p->in)
- if (!soap_tag_cmp(ns, p->in))
- { if (p->out)
- SOAP_FREE(p->out);
- if ((p->out = (char*)SOAP_MALLOC(strlen(ns) + 1)))
- strcpy(p->out, ns);
- break;
- }
- }
- }
- if (i == 0 && (!p->ns || strcmp(ns, p->ns)))
- { if (p[0].out)
- SOAP_FREE(p[0].out);
- if ((p[0].out = (char*)SOAP_MALLOC(strlen(ns) + 1)))
- strcpy(p[0].out, ns);
- if (p[1].out)
- SOAP_FREE(p[1].out);
- if (soap->version == 1)
- { if ((p[1].out = (char*)SOAP_MALLOC(sizeof(soap_enc1))))
- strcpy(p[1].out, soap_enc1);
- }
- else if ((p[1].out = (char*)SOAP_MALLOC(sizeof(soap_enc2))))
- strcpy(p[1].out, soap_enc2);
- }
- if (p && p->id)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id));
- np->index = i;
- }
- }
- if (!p || !p->id)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns));
- np->ns = (char*)SOAP_MALLOC(strlen(ns) + 1);
- if (!np->ns)
- return soap->error = SOAP_EOM;
- strcpy(np->ns, ns);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_push_default_namespace(struct soap *soap, const char *id, int n)
-{ register struct soap_nlist *np = soap->nlist;
- while (np && np->index >= -1)
- np = np->next;
- if (np && (!strncmp(np->id, id, n) && !np->id[n]))
- return SOAP_OK;
- np = (struct soap_nlist*)SOAP_MALLOC(sizeof(struct soap_nlist) + n);
- if (!np)
- return soap->error = SOAP_EOM;
- np->next = soap->nlist;
- soap->nlist = np;
- strncpy(np->id, id, n);
- np->id[n] = '\0';
- np->level = soap->level;
- np->index = -2;
- np->ns = NULL;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_pop_namespace(struct soap *soap)
-{ register struct soap_nlist *np;
- while (soap->nlist && soap->nlist->level >= soap->level)
- { np = soap->nlist->next;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Popped namespace binding (level=%u) '%s'\n", soap->level, soap->nlist->id));
- if (soap->nlist->ns)
- SOAP_FREE(soap->nlist->ns);
- SOAP_FREE(soap->nlist);
- soap->nlist = np;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_namespace(struct soap *soap, const char *id1, const char *id2, int n1, int n2)
-{ register struct soap_nlist *np = soap->nlist;
- while (np && (np->index == -2 || (strncmp(np->id, id1, n1) || np->id[n1])))
- np = np->next;
- if (np)
- { if (np->index < 0 || (np->index >= 0 && soap->local_namespaces[np->index].id && (strncmp(soap->local_namespaces[np->index].id, id2, n2) || soap->local_namespaces[np->index].id[n2])))
- return SOAP_NAMESPACE;
- return SOAP_OK;
- }
- if (n1 == 3 && n1 == n2 && !strcmp(id1, "xml") && !strcmp(id1, id2))
- return SOAP_OK;
- return SOAP_SYNTAX_ERROR;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_default_namespace(struct soap *soap)
-{ register struct soap_nlist *np = soap->nlist;
- while (np && np->index >= -1)
- np = np->next;
- if (np)
- return np->id;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_tag_cmp(register const char *s, register const char *t)
-{ for (; *s && *s != '"'; s++, t++)
- if (tolower(*s) != tolower(*t))
- if (*t != '-')
- { if (*t != '*')
- return 1;
- if (*++t)
- { register int c = tolower(*t);
- for (; *s && *s != '"'; s++)
- { if (tolower(*s) == c)
- if (!soap_tag_cmp(s + 1, t + 1))
- return 0;
- }
- break;
- }
- else
- return 0;
- }
- if (*t == '*' && !t[1])
- return 0;
- return *t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_tag(struct soap *soap, const char *tag1, const char *tag2)
-{ register const char *s, *t;
- if (!tag1 || !tag2 || !*tag2)
- return SOAP_OK;
- s = strchr(tag1, ':');
- t = strchr(tag2, ':');
- if (t)
- { if (s)
- { if (SOAP_STRCMP(s + 1, t + 1))
- return SOAP_TAG_MISMATCH;
- if (t != tag2 && soap_match_namespace(soap, tag1, tag2, s - tag1, t - tag2))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
- return SOAP_TAG_MISMATCH;
- }
- }
- else if (SOAP_STRCMP(tag1, t + 1))
- return SOAP_TAG_MISMATCH;
- else if (t != tag2 && soap_match_namespace(soap, tag1, tag2, 0, t - tag2))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
- return SOAP_TAG_MISMATCH;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags and (default) namespaces match: '%s' '%s'\n", tag1, tag2));
- return SOAP_OK;
- }
- if (s)
- { if (((soap->mode & SOAP_XML_STRICT) && soap->part != SOAP_IN_HEADER && soap->encodingStyle))
- return SOAP_TAG_MISMATCH;
- if (SOAP_STRCMP(s + 1, tag2))
- return SOAP_TAG_MISMATCH;
- if (!soap->encodingStyle)
- { t = soap_default_namespace(soap);
- if (!t || soap_match_namespace(soap, tag1, t, s - tag1, strlen(t)))
- return SOAP_TAG_MISMATCH;
- }
- }
- else if (SOAP_STRCMP(tag1, tag2))
- return SOAP_TAG_MISMATCH;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags match: '%s' '%s'\n", tag1, tag2));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_array(struct soap *soap, const char *type)
-{ if (*soap->arrayType)
- if (soap_match_tag(soap, soap->arrayType, type)
- && soap_match_tag(soap, soap->arrayType, "xsd:anyType")
- && soap_match_tag(soap, soap->arrayType, "xsd:ur-type")
- )
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array type mismatch: '%s' '%s'\n", soap->arrayType, type));
- return SOAP_TAG_MISMATCH;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-
-#ifdef WITH_OPENSSL
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid)
-{ int err;
- soap->keyfile = keyfile;
- soap->password = password;
- soap->cafile = cafile;
- soap->capath = capath;
- if (dhfile)
- { soap->dhfile = dhfile;
- soap->rsa = 0;
- }
- else
- { soap->dhfile = NULL;
- soap->rsa = 1;
- }
- soap->randfile = randfile;
- soap->require_client_auth = (flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION);
- if (!(err = soap->fsslauth(soap)))
- if (sid)
- SSL_CTX_set_session_id_context(soap->ctx, (unsigned char*)sid, strlen(sid));
- return err;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *randfile)
-{ soap->keyfile = keyfile;
- soap->password = password;
- soap->cafile = cafile;
- soap->capath = capath;
- soap->dhfile = NULL;
- soap->rsa = 0;
- soap->randfile = randfile;
- soap->require_server_auth = (flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION);
- return soap->fsslauth(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-ssl_init()
-{ static int done = 0;
- if (!done)
- { done = 1;
- SSL_library_init();
-#ifndef WITH_LEAN
- SSL_load_error_strings();
-#endif
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char *
-ssl_error(struct soap *soap, int ret)
-{ int err = SSL_get_error(soap->ssl, ret);
- const char *msg = soap_str_code(h_ssl_error_codes, err);
- if (msg)
- strcpy(soap->msgbuf, msg);
- else
- return ERR_error_string(err, soap->msgbuf);
- if (ERR_peek_error())
- { unsigned long r;
- strcat(soap->msgbuf, "\n");
- while ((r = ERR_get_error()))
- ERR_error_string_n(r, soap->msgbuf + strlen(soap->msgbuf), sizeof(soap->msgbuf) - strlen(soap->msgbuf));
- }
- else
- { switch (ret)
- { case 0:
- strcpy(soap->msgbuf, "EOF was observed that violates the protocol. The client probably provided invalid authentication information.");
- break;
- case -1:
- sprintf(soap->msgbuf, "Error observed by underlying BIO: %s", strerror(errno));
- break;
- }
- }
- return soap->msgbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_password(char *buf, int num, int rwflag, void *userdata)
-{ if (num < (int)strlen((char*)userdata) + 1)
- return 0;
- return strlen(strcpy(buf, (char*)userdata));
-}
-#endif
-
-/******************************************************************************/
-/* This callback is included for future references. It should not be deleted
-#ifndef PALM_1
-static DH *
-ssl_tmp_dh(SSL *ssl, int is_export, int keylength)
-{ static DH *dh512 = NULL;
- static DH *dh1024 = NULL;
- DH *dh;
- switch (keylength)
- { case 512:
- if (!dh512)
- { BIO *bio = BIO_new_file("dh512.pem", "r");
- if (bio)
- { dh512 = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- return dh512;
- }
- }
- else
- return dh512;
- default:
- if (!dh1024)
- { BIO *bio = BIO_new_file("dh1024.pem", "r");
- if (bio)
- { dh1024 = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- }
- }
- dh = dh1024;
- }
- return dh;
-}
-#endif
-*/
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_auth_init(struct soap *soap)
-{ ssl_init();
- if (!soap->ctx)
- if (!(soap->ctx = SSL_CTX_new(SSLv23_method())))
- return soap_set_receiver_error(soap, "SSL error", "Can't setup context", SOAP_SSL_ERROR);
- if (soap->randfile)
- { if (!RAND_load_file(soap->randfile, -1))
- return soap_set_receiver_error(soap, "SSL error", "Can't load randomness", SOAP_SSL_ERROR);
- }
- else if (!RAND_load_file("/dev/urandom", 1024))
- { int r;
-#ifdef HAVE_RAND_R
- unsigned int s = (unsigned int)time(NULL);
-#endif
- RAND_seed(soap->buf, sizeof(soap->buf));
- while (!RAND_status())
- {
-#ifdef HAVE_RAND_R
- r = rand_r(&s);
-#else
- r = rand();
-#endif
- RAND_seed(&r, sizeof(int));
- }
- }
- if (soap->cafile || soap->capath)
- if (!SSL_CTX_load_verify_locations(soap->ctx, soap->cafile, soap->capath))
- return soap_set_receiver_error(soap, "SSL error", "Can't read CA file and/or directory", SOAP_SSL_ERROR);
- if (!SSL_CTX_set_default_verify_paths(soap->ctx))
- return soap_set_receiver_error(soap, "SSL error", "Can't read default CA file and/or directory", SOAP_SSL_ERROR);
- if (soap->keyfile)
- { if (!SSL_CTX_use_certificate_chain_file(soap->ctx, soap->keyfile))
- return soap_set_receiver_error(soap, "SSL error", "Can't read certificate key file", SOAP_SSL_ERROR);
- if (soap->password)
- { SSL_CTX_set_default_passwd_cb_userdata(soap->ctx, (void*)soap->password);
- SSL_CTX_set_default_passwd_cb(soap->ctx, ssl_password);
- if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM))
- return soap_set_receiver_error(soap, "SSL error", "Can't read key file", SOAP_SSL_ERROR);
- }
- }
- if (soap->rsa)
- { RSA *rsa = RSA_generate_key(512, RSA_F4, NULL, NULL);
- if (!SSL_CTX_set_tmp_rsa(soap->ctx, rsa))
- { if (rsa)
- RSA_free(rsa);
- return soap_set_receiver_error(soap, "SSL error", "Can't set RSA key", SOAP_SSL_ERROR);
- }
- RSA_free(rsa);
- }
- else if (soap->dhfile)
- { DH *dh = 0;
- BIO *bio;
- bio = BIO_new_file(soap->dhfile, "r");
- if (!bio)
- return soap_set_receiver_error(soap, "SSL error", "Can't read DH file", SOAP_SSL_ERROR);
- dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- if (SSL_CTX_set_tmp_dh(soap->ctx, dh) < 0)
- { if (dh)
- DH_free(dh);
- return soap_set_receiver_error(soap, "SSL error", "Can't set DH parameters", SOAP_SSL_ERROR);
- }
- DH_free(dh);
- }
- SSL_CTX_set_options(soap->ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2);
- SSL_CTX_set_verify(soap->ctx, soap->require_client_auth ? (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT) : soap->require_server_auth ? SSL_VERIFY_PEER : SSL_VERIFY_NONE, soap->fsslverify);
-#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
- SSL_CTX_set_verify_depth(soap->ctx, 1);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_verify_callback(int ok, X509_STORE_CTX *store)
-{
-#ifdef SOAP_DEBUG
- if (!ok)
- { char data[256];
- X509 *cert = X509_STORE_CTX_get_current_cert(store);
- fprintf(stderr, "SSL Verify error with certificate at depth %d: %s\n", X509_STORE_CTX_get_error_depth(store), X509_verify_cert_error_string(X509_STORE_CTX_get_error(store)));
- X509_NAME_oneline(X509_get_issuer_name(cert), data, sizeof(data));
- fprintf(stderr, "certificate issuer %s\n", data);
- X509_NAME_oneline(X509_get_subject_name(cert), data, sizeof(data));
- fprintf(stderr, "certificate subject %s\n", data);
- }
-#endif
- return ok;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_accept(struct soap *soap)
-{ int i, r;
- if (!soap_valid_socket(soap->socket))
- return soap_set_receiver_error(soap, "SSL error", "No socket in soap_ssl_accept()", SOAP_SSL_ERROR);
- if (!soap->ssl)
- { soap->ssl = SSL_new(soap->ctx);
- if (!soap->ssl)
- return soap_set_receiver_error(soap, "SSL error", "SSL_new() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
- }
- else
- SSL_clear(soap->ssl);
- soap->imode |= SOAP_ENC_SSL;
- soap->omode |= SOAP_ENC_SSL;
-#ifdef WIN32
- u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &nonblocking);
-#else
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)|O_NONBLOCK);
-#endif
- soap->bio = BIO_new_socket((SOAP_SOCKET)soap->socket, BIO_NOCLOSE);
- SSL_set_bio(soap->ssl, soap->bio, soap->bio);
- i = 100;
- while ((r = SSL_accept(soap->ssl)) <= 0)
- { int err = SSL_get_error(soap->ssl, r);
- if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
- { struct timeval timeout;
- fd_set fd;
- if (i-- <= 0)
- break;
- timeout.tv_sec = 0;
- timeout.tv_usec = 100000;
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r < 0 && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- }
- else
- { soap->errnum = err;
- break;
- }
- }
-#ifdef WIN32
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking);
- }
-#else
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)&~O_NONBLOCK);
-#endif
- if (r <= 0)
- { soap_set_receiver_error(soap, ssl_error(soap, r), "SSL_accept() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
- soap_closesock(soap);
- return SOAP_SSL_ERROR;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#endif /* WITH_OPENSSL */
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-tcp_init(struct soap *soap)
-{ soap->errmode = 1;
-#ifdef WIN32
- if (tcp_done)
- return 0;
- else
- { WSADATA w;
- if (WSAStartup(MAKEWORD(1, 1), &w))
- return -1;
- tcp_done = 1;
- }
-#endif
-#ifdef PALM
- errno = 0;
- h_errno = 0;
- AppNetRefnum = 0;
- NetUInit();
- AppNetTimeout = 10000;
- NetLibOpen(AppNetRefnum, &h_errno);
-#endif
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_done(struct soap *soap)
-{
-#ifndef WITH_LEAN
- int i;
-#endif
- soap_free(soap);
- while (soap->clist)
- { struct soap_clist *p = soap->clist->next;
- SOAP_FREE(soap->clist);
- soap->clist = p;
- }
- soap->keep_alive = 0; /* to force close the socket */
- soap_closesock(soap);
-#ifdef WITH_COOKIES
- soap_free_cookies(soap);
-#endif
- while (soap->plugins)
- { register struct soap_plugin *p = soap->plugins->next;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Removing plugin '%s'\n", soap->plugins->id));
- if (soap->plugins->fcopy || !soap->copy)
- soap->plugins->fdelete(soap, soap->plugins);
- SOAP_FREE(soap->plugins);
- soap->plugins = p;
- }
- soap->fplugin = fplugin;
- soap->fpost = http_post;
- soap->fget = http_get;
- soap->fposthdr = http_post_header;
- soap->fresponse = http_response;
- soap->fparse = http_parse;
- soap->fparsehdr = http_parse_header;
-#ifndef MAC_CARBON
- soap->faccept = tcp_accept;
- soap->fopen = tcp_connect;
- soap->fclose = tcp_disconnect;
- soap->fsend = fsend;
- soap->frecv = frecv;
-#endif
- soap->fprepare = NULL;
- soap->fignore = NULL;
-#ifdef WITH_OPENSSL
- if (soap->session)
- { SSL_SESSION_free(soap->session);
- soap->session = NULL;
- }
-#endif
- if (!soap->copy)
- { if (soap_valid_socket(soap->master))
- { closesocket((SOAP_SOCKET)soap->master);
- soap->master = SOAP_INVALID_SOCKET;
- }
-#ifdef WITH_OPENSSL
- if (soap->ctx)
- { SSL_CTX_free(soap->ctx);
- soap->ctx = NULL;
- }
-#endif
- }
-#ifndef WITH_LEAN
- for (i = 0; i < SOAP_MAXLOGS; i++)
- { soap_close_logfile(soap, i);
- if (soap->logfile[i])
- { SOAP_FREE((void*)soap->logfile[i]);
- soap->logfile[i] = NULL;
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_cleanup(struct soap *soap)
-{ soap_done(soap);
-#ifdef WIN32
- if (!tcp_done)
- return;
- tcp_done = 0;
- WSACleanup();
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-tcp_error(struct soap *soap)
-{ register const char *msg = NULL;
- switch (soap->errmode)
- { case 0:
- msg = soap_strerror(soap);
- break;
- case 1:
- msg = "WSAStartup failed";
- break;
- case 2:
- {
-#ifndef WITH_LEAN
- msg = soap_str_code(h_error_codes, soap->errnum);
- if (!msg)
-#endif
- { sprintf(soap->msgbuf, "TCP error %d", soap->errnum);
- msg = soap->msgbuf;
- }
- }
- }
- return msg;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-http_error(struct soap *soap, int status)
-{ register const char *msg = NULL;
-#ifndef WITH_LEAN
- msg = soap_str_code(h_http_error_codes, status);
- if (!msg)
-#endif
- { sprintf(soap->msgbuf, "HTTP error %d", status);
- msg = soap->msgbuf;
- }
- return msg;
-}
-#endif
-
-/******************************************************************************/
-/* WR[ */
-#ifndef WITH_IPV6
-/* ]WR */
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-soap_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr)
-{ unsigned long iadd;
- struct hostent hostent, *host = &hostent;
-/* WR[ */
-#ifdef VXWORKS
- int hostint;
- char * addrcopy = (char*)malloc(strlen(addr) + 1); /*copy of addr. */
- /* inet_addr(), and hostGetByName() expect "char *"; addr is a "const char *". */
- strncpy(addrcopy, addr, strlen(addr)+1);
- iadd = inet_addr(addrcopy);
-#else
-/* ]WR */
-#if defined(_AIXVERSION_431) || defined(TRU64)
- struct hostent_data ht_data;
-#endif
- iadd = inet_addr(addr);
-/* WR[ */
-#endif
-/* ]WR */
- if ((int)iadd != -1)
- { memcpy(inaddr, &iadd, sizeof(iadd));
-/* WR[ */
-#ifdef VXWORKS
- free(addrcopy);
-#endif
-/* ]WR */
- return 0;
- }
-#if defined(__GLIBC__)
- if (gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &host, &soap->errnum) < 0)
- host = NULL;
-#elif defined(_AIXVERSION_431) || defined(TRU64)
- memset(&ht_data, 0, sizeof(ht_data));
- if (gethostbyname_r(addr, &hostent, &ht_data) < 0)
- { host = NULL;
- soap->errnum = h_errno;
- }
-#elif defined(HAVE_GETHOSTBYNAME_R)
- host = gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &soap->errnum);
-/* WR[ */
-#elif defined(VXWORKS)
- /* If the DNS resolver library resolvLib has been configured in the vxWorks
- * image, a query for the host IP address is sent to the DNS server, if the
- * name was not found in the local host table. */
- hostint = hostGetByName(addrcopy);
- if (hostint == ERROR)
- {
- host = NULL;
- soap->errnum = soap_errno;
- }
- free(addrcopy); /*free() is placed after the error checking to assure that
- * errno captured is that from hostGetByName() */
-/* ]WR */
-#else
- if (!(host = gethostbyname(addr)))
- soap->errnum = h_errno;
-#endif
- if (!host)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Host name not found\n"));
- return -1;
- }
-/* WR[ */
-#ifdef VXWORKS
- inaddr->s_addr = hostint;
-#else
-/* ]WR */
- memcpy(inaddr, host->h_addr, host->h_length);
-/* WR[ */
-#endif
-/* ]WR */
- return 0;
-}
-#endif
-#endif
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port)
-{ struct sockaddr_in sockaddr;
-/* WR[ */
-#ifdef WITH_IPV6
- struct addrinfo *addrinfo;
- struct addrinfo hints;
- struct addrinfo resaddr;
- struct sockaddr_storage addrstorage;
- int err;
-#endif /* WITH_IPV6 */
-/* ]WR */
- register int fd;
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- if (soap_valid_socket(soap->socket))
- closesocket((SOAP_SOCKET)soap->socket);
- soap->socket = SOAP_INVALID_SOCKET;
- if (tcp_init(soap))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP initialization failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- soap->errmode = 0;
-/* WR[ */
-#ifdef WITH_IPV6
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- soap->errmode = 2;
- if (soap->proxy_host)
- err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &addrinfo);
- else
- err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
- if (addrinfo)
- { resaddr = *addrinfo;
- addrstorage = *((struct sockaddr_storage *) addrinfo->ai_addr);
- resaddr.ai_addr = (struct sockaddr *) &addrstorage;
- freeaddrinfo(addrinfo);
- }
- if (err)
- { soap_set_sender_error(soap, gai_strerror(err),
- "TCP getaddrinfo on proxy host failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- fd = (int)socket(resaddr.ai_family, resaddr.ai_socktype, resaddr.ai_protocol); /* modified to use fd */
- soap->errmode = 0;
-#else /* WITH_IPV6 */
-/* ]WR */
- fd = (int)socket(AF_INET, SOCK_STREAM, 0);
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- if (fd < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP socket failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifndef WITH_LEAN
- if (soap->connect_flags & SO_LINGER)
- { struct linger linger;
- memset(&linger, 0, sizeof(struct linger));
- linger.l_onoff = 1;
- linger.l_linger = 0;
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- }
- if ((soap->connect_flags & ~SO_LINGER) && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, soap->connect_flags & ~SO_LINGER, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
-#endif
-#endif
-/* WR[ */
-#ifndef WITH_IPV6
-/* ]WR */
- memset(&sockaddr, 0, sizeof(sockaddr));
- sockaddr.sin_family = AF_INET;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Open socket %d to host='%s'\n", fd, host));
- soap->errmode = 2;
- if (soap->proxy_host)
- { if (soap_gethost(soap, soap->proxy_host, &sockaddr.sin_addr))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- sockaddr.sin_port = htons((short)soap->proxy_port);
- }
- else
- { if (soap_gethost(soap, host, &sockaddr.sin_addr))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP get host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- sockaddr.sin_port = htons((short)port);
- }
- soap->errmode = 0;
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#if defined(WIN32)
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- {
- vx_nonblocking = TRUE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK);
-#endif
- else
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- {
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- for (;;)
- {
-/* WR[ */
-#ifdef WITH_IPV6
- if (connect((SOAP_SOCKET)fd, resaddr.ai_addr, resaddr.ai_addrlen)) /* modified to use fd */
-#else /* WITH_IPV6 */
- if (connect((SOAP_SOCKET)fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)))
-#endif /* WITH_IPV6 */
-/* ]WR */
- {
-#ifndef WITH_LEAN
- if (soap->connect_timeout && (soap_socket_errno == SOAP_EINPROGRESS || soap_socket_errno == SOAP_EWOULDBLOCK))
- { struct timeval timeout;
-#if defined(SOCKLEN_T)
- SOCKLEN_T n = sizeof(struct sockaddr_in);
-#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN)
- socklen_t n = sizeof(struct sockaddr_in);
-#elif defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)
- int n = sizeof(struct sockaddr_in);
-#else
- size_t n = sizeof(struct sockaddr_in);
-#endif
- fd_set fds;
- if (soap->connect_timeout > 0)
- { timeout.tv_sec = soap->connect_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->connect_timeout/1000000;
- timeout.tv_usec = -soap->connect_timeout%1000000;
- }
- FD_ZERO(&fds);
- FD_SET((SOAP_SOCKET)fd, &fds);
- for (;;)
- { int r = select((SOAP_SOCKET)(fd + 1), NULL, &fds, NULL, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
- soap_set_sender_error(soap, "Timeout", "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- }
- n = sizeof(soap->errnum);
- if (!getsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &n) && !soap->errnum)
- break;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- else
-#endif
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- closesocket((SOAP_SOCKET)fd);
- return -1;
- }
- }
- else
- break;
- }
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- {
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- soap->socket = fd;
-#ifdef WITH_OPENSSL
- soap->imode &= ~SOAP_ENC_SSL;
- soap->omode &= ~SOAP_ENC_SSL;
- if (!strncmp(endpoint, "https:", 6))
- { int r;
- if (soap->proxy_host)
- { unsigned int k = soap->omode; /* make sure we only parse HTTP */
- size_t n = soap->count; /* save the content length */
- soap->omode &= ~0xFF; /* mask IO and ENC */
- soap->omode |= SOAP_IO_BUFFER;
- soap_begin_send(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to proxy server\n"));
- sprintf(soap->tmpbuf, "CONNECT %s:%d HTTP/%s", host, port, soap->http_version);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return -1;
-#ifndef WITH_LEAN
- if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((soap->error = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
- return soap->error;
- }
-#endif
- if ((soap->error = soap->fposthdr(soap, NULL, NULL))
- || soap_flush(soap))
- return -1;
- soap->omode = k;
- k = soap->imode;
- soap->imode &= ~0xFF; /* mask IO and ENC */
- if (soap_begin_recv(soap))
- return -1;
- soap->imode = k;
- soap->count = n;
- soap_begin_send(soap);
- }
- if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
- { soap_set_sender_error(soap, "SSL error", "SSL authentication failed in tcp_connect(): check password, key file, and ca file.", SOAP_SSL_ERROR);
- return -1;
- }
- soap->ssl = SSL_new(soap->ctx);
- if (!soap->ssl)
- { soap->error = SOAP_SSL_ERROR;
- return -1;
- }
- if (soap->session)
- { if (!strcmp(soap->session_host, host) && soap->session_port == port)
- SSL_set_session(soap->ssl, soap->session);
- SSL_SESSION_free(soap->session);
- soap->session = NULL;
- }
- soap->imode |= SOAP_ENC_SSL;
- soap->omode |= SOAP_ENC_SSL;
- soap->bio = BIO_new_socket((SOAP_SOCKET)fd, BIO_NOCLOSE);
- SSL_set_bio(soap->ssl, soap->bio, soap->bio);
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#ifdef WIN32
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking);
- }
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK);
-#endif
-#endif
- for (;;)
- { if ((r = SSL_connect(soap->ssl)) <= 0)
- { int err = SSL_get_error(soap->ssl, r);
- if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- { soap_set_sender_error(soap, ssl_error(soap, r), "SSL connect failed in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- if (soap->connect_timeout)
- { struct timeval timeout;
- fd_set fds;
- if (soap->connect_timeout > 0)
- { timeout.tv_sec = soap->connect_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->connect_timeout/1000000;
- timeout.tv_usec = -soap->connect_timeout%1000000;
- }
- FD_ZERO(&fds);
- FD_SET((SOAP_SOCKET)(soap->socket), &fds);
- for (;;)
- { int r = select((SOAP_SOCKET)(soap->socket + 1), &fds, NULL, &fds, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
- soap_set_sender_error(soap, "Timeout", "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- continue;
- }
- }
- break;
- }
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#ifdef WIN32
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- if (soap->require_server_auth)
- { X509 *peer;
- int err;
- if ((err = SSL_get_verify_result(soap->ssl)) != X509_V_OK)
- { soap_set_sender_error(soap, X509_verify_cert_error_string(err), "SSL certificate cannot be verified in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- peer = SSL_get_peer_certificate(soap->ssl);
- if (!peer)
- { soap_set_sender_error(soap, "SSL error", "No SSL certificate was presented by the peer in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName, soap->msgbuf, sizeof(soap->msgbuf));
- X509_free(peer);
- if (soap_tag_cmp(soap->msgbuf, host))
- { soap_set_sender_error(soap, "SSL error", "SSL certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- }
- }
-#endif
- return fd;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_bind(struct soap *soap, const char *host, int port, int backlog)
-{ struct sockaddr_in sockaddr;
-/* WR[ */
-#ifdef WITH_IPV6
- struct addrinfo *addrinfo;
- struct addrinfo hints;
- struct addrinfo resaddr;
- struct sockaddr_storage addrstorage;
- int err;
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- if (soap_valid_socket(soap->master))
- { closesocket((SOAP_SOCKET)soap->master);
- soap->master = SOAP_INVALID_SOCKET;
- }
- soap->socket = SOAP_INVALID_SOCKET;
- soap->errmode = 1;
- if (tcp_init(soap))
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP init failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#ifdef WITH_IPV6
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_PASSIVE;
- soap->errmode = 2;
- if (host)
- err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
- else
- err = getaddrinfo(NULL, soap_int2s(soap, port), &hints, &addrinfo);
- if (NULL != addrinfo)
- {
- resaddr = *addrinfo;
- addrstorage = *((struct sockaddr_storage *) addrinfo->ai_addr);
- resaddr.ai_addr = (struct sockaddr *) &addrstorage;
- freeaddrinfo(addrinfo);
- }
- if (err)
- { soap_set_receiver_error(soap, gai_strerror(err), "TCP getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- soap->errmode = 0;
- if ((soap->master = socket(resaddr.ai_family, resaddr.ai_socktype, resaddr.ai_protocol)) < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP socket failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- soap->errmode = 0;
- if ((soap->master = (int)socket(AF_INET, SOCK_STREAM, 0)) < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP socket failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- if (soap->bind_flags && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, soap->bind_flags, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)soap->master, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#endif
-#endif
-/* WR[ */
-#ifdef WITH_IPV6
- soap->errmode = 0;
- if (bind(soap->master, resaddr.ai_addr, resaddr.ai_addrlen) || listen(soap->master, backlog))
- {
- soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
- soap_closesock(soap);
- soap_set_receiver_error(soap, tcp_error(soap), "TCP bind failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- memset(&sockaddr, 0, sizeof(sockaddr));
- sockaddr.sin_family = AF_INET;
- soap->errmode = 2;
- if (host)
- { if (soap_gethost(soap, host, &sockaddr.sin_addr))
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP get host by name failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- else
- sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
- sockaddr.sin_port = htons((short)port);
- soap->errmode = 0;
- if (bind((SOAP_SOCKET)soap->master, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) || listen((SOAP_SOCKET)soap->master, backlog))
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
- soap_closesock(soap);
- soap_set_receiver_error(soap, tcp_error(soap), "TCP bind failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifdef WITH_OPENSSL
- if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
- return -1;
-#endif
- return soap->master;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_poll(struct soap *soap)
-{
-#ifndef WITH_LEAN
- struct timeval timeout;
- fd_set sfd,rfd;
- int r;
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- FD_ZERO(&rfd);
- FD_ZERO(&sfd);
- if (soap->socket >= 0)
- { FD_SET(soap->socket, &rfd);
- FD_SET(soap->socket, &sfd);
- r = select(soap->socket + 1, &rfd, &sfd, NULL, &timeout);
- }
- else if (soap->master >= 0)
- { FD_SET(soap->master, &rfd);
- r = select(soap->master + 1, &rfd, &sfd, NULL, &timeout);
- }
- else
- { FD_SET(soap->sendfd, &sfd);
- FD_SET(soap->recvfd, &rfd);
- r = select((soap->sendfd > soap->recvfd ? soap->sendfd : soap->recvfd) + 1, &rfd, &sfd, NULL, &timeout);
- }
- if (r > 0)
- {
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { if ((soap->socket >= 0) && FD_ISSET(soap->socket, &rfd))
- { char buf = '\0';
- if (SSL_peek(soap->ssl, &buf, 1) <= 0)
- return SOAP_EOF;
- }
- }
-#endif
- return SOAP_OK;
- }
- if (r < 0 && (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "select failed in soap_poll()", SOAP_TCP_ERROR);
- return soap->error = SOAP_TCP_ERROR;
- }
- else
- soap->errnum = soap_errno;
- return SOAP_EOF;
-#else
- return SOAP_OK;
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_accept(struct soap *soap, int s, struct sockaddr *a, int *n)
-{
-#if defined(SOCKLEN_T)
- return (int)accept((SOAP_SOCKET)s, a, (SOCKLEN_T*)n);
-#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN)
- return (int)accept((SOAP_SOCKET)s, a, (socklen_t*)n);
-#elif defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)
- return (int)accept((SOAP_SOCKET)s, a, n);
-#else
- return (int)accept((SOAP_SOCKET)s, a, (size_t*)n);
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_accept(struct soap *soap)
-{
-/* WR[ */
-#ifdef WITH_IPV6
- struct sockaddr_storage sockaddr;
-#else /* WITH_IPV6 */
-/* ]WR */
- struct sockaddr_in sockaddr;
-/* WR[ */
-#endif
-/* ]WR */
- int n = (int)sizeof(struct sockaddr);
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- memset(&sockaddr, 0, sizeof(sockaddr));
- soap->socket = SOAP_INVALID_SOCKET;
- soap->errmode = 0;
- if (soap_valid_socket(soap->master))
- { for (;;)
- {
-#ifndef WITH_LEAN
- if (soap->accept_timeout)
- { struct timeval timeout;
- fd_set fd;
- if (soap->accept_timeout > 0)
- { timeout.tv_sec = soap->accept_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->accept_timeout/1000000;
- timeout.tv_usec = -soap->accept_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->master, &fd);
- for (;;)
- { int r = select((SOAP_SOCKET)(soap->master + 1), &fd, &fd, NULL, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- soap_set_receiver_error(soap, "Timeout", "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- soap_closesock(soap);
- soap_set_sender_error(soap, tcp_error(soap), "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
-#if defined(WIN32)
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &nonblocking);
- }
-#elif defined(VXWORKS)
- { vx_nonblocking = TRUE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- }
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)|O_NONBLOCK);
-#endif
- }
- else
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- {
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- if ((soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&sockaddr, &n)) >= 0)
- {
-/* WR[ */
-#ifdef WITH_IPV6
-/* Use soap->host to store the numeric form of the remote host */
- getnameinfo((struct sockaddr*)&sockaddr, n, soap->host, sizeof(soap->host), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV);
- soap->ip = 0; /* info stored in soap->host */
- soap->port = 0; /* info stored in soap->host */
-#else /* WITH_IPV6 */
-/* ]WR */
- soap->ip = ntohl(sockaddr.sin_addr.s_addr);
- soap->port = (int)ntohs(sockaddr.sin_port);
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- soap->keep_alive = ((soap->imode & SOAP_IO_KEEPALIVE) != 0);
-#ifndef WITH_LEAN
- if (soap->accept_flags & SO_LINGER)
- { struct linger linger;
- memset(&linger, 0, sizeof(struct linger));
- linger.l_onoff = 1;
- linger.l_linger = 0;
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- if ((soap->accept_flags & ~SO_LINGER) && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, soap->accept_flags & ~SO_LINGER, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-#endif
-#endif
- if (soap->accept_timeout)
- {
-#if defined(WIN32)
- u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &blocking);
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking);
-/* WR[ */
-#elif defined(VXWORKS)
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)(&vx_nonblocking));
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK);
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)&~O_NONBLOCK);
-#endif
- }
- return soap->socket;
- }
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- }
- else
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP no master socket in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_disconnect(struct soap *soap)
-{
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { int r, s = 0;
- if (soap->session)
- SSL_SESSION_free(soap->session);
- if (*soap->host)
- { soap->session = SSL_get1_session(soap->ssl);
- if (soap->session)
- { strcpy(soap->session_host, soap->host);
- soap->session_port = soap->port;
- }
- }
- r = SSL_shutdown(soap->ssl);
- if (r != 1)
- { s = ERR_get_error();
- if (s)
- { if (soap_valid_socket(soap->socket))
- { shutdown((SOAP_SOCKET)soap->socket, 1);
- soap->socket = SOAP_INVALID_SOCKET;
- }
- r = SSL_shutdown(soap->ssl);
- }
- }
- DBGLOG(TEST, if (s) SOAP_MESSAGE(fdebug, "Shutdown failed: %d\n", SSL_get_error(soap->ssl, r)));
- SSL_free(soap->ssl);
- soap->ssl = NULL;
- if (s)
- return SOAP_SSL_ERROR;
- ERR_remove_state(0);
- }
-#endif
- if (soap_valid_socket(soap->socket))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Closing socket %d\n", soap->socket));
- shutdown((SOAP_SOCKET)soap->socket, 2);
- closesocket((SOAP_SOCKET)soap->socket);
- soap->socket = SOAP_INVALID_SOCKET;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_closesock(struct soap *soap)
-{ register int status = soap->error;
-#ifndef MAC_CARBON
- if (status == SOAP_EOF || !soap->keep_alive)
- { if ((soap->error = soap->fclose(soap)))
- return soap->error;
- soap->socket = SOAP_INVALID_SOCKET;
- }
-#endif
-#ifdef WITH_ZLIB
- if (soap->zlib_state == SOAP_ZLIB_DEFLATE)
- deflateEnd(&soap->d_stream);
- else if (soap->zlib_state == SOAP_ZLIB_INFLATE)
- inflateEnd(&soap->d_stream);
- soap->zlib_state = SOAP_ZLIB_NONE;
-#endif
- return soap->error = status;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_hash(register const char *s)
-{ register int h = 0;
- while (*s)
- h += *s++ & 0x1F;
- return h % SOAP_IDHASH;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_init_pht(struct soap *soap)
-{ register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing pointer hashtable\n"));
- for (i = 0; i < SOAP_PTRHASH; i++)
- soap->pht[i] = NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new()
-{ struct soap *soap = (struct soap*)SOAP_MALLOC(sizeof(struct soap));
- if (soap)
- soap_init(soap);
- return soap;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new1(int mode)
-{ return soap_new2(mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new2(int imode, int omode)
-{ struct soap *soap = (struct soap*)SOAP_MALLOC(sizeof(struct soap));
- if (soap)
- soap_init2(soap, imode, omode);
- return soap;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-soap_free_pht(struct soap *soap)
-{ register struct soap_plist *pp, *next;
- register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n"));
- for (i = 0; i < SOAP_PTRHASH; i++)
- { for (pp = soap->pht[i]; pp; pp = next)
- { next = pp->next;
- SOAP_FREE(pp);
- }
- soap->pht[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embed_element(struct soap *soap, const void *p, const char *tag, int type)
-{ register int i;
- struct soap_plist *pp;
- if (soap->version != 1)
- soap->encoding = 1;
- if ((i = soap_pointer_lookup(soap, p, type, &pp)))
- { if (soap_is_embedded(soap, pp) || soap_is_single(soap, pp))
- return 0;
- soap_set_embedded(soap, pp);
- }
- return i;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embed_array(struct soap *soap, const void *p, const struct soap_array *a, int n, const char *tag, int type)
-{ register int i;
- struct soap_plist *pp;
- if (soap->version != 1)
- soap->encoding = 1;
- if ((i = soap_array_pointer_lookup(soap, p, a, n, type, &pp)))
- { if (soap_is_embedded(soap, pp) || soap_is_single(soap, pp))
- return 0;
- soap_set_embedded(soap, pp);
- }
- return i;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pointer_lookup(struct soap *soap, const void *p, int type, struct soap_plist **ppp)
-{ register struct soap_plist *pp;
- *ppp = NULL;
- if (p)
- for (pp = soap->pht[soap_hash_ptr(p)]; pp; pp = pp->next)
- if (pp->ptr == p && pp->type == type)
- { *ppp = pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d id=%d\n", p, type, pp->id));
- return pp->id;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d: not found\n", p, type));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_pointer_lookup(struct soap *soap, const void *p, const struct soap_array *a, int n, int type, struct soap_plist **ppp)
-{ struct soap_plist *pp;
- *ppp = NULL;
- if (!p || !a->__ptr)
- return 0;
- for (pp = soap->pht[soap_hash_ptr(a->__ptr)]; pp; pp = pp->next)
- if (pp->type == type && pp->array && pp->array->__ptr == a->__ptr && pp->array->__size == n)
- { *ppp = pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d id=%d\n", a->__ptr, type, pp->id));
- return pp->id;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d: not found\n", a->__ptr, type));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pointer_enter(struct soap *soap, const void *p, int type, struct soap_plist **ppp)
-{ register struct soap_plist *pp;
- if (!p)
- { *ppp = NULL;
- return 0;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enter location=%p type=%d id=%lu\n", p, type, soap->idnum+1));
- *ppp = pp = (struct soap_plist*)SOAP_MALLOC(sizeof(struct soap_plist));
- if (pp)
- { register int h = soap_hash_ptr(p);
- pp->next = soap->pht[h];
- pp->type = type;
- if ((soap->mode & SOAP_XML_TREE) || soap->part == SOAP_IN_HEADER)
- { pp->mark1 = 0;
- pp->mark2 = 0;
- }
- else
- { pp->mark1 = 1;
- pp->mark2 = 1;
- }
- pp->ptr = p;
- pp->array = NULL;
- soap->pht[h] = pp;
- return pp->id = ++soap->idnum;
- }
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_pointer_enter(struct soap *soap, const void *p, const struct soap_array *a, int type, struct soap_plist **ppp)
-{ struct soap_plist *pp;
- *ppp = NULL;
- if (!p || !a->__ptr)
- return 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array enter location=%p size=%d type=%d id=%lu\n", a->__ptr, a->__size, type, soap->idnum+1));
- *ppp = pp = (struct soap_plist*)SOAP_MALLOC(sizeof(struct soap_plist));
- if (pp)
- { register int h = soap_hash_ptr(a->__ptr);
- pp->next = soap->pht[h];
- pp->type = type;
- if ((soap->mode & SOAP_XML_TREE) || soap->part == SOAP_IN_HEADER)
- { pp->mark1 = 0;
- pp->mark2 = 0;
- }
- else
- { pp->mark1 = 1;
- pp->mark2 = 1;
- }
- pp->ptr = p;
- pp->array = a;
- soap->pht[h] = pp;
- return pp->id = ++soap->idnum;
- }
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_begin_count(struct soap *soap)
-{ soap_clr_attr(soap);
- soap_set_local_namespaces(soap);
- if (soap->mode & SOAP_ENC_DIME)
- soap->mode = soap->omode | SOAP_IO_LENGTH | SOAP_ENC_DIME;
- else
- { soap->mode = soap->omode;
- if (((soap->mode & (SOAP_IO_STORE | SOAP_IO_CHUNK)) || (soap->mode & SOAP_ENC_XML)) && !soap->fprepare)
- soap->mode &= ~SOAP_IO_LENGTH;
- else
- soap->mode |= SOAP_IO_LENGTH;
- }
- if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
- { if (!(soap->mode & SOAP_ENC_DIME))
- soap->mode &= ~SOAP_IO_LENGTH;
- if (soap->mode & SOAP_ENC_XML)
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- soap->count = 0;
- soap->ns = 0;
- soap->null = 0;
- soap->position = 0;
- soap->mustUnderstand = 0;
- soap->encoding = 0;
- soap->part = SOAP_BEGIN;
- soap->idnum = 0;
- soap->dime_count = 0; /* count # of attachments */
- soap->dime_size = 0; /* accumulate total size of attachments */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=%hd count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_begin_send(struct soap *soap)
-{ soap_clr_attr(soap);
- soap_set_local_namespaces(soap);
- soap->mode = (soap->omode & ~SOAP_IO_LENGTH) | (soap->mode & SOAP_ENC_DIME);
- if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
- { if (soap->mode & SOAP_ENC_XML)
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket))
- { if (soap->count || (soap->mode & SOAP_ENC_XML))
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- soap_new_block(soap);
- if (!(soap->mode & SOAP_IO_KEEPALIVE))
- soap->keep_alive = 0;
-#ifdef WIN32
-#ifndef UNDER_CE
-#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket)) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
-#ifdef __BORLANDC__
- setmode((SOAP_SOCKET)soap->sendfd, O_BINARY);
-#else
- _setmode((SOAP_SOCKET)soap->sendfd, _O_BINARY);
-#endif
-#endif
-#endif
-#endif
- if (soap->mode & SOAP_IO)
- { soap->bufidx = 0;
- soap->buflen = 0;
- }
- soap->chunksize = 0;
- soap->ns = 0;
- soap->null = 0;
- soap->position = 0;
- soap->mustUnderstand = 0;
- soap->encoding = 0;
- soap->part = SOAP_BEGIN;
- soap->idnum = 0;
- soap->level = 0;
-#ifdef WITH_ZLIB
- soap->z_ratio_out = 1.0;
- if ((soap->mode & SOAP_ENC_ZLIB) && soap->zlib_state != SOAP_ZLIB_DEFLATE)
- {
-#ifdef WITH_GZIP
- memcpy(soap->z_buf, "\37\213\10\0\0\0\0\0\0\377", 10);
- soap->d_stream.next_out = (Byte*)soap->z_buf + 10;
- soap->d_stream.avail_out = SOAP_BUFLEN - 10;
- soap->z_crc = crc32(0L, NULL, 0);
- if (deflateInit2(&soap->d_stream, soap->z_level, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK)
-#else
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- if (deflateInit(&soap->d_stream, soap->z_level) != Z_OK)
-#endif
- return soap->error = SOAP_ZLIB_ERROR;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflate initialized\n"));
- soap->zlib_state = SOAP_ZLIB_DEFLATE;
- }
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin send phase (socket=%d mode=%hd count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_embedded(struct soap *soap, const void *p, int t)
-{ struct soap_plist *pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded %p type=%d\n", p, t));
- if (soap_pointer_lookup(soap, p, t, &pp))
- { pp->mark1 = 1;
- pp->mark2 = 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded %p type=%d set to %d\n", p, t, (int)pp->mark1));
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_reference(struct soap *soap, const void *p, int t)
-{ register int i;
- struct soap_plist *pp;
- if (!p)
- return 1;
- i = soap_pointer_lookup(soap, p, t, &pp);
- if (i)
- { if (pp->mark1 == 0)
- { pp->mark1 = 2;
- pp->mark2 = 2;
- }
- }
- else
- { soap_pointer_enter(soap, p, t, &pp);
- pp->mark1 = 0;
- pp->mark2 = 0;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reference %p type = %d (%d %d)\n", p, t, (int)pp->mark1, (int)pp->mark2));
- return pp->mark1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_reference(struct soap *soap, const void *p, const struct soap_array *a, int n, int t)
-{ register int i;
- struct soap_plist *pp;
- if (!p)
- return 1;
- i = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
- if (i)
- { if (pp->mark1 == 0)
- { pp->mark1 = 2;
- pp->mark2 = 2;
- }
- }
- else if (!soap_array_pointer_enter(soap, p, a, t, &pp))
- return 1;
- pp->mark1 = 0;
- pp->mark2 = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array reference %p ptr=%p size=%d type = %d (%d %d)\n", p, a->__ptr, n, t, (int)pp->mark1, (int)pp->mark2));
- return pp->mark1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embedded_id(struct soap *soap, int id, const void *p, int t)
-{ struct soap_plist *pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id %p type=%d id=%d\n", p, t, id));
- if (soap->version == 1 && soap->encodingStyle && !(soap->mode & (SOAP_XML_TREE | SOAP_XML_GRAPH)) && soap->part != SOAP_IN_HEADER)
- { if (id < 0)
- { id = soap_pointer_lookup(soap, p, t, &pp);
- if (id > 0 && pp)
- { if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 2;
- else
- pp->mark2 = 2;
- }
- return -1;
- }
- return id;
- }
- if (id < 0)
- id = soap_pointer_lookup(soap, p, t, &pp);
- else
- soap_pointer_lookup(soap, p, t, &pp);
- if (id > 0 && pp)
- { if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 1;
- else
- pp->mark2 = 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id id=%d %p type=%d = (%d %d)\n", id, p, t, (int)pp->mark1, (int)pp->mark2));
- }
- return id;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_embedded(struct soap *soap, struct soap_plist *pp)
-{ if (!pp)
- return 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Is embedded? %d %d\n", (int)pp->mark1, (int)pp->mark2));
- if (soap->version == 1 && soap->encodingStyle && !(soap->mode & (SOAP_XML_TREE | SOAP_XML_GRAPH)) && soap->part != SOAP_IN_HEADER)
- { if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 != 0;
- return pp->mark2 != 0;
- }
- if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 1;
- return pp->mark2 == 1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_single(struct soap *soap, struct soap_plist *pp)
-{ if ((soap->mode & SOAP_XML_TREE) || soap->part == SOAP_IN_HEADER)
- return 1;
- if (!pp)
- return 0;
- if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 0;
- return pp->mark2 == 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_multi(struct soap *soap, struct soap_plist *pp)
-{ if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 2;
- return pp->mark2 == 2;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_embedded(struct soap *soap, struct soap_plist *pp)
-{ if (!pp)
- return;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 1;
- else
- pp->mark2 = 1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_attached(struct soap *soap, struct soap_plist *pp, const char *id, const char *type, const char *options, size_t size)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set attached id='%s' type='%s'\n", id?id:"", type?type:""));
- if (soap->mode & SOAP_IO_LENGTH)
- { if (pp->mark1 != 3)
- { pp->mark1 = 3;
- soap->dime_count++; /* one more attachment found */
- soap->dime_size += 12; /* increase total size (DIME fields) */
- if (id)
- soap->dime_size += (strlen(id)+3)&(~3);
- if (type)
- soap->dime_size += (strlen(type)+3)&(~3);
- if (options)
- soap->dime_size += 4 + (((((unsigned char)options[2] << 8 | (unsigned char)options[3]))+3)&(~3));
- soap->dime_size += (size+3)&(~3);
- }
- }
- else if (pp->mark2 != 3)
- pp->mark2 = 3;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_init_iht(struct soap *soap)
-{ register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing ID hashtable\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- soap->iht[i] = NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-soap_free_iht(struct soap *soap)
-{ register int i;
- register struct soap_ilist *ip, *p;
- register struct soap_flist *fp, *q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free ID hashtable\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = p)
- { for (fp = ip->flist; fp; fp = q)
- { q = fp->next;
- SOAP_FREE(fp);
- }
- p = ip->next;
- SOAP_FREE(ip);
- }
- soap->iht[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static struct soap_ilist *
-soap_hlookup(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- for (ip = soap->iht[soap_hash(id)]; ip; ip = ip->next)
- if (!strcmp(ip->id, id))
- return ip;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_ilist *
-SOAP_FMAC2
-soap_lookup(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- ip = soap_hlookup(soap, id);
-#ifndef WITH_LEANER
- if (!ip && *id != '#' && !strchr(id, ':')) /* try content id "cid:" with DIME attachments */
- { char cid[SOAP_TAGLEN];
- strcpy(cid, "cid:");
- strncat(cid + 4, id, sizeof(cid) - 5);
- cid[sizeof(cid) - 1] = '\0';
- ip = soap_hlookup(soap, cid);
- }
-#endif
- return ip;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_ilist *
-SOAP_FMAC2
-soap_enter(struct soap *soap, const char *id)
-{ register int h;
- register struct soap_ilist *ip;
- ip = (struct soap_ilist*)SOAP_MALLOC(sizeof(struct soap_ilist) + strlen(id));
- if (ip)
- { h = soap_hash(id);
- strcpy(ip->id, id);
- ip->next = soap->iht[h];
- soap->iht[h] = ip;
- return ip;
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_malloc(struct soap *soap, size_t n)
-{ register char *p;
- if (!n)
- return NULL;
- if (!soap)
- return SOAP_MALLOC(n);
- n += (-(long)n) & 7;
- if (!(p = (char*)SOAP_MALLOC(n + sizeof(void*) + sizeof(size_t))))
- { soap->error = SOAP_EOM;
- return NULL;
- }
- /* keep chain of alloced cells for later destruction */
- soap->alloced = 1;
- *(void**)(p + n) = soap->alist;
- *(size_t*)(p + n + sizeof(void*)) = n;
- soap->alist = p + n;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Malloc %u bytes at location %p\n", (unsigned int)n, p));
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_dealloc(struct soap *soap, void *p)
-{ if (!soap)
- return;
- if (p)
- { register char **q;
- for (q = (char**)&soap->alist; *q; q = *(char***)q)
- { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
- { *q = **(char***)q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Freed data at %p\n", p));
- SOAP_FREE(p);
- return;
- }
- }
- soap_delete(soap, p);
- }
- else
- { register char *q;
- while (soap->alist)
- { q = (char*)soap->alist;
- soap->alist = *(void**)q;
- q -= *(size_t*)(q + sizeof(void*));
- if (q == (char*)soap->fault)
- soap->fault = NULL; /* this was deallocated */
- else if (q == (char*)soap->header)
- soap->header = NULL; /* this was deallocated */
- SOAP_FREE(q);
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Dealloc all data done\n"));
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_delete(struct soap *soap, void *p)
-{ register struct soap_clist **cp = &soap->clist;
- if (p)
- { while (*cp)
- { if (p == (*cp)->ptr)
- { register struct soap_clist *q = *cp;
- *cp = q->next;
- q->fdelete(q);
- SOAP_FREE(q);
- return;
- }
- cp = &(*cp)->next;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: address not in list\n", p));
- }
- else
- { while (*cp)
- { register struct soap_clist *q = *cp;
- *cp = q->next;
- if (q->ptr == (void*)soap->fault)
- soap->fault = NULL; /* this was deallocated */
- else if (q->ptr == (void*)soap->header)
- soap->header = NULL; /* this was deallocated */
- q->fdelete(q);
- SOAP_FREE(q);
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_clist *
-SOAP_FMAC2
-soap_link(struct soap *soap, void *p, int t, int n, void (*fdelete)(struct soap_clist*))
-{ register struct soap_clist *cp;
- if ((cp = (struct soap_clist*)SOAP_MALLOC(sizeof(struct soap_clist))))
- { cp->next = soap->clist;
- cp->type = t;
- cp->size = n;
- cp->ptr = p;
- cp->fdelete = fdelete;
- soap->clist = cp;
- }
- return cp;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_unlink(struct soap *soap, const void *p)
-{ register char **q;
- register struct soap_clist **cp;
- if (!soap || !p)
- return;
- for (q = (char**)&soap->alist; *q; q = *(char***)q)
- { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
- { *q = **(char***)q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked data %p\n", p));
- return;
- }
- }
- for (cp = &soap->clist; *cp; cp = &(*cp)->next)
- { if (p == (*cp)->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked class instance %p\n", p));
- q = (char**)*cp;
- *cp = (*cp)->next;
- SOAP_FREE(q);
- return;
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_lookup_type(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- if (*id)
- { ip = soap_lookup(soap, id);
- if (ip)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup id='%s' type=%d\n", id, ip->type));
- return ip->type;
- }
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "lookup type id='%s' NOT FOUND! Need to get it from xsi:type\n", id));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_lookup(struct soap *soap, const char *id, void **p, int t, size_t n, unsigned int k)
-{ struct soap_ilist *ip;
- void **q;
- if (*id == '\0')
- return p;
- soap->alloced = 0;
- if (!p)
- p = (void**)soap_malloc(soap, sizeof(void*));
- ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
- if (!ip)
- { ip = soap_enter(soap, id); /* new hash table entry for string id */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding first href='%s' %p (%u bytes)\n", id, p, (unsigned int)n));
- ip->type = t;
- ip->size = n;
- ip->link = p;
- ip->copy = NULL;
- ip->flist = NULL;
- ip->ptr = NULL;
- ip->level = k;
- *p = NULL;
- }
- else if (!soap->blist && ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolved href='%s' type='%d' (%u bytes)\n", id, t, (unsigned int)n));
- if (ip->type != t)
- { soap->error = SOAP_HREF;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Object mismatch: id's type='%d' href's type='%d'\n", ip->type, t));
- return NULL;
- }
- while (ip->level < k)
- { q = (void**)soap_malloc(soap, sizeof(void*));
- if (!q)
- return NULL;
- *p = (void*)q;
- p = q;
- k--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- *p = ip->ptr;
- }
- else if (ip->level > k)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving level %u pointers to href='%s'\n", ip->level, id));
- while (ip->level > k)
- { void *s, **r = &ip->link;
- q = (void**)ip->link;
- while (q)
- { *r = (void*)soap_malloc(soap, sizeof(void*));
- s = *q;
- *q = *r;
- r = *(void***)q;
- q = (void**)s;
- }
- *r = NULL;
- ip->size = n;
- ip->copy = NULL;
- ip->level = ip->level - 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- q = (void**)ip->link;
- ip->link = p;
- *p = (void*)q;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarded href='%s' (%u bytes)\n", id, (unsigned int)n));
- while (ip->level < k)
- { q = (void**)soap_malloc(soap, sizeof(void*));
- *p = q;
- p = q;
- k--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- q = (void**)ip->link;
- ip->link = p;
- *p = (void*)q;
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_forward(struct soap *soap, const char *href, void *p, int t, size_t n)
-{ struct soap_ilist *ip;
- if (!p || !*href)
- return p;
- ip = soap_lookup(soap, soap->href); /* lookup pointer to hash table entry for string id */
- if (!ip)
- { if (n >= sizeof(void*))
- { ip = soap_enter(soap, href); /* new hash table entry for string id */
- ip->type = t;
- ip->size = n;
- ip->link = NULL;
- ip->copy = p;
- ip->flist = NULL;
- *(void**)p = NULL;
- ip->ptr = NULL;
- ip->level = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding first copying address %p for type %d href='%s'\n", p, t, href));
- return p;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding problem: copying location %p too small (%u) for href='%s'\n", p, (unsigned int)n, href));
- soap->error = SOAP_HREF;
- return NULL;
- }
- else if (ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying value from location %p to location %p to resolve href='%s'\n", ip->ptr, p, href));
- memcpy(p, ip->ptr, n);
- }
- else if (n >= sizeof(void*))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding copying address %p for type %d href='%s' (prev in chain = %p)\n", p, t, href, ip->copy));
- *(void**)p = ip->copy;
- ip->copy = p;
- return p;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding problem: copying location %p too small (%u) for href='%s'\n", p, (unsigned int)n, href));
- soap->error = SOAP_HREF; /* href to object too small to hold pointer */
- return NULL;
- }
- return ip->ptr;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_enter(struct soap *soap, const char *id, void *p, int t, size_t n, int k)
-{ struct soap_ilist *ip;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Enter id='%s' type=%d loc=%p size=%d level=%d\n", id, t, p, (int)n, k));
- soap->alloced = 0;
- if (*id == '\0')
- { if (!p)
- return soap_malloc(soap, n);
- else
- return p;
- }
- ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Lookup entry id='%s'\n", id));
- if (!ip)
- { ip = soap_enter(soap, id); /* new hash table entry for string id */
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "New entry id='%s' type=%d size=%u\n", id, t, (unsigned int)n));
- ip->type = t;
- ip->size = n;
- ip->link = NULL;
- ip->copy = NULL;
- ip->flist = NULL;
- if (!p)
- p = soap_malloc(soap, n);
- ip->ptr = p;
- ip->level = k;
- }
- else if (ip->ptr) /* storage address was forwarded */
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Multiply defined id='%s'\n", id));
- if (p)
- { soap->error = SOAP_MULTI_ID;
- return NULL;
- }
- }
- else
- { if (!p)
- p = soap_malloc(soap, n);
- ip->ptr = p;
- if (!soap->blist)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolve link chain to point to %p\n", ip->ptr));
- soap_resolve_ptr(ip);
- }
- }
- return ip->ptr;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_end_send(struct soap *soap)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End send\n"));
- if (soap->mode & SOAP_IO) /* need to flush the remaining data in buffer */
- { if (soap_flush(soap))
-#ifdef WITH_ZLIB
- { if (soap->mode & SOAP_ENC_ZLIB && soap->zlib_state == SOAP_ZLIB_DEFLATE)
- { soap->zlib_state = SOAP_ZLIB_NONE;
- deflateEnd(&soap->d_stream);
- }
- return soap->error;
- }
-#else
- return soap->error;
-#endif
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { int r;
- soap->d_stream.avail_in = 0;
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating remainder\n"));
- r = deflate(&soap->d_stream, Z_FINISH);
- if (soap->d_stream.avail_out != SOAP_BUFLEN)
- { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN - soap->d_stream.avail_out))
- { soap->zlib_state = SOAP_ZLIB_NONE;
- deflateEnd(&soap->d_stream);
- return soap->error;
- }
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- }
- } while (r == Z_OK);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_out = (float)soap->d_stream.total_out / (float)soap->d_stream.total_in;
- soap->mode &= ~SOAP_ENC_ZLIB;
- soap->zlib_state = SOAP_ZLIB_NONE;
- if (deflateEnd(&soap->d_stream) != Z_OK || r != Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to end deflate: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- return soap->error = SOAP_ZLIB_ERROR;
- }
-#ifdef WITH_GZIP
- soap->z_buf[0] = soap->z_crc & 0xFF;
- soap->z_buf[1] = (soap->z_crc >> 8) & 0xFF;
- soap->z_buf[2] = (soap->z_crc >> 16) & 0xFF;
- soap->z_buf[3] = (soap->z_crc >> 24) & 0xFF;
- soap->z_buf[4] = soap->d_stream.total_in & 0xFF;
- soap->z_buf[5] = (soap->d_stream.total_in >> 8) & 0xFF;
- soap->z_buf[6] = (soap->d_stream.total_in >> 16) & 0xFF;
- soap->z_buf[7] = (soap->d_stream.total_in >> 24) & 0xFF;
- if (soap_flush_raw(soap, soap->z_buf, 8))
- return soap->error;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip crc32=%lu\n", soap->z_crc));
-#endif
- }
-#endif
-#ifndef WITH_LEAN
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- { char *p;
- if (!(soap->mode & SOAP_ENC_XML))
- { soap->mode--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending buffered message of length %u\n", (unsigned int)soap->blist->size));
- if (soap->status >= SOAP_POST)
- soap->error = soap->fpost(soap, soap->endpoint, soap->host, soap->port, soap->path, soap->action, soap->blist->size);
- else if (soap->status != SOAP_STOP)
- soap->error = soap->fresponse(soap, soap->status, soap->blist->size);
- if (soap->error || soap_flush(soap))
- return soap->error;
- soap->mode++;
- }
- for (p = soap_first_block(soap); p; p = soap_next_block(soap))
- { DBGMSG(SENT, p, soap_block_size(soap));
- if ((soap->error = soap->fsend(soap, p, soap_block_size(soap))))
- { soap_end_block(soap);
- return soap->error;
- }
- }
- soap_end_block(soap);
- }
- else if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { DBGMSG(SENT, "\r\n0\r\n\r\n", 7);
- if ((soap->error = soap->fsend(soap, "\r\n0\r\n\r\n", 7)))
- return soap->error;
- }
-#endif
- }
-#ifdef WITH_OPENSSL
- if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive)
- shutdown((SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */
-#else
- if (soap_valid_socket(soap->socket) && !soap->keep_alive)
- shutdown((SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send message ok\n"));
- soap->part = SOAP_END;
- soap->count = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_end_recv(struct soap *soap)
-{ soap->part = SOAP_END;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "End of receive message ok\n"));
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { soap->mode &= ~SOAP_ENC_ZLIB;
- memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
- soap->bufidx = (char*)soap->d_stream.next_in - soap->z_buf;
- soap->buflen = soap->z_buflen;
- soap->zlib_state = SOAP_ZLIB_NONE;
- if (inflateEnd(&soap->d_stream) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
-#ifdef WITH_GZIP
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- { wchar c;
- short i;
- for (i = 0; i < 8; i++)
- { if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
- soap->z_buf[i] = (char)c;
- }
- if (soap->z_crc != ((unsigned char)soap->z_buf[0] | (unsigned long)((unsigned char)soap->z_buf[1] << 8) | (unsigned long)((unsigned char)soap->z_buf[2] << 16) | (unsigned long)((unsigned char)soap->z_buf[3] << 24)))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: crc check failed, message corrupted? (crc32=%lu)\n", soap->z_crc));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- if (soap->d_stream.total_out != ((unsigned char)soap->z_buf[4] | (unsigned long)((unsigned char)soap->z_buf[5] << 8) | (unsigned long)((unsigned char)soap->z_buf[6] << 16) | (unsigned long)((unsigned char)soap->z_buf[7] << 24)))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: incorrect message length\n"));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- }
-#endif
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- while ((int)soap_getchar(soap) != EOF) /* advance to last chunk */
- ;
- if (soap->fdisconnect)
- if ((soap->error = soap->fdisconnect(soap)))
- return soap->error;
- return soap_resolve(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_free(struct soap *soap)
-{ register struct soap_nlist *np;
- register struct soap_attribute *tp;
- register struct Namespace *ns;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n"));
- while (soap->nlist)
- { np = soap->nlist->next;
- if (soap->nlist->ns)
- SOAP_FREE(soap->nlist->ns);
- SOAP_FREE(soap->nlist);
- soap->nlist = np;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free any remaining temp blocks\n"));
- while (soap->blist)
- soap_end_block(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attributes\n"));
- while (soap->attributes)
- { tp = soap->attributes->next;
- if (soap->attributes->value)
- SOAP_FREE(soap->attributes->value);
- SOAP_FREE(soap->attributes);
- soap->attributes = tp;
- }
- if (soap->labbuf)
- SOAP_FREE(soap->labbuf);
- soap->labbuf = NULL;
- soap->lablen = 0;
- soap->labidx = 0;
- soap_free_pht(soap);
- soap_free_iht(soap);
- ns = soap->local_namespaces;
- if (ns)
- { for (; ns->id; ns++)
- { if (ns->out)
- { SOAP_FREE(ns->out);
- if (soap->encodingStyle == ns->out)
- soap->encodingStyle = SOAP_STR_EOS;
- ns->out = NULL;
- }
- if (soap->encodingStyle == ns->ns)
- soap->encodingStyle = SOAP_STR_EOS;
- }
- SOAP_FREE(soap->local_namespaces);
- soap->local_namespaces = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static void
-soap_init_logs(struct soap *soap)
-{ int i;
- for (i = 0; i < SOAP_MAXLOGS; i++)
- { soap->logfile[i] = NULL;
- soap->fdebug[i] = NULL;
- }
-#ifdef SOAP_DEBUG
- soap_set_recv_logfile(soap, "RECV.log");
- soap_set_sent_logfile(soap, "SENT.log");
- soap_set_test_logfile(soap, "TEST.log");
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_open_logfile(struct soap *soap, int i)
-{ if (soap->logfile[i])
- soap->fdebug[i] = fopen(soap->logfile[i], i < 2 ? "ab" : "a");
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static void
-soap_close_logfile(struct soap *soap, int i)
-{ if (soap->fdebug[i])
- { fclose(soap->fdebug[i]);
- soap->fdebug[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_close_logfiles(struct soap *soap)
-{ int i;
- for (i = 0; i < SOAP_MAXLOGS; i++)
- soap_close_logfile(soap, i);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static void
-soap_set_logfile(struct soap *soap, int i, const char *logfile)
-{ char *s = NULL;
- soap_close_logfile(soap, i);
- if (soap->logfile[i])
- SOAP_FREE((void*)soap->logfile[i]);
- if (logfile)
- if ((s = (char*)SOAP_MALLOC(strlen(logfile) + 1)))
- strcpy(s, logfile);
- soap->logfile[i] = s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_recv_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_RECV, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_sent_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_SENT, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_test_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_TEST, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_copy(struct soap *soap)
-{ return soap_copy_context((struct soap*)SOAP_MALLOC(sizeof(struct soap)), soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_copy_context(struct soap *copy, struct soap *soap)
-{ if (copy)
- { register struct soap_plugin *p;
- memcpy(copy, soap, sizeof(struct soap));
- copy->copy = 1;
- copy->user = NULL;
- copy->userid = NULL;
- copy->passwd = NULL;
- copy->nlist = NULL;
- copy->blist = NULL;
- copy->clist = NULL;
- copy->alist = NULL;
- copy->attributes = NULL;
- copy->local_namespaces = NULL;
- soap_set_local_namespaces(copy);
- soap_init_iht(copy);
- soap_init_pht(copy);
- copy->header = NULL;
- copy->fault = NULL;
- copy->action = NULL;
- *copy->host = '\0';
-#ifndef WITH_LEAN
-#ifdef WITH_COOKIES
- copy->cookies = soap_copy_cookies(soap);
-#else
- copy->cookies = NULL;
-#endif
- soap_init_logs(copy);
-#endif
- copy->plugins = NULL;
- for (p = soap->plugins; p; p = p->next)
- { register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(sizeof(struct soap_plugin));
- if (!q)
- return NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying plugin '%s'\n", p->id));
- *q = *p;
- if (p->fcopy && (soap->error = p->fcopy(soap, q, p)))
- { SOAP_FREE(q);
- return NULL;
- }
- q->next = copy->plugins;
- copy->plugins = q;
- }
- }
- else
- soap->error = SOAP_EOM;
- return copy;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init(struct soap *soap)
-{ soap->version = 1; /* default SOAP 1.1 */
- soap_imode(soap, SOAP_IO_DEFAULT);
- soap_omode(soap, SOAP_IO_DEFAULT);
- soap->copy = 0;
- soap->plugins = NULL;
- soap->user = NULL;
- soap->userid = NULL;
- soap->passwd = NULL;
- soap->fpost = http_post;
- soap->fget = http_get;
- soap->fposthdr = http_post_header;
- soap->fresponse = http_response;
- soap->fparse = http_parse;
- soap->fparsehdr = http_parse_header;
- soap->fconnect = NULL;
- soap->fdisconnect = NULL;
-#ifndef MAC_CARBON
- soap->faccept = tcp_accept;
- soap->fopen = tcp_connect;
- soap->fclose = tcp_disconnect;
- soap->fsend = fsend;
- soap->frecv = frecv;
-#endif
- soap->fprepare = NULL;
- soap->fignore = NULL;
- soap->fplugin = fplugin;
- soap->fdimereadopen = NULL;
- soap->fdimewriteopen = NULL;
- soap->fdimereadclose = NULL;
- soap->fdimewriteclose = NULL;
- soap->fdimeread = NULL;
- soap->fdimewrite = NULL;
- soap->float_format = "%.8g"; /* .8 preserves single FP precision as much as possible, but might not be very efficient */
- soap->double_format = "%.17lg"; /* .17 preserves double FP precision as much as possible, but might not be very efficient */
- soap->dime_id_format = "cid:id%d"; /* default DIME id format */
- soap->http_version = "1.1";
- soap->encodingStyle = SOAP_STR_EOS;
- soap->actor = NULL;
- soap->max_keep_alive = SOAP_MAXKEEPALIVE;
- soap->keep_alive = 0;
- soap->recv_timeout = 0;
- soap->send_timeout = 0;
- soap->connect_timeout = 0;
- soap->accept_timeout = 0;
- soap->socket_flags = 0;
- soap->connect_flags = 0;
- soap->bind_flags = 0;
- soap->accept_flags = 0;
- soap->ip = 0;
- soap->labbuf = NULL;
- soap->lablen = 0;
- soap->labidx = 0;
-#ifndef WITH_NONAMESPACES
- soap->namespaces = namespaces;
-#else
- soap->namespaces = NULL;
-#endif
- soap->local_namespaces = NULL;
- soap->nlist = NULL;
- soap->blist = NULL;
- soap->clist = NULL;
- soap->alist = NULL;
- soap->attributes = NULL;
- soap->header = NULL;
- soap->fault = NULL;
- soap->master = SOAP_INVALID_SOCKET;
- soap->socket = SOAP_INVALID_SOCKET;
- soap->os = NULL;
- soap->is = NULL;
- soap->dom = NULL;
-#ifndef UNDER_CE
- soap->recvfd = 0;
- soap->sendfd = 1;
-#else
- soap->recvfd = stdin;
- soap->sendfd = stdout;
-#endif
- soap->host[0] = '\0';
- soap->port = 0;
- soap->action = NULL;
- soap->proxy_host = NULL;
- soap->proxy_port = 8080;
- soap->proxy_userid = NULL;
- soap->proxy_passwd = NULL;
-#ifdef WITH_OPENSSL
- soap->fsslauth = ssl_auth_init;
- soap->fsslverify = ssl_verify_callback;
- soap->bio = NULL;
- soap->ssl = NULL;
- soap->ctx = NULL;
- soap->require_server_auth = 0;
- soap->require_client_auth = 0;
- soap->rsa = 0;
- soap->keyfile = NULL;
- soap->password = NULL;
- soap->dhfile = NULL;
- soap->cafile = NULL;
- soap->capath = NULL;
- soap->randfile = NULL;
- soap->session = NULL;
-#endif
-#ifdef WITH_ZLIB
- soap->zlib_state = SOAP_ZLIB_NONE;
- soap->zlib_in = SOAP_ZLIB_NONE;
- soap->zlib_out = SOAP_ZLIB_NONE;
- soap->d_stream.zalloc = NULL;
- soap->d_stream.zfree = NULL;
- soap->d_stream.opaque = NULL;
- soap->z_level = 6;
-#endif
-#ifndef WITH_LEAN
- soap->cookies = NULL;
- soap->cookie_domain = NULL;
- soap->cookie_path = NULL;
- soap->cookie_max = 32;
- soap_init_logs(soap);
-#endif
-/* WR[ */
-#ifdef WMW_RPM_IO
- soap->rpmreqid = NULL;
-#endif /* WMW_RPM_IO */
-/* ]WR */
- soap_init_iht(soap);
- soap_init_pht(soap);
- soap_begin(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init1(struct soap *soap, int mode)
-{ soap_init2(soap, mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init2(struct soap *soap, int imode, int omode)
-{ soap_init(soap);
- soap_imode(soap, imode);
- soap_omode(soap, omode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_begin(struct soap *soap)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing\n"));
- if (!soap->keep_alive)
- { soap->buflen = 0;
- soap->bufidx = 0;
- }
- soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0);
- soap->null = 0;
- soap->position = 0;
- soap->encoding = 0;
- soap->mustUnderstand = 0;
- soap->mode = 0;
- soap->ns = 0;
- soap->part = SOAP_BEGIN;
- soap->alloced = 0;
- soap->count = 0;
- soap->length = 0;
- soap->cdata = 0;
- soap->error = SOAP_OK;
- soap->peeked = 0;
- soap->ahead = 0;
- soap->idnum = 0;
- soap->level = 0;
- soap->endpoint[0] = '\0';
- soap->dime_chunksize = 0;
- soap->dime_buflen = 0;
- soap->dot_net_bug = 0;
- soap_free(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_end(struct soap *soap)
-{ register struct soap_clist *cp;
- soap_free(soap);
- soap_dealloc(soap, NULL);
- while (soap->clist)
- { cp = soap->clist->next;
- SOAP_FREE(soap->clist);
- soap->clist = cp;
- }
- soap_closesock(soap);
-#ifndef WITH_LEAN
- soap_close_logfiles(soap);
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_namespaces(struct soap *soap, struct Namespace *p)
-{ struct Namespace *ns = soap->local_namespaces;
- struct soap_nlist *np, *nq, *nr;
- unsigned int level = soap->level;
- soap->namespaces = p;
- soap->local_namespaces = NULL;
- soap_set_local_namespaces(soap);
- /* reverse the list */
- np = soap->nlist;
- soap->nlist = NULL;
- if (np)
- { nq = np->next;
- np->next = NULL;
- while (nq)
- { nr = nq->next;
- nq->next = np;
- np = nq;
- nq = nr;
- }
- }
- while (np)
- { soap->level = np->level; /* preserve element nesting level */
- if (np->ns)
- { if (soap_push_namespace(soap, np->id, np->ns))
- return soap->error;
- }
- else if (np->index >= 0 && ns)
- { if (ns[np->index].out)
- { if (soap_push_namespace(soap, np->id, ns[np->index].out))
- return soap->error;
- }
- else if (soap_push_namespace(soap, np->id, ns[np->index].ns))
- return soap->error;
- }
- if (np->ns)
- SOAP_FREE(np->ns);
- nq = np;
- np = np->next;
- SOAP_FREE(nq);
- }
- if (ns)
- { int i;
- for (i = 0; ns[i].id; i++)
- { if (ns[i].out)
- { SOAP_FREE(ns[i].out);
- ns[i].out = NULL;
- }
- }
- SOAP_FREE(ns);
- }
- soap->level = level; /* restore level */
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-soap_set_local_namespaces(struct soap *soap)
-{ if (soap->namespaces && !soap->local_namespaces)
- { register struct Namespace *ns;
- register size_t n = 1;
- for (ns = soap->namespaces; ns->id; ns++)
- n++;
- if (n > 3)
- { n *= sizeof(struct Namespace);
- ns = (struct Namespace*)SOAP_MALLOC(n);
- if (ns)
- { memcpy(ns, soap->namespaces, n);
- ns[0].id = "SOAP-ENV";
- ns[1].id = "SOAP-ENC";
- ns[2].id = "xsi";
- if (ns[0].ns)
- { if (!strcmp(ns[0].ns, soap_env1))
- soap->version = 1;
- else
- soap->version = 2;
- }
- soap->local_namespaces = ns;
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element(struct soap *soap, const char *tag, int id, const char *type)
-{ struct Namespace *ns = soap->local_namespaces;
- register const char *s;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' id='%d' type='%s'\n", tag, id, type?type:""));
-/**/
-#ifdef WITH_DOM
- if (soap->mode & SOAP_XML_DOM)
- { register struct soap_dom_element *p, *e = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element));
- e->next = NULL;
- e->prnt = soap->dom;
- e->nstr = NULL;
- e->name = soap_strdup(soap, tag); /* check EOM? */
- e->data = NULL;
- e->type = 0;
- e->node = NULL;
- e->elts = NULL;
- e->atts = NULL;
- if (soap->dom)
- { p = soap->dom->elts;
- if (p)
- { while (p->next)
- p = p->next;
- p->next = e;
- }
- else
- soap->dom->elts = e;
- }
- soap->dom = e;
- }
- else
-#endif
-{
- soap->level++;
- if (!soap->ns && !(soap->mode & SOAP_XML_CANONICAL))
- if (soap_send(soap, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"))
- return soap->error;
- if (soap_send_raw(soap, "<", 1))
- return soap->error;
- s = tag;
- if (ns && soap->part != SOAP_IN_ENVELOPE && (soap->part == SOAP_IN_HEADER || !soap->encodingStyle))
- { register const char *t = strchr(s, ':');
- if (t)
- { s = t + 1;
- for (ns++; ns->id; ns++)
- { if ((ns->out || ns->ns) && !strncmp(ns->id, tag, t - tag) && !ns->id[t - tag])
- { if (soap_send(soap, s) || soap_attribute(soap, "xmlns", ns->out ? ns->out : ns->ns))
- return soap->error;
- s = NULL;
- break;
- }
- }
- }
- }
- if (s)
- if (soap_send(soap, tag))
- return soap->error;
-}
-/**/
- if (!soap->ns)
- { for (ns = soap->local_namespaces; ns && ns->id; ns++)
- { if (*ns->id && (ns->out || ns->ns))
- { sprintf(soap->tmpbuf, "xmlns:%s", ns->id);
- if (soap_attribute(soap, soap->tmpbuf, ns->out ? ns->out : ns->ns))
- return soap->error;
- }
- }
- soap->ns = 1;
- }
- if (id > 0)
- { sprintf(soap->tmpbuf, "_%d", id);
- if (soap_attribute(soap, "id", soap->tmpbuf))
- return soap->error;
- }
- if (type && *type)
- { if (soap_attribute(soap, "xsi:type", type))
- return soap->error;
- }
- if (soap->null && soap->position > 0)
- { int i;
- sprintf(soap->tmpbuf, "[%d", soap->positions[0]);
- for (i = 1; i < soap->position; i++)
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), ",%d", soap->positions[i]);
- strcat(soap->tmpbuf, "]");
- if (soap_attribute(soap, "SOAP-ENC:position", soap->tmpbuf))
- return soap->error;
- }
- if (soap->mustUnderstand)
- { if (soap->actor && *soap->actor)
- { if (soap_attribute(soap, soap->version == 2 ? "SOAP-ENV:role" : "SOAP-ENV:actor", soap->actor))
- return soap->error;
- }
- if (soap_attribute(soap, "SOAP-ENV:mustUnderstand", soap->version == 2 ? "true" : "1"))
- return soap->error;
- soap->mustUnderstand = 0;
- }
- if (soap->encoding)
- { if (soap->encodingStyle)
- { if (!*soap->encodingStyle && soap->local_namespaces)
- { if (soap->local_namespaces[1].out)
- soap->encodingStyle = soap->local_namespaces[1].out;
- else
- soap->encodingStyle = soap->local_namespaces[1].ns;
- }
- if (soap_attribute(soap, "SOAP-ENV:encodingStyle", soap->encodingStyle))
- return soap->error;
- }
- soap->encoding = 0;
- }
- soap->null = 0;
- soap->position = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_begin_out(struct soap *soap, const char *tag, int id, const char *type)
-{ if (*tag == '-')
- return SOAP_OK;
- if (soap_element(soap, tag, id, type))
- return soap->error;
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRRCHR
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_strrchr(const char *s, int t)
-{ register char *r = NULL;
- while (*s)
- if (*s++ == t)
- r = (char*)s - 1;
- return r;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRTOL
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_strtol(const char *s, char **t, int b)
-{ register long n = 0;
- register int c;
- while (*s > 0 && *s <= 32)
- s++;
- if (b == 10)
- { short neg = 0;
- if (*s == '-')
- { s++;
- neg = 1;
- }
- else if (*s == '+')
- s++;
- while ((c = *s) && c >= '0' && c <= '9')
- { if (n > 214748364)
- break;
- n *= 10;
- n += c - '0';
- s++;
- }
- if (neg)
- n = -n;
- }
- else /* b == 16 and value is always positive */
- { while ((c = *s))
- { if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- if (n > 0x07FFFFFF)
- break;
- n <<= 4;
- n += c;
- s++;
- }
- }
- if (t)
- *t = (char*)s;
- return n;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRTOUL
-SOAP_FMAC1
-unsigned long
-SOAP_FMAC2
-soap_strtoul(const char *s, char **t, int b)
-{ unsigned long n = 0;
- register int c;
- while (*s > 0 && *s <= 32)
- s++;
- if (b == 10)
- { if (*s == '+')
- s++;
- while ((c = *s) && c >= '0' && c <= '9')
- { if (n > 429496729)
- break;
- n *= 10;
- n += c - '0';
- s++;
- }
- }
- else /* b == 16 */
- { while ((c = *s))
- { if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- if (n > 0x0FFFFFFF)
- break;
- n <<= 4;
- n += c;
- s++;
- }
- }
- if (t)
- *t = (char*)s;
- return n;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_begin_out(struct soap *soap, const char *tag, int id, const char *type, const char *offset)
-{ if (soap_element(soap, tag, id, "SOAP-ENC:Array"))
- return soap->error;
- if (soap->version == 2)
- { const char *s;
- s = soap_strrchr(type, '[');
- if ((size_t)(s - type) < sizeof(soap->tmpbuf))
- { strncpy(soap->tmpbuf, type, s - type);
- soap->tmpbuf[s - type] = '\0';
- if (type && *type && (soap_attribute(soap, "SOAP-ENC:itemType", soap->tmpbuf)))
- return soap->error;
- if (s && (soap_attribute(soap, "SOAP-ENC:arraySize", s + 1)))
- return soap->error;
- }
- }
- else
- { if (offset && (soap_attribute(soap, "SOAP-ENC:offset", offset)))
- return soap->error;
- if (type && *type && (soap_attribute(soap, "SOAP-ENC:arrayType", type)))
- return soap->error;
- }
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_start_end_out(struct soap *soap, const char *tag)
-{ register struct soap_attribute *tp;
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible)
- { register struct soap_dom_attribute *a = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
- a->next = soap->dom->atts;
- a->nstr = NULL;
- a->name = soap_strdup(soap, tp->name); /* check EOM */
- a->data = soap_strdup(soap, tp->value); /* check EOM */
- a->wide = NULL;
- soap->dom->atts = a;
- tp->visible = 0;
- }
- }
- return SOAP_OK;
- }
-#endif
-/**/
- for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible)
- { if (soap_send_raw(soap, " ", 1)
- || soap_send(soap, tp->name))
- return soap->error;
- if (tp->visible == 2 && tp->value)
- if (soap_send_raw(soap, "=\"", 2)
- || soap_string_out(soap, tp->value, 1)
- || soap_send_raw(soap, "\"", 1))
- return soap->error;
- tp->visible = 0;
- }
- }
- if (tag)
- { soap->level--;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { if (soap_send_raw(soap, ">", 1)
- || soap_element_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
- }
-#endif
- return soap_send_raw(soap, "/>", 2);
- }
- return soap_send_raw(soap, ">", 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_end_out(struct soap *soap, const char *tag)
-{ if (*tag == '-')
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element ending tag='%s'\n", tag));
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { if (soap->dom->prnt)
- soap->dom = soap->dom->prnt;
- return SOAP_OK;
- }
-#endif
-/**/
- if (soap->part != SOAP_IN_ENVELOPE && (soap->part == SOAP_IN_HEADER || !soap->encodingStyle) && soap->local_namespaces)
- { const char *s = strchr(tag, ':');
- if (s && strncmp(tag, "SOAP-ENV", s - tag))
- tag = s + 1;
- }
- soap->level--;
- if (soap_send_raw(soap, "</", 2)
- || soap_send(soap, tag)
- || soap_send_raw(soap, ">", 1))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_ref(struct soap *soap, const char *tag, int id, int href)
-{ int n = 0;
- if (soap_element(soap, tag, id, NULL))
- return soap->error;
- if (soap->version == 2)
- n = 1;
- sprintf(soap->tmpbuf, "#_%d", href);
- if (soap_attribute(soap, "href" + n, soap->tmpbuf + n)
- || soap_element_start_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_href(struct soap *soap, const char *tag, int id, const char *href)
-{ if (soap_element(soap, tag, id, NULL)
- || soap_attribute(soap, "href", href)
- || soap_element_start_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_null(struct soap *soap, const char *tag, int id, const char *type)
-{ struct soap_attribute *tp;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (tp->visible)
- break;
- if (tp || (soap->version == 2 && soap->position > 0) || id > 0 || (soap->mode & SOAP_XML_NIL))
- { if (soap_element(soap, tag, id, type))
- return soap->error;
- if (soap->part != SOAP_IN_HEADER && soap->encodingStyle)
- if (soap_attribute(soap, "xsi:nil", "true"))
- return soap->error;
- return soap_element_start_end_out(soap, tag);
- }
- soap->null = 1;
- soap->position = 0;
- soap->mustUnderstand = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_result(struct soap *soap, const char *tag)
-{ if (soap->version == 2 && soap->encodingStyle)
- if (soap_element(soap, "SOAP-RPC:result", 0, NULL)
- || soap_attribute(soap, "xmlns:SOAP-RPC", soap_rpc)
- || soap_element_start_end_out(soap, NULL)
- || soap_string_out(soap, tag, 0)
- || soap_element_end_out(soap, "SOAP-RPC:result"))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_attribute(struct soap *soap, const char *name, const char *value)
-{
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { register struct soap_dom_attribute *a = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
- a->next = soap->dom->atts;
- a->nstr = NULL;
- a->name = soap_strdup(soap, name); /* check EOM */
- a->data = soap_strdup(soap, value); /* check EOM */
- a->wide = NULL;
- soap->dom->atts = a;
- return SOAP_OK;
- }
-#endif
-/**/
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { if (soap_set_attr(soap, name, value))
- return soap->error;
- }
- else
-#endif
- { if (soap_send_raw(soap, " ", 1)
- || soap_send(soap, name))
- return soap->error;
- if (value)
- if (soap_send_raw(soap, "=\"", 2)
- || soap_string_out(soap, value, 1)
- || soap_send_raw(soap, "\"", 1))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_begin_in(struct soap *soap, const char *tag)
-{ if (tag && *tag == '-')
- return SOAP_OK;
- if (!soap_peek_element(soap))
- { if (soap->other)
- return soap->error = SOAP_TAG_MISMATCH;
- if (!(soap->error = soap_match_tag(soap, soap->tag, tag)))
- { if (tag && !soap->encodingStyle)
- { const char *s = strchr(tag, ':');
- if (s)
- soap_push_default_namespace(soap, tag, s - tag);
- }
- soap->peeked = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:"" ));
- if (soap->body)
- soap->level++;
- }
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_end_in(struct soap *soap, const char *tag)
-{ register wchar c;
- register char *s;
- register const char *t;
- if (tag && *tag == '-')
- return SOAP_OK;
- soap->level--;
- soap_pop_namespace(soap);
- if (soap->peeked)
- { if (*soap->tag == '\0')
- { soap->peeked = 0;
- soap->error = SOAP_OK;
- }
- else
- return soap->error = SOAP_SYNTAX_ERROR;
- }
- else
- { while (((c = soap_get(soap)) != TT))
- { if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (c == LT)
- return soap->error = SOAP_SYNTAX_ERROR;
- }
- }
- s = soap->tag;
- do c = soap_get(soap);
- while (soap_blank(c));
- do
- { *s++ = (char)c;
- c = soap_get(soap);
- } while (soap_notblank(c));
- *s = '\0';
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- while (soap_blank(c))
- c = soap_get(soap);
- if (c != GT)
- return soap->error = SOAP_SYNTAX_ERROR;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:""));
- if (!tag)
- return SOAP_OK;
- if ((s = strchr(soap->tag, ':')))
- s++;
- else
- s = soap->tag;
- if ((t = strchr(tag, ':')))
- t++;
- else
- t = tag;
- if (!SOAP_STRCMP(s, t))
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element does not match\n"));
- return soap->error = SOAP_SYNTAX_ERROR;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_attribute *
-SOAP_FMAC2
-soap_attr(struct soap *soap, const char *name)
-{ register struct soap_attribute *tp;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!soap_match_tag(soap, tp->name, name))
- return tp;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char *
-SOAP_FMAC2
-soap_attr_value(struct soap *soap, const char *name)
-{ register struct soap_attribute *tp = soap_attr(soap, name);
- if (tp && tp->visible == 2)
- return tp->value;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_attr(struct soap *soap, const char *name, const char *value)
-{ register struct soap_attribute *tp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set attribute %s='%s'\n", name, value?value:""));
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!strcmp(tp->name, name))
- break;
- if (!tp)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute %s\n", name));
- if (!(tp = (struct soap_attribute*)SOAP_MALLOC(sizeof(struct soap_attribute) + strlen(name))))
- return soap->error = SOAP_EOM;
- tp->ns = NULL;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { struct soap_attribute **tpp = &soap->attributes;
- const char *s = strchr(name, ':');
- if (!strncmp(name, "xmlns", 5))
- { for (; *tpp; tpp = &(*tpp)->next)
- if (strncmp((*tpp)->name, "xmlns", 5) || strcmp((*tpp)->name + 5, name + 5) > 0)
- break;
- }
- else if (!s)
- { for (; *tpp; tpp = &(*tpp)->next)
- if (strncmp((*tpp)->name, "xmlns", 5) && ((*tpp)->ns || strcmp((*tpp)->name, name) > 0))
- break;
- }
- else
- { int k;
- for (; *tpp; tpp = &(*tpp)->next)
- { if (!strncmp((*tpp)->name, "xmlns:", 6) && !strncmp((*tpp)->name + 6, name, s - name) && !(*tpp)->name[6 + s - name])
- { if (!tp->ns)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Canonicalization: prefix %s=%p(%s)\n", name, (*tpp)->ns, (*tpp)->ns));
- tp->ns = (*tpp)->ns;
- }
- }
- else if (strncmp((*tpp)->name, "xmlns", 5) && (*tpp)->ns && tp->ns && ((k = strcmp((*tpp)->ns, tp->ns)) > 0 || (!k && strcmp((*tpp)->name, name) > 0)))
- break;
- }
- }
- tp->next = *tpp;
- *tpp = tp;
- }
- else
-#endif
- { tp->next = soap->attributes;
- soap->attributes = tp;
- }
- strcpy(tp->name, name);
- tp->value = NULL;
- }
- else if (value && tp->value && tp->size <= strlen(value))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attribute value of %s (free %p)\n", name, tp->value));
- SOAP_FREE(tp->value);
- tp->value = NULL;
- tp->ns = NULL;
- }
- if (value)
- { if (!tp->value)
- { tp->size = strlen(value) + 1;
- if (!(tp->value = (char*)SOAP_MALLOC(tp->size)))
- return soap->error = SOAP_EOM;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute value of %s (%p)\n", tp->name, tp->value));
- }
- strcpy(tp->value, value);
- if (!strncmp(tp->name, "xmlns:", 6))
- tp->ns = tp->value;
- tp->visible = 2;
- }
- else
- tp->visible = 1;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_attr(struct soap *soap)
-{ register struct soap_attribute *tp;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { while (soap->attributes)
- { tp = soap->attributes->next;
- SOAP_FREE(soap->attributes->value);
- SOAP_FREE(soap->attributes);
- soap->attributes = tp;
- }
- }
- else
-#endif
- { for (tp = soap->attributes; tp; tp = tp->next)
- tp->visible = 0;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static int
-soap_getattrval(struct soap *soap, char *s, size_t n, wchar d)
-{ size_t i;
- wchar c;
- for (i = 0; i < n; i++)
- { c = soap_getutf8(soap);
- switch (c)
- {
- case TT:
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case LT:
- *s++ = '<';
- break;
- case GT:
- if (d == ' ')
- { soap_unget(soap, c);
- *s = '\0';
- return SOAP_OK;
- }
- *s++ = '>';
- break;
- case QT:
- if (c == d)
- { *s = '\0';
- return SOAP_OK;
- }
- *s++ = '"';
- break;
- case AP:
- if (c == d)
- { *s = '\0';
- return SOAP_OK;
- }
- *s++ = '\'';
- break;
- case '\t':
- case '\n':
- case '\r':
- case ' ':
- case '/':
- if (d == ' ')
- { soap_unget(soap, c);
- *s = '\0';
- return SOAP_OK;
- }
- default:
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- }
- return soap->error = SOAP_EOM;
-}
-#endif
-
-/******************************************************************************/
-#ifdef WITH_FAST
-#ifndef PALM_2
-static int
-soap_append_lab(struct soap *soap, const char *s, size_t n)
-{ if (soap->labidx + n >= soap->lablen)
- { register char *t = soap->labbuf;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enlarging look-aside buffer to append data, old size=%lu", (unsigned long)soap->lablen));
- if (soap->lablen == 0)
- soap->lablen = SOAP_LABLEN;
- while (soap->labidx + n >= soap->lablen)
- soap->lablen <<= 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, ", new size=%lu\n", (unsigned long)soap->lablen));
- soap->labbuf = (char*)SOAP_MALLOC(soap->lablen);
- if (!soap->labbuf)
- { if (t)
- free(t);
- return soap->error = SOAP_EOM;
- }
- if (t && soap->labidx)
- { memcpy(soap->labbuf, t, soap->labidx);
- free(t);
- }
- }
- if (s)
- { memcpy(soap->labbuf + soap->labidx, s, n);
- soap->labidx += n;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_peek_element(struct soap *soap)
-{ struct soap_attribute *tp;
- const char *t;
- register char *s;
- register wchar c;
- register int i;
- if (soap->peeked)
- { if (*soap->tag == '\0')
- return soap->error = SOAP_NO_TAG;
- return SOAP_OK;
- }
- soap->peeked = 1;
- for (;;)
- { while (((c = soap_get(soap)) != LT) && c != TT)
- { if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- }
- if (c == TT)
- { *soap->tag = '\0';
- return soap->error = SOAP_NO_TAG; /* ending tag found */
- }
- s = soap->tag;
- do c = soap_get(soap);
- while (soap_blank(c));
- i = sizeof(soap->tag);
- while (c != '/' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- while (soap_blank(c))
- c = soap_get(soap);
- *s = '\0';
- if (*soap->tag != '?')
- break;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI <%s?>\n", soap->tag));
- while ((int)c != EOF && c != GT && c != '?')
- { s = soap->tmpbuf;
- i = sizeof(soap->tmpbuf) - 2;
- while (c != '=' && c != GT && c != '?' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- while (soap_blank(c))
- c = soap_get(soap);
- if (c == '=')
- { *s++ = '=';
- do c = soap_get(soap);
- while (soap_blank(c));
- if (c != QT && c != AP)
- { soap_unget(soap, c);
- c = ' '; /* blank delimiter */
- }
- if (soap_getattrval(soap, s, i, c) == SOAP_EOM)
- while (soap_getattrval(soap, soap->tmpbuf, sizeof(soap->tmpbuf), c) == SOAP_EOM)
- ;
- else if (!strcmp(soap->tag, "?xml") && (!soap_tag_cmp(soap->tmpbuf, "encoding=iso-8859-1") || !soap_tag_cmp(soap->tmpbuf, "encoding=latin1")))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML latin1 encoding\n"));
- soap->mode |= SOAP_C_LATIN;
- }
- }
- do c = soap_get(soap);
- while (soap_blank(c));
- }
- }
- soap->id[0] = '\0';
- soap->href[0] = '\0';
- soap->type[0] = '\0';
- soap->arrayType[0] = '\0';
- soap->arraySize[0] = '\0';
- soap->arrayOffset[0] = '\0';
- soap->other = 0;
- soap->root = -1;
- soap->position = 0;
- soap->null = 0;
- soap->mustUnderstand = 0;
- soap_clr_attr(soap);
- soap_pop_namespace(soap);
- while ((int)c != EOF && c != GT && c != '/')
- { s = soap->tmpbuf;
- i = sizeof(soap->tmpbuf);
- while (c != '=' && c != '/' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- *s = '\0';
- if (i == sizeof(soap->tmpbuf))
- return soap->error = SOAP_SYNTAX_ERROR;
- if (!strncmp(soap->tmpbuf, "xmlns:", 6))
- { soap->tmpbuf[5] = '\0';
- t = soap->tmpbuf + 6;
- }
- else if (!strcmp(soap->tmpbuf, "xmlns"))
- t = SOAP_STR_EOS;
- else
- t = NULL;
- tp = soap_attr(soap, soap->tmpbuf);
- if (!tp)
- { tp = (struct soap_attribute*)SOAP_MALLOC(sizeof(struct soap_attribute) + strlen(soap->tmpbuf));
- if (!tp)
- return soap->error = SOAP_EOM;
- strcpy(tp->name, soap->tmpbuf);
- tp->value = NULL;
- tp->size = 0;
- tp->next = soap->attributes;
- soap->attributes = tp;
- }
- while (soap_blank(c))
- c = soap_get(soap);
- if (c == '=')
- { do c = soap_get(soap);
- while (soap_blank(c));
- if (c != QT && c != AP)
- { soap_unget(soap, c);
- c = ' '; /* blank delimiter */
- }
- if (soap_getattrval(soap, tp->value, tp->size, c))
- {
-#ifdef WITH_FAST
- if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- soap->labidx = 0;
- if (soap_append_lab(soap, tp->value, tp->size))
- return soap->error;
- SOAP_FREE(tp->value);
- for (;;)
- { if (soap_getattrval(soap, soap->labbuf + soap->labidx, soap->lablen - soap->labidx, c))
- { if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- soap->labidx = soap->lablen;
- if (soap_append_lab(soap, NULL, 0))
- return soap->error;
- }
- else
- break;
- }
- tp->size = soap->lablen;
- if (!(tp->value = (char*)SOAP_MALLOC(tp->size)))
- return soap->error = SOAP_EOM;
- memcpy(tp->value, soap->labbuf, soap->lablen);
-#else
- size_t n;
- if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- if (soap_new_block(soap))
- return soap->error;
- for (;;)
- { if (!(s = (char*)soap_push_block(soap, SOAP_BLKLEN)))
- return soap->error;
- if (soap_getattrval(soap, s, SOAP_BLKLEN, c))
- { if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- }
- else
- break;
- }
- n = tp->size + soap->blist->size;
- if (!(s = (char*)SOAP_MALLOC(n)))
- return soap->error = SOAP_EOM;
- if (tp->value)
- { memcpy(s, tp->value, tp->size);
- SOAP_FREE(tp->value);
- }
- soap_save_block(soap, s + tp->size);
- tp->value = s;
- tp->size = n;
-#endif
- }
- do c = soap_get(soap);
- while (soap_blank(c));
- tp->visible = 2; /* seen this attribute w/ value */
- }
- else
- tp->visible = 1; /* seen this attribute w/o value */
- if (t && tp->value)
- { if (soap_push_namespace(soap, t, tp->value))
- return soap->error;
- tp->visible = 0;
- }
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible && tp->value)
- { if (!strcmp(tp->name, "id"))
- { if (soap->part != SOAP_IN_HEADER || !soap->dot_net_bug)
- { *soap->id = '#';
- strncpy(soap->id + 1, tp->value, sizeof(soap->id) - 2);
- }
- }
- else if (soap->version == 1 && !strcmp(tp->name, "href"))
- strncpy(soap->href, tp->value, sizeof(soap->href) - 1);
- else if (soap->version == 2 && !strcmp(tp->name, "ref"))
- { *soap->href = '#';
- strncpy(soap->href + 1, tp->value, sizeof(soap->href) - 2);
- }
- else if (!soap_match_tag(soap, tp->name, "xsi:type"))
- strncpy(soap->type, tp->value, sizeof(soap->type) - 1);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:arrayType"))
- { s = soap_strrchr(tp->value, '[');
- if (s && (size_t)(s - tp->value) < sizeof(soap->arrayType))
- { strncpy(soap->arrayType, tp->value, s - tp->value);
- soap->arrayType[s - tp->value] = '\0';
- strncpy(soap->arraySize, s, sizeof(soap->arraySize) - 1);
- }
- else
- strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1);
- }
- else if (soap->version == 2 && !soap_match_tag(soap, tp->name, "SOAP-ENC:itemType"))
- strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1);
- else if (soap->version == 2 && !soap_match_tag(soap, tp->name, "SOAP-ENC:arraySize"))
- strncpy(soap->arraySize, tp->value, sizeof(soap->arraySize) - 1);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:offset"))
- strncpy(soap->arrayOffset, tp->value, sizeof(soap->arrayOffset));
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:position"))
- soap->position = soap_getposition(tp->value, soap->positions);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:root"))
- soap->root = ((!strcmp(tp->value, "1") || !strcmp(tp->value, "true")));
- else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:actor")
- || !soap_match_tag(soap, tp->name, "SOAP-ENV:role"))
- { if ((!soap->actor || strcmp(soap->actor, tp->value))
- && strcmp(tp->value, "http://schemas.xmlsoap.org/soap/actor/next")
- && strcmp(tp->value, "http://www.w3.org/2003/05/soap-envelope/role/next"))
- soap->other = 1;
- }
- else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:mustUnderstand")
- && (!strcmp(tp->value, "1") || !strcmp(tp->value, "true")))
- soap->mustUnderstand = 1;
- else if ((!soap_match_tag(soap, tp->name, "xsi:null")
- || !soap_match_tag(soap, tp->name, "xsi:nil"))
- && (!strcmp(tp->value, "1")
- || !strcmp(tp->value, "true")))
- soap->null = 1;
- }
- }
- if (!(soap->body = (c != '/')))
- do c = soap_get(soap);
- while (soap_blank(c));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_retry(struct soap *soap)
-{ soap->peeked = 1;
- soap->error = SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_revert(struct soap *soap)
-{ soap->peeked = 1;
- if (soap->body)
- soap->level--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reverting last element (level=%u)\n", soap->level));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_string_out(struct soap *soap, const char *s, int flag)
-{ register const char *t;
- register wchar c;
- register wchar mask = 0x80000000;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->data = soap_strdup(soap, s); /* check EOM */
- return SOAP_OK;
- }
-#endif
- if (soap->mode & SOAP_C_UTFSTRING)
- mask = 0;
- t = s;
- while ((c = *t++))
- { switch (c)
- {
- case 9:
- if (flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "	", 5))
- return soap->error;
- s = t;
- }
- break;
- case 10:
- if (flag || !(soap->mode & SOAP_XML_CANONICAL))
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
- return soap->error;
- s = t;
- }
- break;
- case 13:
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
- return soap->error;
- s = t;
- break;
- case '&':
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "&", 5))
- return soap->error;
- s = t;
- break;
- case '<':
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "<", 4))
- return soap->error;
- s = t;
- break;
- case '>':
- if (!flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, ">", 4))
- return soap->error;
- s = t;
- }
- break;
- case '"':
- if (flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, """, 6))
- return soap->error;
- s = t;
- }
- break;
- default:
-#ifdef HAVE_MBTOWC
- if (soap->mode & SOAP_C_MBSTRING)
- { wchar_t wc;
- register int m = mbtowc(&wc, t - 1, MB_CUR_MAX);
- if (m > 0 && wc != c)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, wc))
- return soap->error;
- s = t + m - 1;
- continue;
- }
- }
-#endif
- if (c & mask)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, (unsigned char)c))
- return soap->error;
- s = t;
- }
- }
- }
- return soap_send_raw(soap, s, t - s - 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_string_in(struct soap *soap, int flag)
-{ register char *s;
- char *t = NULL;
- register size_t i;
- register int n = 0;
- register int m = 0;
- register wchar c;
-#ifdef HAVE_WCTOMB
- char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8];
-#else
- char buf[8];
-#endif
-#ifdef WITH_CDATA
- if (!flag)
- { register int state = 0;
-#ifdef WITH_FAST
- soap->labidx = 0; /* use look-aside buffer */
-#else
- if (soap_new_block(soap))
- return NULL;
-#endif
- for (;;)
- {
-#ifdef WITH_FAST
- register size_t k;
- if (soap_append_lab(soap, NULL, 0)) /* allocate more space in look-aside buffer if necessary */
- return NULL;
- s = soap->labbuf + soap->labidx; /* space to populate */
- k = soap->lablen - soap->labidx; /* number of bytes available */
- soap->labidx = soap->lablen; /* claim this space */
-#else
- register size_t k = SOAP_BLKLEN;
- if (!(s = (char*)soap_push_block(soap, k)))
- return NULL;
-#endif
- for (i = 0; i < k; i++)
- { if (m > 0)
- { *s++ = *t++; /* copy multibyte characters */
- m--;
- continue;
- }
- c = soap_getchar(soap);
- if ((int)c == EOF)
- goto end;
- if (c >= 0x80 && !(soap->mode & SOAP_C_LATIN))
- { soap_unget(soap, c);
- c = soap_getutf8(soap);
- if (soap->mode & SOAP_C_UTFSTRING)
- { if ((c & 0x80000000) && c >= -0x7FFFFF80 && c < AP)
- { c &= 0x7FFFFFFF;
- t = buf;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- m = (int)(t - buf) - 1;
- t = buf;
- *s++ = *t++;
- continue;
- }
- }
- }
- switch (state)
- { case 1:
- if (c == ']')
- state = 4;
- *s++ = c;
- continue;
- case 2:
- if (c == '-')
- state = 6;
- *s++ = c;
- continue;
- case 3:
- if (c == '?')
- state = 8;
- *s++ = c;
- continue;
- /* CDATA */
- case 4:
- if (c == ']')
- state = 5;
- else
- state = 1;
- *s++ = c;
- continue;
- case 5:
- if (c == '>')
- state = 0;
- else
- state = 1;
- *s++ = c;
- continue;
- /* comment */
- case 6:
- if (c == '-')
- state = 7;
- else
- state = 2;
- *s++ = c;
- continue;
- case 7:
- if (c == '>')
- state = 0;
- else
- state = 2;
- *s++ = c;
- continue;
- /* PI */
- case 8:
- if (c == '>')
- state = 0;
- else
- state = 3;
- *s++ = c;
- continue;
- }
- switch (c)
- {
- case '/':
- if (n > 0)
- { c = soap_get1(soap);
- if (c == '>')
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- c = soap_get1(soap);
- if (c == '/')
- { if (n == 0)
- { c = TT;
- goto end;
- }
- n--;
- }
- else if (c == '!')
- { c = soap_get1(soap);
- if (c == '[')
- { do c = soap_get1(soap);
- while ((int)c != EOF && c != '[');
- if ((int)c == EOF)
- goto end;
- t = (char*)"![CDATA[";
- state = 1;
- }
- else if (c == '-')
- { if ((c = soap_get1(soap)) == '-')
- state = 2;
- t = (char*)"!-";
- soap_unget(soap, c);
- }
- else
- { t = (char*)"!";
- soap_unget(soap, c);
- }
- *s++ = '<';
- break;
- }
- else if (c == '?')
- state = 3;
- else
- n++;
- soap_unget(soap, c);
- *s++ = '<';
- break;
- case '>':
- *s++ = '>';
- break;
- case '"':
- *s++ = '"';
- break;
- default:
-#ifdef HAVE_WCTOMB
- if (soap->mode & SOAP_C_MBSTRING)
- { m = wctomb(buf, c & 0x7FFFFFFF);
- if (m >= 1)
- { t = buf;
- *s++ = *t++;
- m--;
- }
- else
- *s++ = SOAP_UNKNOWN_CHAR;
- }
- else
-#endif
- *s++ = (char)(c & 0xFF);
- }
- }
- }
- }
-#endif
-#ifdef WITH_FAST
- soap->labidx = 0; /* use look-aside buffer */
-#else
- if (soap_new_block(soap))
- return NULL;
-#endif
- for (;;)
- {
-#ifdef WITH_FAST
- register size_t k;
- if (soap_append_lab(soap, NULL, 0)) /* allocate more space in look-aside buffer if necessary */
- return NULL;
- s = soap->labbuf + soap->labidx; /* space to populate */
- k = soap->lablen - soap->labidx; /* number of bytes available */
- soap->labidx = soap->lablen; /* claim this space */
-#else
- register size_t k = SOAP_BLKLEN;
- if (!(s = (char*)soap_push_block(soap, k)))
- return NULL;
-#endif
- for (i = 0; i < k; i++)
- { if (m > 0)
- { *s++ = *t++; /* copy multibyte characters */
- m--;
- continue;
- }
- if (soap->mode & SOAP_C_UTFSTRING)
- { if (((c = soap_get(soap)) & 0x80000000) && c >= -0x7FFFFF80 && c < AP)
- { c &= 0x7FFFFFFF;
- t = buf;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- m = (int)(t - buf) - 1;
- t = buf;
- *s++ = *t++;
- continue;
- }
- }
- else if (soap->mode & SOAP_C_LATIN)
- c = soap_get(soap);
- else
- c = soap_getutf8(soap);
- switch (c)
- {
- case TT:
- if (n == 0)
- goto end;
- n--;
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case LT:
- n++;
- *s++ = '<';
- break;
- case GT:
- *s++ = '>';
- break;
- case QT:
- *s++ = '"';
- break;
- case AP:
- *s++ = '\'';
- break;
- case '/':
- if (n > 0)
- { c = soap_get(soap);
- if (c == GT)
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- if (flag)
- *s++ = '<';
- else
- { *s++ = '&';
- t = (char*)"lt;";
- }
- break;
- case '>':
- if (flag)
- *s++ = '>';
- else
- { *s++ = '&';
- t = (char*)"gt;";
- }
- break;
- case '"':
- if (flag)
- *s++ = '"';
- else
- { *s++ = '&';
- t = (char*)"quot;";
- }
- break;
- default:
- if ((int)c == EOF)
- goto end;
-#ifdef HAVE_WCTOMB
- if (soap->mode & SOAP_C_MBSTRING)
- { m = wctomb(buf, c & 0x7FFFFFFF);
- if (m >= 1)
- { t = buf;
- *s++ = *t++;
- m--;
- }
- else
- *s++ = SOAP_UNKNOWN_CHAR;
- }
- else
-#endif
- *s++ = (char)(c & 0xFF);
- }
- }
- }
-end:
- soap_unget(soap, c);
- *s = '\0';
-#ifdef WITH_FAST
- t = soap_strdup(soap, soap->labbuf);
-#else
- soap_size_block(soap, i+1);
- t = soap_save_block(soap, NULL);
-#endif
- if (flag == 2)
- if (soap_s2QName(soap, t, &t))
- return NULL;
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_wstring_out(struct soap *soap, const wchar_t *s, int flag)
-{ const char *t;
- char tmp;
- register wchar c;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->wide = NULL; /* soap_malloc() ??? */
- return SOAP_OK;
- }
-#endif
- while ((c = *s++))
- { switch (c)
- {
- case 9:
- if (flag)
- t = "	";
- else
- t = "\t";
- break;
- case 10:
- if (flag || !(soap->mode & SOAP_XML_CANONICAL))
- t = "
";
- else
- t = "\n";
- break;
- case 13:
- t = "
";
- break;
- case '&':
- t = "&";
- break;
- case '<':
- t = "<";
- break;
- case '>':
- if (flag)
- t = ">";
- else
- t = ">";
- break;
- case '"':
- if (flag)
- t = """;
- else
- t = "\"";
- break;
- default:
- if (c > 0 && c < 0x80)
- { tmp = (char)c;
- if (soap_send_raw(soap, &tmp, 1))
- return soap->error;
- }
- else if (soap_pututf8(soap, (unsigned long)c))
- return soap->error;
- continue;
- }
- if (soap_send(soap, t))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t *
-SOAP_FMAC2
-soap_wstring_in(struct soap *soap, int flag)
-{ wchar_t *s;
- register int i, n = 0;
- register wchar c;
- const char *t = NULL;
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { if (!(s = (wchar_t*)soap_push_block(soap, sizeof(wchar_t)*SOAP_BLKLEN)))
- return NULL;
- for (i = 0; i < SOAP_BLKLEN; i++)
- { if (t)
- { *s++ = (wchar_t)*t++;
- if (!*t)
- t = NULL;
- continue;
- }
- if (soap->mode & SOAP_C_LATIN)
- c = soap_get(soap);
- else
- c = soap_getutf8(soap);
- switch (c)
- {
- case TT:
- if (n == 0)
- goto end;
- n--;
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case LT:
- n++;
- *s++ = '<';
- break;
- case GT:
- *s++ = '>';
- break;
- case QT:
- *s++ = '"';
- break;
- case AP:
- *s++ = '\'';
- break;
- case '/':
- if (n > 0)
- { c = soap_getutf8(soap);
- if (c == GT)
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- if (flag)
- *s++ = (wchar)'<';
- else
- { *s++ = (wchar)'&';
- t = "lt;";
- }
- break;
- case '>':
- if (flag)
- *s++ = (wchar)'>';
- else
- { *s++ = (wchar)'&';
- t = "gt;";
- }
- break;
- case '"':
- if (flag)
- *s++ = (wchar)'"';
- else
- { *s++ = (wchar)'&';
- t = "quot;";
- }
- break;
- default:
- if ((int)c == EOF)
- goto end;
- *s++ = (wchar_t)c & 0x7FFFFFFF;
- }
- }
- }
-end:
- soap_unget(soap, c);
- *s = '\0';
- soap_size_block(soap, sizeof(wchar_t) * (i + 1));
- return (wchar_t*)soap_save_block(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_int2s(struct soap *soap, int n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outint(struct soap *soap, const char *tag, int id, const int *p, const char *type, int n)
-{ long m = (long)*p;
- return soap_outlong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2int(struct soap *soap, const char *s, int *p)
-{ if (s)
- { char *r;
- *p = (int)soap_strtol(s, &r, 10);
- if (*r)
- return soap->error = SOAP_TYPE;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int *
-SOAP_FMAC2
-soap_inint(struct soap *soap, const char *tag, int *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (int*)soap_id_enter(soap, soap->id, p, t, sizeof(int), 0);
- if (p && soap->body && !*soap->href)
- soap_s2int(soap, soap_value(soap), p);
- else
- p = (int*)soap_id_forward(soap, soap->href, p, t, sizeof(int));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_long2s(struct soap *soap, long n)
-{ sprintf(soap->tmpbuf, "%ld", n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outlong(struct soap *soap, const char *tag, int id, const long *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2long(struct soap *soap, const char *s, long *p)
-{ if (s)
- { char *r;
- *p = soap_strtol(s, &r, 10);
- if (*r)
- return soap->error = SOAP_TYPE;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-long *
-SOAP_FMAC2
-soap_inlong(struct soap *soap, const char *tag, long *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (long*)soap_id_enter(soap, soap->id, p, t, sizeof(long), 0);
- if (p && soap->body && !*soap->href)
- soap_s2long(soap, soap_value(soap), p);
- else
- p = (long*)soap_id_forward(soap, soap->href, p, t, sizeof(long));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_LONG642s(struct soap *soap, LONG64 n)
-{ sprintf(soap->tmpbuf, SOAP_LONG_FORMAT, n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outLONG64(struct soap *soap, const char *tag, int id, const LONG64 *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_LONG642s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2LONG64(struct soap *soap, const char *s, LONG64 *p)
-{ if (s && sscanf(s, SOAP_LONG_FORMAT, p) != 1)
- return soap->error = SOAP_TYPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-LONG64 *
-SOAP_FMAC2
-soap_inLONG64(struct soap *soap, const char *tag, LONG64 *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":integer")
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":negativeInteger")
- && soap_match_tag(soap, soap->type, ":nonPositiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":long")
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (LONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(LONG64), 0);
- if (soap->body && !*soap->href)
- soap_s2LONG64(soap, soap_value(soap), p);
- else
- p = (LONG64*)soap_id_forward(soap, soap->href, p, t, sizeof(LONG64));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_byte2s(struct soap *soap, char n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outbyte(struct soap *soap, const char *tag, int id, const char *p, const char *type, int n)
-{ long m = (long)*p;
- return soap_outlong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2byte(struct soap *soap, const char *s, char *p)
-{ if (s)
- { long n;
- char *r;
- n = soap_strtol(s, &r, 10);
- if (*r || n < -128 || n > 127)
- return soap->error = SOAP_TYPE;
- *p = (char)n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_inbyte(struct soap *soap, const char *tag, char *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (char*)soap_id_enter(soap, soap->id, p, t, sizeof(char), 0);
- if (soap->body && !*soap->href)
- soap_s2byte(soap, soap_value(soap), p);
- else
- p = (char*)soap_id_forward(soap, soap->href, p, t, sizeof(char));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_short2s(struct soap *soap, short n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outshort(struct soap *soap, const char *tag, int id, const short *p, const char *type, int n)
-{ long m = (long)*p;
- return soap_outlong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2short(struct soap *soap, const char *s, short *p)
-{ if (s)
- { long n;
- char *r;
- n = soap_strtol(s, &r, 10);
- if (*r || n < -32768 || n > 32767)
- return soap->error = SOAP_TYPE;
- *p = (char)n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-short *
-SOAP_FMAC2
-soap_inshort(struct soap *soap, const char *tag, short *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (short*)soap_id_enter(soap, soap->id, p, t, sizeof(short), 0);
- if (soap->body && !*soap->href)
- soap_s2short(soap, soap_value(soap), p);
- else
- p = (short*)soap_id_forward(soap, soap->href, p, t, sizeof(short));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_float2s(struct soap *soap, float n)
-{ const char *s;
- if (isnan(n))
- s = "NaN";
- else if (n >= FLT_PINFTY)
- s = "INF";
- else if (n <= FLT_NINFTY)
- s = "-INF";
- else
- { sprintf(soap->tmpbuf, soap->float_format, n);
- s = soap->tmpbuf;
- }
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outfloat(struct soap *soap, const char *tag, int id, const float *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_float2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2float(struct soap *soap, const char *s, float *p)
-{ if (s)
- { if (!soap_tag_cmp(s, "INF"))
- *p = FLT_PINFTY;
- else if (!soap_tag_cmp(s, "+INF"))
- *p = FLT_PINFTY;
- else if (!soap_tag_cmp(s, "-INF"))
- *p = FLT_NINFTY;
- else if (!soap_tag_cmp(s, "NaN"))
- *p = FLT_NAN;
- else
- {
-#ifdef HAVE_STRTOD
- char *r;
- *p = (float)strtod(s, &r);
- if (*r)
-#endif
- if (sscanf(s, soap->float_format, p) != 1)
- return soap->error = SOAP_TYPE;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static int soap_isnumeric(struct soap *soap, const char *type)
-{ if (soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":float")
- && soap_match_tag(soap, soap->type, ":double")
- && soap_match_tag(soap, soap->type, ":decimal")
- && soap_match_tag(soap, soap->type, ":integer")
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":negativeInteger")
- && soap_match_tag(soap, soap->type, ":nonPositiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":long")
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte")
- && soap_match_tag(soap, soap->type, ":unsignedLong")
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return SOAP_ERR;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-float *
-SOAP_FMAC2
-soap_infloat(struct soap *soap, const char *tag, float *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type != '\0' && soap_isnumeric(soap, type))
- return NULL;
- p = (float*)soap_id_enter(soap, soap->id, p, t, sizeof(float), 0);
- if (soap->body && !*soap->href)
- soap_s2float(soap, soap_value(soap), p);
- else
- p = (float*)soap_id_forward(soap, soap->href, p, t, sizeof(float));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_double2s(struct soap *soap, double n)
-{ const char *s;
- if (isnan(n))
- s = "NaN";
- else if (n >= DBL_PINFTY)
- s = "INF";
- else if (n <= DBL_NINFTY)
- s = "-INF";
- else
- { sprintf(soap->tmpbuf, soap->double_format, n);
- s = soap->tmpbuf;
- }
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outdouble(struct soap *soap, const char *tag, int id, const double *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_double2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2double(struct soap *soap, const char *s, double *p)
-{ if (s)
- { if (!soap_tag_cmp(s, "INF"))
- *p = DBL_PINFTY;
- else if (!soap_tag_cmp(s, "+INF"))
- *p = DBL_PINFTY;
- else if (!soap_tag_cmp(s, "-INF"))
- *p = DBL_NINFTY;
- else if (!soap_tag_cmp(s, "NaN"))
- *p = DBL_NAN;
- else
- {
-#ifdef HAVE_STRTOD
- char *r;
- *p = strtod(s, &r);
- if (*r)
-#endif
- if (sscanf(s, soap->double_format, p) != 1)
- return soap->error = SOAP_TYPE;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-double *
-SOAP_FMAC2
-soap_indouble(struct soap *soap, const char *tag, double *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type != '\0' && soap_isnumeric(soap, type))
- return NULL;
- p = (double*)soap_id_enter(soap, soap->id, p, t, sizeof(double), 0);
- if (soap->body && !*soap->href)
- soap_s2double(soap, soap_value(soap), p);
- else
- p = (double*)soap_id_forward(soap, soap->href, p, t, sizeof(double));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedByte2s(struct soap *soap, unsigned char n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedByte(struct soap *soap, const char *tag, int id, const unsigned char *p, const char *type, int n)
-{ unsigned long m = (unsigned long)*p;
- return soap_outunsignedLong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedByte(struct soap *soap, const char *s, unsigned char *p)
-{ if (s)
- { unsigned long n;
- char *r;
- n = soap_strtoul(s, &r, 10);
- if (*r || n > 255)
- return soap->error = SOAP_TYPE;
- *p = (unsigned char)n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned char *
-SOAP_FMAC2
-soap_inunsignedByte(struct soap *soap, const char *tag, unsigned char *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (unsigned char*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned char), 0);
- if (soap->body && !*soap->href)
- soap_s2unsignedByte(soap, soap_value(soap), p);
- else
- p = (unsigned char*)soap_id_forward(soap, soap->href, p, t, sizeof(unsigned char));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedShort2s(struct soap *soap, unsigned short n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedShort(struct soap *soap, const char *tag, int id, const unsigned short *p, const char *type, int n)
-{ unsigned long m = (unsigned long)*p;
- return soap_outunsignedLong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedShort(struct soap *soap, const char *s, unsigned short *p)
-{ if (s)
- { unsigned long n;
- char *r;
- n = soap_strtoul(s, &r, 10);
- if (*r || n > 65535)
- return soap->error = SOAP_TYPE;
- *p = (unsigned short)n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-unsigned short *
-SOAP_FMAC2
-soap_inunsignedShort(struct soap *soap, const char *tag, unsigned short *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (unsigned short*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned short), 0);
- if (soap->body && !*soap->href)
- soap_s2unsignedShort(soap, soap_value(soap), p);
- else
- p = (unsigned short*)soap_id_forward(soap, soap->href, p, t, sizeof(unsigned short));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedInt2s(struct soap *soap, unsigned int n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedInt(struct soap *soap, const char *tag, int id, const unsigned int *p, const char *type, int n)
-{ unsigned long m = (unsigned long)*p;
- return soap_outunsignedLong(soap, tag, id, &m, type, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedInt(struct soap *soap, const char *s, unsigned int *p)
-{ if (s)
- { char *r;
- *p = (unsigned int)soap_strtoul(s, &r, 10);
- if (*r)
- return soap->error = SOAP_TYPE;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned int *
-SOAP_FMAC2
-soap_inunsignedInt(struct soap *soap, const char *tag, unsigned int *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (unsigned int*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned int), 0);
- if (soap->body && !*soap->href)
- soap_s2unsignedInt(soap, soap_value(soap), p);
- else
- p = (unsigned int*)soap_id_forward(soap, soap->href, p, t, sizeof(unsigned int));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedLong2s(struct soap *soap, unsigned long n)
-{ sprintf(soap->tmpbuf, "%lu", n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedLong(struct soap *soap, const char *tag, int id, const unsigned long *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedLong(struct soap *soap, const char *s, unsigned long *p)
-{ if (s)
- { char *r;
- *p = soap_strtoul(s, &r, 10);
- if (*r)
- return soap->error = SOAP_TYPE;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned long *
-SOAP_FMAC2
-soap_inunsignedLong(struct soap *soap, const char *tag, unsigned long *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (unsigned long*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned long), 0);
- if (soap->body && !*soap->href)
- soap_s2unsignedLong(soap, soap_value(soap), p);
- else
- p = (unsigned long*)soap_id_forward(soap, soap->href, p, t, sizeof(unsigned long));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_ULONG642s(struct soap *soap, ULONG64 n)
-{ sprintf(soap->tmpbuf, SOAP_ULONG_FORMAT, n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outULONG64(struct soap *soap, const char *tag, int id, const ULONG64 *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_ULONG642s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2ULONG64(struct soap *soap, const char *s, ULONG64 *p)
-{ if (s && sscanf(s, SOAP_ULONG_FORMAT, p) != 1)
- return soap->error = SOAP_TYPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-ULONG64 *
-SOAP_FMAC2
-soap_inULONG64(struct soap *soap, const char *tag, ULONG64 *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":unsignedLong")
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (ULONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(ULONG64), 0);
- if (soap->body && !*soap->href)
- soap_s2ULONG64(soap, soap_value(soap), p);
- else
- p = (ULONG64*)soap_id_forward(soap, soap->href, p, t, sizeof(ULONG64));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2string(struct soap *soap, const char *s, char **t)
-{ *t = NULL;
- if (s && !(*t = soap_strdup(soap, s)))
- return soap->error = SOAP_EOM;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2QName(struct soap *soap, const char *s, char **t)
-{ if (s)
- { struct soap_nlist *np = soap->nlist;
- const char *p = strchr(s, ':');
- if (p)
- { int n = p - s;
- while (np && (np->index == -2 || strncmp(np->id, s, n) || np->id[n]))
- np = np->next;
- p++;
- }
- else
- { while (np && *np->id)
- np = np->next;
- p = s;
- }
- if (np)
- { if (np->index >= 0 && soap->local_namespaces)
- { const char *q = soap->local_namespaces[np->index].id;
- if (q)
- { if ((*t = (char*)soap_malloc(soap, strlen(p) + strlen(q) + 2)))
- sprintf(*t, "%s:%s", q, p);
- return SOAP_OK;
- }
- }
- if (np->ns)
- { if ((*t = (char*)soap_malloc(soap, strlen(p) + strlen(np->ns) + 4)))
- sprintf(*t, "\"%s\":%s", np->ns, p);
- return SOAP_OK;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Namespace prefix of '%s' not defined (index=%d, URI=%s)\n", s, np->index, np->ns?np->ns:""));
- return soap->error = SOAP_NAMESPACE;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Namespace prefix of '%s' not defined, assuming empty namespace\n", s));
- if ((*t = (char*)soap_malloc(soap, strlen(p) + 4)))
- sprintf(*t, "\"\":%s", p);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_QName2s(struct soap *soap, const char *s)
-{ struct Namespace *p;
- char *t;
- int n;
- if (!s || *s != '"')
- return s;
- s++;
- if ((p = soap->local_namespaces))
- { for (; p->id; p++)
- { if (p->ns)
- if (!soap_tag_cmp(s, p->ns))
- break;
- if (p->in)
- if (!soap_tag_cmp(s, p->in))
- break;
- }
- if (p && p->id)
- { s = strchr(s, '"');
- if (s)
- { t = (char*)soap_malloc(soap, strlen(p->id) + strlen(s));
- strcpy(t, p->id);
- strcat(t, s + 1);
- return t;
- }
- }
- }
- t = (char*)strchr(s, '"');
- if (t)
- n = t - s;
- else
- n = 0;
- t = soap_strdup(soap, s);
- t[n] = '\0';
- sprintf(soap->tmpbuf, "xmlns:_%lu", soap->idnum++);
- soap_set_attr(soap, soap->tmpbuf, t);
- s = strchr(s, '"');
- if (s)
- { t = (char*)soap_malloc(soap, strlen(soap->tmpbuf) + strlen(s) - 6);
- strcpy(t, soap->tmpbuf + 6);
- strcat(t, s + 1);
- }
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outstring(struct soap *soap, const char *tag, int id, char *const*p, const char *type, int n)
-{ if (!*p)
- { if (soap_element_null(soap, tag, id, type))
- return soap->error;
- }
- else
- { struct soap_plist *pp;
- int i = soap_pointer_lookup(soap, *p, n, &pp);
- if (id > 0)
- { if (i)
- { if (soap_element_begin_out(soap, tag, id, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- soap_set_embedded(soap, pp);
- }
- else
- { i = soap_pointer_enter(soap, *p, n, &pp);
- if (soap_element_begin_out(soap, tag, id, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 0;
- else
- pp->mark2 = 0;
- }
- }
- else if (i)
- { if (soap_is_embedded(soap, pp))
- { if (soap_element_ref(soap, tag, 0, i))
- return soap->error;
- }
- else if (soap_is_single(soap, pp))
- { if (soap_element_begin_out(soap, tag, 0, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- }
- else
- { if (soap_element_begin_out(soap, tag, i, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- soap_set_embedded(soap, pp);
- }
- }
- else
- { soap_pointer_enter(soap, *p, n, &pp);
- if (soap_element_begin_out(soap, tag, id, type) || soap_string_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 0;
- else
- pp->mark2 = 0;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char **
-SOAP_FMAC2
-soap_instring(struct soap *soap, const char *tag, char **p, const char *type, int t, int flag)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { p = (char**)soap_id_enter(soap, soap->id, p, t, sizeof(char**), 0);
- if (p)
- *p = NULL;
- }
- else if (soap->body && !*soap->href)
- { if (soap_match_tag(soap, soap->type, "PointerTostring") == 0)
- { p = (char**)soap_id_enter(soap, soap->id, p, t, sizeof(char**), 0);
- p = (char**)soap_instring(soap, "string", p, type, t, flag);
- }
- else
- { if (!p)
- if ((p = (char**)soap_id_enter(soap, SOAP_STR_EOS, p, t, sizeof(char**), 0)) == NULL)
- return NULL;
- *p = (char*)soap_id_enter(soap, soap->id, soap_string_in(soap, flag), t, 0, 0);
- }
- }
- else
- p = (char**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(char*), 0);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outwstring(struct soap *soap, const char *tag, int id, wchar_t *const*p, const char *type, int n)
-{ if (!*p)
- { if (soap_element_null(soap, tag, id, type))
- return soap->error;
- }
- else
- { struct soap_plist *pp;
- int i = soap_pointer_lookup(soap, *p, n, &pp);
- if (id > 0)
- { if (i)
- { if (soap_element_begin_out(soap, tag, id, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- soap_set_embedded(soap, pp);
- }
- else
- { i = soap_pointer_enter(soap, *p, n, &pp);
- if (soap_element_begin_out(soap, tag, id, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 0;
- else
- pp->mark2 = 0;
- }
- }
- else if (i)
- { if (soap_is_embedded(soap, pp))
- { if (soap_element_ref(soap, tag, 0, i))
- return soap->error;
- }
- else if (soap_is_single(soap, pp))
- { if (soap_element_begin_out(soap, tag, 0, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- }
- else
- { if (soap_element_begin_out(soap, tag, i, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- soap_set_embedded(soap, pp);
- }
- }
- else
- { if (soap_element_begin_out(soap, tag, id, type) || soap_wstring_out(soap, *p, 0) || soap_element_end_out(soap, tag))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 0;
- else
- pp->mark2 = 0;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t **
-SOAP_FMAC2
-soap_inwstring(struct soap *soap, const char *tag, wchar_t **p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { p = (wchar_t**)soap_id_enter(soap, soap->id, p, t, sizeof(wchar_t**), 0);
- if (p)
- *p = NULL;
- }
- else if (soap->body && !*soap->href)
- { if (soap_match_tag(soap, soap->type, "PointerTostring") == 0)
- p = (wchar_t**)soap_inwstring(soap, "string", (wchar_t**)soap_id_enter(soap, soap->id, p, t, sizeof(wchar_t**), 0), type, t);
- else
- { if (!p)
- if (!(p = (wchar_t**)soap_id_enter(soap, SOAP_STR_EOS, p, t, sizeof(wchar_t**), 0)))
- return NULL;
- *p = (wchar_t*)soap_id_enter(soap, soap->id, soap_wstring_in(soap, 1), t, 0, 0);
- }
- }
- else
- p = (wchar_t**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(wchar_t*), 0);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static time_t
-soap_timegm(struct tm *T)
-{
-#if defined(HAVE_TIMEGM)
- return timegm(T);
-#elif defined(HAVE_GETTIMEOFDAY)
- struct timezone t;
- struct timeval tv;
- gettimeofday(&tv, &t); /* doesn't work properly on Solaris */
- T->tm_min -= t.tz_minuteswest;
- T->tm_isdst = (t.tz_dsttime != 0);
- return mktime(T);
-/* WR[ */
- /* The following define was added for VxWorks*/
-#elif defined(HAVE_MKTIME)
- /* FOR VXWORKS:
- vxWorks does not seem to have any variable representation of time zones, but
- timezone information can be set in INSTALL_DIR/target/h/private/timeP.h header
- file, by setting the ZONEBUFFER define. The ZONEBUFFER define follows this
- format:
-
- name_of_zone:<(unused)>:time_in_minutes_from_UTC:daylight_start:daylight_end
-
- To calculate local time, the value of time_in_minutes_from_UTC is subtracted
- from UTC; time_in_minutes_from_UTC must be positive. Daylight information is
- expressed as mmddhh (month-day-hour), for example:
-
- UTC::0:040102:100102
-
- */
- return mktime(T);
-/* ]WR */
-#elif defined(HAVE_FTIME)
- struct timeb t;
- t.timezone = 0;
- t.dstflag = -1;
- ftime(&t);
- T->tm_min -= t.timezone;
- T->tm_isdst = t.dstflag; /* doesn't work properly on Solaris */
- return mktime(T);
-#else
-#warning "time_t (de)serialization is not MT safe on this platform"
- time_t t;
- char *tz = getenv("TZ");
- putenv("TZ=UTC");
- tzset();
- t = mktime(T);
- if (tz)
- { char tmp[16];
- strcpy(tmp, "TZ=");
- strncat(tmp, tz, 12);
- tmp[15] = '\0';
- putenv(tmp);
- }
- else
- putenv("TZ=");
- tzset();
- return t;
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_dateTime2s(struct soap *soap, time_t n)
-{ struct tm T;
- struct tm *pT = &T;
-#if defined(HAVE_GMTIME_R)
- if (gmtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PGMTIME_R)
- if (gmtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-#elif defined(HAVE_PGMTIME)
- if (gmtime(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-/* ]WR */
-#elif defined(HAVE_GMTIME)
- if ((pT = gmtime(&n)))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-#elif defined(HAVE_GETTIMEOFDAY)
- struct timezone t;
-#if defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- { struct timeval tv;
- gettimeofday(&tv, &t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.tz_minuteswest/60-(t.tz_dsttime!=0), abs(t.tz_minuteswest)%60);
- }
-#else
- if ((pT = localtime(&n)))
- { struct timeval tv;
- gettimeofday(&tv, &t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.tz_minuteswest/60-(t.tz_dsttime!=0), abs(t.tz_minuteswest)%60);
- }
-#endif
-#elif defined(HAVE_FTIME)
- struct timeb t;
-#if defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- { ftime(&t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60-(t.dstflag!=0), abs(t.timezone)%60);
- }
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PLOCALTIME_R)
- if (localtime_r(&n, pT))
- { strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf+strlen(soap->tmpbuf), "%+03d:%02d", t.timezone/60, abs(t.timezone)%60);
- }
-/* ]WR */
-#else
- if ((pT = localtime(&n)))
- { ftime(&t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60-(t.dstflag!=0), abs(t.timezone)%60);
- }
-#endif
-#elif defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PLOCALTIME_R)
- if (localtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-/* ]WR */
-#else
- if ((pT = localtime(&n)))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-#endif
- else
- strcpy(soap->tmpbuf, "1969-12-31T23:59:59Z");
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outdateTime(struct soap *soap, const char *tag, int id, const time_t *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_dateTime2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2dateTime(struct soap *soap, const char *s, time_t *p)
-{ if (s)
- { struct tm T;
- char zone[16];
- memset(&T, 0, sizeof(struct tm));
- zone[sizeof(zone)-1] = '\0';
- sscanf(s, "%d-%d-%dT%d:%d:%d%15s", &T.tm_year, &T.tm_mon, &T.tm_mday, &T.tm_hour, &T.tm_min, &T.tm_sec, zone);
- if (T.tm_year == 1)
- T.tm_year = 70;
- else
- T.tm_year -= 1900;
- T.tm_mon--;
- if (*zone)
- { if (*zone == '.')
- { for (s = zone + 1; *s; s++)
- if (*s < '0' || *s > '9')
- break;
- }
- else
- s = zone;
- if (*s != 'Z')
- { int h = 0, m = 0;
- sscanf(s, "%d:%d", &h, &m);
- T.tm_hour -= h;
- if (h >= 0)
- T.tm_min -= m;
- else
- T.tm_min += m;
- }
- *p = soap_timegm(&T);
- }
- else
- *p = mktime(&T); /* no time zone: suppose it is localtime? */
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-time_t *
-SOAP_FMAC2
-soap_indateTime(struct soap *soap, const char *tag, time_t *p, const char * type, int t)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (soap->null)
- { if (soap->mode & SOAP_XML_NIL)
- { soap->error = SOAP_NULL;
- return NULL;
- }
- return p;
- }
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":dateTime"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (time_t*)soap_id_enter(soap, soap->id, p, t, sizeof(time_t), 0);
- if (soap->body && !*soap->href)
- soap_s2dateTime(soap, soap_value(soap), p);
- else
- p = (time_t*)soap_id_forward(soap, soap->href, p, t, sizeof(time_t));
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outliteral(struct soap *soap, const char *tag, char *const*p)
-{ int i;
- const char *t = NULL;
- if (tag && *tag != '-')
- { if ((t = strchr(tag, ':')))
- { strncpy(soap->tmpbuf, tag, t-tag);
- soap->tmpbuf[t-tag] = '\0';
- for (i = 0; soap->local_namespaces[i].id; i++)
- if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
- break;
- t++;
- sprintf(soap->tmpbuf, "<%s xmlns=\"%s\">", t, soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS);
- }
- else
- { t = tag;
- sprintf(soap->tmpbuf, "<%s>", tag);
- }
- if (soap_send(soap, soap->tmpbuf))
- return soap->error;
- }
- if (p && *p)
- { if (soap_send(soap, *p))
- return soap->error;
- }
- if (t)
- { sprintf(soap->tmpbuf, "</%s>", t);
- return soap_send(soap, soap->tmpbuf);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char **
-SOAP_FMAC2
-soap_inliteral(struct soap *soap, const char *tag, char **p)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (!p)
- if (!(p = (char**)soap_malloc(soap, sizeof(char*))))
- return NULL;
- if (soap->null)
- *p = NULL;
- else if (soap->body)
- *p = soap_string_in(soap, 0);
- else
- *p = NULL;
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p)
-{ int i;
- const char *t = NULL;
- wchar_t c;
- const wchar_t *s;
- if (tag && *tag != '-')
- { if (tag && (t = strchr(tag, ':')))
- { strncpy(soap->tmpbuf, tag, t-tag);
- soap->tmpbuf[t-tag] = '\0';
- for (i = 0; soap->local_namespaces[i].id; i++)
- if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
- break;
- t++;
- sprintf(soap->tmpbuf, "<%s xmlns=\"%s\">", t, soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS);
- }
- else
- { t = tag;
- sprintf(soap->tmpbuf, "<%s>", tag);
- }
- if (soap_send(soap, soap->tmpbuf))
- return soap->error;
- }
- if (p)
- { s = *p;
- while ((c = *s++))
- if (soap_pututf8(soap, (unsigned char)c))
- return soap->error;
- }
- if (t)
- { sprintf(soap->tmpbuf, "</%s>", t);
- return soap_send(soap, soap->tmpbuf);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t **
-SOAP_FMAC2
-soap_inwliteral(struct soap *soap, const char *tag, wchar_t **p)
-{ if (soap_element_begin_in(soap, tag))
- return NULL;
- if (!p)
- if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*))))
- return NULL;
- if (soap->null)
- *p = NULL;
- else if (soap->body)
- *p = soap_wstring_in(soap, 0);
- else
- *p = NULL;
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_value(struct soap *soap)
-{ size_t i;
- wchar c = 0;
- char *s;
- s = soap->tmpbuf;
- for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++)
- { c = soap_get(soap);
- if (c == TT || (int)c == EOF || soap_blank(c))
- break;
- *s++ = (char)c;
- }
- if ((int)c == EOF || c == TT)
- soap_unget(soap, c);
- *s = '\0';
- return soap->tmpbuf; /* return non-null pointer */
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getline(struct soap *soap, char *s, int len)
-{ int i = len;
- wchar c = 0;
- for (;;)
- { while (--i > 0)
- { c = soap_getchar(soap);
- if (c == '\r' || c == '\n' || (int)c == EOF)
- break;
- *s++ = (char)c;
- }
- *s = '\0';
- while (c != '\n' && (int)c != EOF)
- c = soap_getchar(soap);
- if ((int)c == EOF)
- return SOAP_EOF;
- if (i+1 == len) /* empty line: end of HTTP header */
- break;
- c = soap_unget(soap, soap_getchar(soap));
- if (c != ' ' && c != '\t') /* HTTP line continuation? */
- break;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static size_t
-soap_begin_dime(struct soap *soap)
-{
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- { size_t count;
- sprintf(soap->id, soap->dime_id_format, 0);
- soap->dime_id = soap->id;
- if (soap->local_namespaces)
- { if (soap->local_namespaces[0].out)
- soap->dime_type = (char*)soap->local_namespaces[0].out;
- else
- soap->dime_type = (char*)soap->local_namespaces[0].ns;
- }
- soap->dime_options = NULL;
- count = soap->dime_size + 12 + ((soap->count+3)&(~3)) + ((strlen(soap->dime_id)+3)&(~3)) + ((strlen(soap->dime_type)+3)&(~3));
- soap->dime_size = soap->count;
- if (soap->dime_count)
- soap->dime_flags = SOAP_DIME_MB | SOAP_DIME_ABSURI;
- else
- soap->dime_flags = SOAP_DIME_MB | SOAP_DIME_ME | SOAP_DIME_ABSURI;
- return count;
- }
-#endif
- return soap->count;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static int
-soap_putdimefield(struct soap *soap, const char *s, size_t n)
-{ if (soap_send_raw(soap, s, n))
- return soap->error;
- return soap_send_raw(soap, SOAP_STR_PADDING, -(long)n&3);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_dime_option(struct soap *soap, unsigned short type, const char *option)
-{ size_t n;
- char *s = NULL;
- if (option)
- { n = strlen(option);
- s = (char*)soap_malloc(soap, n + 5);
- if (s)
- { s[0] = type >> 8;
- s[1] = type & 0xFF;
- s[2] = n >> 8;
- s[3] = n & 0xFF;
- strcpy(s + 4, option);
- }
- }
- return s;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putdimehdr(struct soap *soap)
-{ unsigned char tmp[12];
- size_t optlen = 0, idlen = 0, typelen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Put DIME header id='%s'\n", soap->dime_id?soap->dime_id:""));
- if (soap->dime_options)
- optlen = (((unsigned char)soap->dime_options[2] << 8) | ((unsigned char)soap->dime_options[3])) + 4;
- if (soap->dime_id)
- idlen = strlen(soap->dime_id);
- if (soap->dime_type)
- typelen = strlen(soap->dime_type);
- tmp[0] = SOAP_DIME_VERSION | (soap->dime_flags & 0x7);
- tmp[1] = soap->dime_flags & 0xF0;
- tmp[2] = optlen >> 8;
- tmp[3] = optlen & 0xFF;
- tmp[4] = idlen >> 8;
- tmp[5] = idlen & 0xFF;
- tmp[6] = typelen >> 8;
- tmp[7] = typelen & 0xFF;
- tmp[8] = soap->dime_size >> 24;
- tmp[9] = (soap->dime_size >> 16) & 0xFF;
- tmp[10] = (soap->dime_size >> 8) & 0xFF;
- tmp[11] = soap->dime_size & 0xFF;
- if (soap_send_raw(soap, (char*)tmp, 12)
- || soap_putdimefield(soap, soap->dime_options, optlen)
- || soap_putdimefield(soap, soap->dime_id, idlen)
- || soap_putdimefield(soap, soap->dime_type, typelen))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putdime(struct soap *soap, int i, char *id, char *type, char *options, void *ptr, size_t size)
-{ void *h;
- if (id)
- soap->dime_id = id;
- else
- { sprintf(soap->id, soap->dime_id_format, i);
- soap->dime_id = soap->id;
- }
- soap->dime_type = type;
- soap->dime_options = options;
- soap->dime_size = size;
- soap->dime_flags = SOAP_DIME_VERSION | SOAP_DIME_MEDIA;
- if (soap->fdimereadopen && ((h = soap->fdimereadopen(soap, (void*)ptr, soap->dime_id, type, options)) || soap->error))
- { size_t n;
- if (!h)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadopen failed\n"));
- return soap->error;
- }
- if (!size && ((soap->mode & SOAP_ENC_XML) || (soap->mode & SOAP_IO) == SOAP_IO_CHUNK || (soap->mode & SOAP_IO) == SOAP_IO_STORE))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked streaming DIME\n"));
- n = sizeof(soap->tmpbuf);
- do
- { size = soap->fdimeread(soap, h, soap->tmpbuf, n);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread returned %lu bytes\n", (unsigned long)size));
- if (size == n)
- soap->dime_flags |= SOAP_DIME_CF;
- else
- { soap->dime_flags &= ~SOAP_DIME_CF;
- if (--soap->dime_count == 0)
- soap->dime_flags |= SOAP_DIME_ME;
- }
- soap->dime_size = size;
- if (soap_putdimehdr(soap)
- || soap_send_raw(soap, soap->tmpbuf, size)
- || soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime_size&3))
- break;
- if (soap->dime_id)
- { soap->dime_flags &= ~(SOAP_DIME_MB | SOAP_DIME_MEDIA);
- soap->dime_id = NULL;
- soap->dime_type = NULL;
- soap->dime_options = NULL;
- }
- } while (size >= n);
- }
- else
- { if (--soap->dime_count == 0)
- soap->dime_flags |= SOAP_DIME_ME;
- if (soap_putdimehdr(soap))
- return soap->error;
- do
- { if (size < sizeof(soap->tmpbuf))
- n = size;
- else
- n = sizeof(soap->tmpbuf);
- if (!(n = soap->fdimeread(soap, h, soap->tmpbuf, n)))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)soap->dime_size));
- soap->error = SOAP_EOF;
- break;
- }
- if (soap_send_raw(soap, soap->tmpbuf, n))
- break;
- size -= n;
- } while (size);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
- soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime_size&3);
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
- if (soap->fdimereadclose)
- soap->fdimereadclose(soap, h);
- return soap->error;
- }
- if (--soap->dime_count == 0)
- soap->dime_flags |= SOAP_DIME_ME;
- if (soap_putdimehdr(soap))
- return soap->error;
- return soap_putdimefield(soap, (char*)ptr, size);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static char *
-soap_getdimefield(struct soap *soap, size_t n)
-{ register wchar c;
- register int i;
- register char *s;
- char *p = NULL;
- if (n)
- { p = (char*)soap_malloc(soap, n + 1);
- if (p)
- { s = p;
- for (i = n; i > 0; i--)
- { if ((int)(c = soap_get1(soap)) == EOF)
- { soap->error = SOAP_EOF;
- return NULL;
- }
- *s++ = (char)c;
- }
- *s = '\0';
- if ((soap->error = soap_move(soap, -(long)n&3)))
- return NULL;
- }
- else
- soap->error = SOAP_EOM;
- }
- return p;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getdimehdr(struct soap *soap)
-{ register wchar c;
- register char *s;
- register int i;
- unsigned char tmp[12];
- size_t optlen, idlen, typelen;
- if (!(soap->mode & SOAP_ENC_DIME))
- return soap->error = SOAP_EOD;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME header\n"));
- if (soap->dime_buflen || soap->dime_chunksize)
- { if (soap_move(soap, (long)(soap->dime_size - soap_tell(soap))))
- return soap->error = SOAP_EOF;
- soap_unget(soap, soap_getchar(soap)); /* skip padding and get hdr */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... From chunked\n"));
- return SOAP_OK;
- }
- s = (char*)tmp;
- for (i = 12; i > 0; i--)
- { if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- if ((tmp[0] & 0xF8) != SOAP_DIME_VERSION)
- return soap->error = SOAP_DIME_MISMATCH;
- soap->dime_flags = (tmp[0] & 0x7) | (tmp[1] & 0xF0);
- optlen = (tmp[2] << 8) | tmp[3];
- idlen = (tmp[4] << 8) | tmp[5];
- typelen = (tmp[6] << 8) | tmp[7];
- soap->dime_size = (tmp[8] << 24) | (tmp[9] << 16) | (tmp[10] << 8) | tmp[11];
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME size=%u flags=0x%X\n", (unsigned int)soap->dime_size, soap->dime_flags));
- if (!(soap->dime_options = soap_getdimefield(soap, optlen)) && soap->error)
- return soap->error;
- if (!(soap->dime_id = soap_getdimefield(soap, idlen)) && soap->error)
- return soap->error;
- if (!(soap->dime_type = soap_getdimefield(soap, typelen)) && soap->error)
- return soap->error;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME id=%s, type=%s, options=%s\n", soap->dime_id?soap->dime_id:"", soap->dime_type?soap->dime_type:"", soap->dime_options?soap->dime_options+4:""));
- if (soap->dime_flags & SOAP_DIME_ME)
- soap->mode &= ~SOAP_ENC_DIME;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getdime(struct soap *soap)
-{ if (soap_getdimehdr(soap))
- return soap->error;
- if (soap->fdimewriteopen && ((soap->dime_ptr = (char*)soap->fdimewriteopen(soap, soap->dime_id, soap->dime_type, soap->dime_options)) || soap->error))
- { char *id, *type, *options;
- size_t size, n;
- if (!soap->dime_ptr)
- return soap->error;
- id = soap->dime_id;
- type = soap->dime_type;
- options = soap->dime_options;
- for (;;)
- { size = soap->dime_size;
- for (;;)
- { n = soap->buflen - soap->bufidx;
- if (size < n)
- n = size;
- if ((soap->error = soap->fdimewrite(soap, (void*)soap->dime_ptr, soap->buf + soap->bufidx, n)))
- break;
- size -= n;
- if (!size)
- { soap->bufidx += n;
- break;
- }
- if (soap_recv(soap))
- { soap->error = SOAP_EOF;
- goto end;
- }
- }
- if (soap_move(soap, -(long)soap->dime_size&3))
- { soap->error = SOAP_EOF;
- break;
- }
- if (!(soap->dime_flags & SOAP_DIME_CF))
- break;
- if (soap_getdimehdr(soap))
- break;
- }
-end:
- if (soap->fdimewriteclose)
- soap->fdimewriteclose(soap, (void*)soap->dime_ptr);
- soap->dime_size = 0;
- soap->dime_id = id;
- soap->dime_type = type;
- soap->dime_options = options;
- }
- else if (soap->dime_flags & SOAP_DIME_CF)
- { char *id, *type, *options;
- register wchar c;
- register char *s;
- register int i;
- id = soap->dime_id;
- type = soap->dime_type;
- options = soap->dime_options;
- if (soap_new_block(soap))
- return SOAP_EOM;
- for (;;)
- { s = (char*)soap_push_block(soap, soap->dime_size);
- if (!s)
- return soap->error = SOAP_EOM;
- for (i = soap->dime_size; i > 0; i--)
- { if ((int)(c = soap_get1(soap)) == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- if (soap_move(soap, -(long)soap->dime_size&3))
- return soap->error = SOAP_EOF;
- if (!(soap->dime_flags & SOAP_DIME_CF))
- break;
- if (soap_getdimehdr(soap))
- return soap->error;
- }
- soap->dime_size = soap->blist->size++; /* allocate one more for '\0' */
- if (!(soap->dime_ptr = soap_save_block(soap, NULL)))
- return soap->error;
- soap->dime_ptr[soap->dime_size] = '\0'; /* make 0-terminated to enable string-based attachments */
- soap->dime_id = id;
- soap->dime_type = type;
- soap->dime_options = options;
- }
- else
- soap->dime_ptr = soap_getdimefield(soap, soap->dime_size);
- return soap->error;
-}
-#endif
-#endif
-
-/******************************************************************************/
-
-#ifdef WITH_COOKIES
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_encode_cookie(const char *s, char *t, int len)
-{ register int c;
- register int n = len;
- while ((c = *s++) && --n > 0)
- { if (c > ' ' && c < 128 && c != ';' && c != ',')
- *t++ = c;
- else if (n > 2)
- { *t++ = '%';
- *t++ = (c >> 4) + (c > 159 ? '7' : '0');
- c &= 0xF;
- *t++ = c + (c > 9 ? '7' : '0');
- n -= 2;
- }
- else
- break;
- }
- *t = '\0';
- return len - n;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_decode_cookie(char *buf, int len, const char *val)
-{ const char *s;
- char *t;
- for (s = val; *s; s++)
- if (*s != ' ' && *s != '=')
- break;
- if (*s == '"')
- { t = buf;
- s++;
- while (*s && *s != '"' && --len)
- *t++ = *s++;
- *t = '\0';
- do s++;
- while (*s && *s != ';' && *s != '=');
- }
- else
- { t = buf;
- while (*s && *s != ';' && *s != '=' && --len)
- switch (*s)
- { case ' ':
- s++;
- break;
- case '%':
- *t++ = ((s[1] >= 'A' ? (s[1] & 0x7) + 9 : s[1] - '0') << 4)
- + (s[2] >= 'A' ? (s[2] & 0x7) + 9 : s[2] - '0');
- s += 3;
- break;
- default:
- *t++ = *s++;
- }
- *t = '\0';
- }
- return s;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- size_t n;
- if (!domain)
- domain = soap->cookie_domain;
- if (!path)
- path = soap->cookie_path;
- if (*path == '/')
- path++;
- n = strlen(path);
- for (p = soap->cookies; p; p = p->next)
- if (!strcmp(p->name, name)
- && domain
- && p->domain
- && !strcmp(p->domain, domain)
- && !strncmp(p->path, path, n))
- break;
- return p;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_set_cookie(struct soap *soap, const char *name, const char *value, const char *domain, const char *path)
-{ struct soap_cookie **p, *q;
- int n;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie: %s=%s domain=%s path=%s\n", name, value?value:"", domain?domain:"", path?path:""));
- if (!domain)
- domain = soap->cookie_domain;
- if (!path)
- path = soap->cookie_path;
- if (!path)
- { soap_set_receiver_error(soap, "Cookie path not set", NULL, SOAP_HTTP_ERROR);
- return NULL;
- }
- if (*path == '/')
- path++;
- q = soap_cookie(soap, name, domain, path);
- if (!q)
- { if ((q = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- { if ((q->name = (char*)SOAP_MALLOC(strlen(name)+1)))
- strcpy(q->name, name);
- q->value = NULL;
- q->domain = NULL;
- q->path = NULL;
- q->expire = -1;
- q->version = 0;
- q->secure = 0;
- q->env = 0;
- q->modified = 0;
- for (p = &soap->cookies, n = soap->cookie_max; *p && n; p = &(*p)->next, n--)
- if (!strcmp((*p)->name, name) && (*p)->path && strcmp((*p)->path, path) < 0)
- break;
- if (n)
- { q->next = *p;
- *p = q;
- }
- else
- { SOAP_FREE(q->name);
- SOAP_FREE(q);
- q = NULL;
- }
- }
- }
- else
- q->modified = 1;
- if (q)
- { if (q->value)
- { SOAP_FREE(q->value);
- q->value = NULL;
- }
- if (q->domain)
- { SOAP_FREE(q->domain);
- q->domain = NULL;
- }
- if (q->path)
- { SOAP_FREE(q->path);
- q->path = NULL;
- }
- if (value && *value && (q->value = (char*)SOAP_MALLOC(strlen(value)+1)))
- strcpy(q->value, value);
- if (domain && *domain && (q->domain = (char*)SOAP_MALLOC(strlen(domain)+1)))
- strcpy(q->domain, domain);
- if (path && *path && (q->path = (char*)SOAP_MALLOC(strlen(path)+1)))
- strcpy(q->path, path);
- q->session = 1;
- }
- return q;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie **p, *q;
- if (!domain)
- domain = soap->cookie_domain;
- if (!domain)
- { soap_set_receiver_error(soap, "Cookie domain not set", SOAP_STR_EOS, SOAP_HTTP_ERROR);
- return;
- }
- if (!path)
- path = soap->cookie_path;
- if (!path)
- { soap_set_receiver_error(soap, "Cookie path not set", SOAP_STR_EOS, SOAP_HTTP_ERROR);
- return;
- }
- if (*path == '/')
- path++;
- for (p = &soap->cookies, q = *p; q; q = *p)
- if (!strcmp(q->name, name) && !strcmp(q->domain, domain) && !strncmp(q->path, path, strlen(q->path)))
- { if (q->value)
- SOAP_FREE(q->value);
- if (q->domain)
- SOAP_FREE(q->domain);
- if (q->path)
- SOAP_FREE(q->path);
- *p = q->next;
- SOAP_FREE(q);
- }
- else
- p = &q->next;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_cookie_value(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- return p->value;
- return NULL;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_cookie_expire(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- return p->expire;
- return -1;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_cookie_expire(struct soap *soap, const char *name, long expire, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->expire = expire;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->session = 1;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_clr_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->session = 0;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putsetcookies(struct soap *soap)
-{ struct soap_cookie *p;
- char *s, tmp[4096];
- const char *t;
- for (p = soap->cookies; p; p = p->next)
- if (p->modified || !p->env)
- { s = tmp;
- if (p->name)
- s += soap_encode_cookie(p->name, s, tmp-s+4064);
- if (p->value)
- { *s++ = '=';
- s += soap_encode_cookie(p->value, s, tmp-s+4064);
- }
- if (p->domain && (int)strlen(p->domain) < tmp-s+4064)
- sprintf(s, ";Domain=%s", p->domain);
- else if (soap->cookie_domain && (int)strlen(soap->cookie_domain) < tmp-s+4064)
- sprintf(s, ";Domain=%s", soap->cookie_domain);
- strcpy(s, ";Path=/");
- if (p->path)
- t = p->path;
- else
- t = soap->cookie_path;
- if (t)
- { if (*t == '/')
- t++;
- if ((int)strlen(t) < tmp-s+4064)
- strcat(s, t);
- }
- s += strlen(s);
- if (p->version > 0)
- { sprintf(s, ";Version=%u", p->version);
- s += strlen(s);
- }
- if (p->expire >= 0)
- { sprintf(s, ";Max-Age=%ld", p->expire);
- s += strlen(s);
- }
- if (p->secure)
- strcpy(s, ";Secure");
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set-Cookie: %s\n", tmp));
- if (soap->fposthdr(soap, "Set-Cookie", tmp))
- return soap->error;
- }
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putcookies(struct soap *soap, const char *domain, const char *path, int secure)
-{ struct soap_cookie **p, *q;
- unsigned int version = 0;
- time_t now = time(NULL);
- char *s, tmp[4096];
- p = &soap->cookies;
- while ((q = *p))
- { if (q->expire && now > q->expire)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name));
- SOAP_FREE(q->name);
- if (q->value)
- SOAP_FREE(q->value);
- if (q->domain)
- SOAP_FREE(q->domain);
- if (q->path)
- SOAP_FREE(q->path);
- *p = q->next;
- SOAP_FREE(q);
- }
- else if ((!q->domain || !strcmp(q->domain, domain))
- && (!q->path || !strncmp(q->path, path, strlen(q->path)))
- && (!q->secure || secure))
- { s = tmp;
- if (q->version != version)
- { sprintf(s, "$Version=%u;", q->version);
- version = q->version;
- }
- if (q->name)
- s += soap_encode_cookie(q->name, s, tmp-s+4080);
- if (q->value)
- { *s++ = '=';
- s += soap_encode_cookie(q->value, s, tmp-s+4080);
- }
- if (q->path && (int)strlen(q->path) < tmp-s+4080)
- { sprintf(s, ";$Path=/%s", q->path);
- s += strlen(s);
- }
- if (q->domain && (int)strlen(q->domain) < tmp-s+4080)
- sprintf(s, ";$Domain=%s", q->domain);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie: %s\n", tmp));
- if (soap->fposthdr(soap, "Cookie", tmp))
- return soap->error;
- p = &q->next;
- }
- else
- p = &q->next;
- }
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_getcookies(struct soap *soap, const char *val)
-{ struct soap_cookie *p = NULL, *q;
- const char *s;
- char *t, tmp[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
- char *domain = NULL;
- char *path = NULL;
- unsigned int version = 0;
- time_t now = time(NULL);
- if (!val)
- return;
- s = val;
- while (*s)
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (!soap_tag_cmp(tmp, "$Version"))
- { if ((s = soap_decode_cookie(tmp, sizeof(tmp), s)))
- { if (p)
- p->version = (int)atol(tmp);
- else
- version = (int)atol(tmp);
- }
- }
- else if (!soap_tag_cmp(tmp, "$Path"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((t = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(t, tmp);
- }
- else
- t = NULL;
- if (p)
- { if (p->path)
- SOAP_FREE(p->path);
- p->path = t;
- }
- else
- { if (path)
- SOAP_FREE(path);
- path = t;
- }
- }
- else if (!soap_tag_cmp(tmp, "$Domain"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((t = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(t, tmp);
- }
- else
- t = NULL;
- if (p)
- { if (p->domain)
- SOAP_FREE(p->domain);
- p->domain = t;
- }
- else
- { if (domain)
- SOAP_FREE(domain);
- domain = t;
- }
- }
- else if (p && !soap_tag_cmp(tmp, "Path"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (p->path)
- SOAP_FREE(p->path);
- if (*tmp)
- { if ((p->path = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(p->path, tmp);
- }
- else
- p->path = NULL;
- }
- else if (p && !soap_tag_cmp(tmp, "Domain"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (*tmp)
- { if ((p->domain = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(p->domain, tmp);
- }
- else
- p->domain = NULL;
- }
- else if (p && !soap_tag_cmp(tmp, "Version"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- p->version = (unsigned int)atol(tmp);
- }
- else if (p && !soap_tag_cmp(tmp, "Max-Age"))
- { s = soap_decode_cookie(tmp, sizeof(tmp), s);
- p->expire = now + atol(tmp);
- }
- else if (p && !soap_tag_cmp(tmp, "Expires"))
- { struct tm T;
- char a[3];
- static const char mns[] = "anebarprayunulugepctovec";
- s = soap_decode_cookie(tmp, sizeof(tmp), s);
- memset(&T, 0, sizeof(struct tm));
- a[0] = tmp[4];
- a[1] = tmp[5];
- a[2] = '\0';
- T.tm_mday = (int)atol(a);
- a[0] = tmp[8];
- a[1] = tmp[9];
- T.tm_mon = (strstr(mns, a) - mns) / 2;
- a[0] = tmp[11];
- a[1] = tmp[12];
- T.tm_year = 100 + (int)atol(a);
- a[0] = tmp[13];
- a[1] = tmp[14];
- T.tm_hour = (int)atol(a);
- a[0] = tmp[16];
- a[1] = tmp[17];
- T.tm_min = (int)atol(a);
- a[0] = tmp[19];
- a[1] = tmp[20];
- T.tm_sec = (int)atol(a);
- p->expire = soap_timegm(&T);
- }
- else if (p && !soap_tag_cmp(tmp, "Secure"))
- p->secure = 1;
- else
- { if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"", p->domain?p->domain:"", p->path?p->path:"", p->expire, p->secure));
- if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
- { q->version = p->version;
- q->expire = p->expire;
- q->secure = p->secure;
- q->env = 1;
- }
- if (p->name)
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
- if ((p = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- { p->name = (char*)SOAP_MALLOC(strlen(tmp)+1);
- strcpy(p->name, tmp);
- s = soap_decode_cookie(tmp, sizeof(tmp), s);
- if (*tmp)
- { p->value = (char*)SOAP_MALLOC(strlen(tmp)+1);
- strcpy(p->value, tmp);
- }
- else
- p->value = NULL;
- p->domain = domain;
- p->path = path;
- p->expire = 0;
- p->secure = 0;
- p->version = version;
- }
- }
- if (*s == ';')
- s++;
- }
- if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"", p->domain?p->domain:"", p->path?p->path:"", p->expire, p->secure));
- if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
- { q->version = p->version;
- q->expire = p->expire;
- q->secure = p->secure;
- }
- if (p->name)
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
- if (domain)
- SOAP_FREE(domain);
- if (path)
- SOAP_FREE(path);
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getenv_cookies(struct soap *soap)
-{ struct soap_cookie *p;
- const char *s;
- char key[4096], val[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
- if (!(s = getenv("HTTP_COOKIE")))
- return SOAP_ERR;
- do
- { s = soap_decode_cookie(key, sizeof(key), s);
- s = soap_decode_cookie(val, sizeof(val), s);
- p = soap_set_cookie(soap, key, val, NULL, NULL);
- if (p)
- p->env = 1;
- if (*s == ';')
- s++;
- } while (*s);
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_copy_cookies(struct soap *soap)
-{ struct soap_cookie *p, **q, *r;
- q = &r;
- for (p = soap->cookies; p; p = p->next)
- { if (!(*q = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- return r;
- **q = *p;
- if (p->name)
- { if (((*q)->name = (char*)SOAP_MALLOC(strlen(p->name)+1)))
- strcpy((*q)->name, p->name);
- }
- if (p->value)
- { if (((*q)->value = (char*)SOAP_MALLOC(strlen(p->value)+1)))
- strcpy((*q)->value, p->value);
- }
- if (p->domain)
- { if (((*q)->domain = (char*)SOAP_MALLOC(strlen(p->domain)+1)))
- strcpy((*q)->domain, p->domain);
- }
- if (p->path)
- { if (((*q)->path = (char*)SOAP_MALLOC(strlen(p->path)+1)))
- strcpy((*q)->path, p->path);
- }
- q = &(*q)->next;
- }
- *q = NULL;
- return r;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_free_cookies(struct soap *soap)
-{ struct soap_cookie *p;
- for (p = soap->cookies; p; p = soap->cookies)
- { soap->cookies = p->next;
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
-}
-
-/******************************************************************************/
-#endif /* WITH_COOKIES */
-
-/******************************************************************************/
-#ifdef WITH_GZIP
-#ifndef PALM_2
-static int
-soap_getgzipheader(struct soap *soap)
-{ int i;
- wchar c, f = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get gzip header\n"));
- for (i = 0; i < 9; i++)
- { if ((int)(c = soap_get1(soap) == EOF))
- return soap->error = SOAP_EOF;
- if (i == 2)
- f = c;
- }
- if (f & 0x04) /* FEXTRA */
- { for (i = soap_get1(soap) | (soap_get1(soap) << 8); i; i--)
- if ((int)soap_get1(soap) == EOF)
- return soap->error = SOAP_EOF;
- }
- if (f & 0x08) /* FNAME */
- do
- c = soap_get1(soap);
- while (c && (int)c != EOF);
- if ((int)c != EOF && (f & 0x10)) /* FCOMMENT */
- do
- c = soap_get1(soap);
- while (c && (int)f != EOF);
- if ((int)c != EOF && (f & 0x01)) /* FHCRC */
- { if ((int)(c = soap_get1(soap)) != EOF)
- c = soap_get1(soap);
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_begin_recv(struct soap *soap)
-{ wchar c;
- soap_set_local_namespaces(soap);
- soap->version = 0; /* don't assume we're parsing SOAP content by default */
- soap_free_iht(soap);
- if ((soap->imode & SOAP_IO) == SOAP_IO_CHUNK)
- soap->omode |= SOAP_IO_CHUNK;
- soap->imode &= ~SOAP_IO;
- soap->mode = soap->imode;
- if (!soap->keep_alive)
- { soap->buflen = 0;
- soap->bufidx = 0;
- }
- if (!(soap->mode & SOAP_IO_KEEPALIVE))
- soap->keep_alive = 0;
- soap->ahead = 0;
- soap->peeked = 0;
- soap->level = 0;
- soap->part = SOAP_BEGIN;
- soap->alloced = 0;
- soap->count = 0;
- soap->length = 0;
- soap->cdata = 0;
- *soap->endpoint = '\0';
- soap->userid = NULL;
- soap->passwd = NULL;
- soap->action = NULL;
- soap->dime_chunksize = 0;
- soap->dime_buflen = 0;
-#ifdef WIN32
-#ifndef UNDER_CE
-#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket))
-#ifdef __BORLANDC__
- setmode((SOAP_SOCKET)soap->recvfd, O_BINARY);
-#else
- _setmode((SOAP_SOCKET)soap->recvfd, _O_BINARY);
-#endif
-#endif
-#endif
-#endif
-#ifdef WITH_ZLIB
- soap->mode &= ~SOAP_ENC_ZLIB;
- soap->zlib_in = SOAP_ZLIB_NONE;
- soap->zlib_out = SOAP_ZLIB_NONE;
- soap->d_stream.next_in = Z_NULL;
- soap->d_stream.avail_in = 0;
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- soap->z_ratio_in = 1.0;
-#endif
- c = soap_getchar(soap);
- if ((c & 0xFFFC) == (SOAP_DIME_VERSION | SOAP_DIME_MB) && (soap_get0(soap) & 0xFFF0) == 0x20)
- soap->mode |= SOAP_ENC_DIME;
-#ifdef WITH_GZIP
- else if (c == 0x1F)
- { if (soap_getgzipheader(soap))
- return soap->error;
- if (inflateInit2(&soap->d_stream, -MAX_WBITS) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- soap->mode |= SOAP_ENC_ZLIB;
- soap->zlib_in = SOAP_ZLIB_GZIP;
- soap->z_crc = crc32(0L, NULL, 0);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- /* should not chunk over plain transport, so why bother to check? */
- /* if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) */
- /* soap->z_buflen = soap->bufidx; */
- /* else */
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = soap->buflen - soap->bufidx;
- soap->z_buflen = soap->buflen;
- soap->buflen = soap->bufidx;
- }
-#endif
- else
- { if (c == 0xEF && !(soap->mode & SOAP_C_LATIN))
- { soap_unget(soap, c);
- c = soap_getutf8(soap);
- if (c == 0xFEFF)
- c = soap_getchar(soap);
- }
- while (soap_blank(c))
- c = soap_getchar(soap);
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- soap_unget(soap, c);
- if (c != '<' && !(soap->mode & (SOAP_ENC_DIME | SOAP_ENC_ZLIB)))
- { soap->mode &= ~SOAP_IO;
- if ((soap->error = soap->fparse(soap)))
- { if (soap->error == 307) /* HTTP redirect */
- { soap_getline(soap, soap->endpoint, sizeof(soap->endpoint));
- soap->keep_alive = 0; /* force close when soap_closesock() */
- }
- return soap->error;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { soap->chunkbuflen = soap->buflen;
- soap->buflen = soap->bufidx;
- soap->chunksize = 0;
- }
-#ifdef WITH_ZLIB
- if (soap->zlib_in)
- { /* fparse should not use soap_unget */
-#ifdef WITH_GZIP
- c = soap_get1(soap);
- if (c == 0x1F)
- { if (soap_getgzipheader(soap))
- return soap->error;
- if (inflateInit2(&soap->d_stream, -MAX_WBITS) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- soap->z_crc = crc32(0L, NULL, 0);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
- }
- else
- { soap_revget1(soap);
-#else
- {
-#endif
- if (inflateInit(&soap->d_stream) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate initialized\n"));
- }
- soap->mode |= SOAP_ENC_ZLIB;
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = soap->buflen - soap->bufidx;
- soap->z_buflen = soap->buflen;
- soap->buflen = soap->bufidx;
- }
-#endif
- }
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- { if (soap_getdimehdr(soap))
- return soap->error;
- if (soap->dime_flags & SOAP_DIME_CF)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked DIME SOAP message\n"));
- soap->dime_chunksize = soap->dime_size;
- if (soap->buflen - soap->bufidx >= soap->dime_chunksize)
- { soap->dime_buflen = soap->buflen;
- soap->buflen = soap->bufidx + soap->dime_chunksize;
- }
- else
- soap->dime_chunksize -= soap->buflen - soap->bufidx;
- }
- soap->count = soap->buflen - soap->bufidx;
- }
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_parse(struct soap *soap)
-{ char header[SOAP_HDRLEN], *s;
- unsigned short g = 0, k;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for response...\n"));
- *soap->endpoint = '\0';
- soap->length = 0;
- do
- { if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
- return SOAP_EOF;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP status: %s\n", soap->msgbuf));
- for (;;)
- { if (soap_getline(soap, header, SOAP_HDRLEN))
- return SOAP_EOF;
- if (!*header)
- break;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP header: %s\n", header));
- s = strchr(header, ':');
- if (s)
- { *s = '\0';
- do s++;
- while (*s && *s <= 32);
- if ((soap->error = soap->fparsehdr(soap, header, s)))
- return soap->error;
- }
- }
- if ((s = strchr(soap->msgbuf, ' ')))
- k = (unsigned short)soap_strtoul(s, NULL, 10);
- else
- k = 0;
- } while (k == 100);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Finished HTTP header parsing\n"));
- s = strstr(soap->msgbuf, "HTTP/");
- if (s && s[7] != '1')
- { if (soap->keep_alive == 1)
- soap->keep_alive = 0;
- if (k == 0 && (soap->omode & SOAP_IO) == SOAP_IO_CHUNK) /* k == 0 for HTTP request */
- { soap->imode |= SOAP_IO_CHUNK;
- soap->omode = (soap->omode & ~SOAP_IO) | SOAP_IO_STORE;
- }
- }
- if (soap->keep_alive < 0)
- soap->keep_alive = 1;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Keep alive connection = %d\n", soap->keep_alive));
- if (s && (((g = !strncmp(soap->msgbuf, "GET ", 4))) || !strncmp(soap->msgbuf, "POST ", 5)))
- { size_t m = strlen(soap->endpoint);
- size_t n = m + (s - soap->msgbuf) - 5 - (!g);
- if (n >= sizeof(soap->endpoint))
- n = sizeof(soap->endpoint) - 1;
- strncpy(soap->path, soap->msgbuf + 4 + (!g), n - m);
- soap->path[n - m] = '\0';
- strcat(soap->endpoint, soap->path);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint));
- if (g)
- { soap->error = soap->fget(soap);
- if (soap->error == SOAP_OK)
- soap->error = SOAP_STOP; /* prevents further processing */
- return soap->error;
- }
- return SOAP_OK;
- }
- if (k == 0 || (k >= 200 && k <= 299) || k == 400 || k == 500)
- return SOAP_OK;
- return soap_set_receiver_error(soap, "HTTP error", soap->msgbuf, k);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_parse_header(struct soap *soap, const char *key, const char *val)
-{ if (!soap_tag_cmp(key, "Host"))
- {
-#ifdef WITH_OPENSSL
- if (soap->imode & SOAP_ENC_SSL)
- strcpy(soap->endpoint, "https://");
- else
-#endif
- strcpy(soap->endpoint, "http://");
- strncat(soap->endpoint, val, sizeof(soap->endpoint) - 8);
- soap->endpoint[sizeof(soap->endpoint) - 1] = '\0';
- }
- else if (!soap_tag_cmp(key, "Content-Type"))
- { if (!soap_tag_cmp(val, "*application/dime*"))
- soap->mode |= SOAP_ENC_DIME;
- }
- else if (!soap_tag_cmp(key, "Content-Length"))
- soap->length = soap_strtoul(val, NULL, 10);
- else if (!soap_tag_cmp(key, "Content-Encoding"))
- { if (!soap_tag_cmp(val, "deflate*"))
-#ifdef WITH_ZLIB
- soap->zlib_in = SOAP_ZLIB_DEFLATE;
-#else
- return SOAP_ZLIB_ERROR;
-#endif
- else if (!soap_tag_cmp(val, "gzip*"))
-#ifdef WITH_GZIP
- soap->zlib_in = SOAP_ZLIB_GZIP;
-#else
- return SOAP_ZLIB_ERROR;
-#endif
- }
-#ifdef WITH_ZLIB
- else if (!soap_tag_cmp(key, "Accept-Encoding"))
- {
-#ifdef WITH_GZIP
- if (strchr(val, '*') || !soap_tag_cmp(val, "*gzip*"))
- soap->zlib_out = SOAP_ZLIB_GZIP;
- else
-#endif
- if (strchr(val, '*') || !soap_tag_cmp(val, "*deflate*"))
- soap->zlib_out = SOAP_ZLIB_DEFLATE;
- else
- soap->zlib_out = SOAP_ZLIB_NONE;
- }
-#endif
- else if (!soap_tag_cmp(key, "Transfer-Encoding"))
- { soap->mode &= ~SOAP_IO;
- if (!soap_tag_cmp(val, "chunked*"))
- soap->mode |= SOAP_IO_CHUNK;
- }
- else if (!soap_tag_cmp(key, "Connection"))
- { if (!soap_tag_cmp(val, "keep-alive*"))
- soap->keep_alive = -soap->keep_alive;
- else if (!soap_tag_cmp(val, "close*"))
- soap->keep_alive = 0;
- }
-#ifndef WITH_LEAN
- else if (!soap_tag_cmp(key, "Authorization"))
- { if (!soap_tag_cmp(val, "basic *"))
- { size_t n;
- char *s;
- soap_base642s(soap, val + 6, soap->tmpbuf, sizeof(soap->tmpbuf) - 1, &n);
- soap->tmpbuf[n] = '\0';
- if ((s = strchr(soap->tmpbuf, ':')))
- { *s = '\0';
- soap->userid = soap_strdup(soap, soap->tmpbuf);
- soap->passwd = soap_strdup(soap, s + 1);
- }
- }
- }
-#endif
- else if (!soap_tag_cmp(key, "SOAPAction"))
- { if (val[0] && val[1])
- { soap->action = soap_strdup(soap, val + 1);
- soap->action[strlen(soap->action) - 1] = '\0';
- }
- }
-/* [ Deal with .NET bug (invalid XML id-ref) */
- else if (!soap_tag_cmp(key, "Server"))
- { if (!soap_tag_cmp(val, "Microsoft-IIS*"))
- soap->dot_net_bug = 1;
- }
- else if (!soap_tag_cmp(key, "User-Agent"))
- { if (!soap_tag_cmp(val, "*.NET CLR*") || !soap_tag_cmp(val, "*MS Web Services Client Protocol*"))
- soap->dot_net_bug = 1;
- }
-/* ] */
-#ifdef WITH_COOKIES
- else if (!soap_tag_cmp(key, "Cookie") || !soap_tag_cmp(key, "Set-Cookie"))
- soap_getcookies(soap, val);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_begin_out(struct soap *soap)
-{ soap->part = SOAP_IN_ENVELOPE;
- return soap_element_begin_out(soap, "SOAP-ENV:Envelope", 0, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_end_out(struct soap *soap)
-{ if (soap_element_end_out(soap, "SOAP-ENV:Envelope"))
- return soap->error;
- soap->part = SOAP_END_ENVELOPE;
-#ifndef WITH_LEANER
- if (!(soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME))
- return soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->count&3);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_begin_in(struct soap *soap)
-{ soap->part = SOAP_IN_ENVELOPE;
- if (soap_element_begin_in(soap, "SOAP-ENV:Envelope"))
- return soap->error = SOAP_VERSIONMISMATCH;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_end_in(struct soap *soap)
-{ if (soap_element_end_in(soap, "SOAP-ENV:Envelope"))
- return soap->error;
- soap->part = SOAP_END_ENVELOPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_begin_out(struct soap *soap)
-{ soap->part = SOAP_IN_BODY;
- if (soap->version == 1)
- soap->encoding = 1;
- if (soap_element(soap, "SOAP-ENV:Body", 0, NULL))
- return soap->error;
- if (soap_attribute(soap, "id", "_0"))
- return soap->error;
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_end_out(struct soap *soap)
-{ if (soap_element_end_out(soap, "SOAP-ENV:Body"))
- return soap->error;
- soap->part = SOAP_IN_BODY;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_begin_in(struct soap *soap)
-{ soap->part = SOAP_IN_BODY;
- return soap_element_begin_in(soap, "SOAP-ENV:Body");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_end_in(struct soap *soap)
-{ if (soap_element_end_in(soap, "SOAP-ENV:Body"))
- return soap->error;
- soap->part = SOAP_END_BODY;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_header(struct soap *soap)
-{ if (soap_getheader(soap) && soap->error == SOAP_TAG_MISMATCH)
- soap->error = SOAP_OK;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_endpoint(struct soap *soap, const char *endpoint)
-{ register const char *s;
- register size_t i, n;
- *soap->endpoint = '\0';
- *soap->host = '\0';
- *soap->path = '\0';
- soap->port = 80;
- if (!endpoint || !*endpoint)
- return;
-#ifdef WITH_OPENSSL
- if (!strncmp(endpoint, "https:", 6))
- soap->port = 443;
-#endif
- strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint) - 1);
- s = strchr(endpoint, ':');
- if (s && s[1] == '/' && s[2] == '/')
- s += 3;
- else
- s = endpoint;
- n = strlen(s);
- if (n >= sizeof(soap->host))
- n = sizeof(soap->host) - 1;
-/* WR[ */
-#ifdef WITH_IPV6
- if ('[' == s[0])
- {
- s++;
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (']' == s[i])
- {
- s++;
- break;
- }
- }
- }
- else
- {
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (s[i] == '/' || s[i] == ':')
- break;
- }
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (s[i] == '/' || s[i] == ':')
- break;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- soap->host[i] = '\0';
- if (s[i] == ':')
- { soap->port = (int)atol(s + i + 1);
- for (i++; i < n; i++)
- if (s[i] == '/')
- break;
- }
- if (s[i])
- { strncpy(soap->path, s + i + 1, sizeof(soap->path));
- soap->path[sizeof(soap->path) - 1] = '\0';
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_connect(struct soap *soap, const char *endpoint, const char *action)
-{ return soap_connect_command(soap, SOAP_POST, endpoint, action);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_connect_command(struct soap *soap, int http_command, const char *endpoint, const char *action)
-{ char host[sizeof(soap->host)];
- int port;
- size_t count;
- strcpy(host, soap->host); /* save to compare */
- port = soap->port; /* save to compare */
- soap_set_endpoint(soap, endpoint);
- if (action)
- soap->action = soap_strdup(soap, action);
- if (soap->fconnect)
- {
- if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port)))
- return soap->error;
- }
- else if (*soap->host)
- { soap->status = http_command;
- if (!soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port)
- { soap->keep_alive = 0; /* force close */
- soap_closesock(soap);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port));
- soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
- if (soap->error)
- return soap->error;
- soap->keep_alive = ((soap->omode & SOAP_IO_KEEPALIVE) != 0);
- }
- else if (!soap->keep_alive || soap_poll(soap))
- { soap->keep_alive = 0; /* force close */
- soap_closesock(soap);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port));
- soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
- if (soap->error)
- return soap->error;
- }
- }
- count = soap_begin_dime(soap);
- if (soap_begin_send(soap))
- return soap->error;
- if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML) && endpoint)
- { unsigned int k = soap->mode;
- soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
- if ((k & SOAP_IO) != SOAP_IO_FLUSH)
- soap->mode |= SOAP_IO_BUFFER;
- if ((soap->error = soap->fpost(soap, endpoint, soap->host, soap->port, soap->path, action, count)))
- return soap->error;
- if ((k & SOAP_IO) == SOAP_IO_CHUNK)
- { if (soap_flush(soap))
- return soap->error;
- }
- soap->mode = k;
- }
- if (http_command != SOAP_POST)
- return soap_end_send(soap);
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- return soap_putdimehdr(soap);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2base64(struct soap *soap, const unsigned char *s, char *t, size_t n)
-{ register size_t i;
- register unsigned long m;
- if (!t)
- return SOAP_EOM;
- t[0] = '\0';
- if (!s)
- return SOAP_OK;
- for (; n > 2; n -= 3, s += 3)
- { m = ((unsigned long)((unsigned char*)s)[0] << 16) | ((unsigned long)((unsigned char*)s)[1] << 8) | (unsigned long)((unsigned char*)s)[2];
- for (i = 4; i > 0; m >>= 6)
- t[--i] = soap_base64o[m & 0x3F];
- t += 4;
- }
- t[0] = '\0';
- if (n > 0)
- { m = 0;
- for (i = 0; i < n; i++)
- m = (m << 8) | *s++;
- for (; i < 3; i++)
- m <<= 8;
- for (i++; i > 0; m >>= 6)
- t[--i] = soap_base64o[m & 0x3F];
- for (i = 3; i > n; i--)
- t[i] = '=';
- t[4] = '\0';
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_base642s(struct soap *soap, const char *s, char *t, size_t l, size_t *n)
-{ register int i, j, c;
- register unsigned long m;
- char *p = t;
- if (n)
- *n = 0;
- for (;;)
- { for (i = 0; i < SOAP_BLKLEN; i++)
- { m = 0;
- j = 0;
- while (j < 4)
- { c = *s++;
- if (c == '=' || !c)
- { i *= 3;
- switch (j)
- { case 2:
- *t++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *t++ = (char)((m >> 10) & 0xFF);
- *t++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n += i;
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- }
- *t++ = (char)((m >> 16) & 0xFF);
- *t++ = (char)((m >> 8) & 0xFF);
- *t++ = (char)(m & 0xFF);
- if (l < 3)
- { if (n)
- *n += i;
- return p;
- }
- l -= 3;
- }
- if (n)
- *n += 3 * SOAP_BLKLEN;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_puthttphdr(struct soap *soap, int status, size_t count)
-{ const char *s;
- if (status == SOAP_FILE)
- s = soap->http_content;
- else if (status == SOAP_HTML)
- s = "text/html; charset=utf-8";
- else if (soap->mode & SOAP_ENC_DIME)
- s = "application/dime";
- else if (soap->version == 2)
- s = "application/soap+xml; charset=utf-8";
- else
- s = "text/xml; charset=utf-8";
- soap->error = soap->fposthdr(soap, "Content-Type", s);
- if (soap->error)
- return soap->error;
-#ifdef WITH_ZLIB
- if (soap->omode & SOAP_ENC_ZLIB)
-#ifdef WITH_GZIP
- soap->error = soap->fposthdr(soap, "Content-Encoding", "gzip");
-#else
- soap->error = soap->fposthdr(soap, "Content-Encoding", "deflate");
-#endif
-#endif
- if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)
- soap->error = soap->fposthdr(soap, "Transfer-Encoding", "chunked");
- else if (count > 0)
- { sprintf(soap->tmpbuf, "%lu", (unsigned long)count);
- soap->error = soap->fposthdr(soap, "Content-Length", soap->tmpbuf);
- }
- if (soap->error)
- return soap->error;
- return soap->error = soap->fposthdr(soap, "Connection", soap->keep_alive ? "keep-alive" : "close");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_get(struct soap *soap)
-{ return SOAP_GET_METHOD;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_post(struct soap *soap, const char *endpoint, const char *host, int port, const char *path, const char *action, size_t count)
-{ const char *s;
- if (soap->status == SOAP_GET)
- { s = "GET";
- count = 0;
- }
- else
- s = "POST";
-#ifndef PALM
- if (!endpoint || (strncmp(endpoint, "http:", 5) && strncmp(endpoint, "https:", 6) && strncmp(endpoint, "httpg:", 6)))
-#else
- if (!endpoint || (strncmp(endpoint, "http:", 5) && strncmp(endpoint, "https:", 6) && strncmp(endpoint, "httpg:", 6)) && strncmp(endpoint, "_beam:", 6) && strncmp(endpoint, "_local:", 7) && strncmp(endpoint, "_btobex:", 8))
-#endif
- return SOAP_OK;
- if (soap->proxy_host)
- sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version);
- else
- sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, path, soap->http_version);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return soap->error;
- if (port != 80)
- sprintf(soap->tmpbuf, "%s:%d", host, port);
- else
- strcpy(soap->tmpbuf, host);
- if ((soap->error = soap->fposthdr(soap, "Host", soap->tmpbuf))
- || (soap->error = soap->fposthdr(soap, "User-Agent", "gSOAP/2.6"))
- || (soap->error = soap_puthttphdr(soap, SOAP_OK, count)))
- return soap->error;
-#ifdef WITH_ZLIB
-#ifdef WITH_GZIP
- if ((soap->error = soap->fposthdr(soap, "Accept-Encoding", "gzip, deflate")))
-#else
- if ((soap->error = soap->fposthdr(soap, "Accept-Encoding", "deflate")))
-#endif
- return soap->error;
-#endif
-#ifndef WITH_LEAN
- if (soap->userid && soap->passwd && strlen(soap->userid) + strlen(soap->passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->userid, soap->passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((soap->error = soap->fposthdr(soap, "Authorization", soap->tmpbuf)))
- return soap->error;
- }
- if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((soap->error = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
- return soap->error;
- }
-#endif
-#ifdef WITH_COOKIES
-#ifdef WITH_OPENSSL
- if (soap_putcookies(soap, host, path, soap->ssl != NULL))
- return soap->error;
-#else
- if (soap_putcookies(soap, host, path, 0))
- return soap->error;
-#endif
-#endif
- if (action)
- { sprintf(soap->tmpbuf, "\"%s\"", action);
- if ((soap->error = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf)))
- return soap->error;
- }
- return soap->error = soap->fposthdr(soap, NULL, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_post_header(struct soap *soap, const char *key, const char *val)
-{ if (key)
- { if (soap_send(soap, key))
- return soap->error;
- if (val && (soap_send(soap, ": ") || soap_send(soap, val)))
- return soap->error;
- }
- return soap_send(soap, "\r\n");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_response(struct soap *soap, int status, size_t count)
-{
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- {
- httpOutputEnable(soap->rpmreqid);
- }
-#endif /* WMW_RPM_IO */
-/* ]WR */
- if (!status || status == SOAP_HTML || status == SOAP_FILE)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "OK 200\n"));
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
-#else
-/* ]WR */
- if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */
-/* WR[ */
-#endif /* WMW_RPM_IO */
-/* ]WR */
- { sprintf(soap->tmpbuf, "HTTP/%s 200 OK", soap->http_version);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return soap->error;
- }
- else if ((soap->error = soap->fposthdr(soap, "Status", "200 OK")))
- return soap->error;
- }
- else if (status > 200 && status < 600)
- { sprintf(soap->tmpbuf, "HTTP/%s %d %s", soap->http_version, status, http_error(soap, status));
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return soap->error;
- if (status == 401)
- if ((soap->error = soap->fposthdr(soap, "WWW-Authenticate", "Basic realm=\"gSOAP Service\"")))
- return soap->error;
- }
- else
- { const char *s = *soap_faultcode(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error\n"));
- if (soap->version == 2 && !strcmp(s, "SOAP-ENV:Sender"))
- s = "400 Bad Request";
- else
- s = "500 Internal Server Error";
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
-#else
-/* ]WR */
- if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */
-/* WR[ */
-#endif /* WMW_RPM_IO */
-/* ]WR */
- { sprintf(soap->tmpbuf, "HTTP/%s %s", soap->http_version, s);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return soap->error;
- }
- else if ((soap->error = soap->fposthdr(soap, "Status", s)))
- return soap->error;
- }
- if ((soap->error = soap->fposthdr(soap, "Server", "gSOAP/2.6"))
- || (soap->error = soap_puthttphdr(soap, status, count)))
- return soap->error;
-#ifdef WITH_COOKIES
- if (soap_putsetcookies(soap))
- return soap->error;
-#endif
- return soap->error = soap->fposthdr(soap, NULL, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_response(struct soap *soap, int status)
-{ register size_t count;
- if (!(soap->omode & (SOAP_ENC_XML | SOAP_IO_STORE /* this tests for chunking too */))
- && (status == SOAP_HTML || status == SOAP_FILE))
- { soap->omode &= ~SOAP_IO;
- soap->omode |= SOAP_IO_STORE;
- }
- soap->status = status;
- count = soap_begin_dime(soap);
- if (soap_begin_send(soap))
- return soap->error;
- if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML))
- { register int n = soap->mode;
- soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
- if ((n & SOAP_IO) != SOAP_IO_FLUSH)
- soap->mode |= SOAP_IO_BUFFER;
- if ((soap->error = soap->fresponse(soap, status, count)))
- return soap->error;
- if ((n & SOAP_IO) == SOAP_IO_CHUNK)
- { if (soap_flush(soap))
- return soap->error;
- }
- soap->mode = n;
- }
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- return soap_putdimehdr(soap);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_fault(struct soap *soap)
-{ const char **c = soap_faultcode(soap);
- const char **s = soap_faultstring(soap);
- if (!*c)
- { if (soap->version == 2)
- *c = "SOAP-ENV:Sender";
- else
- *c = "SOAP-ENV:Client";
- }
- if (*s)
- return;
- switch (soap->error)
- { case SOAP_CLI_FAULT:
- *s = "Client fault";
- break;
- case SOAP_SVR_FAULT:
- *s = "Server fault";
- break;
- case SOAP_TAG_MISMATCH:
- sprintf(soap->msgbuf, "Tag mismatch: element '%s' does not correspond to expected element", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_TYPE:
- sprintf(soap->msgbuf, "Data type '%s' mismatch in element '%s'", soap->type, soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_SYNTAX_ERROR:
- *s = "XML syntax error";
- break;
- case SOAP_NO_TAG:
- *s = "No XML element tag found";
- break;
- case SOAP_MUSTUNDERSTAND:
- *c = "SOAP-ENV:MustUnderstand";
- sprintf(soap->msgbuf, "The data in element '%s' must be understood but cannot be handled", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_VERSIONMISMATCH:
- *c = "SOAP-ENV:VersionMismatch";
- *s = "SOAP version mismatch or invalid SOAP message";
- break;
- case SOAP_DATAENCODINGUNKNOWN:
- *c = "SOAP-ENV:DataEncodingUnknown";
- *s = "Unsupported SOAP data encoding";
- break;
- case SOAP_DIME_MISMATCH:
- *s = "DIME version mismatch";
- break;
- case SOAP_NAMESPACE:
- sprintf(soap->msgbuf, "Namespace URI mismatch in element '%s'", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_OBJ_MISMATCH:
- *s = "Object mismatch";
- break;
- case SOAP_FATAL_ERROR:
- *s = "Fatal error";
- break;
- case SOAP_NO_METHOD:
- sprintf(soap->msgbuf, "Method '%s' not implemented", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_GET_METHOD:
- *s = "HTTP GET method not implemented";
- break;
- case SOAP_EOM:
- *s = "Out of memory";
- break;
- case SOAP_IOB:
- *s = "Array index out of bounds";
- break;
- case SOAP_NULL:
- sprintf(soap->msgbuf, "Cannot create nilable object for type '%s' in element '%s'", soap->type, soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_MULTI_ID:
- *s = "Non-unique id attribute";
- break;
- case SOAP_MISSING_ID:
- *s = "Missing id: referenced data is missing or had to be ignored";
- break;
- case SOAP_HREF:
- *s = "Invalid XML: object reference with href attribute is incompatible with actual object referred to";
- break;
- case SOAP_FAULT:
- break;
- case SOAP_TCP_ERROR:
- *s = tcp_error(soap);
- break;
- case SOAP_HTTP_ERROR:
- *s = "HTTP error";
- break;
- case SOAP_SSL_ERROR:
- *s = "SSL error";
- break;
- case SOAP_PLUGIN_ERROR:
- *s = "Plugin registry error";
- break;
- case SOAP_DIME_ERROR:
- *s = "DIME error";
- break;
- case SOAP_ZLIB_ERROR:
-#ifdef WITH_ZLIB
- sprintf(soap->msgbuf, "Zlib/gzip error: '%s'", soap->d_stream.msg?soap->d_stream.msg:"");
- *s = soap->msgbuf;
-#else
- *s = "Zlib not installed for required message (de)compression";
-#endif
- break;
- case SOAP_EOD:
- *s = "End of DIME error";
- break;
- case SOAP_REQUIRED:
- *s = "Validation failure: XML attribute required";
- break;
- case SOAP_OCCURS:
- *s = "Validation failure: XML element occurs count";
- break;
- case SOAP_EOF:
- sprintf(soap->msgbuf, "End of file or no input: '%s'", soap_strerror(soap));
- *s = soap->msgbuf;
- break;
- default:
- if (soap->error > 200 && soap->error < 600)
- { sprintf(soap->msgbuf, "HTTP Error: '%s'", http_error(soap, soap->error));
- *s = soap->msgbuf;
- }
- else
- *s = "Unknown error code";
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send_fault(struct soap *soap)
-{ register int status = soap->error;
- if (status == SOAP_STOP)
- return status;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Sending back fault struct for error code %d\n", soap->error));
- soap->keep_alive = 0; /* to terminate connection */
- soap_set_fault(soap);
- if ((status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) && soap_poll(soap) == SOAP_OK)
- { soap->error = SOAP_OK;
- soap_serializeheader(soap);
- soap_serializefault(soap);
- soap_begin_count(soap);
- if (soap->mode & SOAP_IO_LENGTH)
- { soap_envelope_begin_out(soap);
- soap_putheader(soap);
- soap_body_begin_out(soap);
- soap_putfault(soap);
- soap_body_end_out(soap);
- soap_envelope_end_out(soap);
- }
- if (soap_response(soap, status)
- || soap_envelope_begin_out(soap)
- || soap_putheader(soap)
- || soap_body_begin_out(soap)
- || soap_putfault(soap)
- || soap_body_end_out(soap)
- || soap_envelope_end_out(soap))
- return soap_closesock(soap);
- soap_end_send(soap);
- }
- soap_closesock(soap);
- return soap->error = status;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_fault(struct soap *soap)
-{ register int status = soap->error;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Receiving SOAP Fault\n"));
- soap->error = SOAP_OK;
- if (soap_getfault(soap))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Error: soap_get_soapfault() failed. Is this a SOAP message at all?\n"));
- *soap_faultcode(soap) = (soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client");
- soap->error = status;
- soap_set_fault(soap);
- }
- else
- { register const char *s = *soap_faultcode(soap);
- if (!soap_match_tag(soap, s, "SOAP-ENV:Server") || !soap_match_tag(soap, s, "SOAP-ENV:Receiver"))
- status = SOAP_SVR_FAULT;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:Client") || !soap_match_tag(soap, s, "SOAP-ENV:Sender"))
- status = SOAP_CLI_FAULT;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:MustUnderstand"))
- status = SOAP_MUSTUNDERSTAND;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:VersionMismatch"))
- status = SOAP_VERSIONMISMATCH;
- else
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Fault code %s\n", s));
- status = SOAP_FAULT;
- }
- if (soap_body_end_in(soap)
- || soap_envelope_end_in(soap)
- || soap_end_recv(soap))
- return soap_closesock(soap);
- soap->error = status;
- }
- return soap_closesock(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-soap_strerror(struct soap *soap)
-{ int err = soap->errnum;
- if (!err)
- err = soap_errno;
- if (err)
- {
-#ifndef UNDER_CE
- return strerror(err);
-#else
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)&soap->werrorstr, 256, NULL);
- wcstombs(soap->errorstr, soap->werrorstr, 256);
- return soap->errorstr;
-#endif
- }
- return "Operation interrupted or timed out";
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_set_error(struct soap *soap, const char *faultcode, const char *faultstring, const char *faultdetail, int soaperror)
-{ *soap_faultcode(soap) = faultcode;
- *soap_faultstring(soap) = faultstring;
- if (faultdetail && *faultdetail)
- { register const char **s = soap_faultdetail(soap);
- if (s)
- *s = faultdetail;
- }
- return soap->error = soaperror;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_sender_error(struct soap *soap, const char *faultstring, const char *faultdetail, int soaperror)
-{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultstring, faultdetail, soaperror);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_receiver_error(struct soap *soap, const char *faultstring, const char *faultdetail, int soaperror)
-{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultstring, faultdetail, soaperror);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultstring, const char *faultdetail)
-{ char *s = NULL, *t = NULL;
- if (faultstring)
- s = soap_strdup(soap, faultstring);
- if (faultdetail)
- t = soap_strdup(soap, faultdetail);
- return soap_set_error(soap, faultcode, s, t, SOAP_FAULT);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
-{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultstring, faultdetail);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
-{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultstring, faultdetail);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_print_fault(struct soap *soap, FILE *fd)
-{ if (soap->error)
- { const char **s;
- if (!*soap_faultcode(soap))
- soap_set_fault(soap);
- fprintf(fd, "SOAP FAULT: %s\n\"%s\"\n", *soap_faultcode(soap), *soap_faultstring(soap));
- s = soap_faultdetail(soap);
- if (s && *s)
- fprintf(fd, "Detail: %s\n", *s);
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_print_fault_location(struct soap *soap, FILE *fd)
-{
-#ifndef WITH_LEAN
- int c;
- if (soap->error && soap->buflen > 0)
- { if (soap->bufidx == 0)
- soap->bufidx = 1;
- c = soap->buf[soap->bufidx - 1];
- soap->buf[soap->bufidx - 1] = '\0';
- soap->buf[soap->buflen - 1] = '\0';
- if (soap->bufidx < soap->buflen)
- fprintf(fd, "%s%c\n** HERE **\n%s\n", soap->buf, c, soap->buf + soap->bufidx);
- else
- fprintf(fd, "%s%c\n** HERE **\n", soap->buf, c);
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_register_plugin_arg(struct soap *soap, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void *arg)
-{ register struct soap_plugin *p;
- register int r;
- if (!(p = (struct soap_plugin*)SOAP_MALLOC(sizeof(struct soap_plugin))))
- return soap->error = SOAP_EOM;
- p->id = NULL;
- p->data = NULL;
- p->fcopy = NULL;
- p->fdelete = NULL;
- r = fcreate(soap, p, arg);
- if (!r && p->fdelete)
- { p->next = soap->plugins;
- soap->plugins = p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Registered '%s' plugin\n", p->id));
- return SOAP_OK;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not register plugin '%s': plugin returned error %d (or fdelete callback not set)\n", p->id?p->id:"?", r));
- SOAP_FREE(p);
- return r;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void *
-fplugin(struct soap *soap, const char *id)
-{ register struct soap_plugin *p;
- for (p = soap->plugins; p; p = p->next)
- if (p->id == id || !strcmp(p->id, id))
- return p->data;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void *
-SOAP_FMAC2
-soap_lookup_plugin(struct soap *soap, const char *id)
-{ return soap->fplugin(soap, id);
-}
-#endif
-
-/******************************************************************************/
-#ifdef __cplusplus
-}
-#endif
-
+++ /dev/null
-/*
-
-stdsoap2.c[pp] 2.7.0c
-
-Runtime environment.
-
-gSOAP XML Web services tools
-Copyright (C) 2000-2004, Robert van Engelen, Genivia, Inc., All Rights Reserved.
-
-Contributors:
-
-Wind River Systems, Inc., for the following additions (marked WR[...]):
- - vxWorks compatible
- - Support for IPv6.
-
---------------------------------------------------------------------------------
-gSOAP public license.
-
-The contents of this file are subject to the gSOAP Public License Version 1.3
-(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.cs.fsu.edu/~engelen/soaplicense.html
-Software distributed under the License is distributed on an "AS IS" basis,
-WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-for the specific language governing rights and limitations under the License.
-
-The Initial Developer of the Original Code is Robert A. van Engelen.
-Copyright (C) 2000-2004, Robert van Engelen, Genivia, Inc., All Rights Reserved.
---------------------------------------------------------------------------------
-GPL license.
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307 USA
-
-Author contact information:
-engelen@genivia.com / engelen@acm.org
---------------------------------------------------------------------------------
-
-Installation note:
-
-Win32 build needs winsock.dll (Visual C++ "wsock32.lib")
-To do this in Visual C++ 6.0, go to "Project", "settings", select the "Link"
-tab (the project file needs to be selected in the file view) and add
-"wsock32.lib" to the "Object/library modules" entry
-
-On Mac OS X with gcc (GCC) 3.1 20020420 (prerelease) you MUST compile with
--fstack_check when using -O2 because gcc 3.1 has a bug that smashes the stack
-when locally allocated data exceeds 64K.
-
-*/
-
-#include "stdsoap2.h"
-
-#ifdef __cplusplus
-SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.7.0c 2004-09-27 12:00:00 GMT")
-extern "C" {
-#else
-SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.7.0c 2004-09-27 12:00:00 GMT")
-#endif
-
-/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale) */
-#ifndef SOAP_UNKNOWN_CHAR
-#define SOAP_UNKNOWN_CHAR (127)
-#endif
-
-/* EOF=-1 */
-#define SOAP_LT (soap_wchar)(-2) /* XML character '<' */
-#define SOAP_TT (soap_wchar)(-3) /* XML character '</' */
-#define SOAP_GT (soap_wchar)(-4) /* XML character '>' */
-#define SOAP_QT (soap_wchar)(-5) /* XML character '"' */
-#define SOAP_AP (soap_wchar)(-6) /* XML character ''' */
-
-#define soap_blank(c) ((c) >= 0 && (c) <= 32)
-#define soap_notblank(c) ((c) > 32)
-#define soap_hash_ptr(p) (((unsigned long)(p) >> 3) & (SOAP_PTRHASH - 1))
-
-static int soap_isxdigit(int);
-static soap_wchar soap_char(struct soap*);
-static soap_wchar soap_getchunkchar(struct soap*);
-static void soap_update_ptrs(struct soap*, char*, char*, long);
-static int soap_has_copies(struct soap*, const char*, const char*);
-static struct soap_ilist *soap_hlookup(struct soap*, const char*);
-static void soap_init_iht(struct soap*);
-static void soap_free_iht(struct soap*);
-static void soap_init_pht(struct soap*);
-static void soap_free_pht(struct soap*);
-static int soap_set_error(struct soap*, const char*, const char*, const char*, int);
-static const char *soap_set_validation_fault(struct soap*, const char*, const char*);
-static int soap_copy_fault(struct soap*, const char*, const char*, const char*);
-static int soap_getattrval(struct soap*, char*, size_t, soap_wchar);
-static void soap_set_local_namespaces(struct soap*);
-static int soap_isnumeric(struct soap*, const char*);
-static void *fplugin(struct soap*, const char*);
-static const char *soap_decode(char*, size_t, const char*, const char*);
-
-#ifndef WITH_LEAN
-static time_t soap_timegm(struct tm*);
-#endif
-
-#ifdef SOAP_DEBUG
-static void soap_init_logs(struct soap*);
-static void soap_close_logfile(struct soap*, int);
-static void soap_set_logfile(struct soap*, int, const char*);
-#endif
-
-#ifdef WITH_FAST
-static int soap_append_lab(struct soap*, const char*, size_t);
-#endif
-
-#ifndef WITH_LEANER
-static struct soap_multipart *soap_new_multipart(struct soap*, struct soap_multipart**, struct soap_multipart**, char*, size_t);
-static int soap_putdimefield(struct soap*, const char*, size_t);
-static char *soap_getdimefield(struct soap*, size_t);
-static void soap_select_mime_boundary(struct soap*);
-static int soap_valid_mime_boundary(struct soap*);
-#endif
-
-#ifdef WITH_GZIP
-static int soap_getgziphdr(struct soap*);
-#endif
-
-#ifdef WITH_OPENSSL
-static int ssl_auth_init(struct soap*);
-static int ssl_verify_callback(int, X509_STORE_CTX*);
-static int ssl_password(char*, int, int, void *);
-/* This callback is included for future references. It should not be deleted
-static DH *ssl_tmp_dh(SSL*, int, int);
-*/
-#endif
-
-static const char *soap_strerror(struct soap*);
-static const char *tcp_error(struct soap*);
-static const char *http_error(struct soap*, int);
-static int http_post(struct soap*, const char*, const char*, int, const char*, const char*, size_t);
-static int http_get(struct soap*);
-static int http_send_header(struct soap*, const char*);
-static int http_post_header(struct soap*, const char*, const char*);
-static int http_response(struct soap*, int, size_t);
-static int http_parse(struct soap*);
-static int http_parse_header(struct soap*, const char*, const char*);
-#ifndef MAC_CARBON
-static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr);
-static int tcp_connect(struct soap*, const char *endpoint, const char *host, int port);
-static int tcp_accept(struct soap*, int, struct sockaddr*, int*);
-static int tcp_disconnect(struct soap*);
-static int tcp_closesocket(struct soap*, SOAP_SOCKET);
-static int tcp_shutdownsocket(struct soap*, SOAP_SOCKET, int);
-static int fsend(struct soap*, const char*, size_t);
-static size_t frecv(struct soap*, char*, size_t);
-#endif
-
-/* WR[ */
-#ifdef VXWORKS
-static int vx_nonblocking = TRUE; /* ioctl argument */
-#endif
-/* ]WR */
-
-#ifndef PALM_2
-static const char soap_env1[42] = "http://schemas.xmlsoap.org/soap/envelope/";
-static const char soap_enc1[42] = "http://schemas.xmlsoap.org/soap/encoding/";
-static const char soap_env2[40] = "http://www.w3.org/2003/05/soap-envelope";
-static const char soap_enc2[40] = "http://www.w3.org/2003/05/soap-encoding";
-static const char soap_rpc[35] = "http://www.w3.org/2003/05/soap-rpc";
-#endif
-
-#ifndef PALM_1
-const struct soap_double_nan soap_double_nan = {0xFFFFFFFF, 0xFFFFFFFF};
-static const char soap_base64o[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char soap_base64i[81] = "\76XXX\77\64\65\66\67\70\71\72\73\74\75XXXXXXX\00\01\02\03\04\05\06\07\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31XXXXXX\32\33\34\35\36\37\40\41\42\43\44\45\46\47\50\51\52\53\54\55\56\57\60\61\62\63";
-#endif
-
-static const char soap_padding[3] = "\0\0";
-#define SOAP_STR_PADDING (soap_padding)
-#define SOAP_STR_EOS (soap_padding)
-
-#ifndef WITH_LEAN
-static const struct soap_code_map html_entity_codes[] = /* entities for XHTML parsing */
-{ { 160, "nbsp" },
- { 161, "iexcl" },
- { 162, "cent" },
- { 163, "pound" },
- { 164, "curren" },
- { 165, "yen" },
- { 166, "brvbar" },
- { 167, "sect" },
- { 168, "uml" },
- { 169, "copy" },
- { 170, "ordf" },
- { 171, "laquo" },
- { 172, "not" },
- { 173, "shy" },
- { 174, "reg" },
- { 175, "macr" },
- { 176, "deg" },
- { 177, "plusmn" },
- { 178, "sup2" },
- { 179, "sup3" },
- { 180, "acute" },
- { 181, "micro" },
- { 182, "para" },
- { 183, "middot" },
- { 184, "cedil" },
- { 185, "sup1" },
- { 186, "ordm" },
- { 187, "raquo" },
- { 188, "frac14" },
- { 189, "frac12" },
- { 190, "frac34" },
- { 191, "iquest" },
- { 192, "Agrave" },
- { 193, "Aacute" },
- { 194, "Acirc" },
- { 195, "Atilde" },
- { 196, "Auml" },
- { 197, "Aring" },
- { 198, "AElig" },
- { 199, "Ccedil" },
- { 200, "Egrave" },
- { 201, "Eacute" },
- { 202, "Ecirc" },
- { 203, "Euml" },
- { 204, "Igrave" },
- { 205, "Iacute" },
- { 206, "Icirc" },
- { 207, "Iuml" },
- { 208, "ETH" },
- { 209, "Ntilde" },
- { 210, "Ograve" },
- { 211, "Oacute" },
- { 212, "Ocirc" },
- { 213, "Otilde" },
- { 214, "Ouml" },
- { 215, "times" },
- { 216, "Oslash" },
- { 217, "Ugrave" },
- { 218, "Uacute" },
- { 219, "Ucirc" },
- { 220, "Uuml" },
- { 221, "Yacute" },
- { 222, "THORN" },
- { 223, "szlig" },
- { 224, "agrave" },
- { 225, "aacute" },
- { 226, "acirc" },
- { 227, "atilde" },
- { 228, "auml" },
- { 229, "aring" },
- { 230, "aelig" },
- { 231, "ccedil" },
- { 232, "egrave" },
- { 233, "eacute" },
- { 234, "ecirc" },
- { 235, "euml" },
- { 236, "igrave" },
- { 237, "iacute" },
- { 238, "icirc" },
- { 239, "iuml" },
- { 240, "eth" },
- { 241, "ntilde" },
- { 242, "ograve" },
- { 243, "oacute" },
- { 244, "ocirc" },
- { 245, "otilde" },
- { 246, "ouml" },
- { 247, "divide" },
- { 248, "oslash" },
- { 249, "ugrave" },
- { 250, "uacute" },
- { 251, "ucirc" },
- { 252, "uuml" },
- { 253, "yacute" },
- { 254, "thorn" },
- { 255, "yuml" },
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEAN
-static const struct soap_code_map h_error_codes[] =
-{
-#ifdef HOST_NOT_FOUND
- { HOST_NOT_FOUND, "Host not found" },
-#endif
-#ifdef TRY_AGAIN
- { TRY_AGAIN, "Try Again" },
-#endif
-#ifdef NO_RECOVERY
- { NO_RECOVERY, "No Recovery" },
-#endif
-#ifdef NO_DATA
- { NO_DATA, "No Data" },
-#endif
-#ifdef NO_ADDRESS
- { NO_ADDRESS, "No Address" },
-#endif
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEAN
-static const struct soap_code_map h_http_error_codes[] =
-{ { 201, "Created" },
- { 202, "Accepted" },
- { 203, "Non-Authoritative Information" },
- { 204, "No Content" },
- { 205, "Reset Content" },
- { 206, "Partial Content" },
- { 300, "Multiple Choices" },
- { 301, "Moved Permanently" },
- { 302, "Found" },
- { 303, "See Other" },
- { 304, "Not Modified" },
- { 305, "Use Proxy" },
- { 307, "Temporary Redirect" },
- { 400, "Bad Request" },
- { 401, "Unauthorized" },
- { 402, "Payment Required" },
- { 403, "Forbidden" },
- { 404, "Not Found" },
- { 405, "Method Not Allowed" },
- { 406, "Not Acceptable" },
- { 407, "Proxy Authentication Required" },
- { 408, "Request Time-out" },
- { 409, "Conflict" },
- { 410, "Gone" },
- { 411, "Length Required" },
- { 412, "Precondition Failed" },
- { 413, "Request Entity Too Large" },
- { 414, "Request-URI Too Large" },
- { 415, "Unsupported Media Type" },
- { 416, "Requested range not satisfiable" },
- { 417, "Expectation Failed" },
- { 500, "Internal Server Error" },
- { 501, "Not Implemented" },
- { 502, "Bad Gateway" },
- { 503, "Service Unavailable" },
- { 504, "Gateway Time-out" },
- { 505, "HTTP Version not supported" },
- { 0, NULL }
-};
-#endif
-
-#ifdef WITH_OPENSSL
-static const struct soap_code_map h_ssl_error_codes[] =
-{
-#define _SSL_ERROR(e) { e, #e }
- _SSL_ERROR(SSL_ERROR_SSL),
- _SSL_ERROR(SSL_ERROR_ZERO_RETURN),
- _SSL_ERROR(SSL_ERROR_WANT_READ),
- _SSL_ERROR(SSL_ERROR_WANT_WRITE),
- _SSL_ERROR(SSL_ERROR_WANT_CONNECT),
- _SSL_ERROR(SSL_ERROR_WANT_X509_LOOKUP),
- _SSL_ERROR(SSL_ERROR_SYSCALL),
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEANER
-static const struct soap_code_map mime_codes[] =
-{ { SOAP_MIME_7BIT, "7bit" },
- { SOAP_MIME_8BIT, "8bit" },
- { SOAP_MIME_BINARY, "binary" },
- { SOAP_MIME_QUOTED_PRINTABLE, "quoted-printable" },
- { SOAP_MIME_BASE64, "base64" },
- { SOAP_MIME_IETF_TOKEN, "ietf-token" },
- { SOAP_MIME_X_TOKEN, "x-token" },
- { 0, NULL }
-};
-#endif
-
-#ifdef WIN32
-static int tcp_done = 0;
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-fsend(struct soap *soap, const char *s, size_t n)
-{ register int nwritten;
-#if defined(__cplusplus) && !defined(UNDER_CE)
- if (soap->os)
- { soap->os->write(s, n);
- if (soap->os->good())
- return SOAP_OK;
- return SOAP_EOF;
- }
-#endif
- while (n)
- { if (soap_valid_socket(soap->socket))
- {
-#ifndef WITH_LEAN
- if (soap->send_timeout)
- { struct timeval timeout;
- fd_set fd;
- if (soap->send_timeout > 0)
- { timeout.tv_sec = soap->send_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->send_timeout/1000000;
- timeout.tv_usec = -soap->send_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- for (;;)
- { register int r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- return SOAP_EOF;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- }
- }
-#endif
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- nwritten = SSL_write(soap->ssl, s, n);
- else
-#endif
-#ifndef PALM
- nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags);
-#else
- nwritten = send((SOAP_SOCKET)soap->socket, (void*)s, n, soap->socket_flags);
-#endif
- if (nwritten <= 0)
- {
-#ifdef WITH_OPENSSL
- int err;
- if (soap->ssl && (err = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- return SOAP_EOF;
-#endif
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EWOULDBLOCK && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- nwritten = 0; /* and call write() again */
- }
- }
- else
- {
-#ifdef WITH_FASTCGI
- nwritten = fwrite((void*)s, 1, n, stdout);
- fflush(stdout);
-#else
-#ifdef UNDER_CE
- nwritten = fwrite(s, 1, n, soap->sendfd);
-#else
-/* WR[ */
-#ifdef VXWORKS
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- {
- httpBlockPut(soap->rpmreqid, s, n);
- nwritten = n;
- }
- else
- {
- nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
- }
-#else
- nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
-#endif /* WMW_RPM_IO */
-#else
-/* ]WR */
- nwritten = write((SOAP_SOCKET)soap->sendfd, s, n);
-/* WR[ */
-#endif
-/* ]WR */
-#endif
-#endif
- if (nwritten <= 0)
- { if (soap_errno != SOAP_EINTR && soap_errno != SOAP_EWOULDBLOCK && soap_errno != SOAP_EAGAIN)
- { soap->errnum = soap_errno;
- return SOAP_EOF;
- }
- nwritten = 0; /* and call write() again */
- }
- }
- n -= nwritten;
- s += nwritten;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_flush_raw(struct soap *soap, const char *s, size_t n)
-{ if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- { register char *t;
- if (!(t = (char*)soap_push_block(soap, n)))
- return soap->error = SOAP_EOM;
- memcpy(t, s, n);
- if (soap->fpreparesend)
- return soap->fpreparesend(soap, s, n);
- return SOAP_OK;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { char t[16];
- sprintf(t, "\r\n%lX\r\n" + (soap->chunksize ? 0 : 2), (unsigned long)n);
- DBGMSG(SENT, t, strlen(t));
- if ((soap->error = soap->fsend(soap, t, strlen(t))))
- return soap->error;
- soap->chunksize += n;
- }
- DBGMSG(SENT, s, n);
- return soap->error = soap->fsend(soap, s, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_flush(struct soap *soap)
-{ if (soap->bufidx)
- {
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { soap->d_stream.next_in = (Byte*)soap->buf;
- soap->d_stream.avail_in = (unsigned int)soap->bufidx;
-#ifdef WITH_GZIP
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->bufidx);
-#endif
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating %u bytes\n", soap->d_stream.avail_in));
- if (deflate(&soap->d_stream, Z_NO_FLUSH) != Z_OK)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to deflate: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- if (!soap->d_stream.avail_out)
- { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN))
- return soap->error;
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- }
- } while (soap->d_stream.avail_in);
- }
- else
-#endif
- if (soap_flush_raw(soap, soap->buf, soap->bufidx))
- return soap->error;
- soap->bufidx = 0;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send_raw(struct soap *soap, const char *s, size_t n)
-{ if (!n)
- return SOAP_OK;
- if (soap->mode & SOAP_IO_LENGTH)
- { soap->count += n;
- if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE)
- return soap->fpreparesend(soap, s, n);
- return SOAP_OK;
- }
- if (soap->mode & SOAP_IO)
- { register size_t i = SOAP_BUFLEN - soap->bufidx;
- while (n >= i)
- { memcpy(soap->buf + soap->bufidx, s, i);
- soap->bufidx = SOAP_BUFLEN;
- if (soap_flush(soap))
- return soap->error;
- s += i;
- n -= i;
- i = SOAP_BUFLEN;
- }
- memcpy(soap->buf + soap->bufidx, s, n);
- soap->bufidx += n;
- return SOAP_OK;
- }
- return soap_flush_raw(soap, s, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send(struct soap *soap, const char *s)
-{ if (s)
- return soap_send_raw(soap, s, strlen(s));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send2(struct soap *soap, const char *s1, const char *s2)
-{ if (soap_send(soap, s1))
- return soap->error;
- return soap_send(soap, s2);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send3(struct soap *soap, const char *s1, const char *s2, const char *s3)
-{ if (soap_send(soap, s1)
- || soap_send(soap, s2))
- return soap->error;
- return soap_send(soap, s3);
-}
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static size_t
-frecv(struct soap *soap, char *s, size_t n)
-{ register int r;
- soap->errnum = 0;
-#if defined(__cplusplus) && !defined(UNDER_CE)
- if (soap->is)
- { if (soap->is->good())
- return soap->is->read(s, n).gcount();
- return 0;
- }
-#endif
- if (soap_valid_socket(soap->socket))
- { for (;;)
- {
-#ifndef WITH_LEAN
- struct timeval timeout;
- fd_set fd;
- if (soap->recv_timeout)
- { if (soap->recv_timeout > 0)
- { timeout.tv_sec = soap->recv_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->recv_timeout/1000000;
- timeout.tv_usec = -soap->recv_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- for (;;)
- { r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r > 0)
- break;
- if (r == 0)
- return 0;
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
- }
-#endif
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { int err;
- r = SSL_read(soap->ssl, s, n);
- if ((err = SSL_get_error(soap->ssl, r)) == SSL_ERROR_NONE)
- return (size_t)r;
- if (err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- return 0;
- }
- else
-#endif
- { r = recv((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags);
- if (r >= 0)
- return (size_t)r;
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
-#ifndef WITH_LEAN
- { struct timeval timeout;
- fd_set fd;
- timeout.tv_sec = 0;
- timeout.tv_usec = 10000;
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r < 0 && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
-#endif
- }
- }
-#ifdef WITH_FASTCGI
- return fread(s, 1, n, stdin);
-#else
-#ifdef UNDER_CE
- return fread(s, 1, n, soap->recvfd);
-#else
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- r = httpBlockRead(soap->rpmreqid, s, n);
- else
- r = read(soap->recvfd, s, n);
- if (r >= 0)
- return r;
- return 0;
-#else
-/* ]WR */
- r = read((SOAP_SOCKET)soap->recvfd, s, n);
- if (r >= 0)
- return (size_t)r;
- soap->errnum = soap_errno;
- return 0;
-/* WR[ */
-#endif
-/* ]WR */
-#endif
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static soap_wchar
-soap_getchunkchar(struct soap *soap)
-{ if (soap->bufidx < soap->buflen)
- return soap->buf[soap->bufidx++];
- soap->bufidx = 0;
- soap->buflen = soap->chunkbuflen = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)soap->buflen));
- DBGMSG(RECV, soap->buf, soap->buflen);
- if (soap->buflen)
- return soap->buf[soap->bufidx++];
- return EOF;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_isxdigit(int c)
-{ switch (c)
- { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- return 1;
- }
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_raw(struct soap *soap)
-{ register size_t ret;
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { if (soap->d_stream.next_out == Z_NULL)
- return EOF;
- if (soap->d_stream.avail_in || !soap->d_stream.avail_out)
- { register int r;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflating\n"));
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- r = inflate(&soap->d_stream, Z_NO_FLUSH);
- if (r == Z_OK || r == Z_STREAM_END)
- { soap->bufidx = 0;
- soap->buflen = SOAP_BUFLEN - soap->d_stream.avail_out;
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen);
- if (r == Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out;
- soap->d_stream.next_out = Z_NULL;
- }
- if (soap->buflen)
- { soap->count += soap->buflen;
- return SOAP_OK;
- }
- }
- else if (r != Z_BUF_ERROR)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate error: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- soap->d_stream.next_out = Z_NULL;
- return EOF;
- }
- }
-zlib_again:
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK && !soap->chunksize)
- { memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
- soap->buflen = soap->z_buflen;
- }
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) /* read HTTP chunked transfer */
- {
-chunk_again:
- if (soap->chunksize)
- { soap->buflen = ret = soap->frecv(soap, soap->buf, soap->chunksize > SOAP_BUFLEN ? SOAP_BUFLEN : soap->chunksize);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk: read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- soap->bufidx = 0;
- soap->chunksize -= ret;
- }
- else
- { register soap_wchar c;
- char *t, tmp[8];
- t = tmp;
- if (!soap->chunkbuflen)
- { soap->chunkbuflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- soap->bufidx = 0;
- if (!ret)
- return EOF;
- }
- else
- soap->bufidx = soap->buflen;
- soap->buflen = soap->chunkbuflen;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (%u %u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen));
- while (!soap_isxdigit((int)(c = soap_getchunkchar(soap))))
- if ((int)c == EOF)
- return EOF;
- do
- *t++ = (char)c;
- while (soap_isxdigit((int)(c = soap_getchunkchar(soap))) && t - tmp < 7);
- while ((int)c != EOF && c != '\n')
- c = soap_getchunkchar(soap);
- if ((int)c == EOF)
- return EOF;
- *t = '\0';
- soap->chunksize = soap_strtoul(tmp, &t, 16);
- if (!soap->chunksize)
- { soap->chunkbuflen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of chunked message\n"));
- while ((int)c != EOF && c != '\n')
- c = soap_getchunkchar(soap);
- return EOF;
- }
- soap->buflen = soap->bufidx + soap->chunksize;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to %u (%u %s)\n", (unsigned int)soap->buflen, (unsigned int)soap->bufidx, tmp));
- if (soap->buflen > soap->chunkbuflen)
- { soap->buflen = soap->chunkbuflen;
- soap->chunksize -= soap->buflen - soap->bufidx;
- soap->chunkbuflen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Passed end of buffer for chunked HTTP (%lu bytes left)\n", (unsigned long)(soap->buflen - soap->bufidx)));
- }
- else if (soap->chunkbuflen)
- soap->chunksize = 0;
- ret = soap->buflen - soap->bufidx;
- if (!ret)
- goto chunk_again;
- }
- }
- else
- { soap->bufidx = 0;
- soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- }
- if (soap->fpreparerecv && (soap->error = soap->fpreparerecv(soap, soap->buf, ret)))
- return soap->error;
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { register int r;
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = (unsigned int)ret;
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- r = inflate(&soap->d_stream, Z_NO_FLUSH);
- if (r == Z_OK || r == Z_STREAM_END)
- { soap->bufidx = 0;
- soap->z_buflen = soap->buflen;
- soap->buflen = ret = SOAP_BUFLEN - soap->d_stream.avail_out;
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %u bytes\n", (unsigned int)ret));
- if (!ret)
- goto zlib_again;
- if (r == Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out;
- soap->d_stream.next_out = Z_NULL;
- }
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to inflate: (%d) %s\n", r, soap->d_stream.msg?soap->d_stream.msg:""));
- soap->d_stream.next_out = Z_NULL;
- return EOF;
- }
- }
-#endif
- soap->count += ret;
- return !ret;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv(struct soap *soap)
-{
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- { if (soap->dime.buflen)
- { char *s;
- int i;
- unsigned char tmp[12];
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME hdr for chunked DIME is in buffer\n"));
- soap->count += soap->dime.buflen - soap->buflen;
- soap->buflen = soap->dime.buflen;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Skip padding (%ld bytes)\n", -(long)soap->dime.size&3));
- for (i = -(long)soap->dime.size&3; i > 0; i--)
- { soap->bufidx++;
- if (soap->bufidx >= soap->buflen)
- if (soap_recv_raw(soap))
- return EOF;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME hdr for next chunk\n"));
- s = (char*)tmp;
- for (i = 12; i > 0; i--)
- { *s++ = soap->buf[soap->bufidx++];
- if (soap->bufidx >= soap->buflen)
- if (soap_recv_raw(soap))
- return EOF;
- }
- soap->dime.flags = tmp[0] & 0x7;
- soap->dime.size = ((size_t)tmp[8] << 24) | ((size_t)tmp[9] << 16) | ((size_t)tmp[10] << 8) | ((size_t)tmp[11]);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME chunk (%u bytes)\n", (unsigned int)soap->dime.size));
- if (soap->dime.flags & SOAP_DIME_CF)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "More chunking\n"));
- soap->dime.chunksize = soap->dime.size;
- if (soap->buflen - soap->bufidx >= soap->dime.size)
- { soap->dime.buflen = soap->buflen;
- soap->buflen = soap->bufidx + soap->dime.chunksize;
- }
- else
- soap->dime.chunksize -= soap->buflen - soap->bufidx;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Last chunk\n"));
- soap->dime.buflen = 0;
- soap->dime.chunksize = 0;
- }
- soap->count = soap->buflen - soap->bufidx;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%u bytes remaining\n", (unsigned int)soap->count));
- return SOAP_OK;
- }
- if (soap->dime.chunksize)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get next DIME hdr for chunked DIME (%u bytes chunk)\n", (unsigned int)soap->dime.chunksize));
- if (soap_recv_raw(soap))
- return EOF;
- if (soap->buflen - soap->bufidx >= soap->dime.chunksize)
- { soap->dime.buflen = soap->buflen;
- soap->count -= soap->buflen - soap->bufidx - soap->dime.chunksize;
- soap->buflen = soap->bufidx + soap->dime.chunksize;
- }
- else
- soap->dime.chunksize -= soap->buflen - soap->bufidx;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%lu bytes remaining, count=%u\n", (unsigned long)(soap->buflen-soap->bufidx), (unsigned int)soap->count));
- return SOAP_OK;
- }
- }
-#endif
- return soap_recv_raw(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_getchar(struct soap *soap)
-{ register soap_wchar c;
- if (soap->ahead)
- { c = soap->ahead;
- soap->ahead = 0;
- return c;
- }
- return soap_get1(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const struct soap_code_map*
-SOAP_FMAC2
-soap_code(const struct soap_code_map *map, const char *str)
-{ while (map->string)
- { if (!strcmp(str, map->string)) /* case sensitive */
- return map;
- map++;
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_int_code(const struct soap_code_map *map, const char *str, long other)
-{ while (map->string)
- { if (!soap_tag_cmp(str, map->string)) /* case insensitive */
- return map->code;
- map++;
- }
- return other;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_str_code(const struct soap_code_map *map, long code)
-{ while (map->code != code && map->string)
- map++;
- return map->string;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static soap_wchar
-soap_char(struct soap *soap)
-{ char tmp[8];
- register int i;
- register soap_wchar c;
- register char *s = tmp;
- for (i = 0; i < 7; i++)
- { c = soap_get1(soap);
- if (c == ';' || (int)c == EOF)
- break;
- *s++ = (char)c;
- }
- *s = '\0';
- if (*tmp == '#')
- { if (tmp[1] == 'x' || tmp[1] == 'X')
- return soap_strtol(tmp + 2, NULL, 16);
- return atol(tmp + 1);
- }
- if (!strcmp(tmp, "lt"))
- return '<';
- if (!strcmp(tmp, "gt"))
- return '>';
- if (!strcmp(tmp, "amp"))
- return '&';
- if (!strcmp(tmp, "quot"))
- return '"';
- if (!strcmp(tmp, "apos"))
- return '\'';
-#ifndef WITH_LEAN
- return (soap_wchar)soap_int_code(html_entity_codes, tmp, SOAP_UNKNOWN_CHAR);
-#else
- return SOAP_UNKNOWN_CHAR; /* use this to represent unknown code */
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_get(struct soap *soap)
-{ register soap_wchar c;
- c = soap->ahead;
- if (c)
- soap->ahead = 0;
- else
- c = soap_get1(soap);
- for (;;)
- { if (soap->cdata)
- { if (c == ']')
- { c = soap_get1(soap);
- if (c == ']')
- { soap->cdata = 0;
- soap_get1(soap); /* skip > */
- c = soap_get1(soap);
- }
- else
- { soap_revget1(soap);
- return ']';
- }
- }
- else
- return c;
- }
- switch (c)
- { case '<':
- do c = soap_get1(soap);
- while (soap_blank(c));
- if (c == '!' || c == '?' || c == '%')
- { if (c == '!')
- { c = soap_get1(soap);
- if (c == '[')
- { do c = soap_get1(soap);
- while ((int)c != EOF && c != '[');
- if ((int)c == EOF)
- break;
- soap->cdata = 1;
- c = soap_get1(soap);
- continue;
- }
- if (c == '-' && (c = soap_get1(soap)) == '-')
- { do
- { c = soap_get1(soap);
- if (c == '-' && (c = soap_get1(soap)) == '-')
- break;
- } while ((int)c != EOF);
- }
- }
- while ((int)c != EOF && c != '>')
- c = soap_get1(soap);
- if ((int)c == EOF)
- break;
- c = soap_get1(soap);
- continue;
- }
- if (c == '/')
- return SOAP_TT;
- soap_revget1(soap);
- return SOAP_LT;
- case '>':
- return SOAP_GT;
- case '"':
- return SOAP_QT;
- case '\'':
- return SOAP_AP;
- case '&':
- return soap_char(soap) | 0x80000000;
- }
- break;
- }
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_advance(struct soap *soap)
-{ register soap_wchar c;
- while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT)
- ;
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_skip(struct soap *soap)
-{ register soap_wchar c;
- do c = soap_get(soap);
- while (soap_blank(c));
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_move(struct soap *soap, long n)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving %ld bytes forward\n", (long)n));
- for (; n > 0; n--)
- if ((int)soap_getchar(soap) == EOF)
- return SOAP_EOF;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_tell(struct soap *soap)
-{ return soap->count - soap->buflen + soap->bufidx - (soap->ahead != 0);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pututf8(struct soap *soap, register unsigned long c)
-{ char tmp[16];
- if (c > 0 && c < 0x80)
- { *tmp = (char)c;
- return soap_send_raw(soap, tmp, 1);
- }
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { register char *t = tmp;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- *t = '\0';
- }
- else
-#endif
- sprintf(tmp, "&#%lu;", c);
- return soap_send(soap, tmp);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_getutf8(struct soap *soap)
-{ register soap_wchar c, c1, c2, c3, c4;
- c = soap_get(soap);
- if (c < 0x80 || (soap->mode & SOAP_ENC_LATIN))
- return c;
- c1 = soap_get(soap);
- if (c1 < 0x80)
- { soap_unget(soap, c1);
- return c;
- }
- c1 &= 0x3F;
- if (c < 0xE0)
- return ((soap_wchar)(c & 0x1F) << 6) | c1;
- c2 = (soap_wchar)soap_get1(soap) & 0x3F;
- if (c < 0xF0)
- return ((soap_wchar)(c & 0x0F) << 12) | (c1 << 6) | c2;
- c3 = (soap_wchar)soap_get1(soap) & 0x3F;
- if (c < 0xF8)
- return ((soap_wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;
- c4 = (soap_wchar)soap_get1(soap) & 0x3F;
- if (c < 0xFC)
- return ((soap_wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4;
- return ((soap_wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (soap_wchar)(soap_get1(soap) & 0x3F);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_puthex(struct soap *soap, const unsigned char *s, int n)
-{ /* TODO: serialize to DOM (as an option) using new soap_s2hex() */
- char d[2];
- register int i;
- for (i = 0; i < n; i++)
- { register int m = *s++;
- d[0] = (char)((m >> 4) + (m > 159 ? '7' : '0'));
- m &= 0x0F;
- d[1] = (char)(m + (m > 9 ? '7' : '0'));
- if (soap_send_raw(soap, d, 2))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-unsigned char*
-SOAP_FMAC2
-soap_gethex(struct soap *soap, int *n)
-{
-#ifdef WITH_FAST
- soap->labidx = 0;
- for (;;)
- { register char *s;
- register int i, k;
- if (soap_append_lab(soap, NULL, 0))
- return NULL;
- s = soap->labbuf + soap->labidx;
- k = soap->lablen - soap->labidx;
- soap->labidx = soap->lablen;
- for (i = 0; i < k; i++)
- { register char d1, d2;
- register soap_wchar c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- { d1 = (char)c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- d2 = (char)c;
- else
- { soap->error = SOAP_TYPE;
- return NULL;
- }
- }
- else
- { unsigned char *p;
- soap_unget(soap, c);
- if (n)
- *n = (int)(soap->lablen - k + i);
- p = (unsigned char*)soap_malloc(soap, soap->lablen - k + i);
- if (p)
- memcpy(p, soap->labbuf, soap->lablen - k + i);
- return p;
- }
- *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');
- }
- }
-#else
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { register int i;
- register char *s = (char*)soap_push_block(soap, SOAP_BLKLEN);
- if (!s)
- { soap_end_block(soap);
- return NULL;
- }
- for (i = 0; i < SOAP_BLKLEN; i++)
- { register char d1, d2;
- register soap_wchar c = soap_get(soap);
- if (soap_isxdigit(c))
- { d1 = (char)c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- d2 = (char)c;
- else
- { soap_end_block(soap);
- soap->error = SOAP_TYPE;
- return NULL;
- }
- }
- else
- { unsigned char *p;
- soap_unget(soap, c);
- if (n)
- *n = soap_size_block(soap, i);
- p = (unsigned char*)soap_save_block(soap, NULL, 0);
- return p;
- }
- *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putbase64(struct soap *soap, const unsigned char *s, int n)
-{ register int i;
- register unsigned long m;
- char d[4];
- if (!s)
- return SOAP_OK;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { if (!(soap->dom->data = soap_s2base64(soap, s, soap->dom->data, n)))
- return soap->error;
- return SOAP_OK;
- }
-#endif
- for (; n > 2; n -= 3, s += 3)
- { m = s[0];
- m = (m << 8) | s[1];
- m = (m << 8) | s[2];
- for (i = 4; i > 0; m >>= 6)
- d[--i] = soap_base64o[m & 0x3F];
- if (soap_send_raw(soap, d, 4))
- return soap->error;
- }
- if (n > 0)
- { m = 0;
- for (i = 0; i < n; i++)
- m = (m << 8) | *s++;
- for (; i < 3; i++)
- m <<= 8;
- for (i++; i > 0; m >>= 6)
- d[--i] = soap_base64o[m & 0x3F];
- for (i = 3; i > n; i--)
- d[i] = '=';
- if (soap_send_raw(soap, d, 4))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-unsigned char*
-SOAP_FMAC2
-soap_getbase64(struct soap *soap, int *n, int malloc_flag)
-{
-#ifdef WITH_FAST
- soap->labidx = 0;
- for (;;)
- { register int i, k;
- register char *s;
- if (soap_append_lab(soap, NULL, 2))
- return NULL;
- s = soap->labbuf + soap->labidx;
- k = 3 * ((soap->lablen - soap->labidx) / 3);
- soap->labidx = 3 * (soap->lablen / 3);
- if (!s)
- return NULL;
- for (i = 0; i < k; i += 3)
- { register unsigned long m = 0;
- register int j = 0;
- do
- { register soap_wchar c = soap_get(soap);
- if (c == '=' || c < 0)
- { unsigned char *p;
- switch (j)
- { case 2:
- *s++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *s++ = (char)((m >> 10) & 0xFF);
- *s++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n = (int)(soap->lablen - k + i);
- p = (unsigned char*)soap_malloc(soap, soap->lablen - k + i);
- if (p)
- memcpy(p, soap->labbuf, soap->lablen - k + i);
- if (c >= 0)
- { while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT)
- ;
- }
- soap_unget(soap, c);
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- } while (j < 4);
- *s++ = (char)((m >> 16) & 0xFF);
- *s++ = (char)((m >> 8) & 0xFF);
- *s++ = (char)(m & 0xFF);
- }
- }
-#else
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { register int i;
- register char *s = (char*)soap_push_block(soap, 3 * SOAP_BLKLEN); /* must be multiple of 3 */
- if (!s)
- { soap_end_block(soap);
- return NULL;
- }
- for (i = 0; i < SOAP_BLKLEN; i++)
- { register unsigned long m = 0;
- register int j = 0;
- do
- { register soap_wchar c = soap_get(soap);
- if (c == '=' || c < 0)
- { unsigned char *p;
- i *= 3;
- switch (j)
- { case 2:
- *s++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *s++ = (char)((m >> 10) & 0xFF);
- *s++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n = (int)soap_size_block(soap, i);
- p = (unsigned char*)soap_save_block(soap, NULL, 0);
- if (c >= 0)
- { while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT)
- ;
- }
- soap_unget(soap, c);
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- } while (j < 4);
- *s++ = (char)((m >> 16) & 0xFF);
- *s++ = (char)((m >> 8) & 0xFF);
- *s++ = (char)(m & 0xFF);
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_strdup(struct soap *soap, const char *s)
-{ char *t = NULL;
- if (s && (t = (char*)soap_malloc(soap, strlen(s) + 1)))
- strcpy(t, s);
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_new_block(struct soap *soap)
-{ struct soap_blist *p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New block sequence (prev=%p)\n", soap->blist));
- if (!(p = (struct soap_blist*)SOAP_MALLOC(sizeof(struct soap_blist))))
- return SOAP_EOM;
- p->next = soap->blist;
- p->ptr = NULL;
- p->size = 0;
- soap->blist = p;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_push_block(struct soap *soap, size_t n)
-{ char *p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push block of %u bytes (%u bytes total)\n", (unsigned int)n, (unsigned int)soap->blist->size + (unsigned int)n));
- if (!(p = (char*)SOAP_MALLOC(n + sizeof(char*) + sizeof(size_t))))
- { soap->error = SOAP_EOM;
- return NULL;
- }
- *(char**)p = soap->blist->ptr;
- *(size_t*)(p + sizeof(char*)) = n;
- soap->blist->ptr = p;
- soap->blist->size += n;
- return p + sizeof(char*) + sizeof(size_t);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_pop_block(struct soap *soap)
-{ char *p;
- if (!soap->blist->ptr)
- return;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pop block\n"));
- p = soap->blist->ptr;
- soap->blist->size -= *(size_t*)(p + sizeof(char*));
- soap->blist->ptr = *(char**)p;
- SOAP_FREE(p);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_update_ptrs(struct soap *soap, char *start, char *end, long offset)
-{ int i;
- register struct soap_ilist *ip;
- register struct soap_flist *fp;
- register void *p, **q;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr && (char*)ip->ptr >= start && (char*)ip->ptr < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", ip->id, ip->ptr, (char*)ip->ptr + offset));
- ip->ptr = (char*)ip->ptr + offset;
- }
- for (q = &ip->link; q; q = (void**)p)
- { p = *q;
- if (p && (char*)p >= start && (char*)p < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Link update id='%s' %p\n", ip->id, p));
- *q = (char*)p + offset;
- }
- }
- for (q = &ip->copy; q; q = (void**)p)
- { p = *q;
- if (p && (char*)p >= start && (char*)p < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy chain update id='%s' %p\n", ip->id, p));
- *q = (char*)p + offset;
- }
- }
- for (fp = ip->flist; fp; fp = fp->next)
- { if ((char*)fp->ptr >= start && (char*)fp->ptr < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy list update id='%s' %p\n", ip->id, fp));
- fp->ptr = (char*)fp->ptr + offset;
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_has_copies(struct soap *soap, register const char *start, register const char *end)
-{ register int i;
- register struct soap_ilist *ip;
- register struct soap_flist *fp;
- register const char *p;
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = ip->next)
- { for (p = (const char*)ip->copy; p; p = *(const char**)p)
- if (p >= start && p < end)
- return SOAP_ERR;
- for (fp = ip->flist; fp; fp = fp->next)
- if ((const char*)fp->ptr >= start && (const char*)fp->ptr < end)
- return SOAP_ERR;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_resolve(struct soap *soap)
-{ register int i;
- register struct soap_ilist *ip;
- register struct soap_flist *fp;
- short flag;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr)
- { register void *p, **q, *r;
- q = (void**)ip->link;
- ip->link = NULL;
- r = ip->ptr;
- DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing link chain to resolve id='%s'\n", ip->id));
- while (q)
- { p = *q;
- *q = r;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "... link %p -> %p\n", q, r));
- q = (void**)p;
- }
- }
- else if (*ip->id == '#')
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Missing data for id='%s'\n", ip->id));
- strcpy(soap->id, ip->id + 1);
- return soap->error = SOAP_MISSING_ID;
- }
- }
- }
- do
- { flag = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution phase\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr && !soap_has_copies(soap, (const char*)ip->ptr, (const char*)ip->ptr + ip->size))
- { if (ip->copy)
- { register void *p, **q = (void**)ip->copy;
- DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing copy chain to resolve id='%s'\n", ip->id));
- ip->copy = NULL;
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... copy %p -> %p (%u bytes)\n", ip->ptr, q, (unsigned int)ip->size));
- p = *q;
- memcpy(q, ip->ptr, ip->size);
- q = (void**)p;
- } while (q);
- flag = 1;
- }
- for (fp = ip->flist; fp; fp = ip->flist)
- { register unsigned int k = fp->level;
- register void *p = ip->ptr;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data type=%d location=%p level=%u,%u id='%s'\n", ip->type, p, ip->level, fp->level, ip->id));
- while (ip->level < k)
- { register void **q = (void**)soap_malloc(soap, sizeof(void*));
- if (!q)
- return soap->error;
- *q = p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level, new location=%p holds=%p...\n", q, *q));
- p = (void*)q;
- k--;
- }
- if (fp->fcopy)
- fp->fcopy(soap, ip->type, fp->type, fp->ptr, p, ip->size);
- else
- soap_fcopy(soap, ip->type, fp->type, fp->ptr, p, ip->size);
- ip->flist = fp->next;
- SOAP_FREE(fp);
- flag = 1;
- }
- }
- }
- }
- } while (flag);
-#ifdef SOAP_DEBUG
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->copy || ip->flist)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution error: forwarded data for id='%s' could not be propagated, please report this problem to the developers\n", ip->id));
- }
- }
- }
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution done\n"));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_size_block(struct soap *soap, size_t n)
-{ if (soap->blist->ptr)
- { soap->blist->size -= *(size_t*)(soap->blist->ptr + sizeof(char*)) - n;
- *(size_t*)(soap->blist->ptr + sizeof(char*)) = n;
- }
- return soap->blist->size;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_first_block(struct soap *soap)
-{ char *p, *q, *r;
- p = soap->blist->ptr;
- if (!p)
- return NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "First block\n"));
- r = NULL;
- do
- { q = *(char**)p;
- *(char**)p = r;
- r = p;
- p = q;
- } while (p);
- soap->blist->ptr = r;
- return r + sizeof(char*) + sizeof(size_t);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_next_block(struct soap *soap)
-{ char *p;
- p = soap->blist->ptr;
- if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Next block\n"));
- soap->blist->ptr = *(char**)p;
- SOAP_FREE(p);
- if (soap->blist->ptr)
- return soap->blist->ptr + sizeof(char*) + sizeof(size_t);
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_block_size(struct soap *soap)
-{ return *(size_t*)(soap->blist->ptr + sizeof(char*));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_end_block(struct soap *soap)
-{ struct soap_blist *bp;
- char *p, *q;
- bp = soap->blist;
- if (bp)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of block sequence, free all remaining blocks\n"));
- for (p = bp->ptr; p; p = q)
- { q = *(char**)p;
- SOAP_FREE(p);
- }
- soap->blist = bp->next;
- SOAP_FREE(bp);
- }
- DBGLOG(TEST, if (soap->blist) SOAP_MESSAGE(fdebug, "Restore previous block sequence\n"));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_save_block(struct soap *soap, char *p, int flag)
-{ register size_t n;
- register char *q, *s;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Save all blocks in contiguous memory space of %u bytes (%p->%p)\n", (unsigned int)soap->blist->size, soap->blist->ptr, p));
- if (soap->blist->size)
- { if (!p)
- p = (char*)soap_malloc(soap, soap->blist->size);
- if (p)
- { for (s = p, q = soap_first_block(soap); q; q = soap_next_block(soap))
- { n = soap_block_size(soap);
- if (flag)
- soap_update_ptrs(soap, q, q + n, (long)s - (long)q); /* pointers s and q may or may not be related */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy %u bytes from %p to %p\n", (unsigned int)n, q, s));
- memcpy(s, q, n);
- s += n;
- }
- }
- else
- soap->error = SOAP_EOM;
- }
- soap_end_block(soap);
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsize(struct soap *soap, const char *type, int size)
-{ return soap_putsizes(soap, type, &size, 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsizes(struct soap *soap, const char *type, const int *size, int dim)
-{ return soap_putsizesoffsets(soap, type, size, NULL, dim);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsizesoffsets(struct soap *soap, const char *type, const int *size, const int *offset, int dim)
-{ int i;
- if (!type)
- return NULL;
- if (soap->version == 2)
- { sprintf(soap->type, "%s[%d", type, size[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), " %d", size[i]);
- }
- else
- { if (offset)
- { sprintf(soap->type, "%s[%d", type, size[0] + offset[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), ",%d", size[i] + offset[i]);
- }
- else
- { sprintf(soap->type, "%s[%d", type, size[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), ",%d", size[i]);
- }
- strcat(soap->type, "]");
- }
- return soap->type;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putoffset(struct soap *soap, int offset)
-{ return soap_putoffsets(soap, &offset, 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putoffsets(struct soap *soap, const int *offset, int dim)
-{ register int i;
- sprintf(soap->arrayOffset, "[%d", offset[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->arrayOffset + strlen(soap->arrayOffset), ",%d", offset[i]);
- strcat(soap->arrayOffset, "]");
- return soap->arrayOffset;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_size(const int *size, int dim)
-{ register int i, n = size[0];
- for (i = 1; i < dim; i++)
- n *= size[i];
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getoffsets(const char *attr, const int *size, int *offset, int dim)
-{ register int i, j = 0;
- if (offset)
- for (i = 0; i < dim && attr && *attr; i++)
- { attr++;
- j *= size[i];
- j += offset[i] = (int)atol(attr);
- attr = strchr(attr, ',');
- }
- else
- for (i = 0; i < dim && attr && *attr; i++)
- { attr++;
- j *= size[i];
- j += (int)atol(attr);
- attr = strchr(attr, ',');
- }
- return j;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getsize(const char *attr1, const char *attr2, int *j)
-{ register int n, k;
- char *s;
- *j = 0;
- if (!*attr1)
- return -1;
- n = 1;
- do
- { attr1++;
- k = (int)soap_strtol(attr1, &s, 10);
- n *= k;
- if (k < 0 || n > SOAP_MAXARRAYSIZE || s == attr1)
- return -1;
- attr1 = strchr(s, ',');
- if (!attr1)
- attr1 = strchr(s, ' ');
- if (attr2 && *attr2)
- { attr2++;
- *j *= k;
- k = (int)soap_strtol(attr2, &s, 10);
- *j += k;
- if (k < 0)
- return -1;
- attr2 = s;
- }
- } while (attr1 && *attr1 != ']');
- return n - *j;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getsizes(const char *attr, int *size, int dim)
-{ register int i, k, n;
- if (!*attr)
- return -1;
- i = strlen(attr);
- n = 1;
- do
- { for (i = i-1; i >= 0; i--)
- if (attr[i] == '[' || attr[i] == ',' || attr[i] == ' ')
- break;
- k = (int)atol(attr + i + 1);
- n *= size[--dim] = k;
- if (k < 0 || n > SOAP_MAXARRAYSIZE)
- return -1;
- } while (i >= 0 && attr[i] != '[');
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getposition(const char *attr, int *pos)
-{ register int i, n;
- if (!*attr)
- return -1;
- n = 0;
- i = 1;
- do
- { pos[n++] = (int)atol(attr + i);
- while (attr[i] && attr[i] != ',' && attr[i] != ']')
- i++;
- if (attr[i] == ',')
- i++;
- } while (n < SOAP_MAXDIMS && attr[i] && attr[i] != ']');
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_push_namespace(struct soap *soap, const char *id, const char *ns)
-{ register struct soap_nlist *np;
- register struct Namespace *p;
- np = (struct soap_nlist*)SOAP_MALLOC(sizeof(struct soap_nlist) + strlen(id));
- if (!np)
- return soap->error = SOAP_EOM;
- np->next = soap->nlist;
- soap->nlist = np;
- strcpy(np->id, id);
- np->level = soap->level;
- np->index = -1;
- np->ns = NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns));
- p = soap->local_namespaces;
- if (p)
- { register short i = 0;
- for (; p->id; p++, i++)
- { if (p->ns && !strcmp(ns, p->ns))
- { if (p->out)
- { SOAP_FREE(p->out);
- p->out = NULL;
- }
- break;
- }
- if (p->out)
- { if (!SOAP_STRCMP(ns, p->out))
- break;
- }
- else if (p->in)
- { if (!soap_tag_cmp(ns, p->in))
- { if ((p->out = (char*)SOAP_MALLOC(strlen(ns) + 1)))
- strcpy(p->out, ns);
- break;
- }
- }
- }
- if (p && p->id)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id));
- np->index = i;
- }
- }
- if (!p || !p->id)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns));
- np->ns = (char*)SOAP_MALLOC(strlen(ns) + 1);
- if (!np->ns)
- return soap->error = SOAP_EOM;
- strcpy(np->ns, ns);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_pop_namespace(struct soap *soap)
-{ register struct soap_nlist *np;
- while (soap->nlist && soap->nlist->level >= soap->level)
- { np = soap->nlist->next;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Popped namespace binding (level=%u) '%s'\n", soap->level, soap->nlist->id));
- if (soap->nlist->ns)
- SOAP_FREE(soap->nlist->ns);
- SOAP_FREE(soap->nlist);
- soap->nlist = np;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_namespace(struct soap *soap, const char *id1, const char *id2, int n1, int n2)
-{ register struct soap_nlist *np = soap->nlist;
- while (np && (strncmp(np->id, id1, n1) || np->id[n1]))
- np = np->next;
- if (np)
- { if (np->index < 0 || (np->index >= 0 && soap->local_namespaces[np->index].id && (strncmp(soap->local_namespaces[np->index].id, id2, n2) || soap->local_namespaces[np->index].id[n2])))
- return SOAP_NAMESPACE;
- return SOAP_OK;
- }
- if (n1 == 3 && n1 == n2 && !strcmp(id1, "xml") && !strcmp(id1, id2))
- return SOAP_OK;
- return SOAP_SYNTAX_ERROR;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_default_namespace(struct soap *soap)
-{ register struct soap_nlist *np = soap->nlist;
- while (np && np->index >= -1)
- np = np->next;
- if (np)
- return np->id;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_tag_cmp(register const char *s, register const char *t)
-{ for (; *s && *s != '"'; s++, t++)
- if (tolower(*s) != tolower(*t))
- if (*t != '-')
- { if (*t != '*')
- return 1;
- if (*++t)
- { register int c = tolower(*t);
- for (; *s && *s != '"'; s++)
- { if (tolower(*s) == c)
- if (!soap_tag_cmp(s + 1, t + 1))
- return 0;
- }
- break;
- }
- else
- return 0;
- }
- if (*t == '*' && !t[1])
- return 0;
- return *t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_tag(struct soap *soap, const char *tag1, const char *tag2)
-{ register const char *s, *t;
- if (!tag1 || !tag2 || !*tag2)
- return SOAP_OK;
- s = strchr(tag1, ':');
- t = strchr(tag2, ':');
- if (t)
- { if (s)
- { if (t[1] && SOAP_STRCMP(s + 1, t + 1))
- return SOAP_TAG_MISMATCH;
- if (t != tag2 && soap_match_namespace(soap, tag1, tag2, s - tag1, t - tag2))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
- return SOAP_TAG_MISMATCH;
- }
- }
- else if (SOAP_STRCMP(tag1, t + 1))
- return SOAP_TAG_MISMATCH;
- else if (t != tag2 && soap_match_namespace(soap, tag1, tag2, 0, t - tag2))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
- return SOAP_TAG_MISMATCH;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags and (default) namespaces match: '%s' '%s'\n", tag1, tag2));
- return SOAP_OK;
- }
- if (s)
- { if (SOAP_STRCMP(s + 1, tag2))
- return SOAP_TAG_MISMATCH;
- if (!soap->encodingStyle)
- { t = soap_default_namespace(soap);
- if (!t || soap_match_namespace(soap, tag1, t, s - tag1, strlen(t)))
- return SOAP_TAG_MISMATCH;
- }
- }
- else if (SOAP_STRCMP(tag1, tag2))
- return SOAP_TAG_MISMATCH;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags match: '%s' '%s'\n", tag1, tag2));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_array(struct soap *soap, const char *type)
-{ if (*soap->arrayType)
- if (soap_match_tag(soap, soap->arrayType, type)
- && soap_match_tag(soap, soap->arrayType, "xsd:anyType")
- && soap_match_tag(soap, soap->arrayType, "xsd:ur-type")
- )
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array type mismatch: '%s' '%s'\n", soap->arrayType, type));
- return SOAP_TAG_MISMATCH;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-
-#ifdef WITH_OPENSSL
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid)
-{ int err;
- soap->keyfile = keyfile;
- soap->password = password;
- soap->cafile = cafile;
- soap->capath = capath;
- if (dhfile)
- { soap->dhfile = dhfile;
- soap->rsa = 0;
- }
- else
- { soap->dhfile = NULL;
- soap->rsa = 1;
- }
- soap->randfile = randfile;
- soap->require_client_auth = (flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION);
- if (!(err = soap->fsslauth(soap)))
- if (sid)
- SSL_CTX_set_session_id_context(soap->ctx, (unsigned char*)sid, strlen(sid));
- return err;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *randfile)
-{ soap->keyfile = keyfile;
- soap->password = password;
- soap->cafile = cafile;
- soap->capath = capath;
- soap->dhfile = NULL;
- soap->rsa = 0;
- soap->randfile = randfile;
- soap->require_server_auth = (flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION);
- return soap->fsslauth(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-ssl_init()
-{ static int done = 0;
- if (!done)
- { done = 1;
- SSL_library_init();
-#ifndef WITH_LEAN
- SSL_load_error_strings();
-#endif
- if (!RAND_load_file("/dev/urandom", 1024))
- { int r;
-#ifdef HAVE_RAND_R
- unsigned int s = (unsigned int)time(NULL);
-#endif
- char buf[SOAP_BUFLEN];
- RAND_seed(buf, sizeof(buf));
- while (!RAND_status())
- {
-#ifdef HAVE_RAND_R
- r = rand_r(&s);
-#else
- r = rand();
-#endif
- RAND_seed(&r, sizeof(int));
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char *
-ssl_error(struct soap *soap, int ret)
-{ int err = SSL_get_error(soap->ssl, ret);
- const char *msg = soap_str_code(h_ssl_error_codes, err);
- if (msg)
- strcpy(soap->msgbuf, msg);
- else
- return ERR_error_string(err, soap->msgbuf);
- if (ERR_peek_error())
- { unsigned long r;
- strcat(soap->msgbuf, "\n");
- while ((r = ERR_get_error()))
- ERR_error_string_n(r, soap->msgbuf + strlen(soap->msgbuf), sizeof(soap->msgbuf) - strlen(soap->msgbuf));
- }
- else
- { switch (ret)
- { case 0:
- strcpy(soap->msgbuf, "EOF was observed that violates the protocol. The client probably provided invalid authentication information.");
- break;
- case -1:
- sprintf(soap->msgbuf, "Error observed by underlying BIO: %s", strerror(errno));
- break;
- }
- }
- return soap->msgbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_password(char *buf, int num, int rwflag, void *userdata)
-{ if (num < (int)strlen((char*)userdata) + 1)
- return 0;
- return strlen(strcpy(buf, (char*)userdata));
-}
-#endif
-
-/******************************************************************************/
-/* This callback is included for future references. It should not be deleted
-#ifndef PALM_1
-static DH *
-ssl_tmp_dh(SSL *ssl, int is_export, int keylength)
-{ static DH *dh512 = NULL;
- static DH *dh1024 = NULL;
- DH *dh;
- switch (keylength)
- { case 512:
- if (!dh512)
- { BIO *bio = BIO_new_file("dh512.pem", "r");
- if (bio)
- { dh512 = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- return dh512;
- }
- }
- else
- return dh512;
- default:
- if (!dh1024)
- { BIO *bio = BIO_new_file("dh1024.pem", "r");
- if (bio)
- { dh1024 = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- }
- }
- dh = dh1024;
- }
- return dh;
-}
-#endif
-*/
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_auth_init(struct soap *soap)
-{ ssl_init();
- if (!soap->ctx)
- if (!(soap->ctx = SSL_CTX_new(SSLv23_method())))
- return soap_set_receiver_error(soap, "SSL error", "Can't setup context", SOAP_SSL_ERROR);
- if (soap->randfile)
- { if (!RAND_load_file(soap->randfile, -1))
- return soap_set_receiver_error(soap, "SSL error", "Can't load randomness", SOAP_SSL_ERROR);
- }
- if (soap->cafile || soap->capath)
- if (!SSL_CTX_load_verify_locations(soap->ctx, soap->cafile, soap->capath))
- return soap_set_receiver_error(soap, "SSL error", "Can't read CA file and/or directory", SOAP_SSL_ERROR);
- if (!SSL_CTX_set_default_verify_paths(soap->ctx))
- return soap_set_receiver_error(soap, "SSL error", "Can't read default CA file and/or directory", SOAP_SSL_ERROR);
- if (soap->keyfile)
- { if (!SSL_CTX_use_certificate_chain_file(soap->ctx, soap->keyfile))
- return soap_set_receiver_error(soap, "SSL error", "Can't read certificate key file", SOAP_SSL_ERROR);
- if (soap->password)
- { SSL_CTX_set_default_passwd_cb_userdata(soap->ctx, (void*)soap->password);
- SSL_CTX_set_default_passwd_cb(soap->ctx, ssl_password);
- if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM))
- return soap_set_receiver_error(soap, "SSL error", "Can't read key file", SOAP_SSL_ERROR);
- }
- }
- if (soap->rsa)
- { RSA *rsa = RSA_generate_key(512, RSA_F4, NULL, NULL);
- if (!SSL_CTX_set_tmp_rsa(soap->ctx, rsa))
- { if (rsa)
- RSA_free(rsa);
- return soap_set_receiver_error(soap, "SSL error", "Can't set RSA key", SOAP_SSL_ERROR);
- }
- RSA_free(rsa);
- }
- else if (soap->dhfile)
- { DH *dh = 0;
- BIO *bio;
- bio = BIO_new_file(soap->dhfile, "r");
- if (!bio)
- return soap_set_receiver_error(soap, "SSL error", "Can't read DH file", SOAP_SSL_ERROR);
- dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- if (SSL_CTX_set_tmp_dh(soap->ctx, dh) < 0)
- { if (dh)
- DH_free(dh);
- return soap_set_receiver_error(soap, "SSL error", "Can't set DH parameters", SOAP_SSL_ERROR);
- }
- DH_free(dh);
- }
- SSL_CTX_set_options(soap->ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2);
- SSL_CTX_set_verify(soap->ctx, soap->require_client_auth ? (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT) : soap->require_server_auth ? SSL_VERIFY_PEER : SSL_VERIFY_NONE, soap->fsslverify);
-#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
- SSL_CTX_set_verify_depth(soap->ctx, 1);
-#else
- SSL_CTX_set_verify_depth(soap->ctx, 9);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_verify_callback(int ok, X509_STORE_CTX *store)
-{
-#ifdef SOAP_DEBUG
- if (!ok)
- { char data[256];
- X509 *cert = X509_STORE_CTX_get_current_cert(store);
- fprintf(stderr, "SSL Verify error with certificate at depth %d: %s\n", X509_STORE_CTX_get_error_depth(store), X509_verify_cert_error_string(X509_STORE_CTX_get_error(store)));
- X509_NAME_oneline(X509_get_issuer_name(cert), data, sizeof(data));
- fprintf(stderr, "certificate issuer %s\n", data);
- X509_NAME_oneline(X509_get_subject_name(cert), data, sizeof(data));
- fprintf(stderr, "certificate subject %s\n", data);
- }
-#endif
- /* return 1 to always continue, but unsafe progress will be terminated by SSL */
- return ok;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_accept(struct soap *soap)
-{ int i, r;
- if (!soap_valid_socket(soap->socket))
- return soap_set_receiver_error(soap, "SSL error", "No socket in soap_ssl_accept()", SOAP_SSL_ERROR);
- if (!soap->ssl)
- { soap->ssl = SSL_new(soap->ctx);
- if (!soap->ssl)
- return soap_set_receiver_error(soap, "SSL error", "SSL_new() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
- }
- else
- SSL_clear(soap->ssl);
- soap->imode |= SOAP_ENC_SSL;
- soap->omode |= SOAP_ENC_SSL;
-#ifdef WIN32
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &nonblocking);
- }
-#else
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)|O_NONBLOCK);
-#endif
- soap->bio = BIO_new_socket((SOAP_SOCKET)soap->socket, BIO_NOCLOSE);
- SSL_set_bio(soap->ssl, soap->bio, soap->bio);
- i = 100; /* 100 * 0.1 ms retries */
- while ((r = SSL_accept(soap->ssl)) <= 0)
- { int err = SSL_get_error(soap->ssl, r);
- if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
- { struct timeval timeout;
- fd_set fd;
- if (i-- <= 0)
- break;
- timeout.tv_sec = 0;
- timeout.tv_usec = 100000;
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r < 0 && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- }
- else
- { soap->errnum = err;
- break;
- }
- }
-#ifdef WIN32
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking);
- }
-#else
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)&~O_NONBLOCK);
-#endif
- if (r <= 0)
- { soap_set_receiver_error(soap, ssl_error(soap, r), "SSL_accept() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
- soap_closesock(soap);
- return SOAP_SSL_ERROR;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#endif /* WITH_OPENSSL */
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-tcp_init(struct soap *soap)
-{ soap->errmode = 1;
-#ifdef WIN32
- if (tcp_done)
- return 0;
- else
- { WSADATA w;
- if (WSAStartup(MAKEWORD(1, 1), &w))
- return -1;
- tcp_done = 1;
- }
-#endif
-#ifdef PALM
- errno = 0;
- h_errno = 0;
- AppNetRefnum = 0;
- NetUInit();
- AppNetTimeout = 10000;
- NetLibOpen(AppNetRefnum, &h_errno);
-#endif
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_done(struct soap *soap)
-{
-#ifdef SOAP_DEBUG
- int i;
-#endif
- soap_free(soap);
- while (soap->clist)
- { struct soap_clist *p = soap->clist->next;
- SOAP_FREE(soap->clist);
- soap->clist = p;
- }
- soap->keep_alive = 0; /* to force close the socket */
- soap_closesock(soap);
-#ifdef WITH_COOKIES
- soap_free_cookies(soap);
-#endif
- while (soap->plugins)
- { register struct soap_plugin *p = soap->plugins->next;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Removing plugin '%s'\n", soap->plugins->id));
- if (soap->plugins->fcopy || !soap->copy)
- soap->plugins->fdelete(soap, soap->plugins);
- SOAP_FREE(soap->plugins);
- soap->plugins = p;
- }
- soap->fplugin = fplugin;
- soap->fpost = http_post;
- soap->fget = http_get;
- soap->fposthdr = http_post_header;
- soap->fresponse = http_response;
- soap->fparse = http_parse;
- soap->fparsehdr = http_parse_header;
-#ifndef MAC_CARBON
-#ifndef WITH_IPV6
- soap->fresolve = tcp_gethost;
-#else
- soap->fresolve = NULL;
-#endif
- soap->faccept = tcp_accept;
- soap->fopen = tcp_connect;
- soap->fclose = tcp_disconnect;
- soap->fclosesocket = tcp_closesocket;
- soap->fshutdownsocket = tcp_shutdownsocket;
- soap->fsend = fsend;
- soap->frecv = frecv;
- soap->fpoll = soap_poll;
-#else
- soap->fpoll = NULL;
-#endif
- soap->fprepareinit = NULL;
- soap->fpreparesend = NULL;
- soap->fpreparerecv = NULL;
- soap->fignore = NULL;
- soap->fserveloop = NULL;
-#ifdef WITH_OPENSSL
- if (soap->session)
- { SSL_SESSION_free(soap->session);
- soap->session = NULL;
- }
-#endif
- if (!soap->copy)
- { if (soap_valid_socket(soap->master))
- { soap->fclosesocket(soap, (SOAP_SOCKET)soap->master);
- soap->master = SOAP_INVALID_SOCKET;
- }
-#ifdef WITH_OPENSSL
- if (soap->ctx)
- { SSL_CTX_free(soap->ctx);
- soap->ctx = NULL;
- }
-#endif
- }
-#ifdef SOAP_DEBUG
- for (i = 0; i < SOAP_MAXLOGS; i++)
- { soap_close_logfile(soap, i);
- if (soap->logfile[i])
- { SOAP_FREE((void*)soap->logfile[i]);
- soap->logfile[i] = NULL;
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_cleanup(struct soap *soap)
-{ soap_done(soap);
-#ifdef WIN32
- if (!tcp_done)
- return;
- tcp_done = 0;
- WSACleanup();
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-tcp_error(struct soap *soap)
-{ register const char *msg = NULL;
- switch (soap->errmode)
- { case 0:
- msg = soap_strerror(soap);
- break;
- case 1:
- msg = "WSAStartup failed";
- break;
- case 2:
- {
-#ifndef WITH_LEAN
- msg = soap_str_code(h_error_codes, soap->errnum);
- if (!msg)
-#endif
- { sprintf(soap->msgbuf, "TCP error %d", soap->errnum);
- msg = soap->msgbuf;
- }
- }
- }
- return msg;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-http_error(struct soap *soap, int status)
-{ register const char *msg = NULL;
-#ifndef WITH_LEAN
- msg = soap_str_code(h_http_error_codes, status);
- if (!msg)
-#endif
- { sprintf(soap->msgbuf, "HTTP error %d", status);
- msg = soap->msgbuf;
- }
- return msg;
-}
-#endif
-
-/******************************************************************************/
-/* WR[ */
-#ifndef WITH_IPV6
-/* ]WR */
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr)
-{ unsigned long iadd;
- struct hostent hostent, *host = &hostent;
-/* WR[ */
-#ifdef VXWORKS
- int hostint;
- char *addrcopy = (char*)malloc(strlen(addr) + 1); /*copy of addr. */
- /* inet_addr(), and hostGetByName() expect "char *"; addr is a "const char *". */
- strncpy(addrcopy, addr, strlen(addr)+1);
- iadd = inet_addr(addrcopy);
-#else
-/* ]WR */
-#if defined(_AIXVERSION_431) || defined(TRU64)
- struct hostent_data ht_data;
-#endif
- iadd = inet_addr(addr);
-/* WR[ */
-#endif
-/* ]WR */
- if ((int)iadd != -1)
- { memcpy(inaddr, &iadd, sizeof(iadd));
-/* WR[ */
-#ifdef VXWORKS
- free(addrcopy);
-#endif
-/* ]WR */
- return SOAP_OK;
- }
-#if defined(__GLIBC__)
- if (gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &host, &soap->errnum) < 0)
- host = NULL;
-#elif defined(_AIXVERSION_431) || defined(TRU64)
- memset((void*)&ht_data, 0, sizeof(ht_data));
- if (gethostbyname_r(addr, &hostent, &ht_data) < 0)
- { host = NULL;
- soap->errnum = h_errno;
- }
-#elif defined(HAVE_GETHOSTBYNAME_R)
- host = gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &soap->errnum);
-/* WR[ */
-#elif defined(VXWORKS)
- /* If the DNS resolver library resolvLib has been configured in the vxWorks
- * image, a query for the host IP address is sent to the DNS server, if the
- * name was not found in the local host table. */
- hostint = hostGetByName(addrcopy);
- if (hostint == ERROR)
- { host = NULL;
- soap->errnum = soap_errno;
- }
- free(addrcopy); /*free() is placed after the error checking to assure that
- * errno captured is that from hostGetByName() */
-/* ]WR */
-#else
- if (!(host = gethostbyname(addr)))
- soap->errnum = h_errno;
-#endif
- if (!host)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Host name not found\n"));
- return SOAP_ERR;
- }
-/* WR[ */
-#ifdef VXWORKS
- inaddr->s_addr = hostint;
-#else
-/* ]WR */
- memcpy(inaddr, host->h_addr, host->h_length);
-/* WR[ */
-#endif
-/* ]WR */
- return SOAP_OK;
-}
-#endif
-#endif
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port)
-{ struct sockaddr_in sockaddr;
-/* WR[ */
-#ifdef WITH_IPV6
- struct addrinfo *addrinfo;
- struct addrinfo hints;
- struct addrinfo resaddr;
- struct sockaddr_storage addrstorage;
- int err;
-#endif /* WITH_IPV6 */
-/* ]WR */
- register int fd;
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- if (soap_valid_socket(soap->socket))
- soap->fclosesocket(soap, (SOAP_SOCKET)soap->socket);
- soap->socket = SOAP_INVALID_SOCKET;
- if (tcp_init(soap))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP initialization failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- soap->errmode = 0;
-/* WR[ */
-#ifdef WITH_IPV6
- memset((void*)&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- soap->errmode = 2;
- if (soap->proxy_host)
- err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &addrinfo);
- else
- err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
- if (addrinfo)
- { resaddr = *addrinfo;
- addrstorage = *((struct sockaddr_storage *) addrinfo->ai_addr);
- resaddr.ai_addr = (struct sockaddr *) &addrstorage;
- freeaddrinfo(addrinfo);
- }
- if (err)
- { soap_set_sender_error(soap, gai_strerror(err),
- "TCP getaddrinfo on proxy host failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- fd = (int)socket(resaddr.ai_family, resaddr.ai_socktype, resaddr.ai_protocol); /* modified to use fd */
- soap->errmode = 0;
-#else /* WITH_IPV6 */
-/* ]WR */
- fd = (int)socket(AF_INET, SOCK_STREAM, 0);
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- if (fd < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP socket failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef SOCKET_CLOSE_ON_EXEC
-#ifdef WIN32
-#ifndef UNDER_CE
- SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0);
-#endif
-#else
- fcntl (fd, F_SETFD, 1);
-#endif
-#endif
-#ifndef WITH_LEAN
- if (soap->connect_flags & SO_LINGER)
- { struct linger linger;
- memset((void*)&linger, 0, sizeof(linger));
- linger.l_onoff = 1;
- linger.l_linger = 0;
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- }
- if ((soap->connect_flags & ~SO_LINGER) && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, soap->connect_flags & ~SO_LINGER, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
-#endif
-#endif
-/* WR[ */
-#ifndef WITH_IPV6
-/* ]WR */
- memset((void*)&sockaddr, 0, sizeof(sockaddr));
- sockaddr.sin_family = AF_INET;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Open socket %d to host='%s'\n", fd, host));
- soap->errmode = 2;
- if (soap->proxy_host)
- { if (soap->fresolve(soap, soap->proxy_host, &sockaddr.sin_addr))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- sockaddr.sin_port = htons((short)soap->proxy_port);
- }
- else
- { if (soap->fresolve(soap, host, &sockaddr.sin_addr))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP get host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- sockaddr.sin_port = htons((short)port);
- }
- soap->errmode = 0;
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#if defined(WIN32)
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- { vx_nonblocking = TRUE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK);
-#endif
- else
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- { vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- for (;;)
- {
-/* WR[ */
-#ifdef WITH_IPV6
- if (connect((SOAP_SOCKET)fd, resaddr.ai_addr, resaddr.ai_addrlen)) /* modified to use fd */
-#else /* WITH_IPV6 */
- if (connect((SOAP_SOCKET)fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)))
-#endif /* WITH_IPV6 */
-/* ]WR */
- {
-#ifndef WITH_LEAN
- if (soap->connect_timeout && (soap_socket_errno == SOAP_EINPROGRESS || soap_socket_errno == SOAP_EWOULDBLOCK))
- { struct timeval timeout;
-#if defined(SOCKLEN_T)
- SOCKLEN_T n = sizeof(struct sockaddr_in);
-#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN)
- socklen_t n = sizeof(struct sockaddr_in);
-#elif defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)
- int n = sizeof(struct sockaddr_in);
-#else
- size_t n = sizeof(struct sockaddr_in);
-#endif
- fd_set fds;
- if (soap->connect_timeout > 0)
- { timeout.tv_sec = soap->connect_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->connect_timeout/1000000;
- timeout.tv_usec = -soap->connect_timeout%1000000;
- }
- FD_ZERO(&fds);
- FD_SET((SOAP_SOCKET)fd, &fds);
- for (;;)
- { int r = select((SOAP_SOCKET)(fd + 1), NULL, &fds, NULL, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
- soap_set_sender_error(soap, "Timeout", "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- }
- n = sizeof(soap->errnum);
- if (!getsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &n) && !soap->errnum)
- break;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- else
-#endif
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- }
- else
- break;
- }
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- { vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- soap->socket = fd;
-#ifdef WITH_OPENSSL
- soap->imode &= ~SOAP_ENC_SSL;
- soap->omode &= ~SOAP_ENC_SSL;
- if (!strncmp(endpoint, "https:", 6))
- { int r;
- if (soap->proxy_host)
- { unsigned int k = soap->omode; /* make sure we only parse HTTP */
- size_t n = soap->count; /* save the content length */
- soap->omode &= ~0xFF; /* mask IO and ENC */
- soap->omode |= SOAP_IO_BUFFER;
- soap_begin_send(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to proxy server\n"));
- sprintf(soap->tmpbuf, "CONNECT %s:%d HTTP/%s", host, port, soap->http_version);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return -1;
-#ifndef WITH_LEAN
- if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((soap->error = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
- return soap->error;
- }
-#endif
- if ((soap->error = soap->fposthdr(soap, NULL, NULL))
- || soap_flush(soap))
- return -1;
- soap->omode = k;
- k = soap->imode;
- soap->imode &= ~0xFF; /* mask IO and ENC */
- if (soap_begin_recv(soap))
- return -1;
- soap->imode = k;
- soap->count = n;
- soap_begin_send(soap);
- }
- if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
- { soap_set_sender_error(soap, "SSL error", "SSL authentication failed in tcp_connect(): check password, key file, and ca file.", SOAP_SSL_ERROR);
- return -1;
- }
- soap->ssl = SSL_new(soap->ctx);
- if (!soap->ssl)
- { soap->error = SOAP_SSL_ERROR;
- return -1;
- }
- if (soap->session)
- { if (!strcmp(soap->session_host, host) && soap->session_port == port)
- SSL_set_session(soap->ssl, soap->session);
- SSL_SESSION_free(soap->session);
- soap->session = NULL;
- }
- soap->imode |= SOAP_ENC_SSL;
- soap->omode |= SOAP_ENC_SSL;
- soap->bio = BIO_new_socket((SOAP_SOCKET)fd, BIO_NOCLOSE);
- SSL_set_bio(soap->ssl, soap->bio, soap->bio);
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#ifdef WIN32
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking);
- }
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK);
-#endif
-#endif
- for (;;)
- { if ((r = SSL_connect(soap->ssl)) <= 0)
- { int err = SSL_get_error(soap->ssl, r);
- if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- { soap_set_sender_error(soap, ssl_error(soap, r), "SSL connect failed in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- if (soap->connect_timeout)
- { struct timeval timeout;
- fd_set fds;
- if (soap->connect_timeout > 0)
- { timeout.tv_sec = soap->connect_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->connect_timeout/1000000;
- timeout.tv_usec = -soap->connect_timeout%1000000;
- }
- FD_ZERO(&fds);
- FD_SET((SOAP_SOCKET)(soap->socket), &fds);
- for (;;)
- { int r = select((SOAP_SOCKET)(soap->socket + 1), &fds, NULL, &fds, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
- soap_set_sender_error(soap, "Timeout", "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- continue;
- }
- }
- break;
- }
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#ifdef WIN32
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- if (soap->require_server_auth)
- { X509 *peer;
- int err;
- if ((err = SSL_get_verify_result(soap->ssl)) != X509_V_OK)
- { soap_set_sender_error(soap, X509_verify_cert_error_string(err), "SSL certificate cannot be verified in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- peer = SSL_get_peer_certificate(soap->ssl);
- if (!peer)
- { soap_set_sender_error(soap, "SSL error", "No SSL certificate was presented by the peer in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName, soap->msgbuf, sizeof(soap->msgbuf));
- X509_free(peer);
- if (soap_tag_cmp(soap->msgbuf, host))
- { soap_set_sender_error(soap, "SSL error", "SSL certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- }
- }
-#endif
- return fd;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_bind(struct soap *soap, const char *host, int port, int backlog)
-{ struct sockaddr_in sockaddr;
-/* WR[ */
-#ifdef WITH_IPV6
- struct addrinfo *addrinfo;
- struct addrinfo hints;
- struct addrinfo resaddr;
- struct sockaddr_storage addrstorage;
- int err;
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- if (soap_valid_socket(soap->master))
- { soap->fclosesocket(soap, (SOAP_SOCKET)soap->master);
- soap->master = SOAP_INVALID_SOCKET;
- }
- soap->socket = SOAP_INVALID_SOCKET;
- soap->errmode = 1;
- if (tcp_init(soap))
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP init failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#ifdef WITH_IPV6
- memset((void*)&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_PASSIVE;
- soap->errmode = 2;
- if (host)
- err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
- else
- err = getaddrinfo(NULL, soap_int2s(soap, port), &hints, &addrinfo);
- if (NULL != addrinfo)
- {
- resaddr = *addrinfo;
- addrstorage = *((struct sockaddr_storage *) addrinfo->ai_addr);
- resaddr.ai_addr = (struct sockaddr *) &addrstorage;
- freeaddrinfo(addrinfo);
- }
- if (err)
- { soap_set_receiver_error(soap, gai_strerror(err), "TCP getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- soap->errmode = 0;
- if ((soap->master = socket(resaddr.ai_family, resaddr.ai_socktype, resaddr.ai_protocol)) < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP socket failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- soap->errmode = 0;
- if ((soap->master = (int)socket(AF_INET, SOCK_STREAM, 0)) < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP socket failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifdef SOCKET_CLOSE_ON_EXEC
-#ifdef WIN32
-#ifndef UNDER_CE
- SetHandleInformation((HANDLE)soap->master, HANDLE_FLAG_INHERIT, 0);
-#endif
-#else
- fcntl (soap->master, F_SETFD, 1);
-#endif
-#endif
-#ifndef WITH_LEAN
- if (soap->bind_flags && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, soap->bind_flags, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)soap->master, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#endif
-#endif
-/* WR[ */
-#ifdef WITH_IPV6
- soap->errmode = 0;
- if (bind(soap->master, resaddr.ai_addr, resaddr.ai_addrlen) || listen(soap->master, backlog))
- {
- soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
- soap_closesock(soap);
- soap_set_receiver_error(soap, tcp_error(soap), "TCP bind failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- memset((void*)&sockaddr, 0, sizeof(sockaddr));
- sockaddr.sin_family = AF_INET;
- soap->errmode = 2;
- if (host)
- { if (soap->fresolve(soap, host, &sockaddr.sin_addr))
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP get host by name failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- else
- sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
- sockaddr.sin_port = htons((short)port);
- soap->errmode = 0;
- if (bind((SOAP_SOCKET)soap->master, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) || listen((SOAP_SOCKET)soap->master, backlog))
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
- soap_closesock(soap);
- soap_set_receiver_error(soap, tcp_error(soap), "TCP bind failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifdef WITH_OPENSSL
- if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
- return -1;
-#endif
- return soap->master;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_poll(struct soap *soap)
-{
-#ifndef WITH_LEAN
- struct timeval timeout;
- fd_set sfd,rfd;
- int r;
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- FD_ZERO(&rfd);
- FD_ZERO(&sfd);
- if (soap->socket >= 0)
- { FD_SET(soap->socket, &rfd);
- FD_SET(soap->socket, &sfd);
- r = select(soap->socket + 1, &rfd, &sfd, NULL, &timeout);
- }
- else if (soap->master >= 0)
- { FD_SET(soap->master, &rfd);
- r = select(soap->master + 1, &rfd, &sfd, NULL, &timeout);
- }
- else
- { FD_SET(soap->sendfd, &sfd);
- FD_SET(soap->recvfd, &rfd);
- r = select((soap->sendfd > soap->recvfd ? soap->sendfd : soap->recvfd) + 1, &rfd, &sfd, NULL, &timeout);
- }
- if (r > 0)
- {
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { if ((soap->socket >= 0) && FD_ISSET(soap->socket, &rfd))
- { char buf = '\0';
- if (SSL_peek(soap->ssl, &buf, 1) <= 0)
- return SOAP_EOF;
- }
- }
-#endif
- return SOAP_OK;
- }
- if (r < 0 && (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "select failed in soap_poll()", SOAP_TCP_ERROR);
- return soap->error = SOAP_TCP_ERROR;
- }
- else
- soap->errnum = soap_errno;
- return SOAP_EOF;
-#else
- return SOAP_OK;
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_accept(struct soap *soap, int s, struct sockaddr *a, int *n)
-{ int fd;
-#if defined(SOCKLEN_T)
- fd = (int)accept((SOAP_SOCKET)s, a, (SOCKLEN_T*)n);
-#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN)
- fd = (int)accept((SOAP_SOCKET)s, a, (socklen_t*)n);
-#elif defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)
- fd = (int)accept((SOAP_SOCKET)s, a, n);
-#else
- fd = (int)accept((SOAP_SOCKET)s, a, (size_t*)n);
-#endif
-#ifdef SOCKET_CLOSE_ON_EXEC
-#ifdef WIN32
-#ifndef UNDER_CE
- SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0);
-#endif
-#else
- fcntl(fd, F_SETFD, FD_CLOEXEC);
-#endif
-#endif
- return fd;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_accept(struct soap *soap)
-{
-/* WR[ */
-#ifdef WITH_IPV6
- struct sockaddr_storage sockaddr;
-#else /* WITH_IPV6 */
-/* ]WR */
- struct sockaddr_in sockaddr;
-/* WR[ */
-#endif
-/* ]WR */
- int n = (int)sizeof(struct sockaddr);
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- soap->error = SOAP_OK;
- memset((void*)&sockaddr, 0, sizeof(sockaddr));
- soap->socket = SOAP_INVALID_SOCKET;
- soap->errmode = 0;
- if (soap_valid_socket(soap->master))
- { for (;;)
- {
-#ifndef WITH_LEAN
- if (soap->accept_timeout)
- { struct timeval timeout;
- fd_set fd;
- if (soap->accept_timeout > 0)
- { timeout.tv_sec = soap->accept_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->accept_timeout/1000000;
- timeout.tv_usec = -soap->accept_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->master, &fd);
- for (;;)
- { int r = select((SOAP_SOCKET)(soap->master + 1), &fd, &fd, NULL, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- soap_set_receiver_error(soap, "Timeout", "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- soap_closesock(soap);
- soap_set_sender_error(soap, tcp_error(soap), "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
-#if defined(WIN32)
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &nonblocking);
- }
-#elif defined(VXWORKS)
- { vx_nonblocking = TRUE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- }
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)|O_NONBLOCK);
-#endif
- }
- else
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- { vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- if ((soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&sockaddr, &n)) >= 0)
- {
-/* WR[ */
-#ifdef WITH_IPV6
-/* Use soap->host to store the numeric form of the remote host */
- getnameinfo((struct sockaddr*)&sockaddr, n, soap->host, sizeof(soap->host), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV);
- soap->ip = 0; /* info stored in soap->host */
- soap->port = 0; /* info stored in soap->host */
-#else /* WITH_IPV6 */
-/* ]WR */
- soap->ip = ntohl(sockaddr.sin_addr.s_addr);
- soap->port = (int)ntohs(sockaddr.sin_port);
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- soap->keep_alive = ((soap->imode & SOAP_IO_KEEPALIVE) != 0);
-#ifndef WITH_LEAN
- if (soap->accept_flags & SO_LINGER)
- { struct linger linger;
- memset((void*)&linger, 0, sizeof(linger));
- linger.l_onoff = 1;
- linger.l_linger = 0;
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- if ((soap->accept_flags & ~SO_LINGER) && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, soap->accept_flags & ~SO_LINGER, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-#endif
-#endif
- if (soap->accept_timeout)
- {
-#if defined(WIN32)
- u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &blocking);
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking);
-/* WR[ */
-#elif defined(VXWORKS)
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)(&vx_nonblocking));
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK);
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)&~O_NONBLOCK);
-#endif
- }
- return soap->socket;
- }
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- }
- else
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP no master socket in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_disconnect(struct soap *soap)
-{
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { int r, s = 0;
- if (soap->session)
- SSL_SESSION_free(soap->session);
- if (*soap->host)
- { soap->session = SSL_get1_session(soap->ssl);
- if (soap->session)
- { strcpy(soap->session_host, soap->host);
- soap->session_port = soap->port;
- }
- }
- r = SSL_shutdown(soap->ssl);
- if (r != 1)
- { s = ERR_get_error();
- if (s)
- { if (soap_valid_socket(soap->socket))
- { soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1);
- soap->socket = SOAP_INVALID_SOCKET;
- }
- r = SSL_shutdown(soap->ssl);
- }
- }
- DBGLOG(TEST, if (s) SOAP_MESSAGE(fdebug, "Shutdown failed: %d\n", SSL_get_error(soap->ssl, r)));
- SSL_free(soap->ssl);
- soap->ssl = NULL;
- if (s)
- return SOAP_SSL_ERROR;
- ERR_remove_state(0);
- }
-#endif
- if (soap_valid_socket(soap->socket))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Closing socket %d\n", soap->socket));
- soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 2);
- soap->fclosesocket(soap, (SOAP_SOCKET)soap->socket);
- soap->socket = SOAP_INVALID_SOCKET;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_closesocket(struct soap *soap, SOAP_SOCKET fd)
-{ return closesocket(fd);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET fd, int how)
-{ return shutdown(fd, how);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_closesock(struct soap *soap)
-{ register int status = soap->error;
-#ifndef MAC_CARBON
- if (status == SOAP_EOF || status == SOAP_TCP_ERROR || status == SOAP_SSL_ERROR || !soap->keep_alive)
- { if ((soap->error = soap->fclose(soap)))
- return soap->error;
- soap->socket = SOAP_INVALID_SOCKET;
- }
-#endif
-#ifdef WITH_ZLIB
- if (soap->zlib_state == SOAP_ZLIB_DEFLATE)
- deflateEnd(&soap->d_stream);
- else if (soap->zlib_state == SOAP_ZLIB_INFLATE)
- inflateEnd(&soap->d_stream);
- soap->zlib_state = SOAP_ZLIB_NONE;
-#endif
- return soap->error = status;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_hash(register const char *s)
-{ register size_t h = 0;
- while (*s)
- h = 65599*h + *s++;
- return h % SOAP_IDHASH;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_init_pht(struct soap *soap)
-{ register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing pointer hashtable\n"));
- for (i = 0; i < (int)SOAP_PTRHASH; i++)
- soap->pht[i] = NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new()
-{ struct soap *soap = (struct soap*)SOAP_MALLOC(sizeof(struct soap));
- if (soap)
- soap_init(soap);
- return soap;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new1(int mode)
-{ return soap_new2(mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new2(int imode, int omode)
-{ struct soap *soap = (struct soap*)SOAP_MALLOC(sizeof(struct soap));
- if (soap)
- soap_init2(soap, imode, omode);
- return soap;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-soap_free_pht(struct soap *soap)
-{ register struct soap_plist *pp, *next;
- register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n"));
- for (i = 0; i < (int)SOAP_PTRHASH; i++)
- { for (pp = soap->pht[i]; pp; pp = next)
- { next = pp->next;
- SOAP_FREE(pp);
- }
- soap->pht[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embed(struct soap *soap, const void *p, const struct soap_array *a, int n, const char *tag, int type)
-{ register int i;
- struct soap_plist *pp;
- if (soap->version != 1)
- soap->encoding = 1;
- if (a)
- i = soap_array_pointer_lookup(soap, p, a, n, type, &pp);
- else
- i = soap_pointer_lookup(soap, p, type, &pp);
- if (i)
- { if (soap_is_embedded(soap, pp)
- || soap_is_single(soap, pp))
- return 0;
- soap_set_embedded(soap, pp);
- }
- return i;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pointer_lookup(struct soap *soap, const void *p, int type, struct soap_plist **ppp)
-{ register struct soap_plist *pp;
- *ppp = NULL;
- if (p)
- for (pp = soap->pht[soap_hash_ptr(p)]; pp; pp = pp->next)
- if (pp->ptr == p && pp->type == type)
- { *ppp = pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d id=%d\n", p, type, pp->id));
- return pp->id;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d: not found\n", p, type));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pointer_enter(struct soap *soap, const void *p, const struct soap_array *a, int n, int type, struct soap_plist **ppp)
-{ register int h;
- register struct soap_plist *pp = *ppp = (struct soap_plist*)SOAP_MALLOC(sizeof(struct soap_plist));
- if (!pp)
- return 0;
- if (a)
- h = soap_hash_ptr(a->__ptr);
- else
- h = soap_hash_ptr(p);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pointer enter location=%p array=%p size=%d dim=%d type=%d id=%lu\n", p, a?a->__ptr:NULL, a?a->__size:0, n, type, soap->idnum+1));
- pp->next = soap->pht[h];
- pp->type = type;
- pp->mark1 = 0;
- pp->mark2 = 0;
- pp->ptr = p;
- pp->array = a;
- soap->pht[h] = pp;
- pp->id = ++soap->idnum;
- return pp->id;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_pointer_lookup(struct soap *soap, const void *p, const struct soap_array *a, int n, int type, struct soap_plist **ppp)
-{ register struct soap_plist *pp;
- *ppp = NULL;
- if (!p || !a->__ptr)
- return 0;
- for (pp = soap->pht[soap_hash_ptr(a->__ptr)]; pp; pp = pp->next)
- { if (pp->type == type && pp->array && pp->array->__ptr == a->__ptr)
- { register int i;
- for (i = 0; i < n; i++)
- if (((const int*)&pp->array->__size)[i] != ((const int*)&a->__size)[i])
- break;
- if (i == n)
- { *ppp = pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d id=%d\n", a->__ptr, type, pp->id));
- return pp->id;
- }
- }
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d: not found\n", a->__ptr, type));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_begin_count(struct soap *soap)
-{ soap_clr_attr(soap);
- soap_set_local_namespaces(soap);
-#ifndef WITH_LEANER
- if ((soap->mode & SOAP_ENC_DIME) || (soap->omode & SOAP_ENC_DIME))
- soap->mode = soap->omode | SOAP_IO_LENGTH | SOAP_ENC_DIME;
- else
-#endif
- { soap->mode = soap->omode;
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE
- || (((soap->mode & SOAP_IO) == SOAP_IO_CHUNK || (soap->mode & SOAP_ENC_XML)) && !soap->fpreparesend))
- soap->mode &= ~SOAP_IO_LENGTH;
- else
- soap->mode |= SOAP_IO_LENGTH;
- }
- if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
- { if (!(soap->mode & SOAP_ENC_DIME))
- soap->mode &= ~SOAP_IO_LENGTH;
- if (soap->mode & SOAP_ENC_XML)
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH))
- soap->mode |= SOAP_XML_TREE;
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_MIME)
- soap_select_mime_boundary(soap);
- soap->dime.list = soap->dime.last; /* keep track of last DIME attachment */
-#endif
- soap->count = 0;
- soap->ns = 0;
- soap->null = 0;
- soap->position = 0;
- soap->mustUnderstand = 0;
- soap->encoding = 0;
- soap->part = SOAP_BEGIN;
- soap->idnum = 0;
- soap->dime.count = 0; /* count # of attachments */
- soap->dime.size = 0; /* accumulate total size of attachments */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
- if (soap->fprepareinit && (soap->mode & SOAP_IO) != SOAP_IO_STORE)
- soap->fprepareinit(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_begin_send(struct soap *soap)
-{ soap->error = SOAP_OK;
- soap_clr_attr(soap);
- soap_set_local_namespaces(soap);
- soap->mode = (soap->omode & ~SOAP_IO_LENGTH) | (soap->mode & SOAP_ENC_DIME);
- if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
- { if (soap->mode & SOAP_ENC_XML)
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket))
- { if (soap->count || (soap->mode & SOAP_ENC_XML))
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- soap_new_block(soap);
- if (!(soap->mode & SOAP_IO_KEEPALIVE))
- soap->keep_alive = 0;
- if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH))
- soap->mode |= SOAP_XML_TREE;
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_MIME)
- soap_select_mime_boundary(soap);
-#endif
-#ifdef WIN32
-#ifndef UNDER_CE
-#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket)) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
-#ifdef __BORLANDC__
- setmode((SOAP_SOCKET)soap->sendfd, O_BINARY);
-#else
- _setmode((SOAP_SOCKET)soap->sendfd, _O_BINARY);
-#endif
-#endif
-#endif
-#endif
- if (soap->mode & SOAP_IO)
- { soap->bufidx = 0;
- soap->buflen = 0;
- }
- soap->chunksize = 0;
- soap->ns = 0;
- soap->null = 0;
- soap->position = 0;
- soap->mustUnderstand = 0;
- soap->encoding = 0;
- soap->part = SOAP_BEGIN;
- soap->idnum = 0;
- soap->level = 0;
-#ifdef WITH_ZLIB
- soap->z_ratio_out = 1.0;
- if ((soap->mode & SOAP_ENC_ZLIB) && soap->zlib_state != SOAP_ZLIB_DEFLATE)
- {
-#ifdef WITH_GZIP
- memcpy(soap->z_buf, "\37\213\10\0\0\0\0\0\0\377", 10);
- soap->d_stream.next_out = (Byte*)soap->z_buf + 10;
- soap->d_stream.avail_out = SOAP_BUFLEN - 10;
- soap->z_crc = crc32(0L, NULL, 0);
- if (deflateInit2(&soap->d_stream, soap->z_level, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK)
-#else
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- if (deflateInit(&soap->d_stream, soap->z_level) != Z_OK)
-#endif
- return soap->error = SOAP_ZLIB_ERROR;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflate initialized\n"));
- soap->zlib_state = SOAP_ZLIB_DEFLATE;
- }
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin send phase (socket=%d mode=%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
- if (soap->fprepareinit && (soap->mode & SOAP_IO) == SOAP_IO_STORE)
- soap->fprepareinit(soap);
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_embedded(struct soap *soap, const void *p, int t)
-{ struct soap_plist *pp;
- if (soap_pointer_lookup(soap, p, t, &pp))
- { pp->mark1 = 1;
- pp->mark2 = 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded %p type=%d mark set to 1\n", p, t));
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_reference(struct soap *soap, const void *p, int t)
-{ struct soap_plist *pp;
- if (!p || (soap->mode & SOAP_XML_TREE))
- return 1;
- if (soap_pointer_lookup(soap, p, t, &pp))
- { if (pp->mark1 == 0)
- { pp->mark1 = 2;
- pp->mark2 = 2;
- }
- }
- else if (soap_pointer_enter(soap, p, NULL, 0, t, &pp))
- { pp->mark1 = 0;
- pp->mark2 = 0;
- }
- else
- return 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reference %p type=%d (%d %d)\n", p, t, (int)pp->mark1, (int)pp->mark2));
- return pp->mark1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_reference(struct soap *soap, const void *p, const struct soap_array *a, int n, int t)
-{ register int i;
- struct soap_plist *pp;
- if (!p)
- return 1;
- i = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
- if (i)
- { if (pp->mark1 == 0)
- { pp->mark1 = 2;
- pp->mark2 = 2;
- }
- }
- else if (!soap_pointer_enter(soap, p, a, n, t, &pp))
- return 1;
- else
- { pp->mark1 = 0;
- pp->mark2 = 0;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array reference %p ptr=%p dim=%d type=%d (%d %d)\n", p, a->__ptr, n, t, (int)pp->mark1, (int)pp->mark2));
- return pp->mark1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embedded_id(struct soap *soap, int id, const void *p, int t)
-{ struct soap_plist *pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id %p type=%d id=%d\n", p, t, id));
- if (soap->mode & SOAP_XML_TREE)
- return id;
- if (soap->version == 1 && soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH) && soap->part != SOAP_IN_HEADER)
- { if (id < 0)
- { id = soap_pointer_lookup(soap, p, t, &pp);
- if (id)
- { if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 2;
- else
- pp->mark2 = 2;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id multiref id=%d %p type=%d = (%d %d)\n", id, p, t, (int)pp->mark1, (int)pp->mark2));
- }
- return -1;
- }
- return id;
- }
- if (id < 0)
- id = soap_pointer_lookup(soap, p, t, &pp);
- else if (id && !soap_pointer_lookup(soap, p, t, &pp))
- return 0;
- if (id && pp)
- { if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 1;
- else
- pp->mark2 = 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id embedded ref id=%d %p type=%d = (%d %d)\n", id, p, t, (int)pp->mark1, (int)pp->mark2));
- }
- return id;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_embedded(struct soap *soap, struct soap_plist *pp)
-{ if (!pp)
- return 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Is embedded? %d %d\n", (int)pp->mark1, (int)pp->mark2));
- if (soap->version == 1 && soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH) && soap->part != SOAP_IN_HEADER)
- { if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 != 0;
- return pp->mark2 != 0;
- }
- if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 1;
- return pp->mark2 == 1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_single(struct soap *soap, struct soap_plist *pp)
-{ if (soap->part == SOAP_IN_HEADER)
- return 1;
- if (!pp)
- return 0;
- if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 0;
- return pp->mark2 == 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_embedded(struct soap *soap, struct soap_plist *pp)
-{ if (!pp)
- return;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 1;
- else
- pp->mark2 = 1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_dime(struct soap *soap, const char *tag, int id, const void *p, const struct soap_array *a, const char *aid, const char *atype, const char *aoptions, int n, const char *type, int t)
-{ struct soap_plist *pp;
- if (!p || !a->__ptr || (!aid && !atype))
- return soap_element_id(soap, tag, id, p, a, n, type, t);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Attachment tag='%s' id='%s' (%d) type='%s'\n", tag, aid?aid:"", id, atype?atype:""));
- if (id < 0)
- id = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
- if (!aid)
- { sprintf(soap->tmpbuf, soap->dime_id_format, id);
- aid = soap_strdup(soap, soap->tmpbuf);
- }
- if (soap_element_href(soap, tag, 0, "href", aid))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- { if (pp->mark1 != 3)
- { struct soap_multipart *content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, (char*)a->__ptr, a->__size);
- if (!content)
- return soap->error = SOAP_EOM;
- content->id = aid;
- content->type = atype;
- content->options = aoptions;
- pp->mark1 = 3;
- }
- }
- else
- pp->mark2 = 3;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_init_iht(struct soap *soap)
-{ register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing ID hashtable\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- soap->iht[i] = NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-soap_free_iht(struct soap *soap)
-{ register int i;
- register struct soap_ilist *ip, *p;
- register struct soap_flist *fp, *fq;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free ID hashtable\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = p)
- { for (fp = ip->flist; fp; fp = fq)
- { fq = fp->next;
- SOAP_FREE(fp);
- }
- p = ip->next;
- SOAP_FREE(ip);
- }
- soap->iht[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static struct soap_ilist *
-soap_hlookup(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- for (ip = soap->iht[soap_hash(id)]; ip; ip = ip->next)
- if (!strcmp(ip->id, id))
- return ip;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_ilist *
-SOAP_FMAC2
-soap_lookup(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- ip = soap_hlookup(soap, id);
-#ifndef WITH_LEANER
- if (!ip && *id != '#' && !strchr(id, ':')) /* try content id "cid:" with DIME attachments */
- { char cid[SOAP_TAGLEN];
- strcpy(cid, "cid:");
- strncat(cid + 4, id, sizeof(cid) - 5);
- cid[sizeof(cid) - 1] = '\0';
- ip = soap_hlookup(soap, cid);
- }
-#endif
- return ip;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_ilist *
-SOAP_FMAC2
-soap_enter(struct soap *soap, const char *id)
-{ register size_t h;
- register struct soap_ilist *ip;
- ip = (struct soap_ilist*)SOAP_MALLOC(sizeof(struct soap_ilist) + strlen(id));
- if (ip)
- { h = soap_hash(id);
- strcpy(ip->id, id);
- ip->next = soap->iht[h];
- soap->iht[h] = ip;
- return ip;
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_malloc(struct soap *soap, size_t n)
-{ register char *p;
- if (!n)
- return NULL;
- if (!soap)
- return SOAP_MALLOC(n);
- n += (-(long)n) & 7;
- if (!(p = (char*)SOAP_MALLOC(n + sizeof(void*) + sizeof(size_t))))
- { soap->error = SOAP_EOM;
- return NULL;
- }
- /* keep chain of alloced cells for later destruction */
- soap->alloced = 1;
- *(void**)(p + n) = soap->alist;
- *(size_t*)(p + n + sizeof(void*)) = n;
- soap->alist = p + n;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Malloc %u bytes at location %p\n", (unsigned int)n, p));
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_dealloc(struct soap *soap, void *p)
-{ if (!soap)
- return;
- if (p)
- { register char **q;
- for (q = (char**)&soap->alist; *q; q = *(char***)q)
- { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
- { *q = **(char***)q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Freed data at %p\n", p));
- SOAP_FREE(p);
- return;
- }
- }
- soap_delete(soap, p);
- }
- else
- { register char *q;
- while (soap->alist)
- { q = (char*)soap->alist;
- soap->alist = *(void**)q;
- q -= *(size_t*)(q + sizeof(void*));
- SOAP_FREE(q);
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Dealloc all data done\n"));
- }
- /* we must assume these were deallocated: */
- soap->action = NULL;
- soap->fault = NULL;
- soap->header = NULL;
- soap->authrealm = NULL;
-#ifndef WITH_LEANER
- soap_clr_mime(soap);
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_delete(struct soap *soap, void *p)
-{ register struct soap_clist **cp = &soap->clist;
- if (p)
- { while (*cp)
- { if (p == (*cp)->ptr)
- { register struct soap_clist *q = *cp;
- *cp = q->next;
- q->fdelete(q);
- SOAP_FREE(q);
- return;
- }
- cp = &(*cp)->next;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: address not in list\n", p));
- }
- else
- { while (*cp)
- { register struct soap_clist *q = *cp;
- *cp = q->next;
- if (q->ptr == (void*)soap->fault)
- soap->fault = NULL; /* this was deallocated */
- else if (q->ptr == (void*)soap->header)
- soap->header = NULL; /* this was deallocated */
- q->fdelete(q);
- SOAP_FREE(q);
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_clist *
-SOAP_FMAC2
-soap_link(struct soap *soap, void *p, int t, int n, void (*fdelete)(struct soap_clist*))
-{ register struct soap_clist *cp;
- if ((cp = (struct soap_clist*)SOAP_MALLOC(sizeof(struct soap_clist))))
- { cp->next = soap->clist;
- cp->type = t;
- cp->size = n;
- cp->ptr = p;
- cp->fdelete = fdelete;
- soap->clist = cp;
- }
- return cp;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_unlink(struct soap *soap, const void *p)
-{ register char **q;
- register struct soap_clist **cp;
- if (!soap || !p)
- return;
- for (q = (char**)&soap->alist; *q; q = *(char***)q)
- { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
- { *q = **(char***)q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked data %p\n", p));
- return;
- }
- }
- for (cp = &soap->clist; *cp; cp = &(*cp)->next)
- { if (p == (*cp)->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked class instance %p\n", p));
- q = (char**)*cp;
- *cp = (*cp)->next;
- SOAP_FREE(q);
- return;
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_lookup_type(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- if (id && *id)
- { ip = soap_lookup(soap, id);
- if (ip)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup id='%s' type=%d\n", id, ip->type));
- return ip->type;
- }
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "lookup type id='%s' NOT FOUND! Need to get it from xsi:type\n", id));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_lookup(struct soap *soap, const char *id, void **p, int t, size_t n, unsigned int k)
-{ struct soap_ilist *ip;
- void **q;
- if (!id || !*id)
- return p;
- soap->alloced = 0;
- if (!p)
- p = (void**)soap_malloc(soap, sizeof(void*));
- ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
- if (!ip)
- { ip = soap_enter(soap, id); /* new hash table entry for string id */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding first href='%s' type=%d %p (%u bytes)\n", id, t, p, (unsigned int)n));
- ip->type = t;
- ip->size = n;
- ip->link = p;
- ip->copy = NULL;
- ip->flist = NULL;
- ip->ptr = NULL;
- ip->level = k;
- *p = NULL;
- }
- else if (ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolved href='%s' type=%d location=%p (%u bytes)\n", id, t, ip->ptr, (unsigned int)n));
- if (ip->type != t)
- { strcpy(soap->id, id);
- soap->error = SOAP_HREF;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Type incompatibility: id type=%d href type=%d\n", ip->type, t));
- return NULL;
- }
- while (ip->level < k)
- { q = (void**)soap_malloc(soap, sizeof(void*));
- if (!q)
- return NULL;
- *p = (void*)q;
- p = q;
- k--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- *p = ip->ptr;
- }
- else if (ip->level > k)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving level %u pointers to href='%s'\n", ip->level, id));
- while (ip->level > k)
- { void *s, **r = &ip->link;
- q = (void**)ip->link;
- while (q)
- { *r = (void*)soap_malloc(soap, sizeof(void*));
- s = *q;
- *q = *r;
- r = (void**)*r;
- q = (void**)s;
- }
- *r = NULL;
- ip->size = n;
- ip->copy = NULL;
- ip->level = ip->level - 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- q = (void**)ip->link;
- ip->link = p;
- *p = (void*)q;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarded href='%s' type=%d location=%p (%u bytes)\n", id, t, p, (unsigned int)n));
- while (ip->level < k)
- { q = (void**)soap_malloc(soap, sizeof(void*));
- *p = q;
- p = q;
- k--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- q = (void**)ip->link;
- ip->link = p;
- *p = (void*)q;
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_forward(struct soap *soap, const char *href, void *p, int st, int tt, size_t n, unsigned int k, void (*fcopy)(struct soap*, int, int, void*, const void*, size_t))
-{ struct soap_ilist *ip;
- if (!p || !href || !*href)
- return p;
- ip = soap_lookup(soap, href); /* lookup pointer to hash table entry for string id */
- if (!ip)
- { ip = soap_enter(soap, href); /* new hash table entry for string id */
- ip->type = st;
- ip->size = n;
- ip->link = NULL;
- ip->copy = NULL;
- ip->ptr = NULL;
- ip->level = 0;
- ip->flist = NULL;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "New entry href='%s' type=%d size=%lu level=%d location=%p\n", href, st, (unsigned long)n, k, p));
- }
- else if (ip->type != st || (ip->level == k && ip->size != n))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Type incompatibility id='%s' expect type=%d size=%lu level=%u got type=%d size=%lu\n", href, ip->type, (unsigned long)ip->size, k, st, (unsigned long)n));
- strcpy(soap->id, href);
- soap->error = SOAP_HREF;
- return NULL;
- }
- if (fcopy || n < sizeof(void*) || *href != '#')
- { register struct soap_flist *fp = (struct soap_flist*)SOAP_MALLOC(sizeof(struct soap_flist));
- if (!fp)
- { soap->error = SOAP_EOM;
- return NULL;
- }
- fp->next = ip->flist;
- fp->type = tt;
- fp->ptr = p;
- fp->level = k;
- if (fcopy)
- fp->fcopy = fcopy;
- else
- fp->fcopy = soap_fcopy;
- ip->flist = fp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding type=%d (target type=%d) size=%lu location=%p level=%u href='%s'\n", st, tt, (unsigned long)n, p, k, href));
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding copying address %p for type=%d href='%s'\n", p, st, href));
- *(void**)p = ip->copy;
- ip->copy = p;
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_enter(struct soap *soap, const char *id, void *p, int t, size_t n, unsigned int k, const char *type, const char *arrayType, void *(*finstantiate)(struct soap*, int, const char*, const char*, size_t*))
-{ struct soap_ilist *ip;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Enter id='%s' type=%d loc=%p size=%lu level=%u\n", id, t, p, (unsigned long)n, k));
- soap->alloced = 0;
- if (!p)
- { if (finstantiate)
- p = finstantiate(soap, t, type, arrayType, &n);
- else
- p = soap_malloc(soap, n);
- if (p)
- soap->alloced = 1;
- }
- if (!id || !*id)
- return p;
- ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Lookup entry id='%s for location=%p'\n", id, p));
- if (!ip)
- { ip = soap_enter(soap, id); /* new hash table entry for string id */
- ip->type = t;
- ip->link = NULL;
- ip->copy = NULL;
- ip->flist = NULL;
- ip->size = n;
- ip->ptr = p;
- ip->level = k;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "New entry id='%s' type=%d size=%lu level=%u location=%p\n", id, t, (unsigned long)n, k, p));
- }
- else if ((ip->type != t || (ip->level == k && ip->size != n)) && (ip->copy || ip->flist))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Type incompatibility id='%s' expect type=%d size=%lu level=%u got type=%d size=%lu\n", id, ip->type, (unsigned long)ip->size, k, t, (unsigned long)n));
- strcpy(soap->id, id);
- soap->error = SOAP_HREF;
- return NULL;
- }
- else if (ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Multiply defined id='%s'\n", id));
- strcpy(soap->id, id);
- soap->error = SOAP_MULTI_ID;
- return NULL;
- }
- else
- { ip->size = n;
- ip->ptr = p;
- ip->level = k;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update entry id='%s' type=%d location=%p size=%lu level=%u\n", id, t, p, n, k));
- }
- return ip->ptr;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_fcopy(struct soap *soap, int st, int tt, void *p, const void *q, size_t n)
-{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Copying data type=%d (target type=%d) %p -> %p (%lu bytes)\n", st, tt, q, p, (unsigned long)n));
- memcpy(p, q, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_end_send(struct soap *soap)
-{
-#ifndef WITH_LEANER
- if (soap->dime.list)
- { /* SOAP body referenced attachments must appear first */
- soap->dime.last->next = soap->dime.first;
- soap->dime.first = soap->dime.list->next;
- soap->dime.list->next = NULL;
- soap->dime.last = soap->dime.list;
- }
- if (soap_putdime(soap) || soap_putmime(soap))
- return soap->error;
- soap->mime.list = NULL;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->dime.list = NULL;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End send\n"));
- if (soap->mode & SOAP_IO) /* need to flush the remaining data in buffer */
- { if (soap_flush(soap))
-#ifdef WITH_ZLIB
- { if (soap->mode & SOAP_ENC_ZLIB && soap->zlib_state == SOAP_ZLIB_DEFLATE)
- { soap->zlib_state = SOAP_ZLIB_NONE;
- deflateEnd(&soap->d_stream);
- }
- return soap->error;
- }
-#else
- return soap->error;
-#endif
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { int r;
- soap->d_stream.avail_in = 0;
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating remainder\n"));
- r = deflate(&soap->d_stream, Z_FINISH);
- if (soap->d_stream.avail_out != SOAP_BUFLEN)
- { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN - soap->d_stream.avail_out))
- { soap->zlib_state = SOAP_ZLIB_NONE;
- deflateEnd(&soap->d_stream);
- return soap->error;
- }
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- }
- } while (r == Z_OK);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_out = (float)soap->d_stream.total_out / (float)soap->d_stream.total_in;
- soap->mode &= ~SOAP_ENC_ZLIB;
- soap->zlib_state = SOAP_ZLIB_NONE;
- if (deflateEnd(&soap->d_stream) != Z_OK || r != Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to end deflate: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- return soap->error = SOAP_ZLIB_ERROR;
- }
-#ifdef WITH_GZIP
- soap->z_buf[0] = soap->z_crc & 0xFF;
- soap->z_buf[1] = (soap->z_crc >> 8) & 0xFF;
- soap->z_buf[2] = (soap->z_crc >> 16) & 0xFF;
- soap->z_buf[3] = (soap->z_crc >> 24) & 0xFF;
- soap->z_buf[4] = soap->d_stream.total_in & 0xFF;
- soap->z_buf[5] = (soap->d_stream.total_in >> 8) & 0xFF;
- soap->z_buf[6] = (soap->d_stream.total_in >> 16) & 0xFF;
- soap->z_buf[7] = (soap->d_stream.total_in >> 24) & 0xFF;
- if (soap_flush_raw(soap, soap->z_buf, 8))
- return soap->error;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip crc32=%lu\n", (unsigned long)soap->z_crc));
-#endif
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- { char *p;
- if (!(soap->mode & SOAP_ENC_XML))
- { soap->mode--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending buffered message of length %u\n", (unsigned int)soap->blist->size));
- if (soap->status >= SOAP_POST)
- soap->error = soap->fpost(soap, soap->endpoint, soap->host, soap->port, soap->path, soap->action, soap->blist->size);
- else if (soap->status != SOAP_STOP)
- soap->error = soap->fresponse(soap, soap->status, soap->blist->size);
- if (soap->error || soap_flush(soap))
- return soap->error;
- soap->mode++;
- }
- for (p = soap_first_block(soap); p; p = soap_next_block(soap))
- { DBGMSG(SENT, p, soap_block_size(soap));
- if ((soap->error = soap->fsend(soap, p, soap_block_size(soap))))
- { soap_end_block(soap);
- return soap->error;
- }
- }
- soap_end_block(soap);
- }
- else if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { DBGMSG(SENT, "\r\n0\r\n\r\n", 7);
- if ((soap->error = soap->fsend(soap, "\r\n0\r\n\r\n", 7)))
- return soap->error;
- }
- }
-#ifdef WITH_OPENSSL
- if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive)
- soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */
-#else
- if (soap_valid_socket(soap->socket) && !soap->keep_alive)
- soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send message ok\n"));
- soap->part = SOAP_END;
- soap->count = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_end_recv(struct soap *soap)
-{ soap->part = SOAP_END;
-#ifndef WITH_LEANER
- if ((soap->mode & SOAP_ENC_MIME) && soap_getmime(soap))
- return soap->error;
- soap->mime.list = soap->mime.first;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->dime.list = soap->dime.first;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
-#endif
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "End of receive message ok\n"));
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { soap->mode &= ~SOAP_ENC_ZLIB;
- memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
- soap->bufidx = (char*)soap->d_stream.next_in - soap->z_buf;
- soap->buflen = soap->z_buflen;
- soap->zlib_state = SOAP_ZLIB_NONE;
- if (inflateEnd(&soap->d_stream) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
-#ifdef WITH_GZIP
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- { soap_wchar c;
- short i;
- for (i = 0; i < 8; i++)
- { if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
- soap->z_buf[i] = (char)c;
- }
- if (soap->z_crc != ((uLong)(unsigned char)soap->z_buf[0] | ((uLong)(unsigned char)soap->z_buf[1] << 8) | ((uLong)(unsigned char)soap->z_buf[2] << 16) | ((uLong)(unsigned char)soap->z_buf[3] << 24)))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: crc check failed, message corrupted? (crc32=%lu)\n", (unsigned long)soap->z_crc));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- if (soap->d_stream.total_out != ((uLong)(unsigned char)soap->z_buf[4] | ((uLong)(unsigned char)soap->z_buf[5] << 8) | ((uLong)(unsigned char)soap->z_buf[6] << 16) | ((uLong)(unsigned char)soap->z_buf[7] << 24)))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: incorrect message length\n"));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- }
-#endif
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- while ((int)soap_getchar(soap) != EOF) /* advance to last chunk */
- ;
- if (soap->fdisconnect && (soap->error = soap->fdisconnect(soap)))
- return soap->error;
- return soap_resolve(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_free(struct soap *soap)
-{ register struct soap_nlist *np;
- register struct soap_attribute *tp;
- register struct Namespace *ns;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n"));
- while (soap->nlist)
- { np = soap->nlist->next;
- if (soap->nlist->ns)
- SOAP_FREE(soap->nlist->ns);
- SOAP_FREE(soap->nlist);
- soap->nlist = np;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free any remaining temp blocks\n"));
- while (soap->blist)
- soap_end_block(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attributes\n"));
- while (soap->attributes)
- { tp = soap->attributes->next;
- if (soap->attributes->value)
- SOAP_FREE(soap->attributes->value);
- SOAP_FREE(soap->attributes);
- soap->attributes = tp;
- }
-#ifdef WITH_FAST
- if (soap->labbuf)
- SOAP_FREE(soap->labbuf);
- soap->labbuf = NULL;
- soap->lablen = 0;
- soap->labidx = 0;
-#endif
- soap_free_pht(soap);
- soap_free_iht(soap);
- ns = soap->local_namespaces;
- if (ns)
- { for (; ns->id; ns++)
- { if (ns->out)
- { SOAP_FREE(ns->out);
- if (soap->encodingStyle == ns->out)
- soap->encodingStyle = SOAP_STR_EOS;
- ns->out = NULL;
- }
- if (soap->encodingStyle == ns->ns)
- soap->encodingStyle = SOAP_STR_EOS;
- }
- SOAP_FREE(soap->local_namespaces);
- soap->local_namespaces = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-static void
-soap_init_logs(struct soap *soap)
-{ int i;
- for (i = 0; i < SOAP_MAXLOGS; i++)
- { soap->logfile[i] = NULL;
- soap->fdebug[i] = NULL;
- }
- soap_set_recv_logfile(soap, "RECV.log");
- soap_set_sent_logfile(soap, "SENT.log");
- soap_set_test_logfile(soap, "TEST.log");
-}
-#endif
-
-/******************************************************************************/
-#if !defined(WITH_LEAN) || defined(SOAP_DEBUG)
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_open_logfile(struct soap *soap, int i)
-{ if (soap->logfile[i])
- soap->fdebug[i] = fopen(soap->logfile[i], i < 2 ? "ab" : "a");
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-static void
-soap_close_logfile(struct soap *soap, int i)
-{ if (soap->fdebug[i])
- { fclose(soap->fdebug[i]);
- soap->fdebug[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_close_logfiles(struct soap *soap)
-{ int i;
- for (i = 0; i < SOAP_MAXLOGS; i++)
- soap_close_logfile(soap, i);
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-static void
-soap_set_logfile(struct soap *soap, int i, const char *logfile)
-{ char *s = NULL;
- soap_close_logfile(soap, i);
- if (soap->logfile[i])
- SOAP_FREE((void*)soap->logfile[i]);
- if (logfile)
- if ((s = (char*)SOAP_MALLOC(strlen(logfile) + 1)))
- strcpy(s, logfile);
- soap->logfile[i] = s;
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_recv_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_RECV, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_sent_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_SENT, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_test_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_TEST, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_copy(struct soap *soap)
-{ return soap_copy_context((struct soap*)SOAP_MALLOC(sizeof(struct soap)), soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_copy_context(struct soap *copy, struct soap *soap)
-{ if (copy)
- { register struct soap_plugin *p;
- memcpy(copy, soap, sizeof(struct soap));
- copy->copy = 1;
- copy->user = NULL;
- copy->userid = NULL;
- copy->passwd = NULL;
- copy->nlist = NULL;
- copy->blist = NULL;
- copy->clist = NULL;
- copy->alist = NULL;
- copy->attributes = NULL;
- copy->local_namespaces = NULL;
- soap_set_local_namespaces(copy);
- soap_init_iht(copy);
- soap_init_pht(copy);
- copy->header = NULL;
- copy->fault = NULL;
- copy->action = NULL;
- *copy->host = '\0';
-#ifndef WITH_LEAN
-#ifdef WITH_COOKIES
- copy->cookies = soap_copy_cookies(soap);
-#else
- copy->cookies = NULL;
-#endif
-#endif
-#ifdef SOAP_DEBUG
- soap_init_logs(copy);
-#endif
- copy->plugins = NULL;
- for (p = soap->plugins; p; p = p->next)
- { register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(sizeof(struct soap_plugin));
- if (!q)
- return NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying plugin '%s'\n", p->id));
- *q = *p;
- if (p->fcopy && (soap->error = p->fcopy(soap, q, p)))
- { SOAP_FREE(q);
- return NULL;
- }
- q->next = copy->plugins;
- copy->plugins = q;
- }
- }
- else
- soap->error = SOAP_EOM;
- return copy;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init(struct soap *soap)
-{ soap->version = 0;
- soap_imode(soap, SOAP_IO_DEFAULT);
- soap_omode(soap, SOAP_IO_DEFAULT);
- soap->copy = 0;
- soap->plugins = NULL;
- soap->user = NULL;
- soap->userid = NULL;
- soap->passwd = NULL;
- soap->fpost = http_post;
- soap->fget = http_get;
- soap->fposthdr = http_post_header;
- soap->fresponse = http_response;
- soap->fparse = http_parse;
- soap->fparsehdr = http_parse_header;
- soap->fconnect = NULL;
- soap->fdisconnect = NULL;
-#ifndef MAC_CARBON
-#ifndef WITH_IPV6
- soap->fresolve = tcp_gethost;
-#else
- soap->fresolve = NULL;
-#endif
- soap->faccept = tcp_accept;
- soap->fopen = tcp_connect;
- soap->fclose = tcp_disconnect;
- soap->fclosesocket = tcp_closesocket;
- soap->fshutdownsocket = tcp_shutdownsocket;
- soap->fsend = fsend;
- soap->frecv = frecv;
- soap->fpoll = soap_poll;
-#else
- soap->fpoll = NULL;
-#endif
- soap->fprepareinit = NULL;
- soap->fpreparesend = NULL;
- soap->fpreparerecv = NULL;
- soap->fignore = NULL;
- soap->fserveloop = NULL;
- soap->fplugin = fplugin;
- soap->fdimereadopen = NULL;
- soap->fdimewriteopen = NULL;
- soap->fdimereadclose = NULL;
- soap->fdimewriteclose = NULL;
- soap->fdimeread = NULL;
- soap->fdimewrite = NULL;
- soap->float_format = "%.8g"; /* .8 preserves single FP precision as much as possible, but might not be very efficient */
- soap->double_format = "%.17lg"; /* .17 preserves double FP precision as much as possible, but might not be very efficient */
- soap->dime_id_format = "cid:id%d"; /* default DIME id format */
- soap->http_version = "1.1";
- soap->actor = NULL;
- soap->max_keep_alive = SOAP_MAXKEEPALIVE;
- soap->keep_alive = 0;
- soap->recv_timeout = 0;
- soap->send_timeout = 0;
- soap->connect_timeout = 0;
- soap->accept_timeout = 0;
- soap->socket_flags = 0;
- soap->connect_flags = 0;
- soap->bind_flags = 0;
- soap->accept_flags = 0;
- soap->ip = 0;
- soap->labbuf = NULL;
- soap->lablen = 0;
- soap->labidx = 0;
- soap->encodingStyle = SOAP_STR_EOS;
-#ifndef WITH_NONAMESPACES
- soap->namespaces = namespaces;
-#else
- soap->namespaces = NULL;
-#endif
- soap->local_namespaces = NULL;
- soap->nlist = NULL;
- soap->blist = NULL;
- soap->clist = NULL;
- soap->alist = NULL;
- soap->attributes = NULL;
- soap->header = NULL;
- soap->fault = NULL;
- soap->master = SOAP_INVALID_SOCKET;
- soap->socket = SOAP_INVALID_SOCKET;
- soap->os = NULL;
- soap->is = NULL;
- soap->dom = NULL;
- soap->dime.list = NULL;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
- soap->mime.list = NULL;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->mime.boundary = NULL;
- soap->mime.start = NULL;
-#ifndef UNDER_CE
- soap->recvfd = 0;
- soap->sendfd = 1;
-#else
- soap->recvfd = stdin;
- soap->sendfd = stdout;
-#endif
- soap->host[0] = '\0';
- soap->port = 0;
- soap->action = NULL;
- soap->proxy_host = NULL;
- soap->proxy_port = 8080;
- soap->proxy_userid = NULL;
- soap->proxy_passwd = NULL;
- soap->authrealm = NULL;
- soap->prolog = NULL;
-#ifdef WITH_OPENSSL
- soap->fsslauth = ssl_auth_init;
- soap->fsslverify = ssl_verify_callback;
- soap->bio = NULL;
- soap->ssl = NULL;
- soap->ctx = NULL;
- soap->require_server_auth = 0;
- soap->require_client_auth = 0;
- soap->rsa = 0;
- soap->keyfile = NULL;
- soap->password = NULL;
- soap->dhfile = NULL;
- soap->cafile = NULL;
- soap->capath = NULL;
- soap->randfile = NULL;
- soap->session = NULL;
-#endif
-#ifdef WITH_ZLIB
- soap->zlib_state = SOAP_ZLIB_NONE;
- soap->zlib_in = SOAP_ZLIB_NONE;
- soap->zlib_out = SOAP_ZLIB_NONE;
- soap->d_stream.zalloc = NULL;
- soap->d_stream.zfree = NULL;
- soap->d_stream.opaque = NULL;
- soap->z_level = 6;
-#endif
-#ifndef WITH_LEAN
- soap->cookies = NULL;
- soap->cookie_domain = NULL;
- soap->cookie_path = NULL;
- soap->cookie_max = 32;
-#endif
-#ifdef SOAP_DEBUG
- soap_init_logs(soap);
-#endif
-/* WR[ */
-#ifdef WMW_RPM_IO
- soap->rpmreqid = NULL;
-#endif /* WMW_RPM_IO */
-/* ]WR */
- soap_init_iht(soap);
- soap_init_pht(soap);
- soap_begin(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init1(struct soap *soap, int mode)
-{ soap_init2(soap, mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init2(struct soap *soap, int imode, int omode)
-{ soap_init(soap);
- soap_imode(soap, imode);
- soap_omode(soap, omode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_begin(struct soap *soap)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing\n"));
- if (!soap->keep_alive)
- { soap->buflen = 0;
- soap->bufidx = 0;
- }
- soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0);
- soap->null = 0;
- soap->position = 0;
- soap->encoding = 0;
- soap->mustUnderstand = 0;
- soap->mode = 0;
- soap->ns = 0;
- soap->part = SOAP_BEGIN;
- soap->alloced = 0;
- soap->count = 0;
- soap->length = 0;
- soap->cdata = 0;
- soap->error = SOAP_OK;
- soap->peeked = 0;
- soap->ahead = 0;
- soap->idnum = 0;
- soap->level = 0;
- soap->endpoint[0] = '\0';
- soap->dime.chunksize = 0;
- soap->dime.buflen = 0;
- soap_free(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_end(struct soap *soap)
-{ register struct soap_clist *cp;
- soap_free(soap);
- soap_dealloc(soap, NULL);
- while (soap->clist)
- { cp = soap->clist->next;
- SOAP_FREE(soap->clist);
- soap->clist = cp;
- }
- soap_closesock(soap);
-#ifdef SOAP_DEBUG
- soap_close_logfiles(soap);
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_namespaces(struct soap *soap, struct Namespace *p)
-{ struct Namespace *ns = soap->local_namespaces;
- struct soap_nlist *np, *nq, *nr;
- unsigned int level = soap->level;
- soap->namespaces = p;
- soap->local_namespaces = NULL;
- soap_set_local_namespaces(soap);
- /* reverse the list */
- np = soap->nlist;
- soap->nlist = NULL;
- if (np)
- { nq = np->next;
- np->next = NULL;
- while (nq)
- { nr = nq->next;
- nq->next = np;
- np = nq;
- nq = nr;
- }
- }
- while (np)
- { soap->level = np->level; /* preserve element nesting level */
- if (np->ns)
- { if (soap_push_namespace(soap, np->id, np->ns))
- return soap->error;
- }
- else if (np->index >= 0 && ns)
- { if (ns[np->index].out)
- { if (soap_push_namespace(soap, np->id, ns[np->index].out))
- return soap->error;
- }
- else if (soap_push_namespace(soap, np->id, ns[np->index].ns))
- return soap->error;
- }
- if (np->ns)
- SOAP_FREE(np->ns);
- nq = np;
- np = np->next;
- SOAP_FREE(nq);
- }
- if (ns)
- { int i;
- for (i = 0; ns[i].id; i++)
- { if (ns[i].out)
- { SOAP_FREE(ns[i].out);
- ns[i].out = NULL;
- }
- }
- SOAP_FREE(ns);
- }
- soap->level = level; /* restore level */
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-soap_set_local_namespaces(struct soap *soap)
-{ if (soap->namespaces && !soap->local_namespaces)
- { register const struct Namespace *ns1;
- register struct Namespace *ns2;
- register size_t n = 1;
- for (ns1 = soap->namespaces; ns1->id; ns1++)
- n++;
- if (n > 3)
- { n *= sizeof(struct Namespace);
- ns2 = (struct Namespace*)SOAP_MALLOC(n);
- if (ns2)
- { memcpy(ns2, soap->namespaces, n);
- ns2[0].id = "SOAP-ENV";
- ns2[1].id = "SOAP-ENC";
- ns2[2].id = "xsi";
- if (ns2[0].ns)
- { if (!strcmp(ns2[0].ns, soap_env1))
- soap->version = 1;
- else
- soap->version = 2;
- }
- soap->local_namespaces = ns2;
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element(struct soap *soap, const char *tag, int id, const char *type)
-{ struct Namespace *ns = soap->local_namespaces;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' id='%d' type='%s'\n", tag, id, type?type:""));
-/**/
-#ifdef WITH_DOM
- if (soap->mode & SOAP_XML_DOM)
- { register struct soap_dom_element *p, *e = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element));
- e->next = NULL;
- e->prnt = soap->dom;
- e->nstr = NULL;
- e->name = soap_strdup(soap, tag); /* check EOM? */
- e->data = NULL;
- e->type = 0;
- e->node = NULL;
- e->elts = NULL;
- e->atts = NULL;
- if (soap->dom)
- { p = soap->dom->elts;
- if (p)
- { while (p->next)
- p = p->next;
- p->next = e;
- }
- else
- soap->dom->elts = e;
- }
- soap->dom = e;
- }
- else
-#endif
-{
- soap->level++;
- if (!soap->ns && !(soap->mode & SOAP_XML_CANONICAL))
- if (soap_send(soap, soap->prolog ? soap->prolog : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"))
- return soap->error;
- if (soap_send_raw(soap, "<", 1)
- || soap_send(soap, tag))
- return soap->error;
-}
-/**/
- if (!soap->ns)
- { for (ns = soap->local_namespaces; ns && ns->id; ns++)
- { if (*ns->id && (ns->out || ns->ns))
- { sprintf(soap->tmpbuf, "xmlns:%s", ns->id);
- if (soap_attribute(soap, soap->tmpbuf, ns->out ? ns->out : ns->ns))
- return soap->error;
- }
- }
- soap->ns = 1;
- }
- if (id > 0)
- { sprintf(soap->tmpbuf, "_%d", id);
- if (soap_attribute(soap, "id", soap->tmpbuf))
- return soap->error;
- }
- if (type && *type)
- { if (soap_attribute(soap, "xsi:type", type))
- return soap->error;
- }
- if (soap->null && soap->position > 0)
- { int i;
- sprintf(soap->tmpbuf, "[%d", soap->positions[0]);
- for (i = 1; i < soap->position; i++)
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), ",%d", soap->positions[i]);
- strcat(soap->tmpbuf, "]");
- if (soap_attribute(soap, "SOAP-ENC:position", soap->tmpbuf))
- return soap->error;
- }
- if (soap->mustUnderstand)
- { if (soap->actor && *soap->actor)
- { if (soap_attribute(soap, soap->version == 2 ? "SOAP-ENV:role" : "SOAP-ENV:actor", soap->actor))
- return soap->error;
- }
- if (soap_attribute(soap, "SOAP-ENV:mustUnderstand", soap->version == 2 ? "true" : "1"))
- return soap->error;
- soap->mustUnderstand = 0;
- }
- if (soap->encoding)
- { if (soap->encodingStyle && soap->local_namespaces)
- { if (!*soap->encodingStyle)
- { if (soap->local_namespaces[1].out)
- soap->encodingStyle = soap->local_namespaces[1].out;
- else
- soap->encodingStyle = soap->local_namespaces[1].ns;
- }
- if (soap_attribute(soap, "SOAP-ENV:encodingStyle", soap->encodingStyle))
- return soap->error;
- }
- soap->encoding = 0;
- }
- soap->null = 0;
- soap->position = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_begin_out(struct soap *soap, const char *tag, int id, const char *type)
-{ if (*tag == '-')
- return SOAP_OK;
- if (soap_element(soap, tag, id, type))
- return soap->error;
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRRCHR
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_strrchr(const char *s, int t)
-{ register char *r = NULL;
- while (*s)
- if (*s++ == t)
- r = (char*)s - 1;
- return r;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRTOL
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_strtol(const char *s, char **t, int b)
-{ register long n = 0;
- register int c;
- while (*s > 0 && *s <= 32)
- s++;
- if (b == 10)
- { short neg = 0;
- if (*s == '-')
- { s++;
- neg = 1;
- }
- else if (*s == '+')
- s++;
- while ((c = *s) && c >= '0' && c <= '9')
- { if (n > 214748364)
- break;
- n *= 10;
- n += c - '0';
- s++;
- }
- if (neg)
- n = -n;
- }
- else /* b == 16 and value is always positive */
- { while ((c = *s))
- { if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- if (n > 0x07FFFFFF)
- break;
- n <<= 4;
- n += c;
- s++;
- }
- }
- if (t)
- *t = (char*)s;
- return n;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRTOUL
-SOAP_FMAC1
-unsigned long
-SOAP_FMAC2
-soap_strtoul(const char *s, char **t, int b)
-{ unsigned long n = 0;
- register int c;
- while (*s > 0 && *s <= 32)
- s++;
- if (b == 10)
- { if (*s == '+')
- s++;
- while ((c = *s) && c >= '0' && c <= '9')
- { if (n > 429496729)
- break;
- n *= 10;
- n += c - '0';
- s++;
- }
- }
- else /* b == 16 */
- { while ((c = *s))
- { if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- if (n > 0x0FFFFFFF)
- break;
- n <<= 4;
- n += c;
- s++;
- }
- }
- if (t)
- *t = (char*)s;
- return n;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_begin_out(struct soap *soap, const char *tag, int id, const char *type, const char *offset)
-{ if (soap_element(soap, tag, id, "SOAP-ENC:Array"))
- return soap->error;
- if (soap->version == 2)
- { const char *s;
- s = soap_strrchr(type, '[');
- if ((size_t)(s - type) < sizeof(soap->tmpbuf))
- { strncpy(soap->tmpbuf, type, s - type);
- soap->tmpbuf[s - type] = '\0';
- if (type && *type && (soap_attribute(soap, "SOAP-ENC:itemType", soap->tmpbuf)))
- return soap->error;
- if (s && (soap_attribute(soap, "SOAP-ENC:arraySize", s + 1)))
- return soap->error;
- }
- }
- else
- { if (offset && (soap_attribute(soap, "SOAP-ENC:offset", offset)))
- return soap->error;
- if (type && *type && (soap_attribute(soap, "SOAP-ENC:arrayType", type)))
- return soap->error;
- }
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_start_end_out(struct soap *soap, const char *tag)
-{ register struct soap_attribute *tp;
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible)
- { register struct soap_dom_attribute *a = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
- a->next = soap->dom->atts;
- a->nstr = NULL;
- a->name = soap_strdup(soap, tp->name); /* check EOM */
- a->data = soap_strdup(soap, tp->value); /* check EOM */
- a->wide = NULL;
- soap->dom->atts = a;
- tp->visible = 0;
- }
- }
- return SOAP_OK;
- }
-#endif
-/**/
- for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible)
- { if (soap_send2(soap, " ", tp->name))
- return soap->error;
- if (tp->visible == 2 && tp->value)
- if (soap_send_raw(soap, "=\"", 2)
- || soap_string_out(soap, tp->value, 1)
- || soap_send_raw(soap, "\"", 1))
- return soap->error;
- tp->visible = 0;
- }
- }
- if (tag)
- { soap->level--;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { if (soap_send_raw(soap, ">", 1)
- || soap_element_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
- }
-#endif
- return soap_send_raw(soap, "/>", 2);
- }
- return soap_send_raw(soap, ">", 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_end_out(struct soap *soap, const char *tag)
-{ if (*tag == '-')
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element ending tag='%s'\n", tag));
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { if (soap->dom->prnt)
- soap->dom = soap->dom->prnt;
- return SOAP_OK;
- }
-#endif
-/**/
- soap->level--;
- if (soap_send_raw(soap, "</", 2)
- || soap_send(soap, tag))
- return soap->error;
- return soap_send_raw(soap, ">", 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_ref(struct soap *soap, const char *tag, int id, int href)
-{ register int n = 0;
- if (soap->version == 2)
- n = 1;
- sprintf(soap->href, "#_%d", href);
- return soap_element_href(soap, tag, id, "href" + n, soap->href + n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_href(struct soap *soap, const char *tag, int id, const char *ref, const char *val)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element '%s' reference %s='%s'\n", tag, ref, val));
- if (soap_element(soap, tag, id, NULL)
- || soap_attribute(soap, ref, val)
- || soap_element_start_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_null(struct soap *soap, const char *tag, int id, const char *type)
-{ struct soap_attribute *tp;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (tp->visible)
- break;
- if (tp || (soap->version == 2 && soap->position > 0) || id > 0 || (soap->mode & SOAP_XML_NIL))
- { if (soap_element(soap, tag, id, type))
- return soap->error;
- if (soap->part != SOAP_IN_HEADER && soap->encodingStyle)
- if (soap_attribute(soap, "xsi:nil", "true"))
- return soap->error;
- return soap_element_start_end_out(soap, tag);
- }
- soap->null = 1;
- soap->position = 0;
- soap->mustUnderstand = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_id(struct soap *soap, const char *tag, int id, const void *p, const struct soap_array *a, int n, const char *type, int t)
-{ struct soap_plist *pp;
- if (!p)
- { soap_element_null(soap, tag, id, type);
- return -1;
- }
- if (soap->mode & SOAP_XML_TREE)
- return 0;
- if (id < 0)
- { if (a)
- id = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
- else
- id = soap_pointer_lookup(soap, p, t, &pp);
- if (id)
- { if (soap_is_embedded(soap, pp))
- { soap_element_ref(soap, tag, 0, id);
- return -1;
- }
- if (soap_is_single(soap, pp))
- return 0;
- soap_set_embedded(soap, pp);
- }
- }
- return id;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_result(struct soap *soap, const char *tag)
-{ if (soap->version == 2 && soap->encodingStyle)
- if (soap_element(soap, "SOAP-RPC:result", 0, NULL)
- || soap_attribute(soap, "xmlns:SOAP-RPC", soap_rpc)
- || soap_element_start_end_out(soap, NULL)
- || soap_string_out(soap, tag, 0)
- || soap_element_end_out(soap, "SOAP-RPC:result"))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_attribute(struct soap *soap, const char *name, const char *value)
-{
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { register struct soap_dom_attribute *a = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
- a->next = soap->dom->atts;
- a->nstr = NULL;
- a->name = soap_strdup(soap, name); /* check EOM */
- a->data = soap_strdup(soap, value); /* check EOM */
- a->wide = NULL;
- soap->dom->atts = a;
- return SOAP_OK;
- }
-#endif
-/**/
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { if (soap_set_attr(soap, name, value))
- return soap->error;
- }
- else
-#endif
- { if (soap_send2(soap, " ", name))
- return soap->error;
- if (value)
- if (soap_send_raw(soap, "=\"", 2)
- || soap_string_out(soap, value, 1)
- || soap_send_raw(soap, "\"", 1))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_begin_in(struct soap *soap, const char *tag, int nillable)
-{ if (!soap_peek_element(soap))
- { if (soap->other)
- return soap->error = SOAP_TAG_MISMATCH;
- if (tag && *tag == '-')
- return SOAP_OK;
- if (!(soap->error = soap_match_tag(soap, soap->tag, tag)))
- { soap->peeked = 0;
- if (soap->body)
- soap->level++;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:"" ));
- if (!nillable && soap->null && (soap->mode & SOAP_XML_STRICT))
- return soap->error = SOAP_NULL;
- }
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_end_in(struct soap *soap, const char *tag)
-{ register soap_wchar c;
- register char *s;
- register const char *t;
- if (tag && *tag == '-')
- return SOAP_OK;
- soap->level--;
- soap_pop_namespace(soap);
- if (soap->peeked)
- { if (*soap->tag == '\0')
- { soap->peeked = 0;
- if (soap->error == SOAP_NO_TAG || soap->error == SOAP_TAG_END)
- soap->error = SOAP_OK;
- }
- else
- return soap->error = SOAP_TAG_END;
- }
- else
- { while (((c = soap_get(soap)) != SOAP_TT))
- { if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (c == SOAP_LT)
- return soap->error = SOAP_TAG_END;
- }
- }
- s = soap->tag;
- do c = soap_get(soap);
- while (soap_blank(c));
- do
- { *s++ = (char)c;
- c = soap_get(soap);
- } while (soap_notblank(c));
- *s = '\0';
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- while (soap_blank(c))
- c = soap_get(soap);
- if (c != SOAP_GT)
- return soap->error = SOAP_SYNTAX_ERROR;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:""));
- if (!tag)
- return SOAP_OK;
- if ((s = strchr(soap->tag, ':')))
- s++;
- else
- s = soap->tag;
- if ((t = strchr(tag, ':')))
- t++;
- else
- t = tag;
- if (!SOAP_STRCMP(s, t))
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element tag name does not match\n"));
- return soap->error = SOAP_SYNTAX_ERROR;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char *
-SOAP_FMAC2
-soap_attr_value(struct soap *soap, const char *name, int flag)
-{ register struct soap_attribute *tp;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!soap_match_tag(soap, tp->name, name))
- break;
- if (tp && tp->visible == 2)
- { if (flag == 2 && (soap->mode & SOAP_XML_STRICT))
- soap->error = SOAP_PROHIBITED;
- else
- return tp->value;
- }
- else if (flag == 1 && (soap->mode & SOAP_XML_STRICT))
- soap->error = SOAP_REQUIRED;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_attr(struct soap *soap, const char *name, const char *value)
-{ register struct soap_attribute *tp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set attribute %s='%s'\n", name, value?value:""));
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!strcmp(tp->name, name))
- break;
- if (!tp)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute %s\n", name));
- if (!(tp = (struct soap_attribute*)SOAP_MALLOC(sizeof(struct soap_attribute) + strlen(name))))
- return soap->error = SOAP_EOM;
- tp->ns = NULL;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { struct soap_attribute **tpp = &soap->attributes;
- const char *s = strchr(name, ':');
- if (!strncmp(name, "xmlns", 5))
- { for (; *tpp; tpp = &(*tpp)->next)
- if (strncmp((*tpp)->name, "xmlns", 5) || strcmp((*tpp)->name + 5, name + 5) > 0)
- break;
- }
- else if (!s)
- { for (; *tpp; tpp = &(*tpp)->next)
- if (strncmp((*tpp)->name, "xmlns", 5) && ((*tpp)->ns || strcmp((*tpp)->name, name) > 0))
- break;
- }
- else
- { int k;
- for (; *tpp; tpp = &(*tpp)->next)
- { if (!strncmp((*tpp)->name, "xmlns:", 6) && !strncmp((*tpp)->name + 6, name, s - name) && !(*tpp)->name[6 + s - name])
- { if (!tp->ns)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Canonicalization: prefix %s=%p(%s)\n", name, (*tpp)->ns, (*tpp)->ns));
- tp->ns = (*tpp)->ns;
- }
- }
- else if (strncmp((*tpp)->name, "xmlns", 5) && (*tpp)->ns && tp->ns && ((k = strcmp((*tpp)->ns, tp->ns)) > 0 || (!k && strcmp((*tpp)->name, name) > 0)))
- break;
- }
- }
- tp->next = *tpp;
- *tpp = tp;
- }
- else
-#endif
- { tp->next = soap->attributes;
- soap->attributes = tp;
- }
- strcpy(tp->name, name);
- tp->value = NULL;
- }
- else if (value && tp->value && tp->size <= strlen(value))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attribute value of %s (free %p)\n", name, tp->value));
- SOAP_FREE(tp->value);
- tp->value = NULL;
- tp->ns = NULL;
- }
- if (value)
- { if (!tp->value)
- { tp->size = strlen(value) + 1;
- if (!(tp->value = (char*)SOAP_MALLOC(tp->size)))
- return soap->error = SOAP_EOM;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute value of %s (%p)\n", tp->name, tp->value));
- }
- strcpy(tp->value, value);
- if (!strncmp(tp->name, "xmlns:", 6))
- tp->ns = tp->value;
- tp->visible = 2;
- }
- else
- tp->visible = 1;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_attr(struct soap *soap)
-{ register struct soap_attribute *tp;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { while (soap->attributes)
- { tp = soap->attributes->next;
- SOAP_FREE(soap->attributes->value);
- SOAP_FREE(soap->attributes);
- soap->attributes = tp;
- }
- }
- else
-#endif
- { for (tp = soap->attributes; tp; tp = tp->next)
- tp->visible = 0;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static int
-soap_getattrval(struct soap *soap, char *s, size_t n, soap_wchar d)
-{ size_t i;
- soap_wchar c;
- for (i = 0; i < n; i++)
- { c = soap_getutf8(soap);
- switch (c)
- {
- case SOAP_TT:
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case SOAP_LT:
- *s++ = '<';
- break;
- case SOAP_GT:
- if (d == ' ')
- { soap_unget(soap, c);
- *s = '\0';
- return SOAP_OK;
- }
- *s++ = '>';
- break;
- case SOAP_QT:
- if (c == d)
- { *s = '\0';
- return SOAP_OK;
- }
- *s++ = '"';
- break;
- case SOAP_AP:
- if (c == d)
- { *s = '\0';
- return SOAP_OK;
- }
- *s++ = '\'';
- break;
- case '\t':
- case '\n':
- case '\r':
- case ' ':
- case '/':
- if (d == ' ')
- { soap_unget(soap, c);
- *s = '\0';
- return SOAP_OK;
- }
- default:
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- }
- return soap->error = SOAP_EOM;
-}
-#endif
-
-/******************************************************************************/
-#ifdef WITH_FAST
-#ifndef PALM_2
-static int
-soap_append_lab(struct soap *soap, const char *s, size_t n)
-{ if (soap->labidx + n >= soap->lablen)
- { register char *t = soap->labbuf;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enlarging look-aside buffer to append data, old size=%lu", (unsigned long)soap->lablen));
- if (soap->lablen == 0)
- soap->lablen = SOAP_LABLEN;
- while (soap->labidx + n >= soap->lablen)
- soap->lablen <<= 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, ", new size=%lu\n", (unsigned long)soap->lablen));
- soap->labbuf = (char*)SOAP_MALLOC(soap->lablen);
- if (!soap->labbuf)
- { if (t)
- free(t);
- return soap->error = SOAP_EOM;
- }
- if (t && soap->labidx)
- { memcpy(soap->labbuf, t, soap->labidx);
- free(t);
- }
- }
- if (s)
- { memcpy(soap->labbuf + soap->labidx, s, n);
- soap->labidx += n;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_peek_element(struct soap *soap)
-{ register struct soap_attribute *tp;
- const char *t;
- register char *s;
- register soap_wchar c;
- register int i;
- if (soap->error == SOAP_NO_TAG || soap->error == SOAP_TAG_END || soap->error == SOAP_TAG_MISMATCH)
- soap->error = SOAP_OK; /* retry */
- if (soap->peeked)
- { if (*soap->tag == '\0')
- return soap->error = SOAP_NO_TAG;
- return SOAP_OK;
- }
- soap->peeked = 1;
- for (;;)
- { while (((c = soap_getutf8(soap)) != SOAP_LT) && c != SOAP_TT)
- { if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- }
- if (c == SOAP_TT)
- { *soap->tag = '\0';
- return soap->error = SOAP_NO_TAG; /* ending tag found */
- }
- s = soap->tag;
- do c = soap_get(soap);
- while (soap_blank(c));
- i = sizeof(soap->tag);
- while (c != '/' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- while (soap_blank(c))
- c = soap_get(soap);
- *s = '\0';
- if (*soap->tag != '?')
- break;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI <%s?>\n", soap->tag));
- while ((int)c != EOF && c != SOAP_GT && c != '?')
- { s = soap->tmpbuf;
- i = sizeof(soap->tmpbuf) - 2;
- while (c != '=' && c != SOAP_GT && c != '?' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- while (soap_blank(c))
- c = soap_get(soap);
- if (c == '=')
- { *s++ = '=';
- do c = soap_get(soap);
- while (soap_blank(c));
- if (c != SOAP_QT && c != SOAP_AP)
- { soap_unget(soap, c);
- c = ' '; /* blank delimiter */
- }
- if (soap_getattrval(soap, s, i, c) == SOAP_EOM)
- while (soap_getattrval(soap, soap->tmpbuf, sizeof(soap->tmpbuf), c) == SOAP_EOM)
- ;
- else if (!strcmp(soap->tag, "?xml") && (!soap_tag_cmp(soap->tmpbuf, "encoding=iso-8859-1") || !soap_tag_cmp(soap->tmpbuf, "encoding=latin1")))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML latin1 encoding\n"));
- soap->mode |= SOAP_ENC_LATIN;
- }
- }
- do c = soap_get(soap);
- while (soap_blank(c));
- }
- }
- soap->id[0] = '\0';
- soap->href[0] = '\0';
- soap->type[0] = '\0';
- soap->arrayType[0] = '\0';
- soap->arraySize[0] = '\0';
- soap->arrayOffset[0] = '\0';
- soap->other = 0;
- soap->root = -1;
- soap->position = 0;
- soap->null = 0;
- soap->mustUnderstand = 0;
- soap_clr_attr(soap);
- while ((int)c != EOF && c != SOAP_GT && c != '/')
- { s = soap->tmpbuf;
- i = sizeof(soap->tmpbuf);
- while (c != '=' && c != '/' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- *s = '\0';
- if (i == sizeof(soap->tmpbuf))
- return soap->error = SOAP_SYNTAX_ERROR;
- if (!strncmp(soap->tmpbuf, "xmlns:", 6))
- { soap->tmpbuf[5] = '\0';
- t = soap->tmpbuf + 6;
- }
- else if (!strcmp(soap->tmpbuf, "xmlns"))
- t = SOAP_STR_EOS;
- else
- t = NULL;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!SOAP_STRCMP(tp->name, soap->tmpbuf))
- break;
- if (!tp)
- { tp = (struct soap_attribute*)SOAP_MALLOC(sizeof(struct soap_attribute) + strlen(soap->tmpbuf));
- if (!tp)
- return soap->error = SOAP_EOM;
- strcpy(tp->name, soap->tmpbuf);
- tp->value = NULL;
- tp->size = 0;
- tp->next = soap->attributes;
- soap->attributes = tp;
- }
- while (soap_blank(c))
- c = soap_get(soap);
- if (c == '=')
- { do c = soap_get(soap);
- while (soap_blank(c));
- if (c != SOAP_QT && c != SOAP_AP)
- { soap_unget(soap, c);
- c = ' '; /* blank delimiter */
- }
- if (soap_getattrval(soap, tp->value, tp->size, c))
- {
-#ifdef WITH_FAST
- if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- soap->labidx = 0;
- if (soap_append_lab(soap, tp->value, tp->size))
- return soap->error;
- SOAP_FREE(tp->value);
- for (;;)
- { if (soap_getattrval(soap, soap->labbuf + soap->labidx, soap->lablen - soap->labidx, c))
- { if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- soap->labidx = soap->lablen;
- if (soap_append_lab(soap, NULL, 0))
- return soap->error;
- }
- else
- break;
- }
- tp->size = soap->lablen;
- if (!(tp->value = (char*)SOAP_MALLOC(tp->size)))
- return soap->error = SOAP_EOM;
- memcpy(tp->value, soap->labbuf, soap->lablen);
-#else
- size_t n;
- if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- if (soap_new_block(soap))
- return soap->error;
- for (;;)
- { if (!(s = (char*)soap_push_block(soap, SOAP_BLKLEN)))
- return soap->error;
- if (soap_getattrval(soap, s, SOAP_BLKLEN, c))
- { if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- }
- else
- break;
- }
- n = tp->size + soap->blist->size;
- if (!(s = (char*)SOAP_MALLOC(n)))
- return soap->error = SOAP_EOM;
- if (tp->value)
- { memcpy(s, tp->value, tp->size);
- SOAP_FREE(tp->value);
- }
- soap_save_block(soap, s + tp->size, 0);
- tp->value = s;
- tp->size = n;
-#endif
- }
- do c = soap_get(soap);
- while (soap_blank(c));
- tp->visible = 2; /* seen this attribute w/ value */
- }
- else
- tp->visible = 1; /* seen this attribute w/o value */
- if (t && tp->value)
- { if (soap_push_namespace(soap, t, tp->value))
- return soap->error;
- tp->visible = 0;
- }
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible && tp->value)
- { if (!strcmp(tp->name, "id"))
- { *soap->id = '#';
- strncpy(soap->id + 1, tp->value, sizeof(soap->id) - 2);
- soap->id[sizeof(soap->id)-1] = '\0';
- }
- else if (!strcmp(tp->name, "href"))
- { strncpy(soap->href, tp->value, sizeof(soap->href) - 1);
- soap->href[sizeof(soap->href)-1] = '\0';
- }
- else if ((soap->version == 2 || (soap->mode & SOAP_XML_GRAPH)) && !strcmp(tp->name, "ref"))
- { *soap->href = '#';
- strncpy(soap->href + 1, tp->value, sizeof(soap->href) - 2);
- soap->href[sizeof(soap->href)-1] = '\0';
- }
- else if (!soap_match_tag(soap, tp->name, "xsi:type"))
- { strncpy(soap->type, tp->value, sizeof(soap->type) - 1);
- soap->type[sizeof(soap->type)-1] = '\0';
- }
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:arrayType"))
- { s = soap_strrchr(tp->value, '[');
- if (s && (size_t)(s - tp->value) < sizeof(soap->arrayType))
- { strncpy(soap->arrayType, tp->value, s - tp->value);
- soap->arrayType[s - tp->value] = '\0';
- strncpy(soap->arraySize, s, sizeof(soap->arraySize) - 1);
- }
- else
- strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1);
- soap->arraySize[sizeof(soap->arrayType)-1] = '\0';
- soap->arrayType[sizeof(soap->arrayType)-1] = '\0';
- }
- else if (soap->version == 2 && !soap_match_tag(soap, tp->name, "SOAP-ENC:itemType"))
- strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1);
- else if (soap->version == 2 && !soap_match_tag(soap, tp->name, "SOAP-ENC:arraySize"))
- strncpy(soap->arraySize, tp->value, sizeof(soap->arraySize) - 1);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:offset"))
- strncpy(soap->arrayOffset, tp->value, sizeof(soap->arrayOffset));
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:position"))
- soap->position = soap_getposition(tp->value, soap->positions);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:root"))
- soap->root = ((!strcmp(tp->value, "1") || !strcmp(tp->value, "true")));
- else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:actor")
- || !soap_match_tag(soap, tp->name, "SOAP-ENV:role"))
- { if ((!soap->actor || strcmp(soap->actor, tp->value))
- && strcmp(tp->value, "http://schemas.xmlsoap.org/soap/actor/next")
- && strcmp(tp->value, "http://www.w3.org/2003/05/soap-envelope/role/next"))
- soap->other = 1;
- }
- else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:mustUnderstand")
- && (!strcmp(tp->value, "1") || !strcmp(tp->value, "true")))
- soap->mustUnderstand = 1;
- else if ((!soap_match_tag(soap, tp->name, "xsi:null")
- || !soap_match_tag(soap, tp->name, "xsi:nil"))
- && (!strcmp(tp->value, "1")
- || !strcmp(tp->value, "true")))
- soap->null = 1;
- }
- }
- if (!(soap->body = (c != '/')))
- do c = soap_get(soap);
- while (soap_blank(c));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_retry(struct soap *soap)
-{ soap->peeked = 1;
- soap->error = SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_revert(struct soap *soap)
-{ if (!soap->peeked)
- { soap->peeked = 1;
- if (soap->body)
- soap->level--;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reverting last element (level=%u)\n", soap->level));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_string_out(struct soap *soap, const char *s, int flag)
-{ register const char *t;
- register soap_wchar c;
- register soap_wchar mask = 0x80000000;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->data = soap_strdup(soap, s); /* check EOM */
- return SOAP_OK;
- }
-#endif
- if (soap->mode & SOAP_C_UTFSTRING)
- mask = 0;
- t = s;
- while ((c = *t++))
- { switch (c)
- {
- case 9:
- if (flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "	", 5))
- return soap->error;
- s = t;
- }
- break;
- case 10:
- if (flag || !(soap->mode & SOAP_XML_CANONICAL))
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
- return soap->error;
- s = t;
- }
- break;
- case 13:
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
- return soap->error;
- s = t;
- break;
- case '&':
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "&", 5))
- return soap->error;
- s = t;
- break;
- case '<':
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "<", 4))
- return soap->error;
- s = t;
- break;
- case '>':
- if (!flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, ">", 4))
- return soap->error;
- s = t;
- }
- break;
- case '"':
- if (flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, """, 6))
- return soap->error;
- s = t;
- }
- break;
- default:
-#ifdef HAVE_MBTOWC
- if (soap->mode & SOAP_C_MBSTRING)
- { wchar_t wc;
- register int m = mbtowc(&wc, t - 1, MB_CUR_MAX);
- if (m > 0 && wc != c)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, wc))
- return soap->error;
- s = t + m - 1;
- continue;
- }
- }
-#endif
- if (c & mask)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, (unsigned char)c))
- return soap->error;
- s = t;
- }
- }
- }
- return soap_send_raw(soap, s, t - s - 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
-{ register char *s;
- char *t = NULL;
- register size_t i;
- register long l = 0;
- register int n = 0;
- register int m = 0;
- register soap_wchar c;
-#ifdef HAVE_WCTOMB
- char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8];
-#else
- char buf[8];
-#endif
-#ifdef WITH_CDATA
- if (!flag)
- { register int state = 0;
-#ifdef WITH_FAST
- soap->labidx = 0; /* use look-aside buffer */
-#else
- if (soap_new_block(soap))
- return NULL;
-#endif
- for (;;)
- {
-#ifdef WITH_FAST
- register size_t k;
- if (soap_append_lab(soap, NULL, 0)) /* allocate more space in look-aside buffer if necessary */
- return NULL;
- s = soap->labbuf + soap->labidx; /* space to populate */
- k = soap->lablen - soap->labidx; /* number of bytes available */
- soap->labidx = soap->lablen; /* claim this space */
-#else
- register size_t k = SOAP_BLKLEN;
- if (!(s = (char*)soap_push_block(soap, k)))
- return NULL;
-#endif
- for (i = 0; i < k; i++)
- { if (m > 0)
- { *s++ = *t++; /* copy multibyte characters */
- m--;
- continue;
- }
- c = soap_getchar(soap);
- if ((int)c == EOF)
- goto end;
- if (c >= 0x80 && !(soap->mode & SOAP_ENC_LATIN))
- { soap_unget(soap, c);
- c = soap_getutf8(soap);
- if (soap->mode & SOAP_C_UTFSTRING)
- { if ((c & 0x80000000) && c >= -0x7FFFFF80 && c < SOAP_AP)
- { c &= 0x7FFFFFFF;
- t = buf;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- m = (int)(t - buf) - 1;
- t = buf;
- *s++ = *t++;
- continue;
- }
- }
- }
- switch (state)
- { case 1:
- if (c == ']')
- state = 4;
- *s++ = c;
- continue;
- case 2:
- if (c == '-')
- state = 6;
- *s++ = c;
- continue;
- case 3:
- if (c == '?')
- state = 8;
- *s++ = c;
- continue;
- /* CDATA */
- case 4:
- if (c == ']')
- state = 5;
- else
- state = 1;
- *s++ = c;
- continue;
- case 5:
- if (c == '>')
- state = 0;
- else
- state = 1;
- *s++ = c;
- continue;
- /* comment */
- case 6:
- if (c == '-')
- state = 7;
- else
- state = 2;
- *s++ = c;
- continue;
- case 7:
- if (c == '>')
- state = 0;
- else
- state = 2;
- *s++ = c;
- continue;
- /* PI */
- case 8:
- if (c == '>')
- state = 0;
- else
- state = 3;
- *s++ = c;
- continue;
- }
- switch (c)
- {
- case '/':
- if (n > 0)
- { c = soap_get1(soap);
- if (c == '>')
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- c = soap_get1(soap);
- if (c == '/')
- { if (n == 0)
- { c = SOAP_TT;
- goto end;
- }
- n--;
- }
- else if (c == '!')
- { c = soap_get1(soap);
- if (c == '[')
- { do c = soap_get1(soap);
- while ((int)c != EOF && c != '[');
- if ((int)c == EOF)
- goto end;
- t = (char*)"![CDATA[";
- m = 8;
- state = 1;
- }
- else if (c == '-')
- { if ((c = soap_get1(soap)) == '-')
- state = 2;
- t = (char*)"!-";
- m = 2;
- soap_unget(soap, c);
- }
- else
- { t = (char*)"!";
- m = 1;
- soap_unget(soap, c);
- }
- *s++ = '<';
- break;
- }
- else if (c == '?')
- state = 3;
- else
- n++;
- soap_unget(soap, c);
- *s++ = '<';
- break;
- case '>':
- *s++ = '>';
- break;
- case '"':
- *s++ = '"';
- break;
- default:
-#ifdef HAVE_WCTOMB
- if (soap->mode & SOAP_C_MBSTRING)
- { m = wctomb(buf, c & 0x7FFFFFFF);
- if (m >= 1)
- { t = buf;
- *s++ = *t++;
- m--;
- }
- else
- *s++ = SOAP_UNKNOWN_CHAR;
- }
- else
-#endif
- *s++ = (char)(c & 0xFF);
- }
- l++;
- if ((soap->mode & SOAP_XML_STRICT) && maxlen >= 0 && l > maxlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too long: maxlen=%ld\n", maxlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- }
- }
- }
-#endif
-#ifdef WITH_FAST
- soap->labidx = 0; /* use look-aside buffer */
-#else
- if (soap_new_block(soap))
- return NULL;
-#endif
- for (;;)
- {
-#ifdef WITH_FAST
- register size_t k;
- if (soap_append_lab(soap, NULL, 0)) /* allocate more space in look-aside buffer if necessary */
- return NULL;
- s = soap->labbuf + soap->labidx; /* space to populate */
- k = soap->lablen - soap->labidx; /* number of bytes available */
- soap->labidx = soap->lablen; /* claim this space */
-#else
- register size_t k = SOAP_BLKLEN;
- if (!(s = (char*)soap_push_block(soap, k)))
- return NULL;
-#endif
- for (i = 0; i < k; i++)
- { if (m > 0)
- { *s++ = *t++; /* copy multibyte characters */
- m--;
- continue;
- }
- if (soap->mode & SOAP_C_UTFSTRING)
- { if (((c = soap_get(soap)) & 0x80000000) && c >= -0x7FFFFF80 && c < SOAP_AP)
- { c &= 0x7FFFFFFF;
- t = buf;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- m = (int)(t - buf) - 1;
- t = buf;
- *s++ = *t++;
- continue;
- }
- }
- else
- c = soap_getutf8(soap);
- switch (c)
- {
- case SOAP_TT:
- if (n == 0)
- goto end;
- n--;
- *s++ = '<';
- t = (char*)"/";
- m = 1;
- break;
- case SOAP_LT:
- n++;
- *s++ = '<';
- break;
- case SOAP_GT:
- *s++ = '>';
- break;
- case SOAP_QT:
- *s++ = '"';
- break;
- case SOAP_AP:
- *s++ = '\'';
- break;
- case '/':
- if (n > 0)
- { c = soap_get(soap);
- if (c == SOAP_GT)
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<' | 0x80000000:
- if (flag)
- *s++ = '<';
- else
- { *s++ = '&';
- t = (char*)"lt;";
- m = 3;
- }
- break;
- case '>' | 0x80000000:
- if (flag)
- *s++ = '>';
- else
- { *s++ = '&';
- t = (char*)"gt;";
- m = 3;
- }
- break;
- case '"' | 0x80000000:
- if (flag)
- *s++ = '"';
- else
- { *s++ = '&';
- t = (char*)"quot;";
- m = 5;
- }
- break;
- case '\'' | 0x80000000:
- if (flag)
- *s++ = '\'';
- else
- { *s++ = '&';
- t = (char*)"apos;";
- m = 5;
- }
- break;
- default:
- if ((int)c == EOF)
- goto end;
-#ifdef HAVE_WCTOMB
- if (soap->mode & SOAP_C_MBSTRING)
- { m = wctomb(buf, c & 0x7FFFFFFF);
- if (m >= 1)
- { t = buf;
- *s++ = *t++;
- m--;
- }
- else
- *s++ = SOAP_UNKNOWN_CHAR;
- }
- else
-#endif
- *s++ = (char)(c & 0xFF);
- }
- l++;
- if ((soap->mode & SOAP_XML_STRICT) && maxlen >= 0 && l > maxlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too long: maxlen=%ld\n", maxlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- }
- }
-end:
- soap_unget(soap, c);
- *s = '\0';
-#ifdef WITH_FAST
- t = soap_strdup(soap, soap->labbuf);
-#else
- soap_size_block(soap, i+1);
- t = soap_save_block(soap, NULL, 0);
-#endif
- if ((soap->mode & SOAP_XML_STRICT) && l < minlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too short: %ld chars, minlen=%ld\n", l, minlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- if (flag == 2)
- if (soap_s2QName(soap, t, &t))
- return NULL;
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_wstring_out(struct soap *soap, const wchar_t *s, int flag)
-{ const char *t;
- char tmp;
- register soap_wchar c;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->wide = NULL; /* soap_malloc() ??? */
- return SOAP_OK;
- }
-#endif
- while ((c = *s++))
- { switch (c)
- {
- case 9:
- if (flag)
- t = "	";
- else
- t = "\t";
- break;
- case 10:
- if (flag || !(soap->mode & SOAP_XML_CANONICAL))
- t = "
";
- else
- t = "\n";
- break;
- case 13:
- t = "
";
- break;
- case '&':
- t = "&";
- break;
- case '<':
- t = "<";
- break;
- case '>':
- if (flag)
- t = ">";
- else
- t = ">";
- break;
- case '"':
- if (flag)
- t = """;
- else
- t = "\"";
- break;
- default:
- if (c > 0 && c < 0x80)
- { tmp = (char)c;
- if (soap_send_raw(soap, &tmp, 1))
- return soap->error;
- }
- else if (soap_pututf8(soap, (unsigned long)c))
- return soap->error;
- continue;
- }
- if (soap_send(soap, t))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t *
-SOAP_FMAC2
-soap_wstring_in(struct soap *soap, int flag, long minlen, long maxlen)
-{ wchar_t *s;
- register int i, n = 0;
- register long l = 0;
- register soap_wchar c;
- const char *t = NULL;
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { if (!(s = (wchar_t*)soap_push_block(soap, sizeof(wchar_t)*SOAP_BLKLEN)))
- return NULL;
- for (i = 0; i < SOAP_BLKLEN; i++)
- { if (t)
- { *s++ = (wchar_t)*t++;
- if (!*t)
- t = NULL;
- continue;
- }
- c = soap_getutf8(soap);
- switch (c)
- {
- case SOAP_TT:
- if (n == 0)
- goto end;
- n--;
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case SOAP_LT:
- n++;
- *s++ = '<';
- break;
- case SOAP_GT:
- *s++ = '>';
- break;
- case SOAP_QT:
- *s++ = '"';
- break;
- case SOAP_AP:
- *s++ = '\'';
- break;
- case '/':
- if (n > 0)
- { c = soap_getutf8(soap);
- if (c == SOAP_GT)
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- if (flag)
- *s++ = (soap_wchar)'<';
- else
- { *s++ = (soap_wchar)'&';
- t = "lt;";
- }
- break;
- case '>':
- if (flag)
- *s++ = (soap_wchar)'>';
- else
- { *s++ = (soap_wchar)'&';
- t = "gt;";
- }
- break;
- case '"':
- if (flag)
- *s++ = (soap_wchar)'"';
- else
- { *s++ = (soap_wchar)'&';
- t = "quot;";
- }
- break;
- default:
- if ((int)c == EOF)
- goto end;
- *s++ = (wchar_t)c & 0x7FFFFFFF;
- }
- l++;
- if ((soap->mode & SOAP_XML_STRICT) && maxlen >= 0 && l > maxlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too long: maxlen=%ld\n", maxlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- }
- }
-end:
- soap_unget(soap, c);
- *s = '\0';
- soap_size_block(soap, sizeof(wchar_t) * (i + 1));
- if ((soap->mode & SOAP_XML_STRICT) && l < minlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too short: %ld chars, minlen=%ld\n", l, minlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- return (wchar_t*)soap_save_block(soap, NULL, 0);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_int2s(struct soap *soap, int n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outint(struct soap *soap, const char *tag, int id, const int *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, (long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2int(struct soap *soap, const char *s, int *p)
-{ if (s)
- { char *r;
- *p = (int)soap_strtol(s, &r, 10);
- if (*r)
- soap->error = SOAP_TYPE;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int *
-SOAP_FMAC2
-soap_inint(struct soap *soap, const char *tag, int *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (int*)soap_id_enter(soap, soap->id, p, t, sizeof(int), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2int(soap, soap_value(soap), p))
- return NULL;
- }
- p = (int*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(int), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_long2s(struct soap *soap, long n)
-{ sprintf(soap->tmpbuf, "%ld", n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outlong(struct soap *soap, const char *tag, int id, const long *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2long(struct soap *soap, const char *s, long *p)
-{ if (s)
- { char *r;
- *p = soap_strtol(s, &r, 10);
- if (*r)
- soap->error = SOAP_TYPE;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-long *
-SOAP_FMAC2
-soap_inlong(struct soap *soap, const char *tag, long *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (long*)soap_id_enter(soap, soap->id, p, t, sizeof(long), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2long(soap, soap_value(soap), p))
- return NULL;
- }
- p = (long*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(long), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_LONG642s(struct soap *soap, LONG64 n)
-{ sprintf(soap->tmpbuf, SOAP_LONG_FORMAT, n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outLONG64(struct soap *soap, const char *tag, int id, const LONG64 *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_LONG642s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2LONG64(struct soap *soap, const char *s, LONG64 *p)
-{ if (s && sscanf(s, SOAP_LONG_FORMAT, p) != 1)
- soap->error = SOAP_TYPE;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-LONG64 *
-SOAP_FMAC2
-soap_inLONG64(struct soap *soap, const char *tag, LONG64 *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":integer")
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":negativeInteger")
- && soap_match_tag(soap, soap->type, ":nonPositiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":long")
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (LONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(LONG64), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2LONG64(soap, soap_value(soap), p))
- return NULL;
- }
- p = (LONG64*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(LONG64), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_byte2s(struct soap *soap, char n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outbyte(struct soap *soap, const char *tag, int id, const char *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, (long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2byte(struct soap *soap, const char *s, char *p)
-{ if (s)
- { long n;
- char *r;
- n = soap_strtol(s, &r, 10);
- if (*r || n < -128 || n > 127)
- soap->error = SOAP_TYPE;
- *p = (char)n;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_inbyte(struct soap *soap, const char *tag, char *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (char*)soap_id_enter(soap, soap->id, p, t, sizeof(char), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2byte(soap, soap_value(soap), p))
- return NULL;
- }
- p = (char*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(char), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_short2s(struct soap *soap, short n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outshort(struct soap *soap, const char *tag, int id, const short *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, (long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2short(struct soap *soap, const char *s, short *p)
-{ if (s)
- { long n;
- char *r;
- n = soap_strtol(s, &r, 10);
- if (*r || n < -32768 || n > 32767)
- soap->error = SOAP_TYPE;
- *p = (short)n;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-short *
-SOAP_FMAC2
-soap_inshort(struct soap *soap, const char *tag, short *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (short*)soap_id_enter(soap, soap->id, p, t, sizeof(short), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2short(soap, soap_value(soap), p))
- return NULL;
- }
- p = (short*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(short), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_float2s(struct soap *soap, float n)
-{ const char *s;
- if (isnan(n))
- s = "NaN";
- else if (n >= FLT_PINFTY)
- s = "INF";
- else if (n <= FLT_NINFTY)
- s = "-INF";
- else
- { sprintf(soap->tmpbuf, soap->float_format, n);
- s = soap->tmpbuf;
- }
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outfloat(struct soap *soap, const char *tag, int id, const float *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_float2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2float(struct soap *soap, const char *s, float *p)
-{ if (s)
- { if (!soap_tag_cmp(s, "INF"))
- *p = FLT_PINFTY;
- else if (!soap_tag_cmp(s, "+INF"))
- *p = FLT_PINFTY;
- else if (!soap_tag_cmp(s, "-INF"))
- *p = FLT_NINFTY;
- else if (!soap_tag_cmp(s, "NaN"))
- *p = FLT_NAN;
- else
- {
-#ifdef HAVE_STRTOD
- char *r;
- *p = (float)strtod(s, &r);
- if (*r)
-#endif
- if (sscanf(s, soap->float_format, p) != 1)
- soap->error = SOAP_TYPE;
- }
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static int soap_isnumeric(struct soap *soap, const char *type)
-{ if (soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":float")
- && soap_match_tag(soap, soap->type, ":double")
- && soap_match_tag(soap, soap->type, ":decimal")
- && soap_match_tag(soap, soap->type, ":integer")
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":negativeInteger")
- && soap_match_tag(soap, soap->type, ":nonPositiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":long")
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte")
- && soap_match_tag(soap, soap->type, ":unsignedLong")
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return SOAP_ERR;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-float *
-SOAP_FMAC2
-soap_infloat(struct soap *soap, const char *tag, float *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type != '\0' && soap_isnumeric(soap, type))
- return NULL;
- p = (float*)soap_id_enter(soap, soap->id, p, t, sizeof(float), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2float(soap, soap_value(soap), p))
- return NULL;
- }
- p = (float*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(float), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_double2s(struct soap *soap, double n)
-{ const char *s;
- if (isnan(n))
- s = "NaN";
- else if (n >= DBL_PINFTY)
- s = "INF";
- else if (n <= DBL_NINFTY)
- s = "-INF";
- else
- { sprintf(soap->tmpbuf, soap->double_format, n);
- s = soap->tmpbuf;
- }
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outdouble(struct soap *soap, const char *tag, int id, const double *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_double2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2double(struct soap *soap, const char *s, double *p)
-{ if (s)
- { if (!soap_tag_cmp(s, "INF"))
- *p = DBL_PINFTY;
- else if (!soap_tag_cmp(s, "+INF"))
- *p = DBL_PINFTY;
- else if (!soap_tag_cmp(s, "-INF"))
- *p = DBL_NINFTY;
- else if (!soap_tag_cmp(s, "NaN"))
- *p = DBL_NAN;
- else
- {
-#ifdef HAVE_STRTOD
- char *r;
- *p = strtod(s, &r);
- if (*r)
-#endif
- if (sscanf(s, soap->double_format, p) != 1)
- soap->error = SOAP_TYPE;
- }
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-double *
-SOAP_FMAC2
-soap_indouble(struct soap *soap, const char *tag, double *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type != '\0' && soap_isnumeric(soap, type))
- return NULL;
- p = (double*)soap_id_enter(soap, soap->id, p, t, sizeof(double), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2double(soap, soap_value(soap), p))
- return NULL;
- }
- p = (double*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(double), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedByte2s(struct soap *soap, unsigned char n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedByte(struct soap *soap, const char *tag, int id, const unsigned char *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, (unsigned long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedByte(struct soap *soap, const char *s, unsigned char *p)
-{ if (s)
- { unsigned long n;
- char *r;
- n = soap_strtoul(s, &r, 10);
- if (*r || n > 255)
- soap->error = SOAP_TYPE;
- *p = (unsigned char)n;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned char *
-SOAP_FMAC2
-soap_inunsignedByte(struct soap *soap, const char *tag, unsigned char *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (unsigned char*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned char), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2unsignedByte(soap, soap_value(soap), p))
- return NULL;
- }
- p = (unsigned char*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned char), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedShort2s(struct soap *soap, unsigned short n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedShort(struct soap *soap, const char *tag, int id, const unsigned short *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, (unsigned long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedShort(struct soap *soap, const char *s, unsigned short *p)
-{ if (s)
- { unsigned long n;
- char *r;
- n = soap_strtoul(s, &r, 10);
- if (*r || n > 65535)
- soap->error = SOAP_TYPE;
- *p = (unsigned short)n;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-unsigned short *
-SOAP_FMAC2
-soap_inunsignedShort(struct soap *soap, const char *tag, unsigned short *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (unsigned short*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned short), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2unsignedShort(soap, soap_value(soap), p))
- return NULL;
- }
- p = (unsigned short*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned short), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedInt2s(struct soap *soap, unsigned int n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedInt(struct soap *soap, const char *tag, int id, const unsigned int *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, (unsigned long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedInt(struct soap *soap, const char *s, unsigned int *p)
-{ if (s)
- { char *r;
- *p = (unsigned int)soap_strtoul(s, &r, 10);
- if (*r)
- soap->error = SOAP_TYPE;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned int *
-SOAP_FMAC2
-soap_inunsignedInt(struct soap *soap, const char *tag, unsigned int *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (unsigned int*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned int), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2unsignedInt(soap, soap_value(soap), p))
- return NULL;
- }
- p = (unsigned int*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned int), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedLong2s(struct soap *soap, unsigned long n)
-{ sprintf(soap->tmpbuf, "%lu", n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedLong(struct soap *soap, const char *tag, int id, const unsigned long *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedLong(struct soap *soap, const char *s, unsigned long *p)
-{ if (s)
- { char *r;
- *p = soap_strtoul(s, &r, 10);
- if (*r)
- soap->error = SOAP_TYPE;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned long *
-SOAP_FMAC2
-soap_inunsignedLong(struct soap *soap, const char *tag, unsigned long *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (unsigned long*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned long), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2unsignedLong(soap, soap_value(soap), p))
- return NULL;
- }
- p = (unsigned long*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned long), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_ULONG642s(struct soap *soap, ULONG64 n)
-{ sprintf(soap->tmpbuf, SOAP_ULONG_FORMAT, n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outULONG64(struct soap *soap, const char *tag, int id, const ULONG64 *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_ULONG642s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2ULONG64(struct soap *soap, const char *s, ULONG64 *p)
-{ if (s && sscanf(s, SOAP_ULONG_FORMAT, p) != 1)
- soap->error = SOAP_TYPE;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-ULONG64 *
-SOAP_FMAC2
-soap_inULONG64(struct soap *soap, const char *tag, ULONG64 *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":unsignedLong")
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (ULONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(ULONG64), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2ULONG64(soap, soap_value(soap), p))
- return NULL;
- }
- p = (ULONG64*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(ULONG64), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2string(struct soap *soap, const char *s, char **t)
-{ *t = NULL;
- if (s && !(*t = soap_strdup(soap, s)))
- soap->error = SOAP_EOM;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2QName(struct soap *soap, const char *s, char **t)
-{ if (s)
- { struct soap_nlist *np;
- const char *p;
- if (!strncmp(s, "xml:", 4))
- { *t = soap_strdup(soap, s);
- return SOAP_OK;
- }
- np = soap->nlist;
- p = strchr(s, ':');
- if (p)
- { register int n = p - s;
- while (np && (strncmp(np->id, s, n) || np->id[n]))
- np = np->next;
- p++;
- }
- else
- { while (np && *np->id)
- np = np->next;
- p = s;
- }
- if (np)
- { if (np->index >= 0 && soap->local_namespaces)
- { register const char *q = soap->local_namespaces[np->index].id;
- if (q)
- { if ((*t = (char*)soap_malloc(soap, strlen(p) + strlen(q) + 2)))
- sprintf(*t, "%s:%s", q, p);
- return SOAP_OK;
- }
- }
- if (np->ns)
- { if ((*t = (char*)soap_malloc(soap, strlen(p) + strlen(np->ns) + 4)))
- sprintf(*t, "\"%s\":%s", np->ns, p);
- return SOAP_OK;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Namespace prefix of '%s' not defined (index=%d, URI=%s)\n", s, np->index, np->ns?np->ns:""));
- return soap->error = SOAP_NAMESPACE;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Namespace prefix of '%s' not defined, assuming empty namespace\n", s));
- if ((*t = (char*)soap_malloc(soap, strlen(p) + 4)))
- sprintf(*t, "\"\":%s", p);
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_QName2s(struct soap *soap, const char *s)
-{ struct Namespace *p;
- char *t;
- int n;
- if (!s || *s != '"')
- return s;
- s++;
- if ((p = soap->local_namespaces))
- { for (; p->id; p++)
- { if (p->ns)
- if (!soap_tag_cmp(s, p->ns))
- break;
- if (p->in)
- if (!soap_tag_cmp(s, p->in))
- break;
- }
- if (p && p->id)
- { s = strchr(s, '"');
- if (s)
- { t = (char*)soap_malloc(soap, strlen(p->id) + strlen(s));
- strcpy(t, p->id);
- strcat(t, s + 1);
- return t;
- }
- }
- }
- t = (char*)strchr(s, '"');
- if (t)
- n = t - s;
- else
- n = 0;
- t = soap_strdup(soap, s);
- t[n] = '\0';
- sprintf(soap->tmpbuf, "xmlns:_%lu", soap->idnum++);
- soap_set_attr(soap, soap->tmpbuf, t);
- s = strchr(s, '"');
- if (s)
- { t = (char*)soap_malloc(soap, strlen(soap->tmpbuf) + strlen(s) - 6);
- strcpy(t, soap->tmpbuf + 6);
- strcat(t, s + 1);
- }
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outstring(struct soap *soap, const char *tag, int id, char *const*p, const char *type, int n)
-{ id = soap_element_id(soap, tag, id, *p, NULL, 0, type, n);
- if (id < 0
- || soap_element_begin_out(soap, tag, id, type)
- || soap_string_out(soap, *p, 0)
- || soap_element_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char **
-SOAP_FMAC2
-soap_instring(struct soap *soap, const char *tag, char **p, const char *type, int t, int flag, long minlen, long maxlen)
-{ if (soap_element_begin_in(soap, tag, 1))
- return NULL;
- if (!p)
- if (!(p = (char**)soap_malloc(soap, sizeof(char*))))
- return NULL;
- if (soap->body)
- { *p = soap_string_in(soap, flag, minlen, maxlen);
- if (!*p || !(char*)soap_id_enter(soap, soap->id, *p, t, sizeof(char*), 0, NULL, NULL, NULL))
- return NULL;
- }
- else
- *p = NULL;
- p = (char**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(char**), 0);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outwstring(struct soap *soap, const char *tag, int id, wchar_t *const*p, const char *type, int n)
-{ id = soap_element_id(soap, tag, id, *p, NULL, 0, type, n);
- if (id < 0
- || soap_element_begin_out(soap, tag, id, type)
- || soap_wstring_out(soap, *p, 0)
- || soap_element_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t **
-SOAP_FMAC2
-soap_inwstring(struct soap *soap, const char *tag, wchar_t **p, const char *type, int t, long minlen, long maxlen)
-{ if (soap_element_begin_in(soap, tag, 1))
- return NULL;
- if (!p)
- if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*))))
- return NULL;
- if (soap->body)
- { *p = soap_wstring_in(soap, 1, minlen, maxlen);
- if (!*p || !(wchar_t*)soap_id_enter(soap, soap->id, *p, t, sizeof(wchar_t*), 0, NULL, NULL, NULL))
- return NULL;
- }
- else
- *p = NULL;
- p = (wchar_t**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(wchar_t**), 0);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static time_t
-soap_timegm(struct tm *T)
-{
-#if defined(HAVE_TIMEGM)
- return timegm(T);
-#elif defined(HAVE_GETTIMEOFDAY)
- struct timezone t;
- struct timeval tv;
- memset((void*)&t, 0, sizeof(t));
- gettimeofday(&tv, &t);
- T->tm_min -= t.tz_minuteswest - (t.tz_dsttime != 0)*60;
- T->tm_isdst = 0;
- return mktime(T);
-/* WR[ */
- /* The following define was added for VxWorks*/
-#elif defined(HAVE_MKTIME)
- /* FOR VXWORKS:
- vxWorks does not seem to have any variable representation of time zones, but
- timezone information can be set in INSTALL_DIR/target/h/private/timeP.h header
- file, by setting the ZONEBUFFER define. The ZONEBUFFER define follows this
- format:
- name_of_zone:<(unused)>:time_in_minutes_from_UTC:daylight_start:daylight_end
- To calculate local time, the value of time_in_minutes_from_UTC is subtracted
- from UTC; time_in_minutes_from_UTC must be positive. Daylight information is
- expressed as mmddhh (month-day-hour), for example:
- UTC::0:040102:100102
- */
- return mktime(T);
-/* ]WR */
-#elif defined(HAVE_FTIME)
- struct timeb t;
- memset((void*)&t, 0, sizeof(t));
- t.timezone = 0;
- t.dstflag = -1;
- ftime(&t);
- T->tm_min -= t.timezone - (t.dstflag != 0)*60;
- T->tm_isdst = 0;
- return mktime(T);
-#else
-#warning "time_t (de)serialization is not MT safe on this platform"
- time_t t;
- char *tz = getenv("TZ");
- putenv("TZ=UTC");
- tzset();
- t = mktime(T);
- if (tz)
- { char tmp[16];
- strcpy(tmp, "TZ=");
- strncat(tmp, tz, 12);
- tmp[15] = '\0';
- putenv(tmp);
- }
- else
- putenv("TZ=");
- tzset();
- return t;
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_dateTime2s(struct soap *soap, time_t n)
-{ struct tm T;
- struct tm *pT = &T;
-#if defined(HAVE_GMTIME_R)
- if (gmtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PGMTIME_R)
- if (gmtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-#elif defined(HAVE_PGMTIME)
- if (gmtime(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-/* ]WR */
-#elif defined(HAVE_GMTIME)
- if ((pT = gmtime(&n)))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-#elif defined(HAVE_GETTIMEOFDAY)
- struct timezone tz;
- memset((void*)&tz, 0, sizeof(tz));
-#if defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- { struct timeval tv;
- gettimeofday(&tv, &tz);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(tz.tz_dsttime!=0), abs(tz.tz_minuteswest)%60);
- }
-#else
- if ((pT = localtime(&n)))
- { struct timeval tv;
- gettimeofday(&tv, &tz);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(tz.tz_dsttime!=0), abs(tz.tz_minuteswest)%60);
- }
-#endif
-#elif defined(HAVE_FTIME)
- struct timeb t;
- memset((void*)&t, 0, sizeof(t));
-#if defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- { ftime(&t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(t.dstflag!=0), abs(t.timezone)%60);
- }
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PLOCALTIME_R)
- if (localtime_r(&n, pT))
- { strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf+strlen(soap->tmpbuf), "%+03d:%02d", t.timezone/60, abs(t.timezone)%60);
- }
-/* ]WR */
-#else
- if ((pT = localtime(&n)))
- { ftime(&t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(t.dstflag!=0), abs(t.timezone)%60);
- }
-#endif
-#elif defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PLOCALTIME_R)
- if (localtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-/* ]WR */
-#else
- if ((pT = localtime(&n)))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-#endif
- else
- strcpy(soap->tmpbuf, "1969-12-31T23:59:59Z");
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outdateTime(struct soap *soap, const char *tag, int id, const time_t *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_dateTime2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2dateTime(struct soap *soap, const char *s, time_t *p)
-{ if (s)
- { struct tm T;
- char zone[16];
- memset((void*)&T, 0, sizeof(T));
- zone[sizeof(zone)-1] = '\0';
- sscanf(s, "%d-%d-%dT%d:%d:%d%15s", &T.tm_year, &T.tm_mon, &T.tm_mday, &T.tm_hour, &T.tm_min, &T.tm_sec, zone);
- if (T.tm_year == 1)
- T.tm_year = 70;
- else
- T.tm_year -= 1900;
- T.tm_mon--;
- if (*zone)
- { if (*zone == '.')
- { for (s = zone + 1; *s; s++)
- if (*s < '0' || *s > '9')
- break;
- }
- else
- s = zone;
- if (*s != 'Z')
- { int h = 0, m = 0;
- sscanf(s, "%d:%d", &h, &m);
- T.tm_hour -= h;
- if (h >= 0)
- T.tm_min -= m;
- else
- T.tm_min += m;
- }
- *p = soap_timegm(&T);
- }
- else
- *p = mktime(&T); /* no time zone: suppose it is localtime? */
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-time_t *
-SOAP_FMAC2
-soap_indateTime(struct soap *soap, const char *tag, time_t *p, const char * type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":dateTime"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (time_t*)soap_id_enter(soap, soap->id, p, t, sizeof(time_t), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2dateTime(soap, soap_value(soap), p))
- return NULL;
- }
- p = (time_t*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(time_t), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outliteral(struct soap *soap, const char *tag, char *const*p)
-{ int i;
- const char *t = NULL;
- if (tag && *tag != '-')
- { if ((t = strchr(tag, ':')))
- { strncpy(soap->tmpbuf, tag, t-tag);
- soap->tmpbuf[t-tag] = '\0';
- for (i = 0; soap->local_namespaces[i].id; i++)
- if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
- break;
- t++;
- sprintf(soap->tmpbuf, "<%s xmlns=\"%s\">", t, soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS);
- }
- else
- { t = tag;
- sprintf(soap->tmpbuf, "<%s>", tag);
- }
- if (soap_send(soap, soap->tmpbuf))
- return soap->error;
- }
- if (p && *p)
- { if (soap_send(soap, *p))
- return soap->error;
- }
- if (t)
- { sprintf(soap->tmpbuf, "</%s>", t);
- return soap_send(soap, soap->tmpbuf);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char **
-SOAP_FMAC2
-soap_inliteral(struct soap *soap, const char *tag, char **p)
-{ if (soap_element_begin_in(soap, tag, 1))
- return NULL;
- if (!p)
- if (!(p = (char**)soap_malloc(soap, sizeof(char*))))
- return NULL;
- if (soap->null)
- *p = NULL;
- else if (soap->body)
- *p = soap_string_in(soap, 0, -1, -1);
- else
- *p = NULL;
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p)
-{ int i;
- const char *t = NULL;
- wchar_t c;
- const wchar_t *s;
- if (tag && *tag != '-')
- { if (tag && (t = strchr(tag, ':')))
- { strncpy(soap->tmpbuf, tag, t-tag);
- soap->tmpbuf[t-tag] = '\0';
- for (i = 0; soap->local_namespaces[i].id; i++)
- if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
- break;
- t++;
- sprintf(soap->tmpbuf, "<%s xmlns=\"%s\">", t, soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS);
- }
- else
- { t = tag;
- sprintf(soap->tmpbuf, "<%s>", tag);
- }
- if (soap_send(soap, soap->tmpbuf))
- return soap->error;
- }
- if (p)
- { s = *p;
- while ((c = *s++))
- if (soap_pututf8(soap, (unsigned char)c))
- return soap->error;
- }
- if (t)
- { sprintf(soap->tmpbuf, "</%s>", t);
- return soap_send(soap, soap->tmpbuf);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t **
-SOAP_FMAC2
-soap_inwliteral(struct soap *soap, const char *tag, wchar_t **p)
-{ if (soap_element_begin_in(soap, tag, 1))
- return NULL;
- if (!p)
- if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*))))
- return NULL;
- if (soap->null)
- *p = NULL;
- else if (soap->body)
- *p = soap_wstring_in(soap, 0, -1, -1);
- else
- *p = NULL;
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char *
-SOAP_FMAC2
-soap_value(struct soap *soap)
-{ size_t i;
- soap_wchar c = 0;
- char *s = soap->tmpbuf;
- if (!soap->body)
- return SOAP_STR_EOS;
- for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++)
- { c = soap_get(soap);
- if (c == SOAP_TT || (int)c == EOF || soap_blank(c))
- break;
- *s++ = (char)c;
- }
- if ((int)c == EOF || c == SOAP_TT)
- soap_unget(soap, c);
- *s = '\0';
- return soap->tmpbuf; /* return non-null pointer */
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getline(struct soap *soap, char *s, int len)
-{ int i = len;
- soap_wchar c = 0;
- for (;;)
- { while (--i > 0)
- { c = soap_getchar(soap);
- if (c == '\r')
- break;
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- c = soap_getchar(soap);
- if (c == '\n')
- { *s = '\0';
- if (i+1 == len) /* empty line: end of HTTP header */
- break;
- c = soap_unget(soap, soap_getchar(soap));
- if (c != ' ' && c != '\t') /* HTTP line continuation? */
- break;
- }
- else if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static size_t
-soap_count_attachments(struct soap *soap)
-{
-#ifndef WITH_LEANER
- register struct soap_multipart *content;
- register size_t count = soap->count;
- if (soap->mode & SOAP_ENC_DIME)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the size of DIME attachments\n"));
- for (content = soap->dime.first; content; content = content->next)
- { count += 12 + ((content->size+3)&(~3));
- if (content->id)
- count += ((strlen(content->id)+3)&(~3));
- if (content->type)
- count += ((strlen(content->type)+3)&(~3));
- if (content->options)
- count += ((((unsigned char)content->options[2] << 8) | ((unsigned char)content->options[3]))+7)&(~3);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Size of DIME attachment %lu bytes\n", content->size));
- }
- }
- if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary)
- { register size_t n = strlen(soap->mime.boundary);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the size of MIME attachments\n"));
- for (content = soap->mime.first; content; content = content->next)
- { register const char *s;
- /* count \r\n--boundary\r\n */
- count += 6 + n;
- /* count Content-Type: ...\r\n */
- if (content->type)
- count += 16 + strlen(content->type);
- s = soap_str_code(mime_codes, content->encoding);
- /* count Content-Transfer-Encoding: ...\r\n */
- if (s)
- count += 29 + strlen(s);
- /* count Content-ID: ...\r\n */
- if (content->id)
- count += 14 + strlen(content->id);
- /* count Content-Location: ...\r\n */
- if (content->location)
- count += 20 + strlen(content->location);
- /* count Content-Description: ...\r\n */
- if (content->description)
- count += 23 + strlen(content->location);
- /* count \r\n...content */
- count += 2 + content->size;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Size of MIME attachment %lu bytes\n", content->size));
- }
- /* count \r\n--boundary--\r\n */
- count += 8 + n;
- }
- return count;
-#else
- return soap->count;
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static int
-soap_putdimefield(struct soap *soap, const char *s, size_t n)
-{ if (soap_send_raw(soap, s, n))
- return soap->error;
- return soap_send_raw(soap, SOAP_STR_PADDING, -(long)n&3);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_dime_option(struct soap *soap, unsigned short optype, const char *option)
-{ size_t n;
- char *s = NULL;
- if (option)
- { n = strlen(option);
- s = (char*)soap_malloc(soap, n + 5);
- if (s)
- { s[0] = optype >> 8;
- s[1] = optype & 0xFF;
- s[2] = n >> 8;
- s[3] = n & 0xFF;
- strcpy(s + 4, option);
- }
- }
- return s;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putdimehdr(struct soap *soap)
-{ unsigned char tmp[12];
- size_t optlen = 0, idlen = 0, typelen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Put DIME header id='%s'\n", soap->dime.id?soap->dime.id:""));
- if (soap->dime.options)
- optlen = (((unsigned char)soap->dime.options[2] << 8) | ((unsigned char)soap->dime.options[3])) + 4;
- if (soap->dime.id)
- idlen = strlen(soap->dime.id);
- if (soap->dime.type)
- typelen = strlen(soap->dime.type);
- tmp[0] = SOAP_DIME_VERSION | (soap->dime.flags & 0x7);
- tmp[1] = soap->dime.flags & 0xF0;
- tmp[2] = optlen >> 8;
- tmp[3] = optlen & 0xFF;
- tmp[4] = idlen >> 8;
- tmp[5] = idlen & 0xFF;
- tmp[6] = typelen >> 8;
- tmp[7] = typelen & 0xFF;
- tmp[8] = soap->dime.size >> 24;
- tmp[9] = (soap->dime.size >> 16) & 0xFF;
- tmp[10] = (soap->dime.size >> 8) & 0xFF;
- tmp[11] = soap->dime.size & 0xFF;
- if (soap_send_raw(soap, (char*)tmp, 12)
- || soap_putdimefield(soap, soap->dime.options, optlen)
- || soap_putdimefield(soap, soap->dime.id, idlen)
- || soap_putdimefield(soap, soap->dime.type, typelen))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putdime(struct soap *soap)
-{ struct soap_multipart *content;
- if (!(soap->mode & SOAP_ENC_DIME))
- return SOAP_OK;
- for (content = soap->dime.first; content; content = content->next)
- { void *handle;
- soap->dime.size = content->size;
- soap->dime.id = content->id;
- soap->dime.type = content->type;
- soap->dime.options = content->options;
- soap->dime.flags = SOAP_DIME_VERSION | SOAP_DIME_MEDIA;
- if (soap->fdimereadopen && ((handle = soap->fdimereadopen(soap, (void*)content->ptr, content->id, content->type, content->options)) || soap->error))
- { size_t size = content->size;
- if (!handle)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadopen failed\n"));
- return soap->error;
- }
- if (!content->size && ((soap->mode & SOAP_ENC_XML) || (soap->mode & SOAP_IO) == SOAP_IO_CHUNK || (soap->mode & SOAP_IO) == SOAP_IO_STORE))
- { size_t chunksize = sizeof(soap->tmpbuf);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked streaming DIME\n"));
- do
- { size = soap->fdimeread(soap, handle, soap->tmpbuf, chunksize);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread returned %lu bytes\n", (unsigned long)size));
- if (size < chunksize)
- { soap->dime.flags &= ~SOAP_DIME_CF;
- if (!content->next)
- soap->dime.flags |= SOAP_DIME_ME;
- }
- else
- soap->dime.flags |= SOAP_DIME_CF;
- soap->dime.size = size;
- if (soap_putdimehdr(soap)
- || soap_putdimefield(soap, soap->tmpbuf, size))
- break;
- if (soap->dime.id)
- { soap->dime.flags &= ~(SOAP_DIME_MB | SOAP_DIME_MEDIA);
- soap->dime.id = NULL;
- soap->dime.type = NULL;
- soap->dime.options = NULL;
- }
- } while (size >= chunksize);
- }
- else
- { if (!content->next)
- soap->dime.flags |= SOAP_DIME_ME;
- if (soap_putdimehdr(soap))
- return soap->error;
- do
- { size_t bufsize;
- if (size < sizeof(soap->tmpbuf))
- bufsize = size;
- else
- bufsize = sizeof(soap->tmpbuf);
- if (!(bufsize = soap->fdimeread(soap, handle, soap->tmpbuf, bufsize)))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)soap->dime.size));
- soap->error = SOAP_EOF;
- break;
- }
- if (soap_send_raw(soap, soap->tmpbuf, bufsize))
- break;
- size -= bufsize;
- } while (size);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
- soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime.size&3);
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
- if (soap->fdimereadclose)
- soap->fdimereadclose(soap, handle);
- }
- else
- { if (!content->next)
- soap->dime.flags |= SOAP_DIME_ME;
- if (soap_putdimehdr(soap)
- || soap_putdimefield(soap, (char*)content->ptr, content->size))
- return soap->error;
- }
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static char *
-soap_getdimefield(struct soap *soap, size_t n)
-{ register soap_wchar c;
- register int i;
- register char *s;
- char *p = NULL;
- if (n)
- { p = (char*)soap_malloc(soap, n + 1);
- if (p)
- { s = p;
- for (i = n; i > 0; i--)
- { if ((int)(c = soap_get1(soap)) == EOF)
- { soap->error = SOAP_EOF;
- return NULL;
- }
- *s++ = (char)c;
- }
- *s = '\0';
- if ((soap->error = soap_move(soap, -(long)n&3)))
- return NULL;
- }
- else
- soap->error = SOAP_EOM;
- }
- return p;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getdimehdr(struct soap *soap)
-{ register soap_wchar c;
- register char *s;
- register int i;
- unsigned char tmp[12];
- size_t optlen, idlen, typelen;
- if (!(soap->mode & SOAP_ENC_DIME))
- return soap->error = SOAP_DIME_END;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME header\n"));
- if (soap->dime.buflen || soap->dime.chunksize)
- { if (soap_move(soap, (long)(soap->dime.size - soap_tell(soap))))
- return soap->error = SOAP_EOF;
- soap_unget(soap, soap_getchar(soap)); /* skip padding and get hdr */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... From chunked\n"));
- return SOAP_OK;
- }
- s = (char*)tmp;
- for (i = 12; i > 0; i--)
- { if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- if ((tmp[0] & 0xF8) != SOAP_DIME_VERSION)
- return soap->error = SOAP_DIME_MISMATCH;
- soap->dime.flags = (tmp[0] & 0x7) | (tmp[1] & 0xF0);
- optlen = (tmp[2] << 8) | tmp[3];
- idlen = (tmp[4] << 8) | tmp[5];
- typelen = (tmp[6] << 8) | tmp[7];
- soap->dime.size = (tmp[8] << 24) | (tmp[9] << 16) | (tmp[10] << 8) | tmp[11];
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME size=%lu flags=0x%X\n", (unsigned long)soap->dime.size, soap->dime.flags));
- if (!(soap->dime.options = soap_getdimefield(soap, optlen)) && soap->error)
- return soap->error;
- if (!(soap->dime.id = soap_getdimefield(soap, idlen)) && soap->error)
- return soap->error;
- if (!(soap->dime.type = soap_getdimefield(soap, typelen)) && soap->error)
- return soap->error;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME id=%s, type=%s, options=%s\n", soap->dime.id?soap->dime.id:"", soap->dime.type?soap->dime.type:"", soap->dime.options?soap->dime.options+4:""));
- if (soap->dime.flags & SOAP_DIME_ME)
- soap->mode &= ~SOAP_ENC_DIME;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getdime(struct soap *soap)
-{ struct soap_multipart *content;
- if (soap_getdimehdr(soap))
- return soap->error;
- if (soap->fdimewriteopen && ((soap->dime.ptr = (char*)soap->fdimewriteopen(soap, soap->dime.id, soap->dime.type, soap->dime.options)) || soap->error))
- { const char *id, *type, *options;
- size_t size, n;
- if (!soap->dime.ptr)
- return soap->error;
- id = soap->dime.id;
- type = soap->dime.type;
- options = soap->dime.options;
- for (;;)
- { size = soap->dime.size;
- for (;;)
- { n = soap->buflen - soap->bufidx;
- if (size < n)
- n = size;
- if ((soap->error = soap->fdimewrite(soap, (void*)soap->dime.ptr, soap->buf + soap->bufidx, n)))
- break;
- size -= n;
- if (!size)
- { soap->bufidx += n;
- break;
- }
- if (soap_recv(soap))
- { soap->error = SOAP_EOF;
- goto end;
- }
- }
- if (soap_move(soap, -(long)soap->dime.size&3))
- { soap->error = SOAP_EOF;
- break;
- }
- if (!(soap->dime.flags & SOAP_DIME_CF))
- break;
- if (soap_getdimehdr(soap))
- break;
- }
-end:
- if (soap->fdimewriteclose)
- soap->fdimewriteclose(soap, (void*)soap->dime.ptr);
- soap->dime.size = 0;
- soap->dime.id = id;
- soap->dime.type = type;
- soap->dime.options = options;
- }
- else if (soap->dime.flags & SOAP_DIME_CF)
- { const char *id, *type, *options;
- register soap_wchar c;
- register char *s;
- register int i;
- id = soap->dime.id;
- type = soap->dime.type;
- options = soap->dime.options;
- if (soap_new_block(soap))
- return SOAP_EOM;
- for (;;)
- { s = (char*)soap_push_block(soap, soap->dime.size);
- if (!s)
- return soap->error = SOAP_EOM;
- for (i = soap->dime.size; i > 0; i--)
- { if ((int)(c = soap_get1(soap)) == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- if (soap_move(soap, -(long)soap->dime.size&3))
- return soap->error = SOAP_EOF;
- if (!(soap->dime.flags & SOAP_DIME_CF))
- break;
- if (soap_getdimehdr(soap))
- return soap->error;
- }
- soap->dime.size = soap->blist->size++; /* allocate one more for '\0' */
- if (!(soap->dime.ptr = soap_save_block(soap, NULL, 0)))
- return soap->error;
- soap->dime.ptr[soap->dime.size] = '\0'; /* force 0-terminated */
- soap->dime.id = id;
- soap->dime.type = type;
- soap->dime.options = options;
- }
- else
- soap->dime.ptr = soap_getdimefield(soap, soap->dime.size);
- content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, soap->dime.ptr, soap->dime.size);
- if (!content)
- return soap->error = SOAP_EOM;
- content->id = soap->dime.id;
- content->type = soap->dime.type;
- content->options = soap->dime.options;
- return soap->error;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getmimehdr(struct soap *soap)
-{ struct soap_multipart *content;
- do
- { if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
- return soap->error;
- }
- while (!*soap->msgbuf);
- if (soap->msgbuf[0] == '-' && soap->msgbuf[1] == '-')
- { char *s = soap->msgbuf + strlen(soap->msgbuf) - 1;
- /* remove white space */
- while (soap_blank(*s))
- s--;
- s[1] = '\0';
- if (soap->mime.boundary)
- { if (strcmp(soap->msgbuf + 2, soap->mime.boundary))
- return soap->error = SOAP_MIME_ERROR;
- }
- else
- soap->mime.boundary = soap_strdup(soap, soap->msgbuf + 2);
- if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
- return soap->error;
- }
- if (soap_set_mime_attachment(soap, NULL, 0, SOAP_MIME_NONE, NULL, NULL, NULL, NULL))
- return soap->error = SOAP_EOM;
- content = soap->mime.last;
- for (;;)
- { register char *key = soap->msgbuf;
- register char *val;
- if (!*key)
- break;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "MIME header: %s\n", key));
- val = strchr(soap->msgbuf, ':');
- if (val)
- { *val = '\0';
- do val++;
- while (*val && *val <= 32);
- if (!soap_tag_cmp(key, "Content-ID"))
- content->id = soap_strdup(soap, val);
- else if (!soap_tag_cmp(key, "Content-Location"))
- content->location = soap_strdup(soap, val);
- else if (!soap_tag_cmp(key, "Content-Type"))
- content->type = soap_strdup(soap, val);
- else if (!soap_tag_cmp(key, "Content-Description"))
- content->description = soap_strdup(soap, val);
- else if (!soap_tag_cmp(key, "Content-Transfer-Encoding"))
- content->encoding = (enum soap_mime_encoding)soap_int_code(mime_codes, val, (long)SOAP_MIME_NONE);
- }
- if (soap_getline(soap, key, sizeof(soap->msgbuf)))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getmime(struct soap *soap)
-{ register char c;
- for (;;)
- { register size_t i, m = 0;
- register char *s;
- struct soap_multipart *content = soap->mime.last;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id=%s type=%s\n", content->id?content->id:"", content->type?content->type:""));
- if (soap_new_block(soap))
- return soap->error = SOAP_EOM;
- for (;;)
- { register char *t = NULL;
- if (!(s = (char*)soap_push_block(soap, SOAP_BLKLEN)))
- return soap->error = SOAP_EOM;
- for (i = 0; i < SOAP_BLKLEN; i++)
- { if (m > 0)
- { *s++ = *t++;
- m--;
- }
- else
- { c = soap_get1(soap);
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (c == '\r')
- { t = soap->tmpbuf;
- strcpy(t, "\n--");
- strncat(t, soap->mime.boundary, sizeof(soap->tmpbuf)-3);
- t[sizeof(soap->tmpbuf)-1] = '\0';
- do c = soap_get1(soap);
- while ((char)c == *t++);
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (!*--t)
- goto end;
- *t = (char)c;
- m = t - soap->tmpbuf + 1;
- t = soap->tmpbuf;
- c = '\r';
- }
- *s++ = (char)c;
- }
- }
- }
-end:
- *s = '\0'; /* force 0-terminated */
- content->size = soap_size_block(soap, i+1)-1;
- content->ptr = soap_save_block(soap, NULL, 0);
- if (c == '-' && (int)soap_get1(soap) == '-')
- break;
- while (c != '\r' && (int)c != EOF && soap_blank(c))
- c = soap_get1(soap);
- if (c != '\r' || (int)soap_get1(soap) != '\n')
- return soap->error = SOAP_MIME_ERROR;
- if (soap_getmimehdr(soap))
- return soap->error;
- }
- do c = soap_get1(soap);
- while ((int)c != EOF && c != '\r');
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (soap_get1(soap) != '\n')
- return soap->error = SOAP_MIME_ERROR;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putmimehdr(struct soap *soap, struct soap_multipart *content)
-{ const char *s;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "MIME attachment type=%s\n", content->type?content->type:""));
- if (soap_send3(soap, "\r\n--", soap->mime.boundary, "\r\n"))
- return soap->error;
- if (content->type && soap_send3(soap, "Content-Type: ", content->type, "\r\n"))
- return soap->error;
- s = soap_str_code(mime_codes, content->encoding);
- if (s && soap_send3(soap, "Content-Transfer-Encoding: ", s, "\r\n"))
- return soap->error;
- if (content->id && soap_send3(soap, "Content-ID: ", content->id, "\r\n"))
- return soap->error;
- if (content->location && soap_send3(soap, "Content-Location: ", content->location, "\r\n"))
- return soap->error;
- if (content->description && soap_send3(soap, "Content-Description: ", content->description, "\r\n"))
- return soap->error;
- return soap_send_raw(soap, "\r\n", 2);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putmime(struct soap *soap)
-{ struct soap_multipart *content;
- if (!(soap->mode & SOAP_ENC_MIME) || !soap->mime.boundary)
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending MIME attachments\n"));
- for (content = soap->mime.first; content; content = content->next)
- if (soap_putmimehdr(soap, content)
- || soap_send_raw(soap, content->ptr, content->size))
- return soap->error;
- return soap_send3(soap, "\r\n--", soap->mime.boundary, "--\r\n");
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_dime(struct soap *soap)
-{ soap->omode |= SOAP_ENC_DIME;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_mime(struct soap *soap, const char *boundary, const char *start)
-{ soap->omode |= SOAP_ENC_MIME;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->mime.boundary = soap_strdup(soap, boundary);
- soap->mime.start = soap_strdup(soap, start);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_dime(struct soap *soap)
-{ soap->omode &= ~SOAP_ENC_DIME;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_mime(struct soap *soap)
-{ soap->omode &= ~SOAP_ENC_MIME;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->mime.boundary = NULL;
- soap->mime.start = NULL;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static struct soap_multipart*
-soap_new_multipart(struct soap *soap, struct soap_multipart **first, struct soap_multipart **last, char *ptr, size_t size)
-{ struct soap_multipart *content;
- content = (struct soap_multipart*)soap_malloc(soap, sizeof(struct soap_multipart));
- if (content)
- { content->next = NULL;
- content->ptr = ptr;
- content->size = size;
- content->id = NULL;
- content->type = NULL;
- content->options = NULL;
- content->encoding = SOAP_MIME_NONE;
- content->location = NULL;
- content->description = NULL;
- if (!*first)
- *first = content;
- if (*last)
- (*last)->next = content;
- *last = content;
- }
- return content;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_dime_attachment(struct soap *soap, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option)
-{ struct soap_multipart *content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, ptr, size);
- if (!content)
- return SOAP_EOM;
- content->id = soap_strdup(soap, id);
- content->type = soap_strdup(soap, type);
- content->options = soap_dime_option(soap, optype, option);
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_mime_attachment(struct soap *soap, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description)
-{ struct soap_multipart *content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, ptr, size);
- if (!content)
- return SOAP_EOM;
- content->id = soap_strdup(soap, id);
- content->type = soap_strdup(soap, type);
- content->encoding = encoding;
- content->location = soap_strdup(soap, location);
- content->description = soap_strdup(soap, description);
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap_multipart*
-SOAP_FMAC2
-soap_next_multipart(struct soap_multipart *content)
-{ if (content)
- return content->next;
- return NULL;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static void
-soap_select_mime_boundary(struct soap *soap)
-{ while (!soap->mime.boundary || soap_valid_mime_boundary(soap))
- { char *s = soap->mime.boundary;
- size_t n = 0;
- if (s)
- n = strlen(s);
- if (n < 16)
- { n = 72;
- s = soap->mime.boundary = (char*)soap_malloc(soap, n);
- if (!s)
- return;
- }
- strcpy(s, "<>");
- s += 2;
- n -= 4;
- while (n)
- { *s++ = soap_base64o[rand()&0x3F];
- n--;
- }
- *s = '\0';
- strcat(s, "<>");
- }
- if (!soap->mime.start)
- soap->mime.start = "<SOAP-ENV:Envelope>";
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static int
-soap_valid_mime_boundary(struct soap *soap)
-{ register struct soap_multipart *content;
- register size_t k = strlen(soap->mime.boundary);
- for (content = soap->mime.first; content; content = content->next)
- { if (content->ptr && content->size >= k)
- { register const char *p = (const char*)content->ptr;
- register size_t i;
- for (i = 0; i < content->size - k; i++, p++)
- if (!strncmp(p, soap->mime.boundary, k))
- return SOAP_ERR;
- }
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-
-#ifdef WITH_COOKIES
-/******************************************************************************/
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_encode_cookie(const char *s, char *t, size_t len)
-{ register int c;
- register size_t n = len;
- while ((c = *s++) && --n > 0)
- { if (c > ' ' && c < 128 && c != ';' && c != ',')
- *t++ = c;
- else if (n > 2)
- { *t++ = '%';
- *t++ = (c >> 4) + (c > 159 ? '7' : '0');
- c &= 0xF;
- *t++ = c + (c > 9 ? '7' : '0');
- n -= 2;
- }
- else
- break;
- }
- *t = '\0';
- return len - n;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- size_t n;
- if (!domain)
- domain = soap->cookie_domain;
- if (!path)
- path = soap->cookie_path;
- if (*path == '/')
- path++;
- n = strlen(path);
- for (p = soap->cookies; p; p = p->next)
- if (!strcmp(p->name, name)
- && domain
- && p->domain
- && !strcmp(p->domain, domain)
- && !strncmp(p->path, path, n))
- break;
- return p;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_set_cookie(struct soap *soap, const char *name, const char *value, const char *domain, const char *path)
-{ struct soap_cookie **p, *q;
- int n;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie: %s=%s domain=%s path=%s\n", name, value?value:"", domain?domain:"", path?path:""));
- if (!domain)
- domain = soap->cookie_domain;
- if (!path)
- path = soap->cookie_path;
- if (!path)
- { soap_set_receiver_error(soap, "Cookie path not set", NULL, SOAP_HTTP_ERROR);
- return NULL;
- }
- if (*path == '/')
- path++;
- q = soap_cookie(soap, name, domain, path);
- if (!q)
- { if ((q = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- { if ((q->name = (char*)SOAP_MALLOC(strlen(name)+1)))
- strcpy(q->name, name);
- q->value = NULL;
- q->domain = NULL;
- q->path = NULL;
- q->expire = -1;
- q->version = 0;
- q->secure = 0;
- q->env = 0;
- q->modified = 0;
- for (p = &soap->cookies, n = soap->cookie_max; *p && n; p = &(*p)->next, n--)
- if (!strcmp((*p)->name, name) && (*p)->path && strcmp((*p)->path, path) < 0)
- break;
- if (n)
- { q->next = *p;
- *p = q;
- }
- else
- { SOAP_FREE(q->name);
- SOAP_FREE(q);
- q = NULL;
- }
- }
- }
- else
- q->modified = 1;
- if (q)
- { if (q->value)
- { SOAP_FREE(q->value);
- q->value = NULL;
- }
- if (q->domain)
- { SOAP_FREE(q->domain);
- q->domain = NULL;
- }
- if (q->path)
- { SOAP_FREE(q->path);
- q->path = NULL;
- }
- if (value && *value && (q->value = (char*)SOAP_MALLOC(strlen(value)+1)))
- strcpy(q->value, value);
- if (domain && *domain && (q->domain = (char*)SOAP_MALLOC(strlen(domain)+1)))
- strcpy(q->domain, domain);
- if (path && *path && (q->path = (char*)SOAP_MALLOC(strlen(path)+1)))
- strcpy(q->path, path);
- q->session = 1;
- }
- return q;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie **p, *q;
- if (!domain)
- domain = soap->cookie_domain;
- if (!domain)
- { soap_set_receiver_error(soap, "Cookie domain not set", SOAP_STR_EOS, SOAP_HTTP_ERROR);
- return;
- }
- if (!path)
- path = soap->cookie_path;
- if (!path)
- { soap_set_receiver_error(soap, "Cookie path not set", SOAP_STR_EOS, SOAP_HTTP_ERROR);
- return;
- }
- if (*path == '/')
- path++;
- for (p = &soap->cookies, q = *p; q; q = *p)
- if (!strcmp(q->name, name) && !strcmp(q->domain, domain) && !strncmp(q->path, path, strlen(q->path)))
- { if (q->value)
- SOAP_FREE(q->value);
- if (q->domain)
- SOAP_FREE(q->domain);
- if (q->path)
- SOAP_FREE(q->path);
- *p = q->next;
- SOAP_FREE(q);
- }
- else
- p = &q->next;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_cookie_value(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- return p->value;
- return NULL;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_cookie_expire(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- return p->expire;
- return -1;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_cookie_expire(struct soap *soap, const char *name, long expire, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->expire = expire;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->session = 1;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_clr_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->session = 0;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putsetcookies(struct soap *soap)
-{ struct soap_cookie *p;
- char *s, tmp[4096];
- const char *t;
- for (p = soap->cookies; p; p = p->next)
- { if (p->modified || !p->env)
- { s = tmp;
- if (p->name)
- s += soap_encode_cookie(p->name, s, tmp-s+4064);
- if (p->value && *p->value)
- { *s++ = '=';
- s += soap_encode_cookie(p->value, s, tmp-s+4064);
- }
- if (p->domain && (int)strlen(p->domain) < tmp-s+4064)
- sprintf(s, ";Domain=%s", p->domain);
- else if (soap->cookie_domain && (int)strlen(soap->cookie_domain) < tmp-s+4064)
- sprintf(s, ";Domain=%s", soap->cookie_domain);
- strcat(s, ";Path=/");
- if (p->path)
- t = p->path;
- else
- t = soap->cookie_path;
- if (t)
- { if (*t == '/')
- t++;
- if ((int)strlen(t) < tmp-s+4064)
- strcat(s, t);
- }
- s += strlen(s);
- if (p->version > 0)
- sprintf(s, ";Version=%u", p->version);
- if (p->expire >= 0)
- sprintf(s, ";Max-Age=%ld", p->expire);
- if (p->secure)
- strcat(s, ";Secure");
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set-Cookie: %s\n", tmp));
- if (soap->fposthdr(soap, "Set-Cookie", tmp))
- return soap->error;
- }
- }
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putcookies(struct soap *soap, const char *domain, const char *path, int secure)
-{ struct soap_cookie **p, *q;
- unsigned int version = 0;
- time_t now = time(NULL);
- char *s, tmp[4096];
- p = &soap->cookies;
- while ((q = *p))
- { if (q->expire && now > q->expire)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name));
- SOAP_FREE(q->name);
- if (q->value)
- SOAP_FREE(q->value);
- if (q->domain)
- SOAP_FREE(q->domain);
- if (q->path)
- SOAP_FREE(q->path);
- *p = q->next;
- SOAP_FREE(q);
- }
- else if ((!q->domain || !strcmp(q->domain, domain))
- && (!q->path || !strncmp(q->path, path, strlen(q->path)))
- && (!q->secure || secure))
- { s = tmp;
- if (q->version != version)
- { sprintf(s, "$Version=%u;", q->version);
- version = q->version;
- }
- if (q->name)
- s += soap_encode_cookie(q->name, s, tmp-s+4080);
- if (q->value && *q->value)
- { *s++ = '=';
- s += soap_encode_cookie(q->value, s, tmp-s+4080);
- }
- if (q->path && (int)strlen(q->path) < tmp-s+4080)
- { sprintf(s, ";$Path=/%s", q->path);
- s += strlen(s);
- }
- if (q->domain && (int)strlen(q->domain) < tmp-s+4080)
- sprintf(s, ";$Domain=%s", q->domain);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie: %s\n", tmp));
- if (soap->fposthdr(soap, "Cookie", tmp))
- return soap->error;
- p = &q->next;
- }
- else
- p = &q->next;
- }
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_getcookies(struct soap *soap, const char *val)
-{ struct soap_cookie *p = NULL, *q;
- const char *s;
- char *t, tmp[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
- char *domain = NULL;
- char *path = NULL;
- unsigned int version = 0;
- time_t now = time(NULL);
- if (!val)
- return;
- s = val;
- while (*s)
- { s = soap_decode_key(tmp, sizeof(tmp), s);
- if (!soap_tag_cmp(tmp, "$Version"))
- { if ((s = soap_decode_val(tmp, sizeof(tmp), s)))
- { if (p)
- p->version = (int)atol(tmp);
- else
- version = (int)atol(tmp);
- }
- }
- else if (!soap_tag_cmp(tmp, "$Path"))
- { s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((t = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(t, tmp);
- }
- else
- t = NULL;
- if (p)
- { if (p->path)
- SOAP_FREE(p->path);
- p->path = t;
- }
- else
- { if (path)
- SOAP_FREE(path);
- path = t;
- }
- }
- else if (!soap_tag_cmp(tmp, "$Domain"))
- { s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((t = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(t, tmp);
- }
- else
- t = NULL;
- if (p)
- { if (p->domain)
- SOAP_FREE(p->domain);
- p->domain = t;
- }
- else
- { if (domain)
- SOAP_FREE(domain);
- domain = t;
- }
- }
- else if (p && !soap_tag_cmp(tmp, "Path"))
- { if (p->path)
- SOAP_FREE(p->path);
- s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((p->path = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(p->path, tmp);
- }
- else
- p->path = NULL;
- }
- else if (p && !soap_tag_cmp(tmp, "Domain"))
- { if (p->domain)
- SOAP_FREE(p->domain);
- s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((p->domain = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(p->domain, tmp);
- }
- else
- p->domain = NULL;
- }
- else if (p && !soap_tag_cmp(tmp, "Version"))
- { s = soap_decode_val(tmp, sizeof(tmp), s);
- p->version = (unsigned int)atol(tmp);
- }
- else if (p && !soap_tag_cmp(tmp, "Max-Age"))
- { s = soap_decode_val(tmp, sizeof(tmp), s);
- p->expire = now + atol(tmp);
- }
- else if (p && !soap_tag_cmp(tmp, "Expires"))
- { struct tm T;
- char a[3];
- static const char mns[] = "anebarprayunulugepctovec";
- s = soap_decode_val(tmp, sizeof(tmp), s);
- if (strlen(tmp) > 20)
- { memset((void*)&T, 0, sizeof(T));
- a[0] = tmp[4];
- a[1] = tmp[5];
- a[2] = '\0';
- T.tm_mday = (int)atol(a);
- a[0] = tmp[8];
- a[1] = tmp[9];
- T.tm_mon = (strstr(mns, a) - mns) / 2;
- a[0] = tmp[11];
- a[1] = tmp[12];
- T.tm_year = 100 + (int)atol(a);
- a[0] = tmp[13];
- a[1] = tmp[14];
- T.tm_hour = (int)atol(a);
- a[0] = tmp[16];
- a[1] = tmp[17];
- T.tm_min = (int)atol(a);
- a[0] = tmp[19];
- a[1] = tmp[20];
- T.tm_sec = (int)atol(a);
- p->expire = soap_timegm(&T);
- }
- }
- else if (p && !soap_tag_cmp(tmp, "Secure"))
- p->secure = 1;
- else
- { if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"", p->domain?p->domain:"", p->path?p->path:"", p->expire, p->secure));
- if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
- { q->version = p->version;
- q->expire = p->expire;
- q->secure = p->secure;
- q->env = 1;
- }
- if (p->name)
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
- if ((p = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- { p->name = (char*)SOAP_MALLOC(strlen(tmp)+1);
- strcpy(p->name, tmp);
- s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { p->value = (char*)SOAP_MALLOC(strlen(tmp)+1);
- strcpy(p->value, tmp);
- }
- else
- p->value = NULL;
- p->domain = domain;
- p->path = path;
- p->expire = 0;
- p->secure = 0;
- p->version = version;
- }
- }
- }
- if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"", p->domain?p->domain:"", p->path?p->path:"", p->expire, p->secure));
- if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
- { q->version = p->version;
- q->expire = p->expire;
- q->secure = p->secure;
- }
- if (p->name)
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
- if (domain)
- SOAP_FREE(domain);
- if (path)
- SOAP_FREE(path);
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getenv_cookies(struct soap *soap)
-{ struct soap_cookie *p;
- const char *s;
- char key[4096], val[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
- if (!(s = getenv("HTTP_COOKIE")))
- return SOAP_ERR;
- do
- { s = soap_decode_key(key, sizeof(key), s);
- s = soap_decode_val(val, sizeof(val), s);
- p = soap_set_cookie(soap, key, val, NULL, NULL);
- if (p)
- p->env = 1;
- } while (*s);
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_copy_cookies(struct soap *soap)
-{ struct soap_cookie *p, **q, *r;
- q = &r;
- for (p = soap->cookies; p; p = p->next)
- { if (!(*q = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- return r;
- **q = *p;
- if (p->name)
- { if (((*q)->name = (char*)SOAP_MALLOC(strlen(p->name)+1)))
- strcpy((*q)->name, p->name);
- }
- if (p->value)
- { if (((*q)->value = (char*)SOAP_MALLOC(strlen(p->value)+1)))
- strcpy((*q)->value, p->value);
- }
- if (p->domain)
- { if (((*q)->domain = (char*)SOAP_MALLOC(strlen(p->domain)+1)))
- strcpy((*q)->domain, p->domain);
- }
- if (p->path)
- { if (((*q)->path = (char*)SOAP_MALLOC(strlen(p->path)+1)))
- strcpy((*q)->path, p->path);
- }
- q = &(*q)->next;
- }
- *q = NULL;
- return r;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_free_cookies(struct soap *soap)
-{ struct soap_cookie *p;
- for (p = soap->cookies; p; p = soap->cookies)
- { soap->cookies = p->next;
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
-}
-
-/******************************************************************************/
-#endif /* WITH_COOKIES */
-
-/******************************************************************************/
-#ifdef WITH_GZIP
-#ifndef PALM_2
-static int
-soap_getgziphdr(struct soap *soap)
-{ int i;
- soap_wchar c, f = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get gzip header\n"));
- for (i = 0; i < 9; i++)
- { if ((int)(c = soap_get1(soap) == EOF))
- return soap->error = SOAP_EOF;
- if (i == 2)
- f = c;
- }
- if (f & 0x04) /* FEXTRA */
- { for (i = soap_get1(soap) | (soap_get1(soap) << 8); i; i--)
- if ((int)soap_get1(soap) == EOF)
- return soap->error = SOAP_EOF;
- }
- if (f & 0x08) /* FNAME */
- do
- c = soap_get1(soap);
- while (c && (int)c != EOF);
- if ((int)c != EOF && (f & 0x10)) /* FCOMMENT */
- do
- c = soap_get1(soap);
- while (c && (int)f != EOF);
- if ((int)c != EOF && (f & 0x01)) /* FHCRC */
- { if ((int)(c = soap_get1(soap)) != EOF)
- c = soap_get1(soap);
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_begin_recv(struct soap *soap)
-{ soap_wchar c;
- soap->error = SOAP_OK;
- soap_free(soap);
- soap_set_local_namespaces(soap);
- soap->version = 0; /* don't assume we're parsing SOAP content by default */
- soap_free_iht(soap);
- if ((soap->imode & SOAP_IO) == SOAP_IO_CHUNK)
- soap->omode |= SOAP_IO_CHUNK;
- soap->imode &= ~SOAP_IO;
- soap->mode = soap->imode;
- if (!soap->keep_alive)
- { soap->buflen = 0;
- soap->bufidx = 0;
- }
- if (!(soap->mode & SOAP_IO_KEEPALIVE))
- soap->keep_alive = 0;
- soap->ahead = 0;
- soap->peeked = 0;
- soap->level = 0;
- soap->part = SOAP_BEGIN;
- soap->alloced = 0;
- soap->count = 0;
- soap->length = 0;
- soap->cdata = 0;
- *soap->endpoint = '\0';
- soap->userid = NULL;
- soap->passwd = NULL;
- soap->action = NULL;
- soap->authrealm = NULL;
- soap->dime.chunksize = 0;
- soap->dime.buflen = 0;
- soap->dime.list = NULL;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
- soap->mime.list = NULL;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->mime.boundary = NULL;
- soap->mime.start = NULL;
-#ifdef WIN32
-#ifndef UNDER_CE
-#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket))
-#ifdef __BORLANDC__
- setmode((SOAP_SOCKET)soap->recvfd, O_BINARY);
-#else
- _setmode((SOAP_SOCKET)soap->recvfd, _O_BINARY);
-#endif
-#endif
-#endif
-#endif
-#ifdef WITH_ZLIB
- soap->mode &= ~SOAP_ENC_ZLIB;
- soap->zlib_in = SOAP_ZLIB_NONE;
- soap->zlib_out = SOAP_ZLIB_NONE;
- soap->d_stream.next_in = Z_NULL;
- soap->d_stream.avail_in = 0;
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- soap->z_ratio_in = 1.0;
- if (soap->fprepareinit)
- soap->fprepareinit(soap);
-#endif
- c = soap_getchar(soap);
-#ifdef WITH_GZIP
- if (c == 0x1F)
- { if (soap_getgziphdr(soap))
- return soap->error;
- if (inflateInit2(&soap->d_stream, -MAX_WBITS) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- soap->mode |= SOAP_ENC_ZLIB;
- soap->zlib_in = SOAP_ZLIB_GZIP;
- soap->z_crc = crc32(0L, NULL, 0);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- /* should not chunk over plain transport, so why bother to check? */
- /* if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) */
- /* soap->z_buflen = soap->bufidx; */
- /* else */
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = soap->buflen - soap->bufidx;
- soap->z_buflen = soap->buflen;
- soap->buflen = soap->bufidx;
- c = soap_getchar(soap);
- }
-#endif
- if (c == '-' && soap_get0(soap) == '-')
- soap->mode |= SOAP_ENC_MIME;
- else if ((c & 0xFFFC) == (SOAP_DIME_VERSION | SOAP_DIME_MB) && (soap_get0(soap) & 0xFFF0) == 0x20)
- soap->mode |= SOAP_ENC_DIME;
- else
- { while (soap_blank(c))
- c = soap_getchar(soap);
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- soap_unget(soap, c);
- if (c != '<' && !(soap->mode & (SOAP_ENC_DIME | SOAP_ENC_ZLIB)))
- { soap->mode &= ~SOAP_IO;
- if ((soap->error = soap->fparse(soap)))
- { soap->keep_alive = 0; /* force close later */
- return soap->error;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { soap->chunkbuflen = soap->buflen;
- soap->buflen = soap->bufidx;
- soap->chunksize = 0;
- }
- else if (soap->fpreparerecv && soap->buflen != soap->bufidx)
- soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx);
-#ifdef WITH_ZLIB
- if (soap->zlib_in)
- { /* fparse should not use soap_unget to push back last char */
-#ifdef WITH_GZIP
- c = soap_get1(soap);
- if (c == 0x1F)
- { if (soap_getgziphdr(soap))
- return soap->error;
- if (inflateInit2(&soap->d_stream, -MAX_WBITS) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- soap->z_crc = crc32(0L, NULL, 0);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
- }
- else
- { soap_revget1(soap);
-#else
- {
-#endif
- if (inflateInit(&soap->d_stream) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate initialized\n"));
- }
- soap->mode |= SOAP_ENC_ZLIB;
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = soap->buflen - soap->bufidx;
- soap->z_buflen = soap->buflen;
- soap->buflen = soap->bufidx;
- }
-#endif
- }
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_MIME)
- { if (soap_getmimehdr(soap))
- return soap->error;
- if (soap_get_header_attribute(soap, soap->mime.first->type, "application/dime"))
- soap->mode |= SOAP_ENC_DIME;
- }
- if (soap->mode & SOAP_ENC_DIME)
- { if (soap_getdimehdr(soap))
- return soap->error;
- if (soap->dime.flags & SOAP_DIME_CF)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked DIME SOAP message\n"));
- soap->dime.chunksize = soap->dime.size;
- if (soap->buflen - soap->bufidx >= soap->dime.chunksize)
- { soap->dime.buflen = soap->buflen;
- soap->buflen = soap->bufidx + soap->dime.chunksize;
- }
- else
- soap->dime.chunksize -= soap->buflen - soap->bufidx;
- }
- soap->count = soap->buflen - soap->bufidx;
- }
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_parse(struct soap *soap)
-{ char header[SOAP_HDRLEN], *s;
- unsigned short g = 0, k;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for response...\n"));
- *soap->endpoint = '\0';
- soap->length = 0;
- do
- { if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
- return soap->error;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP status: %s\n", soap->msgbuf));
- for (;;)
- { if (soap_getline(soap, header, SOAP_HDRLEN))
- return soap->error;
- if (!*header)
- break;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP header: %s\n", header));
- s = strchr(header, ':');
- if (s)
- { *s = '\0';
- do s++;
- while (*s && *s <= 32);
- if ((soap->error = soap->fparsehdr(soap, header, s)))
- return soap->error;
- }
- }
- if ((s = strchr(soap->msgbuf, ' ')))
- k = (unsigned short)soap_strtoul(s, NULL, 10);
- else
- k = 0;
- } while (k == 100);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Finished HTTP header parsing\n"));
- s = strstr(soap->msgbuf, "HTTP/");
- if (s && s[7] != '1')
- { if (soap->keep_alive == 1)
- soap->keep_alive = 0;
- if (k == 0 && (soap->omode & SOAP_IO) == SOAP_IO_CHUNK) /* k == 0 for HTTP request */
- { soap->imode |= SOAP_IO_CHUNK;
- soap->omode = (soap->omode & ~SOAP_IO) | SOAP_IO_STORE;
- }
- }
- if (soap->keep_alive < 0)
- soap->keep_alive = 1;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Keep alive connection = %d\n", soap->keep_alive));
- if (s && (((g = !strncmp(soap->msgbuf, "GET ", 4))) || !strncmp(soap->msgbuf, "POST ", 5)))
- { size_t m = strlen(soap->endpoint);
- size_t n = m + (s - soap->msgbuf) - 5 - (!g);
- if (n >= sizeof(soap->endpoint))
- n = sizeof(soap->endpoint) - 1;
- strncpy(soap->path, soap->msgbuf + 4 + (!g), n - m);
- soap->path[n - m] = '\0';
- strcat(soap->endpoint, soap->path);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint));
- if (g)
- { soap->error = soap->fget(soap);
- if (soap->error == SOAP_OK)
- soap->error = SOAP_STOP; /* prevents further processing */
- return soap->error;
- }
- return SOAP_OK;
- }
- if (k == 0 || (k >= 200 && k <= 299) || k == 400 || k == 500)
- return SOAP_OK;
- return soap_set_receiver_error(soap, "HTTP error", soap->msgbuf, k);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_parse_header(struct soap *soap, const char *key, const char *val)
-{ if (!soap_tag_cmp(key, "Host"))
- {
-#ifdef WITH_OPENSSL
- if (soap->imode & SOAP_ENC_SSL)
- strcpy(soap->endpoint, "https://");
- else
-#endif
- strcpy(soap->endpoint, "http://");
- strncat(soap->endpoint, val, sizeof(soap->endpoint) - 8);
- soap->endpoint[sizeof(soap->endpoint) - 1] = '\0';
- }
-#ifndef WITH_LEANER
- else if (!soap_tag_cmp(key, "Content-Type"))
- { if (soap_get_header_attribute(soap, val, "application/dime"))
- soap->mode |= SOAP_ENC_DIME;
- else if (soap_get_header_attribute(soap, val, "multipart/related"))
- { soap->mime.boundary = soap_strdup(soap, soap_get_header_attribute(soap, val, "boundary"));
- soap->mime.start = soap_strdup(soap, soap_get_header_attribute(soap, val, "start"));
- soap->mode |= SOAP_ENC_MIME;
- }
- }
-#endif
- else if (!soap_tag_cmp(key, "Content-Length"))
- soap->length = soap_strtoul(val, NULL, 10);
- else if (!soap_tag_cmp(key, "Content-Encoding"))
- { if (!soap_tag_cmp(val, "deflate"))
-#ifdef WITH_ZLIB
- soap->zlib_in = SOAP_ZLIB_DEFLATE;
-#else
- return SOAP_ZLIB_ERROR;
-#endif
- else if (!soap_tag_cmp(val, "gzip"))
-#ifdef WITH_GZIP
- soap->zlib_in = SOAP_ZLIB_GZIP;
-#else
- return SOAP_ZLIB_ERROR;
-#endif
- }
-#ifdef WITH_ZLIB
- else if (!soap_tag_cmp(key, "Accept-Encoding"))
- {
-#ifdef WITH_GZIP
- if (strchr(val, '*') || soap_get_header_attribute(soap, val, "gzip"))
- soap->zlib_out = SOAP_ZLIB_GZIP;
- else
-#endif
- if (strchr(val, '*') || soap_get_header_attribute(soap, val, "deflate"))
- soap->zlib_out = SOAP_ZLIB_DEFLATE;
- else
- soap->zlib_out = SOAP_ZLIB_NONE;
- }
-#endif
- else if (!soap_tag_cmp(key, "Transfer-Encoding"))
- { soap->mode &= ~SOAP_IO;
- if (!soap_tag_cmp(val, "chunked"))
- soap->mode |= SOAP_IO_CHUNK;
- }
- else if (!soap_tag_cmp(key, "Connection"))
- { if (!soap_tag_cmp(val, "keep-alive"))
- soap->keep_alive = -soap->keep_alive;
- else if (!soap_tag_cmp(val, "close"))
- soap->keep_alive = 0;
- }
-#ifndef WITH_LEAN
- else if (!soap_tag_cmp(key, "Authorization"))
- { if (!soap_tag_cmp(val, "Basic *"))
- { size_t n;
- char *s;
- soap_base642s(soap, val + 6, soap->tmpbuf, sizeof(soap->tmpbuf) - 1, &n);
- soap->tmpbuf[n] = '\0';
- if ((s = strchr(soap->tmpbuf, ':')))
- { *s = '\0';
- soap->userid = soap_strdup(soap, soap->tmpbuf);
- soap->passwd = soap_strdup(soap, s + 1);
- }
- }
- }
-#endif
- else if (!soap_tag_cmp(key, "SOAPAction"))
- { if (val[0] && val[1])
- { soap->action = soap_strdup(soap, val + 1);
- soap->action[strlen(soap->action) - 1] = '\0';
- }
- }
- else if (!soap_tag_cmp(key, "Location"))
- { strncpy(soap->endpoint, val, sizeof(soap->endpoint));
- soap->endpoint[sizeof(soap->endpoint) - 1] = '\0';
- }
- else if (!soap_tag_cmp(key, "WWW-Authenticate"))
- soap->authrealm = soap_strdup(soap, soap_get_header_attribute(soap, val+6, "realm"));
- else if (!soap_tag_cmp(key, "Expect"))
- { if (!soap_tag_cmp(val, "100-continue"))
- { if ((soap->error = soap->fposthdr(soap, "HTTP/1.1 100 Continue", NULL)))
- return soap->error;
- if ((soap->error = soap->fposthdr(soap, NULL, NULL)))
- return soap->error;
- }
- }
-#ifdef WITH_COOKIES
- else if (!soap_tag_cmp(key, "Cookie") || !soap_tag_cmp(key, "Set-Cookie"))
- soap_getcookies(soap, val);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_get_header_attribute(struct soap *soap, const char *line, const char *key)
-{ register const char *s = line;
- if (s)
- { while (*s)
- { register short flag;
- s = soap_decode_key(soap->tmpbuf, sizeof(soap->tmpbuf), s);
- flag = soap_tag_cmp(soap->tmpbuf, key);
- s = soap_decode_val(soap->tmpbuf, sizeof(soap->tmpbuf), s);
- if (!flag)
- return soap->tmpbuf;
- }
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_decode_key(char *buf, size_t len, const char *val)
-{ return soap_decode(buf, len, val, "=,;");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_decode_val(char *buf, size_t len, const char *val)
-{ if (*val != '=')
- { *buf = '\0';
- return val;
- }
- return soap_decode(buf, len, val + 1, ",;");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-soap_decode(char *buf, size_t len, const char *val, const char *sep)
-{ const char *s;
- char *t = buf;
- for (s = val; *s; s++)
- if (*s != ' ' && *s != '\t' && !strchr(sep, *s))
- break;
- if (*s == '"')
- { s++;
- while (*s && *s != '"' && --len)
- *t++ = *s++;
- }
- else
- { while (soap_notblank(*s) && !strchr(sep, *s) && --len)
- { if (*s == '%')
- { *t++ = ((s[1] >= 'A' ? (s[1] & 0x7) + 9 : s[1] - '0') << 4)
- + (s[2] >= 'A' ? (s[2] & 0x7) + 9 : s[2] - '0');
- s += 3;
- }
- else
- *t++ = *s++;
- }
- }
- *t = '\0';
- while (*s && !strchr(sep, *s))
- s++;
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_begin_out(struct soap *soap)
-{
-#ifndef WITH_LEANER
- size_t n = 0;
- if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && soap->mime.start)
- { const char *s;
- if (soap->mode & SOAP_ENC_DIME)
- s = "application/dime";
- else if (soap->version == 2)
- s = "application/soap+xml; charset=utf-8";
- else
- s = "text/xml; charset=utf-8";
- sprintf(soap->tmpbuf, "--%s\r\nContent-Type: %s\r\nContent-Transfer-Encoding: binary\r\nContent-ID: %s\r\n\r\n", soap->mime.boundary, s, soap->mime.start);
- n = strlen(soap->tmpbuf);
- if (soap_send_raw(soap, soap->tmpbuf, n))
- return soap->error;
- }
- if (soap->mode & SOAP_IO_LENGTH)
- soap->dime.size = soap->count; /* DIME in MIME correction */
- if (!(soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME))
- { if (soap_putdimehdr(soap))
- return soap->error;
- }
-#endif
- soap->part = SOAP_IN_ENVELOPE;
- return soap_element_begin_out(soap, "SOAP-ENV:Envelope", 0, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_end_out(struct soap *soap)
-{ if (soap_element_end_out(soap, "SOAP-ENV:Envelope"))
- return soap->error;
-#ifndef WITH_LEANER
- if ((soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME))
- { soap->dime.size = soap->count - soap->dime.size; /* DIME in MIME correction */
- sprintf(soap->id, soap->dime_id_format, 0);
- soap->dime.id = soap->id;
- if (soap->local_namespaces)
- { if (soap->local_namespaces[0].out)
- soap->dime.type = (char*)soap->local_namespaces[0].out;
- else
- soap->dime.type = (char*)soap->local_namespaces[0].ns;
- }
- soap->dime.options = NULL;
- soap->dime.flags = SOAP_DIME_MB | SOAP_DIME_ABSURI;
- if (!soap->dime.first)
- soap->dime.flags |= SOAP_DIME_ME;
- soap->count += 12 + ((strlen(soap->dime.id)+3)&(~3)) + ((strlen(soap->dime.type)+3)&(~3));
- }
- if (soap->mode & SOAP_ENC_DIME)
- return soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime.size&3);
-#endif
- soap->part = SOAP_END_ENVELOPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_begin_in(struct soap *soap)
-{ register struct Namespace *p;
- soap->part = SOAP_IN_ENVELOPE;
- if (soap_element_begin_in(soap, "SOAP-ENV:Envelope", 0))
- return soap->error = SOAP_VERSIONMISMATCH;
- p = soap->local_namespaces;
- if (p)
- { const char *ns = p[0].out;
- if (!ns)
- ns = p[0].ns;
- if (!strcmp(ns, soap_env1))
- { soap->version = 1; /* make sure we use SOAP 1.1 */
- if (p[1].out)
- SOAP_FREE(p[1].out);
- if ((p[1].out = (char*)SOAP_MALLOC(sizeof(soap_enc1))))
- strcpy(p[1].out, soap_enc1);
- }
- else if (!strcmp(ns, soap_env2))
- { soap->version = 2; /* make sure we use SOAP 1.2 */
- if (p[1].out)
- SOAP_FREE(p[1].out);
- if ((p[1].out = (char*)SOAP_MALLOC(sizeof(soap_enc2))))
- strcpy(p[1].out, soap_enc2);
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_end_in(struct soap *soap)
-{ if (soap_element_end_in(soap, "SOAP-ENV:Envelope"))
- return soap->error;
- soap->part = SOAP_END_ENVELOPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_begin_out(struct soap *soap)
-{ soap->part = SOAP_IN_BODY;
- if (soap->version == 1)
- soap->encoding = 1;
- if (soap_element(soap, "SOAP-ENV:Body", 0, NULL))
- return soap->error;
- if ((soap->mode & SOAP_XML_SEC) && soap_attribute(soap, "id", "_0"))
- return soap->error;
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_end_out(struct soap *soap)
-{ if (soap_element_end_out(soap, "SOAP-ENV:Body"))
- return soap->error;
- soap->part = SOAP_IN_BODY;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_begin_in(struct soap *soap)
-{ soap->part = SOAP_IN_BODY;
- return soap_element_begin_in(soap, "SOAP-ENV:Body", 0);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_end_in(struct soap *soap)
-{ if (soap_element_end_in(soap, "SOAP-ENV:Body"))
- return soap->error;
- soap->part = SOAP_END_BODY;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_header(struct soap *soap)
-{ if (soap_getheader(soap) && soap->error == SOAP_TAG_MISMATCH)
- soap->error = SOAP_OK;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_endpoint(struct soap *soap, const char *endpoint)
-{ register const char *s;
- register size_t i, n;
- *soap->endpoint = '\0';
- *soap->host = '\0';
- *soap->path = '\0';
- soap->port = 80;
- if (!endpoint || !*endpoint)
- return;
-#ifdef WITH_OPENSSL
- if (!strncmp(endpoint, "https:", 6))
- soap->port = 443;
-#endif
- strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint) - 1);
- s = strchr(endpoint, ':');
- if (s && s[1] == '/' && s[2] == '/')
- s += 3;
- else
- s = endpoint;
- n = strlen(s);
- if (n >= sizeof(soap->host))
- n = sizeof(soap->host) - 1;
-/* WR[ */
-#ifdef WITH_IPV6
- if ('[' == s[0])
- {
- s++;
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (']' == s[i])
- {
- s++;
- break;
- }
- }
- }
- else
- {
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (s[i] == '/' || s[i] == ':')
- break;
- }
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (s[i] == '/' || s[i] == ':')
- break;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- soap->host[i] = '\0';
- if (s[i] == ':')
- { soap->port = (int)atol(s + i + 1);
- for (i++; i < n; i++)
- if (s[i] == '/')
- break;
- }
- if (s[i])
- { strncpy(soap->path, s + i + 1, sizeof(soap->path));
- soap->path[sizeof(soap->path) - 1] = '\0';
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_connect(struct soap *soap, const char *endpoint, const char *action)
-{ return soap_connect_command(soap, SOAP_POST, endpoint, action);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_connect_command(struct soap *soap, int http_command, const char *endpoint, const char *action)
-{ char host[sizeof(soap->host)];
- int port;
- size_t count;
- soap->error = SOAP_OK;
- strcpy(host, soap->host); /* save to compare */
- port = soap->port; /* save to compare */
- soap_set_endpoint(soap, endpoint);
- if (action)
- soap->action = soap_strdup(soap, action);
- if (soap->fconnect)
- {
- if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port)))
- return soap->error;
- }
- else if (*soap->host)
- { soap->status = http_command;
- if (!soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port)
- { soap->keep_alive = 0; /* force close */
- soap_closesock(soap);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port));
- soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
- if (soap->error)
- return soap->error;
- soap->keep_alive = ((soap->omode & SOAP_IO_KEEPALIVE) != 0);
- }
- else if (!soap->keep_alive || !soap->fpoll || soap->fpoll(soap))
- { soap->keep_alive = 0; /* force close */
- soap_closesock(soap);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port));
- soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
- if (soap->error)
- return soap->error;
- }
- }
- if (soap_begin_send(soap))
- return soap->error;
- count = soap_count_attachments(soap);
- if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML) && endpoint)
- { unsigned int k = soap->mode;
- soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
- if ((k & SOAP_IO) != SOAP_IO_FLUSH)
- soap->mode |= SOAP_IO_BUFFER;
- if ((soap->error = soap->fpost(soap, endpoint, soap->host, soap->port, soap->path, action, count)))
- return soap->error;
- if ((k & SOAP_IO) == SOAP_IO_CHUNK)
- { if (soap_flush(soap))
- return soap->error;
- }
- soap->mode = k;
- }
- if (http_command != SOAP_POST)
- return soap_end_send(soap);
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_s2base64(struct soap *soap, const unsigned char *s, char *t, size_t n)
-{ register size_t i;
- register unsigned long m;
- register char *p;
- if (!t)
- t = (char*)soap_malloc(soap, (n + 2) / 3 * 4 + 1);
- if (!t)
- { soap->error = SOAP_EOM;
- return NULL;
- }
- p = t;
- t[0] = '\0';
- if (!s)
- return p;
- for (; n > 2; n -= 3, s += 3)
- { m = s[0];
- m = (m << 8) | s[1];
- m = (m << 8) | s[2];
- for (i = 4; i > 0; m >>= 6)
- t[--i] = soap_base64o[m & 0x3F];
- t += 4;
- }
- t[0] = '\0';
- if (n > 0)
- { m = 0;
- for (i = 0; i < n; i++)
- m = (m << 8) | *s++;
- for (; i < 3; i++)
- m <<= 8;
- for (i++; i > 0; m >>= 6)
- t[--i] = soap_base64o[m & 0x3F];
- for (i = 3; i > n; i--)
- t[i] = '=';
- t[4] = '\0';
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_base642s(struct soap *soap, const char *s, char *t, size_t l, size_t *n)
-{ register int i, j, c;
- register unsigned long m;
- char *p = t;
- if (n)
- *n = 0;
- for (;;)
- { for (i = 0; i < SOAP_BLKLEN; i++)
- { m = 0;
- j = 0;
- while (j < 4)
- { c = *s++;
- if (c == '=' || !c)
- { i *= 3;
- switch (j)
- { case 2:
- *t++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *t++ = (char)((m >> 10) & 0xFF);
- *t++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n += i;
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- }
- *t++ = (char)((m >> 16) & 0xFF);
- *t++ = (char)((m >> 8) & 0xFF);
- *t++ = (char)(m & 0xFF);
- if (l < 3)
- { if (n)
- *n += i;
- return p;
- }
- l -= 3;
- }
- if (n)
- *n += 3 * SOAP_BLKLEN;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_puthttphdr(struct soap *soap, int status, size_t count)
-{ register const char *s;
- register int err;
- if (status == SOAP_FILE)
- s = soap->http_content;
- else if (status == SOAP_HTML)
- s = "text/html; charset=utf-8";
-#ifndef WITH_LEANER
- else if (soap->mode & SOAP_ENC_DIME)
- s = "application/dime";
-#endif
- else if (soap->version == 2)
- s = "application/soap+xml; charset=utf-8";
- else
- s = "text/xml; charset=utf-8";
-#ifndef WITH_LEANER
- if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && soap->mime.start && soap->status != SOAP_GET)
- { sprintf(soap->tmpbuf, "multipart/related; boundary=\"%s\"; type=%s; start=\"%s\"", soap->mime.boundary, s, soap->mime.start);
- s = soap->tmpbuf;
- }
-#endif
- if ((err = soap->fposthdr(soap, "Content-Type", s)))
- return err;
-#ifdef WITH_ZLIB
- if (soap->omode & SOAP_ENC_ZLIB)
- {
-#ifdef WITH_GZIP
- err = soap->fposthdr(soap, "Content-Encoding", "gzip");
-#else
- err = soap->fposthdr(soap, "Content-Encoding", "deflate");
-#endif
- if (err)
- return err;
- }
-#endif
- if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)
- err = soap->fposthdr(soap, "Transfer-Encoding", "chunked");
- else if (count > 0)
- { sprintf(soap->tmpbuf, "%lu", (unsigned long)count);
- err = soap->fposthdr(soap, "Content-Length", soap->tmpbuf);
- }
- if (err)
- return err;
- return soap->fposthdr(soap, "Connection", soap->keep_alive ? "keep-alive" : "close");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_get(struct soap *soap)
-{ return SOAP_GET_METHOD;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_post(struct soap *soap, const char *endpoint, const char *host, int port, const char *path, const char *action, size_t count)
-{ register const char *s;
- register int err;
- if (soap->status == SOAP_GET)
- { s = "GET";
- count = 0;
- }
- else
- s = "POST";
-#ifndef PALM
- if (!endpoint || (strncmp(endpoint, "http:", 5) && strncmp(endpoint, "https:", 6) && strncmp(endpoint, "httpg:", 6)))
-#else
- if (!endpoint || (strncmp(endpoint, "http:", 5) && strncmp(endpoint, "https:", 6) && strncmp(endpoint, "httpg:", 6)) && strncmp(endpoint, "_beam:", 6) && strncmp(endpoint, "_local:", 7) && strncmp(endpoint, "_btobex:", 8))
-#endif
- return SOAP_OK;
- if (soap->proxy_host && strncmp(endpoint, "https:", 6))
- sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version);
- else
- sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, path, soap->http_version);
- if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return err;
- if (port != 80)
- sprintf(soap->tmpbuf, "%s:%d", host, port);
- else
- strcpy(soap->tmpbuf, host);
- if ((err = soap->fposthdr(soap, "Host", soap->tmpbuf))
- || (err = soap->fposthdr(soap, "User-Agent", "gSOAP/2.7"))
- || (err = soap_puthttphdr(soap, SOAP_OK, count)))
- return err;
-#ifdef WITH_ZLIB
-#ifdef WITH_GZIP
- if ((err = soap->fposthdr(soap, "Accept-Encoding", "gzip, deflate")))
-#else
- if ((err = soap->fposthdr(soap, "Accept-Encoding", "deflate")))
-#endif
- return err;
-#endif
-#ifndef WITH_LEAN
- if (soap->userid && soap->passwd && strlen(soap->userid) + strlen(soap->passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->userid, soap->passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((err = soap->fposthdr(soap, "Authorization", soap->tmpbuf)))
- return err;
- }
- if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((err = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
- return err;
- }
-#endif
-#ifdef WITH_COOKIES
-#ifdef WITH_OPENSSL
- if (soap_putcookies(soap, host, path, soap->ssl != NULL))
- return soap->error;
-#else
- if (soap_putcookies(soap, host, path, 0))
- return soap->error;
-#endif
-#endif
- if (action && soap->version == 1)
- { sprintf(soap->tmpbuf, "\"%s\"", action);
- if ((err = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf)))
- return err;
- }
- return soap->fposthdr(soap, NULL, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_send_header(struct soap *soap, const char *s)
-{ register const char *t;
- do
- { t = strchr(s, '\n'); /* disallow \n in HTTP headers */
- if (!t)
- t = s + strlen(s);
- if (soap_send_raw(soap, s, t - s))
- return soap->error;
- s = t + 1;
- } while (*t);
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_post_header(struct soap *soap, const char *key, const char *val)
-{ if (key)
- { if (http_send_header(soap, key))
- return soap->error;
- if (val && (soap_send_raw(soap, ": ", 2) || http_send_header(soap, val)))
- return soap->error;
- }
- return soap_send_raw(soap, "\r\n", 2);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_response(struct soap *soap, int status, size_t count)
-{ register int err;
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- {
- httpOutputEnable(soap->rpmreqid);
- }
-#endif /* WMW_RPM_IO */
-/* ]WR */
- if (!status || status == SOAP_HTML || status == SOAP_FILE)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "OK 200\n"));
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
-#else
-/* ]WR */
- if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */
-/* WR[ */
-#endif /* WMW_RPM_IO */
-/* ]WR */
- { sprintf(soap->tmpbuf, "HTTP/%s 200 OK", soap->http_version);
- if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return err;
- }
- else if ((err = soap->fposthdr(soap, "Status", "200 OK")))
- return err;
- }
- else if (status > 200 && status < 600)
- { sprintf(soap->tmpbuf, "HTTP/%s %d %s", soap->http_version, status, http_error(soap, status));
- if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return err;
- if (status == 401)
- { sprintf(soap->tmpbuf, "Basic realm=\"%s\"", soap->authrealm ? soap->authrealm : "gSOAP Web Service");
- if ((err = soap->fposthdr(soap, "WWW-Authenticate", soap->tmpbuf)))
- return err;
- }
- else if ((status >= 301 && status <= 303) || status == 307)
- { if ((err = soap->fposthdr(soap, "Location", soap->endpoint)))
- return err;
- }
- }
- else
- { const char *s = *soap_faultcode(soap);
- if (soap->version == 2 && !strcmp(s, "SOAP-ENV:Sender"))
- s = "400 Bad Request";
- else
- s = "500 Internal Server Error";
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error %s (status=%d)\n", s, status));
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
-#else
-/* ]WR */
- if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */
-/* WR[ */
-#endif /* WMW_RPM_IO */
-/* ]WR */
- { sprintf(soap->tmpbuf, "HTTP/%s %s", soap->http_version, s);
- if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return err;
- }
- else if ((err = soap->fposthdr(soap, "Status", s)))
- return err;
- }
- if ((err = soap->fposthdr(soap, "Server", "gSOAP/2.7"))
- || (err = soap_puthttphdr(soap, status, count)))
- return err;
-#ifdef WITH_COOKIES
- if (soap_putsetcookies(soap))
- return soap->error;
-#endif
- return soap->fposthdr(soap, NULL, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_response(struct soap *soap, int status)
-{ register size_t count;
- if (!(soap->omode & (SOAP_ENC_XML | SOAP_IO_STORE /* this tests for chunking too */))
- && (status == SOAP_HTML || status == SOAP_FILE))
- { soap->omode &= ~SOAP_IO;
- soap->omode |= SOAP_IO_STORE;
- }
- soap->status = status;
- count = soap_count_attachments(soap);
- if (soap_begin_send(soap))
- return soap->error;
- if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML))
- { register int n = soap->mode;
- soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
- if ((n & SOAP_IO) != SOAP_IO_FLUSH)
- soap->mode |= SOAP_IO_BUFFER;
- if ((soap->error = soap->fresponse(soap, status, count)))
- return soap->error;
- if ((n & SOAP_IO) == SOAP_IO_CHUNK)
- { if (soap_flush(soap))
- return soap->error;
- }
- soap->mode = n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-soap_set_validation_fault(struct soap *soap, const char *s, const char *t)
-{ sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element <%s>", s, t?t:SOAP_STR_EOS, soap->tag);
- return soap->msgbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_fault(struct soap *soap)
-{ const char **c = soap_faultcode(soap);
- const char **s = soap_faultstring(soap);
- if (!*c)
- { if (soap->version == 2)
- *c = "SOAP-ENV:Sender";
- else
- *c = "SOAP-ENV:Client";
- }
- if (*s)
- return;
- switch (soap->error)
- { case SOAP_CLI_FAULT:
- *s = "Client fault";
- break;
- case SOAP_SVR_FAULT:
- *s = "Server fault";
- break;
- case SOAP_TAG_MISMATCH:
- *s = soap_set_validation_fault(soap, "tag name or namespace mismatch", NULL);
- break;
- case SOAP_TAG_END:
- *s = soap_set_validation_fault(soap, "incorrect end tag", NULL);
- break;
- case SOAP_TYPE:
- *s = soap_set_validation_fault(soap, "data type mismatch ", soap->type);
- break;
- case SOAP_SYNTAX_ERROR:
- *s = "Well-formedness constraint violation";
- break;
- case SOAP_NO_TAG:
- *s = "No XML element tag found";
- break;
- case SOAP_MUSTUNDERSTAND:
- *c = "SOAP-ENV:MustUnderstand";
- sprintf(soap->msgbuf, "The data in element '%s' must be understood but cannot be handled", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_VERSIONMISMATCH:
- *c = "SOAP-ENV:VersionMismatch";
- *s = "SOAP version mismatch or invalid SOAP message";
- break;
- case SOAP_DATAENCODINGUNKNOWN:
- *c = "SOAP-ENV:DataEncodingUnknown";
- *s = "Unsupported SOAP data encoding";
- break;
- case SOAP_NAMESPACE:
- *s = soap_set_validation_fault(soap, "namespace mismatch", NULL);
- break;
- case SOAP_FATAL_ERROR:
- *s = "Fatal error";
- break;
- case SOAP_NO_METHOD:
- sprintf(soap->msgbuf, "Method '%s' not implemented: method name or namespace not recognized", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_GET_METHOD:
- *s = "HTTP GET method not implemented";
- break;
- case SOAP_EOM:
- *s = "Out of memory";
- break;
- case SOAP_IOB:
- *s = "Array index out of bounds";
- break;
- case SOAP_NULL:
- *s = soap_set_validation_fault(soap, "nil not allowed", NULL);
- break;
- case SOAP_MULTI_ID:
- *s = soap_set_validation_fault(soap, "multiple definitions of id ", soap->id);
- break;
- case SOAP_MISSING_ID:
- *s = soap_set_validation_fault(soap, "missing id for ref ", soap->id);
- break;
- case SOAP_HREF:
- *s = soap_set_validation_fault(soap, "incompatible object ref ", soap->id);
- break;
- case SOAP_FAULT:
- break;
- case SOAP_TCP_ERROR:
- *s = tcp_error(soap);
- break;
- case SOAP_HTTP_ERROR:
- *s = "HTTP error";
- break;
- case SOAP_SSL_ERROR:
- *s = "SSL error";
- break;
- case SOAP_PLUGIN_ERROR:
- *s = "Plugin registry error";
- break;
- case SOAP_DIME_MISMATCH:
- *s = "DIME version/transmission error";
- break;
- case SOAP_DIME_END:
- *s = "End of DIME error";
- break;
- case SOAP_DIME_ERROR:
- *s = "DIME format error";
- break;
- case SOAP_MIME_ERROR:
- *s = "MIME format error";
- break;
- case SOAP_ZLIB_ERROR:
-#ifdef WITH_ZLIB
- sprintf(soap->msgbuf, "Zlib/gzip error: '%s'", soap->d_stream.msg?soap->d_stream.msg:"");
- *s = soap->msgbuf;
-#else
- *s = "Zlib not installed for required message (de)compression";
-#endif
- break;
- case SOAP_REQUIRED:
- *s = soap_set_validation_fault(soap, "missing required attribute", NULL);
- break;
- case SOAP_PROHIBITED:
- *s = soap_set_validation_fault(soap, "prohibited attribute present", NULL);
- break;
- case SOAP_OCCURS:
- *s = soap_set_validation_fault(soap, "a min/maxOccurs violation was detected", NULL);
- break;
- case SOAP_LENGTH:
- *s = soap_set_validation_fault(soap, "content length violation", NULL);
- break;
- case SOAP_EOF:
- sprintf(soap->msgbuf, "End of file or no input: '%s'", soap_strerror(soap));
- *s = soap->msgbuf;
- break;
- default:
- if (soap->error > 200 && soap->error < 600)
- { sprintf(soap->msgbuf, "HTTP Error: '%s'", http_error(soap, soap->error));
- *s = soap->msgbuf;
- }
- else
- *s = "Unknown error code";
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send_fault(struct soap *soap)
-{ register int status = soap->error;
- if (status == SOAP_STOP)
- return status;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Sending back fault struct for error code %d\n", soap->error));
- soap->keep_alive = 0; /* to terminate connection */
- soap_set_fault(soap);
- if ((status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) && (!soap->fpoll || soap->fpoll(soap) == SOAP_OK))
- { soap->error = SOAP_OK;
- soap_serializeheader(soap);
- soap_serializefault(soap);
- soap_begin_count(soap);
- if (soap->mode & SOAP_IO_LENGTH)
- { soap_envelope_begin_out(soap);
- soap_putheader(soap);
- soap_body_begin_out(soap);
- soap_putfault(soap);
- soap_body_end_out(soap);
- soap_envelope_end_out(soap);
- }
- if (soap_response(soap, status)
- || soap_envelope_begin_out(soap)
- || soap_putheader(soap)
- || soap_body_begin_out(soap)
- || soap_putfault(soap)
- || soap_body_end_out(soap)
- || soap_envelope_end_out(soap))
- return soap_closesock(soap);
- soap_end_send(soap);
- }
- soap->error = status;
- return soap_closesock(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_fault(struct soap *soap)
-{ register int status = soap->error;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Receiving SOAP Fault\n"));
- soap->error = SOAP_OK;
- if (soap_getfault(soap))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Error: soap_get_soapfault() failed. Is this a SOAP message at all?\n"));
- *soap_faultcode(soap) = (soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client");
- soap->error = status;
- soap_set_fault(soap);
- }
- else
- { register const char *s = *soap_faultcode(soap);
- if (!soap_match_tag(soap, s, "SOAP-ENV:Server") || !soap_match_tag(soap, s, "SOAP-ENV:Receiver"))
- status = SOAP_SVR_FAULT;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:Client") || !soap_match_tag(soap, s, "SOAP-ENV:Sender"))
- status = SOAP_CLI_FAULT;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:MustUnderstand"))
- status = SOAP_MUSTUNDERSTAND;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:VersionMismatch"))
- status = SOAP_VERSIONMISMATCH;
- else
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Fault code %s\n", s));
- status = SOAP_FAULT;
- }
- if (soap_body_end_in(soap)
- || soap_envelope_end_in(soap)
- || soap_end_recv(soap))
- return soap_closesock(soap);
- soap->error = status;
- }
- return soap_closesock(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-soap_strerror(struct soap *soap)
-{ int err = soap->errnum;
- if (!err)
- err = soap_errno;
- if (err)
- {
-#ifndef UNDER_CE
- return strerror(err);
-#else
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)&soap->werrorstr, sizeof(soap->werrorstr), NULL);
- wcstombs(soap->errorstr, soap->werrorstr, sizeof(soap->errorstr));
- return soap->errorstr;
-#endif
- }
- return "Operation interrupted or timed out";
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_set_error(struct soap *soap, const char *faultcode, const char *faultstring, const char *faultdetail, int soaperror)
-{ *soap_faultcode(soap) = faultcode;
- *soap_faultstring(soap) = faultstring;
- if (faultdetail && *faultdetail)
- { register const char **s = soap_faultdetail(soap);
- if (s)
- *s = faultdetail;
- }
- return soap->error = soaperror;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_sender_error(struct soap *soap, const char *faultstring, const char *faultdetail, int soaperror)
-{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultstring, faultdetail, soaperror);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_receiver_error(struct soap *soap, const char *faultstring, const char *faultdetail, int soaperror)
-{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultstring, faultdetail, soaperror);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultstring, const char *faultdetail)
-{ char *s = NULL, *t = NULL;
- if (faultstring)
- s = soap_strdup(soap, faultstring);
- if (faultdetail)
- t = soap_strdup(soap, faultdetail);
- return soap_set_error(soap, faultcode, s, t, SOAP_FAULT);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
-{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultstring, faultdetail);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
-{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultstring, faultdetail);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_print_fault(struct soap *soap, FILE *fd)
-{ if (soap->error)
- { const char **s;
- if (!*soap_faultcode(soap))
- soap_set_fault(soap);
- fprintf(fd, "SOAP FAULT: %s\n\"%s\"\n", *soap_faultcode(soap), *soap_faultstring(soap));
- s = soap_faultdetail(soap);
- if (s && *s)
- fprintf(fd, "Detail: %s\n", *s);
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_print_fault_location(struct soap *soap, FILE *fd)
-{
-#ifndef WITH_LEAN
- int c;
- if (soap->error && soap->buflen > 0)
- { if (soap->bufidx == 0)
- soap->bufidx = 1;
- c = soap->buf[soap->bufidx - 1];
- soap->buf[soap->bufidx - 1] = '\0';
- if (soap->buflen - soap->bufidx > 1024)
- soap->buf[soap->bufidx + 1024] = '\0';
- else
- soap->buf[soap->buflen - 1] = '\0';
- fprintf(fd, "%s%c\n** HERE **\n", soap->buf, c);
- if (soap->bufidx < soap->buflen)
- fprintf(fd, "%s\n", soap->buf + soap->bufidx);
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_register_plugin_arg(struct soap *soap, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void *arg)
-{ register struct soap_plugin *p;
- register int r;
- if (!(p = (struct soap_plugin*)SOAP_MALLOC(sizeof(struct soap_plugin))))
- return soap->error = SOAP_EOM;
- p->id = NULL;
- p->data = NULL;
- p->fcopy = NULL;
- p->fdelete = NULL;
- r = fcreate(soap, p, arg);
- if (!r && p->fdelete)
- { p->next = soap->plugins;
- soap->plugins = p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Registered '%s' plugin\n", p->id));
- return SOAP_OK;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not register plugin '%s': plugin returned error %d (or fdelete callback not set)\n", p->id?p->id:"?", r));
- SOAP_FREE(p);
- return r;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void *
-fplugin(struct soap *soap, const char *id)
-{ register struct soap_plugin *p;
- for (p = soap->plugins; p; p = p->next)
- if (p->id == id || !strcmp(p->id, id))
- return p->data;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void *
-SOAP_FMAC2
-soap_lookup_plugin(struct soap *soap, const char *id)
-{ return soap->fplugin(soap, id);
-}
-#endif
-
-/******************************************************************************/
-#ifdef __cplusplus
-}
-#endif
-
+++ /dev/null
-/*
-
-stdsoap2.c[pp] 2.7.0d
-
-Runtime environment.
-
-gSOAP XML Web services tools
-Copyright (C) 2000-2004, Robert van Engelen, Genivia, Inc., All Rights Reserved.
-
-Contributors:
-
-Wind River Systems, Inc., for the following additions (marked WR[...]):
- - vxWorks compatible
- - Support for IPv6.
-
---------------------------------------------------------------------------------
-gSOAP public license.
-
-The contents of this file are subject to the gSOAP Public License Version 1.3
-(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.cs.fsu.edu/~engelen/soaplicense.html
-Software distributed under the License is distributed on an "AS IS" basis,
-WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
-for the specific language governing rights and limitations under the License.
-
-The Initial Developer of the Original Code is Robert A. van Engelen.
-Copyright (C) 2000-2004, Robert van Engelen, Genivia, Inc., All Rights Reserved.
---------------------------------------------------------------------------------
-GPL license.
-
-This program is free software; you can redistribute it and/or modify it under
-the terms of the GNU General Public License as published by the Free Software
-Foundation; either version 2 of the License, or (at your option) any later
-version.
-
-This program is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License along with
-this program; if not, write to the Free Software Foundation, Inc., 59 Temple
-Place, Suite 330, Boston, MA 02111-1307 USA
-
-Author contact information:
-engelen@genivia.com / engelen@acm.org
---------------------------------------------------------------------------------
-
-Installation note:
-
-Win32 build needs winsock.dll (Visual C++ "wsock32.lib")
-To do this in Visual C++ 6.0, go to "Project", "settings", select the "Link"
-tab (the project file needs to be selected in the file view) and add
-"wsock32.lib" to the "Object/library modules" entry
-
-On Mac OS X with gcc (GCC) 3.1 20020420 (prerelease) you MUST compile with
--fstack_check when using -O2 because gcc 3.1 has a bug that smashes the stack
-when locally allocated data exceeds 64K.
-
-*/
-
-#include "stdsoap2.h"
-
-#ifdef __cplusplus
-SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.7.0c 2004-09-27 12:00:00 GMT")
-extern "C" {
-#else
-SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.7.0c 2004-09-27 12:00:00 GMT")
-#endif
-
-/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale) */
-#ifndef SOAP_UNKNOWN_CHAR
-#define SOAP_UNKNOWN_CHAR (127)
-#endif
-
-/* EOF=-1 */
-#define SOAP_LT (soap_wchar)(-2) /* XML character '<' */
-#define SOAP_TT (soap_wchar)(-3) /* XML character '</' */
-#define SOAP_GT (soap_wchar)(-4) /* XML character '>' */
-#define SOAP_QT (soap_wchar)(-5) /* XML character '"' */
-#define SOAP_AP (soap_wchar)(-6) /* XML character ''' */
-
-#define soap_blank(c) ((c) >= 0 && (c) <= 32)
-#define soap_notblank(c) ((c) > 32)
-#define soap_hash_ptr(p) (((unsigned long)(p) >> 3) & (SOAP_PTRHASH - 1))
-
-static int soap_isxdigit(int);
-static soap_wchar soap_char(struct soap*);
-static soap_wchar soap_getchunkchar(struct soap*);
-static void soap_update_ptrs(struct soap*, char*, char*, long);
-static int soap_has_copies(struct soap*, const char*, const char*);
-static struct soap_ilist *soap_hlookup(struct soap*, const char*);
-static void soap_init_iht(struct soap*);
-static void soap_free_iht(struct soap*);
-static void soap_init_pht(struct soap*);
-static void soap_free_pht(struct soap*);
-static int soap_set_error(struct soap*, const char*, const char*, const char*, int);
-static const char *soap_set_validation_fault(struct soap*, const char*, const char*);
-static int soap_copy_fault(struct soap*, const char*, const char*, const char*);
-static int soap_getattrval(struct soap*, char*, size_t, soap_wchar);
-static void soap_set_local_namespaces(struct soap*);
-static int soap_isnumeric(struct soap*, const char*);
-static void *fplugin(struct soap*, const char*);
-static const char *soap_decode(char*, size_t, const char*, const char*);
-
-#ifndef WITH_LEAN
-static time_t soap_timegm(struct tm*);
-#endif
-
-#ifdef SOAP_DEBUG
-static void soap_init_logs(struct soap*);
-static void soap_close_logfile(struct soap*, int);
-static void soap_set_logfile(struct soap*, int, const char*);
-#endif
-
-#ifdef WITH_FAST
-static int soap_append_lab(struct soap*, const char*, size_t);
-#endif
-
-#ifndef WITH_LEANER
-static struct soap_multipart *soap_new_multipart(struct soap*, struct soap_multipart**, struct soap_multipart**, char*, size_t);
-static int soap_putdimefield(struct soap*, const char*, size_t);
-static char *soap_getdimefield(struct soap*, size_t);
-static void soap_select_mime_boundary(struct soap*);
-static int soap_valid_mime_boundary(struct soap*);
-#endif
-
-#ifdef WITH_GZIP
-static int soap_getgziphdr(struct soap*);
-#endif
-
-#ifdef WITH_OPENSSL
-static int ssl_auth_init(struct soap*);
-static int ssl_verify_callback(int, X509_STORE_CTX*);
-static int ssl_password(char*, int, int, void *);
-static const char *ssl_error(struct soap*, int);
-/* This callback is included for future references. It should not be deleted
-static DH *ssl_tmp_dh(SSL*, int, int);
-*/
-#endif
-
-static const char *soap_strerror(struct soap*);
-static const char *tcp_error(struct soap*);
-static const char *http_error(struct soap*, int);
-static int http_post(struct soap*, const char*, const char*, int, const char*, const char*, size_t);
-static int http_get(struct soap*);
-static int http_send_header(struct soap*, const char*);
-static int http_post_header(struct soap*, const char*, const char*);
-static int http_response(struct soap*, int, size_t);
-static int http_parse(struct soap*);
-static int http_parse_header(struct soap*, const char*, const char*);
-#ifndef MAC_CARBON
-static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr);
-static int tcp_connect(struct soap*, const char *endpoint, const char *host, int port);
-static int tcp_accept(struct soap*, int, struct sockaddr*, int*);
-static int tcp_disconnect(struct soap*);
-static int tcp_closesocket(struct soap*, SOAP_SOCKET);
-static int tcp_shutdownsocket(struct soap*, SOAP_SOCKET, int);
-static int fsend(struct soap*, const char*, size_t);
-static size_t frecv(struct soap*, char*, size_t);
-#endif
-
-/* WR[ */
-#ifdef VXWORKS
-static int vx_nonblocking = TRUE; /* ioctl argument */
-#endif
-/* ]WR */
-
-#if defined(PALM) && !defined(PALM_2)
-unsigned short errno;
-#endif
-
-#ifndef PALM_1
-static const char soap_env1[42] = "http://schemas.xmlsoap.org/soap/envelope/";
-static const char soap_enc1[42] = "http://schemas.xmlsoap.org/soap/encoding/";
-static const char soap_env2[40] = "http://www.w3.org/2003/05/soap-envelope";
-static const char soap_enc2[40] = "http://www.w3.org/2003/05/soap-encoding";
-static const char soap_rpc[35] = "http://www.w3.org/2003/05/soap-rpc";
-#endif
-
-#ifndef PALM_1
-const struct soap_double_nan soap_double_nan = {0xFFFFFFFF, 0xFFFFFFFF};
-static const char soap_base64o[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char soap_base64i[81] = "\76XXX\77\64\65\66\67\70\71\72\73\74\75XXXXXXX\00\01\02\03\04\05\06\07\10\11\12\13\14\15\16\17\20\21\22\23\24\25\26\27\30\31XXXXXX\32\33\34\35\36\37\40\41\42\43\44\45\46\47\50\51\52\53\54\55\56\57\60\61\62\63";
-#endif
-
-static const char soap_padding[3] = "\0\0";
-#define SOAP_STR_PADDING (soap_padding)
-#define SOAP_STR_EOS (soap_padding)
-
-#ifndef WITH_LEAN
-static const struct soap_code_map html_entity_codes[] = /* entities for XHTML parsing */
-{ { 160, "nbsp" },
- { 161, "iexcl" },
- { 162, "cent" },
- { 163, "pound" },
- { 164, "curren" },
- { 165, "yen" },
- { 166, "brvbar" },
- { 167, "sect" },
- { 168, "uml" },
- { 169, "copy" },
- { 170, "ordf" },
- { 171, "laquo" },
- { 172, "not" },
- { 173, "shy" },
- { 174, "reg" },
- { 175, "macr" },
- { 176, "deg" },
- { 177, "plusmn" },
- { 178, "sup2" },
- { 179, "sup3" },
- { 180, "acute" },
- { 181, "micro" },
- { 182, "para" },
- { 183, "middot" },
- { 184, "cedil" },
- { 185, "sup1" },
- { 186, "ordm" },
- { 187, "raquo" },
- { 188, "frac14" },
- { 189, "frac12" },
- { 190, "frac34" },
- { 191, "iquest" },
- { 192, "Agrave" },
- { 193, "Aacute" },
- { 194, "Acirc" },
- { 195, "Atilde" },
- { 196, "Auml" },
- { 197, "Aring" },
- { 198, "AElig" },
- { 199, "Ccedil" },
- { 200, "Egrave" },
- { 201, "Eacute" },
- { 202, "Ecirc" },
- { 203, "Euml" },
- { 204, "Igrave" },
- { 205, "Iacute" },
- { 206, "Icirc" },
- { 207, "Iuml" },
- { 208, "ETH" },
- { 209, "Ntilde" },
- { 210, "Ograve" },
- { 211, "Oacute" },
- { 212, "Ocirc" },
- { 213, "Otilde" },
- { 214, "Ouml" },
- { 215, "times" },
- { 216, "Oslash" },
- { 217, "Ugrave" },
- { 218, "Uacute" },
- { 219, "Ucirc" },
- { 220, "Uuml" },
- { 221, "Yacute" },
- { 222, "THORN" },
- { 223, "szlig" },
- { 224, "agrave" },
- { 225, "aacute" },
- { 226, "acirc" },
- { 227, "atilde" },
- { 228, "auml" },
- { 229, "aring" },
- { 230, "aelig" },
- { 231, "ccedil" },
- { 232, "egrave" },
- { 233, "eacute" },
- { 234, "ecirc" },
- { 235, "euml" },
- { 236, "igrave" },
- { 237, "iacute" },
- { 238, "icirc" },
- { 239, "iuml" },
- { 240, "eth" },
- { 241, "ntilde" },
- { 242, "ograve" },
- { 243, "oacute" },
- { 244, "ocirc" },
- { 245, "otilde" },
- { 246, "ouml" },
- { 247, "divide" },
- { 248, "oslash" },
- { 249, "ugrave" },
- { 250, "uacute" },
- { 251, "ucirc" },
- { 252, "uuml" },
- { 253, "yacute" },
- { 254, "thorn" },
- { 255, "yuml" },
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEAN
-static const struct soap_code_map h_error_codes[] =
-{
-#ifdef HOST_NOT_FOUND
- { HOST_NOT_FOUND, "Host not found" },
-#endif
-#ifdef TRY_AGAIN
- { TRY_AGAIN, "Try Again" },
-#endif
-#ifdef NO_RECOVERY
- { NO_RECOVERY, "No Recovery" },
-#endif
-#ifdef NO_DATA
- { NO_DATA, "No Data" },
-#endif
-#ifdef NO_ADDRESS
- { NO_ADDRESS, "No Address" },
-#endif
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEAN
-static const struct soap_code_map h_http_error_codes[] =
-{ { 201, "Created" },
- { 202, "Accepted" },
- { 203, "Non-Authoritative Information" },
- { 204, "No Content" },
- { 205, "Reset Content" },
- { 206, "Partial Content" },
- { 300, "Multiple Choices" },
- { 301, "Moved Permanently" },
- { 302, "Found" },
- { 303, "See Other" },
- { 304, "Not Modified" },
- { 305, "Use Proxy" },
- { 307, "Temporary Redirect" },
- { 400, "Bad Request" },
- { 401, "Unauthorized" },
- { 402, "Payment Required" },
- { 403, "Forbidden" },
- { 404, "Not Found" },
- { 405, "Method Not Allowed" },
- { 406, "Not Acceptable" },
- { 407, "Proxy Authentication Required" },
- { 408, "Request Time-out" },
- { 409, "Conflict" },
- { 410, "Gone" },
- { 411, "Length Required" },
- { 412, "Precondition Failed" },
- { 413, "Request Entity Too Large" },
- { 414, "Request-URI Too Large" },
- { 415, "Unsupported Media Type" },
- { 416, "Requested range not satisfiable" },
- { 417, "Expectation Failed" },
- { 500, "Internal Server Error" },
- { 501, "Not Implemented" },
- { 502, "Bad Gateway" },
- { 503, "Service Unavailable" },
- { 504, "Gateway Time-out" },
- { 505, "HTTP Version not supported" },
- { 0, NULL }
-};
-#endif
-
-#ifdef WITH_OPENSSL
-static const struct soap_code_map h_ssl_error_codes[] =
-{
-#define _SSL_ERROR(e) { e, #e }
- _SSL_ERROR(SSL_ERROR_SSL),
- _SSL_ERROR(SSL_ERROR_ZERO_RETURN),
- _SSL_ERROR(SSL_ERROR_WANT_READ),
- _SSL_ERROR(SSL_ERROR_WANT_WRITE),
- _SSL_ERROR(SSL_ERROR_WANT_CONNECT),
- _SSL_ERROR(SSL_ERROR_WANT_X509_LOOKUP),
- _SSL_ERROR(SSL_ERROR_SYSCALL),
- { 0, NULL }
-};
-#endif
-
-#ifndef WITH_LEANER
-static const struct soap_code_map mime_codes[] =
-{ { SOAP_MIME_7BIT, "7bit" },
- { SOAP_MIME_8BIT, "8bit" },
- { SOAP_MIME_BINARY, "binary" },
- { SOAP_MIME_QUOTED_PRINTABLE, "quoted-printable" },
- { SOAP_MIME_BASE64, "base64" },
- { SOAP_MIME_IETF_TOKEN, "ietf-token" },
- { SOAP_MIME_X_TOKEN, "x-token" },
- { 0, NULL }
-};
-#endif
-
-#ifdef WIN32
-static int tcp_done = 0;
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-fsend(struct soap *soap, const char *s, size_t n)
-{ register int nwritten;
-#if defined(__cplusplus) && !defined(WITH_LEAN)
- if (soap->os)
- { soap->os->write(s, n);
- if (soap->os->good())
- return SOAP_OK;
- return SOAP_EOF;
- }
-#endif
- while (n)
- { if (soap_valid_socket(soap->socket))
- {
-#ifndef WITH_LEAN
- if (soap->send_timeout)
- { struct timeval timeout;
- fd_set fd;
- if (soap->send_timeout > 0)
- { timeout.tv_sec = soap->send_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->send_timeout/1000000;
- timeout.tv_usec = -soap->send_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- for (;;)
- { register int r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- return SOAP_EOF;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- }
- }
-#endif
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- nwritten = SSL_write(soap->ssl, s, n);
- else
-#endif
-#ifndef PALM
- nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags);
-#else
- nwritten = send((SOAP_SOCKET)soap->socket, (void*)s, n, soap->socket_flags);
-#endif
- if (nwritten <= 0)
- {
-#ifdef WITH_OPENSSL
- int err;
- if (soap->ssl && (err = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- return SOAP_EOF;
-#endif
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EWOULDBLOCK && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- nwritten = 0; /* and call write() again */
- }
- }
- else
- {
-#ifdef WITH_FASTCGI
- nwritten = fwrite((void*)s, 1, n, stdout);
- fflush(stdout);
-#else
-#ifdef UNDER_CE
- nwritten = fwrite(s, 1, n, soap->sendfd);
-#else
-/* WR[ */
-#ifdef VXWORKS
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- {
- httpBlockPut(soap->rpmreqid, s, n);
- nwritten = n;
- }
- else
- {
- nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
- }
-#else
- nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
-#endif /* WMW_RPM_IO */
-#else
-/* ]WR */
- nwritten = write((SOAP_SOCKET)soap->sendfd, s, n);
-/* WR[ */
-#endif
-/* ]WR */
-#endif
-#endif
- if (nwritten <= 0)
- { if (soap_errno != SOAP_EINTR && soap_errno != SOAP_EWOULDBLOCK && soap_errno != SOAP_EAGAIN)
- { soap->errnum = soap_errno;
- return SOAP_EOF;
- }
- nwritten = 0; /* and call write() again */
- }
- }
- n -= nwritten;
- s += nwritten;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_flush_raw(struct soap *soap, const char *s, size_t n)
-{ if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- { register char *t;
- if (!(t = (char*)soap_push_block(soap, n)))
- return soap->error = SOAP_EOM;
- memcpy(t, s, n);
- if (soap->fpreparesend)
- return soap->fpreparesend(soap, s, n);
- return SOAP_OK;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { char t[16];
- sprintf(t, "\r\n%lX\r\n" + (soap->chunksize ? 0 : 2), (unsigned long)n);
- DBGMSG(SENT, t, strlen(t));
- if ((soap->error = soap->fsend(soap, t, strlen(t))))
- return soap->error;
- soap->chunksize += n;
- }
- DBGMSG(SENT, s, n);
- return soap->error = soap->fsend(soap, s, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_flush(struct soap *soap)
-{ if (soap->bufidx)
- {
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { soap->d_stream.next_in = (Byte*)soap->buf;
- soap->d_stream.avail_in = (unsigned int)soap->bufidx;
-#ifdef WITH_GZIP
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->bufidx);
-#endif
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating %u bytes\n", soap->d_stream.avail_in));
- if (deflate(&soap->d_stream, Z_NO_FLUSH) != Z_OK)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to deflate: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- if (!soap->d_stream.avail_out)
- { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN))
- return soap->error;
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- }
- } while (soap->d_stream.avail_in);
- }
- else
-#endif
- if (soap_flush_raw(soap, soap->buf, soap->bufidx))
- return soap->error;
- soap->bufidx = 0;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send_raw(struct soap *soap, const char *s, size_t n)
-{ if (!n)
- return SOAP_OK;
- if (soap->mode & SOAP_IO_LENGTH)
- { soap->count += n;
- if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE)
- return soap->fpreparesend(soap, s, n);
- return SOAP_OK;
- }
- if (soap->mode & SOAP_IO)
- { register size_t i = SOAP_BUFLEN - soap->bufidx;
- while (n >= i)
- { memcpy(soap->buf + soap->bufidx, s, i);
- soap->bufidx = SOAP_BUFLEN;
- if (soap_flush(soap))
- return soap->error;
- s += i;
- n -= i;
- i = SOAP_BUFLEN;
- }
- memcpy(soap->buf + soap->bufidx, s, n);
- soap->bufidx += n;
- return SOAP_OK;
- }
- return soap_flush_raw(soap, s, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send(struct soap *soap, const char *s)
-{ if (s)
- return soap_send_raw(soap, s, strlen(s));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send2(struct soap *soap, const char *s1, const char *s2)
-{ if (soap_send(soap, s1))
- return soap->error;
- return soap_send(soap, s2);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send3(struct soap *soap, const char *s1, const char *s2, const char *s3)
-{ if (soap_send(soap, s1)
- || soap_send(soap, s2))
- return soap->error;
- return soap_send(soap, s3);
-}
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static size_t
-frecv(struct soap *soap, char *s, size_t n)
-{ register int r;
- soap->errnum = 0;
-#if defined(__cplusplus) && !defined(WITH_LEAN)
- if (soap->is)
- { if (soap->is->good())
- return soap->is->read(s, n).gcount();
- return 0;
- }
-#endif
- if (soap_valid_socket(soap->socket))
- { for (;;)
- {
-#ifndef WITH_LEAN
- struct timeval timeout;
- fd_set fd;
- if (soap->recv_timeout)
- { if (soap->recv_timeout > 0)
- { timeout.tv_sec = soap->recv_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->recv_timeout/1000000;
- timeout.tv_usec = -soap->recv_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- for (;;)
- { r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r > 0)
- break;
- if (r == 0)
- return 0;
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
- }
-#endif
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { int err;
- r = SSL_read(soap->ssl, s, n);
- if ((err = SSL_get_error(soap->ssl, r)) == SSL_ERROR_NONE)
- return (size_t)r;
- if (err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- return 0;
- }
- else
-#endif
- { r = recv((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags);
- if (r >= 0)
- return (size_t)r;
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
-#ifndef WITH_LEAN
- { struct timeval timeout;
- fd_set fd;
- timeout.tv_sec = 0;
- timeout.tv_usec = 10000;
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r < 0 && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return 0;
- }
- }
-#endif
- }
- }
-#ifdef WITH_FASTCGI
- return fread(s, 1, n, stdin);
-#else
-#ifdef UNDER_CE
- return fread(s, 1, n, soap->recvfd);
-#else
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- r = httpBlockRead(soap->rpmreqid, s, n);
- else
- r = read(soap->recvfd, s, n);
- if (r >= 0)
- return r;
- return 0;
-#else
-/* ]WR */
- r = read((SOAP_SOCKET)soap->recvfd, s, n);
- if (r >= 0)
- return (size_t)r;
- soap->errnum = soap_errno;
- return 0;
-/* WR[ */
-#endif
-/* ]WR */
-#endif
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static soap_wchar
-soap_getchunkchar(struct soap *soap)
-{ if (soap->bufidx < soap->buflen)
- return soap->buf[soap->bufidx++];
- soap->bufidx = 0;
- soap->buflen = soap->chunkbuflen = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)soap->buflen));
- DBGMSG(RECV, soap->buf, soap->buflen);
- if (soap->buflen)
- return soap->buf[soap->bufidx++];
- return EOF;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_isxdigit(int c)
-{ switch (c)
- { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
- case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
- return 1;
- }
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_raw(struct soap *soap)
-{ register size_t ret;
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { if (soap->d_stream.next_out == Z_NULL)
- return EOF;
- if (soap->d_stream.avail_in || !soap->d_stream.avail_out)
- { register int r;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflating\n"));
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- r = inflate(&soap->d_stream, Z_NO_FLUSH);
- if (r == Z_OK || r == Z_STREAM_END)
- { soap->bufidx = 0;
- soap->buflen = SOAP_BUFLEN - soap->d_stream.avail_out;
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen);
- if (r == Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out;
- soap->d_stream.next_out = Z_NULL;
- }
- if (soap->buflen)
- { soap->count += soap->buflen;
- return SOAP_OK;
- }
- }
- else if (r != Z_BUF_ERROR)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate error: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- soap->d_stream.next_out = Z_NULL;
- return EOF;
- }
- }
-zlib_again:
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK && !soap->chunksize)
- { memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
- soap->buflen = soap->z_buflen;
- }
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) /* read HTTP chunked transfer */
- {
-chunk_again:
- if (soap->chunksize)
- { soap->buflen = ret = soap->frecv(soap, soap->buf, soap->chunksize > SOAP_BUFLEN ? SOAP_BUFLEN : soap->chunksize);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk: read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- soap->bufidx = 0;
- soap->chunksize -= ret;
- }
- else
- { register soap_wchar c;
- char *t, tmp[8];
- t = tmp;
- if (!soap->chunkbuflen)
- { soap->chunkbuflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- soap->bufidx = 0;
- if (!ret)
- return EOF;
- }
- else
- soap->bufidx = soap->buflen;
- soap->buflen = soap->chunkbuflen;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (%u %u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen));
- while (!soap_isxdigit((int)(c = soap_getchunkchar(soap))))
- if ((int)c == EOF)
- return EOF;
- do
- *t++ = (char)c;
- while (soap_isxdigit((int)(c = soap_getchunkchar(soap))) && t - tmp < 7);
- while ((int)c != EOF && c != '\n')
- c = soap_getchunkchar(soap);
- if ((int)c == EOF)
- return EOF;
- *t = '\0';
- soap->chunksize = soap_strtoul(tmp, &t, 16);
- if (!soap->chunksize)
- { soap->chunkbuflen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of chunked message\n"));
- while ((int)c != EOF && c != '\n')
- c = soap_getchunkchar(soap);
- return EOF;
- }
- soap->buflen = soap->bufidx + soap->chunksize;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to %u (%u %s)\n", (unsigned int)soap->buflen, (unsigned int)soap->bufidx, tmp));
- if (soap->buflen > soap->chunkbuflen)
- { soap->buflen = soap->chunkbuflen;
- soap->chunksize -= soap->buflen - soap->bufidx;
- soap->chunkbuflen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Passed end of buffer for chunked HTTP (%lu bytes left)\n", (unsigned long)(soap->buflen - soap->bufidx)));
- }
- else if (soap->chunkbuflen)
- soap->chunksize = 0;
- ret = soap->buflen - soap->bufidx;
- if (!ret)
- goto chunk_again;
- }
- }
- else
- { soap->bufidx = 0;
- soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes\n", (unsigned int)ret));
- DBGMSG(RECV, soap->buf, ret);
- }
- if (soap->fpreparerecv && (soap->error = soap->fpreparerecv(soap, soap->buf, ret)))
- return soap->error;
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { register int r;
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = (unsigned int)ret;
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- r = inflate(&soap->d_stream, Z_NO_FLUSH);
- if (r == Z_OK || r == Z_STREAM_END)
- { soap->bufidx = 0;
- soap->z_buflen = soap->buflen;
- soap->buflen = ret = SOAP_BUFLEN - soap->d_stream.avail_out;
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)soap->buflen);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %u bytes\n", (unsigned int)ret));
- if (!ret)
- goto zlib_again;
- if (r == Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_in = (float)soap->d_stream.total_in / (float)soap->d_stream.total_out;
- soap->d_stream.next_out = Z_NULL;
- }
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to inflate: (%d) %s\n", r, soap->d_stream.msg?soap->d_stream.msg:""));
- soap->d_stream.next_out = Z_NULL;
- return EOF;
- }
- }
-#endif
- soap->count += ret;
- return !ret;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv(struct soap *soap)
-{
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_DIME)
- { if (soap->dime.buflen)
- { char *s;
- int i;
- unsigned char tmp[12];
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME hdr for chunked DIME is in buffer\n"));
- soap->count += soap->dime.buflen - soap->buflen;
- soap->buflen = soap->dime.buflen;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Skip padding (%ld bytes)\n", -(long)soap->dime.size&3));
- for (i = -(long)soap->dime.size&3; i > 0; i--)
- { soap->bufidx++;
- if (soap->bufidx >= soap->buflen)
- if (soap_recv_raw(soap))
- return EOF;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME hdr for next chunk\n"));
- s = (char*)tmp;
- for (i = 12; i > 0; i--)
- { *s++ = soap->buf[soap->bufidx++];
- if (soap->bufidx >= soap->buflen)
- if (soap_recv_raw(soap))
- return EOF;
- }
- soap->dime.flags = tmp[0] & 0x7;
- soap->dime.size = ((size_t)tmp[8] << 24) | ((size_t)tmp[9] << 16) | ((size_t)tmp[10] << 8) | ((size_t)tmp[11]);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME chunk (%u bytes)\n", (unsigned int)soap->dime.size));
- if (soap->dime.flags & SOAP_DIME_CF)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "More chunking\n"));
- soap->dime.chunksize = soap->dime.size;
- if (soap->buflen - soap->bufidx >= soap->dime.size)
- { soap->dime.buflen = soap->buflen;
- soap->buflen = soap->bufidx + soap->dime.chunksize;
- }
- else
- soap->dime.chunksize -= soap->buflen - soap->bufidx;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Last chunk\n"));
- soap->dime.buflen = 0;
- soap->dime.chunksize = 0;
- }
- soap->count = soap->buflen - soap->bufidx;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%u bytes remaining\n", (unsigned int)soap->count));
- return SOAP_OK;
- }
- if (soap->dime.chunksize)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get next DIME hdr for chunked DIME (%u bytes chunk)\n", (unsigned int)soap->dime.chunksize));
- if (soap_recv_raw(soap))
- return EOF;
- if (soap->buflen - soap->bufidx >= soap->dime.chunksize)
- { soap->dime.buflen = soap->buflen;
- soap->count -= soap->buflen - soap->bufidx - soap->dime.chunksize;
- soap->buflen = soap->bufidx + soap->dime.chunksize;
- }
- else
- soap->dime.chunksize -= soap->buflen - soap->bufidx;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%lu bytes remaining, count=%u\n", (unsigned long)(soap->buflen-soap->bufidx), (unsigned int)soap->count));
- return SOAP_OK;
- }
- }
-#endif
- return soap_recv_raw(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_getchar(struct soap *soap)
-{ register soap_wchar c;
- if (soap->ahead)
- { c = soap->ahead;
- soap->ahead = 0;
- return c;
- }
- return soap_get1(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const struct soap_code_map*
-SOAP_FMAC2
-soap_code(const struct soap_code_map *map, const char *str)
-{ while (map->string)
- { if (!strcmp(str, map->string)) /* case sensitive */
- return map;
- map++;
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_int_code(const struct soap_code_map *map, const char *str, long other)
-{ while (map->string)
- { if (!soap_tag_cmp(str, map->string)) /* case insensitive */
- return map->code;
- map++;
- }
- return other;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_str_code(const struct soap_code_map *map, long code)
-{ while (map->code != code && map->string)
- map++;
- return map->string;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static soap_wchar
-soap_char(struct soap *soap)
-{ char tmp[8];
- register int i;
- register soap_wchar c;
- register char *s = tmp;
- for (i = 0; i < 7; i++)
- { c = soap_get1(soap);
- if (c == ';' || (int)c == EOF)
- break;
- *s++ = (char)c;
- }
- *s = '\0';
- if (*tmp == '#')
- { if (tmp[1] == 'x' || tmp[1] == 'X')
- return soap_strtol(tmp + 2, NULL, 16);
- return atol(tmp + 1);
- }
- if (!strcmp(tmp, "lt"))
- return '<';
- if (!strcmp(tmp, "gt"))
- return '>';
- if (!strcmp(tmp, "amp"))
- return '&';
- if (!strcmp(tmp, "quot"))
- return '"';
- if (!strcmp(tmp, "apos"))
- return '\'';
-#ifndef WITH_LEAN
- return (soap_wchar)soap_int_code(html_entity_codes, tmp, SOAP_UNKNOWN_CHAR);
-#else
- return SOAP_UNKNOWN_CHAR; /* use this to represent unknown code */
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_get(struct soap *soap)
-{ register soap_wchar c;
- c = soap->ahead;
- if (c)
- soap->ahead = 0;
- else
- c = soap_get1(soap);
- for (;;)
- { if (soap->cdata)
- { if (c == ']')
- { c = soap_get1(soap);
- if (c == ']')
- { soap->cdata = 0;
- soap_get1(soap); /* skip > */
- c = soap_get1(soap);
- }
- else
- { soap_revget1(soap);
- return ']';
- }
- }
- else
- return c;
- }
- switch (c)
- { case '<':
- do c = soap_get1(soap);
- while (soap_blank(c));
- if (c == '!' || c == '?' || c == '%')
- { if (c == '!')
- { c = soap_get1(soap);
- if (c == '[')
- { do c = soap_get1(soap);
- while ((int)c != EOF && c != '[');
- if ((int)c == EOF)
- break;
- soap->cdata = 1;
- c = soap_get1(soap);
- continue;
- }
- if (c == '-' && (c = soap_get1(soap)) == '-')
- { do
- { c = soap_get1(soap);
- if (c == '-' && (c = soap_get1(soap)) == '-')
- break;
- } while ((int)c != EOF);
- }
- }
- while ((int)c != EOF && c != '>')
- c = soap_get1(soap);
- if ((int)c == EOF)
- break;
- c = soap_get1(soap);
- continue;
- }
- if (c == '/')
- return SOAP_TT;
- soap_revget1(soap);
- return SOAP_LT;
- case '>':
- return SOAP_GT;
- case '"':
- return SOAP_QT;
- case '\'':
- return SOAP_AP;
- case '&':
- return soap_char(soap) | 0x80000000;
- }
- break;
- }
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_advance(struct soap *soap)
-{ register soap_wchar c;
- while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT)
- ;
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_skip(struct soap *soap)
-{ register soap_wchar c;
- do c = soap_get(soap);
- while (soap_blank(c));
- return c;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_move(struct soap *soap, long n)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving %ld bytes forward\n", (long)n));
- for (; n > 0; n--)
- if ((int)soap_getchar(soap) == EOF)
- return SOAP_EOF;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_tell(struct soap *soap)
-{ return soap->count - soap->buflen + soap->bufidx - (soap->ahead != 0);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pututf8(struct soap *soap, register unsigned long c)
-{ char tmp[16];
- if (c > 0 && c < 0x80)
- { *tmp = (char)c;
- return soap_send_raw(soap, tmp, 1);
- }
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { register char *t = tmp;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- *t = '\0';
- }
- else
-#endif
- sprintf(tmp, "&#%lu;", c);
- return soap_send(soap, tmp);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-soap_wchar
-SOAP_FMAC2
-soap_getutf8(struct soap *soap)
-{ register soap_wchar c, c1, c2, c3, c4;
- c = soap_get(soap);
- if (c < 0x80 || (soap->mode & SOAP_ENC_LATIN))
- return c;
- c1 = soap_get(soap);
- if (c1 < 0x80)
- { soap_unget(soap, c1);
- return c;
- }
- c1 &= 0x3F;
- if (c < 0xE0)
- return ((soap_wchar)(c & 0x1F) << 6) | c1;
- c2 = (soap_wchar)soap_get1(soap) & 0x3F;
- if (c < 0xF0)
- return ((soap_wchar)(c & 0x0F) << 12) | (c1 << 6) | c2;
- c3 = (soap_wchar)soap_get1(soap) & 0x3F;
- if (c < 0xF8)
- return ((soap_wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3;
- c4 = (soap_wchar)soap_get1(soap) & 0x3F;
- if (c < 0xFC)
- return ((soap_wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4;
- return ((soap_wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (soap_wchar)(soap_get1(soap) & 0x3F);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_puthex(struct soap *soap, const unsigned char *s, int n)
-{ /* TODO: serialize to DOM (as an option) using new soap_s2hex() */
- char d[2];
- register int i;
- for (i = 0; i < n; i++)
- { register int m = *s++;
- d[0] = (char)((m >> 4) + (m > 159 ? '7' : '0'));
- m &= 0x0F;
- d[1] = (char)(m + (m > 9 ? '7' : '0'));
- if (soap_send_raw(soap, d, 2))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-unsigned char*
-SOAP_FMAC2
-soap_gethex(struct soap *soap, int *n)
-{
-#ifdef WITH_FAST
- soap->labidx = 0;
- for (;;)
- { register char *s;
- register int i, k;
- if (soap_append_lab(soap, NULL, 0))
- return NULL;
- s = soap->labbuf + soap->labidx;
- k = soap->lablen - soap->labidx;
- soap->labidx = soap->lablen;
- for (i = 0; i < k; i++)
- { register char d1, d2;
- register soap_wchar c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- { d1 = (char)c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- d2 = (char)c;
- else
- { soap->error = SOAP_TYPE;
- return NULL;
- }
- }
- else
- { unsigned char *p;
- soap_unget(soap, c);
- if (n)
- *n = (int)(soap->lablen - k + i);
- p = (unsigned char*)soap_malloc(soap, soap->lablen - k + i);
- if (p)
- memcpy(p, soap->labbuf, soap->lablen - k + i);
- return p;
- }
- *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');
- }
- }
-#else
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { register int i;
- register char *s = (char*)soap_push_block(soap, SOAP_BLKLEN);
- if (!s)
- { soap_end_block(soap);
- return NULL;
- }
- for (i = 0; i < SOAP_BLKLEN; i++)
- { register char d1, d2;
- register soap_wchar c = soap_get(soap);
- if (soap_isxdigit(c))
- { d1 = (char)c;
- c = soap_get(soap);
- if (soap_isxdigit(c))
- d2 = (char)c;
- else
- { soap_end_block(soap);
- soap->error = SOAP_TYPE;
- return NULL;
- }
- }
- else
- { unsigned char *p;
- soap_unget(soap, c);
- if (n)
- *n = soap_size_block(soap, i);
- p = (unsigned char*)soap_save_block(soap, NULL, 0);
- return p;
- }
- *s++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0');
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putbase64(struct soap *soap, const unsigned char *s, int n)
-{ register int i;
- register unsigned long m;
- char d[4];
- if (!s)
- return SOAP_OK;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { if (!(soap->dom->data = soap_s2base64(soap, s, soap->dom->data, n)))
- return soap->error;
- return SOAP_OK;
- }
-#endif
- for (; n > 2; n -= 3, s += 3)
- { m = s[0];
- m = (m << 8) | s[1];
- m = (m << 8) | s[2];
- for (i = 4; i > 0; m >>= 6)
- d[--i] = soap_base64o[m & 0x3F];
- if (soap_send_raw(soap, d, 4))
- return soap->error;
- }
- if (n > 0)
- { m = 0;
- for (i = 0; i < n; i++)
- m = (m << 8) | *s++;
- for (; i < 3; i++)
- m <<= 8;
- for (i++; i > 0; m >>= 6)
- d[--i] = soap_base64o[m & 0x3F];
- for (i = 3; i > n; i--)
- d[i] = '=';
- if (soap_send_raw(soap, d, 4))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-unsigned char*
-SOAP_FMAC2
-soap_getbase64(struct soap *soap, int *n, int malloc_flag)
-{
-#ifdef WITH_FAST
- soap->labidx = 0;
- for (;;)
- { register int i, k;
- register char *s;
- if (soap_append_lab(soap, NULL, 2))
- return NULL;
- s = soap->labbuf + soap->labidx;
- k = 3 * ((soap->lablen - soap->labidx) / 3);
- soap->labidx = 3 * (soap->lablen / 3);
- if (!s)
- return NULL;
- for (i = 0; i < k; i += 3)
- { register unsigned long m = 0;
- register int j = 0;
- do
- { register soap_wchar c = soap_get(soap);
- if (c == '=' || c < 0)
- { unsigned char *p;
- switch (j)
- { case 2:
- *s++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *s++ = (char)((m >> 10) & 0xFF);
- *s++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n = (int)(soap->lablen - k + i);
- p = (unsigned char*)soap_malloc(soap, soap->lablen - k + i);
- if (p)
- memcpy(p, soap->labbuf, soap->lablen - k + i);
- if (c >= 0)
- { while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT)
- ;
- }
- soap_unget(soap, c);
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- } while (j < 4);
- *s++ = (char)((m >> 16) & 0xFF);
- *s++ = (char)((m >> 8) & 0xFF);
- *s++ = (char)(m & 0xFF);
- }
- }
-#else
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { register int i;
- register char *s = (char*)soap_push_block(soap, 3 * SOAP_BLKLEN); /* must be multiple of 3 */
- if (!s)
- { soap_end_block(soap);
- return NULL;
- }
- for (i = 0; i < SOAP_BLKLEN; i++)
- { register unsigned long m = 0;
- register int j = 0;
- do
- { register soap_wchar c = soap_get(soap);
- if (c == '=' || c < 0)
- { unsigned char *p;
- i *= 3;
- switch (j)
- { case 2:
- *s++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *s++ = (char)((m >> 10) & 0xFF);
- *s++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n = (int)soap_size_block(soap, i);
- p = (unsigned char*)soap_save_block(soap, NULL, 0);
- if (c >= 0)
- { while ((int)((c = soap_get(soap)) != EOF) && c != SOAP_LT && c != SOAP_TT)
- ;
- }
- soap_unget(soap, c);
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- } while (j < 4);
- *s++ = (char)((m >> 16) & 0xFF);
- *s++ = (char)((m >> 8) & 0xFF);
- *s++ = (char)(m & 0xFF);
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_strdup(struct soap *soap, const char *s)
-{ char *t = NULL;
- if (s && (t = (char*)soap_malloc(soap, strlen(s) + 1)))
- strcpy(t, s);
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_new_block(struct soap *soap)
-{ struct soap_blist *p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New block sequence (prev=%p)\n", soap->blist));
- if (!(p = (struct soap_blist*)SOAP_MALLOC(sizeof(struct soap_blist))))
- return SOAP_EOM;
- p->next = soap->blist;
- p->ptr = NULL;
- p->size = 0;
- soap->blist = p;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_push_block(struct soap *soap, size_t n)
-{ char *p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push block of %u bytes (%u bytes total)\n", (unsigned int)n, (unsigned int)soap->blist->size + (unsigned int)n));
- if (!(p = (char*)SOAP_MALLOC(n + sizeof(char*) + sizeof(size_t))))
- { soap->error = SOAP_EOM;
- return NULL;
- }
- *(char**)p = soap->blist->ptr;
- *(size_t*)(p + sizeof(char*)) = n;
- soap->blist->ptr = p;
- soap->blist->size += n;
- return p + sizeof(char*) + sizeof(size_t);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_pop_block(struct soap *soap)
-{ char *p;
- if (!soap->blist->ptr)
- return;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pop block\n"));
- p = soap->blist->ptr;
- soap->blist->size -= *(size_t*)(p + sizeof(char*));
- soap->blist->ptr = *(char**)p;
- SOAP_FREE(p);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_update_ptrs(struct soap *soap, char *start, char *end, long offset)
-{ int i;
- register struct soap_ilist *ip;
- register struct soap_flist *fp;
- register void *p, **q;
- for (i = 0; i < SOAP_IDHASH; i++)
- for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr && (char*)ip->ptr >= start && (char*)ip->ptr < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", ip->id, ip->ptr, (char*)ip->ptr + offset));
- ip->ptr = (char*)ip->ptr + offset;
- }
- for (q = &ip->link; q; q = (void**)p)
- { p = *q;
- if (p && (char*)p >= start && (char*)p < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Link update id='%s' %p\n", ip->id, p));
- *q = (char*)p + offset;
- }
- }
- for (q = &ip->copy; q; q = (void**)p)
- { p = *q;
- if (p && (char*)p >= start && (char*)p < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy chain update id='%s' %p\n", ip->id, p));
- *q = (char*)p + offset;
- }
- }
- for (fp = ip->flist; fp; fp = fp->next)
- { if ((char*)fp->ptr >= start && (char*)fp->ptr < end)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy list update id='%s' %p\n", ip->id, fp));
- fp->ptr = (char*)fp->ptr + offset;
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-soap_has_copies(struct soap *soap, register const char *start, register const char *end)
-{ register int i;
- register struct soap_ilist *ip;
- register struct soap_flist *fp;
- register const char *p;
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = ip->next)
- { for (p = (const char*)ip->copy; p; p = *(const char**)p)
- if (p >= start && p < end)
- return SOAP_ERR;
- for (fp = ip->flist; fp; fp = fp->next)
- if ((const char*)fp->ptr >= start && (const char*)fp->ptr < end)
- return SOAP_ERR;
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_resolve(struct soap *soap)
-{ register int i;
- register struct soap_ilist *ip;
- register struct soap_flist *fp;
- short flag;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr)
- { register void *p, **q, *r;
- q = (void**)ip->link;
- ip->link = NULL;
- r = ip->ptr;
- DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing link chain to resolve id='%s'\n", ip->id));
- while (q)
- { p = *q;
- *q = r;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "... link %p -> %p\n", q, r));
- q = (void**)p;
- }
- }
- else if (*ip->id == '#')
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Missing data for id='%s'\n", ip->id));
- strcpy(soap->id, ip->id + 1);
- return soap->error = SOAP_MISSING_ID;
- }
- }
- }
- do
- { flag = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution phase\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->ptr && !soap_has_copies(soap, (const char*)ip->ptr, (const char*)ip->ptr + ip->size))
- { if (ip->copy)
- { register void *p, **q = (void**)ip->copy;
- DBGLOG(TEST, if (q) SOAP_MESSAGE(fdebug, "Traversing copy chain to resolve id='%s'\n", ip->id));
- ip->copy = NULL;
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... copy %p -> %p (%u bytes)\n", ip->ptr, q, (unsigned int)ip->size));
- p = *q;
- memcpy(q, ip->ptr, ip->size);
- q = (void**)p;
- } while (q);
- flag = 1;
- }
- for (fp = ip->flist; fp; fp = ip->flist)
- { register unsigned int k = fp->level;
- register void *p = ip->ptr;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving forwarded data type=%d location=%p level=%u,%u id='%s'\n", ip->type, p, ip->level, fp->level, ip->id));
- while (ip->level < k)
- { register void **q = (void**)soap_malloc(soap, sizeof(void*));
- if (!q)
- return soap->error;
- *q = p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level, new location=%p holds=%p...\n", q, *q));
- p = (void*)q;
- k--;
- }
- if (fp->fcopy)
- fp->fcopy(soap, ip->type, fp->type, fp->ptr, p, ip->size);
- else
- soap_fcopy(soap, ip->type, fp->type, fp->ptr, p, ip->size);
- ip->flist = fp->next;
- SOAP_FREE(fp);
- flag = 1;
- }
- }
- }
- }
- } while (flag);
-#ifdef SOAP_DEBUG
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = ip->next)
- { if (ip->copy || ip->flist)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution error: forwarded data for id='%s' could not be propagated, please report this problem to the developers\n", ip->id));
- }
- }
- }
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolution done\n"));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_size_block(struct soap *soap, size_t n)
-{ if (soap->blist->ptr)
- { soap->blist->size -= *(size_t*)(soap->blist->ptr + sizeof(char*)) - n;
- *(size_t*)(soap->blist->ptr + sizeof(char*)) = n;
- }
- return soap->blist->size;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_first_block(struct soap *soap)
-{ char *p, *q, *r;
- p = soap->blist->ptr;
- if (!p)
- return NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "First block\n"));
- r = NULL;
- do
- { q = *(char**)p;
- *(char**)p = r;
- r = p;
- p = q;
- } while (p);
- soap->blist->ptr = r;
- return r + sizeof(char*) + sizeof(size_t);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_next_block(struct soap *soap)
-{ char *p;
- p = soap->blist->ptr;
- if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Next block\n"));
- soap->blist->ptr = *(char**)p;
- SOAP_FREE(p);
- if (soap->blist->ptr)
- return soap->blist->ptr + sizeof(char*) + sizeof(size_t);
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_block_size(struct soap *soap)
-{ return *(size_t*)(soap->blist->ptr + sizeof(char*));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_end_block(struct soap *soap)
-{ struct soap_blist *bp;
- char *p, *q;
- bp = soap->blist;
- if (bp)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of block sequence, free all remaining blocks\n"));
- for (p = bp->ptr; p; p = q)
- { q = *(char**)p;
- SOAP_FREE(p);
- }
- soap->blist = bp->next;
- SOAP_FREE(bp);
- }
- DBGLOG(TEST, if (soap->blist) SOAP_MESSAGE(fdebug, "Restore previous block sequence\n"));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_save_block(struct soap *soap, char *p, int flag)
-{ register size_t n;
- register char *q, *s;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Save all blocks in contiguous memory space of %u bytes (%p->%p)\n", (unsigned int)soap->blist->size, soap->blist->ptr, p));
- if (soap->blist->size)
- { if (!p)
- p = (char*)soap_malloc(soap, soap->blist->size);
- if (p)
- { for (s = p, q = soap_first_block(soap); q; q = soap_next_block(soap))
- { n = soap_block_size(soap);
- if (flag)
- soap_update_ptrs(soap, q, q + n, (long)s - (long)q); /* pointers s and q may or may not be related */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copy %u bytes from %p to %p\n", (unsigned int)n, q, s));
- memcpy(s, q, n);
- s += n;
- }
- }
- else
- soap->error = SOAP_EOM;
- }
- soap_end_block(soap);
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsize(struct soap *soap, const char *type, int size)
-{ return soap_putsizes(soap, type, &size, 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsizes(struct soap *soap, const char *type, const int *size, int dim)
-{ return soap_putsizesoffsets(soap, type, size, NULL, dim);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putsizesoffsets(struct soap *soap, const char *type, const int *size, const int *offset, int dim)
-{ int i;
- if (!type)
- return NULL;
- if (soap->version == 2)
- { sprintf(soap->type, "%s[%d", type, size[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), " %d", size[i]);
- }
- else
- { if (offset)
- { sprintf(soap->type, "%s[%d", type, size[0] + offset[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), ",%d", size[i] + offset[i]);
- }
- else
- { sprintf(soap->type, "%s[%d", type, size[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->type + strlen(soap->type), ",%d", size[i]);
- }
- strcat(soap->type, "]");
- }
- return soap->type;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putoffset(struct soap *soap, int offset)
-{ return soap_putoffsets(soap, &offset, 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_putoffsets(struct soap *soap, const int *offset, int dim)
-{ register int i;
- sprintf(soap->arrayOffset, "[%d", offset[0]);
- for (i = 1; i < dim; i++)
- sprintf(soap->arrayOffset + strlen(soap->arrayOffset), ",%d", offset[i]);
- strcat(soap->arrayOffset, "]");
- return soap->arrayOffset;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_size(const int *size, int dim)
-{ register int i, n = size[0];
- for (i = 1; i < dim; i++)
- n *= size[i];
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getoffsets(const char *attr, const int *size, int *offset, int dim)
-{ register int i, j = 0;
- if (offset)
- for (i = 0; i < dim && attr && *attr; i++)
- { attr++;
- j *= size[i];
- j += offset[i] = (int)atol(attr);
- attr = strchr(attr, ',');
- }
- else
- for (i = 0; i < dim && attr && *attr; i++)
- { attr++;
- j *= size[i];
- j += (int)atol(attr);
- attr = strchr(attr, ',');
- }
- return j;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getsize(const char *attr1, const char *attr2, int *j)
-{ register int n, k;
- char *s;
- *j = 0;
- if (!*attr1)
- return -1;
- n = 1;
- do
- { attr1++;
- k = (int)soap_strtol(attr1, &s, 10);
- n *= k;
- if (k < 0 || n > SOAP_MAXARRAYSIZE || s == attr1)
- return -1;
- attr1 = strchr(s, ',');
- if (!attr1)
- attr1 = strchr(s, ' ');
- if (attr2 && *attr2)
- { attr2++;
- *j *= k;
- k = (int)soap_strtol(attr2, &s, 10);
- *j += k;
- if (k < 0)
- return -1;
- attr2 = s;
- }
- } while (attr1 && *attr1 != ']');
- return n - *j;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getsizes(const char *attr, int *size, int dim)
-{ register int i, k, n;
- if (!*attr)
- return -1;
- i = strlen(attr);
- n = 1;
- do
- { for (i = i-1; i >= 0; i--)
- if (attr[i] == '[' || attr[i] == ',' || attr[i] == ' ')
- break;
- k = (int)atol(attr + i + 1);
- n *= size[--dim] = k;
- if (k < 0 || n > SOAP_MAXARRAYSIZE)
- return -1;
- } while (i >= 0 && attr[i] != '[');
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getposition(const char *attr, int *pos)
-{ register int i, n;
- if (!*attr)
- return -1;
- n = 0;
- i = 1;
- do
- { pos[n++] = (int)atol(attr + i);
- while (attr[i] && attr[i] != ',' && attr[i] != ']')
- i++;
- if (attr[i] == ',')
- i++;
- } while (n < SOAP_MAXDIMS && attr[i] && attr[i] != ']');
- return n;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_push_namespace(struct soap *soap, const char *id, const char *ns)
-{ register struct soap_nlist *np;
- register struct Namespace *p;
- np = (struct soap_nlist*)SOAP_MALLOC(sizeof(struct soap_nlist) + strlen(id));
- if (!np)
- return soap->error = SOAP_EOM;
- np->next = soap->nlist;
- soap->nlist = np;
- strcpy(np->id, id);
- np->level = soap->level;
- np->index = -1;
- np->ns = NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns));
- p = soap->local_namespaces;
- if (p)
- { register short i = 0;
- for (; p->id; p++, i++)
- { if (p->ns && !strcmp(ns, p->ns))
- { if (p->out)
- { SOAP_FREE(p->out);
- p->out = NULL;
- }
- break;
- }
- if (p->out)
- { if (!SOAP_STRCMP(ns, p->out))
- break;
- }
- else if (p->in)
- { if (!soap_tag_cmp(ns, p->in))
- { if ((p->out = (char*)SOAP_MALLOC(strlen(ns) + 1)))
- strcpy(p->out, ns);
- break;
- }
- }
- }
- if (p && p->id)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id));
- np->index = i;
- }
- }
- if (!p || !p->id)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns));
- np->ns = (char*)SOAP_MALLOC(strlen(ns) + 1);
- if (!np->ns)
- return soap->error = SOAP_EOM;
- strcpy(np->ns, ns);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_pop_namespace(struct soap *soap)
-{ register struct soap_nlist *np;
- while (soap->nlist && soap->nlist->level >= soap->level)
- { np = soap->nlist->next;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Popped namespace binding (level=%u) '%s'\n", soap->level, soap->nlist->id));
- if (soap->nlist->ns)
- SOAP_FREE(soap->nlist->ns);
- SOAP_FREE(soap->nlist);
- soap->nlist = np;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_namespace(struct soap *soap, const char *id1, const char *id2, int n1, int n2)
-{ register struct soap_nlist *np = soap->nlist;
- while (np && (strncmp(np->id, id1, n1) || np->id[n1]))
- np = np->next;
- if (np)
- { if (np->index < 0 || (np->index >= 0 && soap->local_namespaces[np->index].id && (strncmp(soap->local_namespaces[np->index].id, id2, n2) || soap->local_namespaces[np->index].id[n2])))
- return SOAP_NAMESPACE;
- return SOAP_OK;
- }
- if (n1 == 3 && n1 == n2 && !strcmp(id1, "xml") && !strcmp(id1, id2))
- return SOAP_OK;
- return SOAP_SYNTAX_ERROR;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_tag_cmp(const char *s, const char *t)
-{ for (;;)
- { register int c1 = *s;
- register int c2 = *t;
- if (!c1 || c1 == '"')
- break;
- if (c2 != '-')
- { if (c1 != c2)
- { if (c1 >= 'A' && c1 <= 'Z')
- c1 += 'a' - 'A';
- if (c2 >= 'A' && c2 <= 'Z')
- c2 += 'a' - 'A';
- }
- if (c1 != c2)
- { if (c2 != '*')
- return 1;
- c2 = *++t;
- if (!c2)
- return 0;
- if (c2 >= 'A' && c2 <= 'Z')
- c2 += 'a' - 'A';
- for (;;)
- { c1 = *s;
- if (!c1 || c1 == '"')
- break;
- if (c1 >= 'A' && c1 <= 'Z')
- c1 += 'a' - 'A';
- if (c1 == c2)
- if (!soap_tag_cmp(s + 1, t + 1))
- return 0;
- s++;
- }
- break;
- }
- }
- s++;
- t++;
- }
- if (*t == '*' && !t[1])
- return 0;
- return *t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_tag(struct soap *soap, const char *tag1, const char *tag2)
-{ register const char *s, *t;
- if (!tag1 || !tag2 || !*tag2)
- return SOAP_OK;
- s = strchr(tag1, ':');
- t = strchr(tag2, ':');
- if (t)
- { if (s)
- { if (t[1] && SOAP_STRCMP(s + 1, t + 1))
- return SOAP_TAG_MISMATCH;
- if (t != tag2 && soap_match_namespace(soap, tag1, tag2, s - tag1, t - tag2))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
- return SOAP_TAG_MISMATCH;
- }
- }
- else if (SOAP_STRCMP(tag1, t + 1))
- return SOAP_TAG_MISMATCH;
- else if (t != tag2 && soap_match_namespace(soap, tag1, tag2, 0, t - tag2))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags '%s' and '%s' match but namespaces differ\n", tag1, tag2));
- return SOAP_TAG_MISMATCH;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags and (default) namespaces match: '%s' '%s'\n", tag1, tag2));
- return SOAP_OK;
- }
- if (s)
- { if (SOAP_STRCMP(s + 1, tag2))
- return SOAP_TAG_MISMATCH;
- }
- else if (SOAP_STRCMP(tag1, tag2))
- return SOAP_TAG_MISMATCH;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Tags match: '%s' '%s'\n", tag1, tag2));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_match_array(struct soap *soap, const char *type)
-{ if (*soap->arrayType)
- if (soap_match_tag(soap, soap->arrayType, type)
- && soap_match_tag(soap, soap->arrayType, "xsd:anyType")
- && soap_match_tag(soap, soap->arrayType, "xsd:ur-type")
- )
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array type mismatch: '%s' '%s'\n", soap->arrayType, type));
- return SOAP_TAG_MISMATCH;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-
-#ifdef WITH_OPENSSL
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_server_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *dhfile, const char *randfile, const char *sid)
-{ int err;
- soap->keyfile = keyfile;
- soap->password = password;
- soap->cafile = cafile;
- soap->capath = capath;
- if (dhfile)
- { soap->dhfile = dhfile;
- soap->rsa = 0;
- }
- else
- { soap->dhfile = NULL;
- soap->rsa = 1;
- }
- soap->randfile = randfile;
- soap->require_client_auth = (flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION);
- if (!(err = soap->fsslauth(soap)))
- if (sid)
- SSL_CTX_set_session_id_context(soap->ctx, (unsigned char*)sid, strlen(sid));
- return err;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_client_context(struct soap *soap, unsigned short flags, const char *keyfile, const char *password, const char *cafile, const char *capath, const char *randfile)
-{ soap->keyfile = keyfile;
- soap->password = password;
- soap->cafile = cafile;
- soap->capath = capath;
- soap->dhfile = NULL;
- soap->rsa = 0;
- soap->randfile = randfile;
- soap->require_server_auth = (flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION);
- return soap->fsslauth(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static void
-ssl_init()
-{ static int done = 0;
- if (!done)
- { done = 1;
- SSL_library_init();
-#ifndef WITH_LEAN
- SSL_load_error_strings();
-#endif
- if (!RAND_load_file("/dev/urandom", 1024))
- { int r;
-#ifdef HAVE_RAND_R
- unsigned int s = (unsigned int)time(NULL);
-#endif
- char buf[SOAP_BUFLEN];
- RAND_seed(buf, sizeof(buf));
- while (!RAND_status())
- {
-#ifdef HAVE_RAND_R
- r = rand_r(&s);
-#else
- r = rand();
-#endif
- RAND_seed(&r, sizeof(int));
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char *
-ssl_error(struct soap *soap, int ret)
-{ int err = SSL_get_error(soap->ssl, ret);
- const char *msg = soap_str_code(h_ssl_error_codes, err);
- if (msg)
- strcpy(soap->msgbuf, msg);
- else
- return ERR_error_string(err, soap->msgbuf);
- if (ERR_peek_error())
- { unsigned long r;
- strcat(soap->msgbuf, "\n");
- while ((r = ERR_get_error()))
- ERR_error_string_n(r, soap->msgbuf + strlen(soap->msgbuf), sizeof(soap->msgbuf) - strlen(soap->msgbuf));
- }
- else
- { switch (ret)
- { case 0:
- strcpy(soap->msgbuf, "EOF was observed that violates the protocol. The client probably provided invalid authentication information.");
- break;
- case -1:
- sprintf(soap->msgbuf, "Error observed by underlying BIO: %s", strerror(errno));
- break;
- }
- }
- return soap->msgbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_password(char *buf, int num, int rwflag, void *userdata)
-{ if (num < (int)strlen((char*)userdata) + 1)
- return 0;
- return strlen(strcpy(buf, (char*)userdata));
-}
-#endif
-
-/******************************************************************************/
-/* This callback is included for future references. It should not be deleted
-#ifndef PALM_2
-static DH *
-ssl_tmp_dh(SSL *ssl, int is_export, int keylength)
-{ static DH *dh512 = NULL;
- static DH *dh1024 = NULL;
- DH *dh;
- switch (keylength)
- { case 512:
- if (!dh512)
- { BIO *bio = BIO_new_file("dh512.pem", "r");
- if (bio)
- { dh512 = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- return dh512;
- }
- }
- else
- return dh512;
- default:
- if (!dh1024)
- { BIO *bio = BIO_new_file("dh1024.pem", "r");
- if (bio)
- { dh1024 = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- }
- }
- dh = dh1024;
- }
- return dh;
-}
-#endif
-*/
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_auth_init(struct soap *soap)
-{ ssl_init();
- if (!soap->ctx)
- if (!(soap->ctx = SSL_CTX_new(SSLv23_method())))
- return soap_set_receiver_error(soap, "SSL error", "Can't setup context", SOAP_SSL_ERROR);
- if (soap->randfile)
- { if (!RAND_load_file(soap->randfile, -1))
- return soap_set_receiver_error(soap, "SSL error", "Can't load randomness", SOAP_SSL_ERROR);
- }
- if (soap->cafile || soap->capath)
- if (!SSL_CTX_load_verify_locations(soap->ctx, soap->cafile, soap->capath))
- return soap_set_receiver_error(soap, "SSL error", "Can't read CA file and/or directory", SOAP_SSL_ERROR);
- if (!SSL_CTX_set_default_verify_paths(soap->ctx))
- return soap_set_receiver_error(soap, "SSL error", "Can't read default CA file and/or directory", SOAP_SSL_ERROR);
- if (soap->keyfile)
- { if (!SSL_CTX_use_certificate_chain_file(soap->ctx, soap->keyfile))
- return soap_set_receiver_error(soap, "SSL error", "Can't read certificate key file", SOAP_SSL_ERROR);
- if (soap->password)
- { SSL_CTX_set_default_passwd_cb_userdata(soap->ctx, (void*)soap->password);
- SSL_CTX_set_default_passwd_cb(soap->ctx, ssl_password);
- if (!SSL_CTX_use_PrivateKey_file(soap->ctx, soap->keyfile, SSL_FILETYPE_PEM))
- return soap_set_receiver_error(soap, "SSL error", "Can't read key file", SOAP_SSL_ERROR);
- }
- }
- if (soap->rsa)
- { RSA *rsa = RSA_generate_key(512, RSA_F4, NULL, NULL);
- if (!SSL_CTX_set_tmp_rsa(soap->ctx, rsa))
- { if (rsa)
- RSA_free(rsa);
- return soap_set_receiver_error(soap, "SSL error", "Can't set RSA key", SOAP_SSL_ERROR);
- }
- RSA_free(rsa);
- }
- else if (soap->dhfile)
- { DH *dh = 0;
- BIO *bio;
- bio = BIO_new_file(soap->dhfile, "r");
- if (!bio)
- return soap_set_receiver_error(soap, "SSL error", "Can't read DH file", SOAP_SSL_ERROR);
- dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
- BIO_free(bio);
- if (SSL_CTX_set_tmp_dh(soap->ctx, dh) < 0)
- { if (dh)
- DH_free(dh);
- return soap_set_receiver_error(soap, "SSL error", "Can't set DH parameters", SOAP_SSL_ERROR);
- }
- DH_free(dh);
- }
- SSL_CTX_set_options(soap->ctx, SSL_OP_ALL | SSL_OP_NO_SSLv2);
- SSL_CTX_set_verify(soap->ctx, soap->require_client_auth ? (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT) : soap->require_server_auth ? SSL_VERIFY_PEER : SSL_VERIFY_NONE, soap->fsslverify);
-#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
- SSL_CTX_set_verify_depth(soap->ctx, 1);
-#else
- SSL_CTX_set_verify_depth(soap->ctx, 9);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-ssl_verify_callback(int ok, X509_STORE_CTX *store)
-{
-#ifdef SOAP_DEBUG
- if (!ok)
- { char data[256];
- X509 *cert = X509_STORE_CTX_get_current_cert(store);
- fprintf(stderr, "SSL Verify error with certificate at depth %d: %s\n", X509_STORE_CTX_get_error_depth(store), X509_verify_cert_error_string(X509_STORE_CTX_get_error(store)));
- X509_NAME_oneline(X509_get_issuer_name(cert), data, sizeof(data));
- fprintf(stderr, "certificate issuer %s\n", data);
- X509_NAME_oneline(X509_get_subject_name(cert), data, sizeof(data));
- fprintf(stderr, "certificate subject %s\n", data);
- }
-#endif
- /* return 1 to always continue, but unsafe progress will be terminated by SSL */
- return ok;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_ssl_accept(struct soap *soap)
-{ int i, r;
- if (!soap_valid_socket(soap->socket))
- return soap_set_receiver_error(soap, "SSL error", "No socket in soap_ssl_accept()", SOAP_SSL_ERROR);
- if (!soap->ssl)
- { soap->ssl = SSL_new(soap->ctx);
- if (!soap->ssl)
- return soap_set_receiver_error(soap, "SSL error", "SSL_new() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
- }
- else
- SSL_clear(soap->ssl);
- soap->imode |= SOAP_ENC_SSL;
- soap->omode |= SOAP_ENC_SSL;
-#ifdef WIN32
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &nonblocking);
- }
-#else
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)|O_NONBLOCK);
-#endif
- soap->bio = BIO_new_socket((SOAP_SOCKET)soap->socket, BIO_NOCLOSE);
- SSL_set_bio(soap->ssl, soap->bio, soap->bio);
- i = 100; /* 100 * 0.1 ms retries */
- while ((r = SSL_accept(soap->ssl)) <= 0)
- { int err = SSL_get_error(soap->ssl, r);
- if (err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE)
- { struct timeval timeout;
- fd_set fd;
- if (i-- <= 0)
- break;
- timeout.tv_sec = 0;
- timeout.tv_usec = 100000;
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->socket, &fd);
- r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout);
- if (r < 0 && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- return SOAP_EOF;
- }
- }
- else
- { soap->errnum = err;
- break;
- }
- }
-#ifdef WIN32
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking);
- }
-#else
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)&~O_NONBLOCK);
-#endif
- if (r <= 0)
- { soap_set_receiver_error(soap, ssl_error(soap, r), "SSL_accept() failed in soap_ssl_accept()", SOAP_SSL_ERROR);
- soap_closesock(soap);
- return SOAP_SSL_ERROR;
- }
- if (soap->require_client_auth)
- { X509 *peer;
- int err;
- if ((err = SSL_get_verify_result(soap->ssl)) != X509_V_OK)
- { soap_closesock(soap);
- return soap_set_sender_error(soap, X509_verify_cert_error_string(err), "SSL certificate presented by peer cannot be verified in soap_ssl_accept()", SOAP_SSL_ERROR);
- }
- peer = SSL_get_peer_certificate(soap->ssl);
- if (!peer)
- { soap_closesock(soap);
- return soap_set_sender_error(soap, "SSL error", "No SSL certificate was presented by the peer in soap_ssl_accept()", SOAP_SSL_ERROR);
- }
- X509_free(peer);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#endif /* WITH_OPENSSL */
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-tcp_init(struct soap *soap)
-{ soap->errmode = 1;
-#ifdef WIN32
- if (tcp_done)
- return 0;
- else
- { WSADATA w;
- if (WSAStartup(MAKEWORD(1, 1), &w))
- return -1;
- tcp_done = 1;
- }
-#endif
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_done(struct soap *soap)
-{
-#ifdef SOAP_DEBUG
- int i;
-#endif
- soap_free(soap);
- while (soap->clist)
- { struct soap_clist *p = soap->clist->next;
- SOAP_FREE(soap->clist);
- soap->clist = p;
- }
- soap->keep_alive = 0; /* to force close the socket */
- soap_closesock(soap);
-#ifdef WITH_COOKIES
- soap_free_cookies(soap);
-#endif
- while (soap->plugins)
- { register struct soap_plugin *p = soap->plugins->next;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Removing plugin '%s'\n", soap->plugins->id));
- if (soap->plugins->fcopy || !soap->copy)
- soap->plugins->fdelete(soap, soap->plugins);
- SOAP_FREE(soap->plugins);
- soap->plugins = p;
- }
- soap->fplugin = fplugin;
- soap->fpost = http_post;
- soap->fget = http_get;
- soap->fposthdr = http_post_header;
- soap->fresponse = http_response;
- soap->fparse = http_parse;
- soap->fparsehdr = http_parse_header;
-#ifndef MAC_CARBON
-#ifndef WITH_IPV6
- soap->fresolve = tcp_gethost;
-#else
- soap->fresolve = NULL;
-#endif
- soap->faccept = tcp_accept;
- soap->fopen = tcp_connect;
- soap->fclose = tcp_disconnect;
- soap->fclosesocket = tcp_closesocket;
- soap->fshutdownsocket = tcp_shutdownsocket;
- soap->fsend = fsend;
- soap->frecv = frecv;
- soap->fpoll = soap_poll;
-#else
- soap->fpoll = NULL;
-#endif
- soap->fprepareinit = NULL;
- soap->fpreparesend = NULL;
- soap->fpreparerecv = NULL;
- soap->fignore = NULL;
- soap->fserveloop = NULL;
-#ifdef WITH_OPENSSL
- if (soap->session)
- { SSL_SESSION_free(soap->session);
- soap->session = NULL;
- }
-#endif
- if (!soap->copy)
- { if (soap_valid_socket(soap->master))
- { soap->fclosesocket(soap, (SOAP_SOCKET)soap->master);
- soap->master = SOAP_INVALID_SOCKET;
- }
-#ifdef WITH_OPENSSL
- if (soap->ctx)
- { SSL_CTX_free(soap->ctx);
- soap->ctx = NULL;
- }
-#endif
- }
-#ifdef SOAP_DEBUG
- for (i = 0; i < SOAP_MAXLOGS; i++)
- { soap_close_logfile(soap, i);
- if (soap->logfile[i])
- { SOAP_FREE((void*)soap->logfile[i]);
- soap->logfile[i] = NULL;
- }
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_cleanup(struct soap *soap)
-{ soap_done(soap);
-#ifdef WIN32
- if (!tcp_done)
- return;
- tcp_done = 0;
- WSACleanup();
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-tcp_error(struct soap *soap)
-{ register const char *msg = NULL;
- switch (soap->errmode)
- { case 0:
- msg = soap_strerror(soap);
- break;
- case 1:
- msg = "WSAStartup failed";
- break;
- case 2:
- {
-#ifndef WITH_LEAN
- msg = soap_str_code(h_error_codes, soap->errnum);
- if (!msg)
-#endif
- { sprintf(soap->msgbuf, "TCP error %d", soap->errnum);
- msg = soap->msgbuf;
- }
- }
- }
- return msg;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-http_error(struct soap *soap, int status)
-{ register const char *msg = NULL;
-#ifndef WITH_LEAN
- msg = soap_str_code(h_http_error_codes, status);
- if (!msg)
-#endif
- { sprintf(soap->msgbuf, "HTTP error %d", status);
- msg = soap->msgbuf;
- }
- return msg;
-}
-#endif
-
-/******************************************************************************/
-/* WR[ */
-#ifndef WITH_IPV6
-/* ]WR */
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr)
-{ unsigned long iadd;
- struct hostent hostent, *host = &hostent;
-/* WR[ */
-#ifdef VXWORKS
- int hostint;
- char *addrcopy = (char*)malloc(strlen(addr) + 1); /*copy of addr. */
- /* inet_addr(), and hostGetByName() expect "char *"; addr is a "const char *". */
- strncpy(addrcopy, addr, strlen(addr)+1);
- iadd = inet_addr(addrcopy);
-#else
-/* ]WR */
-#if defined(_AIXVERSION_431) || defined(TRU64)
- struct hostent_data ht_data;
-#endif
- iadd = inet_addr(addr);
-/* WR[ */
-#endif
-/* ]WR */
- if ((int)iadd != -1)
- { memcpy(inaddr, &iadd, sizeof(iadd));
-/* WR[ */
-#ifdef VXWORKS
- free(addrcopy);
-#endif
-/* ]WR */
- return SOAP_OK;
- }
-#if defined(__GLIBC__)
- if (gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &host, &soap->errnum) < 0)
- host = NULL;
-#elif defined(_AIXVERSION_431) || defined(TRU64)
- memset((void*)&ht_data, 0, sizeof(ht_data));
- if (gethostbyname_r(addr, &hostent, &ht_data) < 0)
- { host = NULL;
- soap->errnum = h_errno;
- }
-#elif defined(HAVE_GETHOSTBYNAME_R)
- host = gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &soap->errnum);
-/* WR[ */
-#elif defined(VXWORKS)
- /* If the DNS resolver library resolvLib has been configured in the vxWorks
- * image, a query for the host IP address is sent to the DNS server, if the
- * name was not found in the local host table. */
- hostint = hostGetByName(addrcopy);
- if (hostint == ERROR)
- { host = NULL;
- soap->errnum = soap_errno;
- }
- free(addrcopy); /*free() is placed after the error checking to assure that
- * errno captured is that from hostGetByName() */
-/* ]WR */
-#else
- if (!(host = gethostbyname(addr)))
- soap->errnum = h_errno;
-#endif
- if (!host)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Host name not found\n"));
- return SOAP_ERR;
- }
-/* WR[ */
-#ifdef VXWORKS
- inaddr->s_addr = hostint;
-#else
-/* ]WR */
- memcpy(inaddr, host->h_addr, host->h_length);
-/* WR[ */
-#endif
-/* ]WR */
- return SOAP_OK;
-}
-#endif
-#endif
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port)
-{ struct sockaddr_in sockaddr;
-/* WR[ */
-#ifdef WITH_IPV6
- struct addrinfo *addrinfo;
- struct addrinfo hints;
- struct addrinfo resaddr;
- struct sockaddr_storage addrstorage;
- int err;
-#endif /* WITH_IPV6 */
-/* ]WR */
- register int fd;
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- if (soap_valid_socket(soap->socket))
- soap->fclosesocket(soap, (SOAP_SOCKET)soap->socket);
- soap->socket = SOAP_INVALID_SOCKET;
- if (tcp_init(soap))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP initialization failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- soap->errmode = 0;
-/* WR[ */
-#ifdef WITH_IPV6
- memset((void*)&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- soap->errmode = 2;
- if (soap->proxy_host)
- err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &addrinfo);
- else
- err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
- if (addrinfo)
- { resaddr = *addrinfo;
- addrstorage = *((struct sockaddr_storage*)addrinfo->ai_addr);
- resaddr.ai_addr = (struct sockaddr*)&addrstorage;
- freeaddrinfo(addrinfo);
- }
- if (err)
- { soap_set_sender_error(soap, gai_strerror(err),
- "TCP getaddrinfo on proxy host failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- fd = (int)socket(resaddr.ai_family, resaddr.ai_socktype, resaddr.ai_protocol); /* modified to use fd */
- soap->errmode = 0;
-#else /* WITH_IPV6 */
-/* ]WR */
- fd = (int)socket(AF_INET, SOCK_STREAM, 0);
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- if (fd < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP socket failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef SOCKET_CLOSE_ON_EXEC
-#ifdef WIN32
-#ifndef UNDER_CE
- SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0);
-#endif
-#else
- fcntl (fd, F_SETFD, 1);
-#endif
-#endif
-#ifndef WITH_LEAN
- if (soap->connect_flags & SO_LINGER)
- { struct linger linger;
- memset((void*)&linger, 0, sizeof(linger));
- linger.l_onoff = 1;
- linger.l_linger = 0;
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- }
- if ((soap->connect_flags & ~SO_LINGER) && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, soap->connect_flags & ~SO_LINGER, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_sender_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
-#endif
-#endif
-/* WR[ */
-#ifndef WITH_IPV6
-/* ]WR */
- memset((void*)&sockaddr, 0, sizeof(sockaddr));
- sockaddr.sin_family = AF_INET;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Open socket %d to host='%s'\n", fd, host));
- soap->errmode = 2;
- if (soap->proxy_host)
- { if (soap->fresolve(soap, soap->proxy_host, &sockaddr.sin_addr))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- sockaddr.sin_port = htons((short)soap->proxy_port);
- }
- else
- { if (soap->fresolve(soap, host, &sockaddr.sin_addr))
- { soap_set_sender_error(soap, tcp_error(soap), "TCP get host by name failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- sockaddr.sin_port = htons((short)port);
- }
- soap->errmode = 0;
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#if defined(WIN32)
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- { vx_nonblocking = TRUE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK);
-#endif
- else
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- { vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- for (;;)
- {
-/* WR[ */
-#ifdef WITH_IPV6
- if (connect((SOAP_SOCKET)fd, resaddr.ai_addr, resaddr.ai_addrlen)) /* modified to use fd */
-#else /* WITH_IPV6 */
- if (connect((SOAP_SOCKET)fd, (struct sockaddr*)&sockaddr, sizeof(sockaddr)))
-#endif /* WITH_IPV6 */
-/* ]WR */
- {
-#ifndef WITH_LEAN
- if (soap->connect_timeout && (soap_socket_errno == SOAP_EINPROGRESS || soap_socket_errno == SOAP_EWOULDBLOCK))
- { struct timeval timeout;
-#if defined(SOCKLEN_T)
- SOCKLEN_T n = sizeof(struct sockaddr_in);
-#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN)
- socklen_t n = sizeof(struct sockaddr_in);
-#elif defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)
- int n = sizeof(struct sockaddr_in);
-#else
- size_t n = sizeof(struct sockaddr_in);
-#endif
- fd_set fds;
- if (soap->connect_timeout > 0)
- { timeout.tv_sec = soap->connect_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->connect_timeout/1000000;
- timeout.tv_usec = -soap->connect_timeout%1000000;
- }
- FD_ZERO(&fds);
- FD_SET((SOAP_SOCKET)fd, &fds);
- for (;;)
- { int r = select((SOAP_SOCKET)(fd + 1), NULL, &fds, NULL, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
- soap_set_sender_error(soap, "Timeout", "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- }
- n = sizeof(soap->errnum);
- if (!getsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &n) && !soap->errnum)
- break;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- else
-#endif
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n"));
- soap_set_sender_error(soap, tcp_error(soap), "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- soap->fclosesocket(soap, (SOAP_SOCKET)fd);
- return -1;
- }
- }
- else
- break;
- }
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- { vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- soap->socket = fd;
-#ifdef WITH_OPENSSL
- soap->imode &= ~SOAP_ENC_SSL;
- soap->omode &= ~SOAP_ENC_SSL;
- if (!strncmp(endpoint, "https:", 6))
- { int r;
- if (soap->proxy_host)
- { unsigned int k = soap->omode; /* make sure we only parse HTTP */
- size_t n = soap->count; /* save the content length */
- soap->omode &= ~0xFF; /* mask IO and ENC */
- soap->omode |= SOAP_IO_BUFFER;
- soap_begin_send(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to proxy server\n"));
- sprintf(soap->tmpbuf, "CONNECT %s:%d HTTP/%s", host, port, soap->http_version);
- if ((soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return -1;
-#ifndef WITH_LEAN
- if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((soap->error = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
- return soap->error;
- }
-#endif
- if ((soap->error = soap->fposthdr(soap, NULL, NULL))
- || soap_flush(soap))
- return -1;
- soap->omode = k;
- k = soap->imode;
- soap->imode &= ~0xFF; /* mask IO and ENC */
- if (soap_begin_recv(soap))
- return -1;
- soap->imode = k;
- soap->count = n;
- soap_begin_send(soap);
- }
- if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
- { soap_set_sender_error(soap, "SSL error", "SSL authentication failed in tcp_connect(): check password, key file, and ca file.", SOAP_SSL_ERROR);
- return -1;
- }
- soap->ssl = SSL_new(soap->ctx);
- if (!soap->ssl)
- { soap->error = SOAP_SSL_ERROR;
- return -1;
- }
- if (soap->session)
- { if (!strcmp(soap->session_host, host) && soap->session_port == port)
- SSL_set_session(soap->ssl, soap->session);
- SSL_SESSION_free(soap->session);
- soap->session = NULL;
- }
- soap->imode |= SOAP_ENC_SSL;
- soap->omode |= SOAP_ENC_SSL;
- soap->bio = BIO_new_socket((SOAP_SOCKET)fd, BIO_NOCLOSE);
- SSL_set_bio(soap->ssl, soap->bio, soap->bio);
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#ifdef WIN32
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking);
- }
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK);
-#endif
-#endif
- for (;;)
- { if ((r = SSL_connect(soap->ssl)) <= 0)
- { int err = SSL_get_error(soap->ssl, r);
- if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE)
- { soap_set_sender_error(soap, ssl_error(soap, r), "SSL connect failed in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- if (soap->connect_timeout)
- { struct timeval timeout;
- fd_set fds;
- if (soap->connect_timeout > 0)
- { timeout.tv_sec = soap->connect_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->connect_timeout/1000000;
- timeout.tv_usec = -soap->connect_timeout%1000000;
- }
- FD_ZERO(&fds);
- FD_SET((SOAP_SOCKET)(soap->socket), &fds);
- for (;;)
- { int r = select((SOAP_SOCKET)(soap->socket + 1), &fds, NULL, &fds, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connect timeout\n"));
- soap_set_sender_error(soap, "Timeout", "TCP connect failed in tcp_connect()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- continue;
- }
- }
- break;
- }
-#ifndef WITH_LEAN
- if (soap->connect_timeout)
-#ifdef WIN32
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking);
- }
-#else
- fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- if (soap->require_server_auth)
- { X509 *peer;
- int err;
- if ((err = SSL_get_verify_result(soap->ssl)) != X509_V_OK)
- { soap_set_sender_error(soap, X509_verify_cert_error_string(err), "SSL certificate presented by peer cannot be verified in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- peer = SSL_get_peer_certificate(soap->ssl);
- if (!peer)
- { soap_set_sender_error(soap, "SSL error", "No SSL certificate was presented by the peer in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- X509_NAME_get_text_by_NID(X509_get_subject_name(peer), NID_commonName, soap->msgbuf, sizeof(soap->msgbuf));
- X509_free(peer);
- if (soap_tag_cmp(soap->msgbuf, host))
- { soap_set_sender_error(soap, "SSL error", "SSL certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR);
- return -1;
- }
- }
- }
-#endif
- return fd;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_bind(struct soap *soap, const char *host, int port, int backlog)
-{ struct sockaddr_in sockaddr;
-/* WR[ */
-#ifdef WITH_IPV6
- struct addrinfo *addrinfo;
- struct addrinfo hints;
- struct addrinfo resaddr;
- struct sockaddr_storage addrstorage;
- int err;
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- if (soap_valid_socket(soap->master))
- { soap->fclosesocket(soap, (SOAP_SOCKET)soap->master);
- soap->master = SOAP_INVALID_SOCKET;
- }
- soap->socket = SOAP_INVALID_SOCKET;
- soap->errmode = 1;
- if (tcp_init(soap))
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP init failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#ifdef WITH_IPV6
- memset((void*)&hints, 0, sizeof(hints));
- hints.ai_family = PF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_PASSIVE;
- soap->errmode = 2;
- if (host)
- err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo);
- else
- err = getaddrinfo(NULL, soap_int2s(soap, port), &hints, &addrinfo);
- if (NULL != addrinfo)
- {
- resaddr = *addrinfo;
- addrstorage = *((struct sockaddr_storage *) addrinfo->ai_addr);
- resaddr.ai_addr = (struct sockaddr *) &addrstorage;
- freeaddrinfo(addrinfo);
- }
- if (err)
- { soap_set_receiver_error(soap, gai_strerror(err), "TCP getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- soap->errmode = 0;
- if ((soap->master = socket(resaddr.ai_family, resaddr.ai_socktype, resaddr.ai_protocol)) < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP socket failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- soap->errmode = 0;
- if ((soap->master = (int)socket(AF_INET, SOCK_STREAM, 0)) < 0)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP socket failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifdef SOCKET_CLOSE_ON_EXEC
-#ifdef WIN32
-#ifndef UNDER_CE
- SetHandleInformation((HANDLE)soap->master, HANDLE_FLAG_INHERIT, 0);
-#endif
-#else
- fcntl (soap->master, F_SETFD, 1);
-#endif
-#endif
-#ifndef WITH_LEAN
- if (soap->bind_flags && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, soap->bind_flags, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)soap->master, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#endif
-#endif
-/* WR[ */
-#ifdef WITH_IPV6
- soap->errmode = 0;
- if (bind(soap->master, resaddr.ai_addr, resaddr.ai_addrlen) || listen(soap->master, backlog))
- {
- soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
- soap_closesock(soap);
- soap_set_receiver_error(soap, tcp_error(soap), "TCP bind failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- memset((void*)&sockaddr, 0, sizeof(sockaddr));
- sockaddr.sin_family = AF_INET;
- soap->errmode = 2;
- if (host)
- { if (soap->fresolve(soap, host, &sockaddr.sin_addr))
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP get host by name failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- else
- sockaddr.sin_addr.s_addr = htonl(INADDR_ANY);
- sockaddr.sin_port = htons((short)port);
- soap->errmode = 0;
- if (bind((SOAP_SOCKET)soap->master, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) || listen((SOAP_SOCKET)soap->master, backlog))
- { soap->errnum = soap_socket_errno;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n"));
- soap_closesock(soap);
- soap_set_receiver_error(soap, tcp_error(soap), "TCP bind failed in soap_bind()", SOAP_TCP_ERROR);
- return -1;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
-#ifdef WITH_OPENSSL
- if (!soap->ctx && (soap->error = soap->fsslauth(soap)))
- return -1;
-#endif
- return soap->master;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_poll(struct soap *soap)
-{
-#ifndef WITH_LEAN
- struct timeval timeout;
- fd_set sfd,rfd;
- int r;
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- FD_ZERO(&rfd);
- FD_ZERO(&sfd);
- if (soap->socket >= 0)
- { FD_SET(soap->socket, &rfd);
- FD_SET(soap->socket, &sfd);
- r = select(soap->socket + 1, &rfd, &sfd, NULL, &timeout);
- }
- else if (soap->master >= 0)
- { FD_SET(soap->master, &rfd);
- r = select(soap->master + 1, &rfd, &sfd, NULL, &timeout);
- }
- else
- { FD_SET(soap->sendfd, &sfd);
- FD_SET(soap->recvfd, &rfd);
- r = select((soap->sendfd > soap->recvfd ? soap->sendfd : soap->recvfd) + 1, &rfd, &sfd, NULL, &timeout);
- }
- if (r > 0)
- {
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { if ((soap->socket >= 0) && FD_ISSET(soap->socket, &rfd))
- { char buf = '\0';
- if (SSL_peek(soap->ssl, &buf, 1) <= 0)
- return SOAP_EOF;
- }
- }
-#endif
- return SOAP_OK;
- }
- if (r < 0 && (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "select failed in soap_poll()", SOAP_TCP_ERROR);
- return soap->error = SOAP_TCP_ERROR;
- }
- else
- soap->errnum = soap_errno;
- return SOAP_EOF;
-#else
- return SOAP_OK;
-#endif
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_accept(struct soap *soap, int s, struct sockaddr *a, int *n)
-{ int fd;
-#if defined(SOCKLEN_T)
- fd = (int)accept((SOAP_SOCKET)s, a, (SOCKLEN_T*)n);
-#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN)
- fd = (int)accept((SOAP_SOCKET)s, a, (socklen_t*)n);
-#elif defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS)
- fd = (int)accept((SOAP_SOCKET)s, a, n);
-#else
- fd = (int)accept((SOAP_SOCKET)s, a, (size_t*)n);
-#endif
-#ifdef SOCKET_CLOSE_ON_EXEC
-#ifdef WIN32
-#ifndef UNDER_CE
- SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0);
-#endif
-#else
- fcntl(fd, F_SETFD, FD_CLOEXEC);
-#endif
-#endif
- return fd;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_accept(struct soap *soap)
-{
-/* WR[ */
-#ifdef WITH_IPV6
- struct sockaddr_storage sockaddr;
-#else /* WITH_IPV6 */
-/* ]WR */
- struct sockaddr_in sockaddr;
-/* WR[ */
-#endif
-/* ]WR */
- int n = (int)sizeof(sockaddr);
-#ifndef WITH_LEAN
- int len = SOAP_BUFLEN;
- int set = 1;
-#endif
- soap->error = SOAP_OK;
- memset((void*)&sockaddr, 0, sizeof(sockaddr));
- soap->socket = SOAP_INVALID_SOCKET;
- soap->errmode = 0;
- if (soap_valid_socket(soap->master))
- { for (;;)
- {
-#ifndef WITH_LEAN
- if (soap->accept_timeout)
- { struct timeval timeout;
- fd_set fd;
- if (soap->accept_timeout > 0)
- { timeout.tv_sec = soap->accept_timeout;
- timeout.tv_usec = 0;
- }
- else
- { timeout.tv_sec = -soap->accept_timeout/1000000;
- timeout.tv_usec = -soap->accept_timeout%1000000;
- }
- FD_ZERO(&fd);
- FD_SET((SOAP_SOCKET)soap->master, &fd);
- for (;;)
- { int r = select((SOAP_SOCKET)(soap->master + 1), &fd, &fd, NULL, &timeout);
- if (r > 0)
- break;
- if (!r)
- { soap->errnum = 0;
- soap_set_receiver_error(soap, "Timeout", "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap_socket_errno != SOAP_EINTR)
- { soap->errnum = soap_socket_errno;
- soap_closesock(soap);
- soap_set_sender_error(soap, tcp_error(soap), "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
-#if defined(WIN32)
- { u_long nonblocking = 1;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &nonblocking);
- }
-#elif defined(VXWORKS)
- { vx_nonblocking = TRUE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- }
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)|O_NONBLOCK);
-#endif
- }
- else
-#if defined(WIN32)
- { u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &blocking);
- }
-/* WR[ */
-#elif defined(VXWORKS)
- { vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- }
-/* ]WR */
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK);
-#endif
-#endif
- if ((soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&sockaddr, &n)) >= 0)
- {
-/* WR[ */
-#ifdef WITH_IPV6
-/* Use soap->host to store the numeric form of the remote host */
- getnameinfo((struct sockaddr*)&sockaddr, n, soap->host, sizeof(soap->host), NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket %d from %s\n", soap->socket, soap->host));
- soap->ip = 0; /* info stored in soap->host */
- soap->port = 0; /* info stored in soap->host */
-#else /* WITH_IPV6 */
-/* ]WR */
- soap->ip = ntohl(sockaddr.sin_addr.s_addr);
- soap->port = (int)ntohs(sockaddr.sin_port); /* does not return port number on some systems */
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept socket %d at port %d from IP %d.%d.%d.%d\n", soap->socket, soap->port, (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF));
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- soap->keep_alive = ((soap->imode & SOAP_IO_KEEPALIVE) != 0);
-#ifndef WITH_LEAN
- if (soap->accept_flags & SO_LINGER)
- { struct linger linger;
- memset((void*)&linger, 0, sizeof(linger));
- linger.l_onoff = 1;
- linger.l_linger = 0;
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- if ((soap->accept_flags & ~SO_LINGER) && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, soap->accept_flags & ~SO_LINGER, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (soap->keep_alive && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-#ifdef TCP_NODELAY
- if (setsockopt((SOAP_SOCKET)soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int)))
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-#endif
-#endif
- if (soap->accept_timeout)
- {
-#if defined(WIN32)
- u_long blocking = 0;
- ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &blocking);
- ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking);
-/* WR[ */
-#elif defined(VXWORKS)
- vx_nonblocking = FALSE;
- ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking));
- ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)(&vx_nonblocking));
-/* ]WR */
-#elif defined(PALM)
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL,0)&~O_NONBLOCK);
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL,0)&~O_NONBLOCK);
-#elif defined(SYMBIAN)
- long blocking = 0;
- ioctl((SOAP_SOCKET)soap->master, 0/*FIONBIO*/, &blocking);
-#else
- fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK);
- fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)&~O_NONBLOCK);
-#endif
- }
- return soap->socket;
- }
- if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN)
- { soap->errnum = soap_socket_errno;
- soap_set_receiver_error(soap, tcp_error(soap), "TCP accept failed in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
- }
- }
- else
- { soap_set_receiver_error(soap, tcp_error(soap), "TCP no master socket in soap_accept()", SOAP_TCP_ERROR);
- return -1;
- }
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_disconnect(struct soap *soap)
-{
-#ifdef WITH_OPENSSL
- if (soap->ssl)
- { int r, s = 0;
- if (soap->session)
- SSL_SESSION_free(soap->session);
- if (*soap->host)
- { soap->session = SSL_get1_session(soap->ssl);
- if (soap->session)
- { strcpy(soap->session_host, soap->host);
- soap->session_port = soap->port;
- }
- }
- r = SSL_shutdown(soap->ssl);
- if (r != 1)
- { s = ERR_get_error();
- if (s)
- { if (soap_valid_socket(soap->socket))
- { soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1);
- soap->socket = SOAP_INVALID_SOCKET;
- }
- r = SSL_shutdown(soap->ssl);
- }
- }
- DBGLOG(TEST, if (s) SOAP_MESSAGE(fdebug, "Shutdown failed: %d\n", SSL_get_error(soap->ssl, r)));
- SSL_free(soap->ssl);
- soap->ssl = NULL;
- if (s)
- return SOAP_SSL_ERROR;
- ERR_remove_state(0);
- }
-#endif
- if (soap_valid_socket(soap->socket))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Closing socket %d\n", soap->socket));
- soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 2);
- soap->fclosesocket(soap, (SOAP_SOCKET)soap->socket);
- soap->socket = SOAP_INVALID_SOCKET;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_closesocket(struct soap *soap, SOAP_SOCKET fd)
-{ return closesocket(fd);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef MAC_CARBON
-#ifndef PALM_1
-static int
-tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET fd, int how)
-{ return shutdown(fd, how);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_closesock(struct soap *soap)
-{ register int status = soap->error;
-#ifndef MAC_CARBON
- if (status == SOAP_EOF || status == SOAP_TCP_ERROR || status == SOAP_SSL_ERROR || !soap->keep_alive)
- { if ((soap->error = soap->fclose(soap)))
- return soap->error;
- soap->socket = SOAP_INVALID_SOCKET;
- }
-#endif
-#ifdef WITH_ZLIB
- if (soap->zlib_state == SOAP_ZLIB_DEFLATE)
- deflateEnd(&soap->d_stream);
- else if (soap->zlib_state == SOAP_ZLIB_INFLATE)
- inflateEnd(&soap->d_stream);
- soap->zlib_state = SOAP_ZLIB_NONE;
-#endif
- return soap->error = status;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_hash(register const char *s)
-{ register size_t h = 0;
- while (*s)
- h = 65599*h + *s++;
- return h % SOAP_IDHASH;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_init_pht(struct soap *soap)
-{ register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing pointer hashtable\n"));
- for (i = 0; i < (int)SOAP_PTRHASH; i++)
- soap->pht[i] = NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new()
-{ struct soap *soap = (struct soap*)SOAP_MALLOC(sizeof(struct soap));
- if (soap)
- soap_init(soap);
- return soap;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new1(int mode)
-{ return soap_new2(mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_new2(int imode, int omode)
-{ struct soap *soap = (struct soap*)SOAP_MALLOC(sizeof(struct soap));
- if (soap)
- soap_init2(soap, imode, omode);
- return soap;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_free_pht(struct soap *soap)
-{ register struct soap_plist *pp, *next;
- register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n"));
- for (i = 0; i < (int)SOAP_PTRHASH; i++)
- { for (pp = soap->pht[i]; pp; pp = next)
- { next = pp->next;
- SOAP_FREE(pp);
- }
- soap->pht[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embed(struct soap *soap, const void *p, const struct soap_array *a, int n, const char *tag, int type)
-{ register int i;
- struct soap_plist *pp;
- if (soap->version != 1)
- soap->encoding = 1;
- if (a)
- i = soap_array_pointer_lookup(soap, p, a, n, type, &pp);
- else
- i = soap_pointer_lookup(soap, p, type, &pp);
- if (i)
- { if (soap_is_embedded(soap, pp)
- || soap_is_single(soap, pp))
- return 0;
- soap_set_embedded(soap, pp);
- }
- return i;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pointer_lookup(struct soap *soap, const void *p, int type, struct soap_plist **ppp)
-{ register struct soap_plist *pp;
- *ppp = NULL;
- if (p)
- for (pp = soap->pht[soap_hash_ptr(p)]; pp; pp = pp->next)
- if (pp->ptr == p && pp->type == type)
- { *ppp = pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d id=%d\n", p, type, pp->id));
- return pp->id;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup location=%p type=%d: not found\n", p, type));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_pointer_enter(struct soap *soap, const void *p, const struct soap_array *a, int n, int type, struct soap_plist **ppp)
-{ register int h;
- register struct soap_plist *pp = *ppp = (struct soap_plist*)SOAP_MALLOC(sizeof(struct soap_plist));
- if (!pp)
- return 0;
- if (a)
- h = soap_hash_ptr(a->__ptr);
- else
- h = soap_hash_ptr(p);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pointer enter location=%p array=%p size=%d dim=%d type=%d id=%lu\n", p, a?a->__ptr:NULL, a?a->__size:0, n, type, soap->idnum+1));
- pp->next = soap->pht[h];
- pp->type = type;
- pp->mark1 = 0;
- pp->mark2 = 0;
- pp->ptr = p;
- pp->array = a;
- soap->pht[h] = pp;
- pp->id = ++soap->idnum;
- return pp->id;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_pointer_lookup(struct soap *soap, const void *p, const struct soap_array *a, int n, int type, struct soap_plist **ppp)
-{ register struct soap_plist *pp;
- *ppp = NULL;
- if (!p || !a->__ptr)
- return 0;
- for (pp = soap->pht[soap_hash_ptr(a->__ptr)]; pp; pp = pp->next)
- { if (pp->type == type && pp->array && pp->array->__ptr == a->__ptr)
- { register int i;
- for (i = 0; i < n; i++)
- if (((const int*)&pp->array->__size)[i] != ((const int*)&a->__size)[i])
- break;
- if (i == n)
- { *ppp = pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d id=%d\n", a->__ptr, type, pp->id));
- return pp->id;
- }
- }
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array lookup location=%p type=%d: not found\n", a->__ptr, type));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_begin_count(struct soap *soap)
-{ soap_clr_attr(soap);
- soap_set_local_namespaces(soap);
-#ifndef WITH_LEANER
- if ((soap->mode & SOAP_ENC_DIME) || (soap->omode & SOAP_ENC_DIME))
- soap->mode = soap->omode | SOAP_IO_LENGTH | SOAP_ENC_DIME;
- else
-#endif
- { soap->mode = soap->omode;
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE
- || (((soap->mode & SOAP_IO) == SOAP_IO_CHUNK || (soap->mode & SOAP_ENC_XML)) && !soap->fpreparesend))
- soap->mode &= ~SOAP_IO_LENGTH;
- else
- soap->mode |= SOAP_IO_LENGTH;
- }
- if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
- { if (!(soap->mode & SOAP_ENC_DIME))
- soap->mode &= ~SOAP_IO_LENGTH;
- if (soap->mode & SOAP_ENC_XML)
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH))
- soap->mode |= SOAP_XML_TREE;
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_MIME)
- soap_select_mime_boundary(soap);
- soap->dime.list = soap->dime.last; /* keep track of last DIME attachment */
-#endif
- soap->count = 0;
- soap->ns = 0;
- soap->null = 0;
- soap->position = 0;
- soap->mustUnderstand = 0;
- soap->encoding = 0;
- soap->part = SOAP_BEGIN;
- soap->idnum = 0;
- soap->dime.count = 0; /* count # of attachments */
- soap->dime.size = 0; /* accumulate total size of attachments */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
- if (soap->fprepareinit && (soap->mode & SOAP_IO) != SOAP_IO_STORE)
- soap->fprepareinit(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_begin_send(struct soap *soap)
-{ soap->error = SOAP_OK;
- soap_clr_attr(soap);
- soap_set_local_namespaces(soap);
- soap->mode = (soap->omode & ~SOAP_IO_LENGTH) | (soap->mode & SOAP_ENC_DIME);
- if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
- { if (soap->mode & SOAP_ENC_XML)
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket))
- { if (soap->count || (soap->mode & SOAP_ENC_XML))
- soap->mode |= SOAP_IO_BUFFER;
- else
- soap->mode |= SOAP_IO_STORE;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- soap_new_block(soap);
- if (!(soap->mode & SOAP_IO_KEEPALIVE))
- soap->keep_alive = 0;
- if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH))
- soap->mode |= SOAP_XML_TREE;
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_MIME)
- soap_select_mime_boundary(soap);
-#endif
-#ifdef WIN32
-#ifndef UNDER_CE
-#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket)) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
-#ifdef __BORLANDC__
- setmode((SOAP_SOCKET)soap->sendfd, O_BINARY);
-#else
- _setmode((SOAP_SOCKET)soap->sendfd, _O_BINARY);
-#endif
-#endif
-#endif
-#endif
- if (soap->mode & SOAP_IO)
- { soap->bufidx = 0;
- soap->buflen = 0;
- }
- soap->chunksize = 0;
- soap->ns = 0;
- soap->null = 0;
- soap->position = 0;
- soap->mustUnderstand = 0;
- soap->encoding = 0;
- soap->part = SOAP_BEGIN;
- soap->idnum = 0;
- soap->level = 0;
-#ifdef WITH_ZLIB
- soap->z_ratio_out = 1.0;
- if ((soap->mode & SOAP_ENC_ZLIB) && soap->zlib_state != SOAP_ZLIB_DEFLATE)
- {
-#ifdef WITH_GZIP
- memcpy(soap->z_buf, "\37\213\10\0\0\0\0\0\0\377", 10);
- soap->d_stream.next_out = (Byte*)soap->z_buf + 10;
- soap->d_stream.avail_out = SOAP_BUFLEN - 10;
- soap->z_crc = crc32(0L, NULL, 0);
- if (deflateInit2(&soap->d_stream, soap->z_level, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK)
-#else
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- if (deflateInit(&soap->d_stream, soap->z_level) != Z_OK)
-#endif
- return soap->error = SOAP_ZLIB_ERROR;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflate initialized\n"));
- soap->zlib_state = SOAP_ZLIB_DEFLATE;
- }
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin send phase (socket=%d mode=%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
- if (soap->fprepareinit && (soap->mode & SOAP_IO) == SOAP_IO_STORE)
- soap->fprepareinit(soap);
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_embedded(struct soap *soap, const void *p, int t)
-{ struct soap_plist *pp;
- if (soap_pointer_lookup(soap, p, t, &pp))
- { pp->mark1 = 1;
- pp->mark2 = 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded %p type=%d mark set to 1\n", p, t));
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_reference(struct soap *soap, const void *p, int t)
-{ struct soap_plist *pp;
- if (!p || (soap->mode & SOAP_XML_TREE))
- return 1;
- if (soap_pointer_lookup(soap, p, t, &pp))
- { if (pp->mark1 == 0)
- { pp->mark1 = 2;
- pp->mark2 = 2;
- }
- }
- else if (soap_pointer_enter(soap, p, NULL, 0, t, &pp))
- { pp->mark1 = 0;
- pp->mark2 = 0;
- }
- else
- return 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reference %p type=%d (%d %d)\n", p, t, (int)pp->mark1, (int)pp->mark2));
- return pp->mark1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_reference(struct soap *soap, const void *p, const struct soap_array *a, int n, int t)
-{ register int i;
- struct soap_plist *pp;
- if (!p)
- return 1;
- i = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
- if (i)
- { if (pp->mark1 == 0)
- { pp->mark1 = 2;
- pp->mark2 = 2;
- }
- }
- else if (!soap_pointer_enter(soap, p, a, n, t, &pp))
- return 1;
- else
- { pp->mark1 = 0;
- pp->mark2 = 0;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Array reference %p ptr=%p dim=%d type=%d (%d %d)\n", p, a->__ptr, n, t, (int)pp->mark1, (int)pp->mark2));
- return pp->mark1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_embedded_id(struct soap *soap, int id, const void *p, int t)
-{ struct soap_plist *pp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id %p type=%d id=%d\n", p, t, id));
- if (soap->mode & SOAP_XML_TREE)
- return id;
- if (soap->version == 1 && soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH) && soap->part != SOAP_IN_HEADER)
- { if (id < 0)
- { id = soap_pointer_lookup(soap, p, t, &pp);
- if (id)
- { if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 2;
- else
- pp->mark2 = 2;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id multiref id=%d %p type=%d = (%d %d)\n", id, p, t, (int)pp->mark1, (int)pp->mark2));
- }
- return -1;
- }
- return id;
- }
- if (id < 0)
- id = soap_pointer_lookup(soap, p, t, &pp);
- else if (id && !soap_pointer_lookup(soap, p, t, &pp))
- return 0;
- if (id && pp)
- { if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 1;
- else
- pp->mark2 = 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Embedded_id embedded ref id=%d %p type=%d = (%d %d)\n", id, p, t, (int)pp->mark1, (int)pp->mark2));
- }
- return id;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_embedded(struct soap *soap, struct soap_plist *pp)
-{ if (!pp)
- return 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Is embedded? %d %d\n", (int)pp->mark1, (int)pp->mark2));
- if (soap->version == 1 && soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH) && soap->part != SOAP_IN_HEADER)
- { if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 != 0;
- return pp->mark2 != 0;
- }
- if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 1;
- return pp->mark2 == 1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_is_single(struct soap *soap, struct soap_plist *pp)
-{ if (soap->part == SOAP_IN_HEADER)
- return 1;
- if (!pp)
- return 0;
- if (soap->mode & SOAP_IO_LENGTH)
- return pp->mark1 == 0;
- return pp->mark2 == 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_embedded(struct soap *soap, struct soap_plist *pp)
-{ if (!pp)
- return;
- if (soap->mode & SOAP_IO_LENGTH)
- pp->mark1 = 1;
- else
- pp->mark2 = 1;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_dime(struct soap *soap, const char *tag, int id, const void *p, const struct soap_array *a, const char *aid, const char *atype, const char *aoptions, int n, const char *type, int t)
-{ struct soap_plist *pp;
- if (!p || !a->__ptr || (!aid && !atype))
- return soap_element_id(soap, tag, id, p, a, n, type, t);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Attachment tag='%s' id='%s' (%d) type='%s'\n", tag, aid?aid:"", id, atype?atype:""));
- if (id < 0)
- id = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
- if (!aid)
- { sprintf(soap->tmpbuf, soap->dime_id_format, id);
- aid = soap_strdup(soap, soap->tmpbuf);
- }
- if (soap_element_href(soap, tag, 0, "href", aid))
- return soap->error;
- if (soap->mode & SOAP_IO_LENGTH)
- { if (pp->mark1 != 3)
- { struct soap_multipart *content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, (char*)a->__ptr, a->__size);
- if (!content)
- return soap->error = SOAP_EOM;
- content->id = aid;
- content->type = atype;
- content->options = aoptions;
- pp->mark1 = 3;
- }
- }
- else
- pp->mark2 = 3;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_init_iht(struct soap *soap)
-{ register int i;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing ID hashtable\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- soap->iht[i] = NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_free_iht(struct soap *soap)
-{ register int i;
- register struct soap_ilist *ip, *p;
- register struct soap_flist *fp, *fq;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free ID hashtable\n"));
- for (i = 0; i < SOAP_IDHASH; i++)
- { for (ip = soap->iht[i]; ip; ip = p)
- { for (fp = ip->flist; fp; fp = fq)
- { fq = fp->next;
- SOAP_FREE(fp);
- }
- p = ip->next;
- SOAP_FREE(ip);
- }
- soap->iht[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static struct soap_ilist *
-soap_hlookup(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- for (ip = soap->iht[soap_hash(id)]; ip; ip = ip->next)
- if (!strcmp(ip->id, id))
- return ip;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_ilist *
-SOAP_FMAC2
-soap_lookup(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- ip = soap_hlookup(soap, id);
-#ifndef WITH_LEANER
- if (!ip && *id != '#' && !strchr(id, ':')) /* try content id "cid:" with DIME attachments */
- { char cid[SOAP_TAGLEN];
- strcpy(cid, "cid:");
- strncat(cid + 4, id, sizeof(cid) - 5);
- cid[sizeof(cid) - 1] = '\0';
- ip = soap_hlookup(soap, cid);
- }
-#endif
- return ip;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_ilist *
-SOAP_FMAC2
-soap_enter(struct soap *soap, const char *id)
-{ register size_t h;
- register struct soap_ilist *ip;
- ip = (struct soap_ilist*)SOAP_MALLOC(sizeof(struct soap_ilist) + strlen(id));
- if (ip)
- { h = soap_hash(id);
- strcpy(ip->id, id);
- ip->next = soap->iht[h];
- soap->iht[h] = ip;
- return ip;
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_malloc(struct soap *soap, size_t n)
-{ register char *p;
- if (!n)
- return NULL;
- if (!soap)
- return SOAP_MALLOC(n);
- n += (-(long)n) & 7;
- if (!(p = (char*)SOAP_MALLOC(n + sizeof(void*) + sizeof(size_t))))
- { soap->error = SOAP_EOM;
- return NULL;
- }
- /* keep chain of alloced cells for later destruction */
- soap->alloced = 1;
- *(void**)(p + n) = soap->alist;
- *(size_t*)(p + n + sizeof(void*)) = n;
- soap->alist = p + n;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Malloc %u bytes at location %p\n", (unsigned int)n, p));
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_dealloc(struct soap *soap, void *p)
-{ if (!soap)
- return;
- if (p)
- { register char **q;
- for (q = (char**)&soap->alist; *q; q = *(char***)q)
- { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
- { *q = **(char***)q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Freed data at %p\n", p));
- SOAP_FREE(p);
- return;
- }
- }
- soap_delete(soap, p);
- }
- else
- { register char *q;
- while (soap->alist)
- { q = (char*)soap->alist;
- soap->alist = *(void**)q;
- q -= *(size_t*)(q + sizeof(void*));
- SOAP_FREE(q);
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Dealloc all data done\n"));
- }
- /* we must assume these were deallocated: */
- soap->action = NULL;
- soap->fault = NULL;
- soap->header = NULL;
- soap->authrealm = NULL;
-#ifndef WITH_LEANER
- soap_clr_mime(soap);
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_delete(struct soap *soap, void *p)
-{ register struct soap_clist **cp = &soap->clist;
- if (p)
- { while (*cp)
- { if (p == (*cp)->ptr)
- { register struct soap_clist *q = *cp;
- *cp = q->next;
- q->fdelete(q);
- SOAP_FREE(q);
- return;
- }
- cp = &(*cp)->next;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: address not in list\n", p));
- }
- else
- { while (*cp)
- { register struct soap_clist *q = *cp;
- *cp = q->next;
- if (q->ptr == (void*)soap->fault)
- soap->fault = NULL; /* this was deallocated */
- else if (q->ptr == (void*)soap->header)
- soap->header = NULL; /* this was deallocated */
- q->fdelete(q);
- SOAP_FREE(q);
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-struct soap_clist *
-SOAP_FMAC2
-soap_link(struct soap *soap, void *p, int t, int n, void (*fdelete)(struct soap_clist*))
-{ register struct soap_clist *cp;
- if ((cp = (struct soap_clist*)SOAP_MALLOC(sizeof(struct soap_clist))))
- { cp->next = soap->clist;
- cp->type = t;
- cp->size = n;
- cp->ptr = p;
- cp->fdelete = fdelete;
- soap->clist = cp;
- }
- return cp;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_unlink(struct soap *soap, const void *p)
-{ register char **q;
- register struct soap_clist **cp;
- if (!soap || !p)
- return;
- for (q = (char**)&soap->alist; *q; q = *(char***)q)
- { if (p == (void*)(*q - *(size_t*)(*q + sizeof(void*))))
- { *q = **(char***)q;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked data %p\n", p));
- return;
- }
- }
- for (cp = &soap->clist; *cp; cp = &(*cp)->next)
- { if (p == (*cp)->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unlinked class instance %p\n", p));
- q = (char**)*cp;
- *cp = (*cp)->next;
- SOAP_FREE(q);
- return;
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_lookup_type(struct soap *soap, const char *id)
-{ register struct soap_ilist *ip;
- if (id && *id)
- { ip = soap_lookup(soap, id);
- if (ip)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Lookup id='%s' type=%d\n", id, ip->type));
- return ip->type;
- }
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "lookup type id='%s' NOT FOUND! Need to get it from xsi:type\n", id));
- return 0;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_lookup(struct soap *soap, const char *id, void **p, int t, size_t n, unsigned int k)
-{ struct soap_ilist *ip;
- void **q;
- if (!id || !*id)
- return p;
- soap->alloced = 0;
- if (!p)
- p = (void**)soap_malloc(soap, sizeof(void*));
- ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
- if (!ip)
- { ip = soap_enter(soap, id); /* new hash table entry for string id */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding first href='%s' type=%d %p (%u bytes)\n", id, t, p, (unsigned int)n));
- ip->type = t;
- ip->size = n;
- ip->link = p;
- ip->copy = NULL;
- ip->flist = NULL;
- ip->ptr = NULL;
- ip->level = k;
- *p = NULL;
- }
- else if (ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolved href='%s' type=%d location=%p (%u bytes)\n", id, t, ip->ptr, (unsigned int)n));
- if (ip->type != t)
- { strcpy(soap->id, id);
- soap->error = SOAP_HREF;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Type incompatibility: id type=%d href type=%d\n", ip->type, t));
- return NULL;
- }
- while (ip->level < k)
- { q = (void**)soap_malloc(soap, sizeof(void*));
- if (!q)
- return NULL;
- *p = (void*)q;
- p = q;
- k--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- *p = ip->ptr;
- }
- else if (ip->level > k)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving level %u pointers to href='%s'\n", ip->level, id));
- while (ip->level > k)
- { void *s, **r = &ip->link;
- q = (void**)ip->link;
- while (q)
- { *r = (void*)soap_malloc(soap, sizeof(void*));
- s = *q;
- *q = *r;
- r = (void**)*r;
- q = (void**)s;
- }
- *r = NULL;
- ip->size = n;
- ip->copy = NULL;
- ip->level = ip->level - 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- q = (void**)ip->link;
- ip->link = p;
- *p = (void*)q;
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarded href='%s' type=%d location=%p (%u bytes)\n", id, t, p, (unsigned int)n));
- while (ip->level < k)
- { q = (void**)soap_malloc(soap, sizeof(void*));
- *p = q;
- p = q;
- k--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Descending one level...\n"));
- }
- q = (void**)ip->link;
- ip->link = p;
- *p = (void*)q;
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_forward(struct soap *soap, const char *href, void *p, int st, int tt, size_t n, unsigned int k, void (*fcopy)(struct soap*, int, int, void*, const void*, size_t))
-{ struct soap_ilist *ip;
- if (!p || !href || !*href)
- return p;
- ip = soap_lookup(soap, href); /* lookup pointer to hash table entry for string id */
- if (!ip)
- { ip = soap_enter(soap, href); /* new hash table entry for string id */
- ip->type = st;
- ip->size = n;
- ip->link = NULL;
- ip->copy = NULL;
- ip->ptr = NULL;
- ip->level = 0;
- ip->flist = NULL;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "New entry href='%s' type=%d size=%lu level=%d location=%p\n", href, st, (unsigned long)n, k, p));
- }
- else if (ip->type != st || (ip->level == k && ip->size != n))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Type incompatibility id='%s' expect type=%d size=%lu level=%u got type=%d size=%lu\n", href, ip->type, (unsigned long)ip->size, k, st, (unsigned long)n));
- strcpy(soap->id, href);
- soap->error = SOAP_HREF;
- return NULL;
- }
- if (fcopy || n < sizeof(void*) || *href != '#')
- { register struct soap_flist *fp = (struct soap_flist*)SOAP_MALLOC(sizeof(struct soap_flist));
- if (!fp)
- { soap->error = SOAP_EOM;
- return NULL;
- }
- fp->next = ip->flist;
- fp->type = tt;
- fp->ptr = p;
- fp->level = k;
- if (fcopy)
- fp->fcopy = fcopy;
- else
- fp->fcopy = soap_fcopy;
- ip->flist = fp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding type=%d (target type=%d) size=%lu location=%p level=%u href='%s'\n", st, tt, (unsigned long)n, p, k, href));
- }
- else
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Forwarding copying address %p for type=%d href='%s'\n", p, st, href));
- *(void**)p = ip->copy;
- ip->copy = p;
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void*
-SOAP_FMAC2
-soap_id_enter(struct soap *soap, const char *id, void *p, int t, size_t n, unsigned int k, const char *type, const char *arrayType, void *(*finstantiate)(struct soap*, int, const char*, const char*, size_t*))
-{ struct soap_ilist *ip;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Enter id='%s' type=%d loc=%p size=%lu level=%u\n", id, t, p, (unsigned long)n, k));
- soap->alloced = 0;
- if (!p)
- { if (finstantiate)
- p = finstantiate(soap, t, type, arrayType, &n);
- else
- p = soap_malloc(soap, n);
- if (p)
- soap->alloced = 1;
- }
- if (!id || !*id)
- return p;
- ip = soap_lookup(soap, id); /* lookup pointer to hash table entry for string id */
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Lookup entry id='%s for location=%p'\n", id, p));
- if (!ip)
- { ip = soap_enter(soap, id); /* new hash table entry for string id */
- ip->type = t;
- ip->link = NULL;
- ip->copy = NULL;
- ip->flist = NULL;
- ip->size = n;
- ip->ptr = p;
- ip->level = k;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "New entry id='%s' type=%d size=%lu level=%u location=%p\n", id, t, (unsigned long)n, k, p));
- }
- else if ((ip->type != t || (ip->level == k && ip->size != n)) && (ip->copy || ip->flist))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Type incompatibility id='%s' expect type=%d size=%lu level=%u got type=%d size=%lu\n", id, ip->type, (unsigned long)ip->size, k, t, (unsigned long)n));
- strcpy(soap->id, id);
- soap->error = SOAP_HREF;
- return NULL;
- }
- else if (ip->ptr)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Multiply defined id='%s'\n", id));
- strcpy(soap->id, id);
- soap->error = SOAP_MULTI_ID;
- return NULL;
- }
- else
- { ip->size = n;
- ip->ptr = p;
- ip->level = k;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update entry id='%s' type=%d location=%p size=%lu level=%u\n", id, t, p, (unsigned long)n, k));
- }
- return ip->ptr;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_fcopy(struct soap *soap, int st, int tt, void *p, const void *q, size_t n)
-{ DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Copying data type=%d (target type=%d) %p -> %p (%lu bytes)\n", st, tt, q, p, (unsigned long)n));
- memcpy(p, q, n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_end_send(struct soap *soap)
-{
-#ifndef WITH_LEANER
- if (soap->dime.list)
- { /* SOAP body referenced attachments must appear first */
- soap->dime.last->next = soap->dime.first;
- soap->dime.first = soap->dime.list->next;
- soap->dime.list->next = NULL;
- soap->dime.last = soap->dime.list;
- }
- if (soap_putdime(soap) || soap_putmime(soap))
- return soap->error;
- soap->mime.list = NULL;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->dime.list = NULL;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End send\n"));
- if (soap->mode & SOAP_IO) /* need to flush the remaining data in buffer */
- { if (soap_flush(soap))
-#ifdef WITH_ZLIB
- { if (soap->mode & SOAP_ENC_ZLIB && soap->zlib_state == SOAP_ZLIB_DEFLATE)
- { soap->zlib_state = SOAP_ZLIB_NONE;
- deflateEnd(&soap->d_stream);
- }
- return soap->error;
- }
-#else
- return soap->error;
-#endif
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { int r;
- soap->d_stream.avail_in = 0;
- do
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating remainder\n"));
- r = deflate(&soap->d_stream, Z_FINISH);
- if (soap->d_stream.avail_out != SOAP_BUFLEN)
- { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN - soap->d_stream.avail_out))
- { soap->zlib_state = SOAP_ZLIB_NONE;
- deflateEnd(&soap->d_stream);
- return soap->error;
- }
- soap->d_stream.next_out = (Byte*)soap->z_buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- }
- } while (r == Z_OK);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflated %lu->%lu bytes\n", soap->d_stream.total_in, soap->d_stream.total_out));
- soap->z_ratio_out = (float)soap->d_stream.total_out / (float)soap->d_stream.total_in;
- soap->mode &= ~SOAP_ENC_ZLIB;
- soap->zlib_state = SOAP_ZLIB_NONE;
- if (deflateEnd(&soap->d_stream) != Z_OK || r != Z_STREAM_END)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to end deflate: %s\n", soap->d_stream.msg?soap->d_stream.msg:""));
- return soap->error = SOAP_ZLIB_ERROR;
- }
-#ifdef WITH_GZIP
- soap->z_buf[0] = soap->z_crc & 0xFF;
- soap->z_buf[1] = (soap->z_crc >> 8) & 0xFF;
- soap->z_buf[2] = (soap->z_crc >> 16) & 0xFF;
- soap->z_buf[3] = (soap->z_crc >> 24) & 0xFF;
- soap->z_buf[4] = soap->d_stream.total_in & 0xFF;
- soap->z_buf[5] = (soap->d_stream.total_in >> 8) & 0xFF;
- soap->z_buf[6] = (soap->d_stream.total_in >> 16) & 0xFF;
- soap->z_buf[7] = (soap->d_stream.total_in >> 24) & 0xFF;
- if (soap_flush_raw(soap, soap->z_buf, 8))
- return soap->error;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip crc32=%lu\n", (unsigned long)soap->z_crc));
-#endif
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
- { char *p;
- if (!(soap->mode & SOAP_ENC_XML))
- { soap->mode--;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending buffered message of length %u\n", (unsigned int)soap->blist->size));
- if (soap->status >= SOAP_POST)
- soap->error = soap->fpost(soap, soap->endpoint, soap->host, soap->port, soap->path, soap->action, soap->blist->size);
- else if (soap->status != SOAP_STOP)
- soap->error = soap->fresponse(soap, soap->status, soap->blist->size);
- if (soap->error || soap_flush(soap))
- return soap->error;
- soap->mode++;
- }
- for (p = soap_first_block(soap); p; p = soap_next_block(soap))
- { DBGMSG(SENT, p, soap_block_size(soap));
- if ((soap->error = soap->fsend(soap, p, soap_block_size(soap))))
- { soap_end_block(soap);
- return soap->error;
- }
- }
- soap_end_block(soap);
- }
- else if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { DBGMSG(SENT, "\r\n0\r\n\r\n", 7);
- if ((soap->error = soap->fsend(soap, "\r\n0\r\n\r\n", 7)))
- return soap->error;
- }
- }
-#ifdef WITH_OPENSSL
- if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive)
- soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */
-#else
- if (soap_valid_socket(soap->socket) && !soap->keep_alive)
- soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */
-#endif
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send message ok\n"));
- soap->part = SOAP_END;
- soap->count = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_end_recv(struct soap *soap)
-{ soap->part = SOAP_END;
-#ifndef WITH_LEANER
- if ((soap->mode & SOAP_ENC_MIME) && soap_getmime(soap))
- return soap->error;
- soap->mime.list = soap->mime.first;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->dime.list = soap->dime.first;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
-#endif
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "End of receive message ok\n"));
-#ifdef WITH_ZLIB
- if (soap->mode & SOAP_ENC_ZLIB)
- { soap->mode &= ~SOAP_ENC_ZLIB;
- memcpy(soap->buf, soap->z_buf, SOAP_BUFLEN);
- soap->bufidx = (char*)soap->d_stream.next_in - soap->z_buf;
- soap->buflen = soap->z_buflen;
- soap->zlib_state = SOAP_ZLIB_NONE;
- if (inflateEnd(&soap->d_stream) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
-#ifdef WITH_GZIP
- if (soap->zlib_in == SOAP_ZLIB_GZIP)
- { soap_wchar c;
- short i;
- for (i = 0; i < 8; i++)
- { if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
- soap->z_buf[i] = (char)c;
- }
- if (soap->z_crc != ((uLong)(unsigned char)soap->z_buf[0] | ((uLong)(unsigned char)soap->z_buf[1] << 8) | ((uLong)(unsigned char)soap->z_buf[2] << 16) | ((uLong)(unsigned char)soap->z_buf[3] << 24)))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: crc check failed, message corrupted? (crc32=%lu)\n", (unsigned long)soap->z_crc));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- if (soap->d_stream.total_out != ((uLong)(unsigned char)soap->z_buf[4] | ((uLong)(unsigned char)soap->z_buf[5] << 8) | ((uLong)(unsigned char)soap->z_buf[6] << 16) | ((uLong)(unsigned char)soap->z_buf[7] << 24)))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Gzip error: incorrect message length\n"));
- return soap->error = SOAP_ZLIB_ERROR;
- }
- }
-#endif
- }
-#endif
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- while ((int)soap_getchar(soap) != EOF) /* advance to last chunk */
- ;
- if (soap->fdisconnect && (soap->error = soap->fdisconnect(soap)))
- return soap->error;
- return soap_resolve(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_free(struct soap *soap)
-{ register struct soap_nlist *np;
- register struct soap_attribute *tp;
- register struct Namespace *ns;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n"));
- while (soap->nlist)
- { np = soap->nlist->next;
- if (soap->nlist->ns)
- SOAP_FREE(soap->nlist->ns);
- SOAP_FREE(soap->nlist);
- soap->nlist = np;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free any remaining temp blocks\n"));
- while (soap->blist)
- soap_end_block(soap);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attributes\n"));
- while (soap->attributes)
- { tp = soap->attributes->next;
- if (soap->attributes->value)
- SOAP_FREE(soap->attributes->value);
- SOAP_FREE(soap->attributes);
- soap->attributes = tp;
- }
-#ifdef WITH_FAST
- if (soap->labbuf)
- SOAP_FREE(soap->labbuf);
- soap->labbuf = NULL;
- soap->lablen = 0;
- soap->labidx = 0;
-#endif
- soap_free_pht(soap);
- soap_free_iht(soap);
- ns = soap->local_namespaces;
- if (ns)
- { for (; ns->id; ns++)
- { if (ns->out)
- { SOAP_FREE(ns->out);
- if (soap->encodingStyle == ns->out)
- soap->encodingStyle = SOAP_STR_EOS;
- ns->out = NULL;
- }
- if (soap->encodingStyle == ns->ns)
- soap->encodingStyle = SOAP_STR_EOS;
- }
- SOAP_FREE(soap->local_namespaces);
- soap->local_namespaces = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-static void
-soap_init_logs(struct soap *soap)
-{ int i;
- for (i = 0; i < SOAP_MAXLOGS; i++)
- { soap->logfile[i] = NULL;
- soap->fdebug[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#if !defined(WITH_LEAN) || defined(SOAP_DEBUG)
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_open_logfile(struct soap *soap, int i)
-{ if (soap->logfile[i])
- soap->fdebug[i] = fopen(soap->logfile[i], i < 2 ? "ab" : "a");
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-static void
-soap_close_logfile(struct soap *soap, int i)
-{ if (soap->fdebug[i])
- { fclose(soap->fdebug[i]);
- soap->fdebug[i] = NULL;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_close_logfiles(struct soap *soap)
-{ int i;
- for (i = 0; i < SOAP_MAXLOGS; i++)
- soap_close_logfile(soap, i);
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-static void
-soap_set_logfile(struct soap *soap, int i, const char *logfile)
-{ char *s = NULL;
- soap_close_logfile(soap, i);
- if (soap->logfile[i])
- SOAP_FREE((void*)soap->logfile[i]);
- if (logfile)
- if ((s = (char*)SOAP_MALLOC(strlen(logfile) + 1)))
- strcpy(s, logfile);
- soap->logfile[i] = s;
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_recv_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_RECV, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_sent_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_SENT, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifdef SOAP_DEBUG
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_test_logfile(struct soap *soap, const char *logfile)
-{ soap_set_logfile(soap, SOAP_INDEX_TEST, logfile);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_copy(struct soap *soap)
-{ return soap_copy_context((struct soap*)SOAP_MALLOC(sizeof(struct soap)), soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap*
-SOAP_FMAC2
-soap_copy_context(struct soap *copy, struct soap *soap)
-{ if (copy)
- { register struct soap_plugin *p;
- memcpy(copy, soap, sizeof(struct soap));
- copy->copy = 1;
- copy->user = NULL;
- copy->userid = NULL;
- copy->passwd = NULL;
- copy->nlist = NULL;
- copy->blist = NULL;
- copy->clist = NULL;
- copy->alist = NULL;
- copy->attributes = NULL;
- copy->local_namespaces = NULL;
- soap_set_local_namespaces(copy);
- soap_init_iht(copy);
- soap_init_pht(copy);
- copy->header = NULL;
- copy->fault = NULL;
- copy->action = NULL;
- *copy->host = '\0';
-#ifndef WITH_LEAN
-#ifdef WITH_COOKIES
- copy->cookies = soap_copy_cookies(soap);
-#else
- copy->cookies = NULL;
-#endif
-#endif
-#ifdef SOAP_DEBUG
- soap_init_logs(copy);
- soap_set_recv_logfile(copy, "RECV.log");
- soap_set_sent_logfile(copy, "SENT.log");
- soap_set_test_logfile(copy, "TEST.log");
-#endif
- copy->plugins = NULL;
- for (p = soap->plugins; p; p = p->next)
- { register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(sizeof(struct soap_plugin));
- if (!q)
- return NULL;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying plugin '%s'\n", p->id));
- *q = *p;
- if (p->fcopy && (soap->error = p->fcopy(soap, q, p)))
- { SOAP_FREE(q);
- return NULL;
- }
- q->next = copy->plugins;
- copy->plugins = q;
- }
- }
- else
- soap->error = SOAP_EOM;
- return copy;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init(struct soap *soap)
-{ soap->version = 0;
- soap_imode(soap, SOAP_IO_DEFAULT);
- soap_omode(soap, SOAP_IO_DEFAULT);
- soap->copy = 0;
- soap->plugins = NULL;
- soap->user = NULL;
- soap->userid = NULL;
- soap->passwd = NULL;
- soap->fpost = http_post;
- soap->fget = http_get;
- soap->fposthdr = http_post_header;
- soap->fresponse = http_response;
- soap->fparse = http_parse;
- soap->fparsehdr = http_parse_header;
- soap->fconnect = NULL;
- soap->fdisconnect = NULL;
-#ifndef MAC_CARBON
-#ifndef WITH_IPV6
- soap->fresolve = tcp_gethost;
-#else
- soap->fresolve = NULL;
-#endif
- soap->faccept = tcp_accept;
- soap->fopen = tcp_connect;
- soap->fclose = tcp_disconnect;
- soap->fclosesocket = tcp_closesocket;
- soap->fshutdownsocket = tcp_shutdownsocket;
- soap->fsend = fsend;
- soap->frecv = frecv;
- soap->fpoll = soap_poll;
-#else
- soap->fpoll = NULL;
-#endif
- soap->fprepareinit = NULL;
- soap->fpreparesend = NULL;
- soap->fpreparerecv = NULL;
- soap->fignore = NULL;
- soap->fserveloop = NULL;
- soap->fplugin = fplugin;
- soap->fdimereadopen = NULL;
- soap->fdimewriteopen = NULL;
- soap->fdimereadclose = NULL;
- soap->fdimewriteclose = NULL;
- soap->fdimeread = NULL;
- soap->fdimewrite = NULL;
- soap->float_format = "%.8g"; /* .8 preserves single FP precision as much as possible, but might not be very efficient */
- soap->double_format = "%.17lg"; /* .17 preserves double FP precision as much as possible, but might not be very efficient */
- soap->dime_id_format = "cid:id%d"; /* default DIME id format */
- soap->http_version = "1.1";
- soap->actor = NULL;
- soap->max_keep_alive = SOAP_MAXKEEPALIVE;
- soap->keep_alive = 0;
- soap->recv_timeout = 0;
- soap->send_timeout = 0;
- soap->connect_timeout = 0;
- soap->accept_timeout = 0;
- soap->socket_flags = 0;
- soap->connect_flags = 0;
- soap->bind_flags = 0;
- soap->accept_flags = 0;
- soap->ip = 0;
- soap->labbuf = NULL;
- soap->lablen = 0;
- soap->labidx = 0;
- soap->encodingStyle = SOAP_STR_EOS;
-#ifndef WITH_NONAMESPACES
- soap->namespaces = namespaces;
-#else
- soap->namespaces = NULL;
-#endif
- soap->local_namespaces = NULL;
- soap->nlist = NULL;
- soap->blist = NULL;
- soap->clist = NULL;
- soap->alist = NULL;
- soap->attributes = NULL;
- soap->header = NULL;
- soap->fault = NULL;
- soap->master = SOAP_INVALID_SOCKET;
- soap->socket = SOAP_INVALID_SOCKET;
- soap->os = NULL;
- soap->is = NULL;
- soap->dom = NULL;
- soap->dime.list = NULL;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
- soap->mime.list = NULL;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->mime.boundary = NULL;
- soap->mime.start = NULL;
-#ifndef UNDER_CE
- soap->recvfd = 0;
- soap->sendfd = 1;
-#else
- soap->recvfd = stdin;
- soap->sendfd = stdout;
-#endif
- soap->host[0] = '\0';
- soap->port = 0;
- soap->action = NULL;
- soap->proxy_host = NULL;
- soap->proxy_port = 8080;
- soap->proxy_userid = NULL;
- soap->proxy_passwd = NULL;
- soap->authrealm = NULL;
- soap->prolog = NULL;
-#ifdef WITH_OPENSSL
- soap->fsslauth = ssl_auth_init;
- soap->fsslverify = ssl_verify_callback;
- soap->bio = NULL;
- soap->ssl = NULL;
- soap->ctx = NULL;
- soap->require_server_auth = 0;
- soap->require_client_auth = 0;
- soap->rsa = 0;
- soap->keyfile = NULL;
- soap->password = NULL;
- soap->dhfile = NULL;
- soap->cafile = NULL;
- soap->capath = NULL;
- soap->randfile = NULL;
- soap->session = NULL;
-#endif
-#ifdef WITH_ZLIB
- soap->zlib_state = SOAP_ZLIB_NONE;
- soap->zlib_in = SOAP_ZLIB_NONE;
- soap->zlib_out = SOAP_ZLIB_NONE;
- soap->d_stream.zalloc = NULL;
- soap->d_stream.zfree = NULL;
- soap->d_stream.opaque = NULL;
- soap->z_level = 6;
-#endif
-#ifndef WITH_LEAN
- soap->cookies = NULL;
- soap->cookie_domain = NULL;
- soap->cookie_path = NULL;
- soap->cookie_max = 32;
-#endif
-#ifdef SOAP_DEBUG
- soap_init_logs(soap);
- soap_set_recv_logfile(soap, "RECV.log");
- soap_set_sent_logfile(soap, "SENT.log");
- soap_set_test_logfile(soap, NULL);
-#endif
-/* WR[ */
-#ifdef WMW_RPM_IO
- soap->rpmreqid = NULL;
-#endif /* WMW_RPM_IO */
-/* ]WR */
-#ifdef PALM
- palmNetLibOpen();
-#endif
- soap_init_iht(soap);
- soap_init_pht(soap);
- soap_begin(soap);
-#ifdef SOAP_DEBUG
- soap_set_test_logfile(soap, "TEST.log");
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init1(struct soap *soap, int mode)
-{ soap_init2(soap, mode, mode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_init2(struct soap *soap, int imode, int omode)
-{ soap_init(soap);
- soap_imode(soap, imode);
- soap_omode(soap, omode);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_begin(struct soap *soap)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing\n"));
- if (!soap->keep_alive)
- { soap->buflen = 0;
- soap->bufidx = 0;
- }
- soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0);
- soap->null = 0;
- soap->position = 0;
- soap->encoding = 0;
- soap->mustUnderstand = 0;
- soap->mode = 0;
- soap->ns = 0;
- soap->part = SOAP_BEGIN;
- soap->alloced = 0;
- soap->count = 0;
- soap->length = 0;
- soap->cdata = 0;
- soap->error = SOAP_OK;
- soap->peeked = 0;
- soap->ahead = 0;
- soap->idnum = 0;
- soap->level = 0;
- soap->endpoint[0] = '\0';
- soap->dime.chunksize = 0;
- soap->dime.buflen = 0;
- soap_free(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_end(struct soap *soap)
-{ register struct soap_clist *cp;
- soap_free(soap);
- soap_dealloc(soap, NULL);
- while (soap->clist)
- { cp = soap->clist->next;
- SOAP_FREE(soap->clist);
- soap->clist = cp;
- }
- soap_closesock(soap);
-#ifdef SOAP_DEBUG
- soap_close_logfiles(soap);
-#endif
-#ifdef PALM
- palmNetLibClose();
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_namespaces(struct soap *soap, struct Namespace *p)
-{ struct Namespace *ns = soap->local_namespaces;
- struct soap_nlist *np, *nq, *nr;
- unsigned int level = soap->level;
- soap->namespaces = p;
- soap->local_namespaces = NULL;
- soap_set_local_namespaces(soap);
- /* reverse the list */
- np = soap->nlist;
- soap->nlist = NULL;
- if (np)
- { nq = np->next;
- np->next = NULL;
- while (nq)
- { nr = nq->next;
- nq->next = np;
- np = nq;
- nq = nr;
- }
- }
- while (np)
- { soap->level = np->level; /* preserve element nesting level */
- if (np->ns)
- { if (soap_push_namespace(soap, np->id, np->ns))
- return soap->error;
- }
- else if (np->index >= 0 && ns)
- { if (ns[np->index].out)
- { if (soap_push_namespace(soap, np->id, ns[np->index].out))
- return soap->error;
- }
- else if (soap_push_namespace(soap, np->id, ns[np->index].ns))
- return soap->error;
- }
- if (np->ns)
- SOAP_FREE(np->ns);
- nq = np;
- np = np->next;
- SOAP_FREE(nq);
- }
- if (ns)
- { int i;
- for (i = 0; ns[i].id; i++)
- { if (ns[i].out)
- { SOAP_FREE(ns[i].out);
- ns[i].out = NULL;
- }
- }
- SOAP_FREE(ns);
- }
- soap->level = level; /* restore level */
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void
-soap_set_local_namespaces(struct soap *soap)
-{ if (soap->namespaces && !soap->local_namespaces)
- { register const struct Namespace *ns1;
- register struct Namespace *ns2;
- register size_t n = 1;
- for (ns1 = soap->namespaces; ns1->id; ns1++)
- n++;
- if (n > 3)
- { n *= sizeof(struct Namespace);
- ns2 = (struct Namespace*)SOAP_MALLOC(n);
- if (ns2)
- { memcpy(ns2, soap->namespaces, n);
- ns2[0].id = "SOAP-ENV";
- ns2[1].id = "SOAP-ENC";
- ns2[2].id = "xsi";
- if (ns2[0].ns)
- { if (!strcmp(ns2[0].ns, soap_env1))
- soap->version = 1;
- else
- soap->version = 2;
- }
- soap->local_namespaces = ns2;
- }
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element(struct soap *soap, const char *tag, int id, const char *type)
-{ struct Namespace *ns = soap->local_namespaces;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' id='%d' type='%s'\n", tag, id, type?type:""));
-/**/
-#ifdef WITH_DOM
- if (soap->mode & SOAP_XML_DOM)
- { register struct soap_dom_element *p, *e = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element));
- e->next = NULL;
- e->prnt = soap->dom;
- e->nstr = NULL;
- e->name = soap_strdup(soap, tag); /* check EOM? */
- e->data = NULL;
- e->type = 0;
- e->node = NULL;
- e->elts = NULL;
- e->atts = NULL;
- if (soap->dom)
- { p = soap->dom->elts;
- if (p)
- { while (p->next)
- p = p->next;
- p->next = e;
- }
- else
- soap->dom->elts = e;
- }
- soap->dom = e;
- }
- else
-#endif
-{
- soap->level++;
- if (!soap->ns && !(soap->mode & SOAP_XML_CANONICAL))
- if (soap_send(soap, soap->prolog ? soap->prolog : "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"))
- return soap->error;
- if (soap_send_raw(soap, "<", 1)
- || soap_send(soap, tag))
- return soap->error;
-}
-/**/
- if (!soap->ns)
- { for (ns = soap->local_namespaces; ns && ns->id; ns++)
- { if (*ns->id && (ns->out || ns->ns))
- { sprintf(soap->tmpbuf, "xmlns:%s", ns->id);
- if (soap_attribute(soap, soap->tmpbuf, ns->out ? ns->out : ns->ns))
- return soap->error;
- }
- }
- soap->ns = 1;
- }
- if (id > 0)
- { sprintf(soap->tmpbuf, "_%d", id);
- if (soap_attribute(soap, "id", soap->tmpbuf))
- return soap->error;
- }
- if (type && *type)
- { if (soap_attribute(soap, "xsi:type", type))
- return soap->error;
- }
- if (soap->null && soap->position > 0)
- { int i;
- sprintf(soap->tmpbuf, "[%d", soap->positions[0]);
- for (i = 1; i < soap->position; i++)
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), ",%d", soap->positions[i]);
- strcat(soap->tmpbuf, "]");
- if (soap_attribute(soap, "SOAP-ENC:position", soap->tmpbuf))
- return soap->error;
- }
- if (soap->mustUnderstand)
- { if (soap->actor && *soap->actor)
- { if (soap_attribute(soap, soap->version == 2 ? "SOAP-ENV:role" : "SOAP-ENV:actor", soap->actor))
- return soap->error;
- }
- if (soap_attribute(soap, "SOAP-ENV:mustUnderstand", soap->version == 2 ? "true" : "1"))
- return soap->error;
- soap->mustUnderstand = 0;
- }
- if (soap->encoding)
- { if (soap->encodingStyle && soap->local_namespaces)
- { if (!*soap->encodingStyle)
- { if (soap->local_namespaces[1].out)
- soap->encodingStyle = soap->local_namespaces[1].out;
- else
- soap->encodingStyle = soap->local_namespaces[1].ns;
- }
- if (soap_attribute(soap, "SOAP-ENV:encodingStyle", soap->encodingStyle))
- return soap->error;
- }
- soap->encoding = 0;
- }
- soap->null = 0;
- soap->position = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_begin_out(struct soap *soap, const char *tag, int id, const char *type)
-{ if (*tag == '-')
- return SOAP_OK;
- if (soap_element(soap, tag, id, type))
- return soap->error;
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRRCHR
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_strrchr(const char *s, int t)
-{ register char *r = NULL;
- while (*s)
- if (*s++ == t)
- r = (char*)s - 1;
- return r;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRTOL
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_strtol(const char *s, char **t, int b)
-{ register long n = 0;
- register int c;
- while (*s > 0 && *s <= 32)
- s++;
- if (b == 10)
- { short neg = 0;
- if (*s == '-')
- { s++;
- neg = 1;
- }
- else if (*s == '+')
- s++;
- while ((c = *s) && c >= '0' && c <= '9')
- { if (n > 214748364)
- break;
- n *= 10;
- n += c - '0';
- s++;
- }
- if (neg)
- n = -n;
- }
- else /* b == 16 and value is always positive */
- { while ((c = *s))
- { if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- if (n > 0x07FFFFFF)
- break;
- n <<= 4;
- n += c;
- s++;
- }
- }
- if (t)
- *t = (char*)s;
- return n;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-#ifndef HAVE_STRTOUL
-SOAP_FMAC1
-unsigned long
-SOAP_FMAC2
-soap_strtoul(const char *s, char **t, int b)
-{ unsigned long n = 0;
- register int c;
- while (*s > 0 && *s <= 32)
- s++;
- if (b == 10)
- { if (*s == '+')
- s++;
- while ((c = *s) && c >= '0' && c <= '9')
- { if (n > 429496729)
- break;
- n *= 10;
- n += c - '0';
- s++;
- }
- }
- else /* b == 16 */
- { while ((c = *s))
- { if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'A' && c <= 'F')
- c -= 'A' - 10;
- else if (c >= 'a' && c <= 'f')
- c -= 'a' - 10;
- if (n > 0x0FFFFFFF)
- break;
- n <<= 4;
- n += c;
- s++;
- }
- }
- if (t)
- *t = (char*)s;
- return n;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_array_begin_out(struct soap *soap, const char *tag, int id, const char *type, const char *offset)
-{ if (soap_element(soap, tag, id, "SOAP-ENC:Array"))
- return soap->error;
- if (soap->version == 2)
- { const char *s;
- s = soap_strrchr(type, '[');
- if ((size_t)(s - type) < sizeof(soap->tmpbuf))
- { strncpy(soap->tmpbuf, type, s - type);
- soap->tmpbuf[s - type] = '\0';
- if (type && *type && (soap_attribute(soap, "SOAP-ENC:itemType", soap->tmpbuf)))
- return soap->error;
- if (s && (soap_attribute(soap, "SOAP-ENC:arraySize", s + 1)))
- return soap->error;
- }
- }
- else
- { if (offset && (soap_attribute(soap, "SOAP-ENC:offset", offset)))
- return soap->error;
- if (type && *type && (soap_attribute(soap, "SOAP-ENC:arrayType", type)))
- return soap->error;
- }
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_start_end_out(struct soap *soap, const char *tag)
-{ register struct soap_attribute *tp;
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible)
- { register struct soap_dom_attribute *a = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
- a->next = soap->dom->atts;
- a->nstr = NULL;
- a->name = soap_strdup(soap, tp->name); /* check EOM */
- a->data = soap_strdup(soap, tp->value); /* check EOM */
- a->wide = NULL;
- soap->dom->atts = a;
- tp->visible = 0;
- }
- }
- return SOAP_OK;
- }
-#endif
-/**/
- for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible)
- { if (soap_send2(soap, " ", tp->name))
- return soap->error;
- if (tp->visible == 2 && tp->value)
- if (soap_send_raw(soap, "=\"", 2)
- || soap_string_out(soap, tp->value, 1)
- || soap_send_raw(soap, "\"", 1))
- return soap->error;
- tp->visible = 0;
- }
- }
- if (tag)
- { soap->level--;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { if (soap_send_raw(soap, ">", 1)
- || soap_element_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
- }
-#endif
- return soap_send_raw(soap, "/>", 2);
- }
- return soap_send_raw(soap, ">", 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_end_out(struct soap *soap, const char *tag)
-{ if (*tag == '-')
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element ending tag='%s'\n", tag));
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { if (soap->dom->prnt)
- soap->dom = soap->dom->prnt;
- return SOAP_OK;
- }
-#endif
-/**/
- soap->level--;
- if (soap_send_raw(soap, "</", 2)
- || soap_send(soap, tag))
- return soap->error;
- return soap_send_raw(soap, ">", 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_ref(struct soap *soap, const char *tag, int id, int href)
-{ register int n = 0;
- if (soap->version == 2)
- n = 1;
- sprintf(soap->href, "#_%d", href);
- return soap_element_href(soap, tag, id, "href" + n, soap->href + n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_href(struct soap *soap, const char *tag, int id, const char *ref, const char *val)
-{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element '%s' reference %s='%s'\n", tag, ref, val));
- if (soap_element(soap, tag, id, NULL)
- || soap_attribute(soap, ref, val)
- || soap_element_start_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_null(struct soap *soap, const char *tag, int id, const char *type)
-{ struct soap_attribute *tp;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (tp->visible)
- break;
- if (tp || (soap->version == 2 && soap->position > 0) || id > 0 || (soap->mode & SOAP_XML_NIL))
- { if (soap_element(soap, tag, id, type))
- return soap->error;
- if (soap->part != SOAP_IN_HEADER && soap->encodingStyle)
- if (soap_attribute(soap, "xsi:nil", "true"))
- return soap->error;
- return soap_element_start_end_out(soap, tag);
- }
- soap->null = 1;
- soap->position = 0;
- soap->mustUnderstand = 0;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_id(struct soap *soap, const char *tag, int id, const void *p, const struct soap_array *a, int n, const char *type, int t)
-{ struct soap_plist *pp;
- if (!p || (a && !a->__ptr))
- { soap_element_null(soap, tag, id, type);
- return -1;
- }
- if (soap->mode & SOAP_XML_TREE)
- return 0;
- if (id < 0)
- { if (a)
- id = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
- else
- id = soap_pointer_lookup(soap, p, t, &pp);
- if (id)
- { if (soap_is_embedded(soap, pp))
- { soap_element_ref(soap, tag, 0, id);
- return -1;
- }
- if (soap_is_single(soap, pp))
- return 0;
- soap_set_embedded(soap, pp);
- }
- }
- return id;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_result(struct soap *soap, const char *tag)
-{ if (soap->version == 2 && soap->encodingStyle)
- if (soap_element(soap, "SOAP-RPC:result", 0, NULL)
- || soap_attribute(soap, "xmlns:SOAP-RPC", soap_rpc)
- || soap_element_start_end_out(soap, NULL)
- || soap_string_out(soap, tag, 0)
- || soap_element_end_out(soap, "SOAP-RPC:result"))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_attribute(struct soap *soap, const char *name, const char *value)
-{
-/**/
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { register struct soap_dom_attribute *a = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute));
- a->next = soap->dom->atts;
- a->nstr = NULL;
- a->name = soap_strdup(soap, name); /* check EOM */
- a->data = soap_strdup(soap, value); /* check EOM */
- a->wide = NULL;
- soap->dom->atts = a;
- return SOAP_OK;
- }
-#endif
-/**/
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { if (soap_set_attr(soap, name, value))
- return soap->error;
- }
- else
-#endif
- { if (soap_send2(soap, " ", name))
- return soap->error;
- if (value)
- if (soap_send_raw(soap, "=\"", 2)
- || soap_string_out(soap, value, 1)
- || soap_send_raw(soap, "\"", 1))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_begin_in(struct soap *soap, const char *tag, int nillable)
-{ if (!soap_peek_element(soap))
- { if (soap->other)
- return soap->error = SOAP_TAG_MISMATCH;
- if (tag && *tag == '-')
- return SOAP_OK;
- if (!(soap->error = soap_match_tag(soap, soap->tag, tag)))
- { soap->peeked = 0;
- if (soap->body)
- soap->level++;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:"" ));
- if (!nillable && soap->null && (soap->mode & SOAP_XML_STRICT))
- return soap->error = SOAP_NULL;
- }
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_element_end_in(struct soap *soap, const char *tag)
-{ register soap_wchar c;
- register char *s;
- register const char *t;
- if (tag && *tag == '-')
- return SOAP_OK;
- soap->level--;
- soap_pop_namespace(soap);
- if (soap->peeked)
- { if (*soap->tag == '\0')
- { soap->peeked = 0;
- if (soap->error == SOAP_NO_TAG || soap->error == SOAP_TAG_END)
- soap->error = SOAP_OK;
- }
- else
- return soap->error = SOAP_TAG_END;
- }
- else
- { while (((c = soap_get(soap)) != SOAP_TT))
- { if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (c == SOAP_LT)
- return soap->error = SOAP_TAG_END;
- }
- }
- s = soap->tag;
- do c = soap_get(soap);
- while (soap_blank(c));
- do
- { *s++ = (char)c;
- c = soap_get(soap);
- } while (soap_notblank(c));
- *s = '\0';
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- while (soap_blank(c))
- c = soap_get(soap);
- if (c != SOAP_GT)
- return soap->error = SOAP_SYNTAX_ERROR;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:""));
- if (!tag)
- return SOAP_OK;
- if ((s = strchr(soap->tag, ':')))
- s++;
- else
- s = soap->tag;
- if ((t = strchr(tag, ':')))
- t++;
- else
- t = tag;
- if (!SOAP_STRCMP(s, t))
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element tag name does not match\n"));
- return soap->error = SOAP_SYNTAX_ERROR;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char *
-SOAP_FMAC2
-soap_attr_value(struct soap *soap, const char *name, int flag)
-{ register struct soap_attribute *tp;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!soap_match_tag(soap, tp->name, name))
- break;
- if (tp && tp->visible == 2)
- { if (flag == 2 && (soap->mode & SOAP_XML_STRICT))
- soap->error = SOAP_PROHIBITED;
- else
- return tp->value;
- }
- else if (flag == 1 && (soap->mode & SOAP_XML_STRICT))
- soap->error = SOAP_REQUIRED;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_attr(struct soap *soap, const char *name, const char *value)
-{ register struct soap_attribute *tp;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set attribute %s='%s'\n", name, value?value:""));
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!strcmp(tp->name, name))
- break;
- if (!tp)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute %s\n", name));
- if (!(tp = (struct soap_attribute*)SOAP_MALLOC(sizeof(struct soap_attribute) + strlen(name))))
- return soap->error = SOAP_EOM;
- tp->ns = NULL;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { struct soap_attribute **tpp = &soap->attributes;
- const char *s = strchr(name, ':');
- if (!strncmp(name, "xmlns", 5))
- { for (; *tpp; tpp = &(*tpp)->next)
- if (strncmp((*tpp)->name, "xmlns", 5) || strcmp((*tpp)->name + 5, name + 5) > 0)
- break;
- }
- else if (!s)
- { for (; *tpp; tpp = &(*tpp)->next)
- if (strncmp((*tpp)->name, "xmlns", 5) && ((*tpp)->ns || strcmp((*tpp)->name, name) > 0))
- break;
- }
- else
- { int k;
- for (; *tpp; tpp = &(*tpp)->next)
- { if (!strncmp((*tpp)->name, "xmlns:", 6) && !strncmp((*tpp)->name + 6, name, s - name) && !(*tpp)->name[6 + s - name])
- { if (!tp->ns)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Canonicalization: prefix %s=%p(%s)\n", name, (*tpp)->ns, (*tpp)->ns));
- tp->ns = (*tpp)->ns;
- }
- }
- else if (strncmp((*tpp)->name, "xmlns", 5) && (*tpp)->ns && tp->ns && ((k = strcmp((*tpp)->ns, tp->ns)) > 0 || (!k && strcmp((*tpp)->name, name) > 0)))
- break;
- }
- }
- tp->next = *tpp;
- *tpp = tp;
- }
- else
-#endif
- { tp->next = soap->attributes;
- soap->attributes = tp;
- }
- strcpy(tp->name, name);
- tp->value = NULL;
- }
- else if (value && tp->value && tp->size <= strlen(value))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attribute value of %s (free %p)\n", name, tp->value));
- SOAP_FREE(tp->value);
- tp->value = NULL;
- tp->ns = NULL;
- }
- if (value)
- { if (!tp->value)
- { tp->size = strlen(value) + 1;
- if (!(tp->value = (char*)SOAP_MALLOC(tp->size)))
- return soap->error = SOAP_EOM;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute value of %s (%p)\n", tp->name, tp->value));
- }
- strcpy(tp->value, value);
- if (!strncmp(tp->name, "xmlns:", 6))
- tp->ns = tp->value;
- tp->visible = 2;
- }
- else
- tp->visible = 1;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_attr(struct soap *soap)
-{ register struct soap_attribute *tp;
-#ifndef WITH_LEAN
- if (soap->mode & SOAP_XML_CANONICAL)
- { while (soap->attributes)
- { tp = soap->attributes->next;
- SOAP_FREE(soap->attributes->value);
- SOAP_FREE(soap->attributes);
- soap->attributes = tp;
- }
- }
- else
-#endif
- { for (tp = soap->attributes; tp; tp = tp->next)
- tp->visible = 0;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static int
-soap_getattrval(struct soap *soap, char *s, size_t n, soap_wchar d)
-{ size_t i;
- soap_wchar c;
- for (i = 0; i < n; i++)
- { c = soap_getutf8(soap);
- switch (c)
- {
- case SOAP_TT:
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case SOAP_LT:
- *s++ = '<';
- break;
- case SOAP_GT:
- if (d == ' ')
- { soap_unget(soap, c);
- *s = '\0';
- return SOAP_OK;
- }
- *s++ = '>';
- break;
- case SOAP_QT:
- if (c == d)
- { *s = '\0';
- return SOAP_OK;
- }
- *s++ = '"';
- break;
- case SOAP_AP:
- if (c == d)
- { *s = '\0';
- return SOAP_OK;
- }
- *s++ = '\'';
- break;
- case '\t':
- case '\n':
- case '\r':
- case ' ':
- case '/':
- if (d == ' ')
- { soap_unget(soap, c);
- *s = '\0';
- return SOAP_OK;
- }
- default:
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- }
- return soap->error = SOAP_EOM;
-}
-#endif
-
-/******************************************************************************/
-#ifdef WITH_FAST
-#ifndef PALM_2
-static int
-soap_append_lab(struct soap *soap, const char *s, size_t n)
-{ if (soap->labidx + n >= soap->lablen)
- { register char *t = soap->labbuf;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enlarging look-aside buffer to append data, old size=%lu", (unsigned long)soap->lablen));
- if (soap->lablen == 0)
- soap->lablen = SOAP_LABLEN;
- while (soap->labidx + n >= soap->lablen)
- soap->lablen <<= 1;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, ", new size=%lu\n", (unsigned long)soap->lablen));
- soap->labbuf = (char*)SOAP_MALLOC(soap->lablen);
- if (!soap->labbuf)
- { if (t)
- free(t);
- return soap->error = SOAP_EOM;
- }
- if (t && soap->labidx)
- { memcpy(soap->labbuf, t, soap->labidx);
- free(t);
- }
- }
- if (s)
- { memcpy(soap->labbuf + soap->labidx, s, n);
- soap->labidx += n;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_peek_element(struct soap *soap)
-{ register struct soap_attribute *tp;
- const char *t;
- register char *s;
- register soap_wchar c;
- register int i;
- if (soap->error == SOAP_NO_TAG || soap->error == SOAP_TAG_END || soap->error == SOAP_TAG_MISMATCH)
- soap->error = SOAP_OK; /* retry */
- if (soap->peeked)
- { if (*soap->tag == '\0')
- return soap->error = SOAP_NO_TAG;
- return SOAP_OK;
- }
- soap->peeked = 1;
- for (;;)
- { while (((c = soap_getutf8(soap)) != SOAP_LT) && c != SOAP_TT)
- { if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- }
- if (c == SOAP_TT)
- { *soap->tag = '\0';
- return soap->error = SOAP_NO_TAG; /* ending tag found */
- }
- s = soap->tag;
- do c = soap_get(soap);
- while (soap_blank(c));
- i = sizeof(soap->tag);
- while (c != '/' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- while (soap_blank(c))
- c = soap_get(soap);
- *s = '\0';
- if (*soap->tag != '?')
- break;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI <%s?>\n", soap->tag));
- while ((int)c != EOF && c != SOAP_GT && c != '?')
- { s = soap->tmpbuf;
- i = sizeof(soap->tmpbuf) - 2;
- while (c != '=' && c != SOAP_GT && c != '?' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- while (soap_blank(c))
- c = soap_get(soap);
- if (c == '=')
- { *s++ = '=';
- do c = soap_get(soap);
- while (soap_blank(c));
- if (c != SOAP_QT && c != SOAP_AP)
- { soap_unget(soap, c);
- c = ' '; /* blank delimiter */
- }
- if (soap_getattrval(soap, s, i, c) == SOAP_EOM)
- while (soap_getattrval(soap, soap->tmpbuf, sizeof(soap->tmpbuf), c) == SOAP_EOM)
- ;
- else if (!strcmp(soap->tag, "?xml") && (!soap_tag_cmp(soap->tmpbuf, "encoding=iso-8859-1") || !soap_tag_cmp(soap->tmpbuf, "encoding=latin1")))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML latin1 encoding\n"));
- soap->mode |= SOAP_ENC_LATIN;
- }
- }
- do c = soap_get(soap);
- while (soap_blank(c));
- }
- }
- soap->id[0] = '\0';
- soap->href[0] = '\0';
- soap->type[0] = '\0';
- soap->arrayType[0] = '\0';
- soap->arraySize[0] = '\0';
- soap->arrayOffset[0] = '\0';
- soap->other = 0;
- soap->root = -1;
- soap->position = 0;
- soap->null = 0;
- soap->mustUnderstand = 0;
- soap_clr_attr(soap);
- while ((int)c != EOF && c != SOAP_GT && c != '/')
- { s = soap->tmpbuf;
- i = sizeof(soap->tmpbuf);
- while (c != '=' && c != '/' && soap_notblank(c))
- { if (--i > 0)
- *s++ = (char)c;
- c = soap_get(soap);
- }
- *s = '\0';
- if (i == sizeof(soap->tmpbuf))
- return soap->error = SOAP_SYNTAX_ERROR;
- if (!strncmp(soap->tmpbuf, "xmlns:", 6))
- { soap->tmpbuf[5] = '\0';
- t = soap->tmpbuf + 6;
- }
- else if (!strcmp(soap->tmpbuf, "xmlns"))
- t = SOAP_STR_EOS;
- else
- t = NULL;
- for (tp = soap->attributes; tp; tp = tp->next)
- if (!SOAP_STRCMP(tp->name, soap->tmpbuf))
- break;
- if (!tp)
- { tp = (struct soap_attribute*)SOAP_MALLOC(sizeof(struct soap_attribute) + strlen(soap->tmpbuf));
- if (!tp)
- return soap->error = SOAP_EOM;
- strcpy(tp->name, soap->tmpbuf);
- tp->value = NULL;
- tp->size = 0;
- tp->next = soap->attributes;
- soap->attributes = tp;
- }
- while (soap_blank(c))
- c = soap_get(soap);
- if (c == '=')
- { do c = soap_get(soap);
- while (soap_blank(c));
- if (c != SOAP_QT && c != SOAP_AP)
- { soap_unget(soap, c);
- c = ' '; /* blank delimiter */
- }
- if (soap_getattrval(soap, tp->value, tp->size, c))
- {
-#ifdef WITH_FAST
- if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- soap->labidx = 0;
- if (soap_append_lab(soap, tp->value, tp->size))
- return soap->error;
- SOAP_FREE(tp->value);
- for (;;)
- { if (soap_getattrval(soap, soap->labbuf + soap->labidx, soap->lablen - soap->labidx, c))
- { if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- soap->labidx = soap->lablen;
- if (soap_append_lab(soap, NULL, 0))
- return soap->error;
- }
- else
- break;
- }
- tp->size = soap->lablen;
- if (!(tp->value = (char*)SOAP_MALLOC(tp->size)))
- return soap->error = SOAP_EOM;
- memcpy(tp->value, soap->labbuf, soap->lablen);
-#else
- size_t n;
- if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- if (soap_new_block(soap))
- return soap->error;
- for (;;)
- { if (!(s = (char*)soap_push_block(soap, SOAP_BLKLEN)))
- return soap->error;
- if (soap_getattrval(soap, s, SOAP_BLKLEN, c))
- { if (soap->error != SOAP_EOM)
- return soap->error;
- soap->error = SOAP_OK;
- }
- else
- break;
- }
- n = tp->size + soap->blist->size;
- if (!(s = (char*)SOAP_MALLOC(n)))
- return soap->error = SOAP_EOM;
- if (tp->value)
- { memcpy(s, tp->value, tp->size);
- SOAP_FREE(tp->value);
- }
- soap_save_block(soap, s + tp->size, 0);
- tp->value = s;
- tp->size = n;
-#endif
- }
- do c = soap_get(soap);
- while (soap_blank(c));
- tp->visible = 2; /* seen this attribute w/ value */
- }
- else
- tp->visible = 1; /* seen this attribute w/o value */
- if (t && tp->value)
- { if (soap_push_namespace(soap, t, tp->value))
- return soap->error;
- tp->visible = 0;
- }
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- for (tp = soap->attributes; tp; tp = tp->next)
- { if (tp->visible && tp->value)
- { if (!strcmp(tp->name, "id"))
- { *soap->id = '#';
- strncpy(soap->id + 1, tp->value, sizeof(soap->id) - 2);
- soap->id[sizeof(soap->id)-1] = '\0';
- }
- else if (!strcmp(tp->name, "href"))
- { strncpy(soap->href, tp->value, sizeof(soap->href) - 1);
- soap->href[sizeof(soap->href)-1] = '\0';
- }
- else if ((soap->version == 2 || (soap->mode & SOAP_XML_GRAPH)) && !strcmp(tp->name, "ref"))
- { *soap->href = '#';
- strncpy(soap->href + 1, tp->value, sizeof(soap->href) - 2);
- soap->href[sizeof(soap->href)-1] = '\0';
- }
- else if (!soap_match_tag(soap, tp->name, "xsi:type"))
- { strncpy(soap->type, tp->value, sizeof(soap->type) - 1);
- soap->type[sizeof(soap->type)-1] = '\0';
- }
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:arrayType"))
- { s = soap_strrchr(tp->value, '[');
- if (s && (size_t)(s - tp->value) < sizeof(soap->arrayType))
- { strncpy(soap->arrayType, tp->value, s - tp->value);
- soap->arrayType[s - tp->value] = '\0';
- strncpy(soap->arraySize, s, sizeof(soap->arraySize) - 1);
- }
- else
- strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1);
- soap->arraySize[sizeof(soap->arrayType)-1] = '\0';
- soap->arrayType[sizeof(soap->arrayType)-1] = '\0';
- }
- else if (soap->version == 2 && !soap_match_tag(soap, tp->name, "SOAP-ENC:itemType"))
- strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1);
- else if (soap->version == 2 && !soap_match_tag(soap, tp->name, "SOAP-ENC:arraySize"))
- strncpy(soap->arraySize, tp->value, sizeof(soap->arraySize) - 1);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:offset"))
- strncpy(soap->arrayOffset, tp->value, sizeof(soap->arrayOffset));
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:position"))
- soap->position = soap_getposition(tp->value, soap->positions);
- else if (soap->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENC:root"))
- soap->root = ((!strcmp(tp->value, "1") || !strcmp(tp->value, "true")));
- else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:actor")
- || !soap_match_tag(soap, tp->name, "SOAP-ENV:role"))
- { if ((!soap->actor || strcmp(soap->actor, tp->value))
- && strcmp(tp->value, "http://schemas.xmlsoap.org/soap/actor/next")
- && strcmp(tp->value, "http://www.w3.org/2003/05/soap-envelope/role/next"))
- soap->other = 1;
- }
- else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:mustUnderstand")
- && (!strcmp(tp->value, "1") || !strcmp(tp->value, "true")))
- soap->mustUnderstand = 1;
- else if ((!soap_match_tag(soap, tp->name, "xsi:null")
- || !soap_match_tag(soap, tp->name, "xsi:nil"))
- && (!strcmp(tp->value, "1")
- || !strcmp(tp->value, "true")))
- soap->null = 1;
- }
- }
- if (!(soap->body = (c != '/')))
- do c = soap_get(soap);
- while (soap_blank(c));
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_retry(struct soap *soap)
-{ soap->peeked = 1;
- soap->error = SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_revert(struct soap *soap)
-{ if (!soap->peeked)
- { soap->peeked = 1;
- if (soap->body)
- soap->level--;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Reverting last element (level=%u)\n", soap->level));
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_string_out(struct soap *soap, const char *s, int flag)
-{ register const char *t;
- register soap_wchar c;
- register soap_wchar mask = 0x80000000;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->data = soap_strdup(soap, s); /* check EOM */
- return SOAP_OK;
- }
-#endif
- if (soap->mode & SOAP_C_UTFSTRING)
- mask = 0;
- t = s;
- while ((c = *t++))
- { switch (c)
- {
- case 9:
- if (flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "	", 5))
- return soap->error;
- s = t;
- }
- break;
- case 10:
- if (flag || !(soap->mode & SOAP_XML_CANONICAL))
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
- return soap->error;
- s = t;
- }
- break;
- case 13:
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "
", 5))
- return soap->error;
- s = t;
- break;
- case '&':
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "&", 5))
- return soap->error;
- s = t;
- break;
- case '<':
- if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, "<", 4))
- return soap->error;
- s = t;
- break;
- case '>':
- if (!flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, ">", 4))
- return soap->error;
- s = t;
- }
- break;
- case '"':
- if (flag)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, """, 6))
- return soap->error;
- s = t;
- }
- break;
- default:
-#ifdef HAVE_MBTOWC
- if (soap->mode & SOAP_C_MBSTRING)
- { wchar_t wc;
- register int m = mbtowc(&wc, t - 1, MB_CUR_MAX);
- if (m > 0 && wc != c)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, wc))
- return soap->error;
- s = t + m - 1;
- continue;
- }
- }
-#endif
- if (c & mask)
- { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, (unsigned char)c))
- return soap->error;
- s = t;
- }
- }
- }
- return soap_send_raw(soap, s, t - s - 1);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_string_in(struct soap *soap, int flag, long minlen, long maxlen)
-{ register char *s;
- char *t = NULL;
- register size_t i;
- register long l = 0;
- register int n = 0;
- register int m = 0;
- register soap_wchar c;
-#ifdef HAVE_WCTOMB
- char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8];
-#else
- char buf[8];
-#endif
-#ifdef WITH_CDATA
- if (!flag)
- { register int state = 0;
-#ifdef WITH_FAST
- soap->labidx = 0; /* use look-aside buffer */
-#else
- if (soap_new_block(soap))
- return NULL;
-#endif
- for (;;)
- {
-#ifdef WITH_FAST
- register size_t k;
- if (soap_append_lab(soap, NULL, 0)) /* allocate more space in look-aside buffer if necessary */
- return NULL;
- s = soap->labbuf + soap->labidx; /* space to populate */
- k = soap->lablen - soap->labidx; /* number of bytes available */
- soap->labidx = soap->lablen; /* claim this space */
-#else
- register size_t k = SOAP_BLKLEN;
- if (!(s = (char*)soap_push_block(soap, k)))
- return NULL;
-#endif
- for (i = 0; i < k; i++)
- { if (m > 0)
- { *s++ = *t++; /* copy multibyte characters */
- m--;
- continue;
- }
- c = soap_getchar(soap);
- if ((int)c == EOF)
- goto end;
- if (c >= 0x80 && !(soap->mode & SOAP_ENC_LATIN))
- { soap_unget(soap, c);
- c = soap_getutf8(soap);
- if (soap->mode & SOAP_C_UTFSTRING)
- { if ((c & 0x80000000) && c >= -0x7FFFFF80 && c < SOAP_AP)
- { c &= 0x7FFFFFFF;
- t = buf;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- m = (int)(t - buf) - 1;
- t = buf;
- *s++ = *t++;
- continue;
- }
- }
- }
- switch (state)
- { case 1:
- if (c == ']')
- state = 4;
- *s++ = c;
- continue;
- case 2:
- if (c == '-')
- state = 6;
- *s++ = c;
- continue;
- case 3:
- if (c == '?')
- state = 8;
- *s++ = c;
- continue;
- /* CDATA */
- case 4:
- if (c == ']')
- state = 5;
- else
- state = 1;
- *s++ = c;
- continue;
- case 5:
- if (c == '>')
- state = 0;
- else
- state = 1;
- *s++ = c;
- continue;
- /* comment */
- case 6:
- if (c == '-')
- state = 7;
- else
- state = 2;
- *s++ = c;
- continue;
- case 7:
- if (c == '>')
- state = 0;
- else
- state = 2;
- *s++ = c;
- continue;
- /* PI */
- case 8:
- if (c == '>')
- state = 0;
- else
- state = 3;
- *s++ = c;
- continue;
- }
- switch (c)
- {
- case '/':
- if (n > 0)
- { c = soap_getchar(soap);
- if (c == '>')
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- c = soap_getchar(soap);
- if (c == '/')
- { if (n == 0)
- { c = SOAP_TT;
- goto end;
- }
- n--;
- }
- else if (c == '!')
- { c = soap_getchar(soap);
- if (c == '[')
- { do c = soap_getchar(soap);
- while ((int)c != EOF && c != '[');
- if ((int)c == EOF)
- goto end;
- t = (char*)"![CDATA[";
- m = 8;
- state = 1;
- }
- else if (c == '-')
- { if ((c = soap_getchar(soap)) == '-')
- state = 2;
- t = (char*)"!-";
- m = 2;
- soap_unget(soap, c);
- }
- else
- { t = (char*)"!";
- m = 1;
- soap_unget(soap, c);
- }
- *s++ = '<';
- break;
- }
- else if (c == '?')
- state = 3;
- else
- n++;
- soap_unget(soap, c);
- *s++ = '<';
- break;
- case '>':
- *s++ = '>';
- break;
- case '"':
- *s++ = '"';
- break;
- default:
-#ifdef HAVE_WCTOMB
- if (soap->mode & SOAP_C_MBSTRING)
- { m = wctomb(buf, c & 0x7FFFFFFF);
- if (m >= 1)
- { t = buf;
- *s++ = *t++;
- m--;
- }
- else
- *s++ = SOAP_UNKNOWN_CHAR;
- }
- else
-#endif
- *s++ = (char)(c & 0xFF);
- }
- l++;
- if ((soap->mode & SOAP_XML_STRICT) && maxlen >= 0 && l > maxlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too long: maxlen=%ld\n", maxlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- }
- }
- }
-#endif
-#ifdef WITH_FAST
- soap->labidx = 0; /* use look-aside buffer */
-#else
- if (soap_new_block(soap))
- return NULL;
-#endif
- for (;;)
- {
-#ifdef WITH_FAST
- register size_t k;
- if (soap_append_lab(soap, NULL, 0)) /* allocate more space in look-aside buffer if necessary */
- return NULL;
- s = soap->labbuf + soap->labidx; /* space to populate */
- k = soap->lablen - soap->labidx; /* number of bytes available */
- soap->labidx = soap->lablen; /* claim this space */
-#else
- register size_t k = SOAP_BLKLEN;
- if (!(s = (char*)soap_push_block(soap, k)))
- return NULL;
-#endif
- for (i = 0; i < k; i++)
- { if (m > 0)
- { *s++ = *t++; /* copy multibyte characters */
- m--;
- continue;
- }
- if (soap->mode & SOAP_C_UTFSTRING)
- { if (((c = soap_get(soap)) & 0x80000000) && c >= -0x7FFFFF80 && c < SOAP_AP)
- { c &= 0x7FFFFFFF;
- t = buf;
- if (c < 0x0800)
- *t++ = (char)(0xC0 | ((c >> 6) & 0x1F));
- else
- { if (c < 0x010000)
- *t++ = (char)(0xE0 | ((c >> 12) & 0x0F));
- else
- { if (c < 0x200000)
- *t++ = (char)(0xF0 | ((c >> 18) & 0x07));
- else
- { if (c < 0x04000000)
- *t++ = (char)(0xF8 | ((c >> 24) & 0x03));
- else
- { *t++ = (char)(0xFC | ((c >> 30) & 0x01));
- *t++ = (char)(0x80 | ((c >> 24) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 18) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 12) & 0x3F));
- }
- *t++ = (char)(0x80 | ((c >> 6) & 0x3F));
- }
- *t++ = (char)(0x80 | (c & 0x3F));
- m = (int)(t - buf) - 1;
- t = buf;
- *s++ = *t++;
- continue;
- }
- }
- else
- c = soap_getutf8(soap);
- switch (c)
- {
- case SOAP_TT:
- if (n == 0)
- goto end;
- n--;
- *s++ = '<';
- t = (char*)"/";
- m = 1;
- break;
- case SOAP_LT:
- n++;
- *s++ = '<';
- break;
- case SOAP_GT:
- *s++ = '>';
- break;
- case SOAP_QT:
- *s++ = '"';
- break;
- case SOAP_AP:
- *s++ = '\'';
- break;
- case '/':
- if (n > 0)
- { c = soap_get(soap);
- if (c == SOAP_GT)
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<' | 0x80000000:
- if (flag)
- *s++ = '<';
- else
- { *s++ = '&';
- t = (char*)"lt;";
- m = 3;
- }
- break;
- case '>' | 0x80000000:
- if (flag)
- *s++ = '>';
- else
- { *s++ = '&';
- t = (char*)"gt;";
- m = 3;
- }
- break;
- case '"' | 0x80000000:
- if (flag)
- *s++ = '"';
- else
- { *s++ = '&';
- t = (char*)"quot;";
- m = 5;
- }
- break;
- case '\'' | 0x80000000:
- if (flag)
- *s++ = '\'';
- else
- { *s++ = '&';
- t = (char*)"apos;";
- m = 5;
- }
- break;
- default:
- if ((int)c == EOF)
- goto end;
-#ifdef HAVE_WCTOMB
- if (soap->mode & SOAP_C_MBSTRING)
- { m = wctomb(buf, c & 0x7FFFFFFF);
- if (m >= 1)
- { t = buf;
- *s++ = *t++;
- m--;
- }
- else
- *s++ = SOAP_UNKNOWN_CHAR;
- }
- else
-#endif
- *s++ = (char)(c & 0xFF);
- }
- l++;
- if ((soap->mode & SOAP_XML_STRICT) && maxlen >= 0 && l > maxlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too long: maxlen=%ld\n", maxlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- }
- }
-end:
- soap_unget(soap, c);
- *s = '\0';
-#ifdef WITH_FAST
- t = soap_strdup(soap, soap->labbuf);
-#else
- soap_size_block(soap, i+1);
- t = soap_save_block(soap, NULL, 0);
-#endif
- if ((soap->mode & SOAP_XML_STRICT) && l < minlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too short: %ld chars, minlen=%ld\n", l, minlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- if (flag == 2)
- if (soap_s2QName(soap, t, &t))
- return NULL;
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_wstring_out(struct soap *soap, const wchar_t *s, int flag)
-{ const char *t;
- char tmp;
- register soap_wchar c;
-#ifdef WITH_DOM
- if ((soap->mode & SOAP_XML_DOM) && soap->dom)
- { soap->dom->wide = NULL; /* soap_malloc() ??? */
- return SOAP_OK;
- }
-#endif
- while ((c = *s++))
- { switch (c)
- {
- case 9:
- if (flag)
- t = "	";
- else
- t = "\t";
- break;
- case 10:
- if (flag || !(soap->mode & SOAP_XML_CANONICAL))
- t = "
";
- else
- t = "\n";
- break;
- case 13:
- t = "
";
- break;
- case '&':
- t = "&";
- break;
- case '<':
- t = "<";
- break;
- case '>':
- if (flag)
- t = ">";
- else
- t = ">";
- break;
- case '"':
- if (flag)
- t = """;
- else
- t = "\"";
- break;
- default:
- if (c > 0 && c < 0x80)
- { tmp = (char)c;
- if (soap_send_raw(soap, &tmp, 1))
- return soap->error;
- }
- else if (soap_pututf8(soap, (unsigned long)c))
- return soap->error;
- continue;
- }
- if (soap_send(soap, t))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t *
-SOAP_FMAC2
-soap_wstring_in(struct soap *soap, int flag, long minlen, long maxlen)
-{ wchar_t *s;
- register int i, n = 0;
- register long l = 0;
- register soap_wchar c;
- const char *t = NULL;
- if (soap_new_block(soap))
- return NULL;
- for (;;)
- { if (!(s = (wchar_t*)soap_push_block(soap, sizeof(wchar_t)*SOAP_BLKLEN)))
- return NULL;
- for (i = 0; i < SOAP_BLKLEN; i++)
- { if (t)
- { *s++ = (wchar_t)*t++;
- if (!*t)
- t = NULL;
- continue;
- }
- c = soap_getutf8(soap);
- switch (c)
- {
- case SOAP_TT:
- if (n == 0)
- goto end;
- n--;
- *s++ = '<';
- soap_unget(soap, '/');
- break;
- case SOAP_LT:
- n++;
- *s++ = '<';
- break;
- case SOAP_GT:
- *s++ = '>';
- break;
- case SOAP_QT:
- *s++ = '"';
- break;
- case SOAP_AP:
- *s++ = '\'';
- break;
- case '/':
- if (n > 0)
- { c = soap_getutf8(soap);
- if (c == SOAP_GT)
- n--;
- soap_unget(soap, c);
- }
- *s++ = '/';
- break;
- case '<':
- if (flag)
- *s++ = (soap_wchar)'<';
- else
- { *s++ = (soap_wchar)'&';
- t = "lt;";
- }
- break;
- case '>':
- if (flag)
- *s++ = (soap_wchar)'>';
- else
- { *s++ = (soap_wchar)'&';
- t = "gt;";
- }
- break;
- case '"':
- if (flag)
- *s++ = (soap_wchar)'"';
- else
- { *s++ = (soap_wchar)'&';
- t = "quot;";
- }
- break;
- default:
- if ((int)c == EOF)
- goto end;
- *s++ = (wchar_t)c & 0x7FFFFFFF;
- }
- l++;
- if ((soap->mode & SOAP_XML_STRICT) && maxlen >= 0 && l > maxlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too long: maxlen=%ld\n", maxlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- }
- }
-end:
- soap_unget(soap, c);
- *s = '\0';
- soap_size_block(soap, sizeof(wchar_t) * (i + 1));
- if ((soap->mode & SOAP_XML_STRICT) && l < minlen)
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "String too short: %ld chars, minlen=%ld\n", l, minlen));
- soap->error = SOAP_LENGTH;
- return NULL;
- }
- return (wchar_t*)soap_save_block(soap, NULL, 0);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_int2s(struct soap *soap, int n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outint(struct soap *soap, const char *tag, int id, const int *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, (long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2int(struct soap *soap, const char *s, int *p)
-{ if (s)
- { char *r;
- *p = (int)soap_strtol(s, &r, 10);
- if (*r)
- soap->error = SOAP_TYPE;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int *
-SOAP_FMAC2
-soap_inint(struct soap *soap, const char *tag, int *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
-#endif
- p = (int*)soap_id_enter(soap, soap->id, p, t, sizeof(int), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2int(soap, soap_value(soap), p))
- return NULL;
- }
- p = (int*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(int), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_long2s(struct soap *soap, long n)
-{ sprintf(soap->tmpbuf, "%ld", n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outlong(struct soap *soap, const char *tag, int id, const long *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2long(struct soap *soap, const char *s, long *p)
-{ if (s)
- { char *r;
- *p = soap_strtol(s, &r, 10);
- if (*r)
- soap->error = SOAP_TYPE;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-long *
-SOAP_FMAC2
-soap_inlong(struct soap *soap, const char *tag, long *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
-#endif
- p = (long*)soap_id_enter(soap, soap->id, p, t, sizeof(long), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2long(soap, soap_value(soap), p))
- return NULL;
- }
- p = (long*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(long), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_LONG642s(struct soap *soap, LONG64 n)
-{ sprintf(soap->tmpbuf, SOAP_LONG_FORMAT, n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outLONG64(struct soap *soap, const char *tag, int id, const LONG64 *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_LONG642s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2LONG64(struct soap *soap, const char *s, LONG64 *p)
-{ if (s && sscanf(s, SOAP_LONG_FORMAT, p) != 1)
- soap->error = SOAP_TYPE;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-LONG64 *
-SOAP_FMAC2
-soap_inLONG64(struct soap *soap, const char *tag, LONG64 *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":integer")
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":negativeInteger")
- && soap_match_tag(soap, soap->type, ":nonPositiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":long")
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
-#endif
- p = (LONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(LONG64), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2LONG64(soap, soap_value(soap), p))
- return NULL;
- }
- p = (LONG64*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(LONG64), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_byte2s(struct soap *soap, char n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outbyte(struct soap *soap, const char *tag, int id, const char *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, (long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2byte(struct soap *soap, const char *s, char *p)
-{ if (s)
- { long n;
- char *r;
- n = soap_strtol(s, &r, 10);
- if (*r || n < -128 || n > 127)
- soap->error = SOAP_TYPE;
- *p = (char)n;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_inbyte(struct soap *soap, const char *tag, char *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
-#endif
- p = (char*)soap_id_enter(soap, soap->id, p, t, sizeof(char), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2byte(soap, soap_value(soap), p))
- return NULL;
- }
- p = (char*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(char), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_short2s(struct soap *soap, short n)
-{ return soap_long2s(soap, (long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outshort(struct soap *soap, const char *tag, int id, const short *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_long2s(soap, (long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2short(struct soap *soap, const char *s, short *p)
-{ if (s)
- { long n;
- char *r;
- n = soap_strtol(s, &r, 10);
- if (*r || n < -32768 || n > 32767)
- soap->error = SOAP_TYPE;
- *p = (short)n;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-short *
-SOAP_FMAC2
-soap_inshort(struct soap *soap, const char *tag, short *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
-#endif
- p = (short*)soap_id_enter(soap, soap->id, p, t, sizeof(short), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2short(soap, soap_value(soap), p))
- return NULL;
- }
- p = (short*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(short), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_float2s(struct soap *soap, float n)
-{ const char *s;
- if (soap_isnan((double)n))
- s = "NaN";
- else if (soap_ispinff(n))
- s = "INF";
- else if (soap_isninff(n))
- s = "-INF";
- else
- { sprintf(soap->tmpbuf, soap->float_format, n);
- s = soap->tmpbuf;
- }
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outfloat(struct soap *soap, const char *tag, int id, const float *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_float2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2float(struct soap *soap, const char *s, float *p)
-{ if (s)
- { if (!soap_tag_cmp(s, "INF"))
- *p = FLT_PINFTY;
- else if (!soap_tag_cmp(s, "+INF"))
- *p = FLT_PINFTY;
- else if (!soap_tag_cmp(s, "-INF"))
- *p = FLT_NINFTY;
- else if (!soap_tag_cmp(s, "NaN"))
- *p = FLT_NAN;
- else
- {
-#ifdef HAVE_STRTOD
- char *r;
- *p = (float)strtod(s, &r);
- if (*r)
-#endif
-#ifdef HAVE_SSCANF
- if (sscanf(s, soap->float_format, p) != 1)
- soap->error = SOAP_TYPE;
-#else
- soap->error = SOAP_TYPE;
-#endif
- }
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static int soap_isnumeric(struct soap *soap, const char *type)
-{ if (soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":float")
- && soap_match_tag(soap, soap->type, ":double")
- && soap_match_tag(soap, soap->type, ":decimal")
- && soap_match_tag(soap, soap->type, ":integer")
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":negativeInteger")
- && soap_match_tag(soap, soap->type, ":nonPositiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":long")
- && soap_match_tag(soap, soap->type, ":int")
- && soap_match_tag(soap, soap->type, ":short")
- && soap_match_tag(soap, soap->type, ":byte")
- && soap_match_tag(soap, soap->type, ":unsignedLong")
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return SOAP_ERR;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-float *
-SOAP_FMAC2
-soap_infloat(struct soap *soap, const char *tag, float *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type != '\0' && soap_isnumeric(soap, type))
- return NULL;
-#endif
- p = (float*)soap_id_enter(soap, soap->id, p, t, sizeof(float), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2float(soap, soap_value(soap), p))
- return NULL;
- }
- p = (float*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(float), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_double2s(struct soap *soap, double n)
-{ const char *s;
- if (soap_isnan(n))
- s = "NaN";
- else if (soap_ispinfd(n))
- s = "INF";
- else if (soap_isninfd(n))
- s = "-INF";
- else
- { sprintf(soap->tmpbuf, soap->double_format, n);
- s = soap->tmpbuf;
- }
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outdouble(struct soap *soap, const char *tag, int id, const double *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_double2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2double(struct soap *soap, const char *s, double *p)
-{ if (s)
- { if (!soap_tag_cmp(s, "INF"))
- *p = DBL_PINFTY;
- else if (!soap_tag_cmp(s, "+INF"))
- *p = DBL_PINFTY;
- else if (!soap_tag_cmp(s, "-INF"))
- *p = DBL_NINFTY;
- else if (!soap_tag_cmp(s, "NaN"))
- *p = DBL_NAN;
- else
- {
-#ifdef HAVE_STRTOD
- char *r;
- *p = strtod(s, &r);
- if (*r)
-#endif
-#ifdef HAVE_SSCANF
- if (sscanf(s, soap->double_format, p) != 1)
- soap->error = SOAP_TYPE;
-#else
- soap->error = SOAP_TYPE;
-#endif
- }
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-double *
-SOAP_FMAC2
-soap_indouble(struct soap *soap, const char *tag, double *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type != '\0' && soap_isnumeric(soap, type))
- return NULL;
-#endif
- p = (double*)soap_id_enter(soap, soap->id, p, t, sizeof(double), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2double(soap, soap_value(soap), p))
- return NULL;
- }
- p = (double*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(double), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedByte2s(struct soap *soap, unsigned char n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedByte(struct soap *soap, const char *tag, int id, const unsigned char *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, (unsigned long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedByte(struct soap *soap, const char *s, unsigned char *p)
-{ if (s)
- { unsigned long n;
- char *r;
- n = soap_strtoul(s, &r, 10);
- if (*r || n > 255)
- soap->error = SOAP_TYPE;
- *p = (unsigned char)n;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned char *
-SOAP_FMAC2
-soap_inunsignedByte(struct soap *soap, const char *tag, unsigned char *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
-#endif
- p = (unsigned char*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned char), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2unsignedByte(soap, soap_value(soap), p))
- return NULL;
- }
- p = (unsigned char*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned char), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedShort2s(struct soap *soap, unsigned short n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedShort(struct soap *soap, const char *tag, int id, const unsigned short *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, (unsigned long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedShort(struct soap *soap, const char *s, unsigned short *p)
-{ if (s)
- { unsigned long n;
- char *r;
- n = soap_strtoul(s, &r, 10);
- if (*r || n > 65535)
- soap->error = SOAP_TYPE;
- *p = (unsigned short)n;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-unsigned short *
-SOAP_FMAC2
-soap_inunsignedShort(struct soap *soap, const char *tag, unsigned short *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
-#endif
- p = (unsigned short*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned short), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2unsignedShort(soap, soap_value(soap), p))
- return NULL;
- }
- p = (unsigned short*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned short), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedInt2s(struct soap *soap, unsigned int n)
-{ return soap_unsignedLong2s(soap, (unsigned long)n);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedInt(struct soap *soap, const char *tag, int id, const unsigned int *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, (unsigned long)*p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedInt(struct soap *soap, const char *s, unsigned int *p)
-{ if (s)
- { char *r;
- *p = (unsigned int)soap_strtoul(s, &r, 10);
- if (*r)
- soap->error = SOAP_TYPE;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned int *
-SOAP_FMAC2
-soap_inunsignedInt(struct soap *soap, const char *tag, unsigned int *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
-#endif
- p = (unsigned int*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned int), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2unsignedInt(soap, soap_value(soap), p))
- return NULL;
- }
- p = (unsigned int*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned int), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_unsignedLong2s(struct soap *soap, unsigned long n)
-{ sprintf(soap->tmpbuf, "%lu", n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outunsignedLong(struct soap *soap, const char *tag, int id, const unsigned long *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_unsignedLong2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2unsignedLong(struct soap *soap, const char *s, unsigned long *p)
-{ if (s)
- { char *r;
- *p = soap_strtoul(s, &r, 10);
- if (*r)
- soap->error = SOAP_TYPE;
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-unsigned long *
-SOAP_FMAC2
-soap_inunsignedLong(struct soap *soap, const char *tag, unsigned long *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
-#ifndef WITH_LEAN
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
-#endif
- p = (unsigned long*)soap_id_enter(soap, soap->id, p, t, sizeof(unsigned long), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2unsignedLong(soap, soap_value(soap), p))
- return NULL;
- }
- p = (unsigned long*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned long), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_ULONG642s(struct soap *soap, ULONG64 n)
-{ sprintf(soap->tmpbuf, SOAP_ULONG_FORMAT, n);
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outULONG64(struct soap *soap, const char *tag, int id, const ULONG64 *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_ULONG642s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2ULONG64(struct soap *soap, const char *s, ULONG64 *p)
-{ if (s && sscanf(s, SOAP_ULONG_FORMAT, p) != 1)
- soap->error = SOAP_TYPE;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-ULONG64 *
-SOAP_FMAC2
-soap_inULONG64(struct soap *soap, const char *tag, ULONG64 *p, const char *type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":positiveInteger")
- && soap_match_tag(soap, soap->type, ":nonNegativeInteger")
- && soap_match_tag(soap, soap->type, ":unsignedLong")
- && soap_match_tag(soap, soap->type, ":unsignedInt")
- && soap_match_tag(soap, soap->type, ":unsignedShort")
- && soap_match_tag(soap, soap->type, ":unsignedByte"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (ULONG64*)soap_id_enter(soap, soap->id, p, t, sizeof(ULONG64), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2ULONG64(soap, soap_value(soap), p))
- return NULL;
- }
- p = (ULONG64*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(ULONG64), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2string(struct soap *soap, const char *s, char **t)
-{ *t = NULL;
- if (s && !(*t = soap_strdup(soap, s)))
- soap->error = SOAP_EOM;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2QName(struct soap *soap, const char *s, char **t)
-{ if (s)
- { struct soap_nlist *np;
- const char *p;
- if (!strncmp(s, "xml:", 4))
- { *t = soap_strdup(soap, s);
- return SOAP_OK;
- }
- np = soap->nlist;
- p = strchr(s, ':');
- if (p)
- { register int n = p - s;
- while (np && (strncmp(np->id, s, n) || np->id[n]))
- np = np->next;
- p++;
- }
- else
- { while (np && *np->id)
- np = np->next;
- p = s;
- }
- if (np)
- { if (np->index >= 0 && soap->local_namespaces)
- { register const char *q = soap->local_namespaces[np->index].id;
- if (q)
- { if ((*t = (char*)soap_malloc(soap, strlen(p) + strlen(q) + 2)))
- sprintf(*t, "%s:%s", q, p);
- return SOAP_OK;
- }
- }
- if (np->ns)
- { if ((*t = (char*)soap_malloc(soap, strlen(p) + strlen(np->ns) + 4)))
- sprintf(*t, "\"%s\":%s", np->ns, p);
- return SOAP_OK;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Namespace prefix of '%s' not defined (index=%d, URI=%s)\n", s, np->index, np->ns?np->ns:""));
- return soap->error = SOAP_NAMESPACE;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Namespace prefix of '%s' not defined, assuming empty namespace\n", s));
- if ((*t = (char*)soap_malloc(soap, strlen(p) + 4)))
- sprintf(*t, "\"\":%s", p);
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_QName2s(struct soap *soap, const char *s)
-{ struct Namespace *p;
- char *t;
- int n;
- if (!s || *s != '"')
- return s;
- s++;
- if ((p = soap->local_namespaces))
- { for (; p->id; p++)
- { if (p->ns)
- if (!soap_tag_cmp(s, p->ns))
- break;
- if (p->in)
- if (!soap_tag_cmp(s, p->in))
- break;
- }
- if (p && p->id)
- { s = strchr(s, '"');
- if (s)
- { t = (char*)soap_malloc(soap, strlen(p->id) + strlen(s));
- strcpy(t, p->id);
- strcat(t, s + 1);
- return t;
- }
- }
- }
- t = (char*)strchr(s, '"');
- if (t)
- n = t - s;
- else
- n = 0;
- t = soap_strdup(soap, s);
- t[n] = '\0';
- sprintf(soap->tmpbuf, "xmlns:_%lu", soap->idnum++);
- soap_set_attr(soap, soap->tmpbuf, t);
- s = strchr(s, '"');
- if (s)
- { t = (char*)soap_malloc(soap, strlen(soap->tmpbuf) + strlen(s) - 6);
- strcpy(t, soap->tmpbuf + 6);
- strcat(t, s + 1);
- }
- return t;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outstring(struct soap *soap, const char *tag, int id, char *const*p, const char *type, int n)
-{ id = soap_element_id(soap, tag, id, *p, NULL, 0, type, n);
- if (id < 0
- || soap_element_begin_out(soap, tag, id, type)
- || soap_string_out(soap, *p, 0)
- || soap_element_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char **
-SOAP_FMAC2
-soap_instring(struct soap *soap, const char *tag, char **p, const char *type, int t, int flag, long minlen, long maxlen)
-{ if (soap_element_begin_in(soap, tag, 1))
- return NULL;
- if (!p)
- if (!(p = (char**)soap_malloc(soap, sizeof(char*))))
- return NULL;
- if (soap->body)
- { *p = soap_string_in(soap, flag, minlen, maxlen);
- if (!*p || !(char*)soap_id_enter(soap, soap->id, *p, t, sizeof(char*), 0, NULL, NULL, NULL))
- return NULL;
- }
- else
- *p = NULL;
- p = (char**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(char**), 0);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outwstring(struct soap *soap, const char *tag, int id, wchar_t *const*p, const char *type, int n)
-{ id = soap_element_id(soap, tag, id, *p, NULL, 0, type, n);
- if (id < 0
- || soap_element_begin_out(soap, tag, id, type)
- || soap_wstring_out(soap, *p, 0)
- || soap_element_end_out(soap, tag))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t **
-SOAP_FMAC2
-soap_inwstring(struct soap *soap, const char *tag, wchar_t **p, const char *type, int t, long minlen, long maxlen)
-{ if (soap_element_begin_in(soap, tag, 1))
- return NULL;
- if (!p)
- if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*))))
- return NULL;
- if (soap->body)
- { *p = soap_wstring_in(soap, 1, minlen, maxlen);
- if (!*p || !(wchar_t*)soap_id_enter(soap, soap->id, *p, t, sizeof(wchar_t*), 0, NULL, NULL, NULL))
- return NULL;
- }
- else
- *p = NULL;
- p = (wchar_t**)soap_id_lookup(soap, soap->href, (void**)p, t, sizeof(wchar_t**), 0);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static time_t
-soap_timegm(struct tm *T)
-{
-#if defined(HAVE_TIMEGM)
- return timegm(T);
-#elif defined(HAVE_GETTIMEOFDAY)
- struct timezone t;
- struct timeval tv;
- memset((void*)&t, 0, sizeof(t));
- gettimeofday(&tv, &t);
- T->tm_min -= t.tz_minuteswest - (t.tz_dsttime != 0)*60;
- T->tm_isdst = 0;
- return mktime(T);
-/* WR[ */
- /* The following define was added for VxWorks*/
-#elif defined(HAVE_MKTIME)
- /* FOR VXWORKS:
- vxWorks does not seem to have any variable representation of time zones, but
- timezone information can be set in INSTALL_DIR/target/h/private/timeP.h header
- file, by setting the ZONEBUFFER define. The ZONEBUFFER define follows this
- format:
- name_of_zone:<(unused)>:time_in_minutes_from_UTC:daylight_start:daylight_end
- To calculate local time, the value of time_in_minutes_from_UTC is subtracted
- from UTC; time_in_minutes_from_UTC must be positive. Daylight information is
- expressed as mmddhh (month-day-hour), for example:
- UTC::0:040102:100102
- */
- return mktime(T);
-/* ]WR */
-#elif defined(HAVE_FTIME)
- struct timeb t;
- memset((void*)&t, 0, sizeof(t));
- t.timezone = 0;
- t.dstflag = -1;
- ftime(&t);
- T->tm_min -= t.timezone - (t.dstflag != 0)*60;
- T->tm_isdst = 0;
- return mktime(T);
-#else
-#warning "time_t (de)serialization is not MT safe on this platform"
- time_t t;
- char *tz = getenv("TZ");
- putenv("TZ=UTC");
- tzset();
- t = mktime(T);
- if (tz)
- { char tmp[16];
- strcpy(tmp, "TZ=");
- strncat(tmp, tz, 12);
- tmp[15] = '\0';
- putenv(tmp);
- }
- else
- putenv("TZ=");
- tzset();
- return t;
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_dateTime2s(struct soap *soap, time_t n)
-{ struct tm T;
- struct tm *pT = &T;
-#if defined(HAVE_GMTIME_R)
- if (gmtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PGMTIME_R)
- if (gmtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-#elif defined(HAVE_PGMTIME)
- if (gmtime(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-/* ]WR */
-#elif defined(HAVE_GMTIME)
- if ((pT = gmtime(&n)))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", pT);
-#elif defined(HAVE_GETTIMEOFDAY)
- struct timezone tz;
- memset((void*)&tz, 0, sizeof(tz));
-#if defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- { struct timeval tv;
- gettimeofday(&tv, &tz);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(tz.tz_dsttime!=0), abs(tz.tz_minuteswest)%60);
- }
-#else
- if ((pT = localtime(&n)))
- { struct timeval tv;
- gettimeofday(&tv, &tz);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -tz.tz_minuteswest/60+(tz.tz_dsttime!=0), abs(tz.tz_minuteswest)%60);
- }
-#endif
-#elif defined(HAVE_FTIME)
- struct timeb t;
- memset((void*)&t, 0, sizeof(t));
-#if defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- { ftime(&t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(t.dstflag!=0), abs(t.timezone)%60);
- }
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PLOCALTIME_R)
- if (localtime_r(&n, pT))
- { strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf+strlen(soap->tmpbuf), "%+03d:%02d", t.timezone/60, abs(t.timezone)%60);
- }
-/* ]WR */
-#else
- if ((pT = localtime(&n)))
- { ftime(&t);
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
- sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(t.dstflag!=0), abs(t.timezone)%60);
- }
-#endif
-#elif defined(HAVE_LOCALTIME_R)
- if (localtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-/* WR[ */
- /* The following defines were added for VxWorks*/
-#elif defined(HAVE_PLOCALTIME_R)
- if (localtime_r(&n, pT))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-/* ]WR */
-#else
- if ((pT = localtime(&n)))
- strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT);
-#endif
- else
- strcpy(soap->tmpbuf, "1969-12-31T23:59:59Z");
- return soap->tmpbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outdateTime(struct soap *soap, const char *tag, int id, const time_t *p, const char *type, int n)
-{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, p, n), type)
- || soap_string_out(soap, soap_dateTime2s(soap, *p), 0))
- return soap->error;
- return soap_element_end_out(soap, tag);
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_s2dateTime(struct soap *soap, const char *s, time_t *p)
-{ if (s)
- { struct tm T;
- char zone[16];
- memset((void*)&T, 0, sizeof(T));
- zone[sizeof(zone)-1] = '\0';
- sscanf(s, "%d-%d-%dT%d:%d:%d%15s", &T.tm_year, &T.tm_mon, &T.tm_mday, &T.tm_hour, &T.tm_min, &T.tm_sec, zone);
- if (T.tm_year == 1)
- T.tm_year = 70;
- else
- T.tm_year -= 1900;
- T.tm_mon--;
- if (*zone)
- { if (*zone == '.')
- { for (s = zone + 1; *s; s++)
- if (*s < '0' || *s > '9')
- break;
- }
- else
- s = zone;
- if (*s != 'Z')
- { int h = 0, m = 0;
- sscanf(s, "%d:%d", &h, &m);
- T.tm_hour -= h;
- if (h >= 0)
- T.tm_min -= m;
- else
- T.tm_min += m;
- }
- *p = soap_timegm(&T);
- }
- else
- *p = mktime(&T); /* no time zone: suppose it is localtime? */
- }
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-time_t *
-SOAP_FMAC2
-soap_indateTime(struct soap *soap, const char *tag, time_t *p, const char * type, int t)
-{ if (soap_element_begin_in(soap, tag, 0))
- return NULL;
- if (*soap->type
- && soap_match_tag(soap, soap->type, type)
- && soap_match_tag(soap, soap->type, ":dateTime"))
- { soap->error = SOAP_TYPE;
- soap_revert(soap);
- return NULL;
- }
- p = (time_t*)soap_id_enter(soap, soap->id, p, t, sizeof(time_t), 0, NULL, NULL, NULL);
- if (p)
- { if (soap_s2dateTime(soap, soap_value(soap), p))
- return NULL;
- }
- p = (time_t*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(time_t), 0, NULL);
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outliteral(struct soap *soap, const char *tag, char *const*p)
-{ int i;
- const char *t = NULL;
- if (tag && *tag != '-')
- { if ((t = strchr(tag, ':')))
- { strncpy(soap->tmpbuf, tag, t-tag);
- soap->tmpbuf[t-tag] = '\0';
- for (i = 0; soap->local_namespaces[i].id; i++)
- if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
- break;
- t++;
- sprintf(soap->tmpbuf, "<%s xmlns=\"%s\">", t, soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS);
- }
- else
- { t = tag;
- sprintf(soap->tmpbuf, "<%s>", tag);
- }
- if (soap_send(soap, soap->tmpbuf))
- return soap->error;
- }
- if (p && *p)
- { if (soap_send(soap, *p))
- return soap->error;
- }
- if (t)
- { sprintf(soap->tmpbuf, "</%s>", t);
- return soap_send(soap, soap->tmpbuf);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-char **
-SOAP_FMAC2
-soap_inliteral(struct soap *soap, const char *tag, char **p)
-{ if (soap_element_begin_in(soap, tag, 1))
- return NULL;
- if (!p)
- if (!(p = (char**)soap_malloc(soap, sizeof(char*))))
- return NULL;
- if (soap->null)
- *p = NULL;
- else if (soap->body)
- *p = soap_string_in(soap, 0, -1, -1);
- else
- *p = NULL;
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p)
-{ int i;
- const char *t = NULL;
- wchar_t c;
- const wchar_t *s;
- if (tag && *tag != '-')
- { if (tag && (t = strchr(tag, ':')))
- { strncpy(soap->tmpbuf, tag, t-tag);
- soap->tmpbuf[t-tag] = '\0';
- for (i = 0; soap->local_namespaces[i].id; i++)
- if (!strcmp(soap->tmpbuf, soap->local_namespaces[i].id))
- break;
- t++;
- sprintf(soap->tmpbuf, "<%s xmlns=\"%s\">", t, soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS);
- }
- else
- { t = tag;
- sprintf(soap->tmpbuf, "<%s>", tag);
- }
- if (soap_send(soap, soap->tmpbuf))
- return soap->error;
- }
- if (p)
- { s = *p;
- while ((c = *s++))
- if (soap_pututf8(soap, (unsigned char)c))
- return soap->error;
- }
- if (t)
- { sprintf(soap->tmpbuf, "</%s>", t);
- return soap_send(soap, soap->tmpbuf);
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-wchar_t **
-SOAP_FMAC2
-soap_inwliteral(struct soap *soap, const char *tag, wchar_t **p)
-{ if (soap_element_begin_in(soap, tag, 1))
- return NULL;
- if (!p)
- if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*))))
- return NULL;
- if (soap->null)
- *p = NULL;
- else if (soap->body)
- *p = soap_wstring_in(soap, 0, -1, -1);
- else
- *p = NULL;
- if (soap->body && soap_element_end_in(soap, tag))
- return NULL;
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-const char *
-SOAP_FMAC2
-soap_value(struct soap *soap)
-{ size_t i;
- soap_wchar c = 0;
- char *s = soap->tmpbuf;
- if (!soap->body)
- return SOAP_STR_EOS;
- for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++)
- { c = soap_get(soap);
- if (c == SOAP_TT || (int)c == EOF || soap_blank(c))
- break;
- *s++ = (char)c;
- }
- if ((int)c == EOF || c == SOAP_TT)
- soap_unget(soap, c);
- *s = '\0';
- return soap->tmpbuf; /* return non-null pointer */
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getline(struct soap *soap, char *s, int len)
-{ int i = len;
- soap_wchar c = 0;
- for (;;)
- { while (--i > 0)
- { c = soap_getchar(soap);
- if (c == '\r')
- break;
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- c = soap_getchar(soap);
- if (c == '\n')
- { *s = '\0';
- if (i+1 == len) /* empty line: end of HTTP header */
- break;
- c = soap_unget(soap, soap_getchar(soap));
- if (c != ' ' && c != '\t') /* HTTP line continuation? */
- break;
- }
- else if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static size_t
-soap_count_attachments(struct soap *soap)
-{
-#ifndef WITH_LEANER
- register struct soap_multipart *content;
- register size_t count = soap->count;
- if (soap->mode & SOAP_ENC_DIME)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the size of DIME attachments\n"));
- for (content = soap->dime.first; content; content = content->next)
- { count += 12 + ((content->size+3)&(~3));
- if (content->id)
- count += ((strlen(content->id)+3)&(~3));
- if (content->type)
- count += ((strlen(content->type)+3)&(~3));
- if (content->options)
- count += ((((unsigned char)content->options[2] << 8) | ((unsigned char)content->options[3]))+7)&(~3);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Size of DIME attachment %lu bytes\n", (unsigned long)content->size));
- }
- }
- if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary)
- { register size_t n = strlen(soap->mime.boundary);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the size of MIME attachments\n"));
- for (content = soap->mime.first; content; content = content->next)
- { register const char *s;
- /* count \r\n--boundary\r\n */
- count += 6 + n;
- /* count Content-Type: ...\r\n */
- if (content->type)
- count += 16 + strlen(content->type);
- s = soap_str_code(mime_codes, content->encoding);
- /* count Content-Transfer-Encoding: ...\r\n */
- if (s)
- count += 29 + strlen(s);
- /* count Content-ID: ...\r\n */
- if (content->id)
- count += 14 + strlen(content->id);
- /* count Content-Location: ...\r\n */
- if (content->location)
- count += 20 + strlen(content->location);
- /* count Content-Description: ...\r\n */
- if (content->description)
- count += 23 + strlen(content->location);
- /* count \r\n...content */
- count += 2 + content->size;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Size of MIME attachment %lu bytes\n", (unsigned long)content->size));
- }
- /* count \r\n--boundary--\r\n */
- count += 8 + n;
- }
- return count;
-#else
- return soap->count;
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static int
-soap_putdimefield(struct soap *soap, const char *s, size_t n)
-{ if (soap_send_raw(soap, s, n))
- return soap->error;
- return soap_send_raw(soap, SOAP_STR_PADDING, -(long)n&3);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_dime_option(struct soap *soap, unsigned short optype, const char *option)
-{ size_t n;
- char *s = NULL;
- if (option)
- { n = strlen(option);
- s = (char*)soap_malloc(soap, n + 5);
- if (s)
- { s[0] = optype >> 8;
- s[1] = optype & 0xFF;
- s[2] = n >> 8;
- s[3] = n & 0xFF;
- strcpy(s + 4, option);
- }
- }
- return s;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putdimehdr(struct soap *soap)
-{ unsigned char tmp[12];
- size_t optlen = 0, idlen = 0, typelen = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Put DIME header id='%s'\n", soap->dime.id?soap->dime.id:""));
- if (soap->dime.options)
- optlen = (((unsigned char)soap->dime.options[2] << 8) | ((unsigned char)soap->dime.options[3])) + 4;
- if (soap->dime.id)
- idlen = strlen(soap->dime.id);
- if (soap->dime.type)
- typelen = strlen(soap->dime.type);
- tmp[0] = SOAP_DIME_VERSION | (soap->dime.flags & 0x7);
- tmp[1] = soap->dime.flags & 0xF0;
- tmp[2] = optlen >> 8;
- tmp[3] = optlen & 0xFF;
- tmp[4] = idlen >> 8;
- tmp[5] = idlen & 0xFF;
- tmp[6] = typelen >> 8;
- tmp[7] = typelen & 0xFF;
- tmp[8] = soap->dime.size >> 24;
- tmp[9] = (soap->dime.size >> 16) & 0xFF;
- tmp[10] = (soap->dime.size >> 8) & 0xFF;
- tmp[11] = soap->dime.size & 0xFF;
- if (soap_send_raw(soap, (char*)tmp, 12)
- || soap_putdimefield(soap, soap->dime.options, optlen)
- || soap_putdimefield(soap, soap->dime.id, idlen)
- || soap_putdimefield(soap, soap->dime.type, typelen))
- return soap->error;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putdime(struct soap *soap)
-{ struct soap_multipart *content;
- if (!(soap->mode & SOAP_ENC_DIME))
- return SOAP_OK;
- for (content = soap->dime.first; content; content = content->next)
- { void *handle;
- soap->dime.size = content->size;
- soap->dime.id = content->id;
- soap->dime.type = content->type;
- soap->dime.options = content->options;
- soap->dime.flags = SOAP_DIME_VERSION | SOAP_DIME_MEDIA;
- if (soap->fdimereadopen && ((handle = soap->fdimereadopen(soap, (void*)content->ptr, content->id, content->type, content->options)) || soap->error))
- { size_t size = content->size;
- if (!handle)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadopen failed\n"));
- return soap->error;
- }
- if (!content->size && ((soap->mode & SOAP_ENC_XML) || (soap->mode & SOAP_IO) == SOAP_IO_CHUNK || (soap->mode & SOAP_IO) == SOAP_IO_STORE))
- { size_t chunksize = sizeof(soap->tmpbuf);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked streaming DIME\n"));
- do
- { size = soap->fdimeread(soap, handle, soap->tmpbuf, chunksize);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread returned %lu bytes\n", (unsigned long)size));
- if (size < chunksize)
- { soap->dime.flags &= ~SOAP_DIME_CF;
- if (!content->next)
- soap->dime.flags |= SOAP_DIME_ME;
- }
- else
- soap->dime.flags |= SOAP_DIME_CF;
- soap->dime.size = size;
- if (soap_putdimehdr(soap)
- || soap_putdimefield(soap, soap->tmpbuf, size))
- break;
- if (soap->dime.id)
- { soap->dime.flags &= ~(SOAP_DIME_MB | SOAP_DIME_MEDIA);
- soap->dime.id = NULL;
- soap->dime.type = NULL;
- soap->dime.options = NULL;
- }
- } while (size >= chunksize);
- }
- else
- { if (!content->next)
- soap->dime.flags |= SOAP_DIME_ME;
- if (soap_putdimehdr(soap))
- return soap->error;
- do
- { size_t bufsize;
- if (size < sizeof(soap->tmpbuf))
- bufsize = size;
- else
- bufsize = sizeof(soap->tmpbuf);
- if (!(bufsize = soap->fdimeread(soap, handle, soap->tmpbuf, bufsize)))
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)soap->dime.size));
- soap->error = SOAP_EOF;
- break;
- }
- if (soap_send_raw(soap, soap->tmpbuf, bufsize))
- break;
- size -= bufsize;
- } while (size);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
- soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime.size&3);
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fdimereadclose\n"));
- if (soap->fdimereadclose)
- soap->fdimereadclose(soap, handle);
- }
- else
- { if (!content->next)
- soap->dime.flags |= SOAP_DIME_ME;
- if (soap_putdimehdr(soap)
- || soap_putdimefield(soap, (char*)content->ptr, content->size))
- return soap->error;
- }
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static char *
-soap_getdimefield(struct soap *soap, size_t n)
-{ register soap_wchar c;
- register int i;
- register char *s;
- char *p = NULL;
- if (n)
- { p = (char*)soap_malloc(soap, n + 1);
- if (p)
- { s = p;
- for (i = n; i > 0; i--)
- { if ((int)(c = soap_get1(soap)) == EOF)
- { soap->error = SOAP_EOF;
- return NULL;
- }
- *s++ = (char)c;
- }
- *s = '\0';
- if ((soap->error = soap_move(soap, -(long)n&3)))
- return NULL;
- }
- else
- soap->error = SOAP_EOM;
- }
- return p;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getdimehdr(struct soap *soap)
-{ register soap_wchar c;
- register char *s;
- register int i;
- unsigned char tmp[12];
- size_t optlen, idlen, typelen;
- if (!(soap->mode & SOAP_ENC_DIME))
- return soap->error = SOAP_DIME_END;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get DIME header\n"));
- if (soap->dime.buflen || soap->dime.chunksize)
- { if (soap_move(soap, (long)(soap->dime.size - soap_tell(soap))))
- return soap->error = SOAP_EOF;
- soap_unget(soap, soap_getchar(soap)); /* skip padding and get hdr */
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "... From chunked\n"));
- return SOAP_OK;
- }
- s = (char*)tmp;
- for (i = 12; i > 0; i--)
- { if ((int)(c = soap_getchar(soap)) == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- if ((tmp[0] & 0xF8) != SOAP_DIME_VERSION)
- return soap->error = SOAP_DIME_MISMATCH;
- soap->dime.flags = (tmp[0] & 0x7) | (tmp[1] & 0xF0);
- optlen = (tmp[2] << 8) | tmp[3];
- idlen = (tmp[4] << 8) | tmp[5];
- typelen = (tmp[6] << 8) | tmp[7];
- soap->dime.size = (tmp[8] << 24) | (tmp[9] << 16) | (tmp[10] << 8) | tmp[11];
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME size=%lu flags=0x%X\n", (unsigned long)soap->dime.size, soap->dime.flags));
- if (!(soap->dime.options = soap_getdimefield(soap, optlen)) && soap->error)
- return soap->error;
- if (!(soap->dime.id = soap_getdimefield(soap, idlen)) && soap->error)
- return soap->error;
- if (!(soap->dime.type = soap_getdimefield(soap, typelen)) && soap->error)
- return soap->error;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DIME id=%s, type=%s, options=%s\n", soap->dime.id?soap->dime.id:"", soap->dime.type?soap->dime.type:"", soap->dime.options?soap->dime.options+4:""));
- if (soap->dime.flags & SOAP_DIME_ME)
- soap->mode &= ~SOAP_ENC_DIME;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getdime(struct soap *soap)
-{ struct soap_multipart *content;
- if (soap_getdimehdr(soap))
- return soap->error;
- if (soap->fdimewriteopen && ((soap->dime.ptr = (char*)soap->fdimewriteopen(soap, soap->dime.id, soap->dime.type, soap->dime.options)) || soap->error))
- { const char *id, *type, *options;
- size_t size, n;
- if (!soap->dime.ptr)
- return soap->error;
- id = soap->dime.id;
- type = soap->dime.type;
- options = soap->dime.options;
- for (;;)
- { size = soap->dime.size;
- for (;;)
- { n = soap->buflen - soap->bufidx;
- if (size < n)
- n = size;
- if ((soap->error = soap->fdimewrite(soap, (void*)soap->dime.ptr, soap->buf + soap->bufidx, n)))
- break;
- size -= n;
- if (!size)
- { soap->bufidx += n;
- break;
- }
- if (soap_recv(soap))
- { soap->error = SOAP_EOF;
- goto end;
- }
- }
- if (soap_move(soap, -(long)soap->dime.size&3))
- { soap->error = SOAP_EOF;
- break;
- }
- if (!(soap->dime.flags & SOAP_DIME_CF))
- break;
- if (soap_getdimehdr(soap))
- break;
- }
-end:
- if (soap->fdimewriteclose)
- soap->fdimewriteclose(soap, (void*)soap->dime.ptr);
- soap->dime.size = 0;
- soap->dime.id = id;
- soap->dime.type = type;
- soap->dime.options = options;
- }
- else if (soap->dime.flags & SOAP_DIME_CF)
- { const char *id, *type, *options;
- register soap_wchar c;
- register char *s;
- register int i;
- id = soap->dime.id;
- type = soap->dime.type;
- options = soap->dime.options;
- if (soap_new_block(soap))
- return SOAP_EOM;
- for (;;)
- { s = (char*)soap_push_block(soap, soap->dime.size);
- if (!s)
- return soap->error = SOAP_EOM;
- for (i = soap->dime.size; i > 0; i--)
- { if ((int)(c = soap_get1(soap)) == EOF)
- return soap->error = SOAP_EOF;
- *s++ = (char)c;
- }
- if (soap_move(soap, -(long)soap->dime.size&3))
- return soap->error = SOAP_EOF;
- if (!(soap->dime.flags & SOAP_DIME_CF))
- break;
- if (soap_getdimehdr(soap))
- return soap->error;
- }
- soap->dime.size = soap->blist->size++; /* allocate one more for '\0' */
- if (!(soap->dime.ptr = soap_save_block(soap, NULL, 0)))
- return soap->error;
- soap->dime.ptr[soap->dime.size] = '\0'; /* force 0-terminated */
- soap->dime.id = id;
- soap->dime.type = type;
- soap->dime.options = options;
- }
- else
- soap->dime.ptr = soap_getdimefield(soap, soap->dime.size);
- content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, soap->dime.ptr, soap->dime.size);
- if (!content)
- return soap->error = SOAP_EOM;
- content->id = soap->dime.id;
- content->type = soap->dime.type;
- content->options = soap->dime.options;
- return soap->error;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getmimehdr(struct soap *soap)
-{ struct soap_multipart *content;
- do
- { if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
- return soap->error;
- }
- while (!*soap->msgbuf);
- if (soap->msgbuf[0] == '-' && soap->msgbuf[1] == '-')
- { char *s = soap->msgbuf + strlen(soap->msgbuf) - 1;
- /* remove white space */
- while (soap_blank(*s))
- s--;
- s[1] = '\0';
- if (soap->mime.boundary)
- { if (strcmp(soap->msgbuf + 2, soap->mime.boundary))
- return soap->error = SOAP_MIME_ERROR;
- }
- else
- soap->mime.boundary = soap_strdup(soap, soap->msgbuf + 2);
- if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
- return soap->error;
- }
- if (soap_set_mime_attachment(soap, NULL, 0, SOAP_MIME_NONE, NULL, NULL, NULL, NULL))
- return soap->error = SOAP_EOM;
- content = soap->mime.last;
- for (;;)
- { register char *key = soap->msgbuf;
- register char *val;
- if (!*key)
- break;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "MIME header: %s\n", key));
- val = strchr(soap->msgbuf, ':');
- if (val)
- { *val = '\0';
- do val++;
- while (*val && *val <= 32);
- if (!soap_tag_cmp(key, "Content-ID"))
- content->id = soap_strdup(soap, val);
- else if (!soap_tag_cmp(key, "Content-Location"))
- content->location = soap_strdup(soap, val);
- else if (!soap_tag_cmp(key, "Content-Type"))
- content->type = soap_strdup(soap, val);
- else if (!soap_tag_cmp(key, "Content-Description"))
- content->description = soap_strdup(soap, val);
- else if (!soap_tag_cmp(key, "Content-Transfer-Encoding"))
- content->encoding = (enum soap_mime_encoding)soap_int_code(mime_codes, val, (long)SOAP_MIME_NONE);
- }
- if (soap_getline(soap, key, sizeof(soap->msgbuf)))
- return soap->error;
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getmime(struct soap *soap)
-{ register soap_wchar c;
- if (!soap->mime.last)
- return SOAP_OK;
- for (;;)
- { register size_t i, m = 0;
- register char *s;
- struct soap_multipart *content = soap->mime.last;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id=%s type=%s\n", content->id?content->id:"", content->type?content->type:""));
- if (soap_new_block(soap))
- return soap->error = SOAP_EOM;
- for (;;)
- { register char *t = NULL;
- if (!(s = (char*)soap_push_block(soap, SOAP_BLKLEN)))
- return soap->error = SOAP_EOM;
- for (i = 0; i < SOAP_BLKLEN; i++)
- { if (m > 0)
- { *s++ = *t++;
- m--;
- }
- else
- { c = soap_get1(soap);
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (c == '\r')
- { t = soap->tmpbuf;
- strcpy(t, "\n--");
- strncat(t, soap->mime.boundary, sizeof(soap->tmpbuf)-3);
- t[sizeof(soap->tmpbuf)-1] = '\0';
- do c = soap_getchar(soap);
- while (c == *t++);
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (!*--t)
- goto end;
- *t = (char)c;
- m = t - soap->tmpbuf + 1;
- t = soap->tmpbuf;
- c = '\r';
- }
- *s++ = (char)c;
- }
- }
- }
-end:
- *s = '\0'; /* force 0-terminated */
- content->size = soap_size_block(soap, i+1)-1;
- content->ptr = soap_save_block(soap, NULL, 0);
- if (c == '-' && soap_getchar(soap) == '-')
- break;
- while (c != '\r' && (int)c != EOF && soap_blank(c))
- c = soap_getchar(soap);
- if (c != '\r' || soap_getchar(soap) != '\n')
- return soap->error = SOAP_MIME_ERROR;
- if (soap_getmimehdr(soap))
- return soap->error;
- }
- do c = soap_getchar(soap);
- while ((int)c != EOF && c != '\r');
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- if (soap_getchar(soap) != '\n')
- return soap->error = SOAP_MIME_ERROR;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putmimehdr(struct soap *soap, struct soap_multipart *content)
-{ const char *s;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "MIME attachment type=%s\n", content->type?content->type:""));
- if (soap_send3(soap, "\r\n--", soap->mime.boundary, "\r\n"))
- return soap->error;
- if (content->type && soap_send3(soap, "Content-Type: ", content->type, "\r\n"))
- return soap->error;
- s = soap_str_code(mime_codes, content->encoding);
- if (s && soap_send3(soap, "Content-Transfer-Encoding: ", s, "\r\n"))
- return soap->error;
- if (content->id && soap_send3(soap, "Content-ID: ", content->id, "\r\n"))
- return soap->error;
- if (content->location && soap_send3(soap, "Content-Location: ", content->location, "\r\n"))
- return soap->error;
- if (content->description && soap_send3(soap, "Content-Description: ", content->description, "\r\n"))
- return soap->error;
- return soap_send_raw(soap, "\r\n", 2);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putmime(struct soap *soap)
-{ struct soap_multipart *content;
- if (!(soap->mode & SOAP_ENC_MIME) || !soap->mime.boundary)
- return SOAP_OK;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending MIME attachments\n"));
- for (content = soap->mime.first; content; content = content->next)
- if (soap_putmimehdr(soap, content)
- || soap_send_raw(soap, content->ptr, content->size))
- return soap->error;
- return soap_send3(soap, "\r\n--", soap->mime.boundary, "--\r\n");
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_dime(struct soap *soap)
-{ soap->omode |= SOAP_ENC_DIME;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_mime(struct soap *soap, const char *boundary, const char *start)
-{ soap->omode |= SOAP_ENC_MIME;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->mime.boundary = soap_strdup(soap, boundary);
- soap->mime.start = soap_strdup(soap, start);
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_dime(struct soap *soap)
-{ soap->omode &= ~SOAP_ENC_DIME;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_mime(struct soap *soap)
-{ soap->omode &= ~SOAP_ENC_MIME;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->mime.boundary = NULL;
- soap->mime.start = NULL;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static struct soap_multipart*
-soap_new_multipart(struct soap *soap, struct soap_multipart **first, struct soap_multipart **last, char *ptr, size_t size)
-{ struct soap_multipart *content;
- content = (struct soap_multipart*)soap_malloc(soap, sizeof(struct soap_multipart));
- if (content)
- { content->next = NULL;
- content->ptr = ptr;
- content->size = size;
- content->id = NULL;
- content->type = NULL;
- content->options = NULL;
- content->encoding = SOAP_MIME_NONE;
- content->location = NULL;
- content->description = NULL;
- if (!*first)
- *first = content;
- if (*last)
- (*last)->next = content;
- *last = content;
- }
- return content;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_dime_attachment(struct soap *soap, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option)
-{ struct soap_multipart *content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, ptr, size);
- if (!content)
- return SOAP_EOM;
- content->id = soap_strdup(soap, id);
- content->type = soap_strdup(soap, type);
- content->options = soap_dime_option(soap, optype, option);
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_mime_attachment(struct soap *soap, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description)
-{ struct soap_multipart *content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, ptr, size);
- if (!content)
- return SOAP_EOM;
- content->id = soap_strdup(soap, id);
- content->type = soap_strdup(soap, type);
- content->encoding = encoding;
- content->location = soap_strdup(soap, location);
- content->description = soap_strdup(soap, description);
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-SOAP_FMAC1
-struct soap_multipart*
-SOAP_FMAC2
-soap_next_multipart(struct soap_multipart *content)
-{ if (content)
- return content->next;
- return NULL;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static void
-soap_select_mime_boundary(struct soap *soap)
-{ while (!soap->mime.boundary || soap_valid_mime_boundary(soap))
- { register char *s = soap->mime.boundary;
- register size_t n = 0;
- if (s)
- n = strlen(s);
- if (n < 16)
- { n = 72;
- s = soap->mime.boundary = (char*)soap_malloc(soap, n);
- if (!s)
- return;
- }
- strcpy(s, "<>");
- s += 2;
- n -= 4;
- while (n)
- { *s++ = soap_base64o[rand()&0x3F];
- n--;
- }
- *s = '\0';
- strcat(s, "<>");
- }
- if (!soap->mime.start)
- soap->mime.start = "<SOAP-ENV:Envelope>";
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEANER
-#ifndef PALM_1
-static int
-soap_valid_mime_boundary(struct soap *soap)
-{ register struct soap_multipart *content;
- register size_t k = strlen(soap->mime.boundary);
- for (content = soap->mime.first; content; content = content->next)
- { if (content->ptr && content->size >= k)
- { register const char *p = (const char*)content->ptr;
- register size_t i;
- for (i = 0; i < content->size - k; i++, p++)
- if (!strncmp(p, soap->mime.boundary, k))
- return SOAP_ERR;
- }
- }
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-
-#ifdef WITH_COOKIES
-/******************************************************************************/
-SOAP_FMAC1
-size_t
-SOAP_FMAC2
-soap_encode_cookie(const char *s, char *t, size_t len)
-{ register int c;
- register size_t n = len;
- while ((c = *s++) && --n > 0)
- { if (c > ' ' && c < 128 && c != ';' && c != ',')
- *t++ = c;
- else if (n > 2)
- { *t++ = '%';
- *t++ = (c >> 4) + (c > 159 ? '7' : '0');
- c &= 0xF;
- *t++ = c + (c > 9 ? '7' : '0');
- n -= 2;
- }
- else
- break;
- }
- *t = '\0';
- return len - n;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- size_t n;
- if (!domain)
- domain = soap->cookie_domain;
- if (!path)
- path = soap->cookie_path;
- if (*path == '/')
- path++;
- n = strlen(path);
- for (p = soap->cookies; p; p = p->next)
- if (!strcmp(p->name, name)
- && domain
- && p->domain
- && !strcmp(p->domain, domain)
- && !strncmp(p->path, path, n))
- break;
- return p;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_set_cookie(struct soap *soap, const char *name, const char *value, const char *domain, const char *path)
-{ struct soap_cookie **p, *q;
- int n;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie: %s=%s domain=%s path=%s\n", name, value?value:"", domain?domain:"", path?path:""));
- if (!domain)
- domain = soap->cookie_domain;
- if (!path)
- path = soap->cookie_path;
- if (!path)
- { soap_set_receiver_error(soap, "Cookie path not set", NULL, SOAP_HTTP_ERROR);
- return NULL;
- }
- if (*path == '/')
- path++;
- q = soap_cookie(soap, name, domain, path);
- if (!q)
- { if ((q = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- { if ((q->name = (char*)SOAP_MALLOC(strlen(name)+1)))
- strcpy(q->name, name);
- q->value = NULL;
- q->domain = NULL;
- q->path = NULL;
- q->expire = -1;
- q->version = 0;
- q->secure = 0;
- q->env = 0;
- q->modified = 0;
- for (p = &soap->cookies, n = soap->cookie_max; *p && n; p = &(*p)->next, n--)
- if (!strcmp((*p)->name, name) && (*p)->path && strcmp((*p)->path, path) < 0)
- break;
- if (n)
- { q->next = *p;
- *p = q;
- }
- else
- { SOAP_FREE(q->name);
- SOAP_FREE(q);
- q = NULL;
- }
- }
- }
- else
- q->modified = 1;
- if (q)
- { if (q->value)
- { SOAP_FREE(q->value);
- q->value = NULL;
- }
- if (q->domain)
- { SOAP_FREE(q->domain);
- q->domain = NULL;
- }
- if (q->path)
- { SOAP_FREE(q->path);
- q->path = NULL;
- }
- if (value && *value && (q->value = (char*)SOAP_MALLOC(strlen(value)+1)))
- strcpy(q->value, value);
- if (domain && *domain && (q->domain = (char*)SOAP_MALLOC(strlen(domain)+1)))
- strcpy(q->domain, domain);
- if (path && *path && (q->path = (char*)SOAP_MALLOC(strlen(path)+1)))
- strcpy(q->path, path);
- q->session = 1;
- }
- return q;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_clr_cookie(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie **p, *q;
- if (!domain)
- domain = soap->cookie_domain;
- if (!domain)
- { soap_set_receiver_error(soap, "Cookie domain not set", SOAP_STR_EOS, SOAP_HTTP_ERROR);
- return;
- }
- if (!path)
- path = soap->cookie_path;
- if (!path)
- { soap_set_receiver_error(soap, "Cookie path not set", SOAP_STR_EOS, SOAP_HTTP_ERROR);
- return;
- }
- if (*path == '/')
- path++;
- for (p = &soap->cookies, q = *p; q; q = *p)
- if (!strcmp(q->name, name) && !strcmp(q->domain, domain) && !strncmp(q->path, path, strlen(q->path)))
- { if (q->value)
- SOAP_FREE(q->value);
- if (q->domain)
- SOAP_FREE(q->domain);
- if (q->path)
- SOAP_FREE(q->path);
- *p = q->next;
- SOAP_FREE(q);
- }
- else
- p = &q->next;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-char *
-SOAP_FMAC2
-soap_cookie_value(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- return p->value;
- return NULL;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-long
-SOAP_FMAC2
-soap_cookie_expire(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- return p->expire;
- return -1;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_cookie_expire(struct soap *soap, const char *name, long expire, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->expire = expire;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->session = 1;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_clr_cookie_session(struct soap *soap, const char *name, const char *domain, const char *path)
-{ struct soap_cookie *p;
- if ((p = soap_cookie(soap, name, domain, path)))
- { p->session = 0;
- p->modified = 1;
- return SOAP_OK;
- }
- return SOAP_ERR;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putsetcookies(struct soap *soap)
-{ struct soap_cookie *p;
- char *s, tmp[4096];
- const char *t;
- for (p = soap->cookies; p; p = p->next)
- { if (p->modified || !p->env)
- { s = tmp;
- if (p->name)
- s += soap_encode_cookie(p->name, s, tmp-s+4064);
- if (p->value && *p->value)
- { *s++ = '=';
- s += soap_encode_cookie(p->value, s, tmp-s+4064);
- }
- if (p->domain && (int)strlen(p->domain) < tmp-s+4064)
- sprintf(s, ";Domain=%s", p->domain);
- else if (soap->cookie_domain && (int)strlen(soap->cookie_domain) < tmp-s+4064)
- sprintf(s, ";Domain=%s", soap->cookie_domain);
- strcat(s, ";Path=/");
- if (p->path)
- t = p->path;
- else
- t = soap->cookie_path;
- if (t)
- { if (*t == '/')
- t++;
- if ((int)strlen(t) < tmp-s+4064)
- strcat(s, t);
- }
- s += strlen(s);
- if (p->version > 0)
- sprintf(s, ";Version=%u", p->version);
- if (p->expire >= 0)
- sprintf(s, ";Max-Age=%ld", p->expire);
- if (p->secure)
- strcat(s, ";Secure");
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set-Cookie: %s\n", tmp));
- if (soap->fposthdr(soap, "Set-Cookie", tmp))
- return soap->error;
- }
- }
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_putcookies(struct soap *soap, const char *domain, const char *path, int secure)
-{ struct soap_cookie **p, *q;
- unsigned int version = 0;
- time_t now = time(NULL);
- char *s, tmp[4096];
- p = &soap->cookies;
- while ((q = *p))
- { if (q->expire && now > q->expire)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name));
- SOAP_FREE(q->name);
- if (q->value)
- SOAP_FREE(q->value);
- if (q->domain)
- SOAP_FREE(q->domain);
- if (q->path)
- SOAP_FREE(q->path);
- *p = q->next;
- SOAP_FREE(q);
- }
- else if ((!q->domain || !strcmp(q->domain, domain))
- && (!q->path || !strncmp(q->path, path, strlen(q->path)))
- && (!q->secure || secure))
- { s = tmp;
- if (q->version != version)
- { sprintf(s, "$Version=%u;", q->version);
- version = q->version;
- }
- if (q->name)
- s += soap_encode_cookie(q->name, s, tmp-s+4080);
- if (q->value && *q->value)
- { *s++ = '=';
- s += soap_encode_cookie(q->value, s, tmp-s+4080);
- }
- if (q->path && (int)strlen(q->path) < tmp-s+4080)
- { sprintf(s, ";$Path=/%s", q->path);
- s += strlen(s);
- }
- if (q->domain && (int)strlen(q->domain) < tmp-s+4080)
- sprintf(s, ";$Domain=%s", q->domain);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie: %s\n", tmp));
- if (soap->fposthdr(soap, "Cookie", tmp))
- return soap->error;
- p = &q->next;
- }
- else
- p = &q->next;
- }
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_getcookies(struct soap *soap, const char *val)
-{ struct soap_cookie *p = NULL, *q;
- const char *s;
- char *t, tmp[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
- char *domain = NULL;
- char *path = NULL;
- unsigned int version = 0;
- time_t now = time(NULL);
- if (!val)
- return;
- s = val;
- while (*s)
- { s = soap_decode_key(tmp, sizeof(tmp), s);
- if (!soap_tag_cmp(tmp, "$Version"))
- { if ((s = soap_decode_val(tmp, sizeof(tmp), s)))
- { if (p)
- p->version = (int)atol(tmp);
- else
- version = (int)atol(tmp);
- }
- }
- else if (!soap_tag_cmp(tmp, "$Path"))
- { s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((t = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(t, tmp);
- }
- else
- t = NULL;
- if (p)
- { if (p->path)
- SOAP_FREE(p->path);
- p->path = t;
- }
- else
- { if (path)
- SOAP_FREE(path);
- path = t;
- }
- }
- else if (!soap_tag_cmp(tmp, "$Domain"))
- { s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((t = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(t, tmp);
- }
- else
- t = NULL;
- if (p)
- { if (p->domain)
- SOAP_FREE(p->domain);
- p->domain = t;
- }
- else
- { if (domain)
- SOAP_FREE(domain);
- domain = t;
- }
- }
- else if (p && !soap_tag_cmp(tmp, "Path"))
- { if (p->path)
- SOAP_FREE(p->path);
- s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((p->path = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(p->path, tmp);
- }
- else
- p->path = NULL;
- }
- else if (p && !soap_tag_cmp(tmp, "Domain"))
- { if (p->domain)
- SOAP_FREE(p->domain);
- s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { if ((p->domain = (char*)SOAP_MALLOC(strlen(tmp)+1)))
- strcpy(p->domain, tmp);
- }
- else
- p->domain = NULL;
- }
- else if (p && !soap_tag_cmp(tmp, "Version"))
- { s = soap_decode_val(tmp, sizeof(tmp), s);
- p->version = (unsigned int)atol(tmp);
- }
- else if (p && !soap_tag_cmp(tmp, "Max-Age"))
- { s = soap_decode_val(tmp, sizeof(tmp), s);
- p->expire = now + atol(tmp);
- }
- else if (p && !soap_tag_cmp(tmp, "Expires"))
- { struct tm T;
- char a[3];
- static const char mns[] = "anebarprayunulugepctovec";
- s = soap_decode_val(tmp, sizeof(tmp), s);
- if (strlen(tmp) > 20)
- { memset((void*)&T, 0, sizeof(T));
- a[0] = tmp[4];
- a[1] = tmp[5];
- a[2] = '\0';
- T.tm_mday = (int)atol(a);
- a[0] = tmp[8];
- a[1] = tmp[9];
- T.tm_mon = (strstr(mns, a) - mns) / 2;
- a[0] = tmp[11];
- a[1] = tmp[12];
- T.tm_year = 100 + (int)atol(a);
- a[0] = tmp[13];
- a[1] = tmp[14];
- T.tm_hour = (int)atol(a);
- a[0] = tmp[16];
- a[1] = tmp[17];
- T.tm_min = (int)atol(a);
- a[0] = tmp[19];
- a[1] = tmp[20];
- T.tm_sec = (int)atol(a);
- p->expire = soap_timegm(&T);
- }
- }
- else if (p && !soap_tag_cmp(tmp, "Secure"))
- p->secure = 1;
- else
- { if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got environment cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"", p->domain?p->domain:"", p->path?p->path:"", p->expire, p->secure));
- if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
- { q->version = p->version;
- q->expire = p->expire;
- q->secure = p->secure;
- q->env = 1;
- }
- if (p->name)
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
- if ((p = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- { p->name = (char*)SOAP_MALLOC(strlen(tmp)+1);
- strcpy(p->name, tmp);
- s = soap_decode_val(tmp, sizeof(tmp), s);
- if (*tmp)
- { p->value = (char*)SOAP_MALLOC(strlen(tmp)+1);
- strcpy(p->value, tmp);
- }
- else
- p->value = NULL;
- p->domain = domain;
- p->path = path;
- p->expire = 0;
- p->secure = 0;
- p->version = version;
- }
- }
- }
- if (p)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Got cookie %s=%s domain=%s path=%s expire=%ld secure=%d\n", p->name, p->value?p->value:"", p->domain?p->domain:"", p->path?p->path:"", p->expire, p->secure));
- if ((q = soap_set_cookie(soap, p->name, p->value, p->domain, p->path)))
- { q->version = p->version;
- q->expire = p->expire;
- q->secure = p->secure;
- }
- if (p->name)
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
- if (domain)
- SOAP_FREE(domain);
- if (path)
- SOAP_FREE(path);
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_getenv_cookies(struct soap *soap)
-{ struct soap_cookie *p;
- const char *s;
- char key[4096], val[4096]; /* cookie size is up to 4096 bytes [RFC2109] */
- if (!(s = getenv("HTTP_COOKIE")))
- return SOAP_ERR;
- do
- { s = soap_decode_key(key, sizeof(key), s);
- s = soap_decode_val(val, sizeof(val), s);
- p = soap_set_cookie(soap, key, val, NULL, NULL);
- if (p)
- p->env = 1;
- } while (*s);
- return SOAP_OK;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-struct soap_cookie*
-SOAP_FMAC2
-soap_copy_cookies(struct soap *soap)
-{ struct soap_cookie *p, **q, *r;
- q = &r;
- for (p = soap->cookies; p; p = p->next)
- { if (!(*q = (struct soap_cookie*)SOAP_MALLOC(sizeof(struct soap_cookie))))
- return r;
- **q = *p;
- if (p->name)
- { if (((*q)->name = (char*)SOAP_MALLOC(strlen(p->name)+1)))
- strcpy((*q)->name, p->name);
- }
- if (p->value)
- { if (((*q)->value = (char*)SOAP_MALLOC(strlen(p->value)+1)))
- strcpy((*q)->value, p->value);
- }
- if (p->domain)
- { if (((*q)->domain = (char*)SOAP_MALLOC(strlen(p->domain)+1)))
- strcpy((*q)->domain, p->domain);
- }
- if (p->path)
- { if (((*q)->path = (char*)SOAP_MALLOC(strlen(p->path)+1)))
- strcpy((*q)->path, p->path);
- }
- q = &(*q)->next;
- }
- *q = NULL;
- return r;
-}
-
-/******************************************************************************/
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_free_cookies(struct soap *soap)
-{ struct soap_cookie *p;
- for (p = soap->cookies; p; p = soap->cookies)
- { soap->cookies = p->next;
- SOAP_FREE(p->name);
- if (p->value)
- SOAP_FREE(p->value);
- if (p->domain)
- SOAP_FREE(p->domain);
- if (p->path)
- SOAP_FREE(p->path);
- SOAP_FREE(p);
- }
-}
-
-/******************************************************************************/
-#endif /* WITH_COOKIES */
-
-/******************************************************************************/
-#ifdef WITH_GZIP
-#ifndef PALM_1
-static int
-soap_getgziphdr(struct soap *soap)
-{ int i;
- soap_wchar c, f = 0;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Get gzip header\n"));
- for (i = 0; i < 9; i++)
- { if ((int)(c = soap_get1(soap) == EOF))
- return soap->error = SOAP_EOF;
- if (i == 2)
- f = c;
- }
- if (f & 0x04) /* FEXTRA */
- { for (i = soap_get1(soap) | (soap_get1(soap) << 8); i; i--)
- if ((int)soap_get1(soap) == EOF)
- return soap->error = SOAP_EOF;
- }
- if (f & 0x08) /* FNAME */
- do
- c = soap_get1(soap);
- while (c && (int)c != EOF);
- if ((int)c != EOF && (f & 0x10)) /* FCOMMENT */
- do
- c = soap_get1(soap);
- while (c && (int)f != EOF);
- if ((int)c != EOF && (f & 0x01)) /* FHCRC */
- { if ((int)(c = soap_get1(soap)) != EOF)
- c = soap_get1(soap);
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- return SOAP_OK;
-}
-#endif
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_begin_recv(struct soap *soap)
-{ soap_wchar c;
- soap->error = SOAP_OK;
- soap_free(soap);
- soap_set_local_namespaces(soap);
- soap->version = 0; /* don't assume we're parsing SOAP content by default */
- soap_free_iht(soap);
- if ((soap->imode & SOAP_IO) == SOAP_IO_CHUNK)
- soap->omode |= SOAP_IO_CHUNK;
- soap->imode &= ~SOAP_IO;
- soap->mode = soap->imode;
- if (!soap->keep_alive)
- { soap->buflen = 0;
- soap->bufidx = 0;
- }
- if (!(soap->mode & SOAP_IO_KEEPALIVE))
- soap->keep_alive = 0;
- soap->ahead = 0;
- soap->peeked = 0;
- soap->level = 0;
- soap->part = SOAP_BEGIN;
- soap->alloced = 0;
- soap->count = 0;
- soap->length = 0;
- soap->cdata = 0;
- *soap->endpoint = '\0';
- soap->userid = NULL;
- soap->passwd = NULL;
- soap->action = NULL;
- soap->authrealm = NULL;
- soap->dime.chunksize = 0;
- soap->dime.buflen = 0;
- soap->dime.list = NULL;
- soap->dime.first = NULL;
- soap->dime.last = NULL;
- soap->mime.list = NULL;
- soap->mime.first = NULL;
- soap->mime.last = NULL;
- soap->mime.boundary = NULL;
- soap->mime.start = NULL;
-#ifdef WIN32
-#ifndef UNDER_CE
-#ifndef WITH_FASTCGI
- if (!soap_valid_socket(soap->socket))
-#ifdef __BORLANDC__
- setmode((SOAP_SOCKET)soap->recvfd, O_BINARY);
-#else
- _setmode((SOAP_SOCKET)soap->recvfd, _O_BINARY);
-#endif
-#endif
-#endif
-#endif
-#ifdef WITH_ZLIB
- soap->mode &= ~SOAP_ENC_ZLIB;
- soap->zlib_in = SOAP_ZLIB_NONE;
- soap->zlib_out = SOAP_ZLIB_NONE;
- soap->d_stream.next_in = Z_NULL;
- soap->d_stream.avail_in = 0;
- soap->d_stream.next_out = (Byte*)soap->buf;
- soap->d_stream.avail_out = SOAP_BUFLEN;
- soap->z_ratio_in = 1.0;
- if (soap->fprepareinit)
- soap->fprepareinit(soap);
-#endif
- c = soap_getchar(soap);
-#ifdef WITH_GZIP
- if (c == 0x1F)
- { if (soap_getgziphdr(soap))
- return soap->error;
- if (inflateInit2(&soap->d_stream, -MAX_WBITS) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- soap->mode |= SOAP_ENC_ZLIB;
- soap->zlib_in = SOAP_ZLIB_GZIP;
- soap->z_crc = crc32(0L, NULL, 0);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- /* should not chunk over plain transport, so why bother to check? */
- /* if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) */
- /* soap->z_buflen = soap->bufidx; */
- /* else */
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = soap->buflen - soap->bufidx;
- soap->z_buflen = soap->buflen;
- soap->buflen = soap->bufidx;
- c = soap_getchar(soap);
- }
-#endif
- if (c == '-' && soap_get0(soap) == '-')
- soap->mode |= SOAP_ENC_MIME;
- else if ((c & 0xFFFC) == (SOAP_DIME_VERSION | SOAP_DIME_MB) && (soap_get0(soap) & 0xFFF0) == 0x20)
- soap->mode |= SOAP_ENC_DIME;
- else
- { while (soap_blank(c))
- c = soap_getchar(soap);
- }
- if ((int)c == EOF)
- return soap->error = SOAP_EOF;
- soap_unget(soap, c);
- if (c != '<' && !(soap->mode & (SOAP_ENC_DIME | SOAP_ENC_ZLIB)))
- { soap->mode &= ~SOAP_IO;
- if ((soap->error = soap->fparse(soap)))
- { soap->keep_alive = 0; /* force close later */
- return soap->error;
- }
- if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
- { soap->chunkbuflen = soap->buflen;
- soap->buflen = soap->bufidx;
- soap->chunksize = 0;
- }
- else if (soap->fpreparerecv && soap->buflen != soap->bufidx)
- soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx);
-#ifdef WITH_ZLIB
- if (soap->zlib_in)
- { /* fparse should not use soap_unget to push back last char */
-#ifdef WITH_GZIP
- c = soap_get1(soap);
- if (c == 0x1F)
- { if (soap_getgziphdr(soap))
- return soap->error;
- if (inflateInit2(&soap->d_stream, -MAX_WBITS) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- soap->z_crc = crc32(0L, NULL, 0);
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n"));
- }
- else
- { soap_revget1(soap);
-#else
- {
-#endif
- if (inflateInit(&soap->d_stream) != Z_OK)
- return soap->error = SOAP_ZLIB_ERROR;
- soap->zlib_state = SOAP_ZLIB_INFLATE;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflate initialized\n"));
- }
- soap->mode |= SOAP_ENC_ZLIB;
- memcpy(soap->z_buf, soap->buf, SOAP_BUFLEN);
- soap->d_stream.next_in = (Byte*)(soap->z_buf + soap->bufidx);
- soap->d_stream.avail_in = soap->buflen - soap->bufidx;
- soap->z_buflen = soap->buflen;
- soap->buflen = soap->bufidx;
- }
-#endif
- }
-#ifndef WITH_LEANER
- if (soap->mode & SOAP_ENC_MIME)
- { if (soap_getmimehdr(soap))
- return soap->error;
- if (soap_get_header_attribute(soap, soap->mime.first->type, "application/dime"))
- soap->mode |= SOAP_ENC_DIME;
- }
- if (soap->mode & SOAP_ENC_DIME)
- { if (soap_getdimehdr(soap))
- return soap->error;
- if (soap->dime.flags & SOAP_DIME_CF)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunked DIME SOAP message\n"));
- soap->dime.chunksize = soap->dime.size;
- if (soap->buflen - soap->bufidx >= soap->dime.chunksize)
- { soap->dime.buflen = soap->buflen;
- soap->buflen = soap->bufidx + soap->dime.chunksize;
- }
- else
- soap->dime.chunksize -= soap->buflen - soap->bufidx;
- }
- soap->count = soap->buflen - soap->bufidx;
- }
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_parse(struct soap *soap)
-{ char header[SOAP_HDRLEN], *s;
- unsigned short g = 0, k;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for response...\n"));
- *soap->endpoint = '\0';
- soap->length = 0;
- do
- { if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf)))
- return soap->error;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP status: %s\n", soap->msgbuf));
- for (;;)
- { if (soap_getline(soap, header, SOAP_HDRLEN))
- return soap->error;
- if (!*header)
- break;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP header: %s\n", header));
- s = strchr(header, ':');
- if (s)
- { *s = '\0';
- do s++;
- while (*s && *s <= 32);
- if ((soap->error = soap->fparsehdr(soap, header, s)))
- return soap->error;
- }
- }
- if ((s = strchr(soap->msgbuf, ' ')))
- k = (unsigned short)soap_strtoul(s, NULL, 10);
- else
- k = 0;
- } while (k == 100);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Finished HTTP header parsing\n"));
- s = strstr(soap->msgbuf, "HTTP/");
- if (s && s[7] != '1')
- { if (soap->keep_alive == 1)
- soap->keep_alive = 0;
- if (k == 0 && (soap->omode & SOAP_IO) == SOAP_IO_CHUNK) /* k == 0 for HTTP request */
- { soap->imode |= SOAP_IO_CHUNK;
- soap->omode = (soap->omode & ~SOAP_IO) | SOAP_IO_STORE;
- }
- }
- if (soap->keep_alive < 0)
- soap->keep_alive = 1;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Keep alive connection = %d\n", soap->keep_alive));
- if (s && (((g = !strncmp(soap->msgbuf, "GET ", 4))) || !strncmp(soap->msgbuf, "POST ", 5)))
- { size_t m = strlen(soap->endpoint);
- size_t n = m + (s - soap->msgbuf) - 5 - (!g);
- if (n >= sizeof(soap->endpoint))
- n = sizeof(soap->endpoint) - 1;
- strncpy(soap->path, soap->msgbuf + 4 + (!g), n - m);
- soap->path[n - m] = '\0';
- strcat(soap->endpoint, soap->path);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint));
- if (g)
- { soap->error = soap->fget(soap);
- if (soap->error == SOAP_OK)
- soap->error = SOAP_STOP; /* prevents further processing */
- return soap->error;
- }
- return SOAP_OK;
- }
- if (k == 0 || (k >= 200 && k <= 299) || k == 400 || k == 500)
- return SOAP_OK;
- return soap_set_receiver_error(soap, "HTTP error", soap->msgbuf, k);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_parse_header(struct soap *soap, const char *key, const char *val)
-{ if (!soap_tag_cmp(key, "Host"))
- {
-#ifdef WITH_OPENSSL
- if (soap->imode & SOAP_ENC_SSL)
- strcpy(soap->endpoint, "https://");
- else
-#endif
- strcpy(soap->endpoint, "http://");
- strncat(soap->endpoint, val, sizeof(soap->endpoint) - 8);
- soap->endpoint[sizeof(soap->endpoint) - 1] = '\0';
- }
-#ifndef WITH_LEANER
- else if (!soap_tag_cmp(key, "Content-Type"))
- { if (soap_get_header_attribute(soap, val, "application/dime"))
- soap->mode |= SOAP_ENC_DIME;
- else if (soap_get_header_attribute(soap, val, "multipart/related"))
- { soap->mime.boundary = soap_strdup(soap, soap_get_header_attribute(soap, val, "boundary"));
- soap->mime.start = soap_strdup(soap, soap_get_header_attribute(soap, val, "start"));
- soap->mode |= SOAP_ENC_MIME;
- }
- }
-#endif
- else if (!soap_tag_cmp(key, "Content-Length"))
- soap->length = soap_strtoul(val, NULL, 10);
- else if (!soap_tag_cmp(key, "Content-Encoding"))
- { if (!soap_tag_cmp(val, "deflate"))
-#ifdef WITH_ZLIB
- soap->zlib_in = SOAP_ZLIB_DEFLATE;
-#else
- return SOAP_ZLIB_ERROR;
-#endif
- else if (!soap_tag_cmp(val, "gzip"))
-#ifdef WITH_GZIP
- soap->zlib_in = SOAP_ZLIB_GZIP;
-#else
- return SOAP_ZLIB_ERROR;
-#endif
- }
-#ifdef WITH_ZLIB
- else if (!soap_tag_cmp(key, "Accept-Encoding"))
- {
-#ifdef WITH_GZIP
- if (strchr(val, '*') || soap_get_header_attribute(soap, val, "gzip"))
- soap->zlib_out = SOAP_ZLIB_GZIP;
- else
-#endif
- if (strchr(val, '*') || soap_get_header_attribute(soap, val, "deflate"))
- soap->zlib_out = SOAP_ZLIB_DEFLATE;
- else
- soap->zlib_out = SOAP_ZLIB_NONE;
- }
-#endif
- else if (!soap_tag_cmp(key, "Transfer-Encoding"))
- { soap->mode &= ~SOAP_IO;
- if (!soap_tag_cmp(val, "chunked"))
- soap->mode |= SOAP_IO_CHUNK;
- }
- else if (!soap_tag_cmp(key, "Connection"))
- { if (!soap_tag_cmp(val, "keep-alive"))
- soap->keep_alive = -soap->keep_alive;
- else if (!soap_tag_cmp(val, "close"))
- soap->keep_alive = 0;
- }
-#ifndef WITH_LEAN
- else if (!soap_tag_cmp(key, "Authorization"))
- { if (!soap_tag_cmp(val, "Basic *"))
- { size_t n;
- char *s;
- soap_base642s(soap, val + 6, soap->tmpbuf, sizeof(soap->tmpbuf) - 1, &n);
- soap->tmpbuf[n] = '\0';
- if ((s = strchr(soap->tmpbuf, ':')))
- { *s = '\0';
- soap->userid = soap_strdup(soap, soap->tmpbuf);
- soap->passwd = soap_strdup(soap, s + 1);
- }
- }
- }
- else if (!soap_tag_cmp(key, "WWW-Authenticate"))
- soap->authrealm = soap_strdup(soap, soap_get_header_attribute(soap, val+6, "realm"));
- else if (!soap_tag_cmp(key, "Expect"))
- { if (!soap_tag_cmp(val, "100-continue"))
- { if ((soap->error = soap->fposthdr(soap, "HTTP/1.1 100 Continue", NULL))
- || (soap->error = soap->fposthdr(soap, NULL, NULL)))
- return soap->error;
- }
- }
-#endif
- else if (!soap_tag_cmp(key, "SOAPAction"))
- { if (val[0] && val[1])
- { soap->action = soap_strdup(soap, val + 1);
- soap->action[strlen(soap->action) - 1] = '\0';
- }
- }
- else if (!soap_tag_cmp(key, "Location"))
- { strncpy(soap->endpoint, val, sizeof(soap->endpoint));
- soap->endpoint[sizeof(soap->endpoint) - 1] = '\0';
- }
-#ifdef WITH_COOKIES
- else if (!soap_tag_cmp(key, "Cookie") || !soap_tag_cmp(key, "Set-Cookie"))
- soap_getcookies(soap, val);
-#endif
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_get_header_attribute(struct soap *soap, const char *line, const char *key)
-{ register const char *s = line;
- if (s)
- { while (*s)
- { register short flag;
- s = soap_decode_key(soap->tmpbuf, sizeof(soap->tmpbuf), s);
- flag = soap_tag_cmp(soap->tmpbuf, key);
- s = soap_decode_val(soap->tmpbuf, sizeof(soap->tmpbuf), s);
- if (!flag)
- return soap->tmpbuf;
- }
- }
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_decode_key(char *buf, size_t len, const char *val)
-{ return soap_decode(buf, len, val, "=,;");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_decode_val(char *buf, size_t len, const char *val)
-{ if (*val != '=')
- { *buf = '\0';
- return val;
- }
- return soap_decode(buf, len, val + 1, ",;");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-soap_decode(char *buf, size_t len, const char *val, const char *sep)
-{ const char *s;
- char *t = buf;
- for (s = val; *s; s++)
- if (*s != ' ' && *s != '\t' && !strchr(sep, *s))
- break;
- if (*s == '"')
- { s++;
- while (*s && *s != '"' && --len)
- *t++ = *s++;
- }
- else
- { while (soap_notblank(*s) && !strchr(sep, *s) && --len)
- { if (*s == '%')
- { *t++ = ((s[1] >= 'A' ? (s[1] & 0x7) + 9 : s[1] - '0') << 4)
- + (s[2] >= 'A' ? (s[2] & 0x7) + 9 : s[2] - '0');
- s += 3;
- }
- else
- *t++ = *s++;
- }
- }
- *t = '\0';
- while (*s && !strchr(sep, *s))
- s++;
- return s;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_begin_out(struct soap *soap)
-{
-#ifndef WITH_LEANER
- size_t n = 0;
- if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && soap->mime.start)
- { const char *s;
- if (soap->mode & SOAP_ENC_DIME)
- s = "application/dime";
- else if (soap->version == 2)
- s = "application/soap+xml; charset=utf-8";
- else
- s = "text/xml; charset=utf-8";
- sprintf(soap->tmpbuf, "--%s\r\nContent-Type: %s\r\nContent-Transfer-Encoding: binary\r\nContent-ID: %s\r\n\r\n", soap->mime.boundary, s, soap->mime.start);
- n = strlen(soap->tmpbuf);
- if (soap_send_raw(soap, soap->tmpbuf, n))
- return soap->error;
- }
- if (soap->mode & SOAP_IO_LENGTH)
- soap->dime.size = soap->count; /* DIME in MIME correction */
- if (!(soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME))
- { if (soap_putdimehdr(soap))
- return soap->error;
- }
-#endif
- soap->part = SOAP_IN_ENVELOPE;
- return soap_element_begin_out(soap, "SOAP-ENV:Envelope", 0, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_end_out(struct soap *soap)
-{ if (soap_element_end_out(soap, "SOAP-ENV:Envelope"))
- return soap->error;
-#ifndef WITH_LEANER
- if ((soap->mode & SOAP_IO_LENGTH) && (soap->mode & SOAP_ENC_DIME))
- { soap->dime.size = soap->count - soap->dime.size; /* DIME in MIME correction */
- sprintf(soap->id, soap->dime_id_format, 0);
- soap->dime.id = soap->id;
- if (soap->local_namespaces)
- { if (soap->local_namespaces[0].out)
- soap->dime.type = (char*)soap->local_namespaces[0].out;
- else
- soap->dime.type = (char*)soap->local_namespaces[0].ns;
- }
- soap->dime.options = NULL;
- soap->dime.flags = SOAP_DIME_MB | SOAP_DIME_ABSURI;
- if (!soap->dime.first)
- soap->dime.flags |= SOAP_DIME_ME;
- soap->count += 12 + ((strlen(soap->dime.id)+3)&(~3)) + ((strlen(soap->dime.type)+3)&(~3));
- }
- if (soap->mode & SOAP_ENC_DIME)
- return soap_send_raw(soap, SOAP_STR_PADDING, -(long)soap->dime.size&3);
-#endif
- soap->part = SOAP_END_ENVELOPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_begin_in(struct soap *soap)
-{ register struct Namespace *p;
- soap->part = SOAP_IN_ENVELOPE;
- if (soap_element_begin_in(soap, "SOAP-ENV:Envelope", 0))
- return soap->error = SOAP_VERSIONMISMATCH;
- p = soap->local_namespaces;
- if (p)
- { const char *ns = p[0].out;
- if (!ns)
- ns = p[0].ns;
- if (!strcmp(ns, soap_env1))
- { soap->version = 1; /* make sure we use SOAP 1.1 */
- if (p[1].out)
- SOAP_FREE(p[1].out);
- if ((p[1].out = (char*)SOAP_MALLOC(sizeof(soap_enc1))))
- strcpy(p[1].out, soap_enc1);
- }
- else if (!strcmp(ns, soap_env2))
- { soap->version = 2; /* make sure we use SOAP 1.2 */
- if (p[1].out)
- SOAP_FREE(p[1].out);
- if ((p[1].out = (char*)SOAP_MALLOC(sizeof(soap_enc2))))
- strcpy(p[1].out, soap_enc2);
- }
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_envelope_end_in(struct soap *soap)
-{ if (soap_element_end_in(soap, "SOAP-ENV:Envelope"))
- return soap->error;
- soap->part = SOAP_END_ENVELOPE;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_begin_out(struct soap *soap)
-{ soap->part = SOAP_IN_BODY;
- if (soap->version == 1)
- soap->encoding = 1;
- if (soap_element(soap, "SOAP-ENV:Body", 0, NULL))
- return soap->error;
- if ((soap->mode & SOAP_XML_SEC) && soap_attribute(soap, "id", "_0"))
- return soap->error;
- return soap_element_start_end_out(soap, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_end_out(struct soap *soap)
-{ if (soap_element_end_out(soap, "SOAP-ENV:Body"))
- return soap->error;
- soap->part = SOAP_IN_BODY;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_begin_in(struct soap *soap)
-{ soap->part = SOAP_IN_BODY;
- return soap_element_begin_in(soap, "SOAP-ENV:Body", 0);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_body_end_in(struct soap *soap)
-{ if (soap_element_end_in(soap, "SOAP-ENV:Body"))
- return soap->error;
- soap->part = SOAP_END_BODY;
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_header(struct soap *soap)
-{ if (soap_getheader(soap) && soap->error == SOAP_TAG_MISMATCH)
- soap->error = SOAP_OK;
- return soap->error;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_endpoint(struct soap *soap, const char *endpoint)
-{ register const char *s;
- register size_t i, n;
- *soap->endpoint = '\0';
- *soap->host = '\0';
- *soap->path = '\0';
- soap->port = 80;
- if (!endpoint || !*endpoint)
- return;
-#ifdef WITH_OPENSSL
- if (!strncmp(endpoint, "https:", 6))
- soap->port = 443;
-#endif
- strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint) - 1);
- s = strchr(endpoint, ':');
- if (s && s[1] == '/' && s[2] == '/')
- s += 3;
- else
- s = endpoint;
- n = strlen(s);
- if (n >= sizeof(soap->host))
- n = sizeof(soap->host) - 1;
-/* WR[ */
-#ifdef WITH_IPV6
- if ('[' == s[0])
- { s++;
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (']' == s[i])
- {
- s++;
- break;
- }
- }
- }
- else
- { for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (s[i] == '/' || s[i] == ':')
- break;
- }
- }
-#else /* WITH_IPV6 */
-/* ]WR */
- for (i = 0; i < n; i++)
- { soap->host[i] = s[i];
- if (s[i] == '/' || s[i] == ':')
- break;
- }
-/* WR[ */
-#endif /* WITH_IPV6 */
-/* ]WR */
- soap->host[i] = '\0';
- if (s[i] == ':')
- { soap->port = (int)atol(s + i + 1);
- for (i++; i < n; i++)
- if (s[i] == '/')
- break;
- }
- if (s[i])
- { strncpy(soap->path, s + i + 1, sizeof(soap->path));
- soap->path[sizeof(soap->path) - 1] = '\0';
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_connect(struct soap *soap, const char *endpoint, const char *action)
-{ return soap_connect_command(soap, SOAP_POST, endpoint, action);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_connect_command(struct soap *soap, int http_command, const char *endpoint, const char *action)
-{ char host[sizeof(soap->host)];
- int port;
- size_t count;
- soap->error = SOAP_OK;
- strcpy(host, soap->host); /* save to compare */
- port = soap->port; /* save to compare */
- soap_set_endpoint(soap, endpoint);
- if (action)
- soap->action = soap_strdup(soap, action);
- if (soap->fconnect)
- {
- if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port)))
- return soap->error;
- }
- else if (*soap->host)
- { soap->status = http_command;
- if (!soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port)
- { soap->keep_alive = 0; /* force close */
- soap_closesock(soap);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port));
- soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
- if (soap->error)
- return soap->error;
- soap->keep_alive = ((soap->omode & SOAP_IO_KEEPALIVE) != 0);
- }
- else if (!soap->keep_alive || !soap->fpoll || soap->fpoll(soap))
- { soap->keep_alive = 0; /* force close */
- soap_closesock(soap);
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port));
- soap->socket = soap->fopen(soap, endpoint, soap->host, soap->port);
- if (soap->error)
- return soap->error;
- }
- }
- if (soap_begin_send(soap))
- return soap->error;
- count = soap_count_attachments(soap);
- if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML) && endpoint)
- { unsigned int k = soap->mode;
- soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
- if ((k & SOAP_IO) != SOAP_IO_FLUSH)
- soap->mode |= SOAP_IO_BUFFER;
- if ((soap->error = soap->fpost(soap, endpoint, soap->host, soap->port, soap->path, action, count)))
- return soap->error;
- if ((k & SOAP_IO) == SOAP_IO_CHUNK)
- { if (soap_flush(soap))
- return soap->error;
- }
- soap->mode = k;
- }
- if (http_command != SOAP_POST)
- return soap_end_send(soap);
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-char*
-SOAP_FMAC2
-soap_s2base64(struct soap *soap, const unsigned char *s, char *t, size_t n)
-{ register size_t i;
- register unsigned long m;
- register char *p;
- if (!t)
- t = (char*)soap_malloc(soap, (n + 2) / 3 * 4 + 1);
- if (!t)
- { soap->error = SOAP_EOM;
- return NULL;
- }
- p = t;
- t[0] = '\0';
- if (!s)
- return p;
- for (; n > 2; n -= 3, s += 3)
- { m = s[0];
- m = (m << 8) | s[1];
- m = (m << 8) | s[2];
- for (i = 4; i > 0; m >>= 6)
- t[--i] = soap_base64o[m & 0x3F];
- t += 4;
- }
- t[0] = '\0';
- if (n > 0)
- { m = 0;
- for (i = 0; i < n; i++)
- m = (m << 8) | *s++;
- for (; i < 3; i++)
- m <<= 8;
- for (i++; i > 0; m >>= 6)
- t[--i] = soap_base64o[m & 0x3F];
- for (i = 3; i > n; i--)
- t[i] = '=';
- t[4] = '\0';
- }
- return p;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-SOAP_FMAC1
-const char*
-SOAP_FMAC2
-soap_base642s(struct soap *soap, const char *s, char *t, size_t l, size_t *n)
-{ register int i, j, c;
- register unsigned long m;
- char *p = t;
- if (n)
- *n = 0;
- for (;;)
- { for (i = 0; i < SOAP_BLKLEN; i++)
- { m = 0;
- j = 0;
- while (j < 4)
- { c = *s++;
- if (c == '=' || !c)
- { i *= 3;
- switch (j)
- { case 2:
- *t++ = (char)((m >> 4) & 0xFF);
- i++;
- break;
- case 3:
- *t++ = (char)((m >> 10) & 0xFF);
- *t++ = (char)((m >> 2) & 0xFF);
- i += 2;
- }
- if (n)
- *n += i;
- return p;
- }
- c -= '+';
- if (c >= 0 && c <= 79)
- { m = (m << 6) + soap_base64i[c];
- j++;
- }
- }
- *t++ = (char)((m >> 16) & 0xFF);
- *t++ = (char)((m >> 8) & 0xFF);
- *t++ = (char)(m & 0xFF);
- if (l < 3)
- { if (n)
- *n += i;
- return p;
- }
- l -= 3;
- }
- if (n)
- *n += 3 * SOAP_BLKLEN;
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_puthttphdr(struct soap *soap, int status, size_t count)
-{ register const char *s;
- register int err;
- if (status == SOAP_FILE)
- s = soap->http_content;
- else if (status == SOAP_HTML)
- s = "text/html; charset=utf-8";
-#ifndef WITH_LEANER
- else if (soap->mode & SOAP_ENC_DIME)
- s = "application/dime";
-#endif
- else if (soap->version == 2)
- s = "application/soap+xml; charset=utf-8";
- else
- s = "text/xml; charset=utf-8";
-#ifndef WITH_LEANER
- if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && soap->mime.start && soap->status != SOAP_GET)
- { sprintf(soap->tmpbuf, "multipart/related; boundary=\"%s\"; type=%s; start=\"%s\"", soap->mime.boundary, s, soap->mime.start);
- s = soap->tmpbuf;
- }
-#endif
- if ((err = soap->fposthdr(soap, "Content-Type", s)))
- return err;
-#ifdef WITH_ZLIB
- if (soap->omode & SOAP_ENC_ZLIB)
- {
-#ifdef WITH_GZIP
- err = soap->fposthdr(soap, "Content-Encoding", "gzip");
-#else
- err = soap->fposthdr(soap, "Content-Encoding", "deflate");
-#endif
- if (err)
- return err;
- }
-#endif
- if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)
- err = soap->fposthdr(soap, "Transfer-Encoding", "chunked");
- else if (count > 0)
- { sprintf(soap->tmpbuf, "%lu", (unsigned long)count);
- err = soap->fposthdr(soap, "Content-Length", soap->tmpbuf);
- }
- if (err)
- return err;
- return soap->fposthdr(soap, "Connection", soap->keep_alive ? "keep-alive" : "close");
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_get(struct soap *soap)
-{ return SOAP_GET_METHOD;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_post(struct soap *soap, const char *endpoint, const char *host, int port, const char *path, const char *action, size_t count)
-{ register const char *s;
- register int err;
- if (soap->status == SOAP_GET)
- { s = "GET";
- count = 0;
- }
- else
- s = "POST";
-#ifdef PALM
- if (!endpoint || (strncmp(endpoint, "http:", 5) && strncmp(endpoint, "https:", 6) && strncmp(endpoint, "httpg:", 6)) && strncmp(endpoint, "_beam:", 6) && strncmp(endpoint, "_local:", 7) && strncmp(endpoint, "_btobex:", 8))
-#else
- if (!endpoint || (strncmp(endpoint, "http:", 5) && strncmp(endpoint, "https:", 6) && strncmp(endpoint, "httpg:", 6)))
-#endif
- return SOAP_OK;
- if (soap->proxy_host && strncmp(endpoint, "https:", 6))
- sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version);
- else
- sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, path, soap->http_version);
- if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return err;
- if (port != 80)
- sprintf(soap->tmpbuf, "%s:%d", host, port);
- else
- strcpy(soap->tmpbuf, host);
- if ((err = soap->fposthdr(soap, "Host", soap->tmpbuf))
- || (err = soap->fposthdr(soap, "User-Agent", "gSOAP/2.7"))
- || (err = soap_puthttphdr(soap, SOAP_OK, count)))
- return err;
-#ifdef WITH_ZLIB
-#ifdef WITH_GZIP
- if ((err = soap->fposthdr(soap, "Accept-Encoding", "gzip, deflate")))
-#else
- if ((err = soap->fposthdr(soap, "Accept-Encoding", "deflate")))
-#endif
- return err;
-#endif
-#ifndef WITH_LEAN
- if (soap->userid && soap->passwd && strlen(soap->userid) + strlen(soap->passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->userid, soap->passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((err = soap->fposthdr(soap, "Authorization", soap->tmpbuf)))
- return err;
- }
- if (soap->proxy_userid && soap->proxy_passwd && strlen(soap->proxy_userid) + strlen(soap->proxy_passwd) < 761)
- { sprintf(soap->tmpbuf + 262, "%s:%s", soap->proxy_userid, soap->proxy_passwd);
- strcpy(soap->tmpbuf, "Basic ");
- soap_s2base64(soap, (const unsigned char*)(soap->tmpbuf + 262), soap->tmpbuf + 6, strlen(soap->tmpbuf + 262));
- if ((err = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf)))
- return err;
- }
-#endif
-#ifdef WITH_COOKIES
-#ifdef WITH_OPENSSL
- if (soap_putcookies(soap, host, path, soap->ssl != NULL))
- return soap->error;
-#else
- if (soap_putcookies(soap, host, path, 0))
- return soap->error;
-#endif
-#endif
- if (action && soap->version == 1)
- { sprintf(soap->tmpbuf, "\"%s\"", action);
- if ((err = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf)))
- return err;
- }
- return soap->fposthdr(soap, NULL, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_send_header(struct soap *soap, const char *s)
-{ register const char *t;
- do
- { t = strchr(s, '\n'); /* disallow \n in HTTP headers */
- if (!t)
- t = s + strlen(s);
- if (soap_send_raw(soap, s, t - s))
- return soap->error;
- s = t + 1;
- } while (*t);
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_post_header(struct soap *soap, const char *key, const char *val)
-{ if (key)
- { if (http_send_header(soap, key))
- return soap->error;
- if (val && (soap_send_raw(soap, ": ", 2) || http_send_header(soap, val)))
- return soap->error;
- }
- return soap_send_raw(soap, "\r\n", 2);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static int
-http_response(struct soap *soap, int status, size_t count)
-{ register int err;
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid)
- httpOutputEnable(soap->rpmreqid);
-#endif /* WMW_RPM_IO */
-/* ]WR */
- if (!status || status == SOAP_HTML || status == SOAP_FILE)
- { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "OK 200\n"));
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
-#else
-/* ]WR */
- if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */
-/* WR[ */
-#endif /* WMW_RPM_IO */
-/* ]WR */
- { sprintf(soap->tmpbuf, "HTTP/%s 200 OK", soap->http_version);
- if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return err;
- }
- else if ((err = soap->fposthdr(soap, "Status", "200 OK")))
- return err;
- }
- else if (status > 200 && status < 600)
- { sprintf(soap->tmpbuf, "HTTP/%s %d %s", soap->http_version, status, http_error(soap, status));
- if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return err;
- if (status == 401)
- { sprintf(soap->tmpbuf, "Basic realm=\"%s\"", soap->authrealm ? soap->authrealm : "gSOAP Web Service");
- if ((err = soap->fposthdr(soap, "WWW-Authenticate", soap->tmpbuf)))
- return err;
- }
- else if ((status >= 301 && status <= 303) || status == 307)
- { if ((err = soap->fposthdr(soap, "Location", soap->endpoint)))
- return err;
- }
- }
- else
- { const char *s = *soap_faultcode(soap);
- if (soap->version == 2 && !strcmp(s, "SOAP-ENV:Sender"))
- s = "400 Bad Request";
- else
- s = "500 Internal Server Error";
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error %s (status=%d)\n", s, status));
-/* WR[ */
-#ifdef WMW_RPM_IO
- if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */
-#else
-/* ]WR */
- if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */
-/* WR[ */
-#endif /* WMW_RPM_IO */
-/* ]WR */
- { sprintf(soap->tmpbuf, "HTTP/%s %s", soap->http_version, s);
- if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL)))
- return err;
- }
- else if ((err = soap->fposthdr(soap, "Status", s)))
- return err;
- }
- if ((err = soap->fposthdr(soap, "Server", "gSOAP/2.7"))
- || (err = soap_puthttphdr(soap, status, count)))
- return err;
-#ifdef WITH_COOKIES
- if (soap_putsetcookies(soap))
- return soap->error;
-#endif
- return soap->fposthdr(soap, NULL, NULL);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_response(struct soap *soap, int status)
-{ register size_t count;
- if (!(soap->omode & (SOAP_ENC_XML | SOAP_IO_STORE /* this tests for chunking too */))
- && (status == SOAP_HTML || status == SOAP_FILE))
- { soap->omode &= ~SOAP_IO;
- soap->omode |= SOAP_IO_STORE;
- }
- soap->status = status;
- count = soap_count_attachments(soap);
- if (soap_begin_send(soap))
- return soap->error;
- if ((soap->mode & SOAP_IO) != SOAP_IO_STORE && !(soap->mode & SOAP_ENC_XML))
- { register int n = soap->mode;
- soap->mode &= ~(SOAP_IO | SOAP_ENC_ZLIB);
- if ((n & SOAP_IO) != SOAP_IO_FLUSH)
- soap->mode |= SOAP_IO_BUFFER;
- if ((soap->error = soap->fresponse(soap, status, count)))
- return soap->error;
- if ((n & SOAP_IO) == SOAP_IO_CHUNK)
- { if (soap_flush(soap))
- return soap->error;
- }
- soap->mode = n;
- }
- return SOAP_OK;
-}
-#endif
-
-/******************************************************************************/
-#ifndef WITH_LEAN
-static const char*
-soap_set_validation_fault(struct soap *soap, const char *s, const char *t)
-{ sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element <%s>", s, t?t:SOAP_STR_EOS, soap->tag);
- return soap->msgbuf;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_set_fault(struct soap *soap)
-{ const char **c = soap_faultcode(soap);
- const char **s = soap_faultstring(soap);
- if (!*c)
- { if (soap->version == 2)
- *c = "SOAP-ENV:Sender";
- else
- *c = "SOAP-ENV:Client";
- }
- if (*s)
- return;
- switch (soap->error)
- {
-#ifndef WITH_LEAN
- case SOAP_CLI_FAULT:
- *s = "Client fault";
- break;
- case SOAP_SVR_FAULT:
- *s = "Server fault";
- break;
- case SOAP_TAG_MISMATCH:
- *s = soap_set_validation_fault(soap, "tag name or namespace mismatch", NULL);
- break;
- case SOAP_TAG_END:
- *s = soap_set_validation_fault(soap, "incorrect end tag", NULL);
- break;
- case SOAP_TYPE:
- *s = soap_set_validation_fault(soap, "data type mismatch ", soap->type);
- break;
- case SOAP_SYNTAX_ERROR:
- *s = "Well-formedness constraint violation";
- break;
- case SOAP_NO_TAG:
- *s = "No XML element tag found";
- break;
- case SOAP_MUSTUNDERSTAND:
- *c = "SOAP-ENV:MustUnderstand";
- sprintf(soap->msgbuf, "The data in element '%s' must be understood but cannot be handled", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_VERSIONMISMATCH:
- *c = "SOAP-ENV:VersionMismatch";
- *s = "SOAP version mismatch or invalid SOAP message";
- break;
- case SOAP_DATAENCODINGUNKNOWN:
- *c = "SOAP-ENV:DataEncodingUnknown";
- *s = "Unsupported SOAP data encoding";
- break;
- case SOAP_NAMESPACE:
- *s = soap_set_validation_fault(soap, "namespace mismatch", NULL);
- break;
- case SOAP_FATAL_ERROR:
- *s = "Fatal error";
- break;
- case SOAP_NO_METHOD:
- sprintf(soap->msgbuf, "Method '%s' not implemented: method name or namespace not recognized", soap->tag);
- *s = soap->msgbuf;
- break;
- case SOAP_GET_METHOD:
- *s = "HTTP GET method not implemented";
- break;
- case SOAP_EOM:
- *s = "Out of memory";
- break;
- case SOAP_IOB:
- *s = "Array index out of bounds";
- break;
- case SOAP_NULL:
- *s = soap_set_validation_fault(soap, "nil not allowed", NULL);
- break;
- case SOAP_MULTI_ID:
- *s = soap_set_validation_fault(soap, "multiple definitions of id ", soap->id);
- break;
- case SOAP_MISSING_ID:
- *s = soap_set_validation_fault(soap, "missing id for ref ", soap->id);
- break;
- case SOAP_HREF:
- *s = soap_set_validation_fault(soap, "incompatible object ref ", soap->id);
- break;
- case SOAP_FAULT:
- break;
- case SOAP_TCP_ERROR:
- *s = tcp_error(soap);
- break;
- case SOAP_HTTP_ERROR:
- *s = "HTTP error";
- break;
- case SOAP_SSL_ERROR:
- *s = "SSL error";
- break;
- case SOAP_PLUGIN_ERROR:
- *s = "Plugin registry error";
- break;
- case SOAP_DIME_MISMATCH:
- *s = "DIME version/transmission error";
- break;
- case SOAP_DIME_END:
- *s = "End of DIME error";
- break;
- case SOAP_DIME_ERROR:
- *s = "DIME format error";
- break;
- case SOAP_MIME_ERROR:
- *s = "MIME format error";
- break;
- case SOAP_ZLIB_ERROR:
-#ifdef WITH_ZLIB
- sprintf(soap->msgbuf, "Zlib/gzip error: '%s'", soap->d_stream.msg?soap->d_stream.msg:"");
- *s = soap->msgbuf;
-#else
- *s = "Zlib not installed for required message (de)compression";
-#endif
- break;
- case SOAP_REQUIRED:
- *s = soap_set_validation_fault(soap, "missing required attribute", NULL);
- break;
- case SOAP_PROHIBITED:
- *s = soap_set_validation_fault(soap, "prohibited attribute present", NULL);
- break;
- case SOAP_OCCURS:
- *s = soap_set_validation_fault(soap, "a min/maxOccurs violation was detected", NULL);
- break;
- case SOAP_LENGTH:
- *s = soap_set_validation_fault(soap, "content length violation", NULL);
- break;
-#endif
- case SOAP_EOF:
- sprintf(soap->msgbuf, "End of file or no input: '%s'", soap_strerror(soap));
- *s = soap->msgbuf;
- break;
- default:
- if (soap->error > 200 && soap->error < 600)
- { sprintf(soap->msgbuf, "HTTP Error: '%s'", http_error(soap, soap->error));
- *s = soap->msgbuf;
- }
- else
- { sprintf(soap->msgbuf, "Error code %d", soap->error);
- *s = soap->msgbuf;
- }
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_send_fault(struct soap *soap)
-{ register int status = soap->error;
- if (status == SOAP_STOP)
- return status;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Sending back fault struct for error code %d\n", soap->error));
- soap->keep_alive = 0; /* to terminate connection */
- soap_set_fault(soap);
- if ((status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) && (!soap->fpoll || soap->fpoll(soap) == SOAP_OK))
- { soap->error = SOAP_OK;
- soap_serializeheader(soap);
- soap_serializefault(soap);
- soap_begin_count(soap);
- if (soap->mode & SOAP_IO_LENGTH)
- { soap_envelope_begin_out(soap);
- soap_putheader(soap);
- soap_body_begin_out(soap);
- soap_putfault(soap);
- soap_body_end_out(soap);
- soap_envelope_end_out(soap);
- }
- if (soap_response(soap, status)
- || soap_envelope_begin_out(soap)
- || soap_putheader(soap)
- || soap_body_begin_out(soap)
- || soap_putfault(soap)
- || soap_body_end_out(soap)
- || soap_envelope_end_out(soap))
- return soap_closesock(soap);
- soap_end_send(soap);
- }
- soap->error = status;
- return soap_closesock(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_recv_fault(struct soap *soap)
-{ register int status = soap->error;
- DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Receiving SOAP Fault\n"));
- soap->error = SOAP_OK;
- if (soap_getfault(soap))
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Error: soap_get_soapfault() failed. Is this a SOAP message at all?\n"));
- *soap_faultcode(soap) = (soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client");
- soap->error = status;
- soap_set_fault(soap);
- }
- else
- { register const char *s = *soap_faultcode(soap);
- if (!soap_match_tag(soap, s, "SOAP-ENV:Server") || !soap_match_tag(soap, s, "SOAP-ENV:Receiver"))
- status = SOAP_SVR_FAULT;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:Client") || !soap_match_tag(soap, s, "SOAP-ENV:Sender"))
- status = SOAP_CLI_FAULT;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:MustUnderstand"))
- status = SOAP_MUSTUNDERSTAND;
- else if (!soap_match_tag(soap, s, "SOAP-ENV:VersionMismatch"))
- status = SOAP_VERSIONMISMATCH;
- else
- { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Fault code %s\n", s));
- status = SOAP_FAULT;
- }
- if (soap_body_end_in(soap)
- || soap_envelope_end_in(soap)
- || soap_end_recv(soap))
- return soap_closesock(soap);
- soap->error = status;
- }
- return soap_closesock(soap);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static const char*
-soap_strerror(struct soap *soap)
-{ int err = soap->errnum;
- if (!err)
- err = soap_errno;
- if (err)
- {
-#ifndef UNDER_CE
- return strerror(err);
-#else
- FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)&soap->werrorstr, sizeof(soap->werrorstr), NULL);
- wcstombs(soap->errorstr, soap->werrorstr, sizeof(soap->errorstr));
- return soap->errorstr;
-#endif
- }
- return "Operation interrupted or timed out";
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static int
-soap_set_error(struct soap *soap, const char *faultcode, const char *faultstring, const char *faultdetail, int soaperror)
-{ *soap_faultcode(soap) = faultcode;
- *soap_faultstring(soap) = faultstring;
- if (faultdetail && *faultdetail)
- { register const char **s = soap_faultdetail(soap);
- if (s)
- *s = faultdetail;
- }
- return soap->error = soaperror;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_sender_error(struct soap *soap, const char *faultstring, const char *faultdetail, int soaperror)
-{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultstring, faultdetail, soaperror);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_set_receiver_error(struct soap *soap, const char *faultstring, const char *faultdetail, int soaperror)
-{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultstring, faultdetail, soaperror);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-static int
-soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultstring, const char *faultdetail)
-{ char *s = NULL, *t = NULL;
- if (faultstring)
- s = soap_strdup(soap, faultstring);
- if (faultdetail)
- t = soap_strdup(soap, faultdetail);
- return soap_set_error(soap, faultcode, s, t, SOAP_FAULT);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
-{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultstring, faultdetail);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetail)
-{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultstring, faultdetail);
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_print_fault(struct soap *soap, FILE *fd)
-{ if (soap->error)
- { const char **s;
- if (!*soap_faultcode(soap))
- soap_set_fault(soap);
- fprintf(fd, "SOAP FAULT: %s\n\"%s\"\n", *soap_faultcode(soap), *soap_faultstring(soap));
- s = soap_faultdetail(soap);
- if (s && *s)
- fprintf(fd, "Detail: %s\n", *s);
- }
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-void
-SOAP_FMAC2
-soap_print_fault_location(struct soap *soap, FILE *fd)
-{
-#ifndef WITH_LEAN
- int c;
- if (soap->error && soap->buflen > 0)
- { if (soap->bufidx == 0)
- soap->bufidx = 1;
- c = soap->buf[soap->bufidx - 1];
- soap->buf[soap->bufidx - 1] = '\0';
- if (soap->buflen - soap->bufidx > 1024)
- soap->buf[soap->bufidx + 1024] = '\0';
- else
- soap->buf[soap->buflen - 1] = '\0';
- fprintf(fd, "%s%c\n** HERE **\n", soap->buf, c);
- if (soap->bufidx < soap->buflen)
- fprintf(fd, "%s\n", soap->buf + soap->bufidx);
- }
-#endif
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-SOAP_FMAC1
-int
-SOAP_FMAC2
-soap_register_plugin_arg(struct soap *soap, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void *arg)
-{ register struct soap_plugin *p;
- register int r;
- if (!(p = (struct soap_plugin*)SOAP_MALLOC(sizeof(struct soap_plugin))))
- return soap->error = SOAP_EOM;
- p->id = NULL;
- p->data = NULL;
- p->fcopy = NULL;
- p->fdelete = NULL;
- r = fcreate(soap, p, arg);
- if (!r && p->fdelete)
- { p->next = soap->plugins;
- soap->plugins = p;
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Registered '%s' plugin\n", p->id));
- return SOAP_OK;
- }
- DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not register plugin '%s': plugin returned error %d (or fdelete callback not set)\n", p->id?p->id:"?", r));
- SOAP_FREE(p);
- return r;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_1
-static void *
-fplugin(struct soap *soap, const char *id)
-{ register struct soap_plugin *p;
- for (p = soap->plugins; p; p = p->next)
- if (p->id == id || !strcmp(p->id, id))
- return p->data;
- return NULL;
-}
-#endif
-
-/******************************************************************************/
-#ifndef PALM_2
-SOAP_FMAC1
-void *
-SOAP_FMAC2
-soap_lookup_plugin(struct soap *soap, const char *id)
-{ return soap->fplugin(soap, id);
-}
-#endif
-
-/******************************************************************************/
-#ifdef __cplusplus
-}
-#endif
-
+++ /dev/null
-#include <getopt.h>
-#include <stdsoap2.h>
-
-#include "glite/security/glite_gsplugin.h"
-#include "glite/lb/consumer.h"
-
-#include "bk_ws_H.h"
-#include "ws_fault.h"
-
-#include "soap_version.h"
-#if GSOAP_VERSION <= 20602
-#define soap_call___lb__GetVersion soap_call___ns1__GetVersion
-#endif
-
-#include "LoggingAndBookkeeping.nsmap"
-
-static struct option opts[] = {
- {"help", 0, NULL, 'h'},
- {"server", 1, NULL, 'm'},
-};
-
-static void usage(char *me)
-{
- fprintf(stderr,"usage: %s [option]\n"
- "\t-h, --help Shows this screen.\n"
- "\t-m, --server BK server address:port.\n"
- , me);
-}
-
-//static void printstat(edg_wll_JobStat stat, int level);
-
-int main(int argc,char** argv)
-{
- edg_wll_Context ctx;
- glite_gsplugin_Context gsplugin_ctx;
- struct soap soap;
- struct _lbe__GetVersion in;
- struct _lbe__GetVersionResponse out;
- int opt, err;
- char *server = "http://localhost:9003/",
- *name = NULL;
-
-
- name = strrchr(argv[0],'/');
- if (name) name++; else name = argv[0];
-
- while ((opt = getopt_long(argc, argv, "hm:", opts, NULL)) != EOF) switch (opt)
- {
- case 'h': usage(name); return 0;
- case 'm': server = optarg; break;
- case '?': usage(name); return 1;
- }
-
- edg_wll_InitContext(&ctx);
- glite_gsplugin_init_context(&gsplugin_ctx);
-
- soap_init(&soap);
- soap_set_namespaces(&soap, namespaces);
-
- if ( soap_register_plugin_arg(&soap, glite_gsplugin, (void *)gsplugin_ctx) )
- {
- soap_print_fault(&soap, stderr);
- return 1;
- }
-
- memset(&in, 0, sizeof(in));
- memset(&out, 0, sizeof(out));
- switch (err = soap_call___lb__GetVersion(&soap, server, "", &in, &out))
- {
- case SOAP_OK: printf("Server version: %s\n", out.version); break;
- case SOAP_FAULT:
- case SOAP_SVR_FAULT:
- {
- char *et,*ed;
-
- edg_wll_FaultToErr(&soap,ctx);
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"%s: %s (%s)\n",argv[0],et,ed);
- exit(1);
- }
- default:
- printf("???, err=%d\n", err);
- soap_print_fault(&soap, stderr);
- }
-
- soap_end(&soap);
- soap_done(&soap);
- glite_gsplugin_free_context(gsplugin_ctx);
- edg_wll_FreeContext(ctx);
-
- return 0;
-}
+++ /dev/null
-#include <getopt.h>
-#include <stdsoap2.h>
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/events_parse.h"
-
-#include "soap_version.h"
-#include "glite/security/glite_gsplugin.h"
-#include "glite/security/glite_gscompat.h"
-
-#include "bk_ws_H.h"
-#include "ws_typeref.h"
-#include "ws_fault.h"
-
-#if GSOAP_VERSION <= 20602
-#define soap_call___lb__QueryEvents soap_call___ns1__QueryEvents
-#endif
-
-#include "LoggingAndBookkeeping.nsmap"
-
-static struct option opts[] = {
- {"help", 0, NULL, 'h'},
- {"server", 1, NULL, 'm'},
- {"jobid", 1, NULL, 'j'}
-};
-
-static void usage(char *me)
-{
- fprintf(stderr,"usage: %s [option]\n"
- "\t-h, --help Shows this screen.\n"
- "\t-m, --server BK server address:port.\n"
- "\t-j, --jobid ID of requested job.\n"
- , me);
-}
-
-static void free_events(edg_wll_Event *events);
-
-int main(int argc,char** argv)
-{
- edg_wll_Context ctx;
- glite_gsplugin_Context gsplugin_ctx;
- struct soap *mydlo = soap_new();
- struct _lbe__QueryEventsResponse out;
- struct _lbe__QueryEvents in;
- edg_wll_QueryRec **jconds = NULL;
- edg_wll_QueryRec j[2], e[1];
- int opt, err, i;
- edg_wlc_JobId job;
- char *server = "http://localhost:9003/",
- *jobid = NULL,
- *name = NULL;
-
-
- name = strrchr(argv[0],'/');
- if (name) name++; else name = argv[0];
-
- while ((opt = getopt_long(argc, argv, "hm:j:", opts, NULL)) != EOF) switch (opt)
- {
- case 'h': usage(name); return 0;
- case 'm': server = optarg; break;
- case 'j': jobid = optarg; break;
- case '?': usage(name); return 1;
- }
-
- if ( !jobid )
- {
- printf("jobid should be given\n");
- usage(name);
- return 1;
- }
- else if (edg_wlc_JobIdParse(jobid,&job)) {
- fprintf(stderr,"%s: can't parse job ID\n",argv[1]);
- return 1;
- }
-
-
- edg_wll_InitContext(&ctx);
- glite_gsplugin_init_context(&gsplugin_ctx);
-
- soap_set_namespaces(mydlo, namespaces);
- if ( soap_register_plugin_arg(mydlo, glite_gsplugin, (void *)gsplugin_ctx) )
- {
- soap_print_fault(mydlo, stderr);
- return 1;
- }
-
- glite_gsplugin_set_udata(mydlo, ctx);
-
- /* prepare job log query */
- memset(j,0,sizeof j);
- memset(e,0,sizeof e);
-
- j[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
- j[0].op = EDG_WLL_QUERY_OP_EQUAL;
- j[0].value.j = job;
-
-
- jconds = (edg_wll_QueryRec **) calloc(2, sizeof(edg_wll_QueryRec *));
- for ( i = 0; i < 1; i++ )
- {
- jconds[i] = (edg_wll_QueryRec *) calloc(2, sizeof(edg_wll_QueryRec));
- jconds[i][0] = j[i];
- }
-
-/* econds = (edg_wll_QueryRec **) calloc(1, sizeof(edg_wll_QueryRec *));
- for ( i = 0; i < 1; i++ )
- {
- econds[i] = (edg_wll_QueryRec *) calloc(1, sizeof(edg_wll_QueryRec));
- econds[i][0] = e[i];
- }*/
-
- memset(&in, 0, sizeof in);
- memset(&out, 0, sizeof out);
-
- if (edg_wll_QueryCondsExtToSoap(mydlo, (const edg_wll_QueryRec **)jconds,
- &in.__sizejobConditions, &in.jobConditions) != SOAP_OK) {
- printf("Error converting QueryConds to Soap!\n");
- return(1);
- }
-
- for (i = 0; jconds[i]; i++) {
- if (jconds[i]) edg_wlc_JobIdFree(jconds[i][0].value.j);
- free(jconds[i]);
- }
- free(jconds);
-
- //edg_wll_QueryCondsExtToSoap(mydlo, (const edg_wll_QueryRec **)econds,
- // &in.__sizeeventConditions, &in.eventConditions);
-
- //in.jobConditions = NULL;
- //in.__sizejobConditions = 0;
- in.eventConditions = NULL;
- in.__sizeeventConditions = 0;
-
- switch (err = soap_call___lb__QueryEvents(mydlo, server, "",&in,&out))
- {
- case SOAP_OK:
- {
- edg_wll_Event *events = NULL;
- int i;
-
-
- edg_wll_SoapToEventsQueryRes(mydlo,out,&events);
-
- for ( i = 0; events && events[i].type != EDG_WLL_EVENT_UNDEF; i++ )
- {
- char *e = edg_wll_UnparseEvent(ctx,events+i);
- fputs(e,stdout);
- fputs("\n",stdout);
- free(e);
- }
-
- free_events(events);
- printf("\nFound %d events\n",i);
- }
- break;
- case SOAP_FAULT:
- case SOAP_SVR_FAULT:
- {
- char *et,*ed;
-
- edg_wll_FaultToErr(mydlo,ctx);
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"%s: %s (%s)\n",argv[0],et,ed);
- soap_done(mydlo);
- exit(1);
- }
- default:
- fprintf(stderr,"err = %d\n",err);
- soap_print_fault(mydlo,stderr);
- }
-
- soap_end(mydlo/*, out.events*/);
- soap_done(mydlo);
- free(mydlo);
- glite_gsplugin_free_context(gsplugin_ctx);
- edg_wll_FreeContext(ctx);
- return 0;
-}
-
-
-static void free_events(edg_wll_Event *events)
-{
- int i;
-
- if (events) {
- for (i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++)
- edg_wll_FreeEvent(&(events[i]));
- edg_wll_FreeEvent(&(events[i])); /* free last line */
- free(events);
- events = NULL;
- }
-}
+++ /dev/null
-#include <getopt.h>
-#include <stdsoap2.h>
-
-#include "soap_version.h"
-#include "glite/security/glite_gsplugin.h"
-#include "glite/security/glite_gscompat.h"
-#include "glite/lb/consumer.h"
-
-#include "bk_ws_H.h"
-#include "ws_typeref.h"
-#include "ws_fault.h"
-
-#if GSOAP_VERSION <= 20602
-#define soap_call___lb__JobStatus soap_call___ns1__JobStatus
-#endif
-
-#include "LoggingAndBookkeeping.nsmap"
-
-static struct option opts[] = {
- {"help", 0, NULL, 'h'},
- {"server", 1, NULL, 'm'},
- {"jobid", 1, NULL, 'j'}
-};
-
-static void usage(char *me)
-{
- fprintf(stderr,"usage: %s [option]\n"
- "\t-h, --help Shows this screen.\n"
- "\t-m, --server BK server address:port.\n"
- "\t-j, --jobid ID of requested job.\n"
- , me);
-}
-
-static void printstat(edg_wll_JobStat stat, int level);
-
-int main(int argc,char** argv)
-{
- edg_wll_Context ctx;
- glite_gsplugin_Context gsplugin_ctx;
- struct soap *mydlo = soap_new();
- struct _lbe__JobStatusResponse out;
- struct _lbe__JobStatus in;
- int opt, err;
- char *server = "http://localhost:9003/",
- *jobid = NULL,
- *name = NULL;
-
-
- name = strrchr(argv[0],'/');
- if (name) name++; else name = argv[0];
-
- while ((opt = getopt_long(argc, argv, "hm:j:", opts, NULL)) != EOF) switch (opt)
- {
- case 'h': usage(name); return 0;
- case 'm': server = optarg; break;
- case 'j': jobid = optarg; break;
- case '?': usage(name); return 1;
- }
-
- if ( !jobid )
- {
- printf("jobid should be given\n");
- usage(name);
- return 1;
- }
-
- edg_wll_InitContext(&ctx);
- soap_set_namespaces(mydlo, namespaces);
- glite_gsplugin_init_context(&gsplugin_ctx);
-
- if ( soap_register_plugin_arg(mydlo, glite_gsplugin, (void *)gsplugin_ctx) )
- {
- soap_print_fault(mydlo, stderr);
- return 1;
- }
-
- glite_gsplugin_set_udata(mydlo, ctx);
-
- in.jobid = soap_strdup(mydlo, jobid);
- in.flags = soap_malloc(mydlo, sizeof(*in.flags));
- edg_wll_JobStatFlagsToSoap(mydlo, 0, in.flags);
-
- switch (err = soap_call___lb__JobStatus(mydlo, server, "",&in,&out))
- {
- case SOAP_OK:
- {
- edg_wll_JobStat s;
-
- edg_wll_SoapToStatus(mydlo,out.stat,&s);
- printstat(s, 0);
- edg_wll_FreeStatus(&s);
- }
- break;
- case SOAP_FAULT:
- case SOAP_SVR_FAULT:
- {
- char *et,*ed;
-
- edg_wll_FaultToErr(mydlo,ctx);
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"%s: %s (%s)\n",argv[0],et,ed);
- exit(1);
- }
- default:
- fprintf(stderr,"err = %d\n",err);
- soap_print_fault(mydlo,stderr);
- }
-
- soap_end(mydlo);
- soap_done(mydlo);
- free(mydlo);
- glite_gsplugin_free_context(gsplugin_ctx);
- edg_wll_FreeContext(ctx);
-
- return 0;
-}
-
-static void printstat(edg_wll_JobStat stat, int level)
-{
- char *s, *j1,*j2, ind[10];
- int i;
-
-
- for (i=0; i < level; i++)
- ind[i]='\t';
- ind[i]='\0';
-
- s = edg_wll_StatToString(stat.state);
-/* print whole flat structure */
- printf("%sstate : %s\n", ind, s);
- printf("%sjobId : %s\n", ind, j1 = edg_wlc_JobIdUnparse(stat.jobId));
- printf("%sowner : %s\n", ind, stat.owner);
- switch (stat.jobtype) {
- case EDG_WLL_STAT_SIMPLE:
- printf("%sjobtype : SIMPLE\n", ind);
- break;
- case EDG_WLL_STAT_DAG:
- printf("%sjobtype : DAG\n", ind);
- break;
- case EDG_WLL_STAT_COLLECTION:
- printf("%sjobtype : COLLECTION\n", ind);
- break;
- case EDG_WLL_STAT_PBS:
- printf("%sjobtype : PBS\n", ind);
- break;
- default:
- break;
- }
- printf("%sparent_job : %s\n", ind,
- j2 = edg_wlc_JobIdUnparse(stat.parent_job));
- if (stat.jobtype) {;
- printf("%sseed : %s\n", ind, stat.seed);
- printf("%schildren_num : %d\n", ind, stat.children_num);
- printf("%schildren :\n", ind);
- if (stat.children)
- for (i=0; stat.children[i]; i++)
- printf("%s\tchildren : %s\n", ind, stat.children[i]);
- printf("%schildren_states :\n", ind);
- if (stat.children_states)
- for (i=0; stat.children_states[i].state; i++)
- printstat(stat.children_states[i], level+1);
- printf("%schildren_hist :\n",ind);
- if (stat.children_hist)
- for (i=1; i<=stat.children_hist[0]; i++)
- printf("%s%14s %d\n", ind, edg_wll_StatToString(i-1),stat.children_hist[i]);
- }
- printf("%scondorId : %s\n", ind, stat.condorId);
- printf("%sglobusId : %s\n", ind, stat.globusId);
- printf("%slocalId : %s\n", ind, stat.localId);
- printf("%sjdl : %s\n", ind, stat.jdl);
- printf("%smatched_jdl : %s\n", ind, stat.matched_jdl);
- printf("%sdestination : %s\n", ind, stat.destination);
- printf("%snetwork server : %s\n", ind, stat.network_server);
- printf("%scondor_jdl : %s\n", ind, stat.condor_jdl);
- printf("%srsl : %s\n", ind, stat.rsl);
- printf("%sreason : %s\n", ind, stat.reason);
- printf("%slocation : %s\n", ind, stat.location);
- printf("%sce_node : %s\n", ind, stat.ce_node);
- printf("%ssubjob_failed : %d\n", ind, stat.subjob_failed);
- printf("%sdone_code : %s\n", ind, edg_wll_done_codeToString(stat.done_code));
- printf("%sexit_code : %d\n", ind, stat.exit_code);
- printf("%sresubmitted : %d\n", ind, stat.resubmitted);
- printf("%scancelling : %d\n", ind, stat.cancelling);
- printf("%scancelReason : %s\n", ind, stat.cancelReason);
- printf("%scpuTime : %d\n", ind, stat.cpuTime);
- printf("%suser_tags :\n",ind);
- if (stat.user_tags)
- for (i=0; stat.user_tags[i].tag; i++) printf("%s%14s = \"%s\"\n", ind,
- stat.user_tags[i].tag,stat.user_tags[i].value);
- printf("%sstateEnterTime : %ld.%06ld\n", ind, stat.stateEnterTime.tv_sec,stat.stateEnterTime.tv_usec);
- printf("%sstateEnterTimes : \n",ind);
- if (stat.stateEnterTimes)
- for (i=1; i<=stat.stateEnterTimes[0]; i++) {
- time_t st = stat.stateEnterTimes[i];
-
- printf("%s%14s %s", ind, edg_wll_StatToString(i-1), st == 0 ?
- " - not available -\n" : ctime(&st));
- }
- printf("%slastUpdateTime : %ld.%06ld\n", ind, stat.lastUpdateTime.tv_sec,stat.lastUpdateTime.tv_usec);
- printf("%sexpectUpdate : %d\n", ind, stat.expectUpdate);
- printf("%sexpectFrom : %s\n", ind, stat.expectFrom);
- printf("%sacl : %s\n", ind, stat.acl);
- printf("%spayload_running: %d\n", ind, stat.payload_running);
- if (stat.possible_destinations) {
- printf("%spossible_destinations : \n", ind);
- for (i=0; stat.possible_destinations[i]; i++)
- printf("%s\t%s \n", ind, stat.possible_destinations[i]);
- }
- if (stat.possible_ce_nodes) {
- printf("%spossible_ce_nodes : \n", ind);
- for (i=0; stat.possible_ce_nodes[i]; i++)
- printf("%s\t%s \n", ind, stat.possible_ce_nodes[i]);
- }
- /* PBS state section */
- if (stat.jobtype == EDG_WLL_STAT_PBS) {
- printf("%spbs_state : %s\n", ind, stat.pbs_state);
- printf("%spbs_queue : %s\n", ind, stat.pbs_queue);
- printf("%spbs_owner : %s\n", ind, stat.pbs_owner);
- printf("%spbs_name : %s\n", ind, stat.pbs_name);
- printf("%spbs_reason : %s\n", ind, stat.pbs_reason);
- printf("%spbs_scheduler : %s\n", ind, stat.pbs_scheduler);
- printf("%spbs_dest_host : %s\n", ind, stat.pbs_dest_host);
- printf("%spbs_pid : %d\n", ind, stat.pbs_pid);
- printf("%spbs_resource_usage : %s%s\n", ind,
- (stat.pbs_resource_usage) ? "\n" : "", stat.pbs_resource_usage);
- printf("%spbs_exit_status : %d\n", ind, stat.pbs_exit_status);
- printf("%spbs_error_desc : %s%s\n", ind,
- (stat.pbs_error_desc) ? "\n" : "", stat.pbs_error_desc);
- }
-
- printf("\n");
-
- free(j1);
- free(j2);
- free(s);
-}
-
+++ /dev/null
-#include <getopt.h>
-#include <stdsoap2.h>
-
-#include "glite/lb/consumer.h"
-
-#include "soap_version.h"
-#include "glite/security/glite_gsplugin.h"
-#include "glite/security/glite_gscompat.h"
-
-#include "bk_ws_H.h"
-#include "ws_fault.h"
-#include "ws_typeref.h"
-
-#if GSOAP_VERSION <= 20602
-#define soap_call___lb__QueryJobs soap_call___ns1__QueryJobs
-#endif
-
-#include "LoggingAndBookkeeping.nsmap"
-
-
-static struct option opts[] = {
- {"help", 0, NULL, 'h'},
- {"server", 1, NULL, 'm'}
-};
-
-static void usage(char *me)
-{
- fprintf(stderr,"usage: %s [option]\n"
- "\t-h, --help Shows this screen.\n"
- "\t-m, --server BK server address:port.\n"
- , me);
-}
-
-static void printstat(edg_wll_JobStat stat, int level);
-
-int main(int argc,char** argv)
-{
- edg_wll_Context ctx;
- glite_gsplugin_Context gsplugin_ctx;
- edg_wll_QueryRec **conditions = NULL;
- struct soap *soap = soap_new();
- struct _lbe__QueryJobs *qjobs = NULL;
- struct _lbe__QueryJobsResponse out;
- int opt, err;
- char *server = "http://localhost:9003/",
- *name = NULL;
- int i;
-
- name = strrchr(argv[0],'/');
- if (name) name++; else name = argv[0];
-
- while ((opt = getopt_long(argc, argv, "hm:", opts, NULL)) != EOF) switch (opt)
- {
- case 'h': usage(name); return 0;
- case 'm': server = optarg; break;
- case '?': usage(name); return 1;
- }
-
- edg_wll_InitContext(&ctx);
- glite_gsplugin_init_context(&gsplugin_ctx);
- soap_set_namespaces(soap, namespaces);
- if ( soap_register_plugin_arg(soap, glite_gsplugin, (void *)gsplugin_ctx) )
- {
- soap_print_fault(soap, stderr);
- return 1;
- }
-
- glite_gsplugin_set_udata(soap, ctx);
-
- conditions = (edg_wll_QueryRec **)calloc(3,sizeof(edg_wll_QueryRec *));
-
- conditions[0] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec));
- conditions[0][0].attr = EDG_WLL_QUERY_ATTR_STATUS;
- conditions[0][0].op = EDG_WLL_QUERY_OP_UNEQUAL;
- conditions[0][0].value.i = EDG_WLL_JOB_DONE;
-
- conditions[1] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- conditions[1][0].attr = EDG_WLL_QUERY_ATTR_OWNER;
-#warning FIXME: NULL should work, use optional in WSDL?
-// conditions[1][0].op = EDG_WLL_QUERY_OP_EQUAL;
-// conditions[1][0].value.c = NULL;
- conditions[1][0].op = EDG_WLL_QUERY_OP_UNEQUAL;
- conditions[1][0].value.c = "x";
-
- qjobs = soap_malloc(soap, sizeof(*qjobs));
- memset(qjobs, 0, sizeof(*qjobs));
- qjobs->flags = soap_malloc(soap, sizeof(*qjobs->flags));
- memset(qjobs->flags, 0, sizeof(*qjobs->flags));
- if (!qjobs->flags || edg_wll_QueryCondsExtToSoap(soap, (const edg_wll_QueryRec **)conditions, &qjobs->__sizeconditions, &qjobs->conditions)
- || edg_wll_JobStatFlagsToSoap(soap, EDG_WLL_STAT_CLASSADS || EDG_WLL_STAT_CHILDREN || EDG_WLL_STAT_CHILDSTAT, qjobs->flags) ) {
- char *et,*ed;
-
- fprintf(stderr, "%s: soap types conversion error...\n", argv[0]);
- edg_wll_FaultToErr(soap, ctx);
- edg_wll_Error(ctx, &et, &ed);
- fprintf(stderr, "%s: %s (%s)\n", argv[0], et, ed);
- exit(1);
- }
-
- for (i = 0; conditions[i]; i++) free(conditions[i]);
- free(conditions);
-
- err = soap_call___lb__QueryJobs(soap, server, "", qjobs, &out);
- switch ( err ) {
- case SOAP_OK: {
- int i;
-
- printf("Query succesfull...\n");
- printf("%-65s%s\n\n", "jobid", "state");
- for ( i = 0; i < out.__sizejobs; i++ ) {
- edg_wll_JobStatCode statCode;
-
-
- edg_wll_SoapToJobStatCode(GLITE_SECURITY_GSOAP_LIST_GET(out.states, i)->state, &statCode);
- char *s = edg_wll_StatToString(statCode);
- printf("%-65s%s\n", out.jobs[i], s);
- free(s);
- }
- }
- break;
- case SOAP_FAULT:
- case SOAP_SVR_FAULT: {
- char *et,*ed;
-
- edg_wll_FaultToErr(soap, ctx);
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"%s: %s (%s)\n",argv[0],et,ed);
- exit(1);
- }
- default:
- fprintf(stderr,"err = %d\n",err);
- soap_print_fault(soap,stderr);
- }
-
- soap_end(soap);
- soap_done(soap);
- free(soap);
- glite_gsplugin_free_context(gsplugin_ctx);
- edg_wll_FreeContext(ctx);
-
- return 0;
-}
-
-static void printstat(edg_wll_JobStat stat, int level)
-{
- char *s, *j, ind[10];
- int i;
-
-
- for (i=0; i < level; i++)
- ind[i]='\t';
- ind[i]='\0';
-
- s = edg_wll_StatToString(stat.state);
-/* print whole flat structure */
- printf("%sstate : %s\n", ind, s);
- printf("%sjobId : %s\n", ind, j = edg_wlc_JobIdUnparse(stat.jobId));
- printf("%sowner : %s\n", ind, stat.owner);
- printf("%sjobtype : %s\n", ind, (stat.jobtype ? "DAG" : "SIMPLE") );
- printf("%sparent_job : %s\n", ind,
- j = edg_wlc_JobIdUnparse(stat.parent_job));
- if (stat.jobtype) {;
- printf("%sseed : %s\n", ind, stat.seed);
- printf("%schildren_num : %d\n", ind, stat.children_num);
- printf("%schildren :\n", ind);
- if (stat.children)
- for (i=0; stat.children[i]; i++)
- printf("%s\tchildren : %s\n", ind, stat.children[i]);
- printf("%schildren_states :\n", ind);
- if (stat.children_states)
- for (i=0; stat.children_states[i].state; i++)
- printstat(stat.children_states[i], level+1);
- printf("%schildren_hist :\n",ind);
- if (stat.children_hist)
- for (i=1; i<=stat.children_hist[0]; i++)
- printf("%s%14s %d\n", ind, edg_wll_StatToString(i-1),stat.children_hist[i]);
- }
- printf("%scondorId : %s\n", ind, stat.condorId);
- printf("%sglobusId : %s\n", ind, stat.globusId);
- printf("%slocalId : %s\n", ind, stat.localId);
- printf("%sjdl : %s\n", ind, stat.jdl);
- printf("%smatched_jdl : %s\n", ind, stat.matched_jdl);
- printf("%sdestination : %s\n", ind, stat.destination);
- printf("%snetwork server : %s\n", ind, stat.network_server);
- printf("%scondor_jdl : %s\n", ind, stat.condor_jdl);
- printf("%srsl : %s\n", ind, stat.rsl);
- printf("%sreason : %s\n", ind, stat.reason);
- printf("%slocation : %s\n", ind, stat.location);
- printf("%ssubjob_failed : %d\n", ind, stat.subjob_failed);
- printf("%sdone_code : %d\n", ind, stat.done_code);
- printf("%sexit_code : %d\n", ind, stat.exit_code);
- printf("%sresubmitted : %d\n", ind, stat.resubmitted);
- printf("%scancelling : %d\n", ind, stat.cancelling);
- printf("%scancelReason : %s\n", ind, stat.cancelReason);
- printf("%scpuTime : %d\n", ind, stat.cpuTime);
- printf("%suser_tags :\n",ind);
- if (stat.user_tags)
- for (i=0; stat.user_tags[i].tag; i++) printf("%s%14s = \"%s\"\n", ind,
- stat.user_tags[i].tag,stat.user_tags[i].value);
- printf("%sstateEnterTime : %ld.%06ld\n", ind, stat.stateEnterTime.tv_sec,stat.stateEnterTime.tv_usec);
- printf("%sstateEnterTimes : \n",ind);
- if (stat.stateEnterTimes)
- for (i=1; i<=stat.stateEnterTimes[0]; i++)
- printf("%s%14s %s", ind, edg_wll_StatToString(i-1), (stat.stateEnterTimes[i] == 0) ?
- " - not available -\n" : ctime((time_t *) &stat.stateEnterTimes[i]));
- printf("%slastUpdateTime : %ld.%06ld\n", ind, stat.lastUpdateTime.tv_sec,stat.lastUpdateTime.tv_usec);
- printf("%sexpectUpdate : %d\n", ind, stat.expectUpdate);
- printf("%sexpectFrom : %s\n", ind, stat.expectFrom);
- printf("%sacl : %s\n", ind, stat.acl);
- printf("\n");
-
- free(j);
- free(s);
-}
+++ /dev/null
-
-int edg_wll_QueryJobIndices(edg_wll_Context,edg_wll_QueryRec ***,char ***);
-int edg_wll_ColumnToQueryRec(const char *,edg_wll_QueryRec *);
-char * edg_wll_QueryRecToColumn(const edg_wll_QueryRec *);
-char * edg_wll_QueryRecToColumnExt(const edg_wll_QueryRec *);
-
-int edg_wll_ParseIndexConfig(edg_wll_Context,const char *,edg_wll_QueryRec ***);
-int edg_wll_DumpIndexConfig(edg_wll_Context,const char *,edg_wll_QueryRec * const *);
-
-int edg_wll_CmpColumn(const edg_wll_QueryRec *,const edg_wll_QueryRec *);
-
-typedef struct _edg_wll_IColumnRec {
- edg_wll_QueryRec qrec;
- char * colname;
-} edg_wll_IColumnRec;
-
-void edg_wll_FreeIColumnRec(edg_wll_IColumnRec *);
-
-int yylex();
-
-extern int lex_int;
-extern char *lex_out;
-extern int lex_line;
-
-#define STD_PREFIX "STD_"
-#define USR_PREFIX "USR_"
-#define TIME_PREFIX "TIME_"
+++ /dev/null
-<?xml version="1.0"?>
-<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd">
-
-<!-- $Header$ -->
-
-<xs:schema
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:a="http://egee.cesnet.cz/en/Schema/LB/Attributes"
- targetNamespace="http://egee.cesnet.cz/en/Schema/LB/Attributes"
- version="1.0"
- elementFormDefault="qualified"
- attributeFormDefault="unqualified"
->
- <xs:simpleType name="statusType">
- <xs:restriction base="xs:string">
- <xs:enumeration value="SUBMITTED" />
- <xs:enumeration value="WAITING" />
- <xs:enumeration value="READY" />
- <xs:enumeration value="SCHEDULED" />
- <xs:enumeration value="RUNNING" />
- <xs:enumeration value="DONE" />
- <xs:enumeration value="CLEARED" />
- <xs:enumeration value="ABORTED" />
- <xs:enumeration value="CANCELLED" />
- <xs:enumeration value="UNKNOWN" />
- </xs:restriction>
- </xs:simpleType>
-
- <xs:simpleType name="doneType">
- <xs:restriction base="xs:string">
- <xs:enumeration value="OK"/>
- <xs:enumeration value="FAIL"/>
- <xs:enumeration value="CANCEL"/>
- </xs:restriction>
- </xs:simpleType>
-
- <xs:complexType name="historyStatusType">
- <xs:complexContent>
- <xs:restriction base="xs:anyType">
- <xs:attribute name="name" type="a:statusType" use="required"/>
- <xs:attribute name="timestamp" type="xs:dateTime" use="required"/>
- <xs:attribute name="reason" type="xs:string" use="optional"/>
- </xs:restriction>
- </xs:complexContent>
- </xs:complexType>
-
- <xs:simpleType name="jobTypeType">
- <xs:restriction base="xs:string">
- <xs:enumeration value="SIMPLE"/>
- <xs:enumeration value="DAG"/>
- </xs:restriction>
- </xs:simpleType>
-
- <xs:complexType name="statusSequenceType">
- <xs:sequence>
- <xs:element name="status" type="a:historyStatusType" minOccurs="0" maxOccurs="unbounded"/>
- </xs:sequence>
- </xs:complexType>
-
- <xs:complexType name="jobIdSequenceType">
- <xs:sequence>
- <xs:element name="jobId" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
- </xs:sequence>
- </xs:complexType>
-
-
-
- <xs:element name="jobId" type="xs:string" />
-
- <xs:element name="user" type="xs:string">
- <xs:annotation> <xs:documentation>Job owner according to LB</xs:documentation> </xs:annotation>
- </xs:element>
-
- <!-- Parent jobId of DAG -->
- <xs:element name="parent" type="xs:string" />
-
- <!-- the following 6 elements have to be retrieved from JDL -->
- <xs:element name="VO" type="xs:string" />
- <xs:element name="aTag" type="xs:string" />
- <xs:element name="rQType" type="xs:string" />
- <xs:element name="eDuration" type="xs:duration" />
- <xs:element name="eNodes" type="xs:int" />
- <xs:element name="eProc" type="xs:int" />
-
- <xs:element name="RB" type="xs:string" />
- <xs:element name="CE" type="xs:string" />
- <xs:element name="host" type="xs:string" /> <!-- worker node -->
-
- <!-- Genevieve's spec has "site" and "country" here, but I've got no idea how to retrieve them -->
- <xs:element name="UIHost" type="xs:string" />
-
- <!-- not mandatory, currently LB hasn't got the info -->
- <xs:element name="CPUTime" type="xs:duration" />
- <xs:element name="NProc" type="xs:int" />
-
- <!-- In LB the real final status is Cleared
- However, Done, Aborted, or Cancelled should be reported here -->
- <xs:element name="finalStatus" type="a:statusType" />
- <xs:element name="finalStatusDate" type="xs:dateTime" />
- <xs:element name="finalStatusReason" type="xs:string" />
- <xs:element name="LRMSDoneStatus" type="a:doneType" />
- <xs:element name="LRMSStatusReason" type="xs:string" />
-
- <xs:element name="retryCount" type="xs:int" />
- <xs:element name="additionalReason" type="xs:string" />
-
- <xs:element name="jobType" type="a:jobTypeType" />
- <xs:element name="nsubjobs" type="xs:int" />
- <xs:element name="subjobs" type="a:jobIdSequenceType" />
-
- <!-- timestamps of the state history of the last resubmission cycle,
- i.e. it is guaranteed that each state apears here only once.
- Cf. stateEnterTimes in LB JobStatus -->
- <xs:element name="lastStatusHistory" type="a:statusSequenceType" />
-
- <!-- timestamps of the whole state history, including all resubmission cycles -->
- <xs:element name="fullStatusHistory" type="a:statusSequenceType" />
-
- <xs:element name="JDL" type="xs:string" />
-
-<!-- No idea where to get these from:
-
- ENVIRONMENT
-
- testbed production, preproduction, specific
- release middleware release (LCG, g-lite...)
- version version of middleware
- job_history_version in case of structure changes
--->
-
-</xs:schema>
+++ /dev/null
-<?xml version="1.0"?>
-<!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSCHEMA 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd">
-
-<!-- $Header$ -->
-
-<xs:schema
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
- xmlns:jr="http://egee.cesnet.cz/en/Schema/LB/JobRecord"
- xmlns:a="http://egee.cesnet.cz/en/Schema/LB/Attributes"
- targetNamespace="http://egee.cesnet.cz/en/Schema/LB/JobRecord"
- version="1.0"
- elementFormDefault="qualified"
- attributeFormDefault="unqualified"
->
-
- <xs:import
- namespace="http://egee.cesnet.cz/en/Schema/LB/Attributes"
- schemaLocation="http://egee.cesnet.cz/en/Schema/LB/Attributes"
- />
-
- <xs:complexType name="jobRecordType">
- <xs:sequence>
-
- <xs:element ref="a:jobId" minOccurs="1" maxOccurs="1"/>
- <xs:element ref="a:user" minOccurs="1" maxOccurs="1"/>
- <xs:element ref="a:parent" minOccurs="0" maxOccurs="1"/>
-
- <!-- the following 6 elements have to be retrieved from JDL -->
- <xs:element ref="a:VO" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:aTag" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:rQType" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:eDuration" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:eNodes" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:eProc" minOccurs="0" maxOccurs="1"/>
-
- <xs:element ref="a:RB" minOccurs="1" maxOccurs="1"/>
- <xs:element ref="a:CE" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:host" minOccurs="0" maxOccurs="1"/> <!-- worker node -->
-
- <!-- Genevieve's spec has "site" and "country" here, but I've got no idea how to retrieve them -->
- <xs:element ref="a:UIHost" minOccurs="0" maxOccurs="1"/>
-
- <!-- not mandatory, currently LB hasn't got the info -->
- <xs:element ref="a:CPUTime" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:NProc" minOccurs="0" maxOccurs="1"/>
-
- <!-- In LB the real final status is Cleared
- However, Done, Aborted, or Cancelled should be reported here -->
- <xs:element ref="a:finalStatus" minOccurs="1" maxOccurs="1"/>
- <xs:element ref="a:finalStatusDate" minOccurs="1" maxOccurs="1"/>
- <xs:element ref="a:finalStatusReason" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:LRMSDoneStatus" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:LRMSStatusReason" minOccurs="0" maxOccurs="1"/>
-
- <xs:element ref="a:retryCount" minOccurs="1" maxOccurs="1"/>
- <xs:element ref="a:additionalReason" minOccurs="0" maxOccurs="1"/>
-
- <xs:element ref="a:jobType" minOccurs="1" maxOccurs="1"/>
- <xs:element ref="a:nsubjobs" minOccurs="0" maxOccurs="1"/>
- <xs:element ref="a:subjobs" minOccurs="0" maxOccurs="1"/>
-
- <!-- timestamps of the state history of the last resubmission cycle,
- i.e. it is guaranteed that each state apears here only once.
- Cf. stateEnterTimes in LB JobStatus -->
-
- <xs:element ref="a:lastStatusHistory" minOccurs="1" maxOccurs="1"/>
-
- <!-- timestamps of the whole state history, including all resubmission cycles -->
- <xs:element ref="a:fullStatusHistory" minOccurs="1" maxOccurs="1"/>
-
- <xs:element ref="a:JDL" minOccurs="0" maxOccurs="1"/>
- </xs:sequence>
-
- <!-- No idea where to get these from:
-
- ENVIRONMENT
-
- testbed production, preproduction, specific
- release middleware release (LCG, g-lite...)
- version version of middleware
- job_history_version in case of structure changes
- -->
-
- <xs:attribute name="jobid" type="xs:string" use="required"/>
- </xs:complexType>
-
-
- <xs:element name="jobRecord" type="jr:jobRecordType"/>
-
-</xs:schema>
+++ /dev/null
-#ifndef LB_AUTHZ_H
-#define LB_AUTHZ_H
-
-#ifndef NO_GACL
-#include <gridsite.h>
-#endif
-
-typedef struct _edg_wll_Acl {
-#ifndef NO_GACL
- GRSTgaclAcl *value;
-#else
- void *value; /* XXX */
-#endif
- char *string;
-} _edg_wll_Acl;
-typedef struct _edg_wll_Acl *edg_wll_Acl;
-
-# ifndef NO_GACL
-
-extern int
-edg_wll_DecodeACL(char *, GRSTgaclAcl **);
-
-extern int
-edg_wll_EncodeACL(GRSTgaclAcl *, char **);
-
-#else
-
-extern int
-edg_wll_DecodeACL(char *, void **);
-
-extern int
-edg_wll_EncodeACL(void *, char **);
-
-#endif /* NO_GACL */
-
-/* we have NO_VOMS||NO_GACL placeholders for following routines */
-
-extern int
-edg_wll_InitAcl(edg_wll_Acl *);
-
-extern void
-edg_wll_FreeAcl(edg_wll_Acl);
-
-extern int
-edg_wll_UpdateACL(edg_wll_Context, edg_wlc_JobId, char *, int, int, int, int);
-
-extern int
-edg_wll_CheckACL(edg_wll_Context, edg_wll_Acl, int);
-
-extern int
-edg_wll_GetACL(edg_wll_Context, edg_wlc_JobId, edg_wll_Acl *);
-
-extern int
-edg_wll_SetVomsGroups(edg_wll_Context, edg_wll_GssConnection *, char *, char *, char *, char *);
-
-extern void
-edg_wll_FreeVomsGroups(edg_wll_VomsGroups *);
-
-#endif
+++ /dev/null
-#ifndef _LBS_DB_H
-#define _LBS_DB_H
-
-#ident "$Header$"
-
-#include <sys/types.h>
-#include <sys/time.h>
-
-#include "glite/lb/consumer.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define EDG_WLL_MYSQL_VERSION 40001
-#define BUF_INSERT_ROW_ALLOC_BLOCK 1000
-
-
-typedef struct _edg_wll_Stmt *edg_wll_Stmt;
-
-edg_wll_ErrorCode edg_wll_DBConnect(
- edg_wll_Context, /* INOUT: */
- const char * /* IN: connect string user/password@host:database */
-);
-
-
-/*
- * structure holds date for multi-rows insert
- */
-typedef struct _edg_wll_bufInsert {
- edg_wll_Context ctx;
- char *table_name;
- char *columns; /* names of columns to be inserted into
- * (values separated with commas) */
- char **rows; /* each row hold string of one row to be inserted
- * (values separated with commas) */
- long rec_num, /* actual number of rows in structure */
- rec_size; /* approx. size of a real insert string */
- long size_limit, /* size and # of records limit which trigger */
- record_limit; /* real insert; zero means unlimitted */
-} edg_wll_bufInsert;
-
-
-void edg_wll_DBClose(edg_wll_Context);
-
-
-/* Parse and execute SQL statement. Returns number of rows selected, created
- * or affected by update, or -1 on error */
-
-int edg_wll_ExecStmt(
- edg_wll_Context, /* INOUT: */
- char *, /* IN: SQL statement */
- edg_wll_Stmt * /* OUT: statement handle. Usable for select only */
-);
-
-
-/* Fetch next row of select statement.
- * All columns are returned as fresh allocated strings
- *
- * return values:
- * >0 - number of fields of the retrieved row
- * 0 - no more rows
- * -1 - error
- *
- * Errors are stored in context passed to previous edg_wll_ExecStmt() */
-
-int edg_wll_FetchRow(
- edg_wll_Stmt, /* IN: statement */
- char ** /* OUT: array of fetched values.
- * As number of columns is fixed and known,
- * expects allocated array of pointers here */
-);
-
-/* Retrieve column names of a query statement */
-
-int edg_wll_QueryColumns(
- edg_wll_Stmt, /* IN: statement */
- char ** /* OUT: result set column names. Expects allocated array. */
-);
-
-/* Free the statement structure */
-
-void edg_wll_FreeStmt(
- edg_wll_Stmt * /* INOUT: statement */
-);
-
-
-/**
- * convert time_t into database-specific time string
- *
- * returns pointer to dynamic area which should be freed
- */
-char *edg_wll_TimeToDB(time_t);
-time_t edg_wll_DBToTime(char *);
-
-extern edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs);
-
-/**
- * Check database version.
- */
-int edg_wll_DBCheckVersion(edg_wll_Context, const char *);
-
-int edg_wll_Transaction(edg_wll_Context ctx);
-int edg_wll_Commit(edg_wll_Context ctx);
-int edg_wll_Rollback(edg_wll_Context ctx);
-
-/**
- * Init data structure for buffered insert
- *
- * takes table_name and columns string for future multirow insert
- * when insert string oversize size_limit or number of rows to be inserted
- * overcome record_limit, the real insert is triggered
- */
-edg_wll_ErrorCode edg_wll_bufferedInsertInit(edg_wll_Context ctx, edg_wll_bufInsert *bi, void *mysql, char *table_name, long size_limit, long record_limit, char * columns);
-
-/**
- * adds row of n values into n columns into an insert buffer
- * if num. of rows or size of data oversteps the limits, real
- * multi-row insert is done
- */
-edg_wll_ErrorCode edg_wll_bufferedInsert(edg_wll_bufInsert *bi, char *row);
-
-/**
- * flush buffered data and free bi structure
- */
-edg_wll_ErrorCode edg_wll_bufferedInsertClose(edg_wll_bufInsert *bi);
-
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-enum lb_srv_perf_sink {
- GLITE_LB_SINK_NONE = 0, // standard behaviour, no sinking
-
- GLITE_LB_SINK_PARSE, // skip everything, only read message and
- // generate reply
- // skips decode_il_msg, db_store
-
- GLITE_LB_SINK_STORE, // do no store data to DB, only decode_il_msg
- // and edg_wll_ParseEvent
- // skips edg_wll_LockJob, edg_wll_StoreEvent
- // edg_wll_UpdateACL, edg_wll_StepIntState,
- // edg_wll_EventSendProxy, edg_wll_NotifMatch
-
- GLITE_LB_SINK_STATE, // do not perform state computation, only save
- // event to DB
- // skips edg_wll_StepIntState
- // edg_wll_EventSendProxy, edg_wll_NotifMatch
-
- GLITE_LB_SINK_SEND,
-};
-
-
-extern enum lb_srv_perf_sink sink_mode;
+++ /dev/null
-#ifndef _LBS_STORE_H
-#define _LBS_STORE_H
-
-#ident "$Header$"
-
-#include "glite/lb/consumer.h"
-#include "jobstat.h"
-#include "lb_authz.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* store an event into the LB database */
-
-int edg_wll_StoreEvent(
- edg_wll_Context, /* INOUT */
- edg_wll_Event *, /* IN */
- int *
-);
-
-void edg_wll_StoreAnonymous(
- edg_wll_Context, /* INOUT */
- int /* IN (boolean) */
-);
-
-/* update stored job state according to new event */
-
-edg_wll_ErrorCode edg_wll_StepIntState(
- edg_wll_Context, /* INOUT */
- edg_wlc_JobId, /* IN */
- edg_wll_Event *, /* IN */
- int, /* IN */
- edg_wll_JobStat *
-);
-
-/* create embriotic job state for DAGs' subjob */
-
-edg_wll_ErrorCode edg_wll_StepIntStateEmbriotic(
- edg_wll_Context ctx, /* INOUT */
- edg_wll_Event *e /* IN */
-);
-
-int db_store(edg_wll_Context,char *, char *);
-int db_parent_store(edg_wll_Context, edg_wll_Event *, intJobStat *);
-int handle_request(edg_wll_Context,char *);
-int create_reply(const edg_wll_Context,char **);
-int trans_db_store(edg_wll_Context,char *,edg_wll_Event *,intJobStat *);
-
-
-int edg_wll_delete_event(edg_wll_Context,const char *, int);
-
-
-#define USER_UNKNOWN "unknown"
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-MultiStruct.pm
-StructField.pm
-at3
-events.T
-status.T
-types.T
+++ /dev/null
-#Fri Aug 18 12:32:02 CEST 2006
-module.build=0245
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- Copyright (c) 2004 on behalf of the EU EGEE Project:
- The European Organization for Nuclear Research (CERN),
- Istituto Nazionale di Fisica Nucleare (INFN), Italy
- Datamat Spa, Italy
- Centre National de la Recherche Scientifique (CNRS), France
- CS Systeme d'Information (CSSI), France
- Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
- Universiteit van Amsterdam (UvA), Netherlands
- University of Helsinki (UH.HIP), Finland
- University of Bergen (UiB), Norway
- Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
-
- Configuration options for the GLite LB Client module
-
- Authors: Ales Krenek <ljocha@ics.muni.cz>
- Version info: $Id$
- Release: $Name$
-
- Revision history:
- $Log$
- Revision 1.11 2006/03/17 11:47:02 zsalvet
- Adapt RGMA export file format and file handling to lcg-mon-job-status
- use. Socket notification code is still available and is nonblocking now.
- C ClassAd API is used to retrieve VO from JDL.
-
- Revision 1.10 2006/03/15 18:13:51 akrenek
- cares
-
- Revision 1.9 2006/03/15 18:12:21 akrenek
- merge 1.5
-
- Revision 1.8.4.2 2006/02/20 09:14:30 zsalvet
- Revert unfinished changes committed by mistake.
-
- Revision 1.8 2005/09/19 15:24:20 akrenek
- "The gigantic merge"; from release 1.4 branch to HEAD
-
- Revision 1.7.2.1 2005/08/09 15:02:10 jskrabal
- - build with broken gsoap 2.7.0 repository package
-
- Revision 1.7 2005/08/03 09:30:28 akrenek
- Merged the release 1.0 branch
-
- Revision 1.6 2005/01/21 11:27:44 jpospi
- completely remove gridsite.prefix and voms.prefix
-
- Revision 1.5 2005/01/20 11:43:00 jpospi
- handle correctly gridsite_prefix and voms_prefix
-
- Revision 1.4.2.1 2005/05/19 13:41:22 akrenek
- fix build with mysql 4.1.x
-
- Revision 1.4 2004/10/15 11:03:03 jskrabal
- - merge fixes
-
- Revision 1.3 2004/10/06 08:14:36 dkouril
- Support for VOMS and GACL (gridsite) from SCM CVS
- - legacy names of GACL routines changed to new ones, which also prevents from
- conflicts with a few older routine names being badly redefined to new ones
- - VOMS and GACL are still commented out in the Makefile until a correct way
- of defining dependencies is negotiated.
-
- Revision 1.2.2.1 2004/09/21 07:39:45 akrenek
-
- - First version of BK server using "server bones" library and WS protocol.
- - Under hard development - unstable & buggy
-
- Revision 1.2 2004/09/08 13:38:03 akrenek
- query event unit test (not complete yet)
-
- Revision 1.1 2004/07/07 12:08:09 akrenek
- *** empty log message ***
-
- Revision 1.2 2004/07/06 20:47:11 flammer
- Moved to configure.properties.xml
-
-
--->
-
- <!-- ======================================================
- Define extra properties here ...
- ====================================================== -->
-
- <project name="LB Client configuration options">
- <target name="lbmakefiles">
- <exec executable="ln" failonerror="true">
- <arg line="-fs ${component.dir}/Makefile ${module.build.dir}/Makefile"/>
- </exec>
- <echo file="${module.build.dir}/Makefile.inc">
-top_srcdir=..
-builddir=build
-stagedir=${stage.abs.dir}
-distdir=${dist.dir}
-globalprefix=${global.prefix}
-lbprefix=${subsystem.prefix}
-package=${module.package.name}
-PREFIX=${install.dir}
-version=${module.version}
-glite_location=${with.glite.location}
-globus_prefix=${with.globus.prefix}
-expat_prefix=${with.expat.prefix}
-cares_prefix=${with.c-ares.prefix}
-mysql_prefix=${with.mysql.prefix}
-mysql_version=${ext.mysql.version}
-cppunit_prefix=${with.cppunit.prefix}
-gsoap_prefix=${with.gsoap.prefix}
-gsoap_version=${ext.gsoap.version}
-classads_prefix=${with.classads.prefix}
-thrflavour=${with.globus.thr.flavor}
-nothrflavour=${with.globus.nothr.flavor}
- </echo>
- </target>
- </project>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2004 on behalf of the EU EGEE Project:
- The European Organization for Nuclear Research (CERN),
- Istituto Nazionale di Fisica Nucleare (INFN), Italy
- Datamat Spa, Italy
- Centre National de la Recherche Scientifique (CNRS), France
- CS Systeme d'Information (CSSI), France
- Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
- Universiteit van Amsterdam (UvA), Netherlands
- University of Helsinki (UH.HIP), Finland
- University of Bergen (UiB), Norway
- Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
-
- Common build properties file for the Glite LB Server component
-
- Authors: Ales Krenek <ljocha@ics.muni.cz>
- Version info: $Id$
- Release: $Name$
-
- Revision history:
- $Log$
--->
-
-<project name="LB Server component common properties">
-
- <!-- Include build properties to allow overwriting
- of properties for subsystem -->
- <property file="build.properties" />
-
- <!-- ======================================================
- Define corresponding subsystem properties
- ====================================================== -->
-
- <!-- Subsystem name -->
- <property name="subsystem.name" value="${lb.subsystem.name}"/>
-
- <!-- Subsystem prefix -->
- <property name="subsystem.prefix" value="${lb.subsystem.prefix}"/>
-
- <!-- ======================================================
- Define component properties
- ====================================================== -->
-
- <!-- Component name prefix -->
- <property name="component.prefix" value="server" />
-
- <!-- ======================================================
- Define general component properties
- ====================================================== -->
-
- <import file="${component.general.properties.file}" />
-
- <!-- ======================================================
- Define extra properties here ...
- ====================================================== -->
-
-
-</project>
\ No newline at end of file
+++ /dev/null
-tar_exclude
-CVS
-build.xml
-build
-build.properties
-properties.xml
-configure-options.xml
-.cvsignore
-.project
-.cdtproject
+++ /dev/null
-# $Header$
-module.version=1.6.2
-module.age=1
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <sysexits.h>
-#include <assert.h>
-
-#include "glite/wmsutils/jobid/strmd5.h"
-#include "glite/lb/consumer.h"
-#include "glite/lb/context-int.h"
-#include "index.h"
-#include "lbs_db.h"
-#include "jobstat.h"
-
-#ifdef LB_PERF
-#include "glite/lb/lb_perftest.h"
-#include "glite/lb/srv_perf.h"
-
-enum lb_srv_perf_sink sink_mode;
-#endif
-
-
-static struct option opts[] = {
- { "mysql",1,NULL,'m' },
- { "remove",0,NULL,'R' },
- { "really",0,NULL,'r' },
- { "dump",0,NULL,'d' },
- { "verbose",0,NULL,'v' },
- { NULL, 0, NULL, 0 }
-};
-
-static void usage(const char *);
-static void do_exit(edg_wll_Context,int);
-static char *col_list(const edg_wll_QueryRec *);
-static char *db_col_type(const edg_wll_QueryRec *);
-
-/* XXX: don't bother with malloc() of arrays that are tiny in real life */
-#define CI_MAX 200
-
-int debug;
-
-int main(int argc,char **argv)
-{
- int opt;
- char *dbstring = getenv("LBDB");
- char *fname = "-";
- int dump = 0, really = 0, verbose = 0, remove_all = 0;
- edg_wll_Context ctx;
- edg_wll_QueryRec **old_indices,**new_indices;
- edg_wll_QueryRec *new_columns[CI_MAX],*old_columns[CI_MAX];
- int add_columns[CI_MAX],drop_columns[CI_MAX];
- int add_indices[CI_MAX],drop_indices[CI_MAX];
- edg_wll_IColumnRec *added_icols;
- int nadd_icols;
- char **index_names;
- int i,j,k;
- int nnew,nold,nadd,ndrop;
- char *stmt;
-
- for (i=0; i<CI_MAX; i++) add_indices[i] = drop_indices[i] = -1;
- memset(new_columns,0,sizeof new_columns);
- memset(old_columns,0,sizeof old_columns);
- memset(add_columns,0,sizeof add_columns);
- memset(drop_columns,0,sizeof drop_columns);
-
- while ((opt = getopt_long(argc,argv,"m:rRdv",opts,NULL)) != EOF) switch (opt) {
- case 'm': dbstring = optarg; break;
- case 'r': really = 1; break;
- case 'R': remove_all = 1; break;
- case 'd': dump = 1; break;
- case 'v': verbose++; break;
- case '?': usage(argv[0]); exit(EX_USAGE);
- }
-
- if (really && dump) { usage(argv[0]); exit(EX_USAGE); }
- if (really && remove_all) { usage(argv[0]); exit(EX_USAGE); }
- if (optind < argc) {
- if (dump || remove_all) { usage(argv[0]); exit(EX_USAGE); }
- else fname = argv[optind];
- }
-
- edg_wll_InitContext(&ctx);
- if (edg_wll_Open(ctx,dbstring)) do_exit(ctx,EX_UNAVAILABLE);
- if (edg_wll_DBCheckVersion(ctx,dbstring)) do_exit(ctx,EX_SOFTWARE);
- if (edg_wll_QueryJobIndices(ctx,&old_indices,&index_names)) do_exit(ctx,EX_SOFTWARE);
-
- if (dump) {
- if (edg_wll_DumpIndexConfig(ctx,fname,old_indices)) do_exit(ctx,EX_SOFTWARE);
- else if ( !remove_all ) return 0;
- }
-
- if (remove_all) {
- if (verbose) printf("Dropping all indices");
- for (i=0; index_names && index_names[i]; i++) {
- asprintf(&stmt,"alter table states drop index `%s`",index_names[i]);
- if (verbose) putchar('.');
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
- free(stmt);
- }
- if (verbose) puts(" done");
- if (verbose) printf("Dropping index columns");
- for (i=0; old_indices && old_indices[i]; i++) {
- char *cname = edg_wll_QueryRecToColumn(old_indices[i]);
- asprintf(&stmt,"alter table states drop column `%s`",cname);
- if (verbose) putchar('.');
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
- free(stmt);
- free(cname);
- }
- if (verbose) puts(" done");
- return 0;
- }
-
- if (edg_wll_ParseIndexConfig(ctx,fname,&new_indices))
- do_exit(ctx,edg_wll_Error(ctx,NULL,NULL) == EINVAL ? EX_DATAERR : EX_IOERR);
-
- /* FIXME: check duplicate columns in indices */
-
-/* indices to add & drop */
- nadd = ndrop = 0;
- if (old_indices && new_indices) {
- for (i=0; old_indices[i]; i++) {
- for (j=0; new_indices[j]; j++) {
- for (k=0; old_indices[i][k].attr &&
- !edg_wll_CmpColumn(&old_indices[i][k],&new_indices[j][k]);
- k++);
- if (!old_indices[i][k].attr && !new_indices[j][k].attr) break;
- }
- if (!new_indices[j]) drop_indices[ndrop++] = i;
- }
-
- for (i=0; new_indices[i]; i++) {
- for (j=0; old_indices[j]; j++) {
- for (k=0; new_indices[i][k].attr &&
- !edg_wll_CmpColumn(&new_indices[i][k],&old_indices[j][k]);
- k++);
- if (!new_indices[i][k].attr && !old_indices[j][k].attr) break;
- }
- if (!old_indices[j]) add_indices[nadd++] = i;
- }
- }
- else if (new_indices) for (i=0; new_indices[i]; i++) add_indices[i] = i;
- else if (old_indices) for (i=0; old_indices[i]; i++) drop_indices[i] = i;
-
-/* old and new column sets */
- nold = nnew = 0;
- if (old_indices) for (i=0; old_indices[i]; i++)
- for (j=0; old_indices[i][j].attr; j++) {
- for (k=0; k<nold && edg_wll_CmpColumn(old_columns[k],&old_indices[i][j]); k++);
- if (k == nold) {
- assert(nold < CI_MAX);
- old_columns[nold++] = &old_indices[i][j];
- }
- }
-
- if (new_indices) for (i=0; new_indices[i]; i++)
- for (j=0; new_indices[i][j].attr; j++) {
- for (k=0; k<nnew && edg_wll_CmpColumn(new_columns[k],&new_indices[i][j]); k++);
- if (k == nnew) {
- assert(nnew < CI_MAX);
- new_columns[nnew++] = &new_indices[i][j];
- }
- }
-
-/* go! */
- if (!really) puts("\n** Dry run, no actual actions performed **\n");
-
- if (verbose) puts("Dropping indices ...");
- for (i=0; drop_indices[i] >= 0; i++) {
- if (verbose) {
- char *n = col_list(old_indices[drop_indices[i]]);
- printf("\t%s(%s) ... ",index_names[drop_indices[i]],n); fflush(stdout);
- free(n);
- }
- if (really) {
- asprintf(&stmt,"alter table states drop index `%s`",index_names[drop_indices[i]]);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
- free(stmt);
- }
- if (verbose) puts(really ? "done" : "");
- }
-
- if (verbose) puts("Dropping columns ...");
- for (i=0; i<nold; i++) {
- for (j=0; j<nnew && edg_wll_CmpColumn(old_columns[i],new_columns[j]); j++);
- if (j == nnew) {
- char *cname = edg_wll_QueryRecToColumn(old_columns[i]);
- if (verbose) printf("\t%s\n",cname);
- if (really) {
- asprintf(&stmt,"alter table states drop column `%s`",cname);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
- free(stmt);
- }
- free(cname);
- }
- }
-
- added_icols = calloc(nnew+1, sizeof(edg_wll_IColumnRec));
- nadd_icols = 0;
- if (verbose) puts("Adding columns ...");
- for (i=0; i<nnew; i++) {
- for (j=0; j<nold && edg_wll_CmpColumn(new_columns[i],old_columns[j]); j++);
- if (j == nold) {
- char *cname = edg_wll_QueryRecToColumn(new_columns[i]);
- if (verbose) printf("\t%s\n",cname);
- if (really) {
- char *ctype = db_col_type(new_columns[i]);
- asprintf(&stmt,"alter table states add `%s` %s",cname,ctype);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
- free(stmt);
- }
- memcpy(&added_icols[nadd_icols].qrec, new_columns[i], sizeof(edg_wll_QueryRec));
- added_icols[nadd_icols].colname = strdup(cname);
- if (new_columns[i]->attr == EDG_WLL_QUERY_ATTR_USERTAG)
- added_icols[nadd_icols].qrec.attr_id.tag =
- strdup(new_columns[i]->attr_id.tag);
- nadd_icols++;
- free(cname);
- }
- }
-
- if (nadd_icols) {
- added_icols[nadd_icols].qrec.attr = EDG_WLL_QUERY_ATTR_UNDEF;
- added_icols[nadd_icols].colname = NULL;
- if (verbose) puts("Refreshing data ...");
- if (really && edg_wll_RefreshIColumns(ctx, (void*) added_icols)) do_exit(ctx,EX_SOFTWARE);
- }
- else if (verbose) puts("No data refresh required");
-
- for (nadd_icols--; nadd_icols >= 0; nadd_icols--)
- edg_wll_FreeIColumnRec(&added_icols[nadd_icols]);
- free(added_icols);
-
- if (verbose) puts("Creating indices ...");
- for (i=0; add_indices[i] >= 0; i++) {
- char *l = col_list(new_indices[add_indices[i]]);
- char *n = str2md5base64(l);
- if (verbose) { printf("\t%s(%s) ... ",n,l); fflush(stdout); }
- if (really) {
- asprintf(&stmt,"create index `%s` on states(%s)",n,l);
- free(n); free(l);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE);
- free(stmt);
- }
- if (verbose) puts(really ? "done" : "");
- }
-
- return 0;
-}
-
-static char *col_list(const edg_wll_QueryRec *ind)
-{
- char *ret,*aux,size[50] = "";
- int j;
-
- aux = edg_wll_QueryRecToColumn(ind);
- if (ind->value.i) sprintf(size,"(%d)",ind->value.i);
- asprintf(&ret,"`%s`%s",aux,size);
- free(aux);
-
- for (j=1; ind[j].attr; j++) {
- char *n = edg_wll_QueryRecToColumn(ind+j),size[50] = "";
- if (ind[j].value.i) sprintf(size,"(%d)",ind[j].value.i);
- aux = ret;
- asprintf(&ret,"%s,`%s`%s",aux,n,size);
- free(n); free(aux);
- }
- return ret;
-}
-
-static char *db_col_type(const edg_wll_QueryRec *r)
-{
- switch (r->attr) {
- case EDG_WLL_QUERY_ATTR_OWNER:
- case EDG_WLL_QUERY_ATTR_LOCATION:
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- case EDG_WLL_QUERY_ATTR_USERTAG:
- case EDG_WLL_QUERY_ATTR_HOST:
- case EDG_WLL_QUERY_ATTR_CHKPT_TAG:
- return "char(250) binary null";
-
- case EDG_WLL_QUERY_ATTR_TIME:
- return "datetime null";
- default:
- return NULL;
- }
-}
-
-static void do_exit(edg_wll_Context ctx,int code)
-{
- char *et,*ed;
-
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"edg-bkindex: %s (%s)\n",et,ed);
- exit(code);
-}
-
-static void usage(const char *me)
-{
- fprintf(stderr,"usage: %s <options> [file]\n"
- " -m,--mysql <dbstring> use non-default database connection\n"
- " -r,--really really perform reindexing\n"
- " -R,--remove remove all indexes from server\n"
- " -d,--dump dump current setup\n"
- " -v,--verbose increase verbosity (2 levels)\n"
- "\n -r and -d are mutually exlusive\n"
- "\n -r and -R are mutually exlusive\n"
- " [file] is applicable only without -d and -R\n",
- me);
-}
-
-/*
- * Set values of index columns in state table (after index reconfiguration)
- */
-
-edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context ctx, void *job_index_cols) {
-
- edg_wll_Stmt sh, sh2;
- int njobs, ret = -1;
- intJobStat *stat;
- edg_wlc_JobId jobid;
- char *res[5];
- char *rest;
- char *icvalues, *stmt;
- int i;
-
- edg_wll_ResetError(ctx);
- if (!job_index_cols) return 0;
-
- if ((njobs = edg_wll_ExecStmt(ctx, "select s.jobid,s.int_status,s.seq,s.version,j.dg_jobid"
- " from states s, jobs j where s.jobid=j.jobid",&sh)) < 0) {
- edg_wll_FreeStmt(&sh);
- return edg_wll_Error(ctx, NULL, NULL);
- }
- while ((ret=edg_wll_FetchRow(sh,res)) >0) {
- if (strcmp(res[3], INTSTAT_VERSION)) {
- stat = NULL;
- if (!edg_wlc_JobIdParse(res[4], &jobid)) {
- if ((stat = malloc(sizeof(intJobStat))) != NULL) {
- if (edg_wll_intJobStatus(ctx, jobid, 0, stat, 1)) {
- free(stat);
- stat = NULL;
- }
- }
- edg_wlc_JobIdFree(jobid);
- }
- } else {
- stat = dec_intJobStat(res[1], &rest);
- if (rest == NULL) stat = NULL;
- }
- if (stat == NULL) {
- edg_wll_FreeStmt(&sh);
- return edg_wll_SetError(ctx, EDG_WLL_ERROR_SERVER_RESPONSE,
- "cannot decode int_status from states DB table");
- }
-
- edg_wll_IColumnsSQLPart(ctx, job_index_cols, stat, 0, NULL, &icvalues);
- trio_asprintf(&stmt, "update states set seq=%s%s where jobid='%|Ss'", res[2], icvalues, res[0]);
- ret = edg_wll_ExecStmt(ctx, stmt, &sh2);
- edg_wll_FreeStmt(&sh2);
-
- for (i = 0; i < 5; i++) free(res[i]);
- destroy_intJobStat(stat); free(stat);
- free(stmt); free(icvalues);
-
- if (ret < 0) return edg_wll_Error(ctx, NULL, NULL);
-
- }
- edg_wll_FreeStmt(&sh);
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <getopt.h>
-#include <linux/limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/uio.h>
-#include <netinet/in.h>
-#include <signal.h>
-#include <errno.h>
-#include <netdb.h>
-#include <limits.h>
-#include <assert.h>
-#include <syslog.h>
-#include <sys/time.h>
-#include <arpa/inet.h>
-#include <arpa/nameser.h>
-#include <resolv.h>
-#include <ares.h>
-#include <sys/ipc.h>
-#include <sys/sem.h>
-
-#include <globus_common.h>
-
-#ifdef GLITE_LB_SERVER_WITH_WS
-#include "soap_version.h"
-#include <stdsoap2.h>
-#include "glite/security/glite_gsplugin.h"
-#endif /* GLITE_LB_SERVER_WITH_WS */
-
-#include "glite/security/glite_gss.h"
-#include "glite/lb/srvbones.h"
-#include "glite/lb/consumer.h"
-#include "glite/lb/purge.h"
-#include "glite/lb/context.h"
-#include "glite/lb/mini_http.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/lb_maildir.h"
-
-#ifdef LB_PERF
-#include "glite/lb/lb_perftest.h"
-#include "glite/lb/srv_perf.h"
-
-enum lb_srv_perf_sink sink_mode;
-#endif
-
-#include "lb_http.h"
-#include "lb_proto.h"
-#include "index.h"
-#include "lbs_db.h"
-#include "lb_authz.h"
-#include "il_notification.h"
-#include "stats.h"
-
-#ifdef GLITE_LB_SERVER_WITH_WS
-# if GSOAP_VERSION < 20700
- /* defined in <arpa/nameser.h> and it's includes
- * break the build
- */
-# undef STATUS
-# undef REFUSED
-# endif
-#include "LoggingAndBookkeeping.nsmap"
-#endif /* GLITE_LB_SERVER_WITH_WS */
-
-extern int edg_wll_StoreProto(edg_wll_Context ctx);
-extern edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs);
-extern edg_wll_ErrorCode edg_wll_Close(edg_wll_Context);
-
-#ifdef LB_PERF
-extern void _start (void), etext (void);
-#endif
-
-#define CON_QUEUE 20 /* accept() */
-#define SLAVE_OVERLOAD 10 /* queue items per slave */
-#define CONNECT_TIMEOUT 30
-#define IDLE_TIMEOUT 10 /* keep idle connection that many seconds */
-#define REQUEST_TIMEOUT 120 /* one client may ask one slave multiple times */
- /* but only limited time to avoid DoS attacks */
-#define DNS_TIMEOUT 5 /* how long wait for DNS lookup */
-#define SLAVE_CONNS_MAX 500 /* commit suicide after that many connections */
-
-#ifndef EDG_PURGE_STORAGE
-#define EDG_PURGE_STORAGE "/tmp/purge"
-#endif
-
-#ifndef EDG_DUMP_STORAGE
-#define EDG_DUMP_STORAGE "/tmp/dump"
-#endif
-
-#ifndef JPREG_DEF_DIR
-#define JPREG_DEF_DIR "/tmp/jpreg"
-#endif
-
-/* file to store pid and generate semaphores key */
-#ifndef EDG_BKSERVERD_PIDFILE
-#define EDG_BKSERVERD_PIDFILE "/var/run/edg-bkserverd.pid"
-#endif
-
-#ifndef dprintf
-#define dprintf(x) { if (debug) printf x; }
-#endif
-
-#define sizofa(a) (sizeof(a)/sizeof((a)[0]))
-
-
-int debug = 0;
-int rgma_export = 0;
-static const int one = 1;
-static int noAuth = 0;
-static int noIndex = 0;
-static int strict_locking = 0;
-static int greyjobs = 0;
-static int count_statistics = 0;
-static int hardJobsLimit = 0;
-static int hardEventsLimit = 0;
-static int hardRespSizeLimit = 0;
-static char *dbstring = NULL,*fake_host = NULL;
-int transactions = -1, use_transactions = -1;
-static int fake_port = 0;
-static char **super_users = NULL;
-static int slaves = 10,
- semaphores = -1,
- semset;
-static char *purgeStorage = EDG_PURGE_STORAGE;
-static char *dumpStorage = EDG_DUMP_STORAGE;
-static char *jpregDir = JPREG_DEF_DIR;
-static int jpreg = 0;
-static char *server_subject = NULL;
-
-
-static time_t purge_timeout[EDG_WLL_NUMBER_OF_STATCODES];
-static time_t notif_duration = 60*60*24*7;
-
-static gss_cred_id_t mycred = GSS_C_NO_CREDENTIAL;
-time_t cert_mtime = 0;
-char *cadir = NULL,
- *vomsdir = NULL,
- *server_key = NULL,
- *server_cert = NULL;
-
-
-static struct option opts[] = {
- {"cert", 1, NULL, 'c'},
- {"key", 1, NULL, 'k'},
- {"CAdir", 1, NULL, 'C'},
- {"VOMSdir", 1, NULL, 'V'},
- {"port", 1, NULL, 'p'},
-#ifdef GLITE_LB_SERVER_WITH_WS
- {"wsport", 1, NULL, 'w'},
-#endif /* GLITE_LB_SERVER_WITH_WS */
- {"address", 1, NULL, 'a'},
- {"debug", 0, NULL, 'd'},
- {"rgmaexport", 0, NULL, 'r'},
- {"mysql", 1, NULL, 'm'},
- {"noauth", 0, NULL, 'n'},
- {"slaves", 1, NULL, 's'},
- {"semaphores", 1, NULL, 'l'},
- {"pidfile", 1, NULL, 'i'},
- {"purge-prefix", 1, NULL, 'S'},
- {"dump-prefix", 1, NULL, 'D'},
- {"jpreg-dir", 1, NULL, 'J'},
- {"enable-jpreg-export", 1, NULL, 'j'},
- {"super-user", 1, NULL, 'R'},
- {"super-users-file", 1, NULL,'F'},
- {"no-index", 1, NULL, 'x'},
- {"strict-locking",0, NULL, 'P'},
- {"limits", 1, NULL, 'L'},
- {"notif-dur", 1, NULL, 'N'},
- {"notif-il-sock", 1, NULL, 'X'},
- {"notif-il-fprefix", 1, NULL, 'Y'},
- {"count-statistics", 1, NULL, 'T'},
- {"request-timeout", 1, NULL, 't'},
- {"silent", 0, NULL, 'z' },
-#ifdef LB_PERF
- {"perf-sink", 1, NULL, 'K'},
-#endif
- {"transactions", 1, NULL, 'b'},
- {"greyjobs", 0, NULL, 'g'},
- {NULL,0,NULL,0}
-};
-
-static const char *get_opt_string = "a:c:k:C:V:p:drm:ns:l:L:N:i:S:D:X:Y:T:t:J:jzb:g"
-#ifdef GLITE_LB_SERVER_WITH_WS
- "w:"
-#endif
-#ifdef LB_PERF
- "K:"
-#endif
-;
-
-static void usage(char *me)
-{
- fprintf(stderr,"usage: %s [option]\n"
- "\t-a, --address\t use this server address (may be faked for debugging)\n"
- "\t-b, --transactions\t transactions switch\n"
- "\t-k, --key\t private key file\n"
- "\t-c, --cert\t certificate file\n"
- "\t-C, --CAdir\t trusted certificates directory\n"
- "\t-V, --VOMSdir\t trusted VOMS servers certificates directory\n"
- "\t-p, --port\t port to listen\n"
-#ifdef GLITE_LB_SERVER_WITH_WS
- "\t-w, --wsport\t port to serve the web services requests\n"
-#endif /* GLITE_LB_SERVER_WITH_WS */
- "\t-m, --mysql\t database connect string\n"
- "\t-d, --debug\t don't run as daemon, additional diagnostics\n"
- "\t-r, --rgmaexport write state info to RGMA interface\n"
- "\t-n, --noauth\t don't check user identity with result owner\n"
- "\t-s, --slaves\t number of slave servers to fork\n"
- "\t-l, --semaphores number of semaphores (job locks) to use\n"
- "\t-i, --pidfile\t file to store master pid\n"
- "\t-L, --limits\t query limits numbers in format \"events_limit:jobs_limit:size_limit\"\n"
- "\t-N, --notif-dur\t Maximal duration of notification registrations in hours\n"
- "\t-S, --purge-prefix\t purge files full-path prefix\n"
- "\t-D, --dump-prefix\t dump files full-path prefix\n"
- "\t-J, --jpreg-dir\t JP registration temporary files prefix (implies '-j')\n"
- "\t-j, --enable-jpreg-export\t enable JP registration export (disabled by default)\n"
- "\t--super-user\t user allowed to bypass authorization and indexing\n"
- "\t--super-users-file\t the same but read the subjects from a file\n"
- "\t--no-index=1\t don't enforce indices for superusers\n"
- "\t =2\t don't enforce indices at all\n"
- "\t--strict-locking=1\t lock jobs also on storing events (may be slow)\n"
- "\t--notif-il-sock\t socket to send notifications\n"
- "\t--notif-il-fprefix\t file prefix for notifications\n"
- "\t--count-statistics=1\t count certain statistics on jobs\n"
- "\t =2\t ... and allow anonymous access\n"
- "\t-t, --request-timeout\t request timeout for one client\n"
- "\t--silent\t don't print diagnostic, even if -d is on\n"
-#ifdef LB_PERF
- "\t--perf-sink\t where to sink events\n"
-#endif
- "\t-g,--greyjobs\t allow delayed registration (grey jobs), implies --strict-locking\n"
-
- ,me);
-}
-
-static void wait_for_open(edg_wll_Context,const char *);
-static int decrement_timeout(struct timeval *, struct timeval, struct timeval);
-static int read_roots(const char *);
-static int asyn_gethostbyaddr(char **, const char *, int, int, struct timeval *);
-static int amIroot(const char *);
-static int parse_limits(char *, int *, int *, int *);
-static int check_mkdir(const char *);
-
-
-/*
- * SERVER BONES structures and handlers
- */
-int bk_clnt_data_init(void **);
-
- /*
- * Serve & Store handlers
- */
-int bk_clnt_reject(int);
-int bk_handle_connection(int, struct timeval *, void *);
-int bk_accept_serve(int, struct timeval *, void *);
-int bk_accept_store(int, struct timeval *, void *);
-int bk_clnt_disconnect(int, struct timeval *, void *);
-
-#ifdef GLITE_LB_SERVER_WITH_WS
- /*
- * WS handlers
- */
-int bk_handle_ws_connection(int, struct timeval *, void *);
-int bk_accept_ws(int, struct timeval *, void *);
-int bk_ws_clnt_reject(int);
-int bk_ws_clnt_disconnect(int, struct timeval *, void *);
-#endif /*GLITE_LB_SERVER_WITH_WS */
-
-#define SRV_SERVE 0
-#define SRV_STORE 1
-#ifdef GLITE_LB_SERVER_WITH_WS
-#define SRV_WS 2
-#endif /* GLITE_LB_SERVER_WITH_WS */
-static struct glite_srvbones_service service_table[] = {
- { "serve", -1, bk_handle_connection, bk_accept_serve, bk_clnt_reject, bk_clnt_disconnect },
- { "store", -1, bk_handle_connection, bk_accept_store, bk_clnt_reject, bk_clnt_disconnect },
-#ifdef GLITE_LB_SERVER_WITH_WS
- { "WS", -1, bk_handle_ws_connection, bk_accept_ws, bk_ws_clnt_reject, bk_ws_clnt_disconnect }
-#endif /* GLITE_LB_SERVER_WITH_WS */
-};
-
-struct clnt_data_t {
- edg_wll_Context ctx;
-#ifdef GLITE_LB_SERVER_WITH_WS
- struct soap *soap;
-#endif /* GLITE_LB_SERVER_WITH_WS */
- int use_transactions;
- void *mysql;
- edg_wll_QueryRec **job_index;
- edg_wll_IColumnRec *job_index_cols;
-};
-
-
-
-int main(int argc, char *argv[])
-{
- int fd, i;
- int dtablesize;
- struct sockaddr_in a;
- char *mysubj = NULL;
- int opt;
- char pidfile[PATH_MAX] = EDG_BKSERVERD_PIDFILE,
- *port,
- *name;
-#ifdef GLITE_LB_SERVER_WITH_WS
- char *ws_port;
-#endif /* GLITE_LB_SERVER_WITH_WS */
- FILE *fpid;
- key_t semkey;
- edg_wll_Context ctx;
- OM_uint32 min_stat;
- edg_wll_GssStatus gss_code;
- struct timeval to;
- int request_timeout = REQUEST_TIMEOUT;
- int silent = 0;
-
-
- /* keep this at start of main() ! */
- dtablesize = getdtablesize();
- for (fd=3; fd < dtablesize ; fd++) close(fd);
-
- name = strrchr(argv[0],'/');
- if (name) name++; else name = argv[0];
-
- asprintf(&port, "%d", GLITE_WMSC_JOBID_DEFAULT_PORT);
-#ifdef GLITE_LB_SERVER_WITH_WS
- asprintf(&ws_port, "%d", GLITE_WMSC_JOBID_DEFAULT_PORT+3);
-#endif /* GLITE_LB_SERVER_WITH_WS */
- server_cert = server_key = cadir = vomsdir = NULL;
-
-/* no magic here: 1 month, 3 and 7 days */
- purge_timeout[EDG_WLL_PURGE_JOBSTAT_OTHER] = 60*60*24*31;
- purge_timeout[EDG_WLL_JOB_CLEARED] = 60*60*24*3;
- purge_timeout[EDG_WLL_JOB_ABORTED] = 60*60*24*7;
- purge_timeout[EDG_WLL_JOB_CANCELLED] = 60*60*24*7;
-
- if (geteuid()) snprintf(pidfile,sizeof pidfile,"%s/edg-bkserverd.pid",
- getenv("HOME"));
-
- while ((opt = getopt_long(argc,argv,get_opt_string,opts,NULL)) != EOF) switch (opt) {
- case 'a': fake_host = strdup(optarg); break;
- case 'b': transactions = atoi(optarg); break;
- case 'c': server_cert = optarg; break;
- case 'k': server_key = optarg; break;
- case 'C': cadir = optarg; break;
- case 'V': vomsdir = optarg; break;
- case 'p': free(port); port = strdup(optarg); break;
-#ifdef GLITE_LB_SERVER_WITH_WS
- case 'w': free(ws_port); ws_port = strdup(optarg); break;
-#endif /* GLITE_LB_SERVER_WITH_WS */
- case 'd': debug = 1; break;
- case 'z': silent = 1; break;
- case 'r': rgma_export = 1; break;
- case 'm': dbstring = optarg; break;
- case 'n': noAuth = 1; break;
- case 's': slaves = atoi(optarg); break;
- case 'l': semaphores = atoi(optarg); break;
- case 'S': purgeStorage = optarg; break;
- case 'D': dumpStorage = optarg; break;
- case 'J': jpregDir = optarg; jpreg = 1; break;
- case 'j': jpreg = 1; break;
- case 'L':
- if ( !parse_limits(optarg, &hardJobsLimit, &hardEventsLimit, &hardRespSizeLimit) )
- {
- usage(name);
- return 1;
- }
- break;
- case 'N': notif_duration = atoi(optarg) * (60*60); break;
- case 'X': notif_ilog_socket_path = strdup(optarg); break;
- case 'Y': notif_ilog_file_prefix = strdup(optarg); break;
- case 'i': strcpy(pidfile,optarg); break;
- case 'R': if (super_users) {
- fprintf(stderr,"%s: super-users already defined, second occurence ignored\n",
- argv[0]);
- break;
- }
- super_users = malloc(2 * sizeof super_users[0]);
- super_users[0] = optarg;
- super_users[1] = NULL;
- break;
- case 'F': if (super_users) {
- fprintf(stderr,"%s: super-users already defined, second occurence ignored\n",
- argv[0]);
- break;
- }
- if (read_roots(optarg)) return 1;
- break;
- case 'x': noIndex = atoi(optarg);
- if (noIndex < 0 || noIndex > 2) { usage(name); return 1; }
- break;
- case 'P': strict_locking = 1;
- break;
- case 'T': count_statistics = atoi(optarg);
- break;
- case 't': request_timeout = atoi(optarg);
- break;
-#ifdef LB_PERF
- case 'K': sink_mode = atoi(optarg);
- break;
-#endif
- case 'g': greyjobs = strict_locking = 1;
- break;
- case '?': usage(name); return 1;
- }
-
- if ( optind < argc ) { usage(name); return 1; }
-
- setlinebuf(stdout);
- setlinebuf(stderr);
-
- fpid = fopen(pidfile,"r");
- if ( fpid )
- {
- int opid = -1;
-
- if ( fscanf(fpid,"%d",&opid) == 1 )
- {
- if ( !kill(opid,0) )
- {
- fprintf(stderr,"%s: another instance running, pid = %d\n",argv[0],opid);
- return 1;
- }
- else if (errno != ESRCH) { perror("kill()"); return 1; }
- }
- fclose(fpid);
- } else if (errno != ENOENT) { perror(pidfile); return 1; }
-
- fpid = fopen(pidfile, "w");
- if (!fpid) { perror(pidfile); return 1; }
- if (fprintf(fpid, "%d", getpid()) <= 0) { perror(pidfile); return 1; }
- if (fclose(fpid) != 0) { perror(pidfile); return 1; }
-
- semkey = ftok(pidfile,0);
-
- if (check_mkdir(dumpStorage)) exit(1);
- if (check_mkdir(purgeStorage)) exit(1);
- if ( jpreg ) {
- if ( edg_wll_MaildirInit(jpregDir) ) {
- dprintf(("[%d] edg_wll_MaildirInit failed: %s\n", getpid(), lbm_errdesc));
- if (!debug) syslog(LOG_CRIT, "edg_wll_MaildirInit failed: %s", lbm_errdesc);
- exit(1);
- }
- }
-
-
- if (semaphores == -1) semaphores = slaves;
- semset = semget(semkey, 0, 0);
- if (semset >= 0) semctl(semset, 0, IPC_RMID);
- semset = semget(semkey, semaphores, IPC_CREAT | 0600);
- if (semset < 0) { perror("semget()"); return 1; }
- dprintf(("Using %d semaphores, set id %d\n",semaphores,semset));
- for (i=0; i<semaphores; i++)
- {
- struct sembuf s;
-
- s.sem_num = i; s.sem_op = 1; s.sem_flg = 0;
- if (semop(semset,&s,1) == -1) { perror("semop()"); return 1; }
- }
-
- if ( fake_host )
- {
- char *p = strchr(fake_host,':');
-
- if (p)
- {
- *p = 0;
- fake_port = atoi(p+1);
- }
- else fake_port = atoi(port);
- }
- else
- {
- char buf[300];
-
- if ( globus_module_activate(GLOBUS_COMMON_MODULE) != GLOBUS_SUCCESS )
- {
- dprintf(("[%d]: Unable to initialize Globus common module\n",getpid()));
- if (!debug) syslog(LOG_CRIT,"Unable to initialize Globus common module\n");
- }
-
- globus_libc_gethostname(buf,sizeof buf);
- buf[sizeof buf - 1] = 0;
- fake_host = strdup(buf);
- fake_port = atoi(port);
- }
-
- dprintf(("server address: %s:%d\n", fake_host, fake_port));
-
- service_table[SRV_SERVE].conn = socket(PF_INET, SOCK_STREAM, 0);
- if ( service_table[SRV_SERVE].conn < 0 ) { perror("socket()"); return 1; }
- a.sin_family = AF_INET;
- a.sin_port = htons(atoi(port));
- a.sin_addr.s_addr = INADDR_ANY;
- setsockopt(service_table[SRV_SERVE].conn, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
- if ( bind(service_table[SRV_SERVE].conn, (struct sockaddr *) &a, sizeof(a)) )
- {
- char buf[100];
-
- snprintf(buf,sizeof(buf),"bind(%d)",atoi(port));
- perror(buf);
- return 1;
- }
- if ( listen(service_table[SRV_SERVE].conn, CON_QUEUE) ) { perror("listen()"); return 1; }
-
- service_table[SRV_STORE].conn = socket(PF_INET, SOCK_STREAM, 0);
- if ( service_table[SRV_STORE].conn < 0) { perror("socket()"); return 1; }
- a.sin_family = AF_INET;
-a.sin_port = htons(atoi(port)+1);
-a.sin_addr.s_addr = INADDR_ANY;
- setsockopt(service_table[SRV_STORE].conn, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
- if ( bind(service_table[SRV_STORE].conn, (struct sockaddr *) &a, sizeof(a)))
- {
- char buf[100];
-
- snprintf(buf,sizeof(buf), "bind(%d)", atoi(port)+1);
- perror(buf);
- return 1;
- }
- if ( listen(service_table[SRV_STORE].conn, CON_QUEUE) ) { perror("listen()"); return 1; }
-
-#ifdef GLITE_LB_SERVER_WITH_WS
- service_table[SRV_WS].conn = socket(PF_INET, SOCK_STREAM, 0);
- if ( service_table[SRV_WS].conn < 0) { perror("socket()"); return 1; }
- a.sin_family = AF_INET;
- a.sin_port = htons(atoi(ws_port));
- a.sin_addr.s_addr = INADDR_ANY;
- setsockopt(service_table[SRV_WS].conn, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
- if ( bind(service_table[SRV_WS].conn, (struct sockaddr *) &a, sizeof(a)))
- {
- char buf[100];
-
- snprintf(buf, sizeof(buf), "bind(%d)", atoi(ws_port));
- perror(buf);
- return 1;
- }
- if ( listen(service_table[SRV_WS].conn, CON_QUEUE) ) { perror("listen()"); return 1; }
-
-#endif /* GLITE_LB_SERVER_WITH_WS */
-
- if (!server_cert || !server_key)
- fprintf(stderr, "%s: key or certificate file not specified"
- " - unable to watch them for changes!\n", argv[0]);
-
- if ( cadir ) setenv("X509_CERT_DIR", cadir, 1);
- edg_wll_gss_watch_creds(server_cert, &cert_mtime);
- if ( !edg_wll_gss_acquire_cred_gsi(server_cert, server_key, &mycred, &mysubj, &gss_code) )
- {
- int i;
-
- dprintf(("Server identity: %s\n",mysubj));
- server_subject = strdup(mysubj);
- for ( i = 0; super_users && super_users[i]; i++ ) ;
- super_users = realloc(super_users, (i+2)*sizeof(*super_users));
- super_users[i] = mysubj;
- super_users[i+1] = NULL;
- }
- else {
- dprintf(("Running unauthenticated\n"));
- server_subject = strdup("anonymous LB");
- }
-
- if ( noAuth ) dprintf(("Promiscuous mode\n"));
- dprintf(("Listening at %d,%d (accepting protocols: " COMP_PROTO " and compatible) ...\n",atoi(port),atoi(port)+1));
-
-#ifdef GLITE_LB_SERVER_WITH_WS
- dprintf(("Listening at %d (accepting web service protocol) ...\n", atoi(ws_port)));
-#endif /* GLITE_LB_SERVER_WITH_WS */
-
- if (!dbstring) dbstring = getenv("LBDB");
-
- /* Just check the database and let it be. The slaves do the job. */
- edg_wll_InitContext(&ctx);
- wait_for_open(ctx, dbstring);
-
- if (edg_wll_DBCheckVersion(ctx, dbstring))
- {
- char *et,*ed;
- edg_wll_Error(ctx,&et,&ed);
-
- fprintf(stderr,"%s: open database: %s (%s)\n",argv[0],et,ed);
- return 1;
- }
- fprintf(stderr, "[%d]: DB '%s'\n", getpid(), dbstring);
- if (count_statistics) edg_wll_InitStatistics(ctx);
- if (!ctx->use_transactions && transactions != 0) {
- fprintf(stderr, "[%d]: transactions aren't supported!\n", getpid());
- }
- if (transactions >= 0) {
- fprintf(stderr, "[%d]: transactions forced from %d to %d\n", getpid(), ctx->use_transactions, transactions);
- ctx->use_transactions = transactions;
- }
- use_transactions = ctx->use_transactions;
- edg_wll_Close(ctx);
- edg_wll_FreeContext(ctx);
-
- if ( !debug ) {
- if (daemon(1,0) == -1) {
- perror("deamon()");
- exit(1);
- }
-#ifdef LB_PERF
- monstartup((u_long)&_start, (u_long)&etext);
-#endif
-
- fpid = fopen(pidfile,"w");
- if (!fpid) { perror(pidfile); return 1; }
- fprintf(fpid,"%d",getpid());
- fclose(fpid);
-
- openlog(name,LOG_PID,LOG_DAEMON);
- } else {
- setpgid(0, getpid());
- }
-
- if (silent) debug = 0;
-
- glite_srvbones_set_param(GLITE_SBPARAM_SLAVES_COUNT, slaves);
- glite_srvbones_set_param(GLITE_SBPARAM_SLAVE_OVERLOAD, SLAVE_OVERLOAD);
- glite_srvbones_set_param(GLITE_SBPARAM_SLAVE_CONNS_MAX, SLAVE_CONNS_MAX);
-
- to = (struct timeval){CONNECT_TIMEOUT, 0};
- glite_srvbones_set_param(GLITE_SBPARAM_CONNECT_TIMEOUT, &to);
- to.tv_sec = request_timeout;
- glite_srvbones_set_param(GLITE_SBPARAM_REQUEST_TIMEOUT, &to);
- to = (struct timeval){IDLE_TIMEOUT, 0};
- glite_srvbones_set_param(GLITE_SBPARAM_IDLE_TIMEOUT, &to);
-
- glite_srvbones_run(bk_clnt_data_init, service_table, sizofa(service_table), debug);
-
-
- semctl(semset, 0, IPC_RMID, 0);
- unlink(pidfile);
- free(port);
- gss_release_cred(&min_stat, &mycred);
-
-
- return 0;
-}
-
-
-int bk_clnt_data_init(void **data)
-{
- edg_wll_Context ctx;
- struct clnt_data_t *cdata;
- edg_wll_QueryRec **job_index;
- edg_wll_IColumnRec *job_index_cols;
-
-
- if ( !(cdata = calloc(1, sizeof(*cdata))) )
- return -1;
-
- if ( edg_wll_InitContext(&ctx) )
- {
- free(cdata);
- return -1;
- }
-
- dprintf(("[%d] opening database ...\n", getpid()));
- if ( !dbstring ) dbstring = getenv("LBDB");
- wait_for_open(ctx, dbstring);
- cdata->mysql = ctx->mysql;
- cdata->use_transactions = ctx->use_transactions;
-
- if ( edg_wll_QueryJobIndices(ctx, &job_index, NULL) )
- {
- char *et, *ed;
-
- edg_wll_Error(ctx,&et,&ed);
- dprintf(("[%d]: query_job_indices(): %s: %s, no custom indices available\n",getpid(),et,ed));
- if (!debug) syslog(LOG_ERR,"[%d]: query_job_indices(): %s: %s, no custom indices available\n",getpid(),et,ed);
- free(et);
- free(ed);
- }
- edg_wll_FreeContext(ctx);
- cdata->job_index = job_index;
-
- if ( job_index )
- {
- int i,j, k, maxncol, ncol;
-
- ncol = maxncol = 0;
- for ( i = 0; job_index[i]; i++ )
- for ( j = 0; job_index[i][j].attr; j++ )
- maxncol++;
-
- job_index_cols = calloc(maxncol+1, sizeof(edg_wll_IColumnRec));
- for ( i = 0; job_index[i]; i++ )
- {
- for ( j = 0; job_index[i][j].attr; j++)
- {
- for ( k = 0;
- k < ncol && edg_wll_CmpColumn(&job_index_cols[k].qrec, &job_index[i][j]);
- k++);
-
- if ( k == ncol)
- {
- job_index_cols[ncol].qrec = job_index[i][j];
- if ( job_index[i][j].attr == EDG_WLL_QUERY_ATTR_USERTAG )
- {
- job_index_cols[ncol].qrec.attr_id.tag =
- strdup(job_index[i][j].attr_id.tag);
- }
- job_index_cols[ncol].colname =
- edg_wll_QueryRecToColumn(&job_index_cols[ncol].qrec);
- ncol++;
- }
- }
- }
- job_index_cols[ncol].qrec.attr = EDG_WLL_QUERY_ATTR_UNDEF;
- job_index_cols[ncol].colname = NULL;
- cdata->job_index_cols = job_index_cols;
- }
-
-#ifdef LB_PERF
- glite_wll_perftest_init(NULL, NULL, NULL, NULL, 0);
-#endif
-
- *data = cdata;
- return 0;
-}
-
-
-/*
- * Creates context (initializes it from global vatiables and data given
- * from server_bones)
- * gets the connection info
- * and accepts the gss connection
- */
-int bk_handle_connection(int conn, struct timeval *timeout, void *data)
-{
- struct clnt_data_t *cdata = (struct clnt_data_t *)data;
- edg_wll_Context ctx;
- gss_name_t client_name = GSS_C_NO_NAME;
- gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
- gss_cred_id_t newcred = GSS_C_NO_CREDENTIAL;
- edg_wll_GssStatus gss_code;
- OM_uint32 min_stat,
- maj_stat;
- struct timeval dns_to = {DNS_TIMEOUT, 0},
- conn_start, now;
- struct sockaddr_in a;
- int alen;
- char *server_name = NULL,
- *name = NULL;
- int h_errno, ret;
-
-
-
-/* don't care :-(
- switch ( edg_wll_gss_watch_creds(server_cert, &cert_mtime) ) {
- case 0: break;
- case 1:
-*/
- if ( !edg_wll_gss_acquire_cred_gsi(server_cert, server_key, &newcred, NULL, &gss_code) ) {
- dprintf(("[%d] reloading credentials\n", getpid()));
- gss_release_cred(&min_stat, &mycred);
- mycred = newcred;
- } else { dprintf(("[%d] reloading credentials failed, using old ones\n", getpid())); }
-/*
- break;
- case -1: dprintf(("[%d] edg_wll_gss_watch_creds failed\n", getpid())); break;
- }
-*/
-
- if ( edg_wll_InitContext(&ctx) )
- {
- fprintf(stderr, "Couldn't create context");
- return -1;
- }
- cdata->ctx = ctx;
-
- /* Shared structures (pointers)
- */
- ctx->mysql = cdata->mysql;
- ctx->use_transactions = cdata->use_transactions;
- ctx->job_index_cols = cdata->job_index_cols;
- ctx->job_index = cdata->job_index;
-
- /* set globals
- */
- ctx->notifDuration = notif_duration;
- ctx->purgeStorage = strdup(purgeStorage);
- ctx->dumpStorage = strdup(dumpStorage);
- if ( jpreg ) ctx->jpreg_dir = strdup(jpregDir); else ctx->jpreg_dir = NULL;
- ctx->hardJobsLimit = hardJobsLimit;
- ctx->hardEventsLimit = hardEventsLimit;
- ctx->semset = semset;
- ctx->semaphores = semaphores;
- if ( noAuth ) ctx->noAuth = 1;
- ctx->rgma_export = rgma_export;
- memcpy(ctx->purge_timeout, purge_timeout, sizeof(ctx->purge_timeout));
-
- ctx->p_tmp_timeout.tv_sec = timeout->tv_sec;
- ctx->p_tmp_timeout.tv_usec = timeout->tv_usec;
-
- edg_wll_initConnections();
-
- alen = sizeof(a);
- getpeername(conn, (struct sockaddr *)&a, &alen);
- ctx->connections->serverConnection->peerName = strdup(inet_ntoa(a.sin_addr));
- ctx->connections->serverConnection->peerPort = ntohs(a.sin_port);
- ctx->count_statistics = count_statistics;
-
- ctx->serverIdentity = strdup(server_subject);
-
- gettimeofday(&conn_start, 0);
-
- h_errno = asyn_gethostbyaddr(&name, (char *)&a.sin_addr.s_addr,sizeof(a.sin_addr.s_addr), AF_INET, &dns_to);
- switch ( h_errno )
- {
- case NETDB_SUCCESS:
- if (name) dprintf(("[%d] connection from %s:%d (%s)\n",
- getpid(), inet_ntoa(a.sin_addr), ntohs(a.sin_port), name));
- free(ctx->connections->serverConnection->peerName);
- ctx->connections->serverConnection->peerName = name;
- name = NULL;
- break;
-
- default:
- if (debug) fprintf(stderr, "gethostbyaddr(%s): %s", inet_ntoa(a.sin_addr), hstrerror(h_errno));
- dprintf(("[%d] connection from %s:%d\n", getpid(), inet_ntoa(a.sin_addr), ntohs(a.sin_port)));
- free(ctx->connections->serverConnection->peerName);
- ctx->connections->serverConnection->peerName = strdup(inet_ntoa(a.sin_addr));
- break;
- }
-
- gettimeofday(&now, 0);
- if ( decrement_timeout(timeout, conn_start, now) )
- {
- if (debug) fprintf(stderr, "gethostbyaddr() timeout");
- else syslog(LOG_ERR, "gethostbyaddr(): timeout");
- free(name);
-
- return -1;
- }
-
- if (fake_host)
- {
- ctx->srvName = strdup(fake_host);
- ctx->srvPort = fake_port;
- }
- else
- {
- alen = sizeof(a);
- getsockname(conn,(struct sockaddr *) &a,&alen);
-
- dns_to.tv_sec = DNS_TIMEOUT;
- dns_to.tv_usec = 0;
- h_errno = asyn_gethostbyaddr(&name,
- (char *) &a.sin_addr.s_addr,sizeof(a.sin_addr.s_addr),
- AF_INET,&dns_to);
-
- switch ( h_errno )
- {
- case NETDB_SUCCESS:
- ctx->srvName = name;
- if ( server_name != NULL )
- {
- if ( strcmp(name, server_name))
- {
- if (debug) fprintf(stderr, "different server endpoint names (%s,%s),"
- " check DNS PTR records\n", name, server_name);
- else syslog(LOG_ERR,"different server endpoint names (%s,%s),"
- " check DNS PTR records\n", name, server_name);
- }
- }
- else server_name = strdup(name);
- break;
-
- default:
- if ( debug )
- fprintf(stderr, "gethostbyaddr(%s): %s", inet_ntoa(a.sin_addr), hstrerror(h_errno));
- else
- syslog(LOG_ERR,"gethostbyaddr(%s): %s", inet_ntoa(a.sin_addr), hstrerror(h_errno));
- if ( server_name != NULL )
- ctx->srvName = strdup(server_name);
- break;
- }
- ctx->srvPort = ntohs(a.sin_port);
- }
-
-/* XXX: ugly workaround, we may detect false expired certificated
- * probably due to bug in Globus GSS/SSL. Treated as fatal,
- * restarting the server solves the problem */
-
-#define _EXPIRED_CERTIFICATE_MESSAGE "certificate has expired"
-
- if ( (ret = edg_wll_gss_accept(mycred, conn, timeout, &ctx->connections->serverConnection->gss, &gss_code)) )
- {
- if ( ret == EDG_WLL_GSS_ERROR_TIMEOUT )
- {
- dprintf(("[%d] %s: Client authentication failed - timeout reached, closing.\n", getpid(),ctx->connections->serverConnection->peerName));
- if (!debug) syslog(LOG_ERR, "%s: Client authentication failed - timeout reached",ctx->connections->serverConnection->peerName);
- }
- else if (ret == EDG_WLL_GSS_ERROR_GSS) {
- edg_wll_SetErrorGss(ctx,"Client authentication",&gss_code);
- if (strstr(ctx->errDesc,_EXPIRED_CERTIFICATE_MESSAGE)) {
- dprintf(("[%d] %s: false expired certificate: %s\n",getpid(),ctx->connections->serverConnection->peerName,ctx->errDesc));
- if (!debug) syslog(LOG_ERR,"[%d] %s: false expired certificate: %s",getpid(),ctx->connections->serverConnection->peerName,ctx->errDesc);
- edg_wll_FreeContext(ctx);
- return -1;
- }
- dprintf(("[%d] %s: GSS error: %s, closing.\n", getpid(),ctx->connections->serverConnection->peerName,ctx->errDesc));
- if (!debug) syslog(LOG_ERR, "%s: GSS error: %s",ctx->connections->serverConnection->peerName,ctx->errDesc);
- }
- else
- {
- dprintf(("[%d] %s: Client authentication failed, closing.\n", getpid(),ctx->connections->serverConnection->peerName));
- if (!debug) syslog(LOG_ERR, "%s: Client authentication failed",ctx->connections->serverConnection->peerName);
-
- }
- edg_wll_FreeContext(ctx);
- return 1;
- }
-
- maj_stat = gss_inquire_context(&min_stat, ctx->connections->serverConnection->gss.context,
- &client_name, NULL, NULL, NULL, NULL, NULL, NULL);
- if ( !GSS_ERROR(maj_stat) )
- maj_stat = gss_display_name(&min_stat, client_name, &token, NULL);
-
- if ( !GSS_ERROR(maj_stat) )
- {
- if (ctx->peerName) free(ctx->peerName);
- ctx->peerName = (char *)token.value;
- memset(&token, 0, sizeof(token));
- /* XXX DK: pujde pouzit lifetime z inquire_context()?
- *
- ctx->peerProxyValidity = ASN1_UTCTIME_mktime(X509_get_notAfter(peer));
- */
-
- dprintf(("[%d] client DN: %s\n",getpid(),ctx->peerName));
- }
- else
- /* XXX DK: Check if the ANONYMOUS flag is set ?
- */
- dprintf(("[%d] annonymous client\n",getpid()));
-
- if ( client_name != GSS_C_NO_NAME )
- gss_release_name(&min_stat, &client_name);
- if ( token.value )
- gss_release_buffer(&min_stat, &token);
-
- if ( edg_wll_SetVomsGroups(ctx, &ctx->connections->serverConnection->gss, server_cert, server_key, vomsdir, cadir) )
- {
- char *errt, *errd;
-
- edg_wll_Error(ctx, &errt, &errd);
- dprintf(("[%d] %s (%s)\n[%d]\tignored, continuing without VOMS\n", getpid(), errt, errd,getpid()));
- free(errt); free(errd);
- edg_wll_ResetError(ctx);
- }
- if (debug && ctx->vomsGroups.len > 0)
- {
- int i;
-
- dprintf(("[%d] client's VOMS groups:\n",getpid()));
- for ( i = 0; i < ctx->vomsGroups.len; i++ )
- dprintf(("\t%s:%s\n", ctx->vomsGroups.val[i].vo, ctx->vomsGroups.val[i].name));
- }
-
- /* used also to reset start_time after edg_wll_ssl_accept! */
- /* gettimeofday(&start_time,0); */
-
- ctx->noAuth = noAuth || amIroot(ctx->peerName);
- switch ( noIndex )
- {
- case 0: ctx->noIndex = 0; break;
- case 1: ctx->noIndex = amIroot(ctx->peerName); break;
- case 2: ctx->noIndex = 1; break;
- }
- ctx->strict_locking = strict_locking;
- ctx->greyjobs = greyjobs;
-
-
- return 0;
-}
-
-#ifdef GLITE_LB_SERVER_WITH_WS
-int bk_handle_ws_connection(int conn, struct timeval *timeout, void *data)
-{
- struct clnt_data_t *cdata = (struct clnt_data_t *) data;
- struct soap *soap = NULL;
- glite_gsplugin_Context gsplugin_ctx;
- int rv = 0;
-
-
- if ( glite_gsplugin_init_context(&gsplugin_ctx) ) {
- fprintf(stderr, "Couldn't create gSOAP plugin context");
- return -1;
- }
-
- if ( !(soap = soap_new()) ) {
- fprintf(stderr, "Couldn't create soap environment");
- goto err;
- }
-
- soap_init2(soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
- if ( soap_set_namespaces(soap, namespaces) ) {
- soap_done(soap);
- perror("Couldn't set soap namespaces");
- goto err;
- }
- if ( soap_register_plugin_arg(soap, glite_gsplugin, gsplugin_ctx) ) {
- soap_done(soap);
- perror("Couldn't set soap namespaces");
- goto err;
- }
- if ( (rv = bk_handle_connection(conn, timeout, data)) ) {
- soap_done(soap);
- goto err;
- }
- gsplugin_ctx->connection = &cdata->ctx->connections->serverConnection->gss;
- gsplugin_ctx->cred = mycred;
- cdata->soap = soap;
-
-
- return 0;
-
-err:
- if ( gsplugin_ctx ) glite_gsplugin_free_context(gsplugin_ctx);
- if ( soap ) soap_destroy(soap);
-
- return rv? : -1;
-}
-#endif /* GLITE_LB_SERVER_WITH_WS */
-
-int bk_accept_store(int conn, struct timeval *timeout, void *cdata)
-{
- edg_wll_Context ctx = ((struct clnt_data_t *) cdata)->ctx;
- struct timeval before, after;
-
- /*
- * serve the request
- */
- memcpy(&ctx->p_tmp_timeout, timeout, sizeof(ctx->p_tmp_timeout));
- gettimeofday(&before, NULL);
- if ( edg_wll_StoreProto(ctx) )
- {
- char *errt, *errd;
- int err;
-
-
- errt = errd = NULL;
- switch ( (err = edg_wll_Error(ctx, &errt, &errd)) )
- {
- case ETIMEDOUT:
- case EDG_WLL_ERROR_GSS:
- case EPIPE:
- case EIO:
- dprintf(("[%d] %s (%s)\n", getpid(), errt, errd));
- if (!debug) syslog(LOG_ERR,"%s (%s)", errt, errd);
- /* fallthrough
- */
- case ENOTCONN:
- free(errt); free(errd);
- /*
- * "recoverable" error - return (>0)
- */
- return err;
- break;
-
- case ENOENT:
- case EINVAL:
- case EPERM:
- case EEXIST:
- case EDG_WLL_ERROR_NOINDEX:
- case E2BIG:
- dprintf(("[%d] %s (%s)\n", getpid(), errt, errd));
- if ( !debug ) syslog(LOG_ERR,"%s (%s)", errt, errd);
- /*
- * no action for non-fatal errors
- */
- break;
-
- default:
- dprintf(("[%d] %s (%s)\n", getpid(), errt, errd));
- if (!debug) syslog(LOG_CRIT,"%s (%s)",errt,errd);
- /*
- * unknown error - do rather return (<0) (slave will be killed)
- */
- return -EIO;
- }
- free(errt); free(errd);
- }
- gettimeofday(&after, NULL);
- if ( decrement_timeout(timeout, before, after) ) {
- if (debug) fprintf(stderr, "Serving store connection timed out");
- else syslog(LOG_ERR, "Serving store connection timed out");
- return ETIMEDOUT;
- }
-
- return 0;
-}
-
-int bk_accept_serve(int conn, struct timeval *timeout, void *cdata)
-{
- edg_wll_Context ctx = ((struct clnt_data_t *) cdata)->ctx;
- struct timeval before, after;
-
- /*
- * serve the request
- */
- memcpy(&ctx->p_tmp_timeout, timeout, sizeof(ctx->p_tmp_timeout));
- gettimeofday(&before, NULL);
- if ( edg_wll_ServerHTTP(ctx) )
- {
- char *errt, *errd;
- int err;
-
-
- errt = errd = NULL;
- switch ( (err = edg_wll_Error(ctx, &errt, &errd)) )
- {
- case ETIMEDOUT:
- case EDG_WLL_ERROR_GSS:
- case EPIPE:
- dprintf(("[%d] %s (%s)\n", getpid(), errt, errd));
- if (!debug) syslog(LOG_ERR,"%s (%s)", errt, errd);
- /* fallthrough
- */
- case ENOTCONN:
- free(errt); free(errd);
- /*
- * "recoverable" error - return (>0)
- */
- return err;
- break;
-
- case ENOENT:
- case EINVAL:
- case EPERM:
- case EEXIST:
- case EDG_WLL_ERROR_NOINDEX:
- case E2BIG:
- dprintf(("[%d] %s (%s)\n", getpid(), errt, errd));
- if ( !debug ) syslog(LOG_ERR,"%s (%s)", errt, errd);
- /*
- * no action for non-fatal errors
- */
- break;
-
- default:
- dprintf(("[%d] %s (%s)\n", getpid(), errt, errd));
- if (!debug) syslog(LOG_CRIT,"%s (%s)",errt,errd);
- /*
- * unknown error - do rather return (<0) (slave will be killed)
- */
- return -EIO;
- }
- free(errt); free(errd);
- }
- gettimeofday(&after, NULL);
- if ( decrement_timeout(timeout, before, after) ) {
- if (debug) fprintf(stderr, "Serving store connection timed out");
- else syslog(LOG_ERR, "Serving store connection timed out");
- return ETIMEDOUT;
- }
-
- return 0;
-}
-
-
-#ifdef GLITE_LB_SERVER_WITH_WS
-int bk_accept_ws(int conn, struct timeval *timeout, void *cdata)
-{
- struct soap *soap = ((struct clnt_data_t *) cdata)->soap;
- edg_wll_Context ctx = ((struct clnt_data_t *) cdata)->ctx;
- glite_gsplugin_Context gsplugin_ctx;
- int err;
-
-
- gsplugin_ctx = glite_gsplugin_get_context(soap);
- glite_gsplugin_set_timeout(gsplugin_ctx, timeout);
- glite_gsplugin_set_udata(soap, ctx);
- /* soap->max_keep_alive must be higher tha 0,
- * because on 0 value soap closes the connection
- */
- soap->max_keep_alive = 10;
- soap->keep_alive = 1;
- soap_begin(soap);
- err = 0;
- if ( soap_begin_recv(soap) ) {
- if ( soap->error == SOAP_EOF ) {
- soap_send_fault(soap);
- return ENOTCONN;
- }
- if ( soap->error < SOAP_STOP ) err = soap_send_fault(soap);
- else soap_closesock(soap); /* XXX: Do close the socket here? */
- } else {
- /* XXX: An ugly hack!
- * soap->keep_alive is reset to 0 by soap->fparse (http_parse)
- * handler
- * Disabling http_parse function would be nice :)
- */
- soap->keep_alive = 1;
- if ( soap_envelope_begin_in(soap)
- || soap_recv_header(soap)
- || soap_body_begin_in(soap)
- || soap_serve_request(soap)
-#if GSOAP_VERSION >= 20700
- /* XXX: Is it really neccesary ? */
- || (soap->fserveloop && soap->fserveloop(soap))
-#endif
- )
- err = soap_send_fault(soap);
- }
-
- if ( err ) {
- // soap_print_fault(struct soap *soap, FILE *fd) maybe useful here
- dprintf(("[%d] SOAP error (bk_accept_ws) \n", getpid()));
- if (!debug) syslog(LOG_CRIT,"SOAP error (bk_accept_ws)");
- return ECANCELED;
- }
-
- return ENOTCONN;
-}
-#endif /* GLITE_LB_SERVER_WITH_WS */
-
-
-int bk_clnt_disconnect(int conn, struct timeval *timeout, void *cdata)
-{
- edg_wll_Context ctx = ((struct clnt_data_t *) cdata)->ctx;
-
-
- if ( ctx->connections->serverConnection->gss.context != GSS_C_NO_CONTEXT)
- edg_wll_gss_close(&ctx->connections->serverConnection->gss, timeout);
- edg_wll_FreeContext(ctx);
- ctx = NULL;
-
- return 0;
-}
-
-#ifdef GLITE_LB_SERVER_WITH_WS
-int bk_ws_clnt_disconnect(int conn, struct timeval *timeout, void *cdata)
-{
- struct soap *soap = ((struct clnt_data_t *) cdata)->soap;
- glite_gsplugin_Context gsplugin_ctx;
- int rv;
-
-
- gsplugin_ctx = glite_gsplugin_get_context(soap);
- gsplugin_ctx->cred = GSS_C_NO_CREDENTIAL;
- gsplugin_ctx->connection = NULL;
- if ( (rv = bk_clnt_disconnect(conn, timeout, cdata)) )
- return rv;
-
- soap_destroy(((struct clnt_data_t *)cdata)->soap);
- glite_gsplugin_free_context(gsplugin_ctx);
-
- return 0;
-}
-#endif /* GLITE_LB_SERVER_WITH_WS */
-
-int bk_clnt_reject(int conn)
-{
- int flags = fcntl(conn, F_GETFL, 0);
-
- if ( fcntl(conn, F_SETFL, flags | O_NONBLOCK) < 0 )
- return 1;
-
- edg_wll_gss_reject(conn);
-
- return 0;
-}
-
-#ifdef GLITE_LB_SERVER_WITH_WS
-int bk_ws_clnt_reject(int conn)
-{
- return bk_clnt_reject(conn);
-}
-#endif /* GLITE_LB_SERVER_WITH_WS */
-
-
-static void wait_for_open(edg_wll_Context ctx, const char *dbstring)
-{
- char *dbfail_string1, *dbfail_string2;
-
- dbfail_string1 = dbfail_string2 = NULL;
-
- while (edg_wll_Open(ctx, (char *) dbstring)) {
- char *errt,*errd;
-
- if (dbfail_string1) free(dbfail_string1);
- edg_wll_Error(ctx,&errt,&errd);
- asprintf(&dbfail_string1,"%s (%s)\n",errt,errd);
- if (dbfail_string1 != NULL) {
- if (dbfail_string2 == NULL || strcmp(dbfail_string1,dbfail_string2)) {
- if (dbfail_string2) free(dbfail_string2);
- dbfail_string2 = dbfail_string1;
- dbfail_string1 = NULL;
- dprintf(("[%d]: %s\nStill trying ...\n",getpid(),dbfail_string2));
- if (!debug) syslog(LOG_ERR,dbfail_string2);
- }
- }
- sleep(5);
- }
-
- if (dbfail_string1) free(dbfail_string1);
- if (dbfail_string2 != NULL) {
- free(dbfail_string2);
- dprintf(("[%d]: DB connection established\n",getpid()));
- if (!debug) syslog(LOG_INFO,"DB connection established\n");
- }
-
- ctx->use_transactions = use_transactions;
-}
-
-static void free_hostent(struct hostent *h){
- int i;
-
- if (h) {
- if (h->h_name) free(h->h_name);
- if (h->h_aliases) {
- for (i=0; h->h_aliases[i]; i++) free(h->h_aliases[i]);
- free(h->h_aliases);
- }
- if (h->h_addr_list) {
- for (i=0; h->h_addr_list[i]; i++) free(h->h_addr_list[i]);
- free(h->h_addr_list);
- }
- free(h);
- }
-}
-
-struct asyn_result {
- struct hostent *ent;
- int err;
-};
-
-/* ares callback handler for ares_gethostbyaddr() */
-static void callback_handler(void *arg, int status, struct hostent *h)
-{
- struct asyn_result *arp = (struct asyn_result *) arg;
-
- switch (status) {
- case ARES_SUCCESS:
- if (h && h->h_name) {
- arp->ent->h_name = strdup(h->h_name);
- if (arp->ent->h_name == NULL) {
- arp->err = NETDB_INTERNAL;
- } else {
- arp->err = NETDB_SUCCESS;
- }
- } else {
- arp->err = NO_DATA;
- }
- break;
- case ARES_EBADNAME:
- case ARES_ENOTFOUND:
- arp->err = HOST_NOT_FOUND;
- break;
- case ARES_ENOTIMP:
- arp->err = NO_RECOVERY;
- break;
- case ARES_ENOMEM:
- case ARES_EDESTRUCTION:
- default:
- arp->err = NETDB_INTERNAL;
- break;
- }
-}
-
-static int asyn_gethostbyaddr(char **name, const char *addr,int len, int type, struct timeval *timeout)
-{
- struct asyn_result ar;
- ares_channel channel;
- int nfds;
- fd_set readers, writers;
- struct timeval tv, *tvp;
- struct timeval start_time,check_time;
-
-
-/* start timer */
- gettimeofday(&start_time,0);
-
-/* ares init */
- if ( ares_init(&channel) != ARES_SUCCESS ) return(NETDB_INTERNAL);
- ar.ent = (struct hostent *) malloc (sizeof(*ar.ent));
- memset((void *) ar.ent, 0, sizeof(*ar.ent));
-
-/* query DNS server asynchronously */
- ares_gethostbyaddr(channel, addr, len, type, callback_handler, (void *) &ar);
-
-/* wait for result */
- while (1) {
- FD_ZERO(&readers);
- FD_ZERO(&writers);
- nfds = ares_fds(channel, &readers, &writers);
- if (nfds == 0)
- break;
-
- gettimeofday(&check_time,0);
- if (decrement_timeout(timeout, start_time, check_time)) {
- ares_destroy(channel);
- free_hostent(ar.ent);
- return(TRY_AGAIN);
- }
- start_time = check_time;
-
- tvp = ares_timeout(channel, timeout, &tv);
-
- switch ( select(nfds, &readers, &writers, NULL, tvp) ) {
- case -1: if (errno != EINTR) {
- ares_destroy(channel);
- free_hostent(ar.ent);
- return NETDB_INTERNAL;
- } else
- continue;
- case 0:
- FD_ZERO(&readers);
- FD_ZERO(&writers);
- /* fallthrough */
- default : ares_process(channel, &readers, &writers);
- }
-
- }
-
-
- ares_destroy(channel);
-
- if (ar.err == NETDB_SUCCESS) {
- *name = strdup(ar.ent->h_name);
- free_hostent(ar.ent);
- }
- return (ar.err);
-}
-
-static int read_roots(const char *file)
-{
- FILE *roots = fopen(file,"r");
- char buf[BUFSIZ];
- int cnt = 0;
-
- if (!roots) {
- syslog(LOG_WARNING,"%s: %m, continuing without --super-users-file",file);
- dprintf(("%s: %s, continuing without --super-users-file\n",file,strerror(errno)));
- return 0;
- }
-
- while (fgets(buf,sizeof buf,roots) != NULL) {
- char *nl;
- nl = strchr(buf,'\n');
- if (nl) *nl = 0;
-
- super_users = realloc(super_users, (cnt+2) * sizeof super_users[0]);
- super_users[cnt] = strdup(buf);
- super_users[++cnt] = NULL;
- }
-
- fclose(roots);
-
- return 0;
-}
-
-static int amIroot(const char *subj)
-{
- int i;
-
- if (!subj) return 0;
- for (i=0; super_users && super_users[i]; i++)
- if (strcmp(subj,super_users[i]) == 0) return 1;
-
- return 0;
-}
-
-static int parse_limits(char *opt, int *j_limit, int *e_limit, int *size_limit)
-{
- return (sscanf(opt, "%d:%d:%d", j_limit, e_limit, size_limit) == 3);
-}
-
-
-static int check_mkdir(const char *dir)
-{
- struct stat sbuf;
-
- if ( stat(dir, &sbuf) )
- {
- if ( errno == ENOENT )
- {
- if ( mkdir(dir, S_IRWXU) )
- {
- dprintf(("[%d] %s: %s\n", getpid(), dir, strerror(errno)));
- if (!debug) syslog(LOG_CRIT, "%s: %m", dir);
- return 1;
- }
- }
- else
- {
- dprintf(("[%d] %s: %s\n", getpid(), dir, strerror(errno)));
- if (!debug) syslog(LOG_CRIT, "%s: %m", dir);
- return 1;
- }
- }
-
- if (!S_ISDIR(sbuf.st_mode))
- {
- dprintf(("[%d] %s: not a directory\n", getpid(),dir));
- if (!debug) syslog(LOG_CRIT,"%s: not a directory",dir);
- return 1;
- }
-
- if (access(dir, R_OK | W_OK))
- {
- dprintf(("[%d] %s: directory is not readable/writable\n", getpid(),dir));
- if (!debug) syslog(LOG_CRIT,"%s: directory is not readable/writable",dir);
- return 1;
- }
-
-
- return 0;
-}
-
-static int decrement_timeout(struct timeval *timeout, struct timeval before, struct timeval after)
-{
- (*timeout).tv_sec = (*timeout).tv_sec - (after.tv_sec - before.tv_sec);
- (*timeout).tv_usec = (*timeout).tv_usec - (after.tv_usec - before.tv_usec);
- while ( (*timeout).tv_usec < 0) {
- (*timeout).tv_sec--;
- (*timeout).tv_usec += 1000000;
- }
- if ( ((*timeout).tv_sec < 0) || (((*timeout).tv_sec == 0) && ((*timeout).tv_usec == 0)) ) return(1);
- else return(0);
-}
-
+++ /dev/null
-#ident "$Header$"
-
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-#include <stdlib.h>
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/events_parse.h"
-#include "glite/lb/lb_maildir.h"
-#include "glite/lb/purge.h"
-#include "purge.h"
-#include "store.h"
-#include "lbs_db.h"
-#include "lock.h"
-#include "il_lbproxy.h"
-#include "jobstat.h"
-
-#ifdef LB_PERF
-#include "glite/lb/lb_perftest.h"
-#include "glite/lb/srv_perf.h"
-#endif
-
-
-/* XXX */
-#define use_db 1
-
-extern int edg_wll_NotifMatch(edg_wll_Context, const edg_wll_JobStat *);
-
-static int db_actual_store(edg_wll_Context ctx, char *event, edg_wll_Event *ev, edg_wll_JobStat *newstat);
-
-
-int
-db_store(edg_wll_Context ctx,char *ucs, char *event)
-{
- edg_wll_Event *ev;
- int seq;
- int err;
- edg_wll_JobStat newstat;
-
- ev = NULL;
-
- edg_wll_ResetError(ctx);
- memset(&newstat,0,sizeof newstat);
-
- if(edg_wll_ParseEvent(ctx, event, &ev))
- goto err;
-
-#ifdef LB_PERF
- if (sink_mode == GLITE_LB_SINK_STORE) {
- glite_wll_perftest_consumeEvent(ev);
- edg_wll_FreeEvent(ev);
- free(ev);
- return 0;
- }
-#endif
-
-
- /* XXX: if event type is user tag, convert the tag name to lowercase!
- * (not sure whether to convert a value too is reasonable
- * or keep it 'case sensitive')
- */
- if ( ev->any.type == EDG_WLL_EVENT_USERTAG )
- {
- int i;
- for ( i = 0; ev->userTag.name[i] != '\0'; i++ )
- ev->userTag.name[i] = tolower(ev->userTag.name[i]);
- }
-
- if(ev->any.user == NULL)
- ev->any.user = strdup(ucs);
-
- if(use_db) {
- if (ctx->strict_locking && edg_wll_LockJob(ctx,ev->any.jobId)) goto err;
- if(edg_wll_StoreEvent(ctx, ev,&seq))
- goto err;
- }
-
- if (!ctx->strict_locking && edg_wll_LockJob(ctx,ev->any.jobId)) goto err;
-
- if ( ev->any.type == EDG_WLL_EVENT_CHANGEACL )
- err = edg_wll_UpdateACL(ctx, ev->any.jobId,
- ev->changeACL.user_id, ev->changeACL.user_id_type,
- ev->changeACL.permission, ev->changeACL.permission_type,
- ev->changeACL.operation);
- else {
-#ifdef LB_PERF
- if(sink_mode == GLITE_LB_SINK_STATE) {
- glite_wll_perftest_consumeEvent(ev);
- edg_wll_UnlockJob(ctx,ev->any.jobId);
- goto err;
- }
-#endif
-
- err = edg_wll_StepIntState(ctx,ev->any.jobId, ev, seq, ctx->isProxy? NULL: &newstat);
- }
-
- /* XXX: in edg_wll_StepIntState()
- * if (edg_wll_UnlockJob(ctx,ev->any.jobId)) goto err;
- */
- if (err) goto err;
-
- db_actual_store(ctx, event, ev, &newstat);
-
-err:
-
- if(ev) {
- edg_wll_FreeEvent(ev);
- free(ev);
- }
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-
-int
-db_parent_store(edg_wll_Context ctx, edg_wll_Event *ev, intJobStat *is)
-{
- char *event = NULL;
- int seq;
- int err;
- edg_wll_JobStat newstat;
-
-
- edg_wll_ResetError(ctx);
- memset(&newstat,0,sizeof newstat);
-
-
-#ifdef LB_PERF
- if (sink_mode == GLITE_LB_SINK_STORE) {
- glite_wll_perftest_consumeEvent(ev);
- edg_wll_FreeEvent(ev);
- free(ev);
- return 0;
- }
-#endif
-
-
- /* XXX: if event type is user tag, convert the tag name to lowercase!
- * (not sure whether to convert a value too is reasonable
- * or keep it 'case sensitive')
- */
- if ( ev->any.type == EDG_WLL_EVENT_USERTAG )
- {
- int i;
- for ( i = 0; ev->userTag.name[i] != '\0'; i++ )
- ev->userTag.name[i] = tolower(ev->userTag.name[i]);
- }
-
- assert(ev->any.user);
-
- if(use_db) {
- if(edg_wll_StoreEvent(ctx, ev,&seq))
- goto err;
- }
-
- if ( ev->any.type == EDG_WLL_EVENT_CHANGEACL )
- err = edg_wll_UpdateACL(ctx, ev->any.jobId,
- ev->changeACL.user_id, ev->changeACL.user_id_type,
- ev->changeACL.permission, ev->changeACL.permission_type,
- ev->changeACL.operation);
- else {
-#ifdef LB_PERF
- if(sink_mode == GLITE_LB_SINK_STATE) {
- glite_wll_perftest_consumeEvent(ev);
- goto err;
- }
-#endif
-
- err = edg_wll_StepIntStateParent(ctx,ev->any.jobId, ev, seq, is, ctx->isProxy? NULL: &newstat);
- }
-
- if (err) goto err;
-
- if ( ctx->isProxy ) {
- event = edg_wll_UnparseEvent(ctx, ev);
- assert(event);
- }
-
- db_actual_store(ctx, event, ev, &newstat);
-
-err:
-
- free(event);
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-static int db_actual_store(edg_wll_Context ctx, char *event, edg_wll_Event *ev, edg_wll_JobStat *newstat) {
-
- if ( ctx->isProxy ) {
- /*
- * send event to the proper BK server
- */
- /* XXX: RegJob events, which were logged also directly, are duplicated at server,
- but it should not harm */
-
-#ifdef LB_PERF
- if( sink_mode == GLITE_LB_SINK_SEND ) {
- glite_wll_perftest_consumeEvent(ev);
- } else
-#endif
-
- if (edg_wll_EventSendProxy(ctx, ev->any.jobId, event) ) {
- return edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "edg_wll_EventSendProxy() error.");
- }
-
- /* LB proxy purge
- * XXX: Set propper set of states!
- * TODO: Do the set of states configurable?
- */
- switch ( ev->any.type ) {
- case EDG_WLL_EVENT_CLEAR:
- case EDG_WLL_EVENT_ABORT:
- edg_wll_PurgeServerProxy(ctx, ev->any.jobId);
- break;
- case EDG_WLL_EVENT_CANCEL:
- if (ev->cancel.status_code == EDG_WLL_CANCEL_DONE)
- edg_wll_PurgeServerProxy(ctx, ev->any.jobId);
- break;
- default: break;
- }
- } else
-#ifdef LB_PERF
- if( sink_mode == GLITE_LB_SINK_SEND ) {
- glite_wll_perftest_consumeEvent(ev);
- } else
-#endif
- {
- if ( newstat->state ) {
- edg_wll_NotifMatch(ctx, newstat);
- edg_wll_FreeStatus(newstat);
- }
- if ( ctx->jpreg_dir && ev->any.type == EDG_WLL_EVENT_REGJOB ) {
- char *jids, *msg;
-
- if ( !(jids = edg_wlc_JobIdUnparse(ev->any.jobId)) ) {
- return edg_wll_SetError(ctx, errno, "Can't unparse jobid when registering to JP");
- }
- if ( !(msg = realloc(jids, strlen(jids)+strlen(ev->any.user)+2)) ) {
- free(jids);
- return edg_wll_SetError(ctx, errno, "Can't allocate buffer when registering to JP");
- }
- strcat(msg, "\n");
- strcat(msg, ev->any.user);
- if ( edg_wll_MaildirStoreMsg(ctx->jpreg_dir, ctx->srvName, msg) ) {
- free(msg);
- return edg_wll_SetError(ctx, errno, lbm_errdesc);
- }
- free(msg);
- }
- }
- return edg_wll_Error(ctx,NULL,NULL);
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <time.h>
-#include <stdio.h>
-#include <string.h>
-#include <syslog.h>
-#include <assert.h>
-#include <unistd.h>
-
-#include "glite/lb/trio.h"
-#include "glite/wmsutils/jobid/cjobid.h"
-
-#include "glite/lb/context-int.h"
-#include "glite/lb/events_parse.h"
-#include "glite/lb/ulm_parse.h"
-#include "glite/lb/purge.h"
-#include "glite/lb/purge.h"
-#include "glite/lb/dump.h"
-
-#include "lbs_db.h"
-#include "query.h"
-#include "get_events.h"
-#include "server_state.h"
-#include "purge.h"
-
-static char *time_to_string(time_t t, char **ptr);
-static int handle_specials(edg_wll_Context,time_t *);
-
-#define sizofa(a) (sizeof(a)/sizeof((a)[0]))
-
-int edg_wll_DumpEvents(edg_wll_Context ctx,const edg_wll_DumpRequest *req,edg_wll_DumpResult *result)
-{
- char *from_s, *to_s, *stmt, *time_s, *ptr;
- char *tmpfname;
- time_t start,end;
- edg_wll_Stmt q = NULL;
- char *res[10];
- int event;
- edg_wll_Event e;
- int ret,dump = 2; /* TODO: manage dump file */
- time_t from = req->from,to = req->to;
-
- from_s = to_s = stmt = NULL;
- memset(res,0,sizeof res);
- memset(&e,0,sizeof e);
-
- time(&start);
- edg_wll_ResetError(ctx);
-
- if ( (dump = edg_wll_CreateTmpDumpFile(ctx, &tmpfname)) == -1 )
- return edg_wll_Error(ctx, NULL, NULL);
-
- if (handle_specials(ctx,&from) || handle_specials(ctx,&to))
- {
- unlink(tmpfname);
- return edg_wll_Error(ctx,NULL,NULL);
- }
-
- from_s = strdup(edg_wll_TimeToDB(from));
- to_s = strdup(edg_wll_TimeToDB(to));
-
- trio_asprintf(&stmt,
- "select event,dg_jobid,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived "
- "from events e,users u,jobs j "
- "where u.userid=e.userid "
- "and j.jobid = e.jobid "
- "and j.dg_jobid like 'https://%|Ss:%d%%' "
- "and arrived > %s and arrived <= %s "
- "order by arrived",
- ctx->srvName,ctx->srvPort,
- from_s,to_s);
-
- if (edg_wll_ExecStmt(ctx,stmt,&q) < 0) goto clean;
-
- while ((ret = edg_wll_FetchRow(q,res)) > 0) {
- assert(ret == sizofa(res));
- event = atoi(res[0]); free(res[0]); res[0] = NULL;
-
- if (convert_event_head(ctx,res+1,&e)
- || edg_wll_get_event_flesh(ctx,event,&e))
- {
- char *et,*ed;
- int i;
-
- /* Most likely sort of internal inconsistency.
- * Must not be fatal -- just complain
- */
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"%s event %d: %s (%s)\n",res[1],event,et,ed);
- syslog(LOG_WARNING,"%s event %d: %s (%s)",res[1],event,et,ed);
- free(et); free(ed);
- for (i=0; i<sizofa(res); i++) free(res[i]);
- edg_wll_ResetError(ctx);
- }
- else {
- char *event_s = edg_wll_UnparseEvent(ctx,&e);
- char arr_s[100];
- int len, written, total;
-
- strcpy(arr_s, "DG.ARRIVED=");
- edg_wll_ULMTimevalToDate(e.any.arrived.tv_sec,
- e.any.arrived.tv_usec,
- arr_s+strlen("DG.ARRIVED="));
- len = strlen(arr_s);
- total = 0;
- while (total != len) {
- written = write(dump,arr_s+total,len-total);
- if (written < 0 && errno != EAGAIN) {
- edg_wll_SetError(ctx,errno,"writing dump file");
- free(event_s);
- goto clean;
- }
- total += written;
- }
- write(dump, " ", 1);
- len = strlen(event_s);
- total = 0;
- while (total != len) {
- written = write(dump,event_s+total,len-total);
- if (written < 0 && errno != EAGAIN) {
- edg_wll_SetError(ctx,errno,"writing dump file");
- free(event_s);
- goto clean;
- }
- total += written;
- }
- write(dump,"\n",1);
- free(event_s);
- }
- edg_wll_FreeEvent(&e); memset(&e,0,sizeof e);
- }
-
- time(&end);
- time_s = time_to_string(start, &ptr);
- edg_wll_SetServerState(ctx,EDG_WLL_STATE_DUMP_START,time_s);
- free(ptr);
-
- time_s = time_to_string(end, &ptr);
- edg_wll_SetServerState(ctx,EDG_WLL_STATE_DUMP_END,time_s);
- free(ptr);
-
- result->from = from;
- result->to = to;
-
- edg_wll_CreateDumpFileFromTmp(ctx, tmpfname, &(result->server_file));
- unlink(tmpfname);
-
-clean:
- edg_wll_FreeEvent(&e);
- edg_wll_FreeStmt(&q);
-
- free(stmt);
- free(from_s);
- free(to_s);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-static int handle_specials(edg_wll_Context ctx,time_t *t)
-{
- char *time_s;
- int ret;
-
- edg_wll_ResetError(ctx);
- switch (*t) {
- case EDG_WLL_DUMP_NOW:
- time(t);
- return 0;
- case EDG_WLL_DUMP_LAST_START:
- case EDG_WLL_DUMP_LAST_END:
- switch (ret = edg_wll_GetServerState(ctx,
- *t == EDG_WLL_DUMP_LAST_START ?
- EDG_WLL_STATE_DUMP_START:
- EDG_WLL_STATE_DUMP_END,
- &time_s))
- {
- case ENOENT: *t = 0;
- edg_wll_ResetError(ctx);
- break;
- case 0: *t = edg_wll_DBToTime(time_s);
- assert(*t >= 0);
- break;
- default: break;
- }
- break;
- default: if (*t < 0) return edg_wll_SetError(ctx,EINVAL,"special time limit unrecognized");
- }
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-
-static char *time_to_string(time_t t, char **ptr) {
- char *s;
-
- s = edg_wll_TimeToDB(t);
- s[strlen(s) - 1] = '\0';
- *ptr = s;
-
- return s + 1;
-}
+++ /dev/null
-#ident "$Header$"
-
-/*
-@@@AUTO
-*/
-@@@LANG: C
-
-/* Helper functions for getting events from the LB database *
- * XXX: lots of stuff still hadcoded:
- * there's mapping db.columns <-> union event fields
- */
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <syslog.h>
-
-#include "get_events.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-#include "glite/lb/events_parse.h"
-
-static void edg_wll_set_event_field(edg_wll_Event *,char *,char *);
-static void edg_wll_set_event_field_warn(edg_wll_Event *,char *,char *);
-
-int edg_wll_get_event_flesh(edg_wll_Context ctx,int n,edg_wll_Event *e)
-{
- char *jobid = edg_wlc_JobIdGetUnique(e->any.jobId),
- *q = NULL,*nameval[2];
- edg_wll_Stmt sh;
- int ret,t;
- const char *tables[] = { "short_fields","long_fields" };
-
- edg_wll_ResetError(ctx);
-
- for (t=0; t<=1; t++) {
- trio_asprintf(&q,"select name,value from %s "
- "where jobid = '%|Ss' and event = %d ",
- tables[t],jobid,n);
-
- if ((ret=edg_wll_ExecStmt(ctx,q,&sh)) < 0) goto cleanup;
-
- while ((ret=edg_wll_FetchRow(sh,nameval)) > 0) {
- edg_wll_set_event_field(e,nameval[0],nameval[1]);
- free(nameval[0]);
- /* XXX: nameval[1] freed in edg_wll_set_event_field
- * if necessary
- */
- }
-
- if (ret<0) goto cleanup;
- edg_wll_FreeStmt(&sh);
- free(q); q=NULL;
- }
-
- ret=edg_wll_CheckEvent(ctx,e);
-
-cleanup:
- if (sh) edg_wll_FreeStmt(&sh);
- free(jobid);
- free(q);
-
- if (ret) { edg_wll_FreeEvent(e); memset(e,0,sizeof *e); }
- return ret;
-}
-
-
-/* print/log warning for database inconsistency */
-
-static void edg_wll_set_event_field_warn(
- edg_wll_Event *event,
- char *name,
- char *value)
-{
- char *e = edg_wll_EventToString(event->any.type);
-
- fprintf(stderr, "edg_wll_set_event_field: bad field:"
- "code=\"%s\" name=\"%s\" value=\"%s\"\n",
- e, name, value);
- free(e);
- /* XXX edg_wll_Log */
-}
-
-/* set event structure field */
-
-static void edg_wll_set_event_field(
- edg_wll_Event *event,
- char *name,
- char *value)
-{
-/* XXX: where's the best place to hande it? */
- if (!strcasecmp(name,"SRC_INSTANCE")) {
- event->any.src_instance = value;
- return;
- }
-
-/* XXX: handled separately, should go to event_head one day */
- if (!strcasecmp(name,"SEQCODE")) {
- event->any.seqcode = value;
- return;
- }
-
-@@@{
- for my $n (getAllFieldsOrdered $event) {
- my @occ = getFieldOccurence $event $n;
- next if $#occ == 0 && $occ[0] eq '_common_';
- selectType $event $occ[0];
- my $f = selectField $event $n;
- my $name = getName $f;
- my $lcname = lc $name;
- gen qq{
-! if (!strcasecmp(name,"$lcname")) \{
-! switch (event->any.type) \{
-};
- for (@occ) {
- next if $_ eq '_common_';
- selectType $event $_;
- $f = selectField $event $n;
- my $fucname = ucfirst $n;
- my $uctype = uc $_;
- my $flctype = lcfirst $_;
- if ($flctype =~ m/^pBS/) { $flctype = ucfirst $flctype; }
- if ($flctype =~ m/^condor/) { $flctype = ucfirst $flctype; }
- my $frs = $f->{codes} ?
- "event->$flctype.$name = edg_wll_StringTo$_${fucname}(value);" :
- fromString $f 'value',"event->$flctype.$name";
- gen qq{
-! case EDG_WLL_EVENT_$uctype: $frs break;
-};
- }
- gen qq{
-! default: edg_wll_set_event_field_warn(event,name,value); break;
-! \} /* switch */
-! free(value);
-! return;
-! \}
-};
- }
-@@@}
-
- edg_wll_set_event_field_warn(event,name,value);
- free(value);
- return;
-}
-
-
-int compare_events_by_tv(const void *a, const void *b)
-{
- const edg_wll_Event *e = (edg_wll_Event *)a;
- const edg_wll_Event *f = (edg_wll_Event *)b;
-
- if (e->any.timestamp.tv_sec < f->any.timestamp.tv_sec) return -1;
- if (e->any.timestamp.tv_sec > f->any.timestamp.tv_sec) return 1;
- if (e->any.timestamp.tv_usec < f->any.timestamp.tv_usec) return -1;
- if (e->any.timestamp.tv_usec > f->any.timestamp.tv_usec) return 1;
- return 0;
-}
+++ /dev/null
-#ident "$Header$"
-
-/* Internal functions for getting event sets from the LB database */
-#include "lbs_db.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#if 0 /* rel 1 */
-char *edg_wll_jobid_to_user( edg_wll_Context, char *);
-void edg_wll_set_event_field_warn( edg_wll_Event *, char *, char *);
-void edg_wll_set_event_field( edg_wll_Event *, char *, char *);
-int edg_wll_get_events_restricted( edg_wll_Context, edg_wlc_JobId, char *, int, int, char *, edg_wll_Event **);
-#define edg_wll_get_events(ctx,job,md5,emin,emax,ret) \
- edg_wll_get_events_restricted((ctx),(job),(md5),(emin),(emax),NULL,(ret))
-int edg_wll_last_event( edg_wll_Context, char *);
-int compare_events_by_tv(const void *, const void *);
-#endif
-
-int edg_wll_get_event_flesh(edg_wll_Context,int,edg_wll_Event *);
-
-int edg_wll_QueryEventsServer(edg_wll_Context,int,const edg_wll_QueryRec **,const edg_wll_QueryRec **,edg_wll_Event **);
-
-int edg_wll_QueryJobsServer(edg_wll_Context, const edg_wll_QueryRec **, int, edg_wlc_JobId **, edg_wll_JobStat **);
-
-void edg_wll_SortEvents(edg_wll_Event *);
-
-void edg_wll_SortPEvents(edg_wll_Event **);
-
-#ifdef __cplusplus
-}
-#endif
-
+++ /dev/null
-#ident "$Header$"
-
-#include <syslog.h>
-#include "glite/lb/context-int.h"
-#include "glite/lb/log_proto.h"
-
-#include "il_lbproxy.h"
-
-#define FCNTL_ATTEMPTS 5
-#define FCNTL_TIMEOUT 1
-#define FILE_PREFIX EDG_WLL_LOG_PREFIX_DEFAULT
-#define DEFAULT_SOCKET "/tmp/interlogger.sock"
-
-char *lbproxy_ilog_socket_path = DEFAULT_SOCKET;
-char *lbproxy_ilog_file_prefix = FILE_PREFIX;
-
-
-int
-edg_wll_EventSendProxy(
- edg_wll_Context ctx,
- const edg_wlc_JobId jobid,
- const char *event)
-{
- long filepos;
- char *jobid_s,
- *event_file = NULL;
- int err = 0;
-
-#define _err(n) { err = n; goto out; }
-
- edg_wll_ResetError(ctx);
-
- jobid_s = edg_wlc_JobIdGetUnique(jobid);
- if ( !jobid_s ) {
- edg_wll_SetError(ctx, ENOMEM, "edg_wlc_JobIdGetUnique()");
- _err(1);
- }
-
- asprintf(&event_file, "%s.%s", lbproxy_ilog_file_prefix, jobid_s);
- if ( !event_file ) {
- edg_wll_SetError(ctx, ENOMEM, "asprintf()");
- _err(1);
- }
-
- if ( edg_wll_log_event_write(ctx, event_file, event,
- (ctx->p_tmp_timeout.tv_sec > FCNTL_ATTEMPTS ?
- ctx->p_tmp_timeout.tv_sec : FCNTL_ATTEMPTS),
- FCNTL_TIMEOUT, &filepos) ) {
-
- edg_wll_UpdateError(ctx, 0, "edg_wll_log_event_write()");
- _err(1);
- }
-
- if ( edg_wll_log_event_send(ctx, lbproxy_ilog_socket_path, filepos,
- event, strlen(event), 1, &ctx->p_tmp_timeout) ) {
- char *errt, *errd;
- errt = errd = NULL;
-
- edg_wll_UpdateError(ctx, EDG_WLL_IL_PROTO, "edg_wll_log_event_send()");
- edg_wll_Error(ctx, &errt, &errd);
- syslog(LOG_ERR,"%s (%s)", errt, errd);
- free(errt); free(errd);
- _err(-1);
- }
-
-out:
- if ( jobid_s ) free(jobid_s);
- if ( event_file ) free(event_file);
-
- if ( !err ) return 0;
- if ( err < 0 ) {
- /* do not propagate IL errors */
- edg_wll_ResetError(ctx);
- return 0;
- } else {
- edg_wll_UpdateError(ctx, 0, "edg_wll_EventSendProxy()");
- return edg_wll_Error(ctx, NULL, NULL);
- }
-}
+++ /dev/null
-#ifndef IL_LBPROXY_H
-#define IL_LBPROXY_H
-
-#ifdef __cplusplus
-#extern "C" {
-#endif
-
-extern char *lbproxy_ilog_socket_path;
-extern char *lbproxy_ilog_file_prefix;
-
-int edg_wll_EventSendProxy(edg_wll_Context ctx, const edg_wlc_JobId jobid, const char *event);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-#ident "$Header$"
-/**
- * il_notification.c
- * - implementation of IL API calls for notifications
- *
- */
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-
-#include "glite/lb/context-int.h"
-#include "glite/lb/notifid.h"
-#include "glite/lb/events_parse.h"
-#include "glite/lb/escape.h"
-#include "glite/lb/log_proto.h"
-
-#include "il_notification.h"
-#include "lb_xml_parse.h"
-
-
-
-#define FCNTL_ATTEMPTS 5
-#define FCNTL_TIMEOUT 1
-#define FILE_PREFIX "/tmp/notif_events"
-#define DEFAULT_SOCKET "/tmp/notif_interlogger.sock"
-
-char *notif_ilog_socket_path = DEFAULT_SOCKET;
-char *notif_ilog_file_prefix = FILE_PREFIX;
-
-
-static
-int
-notif_create_ulm(
- edg_wll_Context context,
- edg_wll_NotifId reg_id,
- const char *host,
- const uint16_t port,
- const char *owner,
- const char *notif_data,
- char **ulm_data,
- char **reg_id_s)
-{
- int ret;
- edg_wll_Event *event=NULL;
-
- *ulm_data = NULL;
- *reg_id_s = NULL;
-
- event = edg_wll_InitEvent(EDG_WLL_EVENT_NOTIFICATION);
-
- gettimeofday(&event->any.timestamp,0);
- if (context->p_host) event->any.host = strdup(context->p_host);
- event->any.level = context->p_level;
- event->any.source = context->p_source;
- if (context->p_instance) event->notification.src_instance = strdup(context->p_instance);
- event->notification.notifId = edg_wll_NotifIdDup(reg_id);
- if (owner) event->notification.owner = strdup(owner);
- if (host) event->notification.dest_host = strdup(host);
- event->notification.dest_port = port;
- if (notif_data) event->notification.jobstat = strdup(notif_data);
-
- if ((*ulm_data = edg_wll_UnparseNotifEvent(context,event)) == NULL) {
- edg_wll_SetError(context, ret = ENOMEM, "edg_wll_UnparseNotifEvent()");
- goto out;
- }
-
- if((*reg_id_s = edg_wll_NotifIdGetUnique(reg_id)) == NULL) {
- edg_wll_SetError(context, ret = ENOMEM, "edg_wll_NotifIdGetUnique()");
- goto out;
- }
-
- ret = 0;
-
-out:
- if(event) {
- edg_wll_FreeEvent(event);
- free(event);
- }
- if(ret) edg_wll_UpdateError(context, ret, "notif_create_ulm()");
- return(ret);
-}
-
-
-int
-edg_wll_NotifSend(edg_wll_Context context,
- edg_wll_NotifId reg_id,
- const char *host,
- int port,
- const char *owner,
- const char *notif_data)
-{
- struct timeval timeout;
- int ret;
- long filepos;
- char *ulm_data,
- *reg_id_s,
- *event_file;
-
- if((ret=notif_create_ulm(context,
- reg_id,
- host,
- port,
- owner,
- notif_data,
- &ulm_data,
- ®_id_s))) {
- goto out;
- }
-
- asprintf(&event_file, "%s.%s", notif_ilog_file_prefix, reg_id_s);
- if(event_file == NULL) {
- edg_wll_SetError(context, ret=ENOMEM, "asprintf()");
- goto out;
- }
-
- if ( (ret = edg_wll_log_event_write(context, event_file, ulm_data,
- FCNTL_ATTEMPTS, FCNTL_TIMEOUT, &filepos)) ) {
- edg_wll_UpdateError(context, 0, "edg_wll_log_event_write()");
- goto out;
- }
-
- if ( (ret = edg_wll_log_event_send(context, notif_ilog_socket_path,
- filepos, ulm_data, strlen(ulm_data), 1, &timeout)) ) {
- edg_wll_UpdateError(context, 0, "edg_wll_log_event_send()");
- goto out;
- }
-
- ret = 0;
-
-out:
- if(ulm_data) free(ulm_data);
- if(reg_id_s) free(reg_id_s);
- if(ret) edg_wll_UpdateError(context, ret, "edg_wll_NotifSend()");
- return(ret);
-}
-
-
-int
-edg_wll_NotifJobStatus(edg_wll_Context context,
- edg_wll_NotifId reg_id,
- const char *host,
- int port,
- const char *owner,
- const edg_wll_JobStat notif_job_stat)
-{
- int ret=0;
- char *xml_data, *xml_esc_data=NULL;
-
- if(edg_wll_JobStatusToXML(context, notif_job_stat, &xml_data))
- goto out;
-
- if((xml_esc_data = edg_wll_EscapeXML(xml_data)) == NULL) {
- edg_wll_SetError(context, ret=ENOMEM, "edg_wll_EscapeXML()");
- goto out;
- }
-
- ret=edg_wll_NotifSend(context, reg_id, host, port, owner, xml_esc_data);
-
-out:
- if(xml_data) free(xml_data);
- if(xml_esc_data) free(xml_esc_data);
- if(ret) edg_wll_UpdateError(context, ret, "edg_wll_NotifJobStatus()");
- return(ret);
-}
-
-
-int
-edg_wll_NotifChangeDestination(edg_wll_Context context,
- edg_wll_NotifId reg_id,
- const char *host,
- int port)
-{
- return(edg_wll_NotifSend(context, reg_id, host, port, "", ""));
-}
-
-
-int
-edg_wll_NotifCancelRegId(edg_wll_Context context,
- edg_wll_NotifId reg_id)
-{
- return(edg_wll_NotifSend(context, reg_id, NULL, 0, "", ""));
-}
-
+++ /dev/null
-#ifndef IL_NOTIFICATION_H
-#define IL_NOTIFICATION_H
-
-/* needed for the edg_wll_NotifId */
-#include "glite/lb/notification.h"
-/* import the edg_wll_JobStat structure */
-#include "glite/lb/jobstat.h"
-
-#ifdef __cplusplus
-#extern "C" {
-#endif
-
-extern char *notif_ilog_socket_path;
-extern char *notif_ilog_file_prefix;
-
-/** Send ULM notification string to interlogger.
- * Stores notification to file according to registration id and send it
- * to interlogger using local socket.
- * \param reg_id registration id
- * \param host,port address to deliver the notification to.
- * If NULL, it means no further notifications will
- * follow (the client has unregistered). It always
- * overrides previous values (ie. changes the
- * reg_id->client address mapping in interlogger).
- * \param owner DN of the registration owner, this will be verified
- * against client's certificate
- * \param notif_data ULM formatted notification string, may be NULL,
- * if there is nothing to be sent to client.
- * \retval 0 OK
- * \retval EINVAL bad jobId, unknown event code, or the format
- * string together with the remaining arguments
- * does not form a valid event
- * \retval ENOSPC unable to accept the event due to lack of disk
- * space etc.
- * \retval ENOMEM failed to allocate memory
- * \retval EAGAIN non blocking return from the call, the event
- * did not come through socket, but is backed up
- * in file
- */
-int
-edg_wll_NotifSend(edg_wll_Context context,
- edg_wll_NotifId reg_id,
- const char *host,
- int port,
- const char *owner,
- const char *notif_data);
-
-
-/** Send job status notification.
- * Creates ULM notification string and sends it using
- * edg_wll_NotifSend(). The job status is encoded into XML and escaped
- * before inclusion into ULM.
- * \param reg_id registration id
- * \param host,port address to deliver the notification to.
- * \param owner DN of the registration owner, this will be verified
- * against client's certificate
- * \param notif_job_stat structure describing job status
- * \see edg_wll_NotifSend()
- */
-int
-edg_wll_NotifJobStatus(edg_wll_Context context,
- edg_wll_NotifId reg_id,
- const char *host,
- int port,
- const char *owner,
- const edg_wll_JobStat notif_job_stat);
-
-
-/** Change address for notification delivery.
- * Creates ULM string and uses edg_wll_NotifSend() to pass it
- * to interlogger.
- * \param reg_id registration id
- * \param host,port new delivery address
- * \see edg_wll_NotifSend()
- */
-int
-edg_wll_NotifChangeDestination(edg_wll_Context context,
- edg_wll_NotifId reg_id,
- const char *host,
- int port);
-
-/** Cancel registration.
- * Creates ULM string and uses edg_wll_NotifSend() to pass it to
- * interlogger.
- * \param reg_id registration id
- */
-int
-edg_wll_NotifCancelRegId(edg_wll_Context context,
- edg_wll_NotifId reg_id);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-
-#include "glite/lb/context-int.h"
-#include "lbs_db.h"
-#include "index.h"
-
-extern int debug;
-
-#define const_len(c) (sizeof((c))-1)
-
-/* TODO:
- - better error recovery (skip unrecognised indices etc.)
- - leaks memory on errors
-*/
-
-int edg_wll_QueryJobIndices(edg_wll_Context ctx,edg_wll_QueryRec *** index_out,char ***keys_out)
-{
- edg_wll_QueryRec **idx = NULL;
- edg_wll_Stmt stmt = NULL;
-
- int i,j,ret;
-
- static const char *built_in_indices[] = {
- "PRIMARY",
- "parent_job",
- NULL
- };
-
-/* XXX: "show index from" columns. Matches at least MySQL 4.0.11 */
-
- char *showcol[12];
- int Key_name,Seq_in_index,Column_name,Sub_part;
-
- char **keys = NULL;
- int *cols = NULL;
- char **col_names = NULL;
-
- int nkeys = 0;
-
- Key_name = Seq_in_index = Column_name = Sub_part = -1;
-
- if (edg_wll_ExecStmt(ctx,"show index from states",&stmt)<0)
- return edg_wll_Error(ctx,NULL,NULL);
-
- while ((ret = edg_wll_FetchRow(stmt,showcol))) {
- if (ret < 0) return edg_wll_Error(ctx,NULL,NULL);
- assert(ret <= sizeof showcol/sizeof showcol[0]);
-
- if (!col_names) {
- col_names = malloc(ret * sizeof col_names[0]);
- edg_wll_QueryColumns(stmt,col_names);
- for (i=0; i<ret; i++)
- if (!strcasecmp(col_names[i],"Key_name")) Key_name = i;
- else if (!strcasecmp(col_names[i],"Seq_in_index")) Seq_in_index = i;
- else if (!strcasecmp(col_names[i],"Column_name")) Column_name = i;
- else if (!strcasecmp(col_names[i],"Sub_part")) Sub_part = i;
-
- assert(Key_name >= 0 && Seq_in_index >= 0 &&
- Column_name >= 0 && Sub_part >= 0);
-
- }
-
-
- for (j=0; built_in_indices[j]; j++) {
- if (strcasecmp(showcol[Key_name],built_in_indices[j]) == 0) {
- for (i=0; i<ret; i++) free(showcol[i]);
- goto continue_fetch_index;
- }
- }
-
- for (i=0; i<nkeys && strcasecmp(showcol[Key_name],keys[i]); i++);
-
- if (i == nkeys) {
- keys = realloc(keys,(i+2) * sizeof keys[0]);
- keys[i] = showcol[Key_name];
- keys[i+1] = NULL;
- cols = realloc(cols,(i+1) * sizeof cols[0]);
- cols[i] = 0;
- idx = realloc(idx,(i+2) * sizeof idx[0]);
- idx[i] = idx[i+1] = NULL;
- showcol[Key_name] = NULL;
- nkeys++;
- }
-
- j = atoi(showcol[Seq_in_index])-1;
- if (cols[i] <= j) {
- cols[i] = j+1;
- idx[i] = realloc(idx[i],(j+2)*sizeof idx[i][0]);
- memset(&idx[i][j+1],0,sizeof idx[i][0]);
- }
-
- if (edg_wll_ColumnToQueryRec(showcol[Column_name],&idx[i][j])) {
- char ed[300];
- sprintf(ed,"%s(%s): unsupported column",keys[i],showcol[Column_name]);
- return edg_wll_SetError(ctx,EINVAL,ed);
- }
- else idx[i][j].value.i = atoi(showcol[Sub_part]);
-
- for (i=0; i<ret; i++) free(showcol[i]);
-continue_fetch_index:
- // just for escaping from nested cycles
- ; /* prevent compiler to complain */
- }
-
- edg_wll_FreeStmt(&stmt);
- free(cols);
- free(col_names);
- if (keys_out) *keys_out = keys; else free(keys);
- *index_out = idx;
-
- return edg_wll_ResetError(ctx);
-}
-
-int edg_wll_CmpColumn(const edg_wll_QueryRec *r1,const edg_wll_QueryRec *r2)
-{
- if (r1->attr != r2->attr) return 1;
- switch (r1->attr) {
- case EDG_WLL_QUERY_ATTR_USERTAG:
- return strcasecmp(r1->attr_id.tag,r2->attr_id.tag);
- case EDG_WLL_QUERY_ATTR_TIME:
- return r1->attr_id.state != r2->attr_id.state;
- default:
- return 0;
- }
-}
-
-static struct {
- const char *name;
- edg_wll_QueryAttr attr;
-} std_attrs[] =
-{
-@@@{
- for my $n ($status->getAllFieldsOrdered) {
- my $f = selectField $status $n;
- next unless $f->{index};
- my $u = uc getName $f;
- gen "\t{ \"$n\", EDG_WLL_QUERY_ATTR_$u },\n";
- }
-@@@}
- { NULL, },
-};
-
-int edg_wll_ColumnToQueryRec(const char *col_name,edg_wll_QueryRec *rec)
-{
- int i;
-
- memset(rec,0,sizeof *rec);
- if (strncasecmp(col_name,STD_PREFIX,const_len(STD_PREFIX)) == 0) {
- for (i=0; std_attrs[i].name
- && strcasecmp(std_attrs[i].name,col_name+const_len(STD_PREFIX)); i++);
-
- if (std_attrs[i].name) rec->attr = std_attrs[i].attr;
- }
- else if (strncasecmp(col_name,TIME_PREFIX,const_len(TIME_PREFIX)) == 0) {
- rec->attr_id.state = edg_wll_StringToStat(col_name+const_len(TIME_PREFIX));
- if (rec->attr_id.state != (edg_wll_JobStatCode) -1) rec->attr = EDG_WLL_QUERY_ATTR_TIME;
- }
- else if (strncasecmp(col_name,USR_PREFIX,const_len(USR_PREFIX)) == 0) {
- rec->attr = EDG_WLL_QUERY_ATTR_USERTAG;
- rec->attr_id.tag = strdup(col_name+const_len(USR_PREFIX));
- rec->value.c = NULL;
- }
-
- return !rec->attr;
-}
-
-char * edg_wll_QueryRecToColumn(const edg_wll_QueryRec *rec)
-{
- char col[100] = "";
-
- if (rec->attr == EDG_WLL_QUERY_ATTR_USERTAG) {
- strcpy(col,USR_PREFIX);
- strcat(col,rec->attr_id.tag);
- }
- else if (rec->attr == EDG_WLL_QUERY_ATTR_TIME) {
- char *s = edg_wll_StatToString(rec->attr_id.state);
-
- if (s) {
- strcpy(col,TIME_PREFIX);
- strcat(col,s);
- free(s);
- }
- }
- else {
- int i;
- for (i=0; std_attrs[i].name && std_attrs[i].attr != rec->attr; i++);
- if (std_attrs[i].name) {
- strcpy(col,STD_PREFIX);
- strcat(col,std_attrs[i].name);
- }
- }
-
- return col[0] ? strdup(col) : NULL;
-}
-
-char * edg_wll_QueryRecToColumnExt(const edg_wll_QueryRec *rec)
-{
- char *intern = edg_wll_QueryRecToColumn(rec),
- *out;
-
- if (!intern) return NULL;
-
- switch (rec->attr) {
- case EDG_WLL_QUERY_ATTR_USERTAG:
- out = strdup(intern+const_len(USR_PREFIX));
- break;
- case EDG_WLL_QUERY_ATTR_TIME:
- out = strdup(intern+const_len(TIME_PREFIX));
- break;
- default:
- out = strdup(intern+const_len(STD_PREFIX));
- break;
- }
- free(intern);
- return out;
-}
-
-void edg_wll_FreeIColumnRec(edg_wll_IColumnRec *icrp)
-{
- if (icrp->qrec.attr == EDG_WLL_QUERY_ATTR_USERTAG)
- free(icrp->qrec.attr_id.tag);
- free(icrp->colname);
-}
-
+++ /dev/null
-%{
-#ident "$Header$"
-
-#include <string.h>
-
-#include "glite/lb/context-int.h"
-#include "index_parse.h"
-#include "index.h"
-
-char *lex_out;
-int lex_int;
-int lex_line;
-
-int yywrap(void) { return 1; }
-
-#define YY_NO_UNPUT
-
-%}
-
-
-delim [ \t]
-ws {delim}+
-string \"[^\"\n]*\"
-digit [0-9]
-int {digit}+
-
-%%
-{ws} {}
-
-JobIndices return JOB_INDICES;
-type return TYPE;
-name return NAME;
-prefixlen return PREFIX;
-{int} {
- lex_int = atoi(yytext);
- return INT;
- }
-{string} {
- int len;
- lex_out = malloc(len = strlen(yytext)-1);
- strncpy(lex_out,yytext+1,len-1);
- lex_out[len-1] = 0;
- return STRING;
- }
-\n lex_line++;
-. return *yytext;
-
+++ /dev/null
-%{
-#ident "$Header$"
-
-
-#include <stdio.h>
-#include <string.h>
-
-#include "glite/lb/context-int.h"
-
-#include "lbs_db.h"
-#include "index.h"
-
-#define yyerror(x) {}
-
-#define YYDEBUG 1
-
-#define ATTR_TYPE_SYSTEM "system"
-#define ATTR_TYPE_USER "user"
-#define ATTR_TYPE_TIME "time"
-
-static edg_wll_Context parse_ctx;
-static const char *parse_fname;
-
-#define bailout(msg) \
-{ \
- char *buf; \
- \
- asprintf(&buf,"%s:%d: %s",parse_fname,lex_line,(msg)); \
- edg_wll_SetError(parse_ctx,EINVAL,buf); \
- free(buf); \
- YYABORT; \
-}
-
-extern FILE *yyin;
-
-edg_wll_QueryRec **indices_out;
-
-%}
-
-%term JOB_INDICES
-%term STRING
-%term INT
-%term TYPE
-%term NAME
-%term PREFIX
-
-%union
-{
- char *s;
- int i;
- edg_wll_QueryRec qr;
- edg_wll_QueryRec *qrl;
- edg_wll_QueryRec **qrll;
- struct elem_attr {
- int attr;
- char *val;
- } attr;
-}
-
-%type <s> string
-%type <i> int
-%type <qr> job_index_elem
-%type <qrl> job_index job_index_elem_list
-%type <qrll> job_index_list job_indices;
-%type <attr> elem_attr opt_elem_attr
-
-%%
-
-config : '[' job_indices soft_semicolon ']' { indices_out = $2; }
- ;
-
-job_indices : JOB_INDICES '=' '{' job_index_list soft_comma '}' { $$ = $4; }
- ;
-
-job_index_list : job_index { $$ = calloc(2,sizeof (*$$)); *$$ = $1; }
- | job_index_list ',' job_index
-{
- int i;
- for (i=0; $1[i]; i++);
- $$ = realloc($1,(i+2) * sizeof *$1);
- $$[i] = $3;
- $$[i+1] = NULL;
-}
- ;
-
-job_index : job_index_elem { $$ = calloc(2,sizeof (*$$)); memcpy($$,&$1,sizeof $1); }
- | '{' job_index_elem_list '}' { $$ = $2; }
- ;
-
-job_index_elem_list : job_index_elem { $$ = calloc(2,sizeof (*$$)); memcpy($$,&$1,sizeof $1); }
- | job_index_elem_list ',' job_index_elem
-{
- int i;
- for (i=0; $1[i].attr; i++);
- $$ = realloc($1,(i+2) * sizeof *$1);
- memcpy($$+i,&$3,sizeof $3);
- memset($$+i+1,0,sizeof *$$);
-}
- ;
-
-job_index_elem : '[' elem_attr ';' elem_attr opt_elem_attr ']'
-{
- char *name = $2.attr == NAME ? $2.val :
- $4.attr == NAME ? $4.val :
- $5.attr == NAME ? $5.val : NULL,
- *type = $2.attr == TYPE ? $2.val :
- $4.attr == TYPE ? $4.val :
- $5.attr == TYPE ? $5.val : NULL;
- int prefix = $2.attr == PREFIX ? (int) $2.val :
- $4.attr == PREFIX ? (int) $4.val :
- $5.attr == PREFIX ? (int) $5.val : 0;
-
-
- if (!name) bailout("`name' required");
- if (!type) bailout("`type' required");
-
- if (strcasecmp(type,ATTR_TYPE_SYSTEM) == 0) {
- char *name2;
- asprintf(&name2,STD_PREFIX "%s",name);
- if (edg_wll_ColumnToQueryRec(name2,&$$)) bailout("unknown attribute");
- free(name2);
- free(name);
- }
- else if (strcasecmp(type,ATTR_TYPE_USER) == 0) {
- $$.attr = EDG_WLL_QUERY_ATTR_USERTAG;
- $$.attr_id.tag = name;
- }
- else if (strcasecmp(type,ATTR_TYPE_TIME) == 0) {
- char *name2;
- if (prefix) bailout("PREFIXLEN is not valid with time attributes");
- asprintf(&name2,TIME_PREFIX "%s",name);
- if (edg_wll_ColumnToQueryRec(name2,&$$)) bailout("unknown attribute");
- free(name2);
- free(name);
- }
- else bailout("unknown attr type");
-
- $$.value.i = prefix;
-}
- ;
-
-elem_attr : TYPE '=' string { $$.attr = TYPE; $$.val = $3; }
- | NAME '=' string { $$.attr = NAME; $$.val = $3; }
- | PREFIX '=' int { $$.attr = PREFIX; $$.val = (char *) $3; }
- ;
-
-opt_elem_attr : { $$.attr = 0; $$.val = NULL; }
- | ';' elem_attr { $$ = $2; }
- ;
-
-string : STRING { $$ = lex_out; lex_out = NULL; }
- ;
-
-int : INT { $$ = lex_int; }
- ;
-
-soft_semicolon :
- | ';'
- ;
-
-soft_comma :
- | ','
- ;
-
-
-%%
-
-
-/* XXX: uses static variables -- non thread-safe */
-
-int edg_wll_ParseIndexConfig(edg_wll_Context ctx,const char *fname,edg_wll_QueryRec ***out)
-{
- yyin = strcmp(fname,"-") ? fopen(fname,"r") : stdin;
- lex_line = 1;
-
- if (!yyin) return edg_wll_SetError(ctx,errno,fname);
-
- parse_ctx = ctx;
- parse_fname = fname;
- edg_wll_ResetError(ctx);
-
- /* yydebug = 1; */
- if (yyparse() && !edg_wll_Error(ctx,NULL,NULL)) {
- char buf[100];
- if (yyin != stdin) fclose(yyin);
- sprintf(buf,"%s:%d: parse error",fname,lex_line);
- return edg_wll_SetError(ctx,EINVAL,buf);
- }
- if (yyin != stdin) fclose(yyin);
-
- if (!edg_wll_Error(ctx,NULL,NULL)) *out = indices_out;
- indices_out = NULL; /* XXX: memory leak on error but who cares? */
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-int edg_wll_DumpIndexConfig(edg_wll_Context ctx,const char *fname,edg_wll_QueryRec * const *idx)
-{
- int haveit = 0;
-
- FILE *f = strcmp(fname,"-") ? fopen(fname,"w") : stdout;
-
- if (!f) return edg_wll_SetError(ctx,errno,fname);
- if (idx && *idx) { haveit = 1; fputs("[\n\tJobIndices = {\n",f); }
-
- while (idx && *idx) {
- const edg_wll_QueryRec *i;
- int multi = (*idx)[1].attr;
-
- fputs(multi ? "\t\t{\n" : "\t\t",f);
-
- for (i=*idx; i->attr; i++) {
- char *cn = edg_wll_QueryRecToColumnExt(i);
- char prefix[100] = "";
- char *type;
-
- switch (i->attr) {
- case EDG_WLL_QUERY_ATTR_USERTAG: type = ATTR_TYPE_USER; break;
- case EDG_WLL_QUERY_ATTR_TIME: type = ATTR_TYPE_TIME; break;
- default: type = ATTR_TYPE_SYSTEM; break;
- }
-
- if (i->value.i) sprintf(prefix,"; prefixlen = %d ",i->value.i);
- if (multi) fputs("\t\t\t",f);
- fprintf(f,"[ type = \"%s\"; name = \"%s\" %s]",type,cn,prefix);
- if (multi) fputs(i[1].attr ? ",\n" : "\n",f);
- free(cn);
- }
-
- if (multi) fputs("\t\t}",f);
- fputs(idx[1] ? ",\n" : "\n",f);
-
- idx++;
- }
-
- if (haveit) {
- fputs("\t}\n]\n",f);
- return edg_wll_ResetError(ctx);
- }
- else return edg_wll_SetError(ctx,ENOENT,"no indices");
-}
-
-
+++ /dev/null
-#ident "$Header$"
-
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <stdarg.h>
-#include <regex.h>
-#include <syslog.h>
-
-#include "glite/lb/producer.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-
-#include "get_events.h"
-#include "store.h"
-#include "lock.h"
-#include "index.h"
-#include "lbs_db.h"
-#include "jobstat.h"
-#include "lb_authz.h"
-#include "stats.h"
-
-#define DAG_ENABLE 1
-
-/* TBD: share in whole logging or workload */
-#ifdef __GNUC__
-#define UNUSED_VAR __attribute__((unused))
-#else
-#define UNUSED_VAR
-#endif
-
-
-#define mov(a,b) { free(a); a = b; b = NULL; }
-
-static void warn (const char* format, ...) UNUSED_VAR ;
-static char *job_owner(edg_wll_Context,char *);
-
-
-int js_enable_store = 1;
-
-/*
- * Basic manipulations with the internal representation of job state
- */
-
-#if 0
-static int eval_expect_update(intJobStat *, int *, char **);
-#endif
-
-static char* matched_substr(char *, regmatch_t) UNUSED_VAR;
-
-static char* matched_substr(char *in, regmatch_t match)
-{
- int len;
- char *s;
-
- len = match.rm_eo - match.rm_so;
- s = calloc(1, len + 1);
- if (s != NULL) {
- strncpy(s, in + (int)match.rm_so, len);
- }
-
- return s;
-}
-
-
-int edg_wll_JobStatus(
- edg_wll_Context ctx,
- const edg_wlc_JobId job,
- int flags,
- edg_wll_JobStat *stat)
-{
-
-/* Local variables */
- char *string_jobid;
- char *md5_jobid;
-
- intJobStat jobstat;
- intJobStat *ijsp;
- int intErr = 0;
- int lockErr;
- edg_wll_Acl acl = NULL;
-#if DAG_ENABLE
- char *stmt = NULL;
-#endif
- char *errdesc = NULL;
- //The following declarations have originally been positioned in the funcion's code
- //That was rather messy and lead to redeclaratios :-(
- char *stat_str, *s_out;
- intJobStat *js;
- char *out[1];
- edg_wll_Stmt sh;
- int num_sub, num_f, i, ii;
-
- edg_wll_ResetError(ctx);
-
- string_jobid = edg_wlc_JobIdUnparse(job);
- if (string_jobid == NULL || stat == NULL)
- return edg_wll_SetError(ctx,EINVAL, NULL);
- md5_jobid = edg_wlc_JobIdGetUnique(job);
-
- if ( !(jobstat.pub.owner = job_owner(ctx,md5_jobid)) ) {
- free(md5_jobid);
- free(string_jobid);
- return edg_wll_Error(ctx,NULL,NULL);
- }
-
- intErr = edg_wll_GetACL(ctx, job, &acl);
- if (intErr) {
- free(md5_jobid);
- free(string_jobid);
- return edg_wll_Error(ctx,NULL,NULL);
- }
-
- /* authorization check */
- if ( !(ctx->noAuth) &&
- (!(ctx->peerName) || strcmp(ctx->peerName, jobstat.pub.owner))) {
- intErr = (acl == NULL) || edg_wll_CheckACL(ctx, acl, EDG_WLL_PERM_READ);
- if (intErr) {
- free(string_jobid);
- free(md5_jobid);
- free(jobstat.pub.owner); jobstat.pub.owner = NULL;
- if (acl) {
- edg_wll_FreeAcl(acl);
- return edg_wll_Error(ctx, NULL, NULL);
- } else {
- return edg_wll_SetError(ctx,EPERM, "not owner, no ACL is set");
- }
- }
- }
-
- intErr = edg_wll_LoadIntState(ctx, job, -1 /*all events*/, &ijsp);
- if (!intErr) {
- *stat = ijsp->pub;
- destroy_intJobStat_extension(ijsp);
- free(ijsp);
-
- } else {
- lockErr = edg_wll_LockJob(ctx,job);
- intErr = edg_wll_intJobStatus(ctx, job, flags,&jobstat, js_enable_store && !lockErr);
- if (intErr) edg_wll_Error(ctx, NULL, &errdesc);
- if (!lockErr) {
- edg_wll_UnlockJob(ctx,job);
- }
-
- *stat = jobstat.pub;
- if (intErr) edg_wll_FreeStatus(&jobstat.pub);
- destroy_intJobStat_extension(&jobstat);
- }
-
- if (intErr) {
- free(string_jobid);
- free(md5_jobid);
- if (acl) edg_wll_FreeAcl(acl);
- edg_wll_SetError(ctx, intErr, errdesc);
- free(errdesc);
- return edg_wll_UpdateError(ctx, EDG_WLL_ERROR_SERVER_RESPONSE, "Could not compute job status from events");
- }
-
- if (acl) {
- stat->acl = strdup(acl->string);
- edg_wll_FreeAcl(acl);
- }
-
- if ((flags & EDG_WLL_STAT_CLASSADS) == 0) {
- char *null = NULL;
-
- mov(stat->jdl, null);
- mov(stat->matched_jdl, null);
- mov(stat->condor_jdl, null);
- mov(stat->rsl, null);
- }
-
-#if DAG_ENABLE
- if (stat->jobtype == EDG_WLL_STAT_DAG || stat->jobtype == EDG_WLL_STAT_COLLECTION) {
-
-// XXX: The users does not want any histogram. What do we do about it?
-// if ((!(flags & EDG_WLL_STAT_CHILDHIST_FAST))&&(!(flags & EDG_WLL_STAT_CHILDHIST_THOROUGH))) { /* No Histogram */
-// if (stat->children_hist != NULL) { /* No histogram will be sent even if there was one */
-//
-// printf("\nNo Histogram required\n\n");
-//
-// free(stat->children_hist);
-// }
-//
-// }
-
-
- if (flags & EDG_WLL_STAT_CHILDSTAT) {
-
- trio_asprintf(&stmt, "SELECT int_status FROM states WHERE parent_job='%|Ss'"
- " AND version='%|Ss'",
- md5_jobid, INTSTAT_VERSION);
- if (stmt != NULL) {
- num_sub = edg_wll_ExecStmt(ctx, stmt, &sh);
- if (num_sub >=0 ) {
- i = 0;
- stat->children_states = calloc(num_sub+1, sizeof(edg_wll_JobStat));
- if (stat->children_states == NULL) {
- edg_wll_FreeStmt(&sh);
- goto dag_enomem;
- }
- while ((num_f = edg_wll_FetchRow(sh, &stat_str)) == 1
- && i < num_sub) {
- js = dec_intJobStat(stat_str, &s_out);
- if (s_out != NULL && js != NULL) {
- stat->children_states[i] = js->pub;
- destroy_intJobStat_extension(js);
- free(js);
- i++; // Careful, this value will also be used further
- }
- free(stat_str);
- }
- edg_wll_FreeStmt(&sh);
- }
- free(stmt);
- } else goto dag_enomem;
- }
-
-
- if (flags & EDG_WLL_STAT_CHILDHIST_THOROUGH) { /* Full (thorough) Histogram */
-
-
- if (stat->children_hist == NULL) {
- stat->children_hist = (int*) calloc(1+EDG_WLL_NUMBER_OF_STATCODES, sizeof(int));
- stat->children_hist[0] = EDG_WLL_NUMBER_OF_STATCODES;
- }
- else {
- /* If hist is loaded, it probably contain only incomplete histogram
- * built in update_parent_status. Count it from scratch...*/
- for (ii=1; ii<=EDG_WLL_NUMBER_OF_STATCODES; ii++)
- stat->children_hist[ii] = 0;
- }
-
- if (flags & EDG_WLL_STAT_CHILDSTAT) { // Job states have already been loaded
- for ( ii = 0 ; ii < i ; ii++ ) {
- stat->children_hist[(stat->children_states[ii].state)+1]++;
- }
- }
- else {
- // Get child states from the database
- trio_asprintf(&stmt, "SELECT status FROM states WHERE parent_job='%|Ss' AND version='%|Ss'",
- md5_jobid, INTSTAT_VERSION);
- out[1] = NULL;
- if (stmt != NULL) {
- num_sub = edg_wll_ExecStmt(ctx, stmt, &sh);
- if (num_sub >=0 ) {
- while ((num_f = edg_wll_FetchRow(sh, out)) == 1 ) {
- num_f = atoi(out[0]);
- if (num_f > EDG_WLL_JOB_UNDEF && num_f < EDG_WLL_NUMBER_OF_STATCODES)
- stat->children_hist[num_f+1]++;
- free(out[0]);
- }
- edg_wll_FreeStmt(&sh);
- }
- free(stmt);
- } else goto dag_enomem;
- }
- }
- else {
- if (flags & EDG_WLL_STAT_CHILDHIST_FAST) { /* Fast Histogram */
-
- if (stat->children_hist == NULL) {
- // If the histogram exists, assume that it was already filled during job state retrieval
- stat->children_hist = (int*) calloc(1+EDG_WLL_NUMBER_OF_STATCODES, sizeof(int));
- edg_wll_GetSubjobHistogram(ctx, job, stat->children_hist);
- }
- }
- else {
- if (stat->children_hist) {
- free (stat->children_hist);
- stat->children_hist = NULL;
- }
- }
-
- }
-
-
- if (flags & EDG_WLL_STAT_CHILDREN) {
-
- trio_asprintf(&stmt, "SELECT j.dg_jobid FROM states s,jobs j "
- "WHERE s.parent_job='%|Ss' AND s.version='%|Ss' AND s.jobid=j.jobid",
- md5_jobid, INTSTAT_VERSION);
- if (stmt != NULL) {
- num_sub = edg_wll_ExecStmt(ctx, stmt, &sh);
- if (num_sub >=0 ) {
- while (edg_wll_FetchRow(sh, out) == 1 ) {
- add_stringlist(&stat->children, out[0]);
- free(out[0]);
- }
- edg_wll_FreeStmt(&sh);
- }
- free(stmt);
- } else goto dag_enomem;
-
- }
-
- }
-#endif
- free(string_jobid);
- free(md5_jobid);
- return edg_wll_Error(ctx, NULL, NULL);
-
-#if DAG_ENABLE
-dag_enomem:
- free(string_jobid);
- free(md5_jobid);
- edg_wll_FreeStatus(stat);
- free(stmt);
- return edg_wll_SetError(ctx, ENOMEM, NULL);
-#endif
-}
-
-int edg_wll_intJobStatus(
- edg_wll_Context ctx,
- const edg_wlc_JobId job,
- int flags,
- intJobStat *intstat,
- int update_db)
-{
-
-/* Local variables */
- char *string_jobid;
- char *md5_jobid;
-
- int num_events;
- edg_wll_Event *events = NULL;
-
- int i, intErr = 0;
- int res;
- int be_strict = 0;
- char *errstring = NULL;
-
- edg_wll_QueryRec jqr[2];
- edg_wll_QueryRec **jqra;
-
-/* Processing */
- edg_wll_ResetError(ctx);
- init_intJobStat(intstat);
-
- string_jobid = edg_wlc_JobIdUnparse(job);
- if (string_jobid == NULL || intstat == NULL)
- return edg_wll_SetError(ctx,EINVAL, NULL);
-
- /* can be already filled by public edg_wll_JobStat() */
- if (intstat->pub.owner == NULL) {
- md5_jobid = edg_wlc_JobIdGetUnique(job);
- if ( !(intstat->pub.owner = job_owner(ctx,md5_jobid)) ) {
- free(md5_jobid);
- free(string_jobid);
- return edg_wll_Error(ctx,NULL,NULL);
- }
- free(md5_jobid);
- }
-
- jqr[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
- jqr[0].op = EDG_WLL_QUERY_OP_EQUAL;
- jqr[0].value.j = job;
- jqr[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
-
- jqra = (edg_wll_QueryRec **) malloc (2 * sizeof(edg_wll_QueryRec **));
- jqra[0] = jqr;
- jqra[1] = NULL;
-
- if (edg_wll_QueryEventsServer(ctx,1, (const edg_wll_QueryRec **)jqra, NULL, &events)) {
- free(string_jobid);
- free(jqra);
- return edg_wll_Error(ctx, NULL, NULL);
- }
- free(jqra);
-
- for (num_events = 0; events[num_events].type != EDG_WLL_EVENT_UNDEF;
- num_events++);
-
- if (num_events == 0) {
- free(string_jobid);
- return edg_wll_SetError(ctx,ENOENT,NULL);
- }
-
- edg_wll_SortEvents(events);
-
- for (i = 0; i < num_events; i++) {
- res = processEvent(intstat, &events[i], i, be_strict, &errstring);
- if (res == RET_FATAL || res == RET_INTERNAL) { /* !strict */
- intErr = 1; break;
- }
- }
- if (intstat->pub.state == EDG_WLL_JOB_UNDEF) {
- intstat->pub.state = EDG_WLL_JOB_UNKNOWN;
- }
-
- free(string_jobid);
-
- for (i=0; i < num_events ; i++) edg_wll_FreeEvent(&events[i]);
- free(events);
-
-
- if (intErr) {
- destroy_intJobStat(intstat);
- return edg_wll_SetError(ctx, EDG_WLL_ERROR_SERVER_RESPONSE, NULL);
- } else {
- /* XXX intstat->pub.expectUpdate = eval_expect_update(intstat, &intstat->pub.expectFrom); */
- intErr = edg_wlc_JobIdDup(job, &intstat->pub.jobId);
- if (!intErr) {
- if (update_db) {
- int tsq = num_events - 1;
- edg_wll_StoreIntState(ctx, intstat, tsq);
- /* recheck
- * intJobStat *reread;
- * edg_wll_LoadIntState(ctx, job, tsq, &reread);
- * destroy_intJobStat(reread);
- */
- }
- }
- return edg_wll_SetError(ctx, intErr, NULL);
- }
-
-}
-
-
-/*
- * Helper for warning printouts
- */
-
-static void warn(const char* format, ...)
-{
- va_list l;
- va_start(l, format);
-
- /*
- fprintf(stderr, "Warning: ");
- vfprintf(stderr, format, l);
- fputc('\n', stderr);
- */
-
- va_end(l);
-}
-
-static char *job_owner(edg_wll_Context ctx,char *md5_jobid)
-{
- char *stmt = NULL,*out = NULL;
- edg_wll_Stmt sh;
- int f = -1;
-
- edg_wll_ResetError(ctx);
- trio_asprintf(&stmt,"select cert_subj from users,jobs "
- "where users.userid = jobs.userid "
- "and jobs.jobid = '%|Ss'",md5_jobid);
-
- if (stmt==NULL) {
- edg_wll_SetError(ctx,ENOMEM, NULL);
- return NULL;
- }
- if (edg_wll_ExecStmt(ctx,stmt,&sh) >= 0) {
- f=edg_wll_FetchRow(sh,&out);
- if (f == 0) {
- if (out) free(out);
- out = NULL;
- edg_wll_SetError(ctx,ENOENT,md5_jobid);
- }
- }
- edg_wll_FreeStmt(&sh);
- free(stmt);
-
- return out;
-}
-
-
-#if 0
-/* XXX went_through went out */
-static int eval_expect_update(intJobStat *js, int* went_through, char **expect_from)
-{
- int em = 0;
- int ft = 0; /* fall through following tests */
-
- if (ft || (went_through[ EDG_WLL_JOB_OUTPUTREADY ] && !js->done_failed)) ft = 1;
- if (ft || (went_through[ EDG_WLL_JOB_DONE ] && !js->done_failed)) ft = 1;
- if (ft || went_through[ EDG_WLL_JOB_CHECKPOINTED ]) ft = 1;
- if (ft || went_through[ EDG_WLL_JOB_RUNNING ]) {
- if (js->pub.node == NULL) em |= EXPECT_MASK_JOBMGR;
- ft = 1;
- }
- if (ft || went_through[ EDG_WLL_JOB_SCHEDULED ]) {
- if (js->pub.jssId == NULL) em |= EXPECT_MASK_JSS;
- if (js->pub.rsl == NULL) em |= EXPECT_MASK_JSS;
- if (js->pub.globusId == NULL) em |= EXPECT_MASK_JOBMGR;
- if (js->pub.localId == NULL) em |= EXPECT_MASK_JOBMGR;
- if (js->pub.jss_jdl == NULL) em |= EXPECT_MASK_RB;
- ft = 1;
- }
- if (ft || went_through[ EDG_WLL_JOB_READY ]) {
- if (js->pub.destination == NULL) em |= EXPECT_MASK_RB;
- ft = 1;
- }
- if (ft || went_through[ EDG_WLL_JOB_SUBMITTED ]) {
- if (js->pub.jdl == NULL) em |= EXPECT_MASK_UI;
- ft = 1;
- }
-
- if (em == 0)
- *expect_from = NULL;
- else {
- asprintf(expect_from, "%s%s%s%s%s%s%s",
- (em & EXPECT_MASK_UI ) ? EDG_WLL_SOURCE_UI : "",
- (em & EXPECT_MASK_UI ) ? " " : "",
- (em & EXPECT_MASK_RB ) ? EDG_WLL_SOURCE_RB : "",
- (em & EXPECT_MASK_RB ) ? " " : "",
- (em & EXPECT_MASK_JSS ) ? EDG_WLL_SOURCE_JSS : "",
- (em & EXPECT_MASK_JSS ) ? " " : "",
- (em & EXPECT_MASK_JOBMGR ) ? EDG_WLL_SOURCE_JOBMGR : ""
- );
- }
-
- return (em == 0) ? 0 : 1;
-}
-#endif
-
-/* XXX more thorough malloc, calloc, and asprintf failure handling */
-/* XXX indexes in {short,long}_fields */
-/* XXX strict mode */
-/* XXX caching */
-
-/*
- * Store current job state to states and status_tags DB tables.
- * Should be called with the job locked.
- */
-
-edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context ctx,
- intJobStat *stat,
- int seq)
-{
- char *jobid_md5, *stat_enc, *parent_md5 = NULL;
- char *stmt;
- edg_wll_TagValue *tagp;
- int update;
- int dbret;
- char *icnames, *icvalues;
-
- update = (seq > 0);
- jobid_md5 = edg_wlc_JobIdGetUnique(stat->pub.jobId);
- stat_enc = enc_intJobStat(strdup(""), stat);
-
- tagp = stat->pub.user_tags;
- if (tagp) {
- while ((*tagp).tag != NULL) {
- trio_asprintf(&stmt, "insert into status_tags"
- "(jobid,seq,name,value) values "
- "('%|Ss',%d,'%|Ss','%|Ss')",
- jobid_md5, seq, (*tagp).tag, (*tagp).value);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
- if (EEXIST == edg_wll_Error(ctx, NULL, NULL)) {
- /* XXX: this should not happen */
- edg_wll_ResetError(ctx);
- tagp++;
- continue;
- }
- else
- goto cleanup;
- }
- tagp++;
- }
- }
-
- parent_md5 = edg_wlc_JobIdGetUnique(stat->pub.parent_job);
- if (parent_md5 == NULL) parent_md5 = strdup("*no parent job*");
-
-
- edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 0, NULL, &icvalues);
-
- trio_asprintf(&stmt,
- "update states set "
- "status=%d,seq=%d,int_status='%|Ss',version='%|Ss'"
- ",parent_job='%|Ss'%s "
- "where jobid='%|Ss'",
- stat->pub.state, seq, stat_enc, INTSTAT_VERSION,
- parent_md5, icvalues,
- jobid_md5);
- free(icvalues);
-
- if ((dbret = edg_wll_ExecStmt(ctx,stmt,NULL)) < 0) goto cleanup;
-
- if (dbret == 0) {
- edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 1, &icnames, &icvalues);
- trio_asprintf(&stmt,
- "insert into states"
- "(jobid,status,seq,int_status,version"
- ",parent_job%s) "
- "values ('%|Ss',%d,%d,'%|Ss','%|Ss','%|Ss'%s)",
- icnames,
- jobid_md5, stat->pub.state, seq, stat_enc,
- INTSTAT_VERSION, parent_md5, icvalues);
- free(icnames); free(icvalues);
-
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup;
- }
-
- if (update) {
- trio_asprintf(&stmt, "delete from states "
- "where jobid ='%|Ss' and ( seq<%d or version !='%|Ss')",
- jobid_md5, seq, INTSTAT_VERSION);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup;
- }
- if (update) {
- trio_asprintf(&stmt, "delete from status_tags "
- "where jobid ='%|Ss' and seq<%d", jobid_md5, seq);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup;
- }
-
-cleanup:
- free(stmt);
- free(jobid_md5); free(stat_enc);
- free(parent_md5);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-
-edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context ctx,
- edg_wlc_JobId jobid,
- char *icnames,
- char *values,
- edg_wll_bufInsert *bi)
-{
- char *stmt = NULL;
-
-/* TODO
- edg_wll_UpdateStatistics(ctx, NULL, e, &jobstat.pub);
- if (ctx->rgma_export) write2rgma_status(&jobstat.pub);
-*/
-
-#ifdef LB_BUF
- if (edg_wll_bufferedInsert(bi, values))
- goto cleanup;
-#else
-
- trio_asprintf(&stmt,
- "insert into states"
- "(jobid,status,seq,int_status,version"
- ",parent_job%s) "
- "values (%s)",
- icnames, values);
-
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto cleanup;
-#endif
-
-cleanup:
- free(stmt);
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-/*
- * Retrieve stored job state from states and status_tags DB tables.
- * Should be called with the job locked.
- */
-
-edg_wll_ErrorCode edg_wll_LoadIntState(edg_wll_Context ctx,
- edg_wlc_JobId jobid,
- int seq,
- intJobStat **stat)
-{
- char *jobid_md5;
- char *stmt;
- edg_wll_Stmt sh;
- char *res, *res_rest;
- int nstates;
-
- edg_wll_ResetError(ctx);
- jobid_md5 = edg_wlc_JobIdGetUnique(jobid);
-
- if (seq == -1) {
- /* any sequence number */
- trio_asprintf(&stmt,
- "select int_status from states "
- "where jobid='%|Ss' and version='%|Ss'",
- jobid_md5, INTSTAT_VERSION);
- } else {
- trio_asprintf(&stmt,
- "select int_status from states "
- "where jobid='%|Ss' and seq='%d' and version='%|Ss'",
- jobid_md5, seq, INTSTAT_VERSION);
- }
-
- if (stmt == NULL) {
- return edg_wll_SetError(ctx, ENOMEM, NULL);
- }
-
- if ((nstates = edg_wll_ExecStmt(ctx,stmt,&sh)) < 0) goto cleanup;
- if (nstates == 0) {
- edg_wll_SetError(ctx,ENOENT,"no state in DB");
- goto cleanup;
- }
- if (edg_wll_FetchRow(sh,&res) < 0) goto cleanup;
-
- *stat = dec_intJobStat(res, &res_rest);
- if (res_rest == NULL) {
- edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_CALL,
- "error decoding DB intJobStatus");
- }
-
- free(res);
-cleanup:
- free(jobid_md5);
- free(stmt); edg_wll_FreeStmt(&sh);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-
-static char* hist_to_string(int * hist)
-{
- int i;
- char *s, *s1;
-
-
- assert(hist[0] == EDG_WLL_NUMBER_OF_STATCODES);
- asprintf(&s, "%s=%d", edg_wll_StatToString(1), hist[2]);
-
- for (i=2; i<hist[0] ; i++) {
- asprintf(&s1, "%s, %s=%d", s, edg_wll_StatToString(i), hist[i+1]);
- free(s); s=s1; s1=NULL;
- }
-
- return s;
-}
-
-#if 0 // should not be needed anymore
-
-/* checks whether parent jobid would generate the same sem.num. */
-/* as children jobid */
-static int dependent_parent_lock(edg_wll_Context ctx, edg_wlc_JobId p,edg_wlc_JobId c)
-{
- int p_id, c_id;
-
- if ((p_id=edg_wll_JobSemaphore(ctx, p)) == -1) return -1;
- if ((c_id=edg_wll_JobSemaphore(ctx, c)) == -1) return -1;
-
- if (p_id == c_id) return 1;
- else return 0;
-}
-#endif
-
-
-static edg_wll_ErrorCode load_parent_intJobStat(edg_wll_Context ctx, intJobStat *cis, intJobStat **pis)
-{
- if (*pis) return edg_wll_Error(ctx, NULL, NULL); // already loaded and locked
-
- if (edg_wll_LockJob(ctx,cis->pub.parent_job)) goto err;
-
- if (edg_wll_LoadIntState(ctx, cis->pub.parent_job, - 1, pis))
- goto err;
-
- assert(*pis); // deadlock would happen with next call of this function
-
-err:
- return edg_wll_Error(ctx, NULL, NULL);
-
-}
-
-
-static int log_collectionState_event(edg_wll_Context ctx, edg_wll_JobStatCode state, enum edg_wll_StatDone_code done_code, intJobStat *cis, intJobStat *pis, edg_wll_Event *ce)
-{
- int ret = 0;
-
- edg_wll_Event *event =
- edg_wll_InitEvent(EDG_WLL_EVENT_COLLECTIONSTATE);
-
- if (ctx->serverIdentity)
- event->any.user = strdup(ctx->serverIdentity);
- else
- event->any.user = strdup("LBProxy");
-
- if (!edg_wll_SetSequenceCode(ctx,pis->last_seqcode,EDG_WLL_SEQ_NORMAL)) {
- ctx->p_source = EDG_WLL_SOURCE_LB_SERVER;
- edg_wll_IncSequenceCode(ctx);
- }
- event->any.seqcode = edg_wll_GetSequenceCode(ctx);
- edg_wlc_JobIdDup(pis->pub.jobId, &(event->any.jobId));
- gettimeofday(&event->any.timestamp,0);
- if (ctx->p_host) event->any.host = strdup(ctx->p_host);
- event->any.level = ctx->p_level;
- event->any.source = EDG_WLL_SOURCE_LB_SERVER;
-
-
- event->collectionState.state = edg_wll_StatToString(state);
- event->collectionState.done_code = done_code;
- event->collectionState.histogram = hist_to_string(pis->pub.children_hist);
- edg_wlc_JobIdDup(cis->pub.jobId, &(event->collectionState.child));
- event->collectionState.child_event = edg_wll_EventToString(ce->any.type);
-
- ret = trans_db_store(ctx, NULL, event, pis);
-
- edg_wll_FreeEvent(event);
- free(event);
-
- return ret;
-}
-
-
-/* called only when childen state changed
- */
-static edg_wll_ErrorCode update_parent_status(edg_wll_Context ctx, edg_wll_JobStatCode old_state, enum edg_wll_StatDone_code old_done_code, intJobStat *cis, edg_wll_Event *ce)
-{
- intJobStat *pis = NULL;
- int update_hist = 0;
-
-
- /* Easy version, where the whole histogram is evolving...
- * not used because of performance reasons
- *
- if (load_parent_intJobStat(ctx, cis, &pis)) goto err;
-
- pis->pub.children_hist[cis->pub.state+1]++;
- if (cis->pub.state == EDG_WLL_JOB_DONE)
- pis->children_done_hist[cis->pub.done_code]++;
- pis->pub.children_hist[old_state+1]--;
- if (old_state == EDG_WLL_JOB_DONE)
- pis->children_done_hist[old_done_code]--;
- edg_wll_StoreSubjobHistogram(ctx, cis->pub.parent_job, pis);
- */
-
-
- // XXX: if load_parent_intJobStat occure (and survives in future) in each subcase
- // load parent status at the beginning of this function
-
- /* Increment histogram for interesting states and
- * cook artificial events to enable parent job state shift
- */
- switch (cis->pub.state) {
- case EDG_WLL_JOB_RUNNING:
- if (load_parent_intJobStat(ctx, cis, &pis)) goto err;
- pis->pub.children_hist[cis->pub.state+1]++;
-
- if (pis->pub.jobtype == EDG_WLL_STAT_COLLECTION) {
- /* not RUNNING yet? */
- if (pis->pub.state < EDG_WLL_JOB_RUNNING) {
- if (log_collectionState_event(ctx, cis->pub.state, 0, cis, pis, ce))
- goto err;
- }
- }
- update_hist = 1;
- break;
- case EDG_WLL_JOB_DONE:
- if (load_parent_intJobStat(ctx, cis, &pis)) goto err;
- pis->pub.children_hist[cis->pub.state+1]++;
- pis->children_done_hist[cis->pub.done_code]++;
-
- if (pis->pub.jobtype == EDG_WLL_STAT_COLLECTION) {
- if (pis->pub.children_hist[cis->pub.state+1] == pis->pub.children_num) {
- /* not DONE yet? */
- if (pis->pub.state < EDG_WLL_JOB_DONE) {
- if (log_collectionState_event(ctx, cis->pub.state,
- cis->pub.done_code, cis, pis, ce))
- goto err;
- }
- }
- }
- update_hist = 1;
- break;
- case EDG_WLL_JOB_CLEARED:
- if (load_parent_intJobStat(ctx, cis, &pis)) goto err;
- pis->pub.children_hist[cis->pub.state+1]++;
-
- if (pis->pub.jobtype == EDG_WLL_STAT_COLLECTION) {
- if (pis->pub.children_hist[cis->pub.state+1] == pis->pub.children_num) {
- /* not CLEARED yet? */
- if (pis->pub.state < EDG_WLL_JOB_CLEARED) {
- if (log_collectionState_event(ctx, cis->pub.state,
- cis->pub.done_code, cis, pis, ce))
- goto err;
- }
- }
- }
- update_hist = 1;
- break;
- default:
- if (load_parent_intJobStat(ctx, cis, &pis)) goto err;
- pis->pub.children_hist[EDG_WLL_JOB_UNKNOWN+1]++;
- // update_hist = 1; - triggered by the next case or not needed
- break;
- }
-
-
- /* Decrement histogram for interesting states
- */
- switch (old_state) {
- case EDG_WLL_JOB_RUNNING:
- if (load_parent_intJobStat(ctx, cis, &pis)) goto err;
- pis->pub.children_hist[old_state+1]--;
- update_hist = 1;
- break;
- case EDG_WLL_JOB_DONE:
- if (load_parent_intJobStat(ctx, cis, &pis)) goto err;
- pis->pub.children_hist[old_state+1]--;
- pis->children_done_hist[old_done_code]--;
- update_hist = 1;
- break;
- case EDG_WLL_JOB_CLEARED:
- if (load_parent_intJobStat(ctx, cis, &pis)) goto err;
- pis->pub.children_hist[old_state+1]--;
- update_hist = 1;
- break;
- default:
- if (load_parent_intJobStat(ctx, cis, &pis)) goto err;
- pis->pub.children_hist[EDG_WLL_JOB_UNKNOWN+1]--;
- // update_hist = 1; - triggered by the previous case or not needed
- break;
- }
-
- if (update_hist)
- edg_wll_StoreSubjobHistogram(ctx, cis->pub.parent_job, pis);
-
-err:
- edg_wll_UnlockJob(ctx,cis->pub.parent_job);
-
- if (pis)
- destroy_intJobStat(pis);
-
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-
-/*
- * update stored state according to the new event
- * (must be called with the job locked)
- */
-
-edg_wll_ErrorCode edg_wll_StepIntStateParent(edg_wll_Context ctx,
- edg_wlc_JobId job,
- edg_wll_Event *e,
- int seq,
- intJobStat *ijsp,
- edg_wll_JobStat *stat_out)
-{
- int res;
- int be_strict = 0;
- char *errstring = NULL;
- edg_wll_JobStat oldstat;
- char *oldstat_rgmaline = NULL;
-
-
- memset(&oldstat,0,sizeof oldstat);
-
- edg_wll_CpyStatus(&ijsp->pub,&oldstat);
-
- if (ctx->rgma_export) oldstat_rgmaline = write2rgma_statline(&ijsp->pub);
-
- res = processEvent(ijsp, e, seq, be_strict, &errstring);
- if (res == RET_FATAL || res == RET_INTERNAL) { /* !strict */
- edg_wll_FreeStatus(&oldstat);
- return edg_wll_SetError(ctx, EINVAL, errstring);
- }
- // XXX: store it in update_parent status ??
- edg_wll_StoreIntState(ctx, ijsp, seq);
-
- edg_wll_UpdateStatistics(ctx,&oldstat,e,&ijsp->pub);
-
- if (ctx->rgma_export) write2rgma_chgstatus(&ijsp->pub, oldstat_rgmaline);
-
- if (stat_out) {
- edg_wll_CpyStatus(&ijsp->pub, stat_out);
- }
- edg_wll_FreeStatus(&oldstat);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-
-/*
- * update stored state according to the new event
- * (must be called with the job locked)
-
- * XXX: job is locked on entry, unlocked in this function
- */
-
-edg_wll_ErrorCode edg_wll_StepIntState(edg_wll_Context ctx,
- edg_wlc_JobId job,
- edg_wll_Event *e,
- int seq,
- edg_wll_JobStat *stat_out)
-{
- intJobStat *ijsp;
- int flags = 0;
- int res;
- int be_strict = 0;
- char *errstring = NULL;
- intJobStat jobstat;
- edg_wll_JobStat oldstat;
- char *oldstat_rgmaline = NULL;
-
-
- memset(&oldstat,0,sizeof oldstat);
-
- if (!edg_wll_LoadIntState(ctx, job, seq - 1, &ijsp)) {
- edg_wll_CpyStatus(&ijsp->pub,&oldstat);
-
- if (ctx->rgma_export) oldstat_rgmaline = write2rgma_statline(&ijsp->pub);
-
- res = processEvent(ijsp, e, seq, be_strict, &errstring);
- if (res == RET_FATAL || res == RET_INTERNAL) { /* !strict */
- edg_wll_FreeStatus(&oldstat);
- edg_wll_UnlockJob(ctx,job); /* XXX: error lost */
- return edg_wll_SetError(ctx, EINVAL, errstring);
- }
- edg_wll_StoreIntState(ctx, ijsp, seq);
- if (edg_wll_UnlockJob(ctx,job)) goto err;
-
- edg_wll_UpdateStatistics(ctx,&oldstat,e,&ijsp->pub);
-
- /* check whether subjob state change does not change parent state */
- if ((ijsp->pub.parent_job) && (oldstat.state != ijsp->pub.state)) {
- if (update_parent_status(ctx, oldstat.state, oldstat.done_code, ijsp, e))
- return edg_wll_SetError(ctx, EINVAL, "update_parent_status()");
- }
-
- if (ctx->rgma_export) write2rgma_chgstatus(&ijsp->pub, oldstat_rgmaline);
-
- if (stat_out) {
- memcpy(stat_out,&ijsp->pub,sizeof *stat_out);
- destroy_intJobStat_extension(ijsp);
- }
- else destroy_intJobStat(ijsp);
- free(ijsp);
- edg_wll_FreeStatus(&oldstat);
- }
- else if (!edg_wll_intJobStatus(ctx, job, flags,&jobstat, js_enable_store))
- {
- /* FIXME: we miss state change in the case of seq != 0
- * Does anybody care? */
-
- /* FIXME: collection parent status is wrong in this case.
- However, it should not happen (frequently).
- Right approach is computing parent status from scratch.
- */
-
- if (edg_wll_UnlockJob(ctx,job)) goto err;
- edg_wll_UpdateStatistics(ctx,NULL,e,&jobstat.pub);
-
- if (ctx->rgma_export) write2rgma_status(&jobstat.pub);
-
- if (stat_out) {
- memcpy(stat_out,&jobstat.pub,sizeof *stat_out);
- destroy_intJobStat_extension(&jobstat);
- }
- else destroy_intJobStat(&jobstat);
- }
- else edg_wll_UnlockJob(ctx,job);
-err:
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context ctx, edg_wlc_JobId parent_jobid, int *hist)
-{
-
- char *stmt = NULL,*out = NULL, *rest = NULL;
- edg_wll_Stmt sh;
- int f = -1, i;
- char *jobid_md5;
- intJobStat *ijs = NULL;
-
- jobid_md5 = edg_wlc_JobIdGetUnique(parent_jobid);
-
- edg_wll_ResetError(ctx);
- trio_asprintf(&stmt,"select int_status from states where (jobid='%|Ss') AND (version='%|Ss')", jobid_md5, INTSTAT_VERSION);
-
- free(jobid_md5);
-
- if (stmt==NULL) {
- return edg_wll_SetError(ctx,ENOMEM, NULL);
- }
-
- if (edg_wll_ExecStmt(ctx,stmt,&sh) >= 0) {
- f=edg_wll_FetchRow(sh,&out);
- if (f == 0) {
- if (out) free(out);
- out = NULL;
- edg_wll_SetError(ctx, ENOENT, NULL);
- }
- else {
- // Ready to read the histogram from the record returned
- rest = (char *)calloc(1,strlen(out));
- ijs = dec_intJobStat(out, &rest);
- for (i=0;i<=EDG_WLL_NUMBER_OF_STATCODES;i++) hist[i] = ijs->pub.children_hist[i];
- }
- }
- edg_wll_FreeStmt(&sh);
- free(stmt);
- if (rest==NULL) free(rest);
- if (ijs==NULL) free(rest);
-
-
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-/* Make a histogram of all subjobs belonging to the parent job */
-
-edg_wll_ErrorCode edg_wll_StoreSubjobHistogram(edg_wll_Context ctx, edg_wlc_JobId parent_jobid, intJobStat *ijs)
-{
- char *stat_enc = NULL;
- char *stmt;
- int dbret;
- char *jobid_md5;
-
- stat_enc = enc_intJobStat(strdup(""), ijs);
-
- jobid_md5 = edg_wlc_JobIdGetUnique(parent_jobid);
-
- trio_asprintf(&stmt,
- "update states set "
- "status=%d,int_status='%|Ss',version='%|Ss'"
- "where jobid='%|Ss'",
- ijs->pub.state, stat_enc, INTSTAT_VERSION, jobid_md5);
-
- free(jobid_md5);
-
- if (stmt==NULL) {
- return edg_wll_SetError(ctx,ENOMEM, NULL);
- }
-
-//printf ("\n\n\n Would like to run SQL statament: %s\n\n\n\n", stmt);
-
- if ((dbret = edg_wll_ExecStmt(ctx,stmt,NULL)) < 0) goto cleanup;
-
- assert(dbret); /* update should come through OK as the record exists */
-
-cleanup:
- free(stmt);
- free(stat_enc);
-
- return edg_wll_Error(ctx, NULL, NULL);
-
-}
-
-
+++ /dev/null
-/* $Header$ */
-
-#ifndef _LBS_JOBSTAT_H
-#define _LBS_JOBSTAT_H
-
-
-#include "lbs_db.h"
-
-/*
- * Internal representation of job state
- * (includes edg_wll_JobStat API structure)
- */
-
-#define INTSTAT_VERSION "release-3.2.1_pbs"
-
-
-// Internal error codes
-
-#define RET_FAIL 0
-#define RET_OK 1
-#define RET_FATAL RET_FAIL
-#define RET_SOON 2
-#define RET_LATE 3
-#define RET_BADSEQ 4
-#define RET_SUSPECT 5
-#define RET_IGNORE 6
-#define RET_BADBRANCH 7
-#define RET_GOODBRANCH 8
-#define RET_TOOOLD 9
-#define RET_UNREG 10
-#define RET_INTERNAL 100
-
-
-// shallow resubmission container - holds state of each branch
-// (useful when state restore is needed after ReallyRunning event)
-//
-typedef struct _branch_state {
- int branch;
- char *destination;
- char *ce_node;
- char *jdl;
-} branch_state;
-
-
-typedef struct _intJobStat {
- edg_wll_JobStat pub;
- int resubmit_type;
- char *last_seqcode;
- char *last_cancel_seqcode;
- char *branch_tag_seqcode;
- char *last_branch_seqcode;
- char *deep_resubmit_seqcode;
- branch_state *branch_states; // branch zero terminated array
-
-/* int expect_mask; */
- int children_done_hist[EDG_WLL_NUMBER_OF_DONE_CODES];
- struct timeval last_pbs_event_timestamp;
- int pbs_reruning; // true if rerun event arrived
- } intJobStat;
-
-typedef enum _edg_wll_PBSEventSource {
- EDG_WLL_PBS_EVENT_SOURCE_UNDEF = 0,
- EDG_WLL_PBS_EVENT_SOURCE_SCHEDULER,
- EDG_WLL_PBS_EVENT_SOURCE_SERVER,
- EDG_WLL_PBS_EVENT_SOURCE_MOM,
- EDG_WLL_PBS_EVENT_SOURCE_ACCOUNTING,
- EDG_WLL_PBS_EVENT_SOURCE__LAST
-} edg_wll_PBSEventSource;
-
-typedef enum _edg_wll_CondorEventSource {
- EDG_WLL_CONDOR_EVENT_SOURCE_UNDEF = 0,
- EDG_WLL_CONDOR_EVENT_SOURCE_COLLECTOR,
- EDG_WLL_CONDOR_EVENT_SOURCE_MASTER,
- EDG_WLL_CONDOR_EVENT_SOURCE_MATCH,
- EDG_WLL_CONDOR_EVENT_SOURCE_NEGOTIATOR,
- EDG_WLL_CONDOR_EVENT_SOURCE_SCHED,
- EDG_WLL_CONDOR_EVENT_SOURCE_SHADOW,
- EDG_WLL_CONDOR_EVENT_SOURCE_STARTER,
- EDG_WLL_CONDOR_EVENT_SOURCE_START,
- EDG_WLL_CONDOR_EVENT_SOURCE_JOBQUEUE,
- EDG_WLL_CONDOR_EVENT_SOURCE__LAST
-} edg_wll_CondorEventSource;
-
-void destroy_intJobStat(intJobStat *);
-void destroy_intJobStat_extension(intJobStat *p);
-
-
-edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context, void *, intJobStat *, int , char **, char **);
-edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context, void *);
-int edg_wll_intJobStatus( edg_wll_Context, const edg_wlc_JobId, int, intJobStat *, int);
-edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context, intJobStat *, int);
-edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context, edg_wlc_JobId, char *icnames, char *values, edg_wll_bufInsert *bi);
-edg_wll_ErrorCode edg_wll_LoadIntState(edg_wll_Context , edg_wlc_JobId , int, intJobStat **);
-
-edg_wll_ErrorCode edg_wll_StepIntStateParent(edg_wll_Context,edg_wlc_JobId,edg_wll_Event *,int,intJobStat *,edg_wll_JobStat *);
-
-
-
-intJobStat* dec_intJobStat(char *, char **);
-char *enc_intJobStat(char *, intJobStat* );
-
-void write2rgma_status(edg_wll_JobStat *);
-void write2rgma_chgstatus(edg_wll_JobStat *, char *);
-char* write2rgma_statline(edg_wll_JobStat *);
-
-int before_deep_resubmission(const char *, const char *);
-int same_branch(const char *, const char *);
-int component_seqcode(const char *a, edg_wll_Source index);
-char * set_component_seqcode(char *s,edg_wll_Source index,int val);
-int processEvent(intJobStat *, edg_wll_Event *, int, int, char **);
-int processEvent_PBS(intJobStat *, edg_wll_Event *, int, int, char **);
-int processEvent_Condor(intJobStat *, edg_wll_Event *, int, int, char **);
-
-int add_stringlist(char ***, const char *);
-int edg_wll_compare_seq(const char *, const char *);
-int edg_wll_compare_pbs_seq(const char *,const char *);
-#define edg_wll_compare_condor_seq edg_wll_compare_pbs_seq
-edg_wll_PBSEventSource get_pbs_event_source(const char *pbs_seq_num);
-edg_wll_CondorEventSource get_condor_event_source(const char *pbs_seq_num);
-
-void init_intJobStat(intJobStat *p);
-
-edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context, edg_wlc_JobId parent_jobid, int *hist);
-edg_wll_ErrorCode edg_wll_StoreSubjobHistogram(edg_wll_Context, edg_wlc_JobId parent_jobid, intJobStat *ijs);
-
-#endif
+++ /dev/null
-#ident "$Header$"
-
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <stdarg.h>
-#include <regex.h>
-#include <syslog.h>
-
-#include "glite/wmsutils/jobid/cjobid.h"
-#include "glite/lb/producer.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-
-#include "store.h"
-#include "index.h"
-#include "lbs_db.h"
-#include "jobstat.h"
-#include "get_events.h"
-
-
-/* TBD: share in whole logging or workload */
-#ifdef __GNUC__
-#define UNUSED_VAR __attribute__((unused))
-#else
-#define UNUSED_VAR
-#endif
-
-static char* enc_strlist(char *, char **) UNUSED_VAR;
-static char **dec_strlist(char *, char **) UNUSED_VAR;
-
-/*
- * string encoding routines for safe DB store
- */
-
-static char *enc_string(char *old, char *item)
-{
- char *out;
- if (item == NULL) {
- asprintf(&out,"%s-1 ", old);
- } else {
- asprintf(&out,"%s%ld %s",old, (long)strlen(item), item);
- }
- free(old);
- return out;
-}
-
-static char *dec_string(char *in, char **rest)
-{
- int scret;
- long len = -1;
- char *out;
-
- scret = sscanf(in, "%ld", &len);
- if (scret < 1) {
- *rest = NULL;
- return NULL;
- }
- if (len == -1) {
- out = NULL;
- *rest = strchr(in, ' ') ? strchr(in, ' ') + 1 : NULL;
- } else {
- in = strchr(in, ' ') ? strchr(in, ' ') + 1 : NULL;
- out = (char *)malloc(len+1);
- if (out) {
- memcpy(out, in, len);
- *(out+len) = '\0';
- }
- *rest = in+len;
- }
- return out;
-}
-
-static char *enc_int(char *old, int item)
-{
- char *out;
- asprintf(&out,"%s%d ", old, item);
- free(old);
- return out;
-}
-
-static char *enc_int_array(char *old, int *item, int itemsNo)
-{
- char *out;
- int index;
- char *strpom;
-
- strpom=(char*)calloc(strlen(old)+1,sizeof(char));
-
- for (index=0; index <= itemsNo; index++) sprintf(strpom,"%s%d%s", strpom, item[index],index==itemsNo?"":";");
-
- asprintf(&out,"%s%s ", old, strpom);
- free(strpom);
- free(old);
-
- return out;
-}
-
-static int dec_int(char* in, char **rest)
-{
- int scret;
- int out;
-
- scret = sscanf(in, "%d", &out);
- if (scret == 1) {
- *rest = strchr(in, ' ') ? strchr(in, ' ') + 1 : NULL;
- } else {
- out = 0;
- *rest = in;
- }
- return out;
-}
-
-static int dec_int_array(char* in, char **rest, int *out) // Returns the number of items found in the array
-{
- int charNo, itemsNo = 0, cindex, iindex = 0, lenindex;
- char *tempstr;
-
- /* Find out the number of items in the field first */
-
- for (charNo = 0;charNo<strlen(in);charNo++) {
- if (in[charNo] == ' ') { /* Only ' ' (space) is accepted as a separator. Should not be a broblem. */
- itemsNo++;
- break;
- }
- if (in[charNo] == ';') {
- itemsNo++;
- }
- }
- if (!itemsNo) { /* No separator has been found. This is the last input string */
- itemsNo = 1; /* - consider it an one-item array */
- *rest = NULL;
- }
- else *rest = in + charNo + 1;
-
- tempstr = (char*)calloc(charNo+1,sizeof(char));
-
- strcpy(tempstr,"");
-
- for (cindex = 0; cindex<charNo; cindex++) {
- if ((in[cindex] == ';') || (in[cindex] == ' ')) {
- out[iindex] = atoi(tempstr);
- strcpy(tempstr,"");
- iindex++;
- }
- else {
- lenindex=strlen(tempstr);
- tempstr[lenindex]=in[cindex];
- tempstr[lenindex+1]=0;
- }
- }
- if (in[cindex] != ' ') out[iindex] = atoi(tempstr); /* string not terminated with a separator */
-
- free(tempstr);
- *rest = in + charNo + 1;
-
- return itemsNo;
-}
-
-
-static char* enc_jobid(char *old, edg_wlc_JobId item)
-{
- char *str;
- char *out;
-
- str = edg_wlc_JobIdUnparse(item);
- out = enc_string(old, str);
- free(str);
- return out;
-}
-static edg_wlc_JobId dec_jobid(char *in, char **rest)
-{
- char *str;
- edg_wlc_JobId jobid;
-
- str = dec_string(in, rest);
- if (str == NULL) return NULL;
- edg_wlc_JobIdParse(str, &jobid);
- free(str);
- return jobid;
-}
-
-static char* enc_strlist(char *old, char **item)
-{
- char *ret;
-
- if (item == NULL) {
- asprintf(&ret,"%s-1 ", old);
- free(old);
- return ret;
- } else {
- asprintf(&ret,"%s1 ",old);
- free(old);
- if (ret == NULL) return ret;
- }
- do {
- ret = enc_string(ret, *item);
- } while (*(item++) != NULL);
- return ret;
-}
-
-static char **dec_strlist(char *in, char **rest)
-{
- char **out;
- int len = -1;
- char *tmp_in, *tmp_ret;
- int scret;
-
- scret = sscanf(in, "%d", &len);
- if (scret < 1) {
- *rest = NULL;
- return NULL;
- }
- if (len == -1) {
- *rest = strchr(in, ' ') ? strchr(in, ' ') + 1 : NULL;
- return NULL;
- }
-
- len = 0;
- tmp_in = in = strchr(in, ' ') + 1 ;
- do {
- tmp_ret = dec_string(tmp_in, &tmp_in);
- len++;
- } while (tmp_ret != NULL);
-
- out = (char**) malloc(len*sizeof(char*));
-
- if (out) {
- len = 0;
- tmp_in = in;
- do {
- out[len] = dec_string(tmp_in, &tmp_in);
- } while (out[len++] != NULL);
- }
- *rest = tmp_in;
- return out;
-}
-
-static char *enc_branch_states(char *old, branch_state *item)
-{
- char *ret;
-
- if (item == NULL) {
- asprintf(&ret,"%s-1 ", old);
- free(old);
- return ret;
- } else {
- asprintf(&ret,"%s1 ",old);
- free(old);
- if (ret == NULL) return ret;
- }
- do {
- ret = enc_int(ret, (*item).branch);
- ret = enc_string(ret, (*item).destination);
- ret = enc_string(ret, (*item).ce_node);
- ret = enc_string(ret, (*item).jdl);
- } while ((*(item++)).branch != 0);
- return ret;
-}
-
-static branch_state *dec_branch_states(char *in, char **rest)
-{
- branch_state *out;
- int len = -1, b = 0;
- char *tmp_in, *tmp_ret;
- int scret;
-
- scret = sscanf(in, "%d", &len);
- if (scret < 1) {
- *rest = NULL;
- return NULL;
- }
- if (len == -1) {
- *rest = strchr(in, ' ') ? strchr(in, ' ') + 1 : NULL;
- return NULL;
- }
-
- len = 0;
- tmp_in = in = strchr(in, ' ') + 1 ;
- do {
- b = dec_int(tmp_in, &tmp_in);
- tmp_ret = dec_string(tmp_in, &tmp_in); free(tmp_ret);
- if (!tmp_in) { *rest = tmp_in; return NULL; }
- tmp_ret = dec_string(tmp_in, &tmp_in); free(tmp_ret);
- if (!tmp_in) { *rest = tmp_in; return NULL; }
- tmp_ret = dec_string(tmp_in, &tmp_in); free(tmp_ret);
- if (!tmp_in) { *rest = tmp_in; return NULL; }
- len++;
- } while (b != 0);
-
- out = (branch_state *) calloc(len+1, sizeof(branch_state));
-
- if (out) {
- len = 0;
- tmp_in = in;
-
- do {
- out[len].branch = dec_int(tmp_in, &tmp_in);
- out[len].destination = dec_string(tmp_in, &tmp_in);
- out[len].ce_node = dec_string(tmp_in, &tmp_in);
- out[len].jdl = dec_string(tmp_in, &tmp_in);
- } while (out[len++].branch != 0);
- *rest = tmp_in;
- }
- else
- *rest = 0;
-
- return out;
-
-}
-
-static char* enc_taglist(char *old, edg_wll_TagValue *item)
-{
- char *ret;
-
- if (item == NULL) {
- asprintf(&ret,"%s-1 ", old);
- free(old);
- return ret;
- } else {
- asprintf(&ret,"%s1 ",old);
- free(old);
- if (ret == NULL) return ret;
- }
- do {
- ret = enc_string(ret, (*item).tag);
- ret = enc_string(ret, (*item).value);
- } while ((*(item++)).tag != NULL);
- return ret;
-}
-
-static edg_wll_TagValue *dec_taglist(char *in, char **rest)
-{
- edg_wll_TagValue *out;
- int len = -1;
- char *tmp_in, *tmp_ret;
- int scret, end = 0;
-
- scret = sscanf(in, "%d", &len);
- if (scret < 1) {
- *rest = NULL;
- return NULL;
- }
- if (len == -1) {
- *rest = strchr(in, ' ') ? strchr(in, ' ') + 1 : NULL;
- return NULL;
- }
-
- len = 0;
- tmp_in = in = strchr(in, ' ') + 1 ;
- do {
- tmp_ret = dec_string(tmp_in, &tmp_in);
- if (tmp_ret) free(tmp_ret);
- else end = 1;
- if (!tmp_in) { *rest = tmp_in; return NULL; }
- tmp_ret = dec_string(tmp_in, &tmp_in);
- free(tmp_ret);
- if (!tmp_in) { *rest = tmp_in; return NULL; }
- len++;
- } while (!end);
-
- out = (edg_wll_TagValue *) malloc(len*sizeof(edg_wll_TagValue));
-
- if (out) {
- len = 0;
- tmp_in = in;
-
- do {
- out[len].tag = dec_string(tmp_in, &tmp_in);
- out[len].value = dec_string(tmp_in, &tmp_in);
- } while (out[len++].tag != NULL);
- *rest = tmp_in;
- }
- else
- *rest = 0;
-
- return out;
-}
-
-static char *enc_intlist(char *old, int *item)
-{
- int len;
- char *ret;
-
- if (item == NULL) {
- asprintf(&ret,"%s-1 ", old);
- free(old);
- return ret;
- } else {
- asprintf(&ret,"%s1 ",old);
- free(old);
- if (ret == NULL) return ret;
- }
- len = *item; item++;
- ret = enc_int(ret, len);
- for (; len > 0 ; len--, item++) {
- ret = enc_int(ret, *item);
- }
-
- return ret;
-}
-
-static int *dec_intlist(char *in, char **rest)
-{
- int len = -1;
- int *out, *ptr;
- char *tmp_in;
- int scret;
-
- scret = sscanf(in, "%d", &len);
- if (scret < 1) {
- *rest = NULL;
- return NULL;
- }
- tmp_in = strchr(in, ' ') ? strchr(in, ' ') + 1 : NULL;
- if (len == -1 || tmp_in == NULL) {
- *rest = tmp_in;
- return NULL;
- }
-
- len = dec_int(tmp_in, &tmp_in);
- out = (int *)malloc( (len+1) *sizeof(int));
- if (out) {
- *out = len;
- ptr = out+1;
- while (len) {
- *ptr = dec_int(tmp_in, &tmp_in);
- len--; ptr++;
- }
- }
- *rest = tmp_in;
- return out;
-}
-
-static char* enc_timeval(char *old, struct timeval item)
-{
- char *ret;
-
- ret = enc_int(old, (int)item.tv_sec);
- if (ret) {
- ret = enc_int(ret, (int)item.tv_usec);
- }
- return ret;
-}
-
-static struct timeval dec_timeval(char *in, char **rest)
-{
- struct timeval t;
- char *tmp_in;
-
- t.tv_sec = dec_int(in, &tmp_in);
- if (tmp_in != NULL) t.tv_usec = dec_int(tmp_in, &tmp_in);
- *rest = tmp_in;
- return t;
-}
-
-static char *enc_JobStat(char *old, edg_wll_JobStat* stat)
-{
- char *ret;
-
- ret = enc_int(old, stat->state);
- if (ret) ret = enc_jobid(ret, stat->jobId);
- if (ret) ret = enc_string(ret, stat->owner);
- if (ret) ret = enc_int(ret, stat->jobtype);
- if (ret) ret = enc_jobid(ret, stat->parent_job);
- if (ret) ret = enc_string(ret, stat->seed);
- if (ret) ret = enc_int(ret, stat->children_num);
- /* children histogram also stored in the DB, see bellow. Other children data not stored. */
- if (ret) ret = enc_string(ret, stat->condorId);
- if (ret) ret = enc_string(ret, stat->globusId);
- if (ret) ret = enc_string(ret, stat->localId);
- if (ret) ret = enc_string(ret, stat->jdl);
- if (ret) ret = enc_string(ret, stat->matched_jdl);
- if (ret) ret = enc_string(ret, stat->destination);
- if (ret) ret = enc_string(ret, stat->condor_jdl);
- if (ret) ret = enc_string(ret, stat->rsl);
- if (ret) ret = enc_string(ret, stat->reason);
- if (ret) ret = enc_string(ret, stat->location);
- if (ret) ret = enc_string(ret, stat->ce_node);
- if (ret) ret = enc_string(ret, stat->network_server);
- if (ret) ret = enc_int(ret, stat->subjob_failed);
- if (ret) ret = enc_int(ret, stat->done_code);
- if (ret) ret = enc_int(ret, stat->exit_code);
- if (ret) ret = enc_int(ret, stat->resubmitted);
- if (ret) ret = enc_int(ret, stat->cancelling);
- if (ret) ret = enc_string(ret, stat->cancelReason);
- if (ret) ret = enc_int(ret, stat->cpuTime);
- if (ret) ret = enc_taglist(ret, stat->user_tags);
- if (ret) ret = enc_timeval(ret, stat->stateEnterTime);
- if (ret) ret = enc_intlist(ret, stat->stateEnterTimes);
- if (ret) ret = enc_timeval(ret, stat->lastUpdateTime);
- if (ret) ret = enc_int(ret, stat->expectUpdate);
- if (ret) ret = enc_string(ret, stat->expectFrom);
- if (ret) ret = enc_int(ret, stat->payload_running);
- if (ret) ret = enc_strlist(ret, stat->possible_destinations);
- if (ret) ret = enc_strlist(ret, stat->possible_ce_nodes);
- if (ret) ret = enc_int_array(ret, stat->children_hist, EDG_WLL_NUMBER_OF_STATCODES);
- if (ret) ret = enc_string(ret, stat->pbs_state);
- if (ret) ret = enc_string(ret, stat->pbs_queue);
- if (ret) ret = enc_string(ret, stat->pbs_owner);
- if (ret) ret = enc_string(ret, stat->pbs_name);
- if (ret) ret = enc_string(ret, stat->pbs_reason);
- if (ret) ret = enc_string(ret, stat->pbs_scheduler);
- if (ret) ret = enc_string(ret, stat->pbs_dest_host);
- if (ret) ret = enc_int(ret, stat->pbs_pid);
- if (ret) ret = enc_int(ret, stat->pbs_exit_status);
- if (ret) ret = enc_string(ret, stat->pbs_error_desc);
-
- return ret;
-}
-static edg_wll_JobStat* dec_JobStat(char *in, char **rest)
-{
- char *tmp_in;
- edg_wll_JobStat *stat;
-
- stat = (edg_wll_JobStat *) calloc(1,sizeof(edg_wll_JobStat));
- if (!stat) return stat;
- tmp_in = in;
-
- stat->state = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->jobId = dec_jobid(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->owner = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->jobtype = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->parent_job = dec_jobid(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->seed = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->children_num = dec_int(tmp_in, &tmp_in);
- /* children histogram also stored in the DB, see bellow. Other children data not stored. */
- if (tmp_in != NULL) stat->condorId = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->globusId = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->localId = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->jdl = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->matched_jdl = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->destination = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->condor_jdl = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->rsl = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->reason = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->location = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->ce_node = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->network_server = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->subjob_failed = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->done_code = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->exit_code = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->resubmitted = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->cancelling = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->cancelReason = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->cpuTime = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->user_tags = dec_taglist(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->stateEnterTime = dec_timeval(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->stateEnterTimes = dec_intlist(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->lastUpdateTime = dec_timeval(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->expectUpdate = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->expectFrom = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->payload_running = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->possible_destinations = dec_strlist(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->possible_ce_nodes = dec_strlist(tmp_in, &tmp_in);
- if (tmp_in != NULL) {
- stat->children_hist = (int*)calloc(EDG_WLL_NUMBER_OF_STATCODES+1, sizeof(int));
- dec_int_array(tmp_in, &tmp_in, stat->children_hist);
- }
- if (tmp_in != NULL) stat->pbs_state = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->pbs_queue = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->pbs_owner = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->pbs_name = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->pbs_reason = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->pbs_scheduler = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->pbs_dest_host = dec_string(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->pbs_pid = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->pbs_exit_status = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) stat->pbs_error_desc = dec_string(tmp_in, &tmp_in);
-
- *rest = tmp_in;
-
- return stat;
-}
-
-char *enc_intJobStat(char *old, intJobStat* stat)
-{
- char *ret;
-
- ret = enc_JobStat(old, &stat->pub);
- if (ret) ret = enc_int(ret, stat->resubmit_type);
- if (ret) ret = enc_string(ret, stat->last_seqcode);
- if (ret) ret = enc_string(ret, stat->last_cancel_seqcode);
- if (ret) ret = enc_string(ret, stat->branch_tag_seqcode);
- if (ret) ret = enc_string(ret, stat->last_branch_seqcode);
- if (ret) ret = enc_string(ret, stat->deep_resubmit_seqcode);
- if (ret) ret = enc_branch_states(ret, stat->branch_states);
- if (ret) ret = enc_int_array(ret, stat->children_done_hist, EDG_WLL_NUMBER_OF_DONE_CODES-1);
- if (ret) ret = enc_timeval(ret, stat->last_pbs_event_timestamp);
- if (ret) ret = enc_int(ret, stat->pbs_reruning);
- return ret;
-}
-
-intJobStat* dec_intJobStat(char *in, char **rest)
-{
- edg_wll_JobStat *pubstat;
- intJobStat *stat = 0;
- char *tmp_in;
-
- pubstat = dec_JobStat(in, &tmp_in);
-
- if (tmp_in != NULL) {
- stat = (intJobStat *)calloc(1,sizeof(intJobStat));
- }
- if (stat != NULL) {
- stat->pub = *pubstat;
- free(pubstat);
- stat->resubmit_type = dec_int(tmp_in, &tmp_in);
- if (tmp_in != NULL) {
- stat->last_seqcode = dec_string(tmp_in, &tmp_in);
- }
- if (tmp_in != NULL) {
- stat->last_cancel_seqcode = dec_string(tmp_in, &tmp_in);
- }
- if (tmp_in != NULL) {
- stat->branch_tag_seqcode = dec_string(tmp_in, &tmp_in);
- }
- if (tmp_in != NULL) {
- stat->last_branch_seqcode = dec_string(tmp_in, &tmp_in);
- }
- if (tmp_in != NULL) {
- stat->deep_resubmit_seqcode = dec_string(tmp_in, &tmp_in);
- }
- if (tmp_in != NULL) {
- stat->branch_states = dec_branch_states(tmp_in, &tmp_in);
- }
- if (tmp_in != NULL) {
- dec_int_array(tmp_in, &tmp_in, stat->children_done_hist);
- }
- if (tmp_in != NULL) {
- stat->last_pbs_event_timestamp = dec_timeval(tmp_in, &tmp_in);
- }
- if (tmp_in != NULL) {
- stat->pbs_reruning = dec_int(tmp_in, &tmp_in);
- }
- } else if (tmp_in != NULL) {
- edg_wll_FreeStatus(pubstat);
- free(pubstat);
- }
-
- *rest = tmp_in;
- return stat;
-}
-
-/*
- * Compute part of SQL command used for indexed state table columns
- */
-
-edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context ctx,
- void *job_index_cols_v,
- intJobStat *stat,
- int is_insert,
- char **names_out,
- char **values_out)
-{
- int i;
- char *names, *values;
- char *data;
- char *tmp;
- edg_wll_IColumnRec *job_index_cols = (edg_wll_IColumnRec *)job_index_cols_v;
-
- edg_wll_ResetError(ctx);
-
- if (is_insert) names = strdup(""); else names = NULL;
- values = strdup("");
-
- if (job_index_cols != NULL)
- for (i=0; job_index_cols[i].colname; i++) {
- data = NULL;
- switch (job_index_cols[i].qrec.attr) {
- case EDG_WLL_QUERY_ATTR_OWNER:
- if (stat->pub.owner)
- trio_asprintf(&data, "'%|Ss'", stat->pub.owner);
- else data = strdup("''");
- break;
- case EDG_WLL_QUERY_ATTR_LOCATION:
- if (stat->pub.location)
- trio_asprintf(&data, "'%|Ss'", stat->pub.location);
- else data = strdup("''");
- break;
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- if (stat->pub.destination)
- trio_asprintf(&data, "'%|Ss'", stat->pub.destination);
- else data = strdup("''");
- break;
- case EDG_WLL_QUERY_ATTR_DONECODE:
- asprintf(&data, "%d", stat->pub.done_code);
- break;
- case EDG_WLL_QUERY_ATTR_USERTAG:
- if (stat->pub.user_tags) {
- int k;
- for (k=0; stat->pub.user_tags[k].tag &&
- strcmp(stat->pub.user_tags[k].tag,job_index_cols[i].qrec.attr_id.tag);
- k++);
- if (stat->pub.user_tags[k].tag != NULL) {
- trio_asprintf(&data, "'%|Ss'", stat->pub.user_tags[k].value);
- } else data = strdup("''");
- } else data = strdup("''");
- break;
- case EDG_WLL_QUERY_ATTR_TIME:
- if (stat->pub.stateEnterTimes)
- data = strdup(edg_wll_TimeToDB(stat->pub.stateEnterTimes[
- job_index_cols[i].qrec.attr_id.state+1]));
- else data = strdup("0");
- break;
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- asprintf(&data, "%d", stat->pub.resubmitted);
- break;
-
- /* XXX add more attributes when defined */
- default:
- /* do not use */
- break;
- }
-
- if (!data) continue;
-
- if (is_insert) {
- asprintf(&tmp, "%s,`%s`", names, job_index_cols[i].colname);
- free(names); names = tmp;
- asprintf(&tmp, "%s,%s", values, data);
- free(values); values = tmp;
- } else {
- /* update */
- asprintf(&tmp, "%s,`%s`=%s", values, job_index_cols[i].colname, data);
- free(values); values = tmp;
- }
- free(data);
- }
-
- if (is_insert) *names_out = names;
- *values_out = values;
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-int component_seqcode(const char *a, edg_wll_Source index)
-{
- unsigned int c[EDG_WLL_SOURCE__LAST];
- int res;
- char sc[EDG_WLL_SEQ_SIZE];
-
- if (!strstr(a, "LBS")) snprintf(sc,EDG_WLL_SEQ_SIZE,"%s:LBS=000000",a);
- else snprintf(sc,EDG_WLL_SEQ_SIZE,"%s",a);
-
- res = sscanf(sc, "UI=%d:NS=%d:WM=%d:BH=%d:JSS=%d:LM=%d:LRMS=%d:APP=%d:LBS=%d",
- &c[EDG_WLL_SOURCE_USER_INTERFACE],
- &c[EDG_WLL_SOURCE_NETWORK_SERVER],
- &c[EDG_WLL_SOURCE_WORKLOAD_MANAGER],
- &c[EDG_WLL_SOURCE_BIG_HELPER],
- &c[EDG_WLL_SOURCE_JOB_SUBMISSION],
- &c[EDG_WLL_SOURCE_LOG_MONITOR],
- &c[EDG_WLL_SOURCE_LRMS],
- &c[EDG_WLL_SOURCE_APPLICATION],
- &c[EDG_WLL_SOURCE_LB_SERVER]);
- if (res != EDG_WLL_SOURCE__LAST-1) {
- syslog(LOG_ERR, "unparsable sequence code %s\n", sc);
- fprintf(stderr, "unparsable sequence code %s\n", sc);
- return -1;
- }
-
- return(c[index]);
-}
-
-char * set_component_seqcode(char *a,edg_wll_Source index,int val)
-{
- unsigned int c[EDG_WLL_SOURCE__LAST];
- int res;
- char *ret;
- char sc[EDG_WLL_SEQ_SIZE];
-
- if (!strstr(a, "LBS")) snprintf(sc,EDG_WLL_SEQ_SIZE,"%s:LBS=000000",a);
- else snprintf(sc,EDG_WLL_SEQ_SIZE,"%s",a);
-
- res = sscanf(sc, "UI=%d:NS=%d:WM=%d:BH=%d:JSS=%d:LM=%d:LRMS=%d:APP=%d:LBS=%d",
- &c[EDG_WLL_SOURCE_USER_INTERFACE],
- &c[EDG_WLL_SOURCE_NETWORK_SERVER],
- &c[EDG_WLL_SOURCE_WORKLOAD_MANAGER],
- &c[EDG_WLL_SOURCE_BIG_HELPER],
- &c[EDG_WLL_SOURCE_JOB_SUBMISSION],
- &c[EDG_WLL_SOURCE_LOG_MONITOR],
- &c[EDG_WLL_SOURCE_LRMS],
- &c[EDG_WLL_SOURCE_APPLICATION],
- &c[EDG_WLL_SOURCE_LB_SERVER]);
- if (res != EDG_WLL_SOURCE__LAST-1) {
- syslog(LOG_ERR, "unparsable sequence code %s\n", sc);
- fprintf(stderr, "unparsable sequence code %s\n", sc);
- return NULL;
- }
-
- c[index] = val;
- trio_asprintf(&ret,"UI=%06d:NS=%010d:WM=%06d:BH=%010d:JSS=%06d"
- ":LM=%06d:LRMS=%06d:APP=%06d:LBS=%06d",
- c[EDG_WLL_SOURCE_USER_INTERFACE],
- c[EDG_WLL_SOURCE_NETWORK_SERVER],
- c[EDG_WLL_SOURCE_WORKLOAD_MANAGER],
- c[EDG_WLL_SOURCE_BIG_HELPER],
- c[EDG_WLL_SOURCE_JOB_SUBMISSION],
- c[EDG_WLL_SOURCE_LOG_MONITOR],
- c[EDG_WLL_SOURCE_LRMS],
- c[EDG_WLL_SOURCE_APPLICATION],
- c[EDG_WLL_SOURCE_LB_SERVER]);
- return ret;
-}
-
-int before_deep_resubmission(const char *a, const char *b)
-{
- if (component_seqcode(a, EDG_WLL_SOURCE_WORKLOAD_MANAGER) <
- component_seqcode(b, EDG_WLL_SOURCE_WORKLOAD_MANAGER) )
- return(1);
- else
- return(0);
-
-}
-
-int same_branch(const char *a, const char *b)
-{
- if (component_seqcode(a, EDG_WLL_SOURCE_WORKLOAD_MANAGER) ==
- component_seqcode(b, EDG_WLL_SOURCE_WORKLOAD_MANAGER) )
- return(1);
- else
- return(0);
-}
-
-int edg_wll_compare_pbs_seq(const char *a,const char *b)
-{
- char timestamp_a[14], pos_a[10], ev_code_a, src_a;
- char timestamp_b[14], pos_b[10], ev_code_b, src_b;
- int res;
-
- res = sscanf(a,"TIMESTAMP=%14s:POS=%10s:EV.CODE=%3d:SRC=%c", ×tamp_a, &pos_a, &ev_code_a, &src_a);
-
- if (res != 4) {
- syslog(LOG_ERR, "unparsable sequence code %s\n", a);
- fprintf(stderr, "unparsable sequence code %s\n", a);
- return -1;
- }
-
- res = sscanf(b,"TIMESTAMP=%14s:POS=%10s:EV.CODE=%3d:SRC=%c", ×tamp_b, &pos_b, &ev_code_b, &src_b);
-
- if (res != 4) {
- syslog(LOG_ERR, "unparsable sequence code %s\n", b);
- fprintf(stderr, "unparsable sequence code %s\n", b);
- return -1;
- }
-
- /* wild card for PBSJobReg - this event should always come as firt one */
- /* bacause it hold job.type, which is necessary for further event processing */
- if (ev_code_a == EDG_WLL_EVENT_REGJOB) return -1;
- if (ev_code_b == EDG_WLL_EVENT_REGJOB) return 1;
-
- /* sort event w.t.r. to timestamps */
- if ((res = strcmp(timestamp_a,timestamp_b)) != 0) {
- return res;
- }
- else {
- /* if timestamps equal, sort if w.t.r. to file position */
- /* if you both events come from the same log file */
- if (src_a == src_b) {
- /* zero mean in fact duplicate events in log */
- return strcmp(pos_a,pos_b);
- }
- /* if the events come from diffrent log files */
- /* it is possible to prioritize some src log file */
- else {
- /* prioritize events from pbs_mom */
- if (src_a == 'm') return 1;
- if (src_b == 'm') return -1;
-
- /* then prioritize events from pbs_server */
- if (src_a == 's') return 1;
- if (src_b == 's') return -1;
-
- /* other priorities comes here... */
- }
- }
-
- return 0;
-}
-
-edg_wll_PBSEventSource get_pbs_event_source(const char *pbs_seq_num) {
- switch (pbs_seq_num[EDG_WLL_SEQ_PBS_SIZE-1]) {
- case 'c': return(EDG_WLL_PBS_EVENT_SOURCE_SCHEDULER);
- case 's': return(EDG_WLL_PBS_EVENT_SOURCE_SERVER);
- case 'm': return(EDG_WLL_PBS_EVENT_SOURCE_MOM);
- case 'a': return(EDG_WLL_PBS_EVENT_SOURCE_ACCOUNTING);
- default: return(EDG_WLL_PBS_EVENT_SOURCE_UNDEF);
- }
-}
-
-edg_wll_CondorEventSource get_condor_event_source(const char *condor_seq_num) {
- switch (condor_seq_num[EDG_WLL_SEQ_CONDOR_SIZE-1]) {
- case 'L': return(EDG_WLL_CONDOR_EVENT_SOURCE_COLLECTOR);
- case 'M': return(EDG_WLL_CONDOR_EVENT_SOURCE_MASTER);
- case 'm': return(EDG_WLL_CONDOR_EVENT_SOURCE_MATCH);
- case 'N': return(EDG_WLL_CONDOR_EVENT_SOURCE_NEGOTIATOR);
- case 'C': return(EDG_WLL_CONDOR_EVENT_SOURCE_SCHED);
- case 'H': return(EDG_WLL_CONDOR_EVENT_SOURCE_SHADOW);
- case 's': return(EDG_WLL_CONDOR_EVENT_SOURCE_STARTER);
- case 'S': return(EDG_WLL_CONDOR_EVENT_SOURCE_START);
- case 'j': return(EDG_WLL_CONDOR_EVENT_SOURCE_JOBQUEUE);
- default: return(EDG_WLL_CONDOR_EVENT_SOURCE_UNDEF);
- }
-}
-
-int edg_wll_compare_seq(const char *a, const char *b)
-{
- unsigned int c[EDG_WLL_SOURCE__LAST];
- unsigned int d[EDG_WLL_SOURCE__LAST];
- int res, i;
- char sca[EDG_WLL_SEQ_SIZE], scb[EDG_WLL_SEQ_SIZE];
-
-
- if ( (strstr(a,"TIMESTAMP=") == a) && (strstr(b,"TIMESTAMP=") == b) )
- return edg_wll_compare_pbs_seq(a,b);
-
- if (!strstr(a, "LBS")) snprintf(sca,EDG_WLL_SEQ_SIZE,"%s:LBS=000000",a);
- else snprintf(sca,EDG_WLL_SEQ_SIZE,"%s",a);
- if (!strstr(b, "LBS")) snprintf(scb,EDG_WLL_SEQ_SIZE,"%s:LBS=000000",b);
- else snprintf(scb,EDG_WLL_SEQ_SIZE,"%s",b);
-
- assert(EDG_WLL_SOURCE__LAST == 10);
-
- res = sscanf(sca, "UI=%d:NS=%d:WM=%d:BH=%d:JSS=%d:LM=%d:LRMS=%d:APP=%d:LBS=%d",
- &c[EDG_WLL_SOURCE_USER_INTERFACE],
- &c[EDG_WLL_SOURCE_NETWORK_SERVER],
- &c[EDG_WLL_SOURCE_WORKLOAD_MANAGER],
- &c[EDG_WLL_SOURCE_BIG_HELPER],
- &c[EDG_WLL_SOURCE_JOB_SUBMISSION],
- &c[EDG_WLL_SOURCE_LOG_MONITOR],
- &c[EDG_WLL_SOURCE_LRMS],
- &c[EDG_WLL_SOURCE_APPLICATION],
- &c[EDG_WLL_SOURCE_LB_SERVER]);
- if (res != EDG_WLL_SOURCE__LAST-1) {
- syslog(LOG_ERR, "unparsable sequence code %s\n", sca);
- fprintf(stderr, "unparsable sequence code %s\n", sca);
- return -1;
- }
-
- res = sscanf(scb, "UI=%d:NS=%d:WM=%d:BH=%d:JSS=%d:LM=%d:LRMS=%d:APP=%d:LBS=%d",
- &d[EDG_WLL_SOURCE_USER_INTERFACE],
- &d[EDG_WLL_SOURCE_NETWORK_SERVER],
- &d[EDG_WLL_SOURCE_WORKLOAD_MANAGER],
- &d[EDG_WLL_SOURCE_BIG_HELPER],
- &d[EDG_WLL_SOURCE_JOB_SUBMISSION],
- &d[EDG_WLL_SOURCE_LOG_MONITOR],
- &d[EDG_WLL_SOURCE_LRMS],
- &d[EDG_WLL_SOURCE_APPLICATION],
- &d[EDG_WLL_SOURCE_LB_SERVER]);
- if (res != EDG_WLL_SOURCE__LAST-1) {
- syslog(LOG_ERR, "unparsable sequence code %s\n", scb);
- fprintf(stderr, "unparsable sequence code %s\n", scb);
- return 1;
- }
-
- for (i = EDG_WLL_SOURCE_USER_INTERFACE ; i < EDG_WLL_SOURCE__LAST; i++) {
- if (c[i] < d[i]) return -1;
- if (c[i] > d[i]) return 1;
- }
-
- return 0;
-}
-
-static int compare_events_by_seq(const void *a, const void *b)
-{
- const edg_wll_Event *e = (edg_wll_Event *) a;
- const edg_wll_Event *f = (edg_wll_Event *) b;
- int ret;
-
-
- ret = edg_wll_compare_seq(e->any.seqcode, f->any.seqcode);
- if (ret) return ret;
-
- if (e->any.timestamp.tv_sec < f->any.timestamp.tv_sec) return -1;
- if (e->any.timestamp.tv_sec > f->any.timestamp.tv_sec) return 1;
- if (e->any.timestamp.tv_usec < f->any.timestamp.tv_usec) return -1;
- if (e->any.timestamp.tv_usec > f->any.timestamp.tv_usec) return 1;
- return 0;
-}
-
-static int compare_pevents_by_seq(const void *a, const void *b)
-{
- const edg_wll_Event **e = (const edg_wll_Event **) a;
- const edg_wll_Event **f = (const edg_wll_Event **) b;
- return compare_events_by_seq(*e,*f);
-}
-
-void edg_wll_SortEvents(edg_wll_Event *e)
-{
- int n;
-
- if (!e) return;
- for (n=0; e[n].type; n++);
- qsort(e,n,sizeof(*e),compare_events_by_seq);
-}
-
-void edg_wll_SortPEvents(edg_wll_Event **e)
-{
- edg_wll_Event **p;
- int n;
-
- if (!e) return;
- p = e;
- for (n=0; *p; n++) {
- p++;
- }
- qsort(e,n,sizeof(*e),compare_pevents_by_seq);
-}
-
-
-void init_intJobStat(intJobStat *p)
-{
- memset(p, 0, sizeof(intJobStat));
- p->pub.jobtype = -1 /* why? EDG_WLL_STAT_SIMPLE */;
- p->pub.children_hist = (int*) calloc(1+EDG_WLL_NUMBER_OF_STATCODES, sizeof(int));
- p->pub.children_hist[0] = EDG_WLL_NUMBER_OF_STATCODES;
- p->pub.stateEnterTimes = (int*) calloc(1+EDG_WLL_NUMBER_OF_STATCODES, sizeof(int));
- p->pub.stateEnterTimes[0] = EDG_WLL_NUMBER_OF_STATCODES;
- /* TBD: generate */
-}
-
+++ /dev/null
-<?xml version="1.0"?>
-
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xs="http://www.w3.org/2001/XMLSchema"
->
-
-<xsl:output method="text"/>
-
-<xsl:template match="xs:schema">
-#ifndef __GLITE_LB_JP_JOB_ATTR_H
-#define __GLITE_LB_JP_JOB_ATTR_H
-#define GLITE_JP_LB_NS "http://egee.cesnet.cz/en/Schema/LB/Attributes"
-#define GLITE_JP_LB_JDL_NS "http://egee.cesnet.cz/en/Schema/LB/Attributes:JDL"
- <xsl:apply-templates select="xs:element"/>
-#define GLITE_JP_LB_CLASSAD_NS "http://jdl"
-#endif
-</xsl:template>
-
-<xsl:template match="xs:element">
-/** <xsl:value-of select="xs:documentation/text()"/> */
-#define GLITE_JP_LB_<xsl:value-of select="@name"/> GLITE_JP_LB_NS ":<xsl:value-of select="@name"/>"
-</xsl:template>
-
-</xsl:stylesheet>
+++ /dev/null
-#ident "$Header$"
-
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include <syslog.h>
-
-#include "glite/lb/context-int.h"
-#include "lb_authz.h"
-
-#ifndef NO_VOMS
-
-#include <openssl/ssl.h>
-#include <libxml/parser.h>
-#undef WITHOUT_TRIO
-
-#include "glite/security/voms/voms_apic.h"
-#include "glite/wmsutils/jobid/strmd5.h"
-#include "glite/wmsutils/jobid/cjobid.h"
-#include "glite/lb/producer.h"
-#include "glite/lb/trio.h"
-#include "lbs_db.h"
-
-/* XXX should be defined in gridsite-gacl.h */
-GRSTgaclEntry *GACLparseEntry(xmlNodePtr cur);
-
-static int
-add_groups(edg_wll_Context ctx, struct voms *voms_cert, char *vo_name,
- edg_wll_VomsGroups *groups)
-{
- struct data **voms_data;
- edg_wll_VomsGroup *tmp = NULL;
-
- if (voms_cert->type != TYPE_STD) {
- edg_wll_SetError(ctx, EINVAL, "not supported VOMS certificate type");
- return EINVAL;
- }
-
- for (voms_data = voms_cert->std; voms_data && *voms_data; voms_data++) {
- if ((*voms_data)->group && *(*voms_data)->group) {
- tmp = realloc(groups->val, (groups->len + 1) * sizeof(*groups->val));
- if (tmp == NULL)
- return ENOMEM;
- groups->val = tmp;
- groups->val[groups->len].vo = strdup(vo_name);
- groups->val[groups->len].name = strdup((*voms_data)->group);
- groups->len++;
- }
- }
- return 0;
-}
-
-static int
-get_groups(edg_wll_Context ctx, struct vomsdata *voms_info,
- edg_wll_VomsGroups *res_groups)
-{
- struct voms **voms_cert = NULL;
- edg_wll_VomsGroups groups;
- int ret;
-
- memset(&groups, 0, sizeof(groups));
-
- for (voms_cert = voms_info->data; voms_cert && *voms_cert; voms_cert++) {
- if ((*voms_cert)->voname) {
- ret = add_groups(ctx, *voms_cert, (*voms_cert)->voname, &groups);
- if (ret) {
- edg_wll_FreeVomsGroups(&groups);
- return ret;
- }
- }
- }
-
- res_groups->len = groups.len;
- res_groups->val = groups.val;
- return 0;
-}
-
-static int
-get_peer_cred(edg_wll_GssConnection *gss, char *server_cert, char *server_key, STACK_OF(X509) **chain, X509 **cert)
-{
- OM_uint32 maj_stat, min_stat;
- gss_buffer_desc buffer = GSS_C_EMPTY_BUFFER;
- BIO *bio = NULL;
- SSL_SESSION *session = NULL;
- unsigned char int_buffer[4];
- long length;
- int ret, index;
- STACK_OF(X509) *cert_chain = NULL;
- X509 *peer_cert = NULL;
- X509 *p_cert;
-
- maj_stat = gss_export_sec_context(&min_stat, &gss->context, &buffer);
- if (GSS_ERROR(maj_stat))
- return -1; /* XXX */
-
- {
- /* The GSSAPI specs requires gss_export_sec_context() to destroy the
- * context after exporting. So we have to resurrect the context here by
- * importing from just generated buffer. gss_import_sec_context() must be
- * able to read valid credential before it loads the exported context
- * so we set the environment temporarily to point to the ones used by
- * the server.
- *
- * I'm eagerly waiting for adaptations in the VOMS API to avoid these
- * hacks */
-
- char *orig_cert = NULL, *orig_key = NULL;
-
- orig_cert = getenv("X509_USER_CERT");
- orig_key = getenv("X509_USER_KEY");
-
- if (server_cert)
- setenv("X509_USER_CERT", server_cert, 1);
- if (server_key)
- setenv("X509_USER_KEY", server_key, 1);
-
- maj_stat = gss_import_sec_context(&min_stat, &buffer, &gss->context);
-
- if (orig_cert)
- setenv("X509_USER_CERT", orig_cert, 1);
- else
- unsetenv("X509_USER_CERT");
-
- if (orig_key)
- setenv("X509_USER_KEY", orig_key, 1);
- else
- unsetenv("X509_USER_KEY");
-
- if (GSS_ERROR(maj_stat)) {
- ret = -1;
- goto end;
- }
- }
-
- bio = BIO_new(BIO_s_mem());
- if (bio == NULL) {
- ret = -1;
- goto end;
- }
-
- /* Store exported context to memory, skipping the version number and and cred_usage fields */
- BIO_write(bio, buffer.value + 8 , buffer.length - 8);
-
- /* decode the session data in order to skip at the start of the cert chain */
- session = d2i_SSL_SESSION_bio(bio, NULL);
- if (session == NULL) {
- ret = -1; /* XXX */
- goto end;
- }
- if (session->peer)
- peer_cert = X509_dup(session->peer);
-
- SSL_SESSION_free(session);
-
- BIO_read(bio, (char *) int_buffer, 4);
- length = (((size_t) int_buffer[0]) << 24) & 0xffff;
- length |= (((size_t) int_buffer[1]) << 16) & 0xffff;
- length |= (((size_t) int_buffer[2]) << 8) & 0xffff;
- length |= (((size_t) int_buffer[3]) ) & 0xffff;
-
- if (length == 0) {
- ret = 0;
- goto end;
- }
-
- cert_chain = sk_X509_new_null();
- for(index = 0; index < length; index++) {
- p_cert = d2i_X509_bio(bio, NULL);
- if (p_cert == NULL) {
- ret = -1; /* XXX */
- sk_X509_pop_free(cert_chain, X509_free);
- goto end;
- }
-
- sk_X509_push(cert_chain, p_cert);
- }
-
- *chain = cert_chain;
- *cert = peer_cert;
- peer_cert = NULL;
- ret = 0;
-
-end:
- if (peer_cert)
- X509_free(peer_cert);
- gss_release_buffer(&min_stat, &buffer);
-
- return ret;
-}
-
-int
-edg_wll_SetVomsGroups(edg_wll_Context ctx, edg_wll_GssConnection *gss, char *server_cert, char *server_key, char *voms_dir, char *ca_dir)
-{
- STACK_OF(X509) *p_chain = NULL;
- X509 *cert = NULL;
- int ret;
- int err = 0;
- struct vomsdata *voms_info = NULL;
-
- /* XXX DK: correct cleanup ?? */
- memset (&ctx->vomsGroups, 0, sizeof(ctx->vomsGroups));
- edg_wll_ResetError(ctx);
-
- ret = get_peer_cred(gss, server_cert, server_key, &p_chain, &cert);
- if (ret) {
-// ret = 0;
-// XXX (MM): I do not know whether this error may be triggered by other
-// bugs too... The error message may be incomplete.
- edg_wll_SetError(ctx, errno, "cert/key file not owned by process owner?");
- goto end;
- }
-
- /* exit if peer's credentials are not available */
- if (p_chain == NULL || cert == NULL) {
- ret = 0;
- goto end;
- }
-
- /* uses X509_CERT_DIR and X509_VOMS_DIR vars */
- voms_info = VOMS_Init(voms_dir, ca_dir);
- if (voms_info == NULL) {
- edg_wll_SetError(ctx, errno, "failed to initialize VOMS structures");
- ret = -1; /* XXX VOMS Error */
- goto end;
- }
-
- ret = VOMS_Retrieve(cert, p_chain, RECURSE_CHAIN, voms_info, &err);
- if (ret == 0) {
- if (err == VERR_NOEXT)
- /* XXX DK:
- edg_wll_SetError(ctx, EINVAL, "no client VOMS certificates found");
- */
- ret = 0;
- else {
- edg_wll_SetError(ctx, -1, "failed to retrieve VOMS info");
- ret = -1; /* XXX VOMS Error */
- }
- goto end;
- }
-
- ret = get_groups(ctx, voms_info, &ctx->vomsGroups);
-
-end:
- if (voms_info)
- VOMS_Destroy(voms_info);
- if (cert)
- X509_free(cert);
-
- return ret;
-}
-
-void
-edg_wll_FreeVomsGroups(edg_wll_VomsGroups *groups)
-{
- size_t len;
-
- if (groups == NULL)
- return;
-
- for (len = 0; len < groups->len; len++) {
- if (groups->val[len].vo)
- free(groups->val[len].vo);
- if (groups->val[len].name)
- free(groups->val[len].name);
- }
-}
-
-#else /* NO_VOMS */
-
-int
-edg_wll_SetVomsGroups(edg_wll_Context ctx, edg_wll_GssConnection *gss, char *server_cert,
- char *server_key, char *voms_dir, char *ca_dir)
-{
- return 0;
-}
-
-void edg_wll_FreeVomsGroups(edg_wll_VomsGroups *groups) {}
-
-#endif
-
-
-#if !defined(NO_VOMS) && !defined(NO_GACL)
-
-static int
-parse_creds(edg_wll_VomsGroups *groups, char *subject, GRSTgaclUser **gacl_user)
-{
- GRSTgaclCred *cred = NULL;
- GRSTgaclUser *user = NULL;
- int ret;
- int i;
-
- GRSTgaclInit();
-
- cred = GRSTgaclCredNew("person");
- if (cred == NULL)
- return ENOMEM;
-
- if (!GRSTgaclCredAddValue(cred, "dn", subject)) {
- ret = EINVAL; /* GACL_ERR */
- goto fail;
- }
-
- user = GRSTgaclUserNew(cred);
- if (user == NULL) {
- ret = ENOMEM;
- goto fail;
- }
- cred = NULL; /* GACLnewUser() doesn't copy content, just store the pointer */
-
- for (i = 0; i < groups->len; i++) {
- cred = GRSTgaclCredNew("voms-cred");
- if (cred == NULL) {
- ret = ENOMEM;
- goto fail;
- }
- if (!GRSTgaclCredAddValue(cred, "vo", groups->val[i].vo) ||
- !GRSTgaclCredAddValue(cred, "group", groups->val[i].name)) {
- ret = EINVAL; /* GACL_ERR */
- goto fail;
- }
- if (!GRSTgaclUserAddCred(user, cred)) {
- ret = EINVAL; /* GACL_ERR */
- goto fail;
- }
- cred = NULL;
- /* GACLuserAddCred() doesn't copy content, just store the pointer. Cred
- * mustn't be free()ed */
- }
-
- *gacl_user = user;
-
- return 0;
-
-fail:
- if (cred)
- /* XXX GRSTgaclCredFree(cred); */
- ;
- if (user)
- /* XXX GRSTgaclUserFree(user); */
- ;
-
- return ret;
-}
-
-static int
-cmp_gacl_names(GRSTgaclNamevalue *n1, GRSTgaclNamevalue *n2)
-{
- if (n1 == NULL && n2 == NULL)
- return 1;
-
- for ( ; n1; n1 = (GRSTgaclNamevalue *)n1->next, n2 = (GRSTgaclNamevalue *) n2->next) {
- if (n2 == NULL)
- return 0;
- if (strcmp(n1->name, n2->name) != 0 ||
- strcmp(n1->value, n2->value) != 0)
- return 0;
- }
-
- return (n2 == NULL);
-}
-
-static int
-cmp_gacl_creds(GRSTgaclCred *c1, GRSTgaclCred *c2)
-{
- if (strcmp(c1->type, c2->type) != 0)
- return 0;
-
- return cmp_gacl_names(c1->firstname, c2->firstname);
- /* we support only "simple" entries containing only one credential (DN or
- * VOMS group */
-}
-
-static int
-addEntry(GRSTgaclAcl *acl, GRSTgaclEntry *entry)
-{
- GRSTgaclEntry *cur = NULL;
-
-
- if ( acl == NULL )
- return EINVAL;
-
- if ( acl->firstentry == NULL )
- return (GRSTgaclAclAddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0;
-
- for ( cur = acl->firstentry; cur; cur = cur->next )
- if ( cmp_gacl_creds(cur->firstcred, entry->firstcred)
- && cur->allowed == entry->allowed
- && cur->denied == entry->denied )
- return EEXIST;
-
- return (GRSTgaclAclAddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0;
-}
-
-static int
-delEntry(GRSTgaclAcl *acl, GRSTgaclEntry *entry)
-{
- GRSTgaclEntry *cur = NULL, *prev = NULL;
- int found = 0;
-
- if (acl == NULL || acl->firstentry == NULL)
- return EINVAL;
-
- cur = acl->firstentry;
- while (cur) {
- if (cmp_gacl_creds(cur->firstcred, entry->firstcred) &&
- cur->allowed == entry->allowed &&
- cur->denied == entry->denied) {
- if (prev)
- prev->next = cur->next;
- else
- acl->firstentry = cur->next;
- /* XXX GRSTgaclEntryFree(cur); */
- found = 1;
- break;
- }
- prev = cur;
- cur = cur->next;
- }
-
- return (found) ? 0 : -1 /* NOT_FOUND */;
-}
-
-static int
-create_cred(char *userid, int user_type, GRSTgaclCred **cred)
-{
- GRSTgaclCred *c = NULL;
- char *group = NULL;
-
- if (user_type == EDG_WLL_USER_SUBJECT) {
- c = GRSTgaclCredNew("person");
- if (c == NULL)
- return ENOMEM;
- if (!GRSTgaclCredAddValue(c, "dn", userid)) {
- /* XXX GRSTgaclCredFree(c); */
- return -1; /* GACL_ERR */
- }
- } else if(user_type == EDG_WLL_USER_VOMS_GROUP) {
- c = GRSTgaclCredNew("voms-cred");
- if (c == NULL)
- return ENOMEM;
- group = strchr(userid, ':');
- if ( !group )
- return EINVAL;
- *group++ = '\0';
- if (!GRSTgaclCredAddValue(c, "vo", userid) ||
- !GRSTgaclCredAddValue(c, "group", group)) {
- /* XXX GRSTgaclCredFree(c); */
- return -1; /* GACL_ERR */
- }
- } else
- return EINVAL;
-
- *cred = c;
-
- return 0;
-}
-
-static int
-change_acl(GRSTgaclAcl *acl, GRSTgaclEntry *entry, int operation)
- /* creds, permission, permission_type */
-{
- if (operation == EDG_WLL_ACL_ADD)
- return addEntry(acl, entry);
-
- if (operation == EDG_WLL_ACL_REMOVE)
- return delEntry(acl, entry);
-
- return -1;
-}
-
-static int
-edg_wll_change_acl(edg_wll_Acl acl, char *user_id, int user_id_type,
- int permission, int perm_type, int operation)
-{
- GRSTgaclCred *cred = NULL;
- GRSTgaclEntry *entry = NULL;
- int ret;
-
- GRSTgaclInit();
-
- if (acl == NULL || acl->value == NULL)
- return EINVAL;
-
- ret = create_cred(user_id, user_id_type, &cred);
- if (ret)
- return ret;
-
- entry = GRSTgaclEntryNew();
- if (entry == NULL) {
- ret = ENOMEM;
- goto end;
- }
-
- if (!GRSTgaclEntryAddCred(entry, cred)) {
- ret = -1; /* GACLErr */
- goto end;
- }
-
- if (perm_type == EDG_WLL_PERM_ALLOW)
- GRSTgaclEntryAllowPerm(entry, permission);
- else if (perm_type == EDG_WLL_PERM_DENY)
- GRSTgaclEntryDenyPerm(entry, permission);
- else {
- ret = EINVAL;
- goto end;
- }
-
- ret = change_acl(acl->value, entry, operation);
- if (ret)
- {
-/* XXX: mem leak?
- GRSTgaclEntryFree(entry);
-*/
- goto end;
- }
-
- if (acl->string) free(acl->string);
- ret = edg_wll_EncodeACL(acl->value, &acl->string);
-
-end:
-
- return ret;
-}
-
-int
-edg_wll_CheckACL(edg_wll_Context ctx, edg_wll_Acl acl, int requested_perm)
-{
- int ret;
- GRSTgaclUser *user = NULL;
- unsigned int perm;
-
- if (acl == NULL || acl->value == NULL)
- return edg_wll_SetError(ctx,EINVAL,"CheckACL");
-
- if (!ctx->peerName) return edg_wll_SetError(ctx,EPERM,"CheckACL");
-
- ret = parse_creds(&ctx->vomsGroups, ctx->peerName, &user);
- if (ret) {
- return edg_wll_SetError(ctx,ret,"parse_creds()");
- }
-
- perm = GRSTgaclAclTestUser(acl->value, user);
-
- /* XXX GRSTgaclUserFree(user); */
-
- if (perm & requested_perm) return edg_wll_ResetError(ctx);
- else return edg_wll_SetError(ctx,EPERM,"CheckACL");
-}
-
-int
-edg_wll_EncodeACL(GRSTgaclAcl *acl, char **str)
-{
- int tmp_fd, ret;
- FILE *fd = NULL;
- char filename[16];
- char line[4096];
- char *buf = NULL;
- size_t buf_len = 0;
- char *p;
-
- snprintf(filename, sizeof(filename), "/tmp/XXXXXX");
- tmp_fd = mkstemp(filename);
- if (tmp_fd == -1)
- return errno;
-
- fd = fdopen(tmp_fd, "r");
-
- ret = GRSTgaclAclSave(acl, filename);
- unlink(filename);
- if (ret == 0) {
- ret = -1; /* GACL_ERR */
- goto end;
- }
-
- buf_len = 1024;
- buf = calloc(buf_len, 1);
- if (buf == NULL) {
- ret = ENOMEM;
- goto end;
- }
-
- while (fgets(line, sizeof(line), fd) != NULL) {
- p = strchr(line, '\n');
- if (p)
- *p = '\0';
-
- if (strlen(buf) + strlen(line) > buf_len) {
- char *tmp;
-
- tmp = realloc(buf, buf_len + 1024);
- if (tmp == NULL) {
- ret = ENOMEM;
- goto end;
- }
- buf = tmp;
- buf_len += 1024;
- }
-
- strcat(buf, line);
- }
-
- *str = buf;
- ret = 0;
-
-end:
- fclose(fd);
- return ret;
-}
-
-int
-edg_wll_DecodeACL(char *buf, GRSTgaclAcl **result_acl)
-{
- /* Got from GACLloadAcl() available from GACL API */
- xmlDocPtr doc;
- xmlNodePtr cur;
- GRSTgaclAcl *acl;
- GRSTgaclEntry *entry;
-
- doc = xmlParseMemory(buf, strlen(buf));
- if (doc == NULL) return EINVAL;
-
- cur = xmlDocGetRootElement(doc);
-
- if (xmlStrcmp(cur->name, (const xmlChar *) "gacl"))
- {
- free(doc);
- free(cur);
- return EINVAL;
- }
-
- cur = cur->xmlChildrenNode;
-
- acl = GRSTgaclAclNew();
-
- while (cur != NULL)
- {
- /*
- if (cur->type == XML_TEXT_NODE && cur->content == '\n') {
- cur=cur->next;
- continue;
- }
- */
- entry = GACLparseEntry(cur);
- if (entry == NULL)
- {
- /* XXX GRSTgaclAclFree(acl); */
- xmlFreeDoc(doc);
- return EINVAL;
- }
-
- GRSTgaclAclAddEntry(acl, entry);
-
- cur=cur->next;
- }
-
- xmlFreeDoc(doc);
- *result_acl = acl;
- return 0;
-}
-
-int
-edg_wll_InitAcl(edg_wll_Acl *acl)
-{
- edg_wll_Acl tmp;
-
- tmp = malloc(sizeof(*tmp));
- if ( !tmp )
- return ENOMEM;
-
- tmp->value = GRSTgaclAclNew();
- tmp->string = NULL;
- *acl = tmp;
- return 0;
-}
-
-void
-edg_wll_FreeAcl(edg_wll_Acl acl)
-{
- /* XXX if ( acl->value ) GRSTgaclAclFree(acl->value); */
- if ( acl->string ) free(acl->string);
- free(acl);
-}
-
-int
-edg_wll_HandleCounterACL(edg_wll_Context ctx, edg_wll_Acl acl,
- char *aclid, int incr)
-{
- char *q1 = NULL,
- *q2 = NULL;
-
- edg_wll_ResetError(ctx);
-
- if ( incr > 0 )
- {
- trio_asprintf(&q1,
- "insert into acls(aclid,value,refcnt) "
- "values ('%|Ss','%|Ss',%d)",
- aclid, acl->string, incr);
-
- for ( ; ; )
- {
- if ( edg_wll_ExecStmt(ctx, q1, NULL) > 0 )
- goto end;
-
- if ( edg_wll_Error(ctx,NULL,NULL) != EEXIST )
- goto end;
-
- /*
- * row allready in DB
- */
- if ( !q2 ) trio_asprintf(&q2,
- "update acls set refcnt = refcnt+%d "
- "where aclid = '%|Ss'",
- incr, aclid);
- if ( edg_wll_ExecStmt(ctx, q2, NULL) < 0 )
- continue;
-
- goto end;
- }
- }
- else if (incr < 0)
- {
- trio_asprintf(&q1,
- "update acls set refcnt = refcnt-%d "
- "where aclid='%|Ss' and refcnt>=%d",
- -incr, aclid, -incr);
-
- if ( edg_wll_ExecStmt(ctx, q1, NULL) > 0 )
- {
- trio_asprintf(&q2,
- "delete from acls "
- "where aclid='%|Ss' and refcnt=0",
- aclid);
- edg_wll_ExecStmt(ctx, q2, NULL);
- }
- else
- {
- fprintf(stderr, "ACL with ID: %s has invalid reference count\n", aclid);
- syslog(LOG_WARNING, "ACL with ID: %s has invalid reference count\n", aclid);
- }
- }
-
-
-end:
- if ( q1 ) free(q1);
- if ( q2 ) free(q2);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-int
-edg_wll_UpdateACL(edg_wll_Context ctx, edg_wlc_JobId job,
- char *user_id, int user_id_type,
- int permission, int perm_type, int operation)
-{
- char *md5_jobid;
- edg_wll_Acl acl = NULL;
- int ret;
- char *stmt = NULL;
- char *new_aclid = NULL, *old_aclid = NULL;
- int updated;
-
- edg_wll_ResetError(ctx);
-
- md5_jobid = edg_wlc_JobIdGetUnique(job);
-
- do {
- if (acl)
- {
- edg_wll_FreeAcl(acl);
- acl = NULL;
- }
- if (old_aclid)
- {
- free(old_aclid);
- old_aclid = NULL;
- }
- if (new_aclid)
- {
- free(new_aclid);
- new_aclid = NULL;
- }
-
- if ( (ret = edg_wll_GetACL(ctx, job, &acl)) )
- goto end;
- if ( !acl && (ret = edg_wll_InitAcl(&acl)) )
- goto end;
-
- old_aclid = acl->string? strdup(strmd5(acl->string, NULL)): NULL;
-
- ret = edg_wll_change_acl(acl, user_id, user_id_type,
- permission, perm_type, operation);
- if (ret)
- {
- if ( ret == EEXIST )
- /*
- * adding allready set entry
- * only upgrade the counter
- */
- ret = edg_wll_HandleCounterACL(ctx, acl, new_aclid, 1);
-
- goto end;
- }
-
- new_aclid = strdup(strmd5(acl->string, NULL));
-
- /* store new ACL or increment its counter if already present in db */
- ret = edg_wll_HandleCounterACL(ctx, acl, new_aclid, 1);
- if (ret)
- goto end;
-
- if ( old_aclid )
- trio_asprintf(&stmt,
- "update jobs set aclid='%|Ss' where jobid='%|Ss' and aclid='%|Ss'",
- new_aclid, md5_jobid, old_aclid);
- else
- trio_asprintf(&stmt,
- "update jobs set aclid='%|Ss' where jobid='%|Ss' and ISNULL(aclid)",
- new_aclid, md5_jobid);
- updated = edg_wll_ExecStmt(ctx, stmt, NULL);
- free(stmt); stmt = NULL;
-
- if (updated > 0)
- /* decrement reference counter of the old ACL, and possibly remove
- * whole ACL if the counter becames zero */
- ret = edg_wll_HandleCounterACL(ctx, NULL, old_aclid, -1);
- else
- /* We failed to store new ACL to db, most likely because the ACL has
- * been changed. Decrement counter of new ACL set before trying
- * updating */
- ret = edg_wll_HandleCounterACL(ctx, NULL, new_aclid, -1);
- } while (updated <= 0);
-
-end:
- free(md5_jobid);
- if (acl)
- edg_wll_FreeAcl(acl);
- if (new_aclid)
- free(new_aclid);
- if (old_aclid)
- free(old_aclid);
-
- return ret;
-}
-
-int edg_wll_GetACL(edg_wll_Context ctx, edg_wlc_JobId jobid, edg_wll_Acl *acl)
-{
- char *q = NULL;
- char *acl_id = NULL;
- char *acl_str = NULL;
- edg_wll_Stmt stmt = NULL;
- int ret;
- GRSTgaclAcl *gacl = NULL;
- char *jobstr = edg_wlc_JobIdGetUnique(jobid);
-
- if (jobid == NULL || jobstr == NULL)
- return edg_wll_SetError(ctx,EINVAL,"edg_wll_GetACL()");
-
- edg_wll_ResetError(ctx);
-
- trio_asprintf(&q,
- "select aclid from jobs where jobid = '%|Ss'", jobstr);
-
- if (edg_wll_ExecStmt(ctx, q, &stmt) < 0 ||
- edg_wll_FetchRow(stmt, &acl_id) < 0) {
- goto end;
- }
- edg_wll_FreeStmt(&stmt); stmt = NULL;
- free(q); q = NULL;
-
- if (acl_id == NULL || *acl_id == '\0') {
- *acl = NULL;
- return 0;
- }
-
- trio_asprintf(&q,
- "select value from acls where aclid = '%|Ss'", acl_id);
- if (edg_wll_ExecStmt(ctx, q, &stmt) < 0 ||
- edg_wll_FetchRow(stmt, &acl_str) < 0) {
- goto end;
- }
-
- ret = edg_wll_DecodeACL(acl_str, &gacl);
- if (ret) {
- edg_wll_SetError(ctx, EINVAL, "encoding ACL");
- goto end;
- }
-
- *acl = calloc(1, sizeof(**acl));
- if (*acl == NULL) {
- ret = ENOMEM;
- edg_wll_SetError(ctx, ENOMEM, "not enough memory");
- goto end;
- }
-
- (*acl)->value = gacl;
- (*acl)->string = acl_str;
- gacl = NULL; acl_str = NULL;
- ret = 0;
-
-end:
- if (q) free(q);
- if (stmt) edg_wll_FreeStmt(&stmt);
- if (acl_id) free(acl_id);
- if (acl_str) free(acl_str);
- /* XXX if (gacl) GRSTgaclAclFree(gacl); */
- if (jobstr) free(jobstr);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-#else /* VOMS & GACL */
-
-
-int edg_wll_CheckACL(edg_wll_Context ctx, edg_wll_Acl acl, int requested_perm) { return EPERM; }
-
-#ifndef NO_GACL
-int edg_wll_EncodeACL(GRSTgaclAcl *acl, char **str) { return 0; }
-int edg_wll_DecodeACL(char *buf, GRSTgaclAcl **result_acl) { return 0; }
-#else
-int edg_wll_EncodeACL(void *acl, char **str) { return 0; }
-int edg_wll_DecodeACL(char *buf, void **result_acl) { return 0; }
-#endif
-
-int edg_wll_InitAcl(edg_wll_Acl *acl) { return 0; }
-void edg_wll_FreeAcl(edg_wll_Acl acl) { }
-int edg_wll_HandleCounterACL(edg_wll_Context ctx, edg_wll_Acl acl,
- char *aclid, int incr) { return 0; }
-int edg_wll_UpdateACL(edg_wll_Context ctx, edg_wlc_JobId job,
- char *user_id, int user_id_type,
- int permission, int perm_type, int operation) { return 0; }
-int edg_wll_GetACL(edg_wll_Context ctx, edg_wlc_JobId jobid, edg_wll_Acl *acl) { return 0; }
-
-
-#endif
-
+++ /dev/null
-#ident "$Header$"
-
-#include "lb_html.h"
-#include "lb_proto.h"
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/context-int.h"
-
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-#ifdef __GNUC__
-#define UNUSED_VAR __attribute__((unused))
-#else
-#define UNUSED_VAR
-#endif
-
-int edg_wll_QueryToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut UNUSED_VAR, char **message UNUSED_VAR)
-{
-/* not implemented yet */
- return -1;
-}
-
-/* construct Message-Body of Response-Line for edg_wll_UserJobs */
-int edg_wll_UserJobsToHTML(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message)
-{
- char *pomA, *pomB;
- int i = 0;
-
- /* head */
- pomB = strdup("");
-
- while (jobsOut[i]) {
- char *chid = edg_wlc_JobIdUnparse(jobsOut[i]);
-
- asprintf(&pomA,"%s\t\t <li> <a href=\"%s\">%s</a>\r\n",
- pomB, chid,chid);
-
- free(chid);
- free(pomB);
- pomB = pomA;
- i++;
- }
-
- asprintf(&pomA, "<html>\r\n\t<body>\r\n"
- "<h2><B>User jobs</B></h2>\r\n"
- "User subject: %s<p>"
- "<ul>%s</ul>"
- "\t</body>\r\n</html>",ctx->peerName,pomB);
- free(pomB);
-
- *message = pomA;
-
- return 0;
-}
-
-
-/* construct Message-Body of Response-Line for edg_wll_JobStatus */
-int edg_wll_JobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat, char **message)
-{
- char *pomA, *pomB;
- char *chid,*chstat;
- char *jdl,*rsl;
-
- jdl = strdup("");
- rsl = strdup("");
-
- pomB = strdup("");
-
- chid = edg_wlc_JobIdUnparse(stat.jobId);
-
-#define TR(name,type,field) \
- if (field) { \
- asprintf(&pomA,"%s<tr><th align=\"left\">" name ":</th>" \
- "<td>" type "</td></tr>",pomB,(field)); \
- free(pomB); \
- pomB = pomA; \
- }
-
- TR("Status","%s",(chstat = edg_wll_StatToString(stat.state)));
- free(chstat);
- TR("owner","%s",stat.owner);
- TR("Condor Id","%s",stat.condorId);
- TR("Globus Id","%s",stat.globusId);
- TR("Local Id","%s",stat.localId);
- TR("Reason","%s",stat.reason);
- if ( (stat.stateEnterTime.tv_sec) || (stat.stateEnterTime.tv_usec) ) {
- time_t time = stat.stateEnterTime.tv_sec;
- TR("State entered","%s",ctime(&time));
- }
- if ( (stat.lastUpdateTime.tv_sec) || (stat.lastUpdateTime.tv_usec) ) {
- time_t time = stat.lastUpdateTime.tv_sec;
- TR("Last update","%s",ctime(&time));
- }
- TR("Expect update","%s",stat.expectUpdate ? "YES" : "NO");
- TR("Expect update from","%s",stat.expectFrom);
- TR("Location","%s",stat.location);
- TR("Destination","%s",stat.destination);
- TR("Cancelling","%s",stat.cancelling>0 ? "YES" : "NO");
- if (stat.cancelReason != NULL) {
- TR("Cancel reason","%s",stat.cancelReason);
- }
- TR("CPU time","%d",stat.cpuTime);
-
-
- TR("Done code","%d",stat.done_code);
- TR("Exit code","%d",stat.exit_code);
-
- if (stat.jdl) asprintf(&jdl,"<h3>Job description</h3>\r\n"
- "<pre>%s</pre>\r\n",stat.jdl);
-
- if (stat.rsl) asprintf(&rsl,"<h3>RSL</h3>\r\n"
- "<pre>%s</pre>\r\n",stat.rsl);
-
-
- asprintf(&pomA, "<html>\r\n\t<body>\r\n"
- "<h2>%s</h2>\r\n"
- "<table halign=\"left\">%s</table>"
- "%s%s"
- "\t</body>\r\n</html>",
- chid,pomB,jdl,rsl);
- free(pomB);
-
- *message = pomA;
-
- free(chid);
- free(jdl);
- free(rsl);
- return 0;
-}
-
-char *edg_wll_ErrorToHTML(edg_wll_Context ctx,int code)
-{
- char *out,*et,*ed;
- char *msg = edg_wll_HTTPErrorMessage(code);
- edg_wll_ErrorCode e;
-
- e = edg_wll_Error(ctx,&et,&ed);
- asprintf(&out,"<html><head><title>Error</title></head>\n"
- "<body><h1>%s</h1>\n"
- "%d: %s (%s)</body></html>",msg,e,et,ed);
-
- free(et); free(ed);
- return out;
-}
+++ /dev/null
-#ifndef _LB_HTML
-#define _LB_HTML
-
-#ident "$Header$"
-
-#include "glite/lb/consumer.h"
-
-int edg_wll_QueryToHTML(edg_wll_Context,edg_wll_Event *,char **);
-int edg_wll_JobStatusToHTML(edg_wll_Context, edg_wll_JobStat, char **);
-int edg_wll_UserJobsToHTML(edg_wll_Context, edg_wlc_JobId *, char **);
-char *edg_wll_ErrorToHTML(edg_wll_Context,int);
-
-#endif
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/mini_http.h"
-#include "glite/lb/context-int.h"
-
-#include "lb_http.h"
-#include "lb_proto.h"
-
-extern int debug;
-#define dprintf(x) if (debug) printf x
-
-
-int edg_wll_ServerHTTP(edg_wll_Context ctx)
-{
- char **hdr = NULL,*req = NULL,*body = NULL,
- **hdrOut = NULL, *resp = NULL, *bodyOut = NULL,
- *err_desc = NULL;
- edg_wll_ErrorCode err = 0;
-
-
- if ( ctx->isProxy ) err = edg_wll_http_recv_proxy(ctx,&req,&hdr,&body);
- else err = edg_wll_http_recv(ctx,&req,&hdr,&body,ctx->connections->serverConnection);
-
- dprintf(("[%d] %s\n",getpid(),req));
- if (body) dprintf(("\n%s\n\n",body));
-
- if (!err) {
- if ((err = edg_wll_Proto(ctx,req,hdr,body,&resp,&hdrOut,&bodyOut)))
- edg_wll_Error(ctx,NULL,&err_desc);
-
- if (resp) {
- if ( ctx->isProxy )
- edg_wll_http_send_proxy(ctx,resp,(char const * const *)hdrOut,bodyOut);
- else
- edg_wll_http_send(ctx,resp,(char const * const *)hdrOut,bodyOut,ctx->connections->serverConnection);
- }
- }
-
- free(req);
- free(resp);
- if (hdr) {
- char **h;
- for (h = hdr; *h; h++) free(*h);
- free(hdr);
- }
- // hdrOut are static
- free(body);
- free(bodyOut);
-
- if (err != edg_wll_Error(ctx,NULL,NULL)) edg_wll_SetError(ctx,err,err_desc);
- free(err_desc);
- return err;
-}
+++ /dev/null
-#ifndef _LB_HTTP_H
-#define _LB_HTTP_H
-
-#ident "$Header$"
-
-#include <stdio.h>
-
-#include "glite/lb/consumer.h"
-
-int edg_wll_ServerHTTP(edg_wll_Context);
-int edg_wll_ServerHTTPProxy(edg_wll_Context);
-
-#endif
+++ /dev/null
-#ident "$Header$"
-
-#include <stdlib.h>
-#include <assert.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdio.h>
-#include <errno.h>
-#include <time.h>
-#include <ctype.h>
-
-#include <cclassad.h>
-
-#include "glite/lb/context.h"
-#include "glite/lb/jobstat.h"
-#include "glite/lb/events.h"
-#include "glite/lb/events_parse.h"
-#include "glite/lb/trio.h"
-#include "glite/lb/producer.h"
-
-#include "jobstat.h"
-#include "get_events.h"
-
-#include "glite/jp/types.h"
-#include "glite/jp/context.h"
-#include "glite/jp/file_plugin.h"
-#include "glite/jp/builtin_plugins.h"
-#include "glite/jp/backend.h"
-#include "glite/jp/attr.h"
-#include "glite/jp/utils.h"
-#include "glite/jp/known_attr.h"
-#include "jp_job_attrs.h"
-
-#define INITIAL_NUMBER_EVENTS 100
-#define INITIAL_NUMBER_STATES EDG_WLL_NUMBER_OF_STATCODES
-#define LB_PLUGIN_NAMESPACE "urn:org.glite.lb"
-
-/*typedef struct _lb_buffer_t {
- char *buf;
- size_t pos, size;
- off_t offset;
-} lb_buffer_t;*/
-
-typedef struct _lb_historyStatus {
- edg_wll_JobStatCode state;
- struct timeval timestamp;
- char *reason;
-} lb_historyStatus;
-
-typedef struct _lb_handle {
- edg_wll_Event **events;
- edg_wll_JobStat status;
- lb_historyStatus **fullStatusHistory, **lastStatusHistory, *finalStatus;
- glite_jpps_fplug_data_t* classad_plugin;
-} lb_handle;
-
-#define check_strdup(s) ((s) ? strdup(s) : NULL)
-
-extern int processEvent(intJobStat *, edg_wll_Event *, int, int, char **);
-
-static int lb_query(void *fpctx, void *handle, const char *attr, glite_jp_attrval_t **attrval);
-static int lb_open(void *fpctx, void *bhandle, const char *uri, void **handle);
-static int lb_close(void *fpctx, void *handle);
-static int lb_filecom(void *fpctx, void *handle);
-static int lb_status(void *handle);
-//static int read_line(glite_jp_context_t ctx, void *handle, lb_buffer_t *buffer, char **line);
-
-static int lb_dummy(void *fpctx, void *handle, int oper, ...) {
- puts("lb_dummy() - generic call not used; for testing purposes only...");
- return -1;
-}
-
-int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data) {
-
- data->fpctx = ctx;
-
- data->uris = calloc(2,sizeof *data->uris);
- data->uris[0] = strdup(GLITE_JP_FILETYPE_LB);
-
- data->classes = calloc(2,sizeof *data->classes);
- data->classes[0] = strdup("lb");
-
- data->namespaces = calloc(4, sizeof *data->namespaces);
- data->namespaces[0] = strdup(GLITE_JP_LB_NS);
- data->namespaces[1] = strdup(GLITE_JP_LB_JDL_NS);
- data->namespaces[2] = strdup(GLITE_JP_LBTAG_NS);
-
- data->ops.open = lb_open;
- data->ops.close = lb_close;
- data->ops.filecom = lb_filecom;
- data->ops.attr = lb_query;
- data->ops.generic = lb_dummy;
-
-#ifdef PLUGIN_DEBUG
- fprintf(stderr,"lb_plugin: init OK\n");
-#endif
- return 0;
-}
-
-
-void done(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data) {
- free(data->uris[0]);
- free(data->classes[0]);
- free(data->namespaces[0]);
- free(data->namespaces[1]);
- free(data->namespaces[2]);
- free(data->uris);
- free(data->classes);
- free(data->namespaces);
- memset(data, 0, sizeof(*data));
-}
-
-
-static int lb_open(void *fpctx, void *bhandle, const char *uri, void **handle) {
-
- lb_handle *h;
- rl_buffer_t buffer;
- glite_jp_context_t ctx = (glite_jp_context_t) fpctx;
- char *line;
- int retval;
- edg_wll_Context context;
- int nevents, maxnevents, i;
- glite_jp_error_t err;
- char *id0 = NULL,*id = NULL;
-
- glite_jp_clear_error(ctx);
- h = calloc(1, sizeof(lb_handle));
-
- if ((retval = edg_wll_InitContext(&context)) != 0) return retval;
-
- // read the file given by bhandle
- // parse events into h->events array
- memset(&buffer, 0, sizeof(buffer));
- buffer.buf = malloc(BUFSIZ);
- maxnevents = INITIAL_NUMBER_EVENTS;
- nevents = 0;
- h->events = malloc(maxnevents * sizeof(edg_wll_Event *));
-
- if ((retval = glite_jppsbe_readline(ctx, bhandle, &buffer, &line)) != 0) {
- err.code = retval;
- err.desc = "reading LB logline";
- err.source = "lb_plugin.c:read_line()";
- glite_jp_stack_error(ctx,&err);
- goto fail;
- }
- while (line) {
-#ifdef PLUGIN_DEBUG
- //fprintf(stderr,"lb_plugin opened\n", line);
-#endif
-
- if (line[0]) {
- if (nevents >= maxnevents) {
- maxnevents <<= 1;
- h->events = realloc(h->events, maxnevents * sizeof(edg_wll_Event *));
- }
- if ((retval = edg_wll_ParseEvent(context, line, &h->events[nevents])) != 0) {
- char *ed;
- free(line);
- err.code = retval;
- edg_wll_Error(context,NULL,&ed);
- err.desc = ed;
- err.source = "edg_wll_ParseEvent()";
- glite_jp_stack_error(ctx,&err);
- free(ed);
- goto fail;
- }
- if (nevents == 0) {
- id0 = edg_wlc_JobIdGetUnique(h->events[nevents]->any.jobId );
- } else {
- id = edg_wlc_JobIdGetUnique(h->events[nevents]->any.jobId );
- if (strcmp(id0,id) != 0) {
- char et[BUFSIZ];
- retval = EINVAL;
- err.code = retval;
- snprintf(et,sizeof et,"Attempt to process different jobs. Id '%s' (event n.%d) differs from '%s'",id,nevents+1,id0);
- et[BUFSIZ-1] = 0;
- err.desc = et;
- err.source = "lb_plugin.c:edg_wlc_JobIdGetUnique()";
- glite_jp_stack_error(ctx,&err);
- goto fail;
- }
- }
-
- if (id) free(id); id = NULL;
- nevents++;
- }
- free(line);
-
- if ((retval = glite_jppsbe_readline(ctx, bhandle, &buffer, &line)) != 0) {
- err.code = retval;
- err.desc = "reading LB logline";
- err.source = "lb_plugin.c:read_line()";
- glite_jp_stack_error(ctx,&err);
- goto fail;
- }
- }
- free(line);
-
- free(buffer.buf);
- edg_wll_FreeContext(context);
-
- if (nevents >= maxnevents) {
- maxnevents <<= 1;
- h->events = realloc(h->events, maxnevents * sizeof(edg_wll_Event *));
- }
- h->events[nevents] = NULL;
-
-#ifdef PLUGIN_DEBUG
- fprintf(stderr,"lb_plugin: opened %d events\n", nevents);
-#endif
-
- // find classad plugin, if it is loaded
- int j;
- h->classad_plugin = NULL;
- for (i=0; ctx->plugins[i]; i++){
- glite_jpps_fplug_data_t *pd = ctx->plugins[i];
- if (pd->namespaces)
- for (j=0; pd->classes[j]; j++)
- if (! strcmp(pd->classes[j], "classad")){
- h->classad_plugin = pd;
- goto cont;
- }
- }
-cont:
-
- /* count state and status history of the job given by the loaded events */
- if ((retval = lb_status(h)) != 0) goto fail;
-
- *handle = (void *)h;
-
- return 0;
-
-fail:
-#ifdef PLUGIN_DEBUG
- fprintf(stderr,"lb_plugin: open ERROR\n");
-#endif
- for (i = 0; i < nevents; i++) {
- edg_wll_FreeEvent(h->events[i]);
- free(h->events[i]);
- }
- free(h->events);
- free(buffer.buf);
- if (id0) free(id0);
- if (id) free(id);
- edg_wll_FreeContext(context);
- free(h);
- *handle = NULL;
- err.code = EIO;
- err.desc = NULL;
- err.source = __FUNCTION__;
- glite_jp_stack_error(ctx,&err);
-
- return retval;
-}
-
-
-static int lb_close(void *fpctx,void *handle) {
-
- lb_handle *h = (lb_handle *) handle;
- int i;
-
- // Free allocated stuctures
- if (h->events) {
- i = 0;
- while (h->events[i]) {
- edg_wll_FreeEvent(h->events[i]);
- free(h->events[i]);
- i++;
- }
- free(h->events);
- }
-
- if (h->status.state != EDG_WLL_JOB_UNDEF)
- edg_wll_FreeStatus(&h->status);
-
- if (h->fullStatusHistory) {
- i = 0;
- while (h->fullStatusHistory[i]) {
- if (h->fullStatusHistory[i]->reason) free(h->fullStatusHistory[i]->reason);
- free (h->fullStatusHistory[i]);
- i++;
- }
- h->fullStatusHistory = NULL;
- h->lastStatusHistory = NULL;
- h->finalStatus = NULL;
- }
-
- free(h);
-
-#ifdef PLUGIN_DEBUG
- fprintf(stderr,"lb_plugin: close OK\n");
-#endif
- return 0;
-}
-
-static int get_classad_attr(const char* attr, glite_jp_context_t ctx, lb_handle *h, glite_jp_attrval_t **av){
- printf("attr = %s\n", attr);
- glite_jp_error_t err;
- glite_jp_clear_error(ctx);
- memset(&err,0,sizeof err);
- err.source = __FUNCTION__;
-
- if (! h->classad_plugin){
- err.code = ENOENT;
- err.desc = strdup("Classad plugin has not been loaded.");
- return glite_jp_stack_error(ctx,&err);
- }
- // Get the attribute from JDL
- int i = 0;
- while (h->events[i]){
- if (h->events[i]->type == EDG_WLL_EVENT_REGJOB
- && h->events[i]->regJob.jdl
- && h->events[i]->regJob.jdl[0])
- {
- void *beh;
- if (! h->classad_plugin->ops.open_str(h->classad_plugin->fpctx, h->events[i]->regJob.jdl, "", "", &beh)){
- if (! h->classad_plugin->ops.attr(h->classad_plugin->fpctx, beh, attr, av))
- (*av)[0].timestamp = h->events[i]->any.timestamp.tv_sec;
- else{
- h->classad_plugin->ops.close(h->classad_plugin->fpctx, beh);
- err.code = ENOENT;
- err.desc = strdup("Classad attribute not found.");
- return glite_jp_stack_error(ctx,&err);
- }
- h->classad_plugin->ops.close(h->classad_plugin->fpctx, beh);
- }
- }
- i++;
- }
- return 0;
-}
-
-static int lb_query(void *fpctx,void *handle, const char *attr,glite_jp_attrval_t **attrval) {
- lb_handle *h = (lb_handle *) handle;
- glite_jp_context_t ctx = (glite_jp_context_t) fpctx;
- glite_jp_error_t err;
- glite_jp_attrval_t *av = NULL;
- int i, j, n_tags;
- char *ns = glite_jpps_get_namespace(attr);
- char *tag;
-
- glite_jp_clear_error(ctx);
- memset(&err,0,sizeof err);
- err.source = __FUNCTION__;
-
- if ((h->events == NULL) ||
- (h->status.state == EDG_WLL_JOB_UNDEF) ||
- (h->fullStatusHistory == NULL) ) {
- *attrval = NULL;
- err.code = ENOENT;
- err.desc = strdup("There is no job information to query.");
- return glite_jp_stack_error(ctx,&err);
- }
-
- if (strcmp(ns, GLITE_JP_LB_JDL_NS) == 0){
- if (get_classad_attr(attr, ctx, h, &av)){
- *attrval = NULL;
- err.code = ENOENT;
- err.desc = strdup("Cannot get attribute from classad.");
- free(ns);
- return glite_jp_stack_error(ctx,&err);
- }
- }
- else if (strcmp(attr, GLITE_JP_LB_user) == 0) {
- if (h->status.owner) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(h->status.owner);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_jobId) == 0) {
- if (h->status.jobId) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = edg_wlc_JobIdUnparse(h->status.jobId);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_parent) == 0) {
- if (h->status.parent_job) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = edg_wlc_JobIdUnparse(h->status.parent_job);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_VO) == 0) {
- if (get_classad_attr(":VirtualOrganisation", ctx, h, &av)){
- printf("error");
- *attrval = NULL;
- err.code = ENOENT;
- err.desc = strdup("Cannot get attribute from classad.");
- free(ns);
- return glite_jp_stack_error(ctx,&err);
- }
- } else if (strcmp(attr, GLITE_JP_LB_eNodes) == 0) {
- if (get_classad_attr(":max_nodes_running", ctx, h, &av)){
- printf("error");
- *attrval = NULL;
- err.code = ENOENT;
- err.desc = strdup("Cannot get attribute from classad.");
- free(ns);
- return glite_jp_stack_error(ctx,&err);
- }
- } else if (strcmp(attr, GLITE_JP_LB_eProc) == 0) {
- if (get_classad_attr(":NodeNumber", ctx, h, &av)){
- printf("error");
- *attrval = NULL;
- err.code = ENOENT;
- err.desc = strdup("Cannot get attribute from classad.");
- free(ns);
- return glite_jp_stack_error(ctx,&err);
- }
- } else if (strcmp(attr, GLITE_JP_LB_aTag) == 0 ||
- strcmp(attr, GLITE_JP_LB_rQType) == 0 ||
- strcmp(attr, GLITE_JP_LB_eDuration) == 0) {
- /* have to be retrieved from JDL, but probably obsolete and not needed at all */
- char et[BUFSIZ];
- *attrval = NULL;
- err.code = ENOSYS;
- snprintf(et,sizeof et,"Attribute '%s' not implemented yet.",attr);
- et[BUFSIZ-1] = 0;
- err.desc = et;
- return glite_jp_stack_error(ctx,&err);
- } else if (strcmp(attr, GLITE_JP_LB_RB) == 0) {
- if (h->status.network_server) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(h->status.network_server);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_CE) == 0) {
- if (h->status.destination) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(h->status.destination);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_host) == 0) {
- if (h->status.ce_node) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(h->status.ce_node);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_UIHost) == 0) {
- i = 0;
- while (h->events[i]) {
- if (h->events[i]->type == EDG_WLL_EVENT_REGJOB) {
- if (h->events[i]->any.host) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(h->events[i]->any.host);
- av[0].size = -1;
- av[0].timestamp = h->events[i]->any.timestamp.tv_sec;
- }
- break;
- }
- i++;
- }
- } else if (strcmp(attr, GLITE_JP_LB_CPUTime) == 0) {
- if (h->status.cpuTime) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- trio_asprintf(&av[0].value,"%d", h->status.cpuTime);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_NProc) == 0) {
- /* currently LB hasn't got the info */
- char et[BUFSIZ];
- *attrval = NULL;
- err.code = ENOSYS;
- snprintf(et,sizeof et,"Attribute '%s' not implemented yet.",attr);
- et[BUFSIZ-1] = 0;
- err.desc = et;
- return glite_jp_stack_error(ctx,&err);
- } else if (strcmp(attr, GLITE_JP_LB_finalStatus) == 0) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- if (h->finalStatus) {
- av[0].value = edg_wll_StatToString(h->finalStatus->state);
- av[0].timestamp = h->finalStatus->timestamp.tv_sec;
- } else {
- av[0].value = edg_wll_StatToString(h->status.state);
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- av[0].size = -1;
- } else if (strcmp(attr, GLITE_JP_LB_finalStatusDate) == 0) {
- struct tm *t = NULL;
- if ( (h->finalStatus) &&
- ((t = gmtime(&h->finalStatus->timestamp.tv_sec)) != NULL) ) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- /* dateTime format: yyyy-mm-ddThh:mm:ss.uuuuuu */
- trio_asprintf(&av[0].value,"%04d-%02d-%02dT%02d:%02d:%02d.%06d",
- 1900+t->tm_year, 1+t->tm_mon, t->tm_mday,
- t->tm_hour, t->tm_min, t->tm_sec,
- h->finalStatus->timestamp.tv_usec);
- av[0].size = -1;
- av[0].timestamp = h->finalStatus->timestamp.tv_sec;
- } else if ((t = gmtime(&h->status.lastUpdateTime.tv_sec)) != NULL) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- /* dateTime format: yyyy-mm-ddThh:mm:ss.uuuuuu */
- trio_asprintf(&av[0].value,"%04d-%02d-%02dT%02d:%02d:%02d.%06d",
- 1900+t->tm_year, 1+t->tm_mon, t->tm_mday,
- t->tm_hour, t->tm_min, t->tm_sec,
- h->status.lastUpdateTime.tv_usec);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_finalStatusReason) == 0) {
- if (h->finalStatus && h->finalStatus->reason) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(h->finalStatus->reason);
- av[0].size = -1;
- av[0].timestamp = h->finalStatus->timestamp.tv_sec;
- } else if (h->status.reason) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(h->status.reason);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_LRMSDoneStatus) == 0) {
- i = 0;
- j = -1;
- while (h->events[i]) {
- if ( (h->events[i]->type == EDG_WLL_EVENT_DONE) &&
- (h->events[i]->any.source == EDG_WLL_SOURCE_LRMS) )
- j = i;
- i++;
- }
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].size = -1;
- if ( j != -1) {
- av[0].value = edg_wll_DoneStatus_codeToString(h->events[j]->done.status_code);
- av[0].timestamp = h->events[j]->any.timestamp.tv_sec;
- } else {
- av[0].value = edg_wll_DoneStatus_codeToString(h->status.done_code);
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_LRMSStatusReason) == 0) {
- i = 0;
- j = -1;
- while (h->events[i]) {
- if ( (h->events[i]->type == EDG_WLL_EVENT_DONE) &&
- (h->events[i]->any.source == EDG_WLL_SOURCE_LRMS) )
- j = i;
- i++;
- }
- if ( ( j != -1) && (h->events[j]->done.reason) ) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(h->events[j]->done.reason);
- av[0].size = -1;
- av[0].timestamp = h->events[j]->any.timestamp.tv_sec;
- }
- } else if (strcmp(attr, GLITE_JP_LB_retryCount) == 0) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- trio_asprintf(&av[0].value,"%d", h->status.resubmitted);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- } else if (strcmp(attr, GLITE_JP_LB_additionalReason) == 0) {
- /* what is it? */
- char et[BUFSIZ];
- *attrval = NULL;
- err.code = ENOSYS;
- snprintf(et,sizeof et,"Attribute '%s' not implemented yet.",attr);
- et[BUFSIZ-1] = 0;
- err.desc = et;
- return glite_jp_stack_error(ctx,&err);
- } else if (strcmp(attr, GLITE_JP_LB_jobType) == 0) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- switch (h->status.jobtype) {
- case EDG_WLL_STAT_SIMPLE:
- av[0].value = strdup("SIMPLE"); break;
- case EDG_WLL_STAT_DAG:
- av[0].value = strdup("DAG"); break;
- default:
- av[0].value = strdup("UNKNOWN"); break;
- }
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- } else if (strcmp(attr, GLITE_JP_LB_nsubjobs) == 0) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- trio_asprintf(&av[0].value,"%d", h->status.children_num);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- } else if (strcmp(attr, GLITE_JP_LB_subjobs) == 0) {
- if (h->status.children_num > 0) {
- char *val = NULL, *old_val;
-
- old_val = strdup ("");
- for (i=0; i<h->status.children_num; i++) {
- trio_asprintf(&val,"%s\t\t<jobId>%s</jobId>\n",
- old_val, h->status.children[i] ? h->status.children[i] : "");
- if (old_val) free(old_val);
- old_val = val; val = NULL;
- }
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = check_strdup(old_val);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- } else {
- char et[BUFSIZ];
- *attrval = NULL;
- err.code = ENOENT;
- snprintf(et,sizeof et,"Value unknown for attribute '%s', there are no subjobs.",attr);
- et[BUFSIZ-1] = 0;
- err.desc = et;
- return glite_jp_stack_error(ctx,&err);
- }
- } else if (strcmp(attr, GLITE_JP_LB_lastStatusHistory) == 0) {
- int i,j;
- char *val, *old_val, *s_str, *t_str, *r_str;
- struct tm *t;
-
- val = s_str = t_str = r_str = NULL;
- old_val = strdup("");
- t = calloc(1, sizeof(*t));
- /* first record is Submitted - hopefully in fullStatusHistory[0] */
- if ((h->fullStatusHistory[0] &&
- (h->fullStatusHistory[0]->state == EDG_WLL_JOB_SUBMITTED)) ) {
-
- s_str = edg_wll_StatToString(h->fullStatusHistory[0]->state);
- for (j = 0; s_str[j]; j++) s_str[j] = toupper(s_str[j]);
- if (gmtime_r(&h->fullStatusHistory[0]->timestamp.tv_sec,t) != NULL) {
- /* dateTime format: yyyy-mm-ddThh:mm:ss.uuuuuu */
- trio_asprintf(&t_str,"timestamp=\"%04d-%02d-%02dT%02d:%02d:%02d.%06d\" ",
- 1900+t->tm_year, 1+t->tm_mon, t->tm_mday,
- t->tm_hour, t->tm_min, t->tm_sec,
- h->fullStatusHistory[0]->timestamp.tv_usec);
- }
- if (h->fullStatusHistory[0]->reason) {
- trio_asprintf(&r_str,"reason=\"%s\" ",h->fullStatusHistory[0]->reason);
- }
- trio_asprintf(&val,"%s\t\t<status xmlns=\"" GLITE_JP_LB_NS "\" name=\"%s\" %s%s/>\n",
- old_val, s_str ? s_str : "", t_str ? t_str : "", r_str ? r_str : "");
- if (s_str) free(s_str);
- if (t_str) free(t_str);
- if (r_str) free(t_str);
- if (old_val) free(old_val);
- old_val = val; val = NULL;
- }
- /* and the rest is from last Waiting to the end - i.e. all lastStatusHistory[] */
- if (h->lastStatusHistory) {
- i = 0;
- while (h->lastStatusHistory[i]) {
- s_str = edg_wll_StatToString(h->lastStatusHistory[i]->state);
- for (j = 0; s_str[j]; j++) s_str[j] = toupper(s_str[j]);
- if (gmtime_r(&h->lastStatusHistory[i]->timestamp.tv_sec,t) != NULL) {
- /* dateTime format: yyyy-mm-ddThh:mm:ss.uuuuuu */
- trio_asprintf(&t_str,"timestamp=\"%04d-%02d-%02dT%02d:%02d:%02d.%06d\" ",
- 1900+t->tm_year, 1+t->tm_mon, t->tm_mday,
- t->tm_hour, t->tm_min, t->tm_sec,
- h->lastStatusHistory[i]->timestamp.tv_usec);
- }
- if (h->lastStatusHistory[i]->reason) {
- trio_asprintf(&r_str,"reason=\"%s\" ",h->lastStatusHistory[i]->reason);
- }
- trio_asprintf(&val,"%s\t\t<status xmlns=\"" GLITE_JP_LB_NS "\" name=\"%s\" %s%s/>\n",
- old_val, s_str ? s_str : "", t_str ? t_str : "", r_str ? r_str : "");
- if (s_str) free(s_str); s_str = NULL;
- if (t_str) free(t_str); t_str = NULL;
- if (r_str) free(r_str); r_str = NULL;
- if (old_val) free(old_val);
- old_val = val; val = NULL;
- i++;
- }
- }
- val = old_val; old_val = NULL;
- if (val) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(val);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- free(val);
- }
- } else if (strcmp(attr, GLITE_JP_LB_fullStatusHistory) == 0) {
- int i,j;
- char *val, *old_val, *s_str, *t_str, *r_str;
- struct tm *t;
-
- val = s_str = t_str = r_str = NULL;
- old_val = strdup("");
- t = calloc(1, sizeof(*t));
- i = 0;
- while (h->fullStatusHistory[i]) {
- s_str = edg_wll_StatToString(h->fullStatusHistory[i]->state);
- for (j = 0; s_str[j]; j++) s_str[j] = toupper(s_str[j]);
- if (gmtime_r(&h->fullStatusHistory[i]->timestamp.tv_sec,t) != NULL) {
- /* dateTime format: yyyy-mm-ddThh:mm:ss:uuuuuu */
- trio_asprintf(&t_str,"timestamp=\"%04d-%02d-%02dT%02d:%02d:%02d.%06d\" ",
- 1900+t->tm_year, 1+t->tm_mon, t->tm_mday,
- t->tm_hour, t->tm_min, t->tm_sec,
- h->fullStatusHistory[i]->timestamp.tv_usec);
- }
- if (h->fullStatusHistory[i]->reason) {
- trio_asprintf(&r_str,"reason=\"%s\" ",h->fullStatusHistory[i]->reason);
- }
- trio_asprintf(&val,"%s\t\t<status xmlns=\"" GLITE_JP_LB_NS "\" name=\"%s\" %s%s/>\n",
- old_val, s_str ? s_str : "", t_str ? t_str : "", r_str ? r_str : "");
- if (s_str) free(s_str); s_str = NULL;
- if (t_str) free(t_str); t_str = NULL;
- if (r_str) free(r_str); r_str = NULL;
- if (old_val) free(old_val);
- old_val = val; val = NULL;
- i++;
- }
- val = old_val; old_val = NULL;
- if (val) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(val);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- free(val);
- }
- } else if (strcmp(ns, GLITE_JP_LBTAG_NS) == 0) {
- tag = strrchr(attr, ':');
- if (h->events && tag) {
- tag++;
- i = 0;
- n_tags = 0;
-
- while (h->events[i]) {
- if ((h->events[i]->type == EDG_WLL_EVENT_USERTAG) &&
- (strcasecmp(h->events[i]->userTag.name, tag) == 0) ) {
-/* XXX: LB tag names are case-insensitive */
- av = realloc(av, (n_tags+2) * sizeof(glite_jp_attrval_t));
- memset(&av[n_tags], 0, 2 * sizeof(glite_jp_attrval_t));
-
- av[n_tags].name = strdup(attr);
- av[n_tags].value = check_strdup(h->events[i]->userTag.value);
- av[n_tags].timestamp =
- h->events[i]->any.timestamp.tv_sec;
- av[n_tags].size = -1;
-
- n_tags++;
- }
- i++;
- }
- }
- } else if (strcmp(attr, GLITE_JP_LB_JDL) == 0) {
- if (h->status.jdl) {
- av = calloc(2, sizeof(glite_jp_attrval_t));
- av[0].name = strdup(attr);
- av[0].value = strdup(h->status.jdl);
- av[0].size = -1;
- av[0].timestamp = h->status.lastUpdateTime.tv_sec;
- }
- } else {
- char et[BUFSIZ];
- *attrval = NULL;
- err.code = EINVAL;
- snprintf(et,sizeof et,"No such attribute '%s'.",attr);
- et[BUFSIZ-1] = 0;
- err.desc = et;
- return glite_jp_stack_error(ctx,&err);
- }
-
- free(ns);
-
- if (av && av[0].value) {
- for (i=0; av[i].name; i++) av[i].origin = GLITE_JP_ATTR_ORIG_FILE;
- *attrval = av;
- return 0;
- } else {
- char et[BUFSIZ];
- *attrval = NULL;
- err.code = ENOENT;
- snprintf(et,sizeof et,"Value unknown for attribute '%s'.",attr);
- et[BUFSIZ-1] = 0;
- err.desc = et;
- if (av) glite_jp_attrval_free(av,1); // XXX: probably not needed
- return glite_jp_stack_error(ctx,&err);
- }
-}
-
-static int lb_filecom(void *fpctx, void *handle){
- glite_jp_context_t ctx = (glite_jp_context_t) fpctx;
- lb_handle *h = (lb_handle *) handle;
- glite_jp_attrval_t attr[2];
- memset(attr, 0, 2 * sizeof(glite_jp_attrval_t));
-
- if (h->events) {
- int i = 0;
- while (h->events[i]) {
- if (h->events[i]->type == EDG_WLL_EVENT_USERTAG &&
- strchr(h->events[i]->userTag.name,':'))
- {
- //printf("%s, %s\n", edg_wlc_JobIdUnparse(h->status.jobId), h->status.jobId);
- attr[0].name = h->events[i]->userTag.name;
- attr[0].value = h->events[i]->userTag.value;
- attr[0].binary = 0;
- attr[0].origin = GLITE_JP_ATTR_ORIG_USER;
- attr[0].timestamp = time(NULL);
- attr[0].origin_detail = NULL; /* XXX */
- attr[1].name = NULL;
- glite_jppsbe_append_tag(ctx, edg_wlc_JobIdUnparse(h->status.jobId), attr);
- }
- i++;
- }
- }
-
- return 0;
-}
-
-static int lb_status(void *handle) {
-
- lb_handle *h = (lb_handle *) handle;
- intJobStat *js;
- int maxnstates, nstates, i, be_strict = 0, retval;
- char *errstring;
- edg_wll_JobStatCode old_state = EDG_WLL_JOB_UNDEF;
-
- js = calloc(1, sizeof(intJobStat));
- init_intJobStat(js);
-
- edg_wll_SortPEvents(h->events);
-
- maxnstates = INITIAL_NUMBER_STATES;
- nstates = 0;
- h->fullStatusHistory = calloc(maxnstates, sizeof(lb_historyStatus *));
- h->lastStatusHistory = NULL;
- h->finalStatus = NULL;
- i = 0;
- while (h->events[i])
- {
- /* realloc the fullStatusHistory if needed */
- if (nstates >= maxnstates) {
- maxnstates <<= 1;
- h->fullStatusHistory = realloc(h->fullStatusHistory, maxnstates * sizeof(lb_historyStatus *));
- }
-
- /* job owner and jobId not filled from events normally */
- if (h->events[i]->any.type == EDG_WLL_EVENT_REGJOB) {
- js->pub.owner = check_strdup(h->events[i]->any.user);
- if (edg_wlc_JobIdDup(h->events[i]->any.jobId,&js->pub.jobId)) {
- goto err;
- }
- }
- /* Process Event and update the state */
- if (processEvent(js, h->events[i], 0, be_strict, &errstring) == RET_FATAL) {
- goto err;
- }
-
- /* if the state has changed, update the status history */
- if (js->pub.state != old_state) {
- h->fullStatusHistory[nstates] = calloc(1,sizeof(lb_historyStatus));
- h->fullStatusHistory[nstates]->state = js->pub.state;
- h->fullStatusHistory[nstates]->timestamp.tv_sec = js->pub.stateEnterTime.tv_sec;
- h->fullStatusHistory[nstates]->timestamp.tv_usec = js->pub.stateEnterTime.tv_usec;
- h->fullStatusHistory[nstates]->reason = check_strdup(js->pub.reason);
- /* lastStatusHistory starts from the last WAITING state */
- if (js->pub.state == EDG_WLL_JOB_WAITING) {
- h->lastStatusHistory = &(h->fullStatusHistory[nstates]);
- }
- /* finalStatus is the one preceeding the CLEARED state */
- if ( (js->pub.state == EDG_WLL_JOB_CLEARED) && (nstates > 0) ) {
- h->finalStatus = h->fullStatusHistory[nstates-1];
- }
- old_state = js->pub.state;
- nstates++;
- }
-
- i++;
- }
- h->fullStatusHistory[nstates] = NULL;
- /* if there is no CLEARED state, finalStatus is just the last status
- and if there is no such thing, leave h->finalStatus NULL and for the attribute
- try to read something from the h->status */
- if ( (h->finalStatus == NULL) && (nstates > 0) ) {
- h->finalStatus = h->fullStatusHistory[nstates-1];
- }
-
- /* fill in also subjobs */
- if (js->pub.children_num > 0) {
- edg_wll_Context context;
- edg_wlc_JobId *subjobs;
-
- if ((retval = edg_wll_InitContext(&context)) != 0) return retval;
- subjobs = calloc(js->pub.children_num, sizeof (*subjobs));
- if ((retval = edg_wll_GenerateSubjobIds(context,
- js->pub.jobId, js->pub.children_num, js->pub.seed, &subjobs) ) != 0 ) {
- goto err;
- }
- js->pub.children = calloc(js->pub.children_num + 1, sizeof (*js->pub.children));
- for (i=0; i<js->pub.children_num; i++) {
- js->pub.children[i] = edg_wlc_JobIdUnparse(subjobs[i]);
- }
- edg_wll_FreeContext(context);
- free(subjobs);
- }
-
- memcpy(&h->status, &js->pub, sizeof(edg_wll_JobStat));
-
- // not very clean, but working
- memset(&js->pub, 0, sizeof(edg_wll_JobStat));
- destroy_intJobStat(js);
-
- return 0;
-
-err:
- destroy_intJobStat(js);
- return -1;
-}
-
-
-/*
- * realloc the line to double size if needed
- *
- * \return 0 if failed, did nothing
- * \return 1 if success
- */
-/*int check_realloc_line(char **line, size_t *maxlen, size_t len) {
- void *tmp;
-
- if (len > *maxlen) {
- *maxlen <<= 1;
- tmp = realloc(*line, *maxlen);
- if (!tmp) return 0;
- *line = tmp;
- }
-
- return 1;
-}
-*/
-
-/*
- * read next line from stream
- *
- * \return error code
- */
-/*static int read_line(glite_jp_context_t ctx, void *handle, lb_buffer_t *buffer, char **line) {
-
- size_t maxlen, len, i;
- ssize_t nbytes;
- int retval, z, end;
-
- maxlen = BUFSIZ;
- i = 0;
- len = 0;
- *line = malloc(maxlen);
- end = 0;
-
- do {
- // read next portion
- if (buffer->pos >= buffer->size) {
- buffer->pos = 0;
- buffer->size = 0;
- if ((retval = glite_jppsbe_pread(ctx, handle, buffer->buf, BUFSIZ, buffer->offset, &nbytes)) == 0) {
- if (nbytes < 0) {
- retval = EINVAL;
- goto fail;
- } else {
- if (nbytes) {
- buffer->size = (size_t)nbytes;
- buffer->offset += nbytes;
- } else end = 1;
- }
- } else goto fail;
- }
-
- // we have buffer->size - buffer->pos bytes
- i = buffer->pos;
- do {
- if (i >= buffer->size) z = '\0';
- else {
- z = buffer->buf[i];
- if (z == '\n') z = '\0';
- }
- len++;
-
- if (!check_realloc_line(line, &maxlen, len)) {
- retval = ENOMEM;
- goto fail;
- }
- (*line)[len - 1] = z;
- i++;
- } while (z && i < buffer->size);
- buffer->pos = i;
- } while (len && (*line)[len - 1] != '\0');
-
- if ((!len || !(*line)[0]) && end) {
- free(*line);
- *line = NULL;
- }
-
- return 0;
-
-fail:
- free(*line);
- *line = NULL;
- return retval;
-}
-*/
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-
-#include <expat.h>
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/mini_http.h"
-#include "glite/lb/xml_conversions.h"
-#include "glite/lb/dump.h"
-#include "glite/lb/load.h"
-#include "glite/lb/purge.h"
-
-#include "lb_proto.h"
-#include "lb_html.h"
-#include "stats.h"
-#include "get_events.h"
-#include "purge.h"
-#include "lb_xml_parse.h"
-#include "lb_xml_parse_V21.h"
-
-
-#define METHOD_GET "GET "
-#define METHOD_POST "POST "
-
-#define KEY_QUERY_JOBS "/queryJobs "
-#define KEY_QUERY_EVENTS "/queryEvents "
-#define KEY_PURGE_REQUEST "/purgeRequest "
-#define KEY_DUMP_REQUEST "/dumpRequest "
-#define KEY_LOAD_REQUEST "/loadRequest "
-#define KEY_INDEXED_ATTRS "/indexedAttrs "
-#define KEY_NOTIF_REQUEST "/notifRequest "
-#define KEY_QUERY_SEQUENCE_CODE "/querySequenceCode "
-#define KEY_STATS_REQUEST "/statsRequest "
-#define KEY_HTTP "HTTP/1.1"
-
-
-#define KEY_ACCEPT "Accept:"
-#define KEY_APP "application/x-dglb"
-#define KEY_AGENT "User-Agent"
-
-
-const char* const response_headers[] = {
- "Cache-Control: no-cache",
- "Accept: application/x-dglb",
- "User-Agent: edg_wll_Server/" PROTO_VERSION "/" COMP_PROTO,
- "Content-Type: application/x-dglb",
- NULL
-};
-
-extern int edg_wll_NotifNewServer(edg_wll_Context,
- edg_wll_QueryRec const * const *, char const *,
- const edg_wll_NotifId, time_t *);
-extern int edg_wll_NotifBindServer(edg_wll_Context,
- const edg_wll_NotifId, const char *, time_t *);
-extern int edg_wll_NotifChangeServer(edg_wll_Context,
- const edg_wll_NotifId, edg_wll_QueryRec const * const *,
- edg_wll_NotifChangeOp);
-extern int edg_wll_NotifRefreshServer(edg_wll_Context,
- const edg_wll_NotifId, time_t *);
-extern int edg_wll_NotifDropServer(edg_wll_Context, edg_wll_NotifId *);
-
-
-
-char *edg_wll_HTTPErrorMessage(int errCode)
-{
- char *msg;
-
- switch (errCode) {
- case HTTP_OK: msg = "OK"; break;
- case HTTP_BADREQ: msg = "Bad Request"; break;
- case HTTP_UNAUTH: msg = "Unauthorized"; break;
- case HTTP_NOTFOUND: msg = "Not Found"; break;
- case HTTP_NOTALLOWED: msg = "Method Not Allowed"; break;
- case HTTP_UNSUPPORTED: msg = "Unsupported Media Type"; break;
- case HTTP_NOTIMPL: msg = "Not Implemented"; break;
- case HTTP_INTERNAL: msg = "Internal Server Error"; break;
- case HTTP_UNAVAIL: msg = "Service Unavailable"; break;
- case HTTP_INVALID: msg = "Invalid Data"; break;
- default: msg = "Unknown error"; break;
- }
-
- return msg;
-}
-
-
-/* returns non-zero if old style (V21) protocols incompatible */
-static int is_protocol_incompatibleV21(char *user_agent)
-{
- char *version, *comp_proto, *needle;
- double v, c, my_v = strtod(PROTO_VERSION_V21, (char **) NULL), my_c;
-
-
- /* get version od the other side */
- if ((version = strstr(user_agent,"/")) == NULL) return(-1);
- else v = strtod(++version, &needle);
-
- /* sent the other side list of compatible protocols? */
- if ( needle[0] == '\0' ) return(-2);
-
- /* test compatibility if server newer*/
- if (my_v > v) {
- comp_proto=COMP_PROTO_V21;
- do {
- my_c = strtod(comp_proto, &needle);
- if (my_c == v) return(0);
- comp_proto = needle + 1;
- } while (needle[0] != '\0');
- return(1);
- }
-
- /* test compatibility if server is older */
- else if (my_v < v) {
- do {
- comp_proto = needle + 1;
- c = strtod(comp_proto, &needle);
- if (my_v == c) return(0);
- } while (needle[0] != '\0');
- return(1);
- }
-
- /* version match */
- return(0);
-}
-
-
-/* returns non-zero if protocols incompatible */
-static int is_protocol_incompatible(char *user_agent)
-{
- char *version, *comp_proto, *needle;
- double v, c, my_v = strtod(PROTO_VERSION, (char **) NULL), my_c;
-
-
- /* get version od the other side */
- if ((version = strstr(user_agent,"/")) == NULL) return(-1);
- else v = strtod(++version, &needle);
-
- /* sent the other side list of compatible protocols? */
- if ( needle[0] == '\0' ) return(-2);
-
- /* test compatibility if server newer*/
- if (my_v > v) {
- comp_proto=COMP_PROTO;
- do {
- my_c = strtod(comp_proto, &needle);
- if (my_c == v) return(0);
- comp_proto = needle + 1;
- } while (needle[0] != '\0');
- return(1);
- }
-
- /* test compatibility if server is older */
- else if (my_v < v) {
- do {
- comp_proto = needle + 1;
- c = strtod(comp_proto, &needle);
- if (my_v == c) return(0);
- } while (needle[0] != '\0');
- return(1);
- }
-
- /* version match */
- return(0);
-}
-
-
-static int outputHTML(char **headers)
-{
- int i;
-
- if (!headers) return 0;
-
- for (i=0; headers[i]; i++)
- if (!strncmp(headers[i], KEY_ACCEPT, sizeof(KEY_ACCEPT) - 1)) {
- if (strstr(headers[i],KEY_APP))
- return 0; /* message sent by edg_wll_Api */
- else
- return 1; /* message sent by other application */
- }
- return 1;
-
-}
-
-
-
-
-edg_wll_ErrorCode edg_wll_ProtoV21(edg_wll_Context ctx,
- char *request,char **headers,char *messageBody,
- char **response,char ***headersOut,char **bodyOut)
-{
- char *requestPTR, *message = NULL;
- int ret = HTTP_OK;
- int html = outputHTML(headers);
- int i;
-
- edg_wll_ResetError(ctx);
-
- for (i=0; headers[i]; i++) /* find line with version number in headers */
- if ( strstr(headers[i], KEY_AGENT) ) break;
-
- if (headers[i] == NULL) { ret = HTTP_BADREQ; goto errV21; } /* if not present */
- switch (is_protocol_incompatibleV21(headers[i])) {
- case 0 : /* protocols compatible */
- ctx->is_V21 = 1;
- break;
- case -1 : /* malformed 'User Agent:' line */
- ret = HTTP_BADREQ;
- goto errV21;
- break;
- case -2 : /* version of one protocol unknown */
- /* fallthrough */
- case 1 : /* protocols incompatible */
- /* fallthrough */
- default : ret = HTTP_UNSUPPORTED;
- edg_wll_SetError(ctx,ENOTSUP,"Protocol versions are incompatible.");
- goto errV21;
- break;
- }
-
-
-/* GET */
- if (!strncmp(request, METHOD_GET, sizeof(METHOD_GET)-1)) {
- // Not supported
- ret = HTTP_BADREQ;
-/* POST */
- } else if (!strncmp(request,METHOD_POST,sizeof(METHOD_POST)-1)) {
-
- requestPTR = request + sizeof(METHOD_POST)-1;
-
- if (!strncmp(requestPTR,KEY_QUERY_EVENTS,sizeof(KEY_QUERY_EVENTS)-1)) {
- edg_wll_Event *eventsOut = NULL;
- edg_wll_QueryRec **job_conditions = NULL, **event_conditions = NULL;
- int i,j;
-
- if (parseQueryEventsRequestV21(ctx, messageBody, &job_conditions, &event_conditions))
- ret = HTTP_BADREQ;
-
- else {
- int fatal = 0;
-
- switch (edg_wll_QueryEventsServer(ctx,ctx->noAuth,
- (const edg_wll_QueryRec **)job_conditions,
- (const edg_wll_QueryRec **)event_conditions, &eventsOut)) {
-
- case 0: if (html) ret = HTTP_NOTIMPL;
- else ret = HTTP_OK;
- break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EPERM : ret = HTTP_UNAUTH; break;
- case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAUTH; break;
- case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break;
- default: ret = HTTP_INTERNAL; break;
- }
- /* glue errors (if eny) to XML responce */
- if (!html && !fatal)
- if (edg_wll_QueryEventsToXMLV21(ctx, eventsOut, &message))
- ret = HTTP_INTERNAL;
- }
-
- if (job_conditions) {
- for (j = 0; job_conditions[j]; j++) {
- for (i = 0 ; (job_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&job_conditions[j][i]);
- free(job_conditions[j]);
- }
- free(job_conditions);
- }
-
- if (event_conditions) {
- for (j = 0; event_conditions[j]; j++) {
- for (i = 0 ; (event_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&event_conditions[j][i]);
- free(event_conditions[j]);
- }
- free(event_conditions);
- }
-
- if (eventsOut != NULL) {
- for (i=0; eventsOut[i].type != EDG_WLL_EVENT_UNDEF; i++)
- edg_wll_FreeEvent(&(eventsOut[i]));
- edg_wll_FreeEvent(&(eventsOut[i])); /* free last line */
- free(eventsOut);
- }
- }
- else if (!strncmp(requestPTR,KEY_QUERY_JOBS,sizeof(KEY_QUERY_JOBS)-1)) {
- edg_wlc_JobId *jobsOut = NULL;
- edg_wll_JobStat *statesOut = NULL;
- edg_wll_QueryRec **conditions = NULL;
- int i,j, flags = 0;
-
- if (parseQueryJobsRequestV21(ctx, messageBody, &conditions, &flags))
- ret = HTTP_BADREQ;
-
- else {
- int fatal = 0,
- retCode;
-
- if (flags & EDG_WLL_STAT_NO_JOBS) {
- flags -= EDG_WLL_STAT_NO_JOBS;
- jobsOut = NULL;
- if (flags & EDG_WLL_STAT_NO_STATES) {
- flags -= EDG_WLL_STAT_NO_STATES;
- statesOut = NULL;
- retCode = edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, NULL, NULL);
- }
- else
- retCode = edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, NULL, &statesOut);
- }
- else {
- if (flags & EDG_WLL_STAT_NO_STATES) {
- flags -= EDG_WLL_STAT_NO_STATES;
- statesOut = NULL;
- retCode = edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, &jobsOut, NULL);
- }
- else
- retCode = edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, &jobsOut, &statesOut);
- }
-
- switch ( retCode ) {
- // case EPERM : ret = HTTP_UNAUTH;
- // /* soft-error fall through */
- case 0: if (html) ret = HTTP_NOTIMPL;
- else ret = HTTP_OK;
-
- break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EPERM: ret = HTTP_UNAUTH; break;
- case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAUTH; break;
- case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break;
- default: ret = HTTP_INTERNAL; break;
- }
- if (!html && !fatal)
- if (edg_wll_QueryJobsToXMLV21(ctx, jobsOut, statesOut, &message))
- ret = HTTP_INTERNAL;
- }
-
- if (conditions) {
- for (j = 0; conditions[j]; j++) {
- for (i = 0; (conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&conditions[j][i]);
- free(conditions[j]);
- }
- free(conditions);
- }
-
- if (jobsOut) {
- for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]);
- free(jobsOut);
- }
- if (statesOut) {
- for (i=0; statesOut[i].state != EDG_WLL_JOB_UNDEF; i++)
- edg_wll_FreeStatus(&(statesOut[i]));
- edg_wll_FreeStatus(&(statesOut[i])); /* free last line */
- free(statesOut);
- }
- }
- /* POST [something else]: not understood */
- else ret = HTTP_BADREQ;
-
-/* other HTTP methods */
- } else ret = HTTP_NOTALLOWED;
-
-errV21: asprintf(response,"HTTP/1.1 %d %s",ret,edg_wll_HTTPErrorMessage(ret));
- *headersOut = (char **) response_headers;
- if ((ret != HTTP_OK) && html)
- *bodyOut = edg_wll_ErrorToHTML(ctx,ret);
- else
- *bodyOut = message;
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-
-
-edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
- char *request,char **headers,char *messageBody,
- char **response,char ***headersOut,char **bodyOut)
-{
- char *requestPTR, *message = NULL;
- int ret = HTTP_OK;
- int html = outputHTML(headers);
- int i;
-
- edg_wll_ResetError(ctx);
-
- for (i=0; headers[i]; i++) /* find line with version number in headers */
- if ( strstr(headers[i], KEY_AGENT) ) break;
-
- if (headers[i] == NULL) { ret = HTTP_BADREQ; goto err; } /* if not present */
- switch (is_protocol_incompatible(headers[i])) {
- case 0 : /* protocols compatible */
- ctx->is_V21 = 0;
- break;
- case -1 : /* malformed 'User Agent:' line */
- ret = HTTP_BADREQ;
- goto err;
- break;
- case 1 : /* protocols incompatible */
- /* try old (V21) version compatibility */
- edg_wll_ProtoV21(ctx, request, headers, messageBody,
- response, headersOut, bodyOut);
-
- /* and propagate errors or results */
- return edg_wll_Error(ctx,NULL,NULL);
- break;
- case -2 : /* version of one protocol unknown */
- /* fallthrough */
- default : ret = HTTP_UNSUPPORTED;
- edg_wll_SetError(ctx,ENOTSUP,"Protocol versions are incompatible.");
- goto err;
- break;
- }
-
-
-/* GET */
- if (!strncmp(request, METHOD_GET, sizeof(METHOD_GET)-1)) {
-
- requestPTR = request + sizeof(METHOD_GET)-1;
-
-
- /* GET /: Current User Jobs */
- if (requestPTR[0]=='/' && (requestPTR[1]==' ' || requestPTR[1]=='?')) {
- edg_wlc_JobId *jobsOut = NULL;
- int i, flags;
-
- flags = (requestPTR[1]=='?') ? edg_wll_string_to_stat_flags(requestPTR + 2) : 0;
-
-// FIXME: edg_wll_UserJobs should take flags as parameter
- if (!ctx->peerName) {
- edg_wll_SetError(ctx,EPERM,"Operation not permitted.");
- ret = HTTP_UNAUTH;
- }
- switch (edg_wll_UserJobs(ctx,&jobsOut,NULL)) {
- case 0: if (html) edg_wll_UserJobsToHTML(ctx, jobsOut, &message);
- else ret = HTTP_OK;
- break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- default: ret = HTTP_INTERNAL; break;
- }
- if (!html && (ret != HTTP_INTERNAL))
- if (edg_wll_UserJobsToXML(ctx, jobsOut, &message))
- ret = HTTP_INTERNAL;
-
- if (jobsOut) {
- for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]);
- free(jobsOut);
- }
- }
-
- /* GET /[jobId]: Job Status */
- else if (*requestPTR=='/') {
- edg_wlc_JobId jobId = NULL;
- char *pom1,*fullid = NULL;
- edg_wll_JobStat stat;
- char *pomCopy;
-
- if (ctx->srvName == NULL) {
- edg_wll_SetError(ctx, EDG_WLL_ERROR_SERVER_RESPONSE,
- "no server name on GET /jobid");
- ret = HTTP_INTERNAL;
- goto err;
- }
- memset(&stat,0,sizeof(stat));
- pomCopy = strdup(requestPTR + 1);
- for (pom1=pomCopy; *pom1 && !isspace(*pom1); pom1++);
- *pom1 = 0;
-
- asprintf(&fullid,GLITE_WMSC_JOBID_PROTO_PREFIX"%s:%u/%s",ctx->srvName,ctx->srvPort,pomCopy);
- free(pomCopy);
-
- if (edg_wlc_JobIdParse(fullid, &jobId)) {
- edg_wll_SetError(ctx,EDG_WLL_ERROR_JOBID_FORMAT,fullid);
- ret = HTTP_BADREQ;
- }
- else switch (edg_wll_JobStatus(ctx,jobId,0,&stat)) {
- case 0: if (html) edg_wll_JobStatusToHTML(ctx,stat,&message);
- else ret = HTTP_OK;
- break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EINVAL: ret = HTTP_INVALID; break;
- case EPERM : ret = HTTP_UNAUTH; break;
- default: ret = HTTP_INTERNAL; break;
- }
- if (!html && (ret != HTTP_INTERNAL))
- if (edg_wll_JobStatusToXML(ctx,stat,&message))
- ret = HTTP_INTERNAL;
-
- free(fullid);
- edg_wlc_JobIdFree(jobId);
- edg_wll_FreeStatus(&stat);
-
- /* GET [something else]: not understood */
- } else ret = HTTP_BADREQ;
-
-/* POST */
- } else if (!strncmp(request,METHOD_POST,sizeof(METHOD_POST)-1)) {
-
- requestPTR = request + sizeof(METHOD_POST)-1;
-
- if (!strncmp(requestPTR,KEY_QUERY_EVENTS,sizeof(KEY_QUERY_EVENTS)-1)) {
- edg_wll_Event *eventsOut = NULL;
- edg_wll_QueryRec **job_conditions = NULL, **event_conditions = NULL;
- int i,j;
-
- if (parseQueryEventsRequest(ctx, messageBody, &job_conditions, &event_conditions))
- ret = HTTP_BADREQ;
-
- else {
- int fatal = 0;
-
- switch (edg_wll_QueryEventsServer(ctx,ctx->noAuth,
- (const edg_wll_QueryRec **)job_conditions,
- (const edg_wll_QueryRec **)event_conditions, &eventsOut)) {
-
- case 0: if (html) ret = HTTP_NOTIMPL;
- else ret = HTTP_OK;
- break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EPERM : ret = HTTP_UNAUTH; break;
- case E2BIG: ret = HTTP_UNAUTH; break;
- case EINVAL: ret = HTTP_UNAUTH; break;
- case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAUTH; break;
- case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break;
- default: ret = HTTP_INTERNAL; break;
- }
- /* glue errors (if eny) to XML responce */
- if (!html && !fatal)
- if (edg_wll_QueryEventsToXML(ctx, eventsOut, &message))
- ret = HTTP_INTERNAL;
- }
-
- if (job_conditions) {
- for (j = 0; job_conditions[j]; j++) {
- for (i = 0 ; (job_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&job_conditions[j][i]);
- free(job_conditions[j]);
- }
- free(job_conditions);
- }
-
- if (event_conditions) {
- for (j = 0; event_conditions[j]; j++) {
- for (i = 0 ; (event_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&event_conditions[j][i]);
- free(event_conditions[j]);
- }
- free(event_conditions);
- }
-
- if (eventsOut != NULL) {
- for (i=0; eventsOut[i].type != EDG_WLL_EVENT_UNDEF; i++)
- edg_wll_FreeEvent(&(eventsOut[i]));
- edg_wll_FreeEvent(&(eventsOut[i])); /* free last line */
- free(eventsOut);
- }
- }
- else if (!strncmp(requestPTR,KEY_QUERY_JOBS,sizeof(KEY_QUERY_JOBS)-1)) {
- edg_wlc_JobId *jobsOut = NULL;
- edg_wll_JobStat *statesOut = NULL;
- edg_wll_QueryRec **conditions = NULL;
- int i,j, flags = 0;
-
- if (parseQueryJobsRequest(ctx, messageBody, &conditions, &flags))
- ret = HTTP_BADREQ;
-
- else {
- int fatal = 0,
- retCode;
-
- if (flags & EDG_WLL_STAT_NO_JOBS) {
- flags -= EDG_WLL_STAT_NO_JOBS;
- jobsOut = NULL;
- if (flags & EDG_WLL_STAT_NO_STATES) {
- flags -= EDG_WLL_STAT_NO_STATES;
- statesOut = NULL;
- retCode = edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, NULL, NULL);
- }
- else
- retCode = edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, NULL, &statesOut);
- }
- else {
- if (flags & EDG_WLL_STAT_NO_STATES) {
- flags -= EDG_WLL_STAT_NO_STATES;
- statesOut = NULL;
- retCode = edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, &jobsOut, NULL);
- }
- else
- retCode = edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, &jobsOut, &statesOut);
- }
-
- switch ( retCode ) {
- // case EPERM : ret = HTTP_UNAUTH;
- // /* soft-error fall through */
- case 0: if (html) ret = HTTP_NOTIMPL;
- else ret = HTTP_OK;
-
- break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EPERM: ret = HTTP_UNAUTH; break;
- case E2BIG: ret = HTTP_UNAUTH; break;
- case EINVAL: ret = HTTP_UNAUTH; break;
- case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAUTH; break;
- case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break;
- default: ret = HTTP_INTERNAL; break;
- }
- if (!html && !fatal)
- if (edg_wll_QueryJobsToXML(ctx, jobsOut, statesOut, &message))
- ret = HTTP_INTERNAL;
- }
-
- if (conditions) {
- for (j = 0; conditions[j]; j++) {
- for (i = 0; (conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&conditions[j][i]);
- free(conditions[j]);
- }
- free(conditions);
- }
-
- if (jobsOut) {
- for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]);
- free(jobsOut);
- }
- if (statesOut) {
- for (i=0; statesOut[i].state != EDG_WLL_JOB_UNDEF; i++)
- edg_wll_FreeStatus(&(statesOut[i]));
- edg_wll_FreeStatus(&(statesOut[i])); /* free last line */
- free(statesOut);
- }
- }
- else if (!strncmp(requestPTR,KEY_PURGE_REQUEST,sizeof(KEY_PURGE_REQUEST)-1)) {
- edg_wll_PurgeRequest request;
-
- ctx->p_tmp_timeout.tv_sec = 86400;
-
- if ( !parsePurgeRequest(ctx,messageBody,(int (*)()) edg_wll_StringToStat,&request) )
- edg_wll_PurgeServer(ctx, (const edg_wll_PurgeRequest *)&request);
-
- if ( request.jobs )
- {
- int i;
- for ( i = 0; request.jobs[i]; i++ )
- free(request.jobs[i]);
- free(request.jobs);
- }
-
- /*
- * response allready sent from edg_wll_PurgeServer() - return NULL results
- */
- *response = NULL;
- *headersOut = NULL;
- *bodyOut = NULL;
- return edg_wll_Error(ctx,NULL,NULL);
- }
- else if (!strncmp(requestPTR,KEY_DUMP_REQUEST,sizeof(KEY_DUMP_REQUEST)-1)) {
- edg_wll_DumpRequest request;
- edg_wll_DumpResult result;
-
- ctx->p_tmp_timeout.tv_sec = 86400;
-
- memset(&request,0,sizeof(request));
- memset(&result,0,sizeof(result));
-
- if (parseDumpRequest(ctx, messageBody, &request))
- ret = HTTP_BADREQ;
- else {
- int fatal = 0;
-
- switch (edg_wll_DumpEvents(ctx,(const edg_wll_DumpRequest *) &request, &result)) {
- case 0: if (html) ret = HTTP_NOTIMPL;
- else ret = HTTP_OK;
- break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EPERM : ret = HTTP_UNAUTH; break;
- case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAUTH; break;
- case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break;
- default: ret = HTTP_INTERNAL; break;
- }
- /* glue errors (if eny) to XML responce */
- if (!html && !fatal)
- if (edg_wll_DumpResultToXML(ctx, &result, &message))
- ret = HTTP_INTERNAL;
- }
-
- free(result.server_file);
- }
- else if (!strncmp(requestPTR,KEY_LOAD_REQUEST,sizeof(KEY_LOAD_REQUEST)-1)) {
- edg_wll_LoadRequest request;
- edg_wll_LoadResult result;
-
- ctx->p_tmp_timeout.tv_sec = 86400;
-
- memset(&request,0,sizeof(request));
- memset(&result,0,sizeof(result));
-
- if (parseLoadRequest(ctx, messageBody, &request))
- ret = HTTP_BADREQ;
- else {
- int fatal = 0;
-
- switch (edg_wll_LoadEvents(ctx,(const edg_wll_LoadRequest *) &request, &result)) {
- case 0: if (html) ret = HTTP_NOTIMPL;
- else ret = HTTP_OK;
- break;
- case EEXIST: ret = HTTP_OK; break;
- case EINVAL: ret = HTTP_INVALID; break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EPERM : ret = HTTP_UNAUTH; break;
- case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAUTH; break;
- case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break;
- default: ret = HTTP_INTERNAL; break;
- }
- /* glue errors (if eny) to XML responce */
- if (!html && !fatal)
- if (edg_wll_LoadResultToXML(ctx, &result, &message))
- ret = HTTP_INTERNAL;
- }
-
- free(result.server_file);
- }
- else if (!strncmp(requestPTR,KEY_INDEXED_ATTRS,sizeof(KEY_INDEXED_ATTRS)-1)) {
- if (!html)
- if (edg_wll_IndexedAttrsToXML(ctx, &message))
- ret = HTTP_INTERNAL;
- }
- else if (!strncmp(requestPTR,KEY_NOTIF_REQUEST,sizeof(KEY_NOTIF_REQUEST)-1)) {
- char *function, *address;
- edg_wll_NotifId notifId;
- edg_wll_NotifChangeOp op;
- edg_wll_QueryRec **conditions;
- time_t validity = -1;
- int i,j;
-
-
- if (parseNotifRequest(ctx, messageBody, &function, ¬ifId,
- &address, &op, &conditions))
- ret = HTTP_BADREQ;
- else {
- int fatal = 0, err = 0;
-
- // XXX presne poradi parametru zatim neni znamo
- // navratove chyby nejsou zname, nutno predelat dle aktualni situace
- if (!strcmp(function,"New"))
- err = edg_wll_NotifNewServer(ctx,
- (edg_wll_QueryRec const * const *)conditions,
- address, notifId, &validity);
- else if (!strcmp(function,"Bind"))
- err = edg_wll_NotifBindServer(ctx, notifId, address, &validity);
- else if (!strcmp(function,"Change"))
- err = edg_wll_NotifChangeServer(ctx, notifId,
- (edg_wll_QueryRec const * const *)conditions, op);
- else if (!strcmp(function,"Refresh"))
- err = edg_wll_NotifRefreshServer(ctx, notifId, &validity);
- else if (!strcmp(function,"Drop"))
- err = edg_wll_NotifDropServer(ctx, notifId);
-
- switch (err) {
- case 0: if (html) ret = HTTP_NOTIMPL;
- else ret = HTTP_OK;
- break;
- case EEXIST: ret = HTTP_OK; break;
- case EINVAL: ret = HTTP_INVALID; break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EPERM : ret = HTTP_UNAUTH; break;
- case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAUTH; break;
- case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break;
- default: ret = HTTP_INTERNAL; break;
- }
- /* glue errors (if eny) to XML responce */
- if (!html && !fatal)
- if (edg_wll_NotifResultToXML(ctx, validity, &message))
- ret = HTTP_INTERNAL;
- }
-
- free(function);
- free(address);
- edg_wll_NotifIdFree(notifId);
- if (conditions) {
- for (j = 0; conditions[j]; j++) {
- for (i = 0; (conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&conditions[j][i]);
- free(conditions[j]);
- }
- free(conditions);
- }
- }
- else if (!strncmp(requestPTR,KEY_QUERY_SEQUENCE_CODE,sizeof(KEY_QUERY_SEQUENCE_CODE)-1)) {
- char *source = NULL;
- char *seqCode = NULL;
- edg_wlc_JobId jobId = NULL;
-
-
- if (parseQuerySequenceCodeRequest(ctx, messageBody, &jobId, &source))
- ret = HTTP_BADREQ;
- else {
- int fatal = 0;
-
- switch (edg_wll_QuerySequenceCodeServer(ctx, jobId, source, &seqCode)) {
- case 0: if (html) ret = HTTP_NOTIMPL;
- else ret = HTTP_OK;
- break;
- case EEXIST: ret = HTTP_OK; break;
- case EINVAL: ret = HTTP_INVALID; break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EPERM : ret = HTTP_UNAUTH; break;
- case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAUTH; break;
- case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break;
- default: ret = HTTP_INTERNAL; break;
- }
-
- /* glue errors (if eny) to XML responce */
- if (!html && !fatal)
- if (edg_wll_QuerySequenceCodeResultToXML(ctx, seqCode, &message))
- ret = HTTP_INTERNAL;
- }
-
- if ( source ) free(source);
- if ( seqCode ) free(seqCode);
- edg_wlc_JobIdFree(jobId);
- }
- else if (!strncmp(requestPTR,KEY_STATS_REQUEST,sizeof(KEY_STATS_REQUEST)-1)) {
- char *function;
- edg_wll_QueryRec **conditions;
- edg_wll_JobStatCode major = EDG_WLL_JOB_UNDEF;
- time_t from, to;
- int i, j, minor, res_from, res_to;
- float rate = 0, duration = 0;
-
-
-
- if (parseStatsRequest(ctx, messageBody, &function, &conditions,
- &major, &minor, &from, &to))
- ret = HTTP_BADREQ;
- else {
- int fatal = 0, err = 0;
-
- // XXX presne poradi parametru zatim neni znamo
- // navratove chyby nejsou zname, nutno predelat dle aktualni situace
- if (!strcmp(function,"Rate"))
- err = edg_wll_StateRateServer(ctx,
- conditions[0], major, minor,
- &from, &to, &rate, &res_from, &res_to);
- else if (!strcmp(function,"Duration"))
- err = edg_wll_StateDurationServer(ctx,
- conditions[0], major, minor,
- &from, &to, &duration, &res_from, &res_to);
-
- switch (err) {
- case 0: if (html) ret = HTTP_NOTIMPL;
- else ret = HTTP_OK;
- break;
- case ENOSYS: ret = HTTP_NOTIMPL; break;
- case EEXIST: ret = HTTP_OK; break;
- case EINVAL: ret = HTTP_INVALID; break;
- case ENOENT: ret = HTTP_NOTFOUND; break;
- case EPERM : ret = HTTP_UNAUTH; break;
- case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAUTH; break;
- case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break;
- default: ret = HTTP_INTERNAL; break;
- }
- /* glue errors (if eny) to XML responce */
- if (!html && !fatal)
- if (edg_wll_StatsResultToXML(ctx, from, to, rate,
- duration, res_from, res_to, &message))
- ret = HTTP_INTERNAL;
- }
-
- free(function);
- if (conditions) {
- for (j = 0; conditions[j]; j++) {
- for (i = 0; (conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&conditions[j][i]);
- free(conditions[j]);
- }
- free(conditions);
- }
- }
-
-
- /* POST [something else]: not understood */
- else ret = HTTP_BADREQ;
-
-/* other HTTP methods */
- } else ret = HTTP_NOTALLOWED;
-
-err: asprintf(response,"HTTP/1.1 %d %s",ret,edg_wll_HTTPErrorMessage(ret));
- *headersOut = (char **) response_headers;
- if ((ret != HTTP_OK) && html)
- *bodyOut = edg_wll_ErrorToHTML(ctx,ret);
- else
- *bodyOut = message;
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
+++ /dev/null
-#ifndef _LB_PROTO_H
-#define _LB_PROTO_H
-
-#ident "$Header$"
-
-#include "glite/lb/consumer.h"
-
-extern const char* const response_headers[];
-
-/* Handle a single request of the LB server protocol
- * returns a complete response string (may contain a formatted error
- * message)
- * or NULL on fatal error*/
-
-extern edg_wll_ErrorCode edg_wll_Proto(
- edg_wll_Context, /* INOUT: context */
- char *, /* IN: HTTP request line */
- char **, /* IN: HTTP message headers */
- char *, /* IN: HTTP message body */
- char **, /* OUT: HTTP response line */
- char ***, /* OUT: HTTP response headers */
- char ** /* OUT: HTTP response body */
-);
-
-extern char *edg_wll_HTTPErrorMessage(int);
-
-#endif
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <ctype.h>
-#include <expat.h>
-
-#include "glite/wmsutils/jobid/cjobid.h"
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/escape.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-#include "glite/lb/xml_conversions.h"
-
-#include "glite/lb/purge.h"
-#include "glite/lb/dump.h"
-#include "glite/lb/load.h"
-
-#include "lb_xml_parse.h"
-
-#ifdef __GNUC__
-#define UNUSED_VAR __attribute__((unused))
-#else
-#define UNUSED_VAR
-#endif
-
-#define QUERY_EVENTS_BEGIN "<edg_wll_QueryEventsResult"
-#define QUERY_EVENTS_END "</edg_wll_QueryEventsResult>\r\n"
-#define QUERY_JOBS_BEGIN "<edg_wll_QueryJobsResult"
-#define QUERY_JOBS_END "</edg_wll_QueryJobsResult>\r\n"
-#define PURGE_RESULT_BEGIN "<edg_wll_PurgeResult"
-#define PURGE_RESULT_END "</edg_wll_PurgeResult>\r\n"
-#define DUMP_RESULT_BEGIN "<edg_wll_DumpResult"
-#define DUMP_RESULT_END "</edg_wll_DumpResult>\r\n"
-#define LOAD_RESULT_BEGIN "<edg_wll_LoadResult"
-#define LOAD_RESULT_END "</edg_wll_LoadResult>\r\n"
-#define INDEXED_ATTRS_BEGIN "<edg_wll_GetIndexedAttributesResult"
-#define INDEXED_ATTRS_END "</edg_wll_GetIndexedAttributesResult>\r\n"
-#define NOTIF_RESULT_BEGIN "<edg_wll_NotifResult"
-#define NOTIF_RESULT_END "</edg_wll_NotifResult>\r\n"
-#define QUERY_SEQUENCE_CODE_RESULT_BEGIN "<edg_wll_QuerySequenceCodeResult"
-#define QUERY_SEQUENCE_CODE_RESULT_END "</edg_wll_QuerySequenceCodeResult>\r\n"
-
-#define STATS_RESULT_BEGIN "<edg_wll_StatsResult"
-#define STATS_RESULT_END "</edg_wll_StatsResult>\r\n"
-
-
-// XXX will be redundant soon
-#define USERJOBS_BEGIN "<edg_wll_UserJobs"
-#define USERJOBS_END "</edg_wll_UserJobs>\r\n"
-
-
-static char *ops[] = { "equal","less","greater","within","unequal" },
- *attrs[] = { "jobid","owner","status","location","destination",
- "donecode","usertag","time","level","host","source",
- "instance","type","chkpt_tag", "resubmitted", "parent_job", "exitcode" };
-
-static const struct timeval null_timeval = {0,0};
-
-#define unexp() {\
- char *e;\
-\
- if (XMLCtx->errtxt) {\
- asprintf(&e,"%s\nunexpected <%s> at line %d",XMLCtx->errtxt,\
- el,XML_GetCurrentLineNumber(XMLCtx->p));\
- free(XMLCtx->errtxt);\
- } else asprintf(&e,"unexpected <%s> at line %d",\
- el,XML_GetCurrentLineNumber(XMLCtx->p));\
- XMLCtx->errtxt = e;\
-}
-
-
-
-static void startJobQueryRec(void *data, const char *el, const char **attr)
-{
- unsigned int i;
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"and")) unexp()
- break;
- case 1: if (strcasecmp(el,"orJobConditions")) unexp()
- else {
- XMLCtx->position = -1;
- XMLCtx->job_conditions = realloc(XMLCtx->job_conditions,
- (++XMLCtx->row+2)*sizeof(*XMLCtx->job_conditions));
- XMLCtx->job_conditions[XMLCtx->row] = NULL;
- XMLCtx->job_conditions[XMLCtx->row+1] = NULL;
- }
- break;
- case 2:
- for (i=0; i<sizeof(ops)/sizeof(ops[0]); i++)
- if (!strcasecmp(el,ops[i])) break;
- if (i == sizeof(ops)/sizeof(ops[0])) unexp()
- else {
- if (!XMLCtx->job_conditions) break;
-
- /* malloc also terminator and set it to 0 (= EDG_WLL_QUERY_ATTR_UNDEF) */
- XMLCtx->job_conditions[XMLCtx->row] = realloc(XMLCtx->job_conditions[XMLCtx->row],
- (++XMLCtx->position+2)*sizeof(**XMLCtx->job_conditions));
- memset(&XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position],0,2*sizeof(**XMLCtx->job_conditions));
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].op = i;
- XMLCtx->bound = 0;
- }
- break;
- case 3: for (i=0; i<sizeof(attrs)/sizeof(attrs[0]) &&
- strcasecmp(el,attrs[i]); i++);
- if (i == sizeof(attrs)/sizeof(attrs[0])) unexp()
- else {
- if (!XMLCtx->job_conditions) break;
- if (!XMLCtx->job_conditions[XMLCtx->row]) break;
-
- if ( (i+1) == EDG_WLL_QUERY_ATTR_USERTAG) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (strcmp(attr[0],"name")) { unexp() break;}
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = strdup(attr[1]);
- }
- else if ( (i+1) == EDG_WLL_QUERY_ATTR_TIME) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
- }
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr = i+1;
- }
- break;
- default: unexp(); break;
- }
- XMLCtx->level++;
-}
-
-
-
-static void startQueryJobsRequest(void *data, const char *el, const char **attr)
-{
- unsigned int i;
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_QueryJobsRequest")) { unexp() break; }
- for ( i = 0; attr[i] && attr[i+1]; i += 2 )
- {
- if ( !strcmp(attr[i],"softLimit") )
- XMLCtx->ctx->softLimit = atoi(attr[i+1]);
- else if ( !strcmp(attr[i],"queryRes") )
- XMLCtx->ctx->p_query_results = atoi(attr[i+1]);
- else { unexp() break; }
- }
- break;
- case 1: if (!strcasecmp(el,"and")) {
- XMLCtx->jobQueryRec_begin = XML_GetCurrentByteIndex(XMLCtx->p);
- break;
- }
- else if (!strcasecmp(el,"flags")) break;
- else unexp()
- break;
- case 2: /* fall through */
- case 3: /* do not check xml tags, processed in startJobQueryRec */
- case 4: break;
- default: unexp(); break;
- }
- XMLCtx->level++;
-}
-
-
-static void startQueryEventsRequest(void *data, const char *el, const char **attr UNUSED_VAR)
-{
- unsigned int i;
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_QueryEventsRequest")) { unexp() break; }
- for ( i = 0; attr[i] && attr[i+1]; i += 2 )
- {
- if ( !strcmp(attr[i],"softLimit") )
- XMLCtx->ctx->softLimit = atoi(attr[i+1]);
- else if ( !strcmp(attr[i],"queryRes") )
- XMLCtx->ctx->p_query_results = atoi(attr[i+1]);
- else { unexp() break; }
- }
- break;
- case 1: if (strcasecmp(el,"and")) unexp()
- break;
- case 2: if (!strcasecmp(el,"orJobConditions")) {
- XMLCtx->type = EDG_WLL_QUERY_TYPE_JOB_CONDITION;
- XMLCtx->position = -1;
- XMLCtx->job_conditions = realloc(XMLCtx->job_conditions,
- (++XMLCtx->row+2)*sizeof(*XMLCtx->job_conditions));
- XMLCtx->job_conditions[XMLCtx->row] = NULL;
- XMLCtx->job_conditions[XMLCtx->row+1] = NULL;
-
- }
- else if (!strcasecmp(el,"orEventConditions")) {
- XMLCtx->type = EDG_WLL_QUERY_TYPE_EVENT_CONDITION;
- XMLCtx->position2 = -1;
- XMLCtx->event_conditions = realloc(XMLCtx->event_conditions,
- (++XMLCtx->row2+2)*sizeof(*XMLCtx->event_conditions));
- XMLCtx->event_conditions[XMLCtx->row2] = NULL;
- XMLCtx->event_conditions[XMLCtx->row2+1] = NULL;
- }
- else unexp()
- break;
- case 3:
- for (i=0; i<sizeof(ops)/sizeof(ops[0]); i++)
- if (!strcasecmp(el,ops[i])) break;
- if (i == sizeof(ops)/sizeof(ops[0])) unexp()
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_JOB_CONDITION) {
- if (!XMLCtx->job_conditions) break;
-
- /* malloc also terminator and set it to 0 (= EDG_WLL_QUERY_ATTR_UNDEF) */
- XMLCtx->job_conditions[XMLCtx->row] = realloc(XMLCtx->job_conditions[XMLCtx->row],
- (++XMLCtx->position+2)*sizeof(**XMLCtx->job_conditions));
- memset(&XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position],0,2*sizeof(**XMLCtx->job_conditions));
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].op = i;
- XMLCtx->bound = 0;
- }
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_EVENT_CONDITION) {
- if (!XMLCtx->event_conditions) break;
- /* malloc also terminator and set it to 0 (= EDG_WLL_QUERY_ATTR_UNDEF) */
- XMLCtx->event_conditions[XMLCtx->row2] = realloc(XMLCtx->event_conditions[XMLCtx->row2],
- (++XMLCtx->position2+2)*sizeof(**XMLCtx->event_conditions));
- memset(&XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2],0,2*sizeof(**XMLCtx->event_conditions));
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].op = i;
- XMLCtx->bound = 0;
- }
-
- break;
- case 4: for (i=0; i<sizeof(attrs)/sizeof(attrs[0]) &&
- strcasecmp(el,attrs[i]); i++);
- if (i == sizeof(attrs)/sizeof(attrs[0])) unexp()
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_JOB_CONDITION) {
- if (!XMLCtx->job_conditions[XMLCtx->row]) break;
- if ( (i+1) == EDG_WLL_QUERY_ATTR_USERTAG) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"name")) { unexp() break;}
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = strdup(attr[1]);
- }
- else if ( (i+1) == EDG_WLL_QUERY_ATTR_TIME) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
- printf("\nchecking time attr\n%s = %s (%d)\n\n", attr[0], attr[1], edg_wll_StringToStat(attr[1]));
- }
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr = i+1;
- }
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_EVENT_CONDITION) {
- if (!XMLCtx->event_conditions[XMLCtx->row2]) break;
- if ( (i+1) == EDG_WLL_QUERY_ATTR_USERTAG) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"name")) { unexp() break;}
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position].attr_id.tag = strdup(attr[1]);
- }
- else if ( (i+1) == EDG_WLL_QUERY_ATTR_TIME) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
- }
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].attr = i+1;
- }
- break;
- default: unexp(); break;
- }
- XMLCtx->level++;
-}
-
-
-
-static void startPurgeRequest(void *data, const char *el, const char **attr)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_PurgeRequest")) unexp()
- break;
- case 1: if (strcasecmp(el,"jobs") && strcasecmp(el,"timeout")
- && strcasecmp(el,"flags")) unexp()
- else
- XMLCtx->position = 0;
- break;
- case 2: if (!strcasecmp(el,"jobId")) {
- XMLCtx->purgeRequestGlobal.jobs = realloc(XMLCtx->purgeRequestGlobal.jobs,
- (XMLCtx->position+2) * sizeof(XMLCtx->purgeRequestGlobal.jobs));
-
- if (!XMLCtx->purgeRequestGlobal.jobs) {
- edg_wll_SetError(XMLCtx->ctx, ENOMEM, NULL);
- unexp() return;
- }
- XMLCtx->purgeRequestGlobal.jobs[XMLCtx->position+1] = NULL;
- }
- else if (XMLCtx->tagToIndex(el) >= 0 ) {
- /* static array, no need to initialize & allocate anything */
- }
- else
- unexp()
- break;
- default: unexp()
- break;
- }
- XMLCtx->level++;
-}
-
-
-static void startDumpRequest(void *data, const char *el, const char **attr)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_DumpRequest")) unexp()
- break;
- case 1: if (strcasecmp(el,"from") && strcasecmp(el,"to")) unexp()
- break;
- default: unexp()
- break;
- }
- XMLCtx->level++;
-}
-
-
-
-static void startLoadRequest(void *data, const char *el, const char **attr)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_LoadRequest")) unexp()
- break;
- case 1: if (strcasecmp(el,"server_file")) unexp()
- break;
- default: unexp()
- break;
- }
- XMLCtx->level++;
-}
-
-
-
-static void startNotifRequest(void *data, const char *el, const char **attr)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (!strcasecmp(el,"edg_wll_NotifRequest") && attr[0] && attr[1]) {
- if (strcmp(attr[0],"function")) { unexp() break;}
- else XMLCtx->notifFunction = strdup(attr[1]);
- }
- else unexp()
- break;
- case 1: if (!strcasecmp(el,"and")) {
- XMLCtx->jobQueryRec_begin = XML_GetCurrentByteIndex(XMLCtx->p);
- }
- else if ( (strcasecmp(el,"notifId")) && (strcasecmp(el,"clientAddress")) &&
- (strcasecmp(el,"notifChangeOp")) ) unexp()
- break;
- case 2: /* fall through */
- case 3: /* do not check xml tags, processed in startJobQueryRec */
- case 4: break;
- default: unexp()
- break;
- }
- XMLCtx->level++;
-}
-
-
-
-static void startQuerySequenceCodeRequest(void *data, const char *el, const char **attr)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_QuerySequenceCodeRequest")) unexp()
- break;
- case 1: if ( (strcasecmp(el,"jobId")) && (strcasecmp(el,"source")) ) unexp()
- break;
- default: unexp()
- break;
- }
- XMLCtx->level++;
-}
-
-
-
-static void startStatsRequest(void *data, const char *el, const char **attr)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (!strcasecmp(el,"edg_wll_StatsRequest") && attr[0] && attr[1]) {
- if (strcmp(attr[0],"function")) { unexp() break;}
- else XMLCtx->statsFunction = strdup(attr[1]);
- }
- else unexp()
- break;
- case 1: if (!strcasecmp(el,"and")) {
- XMLCtx->jobQueryRec_begin = XML_GetCurrentByteIndex(XMLCtx->p);
- }
- else if ( (strcasecmp(el,"major")) && (strcasecmp(el,"minor")) &&
- (strcasecmp(el,"from")) && (strcasecmp(el,"to")) ) unexp()
- break;
- case 2: /* fall through */
- case 3: /* do not check xml tags, processed in startJobQueryRec */
- case 4: break;
- default: unexp()
- break;
- }
- XMLCtx->level++;
-}
-
-#undef unexp
-
-
-static void char_handler(void *data, const char *s, int len)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- int i, found = -1;
- char *temp_s;
-
-
- /* if date are only spaces, t\, \r, \n ... don't bother with them */
- for (i=0; i<len; i++)
- if (!isspace(s[i])) { found = i; break; }
- if (found == -1) return;
-
- temp_s = realloc(XMLCtx->char_buf, XMLCtx->char_buf_len + len + 1);
- if (temp_s == NULL) {
- /* XXX propagate ENOMEM somehow */
- return;
- }
- XMLCtx->char_buf = temp_s;
- memcpy(XMLCtx->char_buf + XMLCtx->char_buf_len, s, len);
- XMLCtx->char_buf[XMLCtx->char_buf_len + len] = '\0';
- XMLCtx->char_buf_len += len;
-}
-
-
-
-static void endJobQueryRec(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- char *e;
- char *s;
-
-
- if (XMLCtx->level == 4 &&
- XMLCtx->job_conditions != NULL &&
- XMLCtx->job_conditions[XMLCtx->row] != NULL) {
- switch (XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr) {
- case EDG_WLL_QUERY_ATTR_JOBID:
- case EDG_WLL_QUERY_ATTR_PARENT:
- if ( (XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.j =
- edg_wll_from_string_to_jobid(XMLCtx)) == NULL )
- {
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid JobId at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid JobId at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- }
- break;
- case EDG_WLL_QUERY_ATTR_OWNER:
- // XXX - this is way how to pass NULL, user will be extracted from ssl partner later
- /* XXX char_buf contains an escaped value, however there's nothing to escape in 'NULL' so we're fine */
- if (XMLCtx->char_buf != NULL && !strcmp(XMLCtx->char_buf,"NULL")) {
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.c = NULL;
- break;
- }
- else /* fall through */
- case EDG_WLL_QUERY_ATTR_LOCATION:
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- case EDG_WLL_QUERY_ATTR_USERTAG:
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.c =
- edg_wll_from_string_to_string(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_STATUS:
- if ( !XMLCtx->bound )
- {
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.i =
- edg_wll_from_string_to_edg_wll_JobStatCode(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value2.i =
- edg_wll_from_string_to_edg_wll_JobStatCode(XMLCtx);
-
- break;
- case EDG_WLL_QUERY_ATTR_DONECODE:
- case EDG_WLL_QUERY_ATTR_EXITCODE:
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- if ( !XMLCtx->bound )
- {
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.i =
- edg_wll_from_string_to_int(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value2.i =
- edg_wll_from_string_to_int(XMLCtx);
-
- break;
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( !XMLCtx->bound )
- {
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value2.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- break;
- default:
- edg_wll_freeBuf(XMLCtx);
- XMLCtx->level--;
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid attribute type at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid attribute type at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- break;
- }
- }
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-
-static void endQueryJobsRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- char *s;
-
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"flags") && XMLCtx->char_buf) {
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- // XXX: check if it works
- XMLCtx->flags = edg_wll_string_to_stat_flags(s);
- free(s);
- }
- else if (!strcmp(el,"and")) {
- long len = (XML_GetCurrentByteIndex(XMLCtx->p) + XML_GetCurrentByteCount(XMLCtx->p))
- - XMLCtx->jobQueryRec_begin;
-
- parseJobQueryRec(XMLCtx->ctx, XMLCtx->message_body + XMLCtx->jobQueryRec_begin, len,
- &XMLCtx->job_conditions);
- }
- }
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-static void endQueryEventsRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- char *e;
- char *s;
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"orJobConditions")) {
- /* make end-of-row */
- XMLCtx->job_conditions[XMLCtx->row] = realloc(XMLCtx->job_conditions[XMLCtx->row],
- (++XMLCtx->position+1)*sizeof(**XMLCtx->job_conditions));
- memset(&XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position],0,sizeof(**XMLCtx->job_conditions));
- }
- else if (!strcmp(XMLCtx->element,"orEventConditions")) {
- /* make end-of-row */
- XMLCtx->event_conditions[XMLCtx->row2] = realloc(XMLCtx->event_conditions[XMLCtx->row2],
- (++XMLCtx->position2+1)*sizeof(**XMLCtx->event_conditions));
- memset(&XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2],0,sizeof(**XMLCtx->event_conditions));
- }
- }
- else if (XMLCtx->level == 5) {
- if (XMLCtx->type == EDG_WLL_QUERY_TYPE_JOB_CONDITION &&
- XMLCtx->job_conditions != NULL &&
- XMLCtx->job_conditions[XMLCtx->row] !=NULL) {
- switch (XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr) {
- case EDG_WLL_QUERY_ATTR_JOBID:
- case EDG_WLL_QUERY_ATTR_PARENT:
- if ( (XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.j =
- edg_wll_from_string_to_jobid(XMLCtx)) == NULL )
- {
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid JobId at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid JobId at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- }
- break;
- case EDG_WLL_QUERY_ATTR_OWNER:
- case EDG_WLL_QUERY_ATTR_LOCATION:
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- case EDG_WLL_QUERY_ATTR_USERTAG:
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.c =
- edg_wll_from_string_to_string(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_STATUS:
- case EDG_WLL_QUERY_ATTR_DONECODE:
- case EDG_WLL_QUERY_ATTR_EXITCODE:
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- if ( !XMLCtx->bound )
- {
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.i =
- edg_wll_from_string_to_int(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value2.i =
- edg_wll_from_string_to_int(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( !XMLCtx->bound )
- {
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value2.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- break;
- default:
- edg_wll_freeBuf(XMLCtx);
- XMLCtx->level--;
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid attribute type at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid attribute type at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- break;
- }
- }
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_EVENT_CONDITION &&
- XMLCtx->event_conditions != NULL &&
- XMLCtx->event_conditions[XMLCtx->row2] != NULL) {
- switch (XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].attr) {
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( !XMLCtx->bound )
- {
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value2.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_LEVEL:
- case EDG_WLL_QUERY_ATTR_SOURCE:
- case EDG_WLL_QUERY_ATTR_EVENT_TYPE:
- if ( !XMLCtx->bound )
- {
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value.i =
- edg_wll_from_string_to_int(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value2.i =
- edg_wll_from_string_to_int(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_HOST:
- case EDG_WLL_QUERY_ATTR_INSTANCE:
- case EDG_WLL_QUERY_ATTR_USERTAG:
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value.c =
- edg_wll_from_string_to_string(XMLCtx);
- break;
- default:
- edg_wll_freeBuf(XMLCtx);
- XMLCtx->level--;
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid attribute type at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid attribute type at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- break;
- }
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- }
- XMLCtx->level--;
-}
-
-
-static void endPurgeRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- char *e, *s;
- int index;
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"flags")) {
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- XMLCtx->purgeRequestGlobal.flags = edg_wll_string_to_purge_flags(s);
- free(s);
- }
- }
- else if (XMLCtx->level == 3) {
- if (!strcmp(XMLCtx->element,"jobId") && XMLCtx->purgeRequestGlobal.jobs != NULL) {
- if ( (XMLCtx->purgeRequestGlobal.jobs[XMLCtx->position++] =
- edg_wll_from_string_to_string(XMLCtx)) == NULL )
- {
- /* XXX char_buf contains an escaped value, unescaping is done within edg_wll_from_string_to_string(), which failed */
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid JobId at line %d",
- XMLCtx->errtxt, XMLCtx->char_buf,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid JobId at line %d",
- XMLCtx->char_buf,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- }
- }
- else if ( ((index = XMLCtx->tagToIndex(XMLCtx->element)) >= 0 ) && XMLCtx->char_buf ) {
- XMLCtx->purgeRequestGlobal.timeout[index] =
- edg_wll_from_string_to_time_t(XMLCtx);
- }
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-static void endDumpRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- char *s;
-
- if (XMLCtx->level == 2) {
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (!strcmp(XMLCtx->element,"from")) {
- if (isdigit(s[0]))
- XMLCtx->dumpRequestGlobal.from = edg_wll_from_string_to_time_t(XMLCtx);
- else
- XMLCtx->dumpRequestGlobal.from = edg_wll_StringToDumpConst(s);
- }
- else if (!strcmp(XMLCtx->element,"to")) {
- if (isdigit(s))
- XMLCtx->dumpRequestGlobal.to = edg_wll_from_string_to_time_t(XMLCtx);
- else
- XMLCtx->dumpRequestGlobal.to = edg_wll_StringToDumpConst(s);
- }
- free(s);
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-
-static void endLoadRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"server_file"))
- XMLCtx->loadRequestGlobal.server_file = edg_wll_from_string_to_string(XMLCtx);
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-
-static void endNotifRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- char *pom;
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"notifId")) {
- pom = edg_wll_from_string_to_string(XMLCtx);
- edg_wll_NotifIdParse(pom, &XMLCtx->notifId);
- free(pom);
- }
- else if (!strcmp(XMLCtx->element,"clientAddress")) {
- XMLCtx->notifClientAddress = edg_wll_from_string_to_string(XMLCtx);
- }
- else if (!strcmp(XMLCtx->element,"notifChangeOp")) {
- pom = edg_wll_from_string_to_string(XMLCtx);
- XMLCtx->notifChangeOp = edg_wll_StringToNotifChangeOp(pom);
- free(pom);
- }
- else if (!strcmp(el,"and")) {
- long len = (XML_GetCurrentByteIndex(XMLCtx->p) + XML_GetCurrentByteCount(XMLCtx->p))
- - XMLCtx->jobQueryRec_begin;
-
- parseJobQueryRec(XMLCtx->ctx, XMLCtx->message_body + XMLCtx->jobQueryRec_begin, len,
- &XMLCtx->job_conditions);
- }
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-
-static void endQuerySequenceCodeRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"jobId")) {
- XMLCtx->jobId = edg_wll_from_string_to_jobid(XMLCtx);
- }
- else if (!strcmp(XMLCtx->element,"source")) {
- XMLCtx->source = edg_wll_from_string_to_string(XMLCtx);
- }
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-
-
-static void endStatsRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"major")) {
- XMLCtx->statsMajor =
- edg_wll_from_string_to_edg_wll_JobStatCode(XMLCtx);
- }
- else if (!strcmp(XMLCtx->element,"minor")) {
- XMLCtx->statsMinor = edg_wll_from_string_to_int(XMLCtx);
- }
- else if (!strcmp(XMLCtx->element,"from")) {
- XMLCtx->statsFrom = edg_wll_from_string_to_time_t(XMLCtx);;
- }
- else if (!strcmp(XMLCtx->element,"to")) {
- XMLCtx->statsTo = edg_wll_from_string_to_time_t(XMLCtx);;
- }
- else if (!strcmp(el,"and")) {
- long len = (XML_GetCurrentByteIndex(XMLCtx->p) + XML_GetCurrentByteCount(XMLCtx->p))
- - XMLCtx->jobQueryRec_begin;
-
- parseJobQueryRec(XMLCtx->ctx, XMLCtx->message_body + XMLCtx->jobQueryRec_begin, len,
- &XMLCtx->statsConditions);
- }
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-
-int parseJobQueryRec(edg_wll_Context ctx, const char *messageBody, long len, edg_wll_QueryRec ***conditions)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.row = -1;
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startJobQueryRec, endJobQueryRec);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, len, 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- int i,j;
-
- if (XMLCtx.job_conditions) {
- for (j = 0; XMLCtx.job_conditions[j]; j++) {
- for (i = 0; (XMLCtx.job_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&XMLCtx.job_conditions[j][i]);
- free(XMLCtx.job_conditions[j]);
- }
- free(XMLCtx.job_conditions);
- }
-
- /* empty list terminators */
- conditions[0] = NULL;
- } else {
- *conditions = XMLCtx.job_conditions;
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-/* parse queryJobs request from client */
-int parseQueryJobsRequest(edg_wll_Context ctx, char *messageBody, edg_wll_QueryRec ***conditions, int *flags)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.ctx = ctx;
- XMLCtx.message_body = messageBody;
- XMLCtx.position = 0;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startQueryJobsRequest, endQueryJobsRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- int i,j;
-
- if (XMLCtx.job_conditions) {
- for (j = 0; XMLCtx.job_conditions[j]; j++) {
- for (i = 0; (XMLCtx.job_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&XMLCtx.job_conditions[j][i]);
- free(XMLCtx.job_conditions[j]);
- }
- free(XMLCtx.job_conditions);
- }
-
- /* empty list terminators */
- conditions[0] = NULL;
- *flags = 0;
- } else {
- *conditions = XMLCtx.job_conditions;
- *flags = XMLCtx.flags;
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-/* parse queryEvents request from client */
-int parseQueryEventsRequest(edg_wll_Context ctx, char *messageBody, edg_wll_QueryRec ***job_conditions, edg_wll_QueryRec ***event_conditions)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.row = -1;
- XMLCtx.row2 = -1;
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startQueryEventsRequest, endQueryEventsRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- int i,j;
-
- if (XMLCtx.job_conditions) {
- for (j = 0; XMLCtx.job_conditions[j]; j++) {
- for (i = 0 ; (XMLCtx.job_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&XMLCtx.job_conditions[j][i]);
- free(XMLCtx.job_conditions[j]);
- }
- free(XMLCtx.job_conditions);
- }
- if (XMLCtx.event_conditions) {
- for (j = 0; XMLCtx.event_conditions[j]; j++) {
- for (i = 0 ; (XMLCtx.event_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&XMLCtx.event_conditions[j][i]);
- free(XMLCtx.event_conditions[j]);
- }
- free(XMLCtx.event_conditions);
- }
-
- /* empty list terminators */
- job_conditions[0] = NULL;
- event_conditions[0] = NULL;
- } else {
- *job_conditions = XMLCtx.job_conditions;
- *event_conditions = XMLCtx.event_conditions;
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-
-/* parse purge request from client */
-int parsePurgeRequest(edg_wll_Context ctx, char *messageBody, int (*tagToIndex)(), edg_wll_PurgeRequest *request)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
- XMLCtx.tagToIndex = tagToIndex;
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startPurgeRequest, endPurgeRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- int i;
-
- if (XMLCtx.purgeRequestGlobal.jobs) {
- for (i=0; XMLCtx.purgeRequestGlobal.jobs[i]; i++)
- free(XMLCtx.purgeRequestGlobal.jobs[i]);
- free(XMLCtx.purgeRequestGlobal.jobs);
- }
- memset(request,0,sizeof(*request));
-
- } else {
- memcpy(request, &XMLCtx.purgeRequestGlobal, sizeof(XMLCtx.purgeRequestGlobal));
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-
-/* parse dump request from client */
-int parseDumpRequest(edg_wll_Context ctx, char *messageBody, edg_wll_DumpRequest *request)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startDumpRequest, endDumpRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL)))
- memset(request,0,sizeof(*request));
-
- else {
- memcpy(request, &XMLCtx.dumpRequestGlobal, sizeof(XMLCtx.dumpRequestGlobal));
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-/* parse load request from client */
-int parseLoadRequest(edg_wll_Context ctx, char *messageBody, edg_wll_LoadRequest *request)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startLoadRequest, endLoadRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL)))
- memset(request,0,sizeof(*request));
-
- else {
- memcpy(request, &XMLCtx.loadRequestGlobal, sizeof(XMLCtx.loadRequestGlobal));
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-
-
-/* parse Stats request from client */
-int parseStatsRequest(edg_wll_Context ctx, char *messageBody, char **function, edg_wll_QueryRec ***conditions, edg_wll_JobStatCode *major, int *minor, time_t *from, time_t *to)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
-
- /* returns emty variables as default; only some variables will be filled in */
- /* depending on vaule of XMLCtx.notifFunction */
- *function = NULL;
- *major = EDG_WLL_JOB_UNDEF;
- *minor = 0;
- *from = 0;
- *to = 0;
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.ctx = ctx;
- XMLCtx.message_body = messageBody;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startStatsRequest, endStatsRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- int i,j;
-
- if (XMLCtx.statsConditions) {
- for (j = 0; XMLCtx.statsConditions[j]; j++) {
- for (i = 0; (XMLCtx.statsConditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&XMLCtx.statsConditions[j][i]);
- free(XMLCtx.statsConditions[j]);
- }
- free(XMLCtx.statsConditions);
- }
- free(XMLCtx.notifFunction);
-
- *function = NULL;
- *conditions = NULL;
- *major = EDG_WLL_JOB_UNDEF;
- *minor = 0;
- *from = 0;
- *to = 0;
- }
- else {
- *function = XMLCtx.statsFunction;
- *conditions = XMLCtx.statsConditions;
- *major = XMLCtx.statsMajor;
- *minor = XMLCtx.statsMinor;
- *from = XMLCtx.statsFrom;
- *to = XMLCtx.statsTo;
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-/* parse Notif request from client */
-int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, edg_wll_NotifId *notifId, char **address, edg_wll_NotifChangeOp *op, edg_wll_QueryRec ***conditions)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
-
- /* returns emty variables as default; only some variables will be filled in */
- /* depending on vaule of XMLCtx.notifFunction */
- *function = NULL;
- *notifId = NULL;
- *address = NULL;
- *op = EDG_WLL_NOTIF_NOOP;
- *conditions = NULL;
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.ctx = ctx;
- XMLCtx.message_body = messageBody;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startNotifRequest, endNotifRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- int i,j;
-
- if (XMLCtx.job_conditions) {
- for (j = 0; XMLCtx.job_conditions[j]; j++) {
- for (i = 0; (XMLCtx.job_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&XMLCtx.job_conditions[j][i]);
- free(XMLCtx.job_conditions[j]);
- }
- free(XMLCtx.job_conditions);
- }
- free(XMLCtx.notifFunction);
- edg_wll_NotifIdFree(&XMLCtx.notifId);
- free(XMLCtx.notifClientAddress);
-
- *function = NULL;
- *notifId = NULL;
- *address = NULL;
- *op = EDG_WLL_NOTIF_NOOP;
- *conditions = NULL;
- } else {
- *function = XMLCtx.notifFunction;
- *notifId = XMLCtx.notifId;
- *address = XMLCtx.notifClientAddress;
- *op = XMLCtx.notifChangeOp;
- *conditions = XMLCtx.job_conditions;
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-
-/* parse Sequence Code request from client */
-int parseQuerySequenceCodeRequest(edg_wll_Context ctx, char *messageBody, edg_wlc_JobId *jobId, char **source)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startQuerySequenceCodeRequest, endQuerySequenceCodeRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- if (XMLCtx.jobId)
- edg_wlc_JobIdFree(XMLCtx.jobId);
-
- *jobId = NULL;
- *source = NULL;
- }
- else {
- *jobId = XMLCtx.jobId;
- *source = XMLCtx.source;
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-
-
-int edg_wll_QueryEventsToXML(edg_wll_Context ctx, edg_wll_Event *eventsOut, char **message)
-{
- char *pomA, *pomB;
- char **list = NULL;
- int i = 0, len, tot_len = 0;
- int *len_list = NULL;
-
-
- while (eventsOut && eventsOut[i].any.type != EDG_WLL_EVENT_UNDEF) {
- pomB = edg_wll_EventToString(eventsOut[i].any.type);
- trio_asprintf(&pomA," <edg_wll_Event name=\"%|Xs\">\r\n", pomB);
- free(pomB);
- pomB = pomA;
-
-
-@@@{
- selectType $event '_common_';
- for (getFieldsOrdered $event) {
- my $f = selectField $event $_;
- my $ft = $f->{type};
- my $n = $f->{null};
- gen "\tedg_wll_add_$ft\_to_XMLBody(&pomB, eventsOut[i].any.$_, \"$_\", $n);\n";
- }
-
- gen "\tswitch (eventsOut[i].any.type) {\n";
- for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } getTypes $event) {
- if ($t ne 'any') {
- selectType $event $t;
- my $u = uc $t;
- gen "\t case EDG_WLL_EVENT_$u :\n";
- for (getFieldsOrdered $event) {
- my $f = selectField $event $_;
- my $ft = $f->{type};
- my $n = $f->{null};
- $t = lcfirst $t;
- if ($t =~ m/^pBS/) { $t = ucfirst $t; }
- if ($t =~ m/^condor/) { $t = ucfirst $t; }
- gen "\t\tedg_wll_add_$ft\_to_XMLBody(&pomB, eventsOut[i].$t.$_, \"$_\", $n);\n";
- }
- gen "\t\tbreak;\n";
- }
- }
- gen "\t default : break;\n";
- gen "\t}\n";
-@@@}
-
-
-
- len = asprintf(&pomA,"%s </edg_wll_Event>\r\n", pomB);
- free(pomB);
- i++;
- tot_len += len;
-
- list = (char **) realloc(list, i * sizeof(*list));
- list[i-1] = pomA;
- len_list = (int *) realloc(len_list, i * sizeof(*len_list));
- len_list[i-1] = len;
-
- }
-
- /* list termination */
- list = (char **) realloc(list, (i+1) * sizeof(*list));
- list[i] = NULL;
-
- /* test errors */
- if (ctx->errDesc || ctx->errCode)
- len = trio_asprintf(&pomB," code=\"%d\" desc=\"%|Xs\">\r\n",ctx->errCode,ctx->errDesc);
- else
- len = asprintf(&pomB,">\r\n");
-
- /* glueing all list fields together & freeing the list */
- pomA = (char *) malloc(tot_len * sizeof(char) +
- sizeof(QUERY_EVENTS_BEGIN) + len + sizeof(QUERY_EVENTS_END) - 1);
-
- memcpy(pomA, QUERY_EVENTS_BEGIN, sizeof(QUERY_EVENTS_BEGIN));
- memcpy(pomA + sizeof(QUERY_EVENTS_BEGIN) - 1, pomB, len);
- free(pomB);
- pomB = pomA + sizeof(QUERY_EVENTS_BEGIN) + len - 1;
-
- i = 0;
- while (list[i]) {
- memcpy(pomB, list[i], len_list[i] );
- pomB += len_list[i];
-
- /* freeing the list */
- free(list[i]);
-
- i++;
- }
-
- strcpy(pomB, QUERY_EVENTS_END);
-
-
- free(list);
- free(len_list);
-
-
- *message = pomA;
-
- return 0;
-}
-
-int edg_wll_QueryJobsToXML(edg_wll_Context ctx, edg_wlc_JobId *jobsIn, edg_wll_JobStat *statesIn, char **message)
-{
- char *pomA, *pomB, *pomC;
- char **list = NULL;
- int i = 0, len, tot_len = 0, nres = 0;
- int *len_list = NULL;
-
-
- if (jobsIn) for (nres = 0; jobsIn[nres]; nres++);
- else if (statesIn) for (nres = 0; statesIn[nres].state; nres++);
-
- while (i < nres) {
- trio_asprintf(&pomA,"\t<edg_wll_Job>\r\n");
- pomB = pomA;
-
- if (jobsIn) {
- trio_asprintf(&pomA,"%s\t\t<jobId>%|Xs</jobId>\r\n",
- pomB, pomC=edg_wlc_JobIdUnparse(jobsIn[i]));
- free(pomC);
- free(pomB);
- pomB = pomA;
- }
-
- if (statesIn) {
- edg_wll_JobStatusToXML(ctx, statesIn[i], &pomC);
- trio_asprintf(&pomA,"%s\t\t%s",pomB,pomC);
- }
- else {
- pomC = edg_wll_StatToString(EDG_WLL_JOB_UNKNOWN);
- trio_asprintf(&pomA,"%s\t\t<jobStat name=\"%|Xs\">\r\n\r\n\t\t</jobStat>\r\n",
- pomB, pomC);
- }
-
- free(pomB);
- free(pomC);
- pomB = pomA;
-
-
- len = asprintf(&pomA,"%s\t</edg_wll_Job>\r\n", pomB);
- free(pomB);
- i++;
- tot_len += len;
-
- list = (char **) realloc(list, i * sizeof(*list));
- list[i-1] = pomA;
- len_list = (int *) realloc(len_list, i * sizeof(*len_list));
- len_list[i-1] = len;
- }
-
- /* list termination */
- list = (char **) realloc(list, (i+1) * sizeof(*list));
- list[i] = NULL;
-
- /* test errors */
- if (ctx->errDesc || ctx->errCode)
- len = trio_asprintf(&pomB," code=\"%d\" desc=\"%|Xs\">\r\n",ctx->errCode,ctx->errDesc);
- else
- len = asprintf(&pomB,">\r\n");
-
- /* glueing all list fields together & freeing the list */
- pomA = (char *) malloc(tot_len * sizeof(char) +
- sizeof(QUERY_JOBS_BEGIN) + len + sizeof(QUERY_JOBS_END) - 1);
-
- memcpy(pomA, QUERY_JOBS_BEGIN, sizeof(QUERY_JOBS_BEGIN));
- memcpy((pomA + sizeof(QUERY_JOBS_BEGIN) - 1), pomB, len);
- free(pomB);
- pomB = pomA + sizeof(QUERY_JOBS_BEGIN) + len - 1;
-
- i = 0;
- while (list[i]) {
- memcpy(pomB, list[i], len_list[i] );
- pomB += len_list[i];
-
- /* freeing the list */
- free(list[i]);
-
- i++;
- }
-
- strcpy(pomB, QUERY_JOBS_END);
-
-
- free(list);
- free(len_list);
-
-
- *message = pomA;
-
- return 0;
-}
-
-/* construct Message-Body of Response-Line for edg_wll_UserJobs */
-int edg_wll_UserJobsToXML(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message)
-{
- char *pomA, *pomB;
- char **list = NULL;
- int i = 0, len, tot_len = 0;
- int *len_list = NULL;
-
-
- while (jobsOut[i]) {
- len = trio_asprintf(&pomA," <jobId>%|Xs</jobId>\r\n",
- pomB=edg_wlc_JobIdUnparse(jobsOut[i]));
-
- free(pomB);
-
- i++;
- tot_len += len;
-
- list = (char **) realloc(list, i * sizeof(*list));
- list[i-1] = pomA;
- pomA = NULL;
- len_list = (int *) realloc(len_list, i * sizeof(*len_list));
- len_list[i-1] = len;
-
- }
-
- /* list termination */
- list = (char **) realloc(list, (i+1) * sizeof(*list));
- list[i] = NULL;
-
- /* test errors */
- if (ctx->errDesc || ctx->errCode)
- len = trio_asprintf(&pomB," code=\"%d\" desc=\"%|Xs\">\r\n",ctx->errCode,ctx->errDesc);
- else
- len = asprintf(&pomB,">\r\n");
-
- /* glueing all list fields together & freeing the list */
- pomA = (char *) malloc(tot_len * sizeof(char) +
- sizeof(USERJOBS_BEGIN) + len + sizeof(USERJOBS_END) - 1);
-
- memcpy(pomA, USERJOBS_BEGIN, sizeof(USERJOBS_BEGIN));
- memcpy((pomA + sizeof(USERJOBS_BEGIN) - 1), pomB, len);
- free(pomB);
- pomB = pomA + sizeof(USERJOBS_BEGIN) + len - 1;
-
- i = 0;
- while (list[i]) {
- memcpy(pomB, list[i], len_list[i] );
- pomB += len_list[i];
-
- /* freeing the list */
- free(list[i]);
-
- i++;
- }
-
- strcpy(pomB, USERJOBS_END);
-
-
- free(list);
- free(len_list);
-
-
- *message = pomA;
-
- return 0;
-}
-
-static void edg_wll_add_stslist_to_XMLBody(edg_wll_Context ctx, char **body, const edg_wll_JobStat *toAdd, const char *tag, const char *UNUSED_subTag, const int null)
-{
- char *pomA, *pomB, *newBody;
- char **list = NULL;
- int i = 0, len, tot_len = 0;
- int *len_list = NULL;
-
-
- while (toAdd[i].state != null) {
- edg_wll_JobStatusToXML(ctx, toAdd[i], &pomA);
- len = strlen(pomA);
-
- i++;
- tot_len += len;
-
- list = (char **) realloc(list, i * sizeof(*list));
- list[i-1] = pomA;
- pomA = NULL;
- len_list = (int *) realloc(len_list, i * sizeof(*len_list));
- len_list[i-1] = len;
- }
-
- /* list termination */
- list = (char **) realloc(list, (i+1) * sizeof(*list));
- list[i] = NULL;
-
- /* glueing all list fields together & freeing the list */
- pomA = (char *) malloc(tot_len * sizeof(char) + 1);
- pomB = pomA;
-
- i = 0;
- while (list[i]) {
- memcpy(pomB, list[i], len_list[i] );
- pomB += len_list[i];
-
- /* freeing the list */
- free(list[i]);
-
- i++;
- }
- *pomB = '\0';
- free(list);
- free(len_list);
-
- asprintf(&newBody,"%s\t\t\t<%s>\r\n%s\t\t\t</%s>\r\n", *body, tag, pomA, tag);
- free(*body);
- free(pomA);
- *body = newBody;
-}
-
-
-
-/* construct Message-Body of Response-Line for edg_wll_JobStatus */
-int edg_wll_JobStatusToXML(edg_wll_Context ctx, edg_wll_JobStat stat, char **message)
-{
- char *pomA, *pomB, *pomC;
-
-
- pomB = strdup("");
-
-@@@{
- selectType $status '_common_';
- for (getFieldsOrdered $status) {
- my $f = selectField $status $_;
- next if defined($f->{special}) && $f->{special} eq 'XMLstructured';
- my $ft = $f->{type};
- my $n = $f->{null};
- gen "edg_wll_add_$ft\_to_XMLBody(&pomB, stat.$_, \"$_\", $n);\n";
- }
-@@@}
- if (stat.possible_destinations) edg_wll_add_strlist_to_XMLBody(&pomB, stat.possible_destinations, "possible_destinations", "name", "\t\t\t", NULL);
- if (stat.possible_ce_nodes) edg_wll_add_strlist_to_XMLBody(&pomB, stat.possible_ce_nodes, "possible_ce_nodes", "name", "\t\t\t", NULL);
- if (stat.children) edg_wll_add_strlist_to_XMLBody(&pomB, stat.children, "children", "jobId", "\t\t\t", NULL);
- if (stat.children_hist) edg_wll_add_intlist_to_XMLBody(&pomB, stat.children_hist, "children_hist", edg_wll_StatToString, "\t\t\t", 1, stat.children_hist[0]);
- if (stat.children_states) edg_wll_add_stslist_to_XMLBody(ctx, &pomB, stat.children_states, "children_states", "", EDG_WLL_JOB_UNDEF);
- if (stat.user_tags) edg_wll_add_taglist_to_XMLBody(&pomB, stat.user_tags, "user_tags", "tag", "name", "\t\t\t", NULL);
- if (stat.stateEnterTimes) edg_wll_add_intlist_to_XMLBody(&pomB, stat.stateEnterTimes, "stateEnterTimes", edg_wll_StatToString, "\t\t\t",1, stat.stateEnterTimes[0]);
-
- pomC = edg_wll_StatToString(stat.state);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomA,"<jobStat name=\"%|Xs\" code=\"%d\" desc=\"%|Xs\">\r\n%s</jobStat>",
- pomC, ctx->errCode,ctx->errDesc, pomB);
- else
- trio_asprintf(&pomA,"<jobStat name=\"%|Xs\">\r\n%s</jobStat>",
- pomC, pomB);
-
- free(pomB);
- free(pomC);
-
- *message = pomA;
-
- return 0;
-}
-
-
-
-/* construct Message-Body of Request-Line for edg_wll_Purge */
-int edg_wll_PurgeResultToXML(
- edg_wll_Context ctx,
- edg_wll_PurgeResult *result,
- char **message)
-{
- char *pomA, *pomB;
-
-
- if (!result) { *message = NULL; return(-1); }
-
- pomA = strdup("");
- edg_wll_add_strlist_to_XMLBody(&pomA, result->jobs, "jobs", "jobId", "\t", NULL);
- edg_wll_add_string_to_XMLBody(&pomA, result->server_file, "server_file", NULL);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomB,"%s code=\"%d\" desc=\"%|Xs\">\r\n%s%s",
- PURGE_RESULT_BEGIN, ctx->errCode, ctx->errDesc, pomA, PURGE_RESULT_END);
- else
- trio_asprintf(&pomB,"%s>\r\n%s%s", PURGE_RESULT_BEGIN, pomA, PURGE_RESULT_END);
- free(pomA);
-
- *message = pomB;
- return 0;
-}
-
-
-
-/* construct Message-Body of Request-Line for edg_wll_Dump */
-int edg_wll_DumpResultToXML(
- edg_wll_Context ctx,
- edg_wll_DumpResult *result,
- char **message)
-{
- char *pomA, *pomB;
-
-
- if (!result) { *message = NULL; return(-1); }
-
- pomA = strdup("");
- edg_wll_add_string_to_XMLBody(&pomA, result->server_file, "server_file", NULL);
- if (result->from < 0)
- edg_wll_add_string_to_XMLBody(&pomA,
- edg_wll_DumpConstToString(result->from), "from", NULL);
- else
- edg_wll_add_time_t_to_XMLBody(&pomA, result->from, "from", 0);
- if (result->to < 0)
- edg_wll_add_string_to_XMLBody(&pomA,
- edg_wll_DumpConstToString(result->to), "to", NULL);
- else
- edg_wll_add_time_t_to_XMLBody(&pomA, result->to, "to", 0);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomB,"%s code=\"%d\" desc=\"%|Xs\">\r\n%s%s",
- DUMP_RESULT_BEGIN, ctx->errCode, ctx->errDesc, pomA, DUMP_RESULT_END);
- else
- trio_asprintf(&pomB,"%s>\r\n%s%s", DUMP_RESULT_BEGIN, pomA, DUMP_RESULT_END);
- free(pomA);
-
- *message = pomB;
- return 0;
-}
-
-
-/* construct Message-Body of Request-Line for edg_wll_Load */
-int edg_wll_LoadResultToXML(
- edg_wll_Context ctx,
- edg_wll_LoadResult *result,
- char **message)
-{
- char *pomA, *pomB;
-
-
- if (!result) { *message = NULL; return(-1); }
-
- pomA = strdup("");
- edg_wll_add_string_to_XMLBody(&pomA, result->server_file, "server_file", NULL);
- edg_wll_add_time_t_to_XMLBody(&pomA, result->from, "from", 0);
- edg_wll_add_time_t_to_XMLBody(&pomA, result->to, "to", 0);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomB,"%s code=\"%d\" desc=\"%|Xs\">\r\n%s%s",
- LOAD_RESULT_BEGIN, ctx->errCode, ctx->errDesc, pomA, LOAD_RESULT_END);
- else
- trio_asprintf(&pomB,"%s>\r\n%s%s", LOAD_RESULT_BEGIN, pomA, LOAD_RESULT_END);
- free(pomA);
-
- *message = pomB;
- return 0;
-}
-
-
-/* construct Message-Body of Request-Line for edg_wll_GetIndexedAttrs */
-int edg_wll_IndexedAttrsToXML(
- edg_wll_Context ctx,
- char **message)
-{
- int i,j;
- char *pomA, *pomB;
-
- pomA = strdup("");
- if (ctx->job_index) {
- for (i=0; ctx->job_index[i]; i++) {
- asprintf(&pomB, "%s\t%s\r\n",pomA,"<index>");
- free(pomA);
- pomA = pomB;
-
- for (j=0; ctx->job_index[i][j].attr != EDG_WLL_QUERY_ATTR_UNDEF; j++) {
- asprintf(&pomB, "%s\t\t%s\r\n",pomA,"<QueryRec>");
- free(pomA);
- pomA = pomB;
-
- edg_wll_add_string_to_XMLBody(&pomA,
- edg_wll_query_attrToString(ctx->job_index[i][j].attr),
- "attribute", NULL);
-
- if (ctx->job_index[i][j].attr == EDG_WLL_QUERY_ATTR_TIME)
- edg_wll_add_string_to_XMLBody(&pomA,
- edg_wll_StatToString(ctx->job_index[i][j].attr_id.state),
- "state", NULL);
-
- if (ctx->job_index[i][j].attr == EDG_WLL_QUERY_ATTR_USERTAG)
- edg_wll_add_string_to_XMLBody(&pomA,
- ctx->job_index[i][j].attr_id.tag,
- "name", NULL);
-
- asprintf(&pomB, "%s\t\t%s\r\n",pomA,"</QueryRec>");
- free(pomA);
- pomA = pomB;
- }
-
- asprintf(&pomB, "%s\t%s\r\n",pomA,"</index>");
- free(pomA);
- pomA = pomB;
- }
- }
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomB,"%s code=\"%d\" desc=\"%|Xs\">\r\n%s%s",
- INDEXED_ATTRS_BEGIN, ctx->errCode, ctx->errDesc, pomA, INDEXED_ATTRS_END);
- else
- trio_asprintf(&pomB,"%s>\r\n%s%s", INDEXED_ATTRS_BEGIN, pomA, INDEXED_ATTRS_END);
- free(pomA);
-
-
- *message = pomB;
- return 0;
-}
-
-
-
-/* construct Message-Body of Request-Line for edg_wll_Notif */
-int edg_wll_NotifResultToXML(
- edg_wll_Context ctx,
- time_t validity,
- char **message)
-{
- char *pomA, *pomB;
-
-
- pomA = strdup("");
- edg_wll_add_time_t_to_XMLBody(&pomA, validity, "validity", -1);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomB,"%s code=\"%d\" desc=\"%|Xs\">\r\n%s%s",
- NOTIF_RESULT_BEGIN, ctx->errCode, ctx->errDesc, pomA, NOTIF_RESULT_END);
- else
- trio_asprintf(&pomB,"%s>\r\n%s%s", NOTIF_RESULT_BEGIN, pomA, NOTIF_RESULT_END);
- free(pomA);
-
- *message = pomB;
- return 0;
-}
-
-
-
-/* construct Message-Body of Request-Line for edg_wll_Notif */
-int edg_wll_QuerySequenceCodeResultToXML(
- edg_wll_Context ctx,
- char *seqCode,
- char **message)
-{
- char *pomA, *pomB;
-
-
- pomA = strdup("");
- edg_wll_add_string_to_XMLBody(&pomA, seqCode, "sequence_code", NULL);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomB,"%s code=\"%d\" desc=\"%|Xs\">\r\n%s%s",
- QUERY_SEQUENCE_CODE_RESULT_BEGIN, ctx->errCode,
- ctx->errDesc, pomA, QUERY_SEQUENCE_CODE_RESULT_END);
- else
- trio_asprintf(&pomB,"%s>\r\n%s%s", QUERY_SEQUENCE_CODE_RESULT_BEGIN,
- pomA, QUERY_SEQUENCE_CODE_RESULT_END);
- free(pomA);
-
- *message = pomB;
- return 0;
-}
-
-
-
-/* construct Message-Body of Request-Line for edg_wll_Stats* */
-int edg_wll_StatsResultToXML(
- edg_wll_Context ctx,
- time_t from,
- time_t to,
- float rate,
- float duration,
- int res_from,
- int res_to,
- char **message)
-{
- char *pomA, *pomB;
-
-
- pomA = strdup("");
- edg_wll_add_time_t_to_XMLBody(&pomA, from, "from", -1);
- edg_wll_add_time_t_to_XMLBody(&pomA, to, "to", -1);
- edg_wll_add_float_to_XMLBody(&pomA, rate, "rate", 0);
- edg_wll_add_float_to_XMLBody(&pomA, duration, "duration", 0);
- edg_wll_add_int_to_XMLBody(&pomA, res_from, "res_from", -1);
- edg_wll_add_int_to_XMLBody(&pomA, res_to, "res_to", -1);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomB,"%s code=\"%d\" desc=\"%|Xs\">\r\n%s%s",
- STATS_RESULT_BEGIN, ctx->errCode, ctx->errDesc, pomA, STATS_RESULT_END);
- else
- trio_asprintf(&pomB,"%s>\r\n%s%s", STATS_RESULT_BEGIN, pomA, STATS_RESULT_END);
- free(pomA);
-
- *message = pomB;
- return 0;
-}
-
-
+++ /dev/null
-#ifndef _LB_XML_PARSE_H
-#define _LB_XML_PARSE_H
-
-#ident "$Header$"
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/notification.h"
-#include "glite/lb/purge.h"
-#include "glite/lb/dump.h"
-#include "glite/lb/load.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* function for parsing/unparsing XML requests from client */
-
-int parseJobQueryRec(edg_wll_Context ctx, const char *messageBody, long len, edg_wll_QueryRec ***conditions);
-int parseQueryJobsRequest(edg_wll_Context ctx, char *messageBody, edg_wll_QueryRec ***conditions, int *flags);
-int parseQueryEventsRequest(edg_wll_Context ctx, char *messageBody, edg_wll_QueryRec ***job_conditions, edg_wll_QueryRec ***event_conditions);
-int parsePurgeRequest(edg_wll_Context ctx, char *messageBody, int (*tagToIndex)(), edg_wll_PurgeRequest *request);
-int parseDumpRequest(edg_wll_Context ctx, char *messageBody, edg_wll_DumpRequest *request);
-int parseLoadRequest(edg_wll_Context ctx, char *messageBody, edg_wll_LoadRequest *request);
-int parseNotifRequest(edg_wll_Context ctx, char *messageBody, char **function, edg_wll_NotifId *notifId, char **address, edg_wll_NotifChangeOp *op, edg_wll_QueryRec ***conditions);
-int parseQuerySequenceCodeRequest(edg_wll_Context ctx, char *messageBody, edg_wlc_JobId *jobId, char **source);
-int edg_wll_QueryEventsToXML(edg_wll_Context, edg_wll_Event *, char **);
-int edg_wll_QueryJobsToXML(edg_wll_Context, edg_wlc_JobId *, edg_wll_JobStat *, char **);
-int edg_wll_JobStatusToXML(edg_wll_Context, edg_wll_JobStat, char **);
-int edg_wll_UserJobsToXML(edg_wll_Context, edg_wlc_JobId *, char **);
-int edg_wll_PurgeResultToXML(edg_wll_Context ctx, edg_wll_PurgeResult *result, char **message);
-int edg_wll_DumpResultToXML(edg_wll_Context ctx, edg_wll_DumpResult *result, char **message);
-int edg_wll_LoadResultToXML(edg_wll_Context ctx, edg_wll_LoadResult *result, char **message);
-int edg_wll_IndexedAttrsToXML(edg_wll_Context ctx, char **message);
-int edg_wll_NotifResultToXML(edg_wll_Context ctx, time_t validity, char **message);
-int edg_wll_QuerySequenceCodeResultToXML(edg_wll_Context ctx, char *source, char **message);
-
-int edg_wll_StatsResultToXML(edg_wll_Context,time_t,time_t,float,float,int,int,char **);
-
-int parseStatsRequest(edg_wll_Context,char *,char **,edg_wll_QueryRec ***,edg_wll_JobStatCode *,int *,time_t *,time_t *);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <ctype.h>
-#include <expat.h>
-
-#include "glite/wmsutils/jobid/cjobid.h"
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/escape.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-#include "glite/lb/xml_conversions.h"
-
-#include "glite/lb/purge.h"
-#include "glite/lb/dump.h"
-
-#include "lb_xml_parse_V21.h"
-
-#ifdef __GNUC__
-#define UNUSED_VAR __attribute__((unused))
-#else
-#define UNUSED_VAR
-#endif
-
-#define QUERY_EVENTS_BEGIN "<edg_wll_QueryEventsResult"
-#define QUERY_EVENTS_END "</edg_wll_QueryEventsResult>\r\n"
-#define QUERY_JOBS_BEGIN "<edg_wll_QueryJobsResult"
-#define QUERY_JOBS_END "</edg_wll_QueryJobsResult>\r\n"
-#define PURGE_RESULT_BEGIN "<edg_wll_PurgeResult"
-#define PURGE_RESULT_END "</edg_wll_PurgeResult>\r\n"
-#define DUMP_RESULT_BEGIN "<edg_wll_DumpResult"
-#define DUMP_RESULT_END "</edg_wll_DumpResult>\r\n"
-
-// XXX will be redundant soon
-#define USERJOBS_BEGIN "<edg_wll_UserJobs"
-#define USERJOBS_END "</edg_wll_UserJobs>\r\n"
-
-
-static char *ops[] = { "equal","less","greater","within" },
- *attrs[] = { "jobid","owner","status","location","destination",
- "donecode","usertag","time","level","host","source",
- "instance","type","chkpt_tag", "resubmitted", "parent_job", "exitcode" };
-
-static const struct timeval null_timeval = {0,0};
-
-#define unexp() {\
- char *e;\
-\
- if (XMLCtx->errtxt) {\
- asprintf(&e,"%s\nunexpected <%s> at line %d",XMLCtx->errtxt,\
- el,XML_GetCurrentLineNumber(XMLCtx->p));\
- free(XMLCtx->errtxt);\
- } else asprintf(&e,"unexpected <%s> at line %d",\
- el,XML_GetCurrentLineNumber(XMLCtx->p));\
- XMLCtx->errtxt = e;\
-}
-
-
-/* Dummy function, returns only const string "el"; just for compatibility */
-static char *return_string_el(edg_wll_JobStatCode statCode) {
- return("el");
-}
-
-
-static void startQueryJobsRequest(void *data, const char *el, const char **attr)
-{
- unsigned int i;
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_QueryJobsRequest")) { unexp() break; }
- for ( i = 0; attr[i] && attr[i+1]; i += 2 )
- {
- if ( !strcmp(attr[i],"softLimit") )
- XMLCtx->ctx->softLimit = atoi(attr[i+1]);
- else if ( !strcmp(attr[i],"queryRes") )
- XMLCtx->ctx->p_query_results = atoi(attr[i+1]);
- else { unexp() break; }
- }
- break;
- case 1: if (strcasecmp(el,"and") && strcasecmp(el,"flags")) unexp()
- break;
- case 2: if (strcasecmp(el,"or")) unexp()
- else {
- XMLCtx->position = -1;
- XMLCtx->conditions = realloc(XMLCtx->conditions,
- (++XMLCtx->row+2)*sizeof(*XMLCtx->conditions));
- XMLCtx->conditions[XMLCtx->row] = NULL;
- XMLCtx->conditions[XMLCtx->row+1] = NULL;
- }
- break;
- case 3:
- for (i=0; i<sizeof(ops)/sizeof(ops[0]); i++)
- if (!strcasecmp(el,ops[i])) break;
- if (i == sizeof(ops)/sizeof(ops[0])) unexp()
- else {
- /* malloc also terminator and set it to 0 (= EDG_WLL_QUERY_ATTR_UNDEF) */
- XMLCtx->conditions[XMLCtx->row] = realloc(XMLCtx->conditions[XMLCtx->row],
- (++XMLCtx->position+2)*sizeof(**XMLCtx->conditions));
- memset(&XMLCtx->conditions[XMLCtx->row][XMLCtx->position],0,2*sizeof(**XMLCtx->conditions));
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].op = i;
- XMLCtx->bound = 0;
- }
- break;
- case 4: for (i=0; i<sizeof(attrs)/sizeof(attrs[0]) &&
- strcasecmp(el,attrs[i]); i++);
- if (i == sizeof(attrs)/sizeof(attrs[0])) unexp()
- else {
- if ( (i+1) == EDG_WLL_QUERY_ATTR_USERTAG) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (strcmp(attr[0],"name")) { unexp() break;}
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = strdup(attr[1]);
- }
- else if ( (i+1) == EDG_WLL_QUERY_ATTR_TIME) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
- }
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].attr = i+1;
- }
- break;
- default: unexp(); break;
- }
- XMLCtx->level++;
-}
-
-
-static void startQueryEventsRequest(void *data, const char *el, const char **attr UNUSED_VAR)
-{
- unsigned int i;
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_QueryEventsRequest")) { unexp() break; }
- for ( i = 0; attr[i] && attr[i+1]; i += 2 )
- {
- if ( !strcmp(attr[i],"softLimit") )
- XMLCtx->ctx->softLimit = atoi(attr[i+1]);
- else if ( !strcmp(attr[i],"queryRes") )
- XMLCtx->ctx->p_query_results = atoi(attr[i+1]);
- else { unexp() break; }
- }
- break;
- case 1: if (strcasecmp(el,"and")) unexp()
- break;
- case 2: if (!strcasecmp(el,"orJobConditions")) {
- XMLCtx->type = EDG_WLL_QUERY_TYPE_JOB_CONDITION;
- XMLCtx->position = -1;
- XMLCtx->job_conditions = realloc(XMLCtx->job_conditions,
- (++XMLCtx->row+2)*sizeof(*XMLCtx->job_conditions));
- XMLCtx->job_conditions[XMLCtx->row] = NULL;
- XMLCtx->job_conditions[XMLCtx->row+1] = NULL;
-
- }
- else if (!strcasecmp(el,"orEventConditions")) {
- XMLCtx->type = EDG_WLL_QUERY_TYPE_EVENT_CONDITION;
- XMLCtx->position2 = -1;
- XMLCtx->event_conditions = realloc(XMLCtx->event_conditions,
- (++XMLCtx->row2+2)*sizeof(*XMLCtx->event_conditions));
- XMLCtx->event_conditions[XMLCtx->row2] = NULL;
- XMLCtx->event_conditions[XMLCtx->row2+1] = NULL;
- }
- else unexp()
- break;
- case 3:
- for (i=0; i<sizeof(ops)/sizeof(ops[0]); i++)
- if (!strcasecmp(el,ops[i])) break;
- if (i == sizeof(ops)/sizeof(ops[0])) unexp()
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_JOB_CONDITION) {
- /* malloc also terminator and set it to 0 (= EDG_WLL_QUERY_ATTR_UNDEF) */
- XMLCtx->job_conditions[XMLCtx->row] = realloc(XMLCtx->job_conditions[XMLCtx->row],
- (++XMLCtx->position+2)*sizeof(**XMLCtx->job_conditions));
- memset(&XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position],0,2*sizeof(**XMLCtx->job_conditions));
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].op = i;
- XMLCtx->bound = 0;
- }
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_EVENT_CONDITION) {
- /* malloc also terminator and set it to 0 (= EDG_WLL_QUERY_ATTR_UNDEF) */
- XMLCtx->event_conditions[XMLCtx->row2] = realloc(XMLCtx->event_conditions[XMLCtx->row2],
- (++XMLCtx->position2+2)*sizeof(**XMLCtx->event_conditions));
- memset(&XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2],0,2*sizeof(**XMLCtx->event_conditions));
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].op = i;
- XMLCtx->bound = 0;
- }
-
- break;
- case 4: for (i=0; i<sizeof(attrs)/sizeof(attrs[0]) &&
- strcasecmp(el,attrs[i]); i++);
- if (i == sizeof(attrs)/sizeof(attrs[0])) unexp()
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_JOB_CONDITION) {
- if ( (i+1) == EDG_WLL_QUERY_ATTR_USERTAG) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"name")) { unexp() break;}
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = strdup(attr[1]);
- }
- else if ( (i+1) == EDG_WLL_QUERY_ATTR_TIME) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
- printf("\nchecking time attr\n%s = %s (%d)\n\n", attr[0], attr[1], edg_wll_StringToStat(attr[1]));
- }
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr = i+1;
- }
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_EVENT_CONDITION) {
- if ( (i+1) == EDG_WLL_QUERY_ATTR_USERTAG) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"name")) { unexp() break;}
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position].attr_id.tag = strdup(attr[1]);
- }
- else if ( (i+1) == EDG_WLL_QUERY_ATTR_TIME) {
- if (!attr[0] || !attr[1]) { unexp() break;}
- if (attr[0] && strcmp(attr[0],"state")) { unexp() break;}
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position].attr_id.state = edg_wll_StringToStat(attr[1]);
- }
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].attr = i+1;
- }
- break;
- default: unexp(); break;
- }
- XMLCtx->level++;
-}
-
-
-
-static void startPurgeRequest(void *data, const char *el, const char **attr)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_PurgeRequest")) unexp()
- break;
- case 1: if (strcasecmp(el,"jobs") && strcasecmp(el,"timeout")
- && strcasecmp(el,"flags")) unexp()
- else
- XMLCtx->position = 0;
- break;
- case 2: if (!strcasecmp(el,"jobId")) {
- XMLCtx->purgeRequestGlobal.jobs = realloc(XMLCtx->purgeRequestGlobal.jobs,
- (XMLCtx->position+2) * sizeof(XMLCtx->purgeRequestGlobal.jobs));
-
- if (!XMLCtx->purgeRequestGlobal.jobs) {
- edg_wll_SetError(XMLCtx->ctx, ENOMEM, NULL);
- unexp() return;
- }
- XMLCtx->purgeRequestGlobal.jobs[XMLCtx->position+1] = NULL;
- }
- else if (!strcasecmp(el,"time")) {
- /* static array, no need to initialize & allocate anything */
- }
- else
- unexp()
- break;
- default: unexp()
- break;
- }
- XMLCtx->level++;
-}
-
-
-static void startDumpRequest(void *data, const char *el, const char **attr)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
-
- strcpy(XMLCtx->element, el);
-
- switch (XMLCtx->level) {
- case 0: if (strcasecmp(el,"edg_wll_DumpRequest")) unexp()
- break;
- case 1: if (strcasecmp(el,"from") && strcasecmp(el,"to")) unexp()
- break;
- default: unexp()
- break;
- }
- XMLCtx->level++;
-}
-
-#undef unexp
-
-
-static void char_handler(void *data, const char *s, int len)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- int i, found = -1;
- char *temp_s;
-
-
- /* if date are only spaces, t\, \r, \n ... don't bother with them */
- for (i=0; i<len; i++)
- if (!isspace(s[i])) { found = i; break; }
- if (found == -1) return;
-
- temp_s = realloc(XMLCtx->char_buf, XMLCtx->char_buf_len + len + 1);
- if (temp_s == NULL) {
- /* XXX propagate ENOMEM somehow */
- return;
- }
- XMLCtx->char_buf = temp_s;
- memcpy(XMLCtx->char_buf + XMLCtx->char_buf_len, s, len);
- XMLCtx->char_buf[XMLCtx->char_buf_len + len] = '\0';
- XMLCtx->char_buf_len += len;
-}
-
-
-
-static void endQueryJobsRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- char *e, *s;
-
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"flags") && XMLCtx->char_buf) {
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
-// XXX: check if it works
- XMLCtx->flags = edg_wll_string_to_stat_flags(s);
- free(s);
- }
- }
- else if (XMLCtx->level == 5) {
- switch (XMLCtx->conditions[XMLCtx->row][XMLCtx->position].attr) {
- case EDG_WLL_QUERY_ATTR_JOBID:
- case EDG_WLL_QUERY_ATTR_PARENT:
- if ( (XMLCtx->conditions[XMLCtx->row][XMLCtx->position].value.j =
- edg_wll_from_string_to_jobid(XMLCtx)) == NULL )
- {
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid JobId at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid JobId at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- }
- break;
- case EDG_WLL_QUERY_ATTR_OWNER:
- // XXX - this is way how to pass NULL, user will be extracted from ssl partner later
- /* XXX char_buf contains an escaped value, however there's nothing to escape in 'NULL' so we're fine */
- if (XMLCtx->char_buf != NULL && !strcmp(XMLCtx->char_buf,"NULL")) {
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].value.c = NULL;
- break;
- }
- else /* fall through */
- case EDG_WLL_QUERY_ATTR_LOCATION:
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- case EDG_WLL_QUERY_ATTR_USERTAG:
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].value.c =
- edg_wll_from_string_to_string(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_STATUS:
- case EDG_WLL_QUERY_ATTR_DONECODE:
- case EDG_WLL_QUERY_ATTR_EXITCODE:
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- if ( !XMLCtx->bound )
- {
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].value.i =
- edg_wll_from_string_to_int(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].value2.i =
- edg_wll_from_string_to_int(XMLCtx);
-
- break;
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( !XMLCtx->bound )
- {
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].value.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->conditions[XMLCtx->row][XMLCtx->position].value2.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- break;
- default:
- edg_wll_freeBuf(XMLCtx);
- XMLCtx->level--;
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid attribute type at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid attribute type at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- break;
- }
- }
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-static void endQueryEventsRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- char *e, *s;
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"orJobConditions")) {
- /* make end-of-row */
- XMLCtx->job_conditions[XMLCtx->row] = realloc(XMLCtx->job_conditions[XMLCtx->row],
- (++XMLCtx->position+1)*sizeof(**XMLCtx->job_conditions));
- memset(&XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position],0,sizeof(**XMLCtx->job_conditions));
- }
- else if (!strcmp(XMLCtx->element,"orEventConditions")) {
- /* make end-of-row */
- XMLCtx->event_conditions[XMLCtx->row2] = realloc(XMLCtx->event_conditions[XMLCtx->row2],
- (++XMLCtx->position2+1)*sizeof(**XMLCtx->event_conditions));
- memset(&XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2],0,sizeof(**XMLCtx->event_conditions));
- }
- }
- else if (XMLCtx->level == 5) {
- if (XMLCtx->type == EDG_WLL_QUERY_TYPE_JOB_CONDITION) {
- switch (XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr) {
- case EDG_WLL_QUERY_ATTR_JOBID:
- case EDG_WLL_QUERY_ATTR_PARENT:
- if ( (XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.j =
- edg_wll_from_string_to_jobid(XMLCtx)) == NULL )
- {
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid JobId at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid JobId at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- }
- break;
- case EDG_WLL_QUERY_ATTR_OWNER:
- case EDG_WLL_QUERY_ATTR_LOCATION:
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- case EDG_WLL_QUERY_ATTR_USERTAG:
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.c =
- edg_wll_from_string_to_string(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_STATUS:
- case EDG_WLL_QUERY_ATTR_DONECODE:
- case EDG_WLL_QUERY_ATTR_EXITCODE:
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- if ( !XMLCtx->bound )
- {
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.i =
- edg_wll_from_string_to_int(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value2.i =
- edg_wll_from_string_to_int(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( !XMLCtx->bound )
- {
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].value2.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- break;
- default:
- edg_wll_freeBuf(XMLCtx);
- XMLCtx->level--;
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid attribute type at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid attribute type at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- break;
- }
- }
- else if (XMLCtx->type == EDG_WLL_QUERY_TYPE_EVENT_CONDITION) {
- switch (XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].attr) {
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( !XMLCtx->bound )
- {
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value2.t.tv_sec =
- edg_wll_from_string_to_time_t(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_LEVEL:
- case EDG_WLL_QUERY_ATTR_SOURCE:
- case EDG_WLL_QUERY_ATTR_EVENT_TYPE:
- if ( !XMLCtx->bound )
- {
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value.i =
- edg_wll_from_string_to_int(XMLCtx);
- XMLCtx->bound++;
- }
- else
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value2.i =
- edg_wll_from_string_to_int(XMLCtx);
- break;
- case EDG_WLL_QUERY_ATTR_HOST:
- case EDG_WLL_QUERY_ATTR_INSTANCE:
- case EDG_WLL_QUERY_ATTR_USERTAG:
- XMLCtx->event_conditions[XMLCtx->row2][XMLCtx->position2].value.c =
- edg_wll_from_string_to_string(XMLCtx);
- break;
- default:
- edg_wll_freeBuf(XMLCtx);
- XMLCtx->level--;
- s = edg_wll_UnescapeXML((const char *) XMLCtx->char_buf);
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid attribute type at line %d",
- XMLCtx->errtxt, s,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid attribute type at line %d",
- s,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- free(s);
- break;
- }
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- }
- XMLCtx->level--;
-}
-
-
-static void endPurgeRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
- char *e;
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"flags"))
- XMLCtx->purgeRequestGlobal.flags = edg_wll_from_string_to_int(XMLCtx);
- }
- else if (XMLCtx->level == 3) {
- if (!strcmp(XMLCtx->element,"jobId")) {
- if ( (XMLCtx->purgeRequestGlobal.jobs[XMLCtx->position++] =
- edg_wll_from_string_to_string(XMLCtx)) == NULL )
- {
- /* XXX char_buf contains an escaped value, unescaping is done within edg_wll_from_string_to_string(), which failed */
- if (XMLCtx->errtxt) {
- asprintf(&e,"%s\n%s: invalid JobId at line %d",
- XMLCtx->errtxt, XMLCtx->char_buf,
- XML_GetCurrentLineNumber(XMLCtx->p));
- free(XMLCtx->errtxt);
- } else asprintf(&e,"%s: invalid JobId at line %d",
- XMLCtx->char_buf,XML_GetCurrentLineNumber(XMLCtx->p));
- XMLCtx->errtxt = e;
- }
- }
- else if (!strcmp(XMLCtx->element,"time") && XMLCtx->char_buf) {
- XMLCtx->purgeRequestGlobal.timeout[XMLCtx->position++] =
- edg_wll_from_string_to_time_t(XMLCtx);
- }
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-
-static void endDumpRequest(void *data, const char *el UNUSED_VAR)
-{
- edg_wll_XML_ctx *XMLCtx = data;
-
- if (XMLCtx->level == 2) {
- if (!strcmp(XMLCtx->element,"from"))
- XMLCtx->dumpRequestGlobal.from = edg_wll_from_string_to_time_t(XMLCtx);
- else if (!strcmp(XMLCtx->element,"to"))
- XMLCtx->dumpRequestGlobal.to = edg_wll_from_string_to_time_t(XMLCtx);
- }
-
- XMLCtx->char_buf = NULL;
- XMLCtx->char_buf_len = 0;
- XMLCtx->level--;
-}
-
-/* parse queryJobs request from client */
-int parseQueryJobsRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_QueryRec ***conditions, int *flags)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.row = -1;
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startQueryJobsRequest, endQueryJobsRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- int i,j;
-
- if (XMLCtx.conditions) {
- for (j = 0; XMLCtx.conditions[j]; j++) {
- for (i = 0; (XMLCtx.conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&XMLCtx.conditions[j][i]);
- free(XMLCtx.conditions[j]);
- }
- free(XMLCtx.conditions);
- }
-
- /* empty list terminators */
- conditions[0] = NULL;
- *flags = 0;
- } else {
- *conditions = XMLCtx.conditions;
- *flags = XMLCtx.flags;
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-/* parse queryEvents request from client */
-int parseQueryEventsRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_QueryRec ***job_conditions, edg_wll_QueryRec ***event_conditions)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.row = -1;
- XMLCtx.row2 = -1;
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startQueryEventsRequest, endQueryEventsRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- int i,j;
-
- if (XMLCtx.job_conditions) {
- for (j = 0; XMLCtx.job_conditions[j]; j++) {
- for (i = 0 ; (XMLCtx.job_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&XMLCtx.job_conditions[j][i]);
- free(XMLCtx.job_conditions[j]);
- }
- free(XMLCtx.job_conditions);
- }
- if (XMLCtx.event_conditions) {
- for (j = 0; XMLCtx.event_conditions[j]; j++) {
- for (i = 0 ; (XMLCtx.event_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ )
- edg_wll_QueryRecFree(&XMLCtx.event_conditions[j][i]);
- free(XMLCtx.event_conditions[j]);
- }
- free(XMLCtx.event_conditions);
- }
-
- /* empty list terminators */
- job_conditions[0] = NULL;
- event_conditions[0] = NULL;
- } else {
- *job_conditions = XMLCtx.job_conditions;
- *event_conditions = XMLCtx.event_conditions;
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-
-/* parse purge request from client */
-int parsePurgeRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_PurgeRequest *request)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startPurgeRequest, endPurgeRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL))) {
- int i;
-
- if (XMLCtx.purgeRequestGlobal.jobs) {
- for (i=0; XMLCtx.purgeRequestGlobal.jobs[i]; i++)
- free(XMLCtx.purgeRequestGlobal.jobs[i]);
- free(XMLCtx.purgeRequestGlobal.jobs);
- }
- memset(request,0,sizeof(*request));
-
- } else {
- memcpy(request, &XMLCtx.purgeRequestGlobal, sizeof(XMLCtx.purgeRequestGlobal));
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-
-/* parse dump request from client */
-int parseDumpRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_DumpRequest *request)
-{
- int ret;
- edg_wll_XML_ctx XMLCtx;
- XML_Char *encoding = "ISO-8859-1";
-
- errno = 0;
- edg_wll_initXMLCtx(&XMLCtx);
- XMLCtx.ctx = ctx;
- edg_wll_ResetError(ctx);
-
-
- /* initialize parser */
- XMLCtx.p = XML_ParserCreate(encoding);
- XML_SetElementHandler(XMLCtx.p, startDumpRequest, endDumpRequest);
- XML_SetCharacterDataHandler(XMLCtx.p, char_handler);
- XML_SetUserData(XMLCtx.p, (void *) &XMLCtx);
-
-
- if (! XML_Parse(XMLCtx.p, messageBody, strlen(messageBody), 1)) {
- char *errorMessage;
-
- asprintf(&errorMessage, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(XMLCtx.p),
- XML_ErrorString(XML_GetErrorCode(XMLCtx.p)));
-
- edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, errorMessage);
- free(errorMessage);
- } else if (XMLCtx.errtxt) edg_wll_SetError(ctx, EDG_WLL_ERROR_XML_PARSE, XMLCtx.errtxt);
-
-
- if ((ret = edg_wll_Error(ctx,NULL,NULL)))
- memset(request,0,sizeof(*request));
-
- else {
- memcpy(request, &XMLCtx.dumpRequestGlobal, sizeof(XMLCtx.dumpRequestGlobal));
- }
-
-
- XML_ParserFree(XMLCtx.p);
- edg_wll_freeXMLCtx(&XMLCtx);
- return ret;
-}
-
-
-
-int edg_wll_QueryEventsToXMLV21(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut, char **message)
-{
- char *pomA, *pomB;
- char **list = NULL;
- int i = 0, len, tot_len = 0;
- int *len_list = NULL;
-
-
- while (eventsOut && eventsOut[i].any.type != EDG_WLL_EVENT_UNDEF) {
- pomB = edg_wll_EventToString(eventsOut[i].any.type);
- trio_asprintf(&pomA," <edg_wll_Event name=\"%|Xs\">\r\n", pomB);
- free(pomB);
- pomB = pomA;
-
-
-@@@{
- selectType $event '_common_';
- for (getFieldsOrdered $event) {
- my $f = selectField $event $_;
- my $ft = $f->{type};
- my $n = $f->{null};
- gen "\tedg_wll_add_$ft\_to_XMLBody(&pomB, eventsOut[i].any.$_, \"$_\", $n);\n";
- }
-
- gen "\tswitch (eventsOut[i].any.type) {\n";
- for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } getTypes $event) {
- if ($t ne 'any') {
- selectType $event $t;
- my $u = uc $t;
- gen "\t case EDG_WLL_EVENT_$u :\n";
- for (getFieldsOrdered $event) {
- my $f = selectField $event $_;
- my $ft = $f->{type};
- my $n = $f->{null};
- $t = lcfirst $t;
- if ($t =~ m/^pBS/) { $t = ucfirst $t; }
- if ($t =~ m/^condor/) { $t = ucfirst $t; }
- gen "\t\tedg_wll_add_$ft\_to_XMLBody(&pomB, eventsOut[i].$t.$_, \"$_\", $n);\n";
- }
- gen "\t\tbreak;\n";
- }
- }
- gen "\t default : break;\n";
- gen "\t}\n";
-@@@}
-
-
-
- len = asprintf(&pomA,"%s </edg_wll_Event>\r\n", pomB);
- free(pomB);
- i++;
- tot_len += len;
-
- list = (char **) realloc(list, i * sizeof(*list));
- list[i-1] = pomA;
- len_list = (int *) realloc(len_list, i * sizeof(*len_list));
- len_list[i-1] = len;
-
- }
-
- /* list termination */
- list = (char **) realloc(list, (i+1) * sizeof(*list));
- list[i] = NULL;
-
- /* test errors */
- if (ctx->errDesc || ctx->errCode)
- len = trio_asprintf(&pomB," code=\"%d\" desc=\"%|Xs\">\r\n",ctx->errCode,ctx->errDesc);
- else
- len = asprintf(&pomB,">\r\n");
-
- /* glueing all list fields together & freeing the list */
- pomA = (char *) malloc(tot_len * sizeof(char) +
- sizeof(QUERY_EVENTS_BEGIN) + len + sizeof(QUERY_EVENTS_END) - 1);
-
- memcpy(pomA, QUERY_EVENTS_BEGIN, sizeof(QUERY_EVENTS_BEGIN));
- memcpy(pomA + sizeof(QUERY_EVENTS_BEGIN) - 1, pomB, len);
- free(pomB);
- pomB = pomA + sizeof(QUERY_EVENTS_BEGIN) + len - 1;
-
- i = 0;
- while (list[i]) {
- memcpy(pomB, list[i], len_list[i] );
- pomB += len_list[i];
-
- /* freeing the list */
- free(list[i]);
-
- i++;
- }
-
- strcpy(pomB, QUERY_EVENTS_END);
-
-
- free(list);
- free(len_list);
-
-
- *message = pomA;
-
- return 0;
-}
-
-int edg_wll_QueryJobsToXMLV21(edg_wll_Context ctx, edg_wlc_JobId *jobsIn, edg_wll_JobStat *statesIn, char **message)
-{
- char *pomA, *pomB, *pomC;
- char **list = NULL;
- int i = 0, len, tot_len = 0, nres = 0;
- int *len_list = NULL;
-
-
- if (jobsIn) for (nres = 0; jobsIn[nres]; nres++);
- else if (statesIn) for (nres = 0; statesIn[nres].state; nres++);
-
- while (i < nres) {
- trio_asprintf(&pomA,"\t<edg_wll_Job>\r\n");
- pomB = pomA;
-
- if (jobsIn) {
- trio_asprintf(&pomA,"%s\t\t<jobId>%|Xs</jobId>\r\n",
- pomB, pomC=edg_wlc_JobIdUnparse(jobsIn[i]));
- free(pomC);
- free(pomB);
- pomB = pomA;
- }
-
- if (statesIn) {
- edg_wll_JobStatusToXMLV21(ctx, statesIn[i], &pomC);
- trio_asprintf(&pomA,"%s\t\t%s",pomB,pomC);
- }
- else {
- pomC = edg_wll_StatToString(EDG_WLL_JOB_UNKNOWN);
- trio_asprintf(&pomA,"%s\t\t<jobStat name=\"%|Xs\">\r\n\r\n\t\t</jobStat>\r\n",
- pomB, pomC);
- }
-
- free(pomB);
- free(pomC);
- pomB = pomA;
-
-
- len = asprintf(&pomA,"%s\t</edg_wll_Job>\r\n", pomB);
- free(pomB);
- i++;
- tot_len += len;
-
- list = (char **) realloc(list, i * sizeof(*list));
- list[i-1] = pomA;
- len_list = (int *) realloc(len_list, i * sizeof(*len_list));
- len_list[i-1] = len;
- }
-
- /* list termination */
- list = (char **) realloc(list, (i+1) * sizeof(*list));
- list[i] = NULL;
-
- /* test errors */
- if (ctx->errDesc || ctx->errCode)
- len = trio_asprintf(&pomB," code=\"%d\" desc=\"%|Xs\">\r\n",ctx->errCode,ctx->errDesc);
- else
- len = asprintf(&pomB,">\r\n");
-
- /* glueing all list fields together & freeing the list */
- pomA = (char *) malloc(tot_len * sizeof(char) +
- sizeof(QUERY_JOBS_BEGIN) + len + sizeof(QUERY_JOBS_END) - 1);
-
- memcpy(pomA, QUERY_JOBS_BEGIN, sizeof(QUERY_JOBS_BEGIN));
- memcpy((pomA + sizeof(QUERY_JOBS_BEGIN) - 1), pomB, len);
- free(pomB);
- pomB = pomA + sizeof(QUERY_JOBS_BEGIN) + len - 1;
-
- i = 0;
- while (list[i]) {
- memcpy(pomB, list[i], len_list[i] );
- pomB += len_list[i];
-
- /* freeing the list */
- free(list[i]);
-
- i++;
- }
-
- strcpy(pomB, QUERY_JOBS_END);
-
-
- free(list);
- free(len_list);
-
-
- *message = pomA;
-
- return 0;
-}
-
-/* construct Message-Body of Response-Line for edg_wll_UserJobs */
-int edg_wll_UserJobsToXMLV21(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOut, char **message)
-{
- char *pomA, *pomB;
- char **list = NULL;
- int i = 0, len, tot_len = 0;
- int *len_list = NULL;
-
-
- while (jobsOut[i]) {
- len = trio_asprintf(&pomA," <jobId>%|Xs</jobId>\r\n",
- pomB=edg_wlc_JobIdUnparse(jobsOut[i]));
-
- free(pomB);
-
- i++;
- tot_len += len;
-
- list = (char **) realloc(list, i * sizeof(*list));
- list[i-1] = pomA;
- pomA = NULL;
- len_list = (int *) realloc(len_list, i * sizeof(*len_list));
- len_list[i-1] = len;
-
- }
-
- /* list termination */
- list = (char **) realloc(list, (i+1) * sizeof(*list));
- list[i] = NULL;
-
- /* test errors */
- if (ctx->errDesc || ctx->errCode)
- len = trio_asprintf(&pomB," code=\"%d\" desc=\"%|Xs\">\r\n",ctx->errCode,ctx->errDesc);
- else
- len = asprintf(&pomB,">\r\n");
-
- /* glueing all list fields together & freeing the list */
- pomA = (char *) malloc(tot_len * sizeof(char) +
- sizeof(USERJOBS_BEGIN) + len + sizeof(USERJOBS_END) - 1);
-
- memcpy(pomA, USERJOBS_BEGIN, sizeof(USERJOBS_BEGIN));
- memcpy((pomA + sizeof(USERJOBS_BEGIN) - 1), pomB, len);
- free(pomB);
- pomB = pomA + sizeof(USERJOBS_BEGIN) + len - 1;
-
- i = 0;
- while (list[i]) {
- memcpy(pomB, list[i], len_list[i] );
- pomB += len_list[i];
-
- /* freeing the list */
- free(list[i]);
-
- i++;
- }
-
- strcpy(pomB, USERJOBS_END);
-
-
- free(list);
- free(len_list);
-
-
- *message = pomA;
-
- return 0;
-}
-
-static void edg_wll_add_stslist_to_XMLBodyV21(edg_wll_Context ctx, char **body, const edg_wll_JobStat *toAdd, const char *tag, const char *UNUSED_subTag, const int null)
-{
- char *pomA, *pomB, *newBody;
- char **list = NULL;
- int i = 0, len, tot_len = 0;
- int *len_list = NULL;
-
-
- while (toAdd[i].state != null) {
- edg_wll_JobStatusToXMLV21(ctx, toAdd[i], &pomA);
- len = strlen(pomA);
-
- i++;
- tot_len += len;
-
- list = (char **) realloc(list, i * sizeof(*list));
- list[i-1] = pomA;
- pomA = NULL;
- len_list = (int *) realloc(len_list, i * sizeof(*len_list));
- len_list[i-1] = len;
- }
-
- /* list termination */
- list = (char **) realloc(list, (i+1) * sizeof(*list));
- list[i] = NULL;
-
- /* glueing all list fields together & freeing the list */
- pomA = (char *) malloc(tot_len * sizeof(char) + 1);
- pomB = pomA;
-
- i = 0;
- while (list[i]) {
- memcpy(pomB, list[i], len_list[i] );
- pomB += len_list[i];
-
- /* freeing the list */
- free(list[i]);
-
- i++;
- }
- *pomB = '\0';
- free(list);
- free(len_list);
-
- asprintf(&newBody,"%s\t\t\t<%s>\r\n%s\t\t\t</%s>\r\n", *body, tag, pomA, tag);
- free(*body);
- free(pomA);
- *body = newBody;
-}
-
-
-/* construct Message-Body of Response-Line for edg_wll_JobStatus */
-int edg_wll_JobStatusToXMLV21(edg_wll_Context ctx, edg_wll_JobStat stat, char **message)
-{
- char *pomA, *pomB, *pomC;
-
-
- pomB = strdup("");
-
-@@@{
- selectType $status '_common_';
- for (getFieldsOrdered $status) {
- my $f = selectField $status $_;
- next if defined($f->{special}) && $f->{special} eq 'XMLstructured';
- my $ft = $f->{type};
- my $n = $f->{null};
- gen "edg_wll_add_$ft\_to_XMLBody(&pomB, stat.$_, \"$_\", $n);\n";
- }
-@@@}
- if (stat.children) edg_wll_add_strlist_to_XMLBody(&pomB, stat.children, "children", "jobId", "\t\t\t", NULL);
- if (stat.children_hist) edg_wll_add_intlist_to_XMLBody(&pomB, stat.children_hist, "children_hist", return_string_el, "\t\t\t", 1, stat.children_hist[0]);
- if (stat.children_states) edg_wll_add_stslist_to_XMLBodyV21(ctx, &pomB, stat.children_states, "children_states", "", EDG_WLL_JOB_UNDEF);
- if (stat.user_tags) edg_wll_add_taglist_to_XMLBody(&pomB, stat.user_tags, "user_tags", "tag", "name", "\t\t\t", NULL);
- if (stat.stateEnterTimes) edg_wll_add_intlist_to_XMLBody(&pomB, stat.stateEnterTimes, "stateEnterTimes", return_string_el, "\t\t\t",1, stat.stateEnterTimes[0]);
-
- pomC = edg_wll_StatToString(stat.state);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomA,"<jobStat name=\"%|Xs\" code=\"%d\" desc=\"%|Xs\">\r\n%s</jobStat>",
- pomC, ctx->errCode,ctx->errDesc, pomB);
- else
- trio_asprintf(&pomA,"<jobStat name=\"%|Xs\">\r\n%s</jobStat>",
- pomC, pomB);
-
- free(pomB);
- free(pomC);
-
- *message = pomA;
-
- return 0;
-}
-
-
-
-/* construct Message-Body of Request-Line for edg_wll_Purge */
-int edg_wll_PurgeResultToXMLV21(
- edg_wll_Context ctx,
- edg_wll_PurgeResult *result,
- char **message)
-{
- char *pomA, *pomB;
-
-
- if (!result) { *message = NULL; return(-1); }
-
- pomA = strdup("");
- edg_wll_add_strlist_to_XMLBody(&pomA, result->jobs, "jobs", "jobId", "\t", NULL);
- edg_wll_add_string_to_XMLBody(&pomA, result->server_file, "server_file", NULL);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomA,"%s code=\"%d\" desc=\"%|Xs\">\r\n%s%s",
- PURGE_RESULT_BEGIN, ctx->errCode, ctx->errDesc, pomA, PURGE_RESULT_END);
- else
- trio_asprintf(&pomB,"%s>\r\n%s%s", PURGE_RESULT_BEGIN, pomA, PURGE_RESULT_END);
- free(pomA);
-
- *message = pomB;
- return 0;
-}
-
-
-
-/* construct Message-Body of Request-Line for edg_wll_Dump */
-int edg_wll_DumpResultToXMLV21(
- edg_wll_Context ctx,
- edg_wll_DumpResult *result,
- char **message)
-{
- char *pomA, *pomB;
-
-
- if (!result) { *message = NULL; return(-1); }
-
- pomA = strdup("");
- edg_wll_add_string_to_XMLBody(&pomA, result->server_file, "server_file", NULL);
- edg_wll_add_time_t_to_XMLBody(&pomA, result->from, "from", 0);
- edg_wll_add_time_t_to_XMLBody(&pomA, result->to, "to", 0);
-
- if (ctx->errDesc || ctx->errCode)
- trio_asprintf(&pomB,"%s code=\"%d\" desc=\"%|Xs\">\r\n%s%s",
- DUMP_RESULT_BEGIN, ctx->errCode, ctx->errDesc, pomA, DUMP_RESULT_END);
- else
- trio_asprintf(&pomB,"%s>\r\n%s%s", DUMP_RESULT_BEGIN, pomA, DUMP_RESULT_END);
- free(pomA);
-
- *message = pomB;
- return 0;
-}
+++ /dev/null
-#ifndef _LB_XML_PARSE_H_V21
-#define _LB_XML_PARSE_H_V21
-
-#ident "$Header$"
-
-#include "glite/lb/consumer.h"
-
-/* function for parsing/unparsing XML requests from client */
-
-int parseQueryJobsRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_QueryRec ***conditions, int *flags);
-int parseQueryEventsRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_QueryRec ***job_conditions, edg_wll_QueryRec ***event_conditions);
-int parsePurgeRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_PurgeRequest *request);
-int parseDumpRequestV21(edg_wll_Context ctx, char *messageBody, edg_wll_DumpRequest *request);
-int edg_wll_QueryEventsToXMLV21(edg_wll_Context, edg_wll_Event *, char **);
-int edg_wll_QueryJobsToXMLV21(edg_wll_Context, edg_wlc_JobId *, edg_wll_JobStat *, char **);
-int edg_wll_JobStatusToXMLV21(edg_wll_Context, edg_wll_JobStat, char **);
-int edg_wll_UserJobsToXMLV21(edg_wll_Context, edg_wlc_JobId *, char **);
-int edg_wll_PurgeResultToXMLV21(edg_wll_Context ctx, edg_wll_PurgeResult *result, char **message);
-int edg_wll_DumpResultToXMLV21(edg_wll_Context ctx, edg_wll_DumpResult *result, char **message);
-
-#endif
+++ /dev/null
-#ident "$Header$"
-
-#include "mysql.h" // MySql header file
-#include "mysqld_error.h"
-#include "errmsg.h"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <time.h>
-#include <assert.h>
-#include <stdarg.h>
-
-#include "lbs_db.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-
-#define DEFAULTCS "lbserver/@localhost:lbserver20"
-
-#define my_err() edg_wll_SetError(ctx,EDG_WLL_ERROR_DB_CALL,mysql_error((MYSQL *) ctx->mysql))
-
-struct _edg_wll_Stmt {
- MYSQL_RES *result;
- edg_wll_Context ctx;
-};
-
-
-static edg_wll_ErrorCode db_connect(edg_wll_Context ctx, const char *cs, MYSQL **mysql)
-{
- char *buf = NULL;
- char *host,*user,*pw,*db;
- char *slash,*at,*colon;
-
- if (!cs) cs = DEFAULTCS;
-
- if (!(*mysql = mysql_init(NULL)))
- return edg_wll_SetError(ctx,ENOMEM,NULL);
-
- mysql_options(*mysql, MYSQL_READ_DEFAULT_FILE, "my");
-
- host = user = pw = db = NULL;
-
- buf = strdup(cs);
- slash = strchr(buf,'/');
- at = strrchr(buf,'@');
- colon = strrchr(buf,':');
-
- if (!slash || !at || !colon) {
- free(buf);
- return edg_wll_SetError(ctx,EINVAL,"DB connect string");
- }
-
- *slash = *at = *colon = 0;
- host = at+1;
- user = buf;
- pw = slash+1;
- db = colon+1;
-
- /* ljocha: CLIENT_FOUND_ROWS added to make authorization check
- * working in update_notif().
- * Hope it does not break anything else */
- if (!mysql_real_connect(*mysql,host,user,pw,db,0,NULL,CLIENT_FOUND_ROWS)) {
- free(buf);
- return my_err();
- }
-
- free(buf);
- return edg_wll_ResetError(ctx);
-}
-
-
-static void db_close(MYSQL *mysql) {
- mysql_close(mysql);
-}
-
-
-static int transaction_test(edg_wll_Context ctx, MYSQL *m2) {
- MYSQL *m1;
- char *desc, *cmd_create, *cmd_insert, *cmd_select, *cmd_drop;
- int retval;
- edg_wll_ErrorCode err;
- pid_t pid;
-
- ctx->use_transactions = 1;
- pid = getpid();
-
- asprintf(&cmd_create, "create table test%d (item int) engine='innodb'", pid);
- asprintf(&cmd_insert, "insert into test%d (item) values (1)", pid);
- asprintf(&cmd_select, "select item from test%d", pid);
- asprintf(&cmd_drop, "drop table test%d", pid);
-
- m1 = (MYSQL *)ctx->mysql;
- edg_wll_ExecStmt(ctx, cmd_drop, NULL);
- if (edg_wll_ExecStmt(ctx, cmd_create, NULL) != 0) {
- edg_wll_ResetError(ctx);
- goto err1;
- }
- if (edg_wll_Transaction(ctx) != 0) goto err2;
- if (edg_wll_ExecStmt(ctx, cmd_insert, NULL) != 1) goto err2;
-
- ctx->mysql = (void *)m2;
- if ((retval = edg_wll_ExecStmt(ctx, cmd_select, NULL)) == -1) goto err2;
- ctx->use_transactions = (retval == 0);
-
- ctx->mysql = (void *)m1;
- if (edg_wll_Commit(ctx) != 0) goto err2;
- if (edg_wll_ExecStmt(ctx, cmd_drop, NULL) != 0) goto err1;
-
-#ifdef LBS_DB_PROFILE
- fprintf(stderr, "[%d] use_transactions = %d\n", getpid(), ctx->use_transactions);
-#endif
-
- goto ok;
-err2:
- err = edg_wll_Error(ctx, NULL, &desc);
- edg_wll_ExecStmt(ctx, cmd_drop, NULL);
- edg_wll_SetError(ctx, err, desc);
-err1:
- ctx->use_transactions = 0;
-ok:
- free(cmd_create);
- free(cmd_insert);
- free(cmd_select);
- free(cmd_drop);
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-edg_wll_ErrorCode edg_wll_DBConnect(edg_wll_Context ctx, const char *cs)
-{
- return db_connect(ctx, cs, (MYSQL **)&ctx->mysql);
-}
-
-
-void edg_wll_DBClose(edg_wll_Context ctx)
-{
- db_close((MYSQL *) ctx->mysql);
- ctx->mysql = NULL;
-}
-
-
-int edg_wll_ExecStmt(edg_wll_Context ctx,char *txt,edg_wll_Stmt *stmt)
-{
- int err;
- int retry_nr = 0;
- int do_reconnect = 0;
-#ifdef LBS_DB_PROFILE
- struct timeval start,end;
- int pid;
-
- static struct timeval sum = {
- tv_sec: 0,
- tv_usec: 0
- };
-#endif
-
- edg_wll_ResetError(ctx);
-
- if (stmt) {
- *stmt = NULL;
- }
-/*
-fputs(txt,stderr);
-putc(10,stderr);
-*/
-
-#ifdef LBS_DB_PROFILE
- gettimeofday(&start,NULL);
-#endif
-
- while (retry_nr == 0 || do_reconnect) {
- do_reconnect = 0;
- if (mysql_query((MYSQL *) ctx->mysql,txt)) {
- /* error occured */
- switch (err = mysql_errno((MYSQL *) ctx->mysql)) {
- case 0:
- break;
- case ER_DUP_ENTRY:
- edg_wll_SetError(ctx,EEXIST,mysql_error((MYSQL *) ctx->mysql));
- return -1;
- break;
- case CR_SERVER_LOST:
- if (retry_nr <= 0)
- do_reconnect = 1;
- break;
- default:
- my_err();
- return -1;
- break;
- }
- }
- retry_nr++;
- }
-
- if (stmt) {
- *stmt = malloc(sizeof(**stmt));
- if (!*stmt) {
- edg_wll_SetError(ctx,ENOMEM,NULL);
- return -1;
- }
- memset(*stmt,0,sizeof(**stmt));
- (**stmt).ctx = ctx;
- (**stmt).result = mysql_store_result((MYSQL *) ctx->mysql);
- if (!(**stmt).result) {
- if (mysql_errno((MYSQL *) ctx->mysql)) {
- my_err();
- return -1;
- }
- }
- } else {
- MYSQL_RES *r = mysql_store_result((MYSQL *) ctx->mysql);
- mysql_free_result(r);
- }
-#ifdef LBS_DB_PROFILE
- pid = getpid();
- gettimeofday(&end,NULL);
- end.tv_usec -= start.tv_usec;
- end.tv_sec -= start.tv_sec;
- if (end.tv_usec < 0) { end.tv_sec--; end.tv_usec += 1000000; }
-
- sum.tv_usec += end.tv_usec;
- sum.tv_sec += end.tv_sec + sum.tv_usec / 1000000;
- sum.tv_usec -= 1000000 * (sum.tv_usec / 1000000);
- fprintf(stderr,"[%d] %s\n[%d] %3ld.%06ld (sum: %3ld.%06ld)\n",pid,txt,pid,end.tv_sec,end.tv_usec,sum.tv_sec,sum.tv_usec);
-#endif
-
- return mysql_affected_rows((MYSQL *) ctx->mysql);
-}
-
-int edg_wll_FetchRow(edg_wll_Stmt stmt,char **res)
-{
- MYSQL_ROW row;
- edg_wll_Context ctx = stmt->ctx;
- int nr,i;
- unsigned long *len;
-
- edg_wll_ResetError(ctx);
-
- if (!stmt->result) return 0;
-
- if (!(row = mysql_fetch_row(stmt->result))) {
- if (mysql_errno((MYSQL *) ctx->mysql)) {
- my_err();
- return -1;
- } else return 0;
- }
-
- nr = mysql_num_fields(stmt->result);
- len = mysql_fetch_lengths(stmt->result);
- for (i=0; i<nr; i++) res[i] = len[i] ? strdup(row[i]) : strdup("");
-
- return nr;
-}
-
-int edg_wll_QueryColumns(edg_wll_Stmt stmt,char **cols)
-{
- int i = 0;
- MYSQL_FIELD *f;
-
- while ((f = mysql_fetch_field(stmt->result))) cols[i++] = f->name;
- return i == 0;
-}
-
-void edg_wll_FreeStmt(edg_wll_Stmt *stmt)
-{
- if (*stmt) {
- if ((**stmt).result) mysql_free_result((**stmt).result);
- free(*stmt);
- *stmt = NULL;
- }
-}
-
-int edg_wll_DBCheckVersion(edg_wll_Context ctx, const char *cs)
-{
- MYSQL *m = (MYSQL *) ctx->mysql;
- MYSQL *m2;
- const char *ver_s = mysql_get_server_info(m);
- int major,minor,sub,version;
-
- if (!ver_s || 3 != sscanf(ver_s,"%d.%d.%d",&major,&minor,&sub))
- return edg_wll_SetError(ctx,EINVAL,"retreiving MySQL version");
-
- version = 10000*major + 100*minor + sub;
-
- if (version < EDG_WLL_MYSQL_VERSION) {
- char msg[300];
-
- snprintf(msg,sizeof msg,"Your MySQL version is %d. At least %d required.",version,EDG_WLL_MYSQL_VERSION);
- return edg_wll_SetError(ctx,EINVAL,msg);
- }
-
- edg_wll_ResetError(ctx);
-
- if (db_connect(ctx, cs, &m2) == 0) {
- transaction_test(ctx, m2);
- db_close(m2);
- }
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-int edg_wll_Transaction(edg_wll_Context ctx) {
- if (ctx->use_transactions) {
- if (edg_wll_ExecStmt(ctx, "set autocommit=0", NULL) < 0) goto err;
- if (edg_wll_ExecStmt(ctx, "begin", NULL) < 0) goto err;
- }
-err:
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-int edg_wll_Commit(edg_wll_Context ctx) {
- if (ctx->use_transactions) {
- if (edg_wll_ExecStmt(ctx, "commit", NULL) < 0) goto err;
- if (edg_wll_ExecStmt(ctx, "set autocommit=1", NULL) < 0) goto err;
- }
-err:
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-int edg_wll_Rollback(edg_wll_Context ctx) {
- if (ctx->use_transactions) {
- if (edg_wll_ExecStmt(ctx, "rollback", NULL) < 0) goto err;
- if (edg_wll_ExecStmt(ctx, "set autocommit=1", NULL) < 0) goto err;
- }
-err:
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-edg_wll_ErrorCode edg_wll_bufferedInsertInit(edg_wll_Context ctx, edg_wll_bufInsert *bi, void *mysql, char *table_name, long size_limit, long record_limit, char *columns)
-{
- bi->ctx = ctx;
- bi->table_name = strdup(table_name);
- bi->columns = strdup(columns);
- bi->rec_num = 0;
- bi->rec_size = 0;
- bi->rows = calloc(record_limit, sizeof(*(bi->rows)) );;
- bi->size_limit = size_limit;
- bi->record_limit = record_limit;
-
- return edg_wll_Error(bi->ctx,NULL,NULL);
-;
-}
-
-
-
-static int string_add(char *what, long *used_size, long *alloc_size, char **where)
-{
- long what_len = strlen(what);
- int reall = 0;
-
- while (*used_size + what_len >= *alloc_size) {
- *alloc_size += BUF_INSERT_ROW_ALLOC_BLOCK;
- reall = 1;
- }
-
- if (reall)
- *where = realloc(*where, *alloc_size * sizeof(char));
-
- what_len = sprintf(*where + *used_size, "%s", what);
- if (what_len < 0) /* ENOMEM? */ return -1;
-
- *used_size += what_len;
-
- return 0;
-}
-
-
-static int flush_bufferd_insert(edg_wll_bufInsert *bi)
-{
- char *stmt, *vals, *temp;
- long i;
-
-
- if (!bi->rec_num)
- return edg_wll_Error(bi->ctx,NULL,NULL);
-
- asprintf(&vals,"(%s)", bi->rows[0]);
- for (i=1; i < bi->rec_num; i++) {
- // XXX: use string add (preallocated memory)
- asprintf(&temp,"%s,(%s)", vals, bi->rows[i]);
- free(vals); vals = temp; temp = NULL;
- free(bi->rows[i]);
- bi->rows[i] = NULL;
- }
-
- trio_asprintf(&stmt, "insert into %|Ss(%|Ss) values %s;",
- bi->table_name, bi->columns, vals);
-
- if (edg_wll_ExecStmt(bi->ctx,stmt,NULL) < 0) {
- if (edg_wll_Error(bi->ctx,NULL,NULL) == EEXIST)
- edg_wll_ResetError(bi->ctx);
- }
-
- /* reset bi counters */
- bi->rec_size = 0;
- bi->rec_num = 0;
-
- free(vals);
- free(stmt);
-
- return edg_wll_Error(bi->ctx,NULL,NULL);
-}
-
-
-/*
- * adds row of n values into n columns into an insert buffer
- * if num. of rows or size of data oversteps the limits, real
- * multi-row insert is done
- */
-edg_wll_ErrorCode edg_wll_bufferedInsert(edg_wll_bufInsert *bi, char *row)
-{
- bi->rows[bi->rec_num++] = strdup(row);
- bi->rec_size += strlen(row);
-
- if ((bi->size_limit && bi->rec_size >= bi->size_limit) ||
- (bi->record_limit && bi->rec_num >= bi->record_limit))
- {
- if (flush_bufferd_insert(bi))
- return edg_wll_Error(bi->ctx,NULL,NULL);
- }
-
- return edg_wll_ResetError(bi->ctx);
-}
-
-static void free_buffered_insert(edg_wll_bufInsert *bi) {
- long i;
-
- free(bi->table_name);
- free(bi->columns);
- for (i=0; i < bi->rec_num; i++) {
- free(bi->rows[i]);
- }
- free(bi->rows);
-}
-
-edg_wll_ErrorCode edg_wll_bufferedInsertClose(edg_wll_bufInsert *bi)
-{
- if (flush_bufferd_insert(bi))
- return edg_wll_Error(bi->ctx,NULL,NULL);
- free_buffered_insert(bi);
-
- return edg_wll_ResetError(bi->ctx);
-}
-
+++ /dev/null
-#ident "$Header$"
-
-#include <time.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-char *edg_wll_TimeToDB(time_t t)
-{
- struct tm *tm = gmtime(&t);
- char tbuf[256];
-
- sprintf(tbuf,"'%4d-%02d-%02d %02d:%02d:%02d'",tm->tm_year+1900,tm->tm_mon+1,
- tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec);
-
- return strdup(tbuf);
-}
-
-time_t edg_wll_DBToTime(char *t)
-{
- struct tm tm;
-
- memset(&tm,0,sizeof(tm));
- setenv("TZ","UTC",1); tzset();
- sscanf(t,"%4d-%02d-%02d %02d:%02d:%02d",
- &tm.tm_year,&tm.tm_mon,&tm.tm_mday,
- &tm.tm_hour,&tm.tm_min,&tm.tm_sec);
- tm.tm_year -= 1900;
- tm.tm_mon--;
-
- return mktime(&tm);
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <time.h>
-#include <stdio.h>
-#include <string.h>
-#include <syslog.h>
-#include <assert.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <ctype.h>
-
-#include "glite/lb/trio.h"
-
-#include "glite/lb/context-int.h"
-#include "glite/lb/events_parse.h"
-#include "glite/lb/ulm_parse.h"
-#include "glite/lb/purge.h"
-#include "glite/lb/purge.h"
-#include "glite/lb/events.h"
-#include "glite/lb/dump.h"
-#include "glite/lb/load.h"
-
-#include "store.h"
-#include "purge.h"
-#include "lbs_db.h"
-#include "query.h"
-#include "get_events.h"
-#include "server_state.h"
-
-static int read_line(char **buff, size_t *maxsize, int fd);
-
-int edg_wll_LoadEvents(edg_wll_Context ctx,const edg_wll_LoadRequest *req,edg_wll_LoadResult *result)
-{
- int fd,
- reject_fd = -1,
- readret, i;
- size_t maxsize;
- char *line = NULL,
- buff[30];
- edg_wll_Event *event;
- edg_wlc_JobId jobid = NULL;
-
-
- edg_wll_ResetError(ctx);
-
- if ( !req->server_file )
- return edg_wll_SetError(ctx, EINVAL, "Server file is not specified for load");
-
- if ( (fd = open(req->server_file, O_RDONLY)) == -1 )
- return edg_wll_SetError(ctx, errno, "Server can not open the file");
-
- if (edg_wll_Transaction(ctx) != 0)
- return edg_wll_Error(ctx, NULL, NULL);
-
- memset(result,0,sizeof(*result));
- i = 0;
- while ( 1 )
- {
- /* Read one line
- */
- if ( (readret = read_line(&line, &maxsize, fd)) == -1 ) {
- edg_wll_Rollback(ctx);
- return edg_wll_SetError(ctx, errno, "reading dump file");
- }
-
- if ( readret == 0 )
- break;
-
- i++;
- if ( sscanf(line, "DG.ARRIVED=%s %*s", buff) != 1
- || edg_wll_ParseEvent(ctx, line, &event) )
- {
- char errs[100];
- sprintf(errs, "Error parsing event at line %d", i);
- if ( !edg_wll_Error(ctx,NULL,NULL) )
- edg_wll_SetError(ctx, EINVAL, errs);
- fprintf(stderr, errs);
- continue;
- }
- edg_wll_ULMDateToTimeval(buff, &(event->any.arrived));
-
- if ( i == 1 )
- {
- result->from = event->any.arrived.tv_sec;
- result->to = event->any.arrived.tv_sec;
- }
- ctx->event_load = 1;
- if ( edg_wll_StoreEvent(ctx, event, NULL) )
- {
- char *errdesc;
- int len = strlen(line),
- total = 0,
- written;
-
- edg_wll_Error(ctx, NULL, &errdesc);
- fprintf(stderr, "Can't store event: %s\n", errdesc);
- if ( reject_fd == -1 )
- {
- char *s, *s1;
-
- if ( result->server_file != NULL )
- goto cycle_clean;
-
- s1 = strdup(req->server_file);
- s = strrchr(s1, '/');
- if ( s )
- {
- *s = '\0';
- reject_fd = edg_wll_CreateFileStorage(ctx,FILE_TYPE_LOAD,s1,&(result->server_file));
- }
- else
- reject_fd = edg_wll_CreateFileStorage(ctx,FILE_TYPE_LOAD,NULL,&(result->server_file));
- if ( reject_fd == -1 )
- goto cycle_clean;
- printf("New reject file %s created\n", result->server_file);
- free(s1);
- }
- /* Save the line into "reject_file"
- */
- while (total != len) {
- written = write(reject_fd, line+total, len-total);
- if (written < 0 && errno != EAGAIN) {
- edg_wll_SetError(ctx, errno, "writing load reject file");
- free(line);
- break;
- }
- total += written;
- }
- write(reject_fd,"\n",1);
- }
- else
- {
- result->to = event->any.arrived.tv_sec;
- if ( jobid )
- {
- char *md5_jobid = edg_wlc_JobIdGetUnique(jobid);
-
- if ( strcmp(md5_jobid, edg_wlc_JobIdGetUnique(event->any.jobId)) )
- {
- edg_wll_JobStat st;
-
- edg_wll_JobStatus(ctx, jobid, 0, &st);
- edg_wll_FreeStatus(&st);
-
- edg_wlc_JobIdFree(jobid);
- edg_wlc_JobIdDup(event->any.jobId, &jobid);
- }
- free(md5_jobid);
- }
- else
- edg_wlc_JobIdDup(event->any.jobId, &jobid);
- }
-
-
-cycle_clean:
- ctx->event_load = 0;
- edg_wll_FreeEvent(event);
- }
-
- if ( jobid )
- {
- edg_wll_JobStat st;
-
- edg_wll_JobStatus(ctx, jobid, 0, &st);
- edg_wll_FreeStatus(&st);
- edg_wlc_JobIdFree(jobid);
- }
-
- if ( reject_fd != -1 )
- close(reject_fd);
-
- if (edg_wll_Commit(ctx) != 0)
- return edg_wll_Error(ctx, NULL, NULL);
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-#define BUFFSZ 1024
-
-static int read_line(char **buff, size_t *maxsize, int fd)
-{
- int ct, i;
- void *tmp;
-
-
- if ( *buff == NULL )
- {
- *buff = malloc(BUFFSZ);
- if ( *buff == NULL )
- return -1;
- *maxsize = BUFFSZ;
- }
-
- i = 0;
- while ( 1 )
- {
- if (i >= *maxsize) {
- (*maxsize) *= 2;
- if ((tmp = realloc(*buff, *maxsize)) == NULL) return -1;
- *buff = (char *)tmp;
- }
- if ( (ct = read(fd, (*buff)+i, 1)) == -1 )
- return -1;
-
- if ( ct == 0 )
- return 0;
-
- if ( (*buff)[i] == '\n' )
- {
- (*buff)[i--] = '\0';
- while ( (i != -1) && isspace((*buff)[i]) ) i--;
- if ( i == -1 )
- {
- /** empty line
- */
- i = 0;
- continue;
- }
- else
- return 1;
- }
-
- i++;
- }
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <unistd.h>
-#include <sys/ipc.h>
-#include <sys/sem.h>
-#include <errno.h>
-
-#include "glite/wmsutils/jobid/cjobid.h"
-#include "glite/lb/context-int.h"
-#include "lock.h"
-
-extern int debug;
-
-int edg_wll_JobSemaphore(const edg_wll_Context ctx, const edg_wlc_JobId job)
-{
- char *un = edg_wlc_JobIdGetUnique(job);
- int n,i;
- static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
-
-
- if (!un) {
- edg_wll_SetError(ctx,EINVAL,"jobid");
- return -1;
- }
-
- for (n=0; n<sizeof b64 && b64[n] != un[0]; n++);
- for (i=0; i<sizeof b64 && b64[i] != un[1]; i++);
- n += i<<6;
-
- free(un);
- return(n % ctx->semaphores);
-}
-
-int edg_wll_LockUnlockJob(const edg_wll_Context ctx,const edg_wlc_JobId job,int lock)
-{
- struct sembuf s;
- int n;
-
-
- if ((n=edg_wll_JobSemaphore(ctx, job)) == -1) return edg_wll_Error(ctx,NULL,NULL);
-
- if (debug) fprintf(stderr,"[%d] try semop(%d,%d) \n",getpid(),n,lock);
-
- s.sem_num = n;
- s.sem_op = lock;
- s.sem_flg = SEM_UNDO;
-
- if (semop(ctx->semset,&s,1)) {
- if (debug) fprintf(stderr,"[%d] failed semop(%d,%d) \n",getpid(),n,lock);
- return edg_wll_SetError(ctx,errno,"edg_wll_LockUnlockJob()");
- }
-
- if (debug) fprintf(stderr,"[%d] got semop(%d,%d) \n",getpid(),n,lock);
- return edg_wll_ResetError(ctx);
-}
+++ /dev/null
-#define edg_wll_LockJob(ctx,job) edg_wll_LockUnlockJob((ctx),(job),-1)
-#define edg_wll_UnlockJob(ctx,job) edg_wll_LockUnlockJob((ctx),(job),1)
-
-int edg_wll_LockUnlockJob(const edg_wll_Context,const edg_wlc_JobId,int);
-int edg_wll_JobSemaphore(const edg_wll_Context ctx, const edg_wlc_JobId job);
+++ /dev/null
-#ident "$Header$"
-
-#include <string.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <syslog.h>
-
-#include "glite/lb/producer.h"
-#include "glite/lb/consumer.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-
-#include "lbs_db.h"
-#include "lb_authz.h"
-#include "lb_xml_parse.h"
-#include "query.h"
-#include "il_notification.h"
-
-static int notif_match_conditions(edg_wll_Context,const edg_wll_JobStat *,const char *);
-static int notif_check_acl(edg_wll_Context,const edg_wll_JobStat *,const char *);
-
-int edg_wll_NotifExpired(edg_wll_Context,const char *);
-
-int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *stat)
-{
- edg_wll_NotifId nid = NULL;
- char *jobq,*ju = NULL,*jobc[5];
- edg_wll_Stmt jobs = NULL;
- int ret,i;
- time_t now = time(NULL);
-
- edg_wll_ResetError(ctx);
-
- if ( (ret = edg_wll_NotifIdCreate(ctx->srvName, ctx->srvPort, &nid)) )
- {
- edg_wll_SetError(ctx, ret, "edg_wll_NotifMatch()");
- goto err;
- }
- trio_asprintf(&jobq,
- "select distinct n.notifid,n.destination,n.valid,u.cert_subj,n.conditions "
- "from notif_jobs j,users u,notif_registrations n "
- "where j.notifid=n.notifid and n.userid=u.userid "
- " and (j.jobid = '%|Ss' or j.jobid = '%|Ss')",
- ju = edg_wlc_JobIdGetUnique(stat->jobId),NOTIF_ALL_JOBS);
-
- free(ju);
-
- if (edg_wll_ExecStmt(ctx,jobq,&jobs) < 0) goto err;
-
- while ((ret = edg_wll_FetchRow(jobs,jobc)) > 0) {
- if (now > edg_wll_DBToTime(jobc[2]))
- edg_wll_NotifExpired(ctx,jobc[0]);
- else if (notif_match_conditions(ctx,stat,jobc[4]) &&
- notif_check_acl(ctx,stat,jobc[3]))
- {
- char *dest, *aux;
- int port;
-
- fprintf(stderr,"NOTIFY: %s, job %s\n",jobc[0],
- ju = edg_wlc_JobIdGetUnique(stat->jobId));
- free(ju);
-
- dest = strdup(jobc[1]);
- if ( !(aux = strchr(dest, ':')) )
- {
- edg_wll_SetError(ctx, EINVAL, "Can't parse notification destination");
- free(dest);
- for (i=0; i<sizeof(jobc)/sizeof(jobc[0]); i++) free(jobc[i]);
- goto err;
- }
- *aux = 0;
- aux++;
- port = atoi(aux);
-
- if ( edg_wll_NotifIdSetUnique(&nid, jobc[0]) )
- {
- free(dest);
- goto err;
- }
- /* XXX: only temporary hack!!!
- */
- ctx->p_instance = strdup("");
- if ( edg_wll_NotifJobStatus(ctx, nid, dest, port, jobc[3], *stat) )
- {
- free(dest);
- for (i=0; i<sizeof(jobc)/sizeof(jobc[0]); i++) free(jobc[i]);
- goto err;
- }
- free(dest);
- }
-
- for (i=0; i<sizeof(jobc)/sizeof(jobc[0]); i++) free(jobc[i]);
- }
- if (ret < 0) goto err;
-
-err:
- if ( nid ) edg_wll_NotifIdFree(nid);
- free(jobq);
- edg_wll_FreeStmt(&jobs);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-int edg_wll_NotifExpired(edg_wll_Context ctx,const char *notif)
-{
- /* TODO */
- return 0;
-}
-
-
-static int notif_match_conditions(edg_wll_Context ctx,const edg_wll_JobStat *stat,const char *cond)
-{
- edg_wll_QueryRec **c,**p;
- int match,i;
-
- if (!cond) return 1;
-
- if (parseJobQueryRec(ctx,cond,strlen(cond),&c)) {
- fputs("notif_match_conditions(): parseJobQueryRec failed\n",stderr);
- syslog(LOG_ERR,"notif_match_conditions(): parseJobQueryRec failed");
- return 1;
- }
-
- match = match_status(ctx,stat,(const edg_wll_QueryRec **) c);
- if ( c )
- {
- for (p = c; *p; p++) {
- for (i=0; (*p)[i].attr; i++)
- edg_wll_QueryRecFree((*p)+i);
- free(*p);
- }
- free(c);
- }
- return match;
-}
-
-/* FIXME: does not favour any VOMS information in ACL
- * effective VOMS groups of the recipient are not available here, should be
- * probably stored along with the registration.
- */
-static int notif_check_acl(edg_wll_Context ctx,const edg_wll_JobStat *stat,const char *recip)
-{
- edg_wll_Acl acl = calloc(1,sizeof *acl);
-/* XXX: NO_GACL GACLacl *gacl; */
- void *gacl;
- int ret;
-
- edg_wll_ResetError(ctx);
- if (ctx->noAuth || strcmp(stat->owner,recip) == 0) return 1;
-
- ret = edg_wll_DecodeACL(stat->acl,&gacl);
- if (ret) {
- edg_wll_SetError(ctx,EINVAL,"decoding ACL");
- return 0;
- }
-
- acl->string = stat->acl;
- acl->value = gacl;
-
- ret = edg_wll_CheckACL(ctx, acl, EDG_WLL_PERM_READ);
-
- acl->string = NULL;
- edg_wll_FreeAcl(acl);
-
- return !ret;
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <string.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "glite/wmsutils/jobid/strmd5.h"
-#include "glite/lb/trio.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/xml_parse.h"
-#include "glite/lb/notification.h"
-#include "il_notification.h"
-#include "lbs_db.h"
-#include "query.h"
-
-
-static char *get_user(edg_wll_Context ctx, int create);
-static int check_notif_request(edg_wll_Context, const edg_wll_NotifId, char **);
-static int split_cond_list(edg_wll_Context, edg_wll_QueryRec const * const *,
- edg_wll_QueryRec ***, char ***);
-static int update_notif(edg_wll_Context, const edg_wll_NotifId,
- const char *, const char *, const char *);
-
-
-int edg_wll_NotifNewServer(
- edg_wll_Context ctx,
- edg_wll_QueryRec const * const *conditions,
- char const *address_override,
- const edg_wll_NotifId nid,
- time_t *valid)
-{
- int i;
- char *q = NULL,
- *nid_s = NULL,
- *time_s = NULL,
- *addr_s = NULL,
- *xml_conds = NULL,
- *owner = NULL,
- **jobs = NULL;
- edg_wll_QueryRec **nconds = NULL;
-
-
- /* Format notification ID
- */
- if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
- goto cleanup;
-
- /* Get notification owner
- */
- if ( !(owner = get_user(ctx, 1)) )
- goto cleanup;
-
- /* Format conditions
- * - separate all jobids
- * - format new condition list without jobids
- */
- if ( split_cond_list(ctx, conditions, &nconds, &jobs) )
- goto cleanup;
-
- /*
- * encode new cond. list into a XML string
- */
- if ( edg_wll_JobQueryRecToXML(ctx, (edg_wll_QueryRec const * const *) nconds, &xml_conds) )
- {
- /* XXX: edg_wll_JobQueryRecToXML() do not set errors in context!
- * can't get propper error number :(
- */
- edg_wll_SetError(ctx, errno, "Can't encode data into xml");
- goto cleanup;
- }
-
- /* Format time of validity
- */
- *valid = time(NULL);
- if ( ctx->peerProxyValidity
- && (ctx->peerProxyValidity - *valid) < ctx->notifDuration )
- *valid = ctx->peerProxyValidity;
- else
- *valid += ctx->notifDuration;
-
- if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) )
- {
- edg_wll_SetError(ctx, errno, NULL);
- goto cleanup;
- }
-
- /* Format the address
- */
- if ( address_override )
- {
- char *aux;
-
- if ( !(aux = strchr(address_override, ':')) )
- {
- edg_wll_SetError(ctx, EINVAL, "Addres overrirde not in format host:port");
- goto cleanup;
- }
- if ( !strncmp(address_override, "0.0.0.0", aux-address_override) )
- trio_asprintf(&addr_s, "%s:%s", ctx->connections->serverConnection->peerName, aux+1);
- }
-
- /* Format DB insert statement
- */
- trio_asprintf(&q,
- "insert into notif_registrations(notifid,destination,valid,userid,conditions) "
- "values ('%|Ss','%|Ss',%s,'%|Ss', '<and>%|Ss</and>')",
- nid_s, addr_s? addr_s: address_override, time_s, owner, xml_conds);
-
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
- goto cleanup;
-
- if (jobs) for ( i = 0; jobs[i]; i++ )
- {
- free(q);
- trio_asprintf(&q,
- "insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')",
- nid_s, jobs[i]);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
- {
- /* XXX: Remove uncoplete registration?
- * Which error has to be returned?
- */
- free(q);
- trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, q, NULL);
- free(q);
- trio_asprintf(&q, "delete from notif_registrations where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, q, NULL);
- goto cleanup;
- }
- }
- else {
- trio_asprintf(&q,"insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')",
- nid_s,NOTIF_ALL_JOBS);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 ) goto cleanup;
-
- }
-
-
-cleanup:
- if ( q ) free(q);
- if ( nid_s ) free(nid_s);
- if ( time_s ) free(time_s);
- if ( addr_s ) free(addr_s);
- if ( xml_conds ) free(xml_conds);
- if ( owner ) free(owner);
- if ( jobs )
- {
- for ( i = 0; jobs[i]; i++ )
- free(jobs[i]);
- free(jobs);
- }
- if ( nconds ) free(nconds);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-int edg_wll_NotifBindServer(
- edg_wll_Context ctx,
- const edg_wll_NotifId nid,
- const char *address_override,
- time_t *valid)
-{
- char *time_s = NULL,
- *addr_s = NULL;
-
-
- if ( !address_override )
- {
- edg_wll_SetError(ctx, EINVAL, "Address parameter not given");
- goto cleanup;
- }
-
- if ( check_notif_request(ctx, nid, NULL) )
- goto cleanup;
-
- /* Format time of validity
- */
- *valid = time(NULL);
- if ( ctx->peerProxyValidity
- && (ctx->peerProxyValidity - *valid) < ctx->notifDuration )
- *valid = ctx->peerProxyValidity;
- else
- *valid += ctx->notifDuration;
-
- if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) )
- {
- edg_wll_SetError(ctx, errno, "Formating validity time");
- goto cleanup;
- }
-
- /* Format the address
- */
- if ( address_override )
- {
- char *aux;
-
- if ( !(aux = strchr(address_override, ':')) )
- {
- edg_wll_SetError(ctx, EINVAL, "Addres overrirde not in format host:port");
- goto cleanup;
- }
- if ( !strncmp(address_override, "0.0.0.0", aux-address_override) )
- trio_asprintf(&addr_s, "%s:%s", ctx->connections->serverConnection->peerName, aux+1);
- }
-
-
- update_notif(ctx, nid, NULL, addr_s? addr_s: address_override, (const char *)(time_s));
-
-cleanup:
- if ( time_s ) free(time_s);
- if ( addr_s ) free(addr_s);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-int edg_wll_NotifChangeServer(
- edg_wll_Context ctx,
- const edg_wll_NotifId nid,
- edg_wll_QueryRec const * const *conditions,
- edg_wll_NotifChangeOp op)
-{
- int i;
- char *q = NULL,
- *nid_s = NULL,
- *xml_conds = NULL,
- **jobs = NULL;
- edg_wll_QueryRec **nconds = NULL;
-
-
- /* Format notification ID
- */
- if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
- goto cleanup;
-
- if ( check_notif_request(ctx, nid, NULL) )
- goto cleanup;
-
- switch ( op )
- {
- case EDG_WLL_NOTIF_REPLACE:
- /* Format conditions
- * - separate all jobids
- * - format new condition list without jobids
- */
- if ( split_cond_list(ctx, conditions, &nconds, &jobs) )
- goto cleanup;
-
- /*
- * encode new cond. list into a XML string
- */
- if ( edg_wll_JobQueryRecToXML(ctx, (edg_wll_QueryRec const * const *) nconds, &xml_conds) )
- {
- /* XXX: edg_wll_JobQueryRecToXML() do not set errors in context!
- * can't get propper error number :(
- */
- edg_wll_SetError(ctx, errno, "Can't encode data into xml");
- goto cleanup;
- }
-
- /* Format DB insert statement
- */
- if ( update_notif(ctx, nid, xml_conds, NULL, NULL) )
- goto cleanup;
-
- if ( jobs )
- {
- /* Format DB insert statement
- */
- trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
- goto cleanup;
-
- for ( i = 0; jobs[i]; i++ )
- {
- free(q);
- trio_asprintf(&q,
- "insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')",
- nid_s, jobs[i]);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
- {
- /* XXX: Remove uncoplete registration?
- * Which error has to be returned?
- */
- free(q);
- trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, q, NULL);
- free(q);
- trio_asprintf(&q,"delete from notif_registrations where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, q, NULL);
- goto cleanup;
- }
- }
- }
- break;
-
- case EDG_WLL_NOTIF_ADD:
- break;
- case EDG_WLL_NOTIF_REMOVE:
- break;
- default:
- break;
- }
-
-cleanup:
- if ( q ) free(q);
- if ( xml_conds ) free(xml_conds);
- if ( nid_s ) free(nid_s);
- if ( jobs )
- {
- for ( i = 0; jobs[i]; i++ )
- free(jobs[i]);
- free(jobs);
- }
- if ( nconds ) free(nconds);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-int edg_wll_NotifRefreshServer(
- edg_wll_Context ctx,
- const edg_wll_NotifId nid,
- time_t *valid)
-{
- char *time_s = NULL;
-
-
- if ( check_notif_request(ctx, nid, NULL) )
- goto cleanup;
-
- /* Format time of validity
- */
- *valid = time(NULL);
- if ( ctx->peerProxyValidity
- && (ctx->peerProxyValidity - *valid) < ctx->notifDuration )
- *valid = ctx->peerProxyValidity;
- else
- *valid += ctx->notifDuration;
-
- if ( !(time_s = strdup(edg_wll_TimeToDB(*valid))) )
- {
- edg_wll_SetError(ctx, errno, "Formating validity time");
- goto cleanup;
- }
-
- update_notif(ctx, nid, NULL, NULL, time_s);
-
-cleanup:
- if ( time_s ) free(time_s);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-int edg_wll_NotifDropServer(
- edg_wll_Context ctx,
- edg_wll_NotifId *nid)
-{
- char *nid_s = NULL,
- *stmt = NULL;
- int ret;
-
-
- if ( check_notif_request(ctx, nid, NULL) )
- goto cleanup;
-
- if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
- goto cleanup;
-
- trio_asprintf(&stmt, "delete from notif_registrations where notifid='%|Ss'", nid_s);
- if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 )
- goto cleanup;
- free(stmt);
- trio_asprintf(&stmt, "delete from notif_jobs where notifid='%|Ss'", nid_s);
- edg_wll_ExecStmt(ctx, stmt, NULL);
- edg_wll_NotifCancelRegId(ctx, nid);
-
-cleanup:
- if ( nid_s ) free(nid_s);
- if ( stmt ) free(stmt);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-static char *get_user(edg_wll_Context ctx, int create)
-{
- edg_wll_Stmt stmt = NULL;
- char *userid = NULL,
- *q = NULL;
- int ret;
-
-
- if ( !ctx->peerName )
- {
- edg_wll_SetError(ctx, EPERM, "Annonymous access not allowed");
- goto cleanup;
- }
- trio_asprintf(&q, "select userid from users where cert_subj='%|Ss'", ctx->peerName);
- if ( edg_wll_ExecStmt(ctx, q, &stmt) < 0 )
- goto cleanup;
-
- /* returned value:
- * 0 no user find - continue only when 'create' parameter is set
- * >0 user found - return selected value
- * <0 SQL error
- */
- if ( ((ret = edg_wll_FetchRow(stmt, &userid)) != 0) || !create )
- goto cleanup;
-
- if ( !(userid = strdup(strmd5(ctx->peerName, NULL))) )
- {
- edg_wll_SetError(ctx, errno, "Creating user ID");
- goto cleanup;
- }
- free(q);
- trio_asprintf(&q, "insert into users(userid,cert_subj) values ('%|Ss','%|Ss')",
- userid, ctx->peerName);
- if ( edg_wll_ExecStmt(ctx, q, NULL) < 0 )
- {
- if ( edg_wll_Error(ctx,NULL,NULL) != EEXIST )
- {
- free(userid);
- userid = NULL;
- }
- else
- edg_wll_ResetError(ctx);
- }
-
-cleanup:
- if ( q ) free(q);
- if ( stmt ) edg_wll_FreeStmt(&stmt);
-
- return userid;
-}
-
-
-static int check_notif_request(
- edg_wll_Context ctx,
- const edg_wll_NotifId nid,
- char **owner)
-{
- char *nid_s = NULL,
- *stmt, *user;
- int ret;
-
-
- if ( !(user = get_user(ctx, 0)) )
- {
- if ( !edg_wll_Error(ctx, NULL, NULL) )
- edg_wll_SetError(ctx, EPERM, "Unknown user");
-
- return edg_wll_Error(ctx, NULL, NULL);
- }
-
- if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
- goto cleanup;
-
- trio_asprintf(&stmt,
- "select notifid from notif_registrations "
- "where notifid='%|Ss' and userid='%|Ss'",
- nid_s, user);
-
- if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 )
- goto cleanup;
- if ( ret == 0 )
- {
- free(stmt);
- trio_asprintf(&stmt,
- "select notifid from notif_registrations where notifid='%|Ss'", nid_s);
- ret = edg_wll_ExecStmt(ctx, stmt, NULL);
- if ( ret == 0 )
- edg_wll_SetError(ctx, ENOENT, "Unknown notification ID");
- else if ( ret > 0 )
- edg_wll_SetError(ctx, EPERM, "Only owner could access the notification");
- }
-
-cleanup:
- if ( !edg_wll_Error(ctx, NULL, NULL) && owner )
- *owner = user;
- else
- free(user);
- if ( nid_s ) free(nid_s);
- if ( stmt ) free(stmt);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
- /* Format conditions
- * - first of all separate all jobids
- * - then format new condition list without jobids and encode it into an XML string
- */
-static int split_cond_list(
- edg_wll_Context ctx,
- edg_wll_QueryRec const * const *conditions,
- edg_wll_QueryRec ***nconds_out,
- char ***jobs_out)
-{
- edg_wll_QueryRec **nconds = NULL;
- char **jobs = NULL;
- int i, j, jobs_ct, nconds_ct;
-
-
- if ( !conditions || !conditions[0] ) {
- if (ctx->noAuth) nconds_ct = jobs_ct = 0;
- else return edg_wll_SetError(ctx, EINVAL, "Empty condition list");
- }
- else for ( nconds_ct = jobs_ct = i = 0; conditions[i]; i++ ) {
- if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID )
- nconds_ct++;
- for ( j = 0; conditions[i][j].attr; j++ )
- if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID )
- jobs_ct++;
- }
-
- if ( jobs_out && jobs_ct )
- if ( !(jobs = calloc(jobs_ct+1, sizeof(char *))) )
- {
- edg_wll_SetError(ctx, errno, NULL);
- goto cleanup;
- }
-
- if ( nconds_out && nconds_ct )
- if ( !(nconds = calloc(nconds_ct+1, sizeof(edg_wll_QueryRec *))) )
- {
- edg_wll_SetError(ctx, errno, NULL);
- goto cleanup;
- }
-
- if ( jobs ) for ( jobs_ct = i = 0; conditions[i]; i++ )
- for ( j = 0; conditions[i][j].attr; j++ )
- if ( conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID )
- if ( !(jobs[jobs_ct++] = edg_wlc_JobIdGetUnique(conditions[i][j].value.j)) )
- {
- edg_wll_SetError(ctx, errno, NULL);
- goto cleanup;
- }
-
- if ( nconds ) for ( nconds_ct = i = 0; conditions[i]; i++ )
- if ( conditions[i][0].attr && conditions[i][0].attr != EDG_WLL_QUERY_ATTR_JOBID )
- /* !!! DO NOT DEALLOCATE this arrays (it is not neccessary to allocate new
- * mem - it's used only once and only for xml parsing
- */
- nconds[nconds_ct++] = (edg_wll_QueryRec *) (conditions[i]);
-
- if ( jobs_out ) { *jobs_out = jobs; jobs = NULL; }
- if ( nconds_out ) { *nconds_out = nconds; nconds = NULL; }
-
-cleanup:
- if ( nconds ) free(nconds);
- if ( jobs )
- {
- for ( i = 0; jobs[i]; i++ )
- free(jobs[i]);
- free(jobs);
- }
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
-
-
-static int update_notif(
- edg_wll_Context ctx,
- const edg_wll_NotifId nid,
- const char *conds,
- const char *dest,
- const char *valid)
-{
- char *nid_s = NULL,
- *host = NULL,
- *stmt, *aux;
- int ret, port;
-
-
- if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) )
- goto cleanup;
-
- /* Format SQL update string
- * (Only the owner could update the notification registration)
- */
- if ( !(stmt = strdup("update notif_registrations set")) )
- {
- edg_wll_SetError(ctx, errno, "updating notification records");
- goto cleanup;
- }
- if ( dest )
- {
- host = strchr(dest, ':');
- port = atoi(host+1);
- if ( !(host = strndup(dest, host-dest)) )
- {
- edg_wll_SetError(ctx, errno, "updating notification records");
- goto cleanup;
- }
- trio_asprintf(&aux, "%s destination='%|Ss'", stmt, dest);
- free(stmt);
- stmt = aux;
- }
- if ( valid )
- {
- trio_asprintf(&aux, "%s %svalid=%s", stmt, dest? ",": "", valid);
- free(stmt);
- stmt = aux;
- }
- if ( conds )
- {
- trio_asprintf(&aux, "%s %sconditions='<and>%|Ss</and>'",
- stmt, (dest||valid)? ",": "", conds);
- free(stmt);
- stmt = aux;
- }
- trio_asprintf(&aux, "%s where notifid='%|Ss'", stmt, nid_s);
- free(stmt);
- stmt = aux;
-
- if ( (ret = edg_wll_ExecStmt(ctx, stmt, NULL)) < 0 )
- goto cleanup;
- if ( ret == 0 )
- {
- free(stmt);
- trio_asprintf(&stmt,
- "select notifid from notif_registrations where notifid='%|Ss'", nid_s);
- ret = edg_wll_ExecStmt(ctx, stmt, NULL);
- if ( ret == 0 )
- edg_wll_SetError(ctx, ENOENT, "Unknown notification ID");
- /*
- * XXX: Be happy?
- * May be: Rows matched: 1 Changed: 0 Warnings: 0 :-)
- else if ( ret > 0 )
- edg_wll_SetError(ctx, EPERM, "Updating notification records");
- */
- }
-
- if ( host ) {
- printf("edg_wll_NotifChangeDestination(ctx, %s, %s, %d)\n",
- nid_s? nid_s: "nid", host, port);
- if ( edg_wll_NotifChangeDestination(ctx, nid, host, port) ) {
- char *errt, *errd;
-
- edg_wll_Error(ctx, &errt, &errd);
- printf("edg_wll_NotifChangeDestination(): %s (%s)\n", errt, errd);
- free(errt);
- free(errd);
- }
- }
-
-
-cleanup:
- if ( nid_s ) free(nid_s);
- if ( stmt ) free(stmt);
- if ( host ) free(host);
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <stdlib.h>
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/context-int.h"
-
-#include "lbs_db.h"
-
-edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs)
-{
- return edg_wll_DBConnect(ctx,cs) ? edg_wll_Error(ctx,NULL,NULL) : 0;
-}
-
-edg_wll_ErrorCode edg_wll_Close(edg_wll_Context ctx)
-{
- return edg_wll_ResetError(ctx);
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <syslog.h>
-
-#include "glite/lb/producer.h"
-#include "glite/lb/context-int.h"
-
-#include "jobstat.h"
-#include "lock.h"
-
-/* TBD: share in whole logging or workload */
-#ifdef __GNUC__
-#define UNUSED_VAR __attribute__((unused))
-#else
-#define UNUSED_VAR
-#endif
-
-static int processEvent_glite(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring);
-
-int processEvent(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring)
-{
- if (js->pub.jobtype == -1 && e->type == EDG_WLL_EVENT_REGJOB)
- switch (e->regJob.jobtype) {
- case EDG_WLL_REGJOB_SIMPLE:
- js->pub.jobtype = EDG_WLL_STAT_SIMPLE;
- break;
- case EDG_WLL_REGJOB_DAG:
- case EDG_WLL_REGJOB_PARTITIONABLE:
- case EDG_WLL_REGJOB_PARTITIONED:
- js->pub.jobtype = EDG_WLL_STAT_DAG;
- break;
- case EDG_WLL_REGJOB_COLLECTION:
- js->pub.jobtype = EDG_WLL_STAT_COLLECTION;
- break;
- case EDG_WLL_REGJOB_PBS:
- js->pub.jobtype = EDG_WLL_STAT_PBS;
- break;
- case EDG_WLL_REGJOB_CONDOR:
- js->pub.jobtype = EDG_WLL_STAT_CONDOR;
- break;
- default:
- asprintf(errstring,"unknown job type %d in registration",e->regJob.jobtype);
- return RET_FAIL;
- }
-
- switch (js->pub.jobtype) {
- case EDG_WLL_STAT_SIMPLE:
- case EDG_WLL_STAT_DAG:
- case EDG_WLL_STAT_COLLECTION:
- return processEvent_glite(js,e,ev_seq,strict,errstring);
- case EDG_WLL_STAT_PBS:
- return processEvent_PBS(js,e,ev_seq,strict,errstring);
- case EDG_WLL_STAT_CONDOR:
- return processEvent_Condor(js,e,ev_seq,strict,errstring);
- case -1: return RET_UNREG;
- default:
- asprintf(errstring,"undefined job type %d",js->pub.jobtype);
- return RET_FAIL;
- }
-}
-
-#define rep(a,b) { free(a); a = (b == NULL) ? NULL : strdup(b); }
-
-static void free_stringlist(char ***lptr)
-{
- char **itptr;
- int i;
-
- if (*lptr) {
- for (i = 0, itptr = *lptr; itptr[i] != NULL; i++)
- free(itptr[i]);
- free(itptr);
- *lptr = NULL;
- }
-}
-
-static int add_taglist(edg_wll_TagValue **lptr, const char *new_item, const char *new_item2)
-{
- edg_wll_TagValue *itptr;
- int i;
-
- if (*lptr == NULL) {
- itptr = (edg_wll_TagValue *) calloc(2,sizeof(edg_wll_TagValue));
- itptr[0].tag = strdup(new_item);
- itptr[0].value = strdup(new_item2);
- *lptr = itptr;
- return 1;
- } else {
- for (i = 0, itptr = *lptr; itptr[i].tag != NULL; i++)
- if ( !strcasecmp(itptr[i].tag, new_item) )
- {
- free(itptr[i].value);
- itptr[i].value = strdup(new_item2);
- return 1;
- }
- itptr = (edg_wll_TagValue *) realloc(*lptr, (i+2)*sizeof(edg_wll_TagValue));
- if (itptr != NULL) {
- itptr[i].tag = strdup(new_item);
- itptr[i].value = strdup(new_item2);
- itptr[i+1].tag = NULL;
- itptr[i+1].value = NULL;
- *lptr = itptr;
- return 1;
- } else {
- return 0;
- }
- }
-}
-
-
-static void update_branch_state(char *b, char *d, char *c, char *j, branch_state **bs)
-{
- int i = 0, branch;
-
-
- if (!b)
- return;
- else
- branch = component_seqcode(b, EDG_WLL_SOURCE_WORKLOAD_MANAGER);
-
- if (*bs != NULL) {
- while ((*bs)[i].branch) {
- if (branch == (*bs)[i].branch) {
- if (d) rep((*bs)[i].destination, d);
- if (c) rep((*bs)[i].ce_node, c);
- if (j) rep((*bs)[i].jdl, j);
-
- return;
- }
- i++;
- }
- }
-
- *bs = (branch_state *) realloc(*bs, (i+2)*sizeof(branch_state));
- memset(&((*bs)[i]), 0, 2*sizeof(branch_state));
-
- (*bs)[i].branch = branch;
- rep((*bs)[i].destination, d);
- rep((*bs)[i].ce_node, c);
- rep((*bs)[i].jdl, j);
-}
-
-
-static void free_branch_state(branch_state **bs)
-{
- int i = 0;
-
- if (*bs == NULL) return;
-
- while ((*bs)[i].branch) {
- free((*bs)[i].destination);
- free((*bs)[i].ce_node);
- free((*bs)[i].jdl);
- i++;
- }
- free(*bs);
- *bs = NULL;
-}
-
-static int compare_branch_states(const void *a, const void *b)
-{
- branch_state *c = (branch_state *) a;
- branch_state *d = (branch_state *) b;
-
- if (c->branch < d->branch) return -1;
- if (c->branch == d->branch) return 0;
- /* avoid warning: if (c->branch > d->branch) */ return 1;
-}
-
-static void load_branch_state(intJobStat *js)
-{
- int i, j, branch;
-
-
- if ( (!js->branch_tag_seqcode) || (!js->branch_states) ) return;
-
- branch = component_seqcode(js->branch_tag_seqcode, EDG_WLL_SOURCE_WORKLOAD_MANAGER);
-
- // count elements
- i = 0;
- while (js->branch_states[i].branch) i++;
-
- // sort them
- qsort(js->branch_states, (size_t) i, sizeof(branch_state),
- compare_branch_states);
-
- // find row corresponding to ReallyRunning WM seq.code (aka branch)
- i = 0;
- while (js->branch_states[i].branch) {
- if (js->branch_states[i].branch == branch) break;
- i++;
- }
-
- // copy this and two before branches data to final state
- // (each field - dest,ce,jdl - comes from different event)
- // (and these events have most likely different WM seq.codes)
- // (even belonging into one logical branch)
- // (the newer the more important - so i-th element is copied as last)
- // (and may overwrite data from previous elements)
- for (j = i - 2; j <= i; j++) {
- if (j >= 0) {
- if (js->branch_states[j].destination)
- rep(js->pub.destination, js->branch_states[j].destination);
- if (js->branch_states[j].ce_node)
- rep(js->pub.ce_node, js->branch_states[j].ce_node);
- if (js->branch_states[j].jdl)
- rep(js->pub.matched_jdl, js->branch_states[j].jdl);
- }
- }
-}
-
-// clear branches (deep resub. or abort)
-static void reset_branch(intJobStat *js, edg_wll_Event *e)
-{
- js->resubmit_type = EDG_WLL_RESUBMISSION_WILLRESUB;
- free_stringlist(&js->pub.possible_destinations);
- free_stringlist(&js->pub.possible_ce_nodes);
- free_branch_state(&js->branch_states);
- js->pub.payload_running = 0;
- rep(js->branch_tag_seqcode, NULL);
- rep(js->deep_resubmit_seqcode, e->any.seqcode);
-}
-
-static char* location_string(const char *source, const char *host, const char *instance)
-{
- char *ret;
- asprintf(&ret, "%s/%s/%s", source, host, instance);
- return ret;
-}
-
-static int after_enter_wm(const char *es,const char *js)
-{
- return component_seqcode(es,EDG_WLL_SOURCE_NETWORK_SERVER) >
- component_seqcode(js,EDG_WLL_SOURCE_NETWORK_SERVER);
-}
-
-
-static int badEvent(intJobStat *js UNUSED_VAR, edg_wll_Event *e, int ev_seq UNUSED_VAR)
-{
- char *str;
-
- str = edg_wll_EventToString(e->any.type);
- fprintf(stderr, "edg_wll_JobStatus: bad event: type %d (%s)\n",
- e->any.type, (str == NULL) ? "unknown" : str);
- free(str);
- return RET_FATAL;
-}
-
-
-// (?) || (0 && 1) => true if (res == RET_OK)
-#define USABLE(res,strict) ((res) == RET_OK || ( (res) == RET_SOON && !strict))
-
-// (?) || (1 && 1) => always true
-#define USABLE_DATA(res,strict) ((res) == RET_OK || ( (res) != RET_FATAL && !strict))
-
-#define USABLE_BRANCH(fine_res) ((fine_res) != RET_TOOOLD && (fine_res) != RET_BADBRANCH)
-#define LRMS_STATE(state) ((state) == EDG_WLL_JOB_RUNNING || (state) == EDG_WLL_JOB_DONE)
-#define PARSABLE_SEQCODE(code) (component_seqcode((code),0) >= 0)
-
-static int processEvent_glite(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring)
-{
- edg_wll_JobStatCode old_state = js->pub.state;
- enum edg_wll_StatDone_code old_done_code = js->pub.done_code;
- edg_wll_JobStatCode new_state = EDG_WLL_JOB_UNKNOWN;
- int res = RET_OK,
- fine_res = RET_OK;
-
- int lm_favour_lrms = 0;
-
- if (old_state == EDG_WLL_JOB_ABORTED ||
- old_state == EDG_WLL_JOB_CANCELLED ||
- old_state == EDG_WLL_JOB_CLEARED) {
- res = RET_LATE;
- }
-
-/* new event coming from NS => forget about any resubmission loops */
- if (e->type != EDG_WLL_EVENT_CANCEL &&
- js->last_seqcode &&
- after_enter_wm(e->any.seqcode,js->last_seqcode))
- {
- rep(js->branch_tag_seqcode,NULL);
- rep(js->deep_resubmit_seqcode,NULL);
- rep(js->last_branch_seqcode,NULL);
- }
-
- if (js->deep_resubmit_seqcode &&
- before_deep_resubmission(e->any.seqcode, js->deep_resubmit_seqcode)) {
- res = RET_LATE;
- fine_res = RET_TOOOLD;
- }
- else if (js->branch_tag_seqcode) { // ReallyRunning ev. arrived
- if (same_branch(e->any.seqcode, js->branch_tag_seqcode)) {
- if ((js->last_branch_seqcode != NULL) &&
- edg_wll_compare_seq(e->any.seqcode, js->last_branch_seqcode) < 0) {
- res = RET_LATE;
- }
- fine_res = RET_GOODBRANCH;
- }
- else {
- res = RET_LATE;
- fine_res = RET_BADBRANCH;
- }
- }
- else if ((js->last_seqcode != NULL) &&
- edg_wll_compare_seq(e->any.seqcode, js->last_seqcode) < 0) {
- res = RET_LATE;
- }
-
-
- switch (e->any.type) {
- case EDG_WLL_EVENT_TRANSFER:
- if (e->transfer.result == EDG_WLL_TRANSFER_OK) {
- switch (e->transfer.source) {
- case EDG_WLL_SOURCE_USER_INTERFACE:
- new_state = EDG_WLL_JOB_WAITING; break;
- case EDG_WLL_SOURCE_JOB_SUBMISSION:
- /* if (LRMS_STATE(old_state)) res = RET_LATE; */
- new_state = EDG_WLL_JOB_READY; break;
- case EDG_WLL_SOURCE_LOG_MONITOR:
- if (LRMS_STATE(old_state)) {
- js->pub.stateEnterTimes[1 + EDG_WLL_JOB_SCHEDULED] =
- e->any.timestamp.tv_sec;
- res = RET_LATE;
- }
- new_state = EDG_WLL_JOB_SCHEDULED;
- lm_favour_lrms = 1;
- break;
- default:
- goto bad_event; break;
- }
- } else if (e->transfer.result == EDG_WLL_TRANSFER_FAIL) {
- /* transfer failed */
- switch (e->transfer.source) {
- case EDG_WLL_SOURCE_USER_INTERFACE:
- new_state = EDG_WLL_JOB_SUBMITTED; break;
- case EDG_WLL_SOURCE_JOB_SUBMISSION:
- if (LRMS_STATE(old_state)) res = RET_LATE;
- new_state = EDG_WLL_JOB_READY; break;
- case EDG_WLL_SOURCE_LOG_MONITOR:
- if (LRMS_STATE(old_state)) res = RET_LATE;
- new_state = EDG_WLL_JOB_READY; break;
- default:
- goto bad_event; break;
- }
- } else {
- /* e->transfer.result == EDG_WLL_TRANSFER_START */
- res = RET_IGNORE;
- }
- if (USABLE(res, strict)) {
- js->pub.state = new_state;
- rep(js->pub.reason, e->transfer.reason);
-
- free(js->pub.location);
- if (e->transfer.result == EDG_WLL_TRANSFER_OK) {
- js->pub.location = location_string(
- edg_wll_SourceToString(e->transfer.destination),
- e->transfer.dest_host,
- e->transfer.dest_instance);
- } else {
- js->pub.location = location_string(
- edg_wll_SourceToString(e->transfer.source),
- e->transfer.host,
- e->transfer.src_instance);
- }
- }
- if (USABLE_DATA(res, strict)) {
- switch (e->transfer.source) {
- case EDG_WLL_SOURCE_USER_INTERFACE:
- rep(js->pub.jdl, e->transfer.job); break;
- case EDG_WLL_SOURCE_JOB_SUBMISSION:
- rep(js->pub.condor_jdl, e->transfer.job); break;
- case EDG_WLL_SOURCE_LOG_MONITOR:
- rep(js->pub.rsl, e->transfer.job); break;
- default:
- goto bad_event; break;
-
- }
- }
- break;
- case EDG_WLL_EVENT_ACCEPTED:
- switch (e->accepted.source) {
- case EDG_WLL_SOURCE_NETWORK_SERVER:
- new_state = EDG_WLL_JOB_WAITING; break;
- case EDG_WLL_SOURCE_LOG_MONITOR:
- if (LRMS_STATE(old_state)) res = RET_LATE;
- new_state = EDG_WLL_JOB_READY;
- lm_favour_lrms = 1;
- break;
- case EDG_WLL_SOURCE_LRMS:
- new_state = EDG_WLL_JOB_SCHEDULED; break;
- default:
- goto bad_event; break;
- }
- if (USABLE(res, strict)) {
- js->pub.state = new_state;
- free(js->pub.location);
- js->pub.location = location_string(
- edg_wll_SourceToString(e->accepted.source),
- e->accepted.host,
- e->accepted.src_instance);
- }
- if (USABLE_DATA(res, strict)) {
- switch (e->accepted.source) {
- case EDG_WLL_SOURCE_NETWORK_SERVER:
- break; /* no WM id */
- case EDG_WLL_SOURCE_LOG_MONITOR:
- rep(js->pub.condorId, e->accepted.local_jobid); break;
- case EDG_WLL_SOURCE_LRMS:
- /* XXX localId */
- rep(js->pub.globusId, e->accepted.local_jobid); break;
- default:
- goto bad_event; break;
- }
- }
- break;
- case EDG_WLL_EVENT_REFUSED:
- switch (e->refused.source) {
- case EDG_WLL_SOURCE_NETWORK_SERVER:
- new_state = EDG_WLL_JOB_SUBMITTED; break;
- case EDG_WLL_SOURCE_LOG_MONITOR:
- new_state = EDG_WLL_JOB_READY; break;
- case EDG_WLL_SOURCE_LRMS:
- new_state = EDG_WLL_JOB_READY; break;
- default:
- goto bad_event; break;
- }
- if (USABLE(res, strict)) {
- js->pub.state = new_state;
- rep(js->pub.reason, e->refused.reason);
-
- free(js->pub.location);
- js->pub.location = location_string(
- edg_wll_SourceToString(e->refused.from),
- e->refused.from_host,
- e->refused.from_instance);
- }
- break;
- case EDG_WLL_EVENT_ENQUEUED:
- if (e->enQueued.result == EDG_WLL_ENQUEUED_OK) {
- switch (e->enQueued.source) {
- case EDG_WLL_SOURCE_NETWORK_SERVER:
- new_state = EDG_WLL_JOB_WAITING; break;
- case EDG_WLL_SOURCE_WORKLOAD_MANAGER:
- if (LRMS_STATE(old_state)) res = RET_LATE;
- update_branch_state(e->any.seqcode, NULL,
- NULL, e->enQueued.job, &js->branch_states);
- new_state = EDG_WLL_JOB_READY; break;
- case EDG_WLL_SOURCE_LOG_MONITOR:
- new_state = EDG_WLL_JOB_WAITING; break;
- default:
- goto bad_event; break;
- }
- } else if (e->enQueued.result == EDG_WLL_ENQUEUED_FAIL) {
- switch (e->enQueued.source) {
- case EDG_WLL_SOURCE_NETWORK_SERVER:
- new_state = EDG_WLL_JOB_WAITING; break;
- case EDG_WLL_SOURCE_WORKLOAD_MANAGER:
- new_state = EDG_WLL_JOB_WAITING; break;
- case EDG_WLL_SOURCE_LOG_MONITOR:
- new_state = old_state; break;
- default:
- goto bad_event; break;
- }
- } else {
- /* e->enQueued.result == EDG_WLL_ENQUEUED_START */
- res = RET_IGNORE;
- }
- if (USABLE(res, strict)) {
- js->pub.state = new_state;
- rep(js->pub.reason, e->enQueued.reason);
-
- free(js->pub.location);
- if (e->enQueued.result == EDG_WLL_ENQUEUED_OK) {
- js->pub.location = location_string(
- e->enQueued.queue,
- e->enQueued.host,
- e->enQueued.src_instance);
- if (e->enQueued.source == EDG_WLL_SOURCE_LOG_MONITOR)
- js->pub.resubmitted = 1;
- } else {
- js->pub.location = location_string(
- edg_wll_SourceToString(e->enQueued.source),
- e->enQueued.host,
- e->enQueued.src_instance);
- }
- }
- if (USABLE_DATA(res, strict)) {
- switch (e->enQueued.source) {
- case EDG_WLL_SOURCE_NETWORK_SERVER:
- rep(js->pub.jdl, e->enQueued.job); break;
- case EDG_WLL_SOURCE_WORKLOAD_MANAGER:
- if (USABLE_BRANCH(res)) {
- rep(js->pub.matched_jdl, e->enQueued.job);
- }
- break;
- case EDG_WLL_SOURCE_LOG_MONITOR:
- /* no interim JDL here */
- break;
- default:
- goto bad_event; break;
- }
- }
- break;
- case EDG_WLL_EVENT_DEQUEUED:
- switch (e->deQueued.source) {
- case EDG_WLL_SOURCE_WORKLOAD_MANAGER:
- new_state = EDG_WLL_JOB_WAITING; break;
- case EDG_WLL_SOURCE_JOB_SUBMISSION:
- if (LRMS_STATE(old_state)) res = RET_LATE;
- new_state = EDG_WLL_JOB_READY; break;
- default:
- goto bad_event; break;
- }
- if (USABLE(res, strict)) {
- js->pub.state = new_state;
- free(js->pub.location);
- js->pub.location = location_string(
- edg_wll_SourceToString(e->deQueued.source),
- e->deQueued.host,
- e->deQueued.src_instance);
- }
- if (USABLE_DATA(res, strict)) {
- /* no WM/JSS local jobid */
- }
- break;
- case EDG_WLL_EVENT_HELPERCALL:
- if (USABLE(res, strict)) {
- js->pub.state = EDG_WLL_JOB_WAITING;
- free(js->pub.location);
- js->pub.location = location_string(
- e->helperCall.helper_name,
- e->helperCall.host,
- e->helperCall.src_instance);
- /* roles and params used only for debugging */
- }
- break;
- case EDG_WLL_EVENT_HELPERRETURN:
- if (USABLE(res, strict)) {
- js->pub.state = EDG_WLL_JOB_WAITING;
- free(js->pub.location);
- js->pub.location = location_string(
- edg_wll_SourceToString(EDG_WLL_SOURCE_WORKLOAD_MANAGER),
- e->helperReturn.host,
- e->helperReturn.src_instance);
- /* roles and retvals used only for debugging */
- }
- break;
- case EDG_WLL_EVENT_RUNNING:
- if (USABLE(res, strict)) {
- js->pub.state = EDG_WLL_JOB_RUNNING;
- free(js->pub.location);
- js->pub.location = location_string(
- edg_wll_SourceToString(EDG_WLL_SOURCE_LRMS),
- "worknode",
- e->running.node);
- }
- if (USABLE_DATA(res, strict)) {
- if (USABLE_BRANCH(fine_res)) {
- rep(js->pub.ce_node, e->running.node);
- }
- /* why? if (e->any.source == EDG_WLL_SOURCE_LOG_MONITOR) { */
- if (e->running.node) {
- update_branch_state(e->any.seqcode, NULL,
- e->running.node, NULL, &js->branch_states);
- add_stringlist(&js->pub.possible_ce_nodes,
- e->running.node);
- }
- /* } */
- }
- break;
- case EDG_WLL_EVENT_REALLYRUNNING:
- /* consistence check -- should not receive two contradicting ReallyRunning's within single
- deep resub cycle */
- if (fine_res == RET_BADBRANCH) {
- syslog(LOG_ERR,"ReallyRunning on bad branch %s",
- e->any.source == EDG_WLL_SOURCE_LOG_MONITOR ? e->reallyRunning.wn_seq : e->any.seqcode);
- break;
- }
- /* select the branch unless TOOOLD, i.e. before deep resubmission */
- if (!(res == RET_LATE && fine_res == RET_TOOOLD)) {
- if (e->any.source == EDG_WLL_SOURCE_LRMS) {
- rep(js->branch_tag_seqcode, e->any.seqcode);
- if (res == RET_OK) {
- rep(js->last_branch_seqcode, e->any.seqcode);
- js->pub.state = EDG_WLL_JOB_RUNNING;
- }
- }
- if (e->any.source == EDG_WLL_SOURCE_LOG_MONITOR) {
- if (!js->branch_tag_seqcode) {
- if (PARSABLE_SEQCODE(e->reallyRunning.wn_seq)) {
- rep(js->branch_tag_seqcode, e->reallyRunning.wn_seq);
- } else
- goto bad_event;
- }
- if (!js->last_branch_seqcode) {
- if (PARSABLE_SEQCODE(e->reallyRunning.wn_seq)) {
- if (res == RET_OK) {
- rep(js->last_branch_seqcode, e->reallyRunning.wn_seq);
- js->pub.state = EDG_WLL_JOB_RUNNING;
- }
- } else
- goto bad_event;
- }
- }
-
- /* XXX: best effort -- if we are lucky, ReallyRunning is on the last shallow cycle,
- so we take in account events processed so far */
- if (res == RET_LATE && !js->last_branch_seqcode) {
- if (same_branch(js->last_seqcode,js->branch_tag_seqcode))
- rep(js->last_branch_seqcode,js->last_seqcode);
- }
-
- js->pub.payload_running = 1;
- load_branch_state(js);
- }
-#if 0
- if (USABLE_DATA(res, strict)) {
- js->pub.state = EDG_WLL_JOB_RUNNING;
- free(js->pub.location);
- js->pub.location = location_string(
- edg_wll_SourceToString(EDG_WLL_SOURCE_LRMS),
- "worknode",
- e->running.node);
- js->pub.payload_running = 1;
- if (e->any.source == EDG_WLL_SOURCE_LRMS) {
- rep(js->branch_tag_seqcode, e->any.seqcode);
- rep(js->last_branch_seqcode, e->any.seqcode);
- }
- if (e->any.source == EDG_WLL_SOURCE_LOG_MONITOR) {
- if (!js->branch_tag_seqcode) {
- if (PARSABLE_SEQCODE(e->reallyRunning.wn_seq)) {
- rep(js->branch_tag_seqcode, e->reallyRunning.wn_seq);
- } else
- goto bad_event;
- }
- if (!js->last_branch_seqcode) {
- if (PARSABLE_SEQCODE(e->reallyRunning.wn_seq)) {
- rep(js->last_branch_seqcode, e->reallyRunning.wn_seq);
- } else
- goto bad_event;
- }
- }
- load_branch_state(js);
- }
-#endif
- break;
- case EDG_WLL_EVENT_RESUBMISSION:
- if (USABLE(res, strict)) {
- if (e->resubmission.result == EDG_WLL_RESUBMISSION_WONTRESUB) {
- rep(js->pub.reason, e->resubmission.reason);
- }
- }
- if (USABLE_DATA(res, strict)) {
- if (e->resubmission.result == EDG_WLL_RESUBMISSION_WONTRESUB) {
- js->resubmit_type = EDG_WLL_RESUBMISSION_WONTRESUB;
- }
- else
- if (e->resubmission.result == EDG_WLL_RESUBMISSION_WILLRESUB &&
- e->any.source == EDG_WLL_SOURCE_WORKLOAD_MANAGER) {
- reset_branch(js, e);
- }
- else
- if (e->resubmission.result == EDG_WLL_RESUBMISSION_SHALLOW) {
- js->resubmit_type = EDG_WLL_RESUBMISSION_SHALLOW;
- // deep resubmit stays forever deadline for events
- // rep(js->deep_resubmit_seqcode, NULL);
- }
- }
- break;
- case EDG_WLL_EVENT_DONE:
- if (e->any.source == EDG_WLL_SOURCE_LRMS) {
- /* Done from JobWrapper is not sufficient for transition
- * to DONE state according its current definition */
- break;
- }
- if (USABLE(res, strict)) {
- js->pub.state = EDG_WLL_JOB_DONE;
- rep(js->pub.reason, e->done.reason);
- if (fine_res == RET_GOODBRANCH) {
- js->pub.payload_running = 0;
- }
- switch (e->done.status_code) {
- case EDG_WLL_DONE_CANCELLED:
- js->pub.state = EDG_WLL_JOB_CANCELLED;
- case EDG_WLL_DONE_OK:
- rep(js->pub.location, "none"); break;
- default:
- free(js->pub.location);
- js->pub.location = location_string(
- edg_wll_SourceToString(e->done.source),
- e->done.host,
- e->done.src_instance);
- }
- }
- if (USABLE_DATA(res, strict)) {
- switch (e->done.status_code) {
- case EDG_WLL_DONE_OK:
- js->pub.exit_code = e->done.exit_code;
- js->pub.done_code = EDG_WLL_STAT_OK; break;
- case EDG_WLL_DONE_CANCELLED:
- js->pub.exit_code = 0;
- js->pub.done_code = EDG_WLL_STAT_CANCELLED; break;
- case EDG_WLL_DONE_FAILED:
- js->pub.exit_code = 0;
- js->pub.done_code = EDG_WLL_STAT_FAILED; break;
- default:
- goto bad_event; break;
- }
- }
- break;
- case EDG_WLL_EVENT_CANCEL:
- if (fine_res != RET_BADBRANCH) {
- if (js->last_cancel_seqcode != NULL &&
- edg_wll_compare_seq(e->any.seqcode, js->last_cancel_seqcode) < 0) {
- res = RET_LATE;
- }
- }
- else {
- res = RET_LATE;
- }
- if (USABLE(res, strict)) {
- switch (e->cancel.status_code) {
- case EDG_WLL_CANCEL_REQ:
- js->pub.cancelling = 1; break;
- case EDG_WLL_CANCEL_DONE:
- js->pub.state = EDG_WLL_JOB_CANCELLED;
- rep(js->pub.reason, e->cancel.reason);
- rep(js->last_seqcode, e->any.seqcode);
- rep(js->pub.location, "none");
- /* fall though */
- case EDG_WLL_CANCEL_ABORT:
- js->pub.cancelling = 0; break;
- default:
- /* do nothing */
- break;
-
- }
- }
- if (USABLE_DATA(res, strict)) {
- rep(js->pub.cancelReason, e->cancel.reason);
- }
- break;
- case EDG_WLL_EVENT_ABORT:
- // XXX: accept Abort from WM in every case
- // setting res make USABLE macro true (awful !!)
- if (e->any.source == EDG_WLL_SOURCE_WORKLOAD_MANAGER) res = RET_OK;
- if (USABLE(res, strict)) {
- js->pub.state = EDG_WLL_JOB_ABORTED;
- rep(js->pub.reason, e->abort.reason);
- rep(js->pub.location, "none");
-
- reset_branch(js, e);
- }
- break;
-
- case EDG_WLL_EVENT_CLEAR:
- if (USABLE(res, strict)) {
- js->pub.state = EDG_WLL_JOB_CLEARED;
- rep(js->pub.location, "none");
- switch (e->clear.reason) {
- case EDG_WLL_CLEAR_USER:
- rep(js->pub.reason, "user retrieved output sandbox");
- break;
- case EDG_WLL_CLEAR_TIMEOUT:
- rep(js->pub.reason, "timed out, resource purge forced");
- break;
- case EDG_WLL_CLEAR_NOOUTPUT:
- rep(js->pub.reason, "no output was generated");
- break;
- default:
- goto bad_event; break;
-
- }
- }
- break;
- case EDG_WLL_EVENT_PURGE:
- /* ignore, meta-information only */
- break;
- case EDG_WLL_EVENT_MATCH:
- if (USABLE(res, strict)) {
- js->pub.state = EDG_WLL_JOB_WAITING;
- js->pub.location = location_string(
- edg_wll_SourceToString(EDG_WLL_SOURCE_WORKLOAD_MANAGER),
- e->match.host,
- e->match.src_instance);
- }
- if (USABLE_DATA(res, strict)) {
- if (USABLE_BRANCH(fine_res)) {
- rep(js->pub.destination, e->match.dest_id);
- }
- if (e->match.dest_id) {
- update_branch_state(e->any.seqcode, e->match.dest_id,
- NULL, NULL, &js->branch_states);
- add_stringlist(&js->pub.possible_destinations,
- e->match.dest_id);
- }
- }
- break;
- case EDG_WLL_EVENT_PENDING:
- if (USABLE(res, strict)) {
- js->pub.state = EDG_WLL_JOB_WAITING;
- rep(js->pub.reason, e->pending.reason);
- js->pub.location = location_string(
- edg_wll_SourceToString(EDG_WLL_SOURCE_WORKLOAD_MANAGER),
- e->match.host,
- e->match.src_instance);
- }
- break;
- case EDG_WLL_EVENT_REGJOB:
- if (USABLE(res, strict)) {
- js->pub.state = EDG_WLL_JOB_SUBMITTED;
- }
- if (USABLE_DATA(res, strict)) {
- rep(js->pub.jdl, e->regJob.jdl);
- edg_wlc_JobIdFree(js->pub.parent_job);
- edg_wlc_JobIdDup(e->regJob.parent,
- &js->pub.parent_job);
- rep(js->pub.network_server, e->regJob.ns);
- js->pub.children_num = e->regJob.nsubjobs;
- switch (e->regJob.jobtype) {
- case EDG_WLL_REGJOB_DAG:
- case EDG_WLL_REGJOB_PARTITIONED:
- js->pub.jobtype = EDG_WLL_STAT_DAG;
- js->pub.children_hist[EDG_WLL_JOB_UNKNOWN+1] = js->pub.children_num;
- break;
- case EDG_WLL_REGJOB_COLLECTION:
- js->pub.jobtype = EDG_WLL_STAT_COLLECTION;
- js->pub.children_hist[EDG_WLL_JOB_UNKNOWN+1] = js->pub.children_num;
- break;
- default:
- break;
- }
- rep(js->pub.seed, e->regJob.seed);
- }
- break;
- case EDG_WLL_EVENT_USERTAG:
- if (USABLE_DATA(res, strict)) {
- if (e->userTag.name != NULL && e->userTag.value != NULL) {
- add_taglist(&js->pub.user_tags,
- e->userTag.name, e->userTag.value);
- } else {
- goto bad_event;
- }
- }
- break;
- case EDG_WLL_EVENT_LISTENER:
- /* ignore, listener port is not part of job status */
- break;
- case EDG_WLL_EVENT_CURDESCR:
- case EDG_WLL_EVENT_CHKPT:
- case EDG_WLL_EVENT_CHANGEACL:
- /* ignore, only for event log */
- break;
- case EDG_WLL_EVENT_COLLECTIONSTATE:
- new_state = edg_wll_StringToStat(e->collectionState.state);
- if (USABLE(res, strict)) {
- js->pub.state = new_state;
- if (new_state == EDG_WLL_JOB_DONE)
- js->pub.done_code = e->collectionState.done_code;
- }
- break;
- default:
- goto bad_event;
- break;
- }
-
- if (USABLE(res,strict)) {
- js->pub.lastUpdateTime = e->any.timestamp;
- if (old_state != js->pub.state) {
- js->pub.stateEnterTime = js->pub.lastUpdateTime;
- js->pub.stateEnterTimes[1 + js->pub.state]
- = (int)js->pub.lastUpdateTime.tv_sec;
- }
- if (e->any.type == EDG_WLL_EVENT_CANCEL) {
- rep(js->last_cancel_seqcode, e->any.seqcode);
- } else {
-
-/* the first set of LM events (Accept, Transfer/* -> LRMS)
- should not should shift the state (to Ready, Scheduled) but NOT to
- update js->last_seqcode completely, in order not to block following
- LRMS events which are likely to arrive later but should still affect
- job state (as there may be no more LM events due to the Condor bug).
- However, don't ignore the incoming seqcode completely, to catch up
- with possibly delayed WM/JSS events */
-
- if (lm_favour_lrms) {
- free(js->last_seqcode);
- js->last_seqcode = set_component_seqcode(e->any.seqcode,EDG_WLL_SOURCE_LOG_MONITOR,0);
- }
- else rep(js->last_seqcode, e->any.seqcode);
- }
-
- if (fine_res == RET_GOODBRANCH) {
- rep(js->last_branch_seqcode, e->any.seqcode);
- }
- }
-
- if (USABLE_DATA(res,strict)) {
- if (e->any.source == EDG_WLL_SOURCE_NETWORK_SERVER &&
- js->pub.network_server == NULL) {
- char *inst;
- inst = e->any.src_instance;
- asprintf(&js->pub.network_server, "%s%s%s",
- e->any.host,
- inst != NULL ? ":" : " ",
- inst != NULL ? inst : "");
- }
- }
-
- return res;
-
-bad_event:
- badEvent(js,e,ev_seq);
- return RET_SUSPECT;
-}
-
-int add_stringlist(char ***lptr, const char *new_item)
-{
- char **itptr;
- int i;
-
- if (*lptr == NULL) {
- itptr = (char **) malloc(2*sizeof(char *));
- itptr[0] = strdup(new_item);
- itptr[1] = NULL;
- *lptr = itptr;
- return 1;
- } else {
- for (i = 0, itptr = *lptr; itptr[i] != NULL; i++);
- itptr = (char **) realloc(*lptr, (i+2)*sizeof(char *));
- if (itptr != NULL) {
- itptr[i] = strdup(new_item);
- itptr[i+1] = NULL;
- *lptr = itptr;
- return 1;
- } else {
- return 0;
- }
- }
-}
-
-void destroy_intJobStat_extension(intJobStat *p)
-{
- free(p->last_seqcode); p->last_seqcode = NULL;
- free(p->last_cancel_seqcode); p->last_cancel_seqcode = NULL;
- p->resubmit_type = EDG_WLL_RESUBMISSION_UNDEFINED;
-}
-
-void destroy_intJobStat(intJobStat *p)
-{
- edg_wll_FreeStatus(&p->pub);
- destroy_intJobStat_extension(p);
- memset(p, 0, sizeof(intJobStat));
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <syslog.h>
-
-#include "glite/lb/producer.h"
-#include "glite/lb/context-int.h"
-
-#include "jobstat.h"
-#include "lock.h"
-
-/* TBD: share in whole logging or workload */
-#ifdef __GNUC__
-#define UNUSED_VAR __attribute__((unused))
-#else
-#define UNUSED_VAR
-#endif
-
-// XXX: maybe not needed any more
-// if not, remove also last_condor_event_timestamp from intJobStat
-static int compare_timestamps(struct timeval a, struct timeval b)
-{
- if ( (a.tv_sec > b.tv_sec) ||
- ((a.tv_sec == b.tv_sec) && (a.tv_usec > b.tv_usec)) ) return 1;
- if ( (a.tv_sec < b.tv_sec) ||
- ((a.tv_sec == b.tv_sec) && (a.tv_usec < b.tv_usec)) ) return -1;
- return 0;
-}
-
-
-// XXX move this defines into some common place to be reusable
-#define USABLE(res) ((res) == RET_OK)
-#define USABLE_DATA(res) (1)
-#define rep(a,b) { free(a); a = (b == NULL) ? NULL : strdup(b); }
-#define rep_cond(a,b) { if (b) { free(a); a = strdup(b); } }
-
-int processEvent_Condor(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring)
-{
- edg_wll_JobStatCode old_state = js->pub.state;
- int res = RET_OK;
-
-
- if ((js->last_seqcode != NULL) &&
- (edg_wll_compare_condor_seq(js->last_seqcode, e->any.seqcode) > 0) ) {
- res = RET_LATE;
- }
-
- switch (e->any.type) {
- case EDG_WLL_EVENT_REGJOB:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_SUBMITTED;
- rep(js->pub.condor_status, "Idle");
- }
- if (USABLE_DATA(res)) {
- rep(js->pub.jdl, e->regJob.jdl);
- }
- break;
- case EDG_WLL_EVENT_CONDORMATCH:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_READY;
- rep(js->pub.condor_status, "Idle");
- }
- if (USABLE_DATA(res)) {
- rep_cond(js->pub.condor_dest_host,e->CondorMatch.dest_host);
- }
- break;
- case EDG_WLL_EVENT_CONDORREJECT:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_ABORTED;
- rep(js->pub.condor_status, "Unexpanded");
- }
- if (USABLE_DATA(res)) {
- switch(e->CondorReject.status_code) {
- case EDG_WLL_CONDORREJECT_NOMATCH:
- rep(js->pub.condor_reason,"No match found.");
- break;
- case EDG_WLL_CONDORREJECT_OTHER:
- default:
- break;
- }
- }
- break;
- case EDG_WLL_EVENT_CONDORSHADOWSTARTED:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_READY;
- rep(js->pub.condor_status, "Idle");
- }
- if (USABLE_DATA(res)) {
- switch (get_condor_event_source(e->any.seqcode)) {
- case EDG_WLL_CONDOR_EVENT_SOURCE_SCHED:
- js->pub.condor_shadow_pid = e->CondorShadowStarted.shadow_pid;
- break;
- default:
- break;
- }
- }
- break;
- case EDG_WLL_EVENT_CONDORSHADOWEXITED:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_DONE;
- rep(js->pub.condor_status, "Completed");
- }
- if (USABLE_DATA(res)) {
- switch (get_condor_event_source(e->any.seqcode)) {
- case EDG_WLL_CONDOR_EVENT_SOURCE_SHADOW:
- js->pub.condor_shadow_exit_status = e->CondorShadowExited.shadow_exit_status;
- break;
- default:
- break;
- }
- }
- break;
- case EDG_WLL_EVENT_CONDORSTARTERSTARTED:
- if (USABLE(res)) {
- switch (get_condor_event_source(e->any.seqcode)) {
- case EDG_WLL_CONDOR_EVENT_SOURCE_START:
- js->pub.state = EDG_WLL_JOB_SCHEDULED;
- rep(js->pub.condor_status, "Idle");
- break;
- case EDG_WLL_CONDOR_EVENT_SOURCE_STARTER:
- js->pub.state = EDG_WLL_JOB_RUNNING;
- rep(js->pub.condor_status, "Running");
- break;
- default:
- break;
- }
- }
- if (USABLE_DATA(res)) {
- switch (get_condor_event_source(e->any.seqcode)) {
- case EDG_WLL_CONDOR_EVENT_SOURCE_STARTER:
- rep(js->pub.condor_universe, e->CondorStarterStarted.universe);
- js->pub.condor_starter_pid = e->CondorStarterStarted.starter_pid;
- break;
- default:
- break;
- }
- }
- break;
- case EDG_WLL_EVENT_CONDORSTARTEREXITED:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_DONE;
- rep(js->pub.condor_status, "Completed");
- }
- if (USABLE_DATA(res)) {
- switch (get_condor_event_source(e->any.seqcode)) {
- case EDG_WLL_CONDOR_EVENT_SOURCE_START:
- js->pub.condor_starter_pid = e->CondorStarterExited.starter_pid;
- js->pub.condor_starter_exit_status = e->CondorStarterExited.starter_exit_status;
- break;
- case EDG_WLL_CONDOR_EVENT_SOURCE_STARTER:
- js->pub.condor_starter_pid = e->CondorStarterExited.starter_pid;
- js->pub.condor_job_pid = e->CondorStarterExited.job_pid;
- js->pub.condor_job_exit_status = e->CondorStarterExited.job_exit_status;
- break;
- default:
- break;
- }
- }
- break;
- case EDG_WLL_EVENT_CONDORRESOURCEUSAGE:
- if (USABLE(res)) {
- }
- if (USABLE_DATA(res)) {
- }
- break;
- case EDG_WLL_EVENT_CONDORERROR:
- if (USABLE(res)) {
- }
- if (USABLE_DATA(res)) {
- }
- break;
-
- default:
- break;
- }
-
-/* XXX : just debug output - remove */
-
- printf("processEvent_Condor(): %s (%s), state: %s --> %s\n ",
- edg_wll_EventToString(e->any.type),
- (res == RET_LATE) ? "RET_LATE" : "RET_OK",
- edg_wll_StatToString(old_state),
- edg_wll_StatToString(js->pub.state) );
- printf("\t%s\n",e->any.seqcode);
- printf("\t(last=%s)\n",js->last_seqcode);
-
-/*----------------------------------*/
-
- if (USABLE(res)) {
- rep(js->last_seqcode, e->any.seqcode);
-
- js->pub.lastUpdateTime = e->any.timestamp;
- if (old_state != js->pub.state) {
- js->pub.stateEnterTime = js->pub.lastUpdateTime;
- js->pub.stateEnterTimes[1 + js->pub.state]
- = (int)js->pub.lastUpdateTime.tv_sec;
- }
- }
- if (! js->pub.location) js->pub.location = strdup("this is CONDOR");
-
-
- return RET_OK;
-}
-
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <assert.h>
-#include <syslog.h>
-
-#include "glite/lb/producer.h"
-#include "glite/lb/context-int.h"
-
-#include "jobstat.h"
-#include "lock.h"
-
-/* TBD: share in whole logging or workload */
-#ifdef __GNUC__
-#define UNUSED_VAR __attribute__((unused))
-#else
-#define UNUSED_VAR
-#endif
-
-// XXX: maybe not needed any more
-// if not, remove also last_pbs_event_timestamp from intJobStat
-static int compare_timestamps(struct timeval a, struct timeval b)
-{
- if ( (a.tv_sec > b.tv_sec) ||
- ((a.tv_sec == b.tv_sec) && (a.tv_usec > b.tv_usec)) ) return 1;
- if ( (a.tv_sec < b.tv_sec) ||
- ((a.tv_sec == b.tv_sec) && (a.tv_usec < b.tv_usec)) ) return -1;
- return 0;
-}
-
-
-// XXX move this defines into some common place to be reusable
-#define USABLE(res) ((res) == RET_OK)
-#define USABLE_DATA(res) (1)
-#define rep(a,b) { free(a); a = (b == NULL) ? NULL : strdup(b); }
-#define rep_cond(a,b) { if (b) { free(a); a = strdup(b); } }
-
-int processEvent_PBS(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring)
-{
- edg_wll_JobStatCode old_state = js->pub.state;
- int res = RET_OK;
-
-
- if ((js->last_seqcode != NULL) &&
- (edg_wll_compare_pbs_seq(js->last_seqcode, e->any.seqcode) > 0) ) {
- res = RET_LATE;
- }
-
- switch (e->any.type) {
- case EDG_WLL_EVENT_REGJOB:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_SUBMITTED;
- rep(js->pub.pbs_state, "Q");
- }
- if (USABLE_DATA(res)) {
- }
- break;
- case EDG_WLL_EVENT_PBSQUEUED:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_WAITING;
- rep(js->pub.pbs_state, "Q");
- }
- if (USABLE_DATA(res)) {
- if (!js->pub.pbs_queue)
- js->pub.pbs_queue = strdup(e->PBSQueued.queue);
- assert(!strcmp(js->pub.pbs_queue, e->PBSQueued.queue));
- rep_cond(js->pub.pbs_owner,e->PBSQueued.owner);
- rep_cond(js->pub.pbs_name,e->PBSQueued.name);
- }
- break;
- case EDG_WLL_EVENT_PBSMATCH:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_READY;
- rep(js->pub.pbs_state, "Q");
- }
- if (USABLE_DATA(res)) {
- rep_cond(js->pub.pbs_dest_host,e->PBSMatch.dest_host);
- }
- break;
- case EDG_WLL_EVENT_PBSPENDING:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_WAITING;
- rep(js->pub.pbs_state, "Q");
- js->pbs_reruning = 0; // reset possible reruning flag
- }
- if (USABLE_DATA(res)) {
- rep_cond(js->pub.pbs_reason,e->PBSPending.reason);
- }
- break;
- case EDG_WLL_EVENT_PBSRUN:
- if (USABLE(res)) {
- switch (get_pbs_event_source(e->any.seqcode)) {
- case EDG_WLL_PBS_EVENT_SOURCE_SERVER:
- js->pub.state = EDG_WLL_JOB_SCHEDULED;
- rep(js->pub.pbs_state, "Q");
- break;
- case EDG_WLL_PBS_EVENT_SOURCE_MOM:
- js->pub.state = EDG_WLL_JOB_RUNNING;
- rep(js->pub.pbs_state, "R");
- break;
- default:
- assert(0); // running event from strange source
- break;
- }
- }
- if (USABLE_DATA(res)) {
- rep_cond(js->pub.pbs_scheduler, e->PBSRun.scheduler);
- rep_cond(js->pub.pbs_dest_host, e->PBSRun.dest_host);
- js->pub.pbs_pid = e->PBSRun.pid;
- }
- break;
- case EDG_WLL_EVENT_PBSRERUN:
- if (USABLE(res)) {
- switch (get_pbs_event_source(e->any.seqcode)) {
- case EDG_WLL_PBS_EVENT_SOURCE_SERVER:
- js->pub.state = EDG_WLL_JOB_WAITING;
- rep(js->pub.pbs_state, "Q");
- break;
- case EDG_WLL_PBS_EVENT_SOURCE_MOM:
- js->pub.state = EDG_WLL_JOB_WAITING;
- rep(js->pub.pbs_state, "E");
- js->pbs_reruning = 1;
- break;
- default:
- assert(0); // running event from strande source
- break;
- }
- }
- if (USABLE_DATA(res)) {
- }
- break;
- case EDG_WLL_EVENT_PBSDONE:
- if (USABLE(res)) {
- switch (get_pbs_event_source(e->any.seqcode)) {
- case EDG_WLL_PBS_EVENT_SOURCE_SERVER:
- js->pub.state = EDG_WLL_JOB_DONE;
- js->pub.done_code = EDG_WLL_STAT_OK;
- rep(js->pub.pbs_state, "C");
- break;
- case EDG_WLL_PBS_EVENT_SOURCE_MOM:
- if (!js->pbs_reruning) {
- js->pub.state = EDG_WLL_JOB_DONE;
- js->pub.done_code = EDG_WLL_STAT_OK;
- rep(js->pub.pbs_state, "C");
- }
- break;
- default:
- assert(0); //done event from strange source
- break;
- }
- }
- if (USABLE_DATA(res)) {
- js->pub.pbs_exit_status = e->PBSDone.exit_status;
- }
- break;
- case EDG_WLL_EVENT_PBSRESOURCEUSAGE:
- if (USABLE(res)) {
- // signalize state done, done_code uknown
- js->pub.state = EDG_WLL_JOB_DONE;
- rep(js->pub.pbs_state, "C");
- }
- if (USABLE_DATA(res)) {
- char *new_resource_usage;
-
- asprintf(&new_resource_usage,"%s%s\t%s = %f [%s]",
- (js->pub.pbs_resource_usage) ? js->pub.pbs_resource_usage : "",
- (js->pub.pbs_resource_usage) ? "\n": "",
- e->PBSResourceUsage.name,
- e->PBSResourceUsage.quantity,
- e->PBSResourceUsage.unit);
-
- if (js->pub.pbs_resource_usage) free(js->pub.pbs_resource_usage);
- js->pub.pbs_resource_usage = new_resource_usage;
- }
- break;
- case EDG_WLL_EVENT_PBSERROR:
- if (USABLE(res)) {
- js->pub.state = EDG_WLL_JOB_DONE;
- js->pub.done_code = EDG_WLL_STAT_FAILED;
- rep(js->pub.pbs_state, "C");
- }
- if (USABLE_DATA(res)) {
- char *new_error_desc;
-
- asprintf(&new_error_desc,"%s%s\t%s",
- (js->pub.pbs_error_desc) ? js->pub.pbs_error_desc : "",
- (js->pub.pbs_error_desc) ? "\n" : "",
- e->PBSError.error_desc);
-
- if (js->pub.pbs_error_desc) free(js->pub.pbs_error_desc);
- js->pub.pbs_error_desc = new_error_desc;
- }
- break;
-
- default:
- break;
- }
-
-/* XXX : just debug output - remove */
-
- printf("processEvent_PBS(): %s (%s), state: %s --> %s\n ",
- edg_wll_EventToString(e->any.type),
- (res == RET_LATE) ? "RET_LATE" : "RET_OK",
- edg_wll_StatToString(old_state),
- edg_wll_StatToString(js->pub.state) );
- printf("\t%s\n",e->any.seqcode);
- printf("\t(last=%s)\n",js->last_seqcode);
-
-/*----------------------------------*/
-
- if (USABLE(res)) {
- rep(js->last_seqcode, e->any.seqcode);
-
- js->pub.lastUpdateTime = e->any.timestamp;
- if (old_state != js->pub.state) {
- js->pub.stateEnterTime = js->pub.lastUpdateTime;
- js->pub.stateEnterTimes[1 + js->pub.state]
- = (int)js->pub.lastUpdateTime.tv_sec;
- }
- }
- if (! js->pub.location) js->pub.location = strdup("this is PBS");
-
-
- return RET_OK;
-}
-
+++ /dev/null
-#ifndef __EDG_WORKLOAD_LOGGING_COMMON_PURGE_H__
-#define __EDG_WORKLOAD_LOGGING_COMMON_PURGE_H__
-
-/** Server side implementation
- * besides output to the SSL stream (in the context) it may produce
- * the server-side dump files
- */
-int edg_wll_PurgeServer(
- edg_wll_Context ctx,
- const edg_wll_PurgeRequest *request
-);
-
-/** LB Proxy purge implementation
- * it gives no output - purge only one job from LB Proxy DB
- */
-int edg_wll_PurgeServerProxy(
- edg_wll_Context ctx,
- edg_wlc_JobId job
-);
-
-#define FILE_TYPE_ANY ""
-#define FILE_TYPE_PURGE "purge"
-#define FILE_TYPE_DUMP "dump"
-#define FILE_TYPE_LOAD "load"
-
-extern int edg_wll_CreateTmpFileStorage(
- edg_wll_Context ctx,
- char *prefix,
- char **fname
-);
-
-extern int edg_wll_CreateFileStorageFromTmp(
- edg_wll_Context ctx,
- char *tmp_type,
- char *file_type,
- char **fname
-);
-
-extern int edg_wll_CreateFileStorage(
- edg_wll_Context ctx,
- char *file_type,
- char *prefix,
- char **fname
-);
-
-#define edg_wll_CreateTmpDumpFile(ctx, f) edg_wll_CreateTmpFileStorage(ctx,ctx->dumpStorage,f)
-#define edg_wll_CreateTmpPurgeFile(ctx, f) edg_wll_CreateTmpFileStorage(ctx,ctx->purgeStorage,f)
-
-#define edg_wll_CreateDumpFileFromTmp(ctx, f, f2) \
- edg_wll_CreateFileStorageFromTmp(ctx, f, FILE_TYPE_DUMP, f2)
-#define edg_wll_CreatePurgeFileFromTmp(ctx, f, f2) \
- edg_wll_CreateFileStorageFromTmp(ctx, f, FILE_TYPE_PURGE, f2)
-
-#define edg_wll_CreateDumpFile(ctx, f) edg_wll_CreateFileStorage(ctx,FILE_TYPE_DUMP,NULL,f)
-#define edg_wll_CreatePurgeFile(ctx, f) edg_wll_CreateFileStorage(ctx,FILE_TYPE_PURGE,NULL,f)
-
-#endif
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <time.h>
-#include <assert.h>
-
-#include "glite/wmsutils/jobid/strmd5.h"
-
-#include "glite/lb/consumer.h"
-#include "glite/lb/producer.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-
-
-#include "get_events.h"
-#include "index.h"
-#include "query.h"
-#include "store.h"
-#include "lb_authz.h"
-
-#define FL_SEL_STATUS 1
-#define FL_SEL_TAGS (1<<1)
-#define FL_SEL_JOB (1<<2)
-
-
-static int check_event_query_index(edg_wll_Context,const edg_wll_QueryRec **,const edg_wll_QueryRec **);
-static int check_job_query_index(edg_wll_Context, const edg_wll_QueryRec **);
-static char *jc_to_head_where(edg_wll_Context, const edg_wll_QueryRec **, int *);
-static char *ec_to_head_where(edg_wll_Context, const edg_wll_QueryRec **);
-static int match_flesh_conditions(const edg_wll_Event *,const edg_wll_QueryRec **);
-static int check_strict_jobid_cond(edg_wll_Context, const edg_wll_QueryRec **);
-
-static int cmp_string(const char *,edg_wll_QueryOp,const char *);
-static int is_all_query(const edg_wll_QueryRec **);
-
-
-
-#define sizofa(a) (sizeof(a)/sizeof((a)[0]))
-
-int edg_wll_QueryEventsServer(
- edg_wll_Context ctx,
- int noAuth,
- const edg_wll_QueryRec **job_conditions,
- const edg_wll_QueryRec **event_conditions,
- edg_wll_Event **events)
-{
- char *job_where = NULL,
- *event_where = NULL,
- *qbase = NULL,
- *q = NULL,
- *res[11];
- edg_wll_Event *out = NULL;
- edg_wll_Stmt sh = NULL;
- int i = 0,
- ret = 0,
- offset = 0, limit = 0,
- limit_loop = 1,
- eperm = 0;
-
-
- edg_wll_ResetError(ctx);
-
- if ( (ctx->p_query_results == EDG_WLL_QUERYRES_ALL) &&
- (!job_conditions || !job_conditions[0] || job_conditions[1] ||
- (job_conditions[0][0].attr != EDG_WLL_QUERY_ATTR_JOBID) ||
- (job_conditions[0][1].attr != EDG_WLL_QUERY_ATTR_UNDEF)) )
- {
- edg_wll_SetError(ctx, EINVAL, "Invalid parameter EDG_WLL_PARAM_QUERY_RESULTS");
- goto cleanup;
- }
-
- if ((!ctx->noIndex && check_event_query_index(ctx,job_conditions,event_conditions)) ||
- check_strict_jobid_cond(ctx,job_conditions) ||
- check_strict_jobid_cond(ctx,event_conditions))
- goto cleanup;
-
- if (event_conditions && *event_conditions && (*event_conditions)->attr &&
- !(event_where = ec_to_head_where(ctx,event_conditions)) &&
- edg_wll_Error(ctx,NULL,NULL) != 0)
- goto cleanup;
-
- if ( job_conditions && *job_conditions && (*job_conditions)->attr &&
- !(job_where = jc_to_head_where(ctx, job_conditions, &i)) )
- goto cleanup;
-
-/* XXX: similar query in srv_purge.c ! They has to match due to common
- * convert_event_head() called on the result
- */
- trio_asprintf(&qbase,"SELECT e.event,j.userid,j.dg_jobid,e.code,"
- "e.prog,e.host,u.cert_subj,e.time_stamp,e.usec,e.level,e.arrived "
- "FROM events e,users u,jobs j%s "
- "WHERE %se.jobid=j.jobid AND e.userid=u.userid AND e.code != %d "
- "%s %s %s %s",
- i & FL_SEL_STATUS ? ",states s" : "",
- i & FL_SEL_STATUS ? "s.jobid=j.jobid AND " : "",
- EDG_WLL_EVENT_UNDEF,
- job_where ? "AND" : "",
- job_where ? job_where : "",
- event_where ? "AND" : "",
- event_where ? event_where : "");
-
- if ( ctx->softLimit )
- {
- if ( ctx->hardEventsLimit )
- limit = ctx->softLimit < ctx->hardEventsLimit? ctx->softLimit: ctx->hardEventsLimit;
- else
- limit = ctx->softLimit;
- }
- else if ( ctx->hardEventsLimit )
- limit = ctx->hardEventsLimit;
- else
- limit = 0;
-
- i = 0;
- out = calloc(1, sizeof(*out));
- do
- {
- if ( limit )
- trio_asprintf(&q, "%s LIMIT %d, %d", qbase, offset, limit);
- else if ( !q )
- q = qbase;
-
-// printf("\nquery: %s\n\n", q);
- ret = edg_wll_ExecStmt(ctx, q, &sh);
- if ( limit )
- free(q);
- if ( ret < 0 )
- {
- edg_wll_FreeStmt(&sh);
- goto cleanup;
- }
- if ( ret == 0 )
- {
- limit_loop = 0;
- goto limit_cycle_cleanup;
- }
- if ( !limit || (ret < limit) )
- limit_loop = 0;
-
- offset += ret;
- while ( (ret = edg_wll_FetchRow(sh, res)) == sizofa(res) )
- {
- int n = atoi(res[0]);
- free(res[0]);
-
- if ( convert_event_head(ctx, res+2, out+i) || edg_wll_get_event_flesh(ctx, n, out+i) )
- {
- free(res[1]);
- memset(out+i, 0, sizeof(*out));
- edg_wll_FreeStmt(&sh);
- goto cleanup;
- }
-
- if ( !match_flesh_conditions(out+i,event_conditions) || check_strict_jobid(ctx,out[i].any.jobId) )
- {
- edg_wll_FreeEvent(out+i);
- edg_wll_ResetError(ctx); /* check_strict_jobid() sets it */
- goto fetch_cycle_cleanup;
- }
-
- if ( !noAuth )
- {
- if (!ctx->peerName || strcmp(res[1],strmd5(ctx->peerName,NULL))) {
- edg_wll_Acl acl = NULL;
- char *jobid = NULL;
-
- ret = edg_wll_GetACL(ctx, out[i].any.jobId, &acl);
- free(jobid);
- if (ret || acl == NULL) {
- eperm = 1;
- edg_wll_FreeEvent(out+i);
- edg_wll_ResetError(ctx); /* XXX: should be reported somewhere at least in debug mode */
- goto fetch_cycle_cleanup;
- }
-
- ret = edg_wll_CheckACL(ctx, acl, EDG_WLL_PERM_READ);
- edg_wll_FreeAcl(acl);
- if (ret) {
- eperm = 1;
- edg_wll_FreeEvent(out+i);
- edg_wll_ResetError(ctx); /* XXX: should be reported somewhere at least in debug mode */
- goto fetch_cycle_cleanup;
- }
- }
- }
-
- if ( (ctx->p_query_results != EDG_WLL_QUERYRES_ALL) && limit && (i+1 > limit) )
- {
- free(res[1]);
- memset(out+i, 0, sizeof(*out));
- edg_wll_SetError(ctx, E2BIG, "Query result size limit exceeded");
- if ( ctx->p_query_results == EDG_WLL_QUERYRES_LIMITED )
- {
- limit_loop = 0;
- goto limit_cycle_cleanup;
- }
- goto cleanup;
- }
-
- i++;
- out = (edg_wll_Event *) realloc(out, (i+1) * sizeof(*out));
-
-fetch_cycle_cleanup:
- memset(out+i, 0, sizeof(*out));
- free(res[1]);
- }
-limit_cycle_cleanup:
- edg_wll_FreeStmt(&sh);
- } while ( limit_loop );
-
- if ( i == 0 && eperm )
- edg_wll_SetError(ctx, EPERM, "matching events found but authorization failed");
- else if ( i == 0 )
- edg_wll_SetError(ctx, ENOENT, "no matching events found");
- else
- {
- edg_wll_SortEvents(out);
- *events = out;
- out = NULL;
- }
-
-cleanup:
- if ( out )
- {
- for ( i = 0; out[i].type; i++ )
- edg_wll_FreeEvent(out+i);
- free(out);
- }
- free(qbase);
- free(job_where);
- free(event_where);
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-int edg_wll_QueryJobsServer(
- edg_wll_Context ctx,
- const edg_wll_QueryRec **conditions,
- int flags,
- edg_wlc_JobId **jobs,
- edg_wll_JobStat **states)
-{
- char *job_where = NULL,
- *state_where = NULL,
- *tags_where = NULL,
- *q = NULL,
- *qbase = NULL,
- *res[3];
- edg_wlc_JobId *jobs_out = NULL;
- edg_wll_JobStat *states_out = NULL;
- edg_wll_Stmt sh;
- int i = 0,
- ret = 0,
- eperm = 0,
- limit = 0, offset = 0,
- limit_loop = 1;
-
-
- memset(res,0,sizeof res);
- edg_wll_ResetError(ctx);
-
- if ( !conditions )
- {
- edg_wll_SetError(ctx, EINVAL, "empty condition list");
- goto cleanup;
- }
-
- if ( (ctx->p_query_results == EDG_WLL_QUERYRES_ALL) &&
- (!conditions[0] || conditions[1] ||
- (conditions[0][0].attr != EDG_WLL_QUERY_ATTR_OWNER) ||
- (conditions[0][1].attr != EDG_WLL_QUERY_ATTR_UNDEF)) )
- {
- edg_wll_SetError(ctx, EINVAL, "Invalid parameter EDG_WLL_PARAM_QUERY_RESULTS");
- goto cleanup;
- }
-
- if ( (!ctx->noIndex && check_job_query_index(ctx, conditions)) || check_strict_jobid_cond(ctx,conditions))
- goto cleanup;
-
- if ( !(job_where = jc_to_head_where(ctx, conditions, &i)) )
- goto cleanup;
-
- if ( (i & FL_SEL_STATUS) )
- trio_asprintf(&qbase,"SELECT DISTINCT j.dg_jobid,j.userid "
- "FROM jobs j, states s WHERE j.jobid=s.jobid AND %s", job_where);
- else
- trio_asprintf(&qbase,"SELECT DISTINCT j.dg_jobid,j.userid "
- "FROM jobs j WHERE %s", job_where);
-
- if ( ctx->softLimit )
- {
- if ( ctx->hardJobsLimit )
- limit = ctx->softLimit < ctx->hardJobsLimit? ctx->softLimit: ctx->hardJobsLimit;
- else
- limit = ctx->softLimit;
- }
- else if ( ctx->hardJobsLimit )
- limit = ctx->hardJobsLimit;
- else
- limit = 0;
-
- jobs_out = calloc(1, sizeof(*jobs_out));
- states_out = calloc(1, sizeof(*states_out));
- i = 0;
- do
- {
- if ( limit )
- trio_asprintf(&q, "%s LIMIT %d, %d", qbase, offset, limit);
- else if ( !q )
- q = qbase;
-
-// printf("\nquery: %s\n\n", q);
- ret = edg_wll_ExecStmt(ctx, q, &sh);
- if ( limit )
- free(q);
- if ( ret < 0 )
- {
- edg_wll_FreeStmt(&sh);
- goto cleanup;
- }
- if ( ret == 0 )
- {
- limit_loop = 0;
- goto limit_cycle_cleanup;
- }
- if ( !limit || (ret < limit) )
- limit_loop = 0;
-
- offset += ret;
- while ( (ret=edg_wll_FetchRow(sh,res)) > 0 )
- {
- if ( (ret = edg_wlc_JobIdParse(res[0], jobs_out+i)) )
- { /* unlikely to happen, internal inconsistency */
- char buf[200];
- snprintf(buf,sizeof buf,"JobIdParse(%s)",res[0]);
- edg_wll_SetError(ctx,ret,buf);
- free(res[0]); free(res[1]); free(res[2]);
- jobs_out[i] = NULL;
- goto cleanup;
- }
-
- if ( check_strict_jobid(ctx, jobs_out[i]) )
- {
- edg_wlc_JobIdFree(jobs_out[i]);
- goto fetch_cycle_cleanup;
- }
-
- if ( edg_wll_JobStatus(ctx, jobs_out[i], flags, &states_out[i]) )
- {
- edg_wlc_JobIdFree(jobs_out[i]);
- if (edg_wll_Error(ctx,NULL,NULL) == EPERM) eperm = 1;
- goto fetch_cycle_cleanup;
- }
-
- if ( !match_status(ctx, states_out+i, conditions) )
- {
- edg_wlc_JobIdFree(jobs_out[i]);
- edg_wll_FreeStatus(states_out+i);
- edg_wll_ResetError(ctx); /* check_strict_jobid() sets it */
- goto fetch_cycle_cleanup;
- }
-
-#if 0
- if ( !ctx->noAuth && (!ctx->peerName || strcmp(res[1], strmd5(ctx->peerName, NULL))) )
- {
- eperm = 1;
- edg_wlc_JobIdFree(jobs_out[i]);
- edg_wll_FreeStatus(states_out+i);
- goto fetch_cycle_cleanup;
- }
-#endif
-
- if ( (ctx->p_query_results != EDG_WLL_QUERYRES_ALL) && limit && (i+1 > limit) )
- {
- edg_wll_SetError(ctx, E2BIG, "Query result size limit exceeded");
- free(res[0]); free(res[1]); free(res[2]);
- memset(states_out+i, 0, sizeof(*states_out));
- jobs_out[i] = NULL;
- if ( ctx->p_query_results == EDG_WLL_QUERYRES_LIMITED )
- {
- limit_loop = 0;
- goto limit_cycle_cleanup;
- }
- goto cleanup;
- }
-
- i++;
- jobs_out = (edg_wlc_JobId *) realloc(jobs_out, (i+1) * sizeof(*jobs_out));
- states_out = (edg_wll_JobStat *) realloc(states_out, (i+1) * sizeof(*states_out));
-
-fetch_cycle_cleanup:
- free(res[0]); free(res[1]); free(res[2]);
- memset(states_out+i, 0, sizeof(*states_out));
- jobs_out[i] = NULL;
- }
-limit_cycle_cleanup:
- edg_wll_FreeStmt(&sh);
- } while ( limit_loop );
-
- if ( !*jobs_out ) {
- if (eperm) edg_wll_SetError(ctx, EPERM, "matching jobs found but authorization failed");
- else edg_wll_SetError(ctx, ENOENT, "no matching jobs found");
- }
-
- if ( i && (ret == 0) )
- {
- if ( states )
- {
- *states = states_out;
- states_out = NULL;
- }
- if ( jobs )
- {
- *jobs = jobs_out;
- jobs_out = NULL;
- }
- }
-
-
-cleanup:
- free(qbase);
- free(state_where);
- free(tags_where);
- free(job_where);
-
- if (jobs_out)
- {
- for ( i = 0; jobs_out[i]; i++ )
- edg_wlc_JobIdFree(jobs_out[i]);
- free(jobs_out);
- }
-
- if (states_out)
- {
- for (i=0; states_out[i].state; i++) edg_wll_FreeStatus(states_out+i);
- free(states_out);
- }
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-
-static int check_event_query_index(edg_wll_Context ctx,const edg_wll_QueryRec **jc,const edg_wll_QueryRec **ec)
-{
- int i, j;
-
- if (check_job_query_index(ctx,jc) == 0) return 0;
- edg_wll_ResetError(ctx);
-
- if (ec && *ec) for (i=0; ec[i]; i++) for (j=0; ec[i][j].attr; j++) switch (ec[i][j].attr) {
- case EDG_WLL_QUERY_ATTR_TIME:
- return 0;
- default: break;
- }
- return edg_wll_SetError(ctx,EDG_WLL_ERROR_NOINDEX,
- is_all_query(jc) ? "\"-all\" queries denied by server configuration" : NULL);
-}
-
-static int check_job_query_index(edg_wll_Context ctx, const edg_wll_QueryRec **jc)
-{
- int i, j, jj;
-
-
- edg_wll_ResetError(ctx);
-
- if ( !jc || !*jc )
- return edg_wll_SetError(ctx,EDG_WLL_ERROR_NOINDEX,"unrestricted queries unsupported");
-
- /*
- * First check presense of jobid - Primary key
- */
- for ( i = 0; jc[i]; i++ ) for ( j = 0; jc[i][j].attr; j++ )
- if ( jc[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID ) return 0;
-
- if ( !ctx->job_index )
- return edg_wll_SetError(ctx, EDG_WLL_ERROR_NOINDEX, "no indices configured: jobid required in query");
-
- for ( j = 0; ctx->job_index[j]; j++ )
- {
- if ( !ctx->job_index[j][0].attr )
- continue;
-
- if ( ctx->job_index[j][1].attr )
- {
- /*
- * check multi comlumn indexes
- */
- for ( jj = 0; ctx->job_index[j][jj].attr; jj++ )
- {
- for ( i = 0; jc[i]; i++ )
- if ( !edg_wll_CmpColumn(&ctx->job_index[j][jj], &jc[i][0]) ) break;
- if ( !jc[i] )
- break;
- }
- if ( !ctx->job_index[j][jj].attr )
- return 0;
- }
- else
- for ( i = 0; jc[i]; i++ )
- if ( !edg_wll_CmpColumn(&ctx->job_index[j][0], &jc[i][0]) ) return 0;
- }
-
- return edg_wll_SetError(ctx,EDG_WLL_ERROR_NOINDEX,
- is_all_query(jc) ? "\"-all\" queries denied by server configuration" : NULL);
-}
-
-#define opToString(op) \
- ((op) == EDG_WLL_QUERY_OP_EQUAL ? "=" : \
- ((op) == EDG_WLL_QUERY_OP_UNEQUAL ? "!=" : \
- ((op) == EDG_WLL_QUERY_OP_LESS ? "<" : ">" )))
-
-static char *ec_to_head_where(edg_wll_Context ctx,const edg_wll_QueryRec **ec)
-{
- int n, ct, m;
- char msg[100],
- *out,
- *aux,
- *conds, *retconds,
- *dbt;
-
-
- /*
- * check correctness only
- */
- for ( ct = m = 0; ec[m]; m++ )
- {
- for ( n = 0; ec[m][n].attr; n++ ) switch ( ec[m][n].attr )
- {
- case EDG_WLL_QUERY_ATTR_HOST:
- if ( ec[m][n].op != EDG_WLL_QUERY_OP_EQUAL && ec[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with host attr");
- return NULL;
- }
- ct++;
- break;
-
- case EDG_WLL_QUERY_ATTR_SOURCE:
- if ( ec[m][n].op != EDG_WLL_QUERY_OP_EQUAL && ec[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with host attr");
- return NULL;
- }
- ct++;
- break;
-
- case EDG_WLL_QUERY_ATTR_USERTAG:
- if ( ec[m][n].op != EDG_WLL_QUERY_OP_EQUAL && ec[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with usertag attr");
- return NULL;
- }
- ct++;
- break;
-
- case EDG_WLL_QUERY_ATTR_INSTANCE:
- if ( ec[m][n].op != EDG_WLL_QUERY_OP_EQUAL && ec[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with instance attr");
- return NULL;
- }
- ct++;
- break;
-
- case EDG_WLL_QUERY_ATTR_EVENT_TYPE:
- case EDG_WLL_QUERY_ATTR_LEVEL:
- /*
- * Any op allowed - but be careful
- */
- case EDG_WLL_QUERY_ATTR_TIME:
- /* any operator allowed */
- ct++;
- break;
-
- default:
- sprintf(msg, "ec_to_head_where(): attr=%d unsupported", ec[m][n].attr);
- edg_wll_SetError(ctx, EINVAL, msg);
- return NULL;
- }
- }
-
- if ( ct == 0 )
- {
- edg_wll_SetError(ctx,EINVAL,"ec_to_head_where(): empty conditions");
- return NULL;
- }
-
- conds = retconds = NULL;
- for ( m = 0; ec[m]; m++ )
- {
- /*
- * conditions captured by match_flesh_conditions() have to be skipped here.
- * with all conditions in same "or clause"
- */
- for ( n = 0; ec[m][n].attr; n++ )
- if ( /* (ec[m][n].attr == EDG_WLL_QUERY_ATTR_USERTAG) || */
- (ec[m][n].attr == EDG_WLL_QUERY_ATTR_INSTANCE) )
- break;
- if ( ec[m][n].attr )
- continue;
-
- for ( n = 0; ec[m][n].attr; n++ ) switch ( ec[m][n].attr )
- {
- case EDG_WLL_QUERY_ATTR_TIME:
- dbt = edg_wll_TimeToDB(ec[m][n].value.t.tv_sec);
- if ( conds )
- {
- if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- {
- trio_asprintf(&aux, "%s", dbt);
- dbt = edg_wll_TimeToDB(ec[m][n].value2.t.tv_sec);
- trio_asprintf(&out, "%s OR (e.time_stamp >= %s AND e.time_stamp <= %s)", conds, aux, dbt);
- free(aux);
- }
- else if (ec[m][n].op == EDG_WLL_QUERY_OP_EQUAL) {
- trio_asprintf(&out, "%s OR (e.time_stamp = %s AND e.usec = %d)",
- conds, dbt, ec[m][n].value.t.tv_usec);
- }
- else
- trio_asprintf(&out, "%s OR e.time_stamp %s %s", conds, opToString(ec[m][n].op), dbt);
- free(conds);
- conds = out;
- }
- else if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- {
- trio_asprintf(&aux, "%s", dbt);
- dbt = edg_wll_TimeToDB(ec[m][n].value2.t.tv_sec);
- trio_asprintf(&conds, "(e.time_stamp >= %s AND e.time_stamp <= %s)", aux, dbt);
- free(aux);
- }
- else if (ec[m][n].op == EDG_WLL_QUERY_OP_EQUAL) {
- trio_asprintf(&conds, "(e.time_stamp = %s AND e.usec = %d)",
- dbt, ec[m][n].value.t.tv_usec);
- }
- else
- trio_asprintf(&conds, "e.time_stamp %s %s", opToString(ec[m][n].op), dbt);
- break;
-
- case EDG_WLL_QUERY_ATTR_LEVEL:
- if ( conds )
- {
- if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- trio_asprintf(&out, "%s OR (e.level >= %d AND e.level <= %d)", conds, ec[m][n].value.i, ec[m][n].value2.i);
- else
- trio_asprintf(&out, "%s OR e.level %s %d", conds, opToString(ec[m][n].op), ec[m][n].value.i);
- free(conds); conds = out;
- }
- else
- if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- trio_asprintf(&conds, "(e.level >= %d AND e.level <= %d)", ec[m][n].value.i, ec[m][n].value2.i);
- else
- trio_asprintf(&conds, "e.level %s %d", opToString(ec[m][n].op), ec[m][n].value.i);
- break;
-
- case EDG_WLL_QUERY_ATTR_SOURCE:
- aux = edg_wll_SourceToString(ec[m][n].value.i);
- if ( conds )
- {
- trio_asprintf(&out, "%s OR e.prog %s '%|Ss'", conds, opToString(ec[m][n].op), aux);
- free(conds); conds = out;
- }
- else
- trio_asprintf(&conds, "e.prog %s '%|Ss'", opToString(ec[m][n].op), aux);
- free(aux);
- break;
-
- case EDG_WLL_QUERY_ATTR_HOST:
- if ( conds )
- {
- trio_asprintf(&out, "%s OR e.host %s '%|Ss'", conds, opToString(ec[m][n].op), ec[m][n].value.c);
- free(conds); conds = out;
- }
- else
- trio_asprintf(&conds, "e.host %s '%|Ss'", opToString(ec[m][n].op), ec[m][n].value.c);
- break;
-
- case EDG_WLL_QUERY_ATTR_USERTAG:
- if ( conds )
- {
- trio_asprintf(&out, "%s OR e.code = %d", conds, EDG_WLL_EVENT_USERTAG);
- free(conds); conds = out;
- }
- else
- trio_asprintf(&conds, "e.code = %d", EDG_WLL_EVENT_USERTAG);
- break;
- case EDG_WLL_QUERY_ATTR_EVENT_TYPE:
- if ( conds )
- {
- if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- trio_asprintf(&out, "%s OR (e.code >= %d AND e.code <= %d)", conds, ec[m][n].value.i, ec[m][n].value2.i);
- else
- trio_asprintf(&out, "%s OR e.code %s %d", conds, opToString(ec[m][n].op), ec[m][n].value.i);
- free(conds); conds = out;
- }
- else
- if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- trio_asprintf(&conds, "(e.code >= %d AND e.code <= %d)", ec[m][n].value.i, ec[m][n].value2.i);
- else
- trio_asprintf(&conds, "e.code %s %d", opToString(ec[m][n].op), ec[m][n].value.i);
- break;
-
- default:
- return NULL;
- }
-
- if ( !conds )
- continue;
-
- if ( retconds )
- {
- trio_asprintf(&out, "%s AND (%s)", retconds, conds);
- free(retconds); retconds = out;
- free(conds); conds = NULL;
- }
- else
- {
- trio_asprintf(&retconds, "(%s)", conds);
- free(conds); conds = NULL;
- }
- }
-
- return retconds;
-}
-
-static int is_indexed(const edg_wll_QueryRec *cond, const edg_wll_Context ctx)
-{
- int i, j;
-
- if ( !(ctx->job_index) )
- return 0;
-
- for ( i = 0; ctx->job_index[i]; i++ ) for ( j = 0; ctx->job_index[i][j].attr; j++ )
- if ( !edg_wll_CmpColumn(&ctx->job_index[i][j], cond) ) return 1;
-
- return 0;
-}
-
-/*
- * use where_flags to recognize which table to jois in SQL select
- *
- */
-static char *jc_to_head_where(
- edg_wll_Context ctx,
- const edg_wll_QueryRec **jc,
- int *where_flags)
-{
- int ct, n, m;
- char *aux,
- *tmps,
- *dbt,
- *cname = NULL,
- msg[100];
- char *conds, *retconds;
-
-
- retconds = conds = NULL;
-
- /*
- * check correctness only
- */
- for ( ct = m = 0; jc[m]; m++ ) for ( n = 0; jc[m][n].attr; n++ )
- {
- if ( (jc[m][0].attr != jc[m][n].attr)
- || ( (jc[m][n].attr == EDG_WLL_QUERY_ATTR_USERTAG)
- && strcmp(jc[m][0].attr_id.tag, jc[m][n].attr_id.tag)) )
- {
- edg_wll_SetError(ctx, EINVAL, "only same attribute types supported in 'or' expressions");
- return NULL;
- }
-
- switch ( jc[m][n].attr )
- {
- case EDG_WLL_QUERY_ATTR_JOBID:
- ct++;
- if ( jc[m][n].op != EDG_WLL_QUERY_OP_EQUAL && jc[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with jobid");
- return NULL;
- }
- break;
-
- case EDG_WLL_QUERY_ATTR_OWNER:
- ct++;
- if ( jc[m][n].op != EDG_WLL_QUERY_OP_EQUAL && jc[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with job owner");
- return NULL;
- }
- break;
-
- case EDG_WLL_QUERY_ATTR_LOCATION:
- ct++;
- if ( jc[m][n].op != EDG_WLL_QUERY_OP_EQUAL && jc[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with job location");
- return NULL;
- }
- break;
-
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- ct++;
- if ( jc[m][n].op != EDG_WLL_QUERY_OP_EQUAL && jc[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with job destinations");
- return NULL;
- }
- break;
-
- case EDG_WLL_QUERY_ATTR_PARENT:
- ct++;
- if ( jc[m][n].op != EDG_WLL_QUERY_OP_EQUAL && jc[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with job parent");
- return NULL;
- }
- break;
-
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- ct++;
- if ( jc[m][n].op != EDG_WLL_QUERY_OP_EQUAL && jc[m][n].op != EDG_WLL_QUERY_OP_UNEQUAL )
- {
- edg_wll_SetError(ctx, EINVAL, "only `=' and '!=' supported with resubmitted attr");
- return NULL;
- }
- break;
-
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( jc[m][n].attr_id.state == EDG_WLL_JOB_UNDEF )
- {
- edg_wll_SetError(ctx, EINVAL, "Time attribut have to be associated with status specification");
- return NULL;
- }
- ct++;
- break;
- case EDG_WLL_QUERY_ATTR_DONECODE:
- case EDG_WLL_QUERY_ATTR_EXITCODE:
- case EDG_WLL_QUERY_ATTR_STATUS:
- ct++;
- break;
-
- case EDG_WLL_QUERY_ATTR_USERTAG:
- ct++;
- break;
-
- default:
- sprintf(msg, "jc_to_head_where(): attr=%d unsupported", jc[m][n].attr);
- edg_wll_SetError(ctx, EINVAL, msg);
- return NULL;
- }
- }
-
- if ( ct == 0 )
- {
- edg_wll_SetError(ctx, EINVAL, "jc_to_head_where(): empty conditions");
- return NULL;
- }
-
- /*
- * Now process conversion
- */
- for ( m = 0; jc[m]; m++ )
- {
- for ( n = 0; jc[m][n].attr; n++ ) switch (jc[m][n].attr)
- {
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( !is_indexed(&(jc[m][n]), ctx)
- || !(cname = edg_wll_QueryRecToColumn(&(jc[m][n]))) )
- break;
-
- *where_flags |= FL_SEL_STATUS;
-
- dbt = edg_wll_TimeToDB(jc[m][n].value.t.tv_sec);
- if ( conds )
- {
- if ( jc[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- {
- trio_asprintf(&aux, "%s", dbt);
- dbt = edg_wll_TimeToDB(jc[m][n].value2.t.tv_sec);
- trio_asprintf(&tmps, "%s OR (s.%s >= %s AND s.%s <= %s)", conds, cname, aux, cname, dbt);
- free(aux);
- }
- else
- trio_asprintf(&tmps, "%s OR s.%s %s %s", conds, cname, opToString(jc[m][n].op), dbt);
-
- free(conds);
- conds = tmps;
- }
- else if ( jc[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- {
- trio_asprintf(&aux, "%s", dbt);
- dbt = edg_wll_TimeToDB(jc[m][n].value2.t.tv_sec);
- trio_asprintf(&conds, "(s.%s >= %s AND s.%s <= %s)", cname, aux, cname, dbt);
- free(aux);
- }
- else
- trio_asprintf(&conds, "s.%s %s %s", cname, opToString(jc[m][n].op), dbt);
-
- free(cname);
- break;
-
- case EDG_WLL_QUERY_ATTR_JOBID:
- *where_flags |= FL_SEL_JOB;
- aux = edg_wlc_JobIdGetUnique(jc[m][n].value.j);
- if ( conds )
- {
- trio_asprintf(&tmps, "%s OR j.jobid%s'%|Ss'", conds, opToString(jc[m][n].op), aux);
- free(conds); conds = tmps;
- }
- else
- trio_asprintf(&conds, "j.jobid%s'%|Ss'", opToString(jc[m][n].op), aux);
- free(aux);
- break;
-
- case EDG_WLL_QUERY_ATTR_PARENT:
- if ( !is_indexed(&(jc[m][n]), ctx)
- || !(cname = edg_wll_QueryRecToColumn(&(jc[m][n]))) )
- break;
-
- *where_flags |= FL_SEL_STATUS;
- aux = edg_wlc_JobIdGetUnique(jc[m][n].value.j);
- if ( conds )
- {
- trio_asprintf(&tmps, "%s OR s.%s%s'%|Ss'", conds, cname, opToString(jc[m][n].op), aux);
- free(conds); conds = tmps;
- }
- else
- trio_asprintf(&conds, "s.%s%s'%|Ss'", cname, opToString(jc[m][n].op), aux);
- free(aux);
- break;
-
- case EDG_WLL_QUERY_ATTR_OWNER:
- if ( !is_indexed(&(jc[m][n]), ctx)
- || !(cname = edg_wll_QueryRecToColumn(&(jc[m][n]))) )
- break;
-
- if ( !jc[m][n].value.c && !ctx->peerName )
- {
- edg_wll_SetError(ctx, EPERM, "jc_to_head_where(): ctx->peerName empty");
- free(cname); free(conds); free(retconds);
- return NULL;
- }
-
- *where_flags |= FL_SEL_STATUS;
- if ( conds )
- {
- if ( jc[m][n].value.c )
- trio_asprintf(&tmps, "%s OR s.%s%s'%|Ss'", conds, cname, opToString(jc[m][n].op), jc[m][n].value.c);
- else
- trio_asprintf(&tmps, "%s OR s.%s%s'%|Ss'", conds, cname, opToString(jc[m][n].op), ctx->peerName);
- free(conds); conds = tmps;
- }
- else
- {
- if ( jc[m][n].value.c )
- trio_asprintf(&conds, "s.%s%s'%|Ss'", cname, opToString(jc[m][n].op), jc[m][n].value.c);
- else
- trio_asprintf(&conds, "s.%s%s'%|Ss'", cname, opToString(jc[m][n].op), ctx->peerName);
- }
- break;
-
- case EDG_WLL_QUERY_ATTR_DONECODE:
- case EDG_WLL_QUERY_ATTR_EXITCODE:
- case EDG_WLL_QUERY_ATTR_STATUS:
- if ( !is_indexed(&(jc[m][n]), ctx)
- || !(cname = edg_wll_QueryRecToColumn(&(jc[m][n]))) )
- break;
-
- *where_flags |= FL_SEL_STATUS;
- if ( conds )
- {
- if ( jc[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- trio_asprintf(&tmps, "%s OR (s.%s >= %d AND s.%s <= %d)", conds, cname, jc[m][n].value.i, cname, jc[m][n].value2.i);
- else
- trio_asprintf(&tmps, "%s OR s.%s %s %d", conds, cname, opToString(jc[m][n].op), jc[m][n].value.i);
- free(conds); conds = tmps;
- }
- else
- if ( jc[m][n].op == EDG_WLL_QUERY_OP_WITHIN )
- trio_asprintf(&conds, "(s.%s >= %d AND s.%s <= %d)", cname, jc[m][n].value.i, cname, jc[m][n].value2.i);
- else
- trio_asprintf(&conds, "s.%s %s %d", cname, opToString(jc[m][n].op),jc[m][n].value.i);
-
- free(cname);
- break;
-
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- case EDG_WLL_QUERY_ATTR_LOCATION:
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- case EDG_WLL_QUERY_ATTR_USERTAG:
- if ( !is_indexed(&(jc[m][n]), ctx)
- || !(cname = edg_wll_QueryRecToColumn(&(jc[m][n]))) )
- break;
-
- *where_flags |= FL_SEL_STATUS;
- if ( conds )
- {
- trio_asprintf(&tmps, "%s OR s.%s%s'%s'", conds, cname, opToString(jc[m][n].op), jc[m][n].value.c);
- free(conds); conds = tmps;
- }
- else
- trio_asprintf(&conds, "s.%s%s'%s'", cname, opToString(jc[m][n].op), jc[m][n].value.c);
-
- free(cname);
- break;
-
- default:
- /* this may never occure, but keep compiler happy */
- break;
- }
-
- if ( !conds ) continue;
-
- if ( retconds )
- {
- trio_asprintf(&tmps, "%s AND (%s)", retconds, conds);
- free(retconds); retconds = tmps;
- free(conds); conds = NULL;
- }
- else
- {
- trio_asprintf(&retconds, "(%s)", conds);
- free(conds); conds = NULL;
- }
- }
-
- return retconds;
-}
-
-
-static int match_flesh_conditions(const edg_wll_Event *e,const edg_wll_QueryRec **ec)
-{
- int i, j;
-
-
- if ( !ec )
- return 1;
-
- for ( i = 0; ec[i]; i++ )
- {
- j = 0;
- while ( (ec[i][j].attr)
- && (ec[i][j].attr != EDG_WLL_QUERY_ATTR_USERTAG)
- && (ec[i][j].attr != EDG_WLL_QUERY_ATTR_INSTANCE) ) j++;
- if ( !ec[i][j].attr )
- continue;
-
- for ( j = 0; ec[i][j].attr; j++ )
- {
- if ( ec[i][j].attr == EDG_WLL_QUERY_ATTR_TIME )
- {
- if ( ((ec[i][j].op == EDG_WLL_QUERY_OP_EQUAL) && (e->any.timestamp.tv_sec == ec[i][j].value.t.tv_sec))
- || ((ec[i][j].op == EDG_WLL_QUERY_OP_LESS) && (e->any.timestamp.tv_sec < ec[i][j].value.t.tv_sec))
- || ((ec[i][j].op == EDG_WLL_QUERY_OP_GREATER) && (e->any.timestamp.tv_sec < ec[i][j].value.t.tv_sec))
- || ( (ec[i][j].op == EDG_WLL_QUERY_OP_WITHIN)
- && (e->any.timestamp.tv_sec >= ec[i][j].value.t.tv_sec)
- && (e->any.timestamp.tv_sec <= ec[i][j].value2.t.tv_sec)) )
- break;
- }
- else if ( ec[i][j].attr == EDG_WLL_QUERY_ATTR_SOURCE )
- {
- if ( e->any.source == EDG_WLL_SOURCE_NONE )
- continue;
- if ( ((ec[i][j].op == EDG_WLL_QUERY_OP_EQUAL) && (e->any.source == ec[i][j].value.i))
- || ((ec[i][j].op == EDG_WLL_QUERY_OP_LESS) && (e->any.source < ec[i][j].value.i))
- || ((ec[i][j].op == EDG_WLL_QUERY_OP_GREATER) && (e->any.source < ec[i][j].value.i))
- || ( (ec[i][j].op == EDG_WLL_QUERY_OP_WITHIN)
- && (e->any.source >= ec[i][j].value.i)
- && (e->any.source <= ec[i][j].value2.i)) )
- break;
- }
- else if ( ec[i][j].attr == EDG_WLL_QUERY_ATTR_LEVEL )
- {
- if ( ((ec[i][j].op == EDG_WLL_QUERY_OP_EQUAL) && (e->any.level == ec[i][j].value.i))
- || ((ec[i][j].op == EDG_WLL_QUERY_OP_LESS) && (e->any.level < ec[i][j].value.i))
- || ((ec[i][j].op == EDG_WLL_QUERY_OP_GREATER) && (e->any.level < ec[i][j].value.i))
- || ( (ec[i][j].op == EDG_WLL_QUERY_OP_WITHIN)
- && (e->any.level >= ec[i][j].value.i)
- && (e->any.level <= ec[i][j].value2.i)) )
- break;
- }
- else if ( ec[i][j].attr == EDG_WLL_QUERY_ATTR_HOST )
- {
- if ( !strcmp(ec[i][j].value.c, e->any.host) )
- break;
- }
- else if ( ec[i][j].attr == EDG_WLL_QUERY_ATTR_EVENT_TYPE )
- {
- if ( e->any.type == ec[i][j].value.i )
- break;
- }
- else if ( ec[i][j].attr == EDG_WLL_QUERY_ATTR_USERTAG )
- {
- if ( e->any.type == EDG_WLL_EVENT_USERTAG &&
- !strcmp(ec[i][j].attr_id.tag,e->userTag.name)
- && cmp_string(e->userTag.value,ec[i][j].op,ec[i][j].value.c))
- break;
- }
- else if ( ec[i][j].attr == EDG_WLL_QUERY_ATTR_INSTANCE )
- {
- if ( e->any.src_instance
- && cmp_string(ec[i][j].value.c, ec[i][j].op, e->any.src_instance) )
- break;
- }
- }
- if ( !ec[i][j].attr )
- /*
- * No condition in "or" clause is valid
- */
- return 0;
- }
-
- return 1;
-}
-
-/* XXX: has to match exactly the main query in edg_wll_QueryEvents
- * and similar one in srv_purge.c
- */
-int convert_event_head(edg_wll_Context ctx,char **f,edg_wll_Event *e)
-{
- int ret,i;
-
- memset(e,0,sizeof *e);
- edg_wll_ResetError(ctx);
-
-
- if ((ret=edg_wlc_JobIdParse(f[0],&e->any.jobId))) {
- edg_wll_SetError(ctx,-ret,"edg_wlc_JobIdParse()");
- goto err;
- }
-
- e->type = atoi(f[1]);
- free(f[1]); f[1] = NULL;
-
- e->any.source = edg_wll_StringToSource(f[2]);
- free(f[2]); f[2] = NULL;
-
- e->any.host = f[3];
- f[3] = NULL;
-
- e->any.user = f[4];
- f[4] = NULL;
-
- e->any.timestamp.tv_sec = edg_wll_DBToTime(f[5]);
- free(f[5]); f[5] = NULL;
-
- e->any.timestamp.tv_usec = atoi(f[6]);
- free(f[6]); f[6] = NULL;
-
- e->any.level = atoi(f[7]);
- free(f[7]); f[7] = NULL;
-
- e->any.arrived.tv_sec = edg_wll_DBToTime(f[8]);
- e->any.arrived.tv_usec = 0;
- free(f[8]); f[8] = NULL;
-
- return 0;
-
-err:
- edg_wll_FreeEvent(e);
- memset(e,0,sizeof *e);
- for (i=0; i<9; i++) free(f[i]);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-
-
-/* FIXME: other op's, ORed conditions */
-int match_status(edg_wll_Context ctx, const edg_wll_JobStat *stat, const edg_wll_QueryRec **conds)
-{
- int i, j, n;
- char *s, *s1;
-
-
- if ( !conds ) return 1;
-
- for ( i = 0; conds[i]; i++ )
- {
- for ( j = 0; conds[i][j].attr; j++ )
- {
- if ( is_indexed(&(conds[i][j]), ctx) ) goto or_satisfied;
-
- switch ( conds[i][j].attr )
- {
- case EDG_WLL_QUERY_ATTR_STATUS:
- switch ( conds[i][j].op )
- {
- case EDG_WLL_QUERY_OP_EQUAL:
- if ( conds[i][j].value.i == stat->state ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_UNEQUAL:
- if ( conds[i][j].value.i != stat->state ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_LESS:
- if ( conds[i][j].value.i > stat->state ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_GREATER:
- if ( conds[i][j].value.i < stat->state ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_WITHIN:
- if ( conds[i][j].value.i <= stat->state
- && conds[i][j].value2.i >= stat->state ) goto or_satisfied;
- break;
- }
- break;
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) {
- if ( conds[i][j].value.i == stat->resubmitted ) goto or_satisfied;
- } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL )
- if ( conds[i][j].value.i != stat->resubmitted ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_ATTR_DONECODE:
- switch ( conds[i][j].op )
- {
- case EDG_WLL_QUERY_OP_EQUAL:
- if ( conds[i][j].value.i == stat->done_code ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_UNEQUAL:
- if ( conds[i][j].value.i != stat->done_code ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_LESS:
- if ( conds[i][j].value.i > stat->done_code ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_GREATER:
- if ( conds[i][j].value.i < stat->done_code ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_WITHIN:
- if ( conds[i][j].value.i <= stat->done_code
- && conds[i][j].value2.i >= stat->done_code ) goto or_satisfied;
- break;
- }
- break;
- case EDG_WLL_QUERY_ATTR_EXITCODE:
- switch ( conds[i][j].op )
- {
- case EDG_WLL_QUERY_OP_EQUAL:
- if ( conds[i][j].value.i == stat->exit_code ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_UNEQUAL:
- if ( conds[i][j].value.i != stat->exit_code ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_LESS:
- if ( conds[i][j].value.i > stat->exit_code ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_GREATER:
- if ( conds[i][j].value.i < stat->exit_code ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_WITHIN:
- if ( conds[i][j].value.i <= stat->exit_code
- && conds[i][j].value2.i >= stat->exit_code ) goto or_satisfied;
- break;
- }
- break;
- case EDG_WLL_QUERY_ATTR_OWNER:
- if (stat->owner) {
- if (conds[i][j].value.c) {
- if (!strcmp(conds[i][j].value.c, stat->owner) ) {
- if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
- } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
- } else if (ctx->peerName) {
- if (!strcmp(ctx->peerName, stat->owner) ) {
- if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
- } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
- }
- }
- break;
- case EDG_WLL_QUERY_ATTR_LOCATION:
- if ( stat->location )
- {
- if ( !strcmp(conds[i][j].value.c, stat->location) ) {
- if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
- } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
- }
- break;
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- if ( stat->destination )
- {
- if ( !strcmp(conds[i][j].value.c, stat->destination) ) {
- if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
- } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
- }
- break;
- case EDG_WLL_QUERY_ATTR_JOBID:
- if ( !stat->jobId )
- break;
- s = edg_wlc_JobIdUnparse(stat->jobId);
- s1 = edg_wlc_JobIdUnparse(conds[i][j].value.j);
- if ( s && s1 )
- {
- int r = strcmp(s1, s);
- free(s); free(s1);
- if ( !r ) {
- if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
- } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
- }
- break;
- case EDG_WLL_QUERY_ATTR_PARENT:
- if ( !stat->parent_job )
- break;
- s = edg_wlc_JobIdUnparse(stat->parent_job);
- s1 = edg_wlc_JobIdUnparse(conds[i][j].value.j);
- if ( s && s1 )
- {
- int r = strcmp(s1, s);
- free(s); free(s1);
- if ( !r ) {
- if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
- } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
- }
- break;
- case EDG_WLL_QUERY_ATTR_USERTAG:
- if ( !stat->user_tags )
- {
- if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL )
- goto or_satisfied;
-
- break;
- }
- for ( n = 0; stat->user_tags[n].tag; n++ )
- if ( !strcasecmp(conds[i][j].attr_id.tag, stat->user_tags[n].tag) )
- {
- if ( !strcmp(conds[i][j].value.c, stat->user_tags[n].value) ) {
- if ( conds[i][j].op == EDG_WLL_QUERY_OP_EQUAL ) goto or_satisfied;
- } else if ( conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL ) goto or_satisfied;
-
- break;
- }
- if ( !stat->user_tags[n].tag && conds[i][j].op == EDG_WLL_QUERY_OP_UNEQUAL )
- goto or_satisfied;
- break;
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( !stat->stateEnterTimes || !stat->stateEnterTimes[1+conds[i][j].attr_id.state] )
- break;
- switch ( conds[i][j].op )
- {
- case EDG_WLL_QUERY_OP_EQUAL:
- if ( conds[i][j].value.t.tv_sec == stat->stateEnterTimes[1+conds[i][j].attr_id.state] ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_UNEQUAL:
- if ( conds[i][j].value.t.tv_sec != stat->stateEnterTimes[1+conds[i][j].attr_id.state] ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_LESS:
- if ( conds[i][j].value.t.tv_sec > stat->stateEnterTimes[1+conds[i][j].attr_id.state] ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_GREATER:
- if ( conds[i][j].value.t.tv_sec < stat->stateEnterTimes[1+conds[i][j].attr_id.state] ) goto or_satisfied;
- break;
- case EDG_WLL_QUERY_OP_WITHIN:
- if ( conds[i][j].value.t.tv_sec <= stat->stateEnterTimes[1+conds[i][j].attr_id.state]
- && conds[i][j].value2.t.tv_sec >= stat->stateEnterTimes[1+conds[i][j].attr_id.state] ) goto or_satisfied;
- break;
- }
- break;
- default:
- break;
- }
- }
-
- /*
- * No one condition in "or clause satisfied
- */
- return 0;
-
-or_satisfied:
- // just for escaping from nested cycles
- ; /* prevent compiler to complain */
- }
-
- return 1;
-}
-
-static int cmp_string(const char *s1,edg_wll_QueryOp op,const char *s2)
-{
- switch (op) {
- case EDG_WLL_QUERY_OP_EQUAL: return !strcmp(s1,s2);
- case EDG_WLL_QUERY_OP_LESS: return strcmp(s1,s2)<0;
- case EDG_WLL_QUERY_OP_GREATER: return strcmp(s1,s2)>0;
- default: return 0;
- }
- return 0;
-}
-
-
-int check_strict_jobid(edg_wll_Context ctx, const edg_wlc_JobId job)
-{
- char *job_host;
- unsigned int job_port;
-
- edg_wll_ResetError(ctx);
-
- /* Allow all jobids when server name is not set. */
- if ( (ctx->srvName == NULL) || (ctx->isProxy)) return edg_wll_Error(ctx,NULL,NULL);
-
- edg_wlc_JobIdGetServerParts(job,&job_host,&job_port);
-
- if (strcasecmp(job_host,ctx->srvName) || job_port != ctx->srvPort)
- {
- char *jobid,msg[300];
-
- jobid = edg_wlc_JobIdUnparse(job);
- snprintf(msg,sizeof msg,"%s: does not match server address",jobid);
- msg[sizeof msg - 1] = 0;
- edg_wll_SetError(ctx,EINVAL,msg);
- free(jobid);
- }
-
- free(job_host);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-static int check_strict_jobid_cond(edg_wll_Context ctx, const edg_wll_QueryRec **cond)
-{
- int i,j,ret;
-
- if (!cond) return edg_wll_ResetError(ctx);
- for (i=0; cond[i]; i++) for (j=0; cond[i][j].attr; j++)
- if (cond[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID &&
- (ret = check_strict_jobid(ctx,cond[i][j].value.j)))
- return ret;
-
- return 0;
-}
-
-static int is_all_query(const edg_wll_QueryRec **jc)
-{
- if (!jc || !*jc) return 1;
-
- if (jc[0][0].attr == EDG_WLL_QUERY_ATTR_OWNER &&
- jc[0][0].op == EDG_WLL_QUERY_OP_EQUAL &&
- !jc[0][1].attr && !jc[1]) return 1;
-
- return 0;
-}
+++ /dev/null
-int convert_event_head(edg_wll_Context,char **,edg_wll_Event *);
-int check_strict_jobid(edg_wll_Context, const edg_wlc_JobId);
-int match_status(edg_wll_Context, const edg_wll_JobStat *stat,const edg_wll_QueryRec **conditions);
-
-#define NOTIF_ALL_JOBS "all_jobs"
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "glite/lb/il_string.h"
-#include "glite/lb/il_msg.h"
-#include "glite/lb/context-int.h"
-
-#include "store.h"
-#include "lbs_db.h"
-
-#ifdef __GNUC__
-#define UNUSED_VAR __attribute__((unused))
-#else
-#define UNUSED_VAR
-#endif
-
-
-int
-trans_db_store(edg_wll_Context ctx, char *event_data, edg_wll_Event *e, intJobStat *is)
-{
- int ret;
-
- if ((ret = edg_wll_Transaction(ctx) != 0)) goto err;
-
- if (e) ret = db_parent_store(ctx, e, is);
- else ret = db_store(ctx, "NOT USED", event_data);
-
- if (ret == 0) {
- if ((ret = edg_wll_Commit(ctx)) != 0) goto err;
- } else {
- edg_wll_Rollback(ctx);
- }
-
-err:
- return(ret);
-}
-
-int
-handle_request(edg_wll_Context ctx,char *buf)
-{
- il_octet_string_t event;
- int ret;
-
- edg_wll_ResetError(ctx);
-
- ret = decode_il_msg(&event, buf);
- if(ret < 0) {
- edg_wll_SetError(ctx,EDG_WLL_IL_PROTO,"decoding event string failed");
- return EDG_WLL_IL_PROTO;
- }
-
- ret = trans_db_store(ctx, event.data, NULL, NULL);
-
- if(event.data)
- free(event.data);
-
- return(ret);
-}
-
-
-int
-create_reply(const edg_wll_Context ctx, char **buf)
-{
- int len, err_code, err_code_min;
- char *err_msg;
-
- err_code_min = 0;
-
- switch(edg_wll_Error(ctx,NULL,&err_msg)) {
-
- case 0:
- err_code = LB_OK;
- break;
-
- case ENOMEM:
- err_code = LB_NOMEM;
- break;
-
- case EDG_WLL_IL_PROTO:
- err_code = LB_PROTO;
- break;
-
- default:
- err_code = LB_DBERR;
- err_code_min = edg_wll_Error(ctx,NULL,NULL);
- break;
-
- }
-
- if (!err_msg) err_msg=strdup("OK");
-
- len = encode_il_reply(buf, err_code, err_code_min, err_msg);
- free(err_msg);
- return(len);
-}
-
-
+++ /dev/null
-#ident "$Header$"
-
-#include <errno.h>
-
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-
-#include "get_events.h"
-#include "store.h"
-#include "lock.h"
-#include "jobstat.h"
-/*
-#include "lb_authz.h"
-*/
-
-
-
-int edg_wll_QuerySequenceCodeServer(edg_wll_Context ctx, edg_wlc_JobId jobid, const char *source, char **seqcode)
-{
- edg_wll_Stmt sh;
- intJobStat *istat = NULL;
- char *jobid_md5 = NULL,
- *stmt = NULL,
- *res = NULL,
- *res_rest = NULL;
- int nstates;
-
-
- edg_wll_ResetError(ctx);
- jobid_md5 = edg_wlc_JobIdGetUnique(jobid);
-
- trio_asprintf(&stmt,
- "select int_status from states "
- "where jobid='%|Ss' and version='%|Ss'",
- jobid_md5, INTSTAT_VERSION);
-
- if ( stmt == NULL ) return edg_wll_SetError(ctx, ENOMEM, NULL);
-
- if ( (nstates = edg_wll_ExecStmt(ctx, stmt, &sh)) < 0 ) goto cleanup;
- if ( nstates == 0 ) {
- edg_wll_SetError(ctx, ENOENT, "no state in DB");
- goto cleanup;
- }
- if ( edg_wll_FetchRow(sh, &res) < 0 ) goto cleanup;
-
- istat = dec_intJobStat(res, &res_rest);
- if ( res_rest && istat ) {
- *seqcode = istat->last_seqcode;
- istat->last_seqcode = NULL;
- }
- else edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_CALL,
- "error decoding DB intJobStatus");
-
-cleanup:
- free(res);
- free(jobid_md5);
- free(stmt);
- edg_wll_FreeStmt(&sh);
- if ( istat ) {
- destroy_intJobStat(istat);
- free(istat);
- }
-
- return edg_wll_Error(ctx, NULL, NULL);
-}
+++ /dev/null
-#ident "$Header$"
-
-#include "glite/lb/trio.h"
-#include "glite/lb/context-int.h"
-
-#include "lbs_db.h"
-#include "server_state.h"
-
-int edg_wll_GetServerState(edg_wll_Context ctx,const char *name,char **val)
-{
- char *stmt = NULL;
- edg_wll_Stmt q = NULL;
-
-
- trio_asprintf(&stmt,"select value from server_state "
- "where prefix = 'https://%|Ss:%d' and name = '%|Ss'",
- ctx->srvName,ctx->srvPort,name);
-
- switch (edg_wll_ExecStmt(ctx,stmt,&q)) {
- case 0: edg_wll_SetError(ctx,ENOENT,name); break;
- case -1: break;
- default: edg_wll_FetchRow(q,val); break;
- }
-
- edg_wll_FreeStmt(&q);
- free(stmt);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-int edg_wll_SetServerState(edg_wll_Context ctx,const char *name,const char *val)
-{
- char *stmt = NULL;
-
- trio_asprintf(&stmt,"insert into server_state (prefix,name,value) "
- "values ('https://%|Ss:%d','%|Ss','%|Ss')",
- ctx->srvName,ctx->srvPort,name,val);
-
- switch(edg_wll_ExecStmt(ctx,stmt,NULL)) {
- case 1: break;
- case -1: if (edg_wll_Error(ctx,NULL,NULL) == EEXIST) {
- free(stmt);
- trio_asprintf(&stmt,"update server_state set value = '%|Ss' "
- "where prefix = 'https://%|Ss:%d' "
- "and name = '%|Ss'",
- val,ctx->srvName,ctx->srvPort,name);
- edg_wll_ExecStmt(ctx,stmt,NULL);
- }
- break;
-
- default: abort();
- }
- free(stmt);
- return edg_wll_Error(ctx,NULL,NULL);
-}
+++ /dev/null
-#ifndef _EDG_WORKLOAD_LOGGING_LBSERVER_H_
-#define EDG_WLL_STATE_DUMP_START "StartDump"
-#define EDG_WLL_STATE_DUMP_END "EndDump"
-
-#ident "$Header$"
-
-int edg_wll_GetServerState(edg_wll_Context,const char *,char **);
-int edg_wll_SetServerState(edg_wll_Context,const char *,const char *);
-
-#endif
+++ /dev/null
-#ident "$Header$"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <syslog.h>
-#include <assert.h>
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-
-#include "glite/wmsutils/jobid/cjobid.h"
-
-#include "glite/lb/trio.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/events_parse.h"
-#include "glite/lb/mini_http.h"
-#include "glite/lb/ulm_parse.h"
-
-#include "lb_html.h"
-#include "lb_proto.h"
-#include "store.h"
-#include "lock.h"
-#include "lbs_db.h"
-#include "query.h"
-#include "get_events.h"
-#include "glite/lb/purge.h"
-#include "glite/lb/load.h"
-#include "glite/lb/dump.h"
-#include "purge.h"
-#include "lb_xml_parse.h"
-
-
-#define DUMP_FILE_STORAGE "/tmp/"
-
-#define sizofa(a) (sizeof(a)/sizeof((a)[0]))
-
-static const char* const resp_headers[] = {
- "Cache-Control: no-cache",
- "Accept: application/x-dglb",
- "User-Agent: edg_wll_Server/" PROTO_VERSION "/" COMP_PROTO,
- "Content-Type: application/x-dglb",
- NULL
-};
-
-static int purge_one(edg_wll_Context ctx,const edg_wlc_JobId,int,int);
-
-int edg_wll_CreateTmpFileStorage(edg_wll_Context ctx, char *prefix, char **fname)
-{
- char fname_buf[1024];
- struct timeval tv;
- int retfd;
-
-
- while ( 1 )
- {
- gettimeofday(&tv, NULL);
- snprintf(fname_buf, 1024, "%s/%ld_%ld", prefix, tv.tv_sec, tv.tv_usec);
-
- if ( (retfd = open(fname_buf, O_WRONLY|O_CREAT|O_EXCL|O_APPEND,0600)) == -1 )
- {
- if ( errno != EEXIST )
- {
- char buff[100];
-
- sprintf(buff, "couldn't create temporary server file");
- edg_wll_SetError(ctx, errno, buff);
- return -1;
- }
- }
- else
- break;
- }
-
- *fname = strdup(fname_buf);
-
- return retfd;
-}
-
-int edg_wll_CreateFileStorageFromTmp(edg_wll_Context ctx, char *old_file, char *file_type, char **fname)
-{
- char fname_buf[1024],
- fname_prefix[1024],
- stimebuf[100];
- char *stmp;
- struct timeval tv;
- int retfd;
-
-
- if ( (stmp = strrchr(old_file, '/')) )
- {
- strncpy(fname_prefix, old_file, stmp - old_file);
- fname_prefix[stmp - old_file] = '\0';
- }
-
- while ( 1 )
- {
- gettimeofday(&tv, NULL);
- edg_wll_ULMTimevalToDate(tv.tv_sec, tv.tv_usec, stimebuf);
- snprintf(fname_buf, 1024, "%s/%s_%s", fname_prefix, file_type, stimebuf);
-
- if ( !link(old_file, fname_buf) )
- break;
-
- if ( errno != EEXIST )
- {
- char buff[100];
-
- sprintf(buff, "couldn't create server %s file", file_type);
- return edg_wll_SetError(ctx, errno, buff);
- }
- }
-
- *fname = strdup(fname_buf);
-
- return retfd;
-}
-
-int edg_wll_CreateFileStorage(edg_wll_Context ctx, char *file_type, char *prefix, char **fname)
-{
- char fname_buf[1024],
- stimebuf[100];
- struct timeval tv;
- int retfd;
-
- if ( *fname )
- {
- snprintf(fname_buf, 1024, "%s/%s", prefix? prefix: "", *fname);
- if ( (retfd = open(*fname, O_WRONLY|O_CREAT|O_EXCL|O_APPEND,0600)) == -1 )
- {
- char buff[100];
- if ( errno == EEXIST )
- sprintf(buff, "Server file %s exist", fname_buf);
- else
- sprintf(buff, "Server couldn't create file %s", fname_buf);
- edg_wll_SetError(ctx, errno, buff);
-
- return -1;
- }
- if ( prefix )
- {
- free(*fname);
- *fname = strdup(fname_buf);
- }
-
- return retfd;
- }
-
- while ( 1 )
- {
- gettimeofday(&tv, NULL);
- edg_wll_ULMTimevalToDate(tv.tv_sec, tv.tv_usec, stimebuf);
- if ( !prefix )
- {
- if ( strcmp(file_type,FILE_TYPE_PURGE) == 0 )
- prefix = ctx->purgeStorage;
- else if ( strcmp(file_type,FILE_TYPE_DUMP) == 0 )
- prefix = ctx->dumpStorage;
- else
- prefix = "";
- }
- snprintf(fname_buf, 1024, "%s/%s_%s", prefix, file_type, stimebuf);
-
- if ( (retfd = open(fname_buf, O_WRONLY|O_CREAT|O_EXCL|O_APPEND,0600)) == -1 )
- {
- if ( errno != EEXIST )
- {
- char buff[100];
-
- sprintf(buff, "couldn't create server %s file", file_type);
- edg_wll_SetError(ctx, errno, buff);
-
- return -1;
- }
- }
- else
- break;
- }
-
- *fname = strdup(fname_buf);
-
- return retfd;
-}
-
-int edg_wll_PurgeServerProxy(edg_wll_Context ctx, edg_wlc_JobId job)
-{
- switch ( purge_one(ctx, job, -1, 1) ) {
- case 0:
- case ENOENT:
- edg_wll_ResetError(ctx);
- return 0;
-
- default:
- return -1;
- }
-}
-
-int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request)
-{
- int i,parse = 0,dumpfile = -1;
- edg_wlc_JobId job;
- char *message = NULL, *response = NULL;
- char *tmpfname = NULL;
- int naffected_jobs = 0;
- edg_wll_PurgeResult result;
- int ret = HTTP_OK;
-
-
- if (!ctx->noAuth) {
- edg_wll_SetError(ctx,EPERM,"only superusers may purge");
- goto abort;
- }
-
- edg_wll_ResetError(ctx);
- memset(&result, 0, sizeof(edg_wll_PurgeResult));
-
-
- if ( (request->flags & EDG_WLL_PURGE_SERVER_DUMP) &&
- ((dumpfile = edg_wll_CreateTmpPurgeFile(ctx, &tmpfname)) == -1 ) )
- return edg_wll_Error(ctx, NULL, NULL);
-
- if (request->flags&EDG_WLL_PURGE_REALLY_PURGE) {
- edg_wll_DumpRequest req = {
- EDG_WLL_DUMP_LAST_END, EDG_WLL_DUMP_NOW
- };
- edg_wll_DumpResult res;
-
- if (edg_wll_DumpEvents(ctx,&req,&res))
- {
- if ( request->flags & EDG_WLL_PURGE_SERVER_DUMP )
- unlink(tmpfname);
- return edg_wll_Error(ctx, NULL, NULL);
- }
- }
-
- if (request->jobs) for (i=0; request->jobs[i]; i++) {
- if (edg_wlc_JobIdParse(request->jobs[i],&job)) {
- fprintf(stderr,"%s: parse error\n",request->jobs[i]);
- parse = 1;
- }
- else {
- if (check_strict_jobid(ctx,job)) {
- fprintf(stderr,"%s: not my job\n",request->jobs[i]);
- parse = 1;
- }
- else {
- switch (purge_one(ctx,job,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE)) {
- case 0: if (request->flags & EDG_WLL_PURGE_LIST_JOBS) {
- result.jobs = realloc(result.jobs,(naffected_jobs+2) * sizeof(*result.jobs));
- result.jobs[naffected_jobs] = strdup(request->jobs[i]);
- result.jobs[naffected_jobs+1] = NULL;
- }
- naffected_jobs++;
- break;
- case ENOENT: parse = 1;
- edg_wll_ResetError(ctx);
- break;
- default: goto abort;
- }
-
- }
- edg_wlc_JobIdFree(job);
- }
- }
- else {
- edg_wll_Stmt s;
- char *job_s;
- int res;
- time_t timeout[EDG_WLL_NUMBER_OF_STATCODES],
- now = time(NULL);
-
- for (i=0; i<EDG_WLL_NUMBER_OF_STATCODES; i++)
- timeout[i] = request->timeout[i] < 0 ? ctx->purge_timeout[i] : request->timeout[i];
-
- if (edg_wll_ExecStmt(ctx,"select dg_jobid from jobs",&s) < 0) goto abort;
- while ((res = edg_wll_FetchRow(s,&job_s)) > 0) {
- if (edg_wlc_JobIdParse(job_s,&job)) {
- fprintf(stderr,"%s: parse error (internal inconsistency !)\n",job_s);
- parse = 1;
- }
- else {
- edg_wll_JobStat stat;
-
- if (check_strict_jobid(ctx,job)) {
- edg_wlc_JobIdFree(job);
- free(job_s);
- parse = 1;
- continue;
- }
-
- memset(&stat,0,sizeof stat);
- if (edg_wll_JobStatus(ctx,job,0,&stat)) goto abort; /* XXX: memory leak */
-
- switch (stat.state) {
- case EDG_WLL_JOB_CLEARED:
- case EDG_WLL_JOB_ABORTED:
- case EDG_WLL_JOB_CANCELLED:
- i = stat.state;
- break;
- default:
- i = EDG_WLL_PURGE_JOBSTAT_OTHER;
- }
-
- if (now-stat.lastUpdateTime.tv_sec > timeout[i] && !check_strict_jobid(ctx,job))
- {
- if (purge_one(ctx,job,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE))
- goto abort;
-
- /* XXX: change with the streaming interface */
- if (request->flags & EDG_WLL_PURGE_LIST_JOBS) {
- result.jobs = realloc(result.jobs,(naffected_jobs+2) * sizeof(*result.jobs));
- result.jobs[naffected_jobs] = job_s;
- result.jobs[naffected_jobs+1] = NULL;
- job_s = NULL;
- }
- naffected_jobs++;
- }
-
- edg_wlc_JobIdFree(job);
- edg_wll_FreeStatus(&stat);
- free(job_s);
- }
- }
- edg_wll_FreeStmt(&s);
-abort:
- // just for escaping from nested cycles
- ; /* prevent compiler to complain */
- }
-
- if (parse && !edg_wll_Error(ctx,NULL,NULL))
- {
- if ( naffected_jobs ) {
- fprintf(stderr,"[%d] Found some jobs not matching server address/port;"\
- " these were not purged but other jobs purged.\n", getpid());
- syslog(LOG_INFO,"Found some jobs not matching server address/port;"\
- " these were not purged but other jobs purged");
- }
- else {
- fprintf(stderr,"[%d] Found only jobs not matching server address/port;"\
- " these were not purged.\n", getpid());
- syslog(LOG_INFO,"Found only jobs not matching server address/port;"\
- " these were not purged.");
- }
- }
-
- switch ( edg_wll_Error(ctx,NULL,NULL) )
- {
- case 0:
- ret = HTTP_OK;
- break;
- case EINVAL:
- ret = HTTP_INVALID;
- break;
- case EPERM:
- ret = HTTP_UNAUTH;
- break;
- case ENOENT:
- ret = HTTP_NOTFOUND;
- break;
-
- /* fatal errors */
- case ENOMEM:
- /* fall through */
- default:
- ret = HTTP_INTERNAL;
- break;
- }
-
- if (ret != HTTP_INTERNAL) {
- if ( request->flags & EDG_WLL_PURGE_SERVER_DUMP && tmpfname )
- {
- edg_wll_CreatePurgeFileFromTmp(ctx, tmpfname, &(result.server_file));
- unlink(tmpfname);
- }
-
- if ( edg_wll_PurgeResultToXML(ctx, &result, &message) )
- ret = HTTP_INTERNAL;
- else
- printf("%s", message);
- }
-
- if ( result.server_file )
- free(result.server_file);
- if ( result.jobs )
- {
- for ( i = 0; result.jobs[i]; i++ )
- free(result.jobs[i]);
- free(result.jobs);
- }
-
- asprintf(&response, "HTTP/1.1 %d %s", ret, edg_wll_HTTPErrorMessage(ret));
-
- edg_wll_http_send(ctx, response, resp_headers, message,ctx->connections->serverConnection);
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-static void unlock_and_check(edg_wll_Context ctx,edg_wlc_JobId job)
-{
- char *job_s,*et,*ed;
-
- if (edg_wll_UnlockJob(ctx,job)) {
- job_s = edg_wlc_JobIdUnparse(job);
-
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"%s: edg_wll_UnlockJob(): %s (%s) -- expect bogus things\n",
- job_s,et,ed);
- syslog(LOG_CRIT,"%s: edg_wll_UnlockJob(): %s (%s) -- expect bogus things",
- job_s,et,ed);
- free(et); free(ed); free(job_s);
- }
-}
-
-
-int purge_one(edg_wll_Context ctx,const edg_wlc_JobId job,int dump, int purge)
-{
- char *dbjob;
- char *stmt = NULL;
- edg_wll_Stmt q;
- int ret,dumped = 0;
-
- edg_wll_ResetError(ctx);
- if ( !purge && dump < 0 ) return 0;
-
- dbjob = edg_wlc_JobIdGetUnique(job); /* XXX: strict jobid already checked */
- if (edg_wll_LockJob(ctx,job)) goto clean;
-
- if ( purge )
- {
- trio_asprintf(&stmt,"delete from jobs where jobid = '%|Ss'",dbjob);
- ret = edg_wll_ExecStmt(ctx,stmt,NULL);
- if (ret <= 0) {
- unlock_and_check(ctx,job);
- if (ret == 0) {
- fprintf(stderr,"%s: no such job\n",dbjob);
- edg_wll_SetError(ctx,ENOENT,dbjob);
- }
- goto clean;
- }
- free(stmt); stmt = NULL;
-
- trio_asprintf(&stmt,"delete from states where jobid = '%|Ss'",dbjob);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
- unlock_and_check(ctx,job);
- goto clean;
- }
- free(stmt); stmt = NULL;
-
-/* Why on earth ?
- trio_asprintf(&stmt,"delete from states where jobid = '%|Ss'",dbjob);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
- unlock_and_check(ctx,job);
- goto clean;
- }
- free(stmt); stmt = NULL;
-*/
-
- }
-
- if (!ctx->strict_locking) unlock_and_check(ctx,job);
-
- if ( purge )
- {
- trio_asprintf(&stmt,"delete from status_tags where jobid = '%|Ss'",dbjob);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) goto unlock;
- free(stmt); stmt = NULL;
- }
-
- if (dump >= 0)
- trio_asprintf(&stmt,
- "select event,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived "
- "from events e,users u "
- "where e.jobid='%|Ss' "
- "and u.userid=e.userid "
- "order by event", dbjob);
- else
- trio_asprintf(&stmt,"select event from events "
- "where jobid='%|Ss' "
- "order by event", dbjob);
-
-/* check for events repeatedly -- new one may have arrived in the meantime */
- while ((ret = edg_wll_ExecStmt(ctx,stmt,&q)) > 0) {
- char *res[9];
-
- dumped = 1;
- while ((ret = edg_wll_FetchRow(q,res)) > 0) {
- int event;
-
- event = atoi(res[0]);
- free(res[0]); res[0] = NULL;
-
- if (dump >= 0) {
- edg_wll_Event e;
-
- assert(ret == 9);
- res[0] = edg_wlc_JobIdUnparse(job);
- if (convert_event_head(ctx,res,&e) || edg_wll_get_event_flesh(ctx,event,&e))
- {
- char *et,*ed;
- int i;
-
- /* Most likely sort of internal inconsistency.
- * Must not be fatal -- just complain
- */
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"%s event %d: %s (%s)\n",dbjob,event,et,ed);
- syslog(LOG_WARNING,"%s event %d: %s (%s)",dbjob,event,et,ed);
- free(et); free(ed);
- for (i=0; i<sizofa(res); i++) free(res[i]);
- edg_wll_ResetError(ctx);
- }
- else {
- char *event_s = edg_wll_UnparseEvent(ctx,&e);
- char arr_s[100];
- int len, written, total;
-
- strcpy(arr_s, "DG.ARRIVED=");
- edg_wll_ULMTimevalToDate(e.any.arrived.tv_sec,
- e.any.arrived.tv_usec,
- arr_s+strlen("DG.ARRIVED="));
-
- len = strlen(arr_s);
- total = 0;
- while (total != len) {
- written = write(dump,arr_s+total,len-total);
- if (written < 0 && errno != EAGAIN) {
- edg_wll_SetError(ctx,errno,"writing dump file");
- free(event_s);
- goto clean;
- }
- total += written;
- }
- write(dump, " ", 1);
-
- len = strlen(event_s);
- total = 0;
- while (total != len) {
- written = write(dump,event_s+total,len-total);
- if (written < 0 && errno != EAGAIN) {
- perror("dump to file");
- syslog(LOG_ERR,"dump to file: %m");
- dump = -1; /* XXX: likely to be a permanent error
- * give up writing but do purge */
- break;
- }
- total += written;
- }
- /* write(dump,"\n",1); edg_wll_UnparseEvent does so */
- free(event_s);
- }
- edg_wll_FreeEvent(&e);
- }
-
- if ( purge ) {
- if (edg_wll_delete_event(ctx,dbjob,event)) {
- char *et,*ed;
-
- /* XXX: just complain and carry on. Is it OK? */
- edg_wll_Error(ctx,&et,&ed);
- fprintf(stderr,"%s event %d: %s (%s)\n",dbjob,event,et,ed);
- syslog(LOG_WARNING,"%s event %d: %s (%s)",dbjob,event,et,ed);
- free(et); free(ed);
- edg_wll_ResetError(ctx);
- }
- }
- }
- edg_wll_FreeStmt(&q);
- if (ret < 0 || !purge) break;
- }
-
- edg_wll_FreeStmt(&q);
-
-unlock:
- if (ctx->strict_locking) unlock_and_check(ctx,job);
-
-clean:
- free(dbjob);
- free(stmt);
- return edg_wll_Error(ctx,NULL,NULL);
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <unistd.h>
-#include <sys/file.h>
-#include <sys/mman.h>
-#include <string.h>
-#include <assert.h>
-#include <stdio.h>
-
-#include "glite/lb/events.h"
-#include "glite/lb/jobstat.h"
-#include "glite/lb/context-int.h"
-
-#include "glite/wmsutils/jobid/strmd5.h"
-
-#include "stats.h"
-static int stats_inc_counter(edg_wll_Context,const edg_wll_JobStat *,edg_wll_Stats *);
-static int stats_record_duration(edg_wll_Context,const edg_wll_JobStat *,const edg_wll_JobStat *,edg_wll_Stats *);
-
-#define dprintf(x) { printf("[%d] ",getpid()); printf x; }
-
-/* XXX: should be configurable at run time */
-static struct _edg_wll_StatsArchive default_archives[] = {
- { 10, 60 },
- { 60, 30 },
- { 900, 12 },
- { 0, 0 }
-};
-
-static edg_wll_QueryRec default_group[2] = {
- { EDG_WLL_QUERY_ATTR_DESTINATION, },
- { EDG_WLL_QUERY_ATTR_UNDEF, }
-};
-
-static edg_wll_Stats default_stats[] = {
- { STATS_COUNT, default_group, EDG_WLL_JOB_READY, 0, default_archives },
- { STATS_COUNT, default_group, EDG_WLL_JOB_SCHEDULED, 0, default_archives },
- { STATS_COUNT, default_group, EDG_WLL_JOB_RUNNING, 0, default_archives },
- { STATS_COUNT, default_group, EDG_WLL_JOB_DONE, EDG_WLL_STAT_OK, default_archives },
- { STATS_COUNT, default_group, EDG_WLL_JOB_DONE, EDG_WLL_STAT_FAILED, default_archives },
- { STATS_DURATION, default_group, EDG_WLL_JOB_SCHEDULED, 0, default_archives },
- { STATS_DURATION, default_group, EDG_WLL_JOB_RUNNING, 0, default_archives },
- { STATS_UNDEF, }
-
-};
-
-int edg_wll_InitStatistics(edg_wll_Context ctx)
-{
- edg_wll_Stats *stats = default_stats; /* XXX: hardcoded */
- int i,j;
-
- for (i=0; stats[i].type; i++) {
- char fname[50],*zero;
-
- strcpy(fname,"/tmp/lb_stats.XXXXXX");
- stats[i].fd = mkstemp(fname);
- if (stats[i].fd < 0) return edg_wll_SetError(ctx,errno,fname);
- /* XXX: should be initialized from LB data */
- stats[i].grpno = 0;
-
- stats[i].grpsize = sizeof(struct edg_wll_stats_group)-sizeof(struct edg_wll_stats_archive);
-
- for (j=0; stats[i].archives[j].interval; j++) {
- stats[i].grpsize += sizeof(struct edg_wll_stats_archive)-sizeof(struct edg_wll_stats_cell);
- stats[i].grpsize += stats[i].archives[j].length * sizeof(struct edg_wll_stats_cell);
- }
- zero = calloc(1,stats[i].grpsize);
- write(stats[i].fd,zero,stats[i].grpsize);
- stats[i].map = mmap(NULL,sizeof zero,PROT_READ|PROT_WRITE,MAP_SHARED,stats[i].fd,0);
- if (stats[i].map == MAP_FAILED) return edg_wll_SetError(ctx,errno,"mmap()");
-
- dprintf(("stats: using %s\n",fname));
- unlink(fname);
- }
- return 0;
-}
-
-int edg_wll_UpdateStatistics(
- edg_wll_Context ctx,
- const edg_wll_JobStat *from,
- const edg_wll_Event *e,
- const edg_wll_JobStat *to)
-{
- int i;
-
- /* XXX: should be propagated somhow via context, not hardcoded */
- edg_wll_Stats *stats = default_stats;
-
- if (!ctx->count_statistics) return 0;
-
- for (i=0; stats[i].type; i++) switch (stats[i].type) {
- case STATS_COUNT:
- if (!to) continue;
- if (to->state == stats[i].major && (!from || from->state != to->state)) {
- switch (to->state) {
- case EDG_WLL_JOB_DONE:
- if (to->done_code != stats[i].minor) continue;
- break;
- default: break;
- }
- stats_inc_counter(ctx,to,stats+i);
- }
- break;
- case STATS_DURATION:
- if (!to || !from) continue;
- if (from->state == stats[i].major && from->state != to->state)
- stats_record_duration(ctx,from,to,stats+i);
- default: break;
- }
- return 0;
-}
-
-static struct edg_wll_stats_archive *archive_skip(
- const struct edg_wll_stats_archive *a,
- int len)
-{
- return (struct edg_wll_stats_archive *)
- (((char *) a) + sizeof(struct edg_wll_stats_archive)
- - sizeof(struct edg_wll_stats_cell)
- + len * sizeof(struct edg_wll_stats_cell)
- );
-}
-
-static int stats_inc_counter(edg_wll_Context ctx,const edg_wll_JobStat *jobstat,edg_wll_Stats *stats)
-{
- int i,j;
- char *sig;
- struct edg_wll_stats_group *g;
- struct edg_wll_stats_archive *a;
- time_t now = jobstat->stateEnterTime.tv_sec;
-
- /* XXX: we support destination grouping only */
- if (!jobstat->destination) return 0;
- edg_wll_ResetError(ctx);
-
- dprintf(("inc_counter: destination %s, stats %d\n",jobstat->destination,
- (int) (stats - (edg_wll_Stats *) default_stats)));
-
- if (flock(stats->fd,LOCK_EX)) return edg_wll_SetError(ctx,errno,"flock()");
-
- /* remap the file if someone changed its size */
- if (stats->map->grpno != stats->grpno) {
- int newgrpno = stats->map->grpno;
- munmap(stats->map,(stats->grpno ? stats->grpno : 1) * stats->grpsize);
- stats->map = mmap(NULL,newgrpno * stats->grpsize,
- PROT_READ|PROT_WRITE,MAP_SHARED,stats->fd,0);
- if (stats->map == MAP_FAILED) {
- edg_wll_SetError(ctx,errno,"mmap()");
- goto cleanup;
- }
- assert(stats->map->grpno == newgrpno);
- stats->grpno = newgrpno;
- }
-
- sig = str2md5base64(jobstat->destination);
-
- for (i=0; i<stats->grpno; i++) {
- g = (struct edg_wll_stats_group *) (
- ((char *) stats->map) + stats->grpsize * i
- );
- if (!strcmp(sig,g->sig)) break;
- }
-
- /* not found, initialize new */
- if (i == stats->grpno) {
- dprintf(("group %s not found\n",sig));
- if (stats->grpno) {
- char *zero = calloc(1,stats->grpsize);
- munmap(stats->map,stats->grpno * stats->grpsize);
- lseek(stats->fd,0,SEEK_END);
- write(stats->fd,zero,stats->grpsize);
- free(zero);
- stats->map = mmap(NULL,stats->grpno * stats->grpsize,
- PROT_READ|PROT_WRITE,MAP_SHARED,stats->fd,0);
-
- if (stats->map == MAP_FAILED) {
- edg_wll_SetError(ctx,errno,"mmap()");
- goto cleanup;
- }
- }
- stats->grpno++;
- stats->map->grpno++;
- dprintf(("allocated\n"));
-
- g = (struct edg_wll_stats_group *) (
- ((char *) stats->map) + stats->grpsize * i);
-
- /* invalidate all cells in all archives */
- a = g->archive;
- for (i=0; stats->archives[i].interval; i++) {
- for (j=0; j<stats->archives[i].length; j++) a->cells[j].cnt = -1;
- a = archive_skip(a,stats->archives[i].length);
- }
-
- strcpy(g->sig,sig);
- g->last_update = now;
- }
- else dprintf(("group %s found at %d\n",sig,i));
-
- a = g->archive;
- for (i=0; stats->archives[i].interval; i++) {
- time_t pt = g->last_update;
-
- pt -= pt % stats->archives[i].interval;
-
- /* nothing happened longer than is history of this archive */
- if (now-pt > stats->archives[i].interval * stats->archives[i].length) {
- for (j=0; j<stats->archives[i].length; j++) a->cells[j].cnt = 0;
- a->ptr = 0;
- }
- /* catch up eventually, cleaning not touched cells */
- else for (pt += stats->archives[i].interval; pt < now;
- pt += stats->archives[i].interval)
- {
- if (++(a->ptr) == stats->archives[i].length) a->ptr = 0;
- a->cells[a->ptr].cnt = 0;
- }
-
- /* validate an unused cell */
- if (a->cells[a->ptr].cnt < 0) a->cells[a->ptr].cnt = 0;
-
- /* now we can do IT */
- a->cells[a->ptr].cnt++;
- dprintf(("update archive %d, cell %d to %d\n",i,a->ptr,a->cells[a->ptr].cnt));
-
- /* go to next archive */
- a = archive_skip(a,stats->archives[i].length);
- }
-
- g->last_update = now;
-
-
-cleanup:
- free(sig);
- flock(stats->fd,LOCK_UN);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-static int stats_record_duration(
- edg_wll_Context ctx,
- const edg_wll_JobStat *from,
- const edg_wll_JobStat *to,
- edg_wll_Stats *stats)
-{
- return 0;
-}
-
-int edg_wll_StateRateServer(
- edg_wll_Context ctx,
- const edg_wll_QueryRec *group,
- edg_wll_JobStatCode major,
- int minor,
- time_t *from,
- time_t *to,
- float *rate,
- int *res_from,
- int *res_to
-)
-{
- edg_wll_Stats *stats = default_stats; /* XXX: hardcoded */
- struct edg_wll_stats_group *g;
- struct edg_wll_stats_archive *a;
- int i,j,matchi;
- char *sig = NULL;
- time_t afrom,ato;
- long match;
-
- edg_wll_ResetError(ctx);
-
- switch (ctx->count_statistics) {
- case 0: return edg_wll_SetError(ctx,ENOSYS,NULL);
- case 1: if (!ctx->noAuth) return edg_wll_SetError(ctx,EPERM,NULL);
- break;
- case 2: break;
- default: abort();
- }
-
- if (group[0].attr != EDG_WLL_QUERY_ATTR_DESTINATION
- || group[1].attr != EDG_WLL_QUERY_ATTR_UNDEF)
- return edg_wll_SetError(ctx,ENOSYS,
- "the only supported grouping is by destination");
-
- if (*from >= *to) return edg_wll_SetError(ctx,EINVAL,"from >= to");
-
- for (;stats->type; stats++) {
- if (stats->type != STATS_COUNT || stats->major != major) continue;
- switch (major) {
- case EDG_WLL_JOB_DONE:
- if (stats->minor != minor) continue;
- break;
- default: break;
- }
- break;
- }
-
- if (!stats->type) return edg_wll_SetError(ctx,ENOENT,"no matching state counter");
-
- if (flock(stats->fd,LOCK_SH)) return edg_wll_SetError(ctx,errno,"flock()");
-
- /* XXX */
- sig = str2md5base64(group->value.c);
-
-
- for (i=0, g=stats->map; i<stats->grpno; i++) {
- if (!strcmp(sig,g->sig)) break;
- g = (struct edg_wll_stats_group *) (((char *) g) + stats->grpsize);
- }
-
- if (i == stats->grpno) {
- edg_wll_SetError(ctx,ENOENT,"no matching group");
- goto cleanup;
- }
-
- match = 0;
- matchi = -1;
- /* XXX: assumes decreasing resolution of archives */
- for (j=0; stats->archives[j].interval; j++) {
- afrom = ato = g->last_update;
-
- ato += stats->archives[j].interval - ato % stats->archives[j].interval;
- afrom -= afrom % stats->archives[j].interval;
- afrom -= stats->archives[j].interval * (stats->archives[j].length-1);
-
- /* intersection of [from,to] and [afrom,ato] */
- if (afrom < *from) afrom = *from;
- if (ato > *to) ato = *to;
-
- /* find the best match */
- if (ato-afrom > match) {
- match = ato - afrom;
- matchi = j;
- }
- }
-
- dprintf(("best match: archive %d, interval %ld\n",matchi,match));
-
- if (matchi < 0) {
- if (*from > g->last_update) {
- /* special case -- we are sure that nothing arrived */
- *rate = 0;
- *res_from = *res_to = stats->archives[0].interval;
- goto cleanup;
- }
- edg_wll_SetError(ctx,ENOENT,"no data available");
- goto cleanup;
- }
-
- *res_from = *res_to = stats->archives[matchi].interval;
-
- a = g->archive;
- for (j=0; j<matchi; j++) a = archive_skip(a,stats->archives[j].length);
-
- i = stats->archives[matchi].interval;
- afrom = g->last_update - g->last_update % i
- - (stats->archives[matchi].length-1)*i;
-
- dprintf(("archive from %ld = %s",afrom,ctime(&afrom)));
-
- if (afrom > *from) *from = afrom;
- if (afrom + stats->archives[matchi].length * i < *to) *to = afrom + stats->archives[matchi].length * i;
-
- *rate = 0;
- match = 0;
-
-
- for (j=0; j<stats->archives[matchi].length; j++,afrom += i) {
- struct edg_wll_stats_cell *c = a->cells + ((a->ptr+j+1) % stats->archives[matchi].length);
-
- dprintf(("cell %d (abs %d): ",j,(a->ptr+j+1) % stats->archives[matchi].length));
- if (c->cnt < 0) {
- dprintf(("invalid\n"));
- continue; /* invalid cell */
- }
-
- dprintf(("search %ld in %ld, %ld\n",*from,afrom,afrom+i));
-
- if (*from >= afrom && *from < afrom+i) {
- match += *from - afrom;
- *rate += c->cnt * (1.0 - ((float) *from-afrom)/i);
- dprintf(("matched from: match %ld, rate %f\n",match,*rate));
- }
- else if (*from < afrom && *to >= afrom) {
- match += i;
- *rate += c->cnt;
- dprintf(("matched in: match %ld, rate %f\n",match,*rate));
- }
-
- if (*to >= afrom && *to < afrom+i) {
- match -= i-(*to-afrom);
- *rate -= c->cnt * (((float) i)-(*to - afrom))/i;
-
- dprintf(("matched to: match %ld, rate %f\n",match,*rate));
-
- /* asi blbost
- if (j == stats->archives[matchi].length - 1
- && *to > g->last_update)
- {
- match -= *to - g->last_update;
- *rate -= c->cnt * (((float) *to) - g->last_update)/i;
- dprintf(("corrected wrt. last_update: match %ld, rate %f\n",match,*rate));
- }
- */
-
- break;
- }
- }
- *rate /= match;
-
-cleanup:
- free(sig);
- flock(stats->fd,LOCK_UN);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-int edg_wll_StateDurationServer(
- edg_wll_Context ctx,
- const edg_wll_QueryRec *group,
- edg_wll_JobStatCode major,
- int minor,
- time_t *from,
- time_t *to,
- float *duration,
- int *res_from,
- int *res_to
-)
-{
- return edg_wll_SetError(ctx,ENOSYS,NULL);
-}
-
+++ /dev/null
-#ifndef __EDG_WORKLOAD_LOGGING_LBSERVER_STATS_H__
-#define __EDG_WORKLOAD_LOGGING_LBSERVER_STATS_H__
-
-int edg_wll_InitStatistics(edg_wll_Context);
-
-int edg_wll_UpdateStatistics(
- edg_wll_Context,
- const edg_wll_JobStat *,
- const edg_wll_Event *,
- const edg_wll_JobStat *);
-
-
-struct edg_wll_stats_cell {
- int cnt;
- float value;
-};
-
-struct edg_wll_stats_archive {
- int ptr;
- struct edg_wll_stats_cell cells[1];
-};
-
-struct edg_wll_stats_group {
- int grpno;
- char sig[33];
- time_t last_update;
- struct edg_wll_stats_archive archive[1];
-};
-
-
-typedef struct {
- enum { STATS_UNDEF = 0, STATS_COUNT, STATS_DURATION } type;
- edg_wll_QueryRec *group;
- edg_wll_JobStatCode major;
- int minor;
- struct _edg_wll_StatsArchive {
- int interval,length;
- } *archives;
-
- int fd;
- struct edg_wll_stats_group *map;
- int grpno,grpsize;
-} edg_wll_Stats;
-
-int edg_wll_StateRateServer(
- edg_wll_Context context,
- const edg_wll_QueryRec *group,
- edg_wll_JobStatCode major,
- int minor,
- time_t *from,
- time_t *to,
- float *rate,
- int *res_from,
- int *res_to
-);
-
-
-int edg_wll_StateDurationServer(
- edg_wll_Context context,
- const edg_wll_QueryRec *group,
- edg_wll_JobStatCode major,
- int minor,
- time_t *from,
- time_t *to,
- float *duration,
- int *res_from,
- int *res_to
-);
-
-#endif
+++ /dev/null
-#ident "$Header$"
-
-/*
-
-@@@AUTO
-
- * XXX: still lots of hardcoded stuff
- * there's mapping db.column <-> event struct field
- */
-
-@@@LANG: C
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include <errno.h>
-#include <syslog.h>
-
-#include <globus_config.h>
-
-#include "glite/wmsutils/jobid/strmd5.h"
-
-#include "glite/lb/events_parse.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/producer.h"
-#include "glite/lb/log_proto.h" /* for EDG_WLL_LOG_USER_DEFAULT */
-#include "glite/lb/trio.h"
-
-#include "store.h"
-#include "get_events.h"
-#include "lbs_db.h"
-#include "lock.h"
-#include "lb_authz.h"
-#include "jobstat.h"
-
-static int store_user(edg_wll_Context,const char *,const char *);
-static int store_job(edg_wll_Context,const edg_wlc_JobId,const char *);
-#ifdef LB_BUF
-static int store_job_block(edg_wll_Context, const edg_wlc_JobId, const char *, edg_wll_bufInsert *);
-#endif
-static int store_job_grey(edg_wll_Context,const edg_wlc_JobId,time_t);
-static int store_flesh(edg_wll_Context,edg_wll_Event *,char *,int);
-static int store_seq(edg_wll_Context,edg_wll_Event *,int);
-static int check_dup(edg_wll_Context,edg_wll_Event *);
-static int check_auth(edg_wll_Context,edg_wll_Event *e);
-#ifndef LB_DAG_EMBRIONIC
-static int register_subjobs(edg_wll_Context,const edg_wll_RegJobEvent *);
-#endif
-static int register_subjobs_embryonic(edg_wll_Context,const edg_wll_RegJobEvent *);
-
-void edg_wll_StoreAnonymous(edg_wll_Context ctx,int anon) {
- ctx->allowAnonymous = anon;
-}
-
-int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,int *seq)
-{
- edg_wll_ErrorCode err = 0;
- char *userid = NULL,*jobid,*stmt;
- char *select_max,*ssrc;
- edg_wll_Stmt sh = NULL;
- int next = 0xDEAD;
- int lbproxy_notreg = 0;
- char *now_s = NULL;
-
- ssrc = jobid = stmt = select_max = NULL;
-
- if ( ctx->event_load )
- now_s = strdup(edg_wll_TimeToDB(e->any.arrived.tv_sec));
- else
- now_s = strdup(edg_wll_TimeToDB(time(NULL)));
-
- edg_wll_ResetError(ctx);
- switch (err = check_auth(ctx,e)) {
- case 0: break;
- case ENOENT:
- if ( !ctx->isProxy ) {
- if (ctx->greyjobs) {
- edg_wll_ResetError(ctx);
- if (store_job_grey(ctx,e->any.jobId,e->any.timestamp.tv_sec))
- goto clean;
- break;
- }
- else goto clean;
- }
-
- edg_wll_ResetError(ctx);
- lbproxy_notreg = 1;
- break;
- case EPERM:
- if (!ctx->noAuth) goto clean;
- edg_wll_ResetError(ctx);
- break;
- default: goto clean;
- }
-
-/* FIXME: does not work for grey jobs due to "select from jobs" -- I don't care for the time being */
- if ((err = check_dup(ctx,e))) goto clean;
-
- userid = strdup(strmd5(e->any.user,NULL));
-
- if ((e->type == EDG_WLL_EVENT_REGJOB || lbproxy_notreg)) {
- /* Register the job and owner. For LBproxy, contant "lbproxy"
- is used as the name - it's harmless as the job is already
- registered with LBserver */
- char *username;
-
- username = (ctx->isProxy) ? "lbproxy" : ctx->peerName;
- userid = strdup(strmd5(username, NULL));
- if ((err = store_user(ctx,userid, username))) goto clean;
- if ((err = store_job(ctx,e->any.jobId,userid))) goto clean;
- } else {
- /* for other events just make sure user record is there */
- userid = strdup(strmd5(e->any.user,NULL));
- if ((err = store_user(ctx,userid,e->any.user))) goto clean;
- }
-
- jobid = edg_wlc_JobIdGetUnique(e->any.jobId);
-
-/* obtain next event sequence number */
- trio_asprintf(&select_max,
- "select max(event) from events "
- "where jobid = '%|Ss'",jobid);
-
- ssrc = edg_wll_SourceToString(e->any.source);
-
-/* try to insert (someone else may be doing the same) */
- while (1) {
- char *max;
-
- if (edg_wll_ExecStmt(ctx,select_max,&sh) < 0 ||
- edg_wll_FetchRow(sh,&max) < 0)
- {
- err = edg_wll_Error(ctx,NULL,NULL);
- goto clean;
- }
- edg_wll_FreeStmt(&sh);
-
- next = max && *max ? atoi(max)+1 : 0;
-
- /*
- * 1) when using transactions:
- * Store the whole event right now.
- *
- * 2) when not using transaction:
- * Store an UNDEF event first in order to prevent race condition
- * with readers and update event code later.
- */
- trio_asprintf(&stmt,
- "insert into events(jobid,event,code,prog,host,time_stamp,usec,arrived,level,userid) "
- "values ('%|Ss',%d,%d,'%|Ss','%|Ss',%s,%d,%s,%d,'%|Ss')",
- jobid,next,
- ctx->use_transactions ? (int) e->any.type : EDG_WLL_EVENT_UNDEF,
- ssrc,e->any.host,
- edg_wll_TimeToDB(e->any.timestamp.tv_sec),e->any.timestamp.tv_usec,
- now_s, e->any.level,userid);
-
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
- if ((err = edg_wll_Error(ctx,NULL,NULL)) != EEXIST)
- goto clean;
- } else break; /* successful insert */
-
- /* we were late -- try once again */
- free(stmt);
- }
-
- free(stmt); stmt = NULL;
- if ((err = store_seq(ctx,e,next)) ||
- (err = store_flesh(ctx,e,jobid,next))) {
- /* attempt to cleanup, ignore new errors */
- char *desc;
- edg_wll_ErrorCode oerr = edg_wll_Error(ctx,NULL,&desc);
-
- edg_wll_delete_event(ctx,jobid,next);
- edg_wll_SetError(ctx,oerr,desc);
- free(desc);
- } else
- if (!ctx->use_transactions) {
- /* emulate commit, i.e. swith to a real event type to make
- * the record valid */
- trio_asprintf(&stmt,
- "update events set code=%d "
- "where jobid='%|Ss' and event=%d",
- (int) e->any.type,jobid,next);
- switch (edg_wll_ExecStmt(ctx,stmt,NULL)) {
- case 0: if (ctx->strict_locking)
- err = edg_wll_SetError(ctx,ENOENT,"event disappeared on store while strict locking");
- /* purge in progres: drop the garbage, ignore errors */
- else {
- edg_wll_delete_event(ctx,jobid,next);
- err = edg_wll_SetError(ctx,ENOENT,"job being purged");
- }
- break;
- case 1: if (ctx->strict_locking) err = 0;
- else {
- /* check whether the job is still there to prevent garbage
- * left while there is a concurrent purge
- */
- free(stmt);
- trio_asprintf(&stmt,
- "select 'x' from jobs where jobid='%|Ss'",
- jobid);
- switch (edg_wll_ExecStmt(ctx,stmt,NULL)) {
- case 1: break;
- case 0: /* purge in progres */
- edg_wll_delete_event(ctx,jobid,next);
- err = edg_wll_SetError(ctx,ENOENT,"job being purged");
- break;
- default: err = edg_wll_SetError(ctx,EDG_WLL_ERROR_DB_CALL,
- "more job records, what is that?");
- break;
- }
- }
- break;
- case -1: err = edg_wll_Error(ctx,NULL,NULL);
- break;
-
- default: err = edg_wll_SetError(ctx,EDG_WLL_ERROR_DB_CALL,
- "more event records, what is that?");
- break;
- }
- } /* if !ctx->use_transactions */
-
- if (err == 0 &&
- e->any.type == EDG_WLL_EVENT_REGJOB &&
- (e->regJob.jobtype == EDG_WLL_REGJOB_DAG ||
- e->regJob.jobtype == EDG_WLL_REGJOB_PARTITIONED ||
- e->regJob.jobtype == EDG_WLL_REGJOB_COLLECTION) &&
- e->regJob.nsubjobs > 0)
-
-#ifdef LB_DAG_EMBRIONIC
- err = register_subjobs_embryonic(ctx,&e->regJob);
-#else
- err = register_subjobs(ctx,&e->regJob);
-#endif
-
-
-clean:
- free(now_s);
- free(userid);
- free(jobid);
- free(stmt);
- free(ssrc);
- free(select_max);
- if (sh) edg_wll_FreeStmt(&sh);
- if (!err && seq) *seq = next;
- return err;
-}
-
-static int store_user(edg_wll_Context ctx,const char *userid,const char *subj)
-{
- char *stmt;
-
- trio_asprintf(&stmt,"insert into users(userid,cert_subj) "
- "values ('%|Ss','%|Ss')",userid,subj);
-
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
- if (edg_wll_Error(ctx,NULL,NULL) == EEXIST)
- edg_wll_ResetError(ctx);
- }
-
- free(stmt);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-static int store_job(edg_wll_Context ctx,const edg_wlc_JobId job,const char *userid)
-{
- char *jobstr = edg_wlc_JobIdUnparse(job);
- char *jobid = edg_wlc_JobIdGetUnique(job);
- char *stmt;
-
-/* debug Duplicate key on index: Duplicate entry '(nil)' for key 1
- */
- if (jobid == NULL || jobstr == NULL)
- return edg_wll_SetError(ctx,EINVAL,"store_job()");
-
- edg_wll_ResetError(ctx);
- trio_asprintf(&stmt,"insert into jobs(jobid,dg_jobid,userid) "
- "values ('%|Ss','%|Ss','%|Ss')",jobid,jobstr,userid);
-
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
- if (edg_wll_Error(ctx,NULL,NULL) == EEXIST)
- edg_wll_ResetError(ctx);
- }
- free(stmt);
-
- if (ctx->greyjobs) {
- trio_asprintf(&stmt,"delete from grey_jobs where jobid = '%|Ss'",jobid);
- edg_wll_ExecStmt(ctx,stmt,NULL); /* XXX: error propagates */
- free(stmt);
- }
-
- free(jobstr);
- free(jobid);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-#ifdef LB_BUF
-static int store_job_block(edg_wll_Context ctx,const edg_wlc_JobId job,const char *userid, edg_wll_bufInsert *bi)
-{
- char *jobstr = edg_wlc_JobIdUnparse(job);
- char *jobid = edg_wlc_JobIdGetUnique(job);
- char *row;
-
-/* debug Duplicate key on index: Duplicate entry '(nil)' for key 1
- */
-
- assert(!ctx->greyjobs); /* XXX: should not happen */
-
- if (jobid == NULL || jobstr == NULL)
- return edg_wll_SetError(ctx,EINVAL,"store_jobi_block()");
-
- edg_wll_ResetError(ctx);
-
- trio_asprintf(&row, "'%|Ss','%|Ss','%|Ss'", jobid,jobstr,userid);
- edg_wll_bufferedInsert(bi, row); // no need to free row
-
- free(jobstr);
- free(jobid);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-#endif
-
-static int store_job_grey(edg_wll_Context ctx,const edg_wlc_JobId job,time_t etime)
-{
- char *jobstr = edg_wlc_JobIdUnparse(job);
- char *jobid = edg_wlc_JobIdGetUnique(job);
- char *stmt;
-
- if (jobid == NULL || jobstr == NULL)
- return edg_wll_SetError(ctx,EINVAL,"store_job_grey()");
-
- edg_wll_ResetError(ctx);
- trio_asprintf(&stmt,"insert into grey_jobs(jobid,dg_jobid,time_stamp) "
- "values ('%|Ss','%|Ss',%s)",
- jobid,jobstr,edg_wll_TimeToDB(etime));
-
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) {
- if (edg_wll_Error(ctx,NULL,NULL) == EEXIST)
- edg_wll_ResetError(ctx);
- }
-
- free(stmt);
- free(jobstr);
- free(jobid);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-/*
- * XXX: store it in SHORT_FIELDS for now despite it should go to dedicated
- * column in EVENTS.
- *
- * don't want to change the database structure now, will be done anyway
- * soon
- */
-static int store_seq(edg_wll_Context ctx,edg_wll_Event *e,int no)
-{
- int ret;
- char *stmt;
- char *jobid = edg_wlc_JobIdGetUnique(e->any.jobId);
-
- edg_wll_ResetError(ctx);
- trio_asprintf(&stmt,"insert into short_fields(jobid,event,name,value) "
- "values ('%|Ss',%d,'SEQCODE','%|Ss')",
- jobid,no,e->any.seqcode);
-
- ret = edg_wll_ExecStmt(ctx,stmt,NULL);
- free(stmt);
- free(jobid);
-
- return ret>=0 ? 0 : edg_wll_Error(ctx,NULL,NULL);
-}
-
-#define SHORT_LEN 255 /* short_fiels.value db column lenght */
-
-static int store_flesh(edg_wll_Context ctx,edg_wll_Event *e,char *jobid,int no)
-{
- struct {
- char *key;
- char *val;
- } f[20];
-
- char *stmt;
- unsigned int i;
- int err = 0;
-
- edg_wll_ResetError(ctx);
- memset(f,0,sizeof(f)); assert(f[0].key == NULL);
-
- switch (e->type) {
-@@@{
- for my $type (getTypesOrdered $event) {
- next if $type eq '_common_';
- selectType $event $type;
- my $uctype = uc $type;
- my $flctype = lcfirst $type;
- if ($flctype =~ m/^pBS/) { $flctype = ucfirst $flctype; }
- if ($flctype =~ m/^condor/) { $flctype = ucfirst $flctype; }
- gen qq{
-! case EDG_WLL_EVENT_$uctype:
-};
- my $idx = 0;
- for (getFieldsOrdered $event) {
- my $f = selectField $event $_;
- my $name = getName $f;
- my $ucname = uc $name;
- my $fucname = ucfirst $name;
- my $tos = $f->{codes} ?
- "f[$idx].val = edg_wll\_$type${fucname}ToString(e->$flctype.$name);" :
- toString $f "e->$flctype.$name","f[$idx].val";
- gen qq{
-! f[$idx].key = "$ucname";
-! $tos
-};
- $idx++;
- }
- gen qq{
-! assert($idx<sizeof f/sizeof f[0]);
-! break;
-};
- }
-@@@}
- default:
- break;
- }
-
- for (i=0; i<sizeof(f)/sizeof(f[0]) && !err; i++) if (f[i].key && f[i].val) {
- trio_asprintf(&stmt,"insert into %s(jobid,event,name,value) "
- "values ('%|Ss',%d,'%|Ss','%|Ss')",
- strlen(f[i].val) <= SHORT_LEN ? "short_fields" : "long_fields",
- jobid,no,f[i].key,f[i].val);
-
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL);
- free(stmt);
- }
- for (i=0; i<sizeof(f)/sizeof(f[0]); i++) free(f[i].val);
-
-/* XXX: hardcoded, no other suitable place to store it */
- if (!err) {
- trio_asprintf(&stmt,"insert into short_fields(jobid,event,name,value) "
- "values ('%|Ss',%d,'SRC_INSTANCE','%|Ss')",
- jobid,no,e->any.src_instance);
- if (edg_wll_ExecStmt(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL);
- free(stmt);
- }
-
- return err;
-}
-
-static int check_dup(edg_wll_Context ctx,edg_wll_Event *e)
-{
- int i,dup_detected = 0;
- int err;
- char *es,*es2;
- edg_wll_QueryRec jc[2],ec[2];
- edg_wll_QueryRec **jca, **eca;
- edg_wll_Event *e2;
-
- edg_wll_ResetError(ctx);
-
- jc[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
- jc[0].value.j = e->any.jobId;
- jc[0].op = EDG_WLL_QUERY_OP_EQUAL;
- jc[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
-
- ec[0].attr = EDG_WLL_QUERY_ATTR_TIME;
- memcpy(&ec[0].value.t,&e->any.timestamp,sizeof(struct timeval));
- ec[0].op = EDG_WLL_QUERY_OP_EQUAL;
- ec[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
-
- jca = (edg_wll_QueryRec **) malloc (2 * sizeof(edg_wll_QueryRec **));
- eca = (edg_wll_QueryRec **) malloc (2 * sizeof(edg_wll_QueryRec **));
- jca[0] = jc;
- jca[1] = NULL;
- eca[0] = ec;
- eca[1] = NULL;
-
- err = edg_wll_QueryEventsServer(ctx,1,(const edg_wll_QueryRec **)jca,
- (const edg_wll_QueryRec **)eca,&e2);
- switch (err) {
- case 0: /* continue normally */
- break;
- case ENOENT:
- free(jca);
- free(eca);
- return edg_wll_ResetError(ctx);
- break;
- default:
- free(jca);
- free(eca);
- return edg_wll_Error(ctx,NULL,NULL);
- break;
- }
-
- es = edg_wll_UnparseEvent(ctx,e);
- assert(es);
-
- for (i=0;e2[i].type && !dup_detected;i++) {
- /* Ignore priority */
- e2[i].any.priority = e->any.priority;
- es2 = edg_wll_UnparseEvent(ctx,e2+i);
- assert(es2);
- if (!strcmp(es,es2)) {
- dup_detected = 1;
- edg_wll_SetError(ctx,EEXIST,"duplicate event");
- }
- free(es2);
- }
-
- free(jca);
- free(eca);
- free(es);
- for (i=0; e2[i].type; i++) edg_wll_FreeEvent(e2+i);
- free(e2);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-static int check_auth(edg_wll_Context ctx,edg_wll_Event *e)
-{
- char *jobid = edg_wlc_JobIdGetUnique(e->any.jobId);
- char *q = NULL,*owner = NULL;
- edg_wll_Stmt stmt = NULL;
- char *user;
-
- edg_wll_ResetError(ctx);
-
- if (e->type == EDG_WLL_EVENT_REGJOB)
- return strcmp(e->any.user,EDG_WLL_LOG_USER_DEFAULT) ?
- 0 : edg_wll_SetError(ctx,EPERM,"can't register jobs anonymously");
-
- trio_asprintf(&q,"select userid from jobs where jobid='%|Ss'",jobid);
-
- if (edg_wll_ExecStmt(ctx,q,&stmt) < 0
- || edg_wll_FetchRow(stmt,&owner) < 0
- ) goto clean;
-
- if (!owner) {
- if ( ctx->isProxy && !e->any.seqcode )
- edg_wll_SetError(ctx, EINVAL, "Job not registered - sequence code needed");
- else
- /* We have to let the calling function know what happened here
- * even if it hapens inside the LB Proxy which shouldn't consider
- * this as an error
- */
- edg_wll_SetError(ctx, ENOENT, "job not registered");
- goto clean;
- }
-
- switch (e->any.source) {
- case EDG_WLL_SOURCE_USER_INTERFACE:
- case EDG_WLL_SOURCE_LRMS:
- case EDG_WLL_SOURCE_APPLICATION:
- user = strmd5(e->any.user,NULL);
- if (strcmp(owner,user)) edg_wll_SetError(ctx,EPERM,"check_auth()");
- break;
- default:
- /* XXX: just don't allow anonymous */
- if (!strcmp(e->any.user,EDG_WLL_LOG_USER_DEFAULT))
- edg_wll_SetError(ctx,EPERM,"check_auth()");
- break;
- }
-
-
-clean:
- if (stmt) edg_wll_FreeStmt(&stmt);
- free(q);
- free(owner);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-#ifndef LB_DAG_EMBRIONIC
-static int register_subjobs(edg_wll_Context ctx,const edg_wll_RegJobEvent *e)
-{
- int i,err;
- edg_wlc_JobId *subjobs;
- struct timeval now;
-
- edg_wll_ResetError(ctx);
- if (e->nsubjobs == 0) return 0;
- if (e->nsubjobs < 0) return edg_wll_SetError(ctx,EINVAL,"negative number of subjobs");
-
- if ((err = edg_wll_GenerateSubjobIds(ctx,e->jobId,e->nsubjobs,e->seed,&subjobs)))
- return err;
-
- gettimeofday(&now,NULL);
-
-/* XXX: increase the overall request timeout. */
- ctx->p_tmp_timeout.tv_sec += e->nsubjobs;
- if (ctx->p_tmp_timeout.tv_sec > 86400) ctx->p_tmp_timeout.tv_sec = 86400;
-
- for (i=0; i<e->nsubjobs; i++) {
- edg_wll_Event e2;
- int seq;
- char *et,*ed,*job_s;
-
- memset(&e2,0,sizeof e2);
- e2.type = EDG_WLL_EVENT_REGJOB;
- e2.any.jobId = subjobs[i]; subjobs[i] = NULL;
- memcpy(&e2.regJob.timestamp,&now,sizeof now);
- e2.any.host = strdup(ctx->srvName);
- e2.any.level = e->level;
- e2.any.priority = e->priority;
- e2.any.seqcode = strdup(EDG_WLL_SEQ_NULL);
- e2.any.user = strdup(e->user);
- e2.any.source = e->source;
- e2.any.src_instance = strdup(ctx->isProxy ?
- "L&B proxy" : "L&B server");
- e2.regJob.ns = strdup(e->ns);
- edg_wlc_JobIdDup(e->jobId,&e2.regJob.parent);
- e2.regJob.jobtype = EDG_WLL_REGJOB_SIMPLE;
- e2.regJob.jdl = strdup("");
-
- switch (edg_wll_StoreEvent(ctx,&e2,&seq)) {
-
- case 0: break;
- /* maybe some non-ignorable errors should be handled here */
-
- default:
- edg_wll_Error(ctx,&et,&ed);
- job_s = edg_wlc_JobIdUnparse(e2.any.jobId);
- fprintf(stderr,"register subjob %s: %s (%s)\n",job_s,et,ed);
- syslog(LOG_ERR,"register subjob %s: %s (%s)",job_s,et,ed);
- free(job_s); free(et); free(ed);
- edg_wll_FreeEvent(&e2);
- edg_wll_ResetError(ctx);
- continue;
- }
-
- if (edg_wll_LockJob(ctx,e2.any.jobId)) {
- job_s = edg_wlc_JobIdUnparse(e2.any.jobId);
- fprintf(stderr,"lock job %s: %s (%s)\n",job_s,et,ed);
- syslog(LOG_ERR,"lock job %s: %s (%s)",job_s,et,ed);
- free(job_s); free(et); free(ed);
- edg_wll_FreeEvent(&e2);
- edg_wll_ResetError(ctx);
- continue;
- }
-
- if ((err = edg_wll_StepIntState(ctx,e2.any.jobId,&e2,seq,NULL)))
- edg_wll_Error(ctx,&et,&ed);
-
- edg_wll_UnlockJob(ctx,e2.any.jobId);
- edg_wll_ResetError(ctx);
-
- if (err) {
- job_s = edg_wlc_JobIdUnparse(e2.any.jobId);
- fprintf(stderr,"%s: %s (%s)\n",job_s,et,ed);
- syslog(LOG_ERR,"%s: %s (%s)",job_s,et,ed);
- free(job_s); free(et); free(ed);
- edg_wll_ResetError(ctx);
- }
-
- edg_wll_FreeEvent(&e2);
- }
-
- free(subjobs);
- return edg_wll_Error(ctx,NULL,NULL);
-}
-#endif
-
-
-/*
- * Returns encoded SQL table states record for embryonic DAG subjob
- */
-
-static edg_wll_ErrorCode states_values_embryonic(
- edg_wll_Context ctx,
- edg_wlc_JobId jobid,
- const edg_wll_RegJobEvent *e,
- char **icnames,
- char **values)
-{
- char *jobid_md5, *stat_enc, *parent_md5;
- char *stmt = NULL;
- char *icvalues;
- intJobStat stat_rec;
- intJobStat *stat = &stat_rec;
-
- init_intJobStat(stat);
- if (edg_wlc_JobIdDup(jobid, &stat->pub.jobId) ||
- edg_wlc_JobIdDup(e->jobId, &stat->pub.parent_job)) goto err;
- stat->pub.state = EDG_WLL_JOB_SUBMITTED;
- stat->pub.owner = strdup(e->user);
- stat->pub.jobtype = EDG_WLL_STAT_SIMPLE;
- stat->pub.stateEnterTimes[1 + EDG_WLL_JOB_SUBMITTED] = (int)e->timestamp.tv_sec;
-
- jobid_md5 = edg_wlc_JobIdGetUnique(jobid);
- parent_md5 = edg_wlc_JobIdGetUnique(e->jobId);
- stat_enc = enc_intJobStat(strdup(""), stat);
- if (jobid_md5 == NULL || parent_md5 == NULL || stat_enc == NULL) goto err;
-
-
- if (edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, stat, 1, icnames, &icvalues)) goto err;
- trio_asprintf(&stmt,
- "'%|Ss',%d,%d,'%|Ss','%|Ss','%|Ss'%s",
- jobid_md5, stat->pub.state, 1, stat_enc,
- INTSTAT_VERSION, parent_md5, icvalues);
- free(icvalues);
-
-err:
- destroy_intJobStat(stat);
- free(jobid_md5);
- free(stat_enc);
- free(parent_md5);
- *values = stmt;
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-static int register_subjobs_embryonic(edg_wll_Context ctx,const edg_wll_RegJobEvent *e)
-{
- int i, err = 0;
- edg_wlc_JobId *subjobs;
- struct timeval now;
- char *userid = strdup(strmd5(e->user,NULL));
- char *jobid_md5, *jobid_md5_old;
- size_t jobid_len;
-#ifdef LB_BUF
- edg_wll_bufInsert bi_j;
- edg_wll_bufInsert *bi_jobs = &bi_j;
- char *states_cols;
-#endif
- edg_wll_bufInsert bi_s, *bi_states = &bi_s;
- char *icnames, *values;
-
-
- edg_wll_ResetError(ctx);
-
- if (e->nsubjobs == 0) return 0;
- if (e->nsubjobs < 0) return edg_wll_SetError(ctx,EINVAL,"negative number of subjobs");
- if ((err = edg_wll_GenerateSubjobIds(ctx,e->jobId,e->nsubjobs,e->seed,&subjobs)))
- return err;
-
- /* find out icnames and values once, then only change jobids */
- if (states_values_embryonic(ctx, subjobs[0], e, &icnames, &values))
- edg_wll_Error(ctx, NULL, NULL);
- jobid_md5_old = edg_wlc_JobIdGetUnique(subjobs[0]);
- jobid_len = strlen(jobid_md5_old);
-
-
-#ifdef LB_BUF
- /* init multirows insert mechanism for tables used here */
- if (edg_wll_bufferedInsertInit(ctx, bi_jobs, NULL, "jobs", 4000, 1000,
- "jobid, dg_jobid, userid"))
- {
- return edg_wll_SetError(ctx, EINVAL, "edg_wll_bufferedInsertInit()");
- }
-
- asprintf(&states_cols,"jobid, status, seq,int_status, version, parent_job%s", icnames);
- if (edg_wll_bufferedInsertInit(ctx, bi_states, NULL, "states", 4000, 1000, states_cols))
- {
- return edg_wll_SetError(ctx, EINVAL, "edg_wll_bufferedInsertInit()");
- }
- free(states_cols);
-#endif
-
-
- gettimeofday(&now,NULL);
-
- /* increase the overall request timeout. */
- ctx->p_tmp_timeout.tv_sec += e->nsubjobs/10;
- if (ctx->p_tmp_timeout.tv_sec > 86400) ctx->p_tmp_timeout.tv_sec = 86400;
-
- for (i=0; i<e->nsubjobs; i++) {
- char *et,*ed,*job_s,*p,*p1;
-
- /* save jobid-userid relation into jobs table */
-#ifdef LB_BUF
- if ((err = store_job_block(ctx, subjobs[i], userid, bi_jobs)))
-#else
- if ((err = store_job(ctx, subjobs[i], userid)))
-#endif
- edg_wll_Error(ctx,&et,&ed);
-
- /* interchange variable parts (jobids) in values */
- /* there are only two occurences of subjob jobid */
- jobid_md5 = edg_wlc_JobIdGetUnique(subjobs[i]);
- if (i) {
- p = strstr(values, jobid_md5_old);
- assert(p);
- memcpy(p, jobid_md5, jobid_len);
-
- p1 = strstr(p + jobid_len, jobid_md5_old);
- assert(p1);
- memcpy(p1, jobid_md5, jobid_len);
- }
- free(jobid_md5_old);
- jobid_md5_old = jobid_md5;
-
- if (!err && (err = edg_wll_StoreIntStateEmbryonic(ctx, subjobs[i], icnames, values, bi_states)))
- edg_wll_Error(ctx,&et,&ed);
-
-//job_s = edg_wlc_JobIdUnparse(subjobs[i]);
-//printf("%s\n", job_s);
-//free(job_s);
-
- if (err) {
- job_s = edg_wlc_JobIdUnparse(subjobs[i]);
- fprintf(stderr,"%s: %s (%s)\n",job_s,et,ed);
- syslog(LOG_ERR,"%s: %s (%s)",job_s,et,ed);
- free(job_s); free(et); free(ed);
- edg_wll_ResetError(ctx);
- }
- edg_wlc_JobIdFree(subjobs[i]);
- }
-
- free(jobid_md5_old); //free the last one
- free(icnames);
- free(values);
- free(subjobs);
-
-#ifdef LB_BUF
- /* commit the rest of multirows insert and clean structures */
- edg_wll_bufferedInsertClose(bi_jobs);
- edg_wll_bufferedInsertClose(bi_states);
-#endif
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-int edg_wll_delete_event(edg_wll_Context ctx,const char *jobid,int event)
-{
- char *stmt;
-
-/* The order of tables is important to prevent another process calling
- * StoreEvent() to get our event number and mess up the fields together.
- *
- * XXX: best effort: more or less ignore errors
- *
- */
-
- trio_asprintf(&stmt,
- "delete from short_fields where jobid='%|Ss' and event=%d",
- jobid,event);
- edg_wll_ExecStmt(ctx,stmt,NULL);
- free(stmt);
-
- trio_asprintf(&stmt,
- "delete from long_fields where jobid='%|Ss' and event=%d",
- jobid,event);
- edg_wll_ExecStmt(ctx,stmt,NULL);
- free(stmt);
-
- trio_asprintf(&stmt,
- "delete from events where jobid='%|Ss' and event=%d",
- jobid,event);
- edg_wll_ExecStmt(ctx,stmt,NULL);
- free (stmt);
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <sys/time.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <assert.h>
-
-#include "glite/security/glite_gss.h"
-#include "glite/lb/il_msg.h"
-#include "glite/lb/lb_plain_io.h"
-#include "glite/lb/context-int.h"
-
-#include "store.h"
-
-#ifdef LB_PERF
-#include "srv_perf.h"
-#endif
-
-
-static
-int
-gss_reader(void *user_data, char *buffer, int max_len)
-{
- edg_wll_Context tmp_ctx = (edg_wll_Context)user_data;
- int ret, len;
- edg_wll_GssStatus gss_code;
-
- ret = edg_wll_gss_read_full(&tmp_ctx->connections->serverConnection->gss,
- buffer, max_len,
- &tmp_ctx->p_tmp_timeout,
- &len, &gss_code);
- if(ret < 0) {
- switch(ret) {
-
- case EDG_WLL_GSS_ERROR_TIMEOUT:
- edg_wll_SetError(tmp_ctx, ETIMEDOUT, "read message");
- break;
-
- case EDG_WLL_GSS_ERROR_EOF:
- edg_wll_SetError(tmp_ctx, ENOTCONN, NULL);
- break;
-
- default:
- edg_wll_SetError(tmp_ctx, EDG_WLL_ERROR_GSS, "read message");
- break;
- }
- }
-
- return(ret);
-}
-
-
-int edg_wll_StoreProto(edg_wll_Context ctx)
-{
- char *buf;
- int len,ret;
- size_t total;
- edg_wll_GssStatus gss_code;
-
- edg_wll_ResetError(ctx);
- ret = read_il_data(ctx, &buf, gss_reader);
- if (ret == EDG_WLL_GSS_ERROR_EOF)
- return edg_wll_SetError(ctx,ENOTCONN,"client side");
- if(ret < 0)
- return edg_wll_SetError(ctx,EIO,"interlogger protocol");
-#ifdef LB_PERF
- if (sink_mode == GLITE_LB_SINK_PARSE) glite_wll_perftest_consumeEventIlMsg(buf);
- else
-#endif
-
- handle_request(ctx,buf);
- free(buf);
-
- if ((len = create_reply(ctx,&buf)) > 0) {
- if ((ret = edg_wll_gss_write_full(&ctx->connections->serverConnection->gss,buf,len,&ctx->p_tmp_timeout,&total,&gss_code)) < 0)
- edg_wll_SetError(ctx,
- ret == EDG_WLL_GSS_ERROR_TIMEOUT ?
- ETIMEDOUT : EDG_WLL_ERROR_GSS,
- "write reply");
- free(buf);
- }
- else edg_wll_SetError(ctx,E2BIG,"create_reply()");
-
- return edg_wll_Error(ctx,NULL,NULL);
-}
-
-
-static
-int
-gss_plain_reader(void *user_data, char *buffer, int max_len)
-{
- edg_wll_Context tmp_ctx = (edg_wll_Context)user_data;
- int ret;
-
- ret = edg_wll_plain_read_full(&tmp_ctx->connProxy->conn, buffer, max_len,
- &tmp_ctx->p_tmp_timeout);
- if(ret < 0)
- edg_wll_SetError(tmp_ctx, errno, "StoreProtoProxy() - reading data");
-
- return(ret);
-}
-
-
-int edg_wll_StoreProtoProxy(edg_wll_Context ctx)
-{
- char *buf,
- *errd = NULL;
- int len, ret,
- err = 0;
-
-
- edg_wll_ResetError(ctx);
- ret = read_il_data(ctx, &buf, gss_plain_reader);
- if ( ret < 0 ) return(ret);
-#ifdef LB_PERF
- if (sink_mode == GLITE_LB_SINK_PARSE) glite_wll_perftest_consumeEventIlMsg(buf);
- else
-#endif
- if ( !(ret = handle_request(ctx, buf)) ) {
- if ( (err = edg_wll_Error(ctx, NULL, &errd)) ) edg_wll_ResetError(ctx);
- }
- free(buf);
-
-
- if ( (len = create_reply(ctx, &buf)) > 0 ) {
- if ( edg_wll_plain_write_full(&ctx->connProxy->conn, buf, len, &ctx->p_tmp_timeout) < 0 ) {
- if ( errd ) free(errd);
- return edg_wll_SetError(ctx, errno, "StoreProtoProxy() - sending reply");
- }
- free(buf);
- }
- else ret = edg_wll_SetError(ctx, E2BIG, "create_reply()");
-
- if ( err ) {
- edg_wll_SetError(ctx, err, errd);
- free(errd);
- }
- return ret? edg_wll_Error(ctx, NULL, NULL): 0;
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-
-#include "glite/wmsutils/jobid/cjobid.h"
-#include "glite/wmsutils/jobid/strmd5.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/trio.h"
-
-#include "lbs_db.h"
-
-int edg_wll_UserJobs(
- edg_wll_Context ctx,
- edg_wlc_JobId **jobs,
- edg_wll_JobStat **states)
-{
- char *userid = strmd5(ctx->peerName,NULL),*stmt = NULL,
- *res = NULL;
- int njobs = 0,ret,i;
- edg_wlc_JobId *out = NULL;
- edg_wll_Stmt sth = NULL;
- edg_wll_ErrorCode err = 0;
-
- edg_wll_ResetError(ctx);
-
- trio_asprintf(&stmt,"select cert_subj from users where userid = '%|Ss'",userid);
-
- switch (edg_wll_ExecStmt(ctx,stmt,&sth)) {
- case 0: edg_wll_SetError(ctx,ENOENT,ctx->peerName);
- case -1: goto err;
- default:
- if (edg_wll_FetchRow(sth,&res) < 0) goto err;
- if (strcmp(ctx->peerName,res)) {
- edg_wll_SetError(ctx,EDG_WLL_ERROR_MD5_CLASH,ctx->peerName);
- goto err;
- }
- }
-
- edg_wll_FreeStmt(&sth);
- free(stmt); stmt = NULL;
- free(res); res = NULL;
-
- trio_asprintf(&stmt,"select dg_jobid from jobs where userid = '%|Ss'",userid);
- switch (njobs = edg_wll_ExecStmt(ctx,stmt,&sth)) {
- case 0: edg_wll_SetError(ctx,ENOENT,ctx->peerName);
- case -1: goto err;
- }
-
- out = malloc(sizeof(*out)*(njobs+1));
- memset(out,0,sizeof(*out)*(njobs+1));
-
- for (i=0; (ret = edg_wll_FetchRow(sth,&res)); i++) {
- if (ret < 0) goto err;
- if ((ret = edg_wlc_JobIdParse(res,out+i))) {
- edg_wll_SetError(ctx,errno,res);
- goto err;
- }
- free(res); res = NULL;
- }
-
-err:
- free(res);
- free(stmt);
- edg_wll_FreeStmt(&sth);
- if ((err = edg_wll_Error(ctx,NULL,NULL))) {
- if (out) {
- for (i=0; i<njobs; i++)
- edg_wlc_JobIdFree(out[i]);
- free(out);
- }
- } else *jobs = out;
-
- return err;
-}
+++ /dev/null
-#ident "$Header$"
-
-#include <assert.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/file.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <sys/uio.h>
-
-
-#include <cclassad.h>
-
-#include "glite/lb/trio.h"
-#include "glite/lb/producer.h"
-#include "glite/lb/context-int.h"
-#include "glite/lb/jobstat.h"
-
-#include "get_events.h"
-#include "store.h"
-#include "lock.h"
-#include "index.h"
-#include "jobstat.h"
-
-static int rgma_fd = -1;
-
-static void write2rgma_line(char *line, int old_style)
-{
-
- int slen;
- int sysret;
- struct iovec iov[2];
-
- static int rgma_sock = -1;
- static char *rgma_fname = NULL;
- static struct sockaddr_un rgma_saddr;
-
- static int rgma_fd_locked = 0;
- struct stat stat_buf,stat_fbuf;
- struct flock filelock;
- int filelock_status;
-
- assert(line != NULL);
-
- if (rgma_fd < -1) return;
- if (rgma_fd == -1) {
- rgma_fname = getenv("GLITE_WMS_LCGMON_FILE");
- if (rgma_fname == NULL) {
- rgma_fname = getenv("EDG_WL_RGMA_FILE");
- if (rgma_fname == NULL) {
- rgma_fd = -2;
- return;
- }
- }
-
- rgma_fd = open(rgma_fname, O_WRONLY|O_CREAT|O_APPEND, 0777);
- if (rgma_fd == -1) return;
- }
-
-
- slen = strlen(line);
- if (old_style) {
- iov[0].iov_base = &slen;
- iov[0].iov_len = sizeof(slen);
- iov[1].iov_base = line;
- iov[1].iov_len = slen + 1;
- } else {
- iov[0].iov_base = line;
- iov[0].iov_len = slen;
- }
-
- if (old_style) {
-
- if ((sysret = flock(rgma_fd, LOCK_SH)) != -1) {
- sysret = writev(rgma_fd, iov, 2);
- flock(rgma_fd, LOCK_UN);
- }
- if (sysret == -1) return;
- } else {
- if (!rgma_fd_locked) {
- do {
- filelock.l_type = F_WRLCK;
- filelock.l_whence = SEEK_SET;
- filelock.l_start = 0;
- filelock.l_len = 0;
- } while((filelock_status = fcntl(rgma_fd,F_SETLKW,&filelock))<0 && errno==EINTR);
- if (filelock_status<0) goto leave;
- }
- rgma_fd_locked = 1;
- if (fstat(rgma_fd, &stat_fbuf)<0 || stat(rgma_fname, &stat_buf)<0)
- goto leave;
- if (stat_fbuf.st_dev != stat_buf.st_dev || stat_fbuf.st_ino != stat_buf.st_ino)
- goto leave;
- if (writev(rgma_fd, iov, 1) < 0)
- goto leave;
- fsync(rgma_fd);
- do {
- filelock.l_type = F_UNLCK;
- filelock.l_whence = SEEK_SET;
- filelock.l_start = 0;
- filelock.l_len = 0;
- } while((filelock_status = fcntl(rgma_fd,F_SETLKW,&filelock))<0 && errno==EINTR);
- if (filelock_status < 0) goto leave;
- rgma_fd_locked = 0;
- leave:
- /* add explicit unlock, incase the later close should fail for some reason */
- if (rgma_fd_locked) {
- do {
- filelock.l_type = F_UNLCK;
- filelock.l_whence = SEEK_SET;
- filelock.l_start = 0;
- filelock.l_len = 0;
- } while((filelock_status = fcntl(rgma_fd,F_SETLKW,&filelock))<0 && errno==EINTR);
- if (filelock_status == 0) {
- rgma_fd_locked = 0;
- }
- }
- /* close the statefile */
- if (close(rgma_fd)==0) {
- rgma_fd = -1;
- rgma_fd_locked = 0;
- }
-
- }
-
- if (rgma_sock < -1) return;
-
- if (rgma_sock == -1) {
- rgma_fname = getenv("EDG_WL_RGMA_SOCK");
- if (rgma_fname == NULL
- || (strlen(rgma_fname) + 1) > sizeof(rgma_saddr.sun_path) ) {
- rgma_sock = -2;
- return;
- }
-
- rgma_sock = socket(PF_UNIX, SOCK_DGRAM,0);
- if (rgma_sock == -1) return;
-
- memset(&rgma_saddr, sizeof(rgma_saddr), 0);
- rgma_saddr.sun_family = PF_UNIX;
- strcpy(rgma_saddr.sun_path, rgma_fname);
- }
-
- sendto(rgma_sock, &slen, 1, MSG_DONTWAIT,
- (struct sockaddr*) &rgma_saddr, SUN_LEN(&rgma_saddr));
-
- return;
-}
-
-
-char* write2rgma_statline(edg_wll_JobStat *stat)
-{
- char *stmt = NULL;
- char *string_jobid, *string_stat, *string_server;
- char *string_vo = NULL;
-
- string_jobid = edg_wlc_JobIdUnparse(stat->jobId);
- string_stat = edg_wll_StatToString(stat->state);
- string_server = edg_wlc_JobIdGetServer(stat->jobId);
-
- if (stat->jdl != NULL) {
- struct cclassad *ad;
-
- ad = cclassad_create(stat->jdl);
- if (ad) {
- if (!cclassad_evaluate_to_string(ad, "VirtualOrganisation", &string_vo))
- string_vo = NULL;
- cclassad_delete(ad);
- }
- }
-
- trio_asprintf(&stmt,
- "JOBID=%|Ss "
- "OWNER=%|Ss "
- "BKSERVER=%|Ss "
- "NETWORKSERVER=%|Ss "
- "VO=%|Ss "
- "LASTUPDATETIME=%d "
- "STATENAME=%s "
- "STATEENTERTIME=%d "
- "CONDORID=%|Ss "
- "DESTINATION=%|Ss "
- "EXITCODE=%d "
- "DONECODE=%d "
- "STATUSREASON=%|Ss"
- "\n",
- string_jobid,
- stat->owner,
- string_server,
- (stat->network_server) ? (stat->network_server) : "",
- (string_vo) ? string_vo : "",
- stat->lastUpdateTime.tv_sec,
- string_stat,
- stat->stateEnterTime.tv_sec,
- (stat->condorId) ? (stat->condorId) : "",
- (stat->destination) ? (stat->destination) : "",
- stat->exit_code,
- stat->done_code,
- (stat->reason) ? (stat->reason) : ""
- );
-
- free(string_vo);
- free(string_jobid);
- free(string_stat);
- free(string_server);
-
- return stmt;
-}
-
-void write2rgma_status(edg_wll_JobStat *stat)
-{
- char *line;
- int lcgmon = 0;
-
- if (rgma_fd < -1) return;
-
- line = write2rgma_statline(stat);
- if (line) {
- if (getenv("GLITE_WMS_LCGMON_FILE")) lcgmon = 1;
- write2rgma_line(line, !lcgmon);
- }
- free(line);
-}
-
-/* Export status record only if new status line is different from
- previous one. free() prev_statline parameter. */
-
-void write2rgma_chgstatus(edg_wll_JobStat *stat, char *prev_statline)
-{
- char *line;
- int lcgmon = 0;
-
- if (rgma_fd < -1) return;
-
- line = write2rgma_statline(stat);
- if (line && (!prev_statline || strcmp(line, prev_statline))) {
- if (getenv("GLITE_WMS_LCGMON_FILE")) lcgmon = 1;
- write2rgma_line(line, !lcgmon);
- }
- free(line);
- free(prev_statline);
-}
-
-#ifdef TEST
-int main(int argc, char* argv[])
-{
- setenv("EDG_WL_RGMA_FILE", "/tmp/rgma_statefile", 1);
- setenv("EDG_WL_RGMA_SOCK", "/tmp/rgma_statesock", 1);
-
- write2rgma_line("123---789\n", 0);
- return 0;
-}
-#endif
+++ /dev/null
-#include <string.h>
-
-#include "glite/lb/context-int.h"
-#include "soap_version.h"
-#include "glite/security/glite_gscompat.h"
-
-#include "bk_ws_H.h"
-#include "bk_ws_Stub.h"
-
-
-#if GSOAP_VERSION >= 20709
- #define GFITEM reason
- #define GFNUM SOAP_TYPE_lbt__genericFault
-#else
- #define GFITEM lbe__genericFault
- #define GFNUM SOAP_TYPE__genericFault
-#endif
-
-
-void edg_wll_ErrToFault(const edg_wll_Context ctx,struct soap *soap)
-{
- char *et,*ed;
- struct SOAP_ENV__Detail *detail = soap_malloc(soap,sizeof *detail);
-#if GSOAP_VERSION >= 20709
- struct lbt__genericFault *f = soap_malloc(soap,sizeof *f);
-#else
- struct _genericFault *f = soap_malloc(soap,sizeof *f);
-#endif
-
- f->GFITEM = soap_malloc(soap,sizeof *f->GFITEM);
- memset(f->GFITEM, 0, sizeof(*f->GFITEM));
-
- f->GFITEM->code = edg_wll_Error(ctx,&et,&ed);
- f->GFITEM->text = soap_malloc(soap,strlen(et)+1);
- strcpy(f->GFITEM->text,et);
- free(et);
- if (ed) {
- f->GFITEM->description = soap_malloc(soap,strlen(ed)+1);
- strcpy(f->GFITEM->description,ed);
- free(ed);
- }
-
- detail->__type = GFNUM;
-#if GSOAP_VERSION >= 20700
- detail->fault = f;
-#else
- detail->value = f;
-#endif
- detail->__any = NULL;
-
- soap_receiver_fault(soap,"shit",NULL);
- if (soap->version == 2) soap->fault->SOAP_ENV__Detail = detail;
- else soap->fault->detail = detail;
-}
-
-
-void edg_wll_FaultToErr(const struct soap *soap,edg_wll_Context ctx)
-{
- struct SOAP_ENV__Detail *detail;
- struct lbt__genericFault *f;
-
- if (!soap->fault) {
- edg_wll_SetError(ctx,EINVAL,"SOAP: (no error info)");
- return;
- }
-
- detail = soap->version == 2 ? soap->fault->SOAP_ENV__Detail : soap->fault->detail;
- if (detail->__type == GFNUM) {
-#if GSOAP_VERSION >= 20709
- f = detail->lbe__genericFault;
-#elif GSOAP_VERSION >= 20700
- f = ((struct _genericFault *) detail->fault)
- ->lbe__genericFault;
-#else
- f = ((struct _genericFault *) detail->value)
- ->lbe__genericFault;
-#endif
- edg_wll_SetError(ctx,f->code,f->description);
- }
- else {
- char *s;
-
- asprintf(&s,"SOAP: %s", soap->version == 2 ?
- GLITE_SECURITY_GSOAP_REASON(soap) : soap->fault->faultstring);
- edg_wll_SetError(ctx,EINVAL,s);
- free(s);
- }
-}
+++ /dev/null
-#ifndef __EDG_WORKLOAD_LOGGING_LBSERVER_WS_FAULT_H__
-#define __EDG_WORKLOAD_LOGGING_LBSERVER_WS_FAULT_H__
-
-extern void edg_wll_ErrToFault(const edg_wll_Context, struct soap *);
-extern void edg_wll_FaultToErr(const struct soap *, edg_wll_Context);
-
-#endif /* __EDG_WORKLOAD_LOGGING_LBSERVER_WS_FAULT_H__ */
+++ /dev/null
-#include <stdsoap2.h>
-
-#include "glite/lb/context-int.h"
-#include "glite/lb/consumer.h"
-
-#include "soap_version.h"
-#include "glite/security/glite_gsplugin.h"
-#include "glite/security/glite_gscompat.h"
-
-#include "jobstat.h"
-#include "query.h"
-#include "bk_ws_H.h"
-#include "get_events.h"
-#include "ws_fault.h"
-#include "ws_typeref.h"
-
-#if GSOAP_VERSION <= 20602
-#define __lb__GetVersion __ns1__GetVersion
-#define __lb__JobStatus __ns1__JobStatus
-#define __lb__UserJobs __ns1__UserJobs
-#define __lb__QueryJobs __ns1__QueryJobs
-#define __lb__QueryEvents __ns1__QueryEvents
-#endif
-
-
-static void freeQueryRecsExt(edg_wll_QueryRec **qr);
-static void freeJobIds(edg_wlc_JobId *jobs);
-static void freeJobStats(edg_wll_JobStat *stats);
-static void freeEvents(edg_wll_Event *events);
-
-
-SOAP_FMAC5 int SOAP_FMAC6 __lb__GetVersion(
- struct soap* soap,
- struct _lbe__GetVersion *in,
- struct _lbe__GetVersionResponse *out)
-{
- out->version = soap_strdup(soap, VERSION);
-
- return out->version ? SOAP_OK : SOAP_FAULT;
-}
-
-
-SOAP_FMAC5 int SOAP_FMAC6 __lb__JobStatus(
- struct soap *soap,
- struct _lbe__JobStatus *in,
- struct _lbe__JobStatusResponse *out)
-{
- edg_wll_Context ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap);
- edg_wlc_JobId j;
- edg_wll_JobStat s;
- int flags;
-
-
- if ( edg_wlc_JobIdParse(in->jobid, &j) )
- {
- edg_wll_SetError(ctx, EINVAL, in->jobid);
- edg_wll_ErrToFault(ctx, soap);
- return SOAP_FAULT;
- }
-
- edg_wll_SoapToJobStatFlags(in->flags, &flags);
-
- if ( edg_wll_JobStatus(ctx, j, flags, &s) )
- {
- edg_wll_ErrToFault(ctx, soap);
- return SOAP_FAULT;
- }
-
- out->stat = soap_malloc(soap, sizeof(*out->stat));
- edg_wll_StatusToSoap(soap, &s, out->stat);
-
- return SOAP_OK;
-}
-
-
-SOAP_FMAC5 int SOAP_FMAC6 __lb__QueryJobs(
- struct soap *soap,
- struct _lbe__QueryJobs *in,
- struct _lbe__QueryJobsResponse *out)
-{
- edg_wll_Context ctx;
- edg_wll_QueryRec **conditions;
- int flags;
- edg_wlc_JobId *jobs;
- edg_wll_JobStat *states;
- int ret;
-
- out->states = soap_malloc(soap, sizeof(*out->states));
- out->jobs = soap_malloc(soap, sizeof(*out->jobs));
- if ( !out->states || !out->jobs ) goto cleanup;
-
- ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap);
- jobs = NULL;
- states = NULL;
- ret = SOAP_FAULT;
-
- edg_wll_ResetError(ctx);
- if ( edg_wll_SoapToQueryCondsExt(in->conditions, in->__sizeconditions, &conditions) ) {
- edg_wll_SetError(ctx, ENOMEM, "Couldn't create internal structures");
- goto cleanup;
- }
- edg_wll_SoapToJobStatFlags(in->flags, &flags);
-
- if (edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, &jobs, &states) != 0) goto cleanup;
-
- if (edg_wll_JobsQueryResToSoap(soap, jobs, states, out) != SOAP_OK) goto cleanup;
- ret = SOAP_OK;
-
-cleanup:
- freeQueryRecsExt(conditions);
- freeJobIds(jobs);
- freeJobStats(states);
-
- if ( ret == SOAP_FAULT ) edg_wll_ErrToFault(ctx, soap);
-
- return ret;
-}
-
-
-SOAP_FMAC5 int SOAP_FMAC6 __lb__UserJobs(
- struct soap *soap,
- struct _lbe__UserJobs *in,
- struct _lbe__UserJobsResponse *out)
-{
- return SOAP_OK;
-}
-
-#if 0
-int edgwll2__UserJobs(
- struct soap *soap,
- struct edgwll2__UserJobsResponse *out)
-{
- out->jobs = NULL;
- out->states = NULL;
-
- return SOAP_OK;
-}
-
-#endif
-
-
-SOAP_FMAC5 int SOAP_FMAC6 __lb__QueryEvents(
- struct soap *soap,
- struct _lbe__QueryEvents *in,
- struct _lbe__QueryEventsResponse *out)
-{
- edg_wll_Context ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap);
- edg_wll_QueryRec **job_conditions;
- edg_wll_QueryRec **event_conditions;
- edg_wll_Event *events = NULL;
- int ret = SOAP_OK;
-
-
- edg_wll_ResetError(ctx);
- if ( edg_wll_SoapToQueryCondsExt(in->jobConditions, in->__sizejobConditions,
- &job_conditions) )
- {
- edg_wll_SetError(ctx, ENOMEM, "Couldn't create internal structures");
- edg_wll_ErrToFault(ctx, soap);
- ret = SOAP_FAULT;
- goto cleanup;
- }
-
- if ( edg_wll_SoapToQueryCondsExt(in->eventConditions, in->__sizeeventConditions,
- &event_conditions) )
- {
- edg_wll_SetError(ctx, ENOMEM, "Couldn't create internal structures");
- edg_wll_ErrToFault(ctx, soap);
- ret = SOAP_FAULT;
- goto cleanup;
- }
-
-
- if (edg_wll_QueryEventsServer(ctx, ctx->noAuth,
- (const edg_wll_QueryRec **)job_conditions,
- (const edg_wll_QueryRec **)event_conditions,
- &events))
- {
- edg_wll_ErrToFault(ctx, soap);
- ret = SOAP_FAULT;
- goto cleanup;
- }
-
- if (edg_wll_EventsQueryResToSoap(soap, events, out) != SOAP_OK)
- {
- ret = SOAP_FAULT;
- goto cleanup;
- }
-
-cleanup:
- freeQueryRecsExt(job_conditions);
- freeQueryRecsExt(event_conditions);
- freeEvents(events);
-
- return ret;
-}
-
-
-static void freeQueryRecsExt(edg_wll_QueryRec **qr) {
- int i, j;
-
- if ( qr ) {
- for ( i = 0; qr[i]; i++ ) {
- if (qr[i]) {
- for ( j = 0; qr[i][j].attr; j++ ) edg_wll_QueryRecFree(&qr[i][j]);
- free(qr[i]);
- }
- }
- free(qr);
- }
-}
-
-
-static void freeJobIds(edg_wlc_JobId *jobs) {
- int i;
-
- if ( jobs ) {
- for ( i = 0; jobs[i]; i++ )
- edg_wlc_JobIdFree(jobs[i]);
- free(jobs);
- }
-}
-
-
-static void freeJobStats(edg_wll_JobStat *stats) {
- int i;
-
- if ( stats ) {
- for ( i = 0; stats[i].state; i++ )
- edg_wll_FreeStatus(&stats[i]);
- free(stats);
- }
-}
-
-
-static void freeEvents(edg_wll_Event *events)
-{
- int i;
-
- if (events != NULL) {
- for (i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++)
- edg_wll_FreeEvent(&(events[i]));
- edg_wll_FreeEvent(&(events[i])); /* free last line */
- free(events);
- }
-}
+++ /dev/null
-lb = http://glite.org/wsdl/services/lb
-lbt = http://glite.org/wsdl/types/lb
-lbe = http://glite.org/wsdl/elements/lb
+++ /dev/null
-#if GSOAP_VERSION >= 20700
-
-#define JOBID lbt__queryAttr__JOBID
-#define OWNER lbt__queryAttr__OWNER
-#define STATUS lbt__queryAttr__STATUS
-#define LOCATION lbt__queryAttr__LOCATION
-#define DESTINATION lbt__queryAttr__DESTINATION
-#define DONECODE lbt__queryAttr__DONECODE
-#define USERTAG lbt__queryAttr__USERTAG
-#define TIME lbt__queryAttr__TIME
-#define LEVEL lbt__queryAttr__LEVEL
-#define HOST lbt__queryAttr__HOST
-#define SOURCE lbt__queryAttr__SOURCE
-#define INSTANCE lbt__queryAttr__INSTANCE
-#define EVENTTYPE lbt__queryAttr__EVENTTYPE
-#define CHKPTTAG lbt__queryAttr__CHKPTTAG
-#define RESUBMITTED lbt__queryAttr__RESUBMITTED
-#define PARENT lbt__queryAttr__PARENT
-#define EXITCODE lbt__queryAttr__EXITCODE
-
-#define EQUAL lbt__queryOp__EQUAL
-#define UNEQUAL lbt__queryOp__UNEQUAL
-#define LESS lbt__queryOp__LESS
-#define GREATER lbt__queryOp__GREATER
-#define WITHIN lbt__queryOp__WITHIN
-
-#define SUBMITTED lbt__statName__SUBMITTED
-#define WAITING lbt__statName__WAITING
-#define READY lbt__statName__READY
-#define SCHEDULED lbt__statName__SCHEDULED
-#define RUNNING lbt__statName__RUNNING
-#define DONE lbt__statName__DONE
-#define CLEARED lbt__statName__CLEARED
-#define ABORTED lbt__statName__ABORTED
-#define CANCELLED lbt__statName__CANCELLED
-#define UNKNOWN lbt__statName__UNKNOWN
-#define PURGED lbt__statName__PURGED
-
-#define SIMPLE lbt__jobtype__SIMPLE
-#define DAG lbt__jobtype__DAG
-
-#define OK lbt__doneCode__OK
-#define FAILED lbt__doneCode__FAILED
-#define CANCELLED_ lbt__doneCode__CANCELLED
-
-#define CLASSADS lbt__jobFlagsValue__CLASSADS
-#define CHILDREN lbt__jobFlagsValue__CHILDREN
-#define CHILDSTAT lbt__jobFlagsValue__CHILDSTAT
-
-#define UserInterface lbt__eventSource__UserInterface
-#define NetworkServer lbt__eventSource__NetworkServer
-#define WorkloadManager lbt__eventSource__WorkloadManager
-#define BigHelper lbt__eventSource__BigHelper
-#define JobSubmission lbt__eventSource__JobSubmission
-#define LogMonitor lbt__eventSource__LogMonitor
-#define LRMS lbt__eventSource__LRMS
-#define Application lbt__eventSource__Application
-#define LBServer lbt__eventSource__LBServer
-
-#endif
+++ /dev/null
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdsoap2.h>
-
-#include "soap_version.h"
-#include "bk_ws_H.h"
-#include "ws_typemap.h"
-
-#include "glite/lb/consumer.h"
-/* XXX: references only, src and dest share pointers */
-
-#include "glite/security/glite_gscompat.h"
-
-#define VALUEEV_GET(X, V) GLITE_SECURITY_GSOAP_CHOICE_GET((X), V, event, 1)
-#define VALUEEV_SET(X, V, VALUE) GLITE_SECURITY_GSOAP_CHOICE_SET((X), V, lbt, event, 1, VALUE)
-#define VALUEEV_ISTYPE(X, V) GLITE_SECURITY_GSOAP_CHOICE_ISTYPE((X), V, lbt, event, 1)
-#define VALUEQR_GET(X, V) GLITE_SECURITY_GSOAP_CHOICE_GET((X), V, queryRecValue, 2)
-#define VALUEQR_SETTYPE(X, V) GLITE_SECURITY_GSOAP_CHOICE_SETTYPE((X), V, lbt, queryRecValue, 2)
-#define VALUEQR_SET(X, V, VALUE) GLITE_SECURITY_GSOAP_CHOICE_SET((X), V, lbt, queryRecValue, 2, VALUE)
-#define VALUEQR_ISTYPE(X, V) GLITE_SECURITY_GSOAP_CHOICE_ISTYPE((X), V, lbt, queryRecValue, 2)
-
-@@@{
-#
-# generate the command for move native data to soap web services structures
-#
-# if the field is optional, is ALWAYS assigned!
-#
-sub eventFieldAssign {
- my ($indent, $src, $dst, $e, $f, $is_common) = @_;
- my ($tn, $soap_en, $soap_fn, $native_en, $native_fn, $func_name, $source, $dest);
-
- $tn = $f->{type};
- $native_en = lcfirst $e;
- if ($native_en =~ m/^pBS/) { $native_en = ucfirst $native_en; }
- if ($native_en =~ m/^condor/) { $native_en = ucfirst $native_en; }
- $native_fn = $f->{name};
- $soap_en = $e;
- while ($soap_en =~ /([[:alpha:]]*)_([[:alpha:]_]*)/) {
- $soap_en = $1.ucfirst($2);
- };
- $soap_fn = $native_fn;
- while ($soap_fn =~ /([[:alpha:]]*)_([[:alpha:]_]*)/) {
- $soap_fn = $1.ucfirst($2);
- };
- $source = "$src->$native_en.$native_fn";
- $dest = "VALUEEV_GET($dst, $soap_en)->$soap_fn";
-# print STDERR "$src, $dst, $soap_en, $soap_fn, $native_fn, $tn, $usuc\n";
-
- if ($tn eq 'int') {
- if ($f->{codes}) {
- $soap_En = ucfirst $soap_en;
- $soap_Fn = ucfirst $soap_fn;
- $func_name = $is_common ? "edg_wll_${soap_Fn}ToSoap" : "edg_wll_${soap_En}${soap_Fn}ToSoap";
- gen $indent."$func_name(soap, $source, &$dest);\n";
- } elsif ($f->{optional}) {
- gen $indent."$dest = soap_malloc(soap, sizeof(*$dest));\n";
- gen $indent."*$dest = $source;\n";
- } else {
- gen $indent."$dest = $source;\n";
- }
- } elsif ($tn eq 'port' || $tn eq 'bool' || $tn eq 'float' || $tn eq 'double') {
- if ($f->{optional}) {
- gen $indent."$dest = soap_malloc(soap, sizeof(*$dest));\n";
- gen $indent."*$dest = $source;\n";
- } else {
- gen $indent."$dest = $source;\n";
- }
- } elsif ($tn eq 'logsrc') {
- gen $indent."edg_wll_SourceToSoap($source, &$dest);\n";
- } elsif ($tn eq 'string' || $tn eq 'notifid') {
- gen $indent."$dest = soap_strdup(soap, $source);\n";
- } elsif ($tn eq 'jobstat') {
- gen $indent."$dest = soap_malloc(soap, sizeof(struct lbt__jobStatus))";
- gen $indent."edg_wll_StatusToSoap(soap, $source, $dest);\n";
- } elsif ($tn eq 'timeval') {
- gen $indent."$dest = soap_malloc(soap, sizeof(struct lbt__timeval));\n";
- gen $indent."$dest->tvSec = $source.tv_sec;\n";
- gen $indent."$dest->tvUsec = $source.tv_usec;\n";
- } elsif ($tn eq 'jobid') {
- gen $indent."s = edg_wlc_JobIdUnparse($source);\n";
- gen $indent."$dest = soap_strdup(soap, s);\n";
- } elsif ($tn eq 'usertag') {
- gen $indent."$dest = soap_malloc(soap, sizeof(*$dst->$soap_fn));\n";
- gen $indent."$dest->tag = soap_strdup(soap, $source.tag);\n";
- gen $indent."$dest->value = soap_strdup(soap, $source.value);\n";
- } else {
- die "Unknown type $tn";
- }
-}
-
-
-sub eventFieldFree {
- my ($indent, $dst, $e, $f) = @_;
- my ($tn, $soap_fn, $dest);
-
- $tn = $f->{type};
- $soap_en = $e;
- while ($soap_en =~ /([[:alpha:]]*)_([[:alpha:]_]*)/) {
- $soap_en = $1.ucfirst($2);
- };
- $soap_fn = $f->{name};
- while ($soap_fn =~ /([[:alpha:]]*)_([[:alpha:]_]*)/) {
- $soap_fn = $1.ucfirst($2);
- };
- $dest = "VALUEEV_GET($dst, $soap_en)->$soap_fn";
-
- if ($tn eq 'int' || $tn eq 'port' || $tn eq 'bool' || $tn eq 'float' || $tn eq 'double' || $tn eq 'logsrc') {
- if ($f->{optional}) {
- gen $indent."if ($dest) soap_dealloc(soap, $dest);\n";
- }
- } elsif ($tn eq 'string' || $tn eq 'notifid' || $tn eq 'jobid' || $tn eq 'timeval') {
- gen $indent."if ($dest) soap_dealloc(soap, $dest);\n";
- } elsif ($tn eq 'usertag') {
- gen $indent."if ($dest) {\n";
- gen $indent." if ($dest->tag) soap_dealloc(soap, $dest->tag);\n";
- gen $indent." if ($dest->value) soap_dealloc(soap, $dest->value);\n";
- gen $indent." soap_dealloc(soap, $dest);\n";
- gen $indent."}\n";
- } else {
- die "Unknown type $tn";
- }
-}
-@@@}
-
-void edg_wll_JobStatCodeToSoap(edg_wll_JobStatCode in, enum lbt__statName *out)
-{
- switch ( in )
- {
-/* XXX: these two should never occur */
- case EDG_WLL_NUMBER_OF_STATCODES:
- case EDG_WLL_JOB_UNDEF: *out = -1; break;
-@@@{
- for my $stat ($status->getTypesOrdered) {
- my $u = uc $stat;
- my $c = getTypeComment $status $stat;
- gen qq{
-! case EDG_WLL_JOB_$u: *out = $u; break; /**< $c */
-};
- }
-@@@}
- }
-}
-
-void edg_wll_SoapToJobStatCode(enum lbt__statName in, edg_wll_JobStatCode *out)
-{
- switch ( in )
- {
-// case UNDEF: *out = EDG_WLL_JOB_UNDEF; break;
-@@@{
- for my $stat ($status->getTypesOrdered) {
- my $u = uc $stat;
- my $c = getTypeComment $status $stat;
- gen qq{
-! case $u: *out = EDG_WLL_JOB_$u; break; /**< $c */
-};
- }
-@@@}
- }
-}
-
-int edg_wll_StatusToSoap(struct soap *soap,edg_wll_JobStat const *src,struct lbt__jobStatus *js)
-{
- int i,j;
- char *s;
-
- memset(js, 0, sizeof(*js));
- edg_wll_JobStatCodeToSoap(src->state, &(js->state));
-@@@{
- selectType $status '_common_';
- for (getFieldsOrdered $status) {
- my $f = selectField $status $_;
- my $ft = $f->{type};
- my $usuc = $_;
- $usuc = $1.uc($2).$3 while ($usuc =~ /([^_]*)_([a-z])(.*)/);
- if ($ft eq 'jobid') {
- gen "\ts = edg_wlc_JobIdUnparse(src->$_);\n";
- gen "\tjs->$usuc = soap_strdup(soap,s); free(s);\n";
- }
- elsif ($ft eq 'strlist') {
- gen qq{
-! for (i=0; src->$_ && src->$_\[i]; i++);
-! js->__size$usuc = i;
-! js->$usuc = soap_malloc(soap,sizeof(char *) * i);
-! for (j=0; j<i; j++) js->$usuc\[j] = soap_strdup(soap,src->$_\[j]);
-};
- } elsif ($ft eq 'intlist') {
- my %fmap = ( children_hist=>'count', stateEnterTimes=>'time');
- gen qq{
-! /* XXX: don't count UNDEF */
-! if (src->$_) {
-! GLITE_SECURITY_GSOAP_LIST_TYPE(lbt, ${usuc}Item) h;
-!
-! GLITE_SECURITY_GSOAP_LIST_CREATE(soap, js, ${usuc}, struct lbt__${usuc}Item, EDG_WLL_NUMBER_OF_STATCODES-1);
-! h = js->${usuc};
-! for (i=1; i<EDG_WLL_NUMBER_OF_STATCODES; i++) {
-! edg_wll_JobStatCodeToSoap(i,&GLITE_SECURITY_GSOAP_LIST_GET(h, i-1)->state);
-! GLITE_SECURITY_GSOAP_LIST_GET(h, i-1)->$fmap{$_} = src->$_\[i];
-! }
-! }
-! else {
-! js->__size$usuc = 0;
-! js->$usuc = NULL;
-! }
-};
- } elsif ($ft eq 'taglist') {
- gen qq{
-! {
-! struct lbt__tagValue *t;
-!
-! for (i=0; src->$_ && src->$_\[i].tag; i++);
-! GLITE_SECURITY_GSOAP_LIST_CREATE(soap, js, $usuc, struct lbt__tagValue, i);
-! for (i=0; src->$_ && src->$_\[i].tag; i++) {
-! t = GLITE_SECURITY_GSOAP_LIST_GET(js->$usuc, i);
-! t->tag = soap_strdup(soap,src->$_\[i].tag);
-! t->value = soap_strdup(soap,src->$_\[i].value);
-! }
-! }
-};
- } elsif ($ft eq 'stslist') {
- gen qq{
-! for (i=0; src->$_ && src->$_\[i].state; i++);
-! GLITE_SECURITY_GSOAP_LIST_CREATE(soap, js, $usuc, struct lbt__jobStatus, i);
-! for (j=0; j<i; j++) edg_wll_StatusToSoap(soap,src->$_+j,GLITE_SECURITY_GSOAP_LIST_GET(js->$usuc, j));
-};
- } elsif ($ft eq 'timeval') {
- gen "\tjs->$usuc = soap_malloc(soap,sizeof *js->$usuc);\n";
- gen "\tjs->$usuc->tvSec = src->$_.tv_sec;\n";
- gen "\tjs->$usuc->tvUsec = src->$_.tv_usec;\n";
- } elsif ($ft eq 'string') {
- gen "\tjs->$usuc = soap_strdup(soap,src->$_);\n";
- } else { gen "\tjs->$usuc = src->$_;\n"; }
- }
-@@@}
-
- return SOAP_OK;
-}
-
-void edg_wll_SoapToStatus(struct soap *soap,struct lbt__jobStatus const *src,edg_wll_JobStat *dest)
-{
- int i;
-
- memset(dest,0,sizeof *dest);
- edg_wll_SoapToJobStatCode(src->state, &(dest->state));
-
-@@@{
- selectType $status '_common_';
- for (getFieldsOrdered $status) {
- my $f = selectField $status $_;
- my $ft = $f->{type};
- my $usuc = $_;
- $usuc = $1.uc($2).$3 while ($usuc =~ /([^_]*)_([a-z])(.*)/);
-
- if ($ft eq 'jobid') {
- gen "\tif (src->$usuc) edg_wlc_JobIdParse(src->$usuc,&dest->$_);\n";
- } elsif ($ft eq 'strlist') {
- gen "\tfor (i=0; i<src->__size$usuc; i++) soap_unlink(soap,src->$usuc\[i]);\n";
- gen "\tsoap_unlink(soap,src->$usuc);\n";
- gen "\tdest->$_ = realloc(src->$usuc,sizeof(*dest->$_) * (src->__size$usuc + 1));\n";
- gen "\tdest->$_\[src->__size$usuc] = NULL;\n";
- } elsif ($ft eq 'intlist') {
-# XXX: only EDG_WLL_NUMBER_OF_STATCODES long lists work
- my %fmap = ( children_hist=>'count', stateEnterTimes=>'time');
- gen qq {
-! if (src->__size$usuc) {
-! dest->$_ = calloc(EDG_WLL_NUMBER_OF_STATCODES+1, sizeof *dest->$_);
-! dest->$_\[0] = src->__size$usuc;
-! for (i=0; i<src->__size$usuc; i++) {
-! edg_wll_JobStatCode s;
-! edg_wll_SoapToJobStatCode(GLITE_SECURITY_GSOAP_LIST_GET(src->$usuc, i)->state,&s);
-! assert(s>=0); assert(s<EDG_WLL_NUMBER_OF_STATCODES);
-! dest->$_\[s+1] = GLITE_SECURITY_GSOAP_LIST_GET(src->$usuc, i)->$fmap{$_};
-! }
-! }
-! else dest->$_ = NULL;
-};
- } elsif ($ft eq 'stslist') {
- gen qq{
-! if (src->__size$usuc) {
-! dest->$_ = calloc(src->__size$usuc + 1,sizeof *dest->$_);
-! for (i=0; i<src->__size$usuc; i++) edg_wll_SoapToStatus(soap,GLITE_SECURITY_GSOAP_LIST_GET(src->$usuc, i),dest->$_ + i);
-! }
-! else dest->$_ = NULL;
-};
- } elsif ($ft eq 'taglist') {
- gen qq{
- if (src->__size$usuc) {
- dest->$_ = calloc(src->__size$usuc + 1,sizeof *dest->$_);
- for (i=0; i<src->__size$usuc; i++) {
- soap_unlink(soap,dest->$_\[i].tag = GLITE_SECURITY_GSOAP_LIST_GET(src->$usuc, i)->tag);
- soap_unlink(soap,dest->$_\[i].tag = GLITE_SECURITY_GSOAP_LIST_GET(src->$usuc, i)->tag);
- }
- }
- else dest->$_ = NULL;
-};
- } elsif ($ft eq 'timeval') {
- gen "\tdest->$_.tv_sec = src->$usuc->tvSec;\n";
- gen "\tdest->$_.tv_usec = src->$usuc->tvUsec;\n";
- } elsif ($ft eq 'string') {
- gen "\tdest->$_ = src->$usuc;\n";
- gen "\tsoap_unlink(soap,src->$usuc);\n";
- } else {
- gen "\tdest->$_ = src->$usuc;\n";
-}
-}
-@@@}
-}
-
-void edg_wll_SoapToJobStatFlags(const struct lbt__jobFlags *in, int *out)
-{
- int i;
-
- assert(in); assert(out);
- *out = 0;
- for ( i = 0; i < in->__sizeflag; i++ ) switch ( in->flag[i] )
- {
- case CLASSADS: *out |= EDG_WLL_STAT_CLASSADS; break;
- case CHILDREN: *out |= EDG_WLL_STAT_CHILDREN; break;
- case CHILDSTAT: *out |= EDG_WLL_STAT_CHILDSTAT; break;
- }
-}
-
-int edg_wll_JobStatFlagsToSoap(struct soap *soap, const int in, struct lbt__jobFlags *out)
-{
- int i = 0;
-
- assert(out);
- memset(out, 0, sizeof(*out));
- if ( in & EDG_WLL_STAT_CLASSADS ) out->__sizeflag++;
- if ( in & EDG_WLL_STAT_CHILDREN ) out->__sizeflag++;
- if ( in & EDG_WLL_STAT_CHILDSTAT ) out->__sizeflag++;
- if ( !out->__sizeflag ) return SOAP_OK;
- out->flag = soap_malloc(soap, sizeof(*(out->flag))*out->__sizeflag);
- if ( !out->flag ) return SOAP_FAULT;
-
- if ( in & EDG_WLL_STAT_CLASSADS ) out->flag[i++] = CLASSADS;
- if ( in & EDG_WLL_STAT_CHILDREN ) out->flag[i++] = CHILDREN;
- if ( in & EDG_WLL_STAT_CHILDSTAT ) out->flag[i++] = CHILDSTAT;
-
- return SOAP_OK;
-}
-
-void edg_wll_SoapToAttr(const enum lbt__queryAttr in, edg_wll_QueryAttr *out)
-{
- switch ( in )
- {
-// case UNDEF: *out = EDG_WLL_QUERY_ATTR_UNDEF; break;
- case JOBID: *out = EDG_WLL_QUERY_ATTR_JOBID; break;
- case OWNER: *out = EDG_WLL_QUERY_ATTR_OWNER; break;
- case STATUS: *out = EDG_WLL_QUERY_ATTR_STATUS; break;
- case LOCATION: *out = EDG_WLL_QUERY_ATTR_LOCATION; break;
- case DESTINATION: *out = EDG_WLL_QUERY_ATTR_DESTINATION; break;
- case DONECODE: *out = EDG_WLL_QUERY_ATTR_DONECODE; break;
- case USERTAG: *out = EDG_WLL_QUERY_ATTR_USERTAG; break;
- case TIME: *out = EDG_WLL_QUERY_ATTR_TIME; break;
-// case LEVEL: *out = EDG_WLL_QUERY_ATTR_LEVEL; break;
- case HOST: *out = EDG_WLL_QUERY_ATTR_HOST; break;
- case SOURCE: *out = EDG_WLL_QUERY_ATTR_SOURCE; break;
- case INSTANCE: *out = EDG_WLL_QUERY_ATTR_INSTANCE; break;
- case EVENTTYPE: *out = EDG_WLL_QUERY_ATTR_EVENT_TYPE; break;
- case CHKPTTAG: *out = EDG_WLL_QUERY_ATTR_CHKPT_TAG; break;
- case RESUBMITTED: *out = EDG_WLL_QUERY_ATTR_RESUBMITTED; break;
- case PARENT: *out = EDG_WLL_QUERY_ATTR_PARENT; break;
- case EXITCODE: *out = EDG_WLL_QUERY_ATTR_EXITCODE; break;
- default: *out = in; break;
- }
-}
-
-void edg_wll_AttrToSoap(const edg_wll_QueryAttr in, enum lbt__queryAttr *out)
-{
- switch ( in )
- {
- case EDG_WLL_QUERY_ATTR_UNDEF: *out = -1; break;
- case EDG_WLL_QUERY_ATTR_JOBID: *out = JOBID; break;
- case EDG_WLL_QUERY_ATTR_OWNER: *out = OWNER; break;
- case EDG_WLL_QUERY_ATTR_STATUS: *out = STATUS; break;
- case EDG_WLL_QUERY_ATTR_LOCATION: *out = LOCATION; break;
- case EDG_WLL_QUERY_ATTR_DESTINATION: *out = DESTINATION; break;
- case EDG_WLL_QUERY_ATTR_DONECODE: *out = DONECODE; break;
- case EDG_WLL_QUERY_ATTR_USERTAG: *out = USERTAG; break;
- case EDG_WLL_QUERY_ATTR_TIME: *out = TIME; break;
-// case EDG_WLL_QUERY_ATTR_LEVEL: *out = LEVEL; break;
- case EDG_WLL_QUERY_ATTR_HOST: *out = HOST; break;
- case EDG_WLL_QUERY_ATTR_SOURCE: *out = SOURCE; break;
- case EDG_WLL_QUERY_ATTR_INSTANCE: *out = INSTANCE; break;
- case EDG_WLL_QUERY_ATTR_EVENT_TYPE: *out = EVENTTYPE; break;
- case EDG_WLL_QUERY_ATTR_CHKPT_TAG: *out = CHKPTTAG; break;
- case EDG_WLL_QUERY_ATTR_RESUBMITTED: *out = RESUBMITTED; break;
- case EDG_WLL_QUERY_ATTR_PARENT: *out = PARENT; break;
- case EDG_WLL_QUERY_ATTR_EXITCODE: *out = EXITCODE; break;
- default: *out = in; break;
- }
-}
-
-void edg_wll_SoapToQueryOp(const enum lbt__queryOp in, edg_wll_QueryOp *out)
-{
- switch ( in )
- {
- case EQUAL: *out = EDG_WLL_QUERY_OP_EQUAL; break;
- case LESS: *out = EDG_WLL_QUERY_OP_LESS; break;
- case GREATER: *out = EDG_WLL_QUERY_OP_GREATER; break;
- case WITHIN: *out = EDG_WLL_QUERY_OP_WITHIN; break;
- default: *out = in; break;
- }
-}
-
-void edg_wll_QueryOpToSoap(const edg_wll_QueryOp in, enum lbt__queryOp *out)
-{
- switch ( in )
- {
- case EDG_WLL_QUERY_OP_EQUAL: *out = EQUAL; break;
- case EDG_WLL_QUERY_OP_LESS: *out = LESS; break;
- case EDG_WLL_QUERY_OP_GREATER: *out = GREATER; break;
- case EDG_WLL_QUERY_OP_WITHIN: *out = WITHIN; break;
- default: *out = in; break;
- }
-}
-
-int edg_wll_SoapToQueryVal(
- const edg_wll_QueryAttr attr,
- const struct lbt__queryRecValue *in,
- union edg_wll_QueryVal *out)
-{
- assert(in); assert(out);
- if ( VALUEQR_ISTYPE(in, c) ) {
- if ( attr == EDG_WLL_QUERY_ATTR_JOBID || attr == EDG_WLL_QUERY_ATTR_PARENT ) {
- if ( edg_wlc_JobIdParse(VALUEQR_GET(in, c), &(out->j)) ) return -1;
- } else {
- if ( !(out->c = strdup(VALUEQR_GET(in, c))) ) return -1;
- }
- }
- else if ( VALUEQR_ISTYPE(in, t) ) {
- out->t.tv_sec = VALUEQR_GET(in, t)->tvSec;
- out->t.tv_usec = VALUEQR_GET(in, t)->tvUsec;
- }
- else if ( VALUEQR_ISTYPE(in, i) ) out->i = *(VALUEQR_GET(in, i));
-
- return 0;
-}
-
-int edg_wll_QueryValToSoap(
- struct soap *soap,
- const edg_wll_QueryAttr attr,
- const union edg_wll_QueryVal *in,
- struct lbt__queryRecValue *out)
-{
- assert(in); assert(out);
- memset(out, 0, sizeof(*out));
- switch ( attr ) {
- case EDG_WLL_QUERY_ATTR_USERTAG:
- case EDG_WLL_QUERY_ATTR_OWNER:
- case EDG_WLL_QUERY_ATTR_LOCATION:
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- case EDG_WLL_QUERY_ATTR_HOST:
- case EDG_WLL_QUERY_ATTR_INSTANCE:
- VALUEQR_SET(out, c, in->c ? soap_strdup(soap, in->c) : NULL);
- if (in->c && !VALUEQR_GET(out, c) ) return SOAP_FAULT;
- break;
- case EDG_WLL_QUERY_ATTR_JOBID:
- case EDG_WLL_QUERY_ATTR_PARENT: {
- char *s = edg_wlc_JobIdUnparse(in->j);
- VALUEQR_SET(out, c, soap_strdup(soap, s));
- free(s);
- if ( !VALUEQR_GET(out, c) ) return SOAP_FAULT;
- }
- break;
- case EDG_WLL_QUERY_ATTR_TIME:
- VALUEQR_SET(out, t, soap_malloc(soap, sizeof(*(VALUEQR_GET(out, t)))));
- if ( !VALUEQR_GET(out, t) ) return SOAP_FAULT;
- VALUEQR_SETTYPE(out, t);
- VALUEQR_GET(out, t)->tvSec = in->t.tv_sec;
- VALUEQR_GET(out, t)->tvUsec = in->t.tv_usec;
- break;
- case EDG_WLL_QUERY_ATTR_STATUS:
- case EDG_WLL_QUERY_ATTR_DONECODE:
- case EDG_WLL_QUERY_ATTR_LEVEL:
- case EDG_WLL_QUERY_ATTR_SOURCE:
- case EDG_WLL_QUERY_ATTR_EVENT_TYPE:
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- default:
- VALUEQR_SET(out, i, soap_malloc(soap, sizeof(*(VALUEQR_GET(out, i)))));
- if ( !VALUEQR_GET(out, i) ) return SOAP_FAULT;
- *(VALUEQR_GET(out, i)) = in->i;
- break;
- }
-
- return SOAP_OK;
-}
-
-int edg_wll_SoapToQueryRec(
- const struct lbt__queryConditions *collection,
- const struct lbt__queryRecord *in,
- edg_wll_QueryRec *out)
-{
- assert(collection); assert(in); assert(out);
- memset(out, 0, sizeof(*out));
- edg_wll_SoapToAttr(collection->attr, &out->attr);
- switch ( out->attr )
- {
- case EDG_WLL_QUERY_ATTR_TIME:
- edg_wll_SoapToJobStatCode(*(collection->statName), &(out->attr_id.state));
- break;
- case EDG_WLL_QUERY_ATTR_USERTAG:
- out->attr_id.tag = strdup(collection->tagName);
- break;
- default:
- break;
- }
- edg_wll_SoapToQueryOp(in->op, &(out->op));
- switch ( out->op )
- {
- case EDG_WLL_QUERY_OP_WITHIN:
- if ( edg_wll_SoapToQueryVal(out->attr, in->value2, &(out->value2)) ) goto err;
- default:
- if ( edg_wll_SoapToQueryVal(out->attr, in->value1, &(out->value)) ) goto err;
- break;
- }
-
- return 0;
-err:
- edg_wll_QueryRecFree(out);
- return -1;
-}
-
-int edg_wll_QueryRecToSoap(
- struct soap *soap,
- const edg_wll_QueryRec *in,
- struct lbt__queryRecord *qr)
-{
- assert(in); assert(qr);
- memset(qr, 0, sizeof(*qr));
- if ( !in ) goto ret;
- edg_wll_QueryOpToSoap(in->op, &(qr->op));
-
- switch ( in->op ) {
- case EDG_WLL_QUERY_OP_WITHIN:
- if ( !(qr->value2 = soap_malloc(soap, sizeof(*(qr->value2)))) ) return SOAP_FAULT;
- if ( edg_wll_QueryValToSoap(soap, in->attr, &(in->value2), qr->value2) ) return SOAP_FAULT;
- default:
- if ( !(qr->value1 = soap_malloc(soap, sizeof(*(qr->value1)))) ) return SOAP_FAULT;
- if ( edg_wll_QueryValToSoap(soap, in->attr, &(in->value), qr->value1) ) return SOAP_FAULT;
- break;
- }
-
-ret:
- return SOAP_OK;
-}
-
-/**
- * Translate query conditions from Soap form to query rec structure
- *
- * \param IN in pointer to soap query condition
- * \param OUT out target array of queryRec
- */
-int edg_wll_SoapToQueryConds(const struct lbt__queryConditions *in, edg_wll_QueryRec **out)
-{
- int i;
- edg_wll_QueryRec *qr;
-
- assert(in); assert(out);
- if ( !(qr = calloc(in->__sizerecord+1, sizeof(*qr))) ) goto err;
- for ( i = 0; i < in->__sizerecord; i++ )
- if ( edg_wll_SoapToQueryRec(in, GLITE_SECURITY_GSOAP_LIST_GET(in->record, i), qr+i) ) goto err;
- *out = qr;
- return 0;
-
-err:
- if ( qr ) {
- for ( i = 0; qr[i].attr; i++ ) edg_wll_QueryRecFree(qr+i);
- free(qr);
- }
- return -1;
-}
-
-int edg_wll_QueryCondsToSoap(
- struct soap *soap,
- const edg_wll_QueryRec *in,
- struct lbt__queryConditions *qc)
-{
- int i;
-
-
- assert(qc);
- memset(qc, 0, sizeof(*qc));
- if ( !in )
- goto ret;
-
- edg_wll_AttrToSoap(in[0].attr, &(qc->attr));
-
- if ( in->attr == EDG_WLL_QUERY_ATTR_TIME ) {
- qc->statName = soap_malloc(soap, sizeof(*(qc->statName)));
- if ( !qc->statName ) return SOAP_FAULT;
- edg_wll_JobStatCodeToSoap(in->attr_id.state, qc->statName);
- }
- else if ( in->attr == EDG_WLL_QUERY_ATTR_USERTAG) {
- qc->tagName = soap_strdup(soap, in->attr_id.tag);
- if ( !qc->tagName ) return SOAP_FAULT;
- }
-
- i = 0;
- while ( in[i].attr ) i++;
-
- if ( !i )
- goto ret;
-
- GLITE_SECURITY_GSOAP_LIST_CREATE(soap, qc, record, struct lbt__queryRecord, i);
- if ( !qc->record )
- return SOAP_FAULT;
-
- for ( i = 0; in[i].attr; i++ )
- if ( edg_wll_QueryRecToSoap(soap, &in[i], GLITE_SECURITY_GSOAP_LIST_GET(qc->record, i)) )
- return SOAP_FAULT;
-
-ret:
- return SOAP_OK;
-}
-
-/**
- * Translate extended query conditions from Soap form to query rec structure
- *
- * \param IN in array of soap query condition
- * \param OUT out target array of queryRec
- */
-int edg_wll_SoapToQueryCondsExt(GLITE_SECURITY_GSOAP_LIST_TYPE(lbt, queryConditions) in, int __sizecondition, edg_wll_QueryRec ***out)
-{
- int i;
- edg_wll_QueryRec **qr;
-
- assert(out);
- if ( !(qr = calloc(__sizecondition + 1, sizeof(*qr))) ) return -1;
- for ( i = 0; i < __sizecondition; i++ )
- if ( edg_wll_SoapToQueryConds(GLITE_SECURITY_GSOAP_LIST_GET(in, i), qr+i) ) goto err;
-
- *out = qr;
- return 0;
-
-err:
- if ( qr ) {
- int j;
- for ( i = 0; qr[i]; i++ )
- {
- for ( j = 0; qr[i][j].attr; j++ ) edg_wll_QueryRecFree(qr[i]);
- free(qr[i]);
- }
- free(qr);
- }
- return -1;
-}
-
-
-/**
- * Translate extended query conditions from Soap form to query rec structure
- *
- * \param IN in target array of queryRec
- * \param OUT out_size number of array elements
- * \param OUT out array of soap query condition
- */
-int edg_wll_QueryCondsExtToSoap(
- struct soap *soap,
- const edg_wll_QueryRec **in,
- int *out_size,
- GLITE_SECURITY_GSOAP_LIST_TYPE(lbt, queryConditions) *out)
-{
- int i, size;
- GLITE_SECURITY_GSOAP_LIST_TYPE(lbt, queryConditions) qc;
- assert(in); assert(out);
-
- size = 0;
- while ( in[size] ) size++;
-
- if ( !size )
- goto ret;
- GLITE_SECURITY_GSOAP_LIST_CREATE0(soap, qc, size, struct lbt__queryConditions, size);
- if ( !qc ) return SOAP_FAULT;
-
- for ( i = 0; in[i]; i++ )
- if ( edg_wll_QueryCondsToSoap(soap, in[i], GLITE_SECURITY_GSOAP_LIST_GET(qc, i)) )
- return SOAP_FAULT;
-
-ret:
- *out = qc;
- *out_size = size;
- return SOAP_OK;
-}
-
-
-int edg_wll_JobsQueryResToSoap(
- struct soap *soap,
- const edg_wlc_JobId *jobs,
- const edg_wll_JobStat *states,
- struct _lbe__QueryJobsResponse *out)
-{
- int i;
-
-
- assert(out); //assert(out->states); assert(out->jobs);
- out->jobs = NULL;
- out->states = NULL;
- out->__sizejobs = 0;
- out->__sizestates = 0;
-
- if ( jobs ) {
- for ( i = 0; jobs[i]; i++ ) ;
- out->jobs = soap_malloc(soap, sizeof(*(out->jobs))*i);
- if ( !out->jobs ) return SOAP_FAULT;
- out->__sizejobs = i;
- for ( i = 0; jobs[i]; i++ ) {
- char *s;
- if ( !(s = edg_wlc_JobIdUnparse(jobs[i])) ) return SOAP_FAULT;
- if ( !(out->jobs[i] = soap_strdup(soap, s)) ) return SOAP_FAULT;
- free(s);
- }
- }
- if ( states ) {
- for ( i = 0; states[i].state; i++ ) ;
- GLITE_SECURITY_GSOAP_LIST_CREATE(soap, out, states, struct lbt__jobStatus, i);
- if ( !out->states ) return SOAP_FAULT;
-
- for ( i = 0; states[i].state; i++ )
- if ( edg_wll_StatusToSoap(soap, states+i, GLITE_SECURITY_GSOAP_LIST_GET(out->states, i)) )
- return SOAP_FAULT;
- }
-
- return SOAP_OK;
-}
-
-static void edg_wll_SoapToSource(enum lbt__eventSource in, edg_wll_Source *out)
-{
- assert(EDG_WLL_SOURCE_LB_SERVER + 1 == EDG_WLL_SOURCE__LAST);
-
- switch ( in ) {
- case UserInterface: *out = EDG_WLL_SOURCE_USER_INTERFACE; break;
- case NetworkServer: *out = EDG_WLL_SOURCE_NETWORK_SERVER; break;
- case WorkloadManager: *out = EDG_WLL_SOURCE_WORKLOAD_MANAGER; break;
- case BigHelper: *out = EDG_WLL_SOURCE_BIG_HELPER; break;
- case JobSubmission: *out = EDG_WLL_SOURCE_JOB_SUBMISSION; break;
- case LogMonitor: *out = EDG_WLL_SOURCE_LOG_MONITOR; break;
- case LRMS: *out = EDG_WLL_SOURCE_LRMS; break;
- case Application: *out = EDG_WLL_SOURCE_APPLICATION; break;
- case LBServer: *out = EDG_WLL_SOURCE_LB_SERVER; break;
- default: assert(0); break;
- }
-}
-
-
-/*
- * Soap to C and C to Soap enumeration translate functions.
- */
-
-@@@{
-foreach ('_common_', sort { $event->{order}->{$a} <=> $event->{order}->{$b} } getTypes $event) {
- my ($e, $upper_en, $soap_en, $en);
-
- $e = $_;
- if ($e eq '_common_') {
- $en = '';
- $upper_en = '';
- $soap_en = '';
- } else {
- $en = ucfirst $e;
- $upper_en = uc $e;
- $soap_en = $en;
- $soap_en = $1.ucfirst $2 while $soap_en =~ /([[:alpha:]]*)_([[:alpha:]_]*)/;
- }
-
- selectType $event $_;
- foreach ($event->getFieldsOrdered) {
- my $f = selectField $event $_;
-
- if ($f->{codes}) {
- my ($fn, $enum_name, $enum_value_prefix, $func2C_name, $func2S_name);
-
- $fn = ucfirst $f->{name};
- $upper_fn = uc $f->{name};
- $soap_fn = $fn;
- $soap_fn = $1.ucfirst $2 while $soap_fn =~ /([[:alpha:]]*)_([[:alpha:]_]*)/;
-
- $enum_name = $e eq '_common_' && $fn eq 'Level' ? "int": "enum edg_wll_${en}${fn}";
- $enum_value_prefix = $e eq '_common_' ? "EDG_WLL_${upper_fn}_" : "EDG_WLL_${upper_en}_";
- $soap_enum_name = "enum lbt__$soap_en$soap_fn ";
- if ($f->{optional}) {$soap_enum_name .= "*";}
-
- # Soap to C function
- $func2C_name = "edg_wll_SoapTo$soap_en$soap_fn";
- gen "\n";
- gen "static void $func2C_name(const ${soap_enum_name}in, $enum_name *out) {\n";
- if ($f->{optional}) {
- gen "\tif (in == NULL) {\n";
- gen "\t\t*out = ${enum_value_prefix}UNDEFINED;\n";
- gen "\t\treturn;\n";
- gen "\t}\n";
- gen "\n";
- gen "\tswitch(*in) {\n";
- } else {
- gen "\tswitch(in) {\n";
- }
- foreach $code (@{$f->{codes}}) {
- my ($enum_value, $soap_enum_value);
-
- $upper_cn = $code->{name};
- $enum_value = "${enum_value_prefix}${upper_cn}";
- $soap_enum_value = "lbt__${soap_en}${soap_fn}__${upper_cn}";
- gen "\tcase $soap_enum_value: *out = $enum_value; break;\n"
- }
- gen "\tdefault: assert(0);\n";
- gen "\t};\n";
- gen "}\n";
- gen "\n";
-
- # C to Soap function
- my $target;
-
- $func2S_name = "edg_wll_${soap_en}${soap_fn}ToSoap";
- gen "\n";
- gen "static void $func2S_name(struct soap *soap, const $enum_name in, ${soap_enum_name}*out) {\n";
- if ($f->{optional}) {
- gen "\tif (in == ${enum_value_prefix}UNDEFINED) {\n";
- gen "\t\t*out = NULL;\n";
- gen "\t\treturn;\n";
- gen "\t}\n";
- gen "\n";
- gen "\t*out = soap_malloc(soap, sizeof(**out));\n";
- $target = "**out";
- } else {
- $target = "*out";
- }
- gen "\tswitch(in) {\n";
- foreach $code (@{$f->{codes}}) {
- my ($enum_value, $soap_enum_value);
-
- $upper_cn = $code->{name};
- $enum_value = "${enum_value_prefix}${upper_cn}";
- $soap_enum_value = "lbt__${soap_en}${soap_fn}__${upper_cn}";
- gen "\tcase $enum_value: $target = $soap_enum_value; break;\n"
- }
- gen "\tdefault: assert(0);\n";
- gen "\t};\n";
- gen "}\n";
- gen "\n";
-
- } # if code
- } # fields
-} # _common_, types
-@@@}
-
-static void edg_wll_SourceToSoap(edg_wll_Source in, enum lbt__eventSource *out)
-{
- assert(EDG_WLL_SOURCE_LB_SERVER + 1 == EDG_WLL_SOURCE__LAST);
-
- switch ( in ) {
- case EDG_WLL_SOURCE_USER_INTERFACE: *out = UserInterface; break;
- case EDG_WLL_SOURCE_NETWORK_SERVER: *out = NetworkServer; break;
- case EDG_WLL_SOURCE_WORKLOAD_MANAGER: *out = WorkloadManager; break;
- case EDG_WLL_SOURCE_BIG_HELPER: *out = BigHelper; break;
- case EDG_WLL_SOURCE_JOB_SUBMISSION: *out = JobSubmission; break;
- case EDG_WLL_SOURCE_LOG_MONITOR: *out = LogMonitor; break;
- case EDG_WLL_SOURCE_LRMS: *out = LRMS; break;
- case EDG_WLL_SOURCE_APPLICATION: *out = Application; break;
- case EDG_WLL_SOURCE_LB_SERVER: *out = LBServer; break;
- default: assert(0); break;
- }
-}
-
-
-/**
- * TODO: not tested
- * Translate event structure to Soap event.
- *
- * \param INOUT soap instance to work with
- * \param IN event source event
- * \param OUT sevent target Soap event
- */
-int edg_wll_EventToSoap(struct soap* soap, const edg_wll_Event *event, struct lbt__event *sevent) {
- char *s;
-
- switch (event->any.type) {
-@@@{
- my ($soap_en);
-
- for my $e (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
- $event->getTypes) {
- my ($u);
-
- $u = uc $e;
- $soap_en = $e;
- while ($soap_en =~ /([[:alpha:]]*)_([[:alpha:]_]*)/) {
- $soap_en = $1.ucfirst($2);
- };
-gen qq {
-! case EDG_WLL_EVENT_$u:
-! VALUEEV_SET(sevent, $soap_en, soap_malloc(soap, sizeof(struct lbt__event$soap_en)));
-};
- selectType $event '_common_';
- for (getFieldsOrdered $event) {
- my ($f);
-
- $f = selectField $event $_;
- eventFieldAssign("\t\t\t", "event", "sevent", $e, $f, 1);
- }
-
- gen "\n";
-
- selectType $event $e;
- for (getFieldsOrdered $event) {
- my ($f);
-
- $f = selectField $event $_;
- eventFieldAssign("\t\t\t", "event", "sevent", $e, $f, 0);
- }
-gen qq {
-! break;
-!
-};
- }
-@@@}
- default:
- break;
- }
-
- return 1;
-}
-
-
-/**
- * TODO: not tested
- * Free Soap event.
- *
- * \param INOUT soap instance to work with
- * \param INOUT sevent released Soap event
- */
-void edg_wll_FreeSoapEvent(struct soap *soap, struct lbt__event *sevent) {
-@@@{
- my ($soap_en);
-
- for my $e (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } getTypes $event) {
- $soap_en = $e;
- $soap_en = $1.ucfirst $2 while $soap_en =~ /([[:alpha:]]*)_([[:alpha:]_]*)/;
-
- gen "\tif (VALUEEV_ISTYPE(sevent, $soap_en)) {\n";
-
- selectType $event '_common_';
- for (getFieldsOrdered $event) {
- my ($f);
-
- $f = selectField $event $_;
- eventFieldFree("\t\t", "sevent", $e, $f);
- }
-
- selectType $event $e;
- for (getFieldsOrdered $event) {
- my ($f);
-
- $f = selectField $event $_;
- eventFieldFree("\t\t", "sevent", $e, $f);
- }
- gen qq "\t\tsoap_dealloc(soap, VALUEEV_GET(sevent, $soap_en));\n";
- gen qq "\t}\n";
-}
-@@@}
- // XXX: element dealocation belongs to higher layer
-#if GSOAP_VERSION <= 20706
- soap_dealloc(soap, sevent);
-#endif
-}
-
-
-static void free_events(edg_wll_Event *events)
-{
- int i;
-
- if (events) {
- for (i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++)
- edg_wll_FreeEvent(&(events[i]));
- edg_wll_FreeEvent(&(events[i])); /* free last line */
- free(events);
- events = NULL;
- }
-}
-
-
-/**
- * Translate event array to Soap event array for eventsQueryResponse.
- *
- * \param INOUT soap instance to work with
- * \param IN events source array of the events
- * \param OUT out result Soap structure
- */
-int edg_wll_EventsQueryResToSoap(
- struct soap *soap,
- const edg_wll_Event *events,
- struct _lbe__QueryEventsResponse *out)
-{
- int i;
- struct lbt__event *event;
-
- /* alloc the events array */
- assert(out != NULL);
- memset(out, 0, sizeof(*out));
- for (out->__sizeevents = 0; events[out->__sizeevents].any.type != EDG_WLL_EVENT_UNDEF; out->__sizeevents++);
- if (!out->__sizeevents) return SOAP_OK;
- GLITE_SECURITY_GSOAP_LIST_CREATE(soap, out, events, struct lbt__event, out->__sizeevents);
- for (i = 0; i < out->__sizeevents; i++)
- memset(GLITE_SECURITY_GSOAP_LIST_GET(out->events, i), 0, sizeof(struct lbt__event));
- if (!out->events) return SOAP_FAULT;
-
- for (i = 0; i < out->__sizeevents; i++) {
- if (!edg_wll_EventToSoap(soap, &events[i], GLITE_SECURITY_GSOAP_LIST_GET(out->events, i))) goto err;
- }
-
- return SOAP_OK;
-
-err:
- event = GLITE_SECURITY_GSOAP_LIST_GET(out->events, 0);
- while (event) {
- edg_wll_FreeSoapEvent(soap, event);
- event++;
- }
- /*
- * XXX: better list destroy here w/o deallocstion in
- * edg_wll_FreeSoapEvent
- */
- soap_dealloc(soap, out->events);
-
- return SOAP_FAULT;
-}
-
-
-static int edg_wll_SoapToEvent(
- struct soap *soap,
- struct lbt__event *in,
- edg_wll_Event *out)
-{
- //XXX: needs flash
-
-@@@{
- for my $name (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } getTypes $event)
- {
- my $comment = getTypeComment $event $name;
- $name = $1.ucfirst $2 while $name =~ /([[:alpha:]]*)_([[:alpha:]_]*)/;
- gen "\t\tif (VALUEEV_ISTYPE(in, $name)) {\n";
- my $event_type = uc $name;
- gen "\t\t\tout->type = EDG_WLL_EVENT_$event_type;\n";
-
- for ('_common_',$name) {
- my $type = $_;
- selectType $event $type;
- for ($event->getFieldsOrdered) {
- my $f = selectField $event $_;
- my $fn = $f->{name};
- my $ft = $f->{type};
- my $tn = $f->getType;
- my $act;
- if ($type eq '_common_') {
- $act = 'any';
- } else {
- $act = lcfirst $name;
- if ($act =~ m/^pBS/) { $act = ucfirst $act; }
- if ($act =~ m/^condor/) { $act = ucfirst $act; }
- }
- my $usuc = $fn;
- $usuc = $1.uc($2).$3 while ($usuc =~ /([^_]*)_([a-z])(.*)/);
- my $fuc = ucfirst($usuc);
-
- my $src = "VALUEEV_GET(in, $name)->$usuc";
- if ($ft eq 'jobid') {
-
- gen "\t\t\tif ($src)\n";
- gen "\t\t\t\tedg_wlc_JobIdParse($src,&out->$act.$fn);\n";
- } elsif ($ft eq 'timeval') {
- gen "\t\t\tout->$act.$fn.tv_sec = $src->tvSec;\n";
- gen "\t\t\tout->$act.$fn.tv_usec = $src->tvUsec;\n";
- } elsif ($ft eq 'string') {
- gen "\t\t\tout->$act.$fn = $src;\n";
- gen "\t\t\tsoap_unlink(soap,$src);\n";
- } elsif ($ft eq 'int') {
- if ($f->{codes}) {
- if ($type eq '_common_') {
- gen "\t\t\tedg_wll_SoapTo$fuc($src,&(out->$act.$fn));\n";
- }
- else {
- gen "\t\t\tedg_wll_SoapTo$name$fuc($src,&(out->$act.$fn));\n";
- }
- }
- elsif ($f->{optional}) {
- gen "\t\t\tout->$act.$fn = *$src;\n";
- } else {
- gen "\t\t\tout->$act.$fn = $src;\n";
- }
- } elsif ($tn eq 'port' || $tn eq 'bool' || $tn eq 'float' || $ft eq 'double') {
- if ($f->{optional}) {
- gen "\t\t\tout->$act.$fn = *$src;\n";
- } else {
- gen "\t\t\tout->$act.$fn = $src;\n";
- }
- } elsif ($ft eq 'logsrc') {
- gen "\t\t\tedg_wll_SoapToSource($src, &(out->$act.$fn));\n";
- } else {
- gen "\t\t\tout->$act.$fn = $src;\n";
- }
- }
- }
- gen "\n\t\t\treturn SOAP_OK;\n";
- gen "\t\t}\n";
- }
-@@@}
-
- return 0;
-}
-
-
-/**
- * Translate Soap event array of eventsQueryResponse to event array.
- *
- * \param INOUT soap instance to work with
- * \param IN in result Soap structure
- * \param OUT out source array of the events
- */
-int edg_wll_SoapToEventsQueryRes(
- struct soap *soap,
- struct _lbe__QueryEventsResponse in,
- edg_wll_Event **out)
-{
- edg_wll_Event *events;
- int i;
-
-
- events = calloc(in.__sizeevents + 1, sizeof(*events));
- if (!events) return SOAP_FAULT;
-
- for (i=0; i < in.__sizeevents; i++) {
- if (edg_wll_SoapToEvent(soap, GLITE_SECURITY_GSOAP_LIST_GET(in.events, i), &events[i]) != SOAP_OK) {
- free_events(events);
- return SOAP_FAULT;
- }
- }
-
- *out = events;
- return SOAP_OK;
-}
-
+++ /dev/null
-#ifndef __EDG_WORKLOAD_LOGGING_LBSERVER_WS_TYPEREF_H__
-#define __EDG_WORKLOAD_LOGGING_LBSERVER_WS_TYPEREF_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern void edg_wll_JobStatCodeToSoap(edg_wll_JobStatCode, enum lbt__statName *);
-extern void edg_wll_SoapToJobStatCode(enum lbt__statName, edg_wll_JobStatCode *);
-
-extern void edg_wll_StatusToSoap(struct soap *, edg_wll_JobStat const *, struct lbt__jobStatus *);
-extern void edg_wll_SoapToStatus(struct soap *, struct lbt__jobStatus const *, edg_wll_JobStat *);
-
-extern void edg_wll_SoapToJobStatFlags(struct lbt__jobFlags const *, int *);
-extern int edg_wll_JobStatFlagsToSoap(struct soap *, const int, struct lbt__jobFlags *);
-
-extern void edg_wll_SoapToAttr(const enum lbt__queryAttr, edg_wll_QueryAttr *);
-extern void edg_wll_AttrToSoap(const edg_wll_QueryAttr, enum lbt__queryAttr *);
-
-extern void edg_wll_SoapToQueryOp(
- const enum lbt__queryOp,
- edg_wll_QueryOp *);
-extern void edg_wll_QueryOpToSoap(
- const edg_wll_QueryOp,
- enum lbt__queryOp *);
-
-extern int edg_wll_SoapToQueryVal(
- const edg_wll_QueryAttr,
- const struct lbt__queryRecValue *,
- union edg_wll_QueryVal *);
-extern int edg_wll_QueryValToSoap(struct soap *,
- const edg_wll_QueryAttr,
- const union edg_wll_QueryVal *,
- struct lbt__queryRecValue *);
-
-extern int edg_wll_SoapToQueryRec(
- const struct lbt__queryConditions *collection,
- const struct lbt__queryRecord *in,
- edg_wll_QueryRec *out);
-extern int edg_wll_QueryRecToSoap(struct soap *,
- const edg_wll_QueryRec *,
- struct lbt__queryRecord *);
-
-
-extern int edg_wll_SoapToQueryConds(
- const struct lbt__queryConditions *,
- edg_wll_QueryRec **);
-extern int edg_wll_QueryCondsToSoap(struct soap *,
- const edg_wll_QueryRec *,
- struct lbt__queryConditions *);
-
-extern int edg_wll_SoapToQueryCondsExt(
- GLITE_SECURITY_GSOAP_LIST_TYPE(lbt, queryConditions) in,
- int __sizecondition,
- edg_wll_QueryRec ***);
-extern int edg_wll_QueryCondsExtToSoap(struct soap *,
- const edg_wll_QueryRec **,
- int *,
- GLITE_SECURITY_GSOAP_LIST_TYPE(lbt, queryConditions) *);
-
-extern int edg_wll_JobsQueryResToSoap(struct soap *,
- edg_wlc_JobId *,
- edg_wll_JobStat *,
- struct _lbe__QueryJobsResponse *);
-
-extern int edg_wll_EventsQueryResToSoap(struct soap *,
- const edg_wll_Event *,
- struct _lbe__QueryEventsResponse *);
-extern int edg_wll_SoapToEventsQueryRes(
- struct soap *,
- struct _lbe__QueryEventsResponse,
- edg_wll_Event **);
-
-
-extern int edg_wll_EventToSoap(struct soap*, const edg_wll_Event *, struct lbt__event *);
-extern void edg_wll_FreeSoapEvent(struct soap *, struct lbt__event *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __EDG_WORKLOAD_LOGGING_LBSERVER_WS_TYPEREF_H__ */
+++ /dev/null
-SELECT e.event,j.userid,j.dg_jobid,e.code,e.prog,e.host,u.cert_subj,e.time_stamp,e.usec,e.level,e.arrived FROM events e,users u,jobs j WHERE e.jobid=j.jobid AND e.userid=u.userid AND e.code != 0 AND (j.jobid='WrCEKje9QTXFiSOZuPMLtw')
-0 294de3557d9d00b3d2d8a1e6aab028cf https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw 17 UserInterface lhun.ics.muni.cz anonymous 2003-08-07 11:08:40 432100 8 2003-08-07 11:08:40
-1 294de3557d9d00b3d2d8a1e6aab028cf https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw 2 NetworkServer lhun.ics.muni.cz anonymous 2003-08-07 11:09:05 664600 8 2003-08-07 11:09:05
-
-select name,value from short_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 0
-JDL x
-JOBTYPE SIMPLE
-NS NNNSSSS
-NSUBJOBS 0
-PARENT https://lhun.ics.muni.cz:4850/Qt7utj80miXexi7bkxyhnA
-SEQCODE (nil)
-SRC_INSTANCE (nil)
-
-select name,value from long_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 0
-
-select name,value from short_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 1
-FROM UserInterface
-FROM_HOST sending component hostname
-FROM_INSTANCE sending component instance
-LOCAL_JOBID new jobId (Condor Globus ...)
-SEQCODE UI=000002:NS=0000000001:WM=000000:BH=0000000000:JSS=000000:LM=000000:LRMS=000000:APP=000000:LBS=000000
-SRC_INSTANCE
-
-select name,value from long_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 1
+++ /dev/null
-#include <fstream>
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/CompilerOutputter.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-
-#include <glite/lb/consumer.h>
-#include <glite/lb/context-int.h>
-
-#include "lbs_db.h"
-#include "get_events.h"
-
-using namespace std;
-
-static const char *test_dir;
-
-class QueryEventsTest: public CppUnit::TestFixture
-{
- CPPUNIT_TEST_SUITE(QueryEventsTest);
- CPPUNIT_TEST(oneJob);
- CPPUNIT_TEST_SUITE_END();
-
-private:
- edg_wll_Context ctx;
-
- ifstream qry_file;
-
- vector<pair<string,vector<string> > > queries;
-
-public:
- void oneJob();
- int ExecStmt(const char *, edg_wll_Stmt *);
-
- void setUp() {
- edg_wll_InitContext(&ctx);
- ctx->mysql = (void *) this; /* XXX */
- }
-
-};
-
-void QueryEventsTest::oneJob()
-{
- edg_wll_QueryRec job[2];
- const edg_wll_QueryRec *jobs[2] = { job,NULL} ;
- edg_wll_Event *events;
-
- job[0].attr = EDG_WLL_QUERY_ATTR_JOBID;
- job[0].op = EDG_WLL_QUERY_OP_EQUAL ;
- edg_wlc_JobIdParse("https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw",
- &job[0].value.j);
- job[1].attr = EDG_WLL_QUERY_ATTR_UNDEF;
-
- string file(test_dir);
- file += "/oneJob.qry";
- qry_file.open(file.c_str());
-
- while (!qry_file.eof()) {
- string query,line;
- vector<string> rows;
-
- getline(qry_file,query);
- cout << "read: " << query <<endl;
- rows.clear();
-
- while (!qry_file.eof()) {
- getline(qry_file,line);
- if (line == "") break;
-
- rows.push_back(line);
- }
- rows.push_back("END");
- queries.push_back(pair<string,vector<string> >(query,rows));
- }
-
- qry_file.close();
-
- CPPUNIT_ASSERT(!edg_wll_QueryEventsServer(ctx,1,jobs,NULL,&events));
-}
-
-int QueryEventsTest::ExecStmt(const char *qry, edg_wll_Stmt *stmt_out)
-{
- vector<pair<string,vector<string> > >::iterator stmt = queries.begin();
-
- for (; stmt != queries.end(); stmt++) {
- const char *q = stmt->first.c_str();
-
- /* XXX: there some spaces at the end of qry */
- if (!strncmp(q,qry,strlen(q))) break;
- }
-
- if (stmt == queries.end()) {
- cerr << "query not found" << endl;
- CPPUNIT_ASSERT(0);
- }
- vector<string>::iterator *rows = new vector<string>::iterator(stmt->second.begin());
-
- *stmt_out = (edg_wll_Stmt) rows;
- return stmt->second.size()-1;
-}
-
-extern "C" {
-
-int edg_wll_ExecStmt(edg_wll_Context ctx,char *qry,edg_wll_Stmt *stmt)
-{
- cout << "edg_wll_ExecStmt: " << qry << endl;
-
- class QueryEventsTest *tst = (class QueryEventsTest *)(ctx->mysql);
- return tst->ExecStmt(qry, stmt);
-}
-
-int edg_wll_FetchRow(edg_wll_Stmt stmt, char **cols)
-{
- vector<string>::iterator *rows = (vector<string>::iterator *) stmt;
- char *row,*p,i=0;
-
- if (**rows == "END") return 0;
- row = strdup((*rows)->c_str());
- (*rows)++;
- for (p = strtok(row,"\t"); p; p = strtok(NULL,"\t"))
- cols[i++] = strdup(p);
-
- return i;
-}
-
-void edg_wll_FreeStmt(edg_wll_Stmt *) {}
-
-int debug;
-
-int edg_wll_QueryColumns(edg_wll_Stmt stmt, char**cols) { return 0; }
-char *edg_wll_TimeToDB(long t) { return NULL; }
-
-time_t edg_wll_DBToTime(char *c) { return (time_t)-1; }
-edg_wll_ErrorCode edg_wll_DBConnect(edg_wll_Context ctx, const char*str) {
- return (edg_wll_ErrorCode)0;
-}
-
-int edg_wll_Transaction(edg_wll_Context ctx) { return 0; }
-int edg_wll_Commit(edg_wll_Context ctx) { return 0; }
-int edg_wll_Rollback(edg_wll_Context ctx) { return 0; }
-
-edg_wll_ErrorCode edg_wll_bufferedInsert(edg_wll_bufInsert *bi, char *row) { return (edg_wll_ErrorCode) 0; };
-
-}
-
-CPPUNIT_TEST_SUITE_REGISTRATION(QueryEventsTest);
-
-int main (int ac,const char *av[])
-{
- CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
- CppUnit::TextUi::TestRunner runner;
-
- test_dir = ac >= 2 ? av[1] : "../test";
-
- runner.addTest(suite);
- return runner.run() ? 0 : 1;
-}
+++ /dev/null
-#include <iostream>
-#include <stdsoap2.h>
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/CompilerOutputter.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-
-#include <glite/lb/consumer.h>
-
-#include "bk_ws_H.h"
-#include "ws_typeref.h"
-
-using namespace std;
-
-class SoapConvTest: public CppUnit::TestFixture
-{
- CPPUNIT_TEST_SUITE(SoapConvTest);
- CPPUNIT_TEST(Conditions);
- CPPUNIT_TEST(States);
- CPPUNIT_TEST_SUITE_END();
-
-private:
- struct soap *soap;
- edg_wll_QueryRec **stdConds;
- edg_wll_JobStat stdStat;
-
- int stdRecCmp(edg_wll_QueryRec &, edg_wll_QueryRec &);
- int stdCondsCmp(edg_wll_QueryRec **, edg_wll_QueryRec **);
- int soapRecCmp(struct edgwll__QueryRec &, struct edgwll__QueryRec &);
- int soapCondsCmp(struct edgwll__QueryConditions &, struct edgwll__QueryConditions &);
-
-public:
- void setUp();
-
- void Conditions();
- void States();
-};
-
-void SoapConvTest::setUp()
-{
- soap = soap_new();
-
- stdConds = (edg_wll_QueryRec **)calloc(17, sizeof(edg_wll_QueryRec *));
-
- stdConds[0] = (edg_wll_QueryRec *)calloc(4, sizeof(edg_wll_QueryRec));
- stdConds[0][0].attr = EDG_WLL_QUERY_ATTR_STATUS;
- stdConds[0][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[0][0].value.i = EDG_WLL_JOB_DONE;
- stdConds[0][1].attr = EDG_WLL_QUERY_ATTR_STATUS;
- stdConds[0][1].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[0][1].value.i = EDG_WLL_JOB_RUNNING;
- stdConds[0][2].attr = EDG_WLL_QUERY_ATTR_STATUS;
- stdConds[0][2].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[0][2].value.i = EDG_WLL_JOB_CANCELLED;
-
- stdConds[1] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[1][0].attr = EDG_WLL_QUERY_ATTR_OWNER;
- stdConds[1][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[1][0].value.c = NULL;
-
- stdConds[2] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[2][0].attr = EDG_WLL_QUERY_ATTR_JOBID;
- stdConds[2][0].op = EDG_WLL_QUERY_OP_EQUAL;
- edg_wlc_JobIdCreate("my.server.org", 9000, &(stdConds[2][0].value.j));
-
- stdConds[3] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[3][0].attr = EDG_WLL_QUERY_ATTR_LOCATION;
- stdConds[3][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[3][0].value.c = strdup("my_location");
-
- stdConds[4] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[4][0].attr = EDG_WLL_QUERY_ATTR_DESTINATION;
- stdConds[4][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[4][0].value.c = strdup("my_destination");
-
- stdConds[5] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[5][0].attr = EDG_WLL_QUERY_ATTR_DONECODE;
- stdConds[5][0].op = EDG_WLL_QUERY_OP_GREATER;
- stdConds[5][0].value.i = 1;
-
- stdConds[6] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[6][0].attr = EDG_WLL_QUERY_ATTR_USERTAG;
- stdConds[6][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[6][0].attr_id.tag = strdup("color");
- stdConds[6][0].value.c = strdup("red");
-
- stdConds[7] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[7][0].attr = EDG_WLL_QUERY_ATTR_TIME;
- stdConds[7][0].op = EDG_WLL_QUERY_OP_WITHIN;
- stdConds[7][0].value.t = (struct timeval){10, 1};
- stdConds[7][0].value2.t = (struct timeval){20, 1};
-
- stdConds[8] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[8][0].attr = EDG_WLL_QUERY_ATTR_LEVEL;
- stdConds[8][0].op = EDG_WLL_QUERY_OP_WITHIN;
- stdConds[8][0].value.i = 10;
- stdConds[8][0].value2.i = 20;
-
- stdConds[9] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[9][0].attr = EDG_WLL_QUERY_ATTR_HOST;
- stdConds[9][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[9][0].value.c = strdup("any.host");
-
- stdConds[10] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[10][0].attr = EDG_WLL_QUERY_ATTR_SOURCE;
- stdConds[10][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[10][0].value.i = 2;
-
- stdConds[11] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[11][0].attr = EDG_WLL_QUERY_ATTR_INSTANCE;
- stdConds[11][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[11][0].value.c = strdup("any.instance");
-
- stdConds[12] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[12][0].attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE;
- stdConds[12][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[12][0].value.i = 1;
-
- stdConds[13] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[13][0].attr = EDG_WLL_QUERY_ATTR_RESUBMITTED;
- stdConds[13][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[13][0].value.c = strdup("where");
-
- stdConds[14] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[14][0].attr = EDG_WLL_QUERY_ATTR_PARENT;
- stdConds[14][0].op = EDG_WLL_QUERY_OP_EQUAL;
- edg_wlc_JobIdCreate("my.server.org", 8000, &(stdConds[14][0].value.j));
-
- stdConds[15] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[15][0].attr = EDG_WLL_QUERY_ATTR_EXITCODE;
- stdConds[15][0].op = EDG_WLL_QUERY_OP_LESS;
- stdConds[15][0].value.i = 255;
-/*
- * XXX: what is that for?
- stdConds[13] = (edg_wll_QueryRec *)calloc(2, sizeof(edg_wll_QueryRec));
- stdConds[13][0].attr = EDG_WLL_QUERY_ATTR_CHKPT_TAG;
- stdConds[13][0].op = EDG_WLL_QUERY_OP_EQUAL;
- stdConds[13][0].value.i = 1;
-*/
-}
-
-int SoapConvTest::stdCondsCmp(edg_wll_QueryRec **c1, edg_wll_QueryRec **c2)
-{
- int i, j;
-
-
- if ( (c1 && !c2) || (!c1 && c2) ) return 1;
- if ( c1 ) for ( i = 0; c1[i]; i++ ) {
- if ( !c2[i] ) return 2;
- for ( j = 0; c1[i][j].attr; j++ ) {
- if ( !c2[i][j].attr ) return 3;
- if ( stdRecCmp(c1[i][j], c2[i][j]) ) return 4;
- }
- if ( c2[i][j].attr ) return 3;
- }
- if ( c2[i] ) return 2;
-
- return 0;
-}
-
-int SoapConvTest::stdRecCmp(edg_wll_QueryRec &qr1, edg_wll_QueryRec &qr2)
-{
- if ( qr1.attr != qr2.attr ) return 1;
- if ( qr1.op != qr2.op ) return 1;
- switch ( qr1.attr) {
- case EDG_WLL_QUERY_ATTR_USERTAG:
- if ( strcmp(qr1.attr_id.tag, qr2.attr_id.tag) ) return 1;
- case EDG_WLL_QUERY_ATTR_OWNER:
- case EDG_WLL_QUERY_ATTR_LOCATION:
- case EDG_WLL_QUERY_ATTR_DESTINATION:
- case EDG_WLL_QUERY_ATTR_HOST:
- case EDG_WLL_QUERY_ATTR_INSTANCE:
- if ( (qr1.value.c && !qr2.value.c) || (!qr1.value.c && qr2.value.c) ) return 1;
- if ( qr1.value.c && qr2.value.c && strcmp(qr1.value.c, qr2.value.c) ) return 1;
- break;
- case EDG_WLL_QUERY_ATTR_JOBID:
- case EDG_WLL_QUERY_ATTR_PARENT: {
- char *s1, *s2;
- int rv;
-
- s1 = edg_wlc_JobIdUnparse(qr1.value.j);
- s2 = edg_wlc_JobIdUnparse(qr2.value.j);
- if ( !s1 || !s2 ) rv = 1;
- else rv = strcmp(s1, s2);
- free(s1); free(s2);
- return rv;
- }
- break;
- case EDG_WLL_QUERY_ATTR_STATUS:
- case EDG_WLL_QUERY_ATTR_DONECODE:
- case EDG_WLL_QUERY_ATTR_LEVEL:
- case EDG_WLL_QUERY_ATTR_SOURCE:
- case EDG_WLL_QUERY_ATTR_EVENT_TYPE:
- case EDG_WLL_QUERY_ATTR_RESUBMITTED:
- case EDG_WLL_QUERY_ATTR_EXITCODE:
- if ( (qr1.value.i != qr2.value.i)
- || (qr1.op == EDG_WLL_QUERY_OP_WITHIN && qr1.value2.i != qr2.value2.i) )
- return 1;
- break;
- case EDG_WLL_QUERY_ATTR_TIME:
- if ( (qr1.value.t.tv_sec != qr2.value.t.tv_sec
- || qr1.value.t.tv_usec != qr2.value.t.tv_usec)
- || (qr1.op == EDG_WLL_QUERY_OP_WITHIN
- && (qr1.value2.t.tv_sec != qr2.value2.t.tv_sec
- || qr1.value2.t.tv_usec != qr2.value2.t.tv_usec)) )
- return 1;
- break;
- /*
- * XXX: what about EDG_WLL_QUERY_ATTR_CHKPT_TAG ???
- */
- default:
- return 1;
- }
-
- return 0;
-}
-
-int SoapConvTest::soapCondsCmp(struct edgwll__QueryConditions &qc1, struct edgwll__QueryConditions &qc2)
-{
- int i, j;
-
-
- if ( qc1.__sizecondition != qc2.__sizecondition ) return 1;
- if ( (qc1.condition && !qc2.condition) || (!qc1.condition && qc2.condition) )
- for ( i = 0; i < qc1.__sizecondition; i++ ) {
- if ( qc1.condition[i]->attr != qc2.condition[i]->attr ) return 2;
- if ( qc1.condition[i]->__sizerecords != qc2.condition[i]->__sizerecords ) return 3;
- for ( j = 0; j < qc1.condition[i]->__sizerecords; j++ )
- if ( soapRecCmp(*(qc1.condition[i]->records[j]),
- *(qc2.condition[i]->records[j])) ) return 4;
- }
-
- return 0;
-}
-
-int SoapConvTest::soapRecCmp(struct edgwll__QueryRec &qr1, struct edgwll__QueryRec &qr2)
-{
- if ( qr1.op != qr2.op ) return 1;
- if ( (qr1.attrid->tag && !qr2.attrid->tag)
- || (!qr1.attrid->tag && qr2.attrid->tag)
- || (qr1.attrid->tag && strcmp(qr1.attrid->tag, qr2.attrid->tag)) ) return 2;
- if ( (qr1.attrid->state && !qr2.attrid->state)
- || (!qr1.attrid->state && qr2.attrid->state)
- || (qr1.attrid->state && (qr1.attrid->state != qr2.attrid->state)) ) return 3;
-
- if ( (qr1.value1 && !qr2.value1)
- || (!qr1.value1 && qr2.value1) ) return 3;
- if ( qr1.value1 ) {
- if ( (qr1.value1->i && !qr2.value1->i)
- || (!qr1.value1->i && qr2.value1->i)
- || (qr1.value1->i && qr1.value1->i != qr2.value1->i) )
- return 4;
- if ( (qr1.value1->c && !qr2.value1->c)
- || (!qr1.value1->c && qr2.value1->c)
- || (qr1.value1->c && strcmp(qr1.value1->c,qr2.value1->c)) )
- return 4;
- if ( (qr1.value1->t && !qr2.value1->t)
- || (!qr1.value1->t && qr2.value1->t)
- || (qr1.value1->t && memcmp(qr1.value1->t,qr2.value1->t,sizeof(*qr2.value1->t))) )
- return 4;
- }
-
- if ( (qr1.value2 && !qr2.value2)
- || (!qr1.value2 && qr2.value2) ) return 3;
- if ( qr1.value2 ) {
- if ( (qr1.value2->i && !qr2.value2->i)
- || (!qr1.value2->i && qr2.value2->i)
- || (qr1.value2->i && qr1.value2->i != qr2.value2->i) )
- return 4;
- if ( (qr1.value2->c && !qr2.value2->c)
- || (!qr1.value2->c && qr2.value2->c)
- || (qr1.value2->c && strcmp(qr1.value2->c,qr2.value2->c)) )
- return 4;
- if ( (qr1.value2->t && !qr2.value2->t)
- || (!qr1.value2->t && qr2.value2->t)
- || (qr1.value2->t && memcmp(qr1.value2->t,qr2.value2->t,sizeof(*qr2.value2->t))) )
- return 4;
- }
-
-
- return 0;
-}
-
-void SoapConvTest::Conditions()
-{
- struct edgwll__QueryConditions *soapConds, *soapConds2;
- edg_wll_QueryRec **stdConds2;
- int ret;
- int size;
- void *tmp1;
-
- ret = edg_wll_QueryCondsExtToSoap(soap, (const edg_wll_QueryRec**)stdConds, &soapConds);
- CPPUNIT_ASSERT_MESSAGE("edg_wll_QueryCondsExtToSoap()", ret == SOAP_OK);
- ret = edg_wll_SoapToQueryCondsExt(soapConds, &stdConds2, &size, &tmp);
- CPPUNIT_ASSERT_MESSAGE("edg_wll_SoapToQueryCondsExt()", !ret);
-
- CPPUNIT_ASSERT_MESSAGE("Converted std results differs", !stdCondsCmp(stdConds, stdConds2));
-
- ret = edg_wll_QueryCondsExtToSoap(soap, (const edg_wll_QueryRec**)stdConds2, &soapConds2);
- CPPUNIT_ASSERT_MESSAGE("edg_wll_QueryCondsExtToSoap()", ret == SOAP_OK);
-
- CPPUNIT_ASSERT_MESSAGE("Converted soap results differs", !soapCondsCmp(*soapConds, *soapConds2));
-}
-
-void SoapConvTest::States()
-{
- struct edgwll__JobStat *soapStat;
- edg_wll_JobStat stdStat2;
-}
-
-CPPUNIT_TEST_SUITE_REGISTRATION(SoapConvTest);
-
-int main (int ac,const char *av[])
-{
- CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
- CppUnit::TextUi::TestRunner runner;
-
- runner.addTest(suite);
- return runner.run() ? 0 : 1;
-}
+++ /dev/null
-#include <iostream>
-
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/CompilerOutputter.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-
-
-#include <glite/lb/producer.h>
-#include "lb_xml_parse.h"
-#include <glite/lb/xml_parse.h>
-
-class XMLParseTest: public CppUnit::TestFixture
-{
- CPPUNIT_TEST_SUITE(XMLParseTest);
- CPPUNIT_TEST(protoEventTest);
- CPPUNIT_TEST(protoStatusTest);
- CPPUNIT_TEST_SUITE_END();
-
-public:
- void protoEventTest();
- void protoStatusTest();
-
-
-};
-
-static char * compare_events(const edg_wll_Event *e1, const edg_wll_Event *e2)
-{
- if (e1->any.type != e2->any.type) return "type";
-@@@{
- selectType $event '_common_';
- for ($event->getFieldsOrdered) {
- my $f = selectField $event $_;
- my $fn = getName $f;
- my $ft = $f->{type};
-
- my $a = "e1->any.$fn";
- my $b = "e2->any.$fn";
-
- gen "\tif (!(".eval($main::compare{C}->{$ft}).")) return \"$fn\";\n";
- }
-
- gen "\tswitch(e1->any.type) {\n";
- for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} }
- $event->getTypes)
- {
- my $tu = uc $t;
- my $tl = lcfirst $t;
- if ($tl =~ m/^pBS/) { $tl = ucfirst $tl; }
- if ($tl =~ m/^condor/) { $tl = ucfirst $tl; }
-
- selectType $event $t;
- gen "\t\tcase EDG_WLL_EVENT\_$tu :\n";
- for ($event->getFieldsOrdered) {
- my $f = selectField $event $_;
- my $fn = $f->{name};
- my $ft = $f->{type};
-
- my $a = "e1->$tl.$fn";
- my $b = "e2->$tl.$fn";
-
- gen "\t\t\tif (!(".eval($main::compare{C}->{$ft}).")) return \"$fn\";\n";
- }
- gen "\t\tbreak;\n";
- }
-@@@}
- default: return "default";
- } /* switch */
- return NULL;
-}
-
-static char * compare_states(const edg_wll_JobStat s1, const edg_wll_JobStat s2)
-{
-@@@{
- selectType $status '_common_';
- for (getFieldsOrdered $status) {
- my $f = selectField $status $_;
- my $fn = getName $f;
- my $ft = $f->{type};
-
- my $a = "s1.$fn";
- my $b = "s2.$fn";
-
- if ($ft eq 'intlist') {
- gen "\tif ( (s1.$_ != NULL) && (s2.$_ == NULL) || (s1.$_ == NULL) && (s2.$_ != NULL) ) return \"$fn\";\n";
- }
- elsif ($ft eq 'strlist') {
- }
- elsif ($ft eq 'taglist') {
- }
- elsif ($ft eq 'stslist') {
- }
- else {
- gen "\tif (!(".eval($main::compare{C}->{$ft}).")) return \"$fn\";\n";
- }
- }
-@@@}
- return NULL;
-}
-
-void XMLParseTest::protoEventTest()
-{
- edg_wll_Context ctx;
- edg_wll_Event *e1, *e2;
- char *message, *et, *ed;
-
- edg_wll_InitContext(&ctx);
- e1 = (edg_wll_Event *) calloc(2,sizeof *e1);
- e1->any.type = EDG_WLL_EVENT_REGJOB;
-
- e1->regJob.jdl = strdup("very long job = \"blabla\" \\\\ \n hugh\t;");
- e1->regJob.ns = strdup("ns address");
- e1->regJob.jobtype = EDG_WLL_REGJOB_SIMPLE;
- e1->regJob.seed = strdup("1234");
-
- gettimeofday(&e1->any.timestamp,NULL);
-
- e1->any.host = strdup("some.host");
- e1->any.level = 7;
- e1->any.priority = 0;
- edg_wlc_JobIdParse("https://some.host:1234/x67qr549qc",&e1->any.jobId);
- e1->any.seqcode = EDG_WLL_SEQ_BIGHELPER_INITIAL;
- e1->any.user = strdup("/O=Grid/CN=This User");
- e1->any.source = EDG_WLL_SOURCE_USER_INTERFACE;
- e1->any.src_instance = strdup("UI");
-
- if (edg_wll_QueryEventsToXML(ctx, e1, &message)) {
- edg_wll_Error(ctx,&et,&ed);
- CPPUNIT_ASSERT_MESSAGE(std::string("QueryEventsToXML():") + et + " " + ed, 0);
- }
-
- CPPUNIT_ASSERT_MESSAGE("message: ", message);
-
- if (edg_wll_ParseQueryEvents(ctx, message, &e2)) {
- edg_wll_Error(ctx,&et,&ed);
- CPPUNIT_ASSERT_MESSAGE(std::string("ParseQueryEvents():") + et + " " + ed, 0);
- }
-
- if ((et = compare_events(e1,e2))) {
- CPPUNIT_ASSERT_MESSAGE(std::string("compare_events():") + et, 0);
- }
-}
-
-void XMLParseTest::protoStatusTest()
-{
- edg_wll_Context ctx;
- edg_wll_JobStat s1, s2;
- char *message, *et, *ed;
- const struct timeval some_timeval = {14,12};
-
-
- edg_wll_InitContext(&ctx);
- edg_wll_InitStatus(&s1);
-
- s1.state = EDG_WLL_JOB_SUBMITTED;
- edg_wlc_JobIdParse("https://some.host:1234/x67qr549qc",&s1.jobId);
- s1.owner = strdup("/O=Grid/CN=This User");
- s1.jobtype = EDG_WLL_STAT_SIMPLE;
- s1.seed = strdup("4321");
- s1.condorId = strdup("condorId");
- s1.globusId = strdup("globusId");
- s1.localId = strdup("localId");
- s1.jdl = strdup("jdl");
- s1.matched_jdl = strdup("matched_jdl");
- s1.destination = strdup("destination");
- s1.condor_jdl = strdup("condor_jdl");
- s1.rsl = strdup("rsl");
- s1.reason = strdup("reason");
- s1.location = strdup("location");
- s1.ce_node = strdup("ce_node");
- s1.network_server = strdup("network_server");
- s1.subjob_failed = 1;
- s1.done_code = EDG_WLL_STAT_FAILED;
- s1.exit_code = 123;
- s1.resubmitted = 1;
- s1.cancelling = 1;
- s1.cancelReason = strdup("cancelReason");
- s1.cpuTime = 10;
- s1.stateEnterTime = some_timeval;
- s1.lastUpdateTime = some_timeval;
- s1.expectUpdate = 20;
- s1.expectFrom = strdup("expectFrom");
- s1.acl = strdup("acl");
-
- if (edg_wll_JobStatusToXML(ctx, s1, &message)) {
- edg_wll_Error(ctx,&et,&ed);
- CPPUNIT_ASSERT_MESSAGE(std::string("QueryEventsToXML():") + et + " " + ed, 0);
- }
-
- CPPUNIT_ASSERT_MESSAGE("message: ", message);
-
- if (edg_wll_ParseJobStat(ctx, message, (long) strlen(message), &s2)) {
- edg_wll_Error(ctx,&et,&ed);
- CPPUNIT_ASSERT_MESSAGE(std::string("ParseJobStat():") + et + " " + ed, 0);
- }
-
- if ((et = compare_states(s1,s2))) {
- CPPUNIT_ASSERT_MESSAGE(std::string("compare_states():") + et, 0);
- }
-
-
-
-}
-
-CPPUNIT_TEST_SUITE_REGISTRATION(XMLParseTest);
-
-int main (int ac,const char *av[])
-{
- CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
- CppUnit::TextUi::TestRunner runner;
-
- runner.addTest(suite);
- return runner.run() ? 0 : 1;
-}
+++ /dev/null
-.project
-.cdtproject
\ No newline at end of file
+++ /dev/null
-LICENSE file for EGEE Middleware\r
-================================\r
-\r
-Copyright (c) 2004 on behalf of the EU EGEE Project: \r
-The European Organization for Nuclear Research (CERN), \r
-Istituto Nazionale di Fisica Nucleare (INFN), Italy\r
-Datamat Spa, Italy\r
-Centre National de la Recherche Scientifique (CNRS), France\r
-CS Systeme d'Information (CSSI), France\r
-Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden\r
-Universiteit van Amsterdam (UvA), Netherlands\r
-University of Helsinki (UH.HIP), Finlan\r
-University of Bergen (UiB), Norway\r
-Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom\r
-\r
-Redistribution and use in source and binary forms, with or without\r
-modification, are permitted provided that the following conditions are\r
-met: \r
-\r
-1. Redistributions of source code must retain the above copyright\r
-notice, this list of conditions and the following disclaimer.\r
-\r
-2. Redistributions in binary form must reproduce the above copyright\r
-notice, this list of conditions and the following disclaimer in the\r
-documentation and/or other materials provided with the distribution.\r
-\r
-3. The end-user documentation included with the redistribution, if\r
-any, must include the following acknowledgment: "This product includes\r
-software developed by The EU EGEE Project (http://cern.ch/eu-egee/)."\r
-Alternatively, this acknowledgment may appear in the software itself, if\r
-and wherever such third-party acknowledgments normally appear.\r
-\r
-4. The names EGEE and the EU EGEE Project must not be\r
-used to endorse or promote products derived from this software without\r
-prior written permission. For written permission, please contact\r
-<email address>.\r
-\r
-5. You are under no obligation whatsoever to provide anyone with any\r
-bug fixes, patches, or upgrades to the features, functionality or\r
-performance of the Software ("Enhancements") that you may develop over\r
-time; however, if you choose to provide your Enhancements to The EU\r
-EGEE Project, or if you choose to otherwise publish or distribute your\r
-Enhancements, in source code form without contemporaneously requiring\r
-end users of The EU EGEE Proejct to enter into a separate written license\r
-agreement for such Enhancements, then you hereby grant The EU EGEE Project\r
-a non-exclusive, royalty-free perpetual license to install, use, copy,\r
-modify, prepare derivative works, incorporate into the EGEE Middleware\r
-or any other computer software, distribute, and sublicense your\r
-Enhancements or derivative works thereof, in binary and source code\r
-form (if any), whether developed by The EU EGEE Project or third parties.\r
-\r
-THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED\r
-WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
-DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE\r
-FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\r
-BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\r
-WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\r
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\r
-IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
-\r
-This software consists of voluntary contributions made by many\r
-individuals on behalf of the EU EGEE Prject. For more information on The\r
-EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on\r
-EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/\r
-\r
-\r
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- Copyright (c) 2004 on behalf of the EU EGEE Project:
- The European Organization for Nuclear Research (CERN),
- Istituto Nazionale di Fisica Nucleare (INFN), Italy
- Datamat Spa, Italy
- Centre National de la Recherche Scientifique (CNRS), France
- CS Systeme d'Information (CSSI), France
- Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
- Universiteit van Amsterdam (UvA), Netherlands
- University of Helsinki (UH.HIP), Finland
- University of Bergen (UiB), Norway
- Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
-
- Build file for the GLite Middleware Loggin and Bookkeeping Subsystem
-
- Authors: Ales Krenek <ljocha@ics.muni.cz>
- Version info: $Id$
- Release: $Name$
-
- Revision history:
- $Log$
- Revision 1.43.2.1 2007/03/29 20:05:00 akrenek
- disable utils temporarily
-
- Revision 1.43 2007/03/21 13:10:38 akrenek
- utils -> jp.primary (sync with 3.1)
-
- Revision 1.42 2006/03/24 08:26:11 akrenek
- missing utils->client dependency (should fix nightly build)
-
- Revision 1.41 2006/03/15 17:35:35 akrenek
- cares
-
- Revision 1.40 2006/03/15 17:33:24 akrenek
- merge of 1.5 branch
-
- Revision 1.39 2005/11/27 21:51:18 eronchie
- Applied fix for bug 13928
-
- Revision 1.38 2005/11/22 12:13:47 eronchie
- Removed one utils
-
- Revision 1.37 2005/11/04 14:39:20 akrenek
- merge in the "lbonly" hack
-
- Revision 1.36.4.6 2006/02/06 12:10:00 akrenek
- make proxy depend on logger explicitely
-
- Revision 1.36.4.5 2005/12/02 11:15:33 akrenek
- resolved logger dependency conflict
-
- Revision 1.36.4.4 2005/12/02 10:04:14 jpospi
- server depends on logger
-
- Revision 1.36.4.3 2005/11/28 10:39:08 akrenek
- merge bug #13928 fix on the pre_cares branch
-
- Revision 1.36.4.2 2005/11/24 12:59:36 akrenek
- server depends on bones
-
- Revision 1.36.4.1 2005/11/24 12:32:02 akrenek
- merged in "lbonly"
-
- Revision 1.39 2005/11/27 21:51:18 eronchie
- Applied fix for bug 13928
-
- Revision 1.38 2005/11/22 12:13:47 eronchie
- Removed one utils
-
- Revision 1.37 2005/11/04 14:39:20 akrenek
- merge in the "lbonly" hack
-
- Revision 1.36 2005/10/15 13:36:26 akrenek
- added lb.utils
-
- Revision 1.35 2005/10/14 17:19:08 akrenek
- build also lb.utils
-
- Revision 1.34 2005/10/14 11:02:06 akrenek
- depends on jp.primary
-
- Revision 1.33 2005/09/19 15:23:45 akrenek
- "The gigantic merge"; from release 1.4 branch to HEAD
-
- Revision 1.32.2.2 2005/10/31 12:45:10 akrenek
- conditional disabling of cross-subsystem builds via "lbonly" property
-
- Revision 1.32.2.1 2005/08/18 10:36:05 eronchie
- Added cross-subsystem dependencies feature in org.glite.lb subsystem.
- Added wms-utils.jobid and security.gsoap-plugin among common dependencies.
- Added security.voms among server dependencies.
- At the moment I have not consider gridsite.core component.
- Once built gridsiste component, run ant in org.glite.lb to build the whole lb
- and its external gLite dependencies.
-
- Revision 1.32 2005/08/03 11:58:25 akrenek
- Merged the release 1.0 branch
-
- Revision 1.31 2005/05/26 15:13:37 zurek
- inserted module.build.file
-
- Revision 1.30 2005/03/17 09:59:31 zsalvet
- Add proxy target.
-
- Revision 1.29 2005/03/16 10:02:52 zsalvet
- proxy component added
-
- Revision 1.28.2.1 2005/02/12 01:38:13 glbuild
- Changed start time
-
- Revision 1.28 2004/11/29 15:16:26 zsalvet
- Add ws-interface to checkout/build machinery.
-
- Revision 1.27 2004/11/29 13:55:02 akrenek
- added dependence on ws-interface
-
- Revision 1.26 2004/10/29 22:53:41 dimeglio
- Use envset target
-
- Revision 1.25 2004/10/28 22:57:36 dimeglio
- Quoted ant command line parameters
-
- Revision 1.24 2004/10/28 18:19:30 dimeglio
- Added envcheck to individual components
-
- Revision 1.23 2004/10/26 15:12:06 dimeglio
- Fixed spelling error in envchecks
-
- Revision 1.22 2004/10/26 13:11:13 dimeglio
- Added dependency of clean on envchecks
-
- Revision 1.21 2004/10/25 20:57:38 dimeglio
- Use antExec
-
- Revision 1.20 2004/10/21 10:37:48 akrenek
- make server depend on logger due to notification interlogger
-
- Revision 1.19 2004/10/15 12:30:01 akrenek
- build with lb.sever-bones
-
- Revision 1.18 2004/09/29 13:35:39 flammer
- Only update of line formatting.
-
- Revision 1.17 2004/09/09 21:05:29 dimeglio
- Moved tag target to targets-common
-
- Revision 1.16 2004/08/27 03:03:12 dimeglio
- Preserve original timestamp when copying file and overwrite when new
-
- Revision 1.15 2004/08/27 02:46:52 dimeglio
- Added logic to create the tagged dependencies properties file
-
- Revision 1.14 2004/08/26 23:48:26 dimeglio
- Added generation of cruisecontrol config file entry
-
- Revision 1.13 2004/08/09 04:56:14 dimeglio
- Replaced rtag with tag
-
- Revision 1.12 2004/08/09 04:36:44 dimeglio
- Fixed inheritance of do.cvs.tag property
-
- Revision 1.11 2004/08/09 03:06:11 dimeglio
- Fixed inheritance of failonerror property
-
- Revision 1.10 2004/08/09 02:35:35 dimeglio
- Set default value for failonerror
-
- Revision 1.9 2004/08/08 19:07:17 dimeglio
- Added small.memory type of build
-
- Revision 1.8 2004/07/29 10:47:46 dimeglio
- Added server and logger
-
- Revision 1.7 2004/07/29 07:39:57 dimeglio
- Removed local envinfo and envcheck target (must use common ones)
-
- Revision 1.6 2004/07/16 16:25:43 flammer
- Added tags for automated adding of components.
-
- Revision 1.5 2004/07/06 17:43:33 flammer
- Update of classpath definitions, targets & configure file.
-
- Revision 1.4 2004/06/23 00:24:03 dimeglio
- Added common and client modules
-
- Revision 1.3 2004/06/22 18:24:35 dimeglio
- Added client interface module
-
- Revision 1.2 2004/06/18 23:05:12 dimeglio
- Added/upgraded default build scripts
-
--->
-
-<project name="lb" default="dist">
-
- <description>
- Ant build file to build the GLite Logging and Bookkeping Subsystem
- </description>
-
- <!-- =========================================
- Builds the GLite LB subsystem
- ========================================= -->
-
- <!-- Import baseline & user properties -->
- <import file="../org.glite/project/baseline.properties.xml" />
-
- <!-- Import subsystem build properties,
- subsystem properties &
- subsystem common properties -->
- <import file="./project/properties.xml" />
-
- <!-- Import global build properties and global properties -->
- <import file="${global.properties.file}" />
-
- <!-- =========================================
- Load dependencies properties files (order is important)
- ========================================= -->
- <property file="${user.dependencies.file}"/>
- <property file="${subsystem.dependencies.file}"/>
- <property file="${global.dependencies.file}"/>
-
- <!-- =========================================
- Load configure options
- ========================================= -->
- <import file="${global.configure.options.file}"/>
-
- <!-- =========================================
- Import global task definitions
- ========================================= -->
- <import file="${global.taskdefs.file}" />
-
- <!-- =========================================
- Import global compiler definitions
- ========================================= -->
- <import file="${global.compilerdefs.file}" />
-
- <!-- =========================================
- Import targets
- ========================================= -->
- <import file="${global.targets-common.file}"/>
-
- <!-- =========================================
- Load version file
- ========================================= -->
- <property file="${module.version.file}"/>
- <property file="${module.build.file}"/>
-
- <!-- ===============================================
- Public common targets
- =============================================== -->
-
- <target name="localinit" depends="envcheck">
-
- <echo> Preparing directories ... </echo>
-
- <mkdir dir="${stage.bin.dir}" />
- <mkdir dir="${stage.lib.dir}" />
- <mkdir dir="${stage.java.dir}" />
- <mkdir dir="${stage.inc.dir}" />
- <mkdir dir="${stage.int.dir}" />
-
- <mkdir dir="${dist.dir}" />
-
- </target>
-
- <target name="init" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="init"/>
- </antcall>
- </target>
-
- <target name="checkstyle" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="checkstyle"/>
- </antcall>
- </target>
-
- <target name="compile" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="compile"/>
- </antcall>
- </target>
-
- <target name="compiletest" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="compiletest"/>
- </antcall>
- </target>
-
- <target name="unittest" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="unittest"/>
- </antcall>
- </target>
-
- <target name="unitcoverage" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="unitcoverage"/>
- </antcall>
- </target>
-
- <target name="stage" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="stage"/>
- </antcall>
- </target>
-
- <target name="dist" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="dist"/>
- </antcall>
- </target>
-
- <target name="install" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="install"/>
- </antcall>
- </target>
-
- <target name="doc" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="doc"/>
- </antcall>
- </target>
-
- <target name="all" depends="localinit">
- <antcall target="buildmodules">
- <param name="target" value="all"/>
- </antcall>
- </target>
-
- <target name="clean" depends="envcheck">
-
- <property name="offline.repository" value="true" />
- <antcall target="buildmodules">
- <param name="target" value="clean"/>
- </antcall>
-
- <delete dir="${module.bin.dir}" />
- <delete dir="${module.lib.dir}" />
- <delete dir="${module.autosrc.dir}" />
- <delete dir="${module.autodoc.dir}" />
- <delete dir="${module.test.reports.dir}" />
-
- </target>
-
- <target name="cleanAll" depends="clean"/>
-
- <!-- ===============================================
- Private targets
- =============================================== -->
-
- <!-- ===============================================
- Modules proxy targets
- =============================================== -->
-
- <!-- component targets definitions tag = do not remove = -->
-
- <target name="security.gsoap-plugin" unless="lbonly" depends="envset">
- <if>
- <isset property="small.memory"/>
- <then>
- <exec dir="${security.subsystem.dir}" executable="${antExec}" failonerror="${failonerror}">
- <arg line="gsoap-plugin -Dtarget=${target} -Dsmall.memory=true -Dbootstrap=${bootstrap} -Dfailonerror=${failonerror} -Ddo.cvs.tag=${do.cvs.tag}"/>
- </exec>
- </then>
- <else>
- <ant dir="${security.subsystem.dir}"
- target="gsoap-plugin"
- inheritall="false" >
- <property name="target" value="${target}"/>
- </ant>
- </else>
- </if>
- </target>
-
- <target name="security.voms-api-c" unless="lbonly" depends="envset">
- <if>
- <isset property="small.memory"/>
- <then>
- <exec dir="${security.subsystem.dir}" executable="${antExec}" failonerror="${failonerror}">
- <arg line="voms-api-c -Dtarget=${target} -Dsmall.memory=true -Dbootstrap=${bootstrap} -Dfailonerror=${failonerror} -Ddo.cvs.tag=${do.cvs.tag}"/>
- </exec>
- </then>
- <else>
- <ant dir="${security.subsystem.dir}"
- target="voms-api-c"
- inheritall="false" >
- <property name="target" value="${target}"/>
- </ant>
- </else>
- </if>
- </target>
-
- <target name="wms-utils.jobid" unless="lbonly" depends="envset">
- <if>
- <isset property="small.memory"/>
- <then>
- <exec dir="${wms-utils.subsystem.dir}" executable="${antExec}" failonerror="${failonerror}">
- <arg line="jobid -Dtarget=${target} -Dsmall.memory=true -Dbootstrap=${bootstrap} -Dfailonerror=${failonerror} -Ddo.cvs.tag=${do.cvs.tag}"/>
- </exec>
- </then>
- <else>
- <ant dir="${wms-utils.subsystem.dir}"
- target="jobid"
- inheritall="false" >
- <property name="target" value="${target}"/>
- </ant>
- </else>
- </if>
- </target>
-
- <target name="jp.primary" unless="lbonly" depends="envset">
- <if>
- <isset property="small.memory"/>
- <then>
- <exec dir="${jp.subsystem.dir}" executable="${antExec}" failonerror="${failonerror}">
- <arg line="primary -Dtarget=${target} -Dsmall.memory=true -Dbootstrap=${bootstrap} -Dfailonerror=${failonerror} -Ddo.cvs.tag=${do.cvs.tag}"/>
- </exec>
- </then>
- <else>
- <ant dir="${jp.subsystem.dir}"
- target="primary"
- inheritall="false" >
- <property name="target" value="${target}"/>
- </ant>
- </else>
- </if>
- </target>
-
- <if>
- <isset property="setenvonly"/>
- <then>
- <property name="lbonly" value="yes"/>
- </then>
- </if>
-
- <target name="client-interface" unless="setenvonly" depends="envset">
- <if>
- <isset property="small.memory" />
- <then>
- <exec dir="${lb.subsystem.dir}.client-interface" executable="${antExec}" failonerror="${failonerror}">
- <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}""/>
- </exec>
- </then>
- <else>
- <ant dir="${lb.subsystem.dir}.client-interface"
- target="${target}"
- inheritall="false" />
- </else>
- </if>
- </target>
-
- <target name="ws-interface" unless="setenvonly" depends="envset">
- <if>
- <isset property="small.memory" />
- <then>
- <exec dir="${lb.subsystem.dir}.ws-interface" executable="${antExec}" failonerror="${failonerror}">
- <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}""/>
- </exec>
- </then>
- <else>
- <ant dir="${lb.subsystem.dir}.ws-interface"
- target="${target}"
- inheritall="false" />
- </else>
- </if>
- </target>
-
- <target name="server-bones" unless="setenvonly" depends="envset">
- <if>
- <isset property="small.memory" />
- <then>
- <exec dir="${lb.subsystem.dir}.server-bones" executable="${antExec}" failonerror="${failonerror}">
- <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}""/>
- </exec>
- </then>
- <else>
- <ant dir="${lb.subsystem.dir}.server-bones"
- target="${target}"
- inheritall="false" />
- </else>
- </if>
- </target>
-
- <target name="common" unless="setenvonly" depends="envset, globus, expat, c-ares, wms-utils.jobid, security.gsoap-plugin, client-interface">
- <if>
- <isset property="small.memory" />
- <then>
- <exec dir="${lb.subsystem.dir}.common" executable="${antExec}" failonerror="${failonerror}">
- <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}""/>
- </exec>
- </then>
- <else>
- <ant dir="${lb.subsystem.dir}.common"
- target="${target}"
- inheritall="false" />
- </else>
- </if>
- </target>
-
- <target name="client" unless="setenvonly" depends="envset, globus, expat, c-ares, client-interface, common">
- <if>
- <isset property="small.memory" />
- <then>
- <exec dir="${lb.subsystem.dir}.client" executable="${antExec}" failonerror="${failonerror}">
- <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}""/>
- </exec>
- </then>
- <else>
- <ant dir="${lb.subsystem.dir}.client"
- target="${target}"
- inheritall="false" />
- </else>
- </if>
- </target>
-
- <target name="server" unless="setenvonly" depends="envset, globus, expat, c-ares, mysql, gsoap, security.voms-api-c, jp.primary, client-interface, ws-interface, common, server-bones, logger">
- <if>
- <isset property="small.memory" />
- <then>
- <exec dir="${lb.subsystem.dir}.server" executable="${antExec}" failonerror="${failonerror}">
- <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}""/>
- </exec>
- </then>
- <else>
- <ant dir="${lb.subsystem.dir}.server"
- target="${target}"
- inheritall="false" />
- </else>
- </if>
- </target>
-
- <target name="proxy" unless="setenvonly" depends="envset, globus, expat, c-ares, client-interface, common, server, logger">
- <if>
- <isset property="small.memory" />
- <then>
- <exec dir="${lb.subsystem.dir}.proxy" executable="${antExec}" failonerror="${failonerror}">
- <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}""/>
- </exec>
- </then>
- <else>
- <ant dir="${lb.subsystem.dir}.proxy"
- target="${target}"
- inheritall="false" />
- </else>
- </if>
- </target>
-
- <target name="logger" unless="setenvonly" depends="envset, globus, expat, c-ares, client-interface, common">
- <if>
- <isset property="small.memory" />
- <then>
- <exec dir="${lb.subsystem.dir}.logger" executable="${antExec}" failonerror="${failonerror}">
- <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}""/>
- </exec>
- </then>
- <else>
- <ant dir="${lb.subsystem.dir}.logger"
- target="${target}"
- inheritall="false" />
- </else>
- </if>
- </target>
-
- <target name="utils" unless="setenvonly" depends="envset, globus, expat, c-ares, client, server, jp.primary">
- <if>
- <isset property="small.memory"/>
- <then>
- <exec dir="${lb.subsystem.dir}.utils" executable="${antExec}" failonerror="${failonerror}">
- <arg line="${target} -Dsmall.memory=true -Dbootstrap=${bootstrap} -Dfailonerror=${failonerror} -Ddo.cvs.tag=${do.cvs.tag}"/>
- </exec>
- </then>
- <else>
- <ant dir="${lb.subsystem.dir}.utils"
- target="${target}"
- inheritall="false" />
- </else>
- </if>
- </target>
-
- <!-- Main proxy -->
- <target name="buildmodules" depends="envset,
- client-interface,
- ws-interface,
- client,
- server-bones,
- common,
- server,
- proxy,
- logger,
- utils">
- <echo append="true" file="${global.project.dir}/cruisecontrol-stub.xml">
- <project name="${subsystem.name}" type="post-subsystem" packageName="${global.prefix}-${subsystem.prefix}"/>
- </echo>
- </target>
-
-</project>
+++ /dev/null
-deploy_all.diff - against RC31
-deploy_lb, deploy_jp - older patches
+++ /dev/null
-Index: org.glite/project/global.dependencies.properties
-===================================================================
-RCS file: /cvs/jra1mw/org.glite/project/global.dependencies.properties,v
-retrieving revision 1.482.2.279
-diff -u -p -u -r1.482.2.279 global.dependencies.properties
---- org.glite/project/global.dependencies.properties 4 Aug 2006 12:21:59 -0000 1.482.2.279
-+++ org.glite/project/global.dependencies.properties 1 Sep 2006 14:23:09 -0000
-@@ -1819,7 +1819,25 @@ ext.globus-sdk.description = The Globus
- ext.globus-sdk.rpm.name = vdt_globus_sdk
- ext.globus-sdk.rpm.version = ${ext.vdt.version}
- ext.globus-sdk.rpm.age = ${ext.vdt.age}
--
-+
-+# Globus vdt data server - grid ftp server
-+ext.globus-data-server.name = ${ext.globus.name}
-+ext.globus-data-server.vendor = ${ext.globus.vendor}
-+ext.globus-data-server.version = ${ext.globus.version}
-+ext.globus-data-server.platform = ${platform}
-+ext.globus-data-server.subdir = ${ext.globus-data-server.name}/${ext.globus-data-server.version}/${ext.globus-data-server.platform}
-+ext.globus-data-server.rep.base = ${jra1.rep.base}
-+ext.globus-data-server.rep.file =
-+ext.globus-data-server.rep.subdir =
-+ext.globus-data-server.rep.url = ${ext.globus-data-server.rep.base}/${ext.globus-data-server.subdir}/${ext.globus-data-server.rep.subdir}/${ext.globus-data-server.rep.file}
-+ext.globus-data-server.files =
-+ext.globus-data-server.download = http://www.cs.wisc.edu/vdt/releases/1.2.2/installing-rpms.html
-+ext.globus-data-server.homepage = http://www.cs.wisc.edu/vdt//index.html
-+ext.globus-data-server.description = The Globus Toolkit(R). This is the version packaged by VDT.
-+ext.globus-data-server.rpm.name = vdt_globus_data_server
-+ext.globus-data-server.rpm.version = ${ext.vdt.version}
-+ext.globus-data-server.rpm.age = 1
-+
- # GPT
- ext.gpt.name = gpt
- ext.gpt.vendor = gpt
-Index: org.glite.deployment/build.xml
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment/build.xml,v
-retrieving revision 1.61.2.2.2.12.2.26
-diff -u -p -u -r1.61.2.2.2.12.2.26 build.xml
---- org.glite.deployment/build.xml 24 Apr 2006 13:39:27 -0000 1.61.2.2.2.12.2.26
-+++ org.glite.deployment/build.xml 1 Sep 2006 14:23:09 -0000
-@@ -1619,6 +1619,39 @@
- </if>
- </target>
-
-+ <target name="jpps" unless="setenvonly" depends="envset,config">
-+ <if>
-+ <isset property="small.memory"/>
-+ <then>
-+ <exec dir="${deployment.subsystem.dir}.jpps" executable="${antExec}" failonerror="${failonerror}">
-+ <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}" "-Dbuild.name=${build.name}""/>
-+ </exec>
-+ </then>
-+ <else>
-+ <ant dir="${deployment.subsystem.dir}.jpps"
-+ target="${target}"
-+ inheritall="false" />
-+ </else>
-+ </if>
-+ </target>
-+
-+
-+ <target name="jpis" unless="setenvonly" depends="envset,config">
-+ <if>
-+ <isset property="small.memory"/>
-+ <then>
-+ <exec dir="${deployment.subsystem.dir}.jpis" executable="${antExec}" failonerror="${failonerror}">
-+ <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}" "-Dbuild.name=${build.name}""/>
-+ </exec>
-+ </then>
-+ <else>
-+ <ant dir="${deployment.subsystem.dir}.jpis"
-+ target="${target}"
-+ inheritall="false" />
-+ </else>
-+ </if>
-+ </target>
-+
- <target name="io-server" unless="setenvonly" depends="envset,config">
- <if>
- <isset property="small.memory"/>
-@@ -1730,6 +1763,8 @@
- wn,
- wms,
- lb,
-+ jpps,
-+ jpis,
- io-server,
- io-client,
- ce,
-Index: org.glite.deployment/project/dependencies.properties
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment/project/dependencies.properties,v
-retrieving revision 1.526.2.5.2.127.2.415.2.203
-diff -u -p -u -r1.526.2.5.2.127.2.415.2.203 dependencies.properties
---- org.glite.deployment/project/dependencies.properties 30 Aug 2006 07:41:36 -0000 1.526.2.5.2.127.2.415.2.203
-+++ org.glite.deployment/project/dependencies.properties 1 Sep 2006 14:23:09 -0000
-@@ -47,6 +47,8 @@
- org.glite.deployment.hydra.version = glite-deployment-hydra_R_1_0_3
- org.glite.deployment.io-client.version = glite-deployment-io-client_R_2_2_0
- org.glite.deployment.io-server.version = glite-deployment-io-server_R_2_1_8
-+ org.glite.deployment.jpps.version = HEAD
-+ org.glite.deployment.jpis.version = HEAD
- org.glite.deployment.lb.version = glite-deployment-lb_R_2_2_4
- org.glite.deployment.lcg-CE_torque.version = glite-deployment-lcg-CE_torque_R_3_0_4
- org.glite.deployment.lcg-CE.version = glite-deployment-lcg-CE_R_3_0_5
-Index: org.glite.deployment/project/glite.deployment.csf.xml
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment/project/glite.deployment.csf.xml,v
-retrieving revision 1.44.2.1.2.11.2.24
-diff -u -p -u -r1.44.2.1.2.11.2.24 glite.deployment.csf.xml
---- org.glite.deployment/project/glite.deployment.csf.xml 18 Apr 2006 15:42:14 -0000 1.44.2.1.2.11.2.24
-+++ org.glite.deployment/project/glite.deployment.csf.xml 1 Sep 2006 14:23:09 -0000
-@@ -667,6 +667,14 @@
- <equals arg1="${org.glite.deployment.lb.version}" arg2="HEAD" />
- </condition>
-
-+ <condition property="jpps.head">
-+ <equals arg1="${org.glite.deployment.jpps.version}" arg2="HEAD" />
-+ </condition>
-+
-+ <condition property="jpis.head">
-+ <equals arg1="${org.glite.deployment.jpis.version}" arg2="HEAD" />
-+ </condition>
-+
- <condition property="io-server.head">
- <equals arg1="${org.glite.deployment.io-server.version}" arg2="HEAD" />
- </condition>
-@@ -1571,6 +1579,28 @@
- tag="${org.glite.deployment.lb.version}" />
- </target>
-
-+ <!-- jpps component -->
-+ <target name="jpps" depends="get.jpps.head, get.jpps.tag"/>
-+ <target name="get.jpps.head" if="jpps.head">
-+ <cvs-co package="org.glite.deployment.jpps" />
-+ </target>
-+
-+ <target name="get.jpps.tag" unless="jpps.head">
-+ <cvs-co package="org.glite.deployment.jpps"
-+ tag="${org.glite.deployment.jpps.version}" />
-+ </target>
-+
-+ <!-- jpis component -->
-+ <target name="jpis" depends="get.jpis.head, get.jpis.tag"/>
-+ <target name="get.jpis.head" if="jpis.head">
-+ <cvs-co package="org.glite.deployment.jpis" />
-+ </target>
-+
-+ <target name="get.jpis.tag" unless="jpis.head">
-+ <cvs-co package="org.glite.deployment.jpis"
-+ tag="${org.glite.deployment.jpis.version}" />
-+ </target>
-+
- <!-- io-server component -->
- <target name="io-server" depends="get.io-server.head, get.io-server.tag"/>
- <target name="get.io-server.head" if="io-server.head">
-@@ -1667,6 +1697,8 @@
- wn,
- wms,
- lb,
-+ jpis,
-+ jpps,
- io-server,
- io-client,
- ce" />
-Index: org.glite.deployment.lb/config/scripts/glite-lb-config.py
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment.lb/config/scripts/glite-lb-config.py,v
-retrieving revision 1.65.2.4
-diff -u -p -u -r1.65.2.4 glite-lb-config.py
---- org.glite.deployment.lb/config/scripts/glite-lb-config.py 26 May 2006 12:24:22 -0000 1.65.2.4
-+++ org.glite.deployment.lb/config/scripts/glite-lb-config.py 1 Sep 2006 14:23:10 -0000
-@@ -129,7 +129,12 @@ python %s-config [OPTION...]""" % (self.
-
- if not os.path.exists('/tmp/mysql.sock'):
- os.symlink('/var/lib/mysql/mysql.sock', '/tmp/mysql.sock')
--
-+
-+
-+ #-------------------------------------------------------------------
-+ # start bkserver
-+ #-------------------------------------------------------------------
-+
- pid = glib.getPID('bkserverd')
- if pid != 0:
- print 'The gLite LB Server service is already running. Restarting...'
-@@ -142,7 +147,7 @@ python %s-config [OPTION...]""" % (self.
- pid = glib.getPID('bkserverd')
-
- if (pid != 0):
-- print "The gLite LB Server service has been started ",
-+ print "The gLite LB Server service has been started ",
- glib.printOkMessage()
- else:
- glib.printErrorMessage("Could not start the gLite LB Server service")
-@@ -151,6 +156,36 @@ python %s-config [OPTION...]""" % (self.
- return 1
-
- #-------------------------------------------------------------------
-+ # start jp-importer, if enabled
-+ #-------------------------------------------------------------------
-+
-+ lb_export = 0
-+ if params.has_key('lb.export.enabled'):
-+ if params['lb.export.enabled'] == "true":
-+ lb_export = 1
-+
-+ if lb_export:
-+ pid = glib.getPID('jp-importer')
-+ if pid != 0:
-+ print 'The gLite JP Importer service is already running. Restarting...'
-+ os.system('%s/etc/init.d/glite-jp-importer stop' % os.environ['GLITE_LOCATION'])
-+ else:
-+ print 'Starting the gLite JP Importer service...'
-+
-+ os.system('%s/etc/init.d/glite-jp-importer start' % os.environ['GLITE_LOCATION'])
-+
-+ pid = glib.getPID('jp-importer')
-+
-+ if (pid != 0):
-+ print "The gLite JP Importer service has been started ",
-+ glib.printOkMessage()
-+ else:
-+ glib.printErrorMessage("Could not start the gLite JP Importer service")
-+ glib.printErrorMessage("Please verify and re-run the script "),
-+ glib.printFailedMessage()
-+ return 1
-+
-+ #-------------------------------------------------------------------
- # Start Servicetool
- #-------------------------------------------------------------------
-
-@@ -170,6 +205,10 @@ python %s-config [OPTION...]""" % (self.
- if (pid != 0):
- os.system('%s/etc/init.d/glite-lb-bkserverd stop' % os.environ['GLITE_LOCATION'])
-
-+ #-------------------------------------------------------------------
-+ # Book Keeping Server
-+ #-------------------------------------------------------------------
-+
- pid = glib.getPID('bkserverd')
- if (pid != 0):
- print 'Could not stop the LB Server service ',
-@@ -180,6 +219,25 @@ python %s-config [OPTION...]""" % (self.
- glib.printOkMessage()
-
- #-------------------------------------------------------------------
-+ # JP Importer
-+ #-------------------------------------------------------------------
-+
-+ pid = glib.getPID('jp-importer')
-+ if (pid != 0):
-+ os.system('%s/etc/init.d/glite-jp-importer stop' % os.environ['GLITE_LOCATION'])
-+
-+ pid = glib.getPID('jp-importer')
-+ if (pid != 0):
-+ print 'Could not stop the JP Importer service ',
-+ glib.printFailedMessage()
-+ error_level = 1
-+ else:
-+ if params.has_key('lb.export.enabled'):
-+ if params['lb.export.enabled'] == "true":
-+ print 'The JP Importer service has been stopped ',
-+ glib.printOkMessage()
-+
-+ #-------------------------------------------------------------------
- # MySQL
- #-------------------------------------------------------------------
-
-@@ -204,6 +262,10 @@ python %s-config [OPTION...]""" % (self.
- if retval != 0:
- error_level = 1
-
-+ retval = os.system('%s/etc/init.d/glite-jp-importer status' % os.environ['GLITE_LOCATION'])
-+ if retval != 0:
-+ error_level = 1
-+
- #-------------------------------------------------------------------
- # Servicetool
- #-------------------------------------------------------------------
-@@ -334,7 +396,29 @@ python %s-config [OPTION...]""" % (self.
- print "\n==> MySQL database %s already exist\n" % params['lb.database.name']
-
- self.mysql.stop()
--
-+
-+ # ------------------------------------------------------------------
-+ # export from bkserver to cron
-+ # ------------------------------------------------------------------
-+ if params['GLITE_LB_EXPORT_ENABLED'] == "true":
-+ file = open('%s/etc/glite-lb-export-cron-wrapper.sh' % os.environ['GLITE_LOCATION'], 'w')
-+ file.write('#! /bin/sh\n')
-+ file.write('. %s\n' % glib.getInstallerExportFile())
-+ file.write('$GLITE_LOCATION/sbin/glite-lb-export.sh\n')
-+ file.close()
-+ os.system('/bin/chmod 0755 %s/etc/glite-lb-export-cron-wrapper.sh' % os.environ['GLITE_LOCATION'])
-+
-+ file = open('/etc/cron.d/glite-lb-export.cron', 'w')
-+ file.write('# periodically run purge and export jobs from bkserver\n')
-+ file.write('00,30 * * * * %s %s/etc/glite-lb-export-cron-wrapper.sh 1>/dev/null\n' % (params['glite.user.name'], os.environ['GLITE_LOCATION']))
-+ file.close()
-+ os.system('/bin/chmod 0644 /etc/cron.d/glite-lb-export.cron')
-+ else
-+ os.system('/bin/rm -f /etc/cron.d/glite-lb-export.cron')
-+
-+ # Touch cron spool directory to cause reloading of the crontabs
-+ os.system("/bin/touch /var/spool/cron")
-+
- #-------------------------------------------------------------------
- # RGMA servicetool: configure servicetool
- #-------------------------------------------------------------------
-@@ -420,6 +504,19 @@ def set_env():
- # Perl
- glib.addEnvPath("PERL5LIB", "%s/lib/perl:%s/lib/perl5" % (os.environ['GPT_LOCATION'],os.environ['GLITE_LOCATION']))
-
-+ # LB export
-+ glib.export('GLITE_LB_EXPORT_ENABLED', params['lb.export.enabled']);
-+ glib.export('GLITE_LB_EXPORT_JPPS', params['lb.export.jpps']);
-+ glib.export('GLITE_LB_EXPORT_JPREG_MAILDIR', params['lb.export.jpreg']);
-+ glib.export('GLITE_LB_EXPORT_JPDUMP_MAILDIR', params['lb.export.jpdump']);
-+ glib.export('GLITE_LB_EXPORT_DUMPDIR', params['lb.export.dump']);
-+ glib.export('GLITE_LB_EXPORT_DUMPDIR_KEEP', params['lb.export.dump.keep']);
-+ glib.export('GLITE_LB_EXPORT_JOBSDIR', params['lb.export.jobs']);
-+ glib.export('GLITE_LB_EXPORT_JOBSDIR_KEEP', params['lb.export.jobs.keep']);
-+ glib.export('GLITE_LB_EXPORT_PURGEDIR', params['lb.export.purge']);
-+ glib.export('GLITE_LB_EXPORT_PURGEDIR_KEEP', params['lb.export.purge.keep']);
-+ glib.export('GLITE_LB_EXPORT_PURGE_ARGS', '%s' % params['lb.export.purgeargs']);
-+
- # Set environment
- glib.setUserEnv()
-
-Index: org.glite.deployment.lb/config/templates/glite-lb.cfg.xml
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment.lb/config/templates/glite-lb.cfg.xml,v
-retrieving revision 1.21
-diff -u -p -u -r1.21 glite-lb.cfg.xml
---- org.glite.deployment.lb/config/templates/glite-lb.cfg.xml 13 Mar 2006 15:19:21 -0000 1.21
-+++ org.glite.deployment.lb/config/templates/glite-lb.cfg.xml 1 Sep 2006 14:23:10 -0000
-@@ -17,9 +17,16 @@
- parameter. Leave it empty of comment it out to use the same as 'glite.user.name'"
- value="changeme"/>
-
-- <mysql.root.password
-- description="The mysql root password"
-- value="changeme"/>
-+ <mysql.root.password
-+ description="The mysql root password"
-+ value="changeme"/>
-+
-+ <lb.export.jpps
-+ description="Job Provenance Primary Storage.
-+ [Example: localhost:8901][Type: string]"
-+ value="changeme"/>
-+
-+
-
- <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
- <!-- Advanced parameters - Change them if you know what you're doing -->
-@@ -55,6 +62,12 @@
- [Example: 17M][Type: Integer][Unit: MB]"
- value="17M"/>
-
-+ <lb.export.enabled
-+ description="Enables exports to Job Provenance.
-+ [Example: true][Type: boolean]"
-+ value="false"/>
-+
-+
- <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
- <!-- System parameters - You should leave these alone -->
- <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
-@@ -67,7 +80,47 @@
- <value>destination</value>
-
- </lb.index.list>
--
-+
-+ <lb.export.jpreg
-+ description="Spool directory where job registration requests are stored before delivered to JPPS.
-+ [Type: string]"
-+ value="/tmp/jpreg"/>
-+
-+ <lb.export.jpdump
-+ description="Spool directory where dump upload requests are stored before delivered to JPPS.
-+ [Type: string]"
-+ value="/tmp/jpdump"/>
-+
-+ <lb.export.dump
-+ description="Temporary directory for monitoring dumps, it's cleaned automatically.
-+ [Type: string]"
-+ value="/tmp/dump"/>
-+
-+ <lb.export.purge
-+ description="Temporary directory for dumps of purged jobs.
-+ [Type: string]"
-+ value="/tmp/purge"/>
-+
-+ <lb.export.purge.keep
-+ description="Directory for dumps of jobs that were already handled (sent to JPPS).
-+ [Type: string]"
-+ value=""/>
-+
-+ <lb.export.jobs
-+ description="Exported events in file per job form before delivered to JPPS.
-+ [Type: string]"
-+ value="/tmp/lb_export"/>
-+
-+ <lb.export.jobs.keep
-+ description="Keep the already handled exported events in file per job form.
-+ [Type: string]"
-+ value=""/>
-+
-+ <lb.export.purgeargs
-+ description="Arguments for LB purge process (a job in a given terminal state will be exported from the LB after timeouts defined here). See also glite-lb-purge documentation.
-+ [Example: -c 1h -a 1h -n 1h -o 1d][Type: string]"
-+ value="--cleared 2d --aborted 2w --cancelled 2w --other 2m"/>
-+
- </parameters>
-
- </config>
-Index: org.glite.deployment.lb/project/glite-lb.sdf.xml.template
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment.lb/project/glite-lb.sdf.xml.template,v
-retrieving revision 1.38.2.2
-diff -u -p -u -r1.38.2.2 glite-lb.sdf.xml.template
---- org.glite.deployment.lb/project/glite-lb.sdf.xml.template 2 May 2006 10:36:19 -0000 1.38.2.2
-+++ org.glite.deployment.lb/project/glite-lb.sdf.xml.template 1 Sep 2006 14:23:10 -0000
-@@ -57,6 +57,12 @@
- build="@org.glite.lb.server-bones.info.build@"
- arch="i386"/>
-
-+ <component name="glite-lb-client"
-+ version="@org.glite.lb.client.info.version@"
-+ age="@org.glite.lb.client.info.age@"
-+ build="@org.glite.lb.client.info.build@"
-+ arch="i386"/>
-+
- <component name="glite-wms-utils-jobid"
- version="@org.glite.wms-utils.jobid.info.version@"
- age="@org.glite.wms-utils.jobid.info.age@"
-@@ -105,6 +111,12 @@
- build="@org.glite.jp.ws-interface.info.build@"
- arch="i386"/>
-
-+ <component name="glite-jp-client"
-+ version="@org.glite.jp.client.info.version@"
-+ age="@org.glite.jp.client.info.age@"
-+ build="@org.glite.jp.client.info.build@"
-+ arch="i386"/>
-+
- <component name="gridsite"
- version="@org.gridsite.core.info.version@"
- age="@org.gridsite.core.info.age@"
+++ /dev/null
-This patch was merged to deploy_all.diff, don't use it anymore
-
-Index: org.glite/project/global.dependencies.properties
-===================================================================
-RCS file: /cvs/jra1mw/org.glite/project/global.dependencies.properties,v
-retrieving revision 1.479.2.70.2.3.2.3.2.1
-diff -u -r1.479.2.70.2.3.2.3.2.1 global.dependencies.properties
---- org.glite/project/global.dependencies.properties 9 May 2006 16:17:50 -0000 1.479.2.70.2.3.2.3.2.1
-+++ org.glite/project/global.dependencies.properties 30 Jun 2006 11:13:49 -0000
-@@ -15,7 +15,7 @@
- # Authors: Joachim Flammer <joachim.flammer@cern.ch>
- #
- # Version info: $Id$
--# Release: $Name$
-+# Release: $Name$
- #
- # Revision history:
- # $Log$
- # Revision 1.3 2006/06/30 11:30:28 mmulac
- # actualized patches
- # - against org.glite a org.glite.deployment from glite_R_3_0_0
- #
-@@ -1562,7 +1562,26 @@
- ext.globus-sdk.rpm.name = vdt_globus_sdk
- ext.globus-sdk.rpm.version = ${ext.vdt.version}
- ext.globus-sdk.rpm.age = 1
--
-+
-+# Globus vdt data server - grid ftp server
-+ext.globus-data-server.name = ${ext.globus.name}
-+ext.globus-data-server.vendor = ${ext.globus.vendor}
-+ext.globus-data-server.version = ${ext.globus.version}
-+ext.globus-data-server.platform = ${platform}
-+ext.globus-data-server.subdir = ${ext.globus-data-server.name}/${ext.globus-data-server.version}/${ext.globus-data-server.platform}
-+ext.globus-data-server.rep.base = ${jra1.rep.base}
-+ext.globus-data-server.rep.file =
-+ext.globus-data-server.rep.subdir =
-+ext.globus-data-server.rep.url = ${ext.globus-data-server.rep.base}/${ext.globus-data-server.subdir}/${ext.globus-data-server.rep.subdir}/${ext.globus-data-server.rep.file}
-+ext.globus-data-server.files =
-+ext.globus-data-server.download = http://www.cs.wisc.edu/vdt/releases/1.2.2/installing-rpms.html
-+ext.globus-data-server.homepage = http://www.cs.wisc.edu/vdt//index.html
-+ext.globus-data-server.description = The Globus Toolkit(R). This is the version packaged by VDT.
-+ext.globus-data-server.rpm.name = vdt_globus_data_server
-+ext.globus-data-server.rpm.version = ${ext.vdt.version}
-+ext.globus-data-server.rpm.age = 1
-+
-+
- # GPT
- ext.gpt.name = gpt
- ext.gpt.vendor = gpt
-@@ -3266,8 +3285,9 @@
- org.glite.dgas.version = glite-dgas_R_1_1_16
- org.glite.gpbox.version = glite-gpbox_R_1_0_15
- org.glite.jdl.version = glite-jdl_R_1_0_0
--org.glite.jp.version = glite-jp_R_1_1_3
--org.glite.lb.version = glite-lb_R_1_2_9
-+org.glite.jp.version = glite-jp_R_1_3_0
-+org.glite.lb.version = glite-lb_R_1_2_11
-+
- org.glite.rgma.version = glite-rgma_R_5_0_26
- org.glite.security.version = glite-security_R_3_0_15
- org.glite.service-discovery.version = glite-service-discovery_R_2_0_12
-Index: org.glite.deployment/build.xml
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment/build.xml,v
-retrieving revision 1.61.2.2.2.12.2.26
-diff -u -r1.61.2.2.2.12.2.26 build.xml
---- org.glite.deployment/build.xml 24 Apr 2006 13:39:27 -0000 1.61.2.2.2.12.2.26
-+++ org.glite.deployment/build.xml 30 Jun 2006 11:13:49 -0000
-@@ -9,7 +9,7 @@
- Authors: Alberto Di Meglio <alberto.di.meglio@cern.ch>
- Version info: $Id$
-
-- Release: $Name$
-+ Release: $Name$
-
- Revision history:
- $Log$
- Revision 1.3 2006/06/30 11:30:28 mmulac
- actualized patches
- - against org.glite a org.glite.deployment from glite_R_3_0_0
-
-@@ -1619,6 +1619,39 @@
- </if>
- </target>
-
-+ <target name="jpps" unless="setenvonly" depends="envset,config">
-+ <if>
-+ <isset property="small.memory"/>
-+ <then>
-+ <exec dir="${deployment.subsystem.dir}.jpps" executable="${antExec}" failonerror="${failonerror}">
-+ <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}" "-Dbuild.name=${build.name}""/>
-+ </exec>
-+ </then>
-+ <else>
-+ <ant dir="${deployment.subsystem.dir}.jpps"
-+ target="${target}"
-+ inheritall="false" />
-+ </else>
-+ </if>
-+ </target>
-+
-+
-+ <target name="jpis" unless="setenvonly" depends="envset,config">
-+ <if>
-+ <isset property="small.memory"/>
-+ <then>
-+ <exec dir="${deployment.subsystem.dir}.jpis" executable="${antExec}" failonerror="${failonerror}">
-+ <arg line="${target} "-Dsmall.memory=true" "-Dbootstrap=${bootstrap}" "-Dfailonerror=${failonerror}" "-Ddo.cvs.tag=${do.cvs.tag}" "-Dbuild.name=${build.name}""/>
-+ </exec>
-+ </then>
-+ <else>
-+ <ant dir="${deployment.subsystem.dir}.jpis"
-+ target="${target}"
-+ inheritall="false" />
-+ </else>
-+ </if>
-+ </target>
-+
- <target name="io-server" unless="setenvonly" depends="envset,config">
- <if>
- <isset property="small.memory"/>
-@@ -1730,6 +1763,8 @@
- wn,
- wms,
- lb,
-+ jpps,
-+ jpis,
- io-server,
- io-client,
- ce,
-Index: org.glite.deployment/project/dependencies.properties
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment/project/dependencies.properties,v
-retrieving revision 1.526.2.5.2.127.2.415.2.22
-diff -u -r1.526.2.5.2.127.2.415.2.22 dependencies.properties
---- org.glite.deployment/project/dependencies.properties 9 May 2006 12:33:18 -0000 1.526.2.5.2.127.2.415.2.22
-+++ org.glite.deployment/project/dependencies.properties 30 Jun 2006 11:13:49 -0000
-@@ -80,6 +80,10 @@
-
- org.glite.deployment.lb.version = glite-deployment-lb_R_2_2_3
-
-+ org.glite.deployment.jpis.version = HEAD
-+
-+ org.glite.deployment.jpps.version = HEAD
-+
- org.glite.deployment.glite-WMSLB.version = glite-deployment-glite-WMSLB_R_2_4_2
-
- org.glite.deployment.wn.version = glite-deployment-wn_R_2_3_7
-Index: org.glite.deployment/project/glite.deployment.csf.xml
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment/project/glite.deployment.csf.xml,v
-retrieving revision 1.44.2.1.2.11.2.24
-diff -u -r1.44.2.1.2.11.2.24 glite.deployment.csf.xml
---- org.glite.deployment/project/glite.deployment.csf.xml 18 Apr 2006 15:42:14 -0000 1.44.2.1.2.11.2.24
-+++ org.glite.deployment/project/glite.deployment.csf.xml 30 Jun 2006 11:13:50 -0000
-@@ -9,7 +9,7 @@
- Authors: Joachim Flammer <Joachim.Flammer@cern.ch>
-
- Version info: $Id$
-- Release: $Name$
-+ Release: $Name$
-
- Revision history:
- $Log$
- Revision 1.3 2006/06/30 11:30:28 mmulac
- actualized patches
- - against org.glite a org.glite.deployment from glite_R_3_0_0
-
-@@ -667,6 +667,14 @@
- <equals arg1="${org.glite.deployment.lb.version}" arg2="HEAD" />
- </condition>
-
-+ <condition property="jpps.head">
-+ <equals arg1="${org.glite.deployment.jpps.version}" arg2="HEAD" />
-+ </condition>
-+
-+ <condition property="jpis.head">
-+ <equals arg1="${org.glite.deployment.jpis.version}" arg2="HEAD" />
-+ </condition>
-+
- <condition property="io-server.head">
- <equals arg1="${org.glite.deployment.io-server.version}" arg2="HEAD" />
- </condition>
-@@ -1571,6 +1579,28 @@
- tag="${org.glite.deployment.lb.version}" />
- </target>
-
-+ <!-- jpps component -->
-+ <target name="jpps" depends="get.jpps.head, get.jpps.tag"/>
-+ <target name="get.jpps.head" if="jpps.head">
-+ <cvs-co package="org.glite.deployment.jpps" />
-+ </target>
-+
-+ <target name="get.jpps.tag" unless="jpps.head">
-+ <cvs-co package="org.glite.deployment.jpps"
-+ tag="${org.glite.deployment.jpps.version}" />
-+ </target>
-+
-+ <!-- jpis component -->
-+ <target name="jpis" depends="get.jpis.head, get.jpis.tag"/>
-+ <target name="get.jpis.head" if="jpis.head">
-+ <cvs-co package="org.glite.deployment.jpis" />
-+ </target>
-+
-+ <target name="get.jpis.tag" unless="jpis.head">
-+ <cvs-co package="org.glite.deployment.jpis"
-+ tag="${org.glite.deployment.jpis.version}" />
-+ </target>
-+
- <!-- io-server component -->
- <target name="io-server" depends="get.io-server.head, get.io-server.tag"/>
- <target name="get.io-server.head" if="io-server.head">
-@@ -1667,6 +1697,8 @@
- wn,
- wms,
- lb,
-+ jpis,
-+ jpps,
- io-server,
- io-client,
- ce" />
+++ /dev/null
-This patch was merged to deploy_all.diff, don't use it anymore.
-
-Index: org.glite.deployment.lb/config/scripts/glite-lb-config.py
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment.lb/config/scripts/glite-lb-config.py,v
-retrieving revision 1.65.2.3
-diff -u -r1.65.2.3 glite-lb-config.py
---- org.glite.deployment.lb/config/scripts/glite-lb-config.py 2 May 2006 10:36:16 -0000 1.65.2.3
-+++ org.glite.deployment.lb/config/scripts/glite-lb-config.py 30 Jun 2006 09:29:21 -0000
-@@ -127,7 +127,12 @@
-
- if not os.path.exists('/tmp/mysql.sock'):
- os.symlink('/var/lib/mysql/mysql.sock', '/tmp/mysql.sock')
--
-+
-+
-+ #-------------------------------------------------------------------
-+ # start bkserver
-+ #-------------------------------------------------------------------
-+
- pid = glib.getPID('bkserverd')
- if pid != 0:
- print 'The gLite LB Server service is already running. Restarting...'
-@@ -140,7 +145,7 @@
- pid = glib.getPID('bkserverd')
-
- if (pid != 0):
-- print "The gLite LB Server service has been started ",
-+ print "The gLite LB Server service has been started ",
- glib.printOkMessage()
- else:
- glib.printErrorMessage("Could not start the gLite LB Server service")
-@@ -149,6 +154,36 @@
- return 1
-
- #-------------------------------------------------------------------
-+ # start jp-importer, if enabled
-+ #-------------------------------------------------------------------
-+
-+ lb_export = 0
-+ if params.has_key('lb.export.enabled'):
-+ if params['lb.export.enabled'] == "true":
-+ lb_export = 1
-+
-+ if lb_export:
-+ pid = glib.getPID('jp-importer')
-+ if pid != 0:
-+ print 'The gLite JP Importer service is already running. Restarting...'
-+ os.system('%s/etc/init.d/glite-jp-importer stop' % os.environ['GLITE_LOCATION'])
-+ else:
-+ print 'Starting the gLite JP Importer service...'
-+
-+ os.system('%s/etc/init.d/glite-jp-importer start' % os.environ['GLITE_LOCATION'])
-+
-+ pid = glib.getPID('jp-importer')
-+
-+ if (pid != 0):
-+ print "The gLite JP Importer service has been started ",
-+ glib.printOkMessage()
-+ else:
-+ glib.printErrorMessage("Could not start the gLite JP Importer service")
-+ glib.printErrorMessage("Please verify and re-run the script "),
-+ glib.printFailedMessage()
-+ return 1
-+
-+ #-------------------------------------------------------------------
- # Start Servicetool
- #-------------------------------------------------------------------
-
-@@ -168,6 +203,10 @@
- if (pid != 0):
- os.system('%s/etc/init.d/glite-lb-bkserverd stop' % os.environ['GLITE_LOCATION'])
-
-+ #-------------------------------------------------------------------
-+ # Book Keeping Server
-+ #-------------------------------------------------------------------
-+
- pid = glib.getPID('bkserverd')
- if (pid != 0):
- print 'Could not stop the LB Server service ',
-@@ -178,6 +217,25 @@
- glib.printOkMessage()
-
- #-------------------------------------------------------------------
-+ # JP Importer
-+ #-------------------------------------------------------------------
-+
-+ pid = glib.getPID('jp-importer')
-+ if (pid != 0):
-+ os.system('%s/etc/init.d/glite-jp-importer stop' % os.environ['GLITE_LOCATION'])
-+
-+ pid = glib.getPID('jp-importer')
-+ if (pid != 0):
-+ print 'Could not stop the JP Importer service ',
-+ glib.printFailedMessage()
-+ error_level = 1
-+ else:
-+ if params.has_key('lb.export.enabled'):
-+ if params['lb.export.enabled'] == "true":
-+ print 'The JP Importer service has been stopped ',
-+ glib.printOkMessage()
-+
-+ #-------------------------------------------------------------------
- # MySQL
- #-------------------------------------------------------------------
-
-@@ -202,6 +260,10 @@
- if retval != 0:
- error_level = 1
-
-+ retval = os.system('%s/etc/init.d/glite-jp-importer status' % os.environ['GLITE_LOCATION'])
-+ if retval != 0:
-+ error_level = 1
-+
- #-------------------------------------------------------------------
- # Servicetool
- #-------------------------------------------------------------------
-@@ -332,7 +394,27 @@
- print "\n==> MySQL database %s already exist\n" % params['lb.database.name']
-
- self.mysql.stop()
--
-+
-+ # ------------------------------------------------------------------
-+ # export from bkserver to cron
-+ # ------------------------------------------------------------------
-+ if params['GLITE_LB_EXPORT_ENABLED'] == "true":
-+ file = open('%s/etc/glite-lb-export-cron-wrapper.sh' % os.environ['GLITE_LOCATION'], 'w')
-+ file.write('#! /bin/sh\n')
-+ file.write('. %s\n' % glib.getInstallerExportFile())
-+ file.write('$GLITE_LOCATION/examples/glite-lb-export.sh\n')
-+ file.close()
-+ os.system('/bin/chmod 0755 %s/etc/glite-lb-export-cron-wrapper.sh' % os.environ['GLITE_LOCATION'])
-+
-+ file = open('/etc/cron.d/glite-lb-export.cron', 'w')
-+ file.write('# periodically run purge and export jobs from bkserver\n')
-+ file.write('00,30 * * * * %s %s/etc/glite-lb-export-cron-wrapper.sh\n' % (params['glite.user.name'], os.environ['GLITE_LOCATION']))
-+ file.close()
-+ os.system('/bin/chmod 0755 /etc/cron.d/glite-lb-export.cron')
-+
-+ # Touch cron spool directory to cause reloading of the crontabs
-+ os.system("/bin/touch /var/spool/cron")
-+
- #-------------------------------------------------------------------
- # RGMA servicetool: configure servicetool
- #-------------------------------------------------------------------
-@@ -418,6 +500,17 @@
- # Perl
- glib.addEnvPath("PERL5LIB", "%s/lib/perl:%s/lib/perl5" % (os.environ['GPT_LOCATION'],os.environ['GLITE_LOCATION']))
-
-+ # LB export
-+ glib.export('GLITE_LB_EXPORT_ENABLED', params['lb.export.enabled']);
-+ glib.export('GLITE_LB_EXPORT_BKSERVER', params['lb.export.bkserver']);
-+ glib.export('GLITE_LB_EXPORT_JPPS', params['lb.export.jpps']);
-+ glib.export('GLITE_LB_EXPORT_JPREG_MAILDIR', params['lb.export.jpreg']);
-+ glib.export('GLITE_LB_EXPORT_JPDUMP_MAILDIR', params['lb.export.jpdump']);
-+ glib.export('GLITE_LB_EXPORT_DUMPDIR', params['lb.export.dump']);
-+ glib.export('GLITE_LB_EXPORT_DUMPDIR_OLD', params['lb.export.dump.old']);
-+ glib.export('GLITE_LB_EXPORT_EXPORTDIR', params['lb.export.export']);
-+ glib.export('GLITE_LB_EXPORT_PURGE_ARGS', '"%s"' % params['lb.export.purgeargs']);
-+
- # Set environment
- glib.setUserEnv()
-
-Index: org.glite.deployment.lb/config/templates/glite-lb.cfg.xml
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment.lb/config/templates/glite-lb.cfg.xml,v
-retrieving revision 1.21
-diff -u -r1.21 glite-lb.cfg.xml
---- org.glite.deployment.lb/config/templates/glite-lb.cfg.xml 13 Mar 2006 15:19:21 -0000 1.21
-+++ org.glite.deployment.lb/config/templates/glite-lb.cfg.xml 30 Jun 2006 09:29:21 -0000
-@@ -17,9 +17,16 @@
- parameter. Leave it empty of comment it out to use the same as 'glite.user.name'"
- value="changeme"/>
-
-- <mysql.root.password
-- description="The mysql root password"
-- value="changeme"/>
-+ <mysql.root.password
-+ description="The mysql root password"
-+ value="changeme"/>
-+
-+ <lb.export.jpps
-+ description="Job Provenance Primary Storage.
-+ [Example: localhost:8901][Type: string]"
-+ value="changeme"/>
-+
-+
-
- <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
- <!-- Advanced parameters - Change them if you know what you're doing -->
-@@ -55,6 +62,12 @@
- [Example: 17M][Type: Integer][Unit: MB]"
- value="17M"/>
-
-+ <lb.export.enabled
-+ description="Enables exports to Job Provenance.
-+ [Example: true][Type: boolean]"
-+ value="true"/>
-+
-+
- <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
- <!-- System parameters - You should leave these alone -->
- <!-- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -->
-@@ -67,7 +80,42 @@
- <value>destination</value>
-
- </lb.index.list>
--
-+
-+ <lb.export.bkserver
-+ description="Book Keeping Server service when differs from default port on localhost.
-+ [Example: localhost:9000][Type: string]"
-+ value=""/>
-+
-+ <lb.export.jpreg
-+ description="Maildir for job registrations.
-+ [Example: /tmp/jpreg][Type: string]"
-+ value=""/>
-+
-+ <lb.export.jpdump
-+ description="Maildir for job dumps.
-+ [Example: /tmp/jpdump][Type: string]"
-+ value=""/>
-+
-+ <lb.export.dump
-+ description="Dump directory for purged jobs.
-+ [Example: /tmp/dump][Type: string]"
-+ value=""/>
-+
-+ <lb.export.dump.old
-+ description="Dump directory for handled purged jobs.
-+ [Example: /tmp/dump.old][Type: string]"
-+ value=""/>
-+
-+ <lb.export.export
-+ description="Exported events divided to file per job.
-+ [Example: /tmp/lb_export][Type: string]"
-+ value=""/>
-+
-+ <lb.export.purgeargs
-+ description="Purge arguments (with timeouts).
-+ [Example: -a 1h -c 1h -n 1h -o 1d][Type: string]"
-+ value="-a 1d -c 1d -n 1d -o 7d"/>
-+
- </parameters>
-
- </config>
-Index: org.glite.deployment.lb/project/glite-lb.sdf.xml.template
-===================================================================
-RCS file: /cvs/jra1mw/org.glite.deployment.lb/project/glite-lb.sdf.xml.template,v
-retrieving revision 1.38.2.2
-diff -u -r1.38.2.2 glite-lb.sdf.xml.template
---- org.glite.deployment.lb/project/glite-lb.sdf.xml.template 2 May 2006 10:36:19 -0000 1.38.2.2
-+++ org.glite.deployment.lb/project/glite-lb.sdf.xml.template 30 Jun 2006 09:29:21 -0000
-@@ -57,6 +57,12 @@
- build="@org.glite.lb.server-bones.info.build@"
- arch="i386"/>
-
-+ <component name="glite-lb-client"
-+ version="@org.glite.lb.client.info.version@"
-+ age="@org.glite.lb.client.info.age@"
-+ build="@org.glite.lb.client.info.build@"
-+ arch="i386"/>
-+
- <component name="glite-wms-utils-jobid"
- version="@org.glite.wms-utils.jobid.info.version@"
- age="@org.glite.wms-utils.jobid.info.age@"
-@@ -105,6 +111,12 @@
- build="@org.glite.jp.ws-interface.info.build@"
- arch="i386"/>
-
-+ <component name="glite-jp-client"
-+ version="@org.glite.jp.client.info.version@"
-+ age="@org.glite.jp.client.info.age@"
-+ build="@org.glite.jp.client.info.build@"
-+ arch="i386"/>
-+
- <component name="gridsite"
- version="@org.gridsite.core.info.version@"
- age="@org.gridsite.core.info.age@"
+++ /dev/null
-These are the instructions how to build LB for VDT:
-
-$ mkdir lb4vdt
-$ cd lb4vdt
-$ export CVSROOT=:pserver:anonymous@jra1mw.cvs.cern.ch:/cvs/jra1mw
-$ cvs co org.glite.lb
-
-you may need to edit ./org.glite.lb/lb4vdt/Makefile.inc
-to specify some paths (some of them should be set automaticaly,
-e.g. by VDT_LOCATION)
-
-and then (still from the top directory) run
-
-$ ./org.glite.lb/lb4vdt/LB_install.sh 2>&1 | tee log
-
-:)
+++ /dev/null
-%
-% Official text received on October 6, 2004
-%
-\vfill{\bf Copyright }\copyright{\bf Members of the EGEE Collaboration. 2004.
-See http://eu-egee.org/partners for details on the copyright holders.
-
-EGEE (``Enabling Grids for E-science in Europe'') is a project funded by
-the European Union. For more information on the project, its partners
-and contributors please see http://www.eu-egee.org.
-
-You are permitted to copy and distribute verbatim copies of this
-document containing this copyright notice, but modifying this document
-is not allowed. You are permitted to copy this document in whole or in
-part into other documents if you attach the following reference to the
-copied elements: ``Copyright }\copyright{\bf 2004. Members of the EGEE
-Collaboration. http://www.eu-egee.org''
-
-The information contained in this document represents the views of
-EGEE as of the date they are published. EGEE does not guarantee that
-any information contained herein is error-free, or up to date.
-
-EGEE MAKES NO WARRANTIES, EXPRESS, IMPLIED, OR STATUTORY, BY
-PUBLISHING THIS DOCUMENT.}
-
+++ /dev/null
-\begin{center}
-{\bf Delivery Slip}
-\end{center}
-\begin{tabularx}{\textwidth}{|l|l|l|X|X|}
-\hline
- & {\bf Name} & {\bf Partner} & {\bf Date} & {\bf Signature} \\
-\hline
-{\bf From} & Ale\v s K\v{r}enek et al.& CESNET & May 28, 2005 & \\
-\hline
-{\bf Reviewed by} & & & & \\
-
-\hline
-{\bf Approved by} & & & & \\
-\hline
-\end{tabularx}
-
-\begin{center}
-{\bf Document Change Log}
-\end{center}
-
-\begin{tabularx}{\textwidth}{|l|l|X|X|}
-\hline
-{\bf Issue } & {\bf Date } & {\bf Comment } & {\bf Author } \\ \hline
-Initial version & Feb 28, 2005 & & A. K\v{r}enek \\ \hline
-Reviewer's comments & Mar 25, 2005 & comments reflected & A. K\v{r}enek \\
-\hline
-\end{tabularx}
-
-\begin{center}
-{\bf Document Change Record}
-\end{center}
-
-\begin{tabularx}{\textwidth}{|l|l|X|}
-\hline
-{\bf Issue } & {\bf Item } & {\bf Reason for Change } \\ \hline
-
-
-\hline
-\end{tabularx}
-
-\input{copyright}
+++ /dev/null
-CLPR=1; for jobid in `./stage/sbin/glite-lb-perftest_logjobs -m scientific.civ.zcu.cz:10000 -f stage/examples/perftest/perf_simple_avg_events.log -n 1000 -p /tmp/perftest_michal.log -s /tmp/proxy_michal.perf|grep https`; do stage/bin/glite-lb-logevent -x -S /tmp/proxy_michal.perfstore.sock -c $SEQCODE -j $jobid -s UserInterface -e Abort --reason Purge; done
+++ /dev/null
-./stage/sbin/glite-lb-purge -j /tmp/perftest_1000.jobids -m scientific.civ.zcu.cz:10000 -s
+++ /dev/null
- REG=1; for jobid in `./stage/sbin/glite-lb-perftest_logjobs -m scientific.civ.zcu.cz:10000 -f stage/examples/perftest/perf_simple_avg_events.log -n 1000 -p /tmp/perftest_michal.log -s /tmp/proxy_michal.perf|grep https`; do stage/examples/glite-lb-job_reg -j $jobid -s UserInterface ; done
+++ /dev/null
-./shared/egee/jra1-head/stage/sbin/perftest_il.sh 10
--------------------------------------------
-Logging test:
- - events sent through IPC and/or files
- - events discarded by IL immediately
--------------------------------------------
-a) events sent only by IPC
-b) events stored to files and sent by IPC
-
- small_job big_job small_dag big_dag
-a) 154727793 11240340 101479915 621678
-[jobs/day]
-b) 11540156 594389 10416164 402240
-[jobs/day]
------------------------------------
-Interlogger test:
- - events sent through IPC & files
- - events discarded in IL
------------------------------------
-a) disabled event parsing, the server address (jobid) is hardcoded
-b) disabled event synchronization from files
-c) disabled recovery thread
-x) disabled sync and recovery
-d) lazy bkserver connection close
-e) normal operation
-
- small_job big_job small_dag big_dag
-a) 14323607 547755 10158371 375594
-[jobs/day]
-b) 6284230 364547 4554967 300055
-[jobs/day]
-c) 7540122 412971 3186381 300417
-[jobs/day]
-x) 9672327 418137 2567653 297477
-[jobs/day]
-d) this test is not yet implemented
-e) 9650719 410507 3651840 301687
-[jobs/day]
------------------------------------
-Interlogger test:
- - events sent through IPC & files
- - events consumed by empty BS
------------------------------------
-a) disabled event parsing, the server address (jobid) is hardcoded
-b) disabled event synchronization from files
-c) disabled recovery thread
-x) disabled sync and recovery
-d) lazy bkserver connection close
-e) normal operation
-
- small_job big_job small_dag big_dag
-a) 2639788 182196 2035014 246654
-[jobs/day]
-b) 1170308 45973 759842 74898
-[jobs/day]
-c) 1060595 42047 921386 76638
-[jobs/day]
-x) 1091863 42247 518302 82129
-[jobs/day]
-d) this test is not yet implemented
-e) 1147040 41790 489257 76627
-[jobs/day]
-
+++ /dev/null
-[michal@scientific jra1-head]$ ./stage/sbin/perftest_il.sh 10
--------------------------------------------
-Logging test:
- - events sent through IPC and/or files
- - events discarded by IL immediately
--------------------------------------------
-a) events sent only by IPC
-b) events stored to files and sent by IPC
-
- small_job big_job small_dag big_dag
-a) 149765990 10933663 100162299 619924
-[jobs/day]
-b) 11857056 479615 2753618 277679
-[jobs/day]
------------------------------------
-Interlogger test:
- - events sent through IPC & files
- - events discarded in IL
------------------------------------
-a) disabled event parsing, the server address (jobid) is hardcoded
-b) disabled event synchronization from files
-c) disabled recovery thread
-x) disabled sync and recovery
-d) lazy bkserver connection close
-e) normal operation
-
- small_job big_job small_dag big_dag
-a) 13813170 268900 6448242 244203
-[jobs/day]
-b) 4525621 255055 6147103 241153
-[jobs/day]
-c) 9338319 217855 5497442 248429
-[jobs/day]
-x) 9335090 232292 3989195 236341
-[jobs/day]
-d) this test is not yet implemented
-e) 3283323 216013 7284868 256479
-[jobs/day]
------------------------------------
-Interlogger test:
- - events sent through IPC & files
- - events consumed by empty BS
------------------------------------
-a) disabled event parsing, the server address (jobid) is hardcoded
-b) disabled event synchronization from files
-c) disabled recovery thread
-x) disabled sync and recovery
-d) lazy bkserver connection close
-e) normal operation
-
- small_job big_job small_dag big_dag
-a) 4019651 44496 766972 95556
-[jobs/day]
-b) 1366885 47501 564779 90055
-[jobs/day]
-c) 1152594 47656 603774 97465
-[jobs/day]
-x) 1049069 48779 607913 88692
-[jobs/day]
-d) this test is not yet implemented
-e) 942509 46271 523129 91103
-[jobs/day]
-
-
-*************************************************************************
-
-
-[michal@scientific jra1-head]$ ./stage/sbin/perftest_il.sh 100
--------------------------------------------
-Logging test:
- - events sent through IPC and/or files
- - events discarded by IL immediately
--------------------------------------------
-a) events sent only by IPC
-b) events stored to files and sent by IPC
-
- small_job big_job small_dag big_dag
-a) 157966907 0 0 620546
-[jobs/day]
-b) 13833450 558487 10210340 283454
-[jobs/day]
------------------------------------
-Interlogger test:
- - events sent through IPC & files
- - events discarded in IL
------------------------------------
-a) disabled event parsing, the server address (jobid) is hardcoded
-b) disabled event synchronization from files
-c) disabled recovery thread
-x) disabled sync and recovery
-d) lazy bkserver connection close
-e) normal operation
-
- small_job big_job small_dag big_dag
-a) 12884330 316703 4447489 151870
-[jobs/day]
-b) 7980713 469667 4641283 244463
-[jobs/day]
-c) 8458472 556919 5657712 253640
-[jobs/day]
-x) 8149836 549678 4765300 257375
-[jobs/day]
-d) this test is not yet implemented
-e) 9687868 503933 4461079 247092
-[jobs/day]
------------------------------------
-Interlogger test:
- - events sent through IPC & files
- - events consumed by empty BS
------------------------------------
-a) disabled event parsing, the server address (jobid) is hardcoded
-b) disabled event synchronization from files
-c) disabled recovery thread
-x) disabled sync and recovery
-d) lazy bkserver connection close
-e) normal operation
-
- small_job big_job small_dag big_dag
-a) 9389344 97159 450483 68610
-[jobs/day]
-b) 1195400 82681 560118 88216
-[jobs/day]
-c) 1351879 88207 830072 102285
-[jobs/day]
-x) 1173835 85897 562648 0
-[jobs/day]
-d) this test is not yet implemented
-e) 1205291 78355 567658 87770
-[jobs/day]
+++ /dev/null
-[michal@scientific jra1-head]$ ./stage/sbin/perftest_il.sh 10
--------------------------------------------
-Logging test:
- - events sent through IPC and/or files
- - events discarded by IL immediately
--------------------------------------------
-a) events sent only by IPC
-b) events stored to files and sent by IPC
-
- small_job big_job small_dag big_dag
-a) 153599999 11157889 101479915 539075
-[jobs/day]
-b) 10835893 1059003 2577803 351095
-[jobs/day]
------------------------------------
-Interlogger test:
- - events sent through IPC & files
- - events discarded in IL
------------------------------------
-a) disabled event parsing, the server address (jobid) is hardcoded
-b) disabled event synchronization from files
-c) disabled recovery thread
-x) disabled sync and recovery
-d) lazy bkserver connection close
-e) normal operation
-
- small_job big_job small_dag big_dag
-a) 14148626 772362 11498383 376986
-[jobs/day]
-b) 5348851 489142 5558879 292071
-[jobs/day]
-c) 9042670 441000 5911613 287842
-[jobs/day]
-x) 7730298 414784 6579748 289834
-[jobs/day]
-d) this test is not applicable
-e) 9288325 365701 7189156 299604
-[jobs/day]
------------------------------------
-Interlogger test:
- - events sent through IPC & files
- - events consumed by empty BS
------------------------------------
-a) disabled event parsing, the server address (jobid) is hardcoded
-b) disabled event synchronization from files
-c) disabled recovery thread
-x) disabled sync and recovery
-d) lazy bkserver connection close
-e) normal operation
-
- small_job big_job small_dag big_dag
-a) 2219003 185867 1785164 258615
-[jobs/day]
-b) 1795503 48283 309380 77422
-[jobs/day]
-c) 1201618 39001 850436 74771
-[jobs/day]
-x) 1134249 48039 447017 74244
-[jobs/day]
-d) 5335078 207059 2438095 96295
-[jobs/day]
-e) 1019269 36465 875966 65565
-[jobs/day]
-
-
+++ /dev/null
-michal:~/shared/egee/jra1-head> ./stage/sbin/perftest_ll.sh 10
-----------------
-Locallogger test
-----------------
-a) glite-lb-logd-perf-nofile --noParse --noIPC
-b) glite-lb-logd-perf-nofile --noIPC
-c) glite-lb-logd-perf --noIPC
-d) glite-lb-logd-perf
-
-Number of jobs: 10
-
- small_job big_job small_dag big_dag
-a) 14.544066 14.590504 14.681760 9.264801 [events/sec]
- 125660 8404 97577 25821 [jobs/day]
-b) 14.614844 14.408043 14.279216 9.600877 [events/sec]
- 126272 8298 94901 26758 [jobs/day]
-c) 0.000000 0.000000 0.000000 0.000000 [events/sec]
- 0 0 0 0 [jobs/day]
-d) 13.331568 13.530218 13.420780 8.363152 [events/sec]
- 115184 7793 89196 23308 [jobs/day]
+++ /dev/null
--------------------
-LB chain test
--------------------
-- proxy & interlogger (lazy variant) running at umbar
-- bkserver running at sci
-- test variants:
- a) 10 jobs
- b) 100 jobs
- c) 1000 jobs
-
-
-Results:
-
- small_job big_job small_dag big_dag
----------------------------------------------------------------
-a) 3.0 x x x [mjobs/day]
-b) 1.0 x x x [mjobs/day]
-c) 0.6 x x x [mjobs/day]
-
-
+++ /dev/null
--------------------
-LB chain test
--------------------
-- proxy & interlogger (lazy variant) running at umbar
-- bkserver running at sci
-- test variants:
- a) 100 jobs, no background queries
- b) 1000 jobs, no background queries
- c) 10000 jobs, no background queries
- d) 100 jobs, 10 parallel queries
- e) 1000 jobs, 10 parallel queries, perf interlogger
- f) 1000 jobs, 10 parallel queries, normal interlogger
-- in d)-f) the server was queried by 10 independent clients for states
- of all jobs periodically with random sleep between queries (0-5sec)
-
-Results:
-
- small_job big_job small_dag big_dag
----------------------------------------------------------------
-a) 1.0 x x x [mjobs/day]
-b) 0.6 x x x [mjobs/day]
-c) 0.5 x x x [mjobs/day]
-d) 0.8 x x x [mjobs/day]
-e) 0.45 x x x [mjobs/day]
-f) 0.4 x x x [mjobs/day]
+++ /dev/null
-----------------------------------
-LB Proxy test
-----------------------------------
-Events are consumed:
-1) before parsing
-2) after parsing, before storing into database
-3) after storing into db, before computing state
-4) after computing state, before sending to IL
-5) by IL
-
- small_job big_job small_dag big_dag
-1) 43005186.489600 2852512.156800 31859581.824000 502823.721600
-[jobs/day]
-2) 37764713.548800 2438483.961600 26108871.523200 340065.648000
-[jobs/day]
-3) 1754530.243200 272980.540800 2051218.684800 0.000000
-[jobs/day]
-4) 1267110.000000 176052.182400 1506470.486400 0.000000
-[jobs/day]
-5) 329471.452800 48787.747200 318152.275200 0.000000
-[jobs/day]
+++ /dev/null
- ./stage/bin/glite-lb-interlogd -d -s /tmp/perftest_michal.sock --file-prefix=/tmp/perftest_michal.log --lazy
+++ /dev/null
-./stage/bin/glite-lb-proxy -d --silent -p /tmp/proxy_michal.perf --proxy-il-sock /tmp/perftest_michal.sock --proxy-il-fprefix /tmp/perftest_michal.log
+++ /dev/null
-./stage/bin/glite-lb-bkserverd -d --perf-sink=4 -p 10000 -w 10003 -S /tmp/purge_michal -D /tmp/dump_michal --silent
+++ /dev/null
-TEST=1; ./stage/sbin/glite-lb-perftest_logjobs -d proxy -m scientific.civ.zcu.cz:10000 -f stage/examples/perftest/perf_simple_avg_events.log -n 1000 -p /tmp/perftest_michal.log -s /tmp/proxy_michal.perf
+++ /dev/null
-\documentclass{egee}
-\usepackage{comment}
-
-\def\LB{L\&B}
-
-\title{\LB\ Performance Test Plan}
-\author{CESNET EGEE JRA1 team}
-\DocIdentifier{EGEE-JRA1-??}
-\Date{\today}
-\Activity{JRA1: Middleware Engineering and Integration}
-\DocStatus{DRAFT}
-\Dissemination{PUBLIC}
-\DocumentLink{}
-
-%\def\req{\noindent\textbf{Prerequisities:}}
-%\def\how{\noindent\textbf{How to run:}}
-%\def\result{\noindent\textbf{Expected result:}}
-
-\def\path#1{{\normalfont\textsf{#1}}}
-\def\code#1{\texttt{#1}}
-\def\todo#1{\textbf{TODO:} #1}
-
-\begin{document}
-
-\input{frontmatter}
-\newpage
-\tableofcontents
-\newpage
-
-\section{Rationale}
-\todo{}
-
-\begin{verbatim}
-
-L&B Performance Testing
-=======================
-
-- all source modifications for tests are in CVS, conditionaly compiled
- only with appropriate symbol
-
-- binaries for all tests are built using special property
- for ant target (or environment variable for Makefile), which
- compiles sources using the right #define combinations
-
-- component tests are run by shell scripts located under component
- directories, these tests may require binaries from other components,
- though
-
-- all tests use sequence of events for typical jobs (small job, big
- job, small DAG, big DAG) prepared beforehand. These events are
- stored in files in ULM format in CVS.
-
-- events are generated by stresslog program, which reads ULM text of
- events for particular test job and logs the event sequence directly
- by calling *_DoLogEvent<variant>. The number of test jobs is
- configurable. Stresslog inserts into every event timestamp when the
- event was generated and sent.*
-
-- event are consumed by breaking normal event processing either in the
- component being tested or the next component in chain, that is
- instrumented to read and discard events immediately. The consumption
- itself is done by calling special function which takes current time,
- extracts timestamp from event and prints the difference (ie. the
- event processing time).* These "break points" are chosen to measure
- throughput of the various component parts and to identify possible
- bottlenecks within the components.
-
- * the only exception is test of the logging library itself
-
-- test jobs are preregistered within the LB if the test includes
- bookkeeping server and/or proxy by the test script program and
- their id's are stored in separate file to enable re-use by other
- load-generating tools (status queries, for example)
-
-- test results:
- - some numbers must be reported by component themselves, not by
- the event generator (due to the asynchronous LB nature). The
- test script collects those numbers and presents them as the test
- result at the end of testing.
-
- - after completion test scripts print the table described for the
- respective tests filled in with measured values (ie. the table
- is not filled in manually by human tester)
-
- - event throughput = 1/(time_delivered - time_arrived)
- * only if next event is sent after previous was delivered
-
-? measure job throughput for event patterns of typical jobs or deduce
-job throughput from throughput of selected types of events?
-
-
-I) Component tests
- ***************
-
-- tests of the isolated components on one node
-- may require binaries from other components to produce/consume events
-
---------------------
-Logging library test
---------------------
-
-* component:
- org.glite.lb.client
-
-* binaries required:
- logevent_libtest
-
-* test shell script:
- perftest_loglib
-
-* input required:
- - events
-
-* test description:
- - measures time required to format given events into ULM. Events
- are read from file, parsed into components, timestamped and
- produced.
-
- - events produced:
- - by calling logging function edg_wll_LogEvent*()
-
- - events consumed:
- - discarded by logging function instead of sending via
- appropriate protocol (LogEventMaster)
-
-* results:
-
- job type (size) throughput (100k jobs)
- -----------------------------------------
- small job
- big job
- small DAG
- big DAG
-
-
-
-----------------
-Locallogger test
-----------------
-
-* component:
- org.glite.lb.logger
-
-* binaries required:
- stresslog
- glite_lb_logd_perf
- glite_lb_logd_perf_nofile
- - does not store events in file
- glite_lb_interlogd_perf_empty
- - consumes immediately after reading event
-
-* test shell script:
- perftest_logd
-
-* input required:
- - client and host certificates
- - events
-
-* test description:
- - measures time required for event to be sent from client to
- local logger and processed by locallogger. Localloger is
- either instructed (by option) or instrumented to skip some
- parts of event processing:
- a) no parse, no file, no ipc
- glite_lb_logd_perf_nofile --noParse --noIPC
- b) no file, no ipc
- glite_lb_logd_perf_nofile --noIPC
- c) no ipc
- glite_lb_logd_perf --noIPC
- d) normal operation
- glite_lb_logd_perf
-
- no parse - LL does not parse events
- no file - LL does not store events into files
- no ipc - LL does not send events through socket to IL
-
- - events produced:
- - stresslog sends events to logd using client->logd
- protocol (*_DoLogEvent())
-
- - events consumed:
- i) after storing into files
- ii) by "empty" IL
-
-* results:
-
-
-
-i) events stored in files
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- a)
- b)
- c)
- d)
-
-ii) events sent to IL
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- a)
- b)
- c)
- d)
-
-
-
-----------------
-Interlogger test
-----------------
-
-* component:
- org.glite.lb.logger
-
-* binaries required:
- stresslog
- glite_lb_interlogd_perf
- glite_lb_interlogd_perf_noparse
- - does not parse events, server address is hardcoded
- glite_lb_interlogd_perf_nosync
- - does not call event_store_sync()
- glite_lb_interlogd_perf_norecover
- - recovery thread disabled
- glite_lb_interlogd_perf_nosend
- - events are consumed instead of sending
- glite_lb_interlogd_perf_lazy
- - lazy closing connection to bkserver
- glite_lb_bkserverd_perf_empty
- - consumes event immediately after receiving
-
-* test shell script:
- perftest_interlogd
-
-* input required:
- - host certificate
- - events
-
-* test description:
- - measures time the event travels through interlogger.
- Interlogger is instrumented to skip some parts of eventh
- processing for particular test, specifically tests include
- these variants:
- a) disabled event parsing. The server address
- (eg. jobid) is hardcoded.
- b) disabled event synchronization from files
- c) disabled recovery thread
- d) lazy bkserver connection close
- e) normal operation
-
- - events produced:
- 1) stresslog sends events to interlogger using the unix
- domain socket and logd->interlogger protocol, events are
- stored in files (stresslog behaves like logd)
- TODO: pro toto neni funkce v producerske knihovne
- 2) interlogger reads events from event files created by
- stresslog (by recovery thread)
- 3) stresslog stores events to files and every n-th
- (optional argument) is sent also through the unix socket
-
- - events consumed:
- i) discarded instead of being sent
- ii) by "empty" bkserver
-
-* results:
-
-
-i) events discarded
-1) events received on socket
-(options 2 and 3 are not tested)
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- a)
- b)
- c)
- e)
-
-
-ii) events sent to empty bkserver
-1) events received on socket
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- a)
- b)
- c)
- d)
- e)
-
-
-2) events recovered from files
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- d)
- e)
-
-
-3) events synced from files, every 10th event sent on socket
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- a)
- b)
- c)
- d)
- e)
-
-
-------------
-LBProxy test
-------------
-
-* component:
- org.glite.lb.proxy
-
-* binaries required:
- stresslog
- glite_lb_proxy_perf_noparse
- - consumes events before parsing
- glite_lb_proxy_perf_nostore
- - consumes events before storing into database
- glite_lb_proxy_perf_nostate
- - consumes events before computing job status
- glite_lb_proxy_perf_nosend
- - consumes events before sending to interlogger
- glite_lb_interlogd_perf_empty
- - consumes immediately after reading event
-
-* test shell script:
- perftest_proxy
-
-* input required:
- - events
-
-* test description:
- - measures time required for processing event by LB proxy. Test
- is performed with (a)) and without (b)) checking for duplicit
- events.
-
- - events produced:
- - stresslog sends events using the IL protokol on local
- socket (using DoLogEventProxy())
-
- - events consumed:
- i) before parsing
- ii) before storing into database
- iii) after storing into database
- iv) after job status computation
- v) normal operation
-
-
-
-
-* results:
-
-a) with duplicity check:
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- i)
- ii)
- iii)
- iv)
- v)
-
-
-b) without duplicity check:
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- i)
- ii)
- iii)
- iv)
- v)
-
-
---------------
-LB server test
---------------
-
-* component:
- org.glite.lb.server
-
-* binaries required:
- stresslog
- glite_lb_server_perf_noparse
- - consumes events before parsing
- glite_lb_server_perf_nostore
- - consumes events before storing into database
- glite_lb_server_perf_nostate
- - consumes events before computing job status
-
-* test shell script:
- perftest_server
-
-* input required:
- - host certificates
- - events
-
-* test description:
- - measures time required for processing event by LB server. Test
- is performed with (a)) and without (b)) checking for duplicit
- events.
-
- - events produced:
- - stresslog sends events using the IL protokol (using DoLogEventDirect())
-
- - events consumed:
- i) before parsing
- ii) before storing into database
- iii) after storing into database
- iv) normal operation
-
-* results:
-
-a) with duplicity check:
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- i)
- ii)
- iii)
- iv)
-
-
-b) without duplicity check:
-
- throughput: small big small big
- job job DAG DAG
- -------------------------------------------------
- i)
- ii)
- iii)
- iv)
-
-
-
----------------------
-Job registration test
----------------------
-
-* component:
- org.glite.lb.server
- org.glite.lb.proxy
-
-* binaries required:
- stressreg
- - generates registration events
- glite_lb_bkserverd
- glite_lb_proxy
- glite_lb_bkserverd_perf_empty
- glite_lb_proxy_perf_empty
-
-* test shell script:
- perftest_jobreg
-
-* input required:
- - host & user certificates
-
-* test description:
- - measures time required to register given number of jobs (time
- to process registration event). The registration event is
- synchronous in principle, so it is possible to get results just
- from the client (stressreg). Test variants include:
- a) current implementation
- b) implementation of connection pool at the client
- c) parallel communication with server and proxy
-
-
- - events produced:
- - stressreg sends registration events by calling
- edg_wll_RegisterJob*()
-
- - events consumed:
- i) normally processed by server & proxy
- ii) server replies immediate success
- iii) proxy replies immediate success
-
-* results:
-
-a) current implementation
-
- throughput: one DAG DAG DAG
- job (1000 nodes) (5000 nodes) (10000 nodes)
- -----------------------------------------------------------------
- i)
- ii)
- iii)
-
-
-b) connection pool
-
- throughput: one DAG DAG DAG
- job (1000 nodes) (5000 nodes) (10000 nodes)
- -----------------------------------------------------------------
- i)
- ii)
- iii)
-
-
-c) parallel communication
-
- throughput: one DAG DAG DAG
- job (1000 nodes) (5000 nodes) (10000 nodes)
- -----------------------------------------------------------------
- i)
-
-
-
-\end{verbatim}
-
-\end{document}
\ No newline at end of file
+++ /dev/null
-\documentclass{egee}
-\usepackage{comment}
-
-\def\LB{L\&B}
-
-\title{\LB\ Test Plan}
-\author{CESNET EGEE JRA1 team}
-\DocIdentifier{EGEE-JRA1-??}
-\Date{\today}
-\Activity{JRA1: Middleware Engineering and Integration}
-\DocStatus{DRAFT}
-\Dissemination{PUBLIC}
-\DocumentLink{}
-
-\def\req{\noindent\textbf{Prerequisities:}}
-\def\how{\noindent\textbf{How to run:}}
-\def\result{\noindent\textbf{Expected result:}}
-
-\def\path#1{{\normalfont\textsf{#1}}}
-\def\code#1{\texttt{#1}}
-
-\def\todo#1{\textbf{TODO:} #1}
-
-
-\specialcomment{hints}{\par\noindent\textbf{Hints: }\begingroup\slshape}{\endgroup}
-%\includecomment{hints}
-
-\begin{document}
-
-\input{frontmatter}
-\newpage
-\tableofcontents
-\newpage
-
-\section{Rationale}
-\todo{}
-
-\section{Test Coverage}
-\todo{}
-
-\section{Test Cases}
-
-\subsection{Event delivery}
-
-% locallogger
-% bez dalsich demonu, registrovat job, vrati EAGAIN, objevi se fajly
-\subsubsection{Standalone locallogger -- job registration}
-\label{reg}
-\req\ running \path{glite-lb-logd} on the test node, don't start either
-\path{glite-lb-interlogd} or \path{glite-lb-bkserverd}
-
-\how\ call \code{edg\_wll\_RegisterJob}. Jobid's should preferably point
-to a~remote \LB\ server.
-
-\result\ The API call returns EAGAIN, but locallogger creates an event file
-in its storage.
-The file should contain single line RegJob event.
-
-\begin{hints}
-\path{glite-lb-regjob} example can be used. It generates a~unique jobid,
-prints it and calls \LB\ API appropriately.
-\end{hints}
-
-% async -- prida do fajlu, OK
-% logevent
-\subsubsection{Standalone locallogger -- log event}
-\label{log}
-\req\ running \path{glite-lb-logd} only, files generated in test~\ref{reg}.
-
-\how\ call \code{edg\_wll\_Log*} for various event types in a~sequence
-resebmling real \LB\ usage, using the same jobid's as in test~\ref{reg}
-
-\result\ API calls return 0, events are added one per line to the locallogger files
-
-\begin{hints}
-\path{glite-lb-logev} client program can be used.
-
-\path{glite-lb-*.sh} examples may be adapted to produce reasonable seqences
-of events.
-\end{hints}
-
-\subsubsection{Interlogger recovery}
-\label{recover}
-% recover interloggeru
-% il & server (remote)
-% spustit, protlaci soubory na server, soubory zmizi, lze se dotazat na stav
-\req\ running \path{glite-lb-bkserverd} on the machine and port where
-jobid's from \ref{reg} point to; files generated in~\ref{log}.
-
-\how\ Make a~copy of the files created in~\ref{log}, then start
-\path{glite-lb-interlogd}. After approx. 10s check the jobs
-with \code{edg\_wll\_JobLog} call.
-
-\result \code{edg\_wll\_JobLog} should return the same events that were
-contained in the locallogger files. The files should be removed by
-interlogger after approx. 1 min.
-
-\begin{hints}
-\path{glite-lb-joblog} example outputs the events in (almost) the same
-format as the locallogger files.
-\end{hints}
-
-% event delivery
-% poslat .sh, job log vrati to, co bylo ve fajlech
-\subsubsection{Normal event delivery}
-\label{normal}
-\req\ all \LB\ daemons running (\path{glite-lb-logd}, \path{glite-lb-interlogd},
-\path{glite-lb-bkserverd}
-
-\how\
-\begin{enumerate}
-
-\item Register jobs with \code{edg\_wll\_RegsterJob}
-\item Log reasonable sequences of events with \code{edg\_wll\_Log*}.
-\item Check with \code{edg\_wll\_JobLog}
-that the events got delivered afterwards (approx. 10s).
-\end{enumerate}
-
-\result\ API calls should return 0. The same events that were logged must be returned.
-
-\begin{hints}
-\path{glite-lb-*.sh} scripts produce reasonable seqences of events, including
-the job initial registration.
-
-There is approx. 1min time window in which the locallogger files exist.
-They can be grabbed and used for comparing the events as in~\ref{recover}.
-
-\end{hints}
-
-\subsection{Job state computation}
-
-% normal event delivery & job state machine
-% .sh, dotaz na stav
-\subsubsection{Normal job states}
-\label{state}
-\req\ \path{glite-lb-bkserverd} running, events from \ref{normal} logged.
-
-\how\ Check state of the jobs with \code{edg\_wll\_JobStatus}.
-
-\result\ The API call should return 0, the jobs should be in the expected
-states. Thorough tests may also cross check the values supplied in the
-events (e.g. destination computing element) wrt. the values reported in the job states.
-
-\begin{hints}
-\path{glite-lb-*.sh} scripts produce sequences of events resultning
-in the job state same as the `*' part of the script name.
-\end{hints}
-
-\subsubsection{DAG job states}
-\todo{}
-% specialni stav DAGu, histogram potomku
-
-\subsection{LB proxy}
-\req\ running \path{glite-lb-proxy}, \path{glite-lb-interlogd} and
-\path{glite-lb-bkserverd}
-
-\how\ Register jobs with \code{edg\_wll\_RegisterJobProxy}, log events
-using \code{edg\_wll\_LogEventProxy} and check the job states against
-both lbproxy (using \code{edg\_wll\_JobStatusProxy}) and bkserver
-(using \code{edg\_wll\_JobStatus}).
-
-\result\ A new job state should be available immediately at the
-lbproxy and probably with a small delay also at the bkserver.
-
-\begin{hints}
-There is already a script \path{test.sh} in
-\path{org.glite.lb.proxy/examples} that can be used together with
-above mentioned scripts \path{glite-lb-*.sh} (they are called from
-\path{test.sh}) to test all this.
-\end{hints}
-
-\subsection{WS interface}
-\req\ \path{glite-lb-bkserverd} running, events from \ref{normal} logged
-
-\how\ retrieve both events and job states with the \LB\ WS interface
-(operations \code{JobStatus}, \code{QueryEvents}).
-
-\result\ the returened data should match those returned by the legacy
-API calls.
-
-\begin{hints}
-Examples \path{org.glite.lb.server/examples/ws\_*.c} convert the WS
-responses back to the legacy \LB\ data structures and print them in
-the same form as e.g. \path{glite-lb-jobstat}.
-\end{hints}
-
-\subsection{Notifications}
-
-% notifikace
-% regjob, reg notifikace na vsechno, poslat udalosti, hlidat notif
-\subsubsection{Single job, any state change}
-\label{notif1}
-\req\ All \LB\ services running
-
-\how
-\begin{enumerate}
-\item Register a job.
-\item Start a~notification client (preferably on another machine),
-register with \code{edg\_wll\_NotifNew} for any state changes of the job,
-and repeatedly invoke \code{edg\_wll\_NotifReceive}.
-\item One by one send events triggering job state change.
-\end{enumerate}
-
-\result\ All the events should trigger notification reported by the running
-notification client.
-
-\begin{hints}
-\path{glite-lb-notify} example can be used with its \path{test} command.
-\end{hints}
-
-\subsubsection{Additional notification criteria}
-\label{notif-complex}
-\req\ All \LB\ services running
-
-\how\ Like~\ref{notif1} but include additional criteria,
-e.g. job is scheduled for a~specific destination.
-
-\result\ Only notifications matching the criteria should be delivered.
-
-% rozsireni dotazu o dalsi job
-\subsubsection{Include another job}
-\label{notif2}
-\req\ All \LB\ services running, notification from \ref{notif1} still active
-
-\how\
-\begin{enumerate}
-\item Register another job.
-\item Augment the notification registration with the new jobid using
-\code{edg\_wll\_NotifChange}.
-\item Start notification client, bind to the registration with
-\code{edg\_wll\_NotifBind}.
-\item Send events for the new job.
-\end{enumerate}
-
-\result\ Notifications should be received by the client.
-
-\begin{hints}
-Commands \path{change} and \path{receive} of \path{glite-lb-notify}
-can be used.
-\end{hints}
-
-% notifikace -- zmena adresy/portu
-% pak poslat udalost, musi dojit
-% uz je v predchozim implicitne
-
-\subsubsection{Delayed delivery}
-% notifikace -- zpozdene doruceni
-% registrovat, odpojit, poslat udalosti, pripojit se
-
-\req\ All \LB\ services running
-
-\how\
-\begin{enumerate}
-\item Register another job.
-\item Register a~notification as in~\ref{notif1} but terminate the client
-immediately.
-\item Log events for the job.
-\item Restart the client, binding to the notification and call
-\code{edg\_wll\_NotifReceive} repeatedly.
-\end{enumerate}
-
-\result\ Delayed notifications should be received by the client almost
-immediately.
-
-\subsection{Server purge}
-
-\textbf{WARNING: This test is destructive, it destroys ALL data in an
-existing \LB\ database.}
-
-The test is fairly complex but it does not make too much sense to split it
-artificially.
-
-\req\ All \LB services running, preferably a~dedicated server for this test.
-
-\how
-\begin{enumerate}
-\item Purge all data on the server with \path{glite-lb-purge}
-\item Log two sets of jobs, separated with delay of at least 60s so
-that the sets can be distinguished from each other.
-\item \label{purgel}
-Using \code{edg\_wll\_JobLog} retrieve events of all the jobs
-\item \label{purge1}
-Purge the first set of jobs (by specifying appropriate timestamp),
-letting the server dump the purged events.
-\item \label{purge2} Purge the other set of jobs, also dumping the events.
-\item \label{purge3} Run purge once more.
-\end{enumerate}
-
-\result\ The data dumped in steps \ref{purge1}, \ref{purge2} should be the
-same as retrieved in~\ref{purgel}. The final purge invocation should
-do nothing (i.e. nothing was left in the database).
-
-% test_purge
-\begin{hints}
-The example \path{glite-lb-test\_purge} does exactly this sequence of steps,
-including the checks.
-\end{hints}
-
-
-\end{document}
+++ /dev/null
-#!/bin/sh
-
-set -e
-
-#OFFLINE=true
-TOPDIR=${PWD}
-
-export LB4VDTDIR=${TOPDIR}/org.glite.lb/lb4vdt
-export STAGEDIR=${TOPDIR}/stage
-mkdir -p ${STAGEDIR}
-
-if [ ! -f ${LB4VDTDIR}/Makefile.inc ]; then
- echo "Error: There is no ${LB4VDTDIR}/Makefile.inc. Exiting."
- exit 1
-fi
-
-if [ -z "${CVSROOT}" ]; then
- export CVSROOT=:pserver:anonymous@jra1mw.cvs.cern.ch:/cvs/jra1mw
-# export CVSROOT=:ext:jpospi@jra1mw.cvs.cern.ch:/cvs/jra1mw
- echo "Using CVSROOT=${CVSROOT}"
-fi
-
-dep_modules="org.glite.wms-utils.jobid
-org.gridsite.core"
-
-modules="org.glite.security.gsoap-plugin
-org.glite.lb.client-interface
-org.glite.lb.common
-org.glite.lb.client
-org.glite.lb.logger
-org.glite.lb.ws-interface
-org.glite.lb.server-bones
-org.glite.lb.server
-org.glite.lb.proxy"
-#org.glite.lb.utils
-
-for i in $dep_modules;
-do
- echo "*********************************************************"
- echo "* Module $i"
- echo "*********************************************************"
- cd ${TOPDIR}
- if [ -n "${OFFLINE}" ]; then
- echo "Working offline"
- else
- echo "Getting sources from CVS"
- cvs co -A $i;
- fi
- if [ -d $i -a -f ${LB4VDTDIR}/patches/$i.patch -a ! -f .$i.patched ]; then
- echo "Patching $i"
- patch -p0 < ${LB4VDTDIR}/patches/$i.patch
- touch .$i.patched
- fi
- if [ -d $i ]; then
- touch .$i.timestamp
- if [ -f ${LB4VDTDIR}/scripts/$i.build ]; then
- echo "Building"
- sh -x ${LB4VDTDIR}/scripts/$i.build
- fi
- cd ${TOPDIR}
- find ${STAGEDIR} -newer .$i.timestamp > .$i.filelist
- else
- echo "WARNING: directory $i not found"
- fi
-done
-
-for i in $modules;
-do
- echo "*********************************************************"
- echo "* Module $i"
- echo "*********************************************************"
- cd ${TOPDIR}
- if [ -n "${OFFLINE}" ]; then
- echo "Working offline"
- else
- echo "Getting sources from CVS"
- cvs co -A $i;
- fi
- if [ -d $i -a -f ${LB4VDTDIR}/patches/$i.patch -a ! -f .$i.patched ]; then
- echo "Patching $i"
- patch -p0 < ${LB4VDTDIR}/patches/$i.patch
- touch .$i.patched
- fi
- if [ -d $i ]; then
- touch .$i.timestamp
- echo "Entering directory ${TOPDIR}/$i"
- cd ${TOPDIR}/$i
- echo "Copying supporting files"
- cp -rv ${TOPDIR}/org.glite.lb/project/{at3,*.T,*.pm} ./project/
- mkdir -p build
- echo "Entering directory ${TOPDIR}/$i/build"
- cd build
- ln -fsv ../Makefile
-# ln -fsv ../../Makefile.inc Makefile.inc
- ln -fsv ${LB4VDTDIR}/Makefile.inc
- echo "Building"
- make LB_STANDALONE=yes
- make stage LB_STANDALONE=yes
- cd ${TOPDIR}
- find ${STAGEDIR} -newer .$i.timestamp > .$i.filelist
- else
- echo "WARNING: directory $i not found"
- fi
- echo "Done"
-done
-
-cd ${TOPDIR}
-echo "Creating filelists"
-cat .org.glite.wms-utils.jobid.filelist .org.gridsite.core.filelist .org.glite.security.gsoap-plugin.filelist .org.glite.lb.common.filelist | sort | uniq > LB-common.filelist
-cat .org.glite.lb.client-interface.filelist .org.glite.lb.client.filelist | sort | uniq > LB-client.filelist
-cat .org.glite.lb.logger.filelist | sort | uniq > LB-logger.filelist
-cat .org.glite.lb.logger.filelist .org.glite.lb.server-bones.filelist .org.glite.lb.proxy.filelist | sort | uniq > LB-proxy.filelist
-cat .org.glite.lb.ws-interface.filelist .org.glite.lb.server-bones.filelist .org.glite.lb.server.filelist | sort | uniq > LB-server.filelist
+++ /dev/null
-#
-# common setting
-#
-
-#vdt_location=/home/honik/egee/vdt-1.5.0
-vdt_location=${VDT_LOCATION}
-
-# missing packages could be for example downloaded to repository from
-# http://eticssoft.web.cern.ch/eticssoft/repository/externals
-
-repository=/home/honik/egee/repository/externals/
-platform=slc3_ia32_gcc323
-
-
-#
-# external dependencies that are already part of VDT (vdt-1.5.0):
-#
-
-#classads_prefix=${repository}/classads/0.9.8/${platform}
-classads_prefix=${vdt_location}/classads
-
-#globus_prefix=${repository}/globus/2.4.3-VDT-1.2.5/${platform}
-globus_prefix=${vdt_location}/globus
-
-#expat_prefix=/usr
-expat_prefix=${vdt_location}/expat
-
-#mysql_prefix=${repository}/mysql-devel/4.1.11/${platform}
-mysql_prefix=${vdt_location}/mysql
-mysql_version=4.1.21
-
-voms_prefix=${vdt_location}/glite
-#voms_prefix=/home/honik/egee/glite/stage
-
-
-#
-# external dependencies that are NOT (yet) part of VDT (vdt-1.5.0):
-#
-
-#cares_prefix=${repository}/c-ares/1.3.0/${platform}
-cares_prefix=/software/cares-1.3
-
-# probably not needed (used "only" for unit tests - 'make check'):
-#cppunit_prefix=${repository}/cppunit/1.10.2/${platform}
-cppunit_prefix=/software/cppunit-1.10.2
-
-# probably not needed:
-#gridsite_prefix=${stagedir}
-
-gsoap_default_version=2.7.6b
-gsoap_versions=${gsoap_default_version}
-#gsoap_prefix=${repository}/gsoap/${gsoap_default_version}/${platform}
-gsoap_prefix=/software/gsoap-${gsoap_default_version}
-
-
-#
-# some other defaults:
-#
-
-#PREFIX=${vdt_location}/glite
-PREFIX=/tmp/lb4vdt
-globalprefix=glite
-lbprefix=lb
-
-builddir=build
-distdir=${STAGEDIR}/../dist
-stagedir=${STAGEDIR}
-top_srcdir=..
-
-#thrflavour=gcc64dbgpthr
-#nothrflavour=gcc64dbg
-thrflavour=gcc32dbgpthr
-nothrflavour=gcc32dbg
-
-# needed by org.glite.lb.client:
-glite_location=${stagedir}
-
+++ /dev/null
-#!/bin/sh
-
-set -e
-
-TOPDIR=${PWD}
-source ${LB4VDTDIR}/Makefile.inc
-cd org.gridsite.core/src
-make build-lib OPENSSL_FLAGS=-I${globus_prefix}/include/${nothrflavour} OPENSSL_LIBS=-L${globus_prefix}/lib FLAVOR_EXT=_${nothrflavour}
-make install-lib prefix=${STAGEDIR}
-cd ${TOPDIR}
-
+++ /dev/null
-package MultiStruct;
-
-use StructField;
-
-sub new {
- shift;
- my $self = {};
- $self->{comments} = {}; # typ->comment
- $self->{fields} = {}; # typ->{ name->StructField, ... }
- $self->{order} = {};
-
- bless $self;
-}
-
-sub selectType {
- my $self = shift;
- my $type = shift;
- $self->{type} = $type;
- 1;
-}
-
-sub addType {
- my $self = shift;
- my $type = shift;
- my $comment = shift;
- $self->selectType($type);
- $self->{comments}->{$type} = $comment;
- $self->{fields}->{$type} = {};
- 1;
-}
-
-sub selectField {
- my $self = shift;
- $self->{field} = shift;
- $self->getField;
-}
-
-sub addField {
- my $self = shift;
- my $field = shift;
-
- die "unselected type" unless $self->{type};
- $self->{fields}->{$self->{type}}->{$field->{name}} = $field;
- $self->selectField($field->{name});
- 1;
-}
-
-sub getField {
- my $self = shift;
- my $f = $self->{fields}->{$self->{type}}->{$self->{field}};
- return $f ? $f : $self->{fields}->{_common_}->{$self->{field}};
-}
-
-sub load {
- my $self = shift;
- my $fh = shift;
- local $_;
-
- while ($_ = <$fh>) {
-
- chomp;
- s/#.*$//;
- next if /^\s*$/;
-
- if (/^\@type\s+(\S+)\s*(.*$)$/) {
- $self->addType($1,$2);
- $self->{order}->{$1} = $.;
- next;
- }
-
- s/^\s*//;
- my ($ftype,$fname,$comment) = split /\s+/,$_,3;
- if ($ftype eq '_code_') {
- my $f = $self->getField();
- addCode $f $fname,$comment;
- }
- elsif ($ftype eq '_alias_') {
- my $f = $self->getField();
- addAlias $f $fname,$comment;
- }
- elsif ($ftype eq '_special_') {
- my $f = $self->getField();
- addSpecial $f $fname;
- }
- elsif ($ftype eq '_null_') {
- my $f = $self->getField();
- setNull $f $fname;
- }
- elsif ($ftype eq '_optional_') {
- my $f = $self->getField();
- $f->{optional} = 1;
- }
- elsif ($ftype eq '_index_') {
- my $f = $self->getField();
- $f->{index} = 1;
- }
- else {
- my $f = new StructField $fname,$ftype,$comment,$.;
- $self->addField($f);
- }
- }
-}
-
-sub getTypes {
- my $self = shift;
- my @out;
- local $_;
-
- for (keys %{$self->{fields}}) {
- push @out,$_ unless $_ eq '_common_';
- }
- @out;
-}
-
-sub getTypesOrdered {
- my $self = shift;
- my @names = getTypes $self;
-
- sort {
- my $oa = $self->{order}->{$a};
- my $ob = $self->{order}->{$b};
- $oa <=> $ob;
- } @names;
-}
-
-sub getTypeComment {
- my $self = shift;
- my $type = shift || $self->{type};
- $self->{comments}->{$type};
-}
-
-sub getFieldComment {
- my $self = shift;
- my $fname = shift;
- $self->{fields}->{$self->{type}}->{$fname}->{comment};
-}
-
-sub getFields {
- my $self = shift;
- keys %{$self->{fields}->{$self->{type}}};
-}
-
-sub getFieldsOrdered {
- my $self = shift;
- my @names = $self->getFields;
- sort {
- my $oa = $self->selectField($a)->{order};
- my $ob = $self->selectField($b)->{order};
- $oa <=> $ob;
- } @names;
-}
-
-sub getFieldOccurence {
- my $self = shift;
- my $fname = shift;
- my @out;
- local $_;
-
- for (keys %{$self->{fields}}) {
- push @out,$_ if $self->{fields}->{$_}->{$fname};
- }
- @out;
-}
-
-sub getAllFields {
- my $self = shift;
- my %out;
- local $_;
-
- for my $t (values %{$self->{fields}}) {
- $out{$_->{name}} = 1 for (values %$t);
- }
- keys %out;
-}
-
-sub getAllFieldsOrdered {
- my $self = shift;
- my @names = getAllFields $self;
-
- sort {
- my @occ = $self->getFieldOccurence($a);
- $self->selectType($occ[0]);
- my $oa = $self->selectField($a)->{order};
- @occ = $self->getFieldOccurence($b);
- $self->selectType($occ[0]);
- my $ob = $self->selectField($b)->{order};
- $oa <=> $ob;
- } @names;
-}
-
-1;
+++ /dev/null
-package StructField;
-
-$lang = 'C';
-1;
-
-sub new {
- shift;
- my $self = {};
- $self->{name} = shift;
- $self->{type} = shift;
- $self->{comment} = shift;
- $self->{order} = shift;
- $self->{null} = $main::DefaultNullValue{$self->{type}};
- bless $self;
-}
-
-sub addCode {
- my $self = shift;
- my $code = shift;
- my $comment = shift;
- push @{$self->{codes}},{name=>$code,comment=>$comment};
- 1;
-}
-
-sub addSpecial {
- my $self = shift;
- my $special = shift;
- $self->{special} = $special;
- 1;
-}
-
-sub addAlias {
- my $self = shift;
- my $name = shift;
- my $lang = shift;
- $self->{aliases}->{$lang} = $name;
- 1;
-}
-
-sub hasAlias {
- my $self = shift;
- my $lang = shift;
- return $self->{aliases}->{$lang} ? 1 : 0;
-}
-
-sub getName {
- my $self = shift;
- my $lang = shift || $lang;
- $self->{aliases}->{$lang} || $self->{name};
-# return $self->{aliases}->{$lang} ? $self->{aliases}->{$lang} : $self->{name};
-}
-
-sub getComment {
- my $self = shift;
- $self->{comment};
-}
-
-sub getDefaultNullValue {
- my $self = shift;
- $self->{null};
-}
-
-sub toString {
- my $self = shift;
- my $src = shift;
- my $dst = shift;
-
- eval $main::toString{$lang}->{$self->{type}};
-}
-
-sub fromString {
- my $self = shift;
- my $src = shift;
- my $dst = shift;
-
- eval $main::fromString{$lang}->{$self->{type}};
-}
-
-sub isNULL {
- my $self = shift;
- my $a = shift;
- my $b = $self->{null};
-
- eval $main::compare{$lang}->{$self->{type}};
-}
-
-sub isnotNULL {
- my $self = shift;
- my $src = shift;
-
- '!('.$self->isNULL($src).')';
-}
-
-sub compare {
- my $self = shift;
- my $a = shift;
- my $b = shift;
- eval $main::compare{$lang}->{$self->{type}};
-}
-
-sub toFormatString {
- my $self = shift;
-
- eval $main::toFormatString{$lang}->{$self->{type}};
-}
-
-sub setNull {
- my $self = shift;
- $self->{null} = shift;
-}
-
-sub getType {
- my $self = shift;
-
- eval $main::types{$lang}->{$self->{type}};
-}
+++ /dev/null
-#!/usr/bin/perl -w
-
-use File::Basename;
-my $dir;
-BEGIN{
- $dir = dirname $0;
-}
-
-my $lines = $ENV{AT3_LINES};
-
-use lib $dir;
-use MultiStruct;
-require 'types.T';
-
-my $eventsn;
-for (@INC) {
- if (-f "$_/events.T") {
- $eventsn="$_/events.T";
- last;
- }
-}
-
-my $statusn;
-for (@INC) {
- if (-f "$_/status.T") {
- $statusn = "$_/status.T";
- last;
- }
-}
-
-my $indent = '';
-
-my $event = new MultiStruct;
-my $status = new MultiStruct;
-
-sub gen {
- local $_ = shift;
-
- s/^\n!//;
- s/\n!/\n/g;
- print $_;
-}
-
-
-open EVENTS,$eventsn or die "$eventsn: $!\n";
-$event->load(\*EVENTS);
-close EVENTS;
-
-open STATUS,$statusn or die "$statusn: $!\n";
-$status->load(\*STATUS);
-close STATUS;
-
-my $code;
-my $startcode;
-while (<>) {
- chomp;
- if (/^\@\@\@LANG: (\S+)$/) {
- $StructField::lang = $1;
- next;
- }
-
- if ($code) {
- if (/^\@\@\@}$/) {
- $code .= "1;\n";
- print "#line $startcode \"$ARGV\"\n/* begin */\n" if $lines;
- eval $code or warn "eval: $@ at $ARGV:$.\n";
- my $nxtline = $.+1;
- print "/* end */\n#line $nxtline \"$ARGV\"\n" if $lines;
- undef $code;
- }
- else { $code .= $_."\n"; }
- }
- else {
- if (/^\@\@\@{$/) {
- $startcode = $.;
- $code = "\n";
- }
- elsif (/^\@\@\@AUTO$/) {
- print qq{
- !! Automatically generated file
- !! Do not edit, your changes will be discarded upon build
- !! Change the corresponding template file $ARGV
-
-};
- print "#line $. \"$ARGV\"\n" if $lines;
- }
- else {
- print "$_\n";
- }
- }
-}
-
-# print $event_common{prog}->copy('bla','hu');
+++ /dev/null
-#Fri Aug 18 12:35:01 CEST 2006
-module.build=0242
+++ /dev/null
-ext.gsoap.version=2.7.6b
+++ /dev/null
-#!/usr/bin/perl
-
-# check_version script to be used to compare client-interface and other modules versions
-# Usage:
-# - set environment variables VERSION and VERSION_AHEAD of the module
-# - run against ${stagedir}/include/glite/lb/interface_version.h
-# Example:
-# ./check_version.pl interface_version.h
-
-my $version = $ENV{VERSION};
-if ($version =~ /(\d+)\.\d+\.\d+/) {
- $version = $1;
-} else {
- print "error: wrong version format ($version)\n";
- exit 1;
-}
-
-my $ahead = $ENV{VERSION_AHEAD};
-if ($ahead =~ /(\d+)/) {
- $ahead = $1;
-} else {
- print "error: wrong version_ahead format ($ahead)\n";
- exit 1;
-}
-
-my $iface;
-
-while (<>) {
- /#define GLITE_LB_CLIENT_INTERFACE "(\d+)\.\d+\.\d+"/;
- $iface = $1;
-}
-
-if ($iface + $ahead != $version) {
- print "error: Major version of the interface ($iface + $ahead ahead) DOES NOT match implementation ($version)\n" ;
- exit 1;
-}
+++ /dev/null
-
-###################################################################
-# System dependencies
-###################################################################
-
-org.glite.version = HEAD
-org.glite.lb.version = glite-lb_R_1_5_2_3
-
-# Component dependencies tag = do not remove this line =
-org.glite.lb.client-interface.version = glite-lb-client-interface_R_2_3_3_1
-org.glite.lb.ws-interface.version = glite-lb-ws-interface_R_2_3_0_3
-org.glite.lb.common.version = glite-lb-common_R_5_1_2_1
-org.glite.lb.client.version = glite-lb-client_R_2_3_5_1
-org.glite.lb.server.version = glite-lb-server_R_1_6_2_1
-org.glite.lb.proxy.version = glite-lb-proxy_R_1_4_1_4
-org.glite.lb.server-bones.version = glite-lb-server-bones_R_2_2_5_1
-org.glite.lb.logger.version = glite-lb-logger_R_1_4_3_1
-org.glite.lb.utils.version = glite-lb-utils_R_1_1_1_3
-
-ext.gsoap.version = 2.7.6b
+++ /dev/null
-@type _common_
- timeval timestamp Time the event was generated.
- _alias_ date ULM
- timeval arrived Time the event was stored into the bookkeeping server database.
- _alias_ arr_date ULM
- _optional_
- string host Hostname of the machine where the event was generated.
- _alias_ host ULM
- int level Logging level (in the range from DEBUG to EMERGENCY).
- _alias_ lvl ULM
- _code_ EMERGENCY emergency
- _code_ ALERT alert
- _code_ ERROR error
- _code_ WARNING warning
- _code_ AUTH authentication
- _code_ SECURITY security
- _code_ USAGE usage
- _code_ SYSTEM system
- _code_ IMPORTANT important
- _code_ DEBUG debug
- int priority Message priority (yet 0 for asynchronous and 1 for synchronous transfers).
- _null_ -1
- jobid jobId Grid job id of the job the event belongs to.
- string seqcode Sequence code assigned to the event.
- string user Identity (certificate subject) of the event sender.
- logsrc source Source (software component) which generated this event.
-# string prog name of program ("EDG WMS" of name of the application).
- string src_instance Instance of source component (e.g. service communication endpoint).
- _optional_
-
-@type Transfer Start, success, or failure of job transfer to another component.
- logsrc destination Destination where the job is being transfered to.
- string dest_host Hostname of server that takes over control of the job.
- string dest_instance Service (instance) that takes over control of the job.
- _optional_
- string job Job description in receiver's language.
- int result Result code of the transfer attempt (START, OK, REFUSED or FAIL).
- _code_ START The sending component has started or is about to start the transfer.
- _code_ OK The job was sent successfully.
- _code_ REFUSED The job was refused by the other component.
- _code_ FAIL The transfer failed for other reason than explicit refusal (eg. network timeout).
- string reason Detailed description of the transfer, especially reason of failure.
- _optional_
- string dest_jobid Job id as assigned by the receiving software component.
- _optional_
-
-@type Accepted Accepting job (successful counterpart to Transfer).
- logsrc from The software component the job was received from.
- string from_host Hostname of the component the job was received from.
- string from_instance Instance of the component the job was received from.
- _optional_
- string local_jobid New job id as assigned by the receiving component.
-
-@type Refused Refusing job (unsuccessful counterpart to Transfer).
- logsrc from The software component that tried to send the job.
- string from_host Hostname of the component that tried to send the job.
- string from_instance Instance of the component that tried to send the job.
- _optional_
- string reason Description of the reason why the job was refused.
-
-@type EnQueued The job has been enqueued in an inter-component queue.
- string queue Queue into which the job has been stored for retrieval by another component.
- string job Job description in the receiver's language.
- int result Result code of the attempt to put job into the queue (START, OK, REFUSED or FAIL).
- _code_ START The sending component has started or is about to start enqueuing the job.
- _code_ OK The job was enqueued successfully.
- _code_ REFUSED The job was refused by the other component.
- _code_ FAIL The transfer failed for other reason than explicit refusal.
- string reason Detailed description of the attempt to enqueue the job, especially the reason of failure.
-
-@type DeQueued The job has been dequeued from an inter-component queue.
- string queue Name of the queue the job was obtained from.
- string local_jobid New job id as assigned by the retreiving component.
-
-@type HelperCall Helper component is called.
- string helper_name Name of the called helper component.
- string helper_params Parameters of the call to the helper component.
- int src_role The role the event sender is playing in the helper call (CALLING or CALLEE).
- _code_ CALLING The logging component is caller.
- _code_ CALLED The logging component is callee.
-
-@type HelperReturn Helper component is returning the control.
- string helper_name Name of the called helper component.
- string retval Data returned by the call to the helper component.
- int src_role The role the event sender is playing in the helper call (CALLING or CALLEE).
- _code_ CALLING The logging component is caller.
- _code_ CALLED The logging component is callee.
-
-@type Running Job wrapper started.
- string node Worker node on which the job executable is being run.
-
-@type Resubmission Result of resubmission decision.
- int result Result code of the resubmission decision (WILLRESUB or WONTRESUB or SHALLOW).
- _code_ WILLRESUB The job will be resubmitted (deep resubmission).
- _code_ WONTRESUB The job will not be resubmitted.
- _code_ SHALLOW Shallow resubmission (user payload has not started yet)
- string reason Reason why the job will or will not be resubmitted.
- string tag Value of the attribute on which the decision to resubmit the job was based.
-
-@type Done Execution terminated (normally or abnormally).
- int status_code Reason code for the termination of the job (OK, FAILED or CANCELLED).
- _code_ OK The job terminated by itself.
- _code_ FAILED The job disappeared from LRMS.
- _code_ CANCELLED The job was cancelled by user request.
- string reason Detailed description why the job was terminated.
- int exit_code Exit code of the job's process.
- _null_ -1
-
-@type Cancel Cancel operation has been attempted on the job.
- int status_code Classification of the attempt to cancel the job (REQ, REFUSE, DONE or ABORT).
- _code_ REQ The request was acknowledged.
- _code_ REFUSE The request was declined by this component.
- _code_ DONE The request was completed by whole WMS.
- _code_ ABORT The request was refused by whole WMS.
- string reason Detailed description of the attempt to cancel the job, especially the reason of failure.
-
-@type Abort Job aborted by system.
- string reason Reason why the job was aborted by the system.
-
-@type Clear Job cleared, output sandbox removed
- int reason Description of the reason why the job was cleared and the output sandbox removed (USER, TIMEOUT or NOOUTPUT).
- _code_ USER User retrieved output sandbox.
- _code_ TIMEOUT Timed out, resource forced purge of the sandbox.
- _code_ NOOUTPUT No output was generated.
-
-@type Purge Job is purged from bookkepping server.
-
-@type Match Matching CE found.
- string dest_id Identification of the queue on the CE that the job could be send to.
-
-@type Pending No matching CE found yet.
- string reason Description why the matching CE for the job was not found (yet).
-
-@type RegJob New job registration.
- string jdl Job description of the job being registered.
- _optional_
- string ns NetworkServer handling the newly registered job.
- jobid parent Grid job id of the parent job registering this new one.
- _optional_
-
- int jobtype Type of the job being registered (SIMPLE, DAG, PARTITIONABLE or PARTITIONED).
- _code_ SIMPLE The job is simple job.
- _code_ DAG The job is dag (containing static set of subjobs).
- _code_ PARTITIONABLE The job is partitionable (may become partitioned).
- _code_ PARTITIONED The job is partitioned (dynamically created dag).
- _code_ COLLECTION The job is collection (containing static set of subjobs).
- _code_ PBS PBS job
- _code_ CONDOR Condor job
-
- int nsubjobs Number of subjobs this job plans to spawn.
- _optional_
- string seed Seed for subjob id generation.
- _optional_
-
-@type Chkpt Application-specific checkpoint record.
- string tag Application specific checkpoint tag.
- string classad Application specific checkpoint value.
-
-@type Listener Listening network port for interactive control.
- string svc_name Name of the port instance for interactive job control.
- string svc_host Hostname of the interactive job controller.
- port svc_port Port number of the interactive job controller.
-
-@type CurDescr Current state of job processing (optional event).
- string descr Description of the current job transformation (output of the helper).
-
-@type UserTag User tag -- arbitrary name=value pair.
- string name Arbitrary user tag name.
- string value Arbitrary user tag value.
-
-@type ChangeACL Management of ACL stored on bookkepping server.
- string user_id DN or VOMS parameter (in format VO:group).
- int user_id_type Type of information given in user_id (DN or VOMS).
- _null_ -1
- int permission ACL permission to change (currently only READ).
- _null_ -1
- int permission_type Type of permission requested ('allow', 'deny').
- _null_ -1
- int operation Operation requested to perform with ACL (add, remove).
- _null_ -1
-
-@type Notification Management of notification service.
- notifid notifId Notification id.
- string owner Identification of the job owner (certificate subject).
- string dest_host Hostname the notification is sent to.
- port dest_port Port number the notification is sent to.
- string jobstat Status of the job (the notification content).
-
-
-@type ResourceUsage Resource (CPU, memory etc.) consumption.
- string resource Resource's name.
- double quantity Resources's quantity (how much).
- string unit Units (sec, kB, etc.).
-
-@type ReallyRunning User payload started.
- _optional_
- string wn_seq Sequence code on the worker node.
-
-@type Suspend Job execution (queuing) was suspended.
- _optional_
- string reason Reason for the suspend.
-
-@type Resume Job execution (queuing) was resumed.
- _optional_
- string reason Reason for the resume.
-
-@type CollectionState State of the collection.
- string state New collection state.
- _optional_
- int done_code In case of (state == Done) contains done code
- _null_ -1
- string histogram User readable histogram; useful for debugging.
- jobid child JobId of subjob, which triggered the state change.
- string child_event Event which triggered the state change.
-
-
-@type PBSQueued Job enqued
- string queue Queue name
- string owner Job owner
- string name Job name
-
-@type PBSMatch Scheduler created exec_host
- string dest_host Aka exec_host
-
-@type PBSPending Scheduler is not able to find exec_host, or some error occured
- string reason Reasons of job pendation or errors
-
-@type PBSRun Job attempted to be run by the logging component
- string scheduler Scheduler ID
- _optional_
- string dest_host Where to run the job
- _optional_
- int pid Actual process ID
- _optional_
-
-@type PBSRerun Job rerun requested
-
-@type PBSDone Job terminated
- int exit_status Exit status
- _optional_ Bypass need of 'null value'
-
-@type PBSDequeued Job dequeued
-
-@type PBSResourceUsage Resources requested/consumed
- int usage Type of record
- _code_ REQUESTED Requested value
- _code_ USED Consumed quantity
- string name Name of resource
- double quantity The quantity
- _optional_ Bypass need of 'null value'
- string unit Units (sec, kB, etc.)
-
-@type PBSError Any error occured
- string error_desc Error reason
-
-@type CondorMatch Job MATCHed
- string owner Owner
- string dest_host Matched host
- string preempting Preempting
- _optional_
-
-@type CondorReject Job REJECTed
- string owner Owner
- int status_code Reason code for the rejection of the job
- _code_ NOMATCH No match found
- _code_ OTHER Other reason
-
-@type CondorShadowStarted Condor Shadow Started
- string shadow_host Shadow host
- port shadow_port Shadow port
- int shadow_pid PID of shadow process
- string shadow_status Shadow status
- _optional_
-
-@type CondorShadowExited Condor Shadow Exited
- int shadow_pid PID of shadow process
- int shadow_exit_status Exit status of shadow process
- _null_ -1
-
-@type CondorStarterStarted Condor Starter Started
- int starter_pid PID of starter process
- _optional_
- string universe Condor Universe
- _optional_
-
-@type CondorStarterExited Condor Starter Exited
- int starter_pid PID of starter process
- _optional_
- int starter_exit_status Exit status of starter process
- _null_ -1
- _optional_
- int job_pid PID of running job
- _optional_
- int job_exit_status Job exit status
- _null_ -1
- _optional_
-
-@type CondorResourceUsage Resources requested/consumed
- int usage Type of record
- _code_ REQUESTED Requested value
- _code_ USED Consumed quantity
- string name Name of resource
- double quantity The quantity
- _optional_ Bypass need of 'null value'
- string unit Units (sec, kB, etc.)
-
-@type CondorError Any Error occured
- string error_desc Error reason
-
+++ /dev/null
-<?xml version="1.0"?>
-<!--
- Copyright (c) 2004 on behalf of the EU EGEE Project:
- The European Organization for Nuclear Research (CERN),
- Istituto Nazionale di Fisica Nucleare (INFN), Italy
- Datamat Spa, Italy
- Centre National de la Recherche Scientifique (CNRS), France
- CS Systeme d'Information (CSSI), France
- Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
- Universiteit van Amsterdam (UvA), Netherlands
- University of Helsinki (UH.HIP), Finland
- University of Bergen (UiB), Norway
- Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
-
- gLite Middleware Logging and Bookkeping Configuration Specification File
-
- Authors: Alberto Di Meglio <alberto.di.meglio@cern.ch>
- Joachim Flammer <Joachim.Flammer@cern.ch>
- Ales Krenek <ljocha@ics.muni.cz>
- Version info: $Id$
- Release: $Name$
-
- Revision history:
- $Log$
- Revision 1.16 2006/03/15 17:33:24 akrenek
- merge of 1.5 branch
-
- Revision 1.15 2005/11/27 21:51:18 eronchie
- Applied fix for bug 13928
-
- Revision 1.14 2005/10/15 20:14:55 jpospi
- remove duplicate lb.utils section
-
- Revision 1.13.2.1.2.1 2005/11/28 10:39:08 akrenek
- merge bug #13928 fix on the pre_cares branch
-
- Revision 1.13.2.1 2005/10/17 16:27:48 akrenek
- merged in the duplicate utils targed patch
-
- Revision 1.15 2005/11/27 21:51:18 eronchie
- Applied fix for bug 13928
-
- Revision 1.14 2005/10/15 20:14:55 jpospi
- remove duplicate lb.utils section
-
- Revision 1.13 2005/10/15 13:36:26 akrenek
- added lb.utils
-
- Revision 1.12 2005/03/16 10:02:52 zsalvet
- proxy component added
-
- Revision 1.11 2004/12/01 18:01:55 zsalvet
- LB here, not R-GMA
-
- Revision 1.10 2004/11/29 16:01:21 zsalvet
- Evaluate component.{head,tag} conditions before use of get.* targets.
-
- Revision 1.9 2004/11/29 15:16:26 zsalvet
- Add ws-interface to checkout/build machinery.
-
- Revision 1.8 2004/10/18 22:55:14 dimeglio
- Added oscheck to various targets
-
- Revision 1.7 2004/10/15 12:30:01 akrenek
- build with lb.sever-bones
-
- Revision 1.6 2004/08/27 10:03:41 zurek
- typo problem
-
- Revision 1.5 2004/08/27 09:13:11 zurek
- changing thee order for build
-
- Revision 1.4 2004/07/29 10:47:46 dimeglio
- Added server and logger
-
- Revision 1.3 2004/07/16 16:25:43 flammer
- Added tags for automated adding of components.
-
- Revision 1.2 2004/06/23 00:22:11 dimeglio
- Added client and client-interface components
-
- Revision 1.1 2004/06/18 23:05:53 dimeglio
- Added/upgraded default build scripts
-
--->
-
-
-<project name="GLite Middleware Logging and Bookkeping CSF" default="all">
-
- <!-- ===============================================
- Determine workspace directory
- =============================================== -->
-
- <!-- Relative workspace root directory -->
- <property name="workspace.dir" value="../.." />
-
- <!-- ===============================================
- Load properties
- =============================================== -->
-
- <!-- load baseline and user properties -->
- <import file="${workspace.dir}/org.glite/project/baseline.properties.xml" />
-
- <!-- define build properties file location since we are already in project dir -->
- <property name="subsystem.build.properties.file" value="./build.properties" />
-
- <!-- Load subsystem-specific property file -->
- <property file="./properties.xml"/>
-
- <!-- load global properties -->
- <import file="${global.properties.file}" />
-
- <!-- ===============================================
- Load dependencies
- =============================================== -->
-
- <!-- Load user dependencies file -->
- <property file="${user.dependencies.file}" />
-
- <!-- Load subsystem dependencies file -->
- <property file="./dependencies.properties" />
-
- <!-- Load global dependencies file -->
- <property file="${global.dependencies.file}" />
-
- <!-- ===============================================
- Load targets
- =============================================== -->
- <import file="${global.targets-envchecks.file}" />
- <import file="${global.targets-external-dependencies.file}" />
-
- <!-- ===============================================
- Evaluate CVS tags
- =============================================== -->
-
- <target name="evaluate.cvs.tags" description="Figure out if we need tagged CVS checkout">
- <condition property="glite.head">
- <and>
- <equals arg1="${org.glite.version}" arg2="HEAD" />
- <or>
- <istrue value="${update}" />
- <not>
- <available file="${global.dependencies.file}" type="file" />
- </not>
- </or>
- </and>
- </condition>
- <condition property="glite.tag">
- <and>
- <not>
- <equals arg1="${org.glite.version}" arg2="HEAD" />
- </not>
- <or>
- <istrue value="${update}" />
- <not>
- <available file="${global.dependencies.file}" type="file" />
- </not>
- </or>
- </and>
- </condition>
- <condition property="glite-lb.head">
- <and>
- <equals arg1="${org.glite.lb.version}" arg2="HEAD" />
- <istrue value="${update}" />
- </and>
- </condition>
- <condition property="glite-lb.tag">
- <and>
- <not>
- <equals arg1="${org.glite.lb.version}" arg2="HEAD" />
- </not>
- <istrue value="${update}" />
- </and>
- </condition>
-
- <!-- condition property tag = do not remove = -->
-
- <condition property="utils.head">
- <equals arg1="${org.glite.lb.utils.version}" arg2="HEAD" />
- </condition>
-
- <condition property="common.head">
- <equals arg1="${org.glite.lb.common.version}" arg2="HEAD" />
- </condition>
-
- <condition property="server-bones.head">
- <equals arg1="${org.glite.lb.server-bones.version}" arg2="HEAD" />
- </condition>
-
- <condition property="client-interface.head">
- <equals arg1="${org.glite.lb.client-interface.version}" arg2="HEAD" />
- </condition>
-
- <condition property="ws-interface.head">
- <equals arg1="${org.glite.lb.ws-interface.version}" arg2="HEAD" />
- </condition>
-
- <condition property="client.head">
- <equals arg1="${org.glite.lb.client.version}" arg2="HEAD" />
- </condition>
-
- <condition property="server.head">
- <equals arg1="${org.glite.lb.server.version}" arg2="HEAD" />
- </condition>
-
- <condition property="proxy.head">
- <equals arg1="${org.glite.lb.proxy.version}" arg2="HEAD" />
- </condition>
-
- <condition property="logger.head">
- <equals arg1="${org.glite.lb.logger.version}" arg2="HEAD" />
- </condition>
-
- </target>
-
- <presetdef name="cvs-co">
- <cvs command="checkout" dest="${workspace.dir}" />
- </presetdef>
-
- <!-- =====================================================
- Self-update if required
- ===================================================== -->
-
- <!-- Update main GLite module -->
- <target name="org.glite" depends="evaluate.cvs.tags, get.glite.head, get.glite.tag"/>
- <target name="get.glite.head" if="glite.head">
- <cvs-co package="org.glite" />
- </target>
- <target name="get.glite.tag" if="glite.tag">
- <cvs-co package="org.glite"
- tag="${org.glite.version}" />
- </target>
-
- <!-- Update the current module -->
- <target name="org.glite.lb" depends="evaluate.cvs.tags, get.glite-lb.head, get.glite-lb.tag"/>
- <target name="get.glite-lb.head" if="glite-lb.head">
- <cvs-co package="org.glite.lb" />
- <fail>The org.glite and org.glite.lb modules have been updated, please rerun the configuration file</fail>
- </target>
- <target name="get.glite-lb.tag" if="glite-lb.tag">
- <cvs-co package="org.glite.lb"
- tag="${org.glite.lb.version}" />
- <fail>The org.glite and org.glite.lb modules have been updated, please rerun the configuration file</fail>
- </target>
-
- <!-- *****************************************************-->
- <!-- Development tools -->
- <!-- *****************************************************-->
-
- <!-- All development tools -->
- <target name="devtools" depends="oscheck,
- evaluate.cvs.tags,
- junitcheck,
- junit,
- chkstyle,
- jalopy,
- ant-contrib,
- cpptasks,
- egee-ant-ext"
- description="Get development tools into repository."/>
-
- <!-- =====================================================
- External libraries
- ===================================================== -->
-
- <!-- All external libraries -->
- <target name="external" depends="oscheck,
- evaluate.cvs.tags,
- classads,
- globus"
- description="Install external packages"/>
-
- <!-- =====================================================
- GLite Middleware LB modules
- ===================================================== -->
-
- <!-- component targets tag = do not remove = -->
-
- <!-- common -->
- <target name="common" depends="evaluate.cvs.tags, get.common.head, get.common.tag"/>
- <target name="get.common.head" if="common.head">
- <cvs-co package="org.glite.lb.common" />
- </target>
- <target name="get.common.tag" unless="common.head">
- <cvs-co package="org.glite.lb.common"
- tag="${org.glite.lb.common.version}" />
- </target>
-
- <!-- server-bones -->
- <target name="server-bones" depends="evaluate.cvs.tags, get.server-bones.head, get.server-bones.tag"/>
- <target name="get.server-bones.head" if="server-bones.head">
- <cvs-co package="org.glite.lb.server-bones" />
- </target>
- <target name="get.server-bones.tag" unless="server-bones.head">
- <cvs-co package="org.glite.lb.server-bones"
- tag="${org.glite.lb.server-bones.version}" />
- </target>
-
- <!-- client-interface -->
- <target name="client-interface" depends="evaluate.cvs.tags, get.client-interface.head, get.client-interface.tag"/>
- <target name="get.client-interface.head" if="client-interface.head">
- <cvs-co package="org.glite.lb.client-interface" />
- </target>
- <target name="get.client-interface.tag" unless="client-interface.head">
- <cvs-co package="org.glite.lb.client-interface"
- tag="${org.glite.lb.client-interface.version}" />
- </target>
-
- <!-- WS interface -->
- <target name="ws-interface" depends="evaluate.cvs.tags, get.ws-interface.head, get.ws-interface.tag"/>
- <target name="get.ws-interface.head" if="ws-interface.head">
- <cvs-co package="org.glite.lb.ws-interface" />
- </target>
- <target name="get.ws-interface.tag" unless="ws-interface.head">
- <cvs-co package="org.glite.lb.ws-interface"
- tag="${org.glite.lb.ws-interface.version}" />
- </target>
-
- <!-- client -->
- <target name="client" depends="evaluate.cvs.tags, get.client.head, get.client.tag"/>
- <target name="get.client.head" if="client.head">
- <cvs-co package="org.glite.lb.client" />
- </target>
- <target name="get.client.tag" unless="client.head">
- <cvs-co package="org.glite.lb.client"
- tag="${org.glite.lb.client.version}" />
- </target>
-
- <!-- server -->
- <target name="server" depends="evaluate.cvs.tags, get.server.head, get.server.tag"/>
- <target name="get.server.head" if="server.head">
- <cvs-co package="org.glite.lb.server" />
- </target>
- <target name="get.server.tag" unless="server.head">
- <cvs-co package="org.glite.lb.server"
- tag="${org.glite.lb.server.version}" />
- </target>
-
- <!-- proxy -->
- <target name="proxy" depends="evaluate.cvs.tags, get.proxy.head, get.proxy.tag"/>
- <target name="get.proxy.head" if="proxy.head">
- <cvs-co package="org.glite.lb.proxy" />
- </target>
- <target name="get.proxy.tag" unless="proxy.head">
- <cvs-co package="org.glite.lb.proxy"
- tag="${org.glite.lb.proxy.version}" />
- </target>
-
- <!-- logger -->
- <target name="logger" depends="evaluate.cvs.tags, get.logger.head, get.logger.tag"/>
- <target name="get.logger.head" if="logger.head">
- <cvs-co package="org.glite.lb.logger" />
- </target>
- <target name="get.logger.tag" unless="logger.head">
- <cvs-co package="org.glite.lb.logger"
- tag="${org.glite.lb.logger.version}" />
- </target>
-
- <!-- utils -->
- <target name="utils" depends="get.utils.head, get.utils.tag"/>
- <target name="get.utils.head" if="utils.head">
- <cvs-co package="org.glite.lb.utils" />
- </target>
- <target name="get.utils.tag" unless="utils.head">
- <cvs-co package="org.glite.lb.utils"
- tag="${org.glite.lb.utils.version}" />
- </target>
-
- <!-- All project modules -->
- <target name="project" depends="utils,
- client-interface,
- ws-interface,
- common,
- server-bones,
- client,
- server,
- proxy,
- logger"/>
-
-
- <!-- ====================================================
- Checkout all
- ==================================================== -->
-
- <!-- All libraries -->
- <target name="all" depends="oscheck,evaluate.cvs.tags, defaultenvchecks, org.glite, org.glite.lb, devtools, external, project" />
-
- <!-- ====================================================
- Print dependecies to console
- ==================================================== -->
-
- <target name="dependencies">
- <concat>
- <fileset dir="." includes="dependencies.properties" />
- </concat>
- </target>
-
-</project>
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2004 on behalf of the EU EGEE Project:
- The European Organization for Nuclear Research (CERN),
- Istituto Nazionale di Fisica Nucleare (INFN), Italy
- Datamat Spa, Italy
- Centre National de la Recherche Scientifique (CNRS), France
- CS Systeme d'Information (CSSI), France
- Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
- Universiteit van Amsterdam (UvA), Netherlands
- University of Helsinki (UH.HIP), Finland
- University of Bergen (UiB), Norway
- Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
-
- Common build properties file for the gLite LB modules
-
- Authors: Ales Krenek <ljocha@ics.muni.cz>
- Alberto Di Meglio <alberto.di.meglio@cern.ch>
- Version info: $Id$
- Release: $Name$
-
- Revision history:
- $Log$
--->
-
-<project name="Logging and Bookkeping subsystem common properties">
-
- <!-- Include build properties to allow overwriting
- of properties for subsystem -->
- <property name="subsystem.build.properties.file" value="./project/build.properties" />
- <property file="${subsystem.build.properties.file}" />
-
- <!-- ======================================================
- Define subsystem properties
- ====================================================== -->
-
- <!-- Subsystem name -->
- <property name="subsystem.name" value="${lb.subsystem.name}"/>
-
- <!-- Subsystem prefix -->
- <property name="subsystem.prefix" value="${lb.subsystem.prefix}"/>
-
- <!-- ======================================================
- Define general subsystem properties
- ====================================================== -->
-
- <!-- Include common subsystem properties -->
- <import file="${subsystem.general.properties.file}" />
-
- <!-- ======================================================
- Define extra properties here ...
- ====================================================== -->
-
-
-</project>
\ No newline at end of file
+++ /dev/null
-#!/bin/sh
-
-cd ../..
-
-cvs co org.glite
-cvs co org.glite.lb
-
-cd org.glite.lb/project
-ant -f glite.lb.csf.xml
-
+++ /dev/null
-@type _common_
-jobid jobId Id of the job
-string owner Job owner
-_index_
-
-int jobtype Type of job
- _null_ -1
- _code_ SIMPLE simple job
- _code_ DAG composite job
- _code_ COLLECTION parent of collection of jobs
- _code_ PBS PBS job
- _code_ CONDOR Condor job
-jobid parent_job parent job of subjob
-
-string seed string used for generation of subjob IDs
-int children_num number of subjobs
-strlist children list of subjob IDs
- _special_ XMLstructured
-intlist children_hist summary (histogram) of children job states
- _special_ XMLstructured
-stslist children_states full status information of the children
- _special_ XMLstructured
-
-string condorId Id within Condor-G
-string globusId Globus allocated Id
-string localId Id within LRMS
-
-string jdl User submitted job description
-string matched_jdl Full job description after matchmaking
-string destination ID of CE where the job is being sent
-_index_
-string condor_jdl ClassAd passed to Condor-G for last job execution
-string rsl Job RSL sent to Globus
-
-string reason Reason of being in this status, if any
-
-string location Where the job is being processed
-_index_
-string ce_node Worker node where the job is executed
-string network_server Network server handling the job
-
-bool subjob_failed Subjob failed (the parent job will fail too)
-int done_code Return code
- _null_ -1
- _code_ OK Finished correctly
- _code_ FAILED Execution failed
- _code_ CANCELLED Cancelled by user
-int exit_code Unix exit code
-bool resubmitted The job was resubmitted
-
-bool cancelling Cancellation request in progress
-string cancelReason Reason of cancel
-
-int cpuTime Consumed CPU time
- _null_ -1
-
-taglist user_tags List of pairs (user_tag, user_value)
- _special_ XMLstructured
-
-timeval stateEnterTime When entered this status
-timeval lastUpdateTime Last known event of the job
-
-intlist stateEnterTimes When all previous states were entered
- _special_ XMLstructured
-
-bool expectUpdate Some logged information has not arrived yet
-string expectFrom Sources of the missing information
-string acl ACL of the job
-
-bool payload_running User payload started
-strlist possible_destinations Possible job destinations
- _special_ XMLstructured
-strlist possible_ce_nodes CE nodes matching to possible_destinations
- _special_ XMLstructured
-
-bool suspended Job is suspended
-string suspend_reason Reason for the suspend
-
-string pbs_state Job state which would probably return PBS qstat (Q/R/C/....)
-string pbs_queue Name of queue in which is job queued
-string pbs_owner Owner of job
-string pbs_name Name of job
-string pbs_reason Glued reasons/errors leading to pending events
-string pbs_scheduler Name of pbs scheduler
-string pbs_dest_host Hostname of node where job is running
-int pbs_pid PID of running job
-string pbs_resource_usage Glued resource usage
-int pbs_exit_status Job exit status
-string pbs_error_desc Glued error descriptions from error events
-
-string condor_status Condor job status
-string condor_universe Condor job Universe (in job ClassAds)
-string condor_owner Job owner
-int condor_shadow_pid PID of Shadow
-int condor_shadow_exit_status Condor shadow exit status (see h/exit.h)
-int condor_starter_pid PID of Starter
-int condor_starter_exit_status Condor starter exit status
-int condor_job_pid PID of running job
-int condor_job_exit_status Job exit status
-string condor_dest_host Hostname of node where job is running
-string condor_reason Glued reasons/errors leading to pending events
-string condor_error_desc Glued error descriptions from error events
-
-
-@type Submitted Entered by the user to the User Interface or registered by Job Partitioner.
-@type Waiting Accepted by WMS, waiting for resource allocation.
-@type Ready Matching resources found.
-@type Scheduled Accepted by LRMS queue.
-@type Running Executable is running.
-@type Done Execution finished, output is available.
-@type Cleared Output transfered back to user and freed.
-@type Aborted Aborted by system (at any stage).
-@type Cancelled Cancelled by user.
-@type Unknown Status cannot be determined.
-@type Purged Job has been purged from bookkeeping server (for LB->RGMA interface).
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Copyright (c) 2004 on behalf of the EU EGEE Project:
- The European Organization for Nuclear Research (CERN),
- Istituto Nazionale di Fisica Nucleare (INFN), Italy
- Datamat Spa, Italy
- Centre National de la Recherche Scientifique (CNRS), France
- CS Systeme d'Information (CSSI), France
- Royal Institute of Technology, Center for Parallel Computers (KTH-PDC), Sweden
- Universiteit van Amsterdam (UvA), Netherlands
- University of Helsinki (UH.HIP), Finland
- University of Bergen (UiB), Norway
- Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom
-
- Common Ant task definition file for the gLite Logging and Bookeeping modules
-
- Authors: Ales Krenek <ljocha@ics.muni.cz>
- Alberto Di Meglio <alberto.di.meglio@cern.ch>
- Version info: $Id$
- Release: $Name$
-
- Revision history:
- $Log$
--->
-
-<project name="Logging and Bookeeping subsystem common tasks and types definitions">
-
- <!-- ======================================================
- Subsystem task definitions
- ====================================================== -->
-
-</project>
\ No newline at end of file
+++ /dev/null
-%types = (
- C=>{
- bool=>'"int"',
- string=>'"char *"',
- strlist=>'"char **"',
- intlist=>'"int *"',
- taglist=>'"edg_wll_TagValue *"',
- stslist=>'"struct _edg_wll_JobStat *"',
- timeval=>'"struct timeval"',
- jobid=>'"edg_wlc_JobId"',
- notifid=>'"edg_wll_NotifId"',
- logsrc=>'"edg_wll_Source"',
- port=>'"uint16_t"',
-# level=>'"enum edg_wll_Level"',
- int=>'"int"',
- float=>'"float"',
- double=>'"double"',
- },
- 'C++'=>{
- string=>'"std::string"',
- timeval=>'"struct timeval"',
- jobid=>'"edg::workload::common::jobid::JobId"',
- bool=>'"int"',
- intlist=>'"std::vector<int>"',
- strlist=>'"std::vector<std::string>"',
- taglist=>'"std::vector<std::pair<std::string>>"',
- stslist=>'"std::vector<JobStatus>"',
- logsrc=>'"int"',
- port=>'"int"',
- int=>'"int"',
- float=>'"float"',
- double=>'"double"',
- },
- 'wsdl'=>{
- bool=>'"xsd:boolean"',
- string=>'"xsd:string"',
- int=>'"xsd:int"',
- jobid=>'"xsd:string"',
- jobstat=>'"jobStatus"',
- usertag=>'"tagValue"',
- timeval=>'"timeval"',
- logsrc=>'"eventSource"',
- notifid=>'"xsd:string"',
- port=>'"xsd:int"',
- float=>'"xsd:float"',
- double=>'"xsd:double"',
- }
-);
-
-%baseTypes = (
- intlist=>'int',
- floatlist=>'float',
- doublelist=>'double',
- strlist=>'string',
- stslist=>'jobstat',
- taglist=>'usertag'
-);
-
-%toString = (
- C=>{
- int=>'qq{asprintf(&$dst,"%d",$src);}',
- float=>'qq{asprintf(&$dst,"%f",$src);}',
- double=>'qq{asprintf(&$dst,"%f",$src);}',
- port=>'qq{asprintf(&$dst,"%d",(int) $src);}',
- bool=>'qq{asprintf(&$dst,"%d",$src);}',
- string=>'qq{$dst = $src?strdup($src):NULL;}',
- timeval=>'qq{edg_wll_ULMTimevalToDate(($src).tv_sec,($src).tv_usec,$dst);}',
- jobid=>'qq{$dst = edg_wlc_JobIdUnparse($src);}',
- notifid=>'qq{$dst = edg_wll_NotifIdUnparse($src);}',
-# level=>'qq{$dst = edg_wll_LevelToString($src);}',
- logsrc=>'qq{$dst = edg_wll_SourceToString($src);}',
-# strlist, intlist, stslist are used only in consumer API, they don't need toString method
- }
-);
-
-%ULMasString = (
- logsrc=>1
-);
-
-%fromString = (
- C=>{
- int=>'qq{$dst = atoi($src);}',
- float=>'qq{$dst = strtof($src,NULL);}',
- double=>'qq{$dst = strtod($src,NULL);}',
- port=>'qq{$dst = (uint16_t) atoi($src);}',
- bool=>'qq{$dst = atoi($src);}',
- string=>'qq{$dst = strdup($src);}',
- timeval=>'qq{edg_wll_ULMDateToTimeval($src,&$dst);}',
- jobid=>'qq{edg_wlc_JobIdParse($src,&$dst);}',
- notifid=>'qq{edg_wll_NotifIdParse($src,&$dst);}',
-# level=>'qq{$dst = edg_wll_StringToLevel($src);}',
- logsrc=>'qq{$dst = edg_wll_StringToSource($src);}',
-# strlist, intlist, stslist are used only in consumer API, they don't need fromString method
- }
-);
-
-%DefaultNullValue = (
- int=>0,
- float=>0.0,
- double=>0.0,
- port=>0,
-# level=>'EDG_WLL_LEVEL_UNDEFINED',
- bool=>0,
- string=>'NULL',
- jobid=>'NULL',
- notifid=>'NULL',
- logsrc=>'EDG_WLL_SOURCE_NONE',
- timeval=>'null_timeval',
- strlist=>'NULL',
- intlist=>'NULL',
- taglist=>'NULL',
- stslist=>'NULL',
-);
-
-%compare = (
- C=>{
- int=>'"($a == $b)"',
- float=>'"($a == $b)"',
- double=>'"($a == $b)"',
- port=>'"($a == $b)"',
-# level=>'"($a == $b)"',
- bool=>'"(($a || !$b) && ($b || !$a))"',
-# string=>'"(($a) == NULL && ($b) == NULL) || (($a)&&($b)&& !strcmp($a,$b))"',
- string=>'if ($b eq \'NULL\') { qq{(($a) == NULL)}; }
- else { qq{(($a) == NULL && ($b) == NULL) || (($a)&&($b)&& !strcmp($a,$b))}; } ',
-# jobid=>'"(($a) == NULL && ($b) == NULL) || (($a)&&($b)&& !strcmp(edg_wlc_JobIdUnparse($a),edg_wlc_JobIdUnparse($b)))"',
- jobid=>'if ($b eq \'NULL\') { qq{(($a) == NULL) }; }
- else { qq{(($a) == NULL && ($b) == NULL) || (($a)&&($b)&& !strcmp(edg_wlc_JobIdUnparse($a),edg_wlc_JobIdUnparse($b)))}; }',
- notifid=>'"($a) == ($b)"',
- logsrc=>'"($a) == ($b)"',
- timeval=>'"($a).tv_sec == ($b).tv_sec && ($a).tv_usec == ($b).tv_usec"',
- }
-);
-
-%toFormatString = (
- C=>{
- int=>'"%d"',
- float=>'"%f"',
- double=>'"%f"',
- port=>'"%d"',
- bool=>'"%d"',
-# level=>'"%s"',
- string=>'"%|Us"',
- jobid=>'"%s"',
- notifid=>'"%s"',
- logsrc=>'"%s"',
- timeval=>'"%s"',
- }
-);
+++ /dev/null
-# $Header$
-module.version=1.5.2
-module.age=3