From 339877d21c7ece2a105a2670b9497afcb34d5a67 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Wed, 17 Feb 2010 15:15:13 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'glite-lb- common_R_7_0_3_2'. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Sprout from branch_3795 2010-02-17 15:15:12 UTC FrantiÅ¡ek Dvořák 'Buildtime dependency on classads.' Delete: org.glite.jobid.api-c/Makefile org.glite.jobid.api-c/configure org.glite.jobid.api-c/interface/cjobid.h org.glite.jobid.api-c/interface/strmd5.h org.glite.jobid.api-c/project/ChangeLog org.glite.jobid.api-c/project/version.properties org.glite.jobid.api-c/src/cjobid.c org.glite.jobid.api-c/src/md32_common.h org.glite.jobid.api-c/src/md5.h org.glite.jobid.api-c/src/md5_dgst.c org.glite.jobid.api-c/src/md5_locl.h org.glite.jobid.api-c/src/strmd5.c org.glite.jobid.api-c/test/base64_test.cpp org.glite.jobid/project/version.properties org.glite.lb.client/.cvsignore org.glite.lb.client/LICENSE org.glite.lb.client/Makefile org.glite.lb.client/build.xml org.glite.lb.client/configure org.glite.lb.client/doc/C.dox org.glite.lb.client/doc/CPP.dox org.glite.lb.client/doc/README-notify org.glite.lb.client/doc/api/Makefile org.glite.lb.client/doc/api/api.tex org.glite.lb.client/doc/api/fig/logging-arch.eps org.glite.lb.client/doc/api/fig/logging-arch.pdf org.glite.lb.client/doc/glite-lb-dump.8 org.glite.lb.client/doc/glite-lb-load.8 org.glite.lb.client/doc/glite-lb-logevent.1 org.glite.lb.client/doc/glite-lb-notify.1 org.glite.lb.client/examples/Makefile org.glite.lb.client/examples/README.examples org.glite.lb.client/examples/abort_job.c org.glite.lb.client/examples/aborted.l org.glite.lb.client/examples/cancelled.l org.glite.lb.client/examples/change_acl.c org.glite.lb.client/examples/chkpt.l org.glite.lb.client/examples/cleared.l org.glite.lb.client/examples/dagids.c org.glite.lb.client/examples/done.l org.glite.lb.client/examples/done_dag.l org.glite.lb.client/examples/done_subjob.l org.glite.lb.client/examples/failed_dag.l org.glite.lb.client/examples/failed_subjob.l org.glite.lb.client/examples/feed_shark.c org.glite.lb.client/examples/flood_proxy.c org.glite.lb.client/examples/gen_begin org.glite.lb.client/examples/gen_sample_job org.glite.lb.client/examples/job-status.pl org.glite.lb.client/examples/job_log.c org.glite.lb.client/examples/job_reg.c org.glite.lb.client/examples/job_status.c org.glite.lb.client/examples/log_usertag_proxy.c org.glite.lb.client/examples/multiple_user_jobs.c org.glite.lb.client/examples/notify.pl org.glite.lb.client/examples/parse_eventsfile.c org.glite.lb.client/examples/purge_test org.glite.lb.client/examples/query_ext.c org.glite.lb.client/examples/query_seq_code.c org.glite.lb.client/examples/ready.l org.glite.lb.client/examples/ready_dag.l org.glite.lb.client/examples/ready_subjob.l org.glite.lb.client/examples/resubmission.l org.glite.lb.client/examples/resubmitted.l org.glite.lb.client/examples/running.l org.glite.lb.client/examples/running_dag.l org.glite.lb.client/examples/running_subjob.l org.glite.lb.client/examples/scheduled.l org.glite.lb.client/examples/scheduled_dag.l org.glite.lb.client/examples/scheduled_subjob.l org.glite.lb.client/examples/shallow_and_full_resub.l org.glite.lb.client/examples/shallow_resub_complex.l org.glite.lb.client/examples/shallow_resub_simple.l org.glite.lb.client/examples/shallow_resub_simple2.l org.glite.lb.client/examples/stats.c org.glite.lb.client/examples/stress_context.c org.glite.lb.client/examples/stresslog.c org.glite.lb.client/examples/submitted.l org.glite.lb.client/examples/submitted_dag.l org.glite.lb.client/examples/submitted_subjob.l org.glite.lb.client/examples/test_changed_jdl.c org.glite.lb.client/examples/test_notif_rotate.pl org.glite.lb.client/examples/ulmfields.pl org.glite.lb.client/examples/user-jobs.pl org.glite.lb.client/examples/user_jobs.c org.glite.lb.client/examples/user_jobs_threaded.c org.glite.lb.client/examples/waiting.l org.glite.lb.client/examples/waiting_dag.l org.glite.lb.client/examples/waiting_subjob.l org.glite.lb.client/examples/webservices/java-trustmanager/Makefile org.glite.lb.client/examples/webservices/java-trustmanager/README org.glite.lb.client/examples/webservices/java-trustmanager/src/LBClientTM.java org.glite.lb.client/examples/webservices/java/Makefile org.glite.lb.client/examples/webservices/java/README org.glite.lb.client/examples/webservices/java/src/ExampleSSLSocketFactory.java org.glite.lb.client/examples/webservices/java/src/LBClientExample.java org.glite.lb.client/examples/webservices/java/src/MyX509KeyManager.java org.glite.lb.client/examples/webservices/java/src/MyX509TrustManager.java org.glite.lb.client/examples/webservices/java/src/log4j.properties org.glite.lb.client/interface/Event.h.T org.glite.lb.client/interface/Job.h org.glite.lb.client/interface/JobStatus.h.T org.glite.lb.client/interface/Notification.h org.glite.lb.client/interface/ServerConnection.h org.glite.lb.client/interface/connection.h org.glite.lb.client/interface/consumer.h org.glite.lb.client/interface/notification.h org.glite.lb.client/interface/prod_proto.h org.glite.lb.client/interface/producer.h.T org.glite.lb.client/interface/stat_fields.h org.glite.lb.client/interface/statistics.h org.glite.lb.client/m4/glite_lb_client.m4 org.glite.lb.client/project/.cvsignore org.glite.lb.client/project/ChangeLog org.glite.lb.client/project/build.number org.glite.lb.client/project/build.properties org.glite.lb.client/project/configure.properties.xml org.glite.lb.client/project/package.description org.glite.lb.client/project/package.summary org.glite.lb.client/project/properties.xml org.glite.lb.client/project/tar_exclude org.glite.lb.client/project/version.properties org.glite.lb.client/src/Event.cpp.T org.glite.lb.client/src/EventAttrNames.pl org.glite.lb.client/src/Job.cpp org.glite.lb.client/src/JobStatus.cpp.T org.glite.lb.client/src/Notification.cpp org.glite.lb.client/src/ServerConnection.cpp org.glite.lb.client/src/StatusAttrNames.pl org.glite.lb.client/src/args.c.T org.glite.lb.client/src/args.h org.glite.lb.client/src/connection.c org.glite.lb.client/src/consumer.c org.glite.lb.client/src/export.sh org.glite.lb.client/src/logevent.c.T org.glite.lb.client/src/notification.c org.glite.lb.client/src/notify.c org.glite.lb.client/src/perftest_jobreg.c org.glite.lb.client/src/perftest_jobreg.sh org.glite.lb.client/src/perftest_logjobs.c org.glite.lb.client/src/perftest_query.sh org.glite.lb.client/src/prod_proto.c org.glite.lb.client/src/producer.c org.glite.lb.client/src/stat_fields.cpp org.glite.lb.client/src/statistics.c org.glite.lb.client/src/uiwrap.T org.glite.lb.client/src/uiwrap.c.T org.glite.lb.client/test/PLOT org.glite.lb.client/test/TEST org.glite.lb.client/test/prod_proto_test.c org.glite.lb.client/test/producer_test.cpp org.glite.lb.logger/.cvsignore org.glite.lb.logger/LICENSE org.glite.lb.logger/Makefile org.glite.lb.logger/build.xml org.glite.lb.logger/config/glite-lb-logger.config.xml org.glite.lb.logger/config/glite-lb-logger.default-properties org.glite.lb.logger/config/startup org.glite.lb.logger/configure org.glite.lb.logger/doc/glite-lb-interlogd.8 org.glite.lb.logger/doc/glite-lb-logd.8 org.glite.lb.logger/project/ChangeLog org.glite.lb.logger/project/build.number org.glite.lb.logger/project/build.properties org.glite.lb.logger/project/configure.properties.xml org.glite.lb.logger/project/package.description org.glite.lb.logger/project/package.summary org.glite.lb.logger/project/properties.xml org.glite.lb.logger/project/tar_exclude org.glite.lb.logger/project/version.properties org.glite.lb.logger/src-nt/Connection.H org.glite.lb.logger/src-nt/Connection.cpp org.glite.lb.logger/src-nt/EventManager.H org.glite.lb.logger/src-nt/EventManager.cpp org.glite.lb.logger/src-nt/Exception.H org.glite.lb.logger/src-nt/HTTPTransport.H org.glite.lb.logger/src-nt/HTTPTransport.cpp org.glite.lb.logger/src-nt/InputChannel.H org.glite.lb.logger/src-nt/InputChannel.cpp org.glite.lb.logger/src-nt/Makefile org.glite.lb.logger/src-nt/Message.H org.glite.lb.logger/src-nt/MessageStore.H org.glite.lb.logger/src-nt/MessageStore.cpp org.glite.lb.logger/src-nt/PlainConnection.H org.glite.lb.logger/src-nt/PlainConnection.cpp org.glite.lb.logger/src-nt/PluginManager.H org.glite.lb.logger/src-nt/PluginManager.cpp org.glite.lb.logger/src-nt/Properties.H org.glite.lb.logger/src-nt/Singleton.H org.glite.lb.logger/src-nt/SocketInput.H org.glite.lb.logger/src-nt/SocketInput.cpp org.glite.lb.logger/src-nt/ThreadPool.H org.glite.lb.logger/src-nt/ThreadPool.cpp org.glite.lb.logger/src-nt/Transport.H org.glite.lb.logger/src-nt/Transport.cpp org.glite.lb.logger/src-nt/main.cpp org.glite.lb.logger/src-nt/test/EventManagerTest.cpp org.glite.lb.logger/src-nt/test/PluginManagerTest.cpp org.glite.lb.logger/src-nt/test/SingletonTest.cpp org.glite.lb.logger/src-nt/test/ThreadPoolTest.cpp org.glite.lb.logger/src-nt/test/test_main.cpp org.glite.lb.logger/src/event_queue.c org.glite.lb.logger/src/event_store.c org.glite.lb.logger/src/event_store_http.c org.glite.lb.logger/src/http.c org.glite.lb.logger/src/il_error.c org.glite.lb.logger/src/il_error.h org.glite.lb.logger/src/il_master.c org.glite.lb.logger/src/input_queue_socket.c org.glite.lb.logger/src/input_queue_socket_http.c org.glite.lb.logger/src/interlogd.c org.glite.lb.logger/src/interlogd.h org.glite.lb.logger/src/logd.c org.glite.lb.logger/src/logd_proto.c org.glite.lb.logger/src/logd_proto.h org.glite.lb.logger/src/perftest_il.sh org.glite.lb.logger/src/perftest_ll.sh org.glite.lb.logger/src/queue_mgr.c org.glite.lb.logger/src/queue_mgr_http.c org.glite.lb.logger/src/queue_thread.c org.glite.lb.logger/src/recover.c org.glite.lb.logger/src/send_event.c org.glite.lb.logger/src/send_event_http.c org.glite.lb.logger/src/server_msg.c org.glite.lb.logger/src/server_msg_http.c org.glite.lb.logger/test/IlTestBase.cpp org.glite.lb.logger/test/IlTestBase.h org.glite.lb.logger/test/event_queueTest.cpp org.glite.lb.logger/test/event_storeTest.cpp org.glite.lb.logger/test/il_test.cpp org.glite.lb.logger/test/input_queue_socketTest.cpp org.glite.lb.logger/test/ll_test.cpp org.glite.lb.logger/test/logd_proto_test.c org.glite.lb.logger/test/server_msgTest.cpp 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.sql org.glite.lb.server/config/glite-lb-index.conf.template org.glite.lb.server/config/glite-lb-migrate_db2version20 org.glite.lb.server/config/startup org.glite.lb.server/configure org.glite.lb.server/doc/glite-lb-bkindex.8 org.glite.lb.server/doc/glite-lb-bkserverd.8 org.glite.lb.server/doc/glite-lb-mon-db.1 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/interface/index.h org.glite.lb.server/interface/lb_authz.h org.glite.lb.server/interface/pretty_print_wrapper.h org.glite.lb.server/interface/query.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/ChangeLog 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/package.description org.glite.lb.server/project/package.summary 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/cond_dump.c org.glite.lb.server/src/cond_dump.h org.glite.lb.server/src/db_calls.c org.glite.lb.server/src/db_calls.h org.glite.lb.server/src/db_store.c org.glite.lb.server/src/db_supp.c org.glite.lb.server/src/db_supp.h 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/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_proto.c org.glite.lb.server/src/lb_proto.h org.glite.lb.server/src/lb_rss.c org.glite.lb.server/src/lb_rss.h org.glite.lb.server/src/lb_text.c org.glite.lb.server/src/lb_text.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/lcas_lb.c org.glite.lb.server/src/load.c org.glite.lb.server/src/mon-db.c 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/openserver.h org.glite.lb.server/src/perftest_proxy.sh org.glite.lb.server/src/pretty_print_wrapper.cpp org.glite.lb.server/src/purge.h org.glite.lb.server/src/query.c 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_trans.sh org.glite.lb.server/test/test_xml.cpp.T org.glite.lb.state-machine/LICENSE org.glite.lb.state-machine/Makefile org.glite.lb.state-machine/configure org.glite.lb.state-machine/interface/intjobstat.h org.glite.lb.state-machine/interface/lb-job-attrs.xsd org.glite.lb.state-machine/interface/lb-job-attrs2.xsd.T org.glite.lb.state-machine/interface/lb-job-record.xsd org.glite.lb.state-machine/interface/process_event.h org.glite.lb.state-machine/interface/seqcode_aux.h org.glite.lb.state-machine/project/ChangeLog org.glite.lb.state-machine/project/package.description org.glite.lb.state-machine/project/package.summary org.glite.lb.state-machine/project/version.properties org.glite.lb.state-machine/src/job_attrs.xsl org.glite.lb.state-machine/src/job_attrs2.xsl org.glite.lb.state-machine/src/jpis_config.xsl org.glite.lb.state-machine/src/lb_plugin.c org.glite.lb.state-machine/src/process_event.c org.glite.lb.state-machine/src/process_event_condor.c org.glite.lb.state-machine/src/process_event_pbs.c org.glite.lb.state-machine/src/seqcode_aux.c org.glite.lb.utils/.cvsignore org.glite.lb.utils/LICENSE org.glite.lb.utils/Makefile org.glite.lb.utils/build.xml org.glite.lb.utils/configure org.glite.lb.utils/doc/README.LB-monitoring org.glite.lb.utils/doc/README.LB-statistics org.glite.lb.utils/doc/glite-lb-mon.1 org.glite.lb.utils/doc/glite-lb-purge.8 org.glite.lb.utils/examples/glite-lb-index.conf org.glite.lb.utils/examples/glite-lb-statistics-gsi.sh org.glite.lb.utils/examples/glite-lb-statistics-rsync.sh org.glite.lb.utils/examples/glite-lb-statistics-sftp.sh org.glite.lb.utils/examples/glite-lb-statistics.sh org.glite.lb.utils/project/ChangeLog org.glite.lb.utils/project/build.number org.glite.lb.utils/project/build.properties org.glite.lb.utils/project/configure.properties.xml org.glite.lb.utils/project/package.description org.glite.lb.utils/project/package.summary org.glite.lb.utils/project/properties.xml org.glite.lb.utils/project/tar_exclude org.glite.lb.utils/project/version.properties org.glite.lb.utils/src/dump.c org.glite.lb.utils/src/dump_exporter.c org.glite.lb.utils/src/glite-lb-bkpurge-offline.sh org.glite.lb.utils/src/load.c org.glite.lb.utils/src/mon.c org.glite.lb.utils/src/process_attrs.c org.glite.lb.utils/src/process_attrs2.c.T org.glite.lb.utils/src/purge.c org.glite.lb.utils/src/state_history.c org.glite.lb.utils/src/statistics.c org.glite.lb/.cvsignore org.glite.lb/LICENSE org.glite.lb/build.xml org.glite.lb/configure 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/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/etics-tag-consistency.pl org.glite.lb/etics-tag-with-subsystems.pl org.glite.lb/etics-tag.pl 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/build.number org.glite.lb/project/build.properties org.glite.lb/project/glite.lb.csf.xml org.glite.lb/project/package.description org.glite.lb/project/package.summary org.glite.lb/project/properties.xml org.glite.lb/project/run-workspace org.glite.lb/project/taskdefs.xml org.glite.lb/project/version.properties org.glite.lbjp-common.db/.cvsignore org.glite.lbjp-common.db/LICENSE org.glite.lbjp-common.db/Makefile org.glite.lbjp-common.db/configure org.glite.lbjp-common.db/doc/C.dox org.glite.lbjp-common.db/examples/db_expire.c org.glite.lbjp-common.db/examples/db_test.c org.glite.lbjp-common.db/interface/db.h org.glite.lbjp-common.db/project/ChangeLog org.glite.lbjp-common.db/project/get_soname.sh org.glite.lbjp-common.db/project/version.properties org.glite.lbjp-common.db/src/db.c org.glite.lbjp-common.jp-interface/Makefile org.glite.lbjp-common.jp-interface/build.xml org.glite.lbjp-common.jp-interface/configure org.glite.lbjp-common.jp-interface/interface/attr.h org.glite.lbjp-common.jp-interface/interface/backend.h org.glite.lbjp-common.jp-interface/interface/builtin_plugins.h org.glite.lbjp-common.jp-interface/interface/context.h org.glite.lbjp-common.jp-interface/interface/file_plugin.h org.glite.lbjp-common.jp-interface/interface/indexdb.h org.glite.lbjp-common.jp-interface/interface/known_attr.h org.glite.lbjp-common.jp-interface/interface/type_plugin.h org.glite.lbjp-common.jp-interface/interface/types.h org.glite.lbjp-common.jp-interface/project/ChangeLog org.glite.lbjp-common.jp-interface/project/version.properties org.glite.lbjp-common.jp-interface/src/attr.c org.glite.lbjp-common.jp-interface/src/context.c org.glite.lbjp-common.jp-interface/src/indexdb.c org.glite.lbjp-common.jp-interface/src/utils.c org.glite.lbjp-common.jp-interface/test/type_test.cpp org.glite.lbjp-common.maildir/.cvsignore org.glite.lbjp-common.maildir/Makefile org.glite.lbjp-common.maildir/configure org.glite.lbjp-common.maildir/interface/maildir.h org.glite.lbjp-common.maildir/project/ChangeLog org.glite.lbjp-common.maildir/project/version.properties org.glite.lbjp-common.maildir/src/maildir.c org.glite.lbjp-common.server-bones/.cvsignore org.glite.lbjp-common.server-bones/Makefile org.glite.lbjp-common.server-bones/configure org.glite.lbjp-common.server-bones/examples/cnt_example.c org.glite.lbjp-common.server-bones/examples/srv_example.c org.glite.lbjp-common.server-bones/interface/srvbones.h org.glite.lbjp-common.server-bones/project/ChangeLog org.glite.lbjp-common.server-bones/project/version.properties org.glite.lbjp-common.server-bones/src/srvbones.c org.glite.lbjp-common.trio/.cvsignore org.glite.lbjp-common.trio/LICENSE org.glite.lbjp-common.trio/Makefile org.glite.lbjp-common.trio/configure org.glite.lbjp-common.trio/interface/escape.h org.glite.lbjp-common.trio/interface/trio.h org.glite.lbjp-common.trio/project/ChangeLog org.glite.lbjp-common.trio/project/version.properties org.glite.lbjp-common.trio/src/escape.c org.glite.lbjp-common.trio/src/strio.c org.glite.lbjp-common.trio/src/strio.h org.glite.lbjp-common.trio/src/trio.c org.glite.lbjp-common.trio/src/triop.h org.glite.lbjp-common.trio/test/trio_test.cpp org.glite.lbjp-common/project/version.properties org.glite.security.gsoap-plugin/LICENSE org.glite.security.gsoap-plugin/Makefile org.glite.security.gsoap-plugin/build.xml org.glite.security.gsoap-plugin/configure org.glite.security.gsoap-plugin/examples/calc.h.S org.glite.security.gsoap-plugin/examples/wscalc_clt_ex.c org.glite.security.gsoap-plugin/examples/wscalc_srv_ex.c org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c org.glite.security.gsoap-plugin/interface/glite_gscompat.h org.glite.security.gsoap-plugin/interface/glite_gsplugin-int.h org.glite.security.gsoap-plugin/interface/glite_gsplugin.h org.glite.security.gsoap-plugin/project/ChangeLog org.glite.security.gsoap-plugin/project/build.number org.glite.security.gsoap-plugin/project/build.properties org.glite.security.gsoap-plugin/project/configure.properties.xml org.glite.security.gsoap-plugin/project/libtoolhack/gcc org.glite.security.gsoap-plugin/project/package.description org.glite.security.gsoap-plugin/project/package.summary org.glite.security.gsoap-plugin/project/properties.xml org.glite.security.gsoap-plugin/project/tar_exclude org.glite.security.gsoap-plugin/project/version.properties org.glite.security.gsoap-plugin/src/glite_gsplugin.c org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.c org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.h org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.c org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.h org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.c org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.h org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.c org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.h org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.c org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.h org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.c org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.h org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.c org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.h org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.c org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.h org.glite.security.gsoap-plugin/test/test_gsplugin_cxx.cpp org.glite.security.gss/LICENSE org.glite.security.gss/Makefile org.glite.security.gss/configure org.glite.security.gss/interface/glite_gss.h org.glite.security.gss/project/ChangeLog org.glite.security.gss/project/package.description org.glite.security.gss/project/package.summary org.glite.security.gss/project/version.properties org.glite.security.gss/src/glite_gss.c org.glite.security.gss/test/test_gss.cpp --- org.glite.jobid.api-c/Makefile | 71 - org.glite.jobid.api-c/configure | 698 - org.glite.jobid.api-c/interface/cjobid.h | 137 - org.glite.jobid.api-c/interface/strmd5.h | 39 - org.glite.jobid.api-c/project/ChangeLog | 11 - org.glite.jobid.api-c/project/version.properties | 3 - org.glite.jobid.api-c/src/cjobid.c | 274 - org.glite.jobid.api-c/src/md32_common.h | 623 - org.glite.jobid.api-c/src/md5.h | 118 - org.glite.jobid.api-c/src/md5_dgst.c | 298 - org.glite.jobid.api-c/src/md5_locl.h | 176 - org.glite.jobid.api-c/src/strmd5.c | 152 - org.glite.jobid.api-c/test/base64_test.cpp | 72 - org.glite.jobid/project/version.properties | 3 - org.glite.lb.client/.cvsignore | 2 - org.glite.lb.client/LICENSE | 69 - org.glite.lb.client/Makefile | 366 - org.glite.lb.client/build.xml | 144 - org.glite.lb.client/configure | 698 - org.glite.lb.client/doc/C.dox | 17 - org.glite.lb.client/doc/CPP.dox | 15 - org.glite.lb.client/doc/README-notify | 106 - org.glite.lb.client/doc/api/Makefile | 9 - org.glite.lb.client/doc/api/api.tex | 1800 --- org.glite.lb.client/doc/api/fig/logging-arch.eps | 1714 --- org.glite.lb.client/doc/api/fig/logging-arch.pdf | 92 - org.glite.lb.client/doc/glite-lb-dump.8 | 62 - org.glite.lb.client/doc/glite-lb-load.8 | 50 - org.glite.lb.client/doc/glite-lb-logevent.1 | 98 - org.glite.lb.client/doc/glite-lb-notify.1 | 142 - org.glite.lb.client/examples/Makefile | 79 - org.glite.lb.client/examples/README.examples | 32 - org.glite.lb.client/examples/abort_job.c | 135 - org.glite.lb.client/examples/aborted.l | 2 - org.glite.lb.client/examples/cancelled.l | 2 - org.glite.lb.client/examples/change_acl.c | 82 - org.glite.lb.client/examples/chkpt.l | 6 - org.glite.lb.client/examples/cleared.l | 4 - org.glite.lb.client/examples/dagids.c | 65 - org.glite.lb.client/examples/done.l | 4 - org.glite.lb.client/examples/done_dag.l | 4 - org.glite.lb.client/examples/done_subjob.l | 4 - org.glite.lb.client/examples/failed_dag.l | 3 - org.glite.lb.client/examples/failed_subjob.l | 3 - org.glite.lb.client/examples/feed_shark.c | 199 - org.glite.lb.client/examples/flood_proxy.c | 81 - org.glite.lb.client/examples/gen_begin | 64 - org.glite.lb.client/examples/gen_sample_job | 124 - org.glite.lb.client/examples/job-status.pl | 53 - org.glite.lb.client/examples/job_log.c | 148 - org.glite.lb.client/examples/job_reg.c | 175 - org.glite.lb.client/examples/job_status.c | 326 - org.glite.lb.client/examples/log_usertag_proxy.c | 116 - org.glite.lb.client/examples/multiple_user_jobs.c | 125 - org.glite.lb.client/examples/notify.pl | 33 - org.glite.lb.client/examples/parse_eventsfile.c | 120 - org.glite.lb.client/examples/purge_test | 191 - org.glite.lb.client/examples/query_ext.c | 926 -- org.glite.lb.client/examples/query_seq_code.c | 84 - org.glite.lb.client/examples/ready.l | 18 - org.glite.lb.client/examples/ready_dag.l | 13 - org.glite.lb.client/examples/ready_subjob.l | 8 - org.glite.lb.client/examples/resubmission.l | 19 - org.glite.lb.client/examples/resubmitted.l | 20 - org.glite.lb.client/examples/running.l | 4 - org.glite.lb.client/examples/running_dag.l | 4 - org.glite.lb.client/examples/running_subjob.l | 4 - org.glite.lb.client/examples/scheduled.l | 13 - org.glite.lb.client/examples/scheduled_dag.l | 12 - org.glite.lb.client/examples/scheduled_subjob.l | 7 - .../examples/shallow_and_full_resub.l | 40 - .../examples/shallow_resub_complex.l | 48 - .../examples/shallow_resub_simple.l | 30 - .../examples/shallow_resub_simple2.l | 31 - org.glite.lb.client/examples/stats.c | 87 - org.glite.lb.client/examples/stress_context.c | 114 - org.glite.lb.client/examples/stresslog.c | 190 - org.glite.lb.client/examples/submitted.l | 5 - org.glite.lb.client/examples/submitted_dag.l | 4 - org.glite.lb.client/examples/submitted_subjob.l | 4 - org.glite.lb.client/examples/test_changed_jdl.c | 45 - org.glite.lb.client/examples/test_notif_rotate.pl | 46 - org.glite.lb.client/examples/ulmfields.pl | 31 - org.glite.lb.client/examples/user-jobs.pl | 45 - org.glite.lb.client/examples/user_jobs.c | 110 - org.glite.lb.client/examples/user_jobs_threaded.c | 225 - org.glite.lb.client/examples/waiting.l | 6 - org.glite.lb.client/examples/waiting_dag.l | 6 - org.glite.lb.client/examples/waiting_subjob.l | 6 - .../webservices/java-trustmanager/Makefile | 29 - .../examples/webservices/java-trustmanager/README | 39 - .../java-trustmanager/src/LBClientTM.java | 64 - .../examples/webservices/java/Makefile | 28 - .../examples/webservices/java/README | 28 - .../java/src/ExampleSSLSocketFactory.java | 108 - .../webservices/java/src/LBClientExample.java | 79 - .../webservices/java/src/MyX509KeyManager.java | 64 - .../webservices/java/src/MyX509TrustManager.java | 83 - .../examples/webservices/java/src/log4j.properties | 30 - org.glite.lb.client/interface/Event.h.T | 308 - org.glite.lb.client/interface/Job.h | 198 - org.glite.lb.client/interface/JobStatus.h.T | 309 - org.glite.lb.client/interface/Notification.h | 102 - org.glite.lb.client/interface/ServerConnection.h | 743 - org.glite.lb.client/interface/connection.h | 26 - org.glite.lb.client/interface/consumer.h | 336 - org.glite.lb.client/interface/notification.h | 191 - org.glite.lb.client/interface/prod_proto.h | 121 - org.glite.lb.client/interface/producer.h.T | 361 - org.glite.lb.client/interface/stat_fields.h | 26 - org.glite.lb.client/interface/statistics.h | 60 - org.glite.lb.client/m4/glite_lb_client.m4 | 129 - org.glite.lb.client/project/.cvsignore | 6 - org.glite.lb.client/project/ChangeLog | 62 - org.glite.lb.client/project/build.number | 2 - org.glite.lb.client/project/build.properties | 0 .../project/configure.properties.xml | 84 - org.glite.lb.client/project/package.description | 1 - org.glite.lb.client/project/package.summary | 1 - org.glite.lb.client/project/properties.xml | 62 - org.glite.lb.client/project/tar_exclude | 10 - org.glite.lb.client/project/version.properties | 3 - org.glite.lb.client/src/Event.cpp.T | 426 - org.glite.lb.client/src/EventAttrNames.pl | 84 - org.glite.lb.client/src/Job.cpp | 203 - org.glite.lb.client/src/JobStatus.cpp.T | 516 - org.glite.lb.client/src/Notification.cpp | 340 - org.glite.lb.client/src/ServerConnection.cpp | 1341 -- org.glite.lb.client/src/StatusAttrNames.pl | 76 - org.glite.lb.client/src/args.c.T | 562 - org.glite.lb.client/src/args.h | 34 - org.glite.lb.client/src/connection.c | 792 - org.glite.lb.client/src/consumer.c | 581 - org.glite.lb.client/src/export.sh | 90 - org.glite.lb.client/src/logevent.c.T | 301 - org.glite.lb.client/src/notification.c | 877 -- org.glite.lb.client/src/notify.c | 507 - org.glite.lb.client/src/perftest_jobreg.c | 218 - org.glite.lb.client/src/perftest_jobreg.sh | 390 - org.glite.lb.client/src/perftest_logjobs.c | 307 - org.glite.lb.client/src/perftest_query.sh | 31 - org.glite.lb.client/src/prod_proto.c | 823 - org.glite.lb.client/src/producer.c | 1241 -- org.glite.lb.client/src/stat_fields.cpp | 123 - org.glite.lb.client/src/statistics.c | 186 - org.glite.lb.client/src/uiwrap.T | 157 - org.glite.lb.client/src/uiwrap.c.T | 17 - org.glite.lb.client/test/PLOT | 48 - org.glite.lb.client/test/TEST | 95 - org.glite.lb.client/test/prod_proto_test.c | 36 - org.glite.lb.client/test/producer_test.cpp | 104 - org.glite.lb.logger/.cvsignore | 2 - org.glite.lb.logger/LICENSE | 69 - org.glite.lb.logger/Makefile | 224 - org.glite.lb.logger/build.xml | 131 - .../config/glite-lb-logger.config.xml | 77 - .../config/glite-lb-logger.default-properties | 18 - org.glite.lb.logger/config/startup | 87 - org.glite.lb.logger/configure | 698 - org.glite.lb.logger/doc/glite-lb-interlogd.8 | 179 - org.glite.lb.logger/doc/glite-lb-logd.8 | 166 - org.glite.lb.logger/project/ChangeLog | 53 - org.glite.lb.logger/project/build.number | 2 - org.glite.lb.logger/project/build.properties | 0 .../project/configure.properties.xml | 65 - org.glite.lb.logger/project/package.description | 1 - org.glite.lb.logger/project/package.summary | 1 - org.glite.lb.logger/project/properties.xml | 59 - org.glite.lb.logger/project/tar_exclude | 10 - org.glite.lb.logger/project/version.properties | 3 - org.glite.lb.logger/src-nt/Connection.H | 34 - org.glite.lb.logger/src-nt/Connection.cpp | 4 - org.glite.lb.logger/src-nt/EventManager.H | 92 - org.glite.lb.logger/src-nt/EventManager.cpp | 23 - org.glite.lb.logger/src-nt/Exception.H | 13 - org.glite.lb.logger/src-nt/HTTPTransport.H | 54 - org.glite.lb.logger/src-nt/HTTPTransport.cpp | 255 - org.glite.lb.logger/src-nt/InputChannel.H | 29 - org.glite.lb.logger/src-nt/InputChannel.cpp | 37 - org.glite.lb.logger/src-nt/Makefile | 51 - org.glite.lb.logger/src-nt/Message.H | 66 - org.glite.lb.logger/src-nt/MessageStore.H | 84 - org.glite.lb.logger/src-nt/MessageStore.cpp | 24 - org.glite.lb.logger/src-nt/PlainConnection.H | 34 - org.glite.lb.logger/src-nt/PlainConnection.cpp | 39 - org.glite.lb.logger/src-nt/PluginManager.H | 69 - org.glite.lb.logger/src-nt/PluginManager.cpp | 6 - org.glite.lb.logger/src-nt/Properties.H | 36 - org.glite.lb.logger/src-nt/Singleton.H | 39 - org.glite.lb.logger/src-nt/SocketInput.H | 32 - org.glite.lb.logger/src-nt/SocketInput.cpp | 71 - org.glite.lb.logger/src-nt/ThreadPool.H | 117 - org.glite.lb.logger/src-nt/ThreadPool.cpp | 413 - org.glite.lb.logger/src-nt/Transport.H | 33 - org.glite.lb.logger/src-nt/Transport.cpp | 5 - org.glite.lb.logger/src-nt/main.cpp | 38 - .../src-nt/test/EventManagerTest.cpp | 45 - .../src-nt/test/PluginManagerTest.cpp | 58 - org.glite.lb.logger/src-nt/test/SingletonTest.cpp | 55 - org.glite.lb.logger/src-nt/test/ThreadPoolTest.cpp | 190 - org.glite.lb.logger/src-nt/test/test_main.cpp | 32 - org.glite.lb.logger/src/event_queue.c | 325 - org.glite.lb.logger/src/event_store.c | 1532 -- org.glite.lb.logger/src/event_store_http.c | 1113 -- org.glite.lb.logger/src/http.c | 197 - org.glite.lb.logger/src/il_error.c | 190 - org.glite.lb.logger/src/il_error.h | 33 - org.glite.lb.logger/src/il_master.c | 483 - org.glite.lb.logger/src/input_queue_socket.c | 323 - org.glite.lb.logger/src/input_queue_socket_http.c | 167 - org.glite.lb.logger/src/interlogd.c | 405 - org.glite.lb.logger/src/interlogd.h | 270 - org.glite.lb.logger/src/logd.c | 486 - org.glite.lb.logger/src/logd_proto.c | 661 - org.glite.lb.logger/src/logd_proto.h | 59 - org.glite.lb.logger/src/perftest_il.sh | 365 - org.glite.lb.logger/src/perftest_ll.sh | 128 - org.glite.lb.logger/src/queue_mgr.c | 269 - org.glite.lb.logger/src/queue_mgr_http.c | 164 - org.glite.lb.logger/src/queue_thread.c | 426 - org.glite.lb.logger/src/recover.c | 65 - org.glite.lb.logger/src/send_event.c | 365 - org.glite.lb.logger/src/send_event_http.c | 282 - org.glite.lb.logger/src/server_msg.c | 222 - org.glite.lb.logger/src/server_msg_http.c | 128 - org.glite.lb.logger/test/IlTestBase.cpp | 15 - org.glite.lb.logger/test/IlTestBase.h | 10 - org.glite.lb.logger/test/event_queueTest.cpp | 145 - org.glite.lb.logger/test/event_storeTest.cpp | 58 - org.glite.lb.logger/test/il_test.cpp | 44 - .../test/input_queue_socketTest.cpp | 69 - org.glite.lb.logger/test/ll_test.cpp | 119 - org.glite.lb.logger/test/logd_proto_test.c | 43 - org.glite.lb.logger/test/server_msgTest.cpp | 57 - org.glite.lb.server/.cvsignore | 2 - org.glite.lb.server/LICENSE | 69 - org.glite.lb.server/Makefile | 413 - org.glite.lb.server/build.xml | 150 - org.glite.lb.server/config/glite-lb-dbsetup.sql | 158 - .../config/glite-lb-index.conf.template | 8 - .../config/glite-lb-migrate_db2version20 | 166 - org.glite.lb.server/config/startup | 208 - org.glite.lb.server/configure | 698 - org.glite.lb.server/doc/glite-lb-bkindex.8 | 171 - org.glite.lb.server/doc/glite-lb-bkserverd.8 | 330 - org.glite.lb.server/doc/glite-lb-mon-db.1 | 57 - org.glite.lb.server/examples/stdsoap2_2.6.0.c | 10775 -------------- org.glite.lb.server/examples/stdsoap2_2.6.2.c | 11020 -------------- org.glite.lb.server/examples/stdsoap2_2.7.0c.c | 11629 --------------- org.glite.lb.server/examples/stdsoap2_2.7.0d.c | 11692 --------------- org.glite.lb.server/interface/index.h | 42 - org.glite.lb.server/interface/lb_authz.h | 75 - .../interface/pretty_print_wrapper.h | 10 - org.glite.lb.server/interface/query.h | 19 - org.glite.lb.server/interface/srv_perf.h | 30 - org.glite.lb.server/interface/store.h | 52 - org.glite.lb.server/project/.cvsignore | 6 - org.glite.lb.server/project/ChangeLog | 108 - org.glite.lb.server/project/build.number | 2 - org.glite.lb.server/project/build.properties | 0 .../project/configure.properties.xml | 115 - org.glite.lb.server/project/package.description | 1 - org.glite.lb.server/project/package.summary | 1 - org.glite.lb.server/project/properties.xml | 59 - org.glite.lb.server/project/tar_exclude | 10 - org.glite.lb.server/project/version.properties | 3 - org.glite.lb.server/src/bkindex.c | 443 - org.glite.lb.server/src/bkserverd.c | 1791 --- org.glite.lb.server/src/cond_dump.c | 214 - org.glite.lb.server/src/cond_dump.h | 9 - org.glite.lb.server/src/db_calls.c | 92 - org.glite.lb.server/src/db_calls.h | 16 - org.glite.lb.server/src/db_store.c | 307 - org.glite.lb.server/src/db_supp.c | 131 - org.glite.lb.server/src/db_supp.h | 27 - org.glite.lb.server/src/dump.c | 198 - org.glite.lb.server/src/get_events.c.T | 182 - org.glite.lb.server/src/get_events.h | 38 - org.glite.lb.server/src/il_lbproxy.c | 82 - org.glite.lb.server/src/il_lbproxy.h | 19 - org.glite.lb.server/src/il_notification.c | 218 - org.glite.lb.server/src/il_notification.h | 104 - org.glite.lb.server/src/index.c.T | 435 - org.glite.lb.server/src/index_lex.l | 47 - org.glite.lb.server/src/index_parse.y | 242 - org.glite.lb.server/src/jobstat.c | 1319 -- org.glite.lb.server/src/jobstat.h | 46 - org.glite.lb.server/src/jobstat_supp.c | 728 - org.glite.lb.server/src/lb_authz.c | 941 -- org.glite.lb.server/src/lb_html.c | 267 - org.glite.lb.server/src/lb_html.h | 18 - org.glite.lb.server/src/lb_http.c | 63 - org.glite.lb.server/src/lb_http.h | 11 - org.glite.lb.server/src/lb_proto.c | 1247 -- org.glite.lb.server/src/lb_proto.h | 39 - org.glite.lb.server/src/lb_rss.c | 77 - org.glite.lb.server/src/lb_rss.h | 9 - org.glite.lb.server/src/lb_text.c | 243 - org.glite.lb.server/src/lb_text.h | 16 - org.glite.lb.server/src/lb_xml_parse.c.T | 2079 --- org.glite.lb.server/src/lb_xml_parse.h | 45 - org.glite.lb.server/src/lb_xml_parse_V21.c.T | 1244 -- org.glite.lb.server/src/lb_xml_parse_V21.h | 23 - org.glite.lb.server/src/lcas_lb.c | 167 - org.glite.lb.server/src/load.c | 223 - org.glite.lb.server/src/mon-db.c | 111 - org.glite.lb.server/src/notif_match.c | 232 - org.glite.lb.server/src/notification.c | 842 -- org.glite.lb.server/src/openserver.c | 98 - org.glite.lb.server/src/openserver.h | 6 - org.glite.lb.server/src/perftest_proxy.sh | 128 - org.glite.lb.server/src/pretty_print_wrapper.cpp | 24 - org.glite.lb.server/src/purge.h | 69 - org.glite.lb.server/src/query.c | 1757 --- org.glite.lb.server/src/request.c | 81 - org.glite.lb.server/src/seqcode.c | 65 - org.glite.lb.server/src/server_state.c | 56 - org.glite.lb.server/src/server_state.h | 12 - org.glite.lb.server/src/srv_purge.c | 900 -- org.glite.lb.server/src/stats.c | 453 - org.glite.lb.server/src/stats.h | 77 - org.glite.lb.server/src/store.c.T | 795 - org.glite.lb.server/src/stored_master.c | 168 - org.glite.lb.server/src/userjobs.c | 108 - org.glite.lb.server/src/write2rgma.c | 281 - org.glite.lb.server/src/ws_fault.c | 91 - org.glite.lb.server/src/ws_fault.h | 11 - org.glite.lb.server/src/ws_query.c | 449 - org.glite.lb.server/src/ws_typemap.dat | 3 - org.glite.lb.server/src/ws_typemap.h | 74 - org.glite.lb.server/src/ws_typeref.c.T | 1198 -- org.glite.lb.server/src/ws_typeref.h | 94 - org.glite.lb.server/test/oneJob.qry | 32 - org.glite.lb.server/test/test_query_events.cpp | 187 - org.glite.lb.server/test/test_soap_conv.cpp | 321 - org.glite.lb.server/test/test_trans.sh | 190 - org.glite.lb.server/test/test_xml.cpp.T | 218 - org.glite.lb.state-machine/LICENSE | 69 - org.glite.lb.state-machine/Makefile | 127 - org.glite.lb.state-machine/configure | 698 - org.glite.lb.state-machine/interface/intjobstat.h | 106 - .../interface/lb-job-attrs.xsd | 139 - .../interface/lb-job-attrs2.xsd.T | 141 - .../interface/lb-job-record.xsd | 95 - .../interface/process_event.h | 7 - org.glite.lb.state-machine/interface/seqcode_aux.h | 22 - org.glite.lb.state-machine/project/ChangeLog | 31 - .../project/package.description | 1 - org.glite.lb.state-machine/project/package.summary | 1 - .../project/version.properties | 3 - org.glite.lb.state-machine/src/job_attrs.xsl | 41 - org.glite.lb.state-machine/src/job_attrs2.xsl | 43 - org.glite.lb.state-machine/src/jpis_config.xsl | 72 - org.glite.lb.state-machine/src/lb_plugin.c | 1896 --- org.glite.lb.state-machine/src/process_event.c | 1063 -- .../src/process_event_condor.c | 207 - org.glite.lb.state-machine/src/process_event_pbs.c | 237 - org.glite.lb.state-machine/src/seqcode_aux.c | 334 - org.glite.lb.utils/.cvsignore | 2 - org.glite.lb.utils/LICENSE | 69 - org.glite.lb.utils/Makefile | 123 - org.glite.lb.utils/build.xml | 115 - org.glite.lb.utils/configure | 698 - org.glite.lb.utils/doc/README.LB-monitoring | 34 - org.glite.lb.utils/doc/README.LB-statistics | 41 - org.glite.lb.utils/doc/glite-lb-mon.1 | 47 - org.glite.lb.utils/doc/glite-lb-purge.8 | 103 - org.glite.lb.utils/examples/glite-lb-index.conf | 11 - .../examples/glite-lb-statistics-gsi.sh | 39 - .../examples/glite-lb-statistics-rsync.sh | 31 - .../examples/glite-lb-statistics-sftp.sh | 42 - org.glite.lb.utils/examples/glite-lb-statistics.sh | 50 - org.glite.lb.utils/project/ChangeLog | 21 - org.glite.lb.utils/project/build.number | 2 - org.glite.lb.utils/project/build.properties | 0 .../project/configure.properties.xml | 58 - org.glite.lb.utils/project/package.description | 1 - org.glite.lb.utils/project/package.summary | 1 - org.glite.lb.utils/project/properties.xml | 60 - org.glite.lb.utils/project/tar_exclude | 10 - org.glite.lb.utils/project/version.properties | 3 - org.glite.lb.utils/src/dump.c | 224 - org.glite.lb.utils/src/dump_exporter.c | 390 - org.glite.lb.utils/src/glite-lb-bkpurge-offline.sh | 174 - org.glite.lb.utils/src/load.c | 204 - org.glite.lb.utils/src/mon.c | 171 - org.glite.lb.utils/src/process_attrs.c | 220 - org.glite.lb.utils/src/process_attrs2.c.T | 85 - org.glite.lb.utils/src/purge.c | 447 - org.glite.lb.utils/src/state_history.c | 78 - org.glite.lb.utils/src/statistics.c | 191 - org.glite.lb/.cvsignore | 2 - org.glite.lb/LICENSE | 69 - org.glite.lb/build.xml | 599 - org.glite.lb/configure | 698 - org.glite.lb/deployment/README | 2 - org.glite.lb/deployment/deploy_all.diff | 551 - org.glite.lb/deployment/deploy_jp.diff | 222 - org.glite.lb/deployment/deploy_lb.diff | 281 - org.glite.lb/doc/README.lb4vdt | 16 - org.glite.lb/doc/perf_clear_proxy | 1 - org.glite.lb/doc/perf_purge | 1 - org.glite.lb/doc/perf_reg_jobs | 1 - org.glite.lb/doc/perf_results/il_sci_09062006.txt | 63 - .../doc/perf_results/il_sci_09062006_01.txt | 129 - org.glite.lb/doc/perf_results/il_sci_12062006.txt | 65 - .../doc/perf_results/ll_michal_21062006.txt | 20 - .../perf_results/proxy2serv_umbar2sci_22062006.txt | 20 - .../perf_results/proxy2serv_umbar2sci_23062006.txt | 25 - .../doc/perf_results/proxy_sci_09062006.txt | 21 - org.glite.lb/doc/perf_run_interlogd | 1 - org.glite.lb/doc/perf_run_proxy | 1 - org.glite.lb/doc/perf_run_server | 1 - org.glite.lb/doc/perf_run_test | 1 - org.glite.lb/etics-tag-consistency.pl | 120 - org.glite.lb/etics-tag-with-subsystems.pl | 296 - org.glite.lb/etics-tag.pl | 304 - org.glite.lb/lb4vdt/LB_install.sh | 113 - org.glite.lb/lb4vdt/Makefile.inc | 77 - .../lb4vdt/scripts/org.gridsite.core.build | 11 - org.glite.lb/project/build.number | 2 - org.glite.lb/project/build.properties | 2 - org.glite.lb/project/glite.lb.csf.xml | 398 - org.glite.lb/project/package.description | 1 - org.glite.lb/project/package.summary | 1 - org.glite.lb/project/properties.xml | 55 - org.glite.lb/project/run-workspace | 10 - org.glite.lb/project/taskdefs.xml | 32 - org.glite.lb/project/version.properties | 3 - org.glite.lbjp-common.db/.cvsignore | 3 - org.glite.lbjp-common.db/LICENSE | 69 - org.glite.lbjp-common.db/Makefile | 143 - org.glite.lbjp-common.db/configure | 698 - org.glite.lbjp-common.db/doc/C.dox | 16 - org.glite.lbjp-common.db/examples/db_expire.c | 147 - org.glite.lbjp-common.db/examples/db_test.c | 247 - org.glite.lbjp-common.db/interface/db.h | 371 - org.glite.lbjp-common.db/project/ChangeLog | 33 - org.glite.lbjp-common.db/project/get_soname.sh | 21 - .../project/version.properties | 3 - org.glite.lbjp-common.db/src/db.c | 1239 -- org.glite.lbjp-common.jp-interface/Makefile | 90 - org.glite.lbjp-common.jp-interface/build.xml | 100 - org.glite.lbjp-common.jp-interface/configure | 698 - .../interface/attr.h | 32 - .../interface/backend.h | 114 - .../interface/builtin_plugins.h | 8 - .../interface/context.h | 26 - .../interface/file_plugin.h | 86 - .../interface/indexdb.h | 59 - .../interface/known_attr.h | 41 - .../interface/type_plugin.h | 74 - .../interface/types.h | 66 - .../project/ChangeLog | 20 - .../project/version.properties | 3 - org.glite.lbjp-common.jp-interface/src/attr.c | 291 - org.glite.lbjp-common.jp-interface/src/context.c | 145 - org.glite.lbjp-common.jp-interface/src/indexdb.c | 71 - org.glite.lbjp-common.jp-interface/src/utils.c | 63 - .../test/type_test.cpp | 200 - org.glite.lbjp-common.maildir/.cvsignore | 1 - org.glite.lbjp-common.maildir/Makefile | 87 - org.glite.lbjp-common.maildir/configure | 698 - org.glite.lbjp-common.maildir/interface/maildir.h | 24 - org.glite.lbjp-common.maildir/project/ChangeLog | 11 - .../project/version.properties | 3 - org.glite.lbjp-common.maildir/src/maildir.c | 399 - org.glite.lbjp-common.server-bones/.cvsignore | 1 - org.glite.lbjp-common.server-bones/Makefile | 77 - org.glite.lbjp-common.server-bones/configure | 698 - .../examples/cnt_example.c | 179 - .../examples/srv_example.c | 224 - .../interface/srvbones.h | 99 - .../project/ChangeLog | 11 - .../project/version.properties | 3 - org.glite.lbjp-common.server-bones/src/srvbones.c | 753 - org.glite.lbjp-common.trio/.cvsignore | 1 - org.glite.lbjp-common.trio/LICENSE | 69 - org.glite.lbjp-common.trio/Makefile | 112 - org.glite.lbjp-common.trio/configure | 698 - org.glite.lbjp-common.trio/interface/escape.h | 59 - org.glite.lbjp-common.trio/interface/trio.h | 187 - org.glite.lbjp-common.trio/project/ChangeLog | 14 - .../project/version.properties | 3 - org.glite.lbjp-common.trio/src/escape.c | 226 - org.glite.lbjp-common.trio/src/strio.c | 581 - org.glite.lbjp-common.trio/src/strio.h | 227 - org.glite.lbjp-common.trio/src/trio.c | 5706 ------- org.glite.lbjp-common.trio/src/triop.h | 138 - org.glite.lbjp-common.trio/test/trio_test.cpp | 85 - org.glite.lbjp-common/project/version.properties | 3 - org.glite.security.gsoap-plugin/LICENSE | 69 - org.glite.security.gsoap-plugin/Makefile | 284 - org.glite.security.gsoap-plugin/build.xml | 128 - org.glite.security.gsoap-plugin/configure | 698 - org.glite.security.gsoap-plugin/examples/calc.h.S | 13 - .../examples/wscalc_clt_ex.c | 52 - .../examples/wscalc_srv_ex.c | 111 - .../examples/wscalc_srv_ex2.c | 138 - .../interface/glite_gscompat.h | 86 - .../interface/glite_gsplugin-int.h | 28 - .../interface/glite_gsplugin.h | 34 - org.glite.security.gsoap-plugin/project/ChangeLog | 26 - .../project/build.number | 1 - .../project/build.properties | 0 .../project/configure.properties.xml | 54 - .../project/libtoolhack/gcc | 1 - .../project/package.description | 1 - .../project/package.summary | 1 - .../project/properties.xml | 55 - .../project/tar_exclude | 10 - .../project/version.properties | 3 - .../src/glite_gsplugin.c | 567 - .../src/stdsoap2_2.6.2.c | 11020 -------------- .../src/stdsoap2_2.6.2.h | 1647 -- .../src/stdsoap2_2.7.0.c | 11692 --------------- .../src/stdsoap2_2.7.0.h | 1764 --- .../src/stdsoap2_2.7.0f.c | 12026 --------------- .../src/stdsoap2_2.7.0f.h | 1885 --- .../src/stdsoap2_2.7.10.c | 14890 ------------------- .../src/stdsoap2_2.7.10.h | 2281 --- .../src/stdsoap2_2.7.6b.c | 13101 ---------------- .../src/stdsoap2_2.7.6b.h | 2053 --- .../src/stdsoap2_2.7.6d.c | 13362 ----------------- .../src/stdsoap2_2.7.6d.h | 2075 --- .../src/stdsoap2_2.7.9b.c | 14172 ------------------ .../src/stdsoap2_2.7.9b.h | 2166 --- .../src/stdsoap2_2.7.9d.c | 14414 ------------------ .../src/stdsoap2_2.7.9d.h | 2184 --- .../test/test_gsplugin_cxx.cpp | 46 - org.glite.security.gss/LICENSE | 69 - org.glite.security.gss/Makefile | 140 - org.glite.security.gss/configure | 698 - org.glite.security.gss/interface/glite_gss.h | 163 - org.glite.security.gss/project/ChangeLog | 17 - org.glite.security.gss/project/package.description | 1 - org.glite.security.gss/project/package.summary | 1 - org.glite.security.gss/project/version.properties | 3 - org.glite.security.gss/src/glite_gss.c | 1482 -- org.glite.security.gss/test/test_gss.cpp | 199 - 540 files changed, 266152 deletions(-) delete mode 100644 org.glite.jobid.api-c/Makefile delete mode 100755 org.glite.jobid.api-c/configure delete mode 100755 org.glite.jobid.api-c/interface/cjobid.h delete mode 100755 org.glite.jobid.api-c/interface/strmd5.h delete mode 100644 org.glite.jobid.api-c/project/ChangeLog delete mode 100644 org.glite.jobid.api-c/project/version.properties delete mode 100644 org.glite.jobid.api-c/src/cjobid.c delete mode 100644 org.glite.jobid.api-c/src/md32_common.h delete mode 100644 org.glite.jobid.api-c/src/md5.h delete mode 100644 org.glite.jobid.api-c/src/md5_dgst.c delete mode 100644 org.glite.jobid.api-c/src/md5_locl.h delete mode 100755 org.glite.jobid.api-c/src/strmd5.c delete mode 100644 org.glite.jobid.api-c/test/base64_test.cpp delete mode 100644 org.glite.jobid/project/version.properties delete mode 100644 org.glite.lb.client/.cvsignore delete mode 100644 org.glite.lb.client/LICENSE delete mode 100644 org.glite.lb.client/Makefile delete mode 100755 org.glite.lb.client/build.xml delete mode 100755 org.glite.lb.client/configure delete mode 100644 org.glite.lb.client/doc/C.dox delete mode 100644 org.glite.lb.client/doc/CPP.dox delete mode 100644 org.glite.lb.client/doc/README-notify delete mode 100755 org.glite.lb.client/doc/api/Makefile delete mode 100644 org.glite.lb.client/doc/api/api.tex delete mode 100644 org.glite.lb.client/doc/api/fig/logging-arch.eps delete mode 100644 org.glite.lb.client/doc/api/fig/logging-arch.pdf delete mode 100644 org.glite.lb.client/doc/glite-lb-dump.8 delete mode 100644 org.glite.lb.client/doc/glite-lb-load.8 delete mode 100644 org.glite.lb.client/doc/glite-lb-logevent.1 delete mode 100644 org.glite.lb.client/doc/glite-lb-notify.1 delete mode 100644 org.glite.lb.client/examples/Makefile delete mode 100644 org.glite.lb.client/examples/README.examples delete mode 100644 org.glite.lb.client/examples/abort_job.c delete mode 100644 org.glite.lb.client/examples/aborted.l delete mode 100644 org.glite.lb.client/examples/cancelled.l delete mode 100644 org.glite.lb.client/examples/change_acl.c delete mode 100644 org.glite.lb.client/examples/chkpt.l delete mode 100644 org.glite.lb.client/examples/cleared.l delete mode 100644 org.glite.lb.client/examples/dagids.c delete mode 100644 org.glite.lb.client/examples/done.l delete mode 100644 org.glite.lb.client/examples/done_dag.l delete mode 100644 org.glite.lb.client/examples/done_subjob.l delete mode 100644 org.glite.lb.client/examples/failed_dag.l delete mode 100644 org.glite.lb.client/examples/failed_subjob.l delete mode 100644 org.glite.lb.client/examples/feed_shark.c delete mode 100644 org.glite.lb.client/examples/flood_proxy.c delete mode 100755 org.glite.lb.client/examples/gen_begin delete mode 100755 org.glite.lb.client/examples/gen_sample_job delete mode 100755 org.glite.lb.client/examples/job-status.pl delete mode 100644 org.glite.lb.client/examples/job_log.c delete mode 100644 org.glite.lb.client/examples/job_reg.c delete mode 100644 org.glite.lb.client/examples/job_status.c delete mode 100644 org.glite.lb.client/examples/log_usertag_proxy.c delete mode 100644 org.glite.lb.client/examples/multiple_user_jobs.c delete mode 100755 org.glite.lb.client/examples/notify.pl delete mode 100644 org.glite.lb.client/examples/parse_eventsfile.c delete mode 100644 org.glite.lb.client/examples/purge_test delete mode 100644 org.glite.lb.client/examples/query_ext.c delete mode 100644 org.glite.lb.client/examples/query_seq_code.c delete mode 100644 org.glite.lb.client/examples/ready.l delete mode 100644 org.glite.lb.client/examples/ready_dag.l delete mode 100644 org.glite.lb.client/examples/ready_subjob.l delete mode 100644 org.glite.lb.client/examples/resubmission.l delete mode 100644 org.glite.lb.client/examples/resubmitted.l delete mode 100644 org.glite.lb.client/examples/running.l delete mode 100644 org.glite.lb.client/examples/running_dag.l delete mode 100644 org.glite.lb.client/examples/running_subjob.l delete mode 100644 org.glite.lb.client/examples/scheduled.l delete mode 100644 org.glite.lb.client/examples/scheduled_dag.l delete mode 100644 org.glite.lb.client/examples/scheduled_subjob.l delete mode 100644 org.glite.lb.client/examples/shallow_and_full_resub.l delete mode 100644 org.glite.lb.client/examples/shallow_resub_complex.l delete mode 100644 org.glite.lb.client/examples/shallow_resub_simple.l delete mode 100644 org.glite.lb.client/examples/shallow_resub_simple2.l delete mode 100644 org.glite.lb.client/examples/stats.c delete mode 100644 org.glite.lb.client/examples/stress_context.c delete mode 100644 org.glite.lb.client/examples/stresslog.c delete mode 100644 org.glite.lb.client/examples/submitted.l delete mode 100644 org.glite.lb.client/examples/submitted_dag.l delete mode 100644 org.glite.lb.client/examples/submitted_subjob.l delete mode 100644 org.glite.lb.client/examples/test_changed_jdl.c delete mode 100755 org.glite.lb.client/examples/test_notif_rotate.pl delete mode 100644 org.glite.lb.client/examples/ulmfields.pl delete mode 100755 org.glite.lb.client/examples/user-jobs.pl delete mode 100644 org.glite.lb.client/examples/user_jobs.c delete mode 100644 org.glite.lb.client/examples/user_jobs_threaded.c delete mode 100644 org.glite.lb.client/examples/waiting.l delete mode 100644 org.glite.lb.client/examples/waiting_dag.l delete mode 100644 org.glite.lb.client/examples/waiting_subjob.l delete mode 100644 org.glite.lb.client/examples/webservices/java-trustmanager/Makefile delete mode 100644 org.glite.lb.client/examples/webservices/java-trustmanager/README delete mode 100644 org.glite.lb.client/examples/webservices/java-trustmanager/src/LBClientTM.java delete mode 100644 org.glite.lb.client/examples/webservices/java/Makefile delete mode 100644 org.glite.lb.client/examples/webservices/java/README delete mode 100644 org.glite.lb.client/examples/webservices/java/src/ExampleSSLSocketFactory.java delete mode 100644 org.glite.lb.client/examples/webservices/java/src/LBClientExample.java delete mode 100644 org.glite.lb.client/examples/webservices/java/src/MyX509KeyManager.java delete mode 100644 org.glite.lb.client/examples/webservices/java/src/MyX509TrustManager.java delete mode 100644 org.glite.lb.client/examples/webservices/java/src/log4j.properties delete mode 100644 org.glite.lb.client/interface/Event.h.T delete mode 100644 org.glite.lb.client/interface/Job.h delete mode 100644 org.glite.lb.client/interface/JobStatus.h.T delete mode 100644 org.glite.lb.client/interface/Notification.h delete mode 100644 org.glite.lb.client/interface/ServerConnection.h delete mode 100644 org.glite.lb.client/interface/connection.h delete mode 100644 org.glite.lb.client/interface/consumer.h delete mode 100644 org.glite.lb.client/interface/notification.h delete mode 100644 org.glite.lb.client/interface/prod_proto.h delete mode 100644 org.glite.lb.client/interface/producer.h.T delete mode 100644 org.glite.lb.client/interface/stat_fields.h delete mode 100644 org.glite.lb.client/interface/statistics.h delete mode 100755 org.glite.lb.client/m4/glite_lb_client.m4 delete mode 100644 org.glite.lb.client/project/.cvsignore delete mode 100644 org.glite.lb.client/project/ChangeLog delete mode 100644 org.glite.lb.client/project/build.number delete mode 100644 org.glite.lb.client/project/build.properties delete mode 100644 org.glite.lb.client/project/configure.properties.xml delete mode 100644 org.glite.lb.client/project/package.description delete mode 100644 org.glite.lb.client/project/package.summary delete mode 100755 org.glite.lb.client/project/properties.xml delete mode 100644 org.glite.lb.client/project/tar_exclude delete mode 100644 org.glite.lb.client/project/version.properties delete mode 100644 org.glite.lb.client/src/Event.cpp.T delete mode 100644 org.glite.lb.client/src/EventAttrNames.pl delete mode 100644 org.glite.lb.client/src/Job.cpp delete mode 100644 org.glite.lb.client/src/JobStatus.cpp.T delete mode 100644 org.glite.lb.client/src/Notification.cpp delete mode 100644 org.glite.lb.client/src/ServerConnection.cpp delete mode 100644 org.glite.lb.client/src/StatusAttrNames.pl delete mode 100644 org.glite.lb.client/src/args.c.T delete mode 100644 org.glite.lb.client/src/args.h delete mode 100644 org.glite.lb.client/src/connection.c delete mode 100644 org.glite.lb.client/src/consumer.c delete mode 100644 org.glite.lb.client/src/export.sh delete mode 100644 org.glite.lb.client/src/logevent.c.T delete mode 100644 org.glite.lb.client/src/notification.c delete mode 100644 org.glite.lb.client/src/notify.c delete mode 100644 org.glite.lb.client/src/perftest_jobreg.c delete mode 100755 org.glite.lb.client/src/perftest_jobreg.sh delete mode 100644 org.glite.lb.client/src/perftest_logjobs.c delete mode 100644 org.glite.lb.client/src/perftest_query.sh delete mode 100644 org.glite.lb.client/src/prod_proto.c delete mode 100644 org.glite.lb.client/src/producer.c delete mode 100644 org.glite.lb.client/src/stat_fields.cpp delete mode 100644 org.glite.lb.client/src/statistics.c delete mode 100644 org.glite.lb.client/src/uiwrap.T delete mode 100644 org.glite.lb.client/src/uiwrap.c.T delete mode 100644 org.glite.lb.client/test/PLOT delete mode 100755 org.glite.lb.client/test/TEST delete mode 100644 org.glite.lb.client/test/prod_proto_test.c delete mode 100644 org.glite.lb.client/test/producer_test.cpp delete mode 100644 org.glite.lb.logger/.cvsignore delete mode 100644 org.glite.lb.logger/LICENSE delete mode 100644 org.glite.lb.logger/Makefile delete mode 100755 org.glite.lb.logger/build.xml delete mode 100644 org.glite.lb.logger/config/glite-lb-logger.config.xml delete mode 100644 org.glite.lb.logger/config/glite-lb-logger.default-properties delete mode 100755 org.glite.lb.logger/config/startup delete mode 100755 org.glite.lb.logger/configure delete mode 100644 org.glite.lb.logger/doc/glite-lb-interlogd.8 delete mode 100644 org.glite.lb.logger/doc/glite-lb-logd.8 delete mode 100644 org.glite.lb.logger/project/ChangeLog delete mode 100644 org.glite.lb.logger/project/build.number delete mode 100644 org.glite.lb.logger/project/build.properties delete mode 100644 org.glite.lb.logger/project/configure.properties.xml delete mode 100644 org.glite.lb.logger/project/package.description delete mode 100644 org.glite.lb.logger/project/package.summary delete mode 100755 org.glite.lb.logger/project/properties.xml delete mode 100644 org.glite.lb.logger/project/tar_exclude delete mode 100644 org.glite.lb.logger/project/version.properties delete mode 100644 org.glite.lb.logger/src-nt/Connection.H delete mode 100644 org.glite.lb.logger/src-nt/Connection.cpp delete mode 100644 org.glite.lb.logger/src-nt/EventManager.H delete mode 100644 org.glite.lb.logger/src-nt/EventManager.cpp delete mode 100644 org.glite.lb.logger/src-nt/Exception.H delete mode 100644 org.glite.lb.logger/src-nt/HTTPTransport.H delete mode 100644 org.glite.lb.logger/src-nt/HTTPTransport.cpp delete mode 100644 org.glite.lb.logger/src-nt/InputChannel.H delete mode 100644 org.glite.lb.logger/src-nt/InputChannel.cpp delete mode 100644 org.glite.lb.logger/src-nt/Makefile delete mode 100644 org.glite.lb.logger/src-nt/Message.H delete mode 100644 org.glite.lb.logger/src-nt/MessageStore.H delete mode 100644 org.glite.lb.logger/src-nt/MessageStore.cpp delete mode 100644 org.glite.lb.logger/src-nt/PlainConnection.H delete mode 100644 org.glite.lb.logger/src-nt/PlainConnection.cpp delete mode 100644 org.glite.lb.logger/src-nt/PluginManager.H delete mode 100644 org.glite.lb.logger/src-nt/PluginManager.cpp delete mode 100644 org.glite.lb.logger/src-nt/Properties.H delete mode 100644 org.glite.lb.logger/src-nt/Singleton.H delete mode 100644 org.glite.lb.logger/src-nt/SocketInput.H delete mode 100644 org.glite.lb.logger/src-nt/SocketInput.cpp delete mode 100644 org.glite.lb.logger/src-nt/ThreadPool.H delete mode 100644 org.glite.lb.logger/src-nt/ThreadPool.cpp delete mode 100644 org.glite.lb.logger/src-nt/Transport.H delete mode 100644 org.glite.lb.logger/src-nt/Transport.cpp delete mode 100644 org.glite.lb.logger/src-nt/main.cpp delete mode 100644 org.glite.lb.logger/src-nt/test/EventManagerTest.cpp delete mode 100644 org.glite.lb.logger/src-nt/test/PluginManagerTest.cpp delete mode 100644 org.glite.lb.logger/src-nt/test/SingletonTest.cpp delete mode 100644 org.glite.lb.logger/src-nt/test/ThreadPoolTest.cpp delete mode 100644 org.glite.lb.logger/src-nt/test/test_main.cpp delete mode 100644 org.glite.lb.logger/src/event_queue.c delete mode 100644 org.glite.lb.logger/src/event_store.c delete mode 100644 org.glite.lb.logger/src/event_store_http.c delete mode 100644 org.glite.lb.logger/src/http.c delete mode 100644 org.glite.lb.logger/src/il_error.c delete mode 100644 org.glite.lb.logger/src/il_error.h delete mode 100644 org.glite.lb.logger/src/il_master.c delete mode 100644 org.glite.lb.logger/src/input_queue_socket.c delete mode 100644 org.glite.lb.logger/src/input_queue_socket_http.c delete mode 100644 org.glite.lb.logger/src/interlogd.c delete mode 100644 org.glite.lb.logger/src/interlogd.h delete mode 100644 org.glite.lb.logger/src/logd.c delete mode 100644 org.glite.lb.logger/src/logd_proto.c delete mode 100644 org.glite.lb.logger/src/logd_proto.h delete mode 100644 org.glite.lb.logger/src/perftest_il.sh delete mode 100644 org.glite.lb.logger/src/perftest_ll.sh delete mode 100644 org.glite.lb.logger/src/queue_mgr.c delete mode 100644 org.glite.lb.logger/src/queue_mgr_http.c delete mode 100644 org.glite.lb.logger/src/queue_thread.c delete mode 100644 org.glite.lb.logger/src/recover.c delete mode 100644 org.glite.lb.logger/src/send_event.c delete mode 100644 org.glite.lb.logger/src/send_event_http.c delete mode 100644 org.glite.lb.logger/src/server_msg.c delete mode 100644 org.glite.lb.logger/src/server_msg_http.c delete mode 100644 org.glite.lb.logger/test/IlTestBase.cpp delete mode 100644 org.glite.lb.logger/test/IlTestBase.h delete mode 100644 org.glite.lb.logger/test/event_queueTest.cpp delete mode 100644 org.glite.lb.logger/test/event_storeTest.cpp delete mode 100644 org.glite.lb.logger/test/il_test.cpp delete mode 100644 org.glite.lb.logger/test/input_queue_socketTest.cpp delete mode 100644 org.glite.lb.logger/test/ll_test.cpp delete mode 100644 org.glite.lb.logger/test/logd_proto_test.c delete mode 100644 org.glite.lb.logger/test/server_msgTest.cpp delete mode 100644 org.glite.lb.server/.cvsignore delete mode 100644 org.glite.lb.server/LICENSE delete mode 100644 org.glite.lb.server/Makefile delete mode 100755 org.glite.lb.server/build.xml delete mode 100644 org.glite.lb.server/config/glite-lb-dbsetup.sql delete mode 100644 org.glite.lb.server/config/glite-lb-index.conf.template delete mode 100644 org.glite.lb.server/config/glite-lb-migrate_db2version20 delete mode 100755 org.glite.lb.server/config/startup delete mode 100755 org.glite.lb.server/configure delete mode 100644 org.glite.lb.server/doc/glite-lb-bkindex.8 delete mode 100644 org.glite.lb.server/doc/glite-lb-bkserverd.8 delete mode 100644 org.glite.lb.server/doc/glite-lb-mon-db.1 delete mode 100644 org.glite.lb.server/examples/stdsoap2_2.6.0.c delete mode 100644 org.glite.lb.server/examples/stdsoap2_2.6.2.c delete mode 100644 org.glite.lb.server/examples/stdsoap2_2.7.0c.c delete mode 100644 org.glite.lb.server/examples/stdsoap2_2.7.0d.c delete mode 100644 org.glite.lb.server/interface/index.h delete mode 100644 org.glite.lb.server/interface/lb_authz.h delete mode 100644 org.glite.lb.server/interface/pretty_print_wrapper.h delete mode 100644 org.glite.lb.server/interface/query.h delete mode 100644 org.glite.lb.server/interface/srv_perf.h delete mode 100644 org.glite.lb.server/interface/store.h delete mode 100644 org.glite.lb.server/project/.cvsignore delete mode 100644 org.glite.lb.server/project/ChangeLog delete mode 100644 org.glite.lb.server/project/build.number delete mode 100644 org.glite.lb.server/project/build.properties delete mode 100644 org.glite.lb.server/project/configure.properties.xml delete mode 100644 org.glite.lb.server/project/package.description delete mode 100644 org.glite.lb.server/project/package.summary delete mode 100755 org.glite.lb.server/project/properties.xml delete mode 100644 org.glite.lb.server/project/tar_exclude delete mode 100644 org.glite.lb.server/project/version.properties delete mode 100644 org.glite.lb.server/src/bkindex.c delete mode 100644 org.glite.lb.server/src/bkserverd.c delete mode 100644 org.glite.lb.server/src/cond_dump.c delete mode 100644 org.glite.lb.server/src/cond_dump.h delete mode 100644 org.glite.lb.server/src/db_calls.c delete mode 100644 org.glite.lb.server/src/db_calls.h delete mode 100644 org.glite.lb.server/src/db_store.c delete mode 100644 org.glite.lb.server/src/db_supp.c delete mode 100644 org.glite.lb.server/src/db_supp.h delete mode 100644 org.glite.lb.server/src/dump.c delete mode 100644 org.glite.lb.server/src/get_events.c.T delete mode 100644 org.glite.lb.server/src/get_events.h delete mode 100644 org.glite.lb.server/src/il_lbproxy.c delete mode 100644 org.glite.lb.server/src/il_lbproxy.h delete mode 100644 org.glite.lb.server/src/il_notification.c delete mode 100644 org.glite.lb.server/src/il_notification.h delete mode 100644 org.glite.lb.server/src/index.c.T delete mode 100644 org.glite.lb.server/src/index_lex.l delete mode 100644 org.glite.lb.server/src/index_parse.y delete mode 100644 org.glite.lb.server/src/jobstat.c delete mode 100644 org.glite.lb.server/src/jobstat.h delete mode 100644 org.glite.lb.server/src/jobstat_supp.c delete mode 100644 org.glite.lb.server/src/lb_authz.c delete mode 100644 org.glite.lb.server/src/lb_html.c delete mode 100644 org.glite.lb.server/src/lb_html.h delete mode 100644 org.glite.lb.server/src/lb_http.c delete mode 100644 org.glite.lb.server/src/lb_http.h delete mode 100644 org.glite.lb.server/src/lb_proto.c delete mode 100644 org.glite.lb.server/src/lb_proto.h delete mode 100644 org.glite.lb.server/src/lb_rss.c delete mode 100644 org.glite.lb.server/src/lb_rss.h delete mode 100644 org.glite.lb.server/src/lb_text.c delete mode 100644 org.glite.lb.server/src/lb_text.h delete mode 100644 org.glite.lb.server/src/lb_xml_parse.c.T delete mode 100644 org.glite.lb.server/src/lb_xml_parse.h delete mode 100644 org.glite.lb.server/src/lb_xml_parse_V21.c.T delete mode 100644 org.glite.lb.server/src/lb_xml_parse_V21.h delete mode 100644 org.glite.lb.server/src/lcas_lb.c delete mode 100644 org.glite.lb.server/src/load.c delete mode 100644 org.glite.lb.server/src/mon-db.c delete mode 100644 org.glite.lb.server/src/notif_match.c delete mode 100644 org.glite.lb.server/src/notification.c delete mode 100644 org.glite.lb.server/src/openserver.c delete mode 100644 org.glite.lb.server/src/openserver.h delete mode 100755 org.glite.lb.server/src/perftest_proxy.sh delete mode 100644 org.glite.lb.server/src/pretty_print_wrapper.cpp delete mode 100644 org.glite.lb.server/src/purge.h delete mode 100644 org.glite.lb.server/src/query.c delete mode 100644 org.glite.lb.server/src/request.c delete mode 100644 org.glite.lb.server/src/seqcode.c delete mode 100644 org.glite.lb.server/src/server_state.c delete mode 100644 org.glite.lb.server/src/server_state.h delete mode 100644 org.glite.lb.server/src/srv_purge.c delete mode 100644 org.glite.lb.server/src/stats.c delete mode 100644 org.glite.lb.server/src/stats.h delete mode 100644 org.glite.lb.server/src/store.c.T delete mode 100644 org.glite.lb.server/src/stored_master.c delete mode 100644 org.glite.lb.server/src/userjobs.c delete mode 100755 org.glite.lb.server/src/write2rgma.c delete mode 100644 org.glite.lb.server/src/ws_fault.c delete mode 100644 org.glite.lb.server/src/ws_fault.h delete mode 100644 org.glite.lb.server/src/ws_query.c delete mode 100644 org.glite.lb.server/src/ws_typemap.dat delete mode 100644 org.glite.lb.server/src/ws_typemap.h delete mode 100644 org.glite.lb.server/src/ws_typeref.c.T delete mode 100644 org.glite.lb.server/src/ws_typeref.h delete mode 100644 org.glite.lb.server/test/oneJob.qry delete mode 100644 org.glite.lb.server/test/test_query_events.cpp delete mode 100644 org.glite.lb.server/test/test_soap_conv.cpp delete mode 100644 org.glite.lb.server/test/test_trans.sh delete mode 100644 org.glite.lb.server/test/test_xml.cpp.T delete mode 100644 org.glite.lb.state-machine/LICENSE delete mode 100644 org.glite.lb.state-machine/Makefile delete mode 100755 org.glite.lb.state-machine/configure delete mode 100644 org.glite.lb.state-machine/interface/intjobstat.h delete mode 100644 org.glite.lb.state-machine/interface/lb-job-attrs.xsd delete mode 100644 org.glite.lb.state-machine/interface/lb-job-attrs2.xsd.T delete mode 100644 org.glite.lb.state-machine/interface/lb-job-record.xsd delete mode 100644 org.glite.lb.state-machine/interface/process_event.h delete mode 100644 org.glite.lb.state-machine/interface/seqcode_aux.h delete mode 100644 org.glite.lb.state-machine/project/ChangeLog delete mode 100644 org.glite.lb.state-machine/project/package.description delete mode 100644 org.glite.lb.state-machine/project/package.summary delete mode 100644 org.glite.lb.state-machine/project/version.properties delete mode 100644 org.glite.lb.state-machine/src/job_attrs.xsl delete mode 100644 org.glite.lb.state-machine/src/job_attrs2.xsl delete mode 100644 org.glite.lb.state-machine/src/jpis_config.xsl delete mode 100644 org.glite.lb.state-machine/src/lb_plugin.c delete mode 100644 org.glite.lb.state-machine/src/process_event.c delete mode 100644 org.glite.lb.state-machine/src/process_event_condor.c delete mode 100644 org.glite.lb.state-machine/src/process_event_pbs.c delete mode 100644 org.glite.lb.state-machine/src/seqcode_aux.c delete mode 100755 org.glite.lb.utils/.cvsignore delete mode 100755 org.glite.lb.utils/LICENSE delete mode 100644 org.glite.lb.utils/Makefile delete mode 100644 org.glite.lb.utils/build.xml delete mode 100755 org.glite.lb.utils/configure delete mode 100644 org.glite.lb.utils/doc/README.LB-monitoring delete mode 100644 org.glite.lb.utils/doc/README.LB-statistics delete mode 100644 org.glite.lb.utils/doc/glite-lb-mon.1 delete mode 100644 org.glite.lb.utils/doc/glite-lb-purge.8 delete mode 100644 org.glite.lb.utils/examples/glite-lb-index.conf delete mode 100755 org.glite.lb.utils/examples/glite-lb-statistics-gsi.sh delete mode 100755 org.glite.lb.utils/examples/glite-lb-statistics-rsync.sh delete mode 100755 org.glite.lb.utils/examples/glite-lb-statistics-sftp.sh delete mode 100755 org.glite.lb.utils/examples/glite-lb-statistics.sh delete mode 100644 org.glite.lb.utils/project/ChangeLog delete mode 100644 org.glite.lb.utils/project/build.number delete mode 100755 org.glite.lb.utils/project/build.properties delete mode 100644 org.glite.lb.utils/project/configure.properties.xml delete mode 100644 org.glite.lb.utils/project/package.description delete mode 100644 org.glite.lb.utils/project/package.summary delete mode 100644 org.glite.lb.utils/project/properties.xml delete mode 100644 org.glite.lb.utils/project/tar_exclude delete mode 100755 org.glite.lb.utils/project/version.properties delete mode 100644 org.glite.lb.utils/src/dump.c delete mode 100644 org.glite.lb.utils/src/dump_exporter.c delete mode 100644 org.glite.lb.utils/src/glite-lb-bkpurge-offline.sh delete mode 100644 org.glite.lb.utils/src/load.c delete mode 100644 org.glite.lb.utils/src/mon.c delete mode 100644 org.glite.lb.utils/src/process_attrs.c delete mode 100644 org.glite.lb.utils/src/process_attrs2.c.T delete mode 100644 org.glite.lb.utils/src/purge.c delete mode 100644 org.glite.lb.utils/src/state_history.c delete mode 100644 org.glite.lb.utils/src/statistics.c delete mode 100644 org.glite.lb/.cvsignore delete mode 100644 org.glite.lb/LICENSE delete mode 100755 org.glite.lb/build.xml delete mode 100755 org.glite.lb/configure delete mode 100644 org.glite.lb/deployment/README delete mode 100644 org.glite.lb/deployment/deploy_all.diff delete mode 100644 org.glite.lb/deployment/deploy_jp.diff delete mode 100644 org.glite.lb/deployment/deploy_lb.diff delete mode 100644 org.glite.lb/doc/README.lb4vdt delete mode 100644 org.glite.lb/doc/perf_clear_proxy delete mode 100644 org.glite.lb/doc/perf_purge delete mode 100644 org.glite.lb/doc/perf_reg_jobs delete mode 100644 org.glite.lb/doc/perf_results/il_sci_09062006.txt delete mode 100644 org.glite.lb/doc/perf_results/il_sci_09062006_01.txt delete mode 100644 org.glite.lb/doc/perf_results/il_sci_12062006.txt delete mode 100644 org.glite.lb/doc/perf_results/ll_michal_21062006.txt delete mode 100644 org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_22062006.txt delete mode 100644 org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_23062006.txt delete mode 100644 org.glite.lb/doc/perf_results/proxy_sci_09062006.txt delete mode 100644 org.glite.lb/doc/perf_run_interlogd delete mode 100644 org.glite.lb/doc/perf_run_proxy delete mode 100644 org.glite.lb/doc/perf_run_server delete mode 100644 org.glite.lb/doc/perf_run_test delete mode 100755 org.glite.lb/etics-tag-consistency.pl delete mode 100755 org.glite.lb/etics-tag-with-subsystems.pl delete mode 100755 org.glite.lb/etics-tag.pl delete mode 100755 org.glite.lb/lb4vdt/LB_install.sh delete mode 100644 org.glite.lb/lb4vdt/Makefile.inc delete mode 100644 org.glite.lb/lb4vdt/scripts/org.gridsite.core.build delete mode 100644 org.glite.lb/project/build.number delete mode 100644 org.glite.lb/project/build.properties delete mode 100644 org.glite.lb/project/glite.lb.csf.xml delete mode 100644 org.glite.lb/project/package.description delete mode 100644 org.glite.lb/project/package.summary delete mode 100755 org.glite.lb/project/properties.xml delete mode 100644 org.glite.lb/project/run-workspace delete mode 100755 org.glite.lb/project/taskdefs.xml delete mode 100644 org.glite.lb/project/version.properties delete mode 100644 org.glite.lbjp-common.db/.cvsignore delete mode 100644 org.glite.lbjp-common.db/LICENSE delete mode 100644 org.glite.lbjp-common.db/Makefile delete mode 100755 org.glite.lbjp-common.db/configure delete mode 100644 org.glite.lbjp-common.db/doc/C.dox delete mode 100644 org.glite.lbjp-common.db/examples/db_expire.c delete mode 100644 org.glite.lbjp-common.db/examples/db_test.c delete mode 100644 org.glite.lbjp-common.db/interface/db.h delete mode 100644 org.glite.lbjp-common.db/project/ChangeLog delete mode 100755 org.glite.lbjp-common.db/project/get_soname.sh delete mode 100644 org.glite.lbjp-common.db/project/version.properties delete mode 100644 org.glite.lbjp-common.db/src/db.c delete mode 100644 org.glite.lbjp-common.jp-interface/Makefile delete mode 100755 org.glite.lbjp-common.jp-interface/build.xml delete mode 100755 org.glite.lbjp-common.jp-interface/configure delete mode 100644 org.glite.lbjp-common.jp-interface/interface/attr.h delete mode 100644 org.glite.lbjp-common.jp-interface/interface/backend.h delete mode 100644 org.glite.lbjp-common.jp-interface/interface/builtin_plugins.h delete mode 100644 org.glite.lbjp-common.jp-interface/interface/context.h delete mode 100644 org.glite.lbjp-common.jp-interface/interface/file_plugin.h delete mode 100644 org.glite.lbjp-common.jp-interface/interface/indexdb.h delete mode 100644 org.glite.lbjp-common.jp-interface/interface/known_attr.h delete mode 100644 org.glite.lbjp-common.jp-interface/interface/type_plugin.h delete mode 100644 org.glite.lbjp-common.jp-interface/interface/types.h delete mode 100644 org.glite.lbjp-common.jp-interface/project/ChangeLog delete mode 100644 org.glite.lbjp-common.jp-interface/project/version.properties delete mode 100644 org.glite.lbjp-common.jp-interface/src/attr.c delete mode 100644 org.glite.lbjp-common.jp-interface/src/context.c delete mode 100644 org.glite.lbjp-common.jp-interface/src/indexdb.c delete mode 100644 org.glite.lbjp-common.jp-interface/src/utils.c delete mode 100644 org.glite.lbjp-common.jp-interface/test/type_test.cpp delete mode 100644 org.glite.lbjp-common.maildir/.cvsignore delete mode 100644 org.glite.lbjp-common.maildir/Makefile delete mode 100755 org.glite.lbjp-common.maildir/configure delete mode 100644 org.glite.lbjp-common.maildir/interface/maildir.h delete mode 100644 org.glite.lbjp-common.maildir/project/ChangeLog delete mode 100644 org.glite.lbjp-common.maildir/project/version.properties delete mode 100644 org.glite.lbjp-common.maildir/src/maildir.c delete mode 100644 org.glite.lbjp-common.server-bones/.cvsignore delete mode 100644 org.glite.lbjp-common.server-bones/Makefile delete mode 100755 org.glite.lbjp-common.server-bones/configure delete mode 100644 org.glite.lbjp-common.server-bones/examples/cnt_example.c delete mode 100644 org.glite.lbjp-common.server-bones/examples/srv_example.c delete mode 100644 org.glite.lbjp-common.server-bones/interface/srvbones.h delete mode 100644 org.glite.lbjp-common.server-bones/project/ChangeLog delete mode 100644 org.glite.lbjp-common.server-bones/project/version.properties delete mode 100644 org.glite.lbjp-common.server-bones/src/srvbones.c delete mode 100644 org.glite.lbjp-common.trio/.cvsignore delete mode 100644 org.glite.lbjp-common.trio/LICENSE delete mode 100644 org.glite.lbjp-common.trio/Makefile delete mode 100755 org.glite.lbjp-common.trio/configure delete mode 100644 org.glite.lbjp-common.trio/interface/escape.h delete mode 100644 org.glite.lbjp-common.trio/interface/trio.h delete mode 100644 org.glite.lbjp-common.trio/project/ChangeLog delete mode 100644 org.glite.lbjp-common.trio/project/version.properties delete mode 100644 org.glite.lbjp-common.trio/src/escape.c delete mode 100644 org.glite.lbjp-common.trio/src/strio.c delete mode 100644 org.glite.lbjp-common.trio/src/strio.h delete mode 100644 org.glite.lbjp-common.trio/src/trio.c delete mode 100644 org.glite.lbjp-common.trio/src/triop.h delete mode 100644 org.glite.lbjp-common.trio/test/trio_test.cpp delete mode 100644 org.glite.lbjp-common/project/version.properties delete mode 100644 org.glite.security.gsoap-plugin/LICENSE delete mode 100644 org.glite.security.gsoap-plugin/Makefile delete mode 100755 org.glite.security.gsoap-plugin/build.xml delete mode 100755 org.glite.security.gsoap-plugin/configure delete mode 100644 org.glite.security.gsoap-plugin/examples/calc.h.S delete mode 100644 org.glite.security.gsoap-plugin/examples/wscalc_clt_ex.c delete mode 100644 org.glite.security.gsoap-plugin/examples/wscalc_srv_ex.c delete mode 100644 org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c delete mode 100644 org.glite.security.gsoap-plugin/interface/glite_gscompat.h delete mode 100644 org.glite.security.gsoap-plugin/interface/glite_gsplugin-int.h delete mode 100644 org.glite.security.gsoap-plugin/interface/glite_gsplugin.h delete mode 100644 org.glite.security.gsoap-plugin/project/ChangeLog delete mode 100644 org.glite.security.gsoap-plugin/project/build.number delete mode 100644 org.glite.security.gsoap-plugin/project/build.properties delete mode 100644 org.glite.security.gsoap-plugin/project/configure.properties.xml delete mode 100644 org.glite.security.gsoap-plugin/project/libtoolhack/gcc delete mode 100644 org.glite.security.gsoap-plugin/project/package.description delete mode 100644 org.glite.security.gsoap-plugin/project/package.summary delete mode 100755 org.glite.security.gsoap-plugin/project/properties.xml delete mode 100644 org.glite.security.gsoap-plugin/project/tar_exclude delete mode 100644 org.glite.security.gsoap-plugin/project/version.properties delete mode 100644 org.glite.security.gsoap-plugin/src/glite_gsplugin.c delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.c delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.h delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.c delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.h delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.c delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.h delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.c delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.h delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.c delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.h delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.c delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.h delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.c delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.h delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.c delete mode 100644 org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.h delete mode 100644 org.glite.security.gsoap-plugin/test/test_gsplugin_cxx.cpp delete mode 100644 org.glite.security.gss/LICENSE delete mode 100644 org.glite.security.gss/Makefile delete mode 100755 org.glite.security.gss/configure delete mode 100644 org.glite.security.gss/interface/glite_gss.h delete mode 100644 org.glite.security.gss/project/ChangeLog delete mode 100644 org.glite.security.gss/project/package.description delete mode 100644 org.glite.security.gss/project/package.summary delete mode 100644 org.glite.security.gss/project/version.properties delete mode 100644 org.glite.security.gss/src/glite_gss.c delete mode 100644 org.glite.security.gss/test/test_gss.cpp diff --git a/org.glite.jobid.api-c/Makefile b/org.glite.jobid.api-c/Makefile deleted file mode 100644 index 7813f71..0000000 --- a/org.glite.jobid.api-c/Makefile +++ /dev/null @@ -1,71 +0,0 @@ -# Default values -top_srcdir=.. -stagedir=. -globalprefix=glite -jobidprefix=jobid -package=glite-jobid-api-c -version=0.0.0 - -CC:=gcc -CXX:=g++ - --include Makefile.inc - -VPATH=${top_srcdir}/src:${top_srcdir}/interface:${top_srcdir}/test -CHECK_VERSION:=VERSION=${version} VERSION_AHEAD=0 perl ${top_srcdir}/project/check_version.pl - -DEBUG:=-g -O0 -Wall - -CFLAGS:=${DEBUG} \ - -I${top_srcdir}/interface -I${top_srcdir}/src \ - ${COVERAGE_FLAGS} \ - -D_GNU_SOURCE - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -CXXCOMPILE:=libtool --mode=compile ${CXX} ${CXXFLAGS} -LINK:=libtool --mode=link ${CC} ${LDFLAGS} -LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS} -INSTALL:=libtool --mode=install install - -LIBOBJS:=cjobid.o strmd5.o -HDRS:=cjobid.h strmd5.h - -LIBLOBJS:=${LIBOBJS:.o=.lo} - -LIB:=libglite_jobid.la - -TEST_LIBS:=-L${cppunit_prefix}/${libdir} -lcppunit -ldl -TEST_INC:=-I${cppunit_prefix}/include - -compile all: ${LIB} - -offset=0 -version_info:=-version-info ${shell \ - perl -e '$$,=":"; @F=split /\./,"${version}"; print $$F[0]+$$F[1]+${offset},$$F[2],$$F[1]' } - -${LIB}: ${LIBOBJS} - ${LINK} ${version_info} -o $@ ${LIBLOBJS} -rpath ${PREFIX}/${libdir} - -check: compile base64_test - ./base64_test base64_test.xml - -base64_test: %: %.cpp compile - ${CXX} -c ${CFLAGS} ${TEST_INC} $< - ${LINKXX} -o $@ $@.o ${LIB} ${TEST_LIBS} - -clean: - rm -rvf *.o *.lo .libs lib* *.c *.cpp *.h - rm -rvf log.xml project rpmbuild RPMS tgz - -install: ${LIB} - mkdir -p ${PREFIX}/${libdir} - mkdir -p ${PREFIX}/include/${globalprefix}/${jobidprefix} - ${INSTALL} -m 644 ${LIB} ${PREFIX}/${libdir} - (cd ${top_srcdir}/interface; ${INSTALL} -m 644 ${HDRS} ${PREFIX}/include/${globalprefix}/${jobidprefix}) - - -%.o: %.c - ${COMPILE} -o $@ -c $< - - -.PHONY: default all compile check install clean diff --git a/org.glite.jobid.api-c/configure b/org.glite.jobid.api-c/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.jobid.api-c/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.jobid.api-c/interface/cjobid.h b/org.glite.jobid.api-c/interface/cjobid.h deleted file mode 100755 index 9b38c81..0000000 --- a/org.glite.jobid.api-c/interface/cjobid.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef _GLITE_JOBID_H -#define _GLITE_JOBID_H - -/*! - * \file cjobid.h - * \brief L&B consumer API - */ - -#ident "$Header$" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct _edg_wlc_JobId *glite_jobid_t; -typedef const struct _edg_wlc_JobId *glite_jobid_const_t; -typedef glite_jobid_t edg_wlc_JobId; - -#define edg_wlc_JobIdCreate glite_jobid_create -#define edg_wlc_JobIdRecreate glite_jobid_recreate -#define edg_wlc_JobIdDup glite_jobid_dup -#define edg_wlc_JobIdFree glite_jobid_free -#define edg_wlc_JobIdParse glite_jobid_parse -#define edg_wlc_JobIdUnparse glite_jobid_unparse -#define edg_wlc_JobIdGetServer glite_jobid_getServer -#define edg_wlc_JobIdGetServerParts glite_jobid_getServerParts -#define edg_wlc_JobIdGetUnique glite_jobid_getUnique - -#define GLITE_JOBID_DEFAULT_PORT 9000 /**< Default port where bookkeeping server listens */ -#define GLITE_JOBID_PROTO_PREFIX "https://" /**< JobId protocol prefix */ - - -/* All the pointer functions return malloc'ed objects (or NULL on error) */ - -/** - * Create a Job ID. - * See the lb_draft document for details on its construction and components - * \param bkserver book keeping server hostname - * \param port port for the bk service - * \param jobid new created job id - * \ret al 0 success - * \retval EINVAL invalid bkserver - * \retval ENOMEM if memory allocation fails - */ -int glite_jobid_create(const char * bkserver, int port, glite_jobid_t * jobid); - -/** - * Recreate a Job ID - * \param bkserver bookkeeping server hostname - * \param port port for the bk service - * \param unique string which represent created jobid (if NULL then new - * one is created) - * \param jobid new created job id - * \retval 0 success - * \retval EINVAL invalid bkserver - * \retval ENOMEM if memory allocation fails - */ -int glite_jobid_recreate(const char *bkserver, int port, const char * unique, edg_wlc_JobId * jobid); - -/** - * Create copy of Job ID - * \param in jobid for duplication - * \param jobid duplicated jobid - * \retval 0 for success - * \retval EINVAL invalid jobid - * \retval ENOMEM if memory allocation fails - */ -int glite_jobid_dup(glite_jobid_const_t in, glite_jobid_t * jobid); - -/* - * Free jobid structure - * \param jobid for dealocation - */ -void glite_jobid_free(glite_jobid_t jobid); - -/** - * Parse Job ID string and creates jobid structure - * \param jobidstr string representation of jobid - * \param jobid parsed job id - * \retval 0 for success - * \retval EINVAL jobidstr can't be parsed - * \retval ENOMEM if memory allocation fails - */ -int glite_jobid_parse(const char* jobidstr, glite_jobid_t * jobid); - -/** - * Unparse Job ID (produce the string form of JobId). - * \param jobid to be converted to string - * \return allocated string which represents jobid - */ -char* glite_jobid_unparse(glite_jobid_const_t jobid); - -/** - * Extract bookkeeping server address (address:port) - * \param jobid from which the bkserver address should be extracted - * \retval pointer to allocated string with bkserver address - * \retval NULL if jobid is 0 or memory allocation fails - */ -char* glite_jobid_getServer(glite_jobid_const_t jobid); - -/** - * Extract bookkeeping server address and port - * \param jobid from which the bkserver address should be extracted - * \param srvName pointer where to return server name - * \param srvPort pointer where to return server port - * */ -void glite_jobid_getServerParts(glite_jobid_const_t jobid, char **srvName, unsigned int *srvPort); - -/** - * Extract bookkeeping server address and port - * \param jobid from which the bkserver address should be extracted - * \param srvName pointer where to return server name - * \param srvPort pointer where to return server port - * */ -void glite_jobid_getServerParts_internal(glite_jobid_const_t jobid, char **srvName, unsigned int *srvPort); - -/** - * Extract unique string - * \param jobid - * \retval pointer to allocated unique string representing jobid - * \retval NULL if jobid is 0 or memory allocation fails - */ -char* glite_jobid_getUnique(glite_jobid_const_t jobid); - -/** - * Extract unique string - * \param jobid - * \retval pointer to allocated unique string representing jobid - * \retval NULL if jobid is 0 or memory allocation fails - */ -char* glite_jobid_getUnique_internal(glite_jobid_const_t jobid); - -#ifdef __cplusplus -} -#endif - -#endif /* _GLITE_JOBID_H */ diff --git a/org.glite.jobid.api-c/interface/strmd5.h b/org.glite.jobid.api-c/interface/strmd5.h deleted file mode 100755 index 79a68c7..0000000 --- a/org.glite.jobid.api-c/interface/strmd5.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _GLITE_STRMD5_H -#define _GLITE_STRMD5_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ident "$Header$" - -/* Compute MD5 sum of the first argument. - * The sum is returned in the 16-byte array pointed to by 2nd argument - * (if not NULL) - * - * Return value: ASCII string of the sum, i.e. 32 characters [0-9a-f] - * (pointer to static area, changed by subsequent calls) - */ - -char *strmd5(const char *src, unsigned char *dst); - -/** - * Returns: allocated 32bytes long ASCII string with md5 sum - * of the first argument - */ -char *str2md5(const char *src); - -/** - * Returns: allocated 22bytes long ASCII string with md5 sum in base64 - * format of the source argument - */ -char *str2md5base64(const char *src); - -int base64_encode(const void *enc, int enc_size, char *out, int out_max_size); -int base64_decode(const char *enc,char *out,int out_size); - -#ifdef __cplusplus -}; -#endif - -#endif /* _GLITE_STRMD5_H */ diff --git a/org.glite.jobid.api-c/project/ChangeLog b/org.glite.jobid.api-c/project/ChangeLog deleted file mode 100644 index 64dbfa2..0000000 --- a/org.glite.jobid.api-c/project/ChangeLog +++ /dev/null @@ -1,11 +0,0 @@ -1.0.0-1 -- ChangeLog created - -1.0.0-2 -- fixes in etics' invocation of configure - -1.0.0-4 -- configure script update - -1.0.0-5 -- install libraries into $libdir diff --git a/org.glite.jobid.api-c/project/version.properties b/org.glite.jobid.api-c/project/version.properties deleted file mode 100644 index f40a67c..0000000 --- a/org.glite.jobid.api-c/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# : /cvs/jra1mw/org.glite.jobid.api-c/project/version.properties,v 1.1 2009/01/16 08:48:52 zsustr Exp $ -module.version=1.0.0 -module.age=5 diff --git a/org.glite.jobid.api-c/src/cjobid.c b/org.glite.jobid.api-c/src/cjobid.c deleted file mode 100644 index 62b52e4..0000000 --- a/org.glite.jobid.api-c/src/cjobid.c +++ /dev/null @@ -1,274 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "cjobid.h" -#include "strmd5.h" - -struct _edg_wlc_JobId { - char *id; /* unique job identification */ - /* additional information */ - char *BShost;/* bookkeeping server hostname */ - unsigned int BSport; /* bookkeeping server port */ - char *info; /* additional information (after ? in URI) */ -}; - -int glite_jobid_create(const char *bkserver, int port, glite_jobid_t *jobId) -{ - return glite_jobid_recreate(bkserver, port, NULL, jobId); -} - - -int glite_jobid_recreate(const char* bkserver, int port, const char *unique, glite_jobid_t *jobId) -{ - glite_jobid_t out; - char hostname[200]; /* used to hold string for encrypt */ - struct timeval tv; - int skip; - char* portbeg; - - struct hostent* he; - - if (!bkserver) - return EINVAL; - - if (unique == NULL) { - gethostname(hostname, 100); - he = gethostbyname(hostname); - assert(he->h_length > 0); - gettimeofday(&tv, NULL); - srandom(tv.tv_usec); - - skip = strlen(hostname); - skip += sprintf(hostname + skip, "-IP:0x%x-pid:%d-rnd:%d-time:%d:%d", - *((int*)he->h_addr_list[0]), getpid(), (int)random(), - (int)tv.tv_sec, (int)tv.tv_usec); - } - - *jobId = NULL; - out = (glite_jobid_t) malloc (sizeof(*out)); - if (!out) - return ENOMEM; - - memset(out, 0, sizeof(*out)); - - /* check if it begins with prefix */ - /* unsupported */ - /* FIXME: fill in PROTO_PREFIX if missing */ - if (strncmp(bkserver, GLITE_JOBID_PROTO_PREFIX, sizeof(GLITE_JOBID_PROTO_PREFIX)-1) == 0) - return EINVAL; - - out->BShost = strdup(bkserver); - portbeg = strchr(out->BShost, ':'); - if (portbeg) { - *portbeg = 0; - /* try to get port number */ - if (port == 0) - port = atoi(portbeg + 1); - } - - if (port == 0) - port = GLITE_JOBID_DEFAULT_PORT; - - out->BSport = port; - - out->id = (unique) ? strdup(unique) : str2md5base64(hostname); - //printf("Encrypt: %s\nBASE64 %s\n", hostname, out->id); - - if (!out->id || !out->BShost) { - glite_jobid_free(out); - return ENOMEM; - } - - *jobId = out; - return 0; -} - - -int glite_jobid_dup(glite_jobid_const_t in, glite_jobid_t *out) -{ - glite_jobid_t jid; - *out = NULL; - if (in == NULL) - return 0; - - jid = malloc(sizeof(*jid)); - if (!jid) - return ENOMEM; - - memset(jid, 0,sizeof(*jid)); - jid->BShost = strdup(in->BShost); - jid->id = strdup(in->id); - if (in->info) - jid->info = strdup(in->info); - - if (jid->BShost == NULL || jid->id == NULL) { - glite_jobid_free(jid); - return ENOMEM; - } - - jid->BSport = in->BSport; - *out = jid; - return 0; -} - - -// XXX -// use recreate -// parse name, port, unique -int glite_jobid_parse(const char *idString, glite_jobid_t *jobId) -{ - char *pom, *pom1, *pom2; - glite_jobid_t out; - - *jobId = NULL; - - out = (glite_jobid_t) malloc (sizeof(*out)); - if (out == NULL ) - return ENOMEM; - - memset(out,0,sizeof(*out)); - - if (strncmp(idString, GLITE_JOBID_PROTO_PREFIX, sizeof(GLITE_JOBID_PROTO_PREFIX) - 1)) { - out->BShost = (char *) NULL; - out->BSport = 0; - - free(out); - return EINVAL; - } - - pom = strdup(idString + sizeof(GLITE_JOBID_PROTO_PREFIX) - 1); - pom1 = strchr(pom, '/'); - pom2 = strchr(pom, ':'); - - if (!pom1) { free(pom); free(out); return EINVAL; } - - if ( pom2 && (pom1 > pom2)) { - pom[pom2-pom] = '\0'; - out->BShost = strdup(pom); - pom[pom1-pom] = '\0'; - out->BSport = (unsigned int) strtoul(pom2 + 1,NULL,10); - } else { - pom[pom1-pom] = '\0'; - out->BShost = strdup(pom); - out->BSport = GLITE_JOBID_DEFAULT_PORT; - } - - /* XXX: localhost not supported in jobid - if (!strncmp(out->BShost,"localhost",9) { - free(pom); - free(out->BShost); - free(out); - return EINVAL; - } - */ - - /* additional info from URI */ - pom2 = strchr(pom1+1,'?'); - if (pom2) { - *pom2 = 0; - out->info = strdup(pom2+1); - } - - /* extract the unique part */ - out->id = strdup(pom1+1); - - for (pom1 = out->BShost; *pom1; pom1++) - if (isspace(*pom1)) break; - - for (pom2 = out->id; *pom2; pom2++) - if (isspace(*pom2)) break; - - if (*pom1 || *pom2) { - free(pom); - glite_jobid_free(out); - return EINVAL; - } - - free(pom); - *jobId = out; - return 0; -} - - -void glite_jobid_free(glite_jobid_t job) -{ - if (job) { - free(job->id); - free(job->BShost); - free(job->info); - free(job); - } -} - - -char* glite_jobid_unparse(glite_jobid_const_t jobid) -{ - char *out, port[40]; - - if (!jobid) - return NULL; - - if (jobid->BSport) - sprintf(port,":%d",jobid->BSport); - else - *port = 0; - - asprintf(&out, GLITE_JOBID_PROTO_PREFIX"%s%s/%s%s%s", - jobid->BShost,port, - jobid->id, - (jobid->info ? "?" : ""), - (jobid->info ? jobid->info : "")); - - return out; -} - - -char* glite_jobid_getServer(glite_jobid_const_t jobid) -{ - char *bs = NULL; - - if (jobid) - asprintf(&bs, "%s:%u", jobid->BShost, - jobid->BSport ? jobid->BSport : GLITE_JOBID_DEFAULT_PORT); - - return bs; -} - - -void glite_jobid_getServerParts(glite_jobid_const_t jobid, char **srvName, unsigned int *srvPort) -{ - if (jobid) { - *srvName = strdup(jobid->BShost); - *srvPort = jobid->BSport ? jobid->BSport : GLITE_JOBID_DEFAULT_PORT; - } -} - - -char* glite_jobid_getUnique(glite_jobid_const_t jobid) -{ - return jobid ? strdup(jobid->id) : NULL; -} - - -void glite_jobid_getServerParts_internal(glite_jobid_const_t jobid, char **srvName, unsigned int *srvPort) -{ - if (jobid) { - *srvName = jobid->BShost; - *srvPort = jobid->BSport ? jobid->BSport : GLITE_JOBID_DEFAULT_PORT; - } -} - - -char* glite_jobid_getUnique_internal(glite_jobid_const_t jobid) -{ - return jobid ? jobid->id : NULL; -} diff --git a/org.glite.jobid.api-c/src/md32_common.h b/org.glite.jobid.api-c/src/md32_common.h deleted file mode 100644 index 0b8496f..0000000 --- a/org.glite.jobid.api-c/src/md32_common.h +++ /dev/null @@ -1,623 +0,0 @@ -/* crypto/md32_common.h */ -/* ==================================================================== - * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * licensing@OpenSSL.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). - * - */ - -/* - * This is a generic 32 bit "collector" for message digest algorithms. - * Whenever needed it collects input character stream into chunks of - * 32 bit values and invokes a block function that performs actual hash - * calculations. - * - * Porting guide. - * - * Obligatory macros: - * - * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN - * this macro defines byte order of input stream. - * HASH_CBLOCK - * size of a unit chunk HASH_BLOCK operates on. - * HASH_LONG - * has to be at lest 32 bit wide, if it's wider, then - * HASH_LONG_LOG2 *has to* be defined along - * HASH_CTX - * context structure that at least contains following - * members: - * typedef struct { - * ... - * HASH_LONG Nl,Nh; - * HASH_LONG data[HASH_LBLOCK]; - * unsigned int num; - * ... - * } HASH_CTX; - * HASH_UPDATE - * name of "Update" function, implemented here. - * HASH_TRANSFORM - * name of "Transform" function, implemented here. - * HASH_FINAL - * name of "Final" function, implemented here. - * HASH_BLOCK_HOST_ORDER - * name of "block" function treating *aligned* input message - * in host byte order, implemented externally. - * HASH_BLOCK_DATA_ORDER - * name of "block" function treating *unaligned* input message - * in original (data) byte order, implemented externally (it - * actually is optional if data and host are of the same - * "endianess"). - * HASH_MAKE_STRING - * macro convering context variables to an ASCII hash string. - * - * Optional macros: - * - * B_ENDIAN or L_ENDIAN - * defines host byte-order. - * HASH_LONG_LOG2 - * defaults to 2 if not states otherwise. - * HASH_LBLOCK - * assumed to be HASH_CBLOCK/4 if not stated otherwise. - * HASH_BLOCK_DATA_ORDER_ALIGNED - * alternative "block" function capable of treating - * aligned input message in original (data) order, - * implemented externally. - * - * MD5 example: - * - * #define DATA_ORDER_IS_LITTLE_ENDIAN - * - * #define HASH_LONG MD5_LONG - * #define HASH_LONG_LOG2 MD5_LONG_LOG2 - * #define HASH_CTX MD5_CTX - * #define HASH_CBLOCK MD5_CBLOCK - * #define HASH_LBLOCK MD5_LBLOCK - * #define HASH_UPDATE MD5_Update - * #define HASH_TRANSFORM MD5_Transform - * #define HASH_FINAL MD5_Final - * #define HASH_BLOCK_HOST_ORDER md5_block_host_order - * #define HASH_BLOCK_DATA_ORDER md5_block_data_order - * - * - */ - -#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) -#error "DATA_ORDER must be defined!" -#endif - -#ifndef HASH_CBLOCK -#error "HASH_CBLOCK must be defined!" -#endif -#ifndef HASH_LONG -#error "HASH_LONG must be defined!" -#endif -#ifndef HASH_CTX -#error "HASH_CTX must be defined!" -#endif - -#ifndef HASH_UPDATE -#error "HASH_UPDATE must be defined!" -#endif -#ifndef HASH_TRANSFORM -#error "HASH_TRANSFORM must be defined!" -#endif -#ifndef HASH_FINAL -#error "HASH_FINAL must be defined!" -#endif - -#ifndef HASH_BLOCK_HOST_ORDER -#error "HASH_BLOCK_HOST_ORDER must be defined!" -#endif - -#if 0 -/* - * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED - * isn't defined. - */ -#ifndef HASH_BLOCK_DATA_ORDER -#error "HASH_BLOCK_DATA_ORDER must be defined!" -#endif -#endif - -#ifndef HASH_LBLOCK -#define HASH_LBLOCK (HASH_CBLOCK/4) -#endif - -#ifndef HASH_LONG_LOG2 -#define HASH_LONG_LOG2 2 -#endif - -/* - * Engage compiler specific rotate intrinsic function if available. - */ -#undef ROTATE -#ifndef PEDANTIC -# if defined(_MSC_VER) || defined(__ICC) -# define ROTATE(a,n) _lrotl(a,n) -# elif defined(__MWERKS__) -# if defined(__POWERPC__) -# define ROTATE(a,n) __rlwinm(a,n,0,31) -# elif defined(__MC68K__) - /* Motorola specific tweak. */ -# define ROTATE(a,n) ( n<24 ? __rol(a,n) : __ror(a,32-n) ) -# else -# define ROTATE(a,n) __rol(a,n) -# endif -# elif defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) - /* - * Some GNU C inline assembler templates. Note that these are - * rotates by *constant* number of bits! But that's exactly - * what we need here... - * - */ -# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) -# define ROTATE(a,n) ({ register unsigned int ret; \ - asm ( \ - "roll %1,%0" \ - : "=r"(ret) \ - : "I"(n), "0"(a) \ - : "cc"); \ - ret; \ - }) -# elif defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__) -# define ROTATE(a,n) ({ register unsigned int ret; \ - asm ( \ - "rlwinm %0,%1,%2,0,31" \ - : "=r"(ret) \ - : "r"(a), "I"(n)); \ - ret; \ - }) -# endif -# endif -#endif /* PEDANTIC */ - -#if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */ -/* A nice byte order reversal from Wei Dai */ -#ifdef ROTATE -/* 5 instructions with rotate instruction, else 9 */ -#define REVERSE_FETCH32(a,l) ( \ - l=*(const HASH_LONG *)(a), \ - ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \ - ) -#else -/* 6 instructions with rotate instruction, else 8 */ -#define REVERSE_FETCH32(a,l) ( \ - l=*(const HASH_LONG *)(a), \ - l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \ - ROTATE(l,16) \ - ) -/* - * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|... - * It's rewritten as above for two reasons: - * - RISCs aren't good at long constants and have to explicitely - * compose 'em with several (well, usually 2) instructions in a - * register before performing the actual operation and (as you - * already realized:-) having same constant should inspire the - * compiler to permanently allocate the only register for it; - * - most modern CPUs have two ALUs, but usually only one has - * circuitry for shifts:-( this minor tweak inspires compiler - * to schedule shift instructions in a better way... - * - * - */ -#endif -#endif - -#ifndef ROTATE -#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) -#endif - -/* - * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED - * and HASH_BLOCK_HOST_ORDER ought to be the same if input data - * and host are of the same "endianess". It's possible to mask - * this with blank #define HASH_BLOCK_DATA_ORDER though... - * - * - */ -#if defined(B_ENDIAN) -# if defined(DATA_ORDER_IS_BIG_ENDIAN) -# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2 -# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER -# endif -# endif -#elif defined(L_ENDIAN) -# if defined(DATA_ORDER_IS_LITTLE_ENDIAN) -# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2 -# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER -# endif -# endif -#endif - -#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) -#ifndef HASH_BLOCK_DATA_ORDER -#error "HASH_BLOCK_DATA_ORDER must be defined!" -#endif -#endif - -#if defined(DATA_ORDER_IS_BIG_ENDIAN) - -#ifndef PEDANTIC -# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) -# if ((defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)) || \ - (defined(__x86_64) || defined(__x86_64__)) - /* - * This gives ~30-40% performance improvement in SHA-256 compiled - * with gcc [on P4]. Well, first macro to be frank. We can pull - * this trick on x86* platforms only, because these CPUs can fetch - * unaligned data without raising an exception. - */ -# define HOST_c2l(c,l) ({ unsigned int r=*((const unsigned int *)(c)); \ - asm ("bswapl %0":"=r"(r):"0"(r)); \ - (c)+=4; (l)=r; }) -# define HOST_l2c(l,c) ({ unsigned int r=(l); \ - asm ("bswapl %0":"=r"(r):"0"(r)); \ - *((unsigned int *)(c))=r; (c)+=4; r; }) -# endif -# endif -#endif - -#ifndef HOST_c2l -#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ - l|=(((unsigned long)(*((c)++)))<<16), \ - l|=(((unsigned long)(*((c)++)))<< 8), \ - l|=(((unsigned long)(*((c)++))) ), \ - l) -#endif -#define HOST_p_c2l(c,l,n) { \ - switch (n) { \ - case 0: l =((unsigned long)(*((c)++)))<<24; \ - case 1: l|=((unsigned long)(*((c)++)))<<16; \ - case 2: l|=((unsigned long)(*((c)++)))<< 8; \ - case 3: l|=((unsigned long)(*((c)++))); \ - } } -#define HOST_p_c2l_p(c,l,sc,len) { \ - switch (sc) { \ - case 0: l =((unsigned long)(*((c)++)))<<24; \ - if (--len == 0) break; \ - case 1: l|=((unsigned long)(*((c)++)))<<16; \ - if (--len == 0) break; \ - case 2: l|=((unsigned long)(*((c)++)))<< 8; \ - } } -/* NOTE the pointer is not incremented at the end of this */ -#define HOST_c2l_p(c,l,n) { \ - l=0; (c)+=n; \ - switch (n) { \ - case 3: l =((unsigned long)(*(--(c))))<< 8; \ - case 2: l|=((unsigned long)(*(--(c))))<<16; \ - case 1: l|=((unsigned long)(*(--(c))))<<24; \ - } } -#ifndef HOST_l2c -#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l) )&0xff), \ - l) -#endif - -#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) - -#if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) -# ifndef B_ENDIAN - /* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */ -# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, l) -# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, l) -# endif -#endif - -#ifndef HOST_c2l -#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ - l|=(((unsigned long)(*((c)++)))<< 8), \ - l|=(((unsigned long)(*((c)++)))<<16), \ - l|=(((unsigned long)(*((c)++)))<<24), \ - l) -#endif -#define HOST_p_c2l(c,l,n) { \ - switch (n) { \ - case 0: l =((unsigned long)(*((c)++))); \ - case 1: l|=((unsigned long)(*((c)++)))<< 8; \ - case 2: l|=((unsigned long)(*((c)++)))<<16; \ - case 3: l|=((unsigned long)(*((c)++)))<<24; \ - } } -#define HOST_p_c2l_p(c,l,sc,len) { \ - switch (sc) { \ - case 0: l =((unsigned long)(*((c)++))); \ - if (--len == 0) break; \ - case 1: l|=((unsigned long)(*((c)++)))<< 8; \ - if (--len == 0) break; \ - case 2: l|=((unsigned long)(*((c)++)))<<16; \ - } } -/* NOTE the pointer is not incremented at the end of this */ -#define HOST_c2l_p(c,l,n) { \ - l=0; (c)+=n; \ - switch (n) { \ - case 3: l =((unsigned long)(*(--(c))))<<16; \ - case 2: l|=((unsigned long)(*(--(c))))<< 8; \ - case 1: l|=((unsigned long)(*(--(c)))); \ - } } -#ifndef HOST_l2c -#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ - *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ - *((c)++)=(unsigned char)(((l)>>16)&0xff), \ - *((c)++)=(unsigned char)(((l)>>24)&0xff), \ - l) -#endif - -#endif - -/* - * Time for some action:-) - */ - -MD5_JOBID_PROTO int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len) - { - const unsigned char *data=data_; - register HASH_LONG * p; - register HASH_LONG l; - size_t sw,sc,ew,ec; - - if (len==0) return 1; - - l=(c->Nl+(((HASH_LONG)len)<<3))&0xffffffffUL; - /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to - * Wei Dai for pointing it out. */ - if (l < c->Nl) /* overflow */ - c->Nh++; - c->Nh+=(len>>29); /* might cause compiler warning on 16-bit */ - c->Nl=l; - - if (c->num != 0) - { - p=c->data; - sw=c->num>>2; - sc=c->num&0x03; - - if ((c->num+len) >= HASH_CBLOCK) - { - l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l; - for (; swnum); - c->num=0; - /* drop through and do the rest */ - } - else - { - c->num+=(unsigned int)len; - if ((sc+len) < 4) /* ugly, add char's to a word */ - { - l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l; - } - else - { - ew=(c->num>>2); - ec=(c->num&0x03); - if (sc) - l=p[sw]; - HOST_p_c2l(data,l,sc); - p[sw++]=l; - for (; sw < ew; sw++) - { - HOST_c2l(data,l); p[sw]=l; - } - if (ec) - { - HOST_c2l_p(data,l,ec); p[sw]=l; - } - } - return 1; - } - } - - sw=len/HASH_CBLOCK; - if (sw > 0) - { -#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED) - /* - * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined - * only if sizeof(HASH_LONG)==4. - */ - if ((((size_t)data)%4) == 0) - { - /* data is properly aligned so that we can cast it: */ - HASH_BLOCK_DATA_ORDER_ALIGNED (c,(const HASH_LONG *)data,sw); - sw*=HASH_CBLOCK; - data+=sw; - len-=sw; - } - else -#if !defined(HASH_BLOCK_DATA_ORDER) - while (sw--) - { - memcpy (p=c->data,data,HASH_CBLOCK); - HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1); - data+=HASH_CBLOCK; - len-=HASH_CBLOCK; - } -#endif -#endif -#if defined(HASH_BLOCK_DATA_ORDER) - { - HASH_BLOCK_DATA_ORDER(c,data,sw); - sw*=HASH_CBLOCK; - data+=sw; - len-=sw; - } -#endif - } - - if (len!=0) - { - p = c->data; - c->num = len; - ew=len>>2; /* words to copy */ - ec=len&0x03; - for (; ew; ew--,p++) - { - HOST_c2l(data,l); *p=l; - } - HOST_c2l_p(data,l,ec); - *p=l; - } - return 1; - } - - -MD5_JOBID_PROTO void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data) - { -#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED) - if ((((size_t)data)%4) == 0) - /* data is properly aligned so that we can cast it: */ - HASH_BLOCK_DATA_ORDER_ALIGNED (c,(const HASH_LONG *)data,1); - else -#if !defined(HASH_BLOCK_DATA_ORDER) - { - - HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1); - } -#endif -#endif -#if defined(HASH_BLOCK_DATA_ORDER) - HASH_BLOCK_DATA_ORDER (c,data,1); -#endif - } - - -MD5_JOBID_PROTO int HASH_FINAL (unsigned char *md, HASH_CTX *c) - { - register HASH_LONG *p; - register unsigned long l; - register int i,j; - static const unsigned char end[4]={0x80,0x00,0x00,0x00}; - const unsigned char *cp=end; - - /* c->num should definitly have room for at least one more byte. */ - p=c->data; - i=c->num>>2; - j=c->num&0x03; - -#if 0 - /* purify often complains about the following line as an - * Uninitialized Memory Read. While this can be true, the - * following p_c2l macro will reset l when that case is true. - * This is because j&0x03 contains the number of 'valid' bytes - * already in p[i]. If and only if j&0x03 == 0, the UMR will - * occur but this is also the only time p_c2l will do - * l= *(cp++) instead of l|= *(cp++) - * Many thanks to Alex Tang for pickup this - * 'potential bug' */ -#ifdef PURIFY - if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */ -#endif - l=p[i]; -#else - l = (j==0) ? 0 : p[i]; -#endif - HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */ - - if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */ - { - if (iNh; - p[HASH_LBLOCK-1]=c->Nl; -#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) - p[HASH_LBLOCK-2]=c->Nl; - p[HASH_LBLOCK-1]=c->Nh; -#endif - HASH_BLOCK_HOST_ORDER (c,p,1); - -#ifndef HASH_MAKE_STRING -#error "HASH_MAKE_STRING must be defined!" -#else - HASH_MAKE_STRING(c,md); -#endif - - c->num=0; - /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack - * but I'm not worried :-) - OPENSSL_cleanse((void *)c,sizeof(HASH_CTX)); - */ - return 1; - } - -#ifndef MD32_REG_T -#define MD32_REG_T long -/* - * This comment was originaly written for MD5, which is why it - * discusses A-D. But it basically applies to all 32-bit digests, - * which is why it was moved to common header file. - * - * In case you wonder why A-D are declared as long and not - * as MD5_LONG. Doing so results in slight performance - * boost on LP64 architectures. The catch is we don't - * really care if 32 MSBs of a 64-bit register get polluted - * with eventual overflows as we *save* only 32 LSBs in - * *either* case. Now declaring 'em long excuses the compiler - * from keeping 32 MSBs zeroed resulting in 13% performance - * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. - * Well, to be honest it should say that this *prevents* - * performance degradation. - * - * Apparently there're LP64 compilers that generate better - * code if A-D are declared int. Most notably GCC-x86_64 - * generates better code. - * - */ -#endif diff --git a/org.glite.jobid.api-c/src/md5.h b/org.glite.jobid.api-c/src/md5.h deleted file mode 100644 index 6bcdfdf..0000000 --- a/org.glite.jobid.api-c/src/md5.h +++ /dev/null @@ -1,118 +0,0 @@ -/* crypto/md5/md5.h */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#ifndef HEADER_MD5_H -#define HEADER_MD5_H - -/* ljocha -#include -*/ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef OPENSSL_NO_MD5 -#error MD5 is disabled. -#endif - -/* - * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then ! - * ! MD5_LONG_LOG2 has to be defined along. ! - * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - */ - -#if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) -#define MD5_LONG unsigned long -#elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) -#define MD5_LONG unsigned long -#define MD5_LONG_LOG2 3 - -/* _CRAY note. I could declare short, but I have no idea what impact - * does it have on performance on none-T3E machines. I could declare - * int, but at least on C90 sizeof(int) can be chosen at compile time. - * So I've chosen long... * - */ -#else -#define MD5_LONG unsigned int -#endif - -#define MD5_CBLOCK 64 -#define MD5_LBLOCK (MD5_CBLOCK/4) -#define MD5_DIGEST_LENGTH 16 - -typedef struct MD5state_st - { - MD5_LONG A,B,C,D; - MD5_LONG Nl,Nh; - MD5_LONG data[MD5_LBLOCK]; - unsigned int num; - } MD5_CTX; - -MD5_JOBID_PROTO int MD5_Init(MD5_CTX *c); -MD5_JOBID_PROTO int MD5_Update(MD5_CTX *c, const void *data, size_t len); -MD5_JOBID_PROTO int MD5_Final(unsigned char *md, MD5_CTX *c); -MD5_JOBID_PROTO unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); -MD5_JOBID_PROTO void MD5_Transform(MD5_CTX *c, const unsigned char *b); -#ifdef __cplusplus -} -#endif - -#endif diff --git a/org.glite.jobid.api-c/src/md5_dgst.c b/org.glite.jobid.api-c/src/md5_dgst.c deleted file mode 100644 index df6d163..0000000 --- a/org.glite.jobid.api-c/src/md5_dgst.c +++ /dev/null @@ -1,298 +0,0 @@ -/* crypto/md5/md5_dgst.c */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#ifndef MD5_JOBID_PROTO -#define MD5_JOBID_PROTO -#endif - -#include -#include "md5_locl.h" -/* ljocha -#include - -const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT; -*/ - -/* Implemented from RFC1321 The MD5 Message-Digest Algorithm - */ - -#define INIT_DATA_A (unsigned long)0x67452301L -#define INIT_DATA_B (unsigned long)0xefcdab89L -#define INIT_DATA_C (unsigned long)0x98badcfeL -#define INIT_DATA_D (unsigned long)0x10325476L - -MD5_JOBID_PROTO int MD5_Init(MD5_CTX *c) - { - c->A=INIT_DATA_A; - c->B=INIT_DATA_B; - c->C=INIT_DATA_C; - c->D=INIT_DATA_D; - c->Nl=0; - c->Nh=0; - c->num=0; - return 1; - } - -#ifndef md5_block_host_order -MD5_JOBID_PROTO void md5_block_host_order (MD5_CTX *c, const void *data, size_t num) - { - const MD5_LONG *X=data; - register unsigned MD32_REG_T A,B,C,D; - - A=c->A; - B=c->B; - C=c->C; - D=c->D; - - for (;num--;X+=HASH_LBLOCK) - { - /* Round 0 */ - R0(A,B,C,D,X[ 0], 7,0xd76aa478L); - R0(D,A,B,C,X[ 1],12,0xe8c7b756L); - R0(C,D,A,B,X[ 2],17,0x242070dbL); - R0(B,C,D,A,X[ 3],22,0xc1bdceeeL); - R0(A,B,C,D,X[ 4], 7,0xf57c0fafL); - R0(D,A,B,C,X[ 5],12,0x4787c62aL); - R0(C,D,A,B,X[ 6],17,0xa8304613L); - R0(B,C,D,A,X[ 7],22,0xfd469501L); - R0(A,B,C,D,X[ 8], 7,0x698098d8L); - R0(D,A,B,C,X[ 9],12,0x8b44f7afL); - R0(C,D,A,B,X[10],17,0xffff5bb1L); - R0(B,C,D,A,X[11],22,0x895cd7beL); - R0(A,B,C,D,X[12], 7,0x6b901122L); - R0(D,A,B,C,X[13],12,0xfd987193L); - R0(C,D,A,B,X[14],17,0xa679438eL); - R0(B,C,D,A,X[15],22,0x49b40821L); - /* Round 1 */ - R1(A,B,C,D,X[ 1], 5,0xf61e2562L); - R1(D,A,B,C,X[ 6], 9,0xc040b340L); - R1(C,D,A,B,X[11],14,0x265e5a51L); - R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL); - R1(A,B,C,D,X[ 5], 5,0xd62f105dL); - R1(D,A,B,C,X[10], 9,0x02441453L); - R1(C,D,A,B,X[15],14,0xd8a1e681L); - R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L); - R1(A,B,C,D,X[ 9], 5,0x21e1cde6L); - R1(D,A,B,C,X[14], 9,0xc33707d6L); - R1(C,D,A,B,X[ 3],14,0xf4d50d87L); - R1(B,C,D,A,X[ 8],20,0x455a14edL); - R1(A,B,C,D,X[13], 5,0xa9e3e905L); - R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L); - R1(C,D,A,B,X[ 7],14,0x676f02d9L); - R1(B,C,D,A,X[12],20,0x8d2a4c8aL); - /* Round 2 */ - R2(A,B,C,D,X[ 5], 4,0xfffa3942L); - R2(D,A,B,C,X[ 8],11,0x8771f681L); - R2(C,D,A,B,X[11],16,0x6d9d6122L); - R2(B,C,D,A,X[14],23,0xfde5380cL); - R2(A,B,C,D,X[ 1], 4,0xa4beea44L); - R2(D,A,B,C,X[ 4],11,0x4bdecfa9L); - R2(C,D,A,B,X[ 7],16,0xf6bb4b60L); - R2(B,C,D,A,X[10],23,0xbebfbc70L); - R2(A,B,C,D,X[13], 4,0x289b7ec6L); - R2(D,A,B,C,X[ 0],11,0xeaa127faL); - R2(C,D,A,B,X[ 3],16,0xd4ef3085L); - R2(B,C,D,A,X[ 6],23,0x04881d05L); - R2(A,B,C,D,X[ 9], 4,0xd9d4d039L); - R2(D,A,B,C,X[12],11,0xe6db99e5L); - R2(C,D,A,B,X[15],16,0x1fa27cf8L); - R2(B,C,D,A,X[ 2],23,0xc4ac5665L); - /* Round 3 */ - R3(A,B,C,D,X[ 0], 6,0xf4292244L); - R3(D,A,B,C,X[ 7],10,0x432aff97L); - R3(C,D,A,B,X[14],15,0xab9423a7L); - R3(B,C,D,A,X[ 5],21,0xfc93a039L); - R3(A,B,C,D,X[12], 6,0x655b59c3L); - R3(D,A,B,C,X[ 3],10,0x8f0ccc92L); - R3(C,D,A,B,X[10],15,0xffeff47dL); - R3(B,C,D,A,X[ 1],21,0x85845dd1L); - R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL); - R3(D,A,B,C,X[15],10,0xfe2ce6e0L); - R3(C,D,A,B,X[ 6],15,0xa3014314L); - R3(B,C,D,A,X[13],21,0x4e0811a1L); - R3(A,B,C,D,X[ 4], 6,0xf7537e82L); - R3(D,A,B,C,X[11],10,0xbd3af235L); - R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL); - R3(B,C,D,A,X[ 9],21,0xeb86d391L); - - A = c->A += A; - B = c->B += B; - C = c->C += C; - D = c->D += D; - } - } -#endif - -#ifndef md5_block_data_order -#ifdef X -#undef X -#endif -MD5_JOBID_PROTO void md5_block_data_order (MD5_CTX *c, const void *data_, size_t num) - { - const unsigned char *data=data_; - register unsigned MD32_REG_T A,B,C,D,l; -#ifndef MD32_XARRAY - /* See comment in crypto/sha/sha_locl.h for details. */ - unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, - XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; -# define X(i) XX##i -#else - MD5_LONG XX[MD5_LBLOCK]; -# define X(i) XX[i] -#endif - - A=c->A; - B=c->B; - C=c->C; - D=c->D; - - for (;num--;) - { - HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l; - /* Round 0 */ - R0(A,B,C,D,X( 0), 7,0xd76aa478L); HOST_c2l(data,l); X( 2)=l; - R0(D,A,B,C,X( 1),12,0xe8c7b756L); HOST_c2l(data,l); X( 3)=l; - R0(C,D,A,B,X( 2),17,0x242070dbL); HOST_c2l(data,l); X( 4)=l; - R0(B,C,D,A,X( 3),22,0xc1bdceeeL); HOST_c2l(data,l); X( 5)=l; - R0(A,B,C,D,X( 4), 7,0xf57c0fafL); HOST_c2l(data,l); X( 6)=l; - R0(D,A,B,C,X( 5),12,0x4787c62aL); HOST_c2l(data,l); X( 7)=l; - R0(C,D,A,B,X( 6),17,0xa8304613L); HOST_c2l(data,l); X( 8)=l; - R0(B,C,D,A,X( 7),22,0xfd469501L); HOST_c2l(data,l); X( 9)=l; - R0(A,B,C,D,X( 8), 7,0x698098d8L); HOST_c2l(data,l); X(10)=l; - R0(D,A,B,C,X( 9),12,0x8b44f7afL); HOST_c2l(data,l); X(11)=l; - R0(C,D,A,B,X(10),17,0xffff5bb1L); HOST_c2l(data,l); X(12)=l; - R0(B,C,D,A,X(11),22,0x895cd7beL); HOST_c2l(data,l); X(13)=l; - R0(A,B,C,D,X(12), 7,0x6b901122L); HOST_c2l(data,l); X(14)=l; - R0(D,A,B,C,X(13),12,0xfd987193L); HOST_c2l(data,l); X(15)=l; - R0(C,D,A,B,X(14),17,0xa679438eL); - R0(B,C,D,A,X(15),22,0x49b40821L); - /* Round 1 */ - R1(A,B,C,D,X( 1), 5,0xf61e2562L); - R1(D,A,B,C,X( 6), 9,0xc040b340L); - R1(C,D,A,B,X(11),14,0x265e5a51L); - R1(B,C,D,A,X( 0),20,0xe9b6c7aaL); - R1(A,B,C,D,X( 5), 5,0xd62f105dL); - R1(D,A,B,C,X(10), 9,0x02441453L); - R1(C,D,A,B,X(15),14,0xd8a1e681L); - R1(B,C,D,A,X( 4),20,0xe7d3fbc8L); - R1(A,B,C,D,X( 9), 5,0x21e1cde6L); - R1(D,A,B,C,X(14), 9,0xc33707d6L); - R1(C,D,A,B,X( 3),14,0xf4d50d87L); - R1(B,C,D,A,X( 8),20,0x455a14edL); - R1(A,B,C,D,X(13), 5,0xa9e3e905L); - R1(D,A,B,C,X( 2), 9,0xfcefa3f8L); - R1(C,D,A,B,X( 7),14,0x676f02d9L); - R1(B,C,D,A,X(12),20,0x8d2a4c8aL); - /* Round 2 */ - R2(A,B,C,D,X( 5), 4,0xfffa3942L); - R2(D,A,B,C,X( 8),11,0x8771f681L); - R2(C,D,A,B,X(11),16,0x6d9d6122L); - R2(B,C,D,A,X(14),23,0xfde5380cL); - R2(A,B,C,D,X( 1), 4,0xa4beea44L); - R2(D,A,B,C,X( 4),11,0x4bdecfa9L); - R2(C,D,A,B,X( 7),16,0xf6bb4b60L); - R2(B,C,D,A,X(10),23,0xbebfbc70L); - R2(A,B,C,D,X(13), 4,0x289b7ec6L); - R2(D,A,B,C,X( 0),11,0xeaa127faL); - R2(C,D,A,B,X( 3),16,0xd4ef3085L); - R2(B,C,D,A,X( 6),23,0x04881d05L); - R2(A,B,C,D,X( 9), 4,0xd9d4d039L); - R2(D,A,B,C,X(12),11,0xe6db99e5L); - R2(C,D,A,B,X(15),16,0x1fa27cf8L); - R2(B,C,D,A,X( 2),23,0xc4ac5665L); - /* Round 3 */ - R3(A,B,C,D,X( 0), 6,0xf4292244L); - R3(D,A,B,C,X( 7),10,0x432aff97L); - R3(C,D,A,B,X(14),15,0xab9423a7L); - R3(B,C,D,A,X( 5),21,0xfc93a039L); - R3(A,B,C,D,X(12), 6,0x655b59c3L); - R3(D,A,B,C,X( 3),10,0x8f0ccc92L); - R3(C,D,A,B,X(10),15,0xffeff47dL); - R3(B,C,D,A,X( 1),21,0x85845dd1L); - R3(A,B,C,D,X( 8), 6,0x6fa87e4fL); - R3(D,A,B,C,X(15),10,0xfe2ce6e0L); - R3(C,D,A,B,X( 6),15,0xa3014314L); - R3(B,C,D,A,X(13),21,0x4e0811a1L); - R3(A,B,C,D,X( 4), 6,0xf7537e82L); - R3(D,A,B,C,X(11),10,0xbd3af235L); - R3(C,D,A,B,X( 2),15,0x2ad7d2bbL); - R3(B,C,D,A,X( 9),21,0xeb86d391L); - - A = c->A += A; - B = c->B += B; - C = c->C += C; - D = c->D += D; - } - } -#endif - -#ifdef undef -int printit(unsigned long *l) - { - int i,ii; - - for (i=0; i<2; i++) - { - for (ii=0; ii<8; ii++) - { - fprintf(stderr,"%08lx ",l[i*8+ii]); - } - fprintf(stderr,"\n"); - } - } -#endif diff --git a/org.glite.jobid.api-c/src/md5_locl.h b/org.glite.jobid.api-c/src/md5_locl.h deleted file mode 100644 index dda821c..0000000 --- a/org.glite.jobid.api-c/src/md5_locl.h +++ /dev/null @@ -1,176 +0,0 @@ -/* crypto/md5/md5_locl.h */ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ - -#include -#include -#include -#include - -#ifndef MD5_LONG_LOG2 -#define MD5_LONG_LOG2 2 /* default to 32 bits */ -#endif - -#ifdef MD5_ASM -# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) || defined(__x86_64) || defined(__x86_64__) -# if !defined(B_ENDIAN) -# define md5_block_host_order md5_block_asm_host_order -# endif -# elif defined(__sparc) && defined(OPENSSL_SYS_ULTRASPARC) - void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,size_t num); -# define HASH_BLOCK_DATA_ORDER_ALIGNED md5_block_asm_data_order_aligned -# endif -#endif - -MD5_JOBID_PROTO void md5_block_host_order (MD5_CTX *c, const void *p,size_t num); -MD5_JOBID_PROTO void md5_block_data_order (MD5_CTX *c, const void *p,size_t num); - -#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) || defined(__x86_64) || defined(__x86_64__) -# if !defined(B_ENDIAN) -/* - * *_block_host_order is expected to handle aligned data while - * *_block_data_order - unaligned. As algorithm and host (x86) - * are in this case of the same "endianness" these two are - * otherwise indistinguishable. But normally you don't want to - * call the same function because unaligned access in places - * where alignment is expected is usually a "Bad Thing". Indeed, - * on RISCs you get punished with BUS ERROR signal or *severe* - * performance degradation. Intel CPUs are in turn perfectly - * capable of loading unaligned data without such drastic side - * effect. Yes, they say it's slower than aligned load, but no - * exception is generated and therefore performance degradation - * is *incomparable* with RISCs. What we should weight here is - * costs of unaligned access against costs of aligning data. - * According to my measurements allowing unaligned access results - * in ~9% performance improvement on Pentium II operating at - * 266MHz. I won't be surprised if the difference will be higher - * on faster systems:-) - * - * - */ -# define md5_block_data_order md5_block_host_order -# endif -#endif - -#define DATA_ORDER_IS_LITTLE_ENDIAN - -#define HASH_LONG MD5_LONG -#define HASH_LONG_LOG2 MD5_LONG_LOG2 -#define HASH_CTX MD5_CTX -#define HASH_CBLOCK MD5_CBLOCK -#define HASH_LBLOCK MD5_LBLOCK -#define HASH_UPDATE MD5_Update -#define HASH_TRANSFORM MD5_Transform -#define HASH_FINAL MD5_Final -#define HASH_MAKE_STRING(c,s) do { \ - unsigned long ll; \ - ll=(c)->A; HOST_l2c(ll,(s)); \ - ll=(c)->B; HOST_l2c(ll,(s)); \ - ll=(c)->C; HOST_l2c(ll,(s)); \ - ll=(c)->D; HOST_l2c(ll,(s)); \ - } while (0) -#define HASH_BLOCK_HOST_ORDER md5_block_host_order -#if !defined(L_ENDIAN) || defined(md5_block_data_order) -#define HASH_BLOCK_DATA_ORDER md5_block_data_order -/* - * Little-endians (Intel and Alpha) feel better without this. - * It looks like memcpy does better job than generic - * md5_block_data_order on copying-n-aligning input data. - * But frankly speaking I didn't expect such result on Alpha. - * On the other hand I've got this with egcs-1.0.2 and if - * program is compiled with another (better?) compiler it - * might turn out other way around. - * - * - */ -#endif - -#include "md32_common.h" - -/* -#define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) -#define G(x,y,z) (((x) & (z)) | ((y) & (~(z)))) -*/ - -/* As pointed out by Wei Dai , the above can be - * simplified to the code below. Wei attributes these optimizations - * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. - */ -#define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) -#define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c)) -#define H(b,c,d) ((b) ^ (c) ^ (d)) -#define I(b,c,d) (((~(d)) | (b)) ^ (c)) - -#define R0(a,b,c,d,k,s,t) { \ - a+=((k)+(t)+F((b),(c),(d))); \ - a=ROTATE(a,s); \ - a+=b; };\ - -#define R1(a,b,c,d,k,s,t) { \ - a+=((k)+(t)+G((b),(c),(d))); \ - a=ROTATE(a,s); \ - a+=b; }; - -#define R2(a,b,c,d,k,s,t) { \ - a+=((k)+(t)+H((b),(c),(d))); \ - a=ROTATE(a,s); \ - a+=b; }; - -#define R3(a,b,c,d,k,s,t) { \ - a+=((k)+(t)+I((b),(c),(d))); \ - a=ROTATE(a,s); \ - a+=b; }; diff --git a/org.glite.jobid.api-c/src/strmd5.c b/org.glite.jobid.api-c/src/strmd5.c deleted file mode 100755 index baab53f..0000000 --- a/org.glite.jobid.api-c/src/strmd5.c +++ /dev/null @@ -1,152 +0,0 @@ -#ident "$Header$" - - -#include -#include -#include - -#define MD5_JOBID_PROTO static -#include "md5.h" -#include "strmd5.h" - -#include "md5_dgst.c" - - -static char mbuf[33]; -static const char* b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; -static char *b64r; - -int base64_encode(const void *enc, int enc_size, char *out, int out_max_size) -{ - - unsigned char* enc_buf = (unsigned char*)enc; - int out_size = 0; - unsigned int bits = 0; - unsigned int shift = 0; - - while ( out_size < out_max_size ) { - if ( enc_size>0 ) { - // Shift in byte - bits <<= 8; - bits |= *enc_buf; - shift += 8; - // Next byte - enc_buf++; - enc_size--; - } else if ( shift>0 ) { - // Pad last bits to 6 bits - will end next loop - bits <<= 6 - shift; - shift = 6; - } else { - // Terminate with Mime style '=' - *out = '='; - out_size++; - - return out_size; - } - - // Encode 6 bit segments - while ( shift>=6 ) { - shift -= 6; - *out = b64[ (bits >> shift) & 0x3F ]; - out++; - out_size++; - } - } - - // Output overflow - return -1; -} - -int base64_decode(const char *enc,char *out,int max_out_size) -{ - unsigned int bits = 0; - int shift = 0; - int out_size = 0; - - if (!b64r) { - int i; - b64r = calloc(128,1); - - for (i=0; b64[i]; i++) b64r[(int)b64[i]] = i; - } - - while (*enc && *enc != '=') { - bits <<= 6; - bits |= b64r[(int)*enc++]; - shift += 6; - - while (shift >= 8) { - if (out_size >= max_out_size) return -1; - shift -= 8; - *out++ = (bits >> shift) & 0xff; - out_size++; - } - } - - return out_size; -} - -char *strmd5(const char *s, unsigned char *digest) -{ - MD5_CTX md5; - unsigned char d[16]; - int i; - - MD5_Init(&md5); - MD5_Update(&md5,s,strlen(s)); - MD5_Final(d,&md5); - - if (digest) memcpy(digest,d,sizeof(d)); - - for (i=0; i<16; i++) { - int dd = d[i] & 0x0f; - mbuf[2*i+1] = dd<10 ? dd+'0' : dd-10+'a'; - dd = d[i] >> 4; - mbuf[2*i] = dd<10 ? dd+'0' : dd-10+'a'; - } - mbuf[32] = 0; - return (char *) mbuf; -} - -char *str2md5(const char *s) -{ - MD5_CTX md5; - unsigned char d[16]; - char* ret = malloc(33); - int i; - - if (!ret) - return NULL; - - MD5_Init(&md5); - MD5_Update(&md5, s, strlen(s)); - MD5_Final(d, &md5); - - for (i=0; i<16; i++) { - int dd = d[i] & 0x0f; - ret[2*i+1] = dd<10 ? dd+'0' : dd-10+'a'; - dd = d[i] >> 4; - ret[2*i] = dd<10 ? dd+'0' : dd-10+'a'; - } - ret[32] = 0; - return ret; -} - -char *str2md5base64(const char *s) -{ - MD5_CTX md5; - unsigned char d[16]; - char buf[50]; - int l; - - MD5_Init(&md5); - MD5_Update(&md5, s, strlen(s)); - MD5_Final(d, &md5); - - l = base64_encode(d, 16, buf, sizeof(buf) - 1); - if (l < 1) - return NULL; - buf[l - 1] = 0; - return strdup(buf); -} diff --git a/org.glite.jobid.api-c/test/base64_test.cpp b/org.glite.jobid.api-c/test/base64_test.cpp deleted file mode 100644 index 0593da9..0000000 --- a/org.glite.jobid.api-c/test/base64_test.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "strmd5.h" - -class Base64Test: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(Base64Test); - CPPUNIT_TEST(test); - CPPUNIT_TEST_SUITE_END(); -public: - void test(); -}; - -void Base64Test::test() -{ - int i; - unsigned char in[2000], b[4000], out[2000]; - - srandom(0xDEAD); - in[0] = 'x'; - for (i=1; i<2000; i++) { - char s[20]; - int len; - sprintf(s,"%d",i); - in[i] = random() % 256; - - std::cerr << '.'; - - base64_encode(in,i,(char *) b,sizeof b); - len = base64_decode((const char *) b,(char *) out,sizeof out); - - CPPUNIT_ASSERT_MESSAGE(std::string("len"),i == len); - CPPUNIT_ASSERT_MESSAGE(std::string(s),!memcmp(in,out,i)); - } - std::cerr << std::endl; -} - -CPPUNIT_TEST_SUITE_REGISTRATION(Base64Test); - - -int main (int argc,const char *argv[]) -{ - CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - - assert(argc == 2); - std::ofstream xml(argv[1]); - - CppUnit::TestResult controller; - CppUnit::TestResultCollector result; - controller.addListener( &result ); - - CppUnit::TestRunner runner; - runner.addTest(suite); - runner.run(controller); - - CppUnit::XmlOutputter xout( &result, xml ); - CppUnit::CompilerOutputter tout( &result, std::cout); - xout.write(); - tout.write(); - - return result.wasSuccessful() ? 0 : 1 ; -} diff --git a/org.glite.jobid/project/version.properties b/org.glite.jobid/project/version.properties deleted file mode 100644 index 73dde3e..0000000 --- a/org.glite.jobid/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# : /cvs/jra1mw/org.glite.jobid.api-c/project/version.properties,v 1.1 2009/01/16 08:48:52 zsustr Exp $ -module.version=1.0.0 -module.age=8 diff --git a/org.glite.lb.client/.cvsignore b/org.glite.lb.client/.cvsignore deleted file mode 100644 index 1df717b..0000000 --- a/org.glite.lb.client/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -.project -.cdtproject \ No newline at end of file diff --git a/org.glite.lb.client/LICENSE b/org.glite.lb.client/LICENSE deleted file mode 100644 index 259a91f..0000000 --- a/org.glite.lb.client/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.lb.client/Makefile b/org.glite.lb.client/Makefile deleted file mode 100644 index bc40be8..0000000 --- a/org.glite.lb.client/Makefile +++ /dev/null @@ -1,366 +0,0 @@ -# Default values -top_srcdir=.. -stagedir=. -globalprefix=glite -lbprefix=lb -package=glite-lb-client -version=0.0.0 - -nothrflavour=gcc32 -thrflavour=gcc32pthr - -CC:=gcc -CXX:=g++ - --include Makefile.inc --include ../project/version.properties - -version=${module.version} - -# We must follow major version changes of org.glite.lb.common due to -# binary compatibility. However, we may live a life of our own, changing our -# major version more frequently. This variable specifies how many steps ahead -# we are (the number can be even negative). - -VERSION_AHEAD=-3 - -VPATH=${top_srcdir}/src:${top_srcdir}/interface:${top_srcdir}/test:${top_srcdir}/examples:${top_srcdir}/doc -AT3=${stagedir}/sbin/glite-lb-at3 -GENSAM=${top_srcdir}/examples/gen_sample_job -CHECK_VERSION:=VERSION=${version} VERSION_AHEAD=${VERSION_AHEAD} perl ${stagedir}/sbin/glite-lb-check_version.pl - -SUFFIXES = .T .l - -l_SRC = \ - chkpt.l \ - cleared.l \ - done.l \ - done_dag.l \ - done_subjob.l \ - ready.l \ - ready_dag.l \ - ready_subjob.l \ - running.l \ - running_dag.l \ - running_subjob.l \ - scheduled.l \ - scheduled_dag.l \ - scheduled_subjob.l \ - submitted.l \ - submitted_dag.l \ - submitted_subjob.l \ - waiting.l \ - waiting_dag.l \ - waiting_subjob.l \ - failed_dag.l \ - failed_subjob.l \ - aborted.l \ - cancelled.l \ - -# TODO: missing resubmission_deep -# shallow_resub_complex.l shallow_resub_simple.l shallow_resub_simple2.l \ -# resubmission.l resubmitted.l - - -sh_PROGS = $(l_SRC:.l=.sh) - -ifdef DEBUG - DEBUG:=-g -O0 -Wall -DEDG_WLL_LOG_STUB -else - DEBUG:=-g -O0 -Wall -endif - -ifdef LB_STANDALONE - LB_STANDALONE_FLAGS:=-DLB_STANDALONE -endif - -ifdef LB_PERF - LB_PERF_FLAGS:=-DLB_PERF - LB_PERF_TOOLS:=perftest_logjobs perftest_jobreg -endif -COMMON_LIB:=-lglite_lb_common_${nothrflavour} -COMMON_LIB_THR:=-lglite_lb_common_${thrflavour} -TRIO_LIB:=-lglite_lbu_trio - -CFLAGS:=${DEBUG} \ - -I. \ - -I${top_srcdir}/src -I${top_srcdir}/interface \ - -I${stagedir}/include \ - ${COVERAGE_FLAGS} \ - -DBUILDING_LB_CLIENT \ - -D_GNU_SOURCE ${LB_STANDALONE_FLAGS} ${LB_PERF_FLAGS} - -CXXFLAGS:=${CFLAGS} - -EXT_LIB:= - -TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit -TEST_INC:=-I${cppunit_prefix}/include - -# TODO: merge - check the 64bit stuff -# - and what about the new JOBID lib? -host_cpu:=${shell uname -m} -ifeq (${libdir},lib) - LDFLAGS:=-L${stagedir}/lib ${COVERAGE_FLAGS} -else - LDFLAGS:=-L${stagedir}/${libdir} -L${stagedir}/lib ${COVERAGE_FLAGS} -endif - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -CXXCOMPILE:=libtool --mode=compile ${CXX} ${CXXFLAGS} -LINK:=libtool --mode=link ${CC} ${LDFLAGS} -LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS} -INSTALL?=libtool --mode=install install - -LIBOBJS:=connection.o consumer.o notification.o prod_proto.o \ - producer.o uiwrap.o statistics.o - -PLUSOBJS:=Event.o Job.o JobStatus.o Notification.o ServerConnection.o stat_fields.o - -HDRS:=consumer.h notification.h statistics.h prod_proto.h connection.h \ - Job.h Notification.h ServerConnection.h stat_fields.h -GEN_HDRS:=Event.h JobStatus.h producer.h - -LIBTHROBJS:=${LIBOBJS:.o=.thr.o} -LIBLOBJS:=${LIBOBJS:.o=.lo} -LIBTHRLOBJS:=${LIBOBJS:.o=.thr.lo} - -PLUSTHROBJS:=${PLUSOBJS:.o=.thr.o} -PLUSLOBJS:=${PLUSOBJS:.o=.lo} -PLUSTHRLOBJS:=${PLUSOBJS:.o=.thr.lo} - -LIB:=libglite_lb_client_${nothrflavour}.la -THRLIB:=libglite_lb_client_${thrflavour}.la - -PLUSLIB:=libglite_lb_clientpp_${nothrflavour}.la -THRPLUSLIB:=libglite_lb_clientpp_${thrflavour}.la - -TOOLS:=${LB_PERF_TOOLS} -EXAMPLES_SRC:=log_usertag_proxy.c job_log.c job_reg.c feed_shark.c query_ext.c query_seq_code.c stats.c abort_job.c change_acl.c stresslog.c flood_proxy.c dagids.c stress_context.c parse_eventsfile.c test_changed_jdl.c -EXAMPLES:=${EXAMPLES_SRC:.c=} - -# TODO: migrate them here from branch_RC31_3 -# EXAMPLES_PLUS_SRC:=indexed_attrs_plus.cpp job_status_plus.cpp query_events_plus.cpp listener.cpp user_jobs_plus.cpp job_log_plus.cpp notify_plus.cpp -# EXAMPLES_PLUS:=${EXAMPLES_PLUS_SRC:.cpp=} - -EXAMPLES_CL_SRC:=user_jobs.c job_status.c multiple_user_jobs.c -EXAMPLES_CL:=${EXAMPLES_CL_SRC:.c=} - -EXAMPLES_CL_THR_SRC:=user_jobs_threaded.c -EXAMPLES_CL_THR:=${EXAMPLES_CL_THR_SRC:.c=} - -MAN_GZ:=glite-lb-logevent.1.gz glite-lb-notify.1.gz -MAN8_GZ:=glite-lb-dump.8.gz glite-lb-load.8.gz -MAN = $(MAN_GZ:.gz=) -MAN8 = $(MAN8_GZ:.gz=) - -PLUS_EXTRA_LIB:=-lglite_jobid - - -# version_info=-version-info `echo ${version} | cut -d. -f1,2 | tr . :` - -# counted minor versions: -offset=0 - -version_info:=-version-info ${shell \ - perl -e '$$,=":"; @F=split "\\.","${version}"; print $$F[0]+$$F[1]+${offset},$$F[2],$$F[1]' } - -ifdef LB_STANDALONE -compile all: generate ${LIB} ${THRLIB} ${TOOLS} logevent notify examples ${MAN_GZ} ${MAN8_GZ} -else -compile all: check_version generate ${LIB} ${THRLIB} ${PLUSLIB} ${THRPLUSLIB} ${TOOLS} logevent notify examples ${MAN_GZ} ${MAN8_GZ} -endif - -generate: ${GEN_HDRS} - -default: all - -${LIB}: ${LIBOBJS} - ${LINK} ${version_info} -o $@ ${LIBLOBJS} -rpath ${PREFIX}/${libdir} \ - ${COMMON_LIB} ${TRIO_LIB} \ - -lglite_security_gss_${nothrflavour} - -${THRLIB}: ${LIBTHROBJS} - ${LINK} ${version_info} -o $@ ${LIBTHRLOBJS} -rpath ${PREFIX}/${libdir} \ - ${COMMON_LIB_THR} ${TRIO_LIB} \ - -lglite_security_gss_${thrflavour} - -${PLUSLIB}: ${PLUSOBJS} ${LIB} - ${LINKXX} ${version_info} -o $@ ${PLUSLOBJS} -rpath ${PREFIX}/${libdir} ${LIB} ${PLUS_EXTRA_LIB} - -${THRPLUSLIB}: ${PLUSTHROBJS} ${THRLIB} - ${LINKXX} ${version_info} -o $@ ${PLUSTHRLOBJS} -rpath ${PREFIX}/${libdir} ${THRLIB} ${PLUS_EXTRA_LIB} - -logevent: logevent.o args.o - ${LINK} -o $@ logevent.o args.o ${LIB} ${EXT_LIB} - -notify: notify.o - ${LINKXX} -o $@ notify.o ${PLUSLIB} ${EXT_LIB} - -${TOOLS} ${EXAMPLES}: %: %.o - ${LINK} -o $@ $< ${LIB} ${EXT_LIB} - -${EXAMPLES_CL}: %: %.o - ${LINK} -o $@ $< ${LIB} ${COMMON_LIB} ${EXT_LIB} - -${EXAMPLES_CL_THR}: %: %.o - ${LINK} -o $@ $< ${THRLIB} ${COMMON_LIB_THR} ${EXT_LIB} - -${TOOLS}: ${LIB} - -${PLUSOBJS}: %.o: %.cpp - ${CXXCOMPILE} -c $< - -${PLUSTHROBJS}: %.thr.o: %.cpp - ${CXXCOMPILE} -o $@ -c $< - -${EXAMPLES_PLUS}: ${PLUSLIB} - -${EXAMPLES_PLUS}: %: %.o - ${LINKXX} -o $@ $< ${PLUSLIB} - -${LIBOBJS}: %.o: %.c - ${COMPILE} -c $< - -${LIBTHROBJS}: %.thr.o: %.c - ${COMPILE} -o $@ -c $< - -${MAN_GZ}: ${MAN} - rm -f ${MAN_GZ} ${MAN} - cp $? . - gzip -f $(notdir $?) - -${MAN8_GZ}: ${MAN8} - cp $? . - gzip -f $(notdir $?) - -perftest_logjobs.o: perftest_logjobs.c - ${CC} ${CFLAGS} -DLB_PERF_DROP -c $< - -# catches $TOOLS and logevent compilation -%.o: %.c - ${CC} ${CFLAGS} -c $< - -%.h: %.h.T - rm -f $@ - ${AT3} $< >$@ || ( rm -f $@; false ) - chmod -w $@ >/dev/null - -%.o: %.cpp - ${CXX} ${CFLAGS} ${GLOBUSINC} -c $< - -%.c: %.c.T - rm -f $@ - ${AT3} $< >$@ || ( rm -f $@; false ) - chmod -w $@ >/dev/null - -%.cpp: %.cpp.T - rm -f $@ - ${AT3} $< >$@ || ( rm -f $@; false ) - chmod -w $@ >/dev/null - -%.sh: %.l gen_begin gen_sample_job - rm -f $@ - -chmod +x ${GENSAM} - $(GENSAM) $< >$@ || rm -f $@ - chmod -w,+x $@ > /dev/null - -examples: ${EXAMPLES} ${EXAMPLES_PLUS} ${EXAMPLES_CL} ${EXAMPLES_CL_THR} ${sh_PROGS} - -check: compile -# shut up check.producer - -check.producer: producer_test - ./producer_test - -producer_test: producer_test.o prod_proto_test.o - ${LINKXX} -o $@ ${LIB} ${TEST_LIBS} $+ ${EXT_LIB} - -producer_test.o: %.o: %.cpp - ${CXX} -c ${CXXFLAGS} ${TEST_INC} $< - -man: ${MAN_GZ} ${MAN8_GZ} - -stage: compile - $(MAKE) install PREFIX=${stagedir} - -# TODO: restructuring - cleanup the documentation -doc: - -olddoc: generate - cp ${top_srcdir}/doc/*.dox . - echo "PROJECT_NUMBER = ${version}" >> C.dox - echo "PROJECT_NUMBER = ${version}" >> CPP.dox - doxygen C.dox - doxygen CPP.dox - -Event.h Event.cpp: EventAttrNames.pl - -JobStatus.h JobStatus.cpp: StatusAttrNames.pl - -#EventAttrNames.pl: -# rm -f $@ -# ln -s ${stagedir}/share/perl/gLite/LB/$@ $@ - -dist: distsrc distbin - -install: - mkdir -p ${PREFIX}/bin - mkdir -p ${PREFIX}/sbin - mkdir -p ${PREFIX}/include/${globalprefix}/${lbprefix} - mkdir -p ${PREFIX}/${libdir} - mkdir -p ${PREFIX}/share/doc/${package}-${version}/api - mkdir -p ${PREFIX}/share/doc/${package}-${version}/examples - mkdir -p ${PREFIX}/share/man/man1 - mkdir -p ${PREFIX}/examples - mkdir -p ${PREFIX}/share/man/man8 - mkdir -p ${PREFIX}/share/build/m4 -ifdef LB_STANDALONE - ${INSTALL} -m 644 ${LIB} ${THRLIB} ${PREFIX}/${libdir} -else - ${INSTALL} -m 644 ${LIB} ${THRLIB} ${PLUSLIB} ${THRPLUSLIB} ${PREFIX}/${libdir} - ${INSTALL} -m 644 ${LIB} ${THRLIB} ${PREFIX}/${libdir} -endif - ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} - ( cd ${top_srcdir}/project && ${INSTALL} -m 644 ChangeLog package.description package.summary ${PREFIX}/share/doc/${package}-${version} ) - ${INSTALL} -m 644 ${top_srcdir}/doc/README-notify ${PREFIX}/share/doc/${package}-${version} - (cd ${top_srcdir}/interface && ${INSTALL} -m 644 ${HDRS} ${PREFIX}/include/${globalprefix}/${lbprefix}) - ${INSTALL} -m 644 ${GEN_HDRS} ${PREFIX}/include/${globalprefix}/${lbprefix} -ifndef LB_STANDALONE -# cp -r C CPP ${PREFIX}/share/doc/${package}-${version} -# cp -r ${top_srcdir}/doc/api/{Makefile,api.tex,fig} ${PREFIX}/share/doc/${package}-${version}/api -endif - for p in logevent notify; do \ - ${INSTALL} -m 755 "$$p" "${PREFIX}/bin/glite-lb-$$p"; \ - done - for p in ${TOOLS} ; do \ - ${INSTALL} -m 755 "$$p" "${PREFIX}/sbin/glite-lb-$$p"; \ - done -# TODO: restructuring - do we really need binaries of the examples to be installed? - for p in ${EXAMPLES} ${EXAMPLES_PLUS} ${EXAMPLES_CL} ${EXAMPLES_CL_THR} ${sh_PROGS} ; do \ - ${INSTALL} -m 755 "$$p" "${PREFIX}/examples/glite-lb-$$p"; \ - done - for p in ${EXAMPLES_SRC} ${EXAMPLES_PLUS_SRC} ${EXAMPLES_CL_SRC} ${EXAMPLES_CL_THR_SRC} ; do \ - ${INSTALL} -m 644 "${top_srcdir}/examples/$$p" "${PREFIX}/share/doc/${package}-${version}/examples/"; \ - done - ${INSTALL} -m 644 ${top_srcdir}/examples/Makefile "${PREFIX}/share/doc/${package}-${version}/examples/" - ${INSTALL} -m 644 ${top_srcdir}/examples/README.examples "${PREFIX}/share/doc/${package}-${version}/examples/" - ${INSTALL} -m 755 ${top_srcdir}/src/export.sh "${PREFIX}/sbin/glite-lb-export.sh" - ${INSTALL} -m 755 ${top_srcdir}/examples/notify.pl ${PREFIX}/examples/glite-lb-notify.pl - ${INSTALL} -m 644 ${MAN_GZ} ${PREFIX}/share/man/man1 - ${INSTALL} -m 644 ${MAN8_GZ} ${PREFIX}/share/man/man8 - sed "s/%LIBDIR%/${libdir}/" ${top_srcdir}/m4/glite_lb_client.m4 > glite_lb_client.m4 - ${INSTALL} -m 644 glite_lb_client.m4 ${PREFIX}/share/build/m4/ - -clean: - rm -rvf *.o *.lo .libs lib* *.c *.cpp *.h *.dox producer_test notify C/ CPP/ - rm -rvf ${LIB} ${THRLIB} ${TOOLS} logevent ${PLUSLIB} ${THRPLUSLIB} ${MAN_GZ} ${MAN8_GZ} - rm -rvf ${EXAMPLES} ${EXAMPLES_CL} ${EXAMPLES_CL_THR} ${sh_PROGS} - rm -f EventAttrNames.pl - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - -check_version: - ${CHECK_VERSION} ${stagedir}/include/glite/lb/common_version.h - - -.PHONY: default all compile examples check stage install clean check_version diff --git a/org.glite.lb.client/build.xml b/org.glite.lb.client/build.xml deleted file mode 100755 index 60d35dc..0000000 --- a/org.glite.lb.client/build.xml +++ /dev/null @@ -1,144 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb.client/configure b/org.glite.lb.client/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lb.client/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lb.client/doc/C.dox b/org.glite.lb.client/doc/C.dox deleted file mode 100644 index d4b6920..0000000 --- a/org.glite.lb.client/doc/C.dox +++ /dev/null @@ -1,17 +0,0 @@ -PROJECT_NAME = "Glite LB Client: C - Interface" -OUTPUT_DIRECTORY = C -OPTIMIZE_OUTPUT_FOR_C = YES -INPUT = ./producer.h \ - ../interface/notification.h \ - ../interface/consumer.h -SHOW_DIRECTORIES = NO -FULL_PATH_NAMES = NO -EXTRACT_ALL = YES -PDF_HYPERLINKS = YES -USE_PDFLATEX = YES -MACRO_EXPANSION = YES -EXPAND_ONLY_PREDEF = YES -PREDEFINED = _EDG_WLL_EVENT_COMMON -HAVE_DOT = NO -GENERATE_MAN = YES -MAN_LINKS = NO diff --git a/org.glite.lb.client/doc/CPP.dox b/org.glite.lb.client/doc/CPP.dox deleted file mode 100644 index a402bbe..0000000 --- a/org.glite.lb.client/doc/CPP.dox +++ /dev/null @@ -1,15 +0,0 @@ -PROJECT_NAME = "Glite LB Client: CPP - Interface" -OUTPUT_DIRECTORY = CPP -INPUT = JobStatus.h \ - ../interface/Job.h \ - ../interface/ServerConnection.h \ - ../interface/Notification.h -SHOW_DIRECTORIES = NO -FULL_PATH_NAMES = NO -EXTRACT_ALL = YES -PDF_HYPERLINKS = YES -USE_PDFLATEX = YES -#HAVE_DOT = YES -#CALL_GRAPH = YES -GENERATE_MAN = YES -MAN_LINKS = NO diff --git a/org.glite.lb.client/doc/README-notify b/org.glite.lb.client/doc/README-notify deleted file mode 100644 index 3411208..0000000 --- a/org.glite.lb.client/doc/README-notify +++ /dev/null @@ -1,106 +0,0 @@ -LB notifications ----------------- - -LB infrastructure enables its users to be notified when something interesting happens on a LB server (typically job status change). It enables the user not to poll LB server periodically to find out whatever he/she is interesting in but confortable wait and let the server itself inform you. If user wants to receive the notifications, he/she must first register to the LB notification infarastructure. - -User registers via some notification client. (program that uses LB client API to handle notifications). He/she must specify a condition under which the notification is sent. For example - job XY reaches status DONE. Currently, one or more JOBID's are required in the condition and only a single occurence of a specific attribute is allowed among ANDed conditions. The condition is then delivered to LB server where it is stored. At the same time, server generates an unique notification ID for such registration and returns it to the user. - -The registration exists only for limited amount of time. The validity is returned by LB server together with notification ID when registering. During this period user can attach to server and receive notifications, change conditions which triger notification, prolong validity of the registration, or remove the registration from LB server. For all such operation you have to supply the notification ID. - - -While the registration is valid, user is able repeatable connect to LB server from different places in the net and continue receiving notifications associated with given notification ID. Notifications generated during the time you are not receiving them are stored and waiting when you reconnect. When you reconnect from another place (another IP or PORT), you will receive all not delivered notifications and continue receiving new ones. - - -How does it work? ------------------ - -The request for notification is delivered to LB server. The notification condition specified in the request is stored in LB database and whenever a new event arrives to the LB server, all notification conditions are tested. Always when some of them is true, corresponding notification is sent. - -For a notification delivery, a special deamon, a notification interlogger is used. It stores notifications in files and periodically tries to deliver them to the adress of the last connection of notification client. If the user changes the place (IP or PORT) where the client listens, LB server instuct the notification deamon to change delivery destination of all pending notifications. - - - -Notification test ------------------ - -Steps bellow describe basic testing procedure of the notification -system by creating a fake job record in the LB server, registering -a notification on any state change of this job, and forcing the job state -change. - -Our example program 'glite-lb-notify' is used as a notification -client here. It uses mentioned client API calls to manipulate with -registrations. - -LB server supporting notifications is running on skurut68-2.cesnet.cz:9100, -local-logger used for sending of events (there's no need to run it on the same -host) on skurut68-2.cesnet.cz:9002. - -1) Register a job - examples/glite-lb-job_reg -m skurut68-2.cesnet.cz:9100 -s UserInterface - - -> returns jobid and sequence code used in next steps - -EDG_JOBID="https://skurut68-2.cesnet.cz:9100/D1qbFGwvXLnd927JOcja1Q" -EDG_WL_SEQUENCE="UI=000002:NS=0000000000:WM=000000:BH=0000000000:JSS=000000:LM=000000:LRMS=000000:APP=000000:LBS=000000" - - -2) Create notification for this jobid - - GLITE_WMS_NOTIF_SERVER=skurut68-2.cesnet.cz:9100 bin/glite-lb-notify -new -j https://skurut68-2.cesnet.cz:9100/D1qbFGwvXLnd927JOcja1Q - - -> returns notification id - notification ID: https://skurut68-2.cesnet.cz:9100/NOTIF:tOsgB19Wz-M884anZufyUw - -3) Start process waiting for notifications on job state change - - GLITE_WMS_NOTIF_SERVER=skurut68-2.cesnet.cz:9100 bin/glite-lb-notify -receive -i 120 https://skurut68-2.cesnet.cz:9100/NOTIF:tOsgB19Wz-M884anZufyUw - -4) Change status of your job - -4a) - - using glite-lb-logevent (sequence code passed from glite-lb-job_reg - and between glite-lb-logevent calls - - GLITE_WMS_LOG_DESTINATION=skurut68-2.cesnet.cz:9002 bin/glite-lb-logevent \ - -j https://skurut68-2.cesnet.cz:9100/D1qbFGwvXLnd927JOcja1Q \ - -e Running -s LogMonitor --node hokus \ - -c "UI=000002:NS=0000000000:WM=000000:BH=0000000000:JSS=000000:LM=000000:LRMS=000000:APP=000000:LBS=000000" - - -> returns seq. code for later usage: - UI=000002:NS=0000000000:WM=000000:BH=0000000000:JSS=000000:LM=000002:LRMS=000000:APP=000000:LBS=000000 - - - GLITE_WMS_LOG_DESTINATION=skurut68-2.cesnet.cz:9002 bin/glite-lb-logevent \ - -j https://skurut68-2.cesnet.cz:9100/D1qbFGwvXLnd927JOcja1Q \ - -e Done -s LogMonitor --status_code=OK --reason="hotovo" --exit_code=0 \ - -c "UI=000002:NS=0000000000:WM=000000:BH=0000000000:JSS=000000:LM=000002:LRMS=000000:APP=000000:LBS=000000" - - -> returns - UI=000002:NS=0000000000:WM=000000:BH=0000000000:JSS=000000:LM=000004:LRMS=000000:APP=000000:LBS=000000 - -4b) - - using examples/glite-lb-running.sh (sends corresponding set of events): - - GLITE_WMS_LOG_DESTINATION=skurut68-2.cesnet.cz:9002 \ - examples/glite-lb-running.sh \ - -j https://skurut68-2.cesnet.cz:9100/D1qbFGwvXLnd927JOcja1Q - -5) Watch incomming notifications. - - You should receive several notification, each correspondig - with job status change: - -https://skurut68-2.cesnet.cz:9100/D1qbFGwvXLnd927JOcja1Q Running /DC=cz/DC=cesnet-ca/O=Masaryk University/CN=Miroslav Ruda - -https://skurut68-2.cesnet.cz:9100/D1qbFGwvXLnd927JOcja1Q Done /DC=cz/DC=cesnet-ca/O=Masaryk University/CN=Miroslav Ruda - - -When you let notification client running several minutes without any incomming notification, it will finish and remove your registration from the server automatically. - -6) Destroy notification - - GLITE_WMS_NOTIF_SERVER=skurut68-2.cesnet.cz:9100 bin/glite-lb-notify \ - drop https://skurut68-2.cesnet.cz:9100/D1qbFGwvXLnd927JOcja1Q diff --git a/org.glite.lb.client/doc/api/Makefile b/org.glite.lb.client/doc/api/Makefile deleted file mode 100755 index 6a6f660..0000000 --- a/org.glite.lb.client/doc/api/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# Makefile for LaTeX, EGEE-JRA1-Testplan - -DOCUMENT=api -DELIVERY=TEMPLATE-$(VERSION) -SRC=. -STYLEPATH := $(SRC)/../../../org.glite.templates-latex-style -VERSION=`cat $(SRC)/VERSION` - -include $(STYLEPATH)/Makefile.template diff --git a/org.glite.lb.client/doc/api/api.tex b/org.glite.lb.client/doc/api/api.tex deleted file mode 100644 index 48aa4d7..0000000 --- a/org.glite.lb.client/doc/api/api.tex +++ /dev/null @@ -1,1800 +0,0 @@ -\documentclass{egee} - -\usepackage{graphicx} -\usepackage{amsbsy} -\usepackage{xspace} - -\ifx\pdfoutput\undefined -\def\driver{dvips} -\def\vsuffix{eps} -\let\bsuffix=\vsuffix -\else -\def\driver{pdftex} -\def\vsuffix{pdf} -\def\bsuffix{jpg} -\fi - -\def\LB{L\&B\xspace} -\def\ie{i.\,e.\xspace} -\def\eg{e.\,g.\xspace} -\def\wrt{w.\,r.\,t.\xspace} -%\def\labelitemi{\textbf{--}} - - -\title{\LB API Reference} -\DocIdentifier{EGEE-doc-identifier} -\Date{\today} -\Activity{JRA1: Middleware} -\DocStatus{DRAFT} -\Subtitle{just to show everything works} %No SubTitle -\Dissemination{PUBLIC} -\DocumentLink{http://cern.ch} -\Abstract{% -\LB API reference. -} - - -\begin{document} - -\parindent=0pt -\parskip=\smallskipamount - -\tableofcontents - -\makeatletter -\def\jobid{\textit{JobId}\xspace} -\def\@tti[#1]{\item[{\normalfont\texttt{#1}}]\catcode`\_=8} -\def\tti{\catcode`\_=11\noexpand\@tti} -\newlength{\tw} - -\def\synopsis{\catcode`\_=11\noexpand\@synopsis} -\def\@synopsis#1#2{ -\tw=\linewidth -\advance\tw-2em -\texttt{#1(}\\ -\strut\hskip2em\begin{tabularx}\tw{>{\begingroup\tt}l<{\endgroup}lX} -#2 -\end{tabularx}\\ -\texttt) -\catcode`\_=8 -} - -\def\Synopsis{\subsubsection*{Synopsis}} -\def\Description{\subsubsection*{Description}} -\def\Return{\subsubsection*{Return values}} - -\begin{thebibliography}{9} -\bibitem[R1]{lbarch}\emph{\LB Architecture release 2}, DataGrid-01-TED-0141. -\bibitem[R2]{lbdraft}\emph{Logging and Bookkeeping Service for the DataGrid}, -DataGrid-01-TEN-0109. -\bibitem[R3]{lbdraft2} -\emph{Logging and Bookkeeping Service for the DataGrid, release~2}, -DataGrid-01-TEN-0132. -\bibitem[R4]{lbadvanced} -\emph{\LB Advanced Queries Extensions}, -DataGrid-01-TEN-0125. -\bibitem[R5]{naming}\emph{Naming Conventions}, DataGrid-12-D12.2-0201. -\bibitem[R6]{draft-abela}\emph{draft-abela-ulm-05}. - -\end{thebibliography} - -\section*{Purpose of this Document} -This document provides a~consistent overview of the API to the \LB (logging and bookkeeping) service of WMS (workload management system) of the EU Datagrid -middleware. -It is inteded for both WP1 developers using the service, -as well as WP1-external users. - -This document obsoletes previous documents providing the API -description~\cite{lbdraft,lbadvanced} and the respecive sections -of~\cite{lbdraft2}. - -\newpage - -\section{\LB Service Overview} -It is not a~purpose of this document to discuss architecture issues of -the \LB service. -However, we provide a~brief overview so that this document is more or less -self-contained. -Further details can be found in~\cite{lbdraft2} and mainly in~\cite{lbarch}. - -Purpose of the service is monitoring a~job from being submitted to the WMS, -going through various stages of planning its execution, being run, -and finally either successfully or unsuccessfully terminating. -End users are able to query the service in order to get information on -an overall status of their jobs, as well as detailed logging information. - -The service works with the following principal data entities: -\begin{description} -\item[Job] corresponds to a~user job (unit task) being submitted to the WMS. -A job is referenced with a~unique identifier -- \jobid. -\item[Event] is a~unit record on anything significant \wrt job life, \eg\ its -submission, assignment of a~suitable computing resource, starting execution -etc. An event is always uniquely associated to a~particular job. -\end{description} - -\begin{figure} -\begin{center} -\includegraphics[width=.8\hsize]{fig/logging-arch.\vsuffix} -\end{center} -\caption{\LB service architecture} -\textbf{FIXME: make it up to date} -\label{f:arch} -\end{figure} - -Figure~\ref{f:arch} shows principal components of the \LB service -and data flow among them. - -\textbf{TODO: daemons, dataflow} - -\subsection{Events} -\label{s:events} - -Every event carries event type and information necessary for identifying the -time and origin of the event (\jobid and string identifying the event -sender). In addition, in release~2, every event includes its sequence code (generated by logging library -when the event is logged, see Sect.~\ref{s:sequence}). -Event type determines additional -data that the event contains. Event types are as follows (because there are many -changes and clarifications since release~1, we list all event types including those with unchanged -type-specific data items): - -\def\jobregister{\emph{Job\-Register}} -\def\jobtransfer{\emph{Job\-Transfer}} -\def\jobaccepted{\emph{Job\-Accepted}} -\def\jobrefused{\emph{Job\-Re\-fused}} -\def\jobenqueue{\emph{Job\-EnQueued}} -\def\jobdequeue{\emph{Job\-DeQueued}} - -\def\helpercall{\emph{Helper\-Call}} -\def\helperret{\emph{Helper\-Return}} - -\def\txfrev{\jobtransfer, \jobaccepted, \jobrefused} - -\def\jobpending{\emph{Job\-Pending}} -\def\jobmatch{\emph{Job\-Match}} - -\def\jobpurge{\emph{Job\-Purge}} -\def\jobabort{\emph{Job\-Abort}} -\def\jobcancel{\emph{Job\-Cancel}} -\def\jobrun{\emph{Job\-Run\-ning}} -\def\jobdone{\emph{Job\-Done}} -\def\jobcleared{\emph{Job\-Cleared}} -\def\jobresub{\emph{Job\-Resubmission}} - -\def\jobchkpt{\emph{Job\-Chkpt}} -\def\joblistener{\emph{Job\-Listener}} -\def\jobcurjdl{\emph{Job\-Cur\-Descr}} - -\subsubsection{Job transfer between components} - -\begin{description} - -\item[\jobtransfer] -- The sender of this event attempted to transfer a~job -to some other component via extenal interface, \eg UI to Network Server or JSS to Condor-G. -This event contains identification of the -other component which the job is being sent to (component name, hostname and network port number) and possibly the job -description being transferred in language this component accepts (job description for NS, RSL -for Globus job-manager, ClassAd for Condor-G). -Result, \ie{} success or failure, of the transfer (as seen by the sender) -and new internal job ID assigned by the other component (if known) must be included. Following result codes are recognized: -\begin{itemize} -\item START -- the sending component has started or is about to start the transfer -\item OK -- job was sent successfully -\item REFUSED -- job was refused by the other component -\item FAIL -- transfer failed for other reason than explicit refusal (\eg network timeout) -\end{itemize} - -\item[\jobaccepted] -- Receiving component accepted the job via external interface. This -event pairs with \jobtransfer\ and should contain identification of the sending component (if possible) and the locally assigned job id (Condor, Globus, \dots). -This event is issued by the receiving component where possible (on JSS to Condor-G transfer, Log Monitor should log this event). - -\item[\jobrefused] -- Receiving component could not accept the job, the reason being a part of the event. - -\item[\jobenqueue] -- The job is inserted into a queue, \eg the queue holding the job after it is received by Network Server and before it is processed by Workload Manager. The data items are the same as in \jobtransfer\ except new internal job ID is not present and the destination is interpreted as queue name. - -\item[\jobdequeue] -- The job is removed from queue. The data items are the same as in \jobaccepted. - -\item[\helpercall] -- Helper component is called during the job processing. The type-specific data include -the name of called Helper, whether the logging component is called or calling one, and optionally parameters -passed to the Helper. - -\item[\helperret] -- Call to Helper returns. The type-specific data include -the name of called Helper, whether the logging component is called or calling one, and optionally -the return data from the Helper (\ie\ modified ClassAd or description of modifications to the input ClassAd). -\end{description} - - -\subsubsection{Job state changes during processing inside a component} - -\begin{description} -\item[\jobrun] -- The job was started on the selected computing element -(its node) by the local resource management system. -\item[\jobresub] -- Reports the result of resubmission decision after the job has failed. Data items include -the result (will/won't be resubmitted), the reason string, and tag -- value of the attribute on which the decision is based. -\item[\jobdone] -- Job has exited, has been successfully cancelled or is considered to be in terminal state by Condor-G. -This event contains status code: -\begin{itemize} -\item OK -- the job has completed successfully from the point of view of WMS -(Unix return code can be non-zero) -\item FAIL -- the job has failed to run -\item CANCELLED -- the job was cancelled by user request -\end{itemize} -In addition to status code, reason for the change (especially with FAIL status code) and process exit code should be filled in, if available. -\item[\jobcancel] -- Cancel operation has been attempted on the job. The event -carries the status code: -\begin{itemize} -\item REQ -- request acknowledged -\item REFUSE -- request declined by this component -\item DONE -- request completed by whole WMS -\item ABORT -- request refused by whole WMS -\end{itemize} -Reason string is also included. -\item[\jobabort] -- Job processing was stopped by WMS due to error condition, the event contains the reason for abort. -\item[\jobcleared] -- Job results (output files) were handed over to the user; all temporary files were removed. -\item[\jobpurge] -- Generated when the job is purged from bookkeping server's database. This event is stored only in -a logging server. -\end{description} - - -\subsubsection{Workload Manager or Helpers} - -\begin{description} -\item[\jobmatch] -- Appriopriate match (\ie\ the CE) was found. -This event contains the ID of selected CE. -\item[\jobpending] -- This event is logged by WM when there was no match -found for given job (\eg\ not enough information was found, requested -resources are not available at the moment, job dependency condition is not -satisfied) and the job is going to be requeued. -The event describes reason why the jobs remains in the queue. -\end{description} - -\subsubsection{Store special information in \LB} -\begin{description} -\item[\jobregister] -- Logged by job creator (UI or Job Partitioner) in order to register the job -or its subjobs with bookkeeping server. This event includes the job description (JDL), parent job ID -(if subjob), number of subjobs to create in \LB, and the seed for subjob ID generation. This event -should be logged synchronously for a job that is not a subjob of another job. - -\item[\jobchkpt] -- An application-specific checkpoint was created (logged by checkpointing API). -Checkpoint tag and ClassAd strings should be included. -\item[\joblistener] -- Use by UI to store listener network port information for interactive jobs. -Listener port number, hostname and service name (multiple ports can be advertised) must be included. -\item[\jobcurjdl] -- This optional event can be used to report ClassAd describing the current -state of job processing (output from Helper modules). -\end{description} - -\subsection{Event sources} -The following table describes which events should be logged by -particular workload management architecture components: -\\ - -{\raggedright - -%\begin{table}[h] -\newlength\kratsi -\setlength{\kratsi}{\textwidth} -\addtolength{\kratsi}{-5mm} -\begin{tabularx}{\kratsi}{@{}lX} -UI & \jobregister, \joblistener, \jobtransfer, \jobcancel, \jobabort \\ -NS & \jobaccepted, \jobrefused, \jobenqueue, \jobcancel, \jobabort \\ -WM & \jobdequeue, \helpercall, \helperret, \jobenqueue, \jobpending, \jobcurjdl, \jobcancel, \jobabort \\ -Helper & \helpercall, \helperret, \jobcurjdl, \jobmatch \\ -JSS & \jobdequeue, \jobtransfer, \jobcancel, \jobabort \\ -LM & \jobtransfer, \jobaccepted, \jobrefused, \jobrun, \jobresub, \jobenqueue, \jobdone, \jobcancel, \jobabort \\ -user app. (CE) & \jobchkpt \\ -Job Wrapper & optionally \jobrun, \jobdone \\ -sandbox storage & \jobcleared \\ -bkserver & \jobpurge\\ -\end{tabularx} -%\end{table} -}% end of \raggedright - -\subsection{Job Status} -\label{s:status} -During its life within WMS a~job passes a~sequence of \emph{job states}. -The following lists briefly describes all possible states. -\begin{description} -\item[\em Submitted] -- Job is entered by the user to the User Interface or registered by Job Partitioner but not yet transferred to Network Server for processing or not yet processed by DAGMan (if subjob) -\item[\em Waiting] -- Job has been accepted by NS and is waiting for Workload Manager processing or is being processed by WM or DAGMan's Helpers -(\eg WM is busy, no appropriate Computing\-Element (cluster) has been found yet, required dataset is not -available, job is waiting for resource allocation) -\item[\em Ready] -- The job has been processed by WM or DAGMan and their Helper modules (especially, appropriate ComputingElement has been found) but not yet transferred to the Computing Element (local batch system queue) via Job Submission Service and Condor-G -\item[\em Scheduled] -- Job is waiting in the queue on the ComputingElement (this state never occurs with DAG/partitioned job) -\item[\em Running] -- Job is running or DAGMan is processing its subjobs (if the job is DAG/partitioned) -\item[\em Done] -- Job has exited or is considered to be in a terminal state by Condor-G (\eg submission to CE has failed in an unrecoverable way). -This also includes user-initiated cancellation of the job. -\item[\em Aborted] -- Job processing was aborted by WMS (waiting in the Workload Manager queue or ComputingElement for too long, over-use of quotas, expiration of -user credentials,~\ldots) -%\item[\em Cancelled] -- Job has been successfully cancelled by user request -\item[\em Cleared] -- Output sandbox was transferred to the user or removed due to the timeout - -\end{description} - -\section{API Design} - -\subsection{General Conventions} - -\textbf{TODO} - -\subsubsection{Return values} -The return type of most of the API functions is return \verb'int'. -Unless specified otherwise the returned values are as follows: -\begin{description} -\item[0] success -\item[errno] an error occured, the nature of the error -matches meaning of one of standard \verb'' error codes. -\item[\LB specific] a~few errors can't be intuitively mapped to \verb'', therefore the are specific \LB error codes, starting from \verb'EDG_WLL_ERROR_BASE'. -\end{description} -See Sect.~\ref{s:error} for details on error handling. - -Few API function return \verb'char *'. In such a~case \verb'NULL' indicates -an error, non-null value means success. - -\subsection{Function arguments} -In the following description the function arguments are classified as follows: -\begin{description} -\item[IN] pure input argument, not modified by the function. -If it is a~pointer, the C prototype includes \verb'const' (which is omitted in -this document for the sake of readability). -\item[OUT] pure output argument. The function expects a~pointer and fills in -the pointed object. - -If the argument is \verb'**', or a~structure containing pointers, -the returned objects are \emph{always} dynamically allocated, -and has to be freed when not used anymore. -The same holds for directly returned pointers. - -\item[INOUT] an argument taken as an input and modified by the function. -Typically it is the \LB context. - -\end{description} - -\subsubsection{Datatypes} -The API uses two classes of custom datatypes: -\begin{description} -\item[opaque types] (\eg context, jobid) do not expose their structure -to the user. -The only way to access them is via the API functions. -The internal structure of those may be subject to change. - -\item[transparent types] (\eg event, status) expose the structure to the -user. The structure is documented and no incompatible changes will be done -without notice. -\end{description} - -\subsection{Job Identifier} -Handling of the \jobid is not restricted to the \LB subsystem only, -it belongs to the common part of the entire WMS software. -However, it is stronly related to the \LB service, therefore we describe -it here for completness. - -\textbf{TODO} - -\iffalse -\subsubsection{Interface} -%\code{\#include "edg/workload/common/jobid/jobid.h"} - -\subsubsection{Datatypes} -\begin{description} -\tti[edg_wlc_JobId] Representation of the \jobid. -Opaque type, it's contents is hidden to the API users and should be -manipulated with the access methods only. -\end{description} -\subsubsection{Functions} -\fi - - - - -\subsection{Context and Parameter Settings} -\label{s:context} - -All the API functions refer to a~\emph{context} argument. -The context type \verb'edg_wll_Context' is opaque. -Context objects preserve various status information -(\eg\ connection to server) among the API calls. -The API caller can create many context objects, those are guaranteed -to be independent on one another. -In this way thread-safety of the library is achieved -- -one context object has to be used by only one thread at time. - -Context is used to set and keep various parameters of the library -(\eg\ default server addresses, timeouts, \dots). -Upon initialization, all the parameters are assinged default values. -However, many of the parameters take their default value from environment -variables. If the corresponding environment variable is set, -the parameter is initialized to its value instead of the default. -Note that a~few parameters cannot be assigned default value; consequently -setting them either in environment or with an explicit API call -is mandatory before using the appropriate part of the API. - -The context also stores details on errors of the recent API call. - -For use with the \emph{producer} calls (see Sect.~\ref{s:producer}) -the context has to be assigned a~single \jobid -(with the \verb'edg_wll_SetLoggingJob' call, see Sect.~\ref{s:sequence}), -and keeps track of an event \emph{sequence code} for the job -(detailed description in~\cite{lbarch}). - -\Synopsis -\synopsis{int edg_wll_InitContext}{ -edg_wll_Context *&OUT&context to be initialized -} - -\synopsis{void edg_wll_FreeContext}{ -edg_wll_Context&IN&context to be freed -} -% -\Description -\verb'edg_wll_InitContext' allocates and initializes a~new context object. -\verb'edg_wll_FreeContext' performs the necessary cleanup (closing pending -connections etc.) and destroys the object. -% -\Return -\verb'edg_wll_InitContext' returns 0 on success, -ENOMEM if \verb'malloc' fails. - -\Synopsis - -\synopsis{int edg_wll_SetParam}{ -edg_wll_Context context & INOUT & context to operate on\\ -edg_wll_ContextParam param & IN & parameter to set (see bellow) \\ -\dots & IN & parameter value to set\\ -} - -\synopsis{int edg_wll_GetParam}{ -edg_wll_Context context & INOUT & context to operate on\\ -edg_wll_ContextParam param & IN & parameter to get (see bellow) \\ -\dots & OUT & pointer to output variable\\ -} - -\Description -\verb'edg_wll_SetParam' sets a~context parameter to a~given value. -If the value is NULL (pointer type) or 0 (int), the parameter is reset -to its default value (or the value given by environment variable), -in exactly the same way as on context initialization. - -\verb'edg_wll_GetParam' retrieves the current value of the parameter. -Even if it is a~default, an actual value is always returned, not NULL or 0. - -All the context parameters are described in the following list. -\def\paritem[#1]{\item[\normalfont EDG\_WLL\_PARAM\_#1]\leavevmode\hbox{}\\} -\begin{quote} -\begin{description} -\paritem[HOST] -Hostname that will appear as the source of generated events. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'char *'\\ -Default& return value of \verb'gethostname'\\ -Environment& GLOBUS\_HOSTNAME -\end{tabularx} - -\paritem[SOURCE] -Identification of the service which is logging: -\begin{itemize} -\item EDG\_WLL\_SOURCE\_USER\_INTERFACE -\item EDG\_WLL\_SOURCE\_NETWORK\_SERVER -\item EDG\_WLL\_SOURCE\_WORKLOAD\_MANAGER -\item EDG\_WLL\_SOURCE\_BIG\_HELPER -\item EDG\_WLL\_SOURCE\_JOB\_SUBMISSION -\item EDG\_WLL\_SOURCE\_LOG\_MONITOR -\item EDG\_WLL\_SOURCE\_LRMS -\item EDG\_WLL\_SOURCE\_APPLICATION -\end{itemize} - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'edg_wll_Source'\\ -Default& N/A, hence it must be set before any producer call\\ -Environment& EDG\_WLL\_LOG\_SOURCE -(split according to the pattern ``source[/instance]'' eventually) -\end{tabularx} - -\paritem[INSTANCE] -Identification of an instance of the service -if more than one may appear on a~single host. -In case of EDG\_WLL\_SOURCE\_APPLICATION the instance is supposed to -identify the concrete application too. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'char *'\\ -Default& N/A\\ -Environment& EDG\_WLL\_LOG\_SOURCE -(split according to the pattern ``source/instance'')\\ -\end{tabularx} - -\paritem[LEVEL] -Logging level, \ie\ severity of messages. Supported values -are: -\begin{itemize} -\item EDG\_WLL\_LOG\_SYSTEM -- \LB system important events, -\item EDG\_WLL\_LOG\_DEBUG -- debugging and informational events. -\end{itemize} - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'edg_wll_Lvl'\\ -Default& EDG\_WLL\_LOG\_SYSTEM\\ -Environment& N/A -\end{tabularx} - -\paritem[DESTINATION] -Name of the host where to send the events, \ie\ the local-logger machine. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'char *'\\ -Default& localhost\\ -Environment& EDG\_WLL\_LOG\_DESTINATION (split accorting to the pattern -``hostname[:port]'') -\end{tabularx} - -\paritem[DESTINATION\_PORT] -Port where the local-logger listens. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'int'\\ -Default& 9002\\ -Environment& EDG\_WLL\_LOG\_DESTINATION (split accorting to the pattern -``hostname[:port]'') -\end{tabularx} - -\paritem[LOG\_TIMEOUT] -Timeout for asynchronous logging calls. -Theoretically, it's not possible to set infinite timeout, -however, we suppose that the maximal possible value of \verb'struct timeval' -is sufficient. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'struct timeval *'\\ -Default& \textbf{TODO}\\ -Environment& EDG\_WLL\_LOG\_TIMEOUT -\end{tabularx} - -\paritem[LOG\_SYNC\_TIMOUT] -Timeout for synchronous logging calls. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'struct timeval *'\\ -Default& \textbf{TODO}\\ -Environment& EDG\_WLL\_LOG\_SYNC\_TIMEOUT -\end{tabularx} - -\paritem[QUERY\_SERVER] -Hostname of the \LB server to query, -applicable only for calls which do not specify \jobid explicitely. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'char *'\\ -Default& N/A, hence must be set before a~call which requires the value\\ -Environment& EDG\_WLL\_QUERY\_SERVER (split according to the pattern -``hostname[:port]'' eventually) -\end{tabularx} - -\paritem[QUERY\_SERVER\_PORT] -\LB server port. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'int'\\ -Default& 9000\\ -Environment& EDG\_WLL\_QUERY\_SERVER (split according to the pattern -``hostname[:port]'')\\ -\end{tabularx} - -\paritem[QUERY\_TIMEOUT] -Maximal time to wait for a~response to a~query. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'struct timeval *query_timeout'\\ -Default& \textbf{TODO}\\ -Environment& EDG\_WLL\_QUERY\_TIMEOUT -\end{tabularx} - -\paritem[QUERY\_LIMIT] -Maximal number of records that a~query may return. -It is used to prevent overloading both server and network by queries that -may return unusably huge datasets. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'int'\\ -Default& unlimited\\ -Environment& N/A -\end{tabularx} - -\paritem[X509\_PROXY] -X509 proxy credentials file for logging or querying authentication. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'char *'\\ -Default& GSI credential search mechanism is applied\\ -Environment& X509\_USER\_PROXY -\end{tabularx} - -\paritem[X509\_KEY] -X509 key file to use for logging or querying authentication. -X509\_CERT has to be set to a~matching certificate file. -If X509\_PROXY is set, X509\_KEY and X509\_CERT parameters are ignored. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'char *'\\ -Default& GSI credential search mechanism is applied\\ -Environment& X509\_USER\_KEY -\end{tabularx} - -\paritem[X509\_CERT] -X509 certificate file for logging or querying authentication. -X509\_KEY has to be set to a~matching key file. -If X509\_PROXY is set, X509\_KEY and X509\_CERT parameters are ignored. - -\begin{tabularx}\linewidth{@{}lX} -Type& \verb'char *'\\ -Default& GSI credential search mechanism is applied\\ -Environment& X509\_USER\_CERT -\end{tabularx} - - - - -\end{description} -\end{quote} - -\Return -The functions return 0 on success and EINVAL if \verb'param' -is not a~valid context parameter. - - -\subsection{Error Handling} -\label{s:error} - -Besides returning an error code, -the API calls record any error details within the \LB context. - -Further on, the API distinguishes between \emph{hard} and \emph{soft} -errors. -In the case of soft error some output data may still be available -(\eg E2BIG -- the result is too big so that it is truncated but its part -is still available). -In case soft errror it is the user responsibility to check the output -and free the data eventually. -Possible soft errors are always indicated in the API description. - -\Synopsis -\synopsis{int edg_wll_Error}{ -edg_wll_Context ctx & IN & context\\ -char ** text & OUT & standard error message\\ -char ** desc & OUT & error details (if any)\\ -} - -\Description -Retrieve recent API call error. -Besides an error code a~standard error message related to the code -is returned (\eg ``No such file or directory'' in the case of ENOENT), -and any details on the error (\eg it should be the filename in the case of ENOENT). -Any of \verb'text' of \verb'desc' can be NULL. No value is retrieved then. - -\Return -The code of recent error. - - -\subsection{Event and Job Status Representation} -In the producer part events are not handled as explicit objects -- -on the other hand, they are created on the fly by the logging calls, -based on context data as well as the particular functions arguments. - -The consumer API part represents an event as a~union \verb'edg_wll_Event' -defined as follows: -\begin{quote} -\begin{verbatim} -typedef union _edg_wll_Event { - edg_wll_EventCode type; - edg_wll_AnyEvent any; - edg_wll_TransferEvent transfer; - ... -} edg_wll_Event; - -typedef struct _edg_wll_AnyEvent { - edg_wll_EventCode type; - struct timeval timestamp; - char *host; - int level; - int priority; - edg_wlc_JobId jobId; - char *seqcode; - char *user; - edg_wll_Source source; - char *src_instance; -} edg_wll_AnyEvent; -\end{verbatim} - -\end{quote} - -The \verb'edg_wll_AnyEvent' contains the common fields of all the event types. -It's guaranteed that the same fields are contained in all the event type -specific structures (\verb'edg_wll_TransferEvent' etc.) on matching positions. -Therefore it's always legal to access the \verb'type' union field to find -out the type of event, and then \verb'any' for the common fields only, -or the corresponding type-specific structure. - -Full definitions of the structures including field types are presented -in Appendix~\ref{a:events}. - -Job status is represented by a~flat \verb'edg_wll_JobStat' structure -(as there is more overlap of data fields among various job states, -following the event union scheme is irrelevant). -Among others, the structure contains the fields: -\def\ttitem[#1]{\item[\normalfont\texttt{#1}]} -\begin{quote} -\raggedright -\begin{description} -\ttitem[state] -- numeric code of the status (EDG\_WLL\_JOB\_SUBMITTED, EDG\_WLL\_JOB\_WAITING, \dots) -\ttitem[type] -- type of the job (EDG\_WLL\_JOB\_SIMPLE or EDG\_WLL\_JOB\_DAG) -\ttitem[children] -- list of subjob \jobid's -\ttitem[children\_histogram] -- number of children in particular states -\ttitem[children\_states] -- full status information of the children -\end{description} -\end{quote} -Note that not all the fields are always filled in, see Sect.~\ref{s:jobstat}. -Full description of the structure can be found in Appendix~\ref{a:events}. - -\subsection{Connection Management} -The producer and consumer parts of the \LB API involve two communication -channels. -Connection data are stored within the context object. -Management of the corresponding network connections is performed -transparently by the \LB -library and it is hidden to the API user. - -The connections are soft-state: they may or may not be preserved across -subsequent API calls, the library may also cache several connections to -different servers. - -%\subsection{Environment Variables} - -\subsection{Producer} -\label{s:producer} -The \emph{producer} part of the library is responsible for -pushing the events into the \LB infrastructure. -It operates in the following modes: -\begin{description} -\item[Asynchronous] calls return as soon as possible, even if -the destination \LB server or a~network connection is down. -A~successful return from the API call -indicates that the event has been accepted by the \LB infrastructure, -persistently stored on the local-logger disk, and will be delivered to -the \LB server reliably. -However, there is no guarantee on time when the delivery actually occurs. - -In addition, the API provides a~flush call to ensure that the previously -sent events are actually stored at the server. -\item[Synchronous] calls do not return successfully -until the logged event is stored at the server. -This may take indefinite time. -A~synchornous call is not equivalent to a~corresponding asynchronous one -followed by the flush call -- synchronous events get precedence, -they may get stored while other previously logged -events heading to the same server may still be delayed (\eg\ because of -slow link). - -Even synchronous calls needn't wait for completition of the operation -undefinitely. -On the contrary, the library defines a~timeout for synchronous calls -(see EDG\_WLL\_PARAM\_LOG\_TIMEOUTS in Sect.~\ref{s:context}), -despite the default value is much larger than for asynchronous counterparts. - -\end{description} - -In general, plain asynchronous calls should be used whenever possible. -Despite asynchronous they are still reliable. -The entire \LB service was initially designed and is optimized for delivery of -asynchronous events. -The synchornous calls and mainly the flush call can take long time and consume -considerable amount of resources, therefore they should be used with care. -The API users are encouraged to design their code with the asynchronicity -of the \LB service in mind rather then relying on synchronous calls. - -\iffalse -Connection between the \LB library and a~local-logger daemon -is established transparently on the logging calls and may or may not be cached. -The following context parameters are taken in account: -\begin{description} -\item[log\_host, log\_port] -- local-logger daemon to connect to, -\item[proxy\_file, key\_file, cert\_file] -- user identity, -\item[log\_async\_timeout, log\_sync\_timeout] -- timeout values for asynchronous and synchronous calls, -\item[log\_level, log\_service, log\_instance] -- current logging level, and identification of the service. -\end{description} -Some of the paramaters need not be set, environment variables as well as default -values are considered then. See Sect.~\ref{s:context} for details. -\fi - -The producer part of the API can be split further into the following -groups: -\begin{itemize} -\item \emph{Sequence code handling calls} allow to retrieve and set the current -sequence code (used by the \LB service for clock-skew resistent event ordering). -\item \emph{Job registration calls} register a~job (and its subjobs) -with the \LB service. -\item \emph{Generic logging calls} capable of logging any defined event. -\item \emph{Specialized logging calls} -- one function per event. -\end{itemize} - -\subsubsection{Sequence Code Handling} -\label{s:sequence} - -\Synopsis -\synopsis{char *edg_wll_GetSequenceCode}{ -edg_wll_Context context&IN&where to retrieve the code from\\ -} - -\synopsis{int edg_wll_SetLoggingJob}{ -edg_wll_Context context&INOUT&the context to use\\ -edg_wlc_JobId job&IN&\jobid to use in following logging calls\\ -char *code&IN&code string as received from the previous component\\ -int flags&IN&one of EDG_WLL_SEQ_NORMAL or EDG_WLL_SEQ_DUPLICATE\\ -} - -\Description -\LB service uses the \emph{sequence codes} to disambiguate the seqence -of events generated by a~job cycling among several WMS components -(\eg\ failure and resubmission) in an environment where clocks needn't -be strictly synchronized. -Details of the mechanism can be found in~\cite{lbarch}. - -Each WMS component, when it passes control of a~job to another component, -is responsible for retrieving the sequence code from the current logging -context (via \verb'edg_wll_GetSequenceCode') -and pass it as an opaque string to the receiving component via their common -communication protocol (\eg\ within a~ClassAd attribute). -The receiving component initializes its logging context for the given job -(via \verb'edg_wll_SetLoggingJob') -with the received string before calling any logging functions. - -If the job control passes through a~component several times but the -component is stateless (\eg\ the Log Monitor), -it may happen that this call is issued several times with the same -\verb'code'. -In such a~case this must be identified with the -EDG\_WLL\_SEQ\_DUPLICATE flag. \LB service relies on event timestamps then. -\emph{Despite unavoidable in some situations this option is dangerous; -its misuse can emerge into incorrect job status computation.} -Therefore usage of this flag should be cross-checked with~\cite{lbarch} -whether all conditions required for proper \LB functionality are met. - -\Return - -\subsubsection{Job Registration} - -\Synopsis - -\synopsis{int edg_wll_RegisterJob}{ -edg_wll_Context context& IN& logging context\\ -edg_wlc_jobid job&IN&\jobid of the registered job\\ -int type&IN&one of EDG_WLL_JOB_SIMPLE or EDG_WLL_JOB_DAG\\ -char *jdl&IN&original (user specified) JDL of the job\\ -char *ns&IN& contact string (URL) of the Network Server handling the job\\ -int num_subjobs&IN&number of subjobs \\ -char *seed&IN& seed for generating the subjobs \jobid's\\ -edg_wlc_JobId **subjobs&OUT& array of generated subjob \jobid's\\ -} - -\synopsis{int edg_wll_RegisterJobSync}{\dots} - -\synopsis{int edg_wll_RegisterSubjobs}{ -edg_wll_Context context&IN& logging context\\ -edg_wlc_JobId *parent&IN& parent \jobid\\ -char **jdls&IN& JDL's of the subjobs\\ -edg_wlc_JobId *subjobs&IN& array of subjob \jobid's\\ -} - -\Description -\verb'edg_wll_RegisterJob' sets the current job of the logging context to -\verb'job', initializes the corresponding sequence code, and registers -the job (including certain critical information -- NS contact, and implicitly -the job owner) with \LB service via logging a~special event. -If the job is a~DAG the \verb'edg_wll_RegisterJob' -also generates the required number of subjob \jobid's and -creates the $\textit{parent}\rightarrow\textit{children}$ association -at the \LB server. -The \verb'seed' argument is used to initialize the subjob \jobid generator. -It's guaranteed that given the same seed and parent \jobid, the -same sequence of \jobid's is generated. - -A~component should also call \verb'edg_wll_RegisterJob' when job type (simple -or DAG) changes. - -\verb'edg_wll_RegisterJob' is a~synchronous variant of the call, -it takes exactly the same arguments. -The synchronous call is usually prefered when registering a~job for the first -time. Further change of the type can be usually logged with the more efficient -plain (asynchronous) call. - -Complementary, the \verb'edg_wll_RegisterSubjobs' call -registers each of the \verb'subjobs' and creates the -$\textit{child}\rightarrow\textit{parent}$ associations at the \LB server. - - -\subsubsection{Generic Logging Calls} - -\Synopsis -\synopsis{int edg_wll_LogEvent}{ -edg_wll_Context context & INOUT & context to work with \\ -edg_wll_EventCode event & IN & event type \\ -char *fmt & IN & format string \\ -\dots& IN & event specific values according to \verb'fmt' -} - -\synopsis{int edg_wll_LogEventSync}{ -edg_wll_Context context & INOUT & context to work with \\ -edg_wll_EventCode event & IN & event type \\ -char *fmt & IN & format string \\ -\dots& IN & event specific values according to \verb'fmt' -} - -\synopsis{int edg_wll_LogFlush}{ -edg_wll_Context context & INOUT & context to work with \\ -struct timeval *timeout & INOUT & wait at most this much time for completition, -remaining time on return -} - -\synopsis{int edg_wll_LogFlushAll}{ -edg_wll_Context context & INOUT & context to work with \\ -struct timeval *timeout & INOUT & wait at most this much time for completition, -remaining time on return -} - -\Description -\verb'edg_wll_LogEvent' (asynchronous) -and \verb'edg_wll_LogEventSync' (synchronous) are generic logging functions. -The event type (as described in Sect.~\ref{s:events}) is determined by the 2nd -argument. The API defines corresponding constants with prefix -\verb'EDG_WLL_EVENT_'. - -The 3rd argument \verb'fmt' is expected to be a~\verb'printf'-like -format string which, together with the remaining arguments, builds -a well-formed ULM~\cite{draft-abela} string. -For each of the described event types there's a~predefined string constant -prefixed with \verb'EDG_WLL_FORMAT_'. - -\verb'edg_wll_LogFlush' instructs the interlogger daemon to deliver -all pending events related to the current job -and waits at most \verb'timeout' for completition. -\verb'edg_wll_LogFlushAll' does the same for all jobs known to the -interlogger (as the events may originate from other processes, -the caller has no control on destination servers -- therefore the -FlushAll call may take unpredictable time). - -\Return -The function return the following codes and set the error details within -the context: - -\begin{tabularx}\hsize{lX} -0 & successful completition \\ -EINVAL & bad \jobid, unknown event code, or the format string together -with the remaining arguments does not form a~valid event, \\ -ENOSPC & \LB infrastructure failed to accept the event due to lack of disk -space etc., \\ -ENOMEM & failed to allocate memory, \\ -ECONREFUSED & cannot connect to the specified local logger, \\ -EAGAIN & non-blocking return (\eg\ timeout) -- needn't be an error, -the event still may be delivered but we can't guarantee it anymore -(even in the case of synchronous call). -It makes sense to attempt logging the same event later, duplicates are ignored. -\\ -\end{tabularx} - -\begin{tabularx}\hsize{lX} -EDG\_WLL\_ERROR\_NOJOBID & logging call attempted without assigning \jobid -to the context (see Sect.~\ref{s:sequence}). -\end{tabularx} - -In addition, the synchronous call may return further errors propagated -from the \LB server: - -\begin{tabularx}\hsize{lX} -EPERM & the user is not authorized to add events to this job, \\ -EEXIST & exactly the same event -has been already stored (this could be reported due to the synchronous -nature of the call, but the duplicates' treatment is exactly the same as -in asynchronous call\,---\,they are ignored).\\ -\dots \\ -\end{tabularx} - -\iffalse -The \verb'edg_wll_LogFlush' call may also return: - -\begin{tabularx}\hsize{lX} -EDG\_WLL\_ERROR\_INTERLOG\_TIMEOUT& The local-logger was contacted but the inter-logger -did not respond within the timeout,\\ -EDG\_WLL\_ERROR\_INTERLOG\_CONLOST& Inter-logger lost connection to one or more -servers,\\ -EDG\_WLL\_ERROR\_INTERLOG\_AGAIN& Not all pending events were delivered -within the timeout. -\end{tabularx} -\fi - -\subsubsection{Specialized Logging Calls} - -Besides the generic logging calls the API also provides specialized -calls for each event type (see Appendix~\ref{a:special} for details). -Those calls don't include the \verb'event' argument (as the even type -is given by the function name) and the format string (the format is fixed -for a~given event type). -The number as well as types of further arguments are determined -by the event type hence fixed. - - -\subsubsection{Logging User Information} -Besides the ``system'' \LB events used to track a~job during its life within -WMS, the \LB service also supports \emph{user} events. -In this way, users are able to log and retrieve application-specific -information. - -All the information is pushed into \LB service via the \emph{UserTags} event, -containing one or more $\textit{name}=\textit{value}$ pairs. -%The events can be logged either with generic logging calls or with -%the following shortcut: - -\Synopsis -\synopsis{edg_wll_LogUserTag}{ -edg_wll_Context context &IN& logging context\\ -char * name&IN& name of the tag\\ -char * value&IN& corresponding value\\ -} - -\iffalse -\synopsis{edg_wll_LogUserTags}{ -edg_wll_Context context &IN& logging context\\ -char ** names &IN& names of the tags\\ -char ** values & IN& corresponding values of the tags\\ -} -\fi - -\Description -The first call logs a~simple \emph{UserTags} event, -containing a~sigle $\textit{name}=\textit{value}$ pair. -The second call is a~more general variant allowing to log more -pairs within a~single event -- it is provided for performance reasons; -it should be used when more pairs are logged simultaneously. -From the point of view of further status queries \verb'edg_wll_LogUserTags' or -a~sequence of several corresponding \verb'edg_wll_LogUserTag''s is equivalent, -as long as the \verb'names' are distinct. - - -\subsection{Consumer} - -%\subsubsection{Job Status} -%\label{s:status} - -\subsubsection{Job Status Query} -\label{s:jobstat} -\Synopsis -\synopsis{int edg_wll_JobStatus}{ -edg_wll_Context context & IN& context\\ -edg_wlc_JobId jobid & IN & \jobid of the job being queried\\ -%int resolution & IN & resolution of the state machine, currently only -%EDG_WLL_STAT_STD\\ -int flags & IN & bitwise OR of EDG_WLL_STAT_* constants (see bellow) -determining which of the optional status fields should be retrieved\\ -edg_wll_JobStat *status & OUT & structure to fill in -} - -\Description -The call queries the \LB server which stores information about the \verb'job' -(possibly opening a~network connection to the server) -and retrieves the job status information. - -The \verb'flags' argument deterimines which of the result structure fields -will be actually filled, in addition to all ``basic'' fields -which are always returned: -\def\rmitem[#1]{\item[\normalfont#1]} -\begin{quote} -\begin{description} -%\rmitem[EDG\_WLL\_STAT\_BASIC] -- only ``short'' fields, \ie\ all except -%job descriptions (JDL, various ClassAd's, RSL, \dots) and any subjob information, -% -\rmitem[EDG\_WLL\_STAT\_CLASSADS] -- job description fields, -\rmitem[EDG\_WLL\_STAT\_CHILDREN] -- list of subjob \jobid's, -\rmitem[EDG\_WLL\_STAT\_CHILDSTAT] -- apply the flags recursively to -all subjobs. -\end{description} -\end{quote} - - -\Return -\begin{tabularx}\hsize{lX} -0&success\\ -EINVAL& Invalid argument, \eg\ unknown or inappropriate condition, -invalid \jobid object etc.\\ -EPERM& User is not authorized to retrieve data on this job.\\ -ENOENT& The job was not found. \\ -ECONREFUSED& Connection refused, \eg\ the server is not running. -\end{tabularx} - - -\subsubsection{General Queries} -\Synopsis -\synopsis{int edg_wll_QueryJobs}{ -edg_wll_Context context& INOUT& context\\ -edg_wll_QueryRec *conditions& IN & query conditions\\ -int flags &IN& status fields to retrieve (see Sect.~\ref{s:jobstat})\\ -edg_wll_JobId **jobs&OUT& matching \jobid's \\ -edg_wll_JobStat **states &OUT& states of matching jobs (if requested)\\ -} - -\Description -Query the \LB server given by the context parameters -QUERY\_SERVER (see Sect.~\ref{s:context}). -Return the jobs satisfying all the query conditions (see bellow). - -The \verb'edg_wll_QueryRec' structure specifies an atomic query condition -and is defined as follows: - -\begin{verbatim} -typedef struct _edg_wll_QueryRec { - edg_wll_QueryAttr attr; - edg_wll_QueryOp op; - char *tag; - union { - int i; - char *c; - struct timeval t; - edg_wlc_JobId j; - } value, value2; -} edg_wll_QueryRec; -\end{verbatim} - -The atomic condition is always a~comparison of an \emph{atrribute} -and value of a~given type provided in an appropriate member of the -\verb'value' union. - -Valid comparisons are -EDG\_WLL\_QUERY\_OP\_EQUAL, -EDG\_WLL\_QUERY\_OP\_LESS, -EDG\_WLL\_QUERY\_OP\_GREATER, -and EDG\_WLL\_QUERY\_OP\_WITHIN. -Meaning of the former three ones is straightforward -the last operation is a~check whether the attribute falls -into the interval given by \verb'value' (low limit) and \verb'value2' -(high limit). -It becomes useful with more complex and-or queries (see bellow). - -\def\qitem[#1]{\item[\normalfont EDG\_WLL\_QUERY\_ATTR\_#1]} - -\verb'edg_wll_QueryJobs' retrieves information on jobs for which the -\emph{current} status satisfies the query conditions. -Attributes valid for quering are: -\begin{quote} -\begin{description} -\qitem[JOBID] (\verb'edg_wlc_JobId'). \jobid. -If this attribute is specified, the server hostname/port taken from -the \jobid is used instead of the QUERY\_SERVER context parameter. -\qitem[OWNER] (\verb'char *'). Job owner (X509 certificate subject). -\qitem[STATUS] (\verb'int'). Job status, see Sect.~\ref{s:status}. -\qitem[LOCATION] (\verb'char *'). Hostname of the machine where the job is -being processed. -\qitem[DESTINATION] (\verb'char *'). Computing Element where the job was, is, or will be executed. -\qitem[DONECODE] (\verb'int'). Minor status of job termination, -one of EDG\_WLL\_STAT\_DONE\_OK, EDG\_WLL\_STAT\_DONE\_FAIL, or EDG\_WLL\_STAT\_DONE\_CANCEL, see Sect.~\ref{s:status}. -\qitem[USERTAG] (\verb'char *'). -User defined tag, the tag name has to be specified in \verb'tag'. -User tags are also interpreted in the ``status'' manner -- -if several \emph{UserTags} events containing the same tag name were logged, -the new value overwrites the older ones. -\end{description} -\end{quote} -In addition, \verb'edg_wll_QueryJobs' called with nonzero \verb'flags' -also returns states of the matching jobs. -The meaning of \verb'flags' is the same as for \verb'edg_wll_JobStatus'. - -\Return -\begin{tabularx}\hsize{lX} -0&success\\ -EINVAL& Invalid argument, \eg\ unknown or inappropriate condition, -invalid \jobid object etc.\\ -EPERM (soft)& The user is not authorized to access all data matching -the query. \\ -ENOENT& No jobs satisfying the query conditions were found.\\ -E2BIG (soft)& Result set size exceeds either the size set by the context parameter -QUERY\_LIMIT or the server imposed limit. -The call still returns the truncated output.\\ -ECONREFUSED& Connection refused, \eg\ the server is not running. -\end{tabularx} - -\begin{tabularx}\hsize{lX} -EDG\_WLL\_ERROR\_NOINDEX & The query is refused by the server being -too general, potentially causing server overload. See the discussion -in Sect.~\ref{s:index}. -\end{tabularx} - -\Synopsis -\synopsis{int edg_wll_QueryJobsExt}{ -edg_wll_QueryRec **conditions& IN & query conditions\\ -int flags &IN& status fields to retrieve (see Sect.~\ref{s:jobstat})\\ -edg_wll_JobId **jobs&OUT& matching \jobid's \\ -edg_wll_JobStat **states &OUT& states of matching jobs (if requested)\\ -} - -\def\attr{\textit{attr}} -\def\val{\textit{val}} -\def\And{\textrm{\ and\ }} -\def\Or{\textrm{\ or\ }} - -\Description -A~more general ``and-or'' variant of \verb'edg_wll_QueryJobs'. -It allows queries in the form -$$ -(\attr_1 = \val_a \Or \attr_1 = \val_b) \And (\attr_2 = \val_c \Or \attr_2=\val_d \Or \attr_3=\val_e) -$$ -The \verb'conditions' are not an array of atomic conditions -but an array (NULL-terminated) of pointers to arrays of conditions. -All conditions in one of the inner arrays should always refer -the same attribute, and are considered logicaly OR-ed, -\ie\ at least one of the conditions within the array has to be satisfied. -On the other hand, the arrays as a~whole are considered logicaly AND-ed. - -The restriction on the structure of the query expression (two nested -levels only) as well as enforcing the same attribute within conditions at the -lower level are imposed due to performance reasons. -An arbitrary complex queries might easily result into unacceptable load on -the \LB\ server. -On the other hand, we believe that a~vast majority of feasible queries -is covered with this interface. - -\Return -Same as \verb'edg_wll_QueryJobs'. In addition EINVAL is returned also -when conditions in one or more inner arrays does not refer to the same -attribute. - - -\Synopsis -\synopsis{int edg_wll_QueryEvents}{ -edg_wll_Context context& INOUT& context\\ -edg_wll_QueryRec *job_conditions& IN & query conditions on current job status\\ -edg_wll_QueryRec *event_conditions& IN & query conditions on the events\\ -edg_wll_Event **events &OUT& matching events\\ -} - -\Description -Query the \LB server given by the context parameters -QUERY\_SERVER (see Sect.~\ref{s:context}). -Return the events satisfying -\verb'job_conditions' and \verb'event_conditions'. -If \verb'job_conditions' is not null, the \emph{current} states of the -the jobs, which the retrieved events are related to, have to satisfy the -conditions. -In addtion, further conditions can be applied on the retrieved events. - -Valid attributes for \verb'job_conditions' are same as for -\verb'edg_wll_QueryJobs'. - -Valid attributes for \verb'event_conditions' are: -\begin{quote} -\begin{description} -%\qitem[JOBID] (\verb'edg_wlc_JobId'). \jobid. -%\qitem[OWNER] (\verb'char *'). Job owner. -\qitem[TIME] (\verb'struct timeval *'). Event timestamp. -\qitem[LEVEL] (\verb'int'). Logging level. -\qitem[HOST] (\verb'char *'). Hostname where the event was generated. -\qitem[SOURCE] (\verb'int'). Service which logged the events, -see the SOURCE context parameter in Sect.~\ref{s:context} for allowed values. -\qitem[INSTANCE] (\verb'char *'). Instance of the service, see Sect.~\ref{s:context} for details. -\qitem[EVENT\_TYPE] (\verb'int'). Event type, see Sect.~\ref{s:events}. -\qitem[USERTAG] (\verb'char *'). -User defined tag, the tag name has to be specified in \verb'tag'. -User tags among event conditions are interpreted in a~different way -\wrt\ those in job status. -All events from the whole job history are retrieved -if they satisfy the conditions, not only the most recent one. - -\end{description} -\end{quote} - -\Return -Same as \verb'edg_wll_QueryJobs'. - -\Synopsis -\synopsis{int edg_wll_QueryEventsExt}{ -edg_wll_Context context& INOUT& context\\ -edg_wll_QueryRec **job_conditions& IN & query conditions on current job status\\ -edg_wll_QueryRec **event_conditions& IN & query conditions on the events\\ -edg_wll_Event **events &OUT& matching events\\ -} - -\Description -\begin{sloppypar} -Analogous ``and-or'' extension of \verb'edg_wll_QueryEvents'. -See the description of \verb'edg_wll_QueryJobsExt' for details -on the allowed query structure and exact meaning of arguments. -\end{sloppypar} - -\subsubsection{Convenience Wrappers} - -\Synopsis -\synopsis{edg_wll_UserJobs}{ -edg_wll_Context context &INOUT \\ -edg_wlc_JobId **jobs &OUT & \jobid's of the current user's jobs\\ -edg_wll_JobStat **states &OUT & states of the jobs \\ -} - -\synopsis{edg_wll_JobLog}{ -edg_wll_Context context &INOUT \\ -edg_wlc_JobId job &IN& \jobid to query \\ -edg_wll_Event **events &OUT& retrieved events -} - -\Description -\verb'edg_wll_UserJobs' queries the current server for all jobs of the -current user. -If the \verb'states' argument is not null, BASIC (see Sect.~\ref{s:jobstat}) -states of the jobs are retrieved as well. - -\verb'edg_wll_JobLog' retrieves all events related to a~given job. - -\Return -Same as \verb'edg_wll_QueryJobs' (the functions are wrappers around -the general queries only). - -\subsubsection{Server Indexed Attributes} -\label{s:index} -The consumer API is quite general, allowing the caller to submit -a wide range of queries. -On the other hand, -a na\"\i ve query can easily emerge into a~full scan of the \LB server -database. As the database is expected to grow very large, the full scan -is unacceptable due to performance reasons. - -In order to allow efficient queries, the server has to index certain attributes -and use the indices as primary selection criteria. -Each server indexes the data on JOBID and OWNER of the job. -In addition the -server's configuration can specify a~further set of indexed attributes -including enumerated user tags. -The user tags are indexed in both their job-status and event-related semantics. - -Each query must include at least one condition on an indexed attribute. -Otherwise, the query is rejected by the server. - -\Synopsis -\synopsis{int edg_wll_GetIndices}{ -edg_wll_Context context &INOUT\\ -edg_wll_QueryAttr **attrs&OUT& array of indexed attributes\\ -char ***userTags &OUT& array of indexed user tags\\ -} -\Description -Query the server configuration for indexed attributes. -Returns the indexed standard \LB attributes in \verb'attrs' -and possibly the indexed user tags in \verb'userTags'. - -\subsubsection{Result Set Size} -In order to further prevent inefficient queries which may result in a~very huge -result set, causing both server and network overload, the consumer -part of the \LB service can impose two limits on the result set size: -\begin{itemize} -\item \emph{Server side} (hard) limit is given by the server configuration, -and it cannot be changed by the user. -\item \emph{Client side} (soft) limit is stored within a~context object -and can be set by the user. -\end{itemize} -The limits are expressed as a~maximal number of entries (\ie\ jobs or events) -returned. -On each query, the client advertises its current limit to the server, -and the server enforces the smaller one of the two limits then. - -Should a~query result in a~larger output, the result is truncated but still -returned to the caller. -Triggering the limit is indicated by returning E2BIG error code. - -The client limit can be manipulated with the Set/Get parameter calls -(see Sect.~\ref{s:context}). - -\Synopsis -\synopsis{edg_wll_GetServerLimit}{ -edg_wll_Context & INOUT \\ -int *limit &OUT & server limit -} - -\Description -Retrieve the current server query result size limit. - - -\section{C++ Binding} -C++ \LB{} server API is closely modelled after the C \LB{} server -API. It consists of the following classes: -\begin{description} - -\item{\emph{JobId}}\\ -Class representing \jobid; this class is not in -fact part of C++ \LB API, as it is shared by all WP1 components. - -\item{\emph{LoggingException}}\\ -Derived from -\emph{edg::workload::common::utilities::Exception}, this class -communicates the error conditions back to C++ \LB API clients. - -\item{\emph{ServerConnection}}\\ -Encapsulates the notion of context of C \LB API. All -functions taking as the parameter the \emph{edg\_wll\_Context} and not specific -to jobs are reflected in methods of \emph{ServerConnection} class. - -\item{\emph{Job}}\\ -Represents the job and defines job specific query methods; -all C \LB API functions taking as parameters \emph{edg\_wll\_Context} and -\emph{edg\_wlc\_JobId} are reflected here. - -\item{\emph{JobStatus}}\\ -Closely related to the \emph{Job} class, this class holds data -about job status, ie. the attribute -- value pairs specific -for a given job state. - -\item{\emph{Event}}\\ -Represents events stored in the bookkeeping -server database; the data are stored as attribute -- value pairs. - -\item{\emph{QueryRecord}}\\ -A helper class for specifying queries to \LB -database. -\end{description} - -\noindent More detailed description of these classes and their methods -follows. - -\subsection*{LoggingException} - -\subsection*{QueryRecord} -Class used to create \verb|AND| queries to the \LB -database, encapsulates \emph{edg\_qll\_QueryRec}. Every object of that -class holds a condition on exactly one attribute of the result; query -methods then take vectors of \emph{QueryRecord} objects as parameters -with logical \verb|AND| semantics. - -\subsubsection*{Constants} -\begin{description} -\item{ -\begin{verbatim} - enum Attr { - UNDEF=0, /**< Not-defined value, used to terminate lists etc. */ - JOBID, /**< Job Id \see _edg_wll_QueryRec */ - OWNER, /**< Job owner \see _edg_wll_QueryRec */ - STATUS, /**< Current job status */ - LOCATION, /**< Where is the job processed */ - DESTINATION,/**< Destination CE */ - DONECODE, /**< Minor done status (OK,fail,cancel) */ - USERTAG, /**< User tag (not implemented yet) */ - TIME, /**< Timestamp \see _edg_wll_QueryRec */ - LEVEL, /**< Logging level (see "dglog.h") * \see _edg_wll_QueryRec */ - HOST, /**< Where the event was generated */ - SOURCE, /**< Source component */ - INSTANCE, /**< Instance of the source component */ - EVENT_TYPE, /**< Event type \see _edg_wll_QueryRec */ - }; - - enum Op { EQUAL=1, LESS, GREATER }; -\end{verbatim} - These constants are used to identify attributes and conditions on -them. Listed attributes are the only ones permitted to query, they -form a subset of all possible attributes. -} -\end{description} - -\subsubsection*{Constructors} -\begin{description} -\item{ -\begin{verbatim} - -QueryRecord(const Attr, const Op, const std::string &); -QueryRecord(const Attr, const Op, const int); -QueryRecord(const Attr, const Op, const struct timeval &); -QueryRecord(const Attr, const Op, const edg::workload::common::jobid::JobId&); -\end{verbatim} -} -There is a constructor for every attribute type allowed in a -query. Supported types include integers, strings, times and \jobid's. - -\end{description} - -\subsection*{Event} -This class provides methods for getting event attribute names and -values. - -\subsubsection*{Constructors} -Constructors are used internally by the library, as the client is not -suposed to create objects of \emph{Event} class. - -\subsubsection*{Event type} -\begin{description} -\item{ - -\begin{verbatim} - enum Type { - UNDEF = 0, - TRANSFER, /**< Start, success, or failure of job transfer to another component */ - ACCEPTED, /**< Accepting job (successful couterpart to Transfer) */ - REFUSED, /**< Refusing job (unsuccessful couterpart to Transfer) */ - ENQUEUED, /**< The job has been enqueued in an inter-component queue */ - DEQUEUED, /**< The job has been dequeued from an inter-component queue */ - HELPERCALL, /**< Helper component is called */ - HELPERRETURN, /**< Helper component is returning the control */ - RUNNING, /**< Executable started */ - RESUBMISSION, /**< Result of resubmission decision */ - DONE, /**< Execution terminated (normally or abnormally) */ - CANCEL, /**< Cancel operation has been attempted on the job */ - ABORT, /**< Job aborted by system */ - CLEAR, /**< Job cleared, output sandbox removed */ - PURGE, /**< Job is purged from bookkepping server */ - MATCH, /**< Matching CE found */ - PENDING, /**< No match found yet */ - REGJOB, /**< New job registration */ - CHKPT, /**< Application-specific checkpoint record */ - LISTENER, /**< Listening network port for interactive control */ - CURDESCR, /**< current state of job processing (optional event) */ - USERTAG, /**< user tag -- arbitrary name=value pair */ - TYPE_MAX - }; -\end{verbatim} -} -Symbolic constants defining possible event types. - -\item{\verb|Type type|}\\ -The event type given by one of the constants above. - -\item{\verb|const std::string & name(void) const|}\\ -Returns string representation of the event's type (ie. ``JobDone''). - -\end{description} - -\subsubsection*{Attributes} -\begin{description} -\leftmargin10pt\listparindent20pt - -\item{\verb|enum AttrType { INT_T, STRING_T, TIMEVAL_T, PORT_T, LOGSRC_T, JOBID_T }|}\\ -Constants determining event attribute types. - -\item{\verb|const std::vector > &getAttrs(void) const|}\\ -This method returns the vector of attribute name and type pairs. The -type is given by the symbolic constant above, for a list of possible -attributes see the header file {\tt edg/workload/logging/client/Event.h}. - -\item{ -\begin{verbatim} -int getValInt(Attr) const -std::string getValString(Attr) const -struct timeval getValTime(Attr) const -const edg::workload::common::jobid::JobId getValJobId(Attr) const -\end{verbatim} -} -Methods for accessing event attribute's value. There is one method for -every supported attribute type. For some attributes the returned -integer values can be defined by symbolic constants; for a list of -allowed constants see the header file -{\tt edg/workload/logging/client/Event.h}. -The \verb|int getValInt(Attr)| method should be used for -the \verb|PORT_T| and \verb|LOGSRC_T| attribute types. - -\item{\verb|const std::string & getAttrName(Attr) const|}\\ -Converts a symbolic attribute name to string representation. - -\end{description} - -\subsection*{ServerConnection class} -Objects of this class represent one bookkeeping server. Underlying -network connections are handled automatically by the library, the -class defines methods for setting connection parameters and general -queries to the \LB database. - -\subsubsection*{Constructors} -\begin{description} -\item{\verb|ServerConnection()|}\\ Creates new object and initializes -it according to the environment variables. -\end{description} - -\subsubsection*{Query parameters} -These methods are dealing with various parameters of connection to the -\LB server. The connections however are managed intrinsically by the -library itself. - -\begin{description} -\item{\verb|void setQueryServer(const std::string&)|}\\ -Set the hostname of \LB server to query. - -\item{\verb|void setQueryTimeout(int)|}\\ -Set timeout for server response. - -\item{\verb|void setX509Proxy(const std::string&)|}\\ -Use the X509 proxy stored in file named in parameter for -authentication. - -\item{\verb|void setX509Cert(const std::string&, const std::string&)|}\\ -Use X509 certificate (certificate filename in the first parameter, private -key stored in file named in the second parameter) for authentication. - -\item{\verb|std::pair getQueryServer() const|}\\ -Returns the hostname and port of the currently used \LB server. - -\item{\verb|int getQueryTimeout() const|}\\ -Returns currently used query timeout. - -\end{description} - -\subsubsection*{Queries} -\begin{description} -\item{\verb|std::vector singleTags(void)|}\\ -\item{\verb|std::vector > multiTags(void)|}\\ - -\item{\verb|std::pair getLimits(void) const|}\\ -Get the hard (first) and soft (second) limit on the number of results -(records) returned by the \LB server in one query. - -\item{\verb|void setSoftLimit(int)|}\\ -Set the soft (client side) limit on the number of query results. - -\item{ -\begin{verbatim} -void queryEvents( -const std::vector& job_cond, -const std::vector& event_cond, -std::vector&) const; -\end{verbatim} -} -Return all events satisfying conditions in the second parameter logged -by jobs satisfying conditions in the first parameter. Result is in the -last parameter. - -\item{ -\begin{verbatim} -std::string queryEventsAggregate( -const std::vector& job_cond, -const std::vector& event_cond, -enum AggOp const op, -std::string const attr) const; -\end{verbatim} -} -The same as above, but do not return particular events. The result of -aggregation operation (currently minimum, maximum and number of -results) on attribute in the fourth parameter is returned instead. - -\item{ -\begin{verbatim} -void queryJobs( -const std::vector& query, -std::vector& ids) const; -\end{verbatim} -} -Return \jobid's of jobs satisfying the query conditions in the first -parameter, result is in the second parameter. - -\item{ -\begin{verbatim} -void queryJobStates( -const std::vector& query, -int flags, -std::vector & states) const; -\end{verbatim} -} -Return states of jobs satisfying the conditions in the first -parameter. The second parameter determines the detail of information -returned on each job, result is in the last parameter. - -\item{\verb|void userJobs(std::vector &) const|}\\ -Returns \jobid's of all jobs owned by the user (as determined by the -X509 proxy or certificate) known by the \LB server. - -\item{\verb|void userJobStates(std::vector& stateList) const|}\\ -Same as above, but return job states instead of \jobid's. - -\end{description} - -\subsection*{Job} -The \emph{Job} class represent individual job in the \LB database and -provides methods for accessing it's state and events stored in the \LB -database. - -\subsubsection*{Constructors} -\begin{description} -\item{\verb|Job(void)|}\\ -Default constructor, creates empty object. - -\item{\verb|Job(const edg::workload::common::jobid::JobId &)|}\\ -Creates object representing job with given \jobid. -\end{description} - -\subsubsection*{Job properties} -\begin{description} - -\item{ -\begin{verbatim} -static const int STAT_CLASSADS; /**< various job description fields */ -static const int STAT_CHILDREN; /**< list of subjob JobId's */ -static const int STAT_CHILDSTAT; /**< apply the flags recursively to subjobs */ -\end{verbatim} -} -These constants differentiate the level of detail returned in job -status information by the \LB. - -\item{\verb|JobStatus status(int) const|}\\ -Returns \emph{JobStatus} object holding information about the job, the -requested level of detail is passed as an argument determined by the -above constants. - -\item{\verb|void log(std::vector &) const|}\\ -Fill in the passed vector argument with all events logged for this job. - -\item{\verb|const std::pair queryListener(const std::string & name) const|}\\ -Return the name and port of the listener for interactive jobs. - -\end{description} - -\subsection*{JobStatus} -The \emph{JobStatus} class represents the result of job status query -to the \LB database. - -\subsubsection*{Constructors} -All constructors are used internally by the \LB client library. - -\subsubsection*{Properties} -All information about job status are encoded as an attribute -name--value pairs, for every attribute type there is a corresponding -method to obtains that attribute's value. - -\begin{description} - -\item{ -\begin{verbatim} -int getValInt(Attr) const; -std::string getValString(Attr) const; -struct timeval getValTime(Attr) const; -const edg::workload::common::jobid::JobId getValJobId(Attr) const; -bool getValBool(Attr) const; -const std::vector getValIntList(Attr) const; -const std::vector getValStringList(Attr) const; -const std::vector getValJobStatusList(Attr) const; -\end{verbatim} -} -Access methods for various attribute types. Each method takes an -attribute symbolic name as an argument. - -\end{description} - -\subsection*{Event} -The \emph{Event} class represents one event stored in the \LB -database. All information about particular event are accessible as an -attribute name--value pairs. Every type of event (and instance of the -\emph{Event} class) defines set of mandatory and optional attributes. - - -\subsubsection*{Constructors} -Constructors are used internally by the \LB client library. - -\subsubsection*{Properties} - -\begin{description} -\item{ -\verb|const std::vector > & getAttrs(void) const;| -}\\ -Return list of defined attributes for this instance. The attributes -are given as a name--type pairs, where both name and type are given by -symbolic constants. For every supported attribute type there is a -corresponding method to obtain value of such attribute; in addition -values of enumerated types (whose values are defined as symbolic -constants and there is a \emph{edg\_wll\_ToString()} function) -can be obtained in string form by calling the \emph{getValString()} method. - -\item{ -\begin{verbatim} -int getValInt(Attr) const; -std::string getValString(Attr) const; -struct timeval getValTime(Attr) const; -const edg::workload::common::jobid::JobId getValJobId(Attr) const; -const std::string & getAttrName(Attr) const; -\end{verbatim} -} -Access methods for supported attribute types, argument is an symbolic -name of the requested attribute. - -\end{description} - -% \section{Use Cases} - -\appendix -\section{Event and Job Status Structures} -\label{a:events} -\section{Specialized Logging Calls} -\label{a:special} - -\end{document} diff --git a/org.glite.lb.client/doc/api/fig/logging-arch.eps b/org.glite.lb.client/doc/api/fig/logging-arch.eps deleted file mode 100644 index 12dcd35..0000000 --- a/org.glite.lb.client/doc/api/fig/logging-arch.eps +++ /dev/null @@ -1,1714 +0,0 @@ -%!PS-Adobe-2.0 EPSF-2.0 -%%BoundingBox: -41 242 799 858 -%%Creator: CorelDRAW! -%%Title: logging-arch.eps -%%CreationDate: Fri May 25 08:33:21 2001 - -%%DocumentFonts: AvantGarde-Book -%%+ AvantGarde-BookOblique -%%+ AvantGarde-Demi -%%DocumentProcessColors: Black -%%EndComments -%%BeginProlog -/AutoFlatness false def -% -------------- POSTSCRIPT PROLOG FOR CORELDRAW 3.X ------ -% Copyright 1992 Corel Corporation. All rights reserved. -/wCorelDict 300 dict def wCorelDict begin/bd{bind def}bind def -/ld{load def}bd/xd{exch def}bd/_ null def -/$c 0 def/$m 0 def/$y 0 def/$k 0 def/$t 1 def -/$n _ def/$o 0 def/$fil 0 def/$bkg false def -/$C 0 def/$M 0 def/$Y 0 def/$K 0 def/$T 1 def -/$N _ def/$O 0 def/$PF false def/$ctm matrix currentmatrix def -/$ptm matrix def/$ttm matrix def/$stm matrix def -/$fst 128 def/$pad 0 def/$rox 0 def/$roy 0 def -currentscreen/@dsp xd/$dsp/@dsp def/$dsa xd -/$dsf xd/$sdf false def/$SDF false def/$Scra 0.0 def -/$sv 0 def/@cp/closepath ld/@gs/gsave ld/@gr/grestore ld -/@np/newpath ld/@sv{/$sv save def}bd/@rs{$sv restore}bd -/@ss{exch $Scra add exch load setscreen}bd -AutoFlatness{/$cpx ([Error: PathTooComplex; OffendingCommand: AnyPaintingOperator]\n) def -/@err1{$cpx print flush newpath}bd/@ifl{dup currentflat exch sub 10 gt -{@err1 exit}{currentflat 2 add setflat}ifelse}bd -/@fill/fill ld/fill{currentflat{{@fill}stopped{@ifl}{exit}ifelse -}bind loop setflat}bd/@eofill/eofill ld/eofill{currentflat{{@eofill} -stopped{@ifl}{exit}ifelse}bind loop setflat}bd -/@clip/clip ld/clip{currentflat{{@clip}stopped{initclip @ifl}{exit -}ifelse}bind loop setflat}bd/@eoclip/eoclip ld -/eoclip{currentflat{{@eoclip}stopped{initclip @ifl}{exit}ifelse -}bind loop setflat}bd/@stroke/stroke ld/stroke{currentflat{{@stroke} -stopped{@ifl}{exit}ifelse}bind loop setflat}bd}if -/InRange{3 -1 roll 2 copy le{pop}{exch pop}ifelse -2 copy ge{pop}{exch pop}ifelse}bd/wDstChck{2 1 roll dup 3 -1 roll -eq{1 add}if}bd/@dot{dup mul exch dup mul add 1 exch sub 2 div}bd -/@lin{exch pop abs 1 exch sub}bd/@MN{2 copy le{pop}{exch pop}ifelse}bd -/setcmykcolor where{pop}{/setcmykcolor{4 1 roll -3{3 index add 1 @MN 1 exch sub 3 1 roll}repeat -setrgbcolor pop}bd}ifelse/setoverprint{/$op xd}bd -/currentoverprint{$op}bd/setsepcolor{1 exch sub setgray}bd -/checksepcolor{1 exch sub dup setgray 1 eq exch 1 eq and not}bd -/setprocesscolor{ColorSeparationMode 0 eq{setcmykcolor}{ -0 4 $ink sub index exch pop 5 1 roll 4{pop}repeat -setsepcolor}ifelse}bd/findcmykcustomcolor{5 array astore}bd -/setcustomcolor where{pop}{/setcustomcolor{ColorSeparationMode 0 eq{ -exch aload pop pop 4{4 index mul 4 1 roll}repeat -5 -1 roll pop setcmykcolor}{exch aload pop -CurrentInkName eq{4 index}{0}ifelse 6 1 roll -5{pop}repeat setsepcolor}ifelse}bd}ifelse/colorimage where{pop}{ -/colorimage{pop pop pop pop pop{currentfile $dat readhexstring pop pop} -repeat pop}bd}ifelse/@tc{dup 1 ge{pop}{4{dup -6 -1 roll mul exch}repeat pop}ifelse}bd/@scc{1 eq setoverprint -dup _ eq{pop setprocesscolor pop}{findcmykcustomcolor -exch setcustomcolor}ifelse ColorSeparationMode 0 eq{true}{ -currentgray 1 eq currentoverprint and not}ifelse}bd -/@sft{/$tx $tllx $pxf add dup $tllx gt{$pwid sub}if def -/$ty $tury $pyf sub dup $tury lt{$phei add}if def}bd -/@stb{pathbbox/$ury xd/$urx xd/$lly xd/$llx xd}bd -/@ep{{cvx exec}forall}bd/@tp{@sv/$in true def -2 copy dup $lly le{/$in false def}if $phei sub $ury ge{/$in false def}if -dup $urx ge{/$in false def}if $pwid add $llx le{/$in false def}if -$in{@np 2 copy m $pwid 0 rl 0 $phei neg rl $pwid neg 0 rl -0 $phei rl clip @np $pn cvlit load aload pop -7 -1 roll 5 index sub 7 -1 roll 3 index sub translate -/$ctm matrix currentmatrix def @ep pop pop pop pop}{pop pop}ifelse -@rs}bd/@th{@sft 0 1 $tly 1 sub{dup $psx mul $tx add{ -dup $llx gt{$pwid sub}{exit}ifelse}loop exch $phei mul $ty exch sub -0 1 $tlx 1 sub{$pwid mul 3 copy 3 -1 roll add exch -@tp pop}for pop pop}for}bd/@tv{@sft 0 1 $tlx 1 sub{dup $pwid mul $tx add -exch $psy mul $ty exch sub{dup $ury lt{$phei add}{exit}ifelse}loop -0 1 $tly 1 sub{$phei mul 3 copy sub @tp pop}for -pop pop}for}bd/@pf{@gs $ctm setmatrix $pm concat -@stb eoclip Bburx Bbury $pm itransform/$tury xd/$turx xd -Bbllx Bblly $pm itransform/$tlly xd/$tllx xd -/$wid $turx $tllx sub def/$hei $tury $tlly sub def -@gs $vectpat{1 0 0 0 0 _ $o @scc{eofill}if}{$t $c $m $y $k $n $o @scc{ -$tllx $tlly translate $wid $hei scale <00> 8 1 false [ 8 0 0 1 0 0 ]{}imagemask -/$bkg true def}if}ifelse @gr $wid 0 gt $hei 0 gt and{ -$pn cvlit load aload pop/$pd xd 3 -1 roll sub/$phei xd -exch sub/$pwid xd/$tlx $wid $pwid div ceiling 1 add def -/$tly $hei $phei div ceiling 1 add def $psx 0 eq{@tv}{@th}ifelse}if -@gr @np/$bkg false def}bd/@dlt{ColorSeparationMode 0 eq{ -/$dc $toc $tot mul $frc $frt mul dup/$c xd sub $fst 1 sub div def -/$dm $tom $tot mul $frm $frt mul dup/$m xd sub $fst 1 sub div def -/$dy $toy $tot mul $fry $frt mul dup/$y xd sub $fst 1 sub div def -/$dk $tok $tot mul $frk $frt mul dup/$k xd sub $fst 1 sub div def -true}{$frt $frc $frm $fry $frk $frn $o @scc -dup{/$frk 1 currentgray sub def}{/$frk 0 def}ifelse -$tot $toc $tom $toy $tok $ton $o @scc dup{/$tok 1 currentgray sub def}{ -/$tok 0 def}ifelse or dup{/$c 0 def/$m 0 def/$y 0 def/$k $frk def -/$dc 0 def/$dm 0 def/$dy 0 def/$dk $tok $frk sub $fst 1 sub div def}if -}ifelse}bd/@ftl{1 index 4 index sub dup $pad mul dup/$pdw xd -2 mul sub $fst div/$wid xd 2 index sub/$hei xd -pop translate $c $m $y $k 4 copy ColorSeparationMode 0 ne -{1 exch sub setgray pop pop pop}{setcmykcolor}ifelse -0 0 moveto 0 $hei lineto $pdw $hei lineto $pdw 0 lineto 0 0 lineto fill -$pdw 0 translate $fst{4 copy ColorSeparationMode 0 ne -{1 exch sub setgray pop pop pop}{setcmykcolor}ifelse -0 0 moveto 0 $hei lineto $wid $hei lineto $wid 0 lineto 0 0 lineto fill -$wid 0 translate $dk add 4 1 roll $dy add 4 1 roll -$dm add 4 1 roll $dc add 4 1 roll}repeat $dk sub 4 1 roll -$dy sub 4 1 roll $dm sub 4 1 roll $dc sub 4 1 roll -ColorSeparationMode 0 ne{1 exch sub setgray pop pop pop} -{setcmykcolor}ifelse 0 0 moveto 0 $hei lineto $pdw $hei lineto $pdw 0 lineto 0 0 lineto fill -}bd/@ftr{1 index 4 index sub dup $rox mul/$row xd -2 div 1 index 4 index sub dup $roy mul/$roh xd -2 div 2 copy dup mul exch dup mul add sqrt -$row dup mul $roh dup mul add sqrt add dup/$hei xd $fst div/$wid xd -4 index add $roh add exch 5 index add $row add -exch translate pop pop pop pop currentflat dup 5 mul setflat -$c $m $y $k 4 copy ColorSeparationMode 0 ne -{1 exch sub setgray pop pop pop}{setcmykcolor}ifelse -$wid 0 moveto 0 0 $hei 0 360 arc fill 1.0 $pad 2 mul sub dup scale -$fst{4 copy ColorSeparationMode 0 ne{1 exch sub setgray pop pop pop} -{setcmykcolor}ifelse $wid 0 moveto 0 0 $hei 0 360 arc fill -/$hei $hei $wid sub def $dk add 4 1 roll $dy add 4 1 roll -$dm add 4 1 roll $dc add 4 1 roll}repeat pop pop pop pop -setflat}bd/@ff{@gs @dlt{$ctm setmatrix eoclip -newpath Bbllx Bblly moveto Bbllx Bbury lineto -Bburx Bbury lineto Bburx Bblly lineto $fan rotate -pathbbox newpath $fty 1 eq{@ftr}{@ftl}ifelse}if -@gr @np}bd/@Pf{@sv ColorSeparationMode 0 eq $ink 3 eq or{0 J 0 j [] 0 d -$t $c $m $y $k $n $o @scc pop $ctm setmatrix -72 1000 div dup matrix scale dup concat dup Bburx exch Bbury exch itransform -ceiling cvi/Bbury xd ceiling cvi/Bburx xd Bbllx exch Bblly exch itransform -floor cvi/Bblly xd floor cvi/Bbllx xd $Prm aload pop -$Psn load exec}{1 setgray eofill}ifelse @rs -@np}bd/g{1 exch sub/$k xd/$c 0 def/$m 0 def/$y 0 def/$t 1 def/$n _ def/$fil 0 def -}bd/G{1 exch sub/$K xd/$C 0 def/$M 0 def/$Y 0 def/$T 1 def/$N _ def}bd -/k{/$k xd/$y xd/$m xd/$c xd/$t 1 def/$n _ def/$fil 0 def}bd -/K{/$K xd/$Y xd/$M xd/$C xd/$T 1 def/$N _ def}bd -/x{/$t xd/$n xd/$k xd/$y xd/$m xd/$c xd/$fil 0 def}bd -/X{/$T xd/$N xd/$K xd/$Y xd/$M xd/$C xd}bd -/d/setdash ld/i{dup 0 ne{setflat}{pop}ifelse}bd -/j/setlinejoin ld/J/setlinecap ld/M/setmiterlimit ld -/w/setlinewidth ld/O{/$o xd}bd/R{/$O xd}bd -/c/curveto ld/C/c ld/v{4 -2 roll 2 copy 6 -2 roll curveto}bd -/V/v ld/y{2 copy curveto}bd/Y/y ld/l/lineto ld -/L/l ld/rl/rlineto ld/m/moveto ld/n/newpath ld -/N/newpath ld/F{matrix currentmatrix $sdf{$scf $sca $scp @ss}if -$fil 1 eq{@pf}{$fil 2 eq{@ff}{$fil 3 eq{@Pf}{$t $c $m $y $k $n $o @scc -{eofill}{@np}ifelse}ifelse}ifelse}ifelse $sdf{$dsf $dsa $dsp @ss}if -setmatrix}bd/f{@cp F}bd/S{matrix currentmatrix -$ctm setmatrix $SDF{$SCF $SCA $SCP @ss}if $T $C $M $Y $K $N $O @scc{ -matrix currentmatrix $ptm concat stroke setmatrix}{@np}ifelse -$SDF{$dsf $dsa $dsp @ss}if setmatrix}bd/s{@cp -S}bd/B{@gs F @gr S}bd/b{@cp B}bd/W{eoclip}bd -/p{/$pm xd 7{pop}repeat/$pyf xd/$pxf xd/$pn xd -/$fil 1 def}bd/P{11{pop}repeat}bd/u{}bd/U{}bd -/A{pop}bd/q/@gs ld/Q/@gr ld/E{5 array astore -exch cvlit exch def}bd/`{}bd/~{}bd/@{}bd/&{}bd -/CorelDrawReencodeVect [ -16#80/grave/circumflex/tilde/dotlessi/florin/quotedblleft/quotedblright/guilsinglleft -16#88/guilsinglright/fi/fl/dagger/daggerdbl/endash/periodcentered/breve -16#90/quotedblbase/ellipsis/perthousand/trademark/Pt/fractionbar -16#98/divide -16#a1/exclamdown/cent/sterling/currency/yen/bar/section -16#a8/dieresis/copyright/ordfeminine/guillemotleft/logicalnot/emdash/registered/overbar -16#b0/ring/plusminus/twosuperior/threesuperior/acute/mu/paragraph/bullet -16#b8/cedilla/onesuperior/ordmasculine/guillemotright/onequarter/onehalf/threequarters/questiondown -16#c0/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE/Ccedilla -16#c8/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex/Idieresis -16#d0/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis/OE -16#d8/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls -16#e0/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla -16#e8/egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis -16#f0/eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/oe -16#f8/oslash/ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis ] def -/@cc{currentfile $dat readhexstring pop}bd -/@sm{/$ctm $ctm currentmatrix def}bd/@E{/Bbury xd/Bburx xd -/Bblly xd/Bbllx xd}bd/@c{@cp}bd/@p{/$fil 1 def -1 eq/$vectpat xd/$pm xd/$psy xd/$psx xd/$pyf xd/$pxf xd -/$pn xd}bd/@P{/$fil 3 def/$Psn xd array astore -/$Prm xd}bd/@k{/$fil 2 def/$roy xd/$rox xd/$pad xd -/$fty xd/$fan xd $fty 1 eq{/$fan 0 def}if/$tok xd/$toy xd/$tom xd/$toc xd -/$frk xd/$fry xd/$frm xd/$frc xd/$frn _ def/$frt 1 def/$ton _ def/$tot 1 def -}bd/@x{/$fil 2 def/$roy xd/$rox xd/$pad xd -/$fty xd/$fan xd/$tot xd/$ton xd/$tok xd/$toy xd/$tom xd/$toc xd -/$frt xd/$frn xd/$frk xd/$fry xd/$frm xd/$frc xd}bd -/@ii{concat 3 index 3 index m 3 index 1 index l -2 copy l 1 index 3 index l 3 index 3 index l -clip pop pop pop pop}bd/@i{@sm @gs @ii 6 index 1 ne{/$frg true def -pop pop}{1 eq{$T $C $M $Y $K $N $O @scc/$frg xd}{/$frg false def -}ifelse 1 eq{@gs $ctm setmatrix $t $c $m $y $k $n $o @scc{eofill}if -@gr}if}ifelse/$frg $frg $bkg or def @np/$ury xd/$urx xd/$lly xd/$llx xd -/$bts xd/$hei xd/$wid xd/$dat $wid $bts mul 8 div ceiling cvi string def -$frg{$SDF{$SCF $SCA $SCP @ss}if $llx $lly translate -$urx $llx sub $ury $lly sub scale $wid $hei abs -$bts 1 eq{false}{$bts}ifelse [ $wid 0 0 $hei neg 0 -$hei 0 gt{$hei}{0}ifelse]/@cc load $bts 1 eq{imagemask}{image}ifelse -$SDF{$dsf $dsa $dsp @ss}if}{$hei abs{@cc pop}repeat}ifelse -@gr $ctm setmatrix}def/@M{@sv}bd/@N{/@cc{}def -1 eq{12 -1 roll neg 12 1 roll @I}{13 -1 roll neg 13 1 roll -@i}ifelse @rs}bd/@I{@sm @gs @ii @np/$ury xd/$urx xd/$lly xd/$llx xd -/$ncl xd/$bts xd/$hei xd/$wid xd/$dat $wid $bts mul $ncl mul 8 div ceiling cvi string def -$llx $lly translate $urx $llx sub $ury $lly sub scale -$wid $hei abs $bts [ $wid 0 0 $hei neg 0 $hei 0 gt{$hei}{0}ifelse] -/@cc load false $ncl colorimage @gr $ctm setmatrix}bd -/z{exch findfont exch scalefont setfont}bd -/ZB{9 dict dup begin 4 1 roll/FontType 3 def -/FontMatrix xd/FontBBox xd/Encoding 256 array def -0 1 255{Encoding exch/.notdef put}for/CharStrings 256 dict def -CharStrings/.notdef{}put/Metrics 256 dict def -Metrics/.notdef 3 -1 roll put/BuildChar{exch -dup/$char exch/Encoding get 3 index get def -dup/Metrics get $char get aload pop setcachedevice -begin Encoding exch get CharStrings exch get -end exec}def end definefont pop}bd/ZBAddChar{findfont begin -dup 4 1 roll dup 6 1 roll Encoding 3 1 roll put -CharStrings 3 1 roll put Metrics 3 1 roll put -end}bd/Z{findfont dup maxlength 2 add dict exch -dup{1 index/FID ne{3 index 3 1 roll put}{pop pop}ifelse}forall -pop dup dup/Encoding get 256 array copy dup/$fe xd -/Encoding exch put dup/Fontname 3 index put -3 -1 roll dup length 0 ne{0 exch{dup type 0 type eq{exch pop}{ -$fe exch 2 index exch put 1 add}ifelse}forall -pop}if dup 256 dict dup/$met xd/Metrics exch put -dup/FontMatrix get 0 get 1000 mul 1 exch div -3 index length 256 eq{0 1 255{dup $fe exch get -dup/.notdef eq{pop pop}{5 index 3 -1 roll get -2 index mul $met 3 1 roll put}ifelse}for}if -pop definefont pop pop}bd/@ftx{{currentpoint 3 -1 roll -(0) dup 3 -1 roll 0 exch put dup @gs true charpath -$ctm setmatrix @@txt @gr @np stringwidth pop 3 -1 roll add exch moveto -}forall}bd/@ft{matrix currentmatrix exch $sdf{$scf $sca $scp @ss}if -$fil 1 eq{/@@txt/@pf ld @ftx}{$fil 2 eq{/@@txt/@ff ld @ftx}{$fil 3 eq -{/@@txt/@Pf ld @ftx}{$t $c $m $y $k $n $o @scc{show}{pop}ifelse}ifelse -}ifelse}ifelse $sdf{$dsf $dsa $dsp @ss}if setmatrix}bd -/@st{matrix currentmatrix exch $SDF{$SCF $SCA $SCP @ss}if -$T $C $M $Y $K $N $O @scc{{currentpoint 3 -1 roll -(0) dup 3 -1 roll 0 exch put dup @gs true charpath -$ctm setmatrix $ptm concat stroke @gr @np stringwidth pop 3 -1 roll add exch moveto -}forall}{pop}ifelse $SDF{$dsf $dsa $dsp @ss}if -setmatrix}bd/@te{@ft}bd/@tr{@st}bd/@ta{dup -@gs @ft @gr @st}bd/@t@a{dup @gs @st @gr @ft}bd -/@tm{/$textsave save def @sm concat}bd/e{/t{@te}def}bd -/r{/t{@tr}def}bd/o{/t{pop}def}bd/a{/t{@ta}def}bd -/@a{/t{@t@a}def}bd/t{@te}def/T{@np $ctm setmatrix -/$ttm matrix def $textsave restore}bd/@t{/$stm $stm currentmatrix def -3 1 roll moveto $ttm concat t $stm setmatrix}def -/@n{/$ttm exch matrix rotate def}bd/@s{}bd -/@l{}bd/@B{@gs S @gr F}bd/@b{@cp @B}bd/@w{matrix rotate/$ptm xd -matrix scale $ptm dup concatmatrix/$ptm xd -1 eq{$ptm exch dup concatmatrix/$ptm xd}if -1 w}bd/@g{1 eq dup/$sdf xd{/$scp xd/$sca xd -/$scf xd}if}bd/@G{1 eq dup/$SDF xd{/$SCP xd -/$SCA xd/$SCF xd}if}bd/@D{3 copy @ss/$dsp xd -/$dsa xd/$dsf xd}bd/@j{@sv @np}bind def/@J{@rs}bind def -/@sep{/ColorSeparationMode where{pop}{/ColorSeparationMode 0 def -/CurrentInkName (Composite) def}ifelse ColorSeparationMode 0 eq{ -/CurrentInkName (Composite) def}if/CurrentInkName where{pop}{ -/CurrentInkName (Composite) def}ifelse CurrentInkName (Composite) eq -{/$ink -1 def}{CurrentInkName (Cyan) eq{/$ink 0 def}{ -CurrentInkName (Magenta) eq{/$ink 1 def}{CurrentInkName (Yellow) eq -{/$ink 2 def}{CurrentInkName (Black) eq{/$ink 3 def}{/$ink 4 def -}ifelse}ifelse}ifelse}ifelse}ifelse}bd @sep -/@whi{@gs -72000 dup moveto -72000 72000 lineto -72000 dup lineto 72000 -72000 lineto closepath 1 setgray fill -@gr}bd/@neg{ [{1 exch sub}/exec cvx currenttransfer/exec cvx] cvx settransfer -@whi}bd/@reg{[] 0 d 0 setgray .3 setlinewidth -2 copy 5.4 0 360 arc closepath 2 copy moveto 9 0 rlineto -2 copy moveto -9 0 rlineto 2 copy moveto 0 9 rlineto -moveto 0 -9 rlineto stroke}bd/leftbracket{(\050)}def -/rightbracket{(\051)}def - -%%EndProlog -%%BeginSetup -11.4737 setmiterlimit -1.00 setflat -/$fst 128 def -[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 277 -295 309 555 555 775 758 352 369 369 426 605 277 332 277 438 555 -555 555 555 555 555 555 555 555 555 277 277 605 605 605 592 867 -740 574 813 744 535 484 871 684 227 482 592 463 920 740 869 592 -871 607 498 426 654 701 961 609 592 480 352 605 352 605 500 352 -684 682 646 686 650 314 674 609 199 203 502 199 938 609 654 682 -682 301 389 340 607 555 830 480 535 426 352 672 352 605 0 379 -502 439 199 555 502 484 252 252 486 484 553 553 500 605 453 502 -1000 1174 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 -295 555 555 555 555 387 615 369 746 369 426 605 1000 746 0 332 -605 332 332 375 607 564 277 324 332 369 426 830 830 830 592 740 -740 740 740 740 740 992 813 535 535 535 535 227 227 227 227 789 -740 869 869 869 869 869 1193 867 654 654 654 654 592 592 555 684 -684 684 684 684 684 1156 646 650 650 650 650 199 199 199 199 654 -609 654 654 654 654 654 1137 652 607 607 607 607 535 682 535 ] -CorelDrawReencodeVect /_AvantGarde-Book /AvantGarde-Book Z -[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 277 -295 309 555 555 775 758 352 369 369 426 605 277 332 277 438 555 -555 555 555 555 555 555 555 555 555 277 277 605 605 605 592 867 -740 574 813 744 535 484 871 684 227 482 592 463 920 740 869 592 -871 607 498 426 654 701 961 609 592 480 352 605 352 605 500 352 -684 682 646 686 650 314 674 609 199 203 502 199 938 609 654 682 -682 301 389 340 607 555 830 480 535 426 352 672 352 605 0 379 -502 439 199 555 502 484 252 252 486 484 553 553 500 605 453 502 -1000 1174 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 -295 555 555 555 555 0 615 369 746 369 426 605 1000 746 0 332 -605 332 332 375 607 564 277 324 332 369 426 830 830 830 592 740 -740 740 740 740 740 992 813 535 535 535 535 227 227 227 227 789 -740 869 869 869 869 869 1193 867 654 654 654 654 592 592 555 684 -684 684 684 684 684 1156 646 650 650 650 650 199 199 199 199 654 -609 654 654 654 654 654 1137 652 607 607 607 607 535 682 535 ] -CorelDrawReencodeVect /_AvantGarde-BookOblique /AvantGarde-BookOblique Z -[ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 279 -279 359 561 561 859 680 279 381 381 439 600 279 420 279 461 561 -561 561 561 561 561 561 561 561 561 279 279 600 600 600 561 740 -740 580 779 699 520 480 840 680 279 480 619 439 900 740 840 561 -840 580 520 420 641 699 900 680 619 500 320 641 320 600 500 279 -660 660 641 660 641 279 660 600 240 260 580 240 939 600 641 660 -660 320 439 301 600 561 801 561 580 461 340 600 340 600 0 420 -539 480 240 561 480 480 240 240 520 520 561 561 500 600 480 480 -1000 1279 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 -279 561 561 561 561 537 561 500 740 359 461 600 1000 740 0 359 -600 336 336 420 576 600 279 340 336 359 461 840 840 840 561 740 -740 740 740 740 740 900 779 520 520 520 520 279 279 279 279 742 -740 840 840 840 840 840 1061 840 641 641 641 641 619 561 600 660 -660 660 660 660 660 1080 641 641 641 641 641 240 240 240 240 641 -600 641 641 641 641 641 1080 660 600 600 600 600 580 660 580 ] -CorelDrawReencodeVect /_AvantGarde-Demi /AvantGarde-Demi Z - -%%EndSetup -@sv -/$ctm matrix currentmatrix def -@sv -%%Note: Object -486.00 729.00 648.00 801.00 @E - 0 O 0 @g -0.00 0.00 0.00 0.50 k -%%RECT 162.000 -72.000 0.000 -486.00 801.00 m -648.00 801.00 L -648.00 729.00 L -486.00 729.00 L -486.00 801.00 L -@c -F -%%Note: Object -495.00 738.00 657.00 810.00 @E - 0 O 0 @g -0.00 0.00 0.00 0.50 k -%%RECT 162.000 -72.000 0.000 -495.00 810.00 m -657.00 810.00 L -657.00 738.00 L -495.00 738.00 L -495.00 810.00 L -@c -F -%%Note: Object -504.00 747.00 666.00 819.00 @E - 0 O 0 @g -0.00 0.00 0.00 0.50 k -%%RECT 162.000 -72.000 0.000 -504.00 819.00 m -666.00 819.00 L -666.00 747.00 L -504.00 747.00 L -504.00 819.00 L -@c -F -%%Note: Object -495.00 756.00 657.00 828.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.00 k -%%RECT 162.000 -72.000 0.000 -495.00 828.00 m -657.00 828.00 L -657.00 756.00 L -495.00 756.00 L -495.00 828.00 L -@c -B -%%Note: Object -486.00 747.00 648.00 819.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.00 k -%%RECT 162.000 -72.000 0.000 -486.00 819.00 m -648.00 819.00 L -648.00 747.00 L -486.00 747.00 L -486.00 819.00 L -@c -B -%%Note: Object -54.00 603.00 63.00 782.86 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.70 k -%%RECT 9.000 -135.000 0.000 -54.00 782.86 m -63.00 782.86 L -63.00 603.00 L -54.00 603.00 L -54.00 782.86 L -@c -B -%%Note: Object -702.00 513.07 710.86 828.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.70 k -%%RECT 9.000 -135.000 0.000 -702.00 828.00 m -710.86 828.00 L -710.86 513.07 L -702.00 513.07 L -702.00 828.00 L -@c -B -%%Note: Object -63.00 692.86 108.00 693.14 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -63.00 693.00 m -100.44 693.00 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -108.00 693.00 m -92.95 699.41 L -95.11 695.09 95.11 690.91 92.95 686.59 C -108.00 693.00 L -f -@J -%%Note: Object -113.40 639.07 224.93 738.00 @E - 0 O 0 @g -0.00 0.00 0.00 0.50 k -%%RECT 81.000 -63.000 0.000 -113.40 738.00 m -224.93 738.00 L -224.93 639.07 L -113.40 639.07 L -113.40 738.00 L -@c -F -%%Note: Object -108.00 648.07 219.24 747.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.00 k -%%RECT 81.000 -63.000 0.000 -108.00 747.00 m -219.24 747.00 L -219.24 648.07 L -108.00 648.07 L -108.00 747.00 L -@c -B -%%Note: Object -123.98 697.68 209.16 712.58 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 125 702] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 194.00 z -0 0 (local logger) @t -T -%%Note: Object -284.40 639.07 395.93 738.00 @E - 0 O 0 @g -0.00 0.00 0.00 0.50 k -%%RECT 81.000 -63.000 0.000 -284.40 738.00 m -395.93 738.00 L -395.93 639.07 L -284.40 639.07 L -284.40 738.00 L -@c -F -%%Note: Object -275.40 648.00 386.64 746.93 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.00 k -%%RECT 81.000 -63.000 0.000 -275.40 746.93 m -386.64 746.93 L -386.64 648.00 L -275.40 648.00 L -275.40 746.93 L -@c -B -%%Note: Object -291.46 697.61 373.10 712.51 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 293 701] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 194.00 z -0 0 (inter-logger) @t -T -%%Note: Object -216.00 585.00 270.00 603.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%ELLI 54.000 -18.000 270.000 270.000 0 -243.00 603.00 m -257.83 603.00 270.00 598.97 270.00 594.00 c -270.00 589.03 257.83 585.00 243.00 585.00 c -228.17 585.00 216.00 589.03 216.00 594.00 c -216.00 598.97 228.17 603.00 243.00 603.00 c -@c -S -%%Note: Object -216.00 531.00 270.00 549.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%ELLI 54.000 -18.000 270.000 270.000 0 -243.00 549.00 m -257.83 549.00 270.00 544.97 270.00 540.00 c -270.00 535.03 257.83 531.00 243.00 531.00 c -228.17 531.00 216.00 535.03 216.00 540.00 c -216.00 544.97 228.17 549.00 243.00 549.00 c -@c -S -%%Note: Object -215.86 540.00 216.14 594.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -216.00 594.00 m -216.00 540.00 L -S -%%Note: Object -269.86 540.00 270.14 594.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -270.00 594.00 m -270.00 540.00 L -S -%%Note: Object -171.00 603.00 225.00 648.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -171.00 648.00 m -219.60 607.54 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.02 2.02 0 @w -225.00 603.00 m -218.02 616.68 L -216.94 612.29 214.49 609.26 210.38 607.46 C -225.00 603.00 L -f -@J -%%Note: Object -261.00 603.00 324.00 648.00 @E -0 J 0 j [10 5 ] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -318.10 643.75 m -261.00 603.00 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.09 2.09 0 @w -324.00 648.00 m -315.72 634.46 L -315.00 639.00 312.70 642.46 308.52 644.69 C -324.00 648.00 L -f -@J -%%Note: Object -387.00 693.00 468.00 774.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -387.00 693.00 m -463.03 769.03 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.02 2.02 0 @w -468.00 774.00 m -453.74 768.31 L -458.06 766.87 460.94 764.14 462.38 759.82 C -468.00 774.00 L -f -@J -%%Note: Object -531.14 684.00 585.14 702.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%ELLI 54.000 -18.000 270.000 270.000 0 -558.14 702.00 m -572.98 702.00 585.14 697.97 585.14 693.00 c -585.14 688.03 572.98 684.00 558.14 684.00 c -543.31 684.00 531.14 688.03 531.14 693.00 c -531.14 697.97 543.31 702.00 558.14 702.00 c -@c -S -%%Note: Object -531.14 630.00 585.14 648.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%ELLI 54.000 -18.000 270.000 270.000 0 -558.14 648.00 m -572.98 648.00 585.14 643.97 585.14 639.00 c -585.14 634.03 572.98 630.00 558.14 630.00 c -543.31 630.00 531.14 634.03 531.14 639.00 c -531.14 643.97 543.31 648.00 558.14 648.00 c -@c -S -%%Note: Object -531.00 639.00 531.29 693.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -531.14 693.00 m -531.14 639.00 L -S -%%Note: Object -585.00 639.00 585.29 693.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -585.14 693.00 m -585.14 639.00 L -S -%%Note: Object -477.00 738.00 639.00 810.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.00 k -%%RECT 162.000 -72.000 0.000 -477.00 810.00 m -639.00 810.00 L -639.00 738.00 L -477.00 738.00 L -477.00 810.00 L -@c -B -%%Note: Object -510.77 759.24 604.30 784.87 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 558 773] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 194.00 z --626 0 (bookkeeping) @t --275 -194 (server) @t -T -%%Note: Object -557.86 702.00 558.14 738.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -558.00 730.44 m -558.00 709.56 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -558.00 738.00 m -564.41 722.95 L -560.09 725.11 555.91 725.11 551.59 722.95 C -558.00 738.00 L -f -@J -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -558.00 702.00 m -564.41 717.12 L -560.09 714.96 555.91 714.96 551.59 717.12 C -558.00 702.00 L -f -@J -%%Note: Object -592.92 662.26 639.07 675.14 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 594 666] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 167.00 z -0 0 (storage) @t -T -%%Note: Object -531.14 468.00 585.14 486.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%ELLI 54.000 -18.000 270.000 270.000 0 -558.14 486.00 m -572.98 486.00 585.14 481.97 585.14 477.00 c -585.14 472.03 572.98 468.00 558.14 468.00 c -543.31 468.00 531.14 472.03 531.14 477.00 c -531.14 481.97 543.31 486.00 558.14 486.00 c -@c -S -%%Note: Object -531.14 414.00 585.14 432.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%ELLI 54.000 -18.000 270.000 270.000 0 -558.14 432.00 m -572.98 432.00 585.14 427.97 585.14 423.00 c -585.14 418.03 572.98 414.00 558.14 414.00 c -543.31 414.00 531.14 418.03 531.14 423.00 c -531.14 427.97 543.31 432.00 558.14 432.00 c -@c -S -%%Note: Object -531.00 423.00 531.29 477.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -531.14 477.00 m -531.14 423.00 L -S -%%Note: Object -585.00 423.00 585.29 477.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -585.14 477.00 m -585.14 423.00 L -S -%%Note: Object -486.00 513.00 648.00 585.00 @E - 0 O 0 @g -0.00 0.00 0.00 0.50 k -%%RECT 162.000 -72.000 0.000 -486.00 585.00 m -648.00 585.00 L -648.00 513.00 L -486.00 513.00 L -486.00 585.00 L -@c -F -%%Note: Object -477.00 522.00 639.00 594.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.00 k -%%RECT 162.000 -72.000 0.000 -477.00 594.00 m -639.00 594.00 L -639.00 522.00 L -477.00 522.00 L -477.00 594.00 L -@c -B -%%Note: Object -531.00 543.24 584.06 568.87 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 558 558] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 194.00 z --358 0 (logging) @t --275 -194 (server) @t -T -%%Note: Object -557.86 486.00 558.14 522.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -558.00 514.44 m -558.00 493.56 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -558.00 522.00 m -564.41 506.95 L -560.09 509.11 555.91 509.11 551.59 506.95 C -558.00 522.00 L -f -@J -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -558.00 486.00 m -564.41 501.12 L -560.09 498.96 555.91 498.96 551.59 501.12 C -558.00 486.00 L -f -@J -%%Note: Object -592.92 446.26 639.07 459.14 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 594 449] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 167.00 z -0 0 (storage) @t -T -%%Note: Object -278.35 568.94 351.50 594.43 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 315 585] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 167.00 z --485 0 (local logger) @t --265 -167 (log file) @t -T -%%Note: Object -16.13 796.18 96.34 811.66 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 18 800] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Demi 194.00 z -0 0 (L) @t -76 0 (ogging A) @t -932 0 (P) @t -1023 0 (I) @t -T -%%Note: Object -682.92 845.57 730.87 857.38 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 684 845] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Demi 194.00 z -0 0 (L) @t -76 0 (&B A) @t -506 0 (P) @t -597 0 (I) @t -T -%%Note: Object -420.26 834.98 536.18 848.45 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 422 836] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Demi 194.00 z -0 0 (L) @t -76 0 (&B A) @t -506 0 (P) @t -597 0 (I \050inter) @t -1182 0 (nal\051) @t -T -%%Note: Object -639.00 773.86 702.00 774.14 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -694.44 774.00 m -646.56 774.00 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -702.00 774.00 m -686.95 767.52 L -689.11 771.84 689.11 776.16 686.95 780.48 C -702.00 774.00 L -f -@J -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -639.00 774.00 m -654.12 767.52 L -651.96 771.84 651.96 776.16 654.12 780.48 C -639.00 774.00 L -f -@J -%%Note: Object -639.00 557.86 702.00 558.14 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -694.44 558.00 m -646.56 558.00 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -702.00 558.00 m -686.95 551.52 L -689.11 555.84 689.11 560.16 686.95 564.48 C -702.00 558.00 L -f -@J -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -639.00 558.00 m -654.12 551.52 L -651.96 555.84 651.96 560.16 654.12 564.48 C -639.00 558.00 L -f -@J -%%Note: Object -387.00 558.00 468.00 693.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -387.00 693.00 m -464.40 564.05 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.02 2.02 0 @w -468.00 558.00 m -465.91 573.19 L -463.46 569.38 460.15 567.36 455.69 567.00 C -468.00 558.00 L -f -@J -%%Note: Object --18.00 755.86 54.00 756.14 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 --18.00 756.00 m -50.47 756.00 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -54.00 756.00 m -47.02 758.95 L -48.02 756.94 48.02 755.06 47.02 753.05 C -54.00 756.00 L -f -@J -%%Note: Object --31.18 763.92 52.92 774.50 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 -29 765] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 167.00 z -0 0 (User Interface) @t -T -%%Note: Object --18.00 711.00 54.00 711.29 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 --18.00 711.14 m -50.47 711.14 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -54.00 711.14 m -47.02 714.10 L -48.02 712.08 48.02 710.21 47.02 708.19 C -54.00 711.14 L -f -@J -%%Note: Object --44.28 718.78 53.57 729.07 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 -41 719] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 167.00 z -0 0 (Resource Broker) @t -T -%%Note: Object --18.00 664.20 54.00 664.49 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 --18.00 664.34 m -50.47 664.34 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -54.00 664.34 m -47.02 667.30 L -48.02 665.28 48.02 663.41 47.02 661.39 C -54.00 664.34 L -f -@J -%%Note: Object --0.43 673.63 18.22 684.22 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 0 675] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 167.00 z -0 0 (JSS) @t -T -%%Note: Object --18.00 621.00 54.00 621.29 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 --18.00 621.14 m -50.47 621.14 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -54.00 621.14 m -47.02 624.10 L -48.02 622.08 48.02 620.21 47.02 618.19 C -54.00 621.14 L -f -@J -%%Note: Object --28.87 626.40 51.05 639.29 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 -26 630] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 167.00 z -0 0 (JobManager) @t -T -%%Note: Object -468.00 738.00 477.00 810.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.70 k -%%RECT 9.000 -72.000 0.000 -468.00 810.00 m -477.00 810.00 L -477.00 738.00 L -468.00 738.00 L -468.00 810.00 L -@c -B -%%Note: Object -468.00 522.00 477.00 594.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w - 0 O 0 @g -0.00 0.00 0.00 0.70 k -%%RECT 9.000 -72.000 0.000 -468.00 594.00 m -477.00 594.00 L -477.00 522.00 L -468.00 522.00 L -468.00 594.00 L -@c -B -%%Note: Object -711.00 746.86 783.00 747.14 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 -714.53 747.00 m -779.47 747.00 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -711.00 747.00 m -718.06 749.95 L -717.05 747.94 717.05 746.06 718.06 744.05 C -711.00 747.00 L -f -@J -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -783.00 747.00 m -776.02 749.95 L -777.02 747.94 777.02 746.06 776.02 744.05 C -783.00 747.00 L -f -@J -%%Note: Object -711.00 665.86 783.00 666.14 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 -714.53 666.00 m -779.47 666.00 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -711.00 666.00 m -718.06 668.95 L -717.05 666.94 717.05 665.06 718.06 663.05 C -711.00 666.00 L -f -@J -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -783.00 666.00 m -776.02 668.95 L -777.02 666.94 777.02 665.06 776.02 663.05 C -783.00 666.00 L -f -@J -%%Note: Object -754.99 710.64 799.27 721.22 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07047 755 710] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 194.00 z -0 0 (clients) @t -T -%%Note: Object -8.42 288.29 32.40 298.87 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 8 289] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-Book 167.00 z -0 0 (UL) @t -179 0 (M) @t -T -%%Note: Object --0.07 271.80 52.06 315.22 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%RECT 54.000 -45.000 0.000 --0.07 315.22 m -52.06 315.22 L -52.06 271.80 L --0.07 271.80 L --0.07 315.22 L -@c -S -%%Note: Object -6.26 323.57 42.84 333.36 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 7 324] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z -0 0 (event) @t -T -%%Note: Object -194.98 319.97 345.46 344.30 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 269 334] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z --992 0 (queueing, transferring to ) @t --750 -167 (appropriate server) @t -T -%%Note: Object -88.42 304.92 153.65 316.80 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 89 307] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z -0 0 (accepting) @t -T -%%Note: Object -80.93 298.58 170.93 298.87 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 -80.93 298.73 m -167.40 298.73 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -170.93 298.73 m -163.94 301.68 L -164.95 299.66 164.95 297.79 163.94 295.78 C -170.93 298.73 L -f -@J -%%Note: Object -376.34 304.99 444.67 317.09 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 377 307] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z -0 0 (transferring) @t -T -%%Note: Object -133.34 249.55 205.34 261.07 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 135 251] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z -0 0 (local scope) @t -T -%%Note: Object -194.98 384.12 323.06 397.01 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 197 386] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z -0 0 (logger & inter-logger) @t -T -%%Note: Object -368.93 298.73 458.93 299.02 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 -368.93 298.87 m -455.40 298.87 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -458.93 298.87 m -451.94 301.82 L -452.95 299.81 452.95 297.94 451.94 295.92 C -458.93 298.87 L -f -@J -%%Note: Object -206.93 289.80 332.86 307.80 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%RECT 135.000 -18.000 0.000 -206.93 307.80 m -332.86 307.80 L -332.86 289.80 L -206.93 289.80 L -206.93 307.80 L -@c -S -%%Note: Object -224.78 289.80 225.07 307.80 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -224.93 307.80 m -224.93 289.80 L -S -%%Note: Object -242.78 289.80 243.07 307.80 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -242.93 307.80 m -242.93 289.80 L -S -%%Note: Object -260.78 289.80 261.07 307.80 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -260.93 307.80 m -260.93 289.80 L -S -%%Note: Object -278.78 289.80 279.07 307.80 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -278.93 307.80 m -278.93 289.80 L -S -%%Note: Object -296.78 289.80 297.07 307.80 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -296.93 307.80 m -296.93 289.80 L -S -%%Note: Object -314.78 289.80 315.07 307.80 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -314.93 307.80 m -314.93 289.80 L -S -%%Note: Object --9.00 243.00 360.00 261.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 1.44 1.44 0.00 @w -%%CURV 4 --9.00 261.00 m --9.00 243.00 L -360.00 243.00 L -360.00 261.00 L -S -%%Note: Object -144.00 360.00 360.00 378.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 1.44 1.44 0.00 @w -%%CURV 4 -144.00 360.00 m -144.00 378.00 L -360.00 378.00 L -360.00 360.00 L -S -%%Note: Object -495.00 312.34 535.54 325.87 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%ELLI 54.000 -18.000 270.000 270.000 0 -515.30 325.87 m -526.39 325.87 535.54 322.85 535.54 319.10 c -535.54 315.36 526.39 312.34 515.30 312.34 c -504.14 312.34 495.00 315.36 495.00 319.10 c -495.00 322.85 504.14 325.87 515.30 325.87 c -@c -S -%%Note: Object -495.00 271.80 535.54 285.26 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%ELLI 54.000 -18.000 270.000 270.000 0 -515.30 285.26 m -526.39 285.26 535.54 282.24 535.54 278.57 c -535.54 274.82 526.39 271.80 515.30 271.80 c -504.14 271.80 495.00 274.82 495.00 278.57 c -495.00 282.24 504.14 285.26 515.30 285.26 c -@c -S -%%Note: Object -494.86 278.57 495.14 319.10 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -495.00 319.10 m -495.00 278.57 L -S -%%Note: Object -535.39 278.57 535.68 319.10 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%CURV 2 -535.54 319.10 m -535.54 278.57 L -S -%%Note: Object -472.61 249.12 658.01 262.01 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 476 251] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z -0 0 (bookkeeping & logging server) @t -T -%%Note: Object -637.70 322.92 691.78 334.80 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 638 325] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z -0 0 (querying) @t -T -%%Note: Object -637.70 286.92 691.78 298.80 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 638 289] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z -0 0 (querying) @t -T -%%Note: Object -478.37 328.54 548.50 353.16 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 512 343] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z --457 0 (permanent) @t --308 -167 (storage) @t -T -%%Note: Object -582.55 357.34 623.81 378.50 @E -%%TEXT -[0.07199 0.00000 0.00000 0.07199 602 370] @tm - 0 O 0 @g -0.00 0.00 0.00 1.00 k -e -/_AvantGarde-BookOblique 167.00 z --231 0 (query) @t --270 -167 (cache) @t -T -%%Note: Object -539.93 307.51 575.86 307.80 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 -539.93 307.66 m -572.33 307.66 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -575.86 307.66 m -568.87 310.61 L -569.88 308.59 569.88 306.72 568.87 304.70 C -575.86 307.66 L -f -@J -%%Note: Object -629.93 316.58 693.00 316.87 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 -633.46 316.73 m -689.47 316.73 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -629.93 316.73 m -636.98 319.68 L -635.98 317.66 635.98 315.79 636.98 313.78 C -629.93 316.73 L -f -@J -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -693.00 316.73 m -686.02 319.68 L -687.02 317.66 687.02 315.79 686.02 313.78 C -693.00 316.73 L -f -@J -%%Note: Object -539.93 280.58 692.93 280.87 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.72 0.72 0.00 @w -%%CURV 2 -543.46 280.73 m -689.40 280.73 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -539.93 280.73 m -546.98 283.68 L -545.98 281.66 545.98 279.79 546.98 277.78 C -539.93 280.73 L -f -@J -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 1.01 1.01 0 @w -692.93 280.73 m -685.94 283.68 L -686.95 281.66 686.95 279.79 685.94 277.78 C -692.93 280.73 L -f -@J -%%Note: Object -584.93 298.73 620.86 352.73 @E -0 J 0 j [5 5 ] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 0.22 0.22 0.00 @w -%%RECT 45.000 -81.000 0.000 -584.93 352.73 m -620.86 352.73 L -620.86 298.73 L -584.93 298.73 L -584.93 352.73 L -@c -S -%%Note: Object -468.00 243.00 656.93 261.00 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 1.44 1.44 0.00 @w -%%CURV 4 -468.00 261.00 m -468.00 243.00 L -656.93 243.00 L -656.93 261.00 L -S -%%Note: Object -219.67 692.86 275.54 693.14 @E -0 J 0 j [] 0 d 0 R 0 @G -0.00 0.00 0.00 1.00 K -0 2.16 2.16 0.00 @w -%%CURV 2 -219.67 693.00 m -267.98 693.00 L -S -@j -0.00 0.00 0.00 1.00 K -0.00 0.00 0.00 1.00 k -0 @g -0 @G -[] 0 d 0 J 0 j -0 R 0 O 0 2.16 2.16 0 @w -275.54 693.00 m -260.50 699.41 L -262.66 695.09 262.66 690.91 260.50 686.59 C -275.54 693.00 L -f -@J -@rs -@rs -%%Trailer - end diff --git a/org.glite.lb.client/doc/api/fig/logging-arch.pdf b/org.glite.lb.client/doc/api/fig/logging-arch.pdf deleted file mode 100644 index 1d40d9d..0000000 --- a/org.glite.lb.client/doc/api/fig/logging-arch.pdf +++ /dev/null @@ -1,92 +0,0 @@ -%PDF-1.2 %âãÏÓ -1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj 2 0 obj << /Type /Pages /Kids [ 4 0 R ] /Count 1 >> endobj 3 0 obj << /ModDate (D:20011008121539) /Producer (Adobe PDF Library 2.0) /CreationDate (D:20010908121539) >> endobj 4 0 obj << /Type /Page /MediaBox [ -119.5 84.8779 730.8936 708.5 ] /Parent 2 0 R /PieceInfo << /Illustrator8.0 << /LastModified ()>> >> /Contents 11 0 R /Resources << /Font << /F12 9 0 R >> /ProcSet [ /PDF /Text ] >> >> endobj 9 0 obj << /Type /Font /Subtype /MMType1 /BaseFont /AdobeSansMM /FirstChar 0 /LastChar 255 /Encoding /WinAnsiEncoding /FontDescriptor 10 0 R /Widths [ 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 377 257 376 591 625 816 687 216 386 386 487 635 240 411 240 501 678 567 676 676 679 678 678 626 677 678 240 240 635 635 635 508 778 603 640 675 675 559 540 674 704 273 439 598 530 964 695 730 628 730 633 589 546 661 609 971 609 566 539 377 501 376 635 568 406 553 585 560 585 561 401 593 591 242 242 529 242 876 591 596 584 585 422 490 460 595 527 884 530 534 452 369 380 369 635 377 377 377 214 582 376 953 545 545 406 1191 589 296 968 377 377 377 377 216 216 376 376 417 474 948 406 923 490 296 968 377 377 566 377 257 644 652 662 634 380 567 406 764 381 476 635 411 764 406 383 635 444 446 406 595 570 240 406 404 393 476 939 949 1016 509 603 603 603 603 603 603 904 675 559 559 559 559 273 273 273 273 683 695 730 730 730 730 730 635 730 661 661 661 661 566 628 604 553 553 553 553 553 553 901 560 561 561 561 561 242 242 242 242 596 591 596 596 596 596 596 635 595 595 595 595 595 534 586 534 ] >> endobj 10 0 obj << /Type /FontDescriptor /FontName /AdobeSansMM /FontBBox [ 0 0 0 0 ] /Flags 32 /CapHeight 700 /Ascent 0 /Descent 0 /StemV 0 /ItalicAngle 0 /XHeight 500 >> endobj 11 0 obj << /Filter [ /ASCII85Decode /FlateDecode ] /Length 12 0 R >> stream -8;X]T>E9H>(&eC8+8RDfUhSGo\tmkK42>_l>*KUT+V-+7`csTUm4g=:f^,ff3N"K8 -5irZ?EN\Nf,'tAp4<\/^6uZ^ -(m_f/JTKGZQX4gJ[B=rLj,`ThZ_u(>(JgORDtEu[GJNES]cWR-UK>'gqbQgL5G#Pl -IpB_ldXLqpChHh]jeqeBF$S(/XnVGbj8+5>Hl(/9ok"3_p&m$HQ%iBqsKaug]qrn"oS$dK20h4s,%Lb.$EGA+(>'1=4'ini&;2?.L] -S(UU7rGMT-@D;q4YOAolT7R<7];mN^*V9JGSm=4T;m('1^UmL@3!3JVoq[GQ,,$/& -D%.Y1`f;?%"JhUZQg&%; -ilMfFA)?30n-Nn#hofAq^0QAhKP3TZS9N+JgV.?r:0-PD=e/]-R*;rkOjs]`?$#fe -H8/Uc@hC[_dtSb&YoH9`^uuRPmJU>.1cdt*B+P(TW_CTKF-0h$(?*$1tNnR@(OS. -ESH%A!jLo/LEAkcTeVM/_El4QRg?=g'V7m_V!;%m%UJ-hLD!F,*NVG=]A=^ghE-ND -f-uQ(6T$-@l4*Tb8)E4Q!E-R2j!qfl8d?XkM,:SGX?t;XWtI]YS`EU6<&e24!!Qt( -:$?3b`u\F5M`J/D5G2@^'KE.cghUEMs4 -kG;e9;'Zjh,U(eU=oh?%0`()(X,sW^mL)d@g&qS#DF9,jJmL+s!TSPPmn+S2\2t&_ -51^65(WNECEPS@]f]s!u?-g>4kTlN8#*s/E<@9B\'j(^';a:@R.&**3n!SeKa**XC -3LFe-.MO5'+$U)8(i!F#n%m/_<:*h)d$hN??2Mde.))->!\=spgW2b1\rpSp?`OP) -[HHRo8?%J4U')>O+fI-dn2XD#Z)A-'AW_d')j7(iOA*K$.]rC>O]dV<6ZkK]YVt+O -_p$j(4dn,](b)>h2Q8G%n5WWFZ)A*>es9Xt1mK1W_((nCVD=P(4O-14[Ouo%(n&_^ -:jPA\5!eEn;4o.W'W=SL2't"=J&kXFE6c/QDVr39/jHH+=4N]8\m@jJQ:VR/LD(!N ---)s-5beW-<9iLapLuC+@r')'j"o'Ym8! -pL\g)ctX#(lrWM8!`)PQc\-Y'K(De^s#TeJfMRfF(_,DG?AJgGQ,s.6SA`E/Mh:7k -+VO\&BPC61:bIf#TgPl`J3b==\EcTcYn+Tj+V_lnFuNb[-X1H/,edfCbIWhs7AoW/lUKi[C^D>=6jYV(6;V1Q6$cRT/8E)&hCED"BfmQ, -,2cU,=t=DHBnXm![DEWA`l$$Sn3*3q1.W*`9q%ltaMSdW`kt5^=Ohc3(H5&7W9Cqb -9P#oL3VWZ-9'P?$%(E1/s?d!Q"`pn/- -Np-2H)i>]>0`A\]qP@9XJ_jU'o?Yh7l?an0F?%^63-Pu\5"A?L$/#cO5c70r_;@r8 -H@)4.p]+k7=i/al@(4B"Z364Rk>u.d*\"?CVgF>ZpFsG:4@ia1M213GE*(6cM%@+4 -*^lMda#f32lVO9bkCK9be,O\7GTgFc#@H"[0_A&?e"cL!J0H9UTB=2tPC8Tu?e5P6 --7&e2#5H*i1N]()$K]mrY(r3gF@!O7;>,Lh0W(,'90b(Y4&%lF\F5L/n-^-K9Mc&Q -W7mk=d08g`.=7@-"Uii?l4aE3kr9CL3=6HO:k;tL;8=le8`Pg`Vht>A_o^#.OGO_G -4:On0W5N$q:J1hc<9Jot;id*`aiRpI^2Nm)_bi0L3?`@[^ubQoQbbrsEXjHEKEUsr -/C2_:AF_ki+^oot=Iu9XalMN9OM)%,4A1N_#pi":q]h2Kg8Ip_[P5c!Z]qGVTJH95 -iV1BX+pKq/VmpK$#WoML%F2bi_\7!M1P4%+*&&A\??6.l5f7,_'A+%M.Y6S?.:HF! -.0=r8L54e@@66HR.(Ba%U,C*^qkIK%J-jLkZ.e2p`nVtcUdVKJXXH*j3`LpR-BIrP -4S+@VN#mf\P&8XXas2ecas2esas.7BA0-S*8sFU3e191;`$YAFfSj8iO!Ltjf:bMV -b`08`'A)baWlsp?rTk3YX[Z1AUnh?$Egnng4';I-J_ -_E(f)4U'`Q3SU5oU`4r!'Y['i*!MN$BnNhG-p$mE6U(lnpu:>oi)O!`ai5_9ON -Sf$D42IR/2i(9&KJ/8pq/a#)mkhGQV$]_8BAAM+Fk^+BQKbWkSs+"0Vq^Zicg\IRM -G.eQsL($rO@S;/D[*b/X1%Lb>FZWKk(SFabDH(`4WG("ec9?Ks".a^^=(!"C-Aa@!, -VT^Q%o"7ktb,\4YKQ'nedN*],bMdC`N_IMegUAiup[co\V-&M5aoCd08>J0,4.r9K -iMKJje"\'/h<2JW7.FfEm[Dpmu@8KN4K(+jH -3L8WNK%WE),[f[k0\JuhX)QK8lGH/sZ"4kC!sje$C#?9RMY(aI]>nFAc8cCMU3$Bp -1=6kA^>O]YM_=P,+?H8#dFl2Y3p/V)aDW0B79ikGic11dNPg=p6>iZliMuS[(U[m8 -X#q%@PplB#dOeW^MB;^-7;!<3HY*t_Eulh'm2@k5dC;096k9`*fZl&7@^EgeGCNr: -eb/m@r@dEcZ5g=_"M\@EJL@'6(>b+5n0)FG%NC/-<2R$le_4%!qt'm,K*7_[c%E#3 -Xhh4r(sMWFm.O]=Wl$GgG1]W@R%Et)]o6n(pH2G.@.6<_Cu]1Nt#$qG71JF -DICe8E"B+t;'7GT&r4U7"_%=[,hd;]*8QrI6?h3*iN[Dj<;u\WINO\L^NK;*qL;EA.oG&dpID!fE^LG?ZYe#od_sOYGCWBW5WknO3HuVufCcNC -i'Gcn&lKcsNQ"D`neH2Mqp`=+r:Uhk.oHH66OBOl>pCU5a_6MPjV^u#UYM#Mb7]5. -E>>cPE_f&U[%r"m9J=N#kpds7+)&Kr%o.D3hQ?fl'+7BtW]ZVqc9eXCV1(Q61fpY* -IhO_?R'[/MHag5bG71/q:M4!`]3rT*/C?NubD\#(SSg#8emuK7@oNb^I(.=O'(XXj+;YhP=*)#9XkfRqR@Q(4aq;.6&]jm/% -grbk?-t+stRY!!+HD^2A/F0-!->(%Y5'R(FWBd1J-W=;jK88h>%A!<)$,JM3-GnJo -;]R9(k%4?b">Z8/+L>q11i/[AG"^7JAtUKhLcqt8I/IsRpA'TF0S -qEs@rWq)dKbI;EMGU6A^WM?1]^\3QsND-*p&k?,,j^T'E[t"-1d-0MOY-39O.M%6m -LLCc$'l)$thq#XRZ+5l3TAF`@Cim-m$:i(U*E02E-R/54^YI+AGA.K1nJ:^D*4r0^?'+l/._t,oI8P:S/Al4+3(\B?fK/]agN#.F&K>u*" -QoC@t.)^4RY$K?k.fBJY2rkf)%b)4`[B(LN(Gm"1qa:t6,>d3"s3i;1,`d\5nV1;# -s"*SHf6b\W_#eJE%Tk9i6-FG1C8O^HJ4;DdZ2%<5,&%[gG4@Br[,.]T/?V=KaeKh%U0LS$&ea+*MQXcRfWR%37Ckc"UVjn -d&dl-86smP))K`Y]hb,"%bmEZ`?8pX6A=D5Q$&g!+Z;bAmOD1>n'`Ua/+#"bAr",c -=SEWO;3ZT=/JuYK#&t^t2e,e&WZa+ch88Hj)q]4oSmNZTksZm`j(d/8g@=B7]e2&S -0@>G-67MiLGb>cZN]8"-2_Ur]-KS)'mkfK_hK)-sPWL.s_,%0u^bZri,8*G7XMPaP -@XT)Z%]AtTKK^,'qYRrfrAO_e?L5B~> endstream endobj 12 0 obj 5047 endobj xref 0 13 0000000005 65535 f -0000000016 00000 n -0000000069 00000 n -0000000133 00000 n -0000000251 00000 n -0000000006 00001 f -0000000007 00001 f -0000000008 00001 f -0000000000 00001 f -0000000486 00000 n -0000001700 00000 n -0000001884 00000 n -0000007028 00000 n -trailer << /Size 13 /Info 3 0 R /Root 1 0 R /ID[] >> startxref 7050 %%EOF \ No newline at end of file diff --git a/org.glite.lb.client/doc/glite-lb-dump.8 b/org.glite.lb.client/doc/glite-lb-dump.8 deleted file mode 100644 index aa2b6fe..0000000 --- a/org.glite.lb.client/doc/glite-lb-dump.8 +++ /dev/null @@ -1,62 +0,0 @@ -.TH GLITE-LB-DUMP 8 "April 2008" "EGEE Project" "Logging&Bookkeeping" - -.SH NAME -glite-lb-dump - utility for dumping job events from L&B database - -.SH SYNOPSIS -.B glite-lb-dump -.RI [ options ] -.br - -.SH DESCRIPTION -.B glite-lb-dump -is utility for dumping job events from L&B database. It is primarilly used for statistical purposes. By default, it dumps events from the time when the last dum ended upto now. - -.B glite-lb-dump -may be run periodically, however the periodic dumps are done by server itself, so check the configuration of the server first. - -.SH OPTIONS -.TP -.BI \-m \fR,\fP --server mkserver -L&B server machine name. If not specified, the environment variable EDG_WL_QUERY_SERVER is beeing checked. - -.TP -.BI \-f \fR,\fP --from YYYYMMDDHHmmss -Beginning of the time interval for events to be dumped. - -.TP -.BI \-t \fR,\fP --to YYYYMMDDHHmmss -End of the time interval for events to be dumped. - -.TP -.BI \-h \fR,\fP --help -Display help. - -.TP -.BI \-v \fR,\fP --version -Display version. - -.TP -.B "-d\fR,\fP --debug" -Print diagnostics on the -.I stderr\fR.\fP - -.\".SH USAGE -.\" Add any additional description here - -.PP - -.SH FILES -No configuration files needed. - -.SH ENVIRONMENT -No environment variables needed. - -.SH REPORTING BUGS -Please, report all bugs to EGEE Bug Tracking System located at https://savannah.cern.ch - -.SH SEE ALSO -.B glite-lb-bkindex\fR(8),\fP glite-lb-bkserverd\fR(8),\fP glite-lb-interlogd\fR(8),\fP glite-lb-logd\fR(8),\fP glite-lb-logevent\fR(1),\fP - -.SH AUTHOR -EU EGEE, JRA1. diff --git a/org.glite.lb.client/doc/glite-lb-load.8 b/org.glite.lb.client/doc/glite-lb-load.8 deleted file mode 100644 index 40509d7..0000000 --- a/org.glite.lb.client/doc/glite-lb-load.8 +++ /dev/null @@ -1,50 +0,0 @@ -.TH GLITE-LB-LOAD 8 "April 2008" "EGEE Project" "Logging&Bookkeeping" - -.SH NAME -glite-lb-load - utility for loading job events into the L&B database - -.SH SYNOPSIS -.B glite-lb-load -.RI [ options ] -.br - -.SH DESCRIPTION -.B glite-lb-load -is utility for loading job events into the L&B database. It is primarilly used for recovery purposes. By default, it loads events from the last dump. - -.SH OPTIONS -.IP "\-m, --server \fIbkserver\fR" -L&B server machine name. If not specified, the environment variable EDG_WL_QUERY_SERVER is beeing checked. - -.IP "\-f, --file \fIfilename\fR" -File with dumped data to be loaded. - -.IP "\-h, --help" -Display help. - -.IP "\-v, --version" -Display version. - -.IP "\-d, --debug" -Print diagnostics on the -.I stderr\fR.\fP - -.\".SH USAGE -.\" Add any additional description here - -.PP - -.SH FILES -No configuration files needed. - -.SH ENVIRONMENT -No environment variables needed. - -.SH REPORTING BUGS -Please, report all bugs to EGEE Bug Tracking System located at https://savannah.cern.ch - -.SH SEE ALSO -.B glite-lb-bkindex\fR(8),\fP glite-lb-bkserverd\fR(8),\fP glite-lb-dump\fR(8),\fP glite-lb-purge\fR(8),\fP - -.SH AUTHOR -EU EGEE, JRA1. diff --git a/org.glite.lb.client/doc/glite-lb-logevent.1 b/org.glite.lb.client/doc/glite-lb-logevent.1 deleted file mode 100644 index 63ce668..0000000 --- a/org.glite.lb.client/doc/glite-lb-logevent.1 +++ /dev/null @@ -1,98 +0,0 @@ -.TH GLITE-LB-LOGEVENT 1 "April 2008" "EU EGEE Project" "Logging&Bookkeeping" - -.SH NAME -glite-lb-logevent - program for logging events to L&B subsystem - -.SH SYNOPSIS -.B glite-lb-logevent -.B -s Application -e UserTag -.B -j -.I JOBID -.B -c -.I SEQCODE -.B --name -.I NAME -.B --value -.I VALUE -.br - -.SH DESCRIPTION -.B glite-lb-logevent -is a low-level program for logging events to the L&B service. -It is used internally by WMS components and has many more options, that are not recomend to be used at the user level. -At the user level it is supposed to be used only for logging user tag events. - -.SH USAGE -Besides -.I NAME -and -.I VALUE -of the tag, which are user defined, the user has to specify a valid -.I JOBID\fR,\fP -and -.I SEQCODE -(L&B event sequence code). - -The user application is always executed from within a -.I JobWrapper -script. The wrapper sets the appropriate JobId in the environment variable -EDG_WL_JOBID. The user should pass this value to the -j option of -.B glite-lb-logevent. - -Similarly, the wrapper sets an initial value of the event sequence code -in the environment variable EDG_WL_SEQUENCE_CODE. -If the user application calls -.B glite-lb-logevent -just once, it is sufficient to pass this value to the -c option. -However, if there are more subsequent calls, the user is responsible for -capturing an updated sequence code from the -.B stdout -of -.B glite-lb-logevent -and using it in subsequent calls. -The L&B design requires the sequence codes in order to be able to sort -events correctly while not relying on strictly synchronized clocks. - -.SH EXAMPLE -The example bellow is a job consisting of 100 phases. -A user tag -.I phase -is used to log the phase currently being executed. -Subsequently, the user may monitor execution of the job phases -as a part of the job status returned by L&B. - -.nf -#!/bin/sh - -for p in `seq 1 100`; do - - # log the UserTag event - EDG_WL_SEQUENCE_CODE=`glite-lb-logevent -s Application - -e UserTag - -j $EDG_WL_JOBID -c $EDG_WL_SEQUENCE_CODE - --name=phase --value=$p` - - # do the actual computation here -done - -.fi - - - -.SH OTHER OPTIONS -See command line help (glite-lb-logevent -h) for extensive help on all options. -However, EDG users should should follow the usage shown in SYNOPSIS strictly. -Logging other events may confuse the L&B service and cause wrong job status -information to be reported. - -.SH FILES -No configuration files needed. - -.SH REPORTING BUGS -Please, report all bugs to EU EGEE Bug Tracking System located at https://savannah.cern.ch - -.SH SEE ALSO -.B glite-lb-bkserverd\fR(8),\fP glite-lb-interlogd\fR(8),\fP glite-lb-logd\fR(8) - -.SH AUTHOR -EU EGEE, JRA1. diff --git a/org.glite.lb.client/doc/glite-lb-notify.1 b/org.glite.lb.client/doc/glite-lb-notify.1 deleted file mode 100644 index b6015f8..0000000 --- a/org.glite.lb.client/doc/glite-lb-notify.1 +++ /dev/null @@ -1,142 +0,0 @@ -.TH GLITE-LB-NOTIFY 1 "Apr 2008" "EU EGEE Project" "Logging&Bookkeeping" - -.SH NAME -glite-lb-notify - Register and receive notification from L&B - -.SH SYNOPSIS -.B glite-lb-notify -.br - \fBnew\fR [ { \fB-s\fI socket_fd\fR | \fB-a \fIfake_addr\fR } \fB-t \fIrequested_validity\fR \fB-j \fIjobid \fR| { \fB-o \fIowner \fR | \fB -O \fR } \fB-n \fInetwork_server \fR \fB-v\fI virtual_organization\fR \fB-c \fR \fB-f\fI flags\fR ] -.br - \fBbind \fR [ { \fB-s\fI socket_fd\fR | \fB-a \fIfake_addr\fR } \fB-t \fIrequested_validity\fR ] \fInotifid\fR -.br - \fBchange \fR \fInotifid\fR \fIjobid\fR -.br - \fBrefresh\fR [ \fB-t \fIrequested_validity \fR ] notifid -.br - \fBreceive\fR [ { \fB-s\fI socket_fd\fR | \fB-a \fIfake_addr\fR } \fB-t \fIrequested_validity\fR ] [ \fB -i \fItimeout \fR] [ \fB-r\fR] [ \fB-f\fI field1,field2\fR,... \fInotifid\fR -.br - \fBdrop\fR \fInotifid\fR -.br - \fBhelp\fR - - -.SH DESCRIPTION -.B glite-lb-notify -is a fairly simple wrapper on the L&B notification API. -It allows to create a notification (with a restricted richness of specifying -conditions), bind to it for receiving notifications, and drop it finally. - -L&B notification is a user-initiated trigger at the server. -Whenever a job enters a state matching conditions specified with the notification, -the current state of the job is sent to the notification client. -On the other hand, the notification client is a network listener -which receives server-initiated connections to get the notifications. -Unless -.B -s -is specified, the notification library creates the listener -socket. - -Within the notification validity, -clients can disappear and even migrate. -However, only a single active client for a notification is allowed. - -This command -is intended to be used in user scripts, graphical tools etc. where -direct access to the API is difficult. - -L&B server and port to contact is specified with GLITE_WMS_NOTIF_SERVER environment -variable. - -.SH USAGE -Common options (mostly) -.TP -.B -t -specifies a requested validity of the notification (in seconds of UNIX Epoch), -the server can truncate the value according to its policy. -.TP -.B -a -allows to specify a fake listener address to register with the notification, -i.e. to overcome firewalls etc. -When notifications are delivered, the server tries to connect to this -address rather than the true address of the listening socket. -Requires re-binding therefore it -can't be used in conjunction with -.B -s -. -.TP -.B -s -allows to pass a opened listening socket (filedescriptor number), see EXAMPLE bellow. -In this case there is no need to re-bind the notification -(it is assumed the socket is recycled) -This is critical for a real usage, as the re-bind operation is rather -expensive. - -.SH \ - -Subcommands: -.TP -.B new -Create a new notification. Conditions on matching jobs are specified -with exacltly one of -.B -j\fR, -.B -o\fR, -.B -n,\fR -.B -v -options. If the option -.B -O\fR -is used, credentials are retrieved from environment. The -.B -c\fR -set matching only on state change. -Prints ID of the created notification. - -.TP -.B bind - -Binds to an existing notification, changing its listener eventually. -Useful for debugging purposes mostly. - -.TP -.B change - -Connect notification with another job. - -.TP -.B refresh - -Extend validity of an existing notification. - -.TP -.B receive - -Bind to an existing notification, and start waiting for an incoming -event, at most the time specified with -.B -i -(seconds). -.B -r -attempts to refresh the notification handle in 1/2 of current validity. -.B -f -allows to specify a custom list of fields of the job status -to display. Run -.B glite-lb-notify -to get list of available fields. - -.TP -.B drop - -Drop the notification from the server, removing all messages on the way eventually. - -.SH EXAMPLE -Installed with the package as share/examples/glite-lb-notify.pl. -Demontstrates using the non-trivial -.B -s -option. - - -.SH SEE ALSO -.B glite-lb-bkserverd\fR(8),\fP glite-lb-interlogd\fR(8),\fP glite-lb-logd\fR(8) - -L&B Users Guide, http://www.glite.org - -.SH AUTHOR -EU EGEE, JRA1. diff --git a/org.glite.lb.client/examples/Makefile b/org.glite.lb.client/examples/Makefile deleted file mode 100644 index 8b4e31f..0000000 --- a/org.glite.lb.client/examples/Makefile +++ /dev/null @@ -1,79 +0,0 @@ -glite_location:=${GLITE_LOCATION} -glite_prefix:=${glite_location} - -host_cpu:=${shell uname -m} -ifeq (${host_cpu},x86_64) - LDFLAGS:=-L${glite_prefix}/lib64 -L${glite_prefix}/lib - nothrflavour=gcc64dbg - thrflavour=gcc64dbgpthr -else - LDFLAGS:=-L${glite_prefix}/lib - nothrflavour=gcc32dbg - thrflavour=gcc32dbgpthr -endif - -CC:=gcc -CXX:=g++ - -COMMON_LIB:=-lglite_lb_common_${nothrflavour} -COMMON_LIB_THR:=-lglite_lb_common_${thrflavour} -CLIENT_LIB:=-lglite_lb_client_${nothrflavour} -CLIENT_LIB_THR:=-lglite_lb_client_${thrflavour} -JOBID_LIB:=-lglite_jobid - -LIB:=${COMMON_LIB} ${CLIENT_LIB} ${JOBID_LIB} -LIB_THR:=${COMMON_LIB_THR} ${CLIENT_LIB_THR} ${JOBID_LIB} -PLUSLIB:= -PLUSLIB_THR:= - -CFLAGS:=${DEBUG} \ - -I${glite_prefix}/include \ - -D_GNU_SOURCE - -CXXFLAGS:=${CFLAGS} - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -CXXCOMPILE:=libtool --mode=compile ${CXX} ${CXXFLAGS} -LINK:=libtool --mode=link ${CC} ${LDFLAGS} -LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS} -INSTALL:=libtool --mode=install install - -EXAMPLES_SRC:=log_usertag_proxy.c job_log.c job_reg.c feed_shark.c query_ext.c query_seq_code.c stats.c abort_job.c change_acl.c stresslog.c flood_proxy.c dagids.c stress_context.c parse_eventsfile.c user_jobs.c job_status.c -EXAMPLES:=${EXAMPLES_SRC:.c=} - -# TODO: migrate them here from branch_RC31_3 -# EXAMPLES_PLUS_SRC:=indexed_attrs_plus.cpp job_status_plus.cpp query_events_plus.cpp listener.cpp user_jobs_plus.cpp job_log_plus.cpp notify_plus.cpp -# EXAMPLES_PLUS:=${EXAMPLES_PLUS_SRC:.cpp=} -# EXAMPLES_PLUS_THR_SRC:= -# EXAMPLES_PLUS_THR:=${EXAMPLES_PLUS_THR_SRC:.cpp=} - -EXAMPLES_THR_SRC:=user_jobs_threaded.c -EXAMPLES_THR:=${EXAMPLES_CL_THR_SRC:.c=} - -default all: examples - -examples: ${EXAMPLES} ${EXAMPLES_THR} ${EXAMPLES_PLUS} ${EXAMPLES_PLUS_THR} - -${EXAMPLES}: %: %.o - ${LINK} -o $@ $< ${LIB} - -${EXAMPLES_THR}: %: %.o - ${LINK} -o $@ $< ${LIB_THR} - -${EXAMPLES_PLUS}: %: %.o - ${LINKXX} -o $@ $< ${PLUSLIB} - -${EXAMPLES_PLUS_THR}: %: %.o - ${LINKXX} -o $@ $< ${PLUSLIB_THR} - -# catches $TOOLS and logevent compilation -%.o: %.c - ${CC} ${CFLAGS} -c $< - -%.o: %.cpp - ${CXX} ${CXXFLAGS} -c $< - -clean: - rm -rvf ${EXAMPLES} ${EXAMPLES_CL} ${EXAMPLES_CL_THR} - rm -rvf *.o .libs/ - diff --git a/org.glite.lb.client/examples/README.examples b/org.glite.lb.client/examples/README.examples deleted file mode 100644 index a500dfb..0000000 --- a/org.glite.lb.client/examples/README.examples +++ /dev/null @@ -1,32 +0,0 @@ -These are examples demonsrtating the usage of LB client API: - -abort_job.c - Manual abort of a job -change_acl.c - Change ACL -dagids.c - (sub)JobIds of a DAG job -feed_shark.c - Notifications "Shark" -flood_proxy.c - Log User Tag to LB Proxy from multiple processes -job_log.c - Return all events for given JobId -job_reg.c - Register a job in LB -job_status.c - Return a job status of given job -log_usertag_proxy.c - Log User Tag to LB Proxy -notify.c - Notifications handling tool (new, bind, change, refresh, receive, test, drop) -parse_eventsfile.c - Check parsing of dglogd* and notif-dglogd* files -query_ext.c - Complex querying tool -query_seq_code.c - How to query the sequence code of a job -stats.c - Return CE rank statistics from LB -stress_context.c - Stress test for working with LB context (Init, SetLoggingJob, Free - multiple processes) -stresslog.c - Stress test for logging (RegisterJOb, LogEvent) -user_jobs.c - Return jobs owned by given user -user_jobs_threaded.c - Return jobs owned by given user (threaded version) - - -The following RPMs must be installed in order to be able to build all the examples: - -glite-lb-client - -(and all its dependencies). - - -To build these examples, just set the GLITE_LOCATION environment variable and run make, e.g. - -$ GLITE_LOCATION=/opt/glite make diff --git a/org.glite.lb.client/examples/abort_job.c b/org.glite.lb.client/examples/abort_job.c deleted file mode 100644 index 3407b22..0000000 --- a/org.glite.lb.client/examples/abort_job.c +++ /dev/null @@ -1,135 +0,0 @@ -#ident "$Header$" - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include -#include -#include -#include - -#include "glite/lb/events_parse.h" -#ifdef BUILDING_LB_CLIENT -#include "consumer.h" -#include "producer.h" -#else -#include "glite/lb/consumer.h" -#include "glite/lb/producer.h" -#endif -#include "glite/jobid/cjobid.h" -#include "glite/lb/context-int.h" - -static void free_events(edg_wll_Event *); - -static void help(const char* n) -{ - fprintf(stderr,"usage: %s \n", n); - exit(1); -} - -int main(int argc,char **argv) -{ - edg_wll_Context ctx; - char *errt,*errd,*e,a; - edg_wll_Event *events; - int i; - edg_wll_QueryRec jq[2],eq[2]; - edg_wlc_JobId job; - edg_wll_Source src; - - if (argc != 3) help(argv[0]); - - puts( -"*\n" -"* USE WITH CARE, AT YOUR OWN RISK, UNDER ABNORMAL CONDITIONS ONLY,\n" -"* AND BE ALWAYS SURE WHAT YOU ARE DOING.\n" -"* \n" -"* THIS PROGRAM IS A PERFECT EXAMPLE HOW L&B SEQENCE CODES SHOULD NOT BE USED\n" -"* IN NORMAL OPERATION.\n" -"\n" -"Do you want to proceed?" - ); - - scanf("%c",&a); - if (a != 'y' && a != 'Y') return 1; - - edg_wll_InitContext(&ctx); - - if (edg_wlc_JobIdParse(argv[1],&job)) { - fprintf(stderr,"%s: can't parse job ID\n",argv[1]); - return 1; - } - - if (( src = edg_wll_StringToSource(argv[2])) == EDG_WLL_SOURCE_NONE) { - fprintf(stderr,"%s: unknown event source\n",argv[2]); - return 1; - } - - jq[0].attr = EDG_WLL_QUERY_ATTR_JOBID; - jq[0].op = EDG_WLL_QUERY_OP_EQUAL; - jq[0].value.j = job; - jq[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - - eq[0].attr = EDG_WLL_QUERY_ATTR_SOURCE; - eq[0].op = EDG_WLL_QUERY_OP_EQUAL; - eq[0].value.i = src; - eq[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - - if ( edg_wll_QueryEvents(ctx,jq,eq,&events) ) - { - if ( edg_wll_Error(ctx, &errt, &errd) != E2BIG ) - goto err; - - fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); - } - - for ( i = 0; events[i].type != EDG_WLL_EVENT_UNDEF; i++ ); - - e = edg_wll_UnparseEvent(ctx,events+i-1); - - fputs(e,stdout); - fputs("\n",stdout); - - if (edg_wll_SetParam(ctx,EDG_WLL_PARAM_SOURCE,src) || - edg_wll_SetLoggingJob(ctx,job,events[i-1].any.seqcode,EDG_WLL_SEQ_NORMAL) || - edg_wll_IncSequenceCode(ctx) || /* necessary to simulate this - * call in last event logging - * _after_ current seq. was used */ - edg_wll_LogAbort(ctx,"manual abort")) goto err; - - - free(e); - free_events(events); - - edg_wll_FreeContext(ctx); - - return 0; - -err: - switch (edg_wll_Error(ctx,&errt,&errd)) { - case 0: break; - case ENOENT: - puts("No events found"); - break; - default: - fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); - return 1; - } - - 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; - } -} diff --git a/org.glite.lb.client/examples/aborted.l b/org.glite.lb.client/examples/aborted.l deleted file mode 100644 index 0f639c8..0000000 --- a/org.glite.lb.client/examples/aborted.l +++ /dev/null @@ -1,2 +0,0 @@ -:ready: --s JobController,-e Abort,--reason "just to test" diff --git a/org.glite.lb.client/examples/cancelled.l b/org.glite.lb.client/examples/cancelled.l deleted file mode 100644 index 1e0cc96..0000000 --- a/org.glite.lb.client/examples/cancelled.l +++ /dev/null @@ -1,2 +0,0 @@ -:running: --s LogMonitor, -e Done, --status_code=CANCELLED, --reason="reason for the change", --exit_code=0 diff --git a/org.glite.lb.client/examples/change_acl.c b/org.glite.lb.client/examples/change_acl.c deleted file mode 100644 index 3464a16..0000000 --- a/org.glite.lb.client/examples/change_acl.c +++ /dev/null @@ -1,82 +0,0 @@ -#ident "$Header$" - -#include -#include - -#include "glite/jobid/cjobid.h" -#ifdef BUILDING_LB_CLIENT -#include "producer.h" -#else -#include "glite/lb/producer.h" -#endif -#include "glite/lb/authz.h" - -void -usage(const char *me) -{ - fprintf(stderr,"usage: %s [-r] [-d] [-g] jobid user_id\n" - "\t-r \tRemove\n" - "\t-d \tOperation is considered as `allow' by default, if -d is given 'deny' will be used\n" - "\t-g \tuser_id is treated as DN by default, if -g is given user_id is expectedto be of form VO:group\n", - - me); -} - -int -main(int argc, char *argv[]) -{ - edg_wll_Context ctx; - int operation = EDG_WLL_CHANGEACL_ADD; - int permission = EDG_WLL_CHANGEACL_READ; - int permission_type = EDG_WLL_CHANGEACL_ALLOW; - int user_id_type = EDG_WLL_CHANGEACL_DN; - edg_wlc_JobId jobid; - int opt; - int ret; - - if (argc < 3) { - usage(argv[0]); - return 1; - } - - while ((opt=getopt(argc, argv, "rdg")) != -1) - switch(opt) { - case 'r': operation = EDG_WLL_CHANGEACL_REMOVE; break; - case 'd': permission_type = EDG_WLL_CHANGEACL_DENY; break; - case 'g': user_id_type = EDG_WLL_CHANGEACL_GROUP; break; - default: - usage(argv[0]); - return 1; - break; - } - - edg_wll_InitContext(&ctx); - - if (edg_wlc_JobIdParse(argv[optind], &jobid)) { - fprintf(stderr,"can't parse job ID\n"); - goto err; - } - - edg_wll_SetParam(ctx, EDG_WLL_PARAM_SOURCE, EDG_WLL_SOURCE_USER_INTERFACE); - - ret = edg_wll_ChangeACL(ctx, - jobid, - argv[optind+1], user_id_type, - permission, permission_type, - operation); - - if (ret) { - char *et, *ed; - edg_wll_Error(ctx, &et, &ed); - fprintf(stderr, "%s: edg_wll_LogChangeACL() failed: %s (%s)\n", - argv[0], et, ed); - goto err; - } - - edg_wll_FreeContext(ctx); - return 0; - -err: - edg_wll_FreeContext(ctx); - return 1; -} diff --git a/org.glite.lb.client/examples/chkpt.l b/org.glite.lb.client/examples/chkpt.l deleted file mode 100644 index dbd7f23..0000000 --- a/org.glite.lb.client/examples/chkpt.l +++ /dev/null @@ -1,6 +0,0 @@ -# macro definition for DONE state - -:running: --s LRMS, -e Chkpt, --tag=chkpt1, --classad="" --s LRMS, -e Chkpt, --tag=chkpt2, --classad="" --s LogMonitor, -e Done, --status_code=OK, --reason="reason for the change", --exit_code=0 diff --git a/org.glite.lb.client/examples/cleared.l b/org.glite.lb.client/examples/cleared.l deleted file mode 100644 index 8b9f86c..0000000 --- a/org.glite.lb.client/examples/cleared.l +++ /dev/null @@ -1,4 +0,0 @@ -# macro definition for DONE state - -:done: --s LogMonitor, -e Clear, --reason=USER diff --git a/org.glite.lb.client/examples/dagids.c b/org.glite.lb.client/examples/dagids.c deleted file mode 100644 index 91f4e60..0000000 --- a/org.glite.lb.client/examples/dagids.c +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#ifdef BUILDING_LB_CLIENT -#include "producer.h" -#else -#include "glite/lb/producer.h" -#endif -#include "glite/lb/events.h" - -extern char *optarg; -extern int opterr,optind; - -static void usage(char *me) -{ - fprintf(stderr,"usage: %s -m bkserver -n num_subjobs [-s seed]\n", me); -} - -int main(int argc, char *argv[]) -{ - char *seed = "seed", *server = NULL,*p; - int done = 0,num_subjobs = 0,i; - edg_wll_Context ctx; - edg_wlc_JobId jobid,*subjobs; - - - edg_wll_InitContext(&ctx); - opterr = 0; - - do { - switch (getopt(argc,argv,"m:n:s:")) { - case 's': seed = strdup(optarg); break; - case 'm': server = strdup(optarg); break; - case 'n': num_subjobs = atoi(optarg); break; - case '?': usage(argv[0]); exit(EINVAL); - case -1: done = 1; break; - } - } while (!done); - - if (!server) { - fprintf(stderr,"%s: -m server required\n",argv[0]); - exit(1); - } - - if (!num_subjobs) { - fprintf(stderr,"%s: -n num_subjobs required\n",argv[0]); - exit(1); - } - - p = strchr(server,':'); - if (p) *p=0; - edg_wlc_JobIdCreate(server,p?atoi(p+1):0,&jobid); - printf("seed=\"%s\"\nnodes=%d\ndag=\"%s\"\n",seed,num_subjobs,edg_wlc_JobIdUnparse(jobid)); - - edg_wll_GenerateSubjobIds(ctx,jobid,num_subjobs,seed,&subjobs); - - for (i=0; i -#include -#include -#include -#include -#include -#include -#include - -#ifdef BUILDING_LB_CLIENT -#include "notification.h" -#else -#include "glite/lb/notification.h" -#endif - -static void usage(const char *); -static void printstat(edg_wll_JobStat, int); - -int main(int argc,char *argv[]) -{ - int o; - edg_wll_Context ctx; - edg_wll_NotifId notif; - time_t valid = 0; - struct timeval timeout; - - edg_wll_InitContext(&ctx); - -/* parse options, reflect them in the LB context */ - while ((o = getopt(argc,argv,"s:")) >= 0) switch (o) { - case 's': { - char *server = strdup(optarg), - *port_s = strchr(server,':'); - - int port; - - if (port_s) { - *port_s = 0; - port = atoi(port_s+1); - } - - edg_wll_SetParam(ctx,EDG_WLL_PARAM_NOTIF_SERVER,server); - if (port_s) edg_wll_SetParam(ctx,EDG_WLL_PARAM_NOTIF_SERVER_PORT,port); - free(server); - } break; - - case '?': usage(argv[0]); exit(EX_USAGE); - } - -/* no notification Id supplied -- create a new one */ - if (argc == optind) { - edg_wll_QueryRec const *empty[] = { NULL }; - char *notif_s; - - if (edg_wll_NotifNew(ctx,empty,0,-1,NULL,¬if,&valid)) { - char *et,*ed; - - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_NotifNew(): %s (%s)\n",et,ed); - exit(EX_UNAVAILABLE); - } - - notif_s = edg_wll_NotifIdUnparse(notif); - printf("notification registered:\n\tId: %s\n\tExpires: %s", - notif_s,ctime(&valid)); - free(notif_s); - } -/* notification Id supplied -- bind to it */ - else if (argc == optind + 1) { - if (edg_wll_NotifIdParse(argv[optind],¬if)) { - fprintf(stderr,"%s: invalid notification Id\n", - argv[optind]); - exit(EX_DATAERR); - } - - if (edg_wll_NotifBind(ctx,notif,-1,NULL,&valid)) { - char *et,*ed; - - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_NotifBind(): %s (%s)\n",et,ed); - exit(EX_UNAVAILABLE); - } - printf("bound to %s\n\t Expires: %s",argv[optind],ctime(&valid)); - } - else { usage(argv[0]); exit(EX_USAGE); } - -/* main loop */ - while (1) { - edg_wll_JobStat stat; - char *et,*ed; - -/* calculate time left for this notification */ - gettimeofday(&timeout,NULL); - timeout.tv_sec = valid - timeout.tv_sec; - assert(timeout.tv_sec >= 0); /* XXX: hope we are no late */ - -/* half time before notification renewal */ - timeout.tv_sec /= 2; - - switch (edg_wll_NotifReceive(ctx,-1,&timeout,&stat,NULL)) { - case 0: /* OK, got it */ - printstat(stat,0); - edg_wll_FreeStatus(&stat); - break; - case EAGAIN: /* timeout */ - if (edg_wll_NotifRefresh(ctx,notif,&valid)) { - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_NotifRefresh(): %s (%s)\n",et,ed); - exit(EX_UNAVAILABLE); - } - printf("Notification refreshed, expires %s",ctime(&valid)); - break; - default: - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_NotifReceive(): %s (%s)\n",et,ed); - exit(EX_UNAVAILABLE); - } - } -} - - -static void usage(const char *me) -{ - fprintf(stderr,"usage: %s [ -s server[:port] ] [notif_id]\n",me); -} - - - -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); -} diff --git a/org.glite.lb.client/examples/flood_proxy.c b/org.glite.lb.client/examples/flood_proxy.c deleted file mode 100644 index 5fb23a6..0000000 --- a/org.glite.lb.client/examples/flood_proxy.c +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef BUILDING_LB_CLIENT -#include "producer.h" -#else -#include "glite/lb/producer.h" -#endif -#include "glite/jobid/cjobid.h" - -static void slave(); - -int main(int argc,char **argv) -{ - int i,nproc; - - if (argc != 2) { - fprintf(stderr,"usage: %s nproc\n",argv[0]); - return 1; - } - - nproc = atoi(argv[1]); - if (nproc < 1) { - fprintf(stderr,"%s: nproc must be >= 1\n",argv[0]); - return 1; - } - - for (i=0; i&$LOGFD - EDG_WL_SEQUENCE=`$LOGEV $LARGE_STRESS $LBPROXY $LBPROXY_STORE_SOCK -j $EDG_JOBID -c $EDG_WL_SEQUENCE "$@" 2>/dev/null` - test $? -ne 0 -o -z "$EDG_WL_SEQUENCE" && exit 4 - true -} - diff --git a/org.glite.lb.client/examples/gen_sample_job b/org.glite.lb.client/examples/gen_sample_job deleted file mode 100755 index 5246e8a..0000000 --- a/org.glite.lb.client/examples/gen_sample_job +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -me=$0 -mydir=`dirname $0`; -export me mydir - - -set -- `getopt n $*` -# test whether it is recursive call - -NESTED="-v nested=0" -while [ $1 != '--' ]; do case $1 in - -n) NESTED="-v nested=1"; shift ;; -esac; done -shift - -awk -F, $NESTED \ -'BEGIN { - if (nested==0) system("cat $mydir/gen_begin"); - OFS = ","; - nlines = 0; -} -/^#/ || /^[ ]*$/ { next; } -{ - source = $2; - - event = $1; - - nline++; -} -# events processing - -/-e Transfer/ { logit(); - next;} - -/-e Accepted/ { if (checkNOP(7) == 0) logit(); - next;} - -/-e Refused/ { if (checkNOP(6) == 0) logit(); - next;} - -/-e EnQueued/ { if (checkNOP(6) == 0) logit(); - next;} - -/-e DeQueued/ { if (checkNOP(4) == 0) logit(); - next;} - -/-e HelperCall/ { if (checkNOP(5) == 0) logit(); - next;} - -/-e HelperReturn/ { if (checkNOP(5) == 0) logit(); - next;} - -/-e Running/ { if (checkNOP(3) == 0) logit(); - next;} - -/-e Resubmission/ { if (checkNOP(5) == 0) logit(); - next;} - -/-e Done/ { if (checkNOP(5) == 0) logit(); - next;} - -/-e Cancel/ { if (checkNOP(4) == 0) logit(); - next;} - -/-e Abort/ { if (checkNOP(3) == 0) logit(); - next;} - -/-e Clear/ { if (checkNOP(3) == 0) logit(); - next;} - -/-e Purge/ { if (checkNOP(2) == 0) logit(); - next;} - -/-e Match/ { if (checkNOP(3) == 0) logit(); - next;} - -/-e Pending/ { if (checkNOP(3) == 0) logit(); - next;} - -/-e RegJob/ { if (checkNOP(7) == 0) logit(); - next;} - -/-e Chkpt/ { if (checkNOP(4) == 0) logit(); - next;} - -/-e Listener/ { if (checkNOP(5) == 0) logit(); - next;} - -/-e CurDescr/ { if (checkNOP(3) == 0) logit(); - next;} - -/-e UserTag/ { if (checkNOP(4) == 0) logit(); - next;} - -/-e ReallyRunning/ { if (checkNOP(3) == 0) logit(); - next;} - -# shell escape (for sequence number branching) - -/^!/ { print substr($0,2,(length($0) - 1)); } - -# macro processing - macro name starts and ends with ':' -# in a file gen_MACRONAME.txt is the macro describtion - -/^:.*:$/ {system("$me -n $mydir/"substr($1,2,(length($1) - 2))".l" )} - - -function checkNOP(NOP) -{ - if (NF != NOP) { print nline" : "$2": "NOP" args required ("NF" supplied)" > "/dev/stderr"; return 1 } - else return 0; -} - -function logit() -{ - split($0,f); - - ff = ""; - for (i=1; i<=NF; i++) ff = ff " " f[i]; - - print "send_log_ev" ff; -} -' $1 diff --git a/org.glite.lb.client/examples/job-status.pl b/org.glite.lb.client/examples/job-status.pl deleted file mode 100755 index c5c654a..0000000 --- a/org.glite.lb.client/examples/job-status.pl +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/perl - -use SOAP::Lite; -use Data::Dumper; - -# see user-jobs.pl for comments on this magic - -$ENV{HTTPS_CA_DIR}='/etc/grid-security/certificates'; -$ENV{HTTPS_VERSION}='3'; - -$proxy = $ENV{X509_USER_PROXY} ? $ENV{X509_USER_PROXY} : "/tmp/x509up_u$<"; -$ENV{HTTPS_CERT_FILE}= $ENV{HTTPS_KEY_FILE} = $ENV{HTTPS_CA_FILE} = $proxy; - -$job = shift or die "usage: $0 jobid\n"; -$job =~ /(https:\/\/.*):([0-9]+)\/.*/ or die "$job: invalid jobid\n"; -$host = $1; $port = $2; -$server = $host . ':' . ($port + 3); - -$c = SOAP::Lite - -> proxy($server) - -> uri('http://glite.org/wsdl/services/lb'); - -service $c 'http://egee.cesnet.cz/cms/export/sites/egee/en/WSDL/HEAD/LB.wsdl'; -ns $c 'http://glite.org/wsdl/elements/lb'; - -# we need another namespace explicitely here -$c->serializer->register_ns('http://glite.org/wsdl/types/lb','lbtype'); - -on_fault $c sub { print Dumper($_[1]->fault); $fault = 1; }; - -# construct the request, see SOAP::Data docs for details -$req = SOAP::Data->value( - SOAP::Data->name(jobid=>$job), -# here the other namespace is used - SOAP::Data->name(flags=>'')->type('lbtype:jobFlags') - ); - -# call the WS op -$resp = JobStatus $c $req; -$body = $resp->body(); - -# print Dumper $resp->body(); - -# pick something reasonable from the response to print -unless ($fault) { - @fields = qw/state jobtype owner networkServer doneCode exitCode childrenNum/; - $stat = $resp->body()->{JobStatusResponse}->{stat}; - - for (@fields) { - print "$_: $stat->{$_}\n"; - } -} - diff --git a/org.glite.lb.client/examples/job_log.c b/org.glite.lb.client/examples/job_log.c deleted file mode 100644 index 03ddd40..0000000 --- a/org.glite.lb.client/examples/job_log.c +++ /dev/null @@ -1,148 +0,0 @@ -#ident "$Header$" - -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif - -#include -#include -#include -#include - -#include "glite/lb/events_parse.h" -#ifdef BUILDING_LB_CLIENT -#include "consumer.h" -#else -#include "glite/lb/consumer.h" -#endif -#include "glite/jobid/cjobid.h" -#ifdef USE_CALLBACKS - #include "consumer_fake.h" -#endif - -static void free_events(edg_wll_Event *); - -static void help(const char* n) -{ - fprintf(stderr,"usage: %s [-r repeat] [-d delay] [ -x|-X non-default_sock_path ] \n", n); - exit(1); -} - -#ifdef USE_CALLBACKS -static int query_events_cb(edg_wll_Context context, edg_wll_Event **events) { - int i; - edg_wll_Event *event; - - i = 0; - while ((event = (*events) + i)->type != EDG_WLL_EVENT_UNDEF) { - event->any.timestamp.tv_sec = (double)rand() / RAND_MAX * 1000000000; - event->any.timestamp.tv_usec = (double)rand() / RAND_MAX * 1000000; - i++; - } - - return 0; -} -#endif - -int main(int argc,char **argv) -{ - edg_wll_Context ctx; - char *errt,*errd; - edg_wll_Event *events = NULL; - edg_wlc_JobId job; - int i,opt,delay = 1,count = 0, proxy = 0; - - if (argc < 2) - help(argv[0]); - - edg_wll_InitContext(&ctx); - - while ((opt=getopt(argc,argv,"r:d:xX:")) != -1) - switch (opt) { - case 'd': delay = atoi(optarg); break; - case 'r': count = atoi(optarg); break; - case 'x': proxy = 1; break; - case 'X': proxy = 1; - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, optarg); - break; - default: - help(argv[0]); - } - - if (edg_wlc_JobIdParse(argv[optind],&job)) { - fprintf(stderr,"%s: can't parse job ID\n",argv[1]); - return 1; - } - -#ifdef USE_CALLBACKS - edg_wll_RegisterTestQueryEvents(query_events_cb); -#endif - - if ( proxy ? edg_wll_JobLogProxy(ctx,job,&events) : edg_wll_JobLog(ctx,job,&events) ) - { - edg_wll_Error(ctx,&errt,&errd); - fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); - } - - 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); - - while (count--) { - puts("Sleeping ..."); - sleep(delay); - if (proxy ? edg_wll_JobLogProxy(ctx,job,&events) : edg_wll_JobLog(ctx,job,&events)) { - edg_wll_Error(ctx,&errt,&errd); - fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); - free(errt); free(errd); errt = errd = NULL; - free_events(events); - } - else puts("OK"); - } - - edg_wlc_JobIdFree(job); - edg_wll_FreeContext(ctx); - -#ifdef USE_CALLBACKS - edg_wll_UnregisterTestQueryEvents(); -#endif - - return 0; - -#ifdef USE_CALLBACKS - edg_wll_UnregisterTestQueryEvents(); -#endif - switch (edg_wll_Error(ctx,&errt,&errd)) { - case 0: break; - case ENOENT: - puts("No events found"); - break; - default: - fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); - return 1; - } - - edg_wlc_JobIdFree(job); - 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; - } -} diff --git a/org.glite.lb.client/examples/job_reg.c b/org.glite.lb.client/examples/job_reg.c deleted file mode 100644 index 8cd4e89..0000000 --- a/org.glite.lb.client/examples/job_reg.c +++ /dev/null @@ -1,175 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#ifdef BUILDING_LB_CLIENT -#include "producer.h" -#else -#include "glite/lb/producer.h" -#endif -#include "glite/lb/events.h" - -extern char *optarg; -extern int opterr,optind; - -static void usage(char *me) -{ - fprintf(stderr,"usage: %s [-m bkserver] [-x|-X non-default_sock_path] [-j dg_jobid] [-s source_id] [-n num_subjobs [-S][-C]] [-P] [-l jdl_file] [-e seed]\n", me); -} - -int main(int argc, char *argv[]) -{ - char *src = NULL,*job = NULL,*server = NULL,*seq,*jdl = NULL, *seed = NULL; - int lbproxy = 0; - int done = 0,num_subjobs = 0,reg_subjobs = 0,i, collection = 0, pbs=0; - edg_wll_Context ctx; - edg_wlc_JobId jobid,*subjobs; - - - edg_wll_InitContext(&ctx); - opterr = 0; - - do { - switch (getopt(argc,argv,"xX:s:j:m:n:SCl:e:P")) { - case 'x': lbproxy = 1; break; - case 'X': lbproxy = 1; - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, optarg); - break; - case 's': src = (char *) strdup(optarg); break; - case 'j': job = (char *) strdup(optarg); break; - case 'm': server = strdup(optarg); break; - case 'n': num_subjobs = atoi(optarg); break; - case 'S': reg_subjobs = 1; break; - case 'C': collection = 1; break; - case 'P': pbs = 1; break; - case 'l': jdl = (char *) strdup(optarg); break; - case 'e': seed = strdup(optarg); break; - case '?': usage(argv[0]); exit(EINVAL); - case -1: done = 1; break; - } - } while (!done); - - if ((num_subjobs <= 0) && (reg_subjobs || collection) ) { - usage(argv[0]); - exit(EINVAL); - } - - if (!job && !server) { - fprintf(stderr,"%s: either -m server or -j jobid has to be specified\n",argv[0]); - exit(1); - } - - if (!src) { - fprintf(stderr,"%s: -s required\n",argv[0]); - exit(1); - } - - if (!job) { - char *p = strchr(server,':'); - if (p) *p=0; - edg_wlc_JobIdCreate(server,p?atoi(p+1):0,&jobid); - job = edg_wlc_JobIdUnparse(jobid); - printf("new jobid: %s\n",job); - } - else if ((errno = edg_wlc_JobIdParse(job,&jobid))) { - perror(job); - exit(1); - } - - if (jdl) { - int f = open(jdl,O_RDONLY,0); - off_t l,p,c; - - if (f<0) { perror(jdl); exit(1); } - l = lseek(f,0,SEEK_END); - lseek(f,0,SEEK_SET); - - jdl = malloc(l+1); - - for (p=0; p < l && (c = read(f,jdl+p,l-p)) > 0; p += c); - if (c<0) { - perror("read()"); - exit (1); - } - jdl[p] = 0; - } - - edg_wll_SetParam(ctx,EDG_WLL_PARAM_SOURCE,edg_wll_StringToSource(src)); - if (lbproxy) { - if (edg_wll_RegisterJobProxy(ctx,jobid, - pbs ? EDG_WLL_REGJOB_PBS - : (num_subjobs ? - (collection?EDG_WLL_REGJOB_COLLECTION:EDG_WLL_REGJOB_DAG) - :EDG_WLL_REGJOB_SIMPLE - ), - jdl ? jdl : "blabla", "NS", - num_subjobs,seed,&subjobs)) - { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_RegisterJobProxy(%s): %s (%s)\n",job,et,ed); - exit(1); - } - } else { - if (edg_wll_RegisterJobSync(ctx,jobid, - pbs ? EDG_WLL_REGJOB_PBS - : (num_subjobs ? - (collection?EDG_WLL_REGJOB_COLLECTION:EDG_WLL_REGJOB_DAG) - :EDG_WLL_REGJOB_SIMPLE - ), - jdl ? jdl : "blabla", "NS", - num_subjobs,seed,&subjobs)) - { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_RegisterJobSync(%s): %s (%s)\n",job,et,ed); - exit(1); - } - } - - seq = edg_wll_GetSequenceCode(ctx); - printf("\n%s=\"%s\"\n",num_subjobs?(collection?"EDG_WL_COLLECTION_JOBID":"EDG_WL_DAG_JOBID"):"EDG_JOBID",job); - printf("EDG_WL_SEQUENCE=\"%s\"\n",seq); - free(seq); - free(job); - - if (num_subjobs) for (i=0; subjobs[i]; i++) { - char *job_s = edg_wlc_JobIdUnparse(subjobs[i]); - printf("EDG_WL_SUB_JOBID[%d]=\"%s\"\n",i,job_s); - free(job_s); - } - - if (reg_subjobs) { - char ** jdls = (char**) calloc(num_subjobs+1, sizeof(char*)); - - for (i=0; subjobs[i]; i++) { - asprintf(jdls+i, "JDL of subjob #%d\n", i+1); - } - - if (lbproxy) { - if (edg_wll_RegisterSubjobsProxy(ctx, jobid, (const char **) jdls, "NS", subjobs)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_RegisterSubjobsProxy: %s (%s)\n", et, ed); - exit(1); - } - } else { - if (edg_wll_RegisterSubjobs(ctx, jobid, (const char **) jdls, "NS", subjobs)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_RegisterSubjobs: %s (%s)\n", et, ed); - exit(1); - } - } - - for (i=0; subjobs[i]; i++) free(jdls[i]); - } - - edg_wll_FreeContext(ctx); - - return 0; -} diff --git a/org.glite.lb.client/examples/job_status.c b/org.glite.lb.client/examples/job_status.c deleted file mode 100644 index 1d33293..0000000 --- a/org.glite.lb.client/examples/job_status.c +++ /dev/null @@ -1,326 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include - -#include "glite/lb/context-int.h" -#ifdef BUILDING_LB_CLIENT -#include "consumer.h" -#else -#include "glite/lb/consumer.h" -#endif -#include "glite/lb/xml_conversions.h" -#include "glite/lb/jobstat.h" - -static void dgerr(edg_wll_Context,char *); -static void printstat(edg_wll_JobStat,int); - -#define MAX_SERVERS 20 - -static char *myname; - -static void usage(char *); -static int query_all(edg_wll_Context, edg_wll_JobStat **, edg_wlc_JobId **); - -int main(int argc,char *argv[]) -{ - edg_wll_Context sctx[MAX_SERVERS]; - char *servers[MAX_SERVERS]; - int i, result=0, nsrv=0, histflags = 0; - - - myname = argv[0]; - printf("\n"); - - if ( argc < 2 || strcmp(argv[1],"--help") == 0 ) { usage(argv[0]); return 0; } - - if ( edg_wll_InitContext(&sctx[0]) ) { - fprintf(stderr,"cannot initialize edg_wll_Context\n"); - exit(1); - } - - if ( !strcmp(argv[1], "-all" ) ) { - edg_wll_JobStat *statesOut; - edg_wlc_JobId *jobsOut; - - jobsOut = NULL; - statesOut = NULL; - if ( (result = query_all(sctx[0], &statesOut, &jobsOut)) ) dgerr(sctx[0], "edg_wll_QueryJobs"); - else for ( i = 0; statesOut[i].state; i++ ) printstat(statesOut[i],0); - - if ( jobsOut ) { - for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); - free(jobsOut); - } - if ( statesOut ) { - for (i=0; statesOut[i].state; i++) edg_wll_FreeStatus(&statesOut[i]); - free(statesOut); - } - edg_wll_FreeContext(sctx[0]); - - return result; - } - - if ( !strcmp(argv[1], "-x") ) { - edg_wlc_JobId job; - edg_wll_JobStat status; - - if ( argc < 3 ) { usage(argv[0]); return 1; } - if ( edg_wll_InitContext(&sctx[0]) ) { - fprintf(stderr,"%s: cannot initialize edg_wll_Context\n",myname); - exit(1); - } - edg_wll_SetParam(sctx[0], EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, argv[2]); - for ( i = 3; i < argc; i++ ) { - memset(&status, 0, sizeof status); - if (edg_wlc_JobIdParse(argv[i],&job)) { - fprintf(stderr,"%s: %s: cannot parse jobId\n", myname, argv[i]); - continue; - } - if ( edg_wll_JobStatusProxy(sctx[0], job, EDG_WLL_STAT_CLASSADS | EDG_WLL_STAT_CHILDREN | EDG_WLL_STAT_CHILDSTAT, &status)) { - dgerr(sctx[0], "edg_wll_JobStatusProxy"); result = 1; - } else printstat(status, 0); - - if ( job ) edg_wlc_JobIdFree(job); - if ( status.state ) edg_wll_FreeStatus(&status); - } - edg_wll_FreeContext(sctx[0]); - - return result; - } - - for ( i = 1; i < argc; i++ ) { - if ( !strcmp(argv[i], "-fullhist") ) { - histflags = EDG_WLL_STAT_CHILDHIST_THOROUGH; - printf("\nFound a FULLHIST flag\n\n"); - } - - if ( !strcmp(argv[i], "-fasthist") ) { - histflags = EDG_WLL_STAT_CHILDHIST_FAST; - printf("\nFound a FASTHIST flag\n\n"); - } - } - - for ( i = 1; i < argc; i++ ) { - int j; - char *bserver; - edg_wlc_JobId job; - edg_wll_JobStat status; - - memset(&status,0,sizeof status); - - if ((strcmp(argv[i], "-fullhist"))&&(strcmp(argv[i], "-fasthist"))) { - if (edg_wlc_JobIdParse(argv[i],&job)) { - fprintf(stderr,"%s: %s: cannot parse jobId\n", myname,argv[i]); - continue; - } - bserver = edg_wlc_JobIdGetServer(job); - if (!bserver) { - fprintf(stderr,"%s: %s: cannot extract bookkeeping server address\n", myname,argv[i]); - edg_wlc_JobIdFree(job); - continue; - } - for ( j = 0; j < nsrv && strcmp(bserver, servers[j]); j++ ); - if ( j == nsrv ) { - if ( i > 0 ) edg_wll_InitContext(&sctx[j]); - nsrv++; - servers[j] = bserver; - } - - if (edg_wll_JobStatus(sctx[j], job, EDG_WLL_STAT_CLASSADS | EDG_WLL_STAT_CHILDREN | EDG_WLL_STAT_CHILDSTAT | histflags, &status)) { - dgerr(sctx[j],"edg_wll_JobStatus"); result = 1; - } else printstat(status,0); - - if (job) edg_wlc_JobIdFree(job); - if (status.state) edg_wll_FreeStatus(&status); - } - } - for ( i = 0; i < nsrv; i++ ) edg_wll_FreeContext(sctx[i]); - - return result; -} - -static void -usage(char *name) -{ - fprintf(stderr,"Usage: %s [-x lb_proxy_serve_sock] [-fasthist|-fullhist] [job_id [...]]\n", name); - fprintf(stderr," %s -all\n", name); -} - -static int -query_all(edg_wll_Context ctx, edg_wll_JobStat **statesOut, edg_wlc_JobId **jobsOut) -{ - edg_wll_QueryRec jc[2]; - int ret; - - memset(jc, 0, sizeof jc); - jc[0].attr = EDG_WLL_QUERY_ATTR_OWNER; - jc[0].op = EDG_WLL_QUERY_OP_EQUAL; - jc[0].value.c = NULL; /* is NULL, peerName filled in on server side */ - jc[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - - if ( (ret = edg_wll_QueryJobs(ctx, jc, 0, jobsOut, statesOut)) ) { - if ( ret == E2BIG ) { - int r; - if ( edg_wll_GetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, &r) ) return ret; - if ( r != EDG_WLL_QUERYRES_LIMITED ) return ret; - - printf("Warning: only limited result returned!\n"); - return 0; - } else return ret; - } - - return ret; -} - -static void -dgerr(edg_wll_Context ctx,char *where) -{ - char *etxt,*edsc; - - edg_wll_Error(ctx,&etxt,&edsc); - fprintf(stderr,"%s: %s: %s",myname,where,etxt); - if (edsc) fprintf(stderr," (%s)",edsc); - putc('\n',stderr); - free(etxt); free(edsc); -} - -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; - case EDG_WLL_STAT_CONDOR: - printf("%sjobtype : CONDOR\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]); - } - printf("%ssuspended : %d\n", ind, stat.suspended); - printf("%ssuspend_reason : %s\n", ind, stat.suspend_reason); - printf("%sfailure_reasons : %s\n", ind, stat.failure_reasons); - printf("%sremove_from_proxy : %d\n", ind, stat.remove_from_proxy); - printf("%sui_host : %s\n", ind, stat.ui_host); - if (stat.user_fqans) { - printf("%suser_fqans : \n", ind); - for (i=0; stat.user_fqans[i]; i++) - printf("%s\t%s \n", ind, stat.user_fqans[i]); - } - printf("%ssandbox_retrieved : %d\n", ind, stat.sandbox_retrieved); - printf("%sjw_status : %s\n", ind, edg_wll_JWStatToString(stat.jw_status)); - - /* 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); -} - diff --git a/org.glite.lb.client/examples/log_usertag_proxy.c b/org.glite.lb.client/examples/log_usertag_proxy.c deleted file mode 100644 index 2b48494..0000000 --- a/org.glite.lb.client/examples/log_usertag_proxy.c +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lb/notifid.h" -#include "glite/lb/events.h" - -#ifdef BUILDING_LB_CLIENT -#include "producer.h" -#else -#include "glite/lb/producer.h" -#endif - -static struct option opts[] = { - {"help", 0, NULL, 'h'}, - {"sock", 1, NULL, 's'}, - {"jobid", 1, NULL, 'j'}, - {"user", 1, NULL, 'u'}, - {"seq", 1, NULL, 'c'}, - {"name", 1, NULL, 'n'}, - {"value", 1, NULL, 'v'} -}; - -static void usage(char *me) -{ - fprintf(stderr, "usage: %s [option]\n" - "\t-h, --help Shows this screen.\n" - "\t-s, --server LB Proxy socket.\n" - "\t-j, --jobid ID of requested job.\n" - "\t-u, --user User DN.\n" - "\t-c, --seq Sequence code.\n" - "\t-n, --name Name of the tag.\n" - "\t-v, --value Value of the tag.\n" - , me); -} - - -int main(int argc, char *argv[]) -{ - edg_wll_Context ctx; - edg_wlc_JobId jobid = NULL; - char *server, *code, *jobid_s, *user, *name, *value; - int opt, err = 0; - - - server = code = jobid_s = name = value = NULL; - while ( (opt = getopt_long(argc, argv, "hs:j:u:c:n:v:", opts, NULL)) != EOF) - switch (opt) { - case 'h': usage(name); return 0; - case 's': server = strdup(optarg); break; - case 'j': jobid_s = strdup(optarg); break; - case 'u': user = strdup(optarg); break; - case 'c': code = strdup(optarg); break; - case 'n': name = strdup(optarg); break; - case 'v': value = strdup(optarg); break; - case '?': usage(name); return 1; - } - - if ( !jobid_s ) { fprintf(stderr, "JobId not given\n"); return 1; } - if ( !server ) { fprintf(stderr, "LB proxy socket not given\n"); return 1; } - if ( !name ) { fprintf(stderr, "Tag name not given\n"); return 1; } - if ( !value ) { fprintf(stderr, "Tag value not given\n"); return 1; } - - if ( (errno = edg_wlc_JobIdParse(jobid_s, &jobid)) ) { perror(jobid_s); return 1; } - - edg_wll_InitContext(&ctx); - - if ( !user ) { - /* - edg_wll_GssStatus gss_stat; - - if ( edg_wll_gss_acquire_cred_gsi( - ctx->p_proxy_filename ? : ctx->p_cert_filename, - ctx->p_proxy_filename ? : ctx->p_key_filename, - NULL, &gss_stat) ) { - fprintf(stderr, "failed to load GSI credentials\n"); - retrun 1; - } - */ - } - - edg_wll_SetParam(ctx, EDG_WLL_PARAM_SOURCE, EDG_WLL_SOURCE_USER_INTERFACE); - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, server); - - if (edg_wll_SetLoggingJobProxy(ctx, jobid, code, user, EDG_WLL_SEQ_NORMAL)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"SetLoggingJob(%s,%s): %s (%s)\n",jobid_s,code,et,ed); - exit(1); - } - - err = edg_wll_LogEventProxy(ctx, - EDG_WLL_EVENT_USERTAG, EDG_WLL_FORMAT_USERTAG, - name, value); - - if (err) { - char *et,*ed; - - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"%s: edg_wll_LogEvent*(): %s (%s)\n", - argv[0],et,ed); - free(et); free(ed); - } - - code = edg_wll_GetSequenceCode(ctx); - puts(code); - free(code); - - edg_wll_FreeContext(ctx); - - return err; -} diff --git a/org.glite.lb.client/examples/multiple_user_jobs.c b/org.glite.lb.client/examples/multiple_user_jobs.c deleted file mode 100644 index 4c38c21..0000000 --- a/org.glite.lb.client/examples/multiple_user_jobs.c +++ /dev/null @@ -1,125 +0,0 @@ -#include -#include -#include - -#include "glite/lb/context.h" -#include "glite/lb/xml_conversions.h" -#include "consumer.h" - -int use_proxy = 0; - -int (*user_jobs)(edg_wll_Context, edg_wlc_JobId **, edg_wll_JobStat **); - - -void -usage(char *me) -{ - fprintf(stderr,"This example demonstrates the use of several user identities provided byi\n" - "proxy files to access a single bkserver and retrieve appropriate information.\n\n" - "usage: %s [-h] \n" - "\t-h, --help\t show this help\n" - "\t\t A list of proxy files to use to contact the bkserver\n" - "\t \t Give \"default\" for default (EDG_WLL_PARAM_X509_PROXY == NULL)\n" - "\n" - ,me); - -} - -int main(int argc,char **argv) -{ - edg_wll_Context *p_ctx; - char *errt,*errd; - glite_jobid_t **jobs = NULL; - edg_wll_JobStat **states = NULL; - int i,j,k; - int no_of_runs; - - if ((argc<2) || !strcmp(argv[1], "-h")) {usage(argv[0]); exit(0);} - - no_of_runs = argc-1; - - p_ctx = (edg_wll_Context*) calloc (sizeof(edg_wll_Context), no_of_runs); - jobs = (edg_wlc_JobId**) calloc (sizeof(edg_wlc_JobId*), no_of_runs); - states = (edg_wll_JobStat**) calloc (sizeof(edg_wll_JobStat*), no_of_runs); - - user_jobs = edg_wll_UserJobs; - for ( i = 1; i <= no_of_runs; i++ ) { - printf ("Proxy file No. %d: %s\n",i,argv[i]); - - edg_wll_InitContext(&p_ctx[i-1]); - if (strcmp(argv[i],"default")) edg_wll_SetParam(p_ctx[i-1], EDG_WLL_PARAM_X509_PROXY, argv[i]); - if (user_jobs(p_ctx[i-1],&jobs[i-1],&states[i-1])) goto err; - - } - - for (k=0; k < no_of_runs; k++) { - printf("Jobs retrieved using file No. %d (%s)\n" - "------------------------------------------\n", k + 1, argv[k + 1]); - for (i=0; states[k][i].state != EDG_WLL_JOB_UNDEF; i++) { - char *id = edg_wlc_JobIdUnparse(states[k][i].jobId), - *st = edg_wll_StatToString(states[k][i].state); - - if (!states[k][i].parent_job) { - if (states[k][i].jobtype == EDG_WLL_STAT_SIMPLE) { - printf(" %s .... %s %s\n", id, st, (states[k][i].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[k][i].done_code) : "" ); - } - else if ((states[k][i].jobtype == EDG_WLL_STAT_DAG) || - (states[k][i].jobtype == EDG_WLL_STAT_COLLECTION)) { - printf("%s %s .... %s %s\n", (states[k][i].jobtype==EDG_WLL_STAT_DAG)?"DAG ":"COLL",id, st, (states[k][i].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[k][i].done_code) : ""); - for (j=0; states[k][j].state != EDG_WLL_JOB_UNDEF; j++) { - if (states[k][j].parent_job) { - char *par_id = edg_wlc_JobIdUnparse(states[k][j].parent_job); - - if (!strcmp(id,par_id)) { - char *sub_id = edg_wlc_JobIdUnparse(states[k][j].jobId), - *sub_st = edg_wll_StatToString(states[k][j].state); - - printf(" `- %s .... %s %s\n", sub_id, sub_st, (states[k][j].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[k][j].done_code) : ""); - free(sub_id); - free(sub_st); - } - free(par_id); - } - } - } - } - - free(id); - free(st); - } - } - - printf("\nFound %d jobs\n",i); - -err: - if (jobs) { - for (k=0; k < no_of_runs; k++) { - if (jobs[k]) - for (i=0; jobs[k][i]; i++) edg_wlc_JobIdFree(jobs[i]); - } - free(jobs); - } - - if (states) { - for (k=0; k < no_of_runs; k++) { - if (states[k]) - for (i=0; states[k][i].state; i++) edg_wll_FreeStatus(states[i]); - } - free(states); - } - - for (k=0; k < no_of_runs; k++) { - if (edg_wll_Error(p_ctx[k],&errt,&errd)) { - fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); - return 1; - } - } - - - for (k=0; k < no_of_runs; k++) { - edg_wll_FreeContext(p_ctx[k]); - } - - return 0; -} - diff --git a/org.glite.lb.client/examples/notify.pl b/org.glite.lb.client/examples/notify.pl deleted file mode 100755 index 7defa0d..0000000 --- a/org.glite.lb.client/examples/notify.pl +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/perl - -use Socket; -use Fcntl; - -$notif = $ENV{NOTIFY_CMD} ? $ENV{NOTIFY_CMD} : './notify'; - -socket SOCK,PF_INET,SOCK_STREAM,getprotobyname('tcp') || die "socket: $!\n"; -bind SOCK,sockaddr_in(0,INADDR_ANY) || die "bind: $!\n"; -listen SOCK,10; - -$fd = fileno SOCK; - -$flags = fcntl SOCK,F_GETFD,0; -fcntl SOCK,F_SETFD,$flags & ~FD_CLOEXEC; - - -$cmd = "$notif new -s $fd"; - -for (@ARGV) { $cmd .= " '$_'"; } -system $cmd; - -$fdin = ''; -vec($fdin,$fd,1) = 1; - -while (1) { - select($fdin,undef,undef,undef); - print "got connection\n"; - - system "$notif receive -s $fd -i 3"; -} - - diff --git a/org.glite.lb.client/examples/parse_eventsfile.c b/org.glite.lb.client/examples/parse_eventsfile.c deleted file mode 100644 index 2f9d339..0000000 --- a/org.glite.lb.client/examples/parse_eventsfile.c +++ /dev/null @@ -1,120 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#ifdef BUILDING_LB_CLIENT -#include "producer.h" -#else -#include "glite/lb/producer.h" -#endif -#include "glite/lb/events.h" -#include "glite/lb/events_parse.h" - -#define MAXMSGSIZE 10240 - -extern char *optarg; -extern int opterr,optind; - -static const char *me; - -static void usage() -{ - fprintf(stderr,"usage: %s [-n] -f file_name\n", me); -} - -int main(int argc, char *argv[]) -{ - char *filename = NULL; - char buf[MAXMSGSIZE]; - int done = 0,i=0,notif=0; - edg_wll_Context ctx; - edg_wll_Event *event = NULL; - FILE *f; - edg_wll_ErrorCode (*parse)(edg_wll_Context context,edg_wll_LogLine logline,edg_wll_Event **event); - edg_wll_LogLine (*unparse)(edg_wll_Context context,edg_wll_Event *event); - const char *parse_str,*unparse_str; - - edg_wll_InitContext(&ctx); - opterr = 0; - - me = strdup(argv[0]); - - do { - switch (getopt(argc,argv,"nf:")) { - case 'n': notif = 1; break; - case 'f': filename = (char *) strdup(optarg); break; - case '?': usage(); exit(EINVAL); - case -1: done = 1; break; - } - } while (!done); - - /* choose the right (un)parser */ - if (notif) { - parse = edg_wll_ParseNotifEvent; - parse_str = "edg_wll_ParseNotifEvent"; - unparse = edg_wll_UnparseNotifEvent; - unparse_str = "edg_wll_UnparseNotifEvent"; - } else { - parse = edg_wll_ParseEvent; - parse_str = "edg_wll_ParseEvent"; - unparse = edg_wll_UnparseEvent; - unparse_str = "edg_wll_UnparseEvent"; - } - - if (!filename) { - fprintf(stderr,"%s: -f required\n",me); - usage(); - exit(1); - } - - if ( (f = fopen(filename,"r")) == NULL) { - perror(filename); - exit(1); - } else { - fprintf(stderr,"Parsing file '%s' for correctness:\n",filename); - } - - /* parse events */ - i = 1; - while (!feof(f)) { - if (!fgets(buf,sizeof(buf),f)) break; - if (strcmp(buf,"\n")) { - // fprintf(stdout,"%d: %s\n",i,buf); - - if (parse(ctx,buf,&event) != 0) { - /* Parse ERROR: */ - char *et=NULL,*ed=NULL; - - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"line %d: %s() error: %s (%s)\n",i,parse_str,et,ed); - if (et) free(et); - if (ed) free(ed); - } else { - /* Parse OK : */ - char *es=NULL; - edg_wll_LogLine logline = NULL; - - es=edg_wll_EventToString(event->type); - logline = unparse(ctx,event); - fprintf(stderr,"line %d: %s() o.k. (event %s), ",i,parse_str,es); - if (logline) { - fprintf(stderr,"%s() o.k.\n",unparse_str); - free(logline); - } else { - fprintf(stderr,"%s() error\n",unparse_str); - } - if (es) free(es); - } - if (event) edg_wll_FreeEvent(event); - } - i++; - } - fclose(f); - - edg_wll_FreeContext(ctx); - - return 0; -} diff --git a/org.glite.lb.client/examples/purge_test b/org.glite.lb.client/examples/purge_test deleted file mode 100644 index 0018cdf..0000000 --- a/org.glite.lb.client/examples/purge_test +++ /dev/null @@ -1,191 +0,0 @@ -#!/usr/bin/perl - - - -BEGIN{ -$inst = $ENV{GLITE_PREFIX}; -$inst = "/opt/glite" unless $inst; -$sbin = "$inst/sbin"; -$bin = "$inst/bin"; -$test = "$inst/examples"; -$purge = "$bin/glite-lb-purge"; -$status = "$test/glite-lb-job_status"; -$log = "$test/glite-lb-job_log"; -$prefix = "/tmp/purge_test_$$"; -$delay = 60; - -$ENV{PATH} .= ":$bin"; -} - -$option = shift; -$server = shift; - -die qq{ -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - This script will DESTROY ALL DATA in the specified bookkeeping server. - -Don't run it unless you are absolutely sure what you are doing. -If you really mean it, the magic usage is: - - $0 --i-want-to-purge server:port - -Good luck! - -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - -} unless $option eq '--i-want-to-purge'; - -die "usage: $0 --i-want-to-purge server:port\n" unless $server; - -sub logit { - my $ids = shift; - my $prefix = shift; - my $failed = 0; - - for (qw/aborted cleared cancelled waiting/) { - my $key = $_ eq waiting ? 'other' : $_; - $id = `$test/glite-lb-$_.sh -m $server`; - chomp $id; - die "$test/glite-lb-$_.sh" if $?; - $id =~ s/EDG_JOBID=//; - $ids->{$key} = $id; -#print "$status $id | head -1\n"; - $stat = `$status $id | head -2 | tail -1`; - chomp $stat; - $stat =~ s/state :\s*//; -#print "$id: ".uc($stat)." ".uc($_)."\n"; - $failed = 1 if uc($stat) ne uc($_); - - system "$log $id | grep -v '^[ ]*\$' | grep -v '^Found' >${prefix}_$_"; - } - - !$failed; -} - -print "** Hey, purging the whole database\n"; -system "$purge --server $server --return-list --aborted=0 --cleared=0 --cancelled=0 --other=0"; -die "$purge: $!\n" if $!; - -print "** Logging test jobs\n"; - -die "!! failed\n" if !logit \%old,"${prefix}_old"; -print "** So far good, sleeping $delay seconds\n"; -sleep $delay; -print "** OK, another set of jobs\n"; -die "!! failed\n" if !logit \%new,"${prefix}_new"; - -print "** Dry run\n"; -$failed = 0; - -$half = $delay/2; -for (qw/aborted cleared cancelled other/) { - open LIST,"$purge --server $server --dry-run --return-list --$_=${half}s| grep '^https://'|" or die "!! run $purge\n"; - - $id = ; chomp $id; - if ($old{$_} ne $id) { - $failed = 1; - print "!! $old{$_} (old $_) is not there\n"; - } - else { - print "$_ $id OK\n"; - } - $id = ; - if ($id) { - $failed = 1; - chomp $id; - print "!! $id should not be there\n"; - } - close LIST; - - open LIST,"$purge --server $server --dry-run --return-list --$_=0s | grep '^https://'|" or die "!! run $purge\n"; - - $cnt = 0; - while ($id = ) { - chomp $id; - if ($old{$_} ne $id && $new{$_} ne $id) { - $failed = 1; - print "!! $id should not be there\n"; - } - else { - print "$_ $id OK\n"; - } - $cnt++; - } - - close LIST; - if ($cnt != 2) { - $failed = 1; - print "!! bad number of $_ jobs ($cnt)\n"; - } -} - -die "!! aborting\n" if $failed; - -print "** Server defaults\n"; - -open LIST,"$purge --server $server --dry-run --return-list | grep '^https://'|" or die "!! run $purge\n"; - -$failed = 0; -while ($id = ) { - $failed = 1; - print "$id\n"; -} - -die "!! Oops, should not do anything, too short defaults?\n" if $failed; - -print "Nothing purged as expected\n"; - -print "** Purge the first set of jobs\n"; - -open DUMP,"$purge --server $server --server-dump --aborted=${half}s --cleared=${half}s --cancelled=${half}s --other=${half}s | grep '^Server dump:'|" - or die "!! run $purge\n"; - -$dump = ; chomp $dump; $dump =~ s/Server dump: //; -close DUMP; - -die "!! no dump file reported\n" unless $dump; -#print "DEBUG: dump file: '$dump'\n"; -@list = glob "${prefix}_old*"; -system "cat @list | sort >${prefix}_old_all"; -system "cat $dump | sed -e s/^.*DATE/DATE/ | sort >${prefix}_old_dump"; -sleep 60; -system "diff ${prefix}_old_all ${prefix}_old_dump >/dev/null"; - -die "!! aggregate log and dump differ\n" if $? & 0xff00; - -print "diff OK\n"; - -print "** Purge the rest\n"; -open DUMP,"$purge --server $server --server-dump --aborted=0 --cleared=0 --cancelled=0 --other=0 | grep '^Server dump:'|" - or die "!! run $purge\n"; - -$dump = ; chomp $dump; $dump =~ s/Server dump: //; -close DUMP; - -die "!! no dump file reported\n" unless $dump; -#print "DEBUG: dump file: '$dump'\n"; -@list = glob "${prefix}_new*"; -system "cat @list | sort >${prefix}_new_all"; -system "cat $dump | sed -e s/^.*DATE/DATE/ | sort >${prefix}_new_dump"; -system "diff ${prefix}_new_all ${prefix}_new_dump >/dev/null"; - -die "!! aggregate log and dump differ\n" if $? & 0xff00; - -print "diff OK\n"; - - -print "** Anything left?\n"; -open LIST,"$purge --server $server --return-list --dry-run --aborted=0 --cleared=0 --cancelled=0 --other=0 | grep '^https://'|" or die "!! $purge\n"; - -$id = ; -close LIST; -die "!! Yes, but should not\n" if $id; -print "No, OK\n"; - -print "\n** All tests passed **\n"; -exit 0; - -END{ unlink glob "${prefix}*" if $prefix; } diff --git a/org.glite.lb.client/examples/query_ext.c b/org.glite.lb.client/examples/query_ext.c deleted file mode 100644 index 82b23c6..0000000 --- a/org.glite.lb.client/examples/query_ext.c +++ /dev/null @@ -1,926 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#ifdef BUILDING_LB_CLIENT -#include "consumer.h" -#else -#include "glite/lb/consumer.h" -#endif - -#define BUFF_LEN 1024 -#define MAX_AND_CONDS 20 - -enum -{ - PQRV_ERR, - PQRV_EOF, - PQRV_EMPTY_LINE, -}; - - -static void printstat(edg_wll_JobStat); -static int cond_parse(edg_wll_QueryRec ***, int); -static void dgerr(edg_wll_Context, char *); -static void free_QueryRec(edg_wll_QueryRec *qr); -static void printconds(edg_wll_QueryRec **); -static time_t StrToTime(char *t); -static char *TimeToStr(time_t t); - -static char *myname; -static FILE *fin; -static char buffer[BUFF_LEN+1], - tmps[500]; -static int query_jobs = 1; -#define query_events (!query_jobs) -static int query_lbproxy = 0; -#define query_bkserver (!query_lbproxy) -static int verbose = 0; - - -static void usage(void) -{ - fprintf(stderr, "Usage: %s [-hvs] [-i file]\n", myname); - fprintf(stderr, " -h show this help\n"); - fprintf(stderr, " -v increase verbosity level\n"); - fprintf(stderr, " -s results described verbosely (query jobs only)\n"); - fprintf(stderr, " -m server name\n"); - fprintf(stderr, " -i file input file (default is stdin)\n\n"); - fprintf(stderr, " -e query events (default is 'query jobs')\n"); - fprintf(stderr, " -P query the L&B Proxy server\n"); - fprintf(stderr, " -p L&B Proxy socket path\n"); - fprintf(stderr, " -r type returned results: limited | all | none\n\n"); - fprintf(stderr, " -J num jobs soft limit\n\n"); - fprintf(stderr, " -E num events soft limit (query events only)\n\n"); -} - -int main(int argc,char *argv[]) -{ - edg_wll_Context ctx; - edg_wll_QueryResults rslts = EDG_WLL_QUERYRES_UNDEF; - edg_wll_QueryRec **jc = NULL, - **ec = NULL; - edg_wll_JobStat *statesOut = NULL; - edg_wlc_JobId *jobsOut = NULL; - edg_wll_Event *eventsOut = NULL; - char *fname = NULL, - *server = NULL, - *proxy_sock = NULL, - *s; - int result = 0, - jobsLimit = 0, - stdisp = 0, - eventsLimit = 0, - i, j, ret, - errCode; - - myname = argv[0]; - ret = 0; - do { - switch ( getopt(argc,argv,"hvsePp:i:m:r:J:E:") ) { - case 'h': usage(); exit(0); - case '?': usage(); exit(EINVAL); - case 'v': verbose = 1; break; - case 'i': fname = strdup(optarg); break; - case 'm': server = strdup(optarg); break; - case 's': stdisp = 1; break; - case 'e': query_jobs = 0; break; - case 'P': query_lbproxy = 1; break; - case 'p': proxy_sock = strdup(optarg); break; - case 'r': - if ( !strcasecmp(optarg, "limited") ) rslts = EDG_WLL_QUERYRES_LIMITED; - else if ( !strcasecmp(optarg, "none") ) rslts = EDG_WLL_QUERYRES_NONE; - else if ( !strcasecmp(optarg, "all") ) rslts = EDG_WLL_QUERYRES_ALL; - else { usage(); exit(EINVAL); } - break; - case 'J': jobsLimit = atoi(optarg); break; - case 'E': eventsLimit = atoi(optarg); break; - case -1: ret = 1; break; - } - } while ( !ret ); - - if ( edg_wll_InitContext(&ctx) ) { - if ( verbose ) fprintf(stderr,"%s: cannot initialize edg_wll_Context\n",myname); - exit(1); - } - - if ( jobsLimit > 0 ) { - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_JOBS_LIMIT, jobsLimit); - if ( verbose ) printf("Soft query limit for jobs: %d\n", jobsLimit); - } - else if ( verbose ) printf("Soft query limit for jobs not set\n"); - - if ( query_events ) { - if ( eventsLimit > 0 ) { - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_EVENTS_LIMIT, eventsLimit); - if ( verbose ) printf("Soft query limit for events: %d\n", eventsLimit); - } - else if ( verbose ) printf("Soft query limit for events not set\n"); - } - - if ( rslts != EDG_WLL_QUERYRES_UNDEF ) - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, rslts); - else - edg_wll_GetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, &rslts); - - if ( verbose ) printf("When any limit overflows, the returned result set is: %s\n", - rslts==EDG_WLL_QUERYRES_LIMITED? "limited": - (rslts==EDG_WLL_QUERYRES_ALL? "unlimited": "empty")); - - if ( server ) { - char *p = strchr(server, ':'); - if ( p ) { - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, atoi(p+1)); - *p = 0; - } - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server); - free(server); - } - - if ( proxy_sock ) { - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, proxy_sock); - free(proxy_sock); - } - - if ( fname ) { - fin = fopen(fname, "r"); - if ( !fin ) { - if ( verbose ) fprintf(stderr, "Can't open given input file %s. Using stdin.\n", fname); - fin = stdin; - } - free(fname); - } else { - if ( verbose ) fprintf(stderr, "No input file given. Using stdin.\n"); - fin = stdin; - } - - jobsOut = NULL; - statesOut = NULL; - eventsOut = NULL; - - - do - { - if ( verbose && (fin == stdin) ) printf("Enter job conditions:\n"); - - ret = cond_parse(&jc, 1); - if ( ret == PQRV_ERR ) { result = 1; goto cleanup; } - if ( query_events && (ret != PQRV_EOF) ) { - if ( verbose && (fin == stdin) ) printf("Enter event conditions:\n"); - ret = cond_parse(&ec, 0); - if ( ret == PQRV_ERR ) { result = 1; goto cleanup; } - } - - if ( (ret == PQRV_EOF) && !jc && (query_jobs || (query_events && !ec)) ) break; - - if ( verbose ) { - printf("job conditions list: "); - printconds(jc); - if ( query_events ) { printf("event condition list: "); printconds(ec); } - } - - if ( query_jobs ) { - if ( query_bkserver ) - errCode = edg_wll_QueryJobsExt(ctx, - (const edg_wll_QueryRec **) jc, - 0, &jobsOut, stdisp? &statesOut: NULL); - else - errCode = edg_wll_QueryJobsExtProxy(ctx, - (const edg_wll_QueryRec **) jc, - 0, &jobsOut, stdisp? &statesOut: NULL); - } else { - if ( query_bkserver ) - errCode = edg_wll_QueryEventsExt(ctx, - (const edg_wll_QueryRec **) jc, - (const edg_wll_QueryRec **) ec, - &eventsOut); - else - errCode = edg_wll_QueryEventsExtProxy(ctx, - (const edg_wll_QueryRec **) jc, - (const edg_wll_QueryRec **) ec, - &eventsOut); - } - - if ( errCode ) { - dgerr(ctx, NULL); - if ( (errCode != EPERM) && (errCode != E2BIG) ) goto cycle_cleanup; - } else if ( verbose ) { - if ( query_jobs ) printf("Matched jobs: "); - else printf("Matched events: "); - } - - if ( verbose ) { - if ( (query_jobs && jobsOut && jobsOut[0]) || - (query_events && eventsOut && eventsOut[0].type) ) - putchar('\n'); - else printf("No one matches\n"); - } - - if ( query_jobs && jobsOut && !stdisp ) { - for ( i = 0; jobsOut[i]; i++ ) { - s = edg_wlc_JobIdUnparse(jobsOut[i]); - printf("jobId: %s\n", edg_wlc_JobIdUnparse(jobsOut[i])); - free(s); - edg_wlc_JobIdFree(jobsOut[i]); - } - free(jobsOut); - jobsOut = NULL; - } - if ( query_jobs && statesOut ) { - if ( stdisp ) for ( i = 0; statesOut[i].state; i++ ) printstat(statesOut[i]); - for ( i = 0; statesOut[i].state; i++ ) edg_wll_FreeStatus(&statesOut[i]); - free(statesOut); - statesOut = NULL; - } - if ( query_events && eventsOut ) { - for ( i = 0; eventsOut[i].type; i++ ) { - s = edg_wlc_JobIdUnparse(eventsOut[i].any.jobId); - printf("event: %-11s (jobid %s)\n", edg_wll_EventToString(eventsOut[i].type), s); - free(s); - } - free(eventsOut); - eventsOut = NULL; - } - -cycle_cleanup: - if ( jc ) { - for ( i = 0; jc[i]; i++ ) { - for ( j = 0; jc[i][j].attr; j++ ) free_QueryRec(&jc[i][j]); - free(jc[i]); - } - free(jc); - } - - if ( ec ) { - for ( i = 0; ec[i]; i++ ) { - for ( j = 0; ec[i][j].attr; j++ ) free_QueryRec(&ec[i][j]); - free(ec[i]); - } - free(ec); - } - } while ( ret != PQRV_EOF ); - -cleanup: - if ( fin != stdin ) fclose(fin); - edg_wll_FreeContext(ctx); - - return result; -} - -static void free_QueryRec(edg_wll_QueryRec *qr) -{ - switch ( qr->attr ) - { - case EDG_WLL_QUERY_ATTR_JOBID: - case EDG_WLL_QUERY_ATTR_PARENT: - edg_wlc_JobIdFree(qr->value.j); - 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: - break; - - case EDG_WLL_QUERY_ATTR_OWNER: - case EDG_WLL_QUERY_ATTR_LOCATION: - case EDG_WLL_QUERY_ATTR_DESTINATION: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - free(qr->value.c); - break; - - case EDG_WLL_QUERY_ATTR_USERTAG: - free(qr->attr_id.tag); - free(qr->value.c); - break; - - default: - break; - } -} - -#define isop(c) ((c == '=') || (c == '<') || (c == '>') || (c == '@')) - -static char *get_attr_name(char *src, char *dest, int sz) -{ - int i = 0, - ct = 0; - - - while ( (src[i] != '\0') && isblank(src[i]) ) i++; /* skip whitespaces */ - while ( (src[i] != '\n') && (src[i] != '\0') && !isop(src[i]) && !isblank(src[i]) ) - { - if ( ct < sz ) - dest[ct++] = src[i]; - i++; - } - dest[ct] = '\0'; - - return src+i; -} - -static char *get_op(char *src, edg_wll_QueryOp *op) -{ - int i = 0; - - - while ( (src[i] != '\0') && isblank(src[i]) ) i++; /* skip whitespaces */ - - if ( src[i] == '=' ) *op = EDG_WLL_QUERY_OP_EQUAL; - else if ( src[i] == '@' ) *op = EDG_WLL_QUERY_OP_WITHIN; - else if ( src[i] == '>' ) *op = EDG_WLL_QUERY_OP_GREATER; - else if ( src[i] == '<' ) - { - if ( (src[i+1] != '\0') && (src[++i] == '>') ) - *op = EDG_WLL_QUERY_OP_UNEQUAL; - else - *op = EDG_WLL_QUERY_OP_LESS; - } - else return NULL; - - return src+i+1; -} - -static char *get_attr_value(char *src, char *dest, int sz) -{ - int i = 0, - ct = 0; - - - while ( (src[i] != '\0') && isblank(src[i]) ) i++; /* skip whitespaces */ - if ( src[i] == '"' ) - { - i++; - while ( (src[i] != '\n') && (src[i] != '\0') && (src[i] != '"') ) - { - if ( ct < sz ) - dest[ct++] = src[i]; - i++; - } - dest[ct] = '\0'; - if ( src[i] != '"' ) - return NULL; - - return src+i+1; - } - - while ( (src[i] != '\n') && (src[i] != '\0') && (src[i] != ';') && !isblank(src[i]) ) - { - if ( ct < sz ) - dest[ct++] = src[i]; - i++; - } - dest[ct] = '\0'; - - return src+i; -} - -static char *get_job_condition(char *src, edg_wll_QueryRec *cond) -{ - char *s; - - - s = get_attr_name(src, tmps, 500); - - if ( tmps[0] == '\0' ) return NULL; - - if ( !strcmp(tmps, "jobid") ) cond->attr = EDG_WLL_QUERY_ATTR_JOBID; - else if ( !strcmp(tmps, "owner") ) cond->attr = EDG_WLL_QUERY_ATTR_OWNER; - else if ( !strcmp(tmps, "status") ) cond->attr = EDG_WLL_QUERY_ATTR_STATUS; - else if ( !strcmp(tmps, "location") ) cond->attr = EDG_WLL_QUERY_ATTR_LOCATION; - else if ( !strcmp(tmps, "destination") ) cond->attr = EDG_WLL_QUERY_ATTR_DESTINATION; - else if ( !strcmp(tmps, "done_code") ) cond->attr = EDG_WLL_QUERY_ATTR_DONECODE; - else if ( !strcmp(tmps, "exit_code") ) cond->attr = EDG_WLL_QUERY_ATTR_EXITCODE; - else if ( !strcmp(tmps, "parent_job") ) cond->attr = EDG_WLL_QUERY_ATTR_PARENT; - else if ( !strcmp(tmps, "time") ) cond->attr = EDG_WLL_QUERY_ATTR_TIME; - else if ( !strcmp(tmps, "state_enter_time") ) cond->attr = EDG_WLL_QUERY_ATTR_STATEENTERTIME; - else if ( !strcmp(tmps, "last_update_time") ) cond->attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME; - else if ( !strcmp(tmps, "jdl_attr") ) cond->attr = EDG_WLL_QUERY_ATTR_JDL_ATTR; - - - /**< When entered current status */ - /**< Time of the last known event of the job */ - /**< Network server aka RB aka WMproxy endpoint */ - - else - { - cond->attr = EDG_WLL_QUERY_ATTR_USERTAG; - cond->attr_id.tag = strdup(tmps); - } - - if ( !(s = get_op(s, &(cond->op))) ) return NULL; - - if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; - - switch ( cond->attr ) - { - case EDG_WLL_QUERY_ATTR_JOBID: - case EDG_WLL_QUERY_ATTR_PARENT: - if ( edg_wlc_JobIdParse(tmps, &cond->value.j) ) - { - fprintf(stderr,"%s: %s: cannot parse jobId\n", myname, tmps); - return NULL; - } - break; - - case EDG_WLL_QUERY_ATTR_OWNER: - if ( !strcmp("NULL", tmps) ) - cond->value.c = NULL; - else if ( !(cond->value.c = strdup(tmps)) ) - return 0; - break; - - case EDG_WLL_QUERY_ATTR_LOCATION: - case EDG_WLL_QUERY_ATTR_DESTINATION: - case EDG_WLL_QUERY_ATTR_USERTAG: - if ( !(cond->value.c = strdup(tmps)) ) - return 0; - break; - - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - if ( !(cond->value.c = strdup(tmps)) ) - return 0; - if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; - if ( tmps[0] == '\0' ) - { - fprintf(stderr,"%s: you need to specify attribute name\n", myname); - return NULL; - } - if ( !(cond->attr_id.tag = strdup(tmps)) ) - return 0; - break; - - case EDG_WLL_QUERY_ATTR_STATUS: - if ( !strcasecmp(tmps, "Submitted") ) cond->value.i = EDG_WLL_JOB_SUBMITTED; - else if ( !strcasecmp(tmps, "Waiting") ) cond->value.i = EDG_WLL_JOB_WAITING; - else if ( !strcasecmp(tmps, "Ready") ) cond->value.i = EDG_WLL_JOB_READY; - else if ( !strcasecmp(tmps, "Scheduled") ) cond->value.i = EDG_WLL_JOB_SCHEDULED; - else if ( !strcasecmp(tmps, "Running") ) cond->value.i = EDG_WLL_JOB_RUNNING; - else if ( !strcasecmp(tmps, "Done") ) cond->value.i = EDG_WLL_JOB_DONE; - else if ( !strcasecmp(tmps, "Aborted") ) cond->value.i = EDG_WLL_JOB_ABORTED; - else if ( !strcasecmp(tmps, "Cancelled") ) cond->value.i = EDG_WLL_JOB_CANCELLED; - else if ( !strcasecmp(tmps, "Cleared") ) cond->value.i = EDG_WLL_JOB_CLEARED; - else - { - fprintf(stderr,"%s: invalid status value (%s)\n", myname, tmps); - return 0; - } - break; - - case EDG_WLL_QUERY_ATTR_DONECODE: - case EDG_WLL_QUERY_ATTR_EXITCODE: - case EDG_WLL_QUERY_ATTR_RESUBMITTED: - cond->value.i = atoi(tmps); - if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) - { - if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; - if ( tmps[0] == '\0' ) - { - fprintf(stderr,"%s: second interval boundary not set\n", myname); - return NULL; - } - cond->value2.i = atoi(tmps); - } - break; - case EDG_WLL_QUERY_ATTR_TIME: - cond->value.t.tv_sec = StrToTime(tmps); - if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) - { - if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; - if ( tmps[0] == '\0' ) - { - fprintf(stderr,"%s: second interval boundary not set\n", myname); - return NULL; - } - cond->value2.t.tv_sec = StrToTime(tmps); - } - if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; - if ( tmps[0] == '\0' ) - { - fprintf(stderr,"%s: time condition must be associated with state condition\n", myname); - return NULL; - } - if ( !strcasecmp(tmps, "Submitted") ) cond->attr_id.state = EDG_WLL_JOB_SUBMITTED; - else if ( !strcasecmp(tmps, "Waiting") ) cond->attr_id.state = EDG_WLL_JOB_WAITING; - else if ( !strcasecmp(tmps, "Ready") ) cond->attr_id.state = EDG_WLL_JOB_READY; - else if ( !strcasecmp(tmps, "Scheduled") ) cond->attr_id.state = EDG_WLL_JOB_SCHEDULED; - else if ( !strcasecmp(tmps, "Running") ) cond->attr_id.state = EDG_WLL_JOB_RUNNING; - else if ( !strcasecmp(tmps, "Done") ) cond->attr_id.state = EDG_WLL_JOB_DONE; - else if ( !strcasecmp(tmps, "Aborted") ) cond->attr_id.state = EDG_WLL_JOB_ABORTED; - else if ( !strcasecmp(tmps, "Cancelled") ) cond->attr_id.state = EDG_WLL_JOB_CANCELLED; - else if ( !strcasecmp(tmps, "Cleared") ) cond->attr_id.state = EDG_WLL_JOB_CLEARED; - else - { - fprintf(stderr,"%s: invalid status value (%s)\n", myname, tmps); - return 0; - } - break; - - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - cond->value.t.tv_sec = StrToTime(tmps); - if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) - { - if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; - if ( tmps[0] == '\0' ) - { - fprintf(stderr,"%s: second interval boundary not set\n", myname); - return NULL; - } - cond->value2.t.tv_sec = StrToTime(tmps); - } - break; - - default: - break; - } - - while ( isblank(*s) || (*s == ';') ) s++; /* skip whitespaces */ - - return s; -} - -static char *get_event_condition(char *src, edg_wll_QueryRec *cond) -{ - char *s; - - - s = get_attr_name(src, tmps, 500); - - if ( tmps[0] == '\0' ) return NULL; - - if ( !strcmp(tmps, "time") ) cond->attr = EDG_WLL_QUERY_ATTR_TIME; - else if ( !strcmp(tmps, "state_enter_time") ) cond->attr = EDG_WLL_QUERY_ATTR_STATEENTERTIME; - else if ( !strcmp(tmps, "last_update_time") ) cond->attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME; - else if ( !strcmp(tmps, "jdl_attr") ) cond->attr = EDG_WLL_QUERY_ATTR_JDL_ATTR; - else if ( !strcmp(tmps, "level") ) cond->attr = EDG_WLL_QUERY_ATTR_LEVEL; - else if ( !strcmp(tmps, "host") ) cond->attr = EDG_WLL_QUERY_ATTR_HOST; - else if ( !strcmp(tmps, "source") ) cond->attr = EDG_WLL_QUERY_ATTR_SOURCE; - else if ( !strcmp(tmps, "instance") ) cond->attr = EDG_WLL_QUERY_ATTR_INSTANCE; - else if ( !strcmp(tmps, "event_type") ) cond->attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE; - else - { - cond->attr = EDG_WLL_QUERY_ATTR_USERTAG; - cond->attr_id.tag = strdup(tmps); - } - - if ( !(s = get_op(s, &(cond->op))) ) return NULL; - - if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; - - switch ( cond->attr ) - { - case EDG_WLL_QUERY_ATTR_USERTAG: - case EDG_WLL_QUERY_ATTR_HOST: - case EDG_WLL_QUERY_ATTR_INSTANCE: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - if ( !(cond->value.c = strdup(tmps)) ) - return 0; - break; - - case EDG_WLL_QUERY_ATTR_SOURCE: - if ( !strcasecmp(tmps, "UserInterface") ) cond->value.i = EDG_WLL_SOURCE_USER_INTERFACE; - else if ( !strcasecmp(tmps, "NetworkServer") ) cond->value.i = EDG_WLL_SOURCE_NETWORK_SERVER; - else if ( !strcasecmp(tmps, "WorkloadManager") ) cond->value.i = EDG_WLL_SOURCE_WORKLOAD_MANAGER; - else if ( !strcasecmp(tmps, "BigHelper") ) cond->value.i = EDG_WLL_SOURCE_BIG_HELPER; - else if ( !strcasecmp(tmps, "JobController") ) cond->value.i = EDG_WLL_SOURCE_JOB_SUBMISSION; - else if ( !strcasecmp(tmps, "LogMonitor") ) cond->value.i = EDG_WLL_SOURCE_LOG_MONITOR; - else if ( !strcasecmp(tmps, "LRMS") ) cond->value.i = EDG_WLL_SOURCE_LRMS; - else if ( !strcasecmp(tmps, "Application") ) cond->value.i = EDG_WLL_SOURCE_APPLICATION; - else - { - fprintf(stderr,"%s: invalid source value (%s)\n", myname, tmps); - return NULL; - } - break; - - case EDG_WLL_QUERY_ATTR_EVENT_TYPE: - case EDG_WLL_QUERY_ATTR_LEVEL: - cond->value.i = atoi(tmps); - if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) - { - if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; - if ( tmps[0] == '\0' ) - { - fprintf(stderr,"%s: second interval boundary not set\n", myname); - return NULL; - } - cond->value2.i = atoi(tmps); - } - break; - - case EDG_WLL_QUERY_ATTR_TIME: - cond->value.t.tv_sec = StrToTime(tmps); - if ( cond->op == EDG_WLL_QUERY_OP_WITHIN ) - { - if ( !(s = get_attr_value(s, tmps, 500)) ) return NULL; - if ( tmps[0] == '\0' ) - { - fprintf(stderr,"%s: second interval boundary not set\n", myname); - return NULL; - } - cond->value2.t.tv_sec = StrToTime(tmps); - } - break; - - default: - break; - } - - while ( isblank(*s) || (*s == ';') ) s++; /* skip whitespaces */ - - return s; -} - -static int cond_parse(edg_wll_QueryRec ***pcond, int jobs) -{ - edg_wll_QueryRec **cond = NULL; - int n, - icond, - ret; - char *s; - - - - n = 0; - if ( !(cond = malloc(sizeof(*cond))) ) - { - perror("cond_parse()"); - exit(ENOMEM); - } - - while ( 1 ) - { - if ( !fgets(buffer, BUFF_LEN, fin) ) - { - if ( !feof(fin) ) - { - fprintf(stderr, "parse_query_cond(): file reading error\n"); - exit(EINVAL); - } - - ret = PQRV_EOF; - goto cleanup; - } - - if ( buffer[0] == '\n' ) - { - ret = PQRV_EMPTY_LINE; - goto cleanup; - } - - if ( !(cond[n] = (edg_wll_QueryRec *) malloc(sizeof(edg_wll_QueryRec))) ) - { - perror("cond_parse()"); - exit(ENOMEM); - } - s = buffer; - icond = 0; - while ( 1 ) - { - if ( jobs ) - s = get_job_condition(s, &(cond[n][icond])); - else - s = get_event_condition(s, &(cond[n][icond])); - - if ( !s ) - { - free(cond[n]); - cond[n] = NULL; - ret = PQRV_ERR; - goto cleanup; - } - icond++; - if ( !(cond[n] = realloc(cond[n], (icond+1)*sizeof(edg_wll_QueryRec))) ) - { - perror("cond_parse()"); - exit(ENOMEM); - } - cond[n][icond].attr = EDG_WLL_QUERY_ATTR_UNDEF; - if ( (*s == '\n') || (*s == '\0') ) - break; - } - - n++; - if ( !(cond = realloc(cond, (n+1)*sizeof(*cond))) ) - { - perror("cond_parse()"); - exit(ENOMEM); - } - cond[n] = NULL; - } - -cleanup: - if ( !n ) - { - free(cond); - *pcond = NULL; - } - else - *pcond = cond; - - return ret; -} - -static void printconds(edg_wll_QueryRec **cond) -{ - int i, j; - int any = 0; - char *s; - - - if ( !cond ) - { - printf("empty\n"); - return ; - } - - for ( i = 0; cond[i]; i++ ) - { - if ( cond[i][0].attr ) - { - any = 1; - if ( i ) - printf(" AND ("); - else - printf("("); - } - for ( j = 0; cond[i][j].attr; j++ ) - { - if ( j ) - printf(" OR "); - switch ( cond[i][j].attr ) - { - case EDG_WLL_QUERY_ATTR_JOBID: printf("jobid"); break; - case EDG_WLL_QUERY_ATTR_OWNER: printf("owner"); break; - case EDG_WLL_QUERY_ATTR_STATUS: printf("status"); break; - case EDG_WLL_QUERY_ATTR_LOCATION: printf("location"); break; - case EDG_WLL_QUERY_ATTR_DESTINATION: printf("destination"); break; - case EDG_WLL_QUERY_ATTR_DONECODE: printf("done_code"); break; - case EDG_WLL_QUERY_ATTR_EXITCODE: printf("exit_code"); break; - case EDG_WLL_QUERY_ATTR_PARENT: printf("parent_job"); break; - case EDG_WLL_QUERY_ATTR_RESUBMITTED: printf("resubmitted"); break; - case EDG_WLL_QUERY_ATTR_USERTAG: printf("%s",cond[i][j].attr_id.tag); break; - case EDG_WLL_QUERY_ATTR_TIME: printf("time"); break; - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: printf("state_enter_time"); break; - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: printf("last_update_time"); break; - case EDG_WLL_QUERY_ATTR_JDL_ATTR: printf("jdl_attr"); break; - case EDG_WLL_QUERY_ATTR_LEVEL: printf("level"); break; - case EDG_WLL_QUERY_ATTR_HOST: printf("host"); break; - case EDG_WLL_QUERY_ATTR_SOURCE: printf("source"); break; - case EDG_WLL_QUERY_ATTR_INSTANCE: printf("instance"); break; - case EDG_WLL_QUERY_ATTR_EVENT_TYPE: printf("ev_type"); break; - default: break; - } - switch ( cond[i][j].op ) - { - case EDG_WLL_QUERY_OP_EQUAL: printf("="); break; - case EDG_WLL_QUERY_OP_UNEQUAL: printf("<>"); break; - case EDG_WLL_QUERY_OP_LESS: printf("<"); break; - case EDG_WLL_QUERY_OP_GREATER: printf(">"); break; - case EDG_WLL_QUERY_OP_WITHIN: printf("@"); break; - } - switch ( cond[i][j].attr ) - { - case EDG_WLL_QUERY_ATTR_JOBID: - case EDG_WLL_QUERY_ATTR_PARENT: - s = edg_wlc_JobIdUnparse(cond[i][j].value.j); - printf("%s", s); - 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_HOST: - case EDG_WLL_QUERY_ATTR_INSTANCE: - case EDG_WLL_QUERY_ATTR_USERTAG: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - printf("%s", cond[i][j].value.c); - 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: - case EDG_WLL_QUERY_ATTR_SOURCE: - if ( cond[i][j].op == EDG_WLL_QUERY_OP_WITHIN ) - printf("[%d,%d]", cond[i][j].value.i, cond[i][j].value2.i); - else - printf("%d", cond[i][j].value.i); - break; - case EDG_WLL_QUERY_ATTR_TIME: - if ( cond[i][j].op == EDG_WLL_QUERY_OP_WITHIN ) - { - printf("[%s,", TimeToStr(cond[i][j].value.t.tv_sec)); - printf("%s] & state = %d", TimeToStr(cond[i][j].value2.t.tv_sec), cond[i][j].attr_id.state); - } - else - printf("%s & state = %d", TimeToStr(cond[i][j].value.t.tv_sec), cond[i][j].attr_id.state); - break; - default: - break; - } - } - if ( j ) - printf(")"); - } - if ( any ) printf("\n"); -} - -static void printstat(edg_wll_JobStat stat) -{ - char *s, *j; - - - s = edg_wll_StatToString(stat.state); - printf("STATUS:\t%s\n\n",s); -/* print whole flat structure */ - printf("state : %s\n", s); - printf("jobId : %s\n", j = edg_wlc_JobIdUnparse(stat.jobId)); - printf("owner : %s\n", stat.owner); - printf("jobtype : %d\n", stat.jobtype); - if (stat.jobtype) {; - printf("seed : %s\n", stat.seed); - printf("children_num : %d\n", stat.children_num); -// XXX deal with subjobs (children, children_hist, children_states) - } - printf("condorId : %s\n", stat.condorId); - printf("globusId : %s\n", stat.globusId); - printf("localId : %s\n", stat.localId); - printf("jdl : %s\n", stat.jdl); - printf("matched_jdl : %s\n", stat.matched_jdl); - printf("destination : %s\n", stat.destination); - printf("network server : %s\n", stat.network_server); - printf("condor_jdl : %s\n", stat.condor_jdl); - printf("rsl : %s\n", stat.rsl); - printf("reason : %s\n", stat.reason); - printf("location : %s\n", stat.location); - printf("ce_node : %s\n", stat.ce_node); - printf("subjob_failed : %d\n", stat.subjob_failed); - printf("done_code : %d\n", stat.done_code); - printf("exit_code : %d\n", stat.exit_code); - printf("resubmitted : %d\n", stat.resubmitted); - printf("cancelling : %d\n", stat.cancelling); - printf("cancelReason : %s\n", stat.cancelReason); - printf("cpuTime : %d\n", stat.cpuTime); -// XXX user_tags user_values - printf("stateEnterTime : %ld.%06ld\n", stat.stateEnterTime.tv_sec,stat.stateEnterTime.tv_usec); - printf("lastUpdateTime : %ld.%06ld\n", stat.lastUpdateTime.tv_sec,stat.lastUpdateTime.tv_usec); - printf("expectUpdate : %d\n", stat.expectUpdate); - printf("expectFrom : %s\n", stat.expectFrom); - - free(j); - free(s); -} - -time_t StrToTime(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); -} - -static char tbuf[256]; - -char *TimeToStr(time_t t) -{ - struct tm *tm = gmtime(&t); - - 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 tbuf; -} - -static void dgerr(edg_wll_Context ctx, char *where) -{ - char *errText, - *errDesc; - - - edg_wll_Error(ctx, &errText, &errDesc); - fprintf(stderr, "%s", errText); - if ( where ) - fprintf(stderr, ": %s", where); - if ( errDesc ) - fprintf(stderr, " (%s)\n", errDesc); - else - putc('\n', stderr); - free(errText); - free(errDesc); -} - diff --git a/org.glite.lb.client/examples/query_seq_code.c b/org.glite.lb.client/examples/query_seq_code.c deleted file mode 100644 index 730dd95..0000000 --- a/org.glite.lb.client/examples/query_seq_code.c +++ /dev/null @@ -1,84 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#ifdef BUILDING_LB_CLIENT -#include "consumer.h" -#else -#include "glite/lb/consumer.h" -#endif - - -static struct option opts[] = { - {"help", 0, NULL, 'h'}, - {"sock", 1, NULL, 's'}, - {"jobid", 1, NULL, 'j'}, -}; - -static void usage(char *me) -{ - fprintf(stderr, "usage: %s [option]\n" - "\t-h, --help Shows this screen.\n" - "\t-s, --server LB Proxy socket.\n" - "\t-j, --jobid ID of requested job.\n" - , me); -} - - -int main(int argc, char *argv[]) -{ - edg_wll_Context ctx; - edg_wlc_JobId jobid = NULL; - char *server, *jobid_s, *code; - int opt, err = 0; - - - server = code = jobid_s = NULL; - while ( (opt = getopt_long(argc, argv, "hs:j:c:n:v:", opts, NULL)) != EOF) - switch (opt) { - case 'h': usage(argv[0]); return 0; - case 's': server = strdup(optarg); break; - case 'j': jobid_s = strdup(optarg); break; - case '?': usage(argv[0]); return 1; - } - - if ( !jobid_s ) { fprintf(stderr, "JobId not given\n"); return 1; } - if ( !server ) { fprintf(stderr, "LB proxy socket not given\n"); return 1; } - - if ( (errno = edg_wlc_JobIdParse(jobid_s, &jobid)) ) { perror(jobid_s); return 1; } - - edg_wll_InitContext(&ctx); - - edg_wll_SetParam(ctx, EDG_WLL_PARAM_SOURCE, EDG_WLL_SOURCE_USER_INTERFACE); - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, server); - -/* - if (edg_wll_SetLoggingJob(ctx, jobid, code, EDG_WLL_SEQ_NORMAL)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"SetLoggingJob(%s,%s): %s (%s)\n",jobid_s,code,et,ed); - exit(1); - } -*/ - if ( (err = edg_wll_QuerySequenceCodeProxy(ctx, jobid, &code)) ) { - char *et,*ed; - - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"%s: edg_wll_QuerySequenceCodeProxy(): %s (%s)\n", - argv[0],et,ed); - free(et); free(ed); - } - - if ( code ) { - puts(code); - free(code); - } - - edg_wll_FreeContext(ctx); - - return err; -} diff --git a/org.glite.lb.client/examples/ready.l b/org.glite.lb.client/examples/ready.l deleted file mode 100644 index 536f8a5..0000000 --- a/org.glite.lb.client/examples/ready.l +++ /dev/null @@ -1,18 +0,0 @@ -# macro definition for WAITING state - -:waiting: -# NetworkServer - --s NetworkServer,-e EnQueued, --queue="destination queue", --job="job description in receiver language", --result=OK, --reason="detailed description of transfer" -# -s NetworkServer,-e Transfer,--destination="WorkloadManager",--dest_host="destination hostname",--dest_instance="destination instance",--job="job description in receiver language",--result=OK,--reason="detailed description of transfer",--dest_jobid="destination internal jobid" - -# WorkloadManager - --s WorkloadManager,-e DeQueued, --queue="queue name", --local_jobid="new jobId assigned by the receiving component" --s WorkloadManager,-e HelperCall, --helper_name="name of the called component",--helper_params="parameters of the call", --src_role=CALLING -#-s Helper,-e HelperCall, --helper_name="name of the called component",--helper_params="parameters of the call", --src_role=CALLED -#-s Helper,-e HelperReturn, --helper_name="name of the called component",--retval="returned data", --src_role=CALLED --s WorkloadManager,-e Match,--dest_id="${DESTINATION:-destination CE/queue}" --s WorkloadManager,-e HelperReturn, --helper_name="name of the called component",--retval="returned data", --src_role=CALLING --s WorkloadManager,-e EnQueued, --queue="destination queue", --job="job description in receiver language", --result=OK, --reason="detailed description of transfer" - diff --git a/org.glite.lb.client/examples/ready_dag.l b/org.glite.lb.client/examples/ready_dag.l deleted file mode 100644 index aa7deae..0000000 --- a/org.glite.lb.client/examples/ready_dag.l +++ /dev/null @@ -1,13 +0,0 @@ -# macro definition for WAITING state - -:waiting_dag: -# NetworkServer - --s NetworkServer,-e EnQueued, --queue="destination queue", --job="job description in receiver language", --result=OK, --reason="detailed description of transfer" - -# WorkloadManager - --s WorkloadManager,-e DeQueued, --queue="queue name", --local_jobid="new jobId assigned by the receiving component" - --s WorkloadManager,-e EnQueued, --queue="destination queue", --job="job description in receiver language", --result=OK, --reason="detailed description of transfer" - diff --git a/org.glite.lb.client/examples/ready_subjob.l b/org.glite.lb.client/examples/ready_subjob.l deleted file mode 100644 index 3f40632..0000000 --- a/org.glite.lb.client/examples/ready_subjob.l +++ /dev/null @@ -1,8 +0,0 @@ -# macro definition for WAITING state - -:waiting_subjob: -# WorkloadManager - --s WorkloadManager,-e Match,--dest_id="Id of the destination CE/queue" --s WorkloadManager,-e HelperReturn, --helper_name="name of the called component",--retval="returned data", --src_role=CALLING - diff --git a/org.glite.lb.client/examples/resubmission.l b/org.glite.lb.client/examples/resubmission.l deleted file mode 100644 index b55f972..0000000 --- a/org.glite.lb.client/examples/resubmission.l +++ /dev/null @@ -1,19 +0,0 @@ -# one resubmission cycle - --s LogMonitor,-e EnQueued, --queue="wm_input.fl", --job="job description in receiver language", --result=OK, --reason="detailed description of transfer" - --s WorkloadManager,-e DeQueued, --queue="wm_input.fl", --local_jobid="WM_ID" --s WorkloadManager, -e Resubmission, --result=${RESUB:-WILLRESUB}, --reason="let's try again", --tag=none --s WorkloadManager,-e HelperCall, --helper_name="name of the called component",--helper_params="parameters of the call", --src_role=CALLING --s WorkloadManager,-e Match,--dest_id="${DESTINATION:-destination CE/queue}" --s WorkloadManager,-e HelperReturn, --helper_name="name of the called component",--retval="returned data", --src_role=CALLING --s WorkloadManager,-e EnQueued, --queue="wm_output.fl", --job="job description in receiver language", --result=OK, --reason="detailed description of transfer" - --s JobController,-e DeQueued, --queue="wm_output.fl", --local_jobid="JC_ID" --s JobController,-e Transfer,--destination="LRMS",--dest_host="destination hostname",--dest_instance="destination instance",--job="job description in receiver language",--result=OK,--reason="detailed description of transfer",--dest_jobid="destination internal jobid" - --s LogMonitor,-e Accepted, --from="JobController", --from_host="sending component hostname", --from_instance="sending component instance", --local_jobid="new jobId (Condor, Globus ...)" --s LogMonitor,-e Transfer,--destination="LRMS",--dest_host="destination hostname",--dest_instance="destination instance",--job="job description in receiver language",--result=OK,--reason="detailed description of transfer",--dest_jobid="destination internal jobid" - --s LogMonitor,-e Running,--node="${CE_NODE:-worker node}" - diff --git a/org.glite.lb.client/examples/resubmitted.l b/org.glite.lb.client/examples/resubmitted.l deleted file mode 100644 index df5d055..0000000 --- a/org.glite.lb.client/examples/resubmitted.l +++ /dev/null @@ -1,20 +0,0 @@ -# resubmitted job example - -! DESTINATION=CE1/queue1 -! CE_NODE=worker1 -:running: - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE2/queue2 -! CE_NODE=worker2 -:resubmission_deep: - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE3/queue3 -! CE_NODE=worker3 -:resubmission_deep: - diff --git a/org.glite.lb.client/examples/running.l b/org.glite.lb.client/examples/running.l deleted file mode 100644 index 60dfe6a..0000000 --- a/org.glite.lb.client/examples/running.l +++ /dev/null @@ -1,4 +0,0 @@ -# macro definition for RUNNING state - -:scheduled: --s LogMonitor,-e Running,--node="${CE_NODE:-worker node}" diff --git a/org.glite.lb.client/examples/running_dag.l b/org.glite.lb.client/examples/running_dag.l deleted file mode 100644 index 74e1efa..0000000 --- a/org.glite.lb.client/examples/running_dag.l +++ /dev/null @@ -1,4 +0,0 @@ -# macro definition for RUNNING state - -:scheduled_dag: --s LogMonitor,-e Running,--node"DAGMan running on server" diff --git a/org.glite.lb.client/examples/running_subjob.l b/org.glite.lb.client/examples/running_subjob.l deleted file mode 100644 index 2069f33..0000000 --- a/org.glite.lb.client/examples/running_subjob.l +++ /dev/null @@ -1,4 +0,0 @@ -# macro definition for RUNNING state - -:scheduled_subjob: --s LogMonitor,-e Running,--node"worker node where the executable is run" diff --git a/org.glite.lb.client/examples/scheduled.l b/org.glite.lb.client/examples/scheduled.l deleted file mode 100644 index f269722..0000000 --- a/org.glite.lb.client/examples/scheduled.l +++ /dev/null @@ -1,13 +0,0 @@ -# macro definition for SCHEDULED state - -:ready: -# JobSubmition - --s JobController,-e DeQueued, --queue="queue name", --local_jobid="new jobId assigned by the receiving component" --s JobController,-e Transfer,--destination="LRMS",--dest_host="destination hostname",--dest_instance="destination instance",--job="job description in receiver language",--result=OK,--reason="detailed description of transfer",--dest_jobid="destination internal jobid" - -# LogMonitor - --s LogMonitor,-e Accepted, --from="JobController", --from_host="sending component hostname", --from_instance="sending component instance", --local_jobid="new jobId (Condor, Globus ...)" --s LogMonitor,-e Transfer,--destination="LRMS",--dest_host="destination hostname",--dest_instance="destination instance",--job="job description in receiver language",--result=OK,--reason="detailed description of transfer",--dest_jobid="destination internal jobid" - diff --git a/org.glite.lb.client/examples/scheduled_dag.l b/org.glite.lb.client/examples/scheduled_dag.l deleted file mode 100644 index 3d7e10d..0000000 --- a/org.glite.lb.client/examples/scheduled_dag.l +++ /dev/null @@ -1,12 +0,0 @@ -# macro definition for SCHEDULED state - -:ready_dag: -# JobSubmition - --s JobController,-e DeQueued, --queue="queue name", --local_jobid="new jobId assigned by the receiving component" --s JobController,-e Transfer,--destination="LogMonitor",--dest_host="destination hostname",--dest_instance="destination instance",--job="job description in receiver language",--result=START,--reason="detailed description of transfer",--dest_jobid="destination internal jobid" - -# LogMonitor - --s LogMonitor,-e Accepted, --from="JobController", --from_host="sending component hostname", --from_instance="sending component instance", --local_jobid="new jobId (Condor, Globus ...)" - diff --git a/org.glite.lb.client/examples/scheduled_subjob.l b/org.glite.lb.client/examples/scheduled_subjob.l deleted file mode 100644 index 76eeec5..0000000 --- a/org.glite.lb.client/examples/scheduled_subjob.l +++ /dev/null @@ -1,7 +0,0 @@ -# macro definition for SCHEDULED state - -:ready_subjob: -# LogMonitor - --s LogMonitor,-e Transfer,--destination="LRMS",--dest_host="destination hostname",--dest_instance="destination instance",--job="job description in receiver language",--result=OK,--reason="detailed description of transfer",--dest_jobid="destination internal jobid" - diff --git a/org.glite.lb.client/examples/shallow_and_full_resub.l b/org.glite.lb.client/examples/shallow_and_full_resub.l deleted file mode 100644 index c171348..0000000 --- a/org.glite.lb.client/examples/shallow_and_full_resub.l +++ /dev/null @@ -1,40 +0,0 @@ -# shallow resubmission job example - -! DESTINATION=CE1/queue1 -! CE_NODE=worker1 -:running: - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE2/queue2 -! CE_NODE=worker2 -! RESUB=SHALLOW -:resubmission: - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE3/queue3 -! CE_NODE=worker3 -! RESUB=SHALLOW -:resubmission: - --s LogMonitor, -e ReallyRunning, --wn_seq="$EDG_WL_SEQUENCE" - -# deep resubmission - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE2/queue2 -! CE_NODE=worker2 -! RESUB=DEEP -:resubmission: - -# payload_running=false -# destination=CE2/queue2 -# ce_node=worker2 -# possible_destinations=CE2/queue2 -# possible_ce_nodes=worker2 - diff --git a/org.glite.lb.client/examples/shallow_resub_complex.l b/org.glite.lb.client/examples/shallow_resub_complex.l deleted file mode 100644 index ba1201b..0000000 --- a/org.glite.lb.client/examples/shallow_resub_complex.l +++ /dev/null @@ -1,48 +0,0 @@ -# shallow resubmission job example - -! DESTINATION=CE1/queue1 -! CE_NODE=worker1 -! RESUB=SHALLOW -:running: - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE2/queue2 -! CE_NODE=worker2 -! RESUB=SHALLOW -:resubmission: -! BRANCH_SEQUENCE="$EDG_WL_SEQUENCE" - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE3/queue3 -! CE_NODE=worker3 -! RESUB=SHALLOW -:resubmission: - --s LogMonitor, -e ReallyRunning, --wn_seq="$BRANCH_SEQUENCE" - -# payload_running=true -# destination=CE2/queue2 -# ce_node=worker2 -# possible_destinations=CE1/queue1 CE2/queue2 CE3/queue3 -# possible_ce_nodes=worker1 worker2 worker3 - -# deep resubmission - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE4/queue4 -! CE_NODE=worker4 -! RESUB=DEEP -:resubmission: - -# payload_running=false -# destination=CE4/queue4 -# ce_node=worker4 -# possible_destinations=CE4/queue4 -# possible_ce_nodes=worker4 - diff --git a/org.glite.lb.client/examples/shallow_resub_simple.l b/org.glite.lb.client/examples/shallow_resub_simple.l deleted file mode 100644 index 134368f..0000000 --- a/org.glite.lb.client/examples/shallow_resub_simple.l +++ /dev/null @@ -1,30 +0,0 @@ -# shallow resubmission job example - -! DESTINATION=CE1/queue1 -! CE_NODE=worker1 -:running: - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE2/queue2 -! CE_NODE=worker2 -! RESUB=SHALLOW -:resubmission: - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE3/queue3 -! CE_NODE=worker3 -! RESUB=SHALLOW -:resubmission: - --s LogMonitor, -e ReallyRunning, --wn_seq="$EDG_WL_SEQUENCE" - -# payload_running=true -# destination=CE3/queue3 -# ce_node=worker3 -# possible_destinations=CE1/queue1 CE2/queue2 CE3/queue3 -# possible_ce_nodes=worker1 worker2 worker3 - diff --git a/org.glite.lb.client/examples/shallow_resub_simple2.l b/org.glite.lb.client/examples/shallow_resub_simple2.l deleted file mode 100644 index 1cb74c2..0000000 --- a/org.glite.lb.client/examples/shallow_resub_simple2.l +++ /dev/null @@ -1,31 +0,0 @@ -# shallow resubmission job example - -! DESTINATION=CE1/queue1 -! CE_NODE=worker1 -:running: - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE2/queue2 -! CE_NODE=worker2 -! RESUB=SHALLOW -:resubmission: -! BRANCH_SEQUENCE="$EDG_WL_SEQUENCE" - --s LogMonitor, -e Done, --status_code=FAILED, --reason="reason for the change", --exit_code=141 --s LogMonitor, -e Resubmission, --result=WILLRESUB, --reason="let's try again", --tag=none - -! DESTINATION=CE3/queue3 -! CE_NODE=worker3 -! RESUB=SHALLOW -:resubmission: - --s LogMonitor, -e ReallyRunning, --wn_seq="$BRANCH_SEQUENCE" - -# payload_running=true -# destination=CE2/queue2 -# ce_node=worker2 -# possible_destinations=CE1/queue1 CE2/queue2 CE3/queue3 -# possible_ce_nodes=worker1 worker2 worker3 - diff --git a/org.glite.lb.client/examples/stats.c b/org.glite.lb.client/examples/stats.c deleted file mode 100644 index 626efde..0000000 --- a/org.glite.lb.client/examples/stats.c +++ /dev/null @@ -1,87 +0,0 @@ -#include -#include -#include -#include - -#ifdef BUILDING_LB_CLIENT -#include "statistics.h" -#else -#include "glite/lb/statistics.h" -#endif - - -int main(int argc,char **argv) -{ - edg_wll_Context ctx; - edg_wll_QueryRec group[2]; - time_t now,from,to; - char *cfrom,*cto; - int from_res,to_res; - float val; - - - edg_wll_InitContext(&ctx); - - if (argc < 3) { - fprintf(stderr,"usage: %s CE major [minor]\n",argv[0]); - return 1; - } - -/* the only supported grouping for now */ - group[0].attr = EDG_WLL_QUERY_ATTR_DESTINATION; - group[0].op = EDG_WLL_QUERY_OP_EQUAL; - group[0].value.c = argv[1]; - group[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - - - time(&now); - to = now; - from = now - 60; - -/* not implemented yet - if (edg_wll_StateDuration(ctx,group,EDG_WLL_JOB_SCHEDULED,0, - &from,&to,&val,&from_res,&to_res)) - { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_StateDuration(): %s, %s\n",et,ed); - return 1; - } - - cfrom = strdup(ctime(&from)); - cto = strdup(ctime(&to)); - cfrom[strlen(cfrom)-1] = 0; - cto[strlen(cto)-1] = 0; - - printf("Average queue traversal time at \"%s\": %f s\n" - " Measuered from %s to %s\n" - " With resolution from %d to %d s\n", - argv[1],val,cfrom,cto,from_res,to_res); - -*/ - - to = now; - from = now - 60; - - if (edg_wll_StateRate(ctx,group,atoi(argv[2]),argc >=4 ? atoi(argv[3]) : 0, - &from,&to,&val,&from_res,&to_res)) - { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_StateRate(): %s, %s\n",et,ed); - return 1; - } - - cfrom = strdup(ctime(&from)); - cto = strdup(ctime(&to)); - cfrom[strlen(cfrom)-1] = 0; - cto[strlen(cto)-1] = 0; - - printf("Average failure rate at \"%s\": %f jobs/s\n" - " Measuered from %s to %s\n" - " With resolution from %d to %d s\n", - argv[1],val,cfrom,cto,from_res,to_res); - - return 0; -} - diff --git a/org.glite.lb.client/examples/stress_context.c b/org.glite.lb.client/examples/stress_context.c deleted file mode 100644 index dfd54a6..0000000 --- a/org.glite.lb.client/examples/stress_context.c +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#ifdef BUILDING_LB_CLIENT -#include "producer.h" -#else -#include "glite/lb/producer.h" -#endif -#include "glite/lb/events.h" - -char *outfile = "context_errors"; -edg_wlc_JobId job; - -static int stop; - -struct { - int err; - char *text,*desc; -} *errors; - -int nerrors; - -static void killslaves(int sig) -{ - kill(0,SIGTERM); - exit(0); -} - -static void terminate(int sig) -{ - stop = sig; -} - -static void slave(int num) -{ - int good = 0,i; - char fname[PATH_MAX]; - FILE *errf; - edg_wll_Context ctx; - - signal(SIGINT,terminate); - signal(SIGTERM,terminate); - signal(SIGHUP,terminate); - - - while (!stop) { - edg_wll_InitContext(&ctx); - edg_wll_SetParam(ctx, EDG_WLL_PARAM_SOURCE, EDG_WLL_SOURCE_WORKLOAD_MANAGER); - - if (edg_wll_SetLoggingJobProxy(ctx,job,NULL,"/I/am/the/user",EDG_WLL_SEQ_NORMAL) && !stop) { - errors = realloc(errors,(nerrors+1) * sizeof(*errors)); - errors[nerrors].err = edg_wll_Error(ctx,&errors[nerrors].text,&errors[nerrors].desc); - nerrors++; - } - else good++; - - edg_wll_FreeContext(ctx); - } - - sprintf(fname,"%s_%03d",outfile,num); - errf = fopen(fname,"w"); - if (!errf) { perror(fname); exit(1); } - - for (i=0; i -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#ifdef BUILDING_LB_CLIENT -#include "producer.h" -#else -#include "glite/lb/producer.h" -#endif -#include "glite/lb/events.h" - -#define MAXMSGSIZE 10240 - -extern char *optarg; -extern int opterr,optind; - -extern int edg_wll_DoLogEvent(edg_wll_Context context, edg_wll_LogLine logline); -extern int edg_wll_DoLogEventProxy(edg_wll_Context context, edg_wll_LogLine logline); -extern int edg_wll_DoLogEventDirect(edg_wll_Context context, edg_wll_LogLine logline); - -static const char *me; - -static void usage() -{ - fprintf(stderr,"usage: %s -m bkserver [-x|-y] [-N numjobs] [-n subjobs (each)] -f file_name \n", me); - fprintf(stderr," - event file not containing DG.JOBID and without -x or -z not containing DG.USER\n"); -} - -int main(int argc, char *argv[]) -{ - char *job = NULL,*server = NULL,*seq = NULL,*filename = NULL; - char buf[MAXMSGSIZE]; - int lbproxy = 0, num_subjobs = 0, lbdirect = 0; - int done = 0, njobs = 1,i,j; - edg_wll_Context ctx; - edg_wlc_JobId jobid,*subjobs; - FILE *f; - - edg_wll_InitContext(&ctx); - - opterr = 0; - - me = strdup(argv[0]); - - do { - switch (getopt(argc,argv,"m:xyN:n:f:")) { - case 'm': server = strdup(optarg); break; - case 'x': lbproxy = 1; break; - case 'y': lbdirect = 1; break; - case 'N': njobs = atoi(optarg); break; - case 'n': num_subjobs = atoi(optarg); break; - case 'f': filename = (char *) strdup(optarg); break; - case '?': usage(); exit(EINVAL); - case -1: done = 1; break; - } - } while (!done); - - if (lbproxy && lbdirect) { - fprintf(stderr,"%s: only one of -x or -y options may be specified \n",me); - usage(); - exit(1); - } - - if (!server) { - fprintf(stderr,"%s: -m required\n",me); - usage(); - exit(1); - } - - if ((njobs <= 0) || (num_subjobs < 0)) { - fprintf(stderr,"%s: wrong number of jobs\n",me); - usage(); - exit(1); - } - - if (!filename) { - fprintf(stderr,"%s: -f required\n",me); - usage(); - exit(1); - } - - if ( (f = fopen(filename,"r")) == NULL) { - perror(filename); - exit(1); - } - -/* MAIN LOOP */ -for (i = 0; i -#include - -#include "notification.h" - -int main(int argc,char **argv) -{ - edg_wll_Context ctx; - edg_wll_QueryRec chj[2], chs[2], *ch2[3] = { chj, chs, NULL }; - char *et,*ed; - edg_wll_NotifId id; - edg_wll_JobStat stat; - time_t valid = 0; - - edg_wll_InitContext(&ctx); - - memset(&chj,0,sizeof chj); - chj[0].op = EDG_WLL_QUERY_OP_CHANGED; - chj[0].attr = EDG_WLL_QUERY_ATTR_JDL_ATTR; - chj[0].attr_id.tag = NULL; - - memset(&chs,0,sizeof chs); - chs[0].op = EDG_WLL_QUERY_OP_EQUAL; - chs[0].attr = EDG_WLL_QUERY_ATTR_STATUS; - chs[0].value.i = EDG_WLL_JOB_WAITING; - - if (edg_wll_NotifNew(ctx,ch2,EDG_WLL_STAT_CLASSADS,-1,NULL,&id,&valid)) { - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_NotifNew(): %s %s\n",et,ed); - return 1; - } - - printf("notif %s\n",edg_wll_NotifIdUnparse(id)); - - for (;;) { - struct timeval tv = {120,0}; - if (edg_wll_NotifReceive(ctx,-1,&tv,&stat,&id)) { - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_NotifReceive(): %s %s\n",et,ed); - return 1; - } - - printf("JDL: %s\n",stat.jdl); - } -} diff --git a/org.glite.lb.client/examples/test_notif_rotate.pl b/org.glite.lb.client/examples/test_notif_rotate.pl deleted file mode 100755 index 8514c7c..0000000 --- a/org.glite.lb.client/examples/test_notif_rotate.pl +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/perl - -use Socket; -use Fcntl; - -$notif = $ENV{NOTIFY_CMD} ? $ENV{NOTIFY_CMD} : './notify'; - -$notifid = shift or die "usage: $0 notifid\n"; - -socket SOCK,PF_INET,SOCK_STREAM,getprotobyname('tcp') || die "socket: $!\n"; -bind SOCK,sockaddr_in(0,INADDR_ANY) || die "bind: $!\n"; -listen SOCK,10; - -$fd = fileno SOCK; - -$flags = fcntl SOCK,F_GETFD,0; -fcntl SOCK,F_SETFD,$flags & ~FD_CLOEXEC; - - -$cmd = "$notif bind -s $fd $notifid"; - -system $cmd; - -die "failed $cmd\n" if $? == 1; -$ret = $? >> 8; -die "$cmd: $ret\n" if $ret; - -print "Bind ok. Press Enter ... "; <>; - -$fdin = ''; -vec($fdin,$fd,1) = 1; - -while (1) { - select($fdin,undef,undef,undef); - print "got connection\n"; - - $cmd = "$notif receive -s $fd -i 3"; - system $cmd; - die "failed $cmd\n" if $? == 1; - $ret = $? >> 8; - die "$cmd: $ret\n" if $ret; - -# print "Receive OK. Press Enter ..."; <>; -} - - diff --git a/org.glite.lb.client/examples/ulmfields.pl b/org.glite.lb.client/examples/ulmfields.pl deleted file mode 100644 index 05c4e6e..0000000 --- a/org.glite.lb.client/examples/ulmfields.pl +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/perl -n - -BEGIN{ - @pf = split /,/,shift; -}; - -next if /^\s*$/; - -@F = split / /; - -undef $prev; -undef %f; - -for $f (@F) { - if ($f =~ /^[.A-Z_]+="/) { -# print $prev,"\n" if $prev; - @P = split /=/,$prev,2; - $f{$P[0]} = $P[1]; - $prev = $f; - } - else { $prev .= $f; } -} - -# print $prev,"\n"; -@P = split /=/,$prev,2; -$f{$P[0]} = $P[1]; - -for $f (@pf) { - print "$f=$f{$f}\n" if $f{$f}; -} -print "\n"; diff --git a/org.glite.lb.client/examples/user-jobs.pl b/org.glite.lb.client/examples/user-jobs.pl deleted file mode 100755 index 658396d..0000000 --- a/org.glite.lb.client/examples/user-jobs.pl +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/perl - -use SOAP::Lite; -use Data::Dumper; - -$ENV{HTTPS_CA_DIR}='/etc/grid-security/certificates'; - -# necessary to get compatible SSL handshake with the Globus server implementation -$ENV{HTTPS_VERSION}='3'; - -# a trick to make proxy credentials work -$proxy = $ENV{X509_USER_PROXY} ? $ENV{X509_USER_PROXY} : "/tmp/x509up_u$<"; -$ENV{HTTPS_CERT_FILE}= $ENV{HTTPS_KEY_FILE} = $ENV{HTTPS_CA_FILE} = $proxy; - -$server = shift or die "usage: $0 server\n"; - -# initialize the server handle, wsdl, and namespace -$c = SOAP::Lite - -> proxy($server) - -> uri('http://glite.org/wsdl/services/lb'); - -service $c 'http://egee.cesnet.cz/cms/export/sites/egee/en/WSDL/HEAD/LB.wsdl'; -ns $c 'http://glite.org/wsdl/elements/lb'; - -# setup trivial fault handler -on_fault $c sub { print Dumper($_[1]->fault); $fault = 1; }; - -# call the actual WS operation -$resp = UserJobs $c; - -$body = $resp->body(); - -# too much rubbish -# print Dumper $body; - -# follow the response structure and pick just jobids and states to print -unless ($fault) { - $njobs = $#{$body->{UserJobsResponse}->{jobs}}; - for ($i = 0; $i <= $njobs; $i++) { - print "$body->{UserJobsResponse}->{jobs}->[$i]\t", - $body->{UserJobsResponse}->{states} ? $body->{UserJobsResponse}->{states}->[$i]->{state} : '', - "\n"; - } -} - diff --git a/org.glite.lb.client/examples/user_jobs.c b/org.glite.lb.client/examples/user_jobs.c deleted file mode 100644 index 1d1dbbb..0000000 --- a/org.glite.lb.client/examples/user_jobs.c +++ /dev/null @@ -1,110 +0,0 @@ -#ident "$Header$" - -#include -#include -#include - -#include "glite/lb/context.h" -#include "glite/lb/xml_conversions.h" -#ifdef BUILDING_LB_CLIENT -#include "consumer.h" -#else -#include "glite/lb/consumer.h" -#endif - -int use_proxy = 0; - -int (*user_jobs)(edg_wll_Context, edg_wlc_JobId **, edg_wll_JobStat **); - - -void -usage(char *me) -{ - fprintf(stderr,"usage: %s [-h] [-x] [userid]\n", me); -} - -int main(int argc,char **argv) -{ - edg_wll_Context ctx; - char *errt,*errd; - edg_wlc_JobId *jobs = NULL; - edg_wll_JobStat *states = NULL; - int i,j; - char *owner = NULL; - - user_jobs = edg_wll_UserJobs; - for ( i = 1; i < argc; i++ ) { - if ( !strcmp(argv[i], "-h") || !strcmp(argv[i], "--help") ) { - usage(argv[0]); - exit(0); - } else if ( !strcmp(argv[i], "-x") ) { - user_jobs = edg_wll_UserJobsProxy; - continue; - } - - owner = strdup(argv[i]); - break; - } - - edg_wll_InitContext(&ctx); - if ( user_jobs == edg_wll_UserJobsProxy && owner ) - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_USER, owner); - - if (user_jobs(ctx,&jobs,&states)) goto err; - for (i=0; states[i].state != EDG_WLL_JOB_UNDEF; i++) { - char *id = edg_wlc_JobIdUnparse(states[i].jobId), - *st = edg_wll_StatToString(states[i].state); - - if (!states[i].parent_job) { - if (states[i].jobtype == EDG_WLL_STAT_SIMPLE) { - printf(" %s .... %s %s\n", id, st, (states[i].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[i].done_code) : "" ); - } - else if ((states[i].jobtype == EDG_WLL_STAT_DAG) || - (states[i].jobtype == EDG_WLL_STAT_COLLECTION)) { - printf("%s %s .... %s %s\n", (states[i].jobtype==EDG_WLL_STAT_DAG)?"DAG ":"COLL",id, st, (states[i].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[i].done_code) : ""); - for (j=0; states[j].state != EDG_WLL_JOB_UNDEF; j++) { - if (states[j].parent_job) { - char *par_id = edg_wlc_JobIdUnparse(states[j].parent_job); - - if (!strcmp(id,par_id)) { - char *sub_id = edg_wlc_JobIdUnparse(states[j].jobId), - *sub_st = edg_wll_StatToString(states[j].state); - - printf(" `- %s .... %s %s\n", sub_id, sub_st, (states[j].state==EDG_WLL_JOB_DONE) ? edg_wll_done_codeToString(states[j].done_code) : ""); - free(sub_id); - free(sub_st); - } - free(par_id); - } - } - } - } - - free(id); - free(st); - } - - printf("\nFound %d jobs\n",i); - -err: - free(owner); - if (jobs) { - for (i=0; jobs[i]; i++) edg_wlc_JobIdFree(jobs[i]); - free(jobs); - } - - if (states) { - for (i=0; states[i].state; i++) edg_wll_FreeStatus(&states[i]); - free(states); - } - - if (edg_wll_Error(ctx,&errt,&errd)) { - fprintf(stderr,"%s: %s (%s)\n",argv[0],errt,errd); - edg_wll_FreeContext(ctx); - return 1; - } - - edg_wll_FreeContext(ctx); - return 0; -} - diff --git a/org.glite.lb.client/examples/user_jobs_threaded.c b/org.glite.lb.client/examples/user_jobs_threaded.c deleted file mode 100644 index 904bfbb..0000000 --- a/org.glite.lb.client/examples/user_jobs_threaded.c +++ /dev/null @@ -1,225 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include - -#include - -#include "glite/lb/context.h" -#include "glite/lb/xml_conversions.h" -#include "glite/security/glite_gss.h" -#include "consumer.h" - -int use_proxy = 0; - -int (*user_jobs)(edg_wll_Context, edg_wlc_JobId **, edg_wll_JobStat **); - - - -static const char *get_opt_string = "hxj:t:p:r:s:w:"; - -static struct option opts[] = { - {"help", 0, NULL, 'h'}, - {"proxy", 0, NULL, 'x'}, - {"owner", 1, NULL, 'o'}, - {"num-threads", 1, NULL, 't'}, - {"port_range", 1, NULL, 'p'}, - {"repeat", 1, NULL, 'r'}, - {"rand-start", 1, NULL, 's'}, -// {"rand-work", 1, NULL, 'w'}, - {NULL, 0, NULL, 0} -}; - - - -static void usage(char *me) -{ - fprintf(stderr,"usage: %s [option]\n" - "\t-h, --help\t show this help\n" - "\t-x, --proxy\t contact proxy (not implemented yet)\n" - "\t-o, --owner DN\t show jobs of user with this DN\n" - "\t-t, --num-threads N\t number for threads to create\n" - "\t-p, --port-range N\t connect to server:port, server:port+10, \n" - "\t\t\t ... server:port+N*10 bkservers\n" - "\t-r, --repeat N\t repeat query in each slave N-times \n" - "\t-s, --rand-start N\t start threads in random interval <0,N> sec\n" -// "\t-w, --rand-work N\t simulate random server respose time <0,N> sec\n" - "\n" - ,me); -} - - -typedef struct { - char *owner; - int proxy; - int rand_start; - int port_range; - int repeat; - char *argv_0;} thread_code_args; - -void *thread_code(thread_code_args *arguments) { - - edg_wll_Context ctx; - char *errt,*errd; - edg_wlc_JobId *jobs = NULL; - edg_wll_JobStat *states = NULL; - int i,j,k,port; - long sl; - - - sl = (unsigned long) ((double) random()/ RAND_MAX * arguments->rand_start * 1000000); - printf("Thread [%lu] - sleeping for %ld us\n",(unsigned long)pthread_self(),sl); - usleep( sl ); - - user_jobs = edg_wll_UserJobs; - - if (arguments->proxy) { - user_jobs = edg_wll_UserJobsProxy; - } - - edg_wll_InitContext(&ctx); - if ( user_jobs == edg_wll_UserJobsProxy && arguments->owner ) - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_USER, arguments->owner); - - edg_wll_GetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, &port); - // pthread_self tend to return even number, so /7 makes some odd numbers... - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, - port + ((long) pthread_self()/7 % arguments->port_range)*10 ); - - for (k=0; krepeat; k++) { - if (user_jobs(ctx,&jobs,&states)) goto err; - for (i=0; states[i].state != EDG_WLL_JOB_UNDEF; i++) { - char *id = edg_wlc_JobIdUnparse(states[i].jobId), - *st = edg_wll_StatToString(states[i].state); - - if (!states[i].parent_job) { - if (states[i].jobtype == EDG_WLL_STAT_SIMPLE) { - printf(" %s .... %s %s\n", id, st, - (states[i].state==EDG_WLL_JOB_DONE) ? - edg_wll_done_codeToString(states[i].done_code) : "" ); - } - else if (states[i].jobtype == EDG_WLL_STAT_DAG) { - printf("DAG %s .... %s %s\n", id, st, - (states[i].state==EDG_WLL_JOB_DONE) ? - edg_wll_done_codeToString(states[i].done_code) : ""); - for (j=0; states[j].state != EDG_WLL_JOB_UNDEF; j++) { - if (states[j].parent_job) { - char *par_id = edg_wlc_JobIdUnparse(states[j].parent_job); - - if (!strcmp(id,par_id)) { - char *sub_id = edg_wlc_JobIdUnparse(states[j].jobId), - *sub_st = edg_wll_StatToString(states[j].state); - - printf(" `- %s .... %s %s\n", sub_id, sub_st, - (states[j].state==EDG_WLL_JOB_DONE) ? - edg_wll_done_codeToString(states[j].done_code) : ""); - free(sub_id); - free(sub_st); - } - free(par_id); - } - } - } - } - - free(id); - free(st); - } - - printf("\nFound %d jobs\n",i); - } -err: - free(arguments->owner); - if (jobs) { - for (i=0; jobs[i]; i++) edg_wlc_JobIdFree(jobs[i]); - free(jobs); - } - - if (states) { - for (i=0; states[i].state; i++) edg_wll_FreeStatus(&states[i]); - free(states); - } - - if (edg_wll_Error(ctx,&errt,&errd)) { - fprintf(stderr,"%s: %s (%s)\n",arguments->argv_0,errt,errd); - edg_wll_FreeContext(ctx); - pthread_exit(NULL); - } - - edg_wll_FreeContext(ctx); - -// printf("Thread %d exitting\n",(int)pthread_self()); - - pthread_exit(NULL); - -} - -int main(int argc,char **argv) -{ - thread_code_args arguments = { NULL, 0, 0, 1, 1,NULL }; - int i,rc,status,opt; - int thr_num = 10; // default - - - while ((opt = getopt_long(argc,argv,get_opt_string,opts,NULL)) != EOF) switch (opt) { - case 'x': arguments.proxy = 1; break; - case 'o': arguments.owner = optarg; break; - case 't': thr_num = atoi(optarg); break; - case 'p': arguments.port_range = atoi(optarg); break; - case 'r': arguments.repeat = atoi(optarg); break; - case 's': arguments.rand_start = atoi(optarg); break; - default : usage(argv[0]); exit(0); break; - } - - arguments.argv_0 = argv[0]; - - /* threads && Globus */ - if (edg_wll_gss_initialize()) { - printf("can't initialize GSS\n"); - return 1; - } - - /* Do a thready work */ - { - pthread_t threads[thr_num]; - pthread_attr_t attr; - - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - - for (i=0;i 0) proxyFile = args[0]; - if (args.length > 1) endpoint = args[1]; - - ConsoleAppender ca = new ConsoleAppender(new org.apache.log4j.SimpleLayout()); -// ca.activateOptions(); - log.addAppender(ca); - - log.info("endpoint being used "+ endpoint); - if (proxyFile != null) log.info("proxy location being used " + proxyFile); - - URL url = new URL(endpoint); - int port = url.getPort(); - String protocol = url.getProtocol(); - String path = url.getPath(); - log.info(" port number "+ port + ", protocol ("+ protocol + "), path: " + path); - - System.setProperty("sslProtocol", "SSLv3"); - AxisProperties.setProperty("axis.socketSecureFactory","org.glite.security.trustmanager.axis.AXISSocketFactory"); - // certificate based authentication */ -// System.setProperty("sslCertFile","/home/valtri/.cert/hostcert.pem"); -// System.setProperty("sslKey","/home/valtri/.cert/hostkey.pem"); -// System.setProperty("sslKeyPasswd",""); - - // proxy based authentication - if (proxyFile != null) System.setProperty("gridProxyFile", proxyFile); - - try { - LoggingAndBookkeeping_ServiceLocator loc = new LoggingAndBookkeeping_ServiceLocator(); - String sn = loc.getLoggingAndBookkeepingWSDDServiceName(); - log.info(" service name " + sn); - - LoggingAndBookkeepingPortType stub = loc.getLoggingAndBookkeeping(url); - log.info(" got endpoint "); - - String version = stub.getVersion(null); - log.info("LB version "+ version); - JobStatus status = stub.jobStatus("https://scientific.civ.zcu.cz:9000/PnSBRXoIHVzX68H5vAtxmA", null); - log.info("job status "+ status); - } catch (AxisFault af) { - log.error( " AxisFault - " + af.getFaultString()); - af.printStackTrace(); - } - } -} diff --git a/org.glite.lb.client/examples/webservices/java/Makefile b/org.glite.lb.client/examples/webservices/java/Makefile deleted file mode 100644 index 4d3f24c..0000000 --- a/org.glite.lb.client/examples/webservices/java/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -CLASSPATH:=${shell echo `find lib -type f | tr '\n' ':'`build} -VPATH=src:build - -all: wsdl build - -wsdl: org/glite/wsdl/services/lb/stubs - -build: org/glite/wsdl/services/lb/example - -run: - if test -z "${FILE}" -o -z "${PASS}"; then echo 'Specify FILE and PASS variables.'; exit 1; fi - java -classpath $(CLASSPATH) org.glite.wsdl.services.lb.example.LBClientExample ${FILE} ${PASS} ${ENDPOINT} - -clean: - rm -rvf build/ - -org/glite/wsdl/services/lb/stubs: - java -classpath $(CLASSPATH) org.apache.axis.wsdl.WSDL2Java -v \ - --buildFile \ - --package org.glite.wsdl.services.lb.stubs \ - --output build \ - http://egee.cesnet.cz/cms/export/sites/egee/en/WSDL/HEAD/LB.wsdl - -org/glite/wsdl/services/lb/example: build/org/glite/wsdl/services/lb/stubs - -mkdir build - javac -classpath $(CLASSPATH) -d build src/*.java build/org/glite/wsdl/services/lb/{stubs,stubs/holders}/*.java - -.PHONY: all wsdl run clean diff --git a/org.glite.lb.client/examples/webservices/java/README b/org.glite.lb.client/examples/webservices/java/README deleted file mode 100644 index 0af4d6b..0000000 --- a/org.glite.lb.client/examples/webservices/java/README +++ /dev/null @@ -1,28 +0,0 @@ -How to build -============ - -1) copy following files to lib/ directory: - -axis-ant.jar -axis.jar -commons-discovery-0.2.jar -commons-logging-1.0.4.jar -jaxrpc.jar -log4j.properties -log4j-1.2.13.jar -saaj.jar -wsdl4j-1.5.1.jar - -2) generate source stubs and build the example by: - - make - - -Launch -====== - - make run FILE=file.p12 PASS=passphrase ENDPOINT=https://host:9003 - -or: - - java -cp `find lib -type f | tr '\n' ':'`:build org.glite.wsdl.services.lb.example.LBClientExample https://host:9003 diff --git a/org.glite.lb.client/examples/webservices/java/src/ExampleSSLSocketFactory.java b/org.glite.lb.client/examples/webservices/java/src/ExampleSSLSocketFactory.java deleted file mode 100644 index f06b6ad..0000000 --- a/org.glite.lb.client/examples/webservices/java/src/ExampleSSLSocketFactory.java +++ /dev/null @@ -1,108 +0,0 @@ -package org.glite.wsdl.services.lb.example; - -import org.apache.axis.components.net.BooleanHolder; -import org.apache.axis.components.net.DefaultSocketFactory; -import org.apache.axis.components.net.SecureSocketFactory; -import org.apache.log4j.Logger; - -import javax.net.ssl.*; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketException; -import java.security.PrivateKey; -import java.security.cert.Certificate; -import java.security.cert.X509Certificate; -import java.util.ArrayList; -import java.util.Date; -import java.util.Hashtable; - -/** - * Factory for SSLSockets for Axis, which creates sockets for SSLv3 connection. - * Globus SSL libraries don't support SSLv2 initial packet, so SSLv2Hello protocol - * on SSLSocket must be disabled. - * - * @author Martin Kuba makub@ics.muni.cz - */ -public class ExampleSSLSocketFactory extends DefaultSocketFactory implements SecureSocketFactory { - - static Logger log = Logger.getLogger(ExampleSSLSocketFactory.class); - - static Certificate[] cChain = null; - static PrivateKey pKey = null; - static X509Certificate[] certAuths = null; - - static void registerForAxis(Certificate[] certs, PrivateKey privateKey, X509Certificate[] certificateAuthorities) { - log.debug("registering as Axis SecureSocketFactory"); - cChain = certs; - pKey = privateKey; - certAuths = certificateAuthorities; - System.setProperty("org.apache.axis.components.net.SecureSocketFactory", ExampleSSLSocketFactory.class.getName()); - } - - protected SSLSocketFactory sslFactory = null; - - public ExampleSSLSocketFactory(Hashtable attributes) throws Exception { - super(attributes); - SSLContext sctx = SSLContext.getInstance("SSL"); - KeyManager[] myKeys = new KeyManager[]{new MyX509KeyManager(cChain, pKey)}; - TrustManager[] myTrust = new TrustManager[]{new MyX509TrustManager(certAuths)}; - //init SSLContext with our keymanager and trustmanager, and default random device - sctx.init(myKeys, myTrust, null); - if (log.isDebugEnabled()) { - log.debug("attributes: " + attributes); - log.debug("SSLContext.provider: " + sctx.getProvider().getInfo()); - } - sslFactory = sctx.getSocketFactory(); - } - - - public Socket create(String host, int port, StringBuffer otherHeaders, BooleanHolder useFullURL) throws IOException, SocketException { - int i; - - log.debug("create(" + host + ":" + port + ")"); - //create SSL socket - SSLSocket socket = (SSLSocket) sslFactory.createSocket(); - //enable only SSLv3 - socket.setEnabledProtocols(new String[]{"SSLv3"}); // SSLv2Hello, SSLv3,TLSv1 - //enable only ciphers without RC4 (some bug, probably in older globus) - String[] ciphers = socket.getEnabledCipherSuites(); - ArrayList al = new ArrayList(ciphers.length); - for (i = 0; i < ciphers.length; i++) { - if (ciphers[i].indexOf("RC4") == -1) al.add(ciphers[i]); - } - socket.setEnabledCipherSuites((String [])al.toArray(new String[al.size()])); - //connect as client - socket.setUseClientMode(true); - socket.setSoTimeout(30000); //read timeout - socket.connect(new InetSocketAddress(host, port), 3000); //connect timeout - //create or join a SSL session - SSLSession sess = socket.getSession(); - if (sess == null) { - log.debug("sess is null"); - return socket; - } - - if (log.isDebugEnabled()) { - //print all we know - byte[] id = sess.getId(); - StringBuffer sb = new StringBuffer(id.length * 2); - for (i = 0; i < id.length; i++) { - sb.append(Integer.toHexString(id[i] < 0 ? 256 - id[i] : id[i])); - } - log.debug("SSLSession.id = " + sb.toString()); -// log.debug("peerHost:Port = " + sess.getPeerHost() + ":" + sess.getPeerPort()); - log.debug("cipherSuite = " + sess.getCipherSuite()); - log.debug("protocol = " + sess.getProtocol()); -// log.debug("isValid = " + sess.isValid()); - log.debug("creationTime = " + (new Date(sess.getCreationTime()))); - log.debug("lastAccessedTime= " + (new Date(sess.getLastAccessedTime()))); -// log.debug("applicationBufferSize= " + sess.getApplicationBufferSize()); -// log.debug("packetBufferSize= " + sess.getPacketBufferSize()); -// log.debug("localPrincipal= " + sess.getLocalPrincipal()); -// log.debug("peerPrincipal= " + sess.getPeerPrincipal()); - } - return socket; - } - -} diff --git a/org.glite.lb.client/examples/webservices/java/src/LBClientExample.java b/org.glite.lb.client/examples/webservices/java/src/LBClientExample.java deleted file mode 100644 index 07d4fcc..0000000 --- a/org.glite.lb.client/examples/webservices/java/src/LBClientExample.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.glite.wsdl.services.lb.example; - -import org.apache.log4j.Logger; -import org.glite.wsdl.services.lb.stubs.LoggingAndBookkeepingPortType; -import org.glite.wsdl.services.lb.stubs.LoggingAndBookkeeping_ServiceLocator; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.PrivateKey; -import java.security.cert.Certificate; -import java.security.cert.CertificateException; -import java.security.cert.X509Certificate; -import java.util.Enumeration; - -/** - * Example client of LoggingAndBookkeeping web service. Please note that the client depends - * only on Axis and Log4j libraries, it uses cryptography included in the JDK. - * - * @author Martin Kuba makub@ics.muni.cz - * @version $Id$ - */ -public class LBClientExample { - static Logger log = Logger.getLogger(LBClientExample.class); - - public static void main(String[] args) throws Exception { - if(args.length<2) { - System.out.println("usage: java LBClientExample []"); - System.exit(-1); - } - File keyfile = new File(args[0]); - String password = args[1]; - URL url = new URL("https://localhost:9003/"); - if(args.length==3) { - url = new URL(args[2]); - } - - //read in a keystore file - KeyStore ks = readKeyStoreFile(keyfile, password); - //find key alias (name) - String alias = null; - for (Enumeration en = ks.aliases(); en.hasMoreElements();) { - alias = (String)en.nextElement(); - if (ks.isKeyEntry(alias)) break; - else alias = null; - } - if (alias == null) throw new RuntimeException("the keystore contains no keys"); - //get my private key and certificates - Certificate[] certs = ks.getCertificateChain(alias); - PrivateKey key = (PrivateKey) ks.getKey(alias, password.toCharArray()); - //use my CA as the only trusted certificate authority - X509Certificate[] trustedCertAuths = new X509Certificate[]{(X509Certificate) certs[certs.length - 1]}; - - //register our SSL handling - ExampleSSLSocketFactory.registerForAxis(certs, key, trustedCertAuths); - - //get client stub - LoggingAndBookkeepingPortType lb = new LoggingAndBookkeeping_ServiceLocator().getLoggingAndBookkeeping(url); - - //call the service - String version = lb.getVersion(null); - System.out.println("LB version: " + version); - } - - public static KeyStore readKeyStoreFile(File ksfile, String password) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException { - String kstype; - if (ksfile.getName().endsWith("ks")) kstype = "JKS"; - else if (ksfile.getName().endsWith(".p12")) kstype = "PKCS12"; - else throw new IOException("Only JKS (*ks) and PKCS12 (*.p12) files are supported "); - KeyStore store = KeyStore.getInstance(kstype); - store.load(new FileInputStream(ksfile), password != null ? password.toCharArray() : null); - return store; - } - -} diff --git a/org.glite.lb.client/examples/webservices/java/src/MyX509KeyManager.java b/org.glite.lb.client/examples/webservices/java/src/MyX509KeyManager.java deleted file mode 100644 index 96e4a40..0000000 --- a/org.glite.lb.client/examples/webservices/java/src/MyX509KeyManager.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.glite.wsdl.services.lb.example; - -import org.apache.log4j.Logger; - -import javax.net.ssl.X509KeyManager; -import java.net.Socket; -import java.security.Principal; -import java.security.PrivateKey; -import java.security.cert.Certificate; -import java.security.cert.X509Certificate; - -/** - * Implementation of X509KeyManager, which always returns one pair of a private key and certificate chain. - */ -public class MyX509KeyManager implements X509KeyManager { - static Logger log = Logger.getLogger(MyX509KeyManager.class); - private final X509Certificate[] certChain; - private final PrivateKey key; - - public MyX509KeyManager(Certificate[] cchain, PrivateKey key) { - this.certChain = new X509Certificate[cchain.length]; - System.arraycopy(cchain, 0, this.certChain, 0, cchain.length); - this.key = key; - } - - //not used - public String[] getClientAliases(String string, Principal[] principals) { - log.debug("getClientAliases()"); - return null; - } - - - // Intented to be implemented by GUI for user interaction, but we have only one key. - public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) { - if (log.isDebugEnabled()) { - log.debug("chooseClientAlias()"); - for (int i = 0; i < keyType.length; i++) log.debug("keyType[" + i + "]=" + keyType[i]); - for (int i = 0; i < issuers.length; i++) log.debug("issuers[" + i + "]=" + issuers[i]); - } - return "thealias"; - } - - //not used on a client - public String[] getServerAliases(String string, Principal[] principals) { - log.debug("getServerAliases()"); - return null; - } - - //not used on a client - public String chooseServerAlias(String string, Principal[] principals, Socket socket) { - log.debug("chooseServerAlias()"); - return null; - } - - public X509Certificate[] getCertificateChain(String alias) { - log.debug("getCertificateChain()"); - return certChain; - } - - public PrivateKey getPrivateKey(String alias) { - log.debug("getPrivateKey()"); - return key; - } -} diff --git a/org.glite.lb.client/examples/webservices/java/src/MyX509TrustManager.java b/org.glite.lb.client/examples/webservices/java/src/MyX509TrustManager.java deleted file mode 100644 index c88f96f..0000000 --- a/org.glite.lb.client/examples/webservices/java/src/MyX509TrustManager.java +++ /dev/null @@ -1,83 +0,0 @@ -package org.glite.wsdl.services.lb.example; - -import org.apache.log4j.Logger; - -import javax.net.ssl.X509TrustManager; -import java.security.InvalidAlgorithmParameterException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.*; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -/** - * Simple trust manager validating server certificates against supplied trusted CAs. - * - * @author Martin Kuba makub@ics.muni.cz - * @version $Id$ - */ -public class MyX509TrustManager implements X509TrustManager { - static Logger log = Logger.getLogger(MyX509TrustManager.class); - private final X509Certificate[] certificateAuthorities; - private final Set trustAnchors; - - /** - * Creates an instance with supplied trusted root CAs. - * @param certificateAuthorities - */ - public MyX509TrustManager(X509Certificate[] certificateAuthorities) { - int i; - - this.certificateAuthorities = certificateAuthorities; - this.trustAnchors = new HashSet(); - for (i = 0; i < certificateAuthorities.length; i++) { - this.trustAnchors.add(new TrustAnchor(certificateAuthorities[i], null)); - } - } - - //not used on a client - public X509Certificate[] getAcceptedIssuers() { - log.debug("getAcceptedIssuers()"); - return this.certificateAuthorities; - } - - //not used on a client - public void checkClientTrusted(X509Certificate[] certs, String authType) { - log.debug("checkClientTrusted()"); - } - - /** - * Validates certificate chain sent by a server against trusted CAs. - * @param certs - * @param authType - * @throws CertificateException - */ - public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { - if (log.isDebugEnabled()) { - log.debug("checkServerTrusted(certs: "+ certs.length + ", authType=" + authType+")"); - for (int i = 0; i < certs.length; i++) { - log.debug("cert[" + i + "]=" + certs[i].getSubjectX500Principal().toString()); - } - } - //validate server certificate - try { - PKIXParameters pkixParameters = new PKIXParameters(this.trustAnchors); - pkixParameters.setRevocationEnabled(false); - CertificateFactory certFact = CertificateFactory.getInstance("X.509"); - CertPath path = certFact.generateCertPath(Arrays.asList(certs)); - CertPathValidator certPathValidator = CertPathValidator.getInstance("PKIX"); - certPathValidator.validate(path, pkixParameters); - } catch (NoSuchAlgorithmException e) { - log.error(e.getMessage(), e); - } catch (InvalidAlgorithmParameterException e) { - log.error(e.getMessage(), e); - } catch (CertPathValidatorException e) { - CertificateException ce; - log.error(e.getMessage(), e); - ce = new CertificateException(e.getMessage()); - ce.setStackTrace(e.getStackTrace()); - throw ce; - } - log.debug("server is trusted"); - } -} diff --git a/org.glite.lb.client/examples/webservices/java/src/log4j.properties b/org.glite.lb.client/examples/webservices/java/src/log4j.properties deleted file mode 100644 index cfdcee3..0000000 --- a/org.glite.lb.client/examples/webservices/java/src/log4j.properties +++ /dev/null @@ -1,30 +0,0 @@ -# Set root category priority to INFO and its only appender to CONSOLE. -# names CONSOLE, R, F are arbitrary -log4j.rootCategory=INFO, CONSOLE - -# Set the enterprise logger category to FATAL and its only appender to CONSOLE. -log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE -log4j.logger.org.apache.axis.utils.JavaUtils=FATAL -log4j.logger.org.glite.wsdl.services.lb=DEBUG - -# CONSOLE is set to be a ConsoleAppender using a PatternLayout. -log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender -log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout -#viz http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html -# %d - date -# %t - thread -# %p - priority -# %c{1} - category (jmeno loggeru) s poctem zobrazovanych casti oddelenych teckou -# %m - message -# %n - line separator -log4j.appender.CONSOLE.layout.ConversionPattern=%d [%t] %-5p %c{1} - %m%n - -log4j.appender.F=org.apache.log4j.FileAppender -log4j.appender.F.File=txt.log -log4j.appender.F.layout=org.apache.log4j.PatternLayout -log4j.appender.F.layout.ConversionPattern=%d [%t] %-5p %c - %m%n - -log4j.appender.R=org.apache.log4j.DailyRollingFileAppender -log4j.appender.R.File=xml.log -log4j.appender.R.layout=org.apache.log4j.xml.XMLLayout -log4j.appender.R.DatePattern='.'yyyy-MM-dd diff --git a/org.glite.lb.client/interface/Event.h.T b/org.glite.lb.client/interface/Event.h.T deleted file mode 100644 index 5d2a89c..0000000 --- a/org.glite.lb.client/interface/Event.h.T +++ /dev/null @@ -1,308 +0,0 @@ -#ifndef GLITE_LB_EVENT_HPP -#define GLITE_LB_EVENT_HPP - - -#ident "$Header$" - -/** @file Event.h - * @version $Revision$ - */ - -/* -@@@AUTO -*/ -@@@LANG: C++ - -#include -#include -#include - -#include "glite/jobid/JobId.h" - -#ifdef BUILDING_LB_COMMON -#include "CountRef.h" -#include "events.h" -#include "notifid.h" -#else -#include "glite/lb/CountRef.h" -#include "glite/lb/events.h" -#include "glite/lb/notifid.h" -#endif - -EWL_BEGIN_NAMESPACE - -/** Class representing one event in the L&B database. - * - * This class represents a L&B event, which is basically list of - * attribute -- value pairs. For each particular event type (returned - * by name()) there is a list of allowed attributes (returned by - * getAttrs()). The Event class provides methods for reading these - * attributes, but no means of changing the - * event are provided; this class is used as a result of L&B queries. - */ -class Event { - friend class Job; - friend class ServerConnection; - friend class CountRef; -public: - /** Event type codes - * identify which of the event fields are valid. - */ - enum Type { - UNDEF = 0, /**< Undefined event type. */ -@@@{ - for my $e ($event->getTypesOrdered) { - my $u = uc $e; - my $c = getTypeComment $event $e; - gen "\t\t$u = EDG_WLL_EVENT_$u,\t/**< $c */\n"; - } -@@@} - TYPE_MAX = EDG_WLL_EVENT__LAST /**< Limit for checking type validity. */ - }; - - /** Event attribute symbolic identifier. - * These symbols provide symbolic names for event - * attributes. In braces are shown the event types for which the - * attribute is defined, for each event type the attribute - * meaning is described. - */ - enum Attr { -@@@{ - - require "../src/EventAttrNames.pl"; - my %EventAttrNums; - my $evno = 0; - for (@main::EventAttrNames) { - $EventAttrNums{$_} = $evno++; - } - - my $max = 0; - for (sort {$a cmp $b} getAllFields $event) { - my $u = $_; -# $u =~ s/([a-z])([A-Z])/$1_$2/g; - $u = uc $u; - - my $c = "\t/**\n"; - for my $t (sort $event->getFieldOccurence($_)) { - selectType $event $t; - my $cc = getFieldComment $event $_; - $t = 'common' if $t eq '_common_'; - $c .= "\t * \\n\[$t\] $cc\n"; - } - $c .= "\t */\n"; - - gen defined($EventAttrNums{$u}) ? - "$c\t\t$u = $EventAttrNums{$u},\n" : - "#error \"$u not defined in EventAttrNames\"\n"; - - $max = $EventAttrNums{$u} if defined($EventAttrNums{$u}) && $EventAttrNums{$u} > $max; - } - $max++; - gen "\t\tATTR_MAX = $max /**< Limit for checking attribute code validity. */\n"; -@@@} - }; - -@@@{ - for my $f (getAllFields $event) { - for my $t (getFieldOccurence $event $f) { - my $ff; - my $ut; - my $utf; - my $fc; - my $fn; - if ($t eq '_common_') { - $ff = $f; - $ut = ''; - $utf = ''; - $fc = ''; - } - else { - selectType $event $t; - selectField $event $f; - $ff = getField $event; - $ut = uc $t . '_'; - $utf = ucfirst $t; - $fc = $event->getFieldComment($f); - } - $fn = ucfirst $ff->{name}; - my @a = ($fn =~ /_(.)/g); - while (@a) { my $c = uc shift @a; $fn =~ s/_(.)/$c/; } - if ($ff->{codes}) { - gen qq{ -! /** $fc */ -! enum ${utf}${fn}Code \{ -}; - for (@{$ff->{codes}}) { - gen qq{ -! $ut$_->{name} = EDG_WLL_$ut$_->{name}, /**< $_->{comment} */ -}; - } - gen qq{ -! \}; -}; - unless ($main::defined_enums{$utf}) { - gen qq{/* backward compatibility */ -!\#define ${utf}Code ${utf}${fn}Code -! -}; - $main::defined_enums{$utf} = 1; - } - } - } - } -@@@} - - /** Symbolic names for types of attribute values. */ - enum AttrType { INT_T, /**< Integer value. */ - STRING_T, /**< String value. */ - TIMEVAL_T, /**< Time value (ie. struct - timeval). */ - PORT_T, /**< Service port (integer). */ - LOGSRC_T, /**< Source of the event - (integer). */ - JOBID_T, /**< JobId value. */ - NOTIFID_T, /**< NotifId value. */ - FLOAT_T, /**< Float value. */ - DOUBLE_T, /**< Double value. */ - }; - - Type type; /**< Type of the event as defined by Type. */ - - /** Default constructor. - * - * Initializes an empty event. - */ - Event(void); - - /** Constructor from corresponding C type. - * - * Initializes the object from the corresponding C struct, in - * fact holding the pointer to it. - */ - Event(edg_wll_Event *); - - /** Copy constructor. - * - * Creates a copy of the object by sharing the C struct - * with the original. - */ - Event(const Event &); - - /** Destructor. - * - * Releases the C struct (possibly deallocating it). - */ - ~Event(void); - - - /** Assign new Event to an existing instance. - * - * The original data are released and new ones are made - * accessible. - * \returns Reference to this object. - */ - Event & operator= (const Event &); - - /** String representation of the event type. - * - * Returns string representing the event type. - * \returns Name of the event. - * \throw Exception Invalid event type. - */ - const std::string & name(void) const; - - /** Retrieve integer attribute. - * - * Retrieves value for attributes of integer type. - * \param[in] name Name of the attribute to retrieve. - * \returns Integer value of the attribute. - * \throw Exception Invalid event type or attribute not - * defined for this event. - */ - int getValInt(Attr name) const; - - /** Retrieve float attribute. - * - * Retrieves value for attributes of float type. - * \param[in] name Name of the attribute to retrieve. - * \returns Integer value of the attribute. - * \throw Exception Invalid event type or attribute not - * defined for this event. - */ - float getValFloat(Attr name) const; - - /** Retrieve double attribute. - * - * Retrieves value for attributes of double type. - * \param[in] name Name of the attribute to retrieve. - * \returns Integer value of the attribute. - * \throw Exception Invalid event type or attribute not - * defined for this event. - */ - double getValDouble(Attr name) const; - - /** Retrieve string attribute. - * - * Retrieves value for attributes of string type. - * \param[in] name Name of the attribute to retrieve. - * \returns String value of the attribute. - * \throw Exception Invalid event type or attribute not - * defined for this event. - */ - std::string getValString(Attr name) const; - - /** Retrieve time attribute. - * - * Retrieves value for attributes of timeval type. - * \param[in] name Name of the attribute to retrieve. - * \returns struct timeval value of the attribute. - */ - struct timeval getValTime(Attr name) const; - - /** Retrieve jobid attribute - * - * Retrieves value for attributes of JobId type. - * \param[in] name Name of the attribute to retrieve. - * \returns JobId value of the attribute. - * \throw Exception Invalid event type or attribute not - * defined for this event. - */ - const glite::jobid::JobId getValJobId(Attr name) const; - - /** Attribute name. - * - * Retrieves string representation of the attribute name. - * \param[in] name Symbolic name of the attribute. - * \returns String name of the attribute. - * \throw Exception Invalid attribute name. - * - */ - static const std::string & getAttrName(Attr name); - - /** List of attributes and types valid for this instance. - * - * Retrieves description of all attributes defined for this event. - * \returns Vector of Attr -- AttrType pairs. - * \throw Exception Invalid event type. - */ - const std::vector > & getAttrs(void) const; - - /** Event name. - * - * Retrieves string representation of the event type. - * \param[in] type Symbolic name of the event type. - * \returns String name of the event. - * \throw Exception Invalid event type. - * - */ - static const std::string getEventName(Type type); - -private: - std::string my_name; - static void destroyFlesh(void *); - CountRef *flesh; -}; - -EWL_END_NAMESPACE - -#endif /* GLITE_LB_EVENT_HPP */ diff --git a/org.glite.lb.client/interface/Job.h b/org.glite.lb.client/interface/Job.h deleted file mode 100644 index c1267d2..0000000 --- a/org.glite.lb.client/interface/Job.h +++ /dev/null @@ -1,198 +0,0 @@ -#ifndef GLITE_LB_JOB_HPP -#define GLITE_LB_JOB_HPP - -#ident "$Header$" - -#include "glite/jobid/JobId.h" - - -#ifdef BUILDING_LB_CLIENT -#include "Event.h" -#include "JobStatus.h" -#include "ServerConnection.h" -#else -#include "glite/lb/Event.h" -#include "glite/lb/JobStatus.h" -#include "glite/lb/ServerConnection.h" -#endif - - -/** - * @file Job.h - * @version $Revision$ - */ - -EWL_BEGIN_NAMESPACE - -/** Class encapsulating the job info stored in the L&B database. - * - * This class is the primary interface for getting information about - * jobs stored in the L&B database. It is constructed from known job - * id, which uniquely identifies the job as well as the bookkeeping - * server where the job data is stored. The Job class provides methods - * for obtaining the data from the bookkeeping server and for setting - * various parameters of the connection to the bookkeeping server. - * - * All query methods have their counterpart in C functions taking - * taking edg_wll_Context and edg_wll_JobId as their first parameters - * (in fact, those functions are used to do the actual work). - */ -class Job { -public: - /** Default constructor. - * - * Initializes the job as empty, not representing anything. - */ - Job(void); - - /** Constructor from job id. - * - * Initializes the job to obtain information for the given job id. - * \param[in] jobid The job id of the job this object will - * represent. - * \throws Exception Could not copy the job id. - */ - Job(const glite::jobid::JobId &jobid); - - - /** Destructor. - * - * All the actual work is done by member destructors, namely ServerConnection. - */ - ~Job(); - - /** Assign new job id to an existing instance. - * - * Redirect this instance to obtain information about - * different job; connection to the server is preserved, if - * possible. - * \param[in] jobid New job id. - * \returns Reference to this object. - * \throws Exception Could not copy the job id. - */ - Job & operator= (const glite::jobid::JobId &jobid); - - /* - * Status retrieval bitmasks. Used ORed as Job::status() argument, - * determine which status fields are actually retrieved. - */ - static const int STAT_CLASSADS; /**< Include the job - * description in the - * query result. */ - static const int STAT_CHILDREN; /**< Include the list of - * subjob id's in the - * query result. */ - static const int STAT_CHILDSTAT; /**< Apply the flags - * recursively to - * subjobs. */ - - /** Return job status. - * - * Obtain the job status (as JobStatus) from the bookkeeping - * server. - * \param[in] flags Specify details of the query. - * \returns Status of the job. - * \throws Exception Could not query the server. - * \see STAT_CLASSADS, STAT_CHILDREN, STAT_CHILDSTAT - */ - JobStatus status(int flags) const; - - /** Return all events corresponding to this job - * - * Obtain all events corresponding to the job that are stored - * in the bookkeeping server database. The maximum number of - * returned events can be set by calling setParam(). - * \param[out] events Vector of events (of type Event). - * \throws Exception Could not query the server. - */ - void log(std::vector &events) const; - - /** Return all events corresponding to this job - * - * Obtain all events corresponding to the job that are stored - * in the bookkeeping server database. The maximum number of - * returned events can be set by calling setParam(). - * \returns Vector of events (of type Event). - * \throws Exception Could not query the server. - */ - const std::vector log(void) const; - - /** Return last known address of a listener associated to the job. - * - * Obtains the information about last listener that has been - * registered for this job in the bookkeeping server database. - * \param[in] name Name of the listener. - * \returns Hostname and port number of the registered - * listener. - * \throws Exception Could not query the server. - */ - const std::pair queryListener(const std::string &name) const; - - /** - * Manipulate LB parameters. - * - * This method sets integer typed parameters for the server connection. - * - * \param[in] ctx Symbolic name of the parameter to change. - * \param[in] val New value of the parameter. - */ - void setParam(edg_wll_ContextParam ctx, int val); - - /** - * Manipulate LB parameters. - * - * This method sets string typed parameters for the server connection. - * - * \param[in] ctx Symbolic name of the parameter to change. - * \param[in] val New value of the parameter. - */ - void setParam(edg_wll_ContextParam ctx, const std::string val); - - /** - * Manipulate LB parameters. - * - * This method sets timeval typed parameters for the server connection. - * - * \param[in] ctx Symbolic name of the parameter to change. - * \param[in] val New value of the parameter. - */ - void setParam(edg_wll_ContextParam ctx, const struct timeval &val); - - /** - * Get LB parameters. - * - * Obtain value of the named integer parameter. - * - * \param[in] ctx Symbolic name of the paramater to obtain. - * \return Value of the parameter. - */ - int getParamInt(edg_wll_ContextParam ctx) const; - - /** - * Get LB parameters. - * - * Obtain value of the named string parameter. - * - * \param[in] ctx Symbolic name of the paramater to obtain. - * \return Value of the parameter. - */ - std::string getParamString(edg_wll_ContextParam ctx) const; - - /** - * Get LB parameters. - * - * Obtain value of the named timeval parameter. - * - * \param[in] ctx Symbolic name of the paramater to obtain. - * \return Value of the parameter. - */ - struct timeval getParamTime(edg_wll_ContextParam ctx) const; - -private: - ServerConnection server; - glite::jobid::JobId jobId; -}; - -EWL_END_NAMESPACE - -#endif /* GLITE_LB_JOB_HPP */ diff --git a/org.glite.lb.client/interface/JobStatus.h.T b/org.glite.lb.client/interface/JobStatus.h.T deleted file mode 100644 index b8103f9..0000000 --- a/org.glite.lb.client/interface/JobStatus.h.T +++ /dev/null @@ -1,309 +0,0 @@ -#ifndef GLITE_LB_JOBSTATUS_HPP -#define GLITE_LB_JOBSTATUS_HPP - -/* -@@@AUTO -*/ - -@@@LANG: C++ - -#include -#include -#include -#include - -#include "glite/jobid/JobId.h" - -#include "glite/lb/jobstat.h" -#include "glite/lb/CountRef.h" - -EWL_BEGIN_NAMESPACE; - -/** Class representing status of job. - * - * This class is used to represent all information about the job status - * as computed and stored in the bookkeeping server's database. Job - * status is, like Event, list of attribute -- value pairs. One of the - * attributes is the job's state as seen by the L&B, ie. something - * like RUNNING or * DONE, other attributes contain - * more information about the job. - * - * The JobStatus class provides methods for reading values of these - * attributes and it is used as a result of server queries. - */ -class JobStatus { - friend class Job; - friend class CountRef; -public: - - /** Symbolic names of job states. */ - enum Code { - UNDEF = 0, /**< Indicates invalid, i.e. uninitialized instance. */ -@@@{ - for my $stat ($status->getTypesOrdered) - { - my $u = uc($stat); - my $c = getTypeComment $status $stat; - gen qq{ -! $u, /**< $c */ -}; - } -@@@} - CODE_MAX /**< Limit for range checking. */ - }; - - /** Symbolic names of attributes. - * - * These constants are used for naming individual attributes - * when invoking their access methods. - */ - enum Attr { -@@@{ - require '../src/StatusAttrNames.pl'; - my %StatusAttrNums; - my $stno = 0; - for (@main::StatusAttrNames) { - $StatusAttrNums{$_} = $stno++; - } - - my $max = 0; - selectType $status '_common_'; - for my $u (sort {$a cmp $b} getAllFields $status) { - selectField $status $u; - my $f = getField $status; - $u =~ s/([a-z])([A-Z])/$1_$2/g; - $u = uc $u; - - gen defined($StatusAttrNums{$u}) ? - "\t/** $f->{comment} */\n\t\t$u = $StatusAttrNums{$u},\n" : - "#error \"$u not defined in StatusAttrNames\"\n"; - $max = $StatusAttrNums{$u} if defined($StatusAttrNums{$u}) && $StatusAttrNums{$u} > $max; - } - $max++; - gen "\t\tATTR_MAX = $max /**< Limit for range checking. */\n"; -@@@} - }; - -@@@{ - selectType $status '_common_'; - for my $n (getAllFields $status) { - selectField $status $n; - my $f = getField $status; - if ($f->{codes}) { - my $n = uc getName $f; - gen qq{ -! enum \{ -}; - for (@{$f->{codes}}) { - gen qq{ -! $n\_$_->{name}, /**< $_->{comment} */ -}; - } - gen qq{ -! \}; -}; - } - } -@@@} - /** Symbolic names of attribute types. - * - * These constants are used to name the various attribute - * types. - */ - enum AttrType { INT_T, /**< Integer type. */ - STRING_T, /**< String type. */ - TIMEVAL_T, /**< struct timeval type. */ - BOOL_T, /**< Boolean type (true or false). */ - JOBID_T, /**< Job id type. */ - INTLIST_T, /**< List of integer values. */ - STRLIST_T, /**< List of string values. */ - TAGLIST_T, /**< List of user tags. */ - STSLIST_T, /**< List of states. */ - CCLASSAD_T /**< Unparsed classad */ - }; - - /** Numeric status code. - * - * This code represents the state of the job. - * \see Code. - */ - Code status; - - /** Get state name. - * - * Returns string representation of the job's state. - */ - const std::string & name(void) const; - - /** Access method for attribute values. - * - * Retrieve integer value of named attribute. - * \param[in] name Symbolic name of attribute. - * \returns Value of attribute. - * \throws LoggingException Invalid attribute name. - */ - int getValInt(Attr name) const; - - /** Access method for attribute values. - * - * Retrieve string value of named attribute. - * \param[in] name Symbolic name of attribute. - * \returns Value of attribute. - * \throws LoggingException Invalid attribute name. - */ - std::string getValString(Attr name) const; - - /** Access method for attribute values. - * - * Retrieve struct timeval value of named attribute. - * \param[in] name Symbolic name of attribute. - * \returns Value of attribute. - * \throws LoggingException Invalid attribute name. - */ - struct timeval getValTime(Attr name) const; - - /** Access method for attribute values. - * - * Retrieve JobId value of named attribute. - * \param[in] name Symbolic name of attribute. - * \returns Value of attribute. - * \throws LoggingException Invalid attribute name. - */ - const glite::jobid::JobId getValJobId(Attr name) const; - - /** Access method for attribute values. - * - * Retrieve bool value of named attribute. - * \param[in] name Symbolic name of attribute. - * \returns Value of attribute. - * \throws LoggingException Invalid attribute name. - */ - bool getValBool(Attr name) const; - - /** Access method for attribute values. - * - * Retrieve integer values of named attribute. - * \param[in] name Symbolic name of attribute. - * \returns Value of attribute. - * \throws LoggingException Invalid attribute name. - */ - const std::vector getValIntList(Attr name) const; - - /** Access method for attribute values. - * - * Retrieve string values of named attribute. - * \param[in] name Symbolic name of attribute. - * \returns Value of attribute. - * \throws LoggingException Invalid attribute name. - */ - const std::vector getValStringList(Attr name) const; - - /** Access method for attribute values. - * - * Retrieve user tags values of named attribute. - * \param[in] name Symbolic name of attribute. - * \returns Value of attribute. - * \throws LoggingException Invalid attribute name. - */ - const std::vector > getValTagList(Attr name) const; - - /** Access method for attribute values. - * - * Retrieve status values of named attribute. - * \param[in] name Symbolic name of attribute. - * \returns Value of attribute. - * \throws LoggingException Invalid attribute name. - */ - const std::vector getValJobStatusList(Attr name) const; - - /** Get name of attribute. - * - * Retrieve string representation of symbolic name of attribute. - * \param[in] name Symbolic name of attribute. - * \returns Name of attribute. - * \throws LoggingException Invalid attribute name. - */ - static const std::string& getAttrName(Attr name); - - /** Find attribute by name (case insensitive) - * \param[in] name String name. - * \returns enum attr value. - * \throws LoggingException Invalid attribute name. - */ - static Attr attrByName(std::string const &); - - /** List of attributes and their types valid for this - * instance. - * - * Returns the vector of (attribute, attribute type) pairs - * that this instance of JobStatus contains. - * \returns List of attributes. - */ - const std::vector >& getAttrs(void) const; - - /** Get name of state. - * - * Retrieve string representation of symbolic job state. - * \param[in] state Symbolic state name. - * \returns String state name. - * \throw Exception Invalid state. - * - */ - static const std::string &getStateName(Code state); - - /** Default constructor. - * - * Initializes an empty instance. - */ - JobStatus(void); - - /** Copy constructor. - * - * Creates identical copy of the original object. - * The underlying C struct edg_wll_JobStatus is shared using - * the CountRef mechanism. - * \param[in] orig Original. - */ - JobStatus(const JobStatus &orig); - - /** Assignment operator. - * - * Creates identical copy of the original object. - * The underlying C struct edg_wll_JobStatus is shared using - * the CountRef mechanism. - * \param[in] orig Original. - */ - JobStatus & operator=(const JobStatus &orig); - - /** Constructor from the C type. - * - * Encapsulates the given struct. - * \param[in] src C struct that holds the status. - * \param[in] destroy destroy src after use. - */ - JobStatus(const edg_wll_JobStat &src,int destroy = 1); - - /** Assignment from the C type. - * - * Encapsulates the given struct. - * \param[in] src C struct that holds the status. - */ - JobStatus & operator=(const edg_wll_JobStat& src); - - /** Destructor. - * - * Releases the encapsulated C struct. - */ - virtual ~JobStatus(); - -protected: - edg_wll_JobStat *c_ptr(void); - -private: - static void destroyFlesh(void *); - CountRef *flesh; -}; - -EWL_END_NAMESPACE; - -#endif /* GLITE_LB_JOBSTATUS_HPP */ diff --git a/org.glite.lb.client/interface/Notification.h b/org.glite.lb.client/interface/Notification.h deleted file mode 100644 index 159096e..0000000 --- a/org.glite.lb.client/interface/Notification.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef GLITE_LB_NOTIFICATION_HPP -#define GLITE_LB_NOTIFICATION_HPP - - -#include "glite/jobid/JobId.h" - -#ifdef BUILDING_LB_CLIENT -#include "consumer.h" -#include "JobStatus.h" -#include "notification.h" -#else -#include "glite/lb/consumer.h" -#include "glite/lb/JobStatus.h" -#include "glite/lb/notification.h" -#endif - - -EWL_BEGIN_NAMESPACE - - -/** Manage LB notifications. - * Simplified API, covers only a subset of C API functinality - */ - -class Notification { -public: - /** Create an empty object - * to be used for new notifications, i.e. with Register() - */ - Notification(); - - /** Create from server host,port pair - * to be used for new notifications, i.e. with Register() - * \param[in] host host - * \param[in] port port - */ - Notification(const std::string host,const u_int16_t port); - - /** Create from NotifId - * to be used for existing notifications, i.e. with Bind() - * \param[in] notifId NotifId - */ - Notification(const std::string notifId); - - ~Notification(); - - std::string getNotifId() const; /**< retrieve NotifId */ - time_t getValid() const; /**< retrieve time until when it is valid */ - int getFd() const; /**< retrieve local listener filedescriptor */ - - /** Add this job to the list. - * Local operation only, Register() has to be called - * to propagate changes to server - * \param[in] jobId JobId - */ - void addJob(const glite::jobid::JobId &jobId); - - /** Remove job from the list, local op again. - * \param[in] jobId JobId - */ - void removeJob(const glite::jobid::JobId &jobId); - - /** Get jobs on the list */ - std::string getJobs(); - - /** Receive notifications on these states */ - void setStates(const std::vector &); - - /** Get states */ - std::string getStates(); - - /** Register (or re-register, i.e. change and extend) - * with the server - */ - void Register(); - - /** Bind to the existing notification at the server - * i.e. change the receiving local address - * \param[in] address address override - */ - void Bind(const std::string address); - - /** Receive notification. - * Blocks at most the specified timeout (maybe 0 for local polling). - * \retval 0 OK - * \retval 1 timeout - */ - int receive(glite::lb::JobStatus &,timeval &); - -private: - std::vector jobs; - std::vector states; - - edg_wll_Context ctx; - edg_wll_NotifId notifId; - time_t valid; -}; - - -EWL_END_NAMESPACE - -#endif /* GLITE_LB_NOTIFICATION_HPP */ diff --git a/org.glite.lb.client/interface/ServerConnection.h b/org.glite.lb.client/interface/ServerConnection.h deleted file mode 100644 index dba776a..0000000 --- a/org.glite.lb.client/interface/ServerConnection.h +++ /dev/null @@ -1,743 +0,0 @@ -#ifndef GLITE_LB_SERVERCONNECTION_HPP -#define GLITE_LB_SERVERCONNECTION_HPP - -#ident "$Header$" - -/** - * @file ServerConnection.h - * @version $Revision$ - */ - -#include -#include - -#include "glite/jobid/JobId.h" - - -#ifdef BUILDING_LB_CLIENT -#include "Event.h" -#include "JobStatus.h" -#include "consumer.h" -#else -#include "glite/lb/Event.h" -#include "glite/lb/JobStatus.h" -#include "glite/lb/consumer.h" -#endif - -EWL_BEGIN_NAMESPACE - -/** Auxiliary class to hold atomic query condition. - * - * This class is used to construct queries to the L&B database. Each - * query is composed of multiple atomic conditions in the form of - * 'attribute' 'predicate' 'value'. QueryRecord represents such an - * atomic condition. - */ -class QueryRecord { -public: - friend class ServerConnection; - friend edg_wll_QueryRec *convertQueryVector(const std::vector &in); - - /* IMPORTANT: must match lbapi.h */ - /** Symbolic names of queryable attributes. - * - * The queryable attributes correspond to the table columns in - * the bookkeeping server database, they relate both to the - * event records and job records. - * \see Event::Attr - */ - enum Attr { - UNDEF=0, /**< Not-defined value, used to terminate lists etc. */ - JOBID = EDG_WLL_QUERY_ATTR_JOBID, /**< Job id. */ - OWNER = EDG_WLL_QUERY_ATTR_OWNER, /**< Job owner (certificate subject). */ - STATUS = EDG_WLL_QUERY_ATTR_STATUS, /**< Current job status code. */ - LOCATION = EDG_WLL_QUERY_ATTR_LOCATION, /**< Where is the job being processed. */ - DESTINATION = EDG_WLL_QUERY_ATTR_DESTINATION, /**< Destination CE. */ - DONECODE = EDG_WLL_QUERY_ATTR_DONECODE, /**< Minor done status (OK,fail,cancel). */ - USERTAG = EDG_WLL_QUERY_ATTR_USERTAG, /**< User tag. */ - TIME = EDG_WLL_QUERY_ATTR_TIME, /**< Timestamp of the event. */ - LEVEL = EDG_WLL_QUERY_ATTR_LEVEL, /**< Logging level. */ - HOST = EDG_WLL_QUERY_ATTR_HOST, /**< Hostname where the event was generated. */ - SOURCE = EDG_WLL_QUERY_ATTR_SOURCE, /**< Source component that sent the event. */ - INSTANCE = EDG_WLL_QUERY_ATTR_INSTANCE, /**< Instance of the source component. */ - EVENT_TYPE = EDG_WLL_QUERY_ATTR_EVENT_TYPE, /**< Event type. */ - CHKPT = EDG_WLL_QUERY_ATTR_CHKPT_TAG, /**< Checkpoint tag. */ - RESUBMITTED = EDG_WLL_QUERY_ATTR_RESUBMITTED, /**< Job was resubmitted */ - PARENT = EDG_WLL_QUERY_ATTR_PARENT, /**< Id of the parent job. */ - EXITCODE = EDG_WLL_QUERY_ATTR_EXITCODE, /**< Job system exit code. */ - JDLATTR = EDG_WLL_QUERY_ATTR_JDL_ATTR, /**< Arbitrary JDL attribute */ - }; - - /** Symbolic names of predicates. - * - * These are the predicates used for creating atomic query - * conditions. - */ - enum Op { - EQUAL=EDG_WLL_QUERY_OP_EQUAL, /**< Equal. */ - LESS=EDG_WLL_QUERY_OP_LESS, /**< Less than. */ - GREATER=EDG_WLL_QUERY_OP_GREATER, /**< Greater than. */ - WITHIN=EDG_WLL_QUERY_OP_WITHIN, /**< Within the - range. */ - UNEQUAL=EDG_WLL_QUERY_OP_UNEQUAL /**< Not equal. */ - }; - - - /** Default constructor. - * - * Initializes empty query condition. - */ - QueryRecord(); - - /** Copy constructor - * - * Initializes an exact copy of the object. - * \param[in] src Original object. - */ - QueryRecord(const QueryRecord &src); - - /** Assignment operator. - * - * Initializes an exact copy of the object. - * \param[in] src Original object. - * \returns Reference to this object. - */ - QueryRecord& operator=(const QueryRecord &src); - - /** Constructor for condition on string typed value. - * - * Initializes the object to hold condition on string typed - * attribute value. - * \param[in] name Name of the attribute. - * \param[in] op Symbolic name of the predicate. - * \param[in] value Actual value. - * \throw Exception Invalid value type for given attribute. - */ - QueryRecord(const Attr name, const Op op, const std::string &value); - - /** Constructor for condition on integer typed value. - * - * Initializes the object to hold condition on integer typed - * attribute value. - * \param[in] name Name of the attribute. - * \param[in] op Symbolic name of the predicate. - * \param[in] value Actual value. - * \throw Exception Invalid value type for given attribute. - */ - QueryRecord(const Attr name, const Op op, const int value); - - /** Constructor for condition on timeval typed value. - * - * Initializes the object to hold condition on timeval typed - * attribute value. - * \param[in] name Name of the attribute. - * \param[in] op Symbolic name of the predicate. - * \param[in] value Actual value. - * \throw Exception Invalid value type for given attribute. - */ - QueryRecord(const Attr name, const Op op, const struct timeval &value); - - /** Constructor for condition on JobId typed value. - * - * Initializes the object to hold condition on JobId typed - * attribute value. - * \param[in] name Name of the attribute. - * \param[in] op Symbolic name of the predicate. - * \param[in] value Actual value. - * \throw Exception Invalid value type for given attribute. - */ - QueryRecord(const Attr name, const Op op, const glite::jobid::JobId &value); - - /* this one is for attr==TIME and particular state */ - /** Constructor for condition on timeval typed value. - * - * Initializes the object to hold condition on the time the job - * stays in given state. - * \param[in] name Name of the attribute. - * \param[in] op Symbolic name of the predicate. - * \param[in] state State of thet job. - * \param[in] value Actual value. - * \throw Exception Invalid value type for given attribute. - */ - QueryRecord(const Attr name, const Op op, const int state, const struct timeval &value); - - /* constructors for WITHIN operator */ - /** Constructor for condition on string typed interval. - * - * Initializes the object to hold condition on string typed - * attribute interval. - * \param[in] name Name of the attribute. - * \param[in] op Symbolic name of the predicate. - * \param[in] value_min Low interval boundary. - * \param[in] value_max High interval boundary. - * \throw Exception Invalid value type for given attribute. - */ - QueryRecord(const Attr name, const Op op, const std::string &value_min, const std::string &value_max); - - /** Constructor for condition on integer typed interval. - * - * Initializes the object to hold condition on integer typed - * attribute interval. - * \param[in] name Name of the attribute. - * \param[in] op Symbolic name of the predicate. - * \param[in] value_min Low interval boundary. - * \param[in] value_max High interval boundary. - * \throw Exception Invalid value type for given attribute. - */ - QueryRecord(const Attr name, const Op op, const int value_min, const int value_max); - - /** Constructor for condition on timeval typed interval. - * - * Initializes the object to hold condition on timeval typed - * attribute interval. - * \param[in] name Name of the attribute. - * \param[in] op Symbolic name of the predicate. - * \param[in] value_min Low interval boundary. - * \param[in] value_max High interval boundary. - * \throw Exception Invalid value type for given attribute. - */ - QueryRecord(const Attr name, const Op op, const struct timeval &value_min, const struct timeval &value_max); - - /** Constructor for condition on timeval typed interval for - * given state. - * - * Initializes the object to hold condition on the time job - * stayed in given state. - * \param[in] name Name of the attribute. - * \param[in] op Symbolic name of the predicate. - * \param[in] state State of thet job. - * \param[in] value_min Low interval boundary. - * \param[in] value_max High interval boundary. - * \throw Exception Invalid value type for given attribute. - */ - QueryRecord(const Attr name, const Op op, const int state, const struct timeval &value_min, const struct timeval &value_max); - - /* convenience for user tags */ - /** Convenience constructor for condition on user tags. - * - * Initializes the object to hold condition on the value of - * user tag. - * \param[in] tag Name of the tag. - * \param[in] op Symbolic name of the predicate. - * \param[in] value Value of the tag. - */ - QueryRecord(const std::string &tag, const Op op, const std::string &value); - - /** Convenience constructor for condition on user tags. - * - * Initializes the object to hold condition on the value of - * user tag. - * \param[in] tag Name of the tag. - * \param[in] op Symbolic namen of the predicate. - * \param[in] value_min Minimal value of the tag. - * \param[in] value_max Maximal value of the tag. - * \throws Exception Predicate is not WITHIN. - */ - QueryRecord(const std::string &tag, const Op op, const std::string &value_min, const std::string &value_max); - - /** Destructor. - * - * The actual work is done by member destructors. - */ - ~QueryRecord(); - - /** Return the string representation of symbolic attribute - * name. - * \param[in] attr Symbolic attribute name. - * \returns Printable attribute name. - */ - static const std::string AttrName(const Attr attr) ; - -protected: - - /* conversion to C API type */ - operator edg_wll_QueryRec() const; - -private: - Attr attr; - Op oper; - std::string tag_name; - int state; - std::string string_value; - glite::jobid::JobId jobid_value; - int int_value; - struct timeval timeval_value; - std::string string_value2; - int int_value2; - struct timeval timeval_value2; -}; - - -/** Supported aggregate operations. */ -enum AggOp { AGG_MIN=1, AGG_MAX, AGG_COUNT }; - - -/** - * Class representing a connection to the L&B server. - * - * This class serves as an interface for queries not related to - * particular job. The address of the bookkeeping server to query can - * be set arbitrarily during the lifetime of this object, connection - * to the server is maintained automatically by the underlying C API - * layer. This class can be thought of also as an encapsulation of - * edg_wll_Context from L&B C API. - * - * ServerConnection's methods correlate to the L&B C API functions - * taking edg_wll_Context as their first argument and not having - * edg_wll_JobId as the second argument. - * \see edg_wll_Context - */ -class ServerConnection { -public: - /** \defgroup query Methods for querying the bookkeeping - * server. - * - * These methods serve for obtaining data from the bookkeeping - * server. The L&B service queries come in two flavors: - * \li conjunctive query, as in (cond1) or (cond2) - * \li conjunction of disjunctive queries, as in ( (cond1) - * or (cond2) ) and ( (cond3) or (cond4) ) - * Methods for both query flavors are provided. - * - * Query methods actually do communicate with the server and - * they are synchronous; their completion can take some time - * not exceeding the query timeout. - */ - - /** \defgroup property Methods for setting and getting - * connection properties. - * - * These methods are used for setting and obtaining various - * parameters of the communication (timeouts, user - * certificates, limits). Both general methods (taking the - * symbolic name of the parameter as an argument) and - * convenience methods (for some parameters) are provided. - * - * The methods are local, no communication takes place. - */ - - friend class Job; - - /** Default constructor. - * - * Initializes the context to default values. - * \throws OSException Initialization failed. - */ - ServerConnection(void); - - /** DEPRECATED. - * - * \throws Exception Always. - */ - ServerConnection(const std::string &); - - /** DEPRECATED. - * - * \throws Exception Always. - */ - void open(const std::string &); - - /** DEPRECATED. - * - * \throws Exception Always. - */ - void close(void); - - /* END DEPRECATED */ - - /* set & get parameter methods */ - - /** Set bookkeeping server address. - * \ingroup property - * - * Directs the instance to query the given bookkeping server. - * \param[in] host Hostname of the server. - * \param[in] port Service port. - * \throws LoggingException Setting parameters failed. - */ - void setQueryServer(const std::string& host, int port); - - /** Set query timeout. - * \ingroup property - * - * Sets the time interval to wait for server response. - * \param[in] time Time in seconds before the query expires. - * \throws LoggingException Setting parameters failed. - */ - void setQueryTimeout(int time); - - /** Set user's proxy certificate. - * \ingroup property - * - * Instructs the instance to authenticate to the server using - * user's X509 proxy certificate. - * \param[in] proxy Name of file containing the user's proxy certificate. - * \throws LoggingException Setting paramater failed. - */ - void setX509Proxy(const std::string& proxy); - - /** Set user's certificate. - * \ingroup property - * - * Instructs the instance to authenticate to the server using - * users's full X509 certificate (which is not a good thing). - * \param[in] cert Name of file containing the user's certificate. - * \param[in] key Name of file containing the user's private - * key. - * \throws LoggingException Setting parameters failed. - */ - void setX509Cert(const std::string& cert, const std::string& key); - - /** Get address of the bookkeeping server. - * \ingroup property - * - * Returns address of the bookkeeping server this instance is - * bound to. - * \returns Address (hostname,port). - * \throws LoggingException Getting parameter failed. - */ - std::pair getQueryServer() const; - - /** Get query timeout. - * \ingroup property - * - * Returns the time interval this instance waits for server - * response. - * \returns Number of seconds to wait. - * \throws LoggingException Getting parameter failed. - */ - int getQueryTimeout() const; - - /** Get user's proxy. - * \ingroup property - * - * Returns filename of the user's X509 proxy certificate used - * to authenticate to the server. - * \returns Filename of the proxy certificate. - * \throws LoggingException Getting parameter failed. - */ - std::string getX509Proxy() const; - - /** Get user's X509 certificate. - * \ingroup property - * - * Returns filenames of the user's full X509 certificate used - * to authenticate to the server. - * \returns Pair of (certificate, key) filenames. - * \throws LoggingException Getting parameter failed. - */ - std::pair getX509Cert() const; - - /* end of set & get */ - - /** Destructor. - * - * Closes the connections and frees the context. - */ - virtual ~ServerConnection(); - - - /* consumer API */ - - /** Retrieve the set of single indexed attributes. - * \ingroup query - * - * Returns the set of attributes that are indexed on the - * server. Every query must contain at least one indexed - * attribute for performance reason; exception to this rule - * requires setting appropriate paramater on the server and is - * not advised. - * - * In the vector returned, outer elements correspond to indices, - * inner vector elements correspond to index - * columns. - * If .first of the pair is USERTAG, .second is its name; - * if .first is TIME, .second is state name - * otherwise .second is meaningless (empty string anyway). - */ - std::vector > > - getIndexedAttrs(void); - - /* Retrieve hard and soft result set size limit. - * \ingroup property - * - * Returns both the hard and soft limit on the number of - * results returned by the bookkeeping server. - * \returns Pair (hard, soft) of limits. - * \throws - */ - // std::pair getLimits(void) const; - - /** Set the soft result set size limit. - * \ingroup property - * - * Sets the maximum number of results this instance is willing - * to obtain when querying for jobs. - * \param max Maximum number of results. - * \throws LoggingException Setting parameter failed. - */ - void setQueryJobsLimit(int max); - - /** Set the soft result set size limit. - * \ingroup property - * - * Sets the maximum number of results this instance is willing - * to obtain when querying for Events. - * \param max Maximum number of results. - * \throws LoggingException Setting parameter failed. - */ - void setQueryEventsLimit(int max); - - /** Retrieve all events satisfying the query records. - * \ingroup query - * - * Returns all events belonging to the jobs specified by \arg - * job_cond and in addition satisfying the \arg event_cond. - * \param[in] job_cond Conjunctive query on jobs. - * \param[in] event_cond Conjunctive query on events. - * \param[out] events Vector of Event objects representing L&B - * events. - * \throws LoggingException Query failed. - */ - void queryEvents(const std::vector& job_cond, - const std::vector& event_cond, - std::vector& events) const; - - /** Convenience form of queryEvents. - * - */ - const std::vector queryEvents(const std::vector& job_cond, - const std::vector& event_cond) const; - - /** Another modification of queryEvents. - * - * The same method, but the results are returned as a list - * instead of vector. - */ - const std::list queryEventsList(const std::vector& job_cond, - const std::vector& event_cond) const; - - - /** NOT IMPLEMENTED. - * \param[in] job_cond - * \param[in] event_cond Vectors of conditions to be satisfied - * by jobs as a whole or particular events. - * \param[in] op Aggregate operator to apply. - * \param[in] attr Attribute to apply the operation to. - */ - std::string queryEventsAggregate(const std::vector& job_cond, - const std::vector& event_cond, - enum AggOp const op, - std::string const attr) const; - - - /** Retrieve all events satisfying the conjunctive-disjunctive - * query. - * - * Returns all events belonging to the jobs specified by - * job_cond and satisfying query_cond. The - * conditions are given in conjunctive-disjunctive form - * ((cond1 OR cond2 OR ...) AND ...) - * \param[in] job_cond Vector of conditions on jobs. - * \param[in] event_cond Vector of coditions on events. - * \param[out] eventList Returned Event's. - * \throws LoggingException Query failed. - */ - void queryEvents(const std::vector >& job_cond, - const std::vector >& event_cond, - std::vector& eventList) const; - - /** Convenience form of queryEvents. - * - * The same as previous, but the resulting vector is passed as - * a return value. - */ - const std::vector - queryEvents(const std::vector >& job_cond, - const std::vector >& event_cond) const; - - - /** Retrieve jobs satisfying the query. - * - * Finds all jobs (represented as JobId's) satisfying given - * query. - * \param[in] query Query in conjunctive form. - * \param[out] jobList List of job id's. - * \throws LoggingException Query failed. - */ - void queryJobs(const std::vector& query, - std::vector& jobList) const; - - /** Convenience form of queryJobs. - * - * The same as above, but job id's are passed as a return - * value. - */ - const std::vector - queryJobs(const std::vector& query) const; - - - /** Retrieve jobs satisfying the query. - * - * Finds all jobs satisfying query given in - * conjunctive-disjunctive form. - * \param[in] query Conjunction of disjunctive queries. - * \param[out] jobList Job id's of found jobs. - * \throws LoggingException Query failed. - */ - void queryJobs(const std::vector >& query, - std::vector& jobList) const; - - /** Convenience form of queryJobs. - * - * Same as above, but result is passed as a retutrn value. - */ - const std::vector - queryJobs(const std::vector >& query) const; - - /** Retrieve status of jobs satisfying the given simple query. - * - * Returns states (represented by JobStatus) of all jobs - * satisfying the query in conjunctive form. - * \param[in] query Condition on jobs. - * \param[in] flags The same as Job::status() flags. - * \param[out] states States of jobs satysfying the condition. - * \throws LoggingException Query failed. - */ - void queryJobStates(const std::vector& query, - int flags, - std::vector & states) const; - - /** Convenience form of queryJobStates. - * - * Same as above, but the result is passed as a return value. - */ - const std::vector queryJobStates(const std::vector& query, - int flags) const; - - /** Convenience form of queryJobStates. - * - * Same as above, but results are returned as list instead of - * vector. - */ - const std::list queryJobStatesList(const std::vector& query, - int flags) const; - - /** Retrieve status of jobs satisfying the given - * conjunctive-disjunctive query. - * - * Returns states (represented by JobStatus) of all jobs - * satisfying the query in conjunctive form. - * \param[in] query Condition on jobs. - * \param[in] flags The same as Job::status() flags. - * \param[out] states States of jobs satysfying the condition. - * \throws LoggingException Query failed. - */ - void queryJobStates(const std::vector >& query, - int flags, - std::vector & states) const; - - /** Convenience form of queryJobStates. - * - * Same as above, but the result is passed as a return value. - */ - const std::vector - queryJobStates(const std::vector >& query, - int flags) const; - - /** Return states of all user's jobs. - * - * Convenience wrapper around queryJobStates, returns status of all - * jobs whose owner is the current user (as named in the X509 - * certificate subject). - * \param[out] stateList States of jobs owned by this user. - * \throws LoggingException Query failed. - */ - void userJobStates(std::vector& stateList) const; - const std::vector userJobStates() const; - - - /** Find all user's jobs. - * - * Convenience wrapper around queryJobs, returns id's of all - * jobs whose owner is the current user (as named in the X509 - * certificate subject). - * \param[out] jobs Id's of jobs owned by this user. - * \throws LoggingException Query failed. - */ - void userJobs(std::vector &jobs) const; - - /** Convenience form of userJobs. - * - * Same as above, but results are passed as a return value. - */ - const std::vector userJobs() const; - - /** Set communication parameters of integer type. - * - * Sets the named parameter to the given integer value. - * \param[in] name Symbolic name of the parameter. - * \param[in] value Value. - * \throws LoggingException Setting parameter failed. - * \see edg_wll_SetParam() - */ - void setParam(edg_wll_ContextParam name, int value); - - /** Set communication parameters of string type. - * - * Sets the named parameter to the given string value. - * \param[in] name Symbolic name of the parameter. - * \param[in] value Value. - * \throws LoggingException Setting parameter failed. - * \see edg_wll_SetParam() - */ - void setParam(edg_wll_ContextParam name, const std::string &value); - - /** Set communication parameters of timeval type. - * - * Sets the named parameter to the given timeval value. - * \param[in] name Symbolic name of the parameter. - * \param[in] value Value. - * \throws LoggingException Setting parameter failed. - * \see edg_wll_SetParam() - */ - void setParam(edg_wll_ContextParam name, const struct timeval &value); - - /** Get communication parameters of integer type. - * - * Gets the named parameter of integer type. - * \param[in] name Symbolic name of the parameter. - * \throws LoggingException Getting parameter failed. - * \see edg_wll_GetParam() - */ - int getParamInt(edg_wll_ContextParam name) const; - - /** Get communication parameters of string type. - * - * Gets the named parameter of string type. - * \param[in] name Symbolic name of the parameter. - * \throws LoggingException Getting parameter failed. - * \see edg_wll_GetParam() - */ - std::string getParamString(edg_wll_ContextParam name) const; - - /** Get communication parameters of timeval type. - * - * Gets the named parameter of timeval type. - * \param[in] name Symbolic name of the parameter. - * \throws LoggingException Getting parameter failed. - * \see edg_wll_GetParam() - */ - struct timeval getParamTime(edg_wll_ContextParam name) const; - -protected: - - edg_wll_Context getContext(void) const; - -private: - edg_wll_Context context; -}; - -EWL_END_NAMESPACE - -#endif /* GLITE_LB_SERVERCONNECTION_HPP */ diff --git a/org.glite.lb.client/interface/connection.h b/org.glite.lb.client/interface/connection.h deleted file mode 100644 index 5bd330d..0000000 --- a/org.glite.lb.client/interface/connection.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef GLITE_LB_CONNECTION_H -#define GLITE_LB_CONNECTION_H - -#ident "$Header$" - -int edg_wll_close(edg_wll_Context ctx,int *); -int edg_wll_open(edg_wll_Context ctx,int *); -int edg_wll_accept(edg_wll_Context ctx, int fd); -int edg_wll_http_send_recv(edg_wll_Context, char *, const char * const *, char *, char **, char ***, char **); - -int edg_wll_close_proxy(edg_wll_Context ctx); -int edg_wll_open_proxy(edg_wll_Context ctx); -int edg_wll_http_send_recv_proxy(edg_wll_Context, char *, const char * const *, char *, char **, char ***, char **); - -int http_check_status(edg_wll_Context, char *); - -int ConnectionIndex(edg_wll_Context ctx, const char *name, int port); -int AddConnection(edg_wll_Context ctx, char *name, int port); -int ReleaseConnection(edg_wll_Context ctx, char *name, int port); -int CloseConnection(edg_wll_Context ctx, int conn_index); -int CloseConnectionNotif(edg_wll_Context ctx); - -#define PROXY_CONNECT_RETRY 10 /* ms */ - - -#endif /* GLITE_LB_CONNECTION_H */ diff --git a/org.glite.lb.client/interface/consumer.h b/org.glite.lb.client/interface/consumer.h deleted file mode 100644 index fe78142..0000000 --- a/org.glite.lb.client/interface/consumer.h +++ /dev/null @@ -1,336 +0,0 @@ -#ifndef GLITE_LB_CONSUMER_H -#define GLITE_LB_CONSUMER_H - -/*! - * \file consumer.h - * \brief L&B consumer API - */ - -#ident "$Header$" - -#include "glite/jobid/cjobid.h" -#include "glite/lb/context.h" -#include "glite/lb/events.h" -#include "glite/lb/jobstat.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#include "glite/lb/query_rec.h" - -/** - * \defgroup Functions for Server querying - * \brief The core part of the LB querying API. - * - * The functions in this part of the API are responsible for - * transforming the user query to the LB protocol, contacting the server, - * receiving back the response and transforming back the results to the - * API data structures. - * - * General rules: - * - functions return 0 on success, nonzero on error, errror details can - * be found via edg_wll_ErrorCode() - * - OUT are ** types, functions malloc()-ate objects and fill in the pointer - * pointed to by the OUT argument - * - returned lists of pointers are NULL-terminated malloc()-ed arrays - * - edg_wll_Query + wrapper terminate arrays with EDG_WLL_EVENT_UNDEF event - * - OUT is NULL if the list is empty - *@{ - */ - -/** - * General query on events. - * Return events satisfying all conditions - * query records represent conditions in the form - * \a attr \a op \a value eg. time > 87654321. - * \see edg_wll_QueryRec - * - * \param[in] context context to work with - * \param[in] job_conditions query conditions (ANDed) on current job status, null (i.e. ATTR_UNDEF) terminated list. NULL means empty list, i.e. always TRUE - * \param[in] event_conditions conditions on events, null terminated list, NULL means empty list, i.e. always TRUE - * \param[out] events list of matching events - */ -int edg_wll_QueryEvents( - edg_wll_Context context, - const edg_wll_QueryRec * job_conditions, - const edg_wll_QueryRec * event_conditions, - edg_wll_Event ** events -); - -/** - * Extended event query interface. - * Similar to \ref edg_wll_QueryEvents but the conditions are nested lists. - * Elements of the inner lists have to refer to the same attribute and they - * are logically ORed. - * The inner lists themselves are logically ANDed then. - */ - -int edg_wll_QueryEventsExt( - edg_wll_Context context, - const edg_wll_QueryRec ** job_conditions, - const edg_wll_QueryRec ** event_conditions, - edg_wll_Event ** events -); - - -/** - * Query LBProxy and use plain communication - * \warning edg_wll_*Proxy() functions are not implemented in release 1. - */ -int edg_wll_QueryEventsProxy( - edg_wll_Context context, - const edg_wll_QueryRec * job_conditions, - const edg_wll_QueryRec * event_conditions, - edg_wll_Event ** events -); - -/** - * \warning edg_wll_*Proxy() functions are not implemented in release 1. - */ - -int edg_wll_QueryEventsExtProxy( - edg_wll_Context context, - const edg_wll_QueryRec ** job_conditions, - const edg_wll_QueryRec ** event_conditions, - edg_wll_Event ** events -); - -/** - * General query on jobs. - * Return jobs (and possibly their states) for which an event satisfying the conditions - * exists. - * \see edg_wll_QueryEvents - * \param[in] context context to work with - * \param[in] conditions query records (ANDed), null (i.e. EDG_WLL_ATTR_UNDEF) terminated list - * \param[in] flags additional status fields to retrieve (\see edg_wll_JobStatus) - * \param[out] jobs list of job ids. May be NULL. - * \param[out] states list of corresponding states (returned only if not NULL) - */ -int edg_wll_QueryJobs( - edg_wll_Context context, - const edg_wll_QueryRec * conditions, - int flags, - edg_wlc_JobId ** jobs, - edg_wll_JobStat ** states -); - -/** - * Extended job query interface. - * Similar to \ref edg_wll_QueryJobs but the conditions are nested lists. - * Elements of the inner lists have to refer to the same attribute and they - * are logically ORed. - * The inner lists themselves are logically ANDed then. - */ - - -int edg_wll_QueryJobsExt( - edg_wll_Context context, - const edg_wll_QueryRec ** conditions, - int flags, - edg_wlc_JobId ** jobs, - edg_wll_JobStat ** states -); - - -/** - * Query LBProxy and use plain communication - * \warning edg_wll_*Proxy() functions are not implemented in release 1. - */ -int edg_wll_QueryJobsProxy( - edg_wll_Context context, - const edg_wll_QueryRec * conditions, - int flags, - edg_wlc_JobId ** jobs, - edg_wll_JobStat ** states -); - -/** - * \warning edg_wll_*Proxy() functions are not implemented in release 1. - */ - -int edg_wll_QueryJobsExtProxy( - edg_wll_Context context, - const edg_wll_QueryRec ** conditions, - int flags, - edg_wlc_JobId ** jobs, - edg_wll_JobStat ** states -); - -/** Return status of a single job. - * \param[in] context context to operate on - * \param[in] jobid query this job - * \param[in] flags specifies optional status fields to retrieve, - * \see EDG_WLL_STAT_CLASSADS, EDG_WLL_STAT_CHILDREN, EDG_WLL_STAT_CHILDSTAT - * \param[out] status status - */ - -int edg_wll_JobStatus( - edg_wll_Context context, - glite_jobid_const_t jobid, - int flags, - edg_wll_JobStat *status -); - -/** - * Query LBProxy and use plain communication - * \param[in] context context to operate on - * \param[in] jobid query this job - * \param[in] flags specifies optional status fields to retrieve, - * \see EDG_WLL_STAT_CLASSADS, EDG_WLL_STAT_CHILDREN, EDG_WLL_STAT_CHILDSTAT - * \param[out] status the status of the job - - * \warning edg_wll_*Proxy() functions are not implemented in release 1. - */ -int edg_wll_JobStatusProxy( - edg_wll_Context context, - glite_jobid_const_t jobid, - int flags, - edg_wll_JobStat *status -); - -/** - * Return all events related to a single job. - * Convenience wrapper around edg_wll_Query() - * \param[in] context context to work with - * \param[in] jobId job to query - * \param[out] events list of events - */ - -int edg_wll_JobLog( - edg_wll_Context context, - glite_jobid_const_t jobId, - edg_wll_Event ** events -); - - -/** - * Query LBProxy and use plain communication - * \warning edg_wll_*Proxy() functions are not implemented in release 1. - - */ -int edg_wll_JobLogProxy( - edg_wll_Context context, - glite_jobid_const_t jobId, - edg_wll_Event ** events -); - -/** - * All current user's jobs. - * \param[in] context context to work with - * \param[out] jobs list of the user's jobs - * \param[out] states list of the jobs' states - */ -int edg_wll_UserJobs( - edg_wll_Context context, - edg_wlc_JobId ** jobs, - edg_wll_JobStat ** states -); - - -/** - * Query LBProxy and use plain communication - * \warning edg_wll_*Proxy() functions are not implemented in release 1. - - */ -int edg_wll_UserJobsProxy( - edg_wll_Context context, - edg_wlc_JobId ** jobs, - edg_wll_JobStat ** states -); - -/** - * Server supported indexed attributes - * \see DataGrid-01-TEN-0125 - * \param[in] context context to work with - * \param[out] attrs configured indices (each index is an UNDEF-terminated - * array of QueryRec's from which only attr (and attr_id - * eventually) are meaningful - */ -int edg_wll_GetIndexedAttrs( - edg_wll_Context context, - edg_wll_QueryRec ***attrs -); - -/** - * Retrieve limit on query result size (no. of events or jobs). - * \warning not implemented. - * \see DataGrid-01-TEN-0125 - * \param[in] context context to work with - * \param[out] limit server imposed limit - */ -int edg_wll_GetServerLimit( - edg_wll_Context context, - int *limit -); - -/** - * UI port for intactive jobs. Used internally by WMS. - * \param[in] context context to work with - * \param[in] jobId job to query - * \param[in] name name of the UI-port - * \param[out] host hostname of port - * \param[out] port port number - */ -int edg_wll_QueryListener( - edg_wll_Context context, - edg_wlc_JobId jobId, - const char * name, - char ** host, - uint16_t * port -); - - -/** - * Query LBProxy and use plain communication - */ -int edg_wll_QueryListenerProxy( - edg_wll_Context context, - edg_wlc_JobId jobId, - const char * name, - char ** host, - uint16_t * port -); - -/** - * Ask LB Proxy server for sequence number - * \param[in] context context to work with - * \param[in] jobId job to query - * \param[out] code sequence code - */ - - -int edg_wll_QuerySequenceCodeProxy( - edg_wll_Context context, - glite_jobid_const_t jobId, - char ** code -); - -/* - *@} end of group - */ - -#ifdef CLIENT_SBIN_PROG -extern int edg_wll_http_send_recv( - edg_wll_Context, - char *, const char * const *, char *, - char **,char ***,char ** -); - -extern int http_check_status( - edg_wll_Context, - char * -); - -extern int set_server_name_and_port( - edg_wll_Context, - const edg_wll_QueryRec ** -); - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* GLITE_LB_CONSUMER_H */ diff --git a/org.glite.lb.client/interface/notification.h b/org.glite.lb.client/interface/notification.h deleted file mode 100644 index add5370..0000000 --- a/org.glite.lb.client/interface/notification.h +++ /dev/null @@ -1,191 +0,0 @@ -#ifndef GLITE_LB_NOTIFICATION_H -#define GLITE_LB_NOTIFICATION_H - -#ident "$Header$" - -#include "glite/jobid/cjobid.h" -#include "glite/lb/notifid.h" -#include "glite/lb/notif_rec.h" -#include "glite/lb/context.h" - -#ifdef BUILDING_LB_CLIENT -#include "consumer.h" -#else -#include "glite/lb/consumer.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** allocate memory for notification buffer using block of size XY -*/ -#define NOTIF_POOL_BUFFER_BLOCK_SIZE 16384 - -/** - * \defgroup notifications Notifications handling - * \brief Notifications handling. - *@{ - */ - -/** Register for receiving notifications. - * Connects to the server specified by EDG_WLL_NOTIF_SERVER context parameter - * (temporary workaround, should be resolved by registry in future). - * \param[in,out] context context to work with - * \param[in] conditions the same conditions as for \ref edg_wll_QueryJobsExt. - * currently one or more JOBID's are required. - * Only a single occurence of a specific attribute is allowed - * among ANDed conditions (due to the ability to modify them - * further). - * \param[in] flags verbosity of notifications - 0 - send basic job status info - EDG_WLL_STAT_CLASSADS - send also JDL in job status - * \param[in] fd = -1 create or reuse the default listening socket (one per context) - * >= 0 non-default listening socket - * \param[in] address_override if not NULL, use this address instead of extracting it - * from the connection (useful when multiple interfaces are present, - * circumventing NAT problems etc.) - * \param[in,out] valid until when the registration is valid - in: requested validity (NULL means 'give me server defaults') - out: value really set on the server - * \param[out] id_out returened NotifId - * the value - * \retval 0 OK - * \retval EINVAL restrictions on conditions are not met - * - */ -int edg_wll_NotifNew( - edg_wll_Context context, - edg_wll_QueryRec const * const *conditions, - int flags, - int fd, - const char *address_override, - edg_wll_NotifId *id_out, - time_t *valid -); - - -/** Change the receiving local address. - * Report the new address to the server. - * - * \param[in,out] context context to work with - * \param[in] id notification ID you are binding to - * \param[in] fd same as for \ref edg_wll_NotifNew - * \param[in] address_override same as for \ref edg_wll_NotifNew - * \param[in,out] valid same as for \ref edg_wll_NotifNew - */ - -int edg_wll_NotifBind( - edg_wll_Context context, - const edg_wll_NotifId id, - int fd, - const char *address_override, - time_t *valid -); - -/** Modify the query conditions for this notification. - * - * If op is either EDG_WLL_NOTIF_ADD or EDG_WLL_NOTIF_REMOVE, for the sake - * of uniqueness the original conditions must have contained only a single - * OR-ed row of conditions on the attributes infolved in the change. - * - * \param[in,out] context context to work with - * \param[in] id notification ID you are working with - * \param[in] conditions same as for \ref edg_wll_NotifNew - * \param[in] op action to be taken on existing conditions, - * \see edg_wll_NotifChangeOp (defined in common notif_rec.h) - */ -int edg_wll_NotifChange( - edg_wll_Context context, - const edg_wll_NotifId id, - edg_wll_QueryRec const * const * conditions, - edg_wll_NotifChangeOp op -); - -/** Refresh the registration, i.e. extend its validity period. - * \param[in,out] context context to work with - * \param[in] id notification ID you are working with - * \param[in,out] valid same as for \ref edg_wll_NotifNew - */ - -int edg_wll_NotifRefresh( - edg_wll_Context context, - const edg_wll_NotifId id, - time_t *valid -); - -/** Drop the registration. - * Server is instructed not to send notifications anymore, pending ones - * are discarded, listening socket is closed, and allocated memory freed. - * \param[in,out] context context to work with - * \param[in] id notification ID you are working with - */ - -int edg_wll_NotifDrop( - edg_wll_Context context, - edg_wll_NotifId id -); - -/** Receive notification. - * The first incoming notification is returned. - * \param[in,out] context context to work with - * \param[in] fd receive on this socket (-1 means the default for the context) - * \param[in] timeout wait atmost this time long. (0,0) means polling, NULL waiting - * indefinitely - * \param[out] state_out returned JobStatus - * \param[out] id_out returned NotifId - * \retval 0 notification received, state_out contains the current job state - * \retval EAGAIN no notification available, timeout occured - */ - -int edg_wll_NotifReceive( - edg_wll_Context context, - int fd, - const struct timeval *timeout, - edg_wll_JobStat *state_out, - edg_wll_NotifId *id_out -); - - -/** Default socket descriptor where to select(2) for notifications. - * Even if nothing is available for reading from the socket, - * there may be some data cached so calling \ref edg_wll_NotifReceive - * may return notifications immediately. - * - * \param[in,out] context context to work with - * \retval >=0 socket descriptor - * \retval -1 error, details set in context - */ - -int edg_wll_NotifGetFd( - edg_wll_Context context -); - -/** Close the default local listening socket. - * Useful to force following \ref edg_wll_NotifBind to open - * a new one. - * \param[in,out] context context to work with - */ - -int edg_wll_NotifCloseFd( - edg_wll_Context context -); - -/** Close all connections in notifPool and free it. - * \param[in,out] context context to work with - */ - -int edg_wll_NotifClosePool( - edg_wll_Context context -); - - -/* - *@} end of group - */ - -#ifdef __cplusplus -} -#endif - -#endif /* GLITE_LB_NOTIFICATION_H */ diff --git a/org.glite.lb.client/interface/prod_proto.h b/org.glite.lb.client/interface/prod_proto.h deleted file mode 100644 index 9014259..0000000 --- a/org.glite.lb.client/interface/prod_proto.h +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef GLITE_LB_PROD_PROTO_H -#define GLITE_LB_PROD_PROTO_H - -#ident "$Header$" - -#ifdef __cplusplus -extern "C" { -#endif - -#include "glite/security/glite_gss.h" -#include "glite/lb/log_proto.h" -#include "glite/lb/context-int.h" - -#define PROXY_CONNECT_RETRY 10 /* ms */ - -/** - * connect to local-logger - * \param[in,out] ctx context to work with - * \param[out] conn opened connection (index in the connection pool) - * \return errno - */ -int edg_wll_log_connect(edg_wll_Context ctx, int *conn); - -/** - * close connection to local-logger - * \param[in,out] ctx context to work with - * \param[in] conn opened connection - * \return errno - */ -int edg_wll_log_close(edg_wll_Context ctx, int conn); - -/** - * write/send to local-logger - * \param[in,out] ctx context to work with - * \param[in] conn connection to use - * \param[in] logline message to send - * \return the number of bytes written (zero indicates nothing was written) or -1 on error - */ -int edg_wll_log_write(edg_wll_Context ctx, int conn, edg_wll_LogLine logline); - -/** - * read/receive answer (stored in context) from local-logger - * \param[in,out] ctx context to work with - * \param[in] conn connection to use - * \return the number of bytes read (zero indicates nothing was read) or -1 on error - */ -int edg_wll_log_read(edg_wll_Context ctx, int conn); - - -/** - * connect to lbproxy - * \param[in,out] ctx context to work with - * \param[out] conn opened connection - * \return errno - */ -int edg_wll_log_proxy_connect(edg_wll_Context ctx, edg_wll_PlainConnection *conn); - -/** - * close connection to lbproxy - * \param[in,out] ctx context to work with - * \param[out] conn opened connection - * \return errno - */ -int edg_wll_log_proxy_close(edg_wll_Context ctx, edg_wll_PlainConnection *conn); - -/** - * write/send to lbproxy - * \param[in,out] ctx context to work with - * \param[in] conn connection to use - * \param[in] logline message to send - * \return the number of bytes written (zero indicates nothing was written) or -1 on error - */ -int edg_wll_log_proxy_write(edg_wll_Context ctx, edg_wll_PlainConnection *conn, edg_wll_LogLine logline); - -/** - * read/receive from lbproxy - * \param[in,out] ctx context to work with - * \param[in] conn connection to use - * \return the number of bytes read (zero indicates nothing was read) or -1 on error - */ -int edg_wll_log_proxy_read(edg_wll_Context ctx, edg_wll_PlainConnection *conn); - - -/** - * connect to bkserver - * \param[in,out] ctx context to work with - * \param[out] conn opened connection - * \return errno - */ -int edg_wll_log_direct_connect(edg_wll_Context ctx, edg_wll_GssConnection *conn); - -/** - * close connection to bkserver - * \param[in,out] ctx context to work with - * \param[out] conn opened connection - * \return errno - */ -int edg_wll_log_direct_close(edg_wll_Context ctx, edg_wll_GssConnection *conn); - -/** - * write/send to bkserver - * \param[in,out] ctx context to work with - * \param[in] conn connection to use - * \param[in] logline message to send - * \return the number of bytes written (zero indicates nothing was written) or -1 on error - */ -int edg_wll_log_direct_write(edg_wll_Context ctx, edg_wll_GssConnection *conn, edg_wll_LogLine logline); - -/** - * read/receive from bkserver - * \param[in,out] ctx context to work with - * \param[in] conn connection to use - * \return the number of bytes read (zero indicates nothing was read) or -1 on error - */ -int edg_wll_log_direct_read(edg_wll_Context ctx, edg_wll_GssConnection *conn); - -#ifdef __cplusplus -} -#endif - -#endif /* GLITE_LB_PROD_PROTO_H */ diff --git a/org.glite.lb.client/interface/producer.h.T b/org.glite.lb.client/interface/producer.h.T deleted file mode 100644 index 470383f..0000000 --- a/org.glite.lb.client/interface/producer.h.T +++ /dev/null @@ -1,361 +0,0 @@ -#ifndef GLITE_LB_PRODUCER_H -#define GLITE_LB_PRODUCER_H - -/** - * \file producer.h - * \brief client API for storing data into L&B service - */ - -#ident "$Header$" -/* -@@@AUTO -*/ -@@@LANG: C - -#ifdef __cplusplus -extern "C" { -#endif - -#include "glite/lb/context.h" -#include "glite/lb/events.h" - -/* Event sources: */ - -#if 0 /* obsolete */ -#define EDG_WLL_SOURCE_UI "UserInterface" -#define EDG_WLL_SOURCE_RB "ResourceBroker" -#define EDG_WLL_SOURCE_JSS "JobSubmissionService" /* aka Condor-G */ -#define EDG_WLL_SOURCE_JOBMGR "GlobusJobmanager" -#define EDG_WLL_SOURCE_LRMS "LocalResourceManager" -#define EDG_WLL_SOURCE_APP "Application" - -#define EDG_WLL_SOURCE_NS "NetworkServer" -#define EDG_WLL_SOURCE_WM "WorkloadManager" -#define EDG_WLL_SOURCE_BH "BigHelper" -#define EDG_WLL_SOURCE_LM "LogMonitor" - -#endif - -/* edg_wll_LogEvent shortcuts */ -@@@{ -$PRINTPROTOTYPESONLY = 1; -$PRINTDOC = 1; - -require '../src/uiwrap.T'; - -@@@} - - -/** - * Formats a logging message and sends it asynchronously to local-logger - * \brief generic asynchronous logging function - * \param[in,out] context context to work with, - * \param[in] event type of the event, - * \param[in] fmt printf()-like format string, - * \param[in] ... event specific values/data according to fmt, - * \retval 0 successful completition, - * \retval EINVAL bad jobId, unknown event code, or the format string together with the remaining arguments does not form a valid event, - * \retval ENOSPC L&B infrastructure failed to accept the event due to lack of disk space etc., - * \retval ENOMEM failed to allocate memory, - * \retval ECONNREFUSED cannot connect to the specified local logger, - * \retval EAGAIN non blocking return from the call, the event may or may not get logged, - * \retval EDG_WLL_ERROR_NOJOBID logging call attempted without assigning jobId to the context. - */ -extern int edg_wll_LogEvent( - edg_wll_Context context, - edg_wll_EventCode event, - char *fmt, ...); - -/** - * Formats a logging message and sends it synchronously to local-logger - * \brief generic synchronous logging function - * \param[in,out] context context to work with, - * \param[in] event type of the event, - * \param[in] fmt printf()-like format string, - * \param[in] ... event specific values/data according to fmt, - * \retval 0 successful completition, - * \retval EINVAL bad jobId, unknown event code, or the format string together with the remaining arguments does not form a valid event, - * \retval ENOSPC L&B infrastructure failed to accept the event due to lack of disk space etc., - * \retval ENOMEM failed to allocate memory, - * \retval ECONNREFUSED cannot connect to the specified local logger, - * \retval EAGAIN non blocking return from the call, the event may or may not get logged, - * \retval EDG_WLL_ERROR_NOJOBID logging call attempted without assigning jobId to the context, - * \retval EPERM the user is not authorized to add events to this job, - * \retval EDG_WLL_ERROR_DB_DUP_KEY exactly the same event has been already stored. - */ -extern int edg_wll_LogEventSync( - edg_wll_Context context, - edg_wll_EventCode event, - char *fmt, ...); - -/** - * Formats a logging message and sends it synchronously to L&B Proxy - * \brief generic synchronous logging function - * \param[in,out] context context to work with, - * \param[in] event type of the event, - * \param[in] fmt printf()-like format string, - * \param[in] ... event specific values/data according to fmt, - * \retval 0 successful completition, - * \retval EINVAL bad jobId, unknown event code, or the format string together with the remaining arguments does not form a valid event, - * \retval ENOSPC L&B infrastructure failed to accept the event due to lack of disk space etc., - * \retval ENOMEM failed to allocate memory, - * \retval ECONNREFUSED cannot connect to the specified L&B Proxy - * \retval EAGAIN non blocking return from the call, the event may or may not get logged, - * \retval EDG_WLL_ERROR_NOJOBID logging call attempted without assigning jobId to the context. - */ -extern int edg_wll_LogEventProxy( - edg_wll_Context context, - edg_wll_EventCode event, - char *fmt, ...); - -/** - * Instructs interlogger to to deliver all pending events related to current job - * \brief flush events from interlogger - * \note sort of status query more than a command - * \param[in,out] context context to work with, - * \param[in,out] timeout wait at most this much time for completition, remaining time on return, - * \retval 0 successful completition, - * \retval EDG_WLL_ERROR_INTERLOG_TIMEOUT the inter-logger did not respond within the timeout, - * \retval EDG_WLL_ERROR_INTERLOG_CONLOST inter-logger lost connection to one or more servers, - * \retval EDG_WLL_ERROR_INTERLOG_AGAIN not all pending events were delivered within the timeout. - */ -extern int edg_wll_LogFlush( - edg_wll_Context context, - struct timeval *timeout); - - -/** - * Instructs interlogger to to deliver all pending events - * \brief flush all events from interlogger - * \note same as edg_wll_LogFlush() for all jobs known to interlogger - * \see edg_wll_LogFlush() - */ -extern int edg_wll_LogFlushAll( - edg_wll_Context context, - struct timeval *timeout); - -/** - * Set a current job for given context. - * \note Should be called before any logging call. - * \param[in,out] context context to work with - * \param[in] job further logging calls are related to this job - * \param[in] code sequence code as obtained from previous component - * \param[in] flags flags on code handling (\see API documentation) - */ -extern int edg_wll_SetLoggingJob( - edg_wll_Context context, - glite_jobid_const_t job, - const char * code, - int flags -); - -/** - * Set a current job for given context. - * \note Should be called before any logging call. - * \param[in,out] context context to work with - * \param[in] job further logging calls are related to this job - * \param[in] code sequence code as obtained from previous component - * \param[in] user user credentials - * \param[in] flags flags on code handling (\see API documentation) - */ -extern int edg_wll_SetLoggingJobProxy( - edg_wll_Context context, - glite_jobid_const_t job, - const char * code, - const char * user, - int flags -); - -/** - * Register job with L&B service. - * Done via logging REGJOB event, may generate subjob id's and create - * the parent-children associations. - * Set the job as current for the context and initialize sequence code. - * - * Partitionable jobs should set num_subjobs=0 initially, - * and re-register when number of subjobs becomes known. - * - * \param[in,out] context context to work with - * \param[in] job jobId - * \param[in] type EDG_WLL_JOB_SIMPLE, EDG_WLL_JOB_DAG, or EDG_WLL_JOB_PARTITIONABLE - * \param[in] jdl user-specified JDL - * \param[in] ns network server contact - * \param[in] num_subjobs number of subjobs to create - * \param[in] seed seed used for subjob id's generator. - * Use non-NULL value to be able to regenerate the set of jobid's - * \param[out] subjobs returned subjob id's - */ - -/* backward compatibility */ -#define EDG_WLL_JOB_SIMPLE EDG_WLL_REGJOB_SIMPLE - -extern int edg_wll_RegisterJob( - edg_wll_Context context, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs -); - -/** - * Synchronous variant of edg_wll_RegisterJob - */ - -extern int edg_wll_RegisterJobSync( - edg_wll_Context context, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs -); - -/** - * Register job with L&B Proxy service. - * Done via logging REGJOB event, may generate subjob id's and create - * the parent-children associations. - * Set the job as current for the context and initialize sequence code. - * - * Partitionable jobs should set num_subjobs=0 initially, - * and re-register when number of subjobs becomes known. - * - * \param[in,out] context context to work with - * \param[in] job jobId - * \param[in] type EDG_WLL_JOB_SIMPLE, EDG_WLL_JOB_DAG, or EDG_WLL_JOB_PARTITIONABLE - * \param[in] jdl user-specified JDL - * \param[in] ns network server contact - * \param[in] num_subjobs number of subjobs to create - * \param[in] seed seed used for subjob id's generator. - * Use non-NULL value to be able to regenerate the set of jobid's - * \param[out] subjobs returned subjob id's - */ - -extern int edg_wll_RegisterJobProxy( - edg_wll_Context context, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs -); - -#ifdef LB_PERF -/* original register to LBProxy */ -extern int edg_wll_RegisterJobProxyOld( - edg_wll_Context context, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs -); - -/* register only to LBProxy */ -/* useful for performance measurements */ - -extern int edg_wll_RegisterJobProxyOnly( - edg_wll_Context context, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs -); -#endif - - - -/** - * Register subjobs in a batch. - * Mainly used to provide JDL's of individual subjobs in a more efficient - * way than logging them one by one. - * \param[in,out] context context to work with - * \param[in] parent parent's jobId - * \param[in] jdls array of JDL's - * \param[in] ns network server contact - * \param[in] subjobs array of jobid's in the same order - */ - -extern int edg_wll_RegisterSubjobs( - edg_wll_Context context, - glite_jobid_const_t parent, - char const * const * jdls, - const char * ns, - edg_wlc_JobId const * subjobs -); - - -/** - * Register subjobs to LB Proxyin a batch. - * Mainly used to provide JDL's of individual subjobs in a more efficient - * way than logging them one by one. - * \param[in,out] context context to work with - * \param[in] parent parent's jobId - * \param[in] jdls array of JDL's - * \param[in] ns network server contact - * \param[in] subjobs array of jobid's in the same order - */ - -extern int edg_wll_RegisterSubjobsProxy( - edg_wll_Context context, - glite_jobid_const_t parent, - char const * const * jdls, - const char * ns, - edg_wlc_JobId const * subjobs -); - -/** - * Generate or regenerate set of subjob ID's. - * Calls the same algorithm used to generate subjob ID's in edg_wll_RegisterJob(). - * Local semantics only, server is not contacted. - */ - -extern int edg_wll_GenerateSubjobIds( - edg_wll_Context context, - glite_jobid_const_t parent, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs -); - - -/** - * Change ACL for given job. - * \param[in,out] context context to work with - * \param[in] job jobId - * \param[in] user_id specification of user's credential - * \param[in] user_id_type type of user_id, - * for EDG_WLL_USER_SUBJECT the user_id parameter is expected to be user's subject name - * for EDG_WLL_USER_VOMS_GROUP the user_id is expected to be of the form VO:group specifying required group membersip as managed by VOMS - * \param[in] permission ACL permission to change - * \param[in] permission_type type of given permission (allow or deny operation) - * \param[in] operation operation to perform with ACL (add or remove record) - */ - -extern int edg_wll_ChangeACL( - edg_wll_Context context, - glite_jobid_const_t job, - const char * user_id, - enum edg_wll_ChangeACLUser_id_type user_id_type, - enum edg_wll_ChangeACLPermission permission, - enum edg_wll_ChangeACLPermission_type permission_type, - enum edg_wll_ChangeACLOperation operation -); - - -#ifdef __cplusplus -} -#endif - -#endif /* GLITE_LB_PRODUCER_H */ diff --git a/org.glite.lb.client/interface/stat_fields.h b/org.glite.lb.client/interface/stat_fields.h deleted file mode 100644 index a4ea8d7..0000000 --- a/org.glite.lb.client/interface/stat_fields.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -char * glite_lb_parse_stat_fields(const char *,void **); -void glite_lb_print_stat_fields(void **,edg_wll_JobStat *); -void glite_lb_dump_stat_fields(void); - -#include - -static char *TimeToStr(time_t t) -{ - struct tm *tm = gmtime(&t); - static char tbuf[1000]; - - sprintf(tbuf,"'%4d-%02d-%02d %02d:%02d:%02d UTC'", - tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, - tm->tm_hour,tm->tm_min,tm->tm_sec); - - return tbuf; -} - - -#ifdef __cplusplus -} -#endif diff --git a/org.glite.lb.client/interface/statistics.h b/org.glite.lb.client/interface/statistics.h deleted file mode 100644 index 3c193d6..0000000 --- a/org.glite.lb.client/interface/statistics.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef GLITE_LB_STATISTICS_H -#define GLITE_LB_STATISTICS_H - -#ifdef BUILDING_LB_CLIENT -#include "consumer.h" -#else -#include "glite/lb/consumer.h" -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/** Count the number of jobs which entered the specified state. - * \param[in] group group of jobs of interest, eg. DESTINATION = something - * (XXX: this is the only query supported right now) - * \param[in] major major code of the state of interest - * \param[in] minor minor state code, eg. DONE_FAILED - * \param[in,out] from,to on input - requested interval of interest - * on output - when the data were available - * \param[out] rate average rate per second in which the jobs enter this state - * \param[out] res_from,res_to time resolution of the data (seconds) - */ - -int edg_wll_StateRate( - 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 -); - - -/** Compute average time for which jobs stay in the specified state. - * \see edg_wll_StateRate for description of parameters. - */ - -int edg_wll_StateDuration( - 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 -); - - - -#ifdef __cplusplus -} -#endif - -#endif /* GLITE_LB_CONSUMER_H */ diff --git a/org.glite.lb.client/m4/glite_lb_client.m4 b/org.glite.lb.client/m4/glite_lb_client.m4 deleted file mode 100755 index f04dca8..0000000 --- a/org.glite.lb.client/m4/glite_lb_client.m4 +++ /dev/null @@ -1,129 +0,0 @@ -dnl Usage: -dnl AC_GLITE_LB -dnl - GLITE_LB_THR_CLIENT_LIBS -dnl - GLITE_LB_THR_CLIENTPP_LIBS -dnl - GLITE_LB_THR_COMMON_LIBS -dnl - GLITE_LB_NOTHR_CLIENT_LIBS -dnl - GLITE_LB_NOTHR_CLIENTPP_LIBS -dnl - GLITE_LB_NOTHR_COMMON_LIBS -dnl - GLITE_STATIC_LB_NOTHR_CLIENT_LIBS -dnl - GLITE_STATIC_LB_NOTHR_COMMON_LIBS - -AC_DEFUN([AC_GLITE_LB], -[ - ac_glite_lb_prefix=$GLITE_LOCATION - - AC_SEC_GSOAP_PLUGIN - - if test -n "ac_glite_lb_prefix" ; then - dnl - dnl - dnl - ac_glite_lb_lib="-L$ac_glite_lb_prefix/%LIBDIR%" - GLITE_LB_THR_CLIENT_LIBS="$ac_glite_lb_lib -lglite_lb_client_$GLOBUS_THR_FLAVOR" - GLITE_LB_THR_CLIENTPP_LIBS="$ac_glite_lb_lib -lglite_lb_clientpp_$GLOBUS_THR_FLAVOR" - GLITE_LB_THR_COMMON_LIBS="$ac_glite_lb_lib -lglite_lb_common_$GLOBUS_THR_FLAVOR $SEC_GSOAP_PLUGIN_GSS_THR_LIBS" - GLITE_LB_NOTHR_CLIENT_LIBS="$ac_glite_lb_lib -lglite_lb_client_$GLOBUS_NOTHR_FLAVOR" - GLITE_LB_NOTHR_CLIENTPP_LIBS="$ac_glite_lb_lib -lglite_lb_clientpp_$GLOBUS_NOTHR_FLAVOR" - GLITE_LB_NOTHR_COMMON_LIBS="$ac_glite_lb_lib -lglite_lb_common_$GLOBUS_NOTHR_FLAVOR $SEC_GSOAP_PLUGIN_GSS_NOTHR_LIBS" - GLITE_STATIC_LB_NOTHR_CLIENT_LIBS="$ac_glite_lb_prefix/%LIBDIR%/libglite_lb_client_$GLOBUS_NOTHR_FLAVOR.a" - GLITE_STATIC_LB_NOTHR_COMMON_LIBS="$ac_glite_lb_prefix/%LIBDIR%/libglite_lb_common_$GLOBUS_NOTHR_FLAVOR.a $SEC_GSOAP_PLUGIN_GSS_STATIC_NOTHR_LIBS" - ifelse([$2], , :, [$2]) - else - GLITE_LB_THR_CLIENT_LIBS="" - GLITE_LB_THR_CLIENTPP_LIBS="" - GLITE_LB_THR_COMMON_LIBS="" - GLITE_LB_NOTHR_CLIENT_LIBS="" - GLITE_LB_NOTHR_CLIENTPP_LIBS="" - GLITE_LB_NOTHR_COMMON_LIBS="" - GLITE_STATIC_LB_NOTHR_CLIENT_LIBS="" - GLITE_STATIC_LB_NOTHR_COMMON_LIBS="" - ifelse([$3], , :, [$3]) - fi - - AC_SUBST(GLITE_LB_THR_CLIENT_LIBS) - AC_SUBST(GLITE_LB_THR_CLIENTPP_LIBS) - AC_SUBST(GLITE_LB_THR_COMMON_LIBS) - AC_SUBST(GLITE_LB_NOTHR_CLIENT_LIBS) - AC_SUBST(GLITE_LB_NOTHR_CLIENTPP_LIBS) - AC_SUBST(GLITE_LB_NOTHR_COMMON_LIBS) - AC_SUBST(GLITE_STATIC_LB_NOTHR_CLIENT_LIBS) - AC_SUBST(GLITE_STATIC_LB_NOTHR_COMMON_LIBS) -]) - -AC_DEFUN([GLITE_CHECK_LB_CLIENT], -[AC_MSG_CHECKING([for org.glite.lb.client]) -save_CPPFLAGS=$CPPFLAGS -CPPFLAGS="$CPPFLAGS $GLITE_CPPFLAGS" -save_LDFLAGS=$LDFLAGS -LDFLAGS="$LDFLAGS $GLITE_LDFLAGS -L$GLOBUS_LOCATION/lib" -save_LIBS=$LIBS - -AC_LANG_PUSH([C]) - -# prepare the test program, to link against the different combinations -# of globus flavours - -AC_LANG_CONFTEST( - [AC_LANG_PROGRAM( - [@%:@include "glite/lb/consumer.h"], - [edg_wll_QueryEvents( - (edg_wll_Context)0, - (const edg_wll_QueryRec*)0, - (const edg_wll_QueryRec*)0, - (edg_wll_Event**)0 - );] - )] -) - -LIBS="-lglite_lb_client_$GLOBUS_THR_FLAVOR $LIBS" -AC_LINK_IFELSE([], - [AC_SUBST([GLITE_LB_CLIENT_THR_LIBS], [-lglite_lb_client_$GLOBUS_THR_FLAVOR])], - [AC_MSG_ERROR([cannot find org.glite.lb.client ($GLOBUS_THR_FLAVOR)])] -) -LIBS=$save_LIBS - -LIBS="-lglite_lb_client_$GLOBUS_NOTHR_FLAVOR $LIBS" -AC_LINK_IFELSE([], - [AC_SUBST([GLITE_LB_CLIENT_NOTHR_LIBS], [-lglite_lb_client_$GLOBUS_NOTHR_FLAVOR])], - [AC_MSG_ERROR([cannot find org.glite.lb.client ($GLOBUS_NOTHR_FLAVOR)])] -) -LIBS=$save_LIBS - -AC_LANG_POP([C]) - -AC_LANG_PUSH([C++]) - -# prepare the test program, to link against the different combinations -# of globus flavours - -AC_LANG_CONFTEST( - [AC_LANG_PROGRAM( - [@%:@include "glite/lb/Job.h"], - [glite::lb::Job job;] - )] -) - -save_LIBS=$LIBS -LIBS="-lglite_lb_clientpp_$GLOBUS_THR_FLAVOR $LIBS" -AC_LINK_IFELSE([], - [AC_SUBST([GLITE_LB_CLIENTPP_THR_LIBS], [-lglite_lb_clientpp_$GLOBUS_THR_FLAVOR])], - [AC_MSG_ERROR([cannot find org.glite.lb.client (C++ - $GLOBUS_THR_FLAVOR)])] -) -LIBS=$save_LIBS - -LIBS="-lglite_lb_clientpp_$GLOBUS_NOTHR_FLAVOR $LIBS" -AC_LINK_IFELSE([], - [AC_SUBST([GLITE_LB_CLIENTPP_NOTHR_LIBS], [-lglite_lb_clientpp_$GLOBUS_NOTHR_FLAVOR])], - [AC_MSG_ERROR([cannot find org.glite.lb.client (C++ - $GLOBUS_NOTHR_FLAVOR)])] -) -LIBS=$save_LIBS - -AC_LANG_POP([C++]) - -LDFLAGS="$save_LDFLAGS" -CPPFLAGS=$save_CPPFLAGS - -AC_MSG_RESULT([yes]) - -]) diff --git a/org.glite.lb.client/project/.cvsignore b/org.glite.lb.client/project/.cvsignore deleted file mode 100644 index 2b56473..0000000 --- a/org.glite.lb.client/project/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -MultiStruct.pm -StructField.pm -at3 -events.T -status.T -types.T diff --git a/org.glite.lb.client/project/ChangeLog b/org.glite.lb.client/project/ChangeLog deleted file mode 100644 index f08813f..0000000 --- a/org.glite.lb.client/project/ChangeLog +++ /dev/null @@ -1,62 +0,0 @@ -3.1.0-1 (lb-1.7.0-1) -- key connections in the pool also with certificate; allows using LB client - while swithing among multiple identities safely -- don't keep proxy connections at all (workaround bug #25153 with little - perfomance impact only) - -3.1.1-1 (lb-1.7.1-1) -- check for loaded credentials in connection pool management (avoid SEGV) -- minor fixes to manpage - -3.1.2-1 (lb-1.7.2-1) -- allow aditional options for purger (variables GLITE_LB_PURGE_OTHER_OPTIONS, - GLITE_LB_DUMP_EXPORTER_OTHER_OPTIONS -- pass errors from credential loading to upper layers properly - -3.1.2-2 (lb-1.7.4-1) -- rebuild wrt. downgraded security 3.1.57-1 - -3.1.3-1 (lb-1.7.5-1) -- align attr_names[] (used in getAttrName methods) in Event and JobStatus - to definitions in *.h from lb.client-interface - -3.1.4-1 -- do the previous quick fix thoroughly -- don't smash name_with_underscores - and nameWithUppercaseLetters - -3.2.0-1 (lb-1.8.0-1) -- added ui_host to jobstat -- store purge files (to be uploaded to JP) in GLITE_LOCATION_VAR rahter then GLITE_TMP - -3.2.1-1 -- use -1 as an invalid socken number instead of 0 -- handle errors generated by gss inquire credentials correctly (#37084) -- correctly release unused credentials (#37069) and reuse connection -- handle gss errors whene receiving notifications (#35118) -- fix producer connection management (re-establishing connections) (#37074) - -4.0.0-1 -- LB 2.0 release - -4.0.0-2 -- fixed configure to work in etics - -4.0.0-3 -- configure script update (globus flavors added to configure call) - -4.0.1-1 -- (from 3.2.2-1) Fix edg_wll_NotifDrop prototype (#34649). -- Notification pool implementation - -4.0.2-1 -- don't use hard-wired types for ACLs events but the ones generated automatically -- change_acl code adapted to the new API using generated types -- new options to the glite-lb-notify command - -4.0.3-1 -- Man page update -- Minor fixes in example builds -- stats extended for any job state - -4.0.3-2 -- install libraries into $libdir diff --git a/org.glite.lb.client/project/build.number b/org.glite.lb.client/project/build.number deleted file mode 100644 index 3a9ef16..0000000 --- a/org.glite.lb.client/project/build.number +++ /dev/null @@ -1,2 +0,0 @@ -#Fri Aug 18 12:27:36 CEST 2006 -module.build=0243 diff --git a/org.glite.lb.client/project/build.properties b/org.glite.lb.client/project/build.properties deleted file mode 100644 index e69de29..0000000 diff --git a/org.glite.lb.client/project/configure.properties.xml b/org.glite.lb.client/project/configure.properties.xml deleted file mode 100644 index f6ae77c..0000000 --- a/org.glite.lb.client/project/configure.properties.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - -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} -mysql_prefix=${with.mysql.prefix} -mysql_version=${ext.mysql.version} -cppunit_prefix=${with.cppunit.prefix} -thrflavour=${with.globus.thr.flavor} -nothrflavour=${with.globus.nothr.flavor} - - - diff --git a/org.glite.lb.client/project/package.description b/org.glite.lb.client/project/package.description deleted file mode 100644 index f32857d..0000000 --- a/org.glite.lb.client/project/package.description +++ /dev/null @@ -1 +0,0 @@ -glite-lb-client is the library implementing client side of gLite LB API. This package contains the library, client tools and many examples. diff --git a/org.glite.lb.client/project/package.summary b/org.glite.lb.client/project/package.summary deleted file mode 100644 index d8535e8..0000000 --- a/org.glite.lb.client/project/package.summary +++ /dev/null @@ -1 +0,0 @@ -gLite Logging and Bookkeeping client library and CLI tools diff --git a/org.glite.lb.client/project/properties.xml b/org.glite.lb.client/project/properties.xml deleted file mode 100755 index d067cbd..0000000 --- a/org.glite.lb.client/project/properties.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb.client/project/tar_exclude b/org.glite.lb.client/project/tar_exclude deleted file mode 100644 index e1fcd1a..0000000 --- a/org.glite.lb.client/project/tar_exclude +++ /dev/null @@ -1,10 +0,0 @@ -tar_exclude -CVS -build.xml -build -build.properties -properties.xml -configure.properties.xml -.cvsignore -.project -.cdtproject diff --git a/org.glite.lb.client/project/version.properties b/org.glite.lb.client/project/version.properties deleted file mode 100644 index 9f4af8d..0000000 --- a/org.glite.lb.client/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# $Header$ -module.version=4.0.3 -module.age=2 diff --git a/org.glite.lb.client/src/Event.cpp.T b/org.glite.lb.client/src/Event.cpp.T deleted file mode 100644 index 301d645..0000000 --- a/org.glite.lb.client/src/Event.cpp.T +++ /dev/null @@ -1,426 +0,0 @@ -/* -@@@AUTO -*/ - -#include -#include -#include -#include - -#include - -#include "glite/jobid/cjobid.h" - -#include "Event.h" -#include "glite/lb/events.h" -#include "glite/lb/notifid.h" -#include "glite/lb/LoggingExceptions.h" - -#include "consumer.h" - -EWL_BEGIN_NAMESPACE; - -#define CLASS_PREFIX "glite::lb::Event::" - -@@@{ - -require '../src/EventAttrNames.pl'; - -sub typeswitch { - my $ftype = shift; - my $resc = shift; - local $_; - my %ctype; - $ctype{$_} = 1 while $_ = shift; - - $resc = 'break;' unless $resc; - - gen $indent."switch (attr) {\n"; - selectType $event $ftype; - for (getFields $event) { - my $f = selectField $event $_; - if($ctype{$f->{type}}) { - my $cstr = $ftype eq '_common_' ? 'any' : lcfirst $ftype; - if ($cstr =~ m/^pBS/) { $cstr = ucfirst $cstr; } - if ($cstr =~ m/^condor/) { $cstr = ucfirst $cstr; } - my $cname = getName $f 'C'; - gen "$indent\tcase Event::".uc($f->{name}).": return(cev->$cstr.$cname);\n"; - } elsif (($f->{type} eq "int") && - ($ctype{"string"}) && - $f->{codes}) { - # conversion from int to string (well, enum to string) - my $cstr = $ftype eq '_common_' ? 'any' : lcfirst $ftype; - if ($cstr =~ m/^pBS/) { $cstr = ucfirst $cstr; } - if ($cstr =~ m/^condor/) { $cstr = ucfirst $cstr; } - my $cname = getName $f 'C'; - my $fn = $ftype eq '_common_' ? "" : ucfirst $ftype; - my $c = $fn . ucfirst $f->{name}; - $cast = ($c eq 'Level') ? "(edg_wll_Level)" : ""; - gen "$indent\tcase Event::".uc($f->{name}).": return((const char *)edg_wll_${c}ToString(${cast}cev->$cstr.$cname));\n"; - } elsif (($f->{type} eq "jobid") && - ($ctype{"string"})) { - # conversion from jobid to string - } - } - gen "$indent\tdefault: $resc\n" if $resc; - gen "$indent\}\n"; -} -@@@} - -Event::Event(void) -{ - type = UNDEF; - flesh = 0; -} - - -Event::Event(const Event &in) -{ - type = in.type; - flesh = in.flesh; - if (flesh) flesh->use(); -} - - -Event::Event(edg_wll_Event *in) -{ - type = (Type)in->type; - flesh = new CountRef((void*)in); -} - - -Event::~Event(void) -{ - if (flesh) flesh->release(); -} - - -Event & -Event::operator= (const Event &in) -{ - if (flesh) flesh->release(); - type = in.type; - flesh = in.flesh; - if (flesh) flesh->use(); - - return *this; -} - -int Event::getValInt(Attr attr) const -{ - edg_wll_Event const *cev = (edg_wll_Event *) flesh->ptr; - -@@@{ - $indent = "\t"; - typeswitch '_common_',undef,'int','port','logsrc'; -@@@} - - switch (cev->type) { -@@@{ - $indent = "\t\t"; - for my $t (getTypes $event) { - gen "\t\tcase ".uc($t).":\n"; - typeswitch $t,'goto badattr;','int','port','logsrc'; - } -@@@} - default: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, - "attribute is not of int type")); - } -badattr: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, ENOENT, "invalid attribute")); - return -1; /* gcc, shut up! */ -} - -float Event::getValFloat(Attr attr) const -{ - edg_wll_Event const *cev = (edg_wll_Event *) flesh->ptr; - -@@@{ - $indent = "\t"; - typeswitch '_common_',undef,'float'; -@@@} - - switch (cev->type) { -@@@{ - $indent = "\t\t"; - for my $t (getTypes $event) { - gen "\t\tcase ".uc($t).":\n"; - typeswitch $t,'goto badattr;','float'; - } -@@@} - default: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, - "attribute is not of float type")); - } -badattr: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, ENOENT, "invalid attribute")); - return -1; /* gcc, shut up! */ -} - -double Event::getValDouble(Attr attr) const -{ - edg_wll_Event const *cev = (edg_wll_Event *) flesh->ptr; - -@@@{ - $indent = "\t"; - typeswitch '_common_',undef,'double'; -@@@} - - switch (cev->type) { -@@@{ - $indent = "\t\t"; - for my $t (getTypes $event) { - gen "\t\tcase ".uc($t).":\n"; - typeswitch $t,'goto badattr;','double'; - } -@@@} - default: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, - "attribute is not of double type")); - } -badattr: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, ENOENT, "invalid attribute")); - return -1; /* gcc, shut up! */ -} - -static char const *get_string_val(const edg_wll_Event *cev, Event::Attr attr) -{ -@@@{ - $indent = "\t"; - typeswitch '_common_',undef,'string'; -@@@} - - switch (cev->type) { -@@@{ - $indent = "\t\t"; - for my $t (getTypes $event) { - gen "\t\tcase Event::".uc($t).":\n"; - typeswitch $t,'goto badattr;','string'; - } -@@@} - default: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, - "attribute is not of string type and can not be converted")); - } -badattr: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, ENOENT, "invalid attribute")); - return NULL; /* gcc, shut up! */ -} - - -std::string -Event::getValString(Attr attr) const -{ - edg_wll_Event const *cev = (edg_wll_Event *) flesh->ptr; - std::string ret; - - try { - char const *s = get_string_val(cev,attr); - if (s) ret.assign(s); - return ret; - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - - -struct timeval -Event::getValTime(Attr attr) const -{ - edg_wll_Event const *cev = (edg_wll_Event *) flesh->ptr; -@@@{ - $indent = "\t"; - typeswitch '_common_',undef,'timeval'; -@@@} - - /* XXX - * to make things simpler we don't include this here as there are no - * type specific timeval attributes currently - * - * switch (cev->type) { - */ - - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, ENOENT, "invalid attribute")); -} - -static -edg_wlc_JobId -get_val_jobid(edg_wll_Event const *cev, Event::Attr attr) -{ -@@@{ - $indent = "\t"; - typeswitch '_common_', undef,'jobid'; -@@@} - switch (cev->type) { -@@@{ - $indent = "\t\t"; - for my $t (getTypes $event) { - gen "\t\tcase Event::".uc($t).":\n"; - typeswitch $t,'goto badattr;','jobid'; - } -@@@} - default: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, - "attribute is not of jobid type")); - } -badattr: - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, ENOENT, "invalid attribute")); - return NULL; /* gcc, shut up! */ -} - -const -glite::jobid::JobId -Event::getValJobId(Attr attr) const -{ - edg_wll_Event const *cev = (edg_wll_Event *) flesh->ptr; - try { - edg_wlc_JobId job_id = get_val_jobid(cev,attr); - return(glite::jobid::JobId(job_id)); - } - catch (Exception &e) { - STACK_ADD; - throw; - } - -} - - -static std::string const names[Event::TYPE_MAX] = { - "undefined", -@@@{ - for (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } - $event->getTypes) - { - gen "\t\"$_\",\n"; - } -@@@} -}; - -const std::string & -Event::name(void) const -{ - if (type<0 || type>TYPE_MAX) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, "invalid event type")); - } - return names[type]; -} - - -static -std::string const attr_names[Event::ATTR_MAX] = { -@@@{ - my %s; - - for (getAllFields $event) { - my $id = $_; - $id =~ s/([a-z])([A-Z])/$1_$2/g; - $s{uc($id)} = $_; - $s{uc($_)} = $_; - } - for (@main::EventAttrNames) { - gen "\t\"$s{$_}\",\n"; - } -@@@} -}; - -const std::string & -Event::getAttrName(Attr attr) -{ - if (attr<0 || attr>=ATTR_MAX) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, "invalid attribute")); - } - return attr_names[attr]; -} - - -typedef std::pair tpair; -static std::vector attrs[Event::TYPE_MAX]; - -#define apush(etype,attr,atype) \ - attrs[etype].push_back(tpair(attr,atype)) - -static bool attrs_inited = false; - -static void init_attrs(void) -{ -@@@{ - for my $t (getTypes $event) { - my $tu = uc $t; - selectType $event '_common_'; - for (getFields $event) { - my $fu = uc $_; - my $f = selectField $event $_; - my $ftu = uc "$f->{type}_T"; - gen "\tapush(Event::$tu,Event::$fu,Event::$ftu);\n"; - } - selectType $event $t; - for (getFields $event) { - my $fu = uc $_; - my $f = selectField $event $_; - my $ftu = uc "$f->{type}_T"; - gen "\tapush(Event::$tu,Event::$fu,Event::$ftu);\n"; - } - } -@@@} -} - -std::vector > const & Event::getAttrs(void) const -{ - if (type<0 || type>=TYPE_MAX) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, "invalid event type")); - } - - /* FIXME: thread safety */ - if (!attrs_inited) { - init_attrs(); - attrs_inited = true; - } - - return attrs[type]; -} - - -const std::string Event::getEventName(Type type) -{ - char *s; - - if(type < 0 || type >= TYPE_MAX) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, "invalid event type")); - } - - s = edg_wll_EventToString(edg_wll_EventCode(type)); - if (!s) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, EINVAL, "invalid event type")); - } - std::string ret(s); - free(s); - return ret; -} - - -void -Event::destroyFlesh(void *in) -{ - edg_wll_FreeEvent((edg_wll_Event *) in); - free(in); -} - -EWL_END_NAMESPACE; diff --git a/org.glite.lb.client/src/EventAttrNames.pl b/org.glite.lb.client/src/EventAttrNames.pl deleted file mode 100644 index a2720e1..0000000 --- a/org.glite.lb.client/src/EventAttrNames.pl +++ /dev/null @@ -1,84 +0,0 @@ -# The order of strings in this array determines assigned numeric value in the Event::Attr enum. -# It must not be changed unless API major number is incremented - -@main::EventAttrNames = qw/ - ARRIVED - CHILD - CHILD_EVENT - CLASSAD - DESCR - DEST_HOST - DEST_ID - DEST_INSTANCE - DEST_JOBID - DEST_PORT - DESTINATION - DONE_CODE - ERROR_DESC - EXIT_CODE - EXIT_STATUS - FROM - FROM_HOST - FROM_INSTANCE - HELPER_NAME - HELPER_PARAMS - HISTOGRAM - HOST - JDL - JOB - JOBID - JOB_EXIT_STATUS - JOB_PID - JOBSTAT - JOBTYPE - LEVEL - LOCAL_JOBID - NAME - NODE - NOTIFID - NS - NSUBJOBS - OPERATION - OWNER - PARENT - PERMISSION - PERMISSION_TYPE - PID - PREEMPTING - PRIORITY - QUANTITY - QUEUE - REASON - RESOURCE - RESULT - RETVAL - SCHEDULER - SEED - SEQCODE - SHADOW_EXIT_STATUS - SHADOW_HOST - SHADOW_PID - SHADOW_PORT - SHADOW_STATUS - SOURCE - SRC_INSTANCE - SRC_ROLE - STARTER_EXIT_STATUS - STARTER_PID - STATE - STATUS_CODE - SVC_HOST - SVC_NAME - SVC_PORT - TAG - TIMESTAMP - UNIT - UNIVERSE - USAGE - USER - USER_ID - USER_ID_TYPE - VALUE - WN_SEQ - EXPIRES -/; diff --git a/org.glite.lb.client/src/Job.cpp b/org.glite.lb.client/src/Job.cpp deleted file mode 100644 index fed330c..0000000 --- a/org.glite.lb.client/src/Job.cpp +++ /dev/null @@ -1,203 +0,0 @@ -#ident "$Header$" - -/** - * @file Job.cpp - * @version $Revision$ - */ - - -#include -#include -#include - -#include - -#include "Job.h" -#include "consumer.h" -#include "glite/lb/LoggingExceptions.h" -#include "glite/lb/context-int.h" - -EWL_BEGIN_NAMESPACE; - -#define CLASS_PREFIX "glite::lb::Job::" - -const int Job::STAT_CLASSADS = EDG_WLL_STAT_CLASSADS; -const int Job::STAT_CHILDREN = EDG_WLL_STAT_CHILDREN; -const int Job::STAT_CHILDSTAT = EDG_WLL_STAT_CHILDSTAT; - -Job::Job(void) - : jobId() -{ -} - - -Job::Job(const glite::jobid::JobId &in) - : jobId(in) -{ -} - - -Job::~Job(void) -{ -} - - -Job & Job::operator= (const glite::jobid::JobId &in) -{ - try { - jobId = in; - return *this; - } catch (Exception &) { - STACK_ADD; - throw; - } -} - - -JobStatus -Job::status(int flags) const -{ - JobStatus jobStatus; - - try { - edg_wll_JobStat *cstat = jobStatus.c_ptr(); - int ret = edg_wll_JobStatus(server.getContext(), - const_cast(jobId.c_jobid()), - flags, - cstat); - check_result(ret, - server.getContext(), - "edg_wll_JobStatus"); - -/* XXX the enums match due to automatic generation */ - jobStatus.status = (JobStatus::Code) cstat->state; - - return(jobStatus); - - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - - -void -Job::log(std::vector &eventList) const -{ - edg_wll_Event *events = NULL,*ev; - int result, qresults_param; - char *errstr = NULL; - edg_wll_Context context; - - try { - context = server.getContext(); - result = edg_wll_JobLog(context, const_cast(jobId.c_jobid()), &events); - if (result == E2BIG) { - edg_wll_Error(context, NULL, &errstr); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_RESULTS, &qresults_param), - context, - "edg_wll_GetParam(EDG_WLL_PARAM_QUERY_RESULTS)"); - if (qresults_param != EDG_WLL_QUERYRES_LIMITED) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_JobLog"); - } - } else { - check_result(result, context,"edg_wll_JobLog"); - } - - for (int i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++) { - ev = (edg_wll_Event *) malloc(sizeof *ev); - memcpy(ev,events+i,sizeof *ev); - eventList.push_back(Event(ev)); - } - - free(events); - - if (result) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_JobLog"); - } - } catch (Exception &e) { - if(errstr) free(errstr); - - STACK_ADD; - throw; - } - -} - - -const std::vector -Job::log(void) const -{ - std::vector eventList; - - log(eventList); - return(eventList); -} - - -const std::pair -Job::queryListener(std::string const & name) const -{ - std::string host; - char *c_host = NULL; - uint16_t port; - - try { - int ret = edg_wll_QueryListener(server.getContext(), - const_cast(jobId.c_jobid()), - name.c_str(), - &c_host, - &port); - check_result(ret, - server.getContext(), - "edg_wll_QueryListener"); - - host = c_host; - free(c_host); - return(std::pair(host,port)); - - } catch (Exception &e) { - if(c_host) free(c_host); - STACK_ADD; - throw; - } -} - - -void Job::setParam(edg_wll_ContextParam par, int val) -{ - server.setParam(par,val); -} - -void Job::setParam(edg_wll_ContextParam par, const std::string val) -{ - server.setParam(par,val); -} - -void Job::setParam(edg_wll_ContextParam par, const struct timeval & val) -{ - server.setParam(par,val); -} - - -int Job::getParamInt(edg_wll_ContextParam par) const -{ - return server.getParamInt(par); -} - -std::string Job::getParamString(edg_wll_ContextParam par) const -{ - return server.getParamString(par); -} - -struct timeval Job::getParamTime(edg_wll_ContextParam par) const -{ - return server.getParamTime(par); -} - - - -EWL_END_NAMESPACE; diff --git a/org.glite.lb.client/src/JobStatus.cpp.T b/org.glite.lb.client/src/JobStatus.cpp.T deleted file mode 100644 index c84c7e6..0000000 --- a/org.glite.lb.client/src/JobStatus.cpp.T +++ /dev/null @@ -1,516 +0,0 @@ -#include -#include -#include -#include -#include - -#include "glite/jobid/JobId.h" -#include "glite/lb/LoggingExceptions.h" - -#include "consumer.h" -#include "JobStatus.h" - - -EWL_BEGIN_NAMESPACE; - -#define CLASS_PREFIX "glite::lb::JobStatus::" - -@@@{ - -require '../src/StatusAttrNames.pl'; - -sub typeswitch { - my ($ftype,$ctype,$resc) = @_; - local $_; - - $resc = "break;" unless $resc; - - gen $indent."switch (attr) {\n"; - selectType $status $ftype; - for (getFields $status) { - my $f = selectField $status $_; - if($f->{type} eq $ctype) { - my $fnu = $f->{name}; - $fnu =~ s/([a-z])([A-Z])/$1_$2/g; - $fnu = uc $fnu; - my $cname = getName $f 'C'; - gen "$indent\tcase JobStatus::$fnu: return cstat->$cname;\n" - }; - # XXX: when there are conversion functions, we may get these as strings as well - #elsif (($f->{type} eq "int") && - # ($ctype eq "string") && - # $f->{codes}) { - # my $fnu = $f->{name}; - # $fnu =~ s/([a-z])([A-Z])/$1_$2/g; - # $fnu = uc $fnu; - # my $cname = getName $f 'C'; - # my $fn = $ftype eq '_common_' ? "" : ucfirst $ftype; - # my $c = $fn . ucfirst $f->{name}; - # $cast = ($c eq 'Level') ? "(edg_wll_Level)" : ""; - # gen "$indent\tcase JobStatus::$fnu: return((const char *)edg_wll_${c}ToString(${cast}cstat->$cname));\n"; } - } - gen "$indent\tdefault: $resc\n" if $resc; - gen "$indent\}\n"; -} -@@@} - -JobStatus::JobStatus(void) -{ - status = UNDEF; - flesh = 0; -} - -JobStatus::JobStatus(const JobStatus & in) -{ - status = in.status; - flesh = in.flesh; - if (flesh) flesh->use(); -} - -JobStatus & -JobStatus::operator=(const JobStatus & in) -{ - if (flesh) flesh->release(); - status = in.status; - flesh = in.flesh; - if (flesh) flesh->use(); - return *this; -} - -JobStatus::JobStatus(const edg_wll_JobStat & in,int destroy) -{ - status = (Code)in.state; - flesh = new CountRef((void*)&in); - if (!destroy) flesh->use(); -} - -JobStatus & -JobStatus::operator=(const edg_wll_JobStat & in) -{ - if(flesh) - flesh->release(); - status = (Code)in.state; - flesh = new CountRef((void*)&in); - return(*this); -} - -JobStatus::~JobStatus() -{ - if (flesh) flesh->release(); -} - -edg_wll_JobStat * -JobStatus::c_ptr(void) -{ - edg_wll_JobStat *s; - - if(flesh) - return((edg_wll_JobStat*)flesh->ptr); - - s = new edg_wll_JobStat; - // XXX - is it neccessary? new should throw exception itself... - if(!s) throw(Exception(EXCEPTION_MANDATORY, - ENOMEM, - "out of memory allocating c-struct for JobStatus")); - - edg_wll_InitStatus(s); - flesh = new CountRef((void*)s); - return(s); -} - - -static std::string const names[JobStatus::CODE_MAX] = { - "undefined", -@@@{ - for (sort { $status->{order}->{$a} <=> $status->{order}->{$b} } - $status->getTypes) - { - gen "\t\"$_\",\n"; - } -@@@} -}; - -const std::string& JobStatus::name(void) const -{ - if (status<0 || status>=CODE_MAX) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - EINVAL, - "status code invalid")); - } - return names[status]; -} - -int JobStatus::getValInt(JobStatus::Attr attr) const -{ - edg_wll_JobStat const *cstat = (edg_wll_JobStat *) flesh->ptr; -@@@{ - $indent = "\t"; - typeswitch '_common_','int'; -@@@} - - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); - return -1; /* make gcc shut up -- never returns */ -} - -bool JobStatus::getValBool(JobStatus::Attr attr) const -{ - edg_wll_JobStat const *cstat = (edg_wll_JobStat *) flesh->ptr; -@@@{ - $indent = "\t"; - typeswitch '_common_','bool'; -@@@} - - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); - return -1; /* make gcc shut up -- never returns */ -} - -static const char * -get_string_val(const edg_wll_JobStat *cstat,JobStatus::Attr attr) -{ -@@@{ - $indent = "\t"; - typeswitch '_common_','string'; -@@@} - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); - return 0; /* make gcc shut up -- never returns */ -} - -std::string -JobStatus::getValString(JobStatus::Attr attr) const -{ - edg_wll_JobStat const *cstat = (edg_wll_JobStat *) flesh->ptr; - std::string ret; - - try{ - const char *s = get_string_val(cstat,attr); - if (s) ret.assign(s); - return ret; - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - - -struct timeval -JobStatus::getValTime(Attr attr) const -{ - edg_wll_JobStat const *cstat = (edg_wll_JobStat *) flesh->ptr; - -@@@{ - $indent = "\t"; - typeswitch '_common_','timeval'; -@@@} - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); -} - - -const -edg_wlc_JobId -get_val_jobid(edg_wll_JobStat const *cstat, JobStatus::Attr attr) -{ -@@@{ - $indent = "\t"; - typeswitch '_common_','jobid'; -@@@} - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); - return 0; /* make gcc shut up -- never returns */ -} - - -const -glite::jobid::JobId -JobStatus::getValJobId(Attr attr) const -{ - edg_wll_JobStat const *cstat = (edg_wll_JobStat *) flesh->ptr; - - try { - edg_wlc_JobId job_id = get_val_jobid(cstat, attr); - return(glite::jobid::JobId(job_id)); - } - catch(Exception &e) { - STACK_ADD; - throw; - } -} - -const -int * -get_val_intlist(edg_wll_JobStat const *cstat, JobStatus::Attr attr) -{ -@@@{ - $indent = "\t"; - typeswitch '_common_','intlist'; -@@@} - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); - return 0; /* make gcc shut up -- never returns */ -} - - -const -std::vector -JobStatus::getValIntList(Attr attr) const -{ - edg_wll_JobStat const *cstat = (edg_wll_JobStat *) flesh->ptr; - - std::vector result; - const int *r; - - try { - r = get_val_intlist(cstat, attr); - if(r) - for(int i = 1; i <= r[0]; i++) - result.push_back(r[i]); - } catch(Exception &e) { - STACK_ADD; - throw; - } - return result; -} - - -char ** const -get_val_stringlist(edg_wll_JobStat const *cstat, JobStatus::Attr attr) -{ -@@@{ - $indent = "\t"; - typeswitch '_common_','strlist'; -@@@} - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); - return 0; /* make gcc shut up -- never returns */ -} - - -const -std::vector -JobStatus::getValStringList(Attr attr) const -{ - edg_wll_JobStat const *cstat = (edg_wll_JobStat *) flesh->ptr; - - std::vector result; - char **r , **p; - - try { - r = (char**)get_val_stringlist(cstat, attr); - if(r) - for(p = r; *p; p++) - result.push_back(std::string(*p)); - } catch(Exception &e) { - STACK_ADD; - throw; - } - return result; -} - - -edg_wll_TagValue * const -get_val_taglist(edg_wll_JobStat const *cstat, JobStatus::Attr attr) -{ -@@@{ - $indent = "\t"; - typeswitch '_common_','taglist'; -@@@} - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); - return 0; /* make gcc shut up -- never returns */ -} - - -const -std::vector > -JobStatus::getValTagList(Attr attr) const -{ - edg_wll_JobStat const *cstat = (edg_wll_JobStat *) flesh->ptr; - - std::vector > result; - edg_wll_TagValue *r , *p; - - try { - r = get_val_taglist(cstat, attr); - if(r) - for(p = r; p->tag ; p++) - result.push_back(std::pair - (std::string(p->tag),std::string(p->value))); - } catch(Exception &e) { - STACK_ADD; - throw; - } - return result; -} - - -const -edg_wll_JobStat * -get_val_stslist(edg_wll_JobStat const *cstat, JobStatus::Attr attr) -{ -@@@{ - $indent = "\t"; - typeswitch '_common_','stslist'; -@@@} - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); - return 0; /* make gcc shut up -- never returns */ -} - - -const -std::vector -JobStatus::getValJobStatusList(Attr attr) const -{ - edg_wll_JobStat const *cstat = (edg_wll_JobStat *) flesh->ptr; - - std::vector result; - const edg_wll_JobStat *r, *p; - - try { - r = get_val_stslist(cstat, attr); - if(r) - for(p=r; p->state != EDG_WLL_JOB_UNDEF; p++) { - edg_wll_JobStat *jsep = new edg_wll_JobStat; - if (!edg_wll_CpyStatus(p,jsep)) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOMEM, - "cannot copy edg_wll_JobStat")); - } - result.push_back(JobStatus(*jsep)); - } - } catch(Exception &e) { - STACK_ADD; - throw; - } - return(result); -} - - -static std::string const attr_names[JobStatus::ATTR_MAX] = { -@@@{ - my %s; - - for (getAllFields $status) { - my $id = $_; - $id =~ s/([a-z])([A-Z])/$1_$2/g; - $s{uc($id)} = $_; - $s{uc($_)} = $_; - } - for (@main::StatusAttrNames) { - gen "\t\"$s{$_}\",\n"; - } -@@@} -}; - -const std::string & -JobStatus::getAttrName(JobStatus::Attr attr) -{ - if (attr<0 || attr>=ATTR_MAX) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - ENOENT, - "no such attribute")); - } - - return attr_names[attr]; -} - -JobStatus::Attr JobStatus::attrByName(std::string const & name) -{ - int a; - for (a=0; a tpair; -static std::vector attrs; - -static bool attrs_inited = false; - -static void init_attrs(void) -{ -/* XXX: currently only common attributes in JobStatus */ -@@@{ - selectType $status '_common_'; - for (getFields $status) { - my $fu = $_; - my $f = selectField $status $_; - my $ftu = uc "$f->{type}_T"; - $fu =~ s/([a-z])([A-Z])/$1_$2/g; - $fu = uc $fu; - - gen "\tattrs.push_back(tpair(JobStatus::$fu,JobStatus::$ftu));\n"; - } -@@@} -} - - -const std::vector& -JobStatus::getAttrs(void) const -{ - if (status<0 || status>=CODE_MAX) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - EINVAL, - "status code invalid")); - } - -/* FIXME: thread safety */ - if (!attrs_inited) { - init_attrs(); - attrs_inited = true; - } - return attrs; -} - -const std::string & -JobStatus::getStateName(Code state) -{ - if (state<0 || state>=CODE_MAX) { - STACK_ADD; - throw(Exception(EXCEPTION_MANDATORY, - EINVAL, - "status code invalid")); - } - return names[state]; -} - - -void -JobStatus::destroyFlesh(void *p) -{ - edg_wll_JobStat *stat = (edg_wll_JobStat *) p; - if (stat) { - edg_wll_FreeStatus(stat); - free(stat); - } -} - -EWL_END_NAMESPACE; diff --git a/org.glite.lb.client/src/Notification.cpp b/org.glite.lb.client/src/Notification.cpp deleted file mode 100644 index d0c1ea7..0000000 --- a/org.glite.lb.client/src/Notification.cpp +++ /dev/null @@ -1,340 +0,0 @@ -#ident "$Header$" - -/** - * @file Notification.cpp - * @version $Revision$ - */ - -#include -#include -#include - -#include -#include - -#include "Notification.h" -#include "JobStatus.h" -#include "glite/lb/LoggingExceptions.h" -#include "ServerConnection.h" - -#include "glite/lb/notifid.h" -#include "notification.h" - -EWL_BEGIN_NAMESPACE; - -#define CLASS_PREFIX "glite::lb::Notification::" - -/* external prototypes */ -extern edg_wll_QueryRec ** -convertQueryVectorExt(const std::vector > &); - -extern void -freeQueryRecVector(edg_wll_QueryRec *); - -/* Constructors */ -Notification::Notification(void) -{ - try { - int ret = edg_wll_InitContext(&this->ctx); - check_result(ret,this->ctx,"edg_wll_InitContext"); - this->notifId = NULL; - this->valid = 0; - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - -Notification::Notification(const std::string notifid_str) -{ - try { - char *host; - unsigned int port; - int ret = edg_wll_InitContext(&this->ctx); - check_result(ret,this->ctx,"edg_wll_InitContext"); - ret = edg_wll_NotifIdParse(notifid_str.c_str(),&this->notifId); - check_result(ret,this->ctx,"edg_wll_NotifIdParse"); - edg_wll_NotifIdGetServerParts(this->notifId,&host,&port); - edg_wll_SetParam(this->ctx, EDG_WLL_PARAM_NOTIF_SERVER, host); - edg_wll_SetParam(this->ctx, EDG_WLL_PARAM_NOTIF_SERVER_PORT, port); - free(host); - this->valid = 0; - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - -Notification::Notification(const std::string host,const u_int16_t port) -{ - try { - int ret = edg_wll_InitContext(&ctx); - check_result(ret,ctx,"edg_wll_InitContext"); - edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER, host.c_str()); - edg_wll_SetParam(ctx, EDG_WLL_PARAM_NOTIF_SERVER_PORT, port); - this->notifId = NULL; - this->valid = 0; - check_result(ret,ctx,"edg_wll_NotifIdCreate"); - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - -/* Destructor */ -Notification::~Notification(void) -{ - try { - edg_wll_FreeContext(this->ctx); - edg_wll_NotifIdFree(this->notifId); - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - -/* Methods */ -std::string -Notification::getNotifId(void) const -{ - try { - std::string notifid_str; - if (this->notifId != NULL) { - notifid_str = edg_wll_NotifIdUnparse(this->notifId); - return(notifid_str); - } else { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "notifId not known at the moment"); - } - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - -time_t -Notification::getValid(void) const -{ - return(this->valid); -} - -int -Notification::getFd(void) const -{ - try { - int ret = edg_wll_NotifGetFd(this->ctx); - check_result(ret,this->ctx,"edg_wll_NotifGetFd"); - return(ret); - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - -void -Notification::addJob(const glite::jobid::JobId &jobId) -{ - std::vector::iterator it; - - try { - if (this->notifId != NULL) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "adding jobs allowed only before registering"); - } - for( it = jobs.begin(); it != jobs.end(); it++ ) { - if ( (*it).toString() == jobId.toString() ) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "job already exists"); - } - } - jobs.push_back(jobId); - - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - -void -Notification::removeJob(const glite::jobid::JobId &jobId) -{ - std::vector::iterator it; - int removed = 0; - - try { - if (this->notifId != NULL) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "removing jobs allowed only before registering"); - } - for( it = jobs.begin(); it != jobs.end(); it++ ) { - if ( (*it).toString() == jobId.toString() ) { - jobs.erase(it); - removed += 1; -// break; - } - } - } catch (Exception &e) { - STACK_ADD; - throw; - } - - if (removed == 0) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "no job to remove"); - } -} - -/* XXX: obsolete, used only for debugging purposes */ - -std::string -Notification::getJobs(void) -{ - std::vector::iterator it; - std::string ret=""; - - try { - for( it = jobs.begin(); it != jobs.end(); it++ ) { - ret += (*it).toString(); - ret += "\n"; - } - return ret; - - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - -void -Notification::setStates(const std::vector &jobStates) -{ - if (this->notifId != NULL) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "removing jobs allowed only before registering"); - } - states = jobStates; -} - -std::string -Notification::getStates(void) -{ - std::vector::iterator it; - JobStatus js; - std::string ret=""; - - try { - for( it = states.begin(); it != states.end(); it++ ) { - js.status = (*it); - ret += js.name(); - ret += "\n"; - } - return ret; - - } catch (Exception &e) { - STACK_ADD; - throw; - } -} - -void -Notification::Register(void) -{ - int ret = 0; - std::vector::iterator it; - std::vector::iterator its; - std::vector > queryExt; - edg_wll_QueryRec **conditions = NULL; - unsigned i; - - try { - if (this->notifId != NULL) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "registering job allowed only once"); - } - /* fill in the query: */ - std::vector query; - for( it = jobs.begin(); it != jobs.end(); it++ ) { - QueryRecord r0(QueryRecord::JOBID,QueryRecord::EQUAL,*it); - query.push_back(r0); - } - queryExt.push_back(query); - query.clear(); - - for( its = states.begin(); its != states.end(); its++ ) { - QueryRecord r(QueryRecord::STATUS,QueryRecord::EQUAL,*its); - query.push_back(r); - } - queryExt.push_back(query); - - /* convert query to conditions */ - conditions = convertQueryVectorExt(queryExt); - /* register */ - ret = edg_wll_NotifNew(ctx,conditions,0,-1,NULL,¬ifId,&valid); - check_result(ret,ctx,"edg_wll_NotifNew"); - /* clean */ - if (conditions) { - for( i = 0; conditions[i]; i++ ) { -// FIXME: not working :o( -// freeQueryRecVector(conditions[i]); - delete[] conditions[i]; - } - delete[] conditions; - } - } catch (Exception &e) { - /* clean */ - if (conditions) { - for( i = 0; conditions[i]; i++ ) { -// FIXME: not working :o( -// freeQueryRecVector(conditions[i]); - delete[] conditions[i]; - } - delete[] conditions; - } - STACK_ADD; - throw; - } -} - -void -Notification::Bind(const std::string address_override) -{ - try { - if (this->notifId == NULL) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "binding allowed only for given notifId"); - } - int ret = edg_wll_NotifBind(this->ctx,this->notifId,-1,address_override.c_str(),&this->valid); - check_result(ret,this->ctx,"edg_wll_NotifBind"); - } - catch (Exception &e) { - STACK_ADD; - throw; - } -} - - - - -int Notification::receive(glite::lb::JobStatus &jobStatus,timeval &timeout) -{ - try { - int ret = 0; - edg_wll_JobStat *status = (edg_wll_JobStat *) calloc(1,sizeof(edg_wll_JobStat)); - if (status == NULL) { - STACK_ADD; - throw OSException(EXCEPTION_MANDATORY, ENOMEM, "allocating jobStatus"); - } - ret = edg_wll_NotifReceive(ctx,-1,&timeout,status,¬ifId); - if ( ret == ETIMEDOUT ) - return 1; - check_result(ret,ctx,"edg_wll_NotifReceive"); - jobStatus = JobStatus(*status); - return 0; - } - catch (Exception &e) { - STACK_ADD; - throw; - } -} - -EWL_END_NAMESPACE; diff --git a/org.glite.lb.client/src/ServerConnection.cpp b/org.glite.lb.client/src/ServerConnection.cpp deleted file mode 100644 index 76111ad..0000000 --- a/org.glite.lb.client/src/ServerConnection.cpp +++ /dev/null @@ -1,1341 +0,0 @@ -//#ident "$Header$" - -/** - * @file ServerConnection.cpp - * @version $Revision$ - */ -#include -#include -#include - -#include -#include -#include - -#include "glite/jobid/JobId.h" -#include "glite/lb/context-int.h" -#include "glite/lb/xml_conversions.h" - -#include "ServerConnection.h" -#include "glite/lb/LoggingExceptions.h" - -EWL_BEGIN_NAMESPACE; - -/** - * definitions of QueryRecord class - */ -#define CLASS_PREFIX "glite::lb::QueryRecord::" - - -QueryRecord::QueryRecord(const Attr a, - const Op o, - const std::string & v) - : attr(a), oper(o), state(EDG_WLL_JOB_UNDEF), string_value(v) -{ - switch(a) { - case OWNER: - case LOCATION: - case DESTINATION: - case HOST: - case INSTANCE: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "invalid value for attribute: " + v); - } -} - - -QueryRecord::QueryRecord(const Attr a, - const Op o, - const int v) - : attr(a), oper(o), state(EDG_WLL_JOB_UNDEF), int_value(v) -{ - switch(a) { - case DONECODE: - case STATUS: - case SOURCE: - case EVENT_TYPE: - case LEVEL: - case EXITCODE: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "attribute is not of integer type"); - } -} - - -QueryRecord::QueryRecord(const Attr a, - const Op o, - const struct timeval& v) - : attr(a), oper(o), state(EDG_WLL_JOB_UNDEF), timeval_value(v) -{ - switch(a) { - case TIME: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "attribute is not of timeval type"); - } -} - - -QueryRecord::QueryRecord(const Attr a, - const Op o, - const glite::jobid::JobId& v) - : attr(a), oper(o), state(EDG_WLL_JOB_UNDEF), jobid_value(v) -{ - switch(a) { - case JOBID: - case PARENT: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "attribute is not of JobId type"); - } -} - - -QueryRecord::QueryRecord(const Attr a, - const Op o, - const int s, - const struct timeval &v) - : attr(a), oper(o), state(s), timeval_value(v) -{ - switch(a) { - case TIME: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "attribute is not of timeval type"); - } -} - - -QueryRecord::QueryRecord(const Attr a, - const Op o, - const std::string &v1, - const std::string &v2) - : attr(a), oper(o), state(EDG_WLL_JOB_UNDEF), string_value(v1), string_value2(v2) -{ - switch(a) { - case OWNER: - case LOCATION: - case DESTINATION: - case HOST: - case INSTANCE: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "invalid value for attribute type"); - } - if(o != WITHIN) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "only operator WITHIN allowed with two values"); - } -} - - -QueryRecord::QueryRecord(const Attr a, - const Op o, - const int v1, - const int v2) - : attr(a), oper(o), state(EDG_WLL_JOB_UNDEF), int_value(v1), int_value2(v2) -{ - switch(a) { - case DONECODE: - case STATUS: - case SOURCE: - case EVENT_TYPE: - case LEVEL: - case EXITCODE: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "attribute is not of integer type"); - } - if(o != WITHIN) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "only operator WITHIN allowed with two values"); - } -} - - -QueryRecord::QueryRecord(const Attr a, - const Op o, - const struct timeval &v1, - const struct timeval &v2) - : attr(a), oper(o), state(EDG_WLL_JOB_UNDEF), timeval_value(v1), timeval_value2(v2) -{ - switch(a) { - case TIME: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "attribute is not of timeval type"); - } - if(o != WITHIN) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "only operator WITHIN allowed with two values"); - } -} - - -QueryRecord::QueryRecord(const Attr a, - const Op o, - const int s, - const struct timeval &v1, - const struct timeval &v2) - : attr(a), oper(o), state(s), timeval_value(v1), timeval_value2(v2) -{ - switch(a) { - case TIME: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "attribute is not of timeval type"); - } - if(o != WITHIN) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "only operator WITHIN allowed with two values"); - } -} - - -QueryRecord::QueryRecord(const std::string &tag, - const Op o, - const std::string &val) - : attr(USERTAG), oper(o), tag_name(tag), state(EDG_WLL_JOB_UNDEF), string_value(val) -{ -} - - -QueryRecord::QueryRecord(const std::string &tag, - const Op o, - const std::string &v1, - const std::string &v2) - : attr(USERTAG), oper(o), tag_name(tag), state(EDG_WLL_JOB_UNDEF), - string_value(v1), string_value2(v2) - -{ - if(o != WITHIN) { - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "only operator WITHIN allowed with two values"); - } -} - - -QueryRecord::QueryRecord(const QueryRecord &src) -{ - attr = src.attr; - oper = src.oper; - - switch (attr) { - - case USERTAG: - tag_name = src.tag_name; - - case OWNER: - case LOCATION: - case DESTINATION: - case HOST: - case INSTANCE: - string_value = src.string_value; - if(src.oper == WITHIN) - string_value2 = src.string_value2; - break; - - case DONECODE: - case STATUS: - case SOURCE: - case EVENT_TYPE: - case LEVEL: - case EXITCODE: - int_value = src.int_value; - if(src.oper == WITHIN) - int_value2 = src.int_value2; - break; - - case TIME: - timeval_value = src.timeval_value; - if(src.oper == WITHIN) - timeval_value2 = src.timeval_value2; - state = src.state; - break; - - case JOBID: - jobid_value = src.jobid_value; - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "query attribute not defined"); - } -} - - -QueryRecord::QueryRecord() : attr(UNDEF), oper(EQUAL) -{ -} - - -QueryRecord::~QueryRecord() -{ -} - - -QueryRecord& -QueryRecord::operator=(const QueryRecord &src) -{ - if(this == &src) - return(*this); - - attr = src.attr; - oper = src.oper; - - switch (attr) { - - case USERTAG: - tag_name = src.tag_name; - - case OWNER: - case LOCATION: - case DESTINATION: - case HOST: - case INSTANCE: - string_value = src.string_value; - if(oper == WITHIN) - string_value2 = src.string_value2; - break; - - case DONECODE: - case STATUS: - case SOURCE: - case EVENT_TYPE: - case LEVEL: - case EXITCODE: - int_value = src.int_value; - if(oper == WITHIN) - int_value2 = src.int_value2; - break; - - case TIME: - timeval_value = src.timeval_value; - state = src.state; - if(oper == WITHIN) - timeval_value2 = src.timeval_value2; - break; - - case JOBID: - jobid_value = src.jobid_value; - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "query attribute not defined"); - } - - return *this; -} - - -QueryRecord::operator edg_wll_QueryRec() const -{ - edg_wll_QueryRec out; - - out.attr = edg_wll_QueryAttr(attr); - out.op = edg_wll_QueryOp(oper); - - switch (attr) { - - case USERTAG: - out.attr_id.tag = strdup(tag_name.c_str()); - - case OWNER: - case LOCATION: - case DESTINATION: - case HOST: - case INSTANCE: - out.value.c = strdup(string_value.c_str()); - if(oper == WITHIN) - out.value2.c = strdup(string_value2.c_str()); - break; - - - case DONECODE: - case STATUS: - case SOURCE: - case EVENT_TYPE: - case LEVEL: - case EXITCODE: - out.value.i = int_value; - if(oper == WITHIN) - out.value2.i = int_value2; - break; - - case TIME: - out.value.t = timeval_value; - out.attr_id.state = (edg_wll_JobStatCode)state; - if(oper == WITHIN) - out.value2.t = timeval_value2; - break; - - case JOBID: - if(glite_jobid_dup(jobid_value.c_jobid(), (glite_jobid_t*)&out.value.j)) { - throw std::bad_alloc(); - } - break; - - case UNDEF: - break; - - default: - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, EINVAL, "query attribute not defined"); - } - - return(out); -} - -const std::string QueryRecord::AttrName(const QueryRecord::Attr attr) -{ - char *an = edg_wll_query_attrToString(edg_wll_QueryAttr(attr)); - std::string ret(an); - free(an); - return ret; -} - - -/** - * definitions of ServerConnection class - */ -#undef CLASS_PREFIX -#define CLASS_PREFIX "glite::lb::ServerConnection::" - -ServerConnection::ServerConnection() -{ - int ret; - edg_wll_Context tmp_context; - - if((ret=edg_wll_InitContext(&tmp_context)) < 0) { - STACK_ADD; - throw OSException(EXCEPTION_MANDATORY, ret, "initializing context"); - } - - context = tmp_context; -} - - -ServerConnection::~ServerConnection() -{ - /* no exceptions should be thrown from destructors */ - edg_wll_FreeContext(context); -} - - -/********************/ -/* BEGIN DEPRECATED */ - -ServerConnection::ServerConnection(const std::string &in) -{ - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, 0, "method deprecated"); -} - - -void -ServerConnection::open(const std::string & in) -{ - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, 0, "method deprecated"); -} - - -void -ServerConnection::close(void) -{ - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, 0, "method deprecated"); -} - -/* END DEPRECATED */ -/******************/ - - -void -ServerConnection::setQueryServer(const std::string& server, int port) -{ - check_result(edg_wll_SetParamString(context, - EDG_WLL_PARAM_QUERY_SERVER, - server.c_str()), - context, - "setting query server address"); - check_result(edg_wll_SetParamInt(context, - EDG_WLL_PARAM_QUERY_SERVER_PORT, - port), - context, - "setting query server port"); -} - - -void -ServerConnection::setQueryTimeout(int timeout) -{ - check_result(edg_wll_SetParamInt(context, - EDG_WLL_PARAM_QUERY_TIMEOUT, - timeout), - context, - "setting query timeout"); -} - - -void ServerConnection::setX509Proxy(const std::string& proxy) -{ - check_result(edg_wll_SetParamString(context, - EDG_WLL_PARAM_X509_PROXY, - proxy.c_str()), - context, - "setting X509 proxy"); -} - - -void ServerConnection::setX509Cert(const std::string& cert, const std::string& key) -{ - check_result(edg_wll_SetParamString(context, - EDG_WLL_PARAM_X509_CERT, - cert.c_str()), - context, - "setting X509 certificate"); - check_result(edg_wll_SetParamString(context, - EDG_WLL_PARAM_X509_KEY, - key.c_str()), - context, - "setting X509 key"); -} - - -void -ServerConnection::setQueryEventsLimit(int max) { - check_result(edg_wll_SetParamInt(context, - EDG_WLL_PARAM_QUERY_EVENTS_LIMIT, - max), - context, - "setting query events limit"); -} - -void -ServerConnection::setQueryJobsLimit(int max) { - check_result(edg_wll_SetParamInt(context, - EDG_WLL_PARAM_QUERY_JOBS_LIMIT, - max), - context, - "setting query jobs limit"); -} - - -std::pair -ServerConnection::getQueryServer() const -{ - char *hostname; - int port; - - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_SERVER, - &hostname), - context, - "getting query server address"); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_SERVER_PORT, - &port), - context, - "getting query server port"); - return std::pair(std::string(strdup(hostname)), port); -} - - -int -ServerConnection::getQueryTimeout() const -{ - int timeout; - - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_TIMEOUT, - &timeout), - context, - "getting query timeout"); - return timeout; -} - - -std::string -ServerConnection::getX509Proxy() const -{ - char *proxy; - - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_X509_PROXY, - &proxy), - context, - "getting X509 proxy"); - return std::string(strdup(proxy)); -} - - -std::pair -ServerConnection::getX509Cert() const -{ - char *cert, *key; - - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_X509_CERT, - &cert), - context, - "getting X509 cert"); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_X509_KEY, - &key), - context, - "getting X509 key"); - - return std::pair(std::string(strdup(cert)), - std::string(strdup(key))); -} - -// static -void freeQueryRecVector(edg_wll_QueryRec *v) -{ - for(; v->attr != EDG_WLL_QUERY_ATTR_UNDEF; v++) - edg_wll_QueryRecFree(v); -} - -// static -void freeQueryRecVectorExt(edg_wll_QueryRec **v) -{ - for(; *v; v++) - edg_wll_QueryRecFree(*v); -} - -std::vector > > -ServerConnection::getIndexedAttrs(void) { - edg_wll_QueryRec **recs; - int i,j; - std::vector > > out; - - check_result(edg_wll_GetIndexedAttrs(context,&recs),context, - "edg_wll_GetIndexedAttrs()"); - - if (!recs) return out; - - for (i=0; recs[i]; i++) { - std::vector > idx; - for (j=0; recs[i][j].attr; j++) { - char *s = strdup(""); - if (recs[i][j].attr == EDG_WLL_QUERY_ATTR_USERTAG) - s = strdup(recs[i][j].attr_id.tag); - else if (recs[i][j].attr == EDG_WLL_QUERY_ATTR_TIME) - s = edg_wll_StatToString(recs[i][j].attr_id.state); - idx.push_back( - std::pair( - QueryRecord::Attr(recs[i][j].attr),s) - ); - free(s); - } - freeQueryRecVector(recs[i]); - out.push_back(idx); - } - free(recs); - return out; -} - - - - -edg_wll_QueryRec * -convertQueryVector(const std::vector &in) -{ - unsigned i; - edg_wll_QueryRec *out = new edg_wll_QueryRec[in.size() + 1]; - QueryRecord empty; - - if(out == NULL) { - STACK_ADD; - throw OSException(EXCEPTION_MANDATORY, ENOMEM, "allocating vector for conversion"); - } - - try { - for(i = 0; i < in.size(); i++) { - out[i] = in[i]; - } - out[i] = empty; - } catch (Exception &e) { - STACK_ADD; - throw; - } - return(out); -} - - -edg_wll_QueryRec ** -convertQueryVectorExt(const std::vector > &in) -{ - unsigned i; - edg_wll_QueryRec **out = new edg_wll_QueryRec*[in.size() + 1]; - - if(out == NULL) { - STACK_ADD; - throw OSException(EXCEPTION_MANDATORY, ENOMEM, "allocating vector for conversion"); - } - - try { - for(i = 0; i < in.size(); i++) { - out[i] = convertQueryVector(in[i]); - } - out[i] = NULL; - } catch (Exception &e) { - STACK_ADD; - throw; - } - return(out); -} - -void -ServerConnection::queryEvents(const std::vector& job_cond, - const std::vector& event_cond, - std::vector & eventList) const -{ - edg_wll_QueryRec *job_rec = NULL, *event_rec = NULL; - edg_wll_Event *events = NULL; - unsigned i; - int result, qresults_param; - char *errstr = NULL; - - /* convert input */ - try { - job_rec = convertQueryVector(job_cond); - event_rec = convertQueryVector(event_cond); - - /* do the query */ - - result = edg_wll_QueryEvents(context, job_rec, event_rec, &events); - if (result == E2BIG) { - edg_wll_Error(context, NULL, &errstr); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_RESULTS, &qresults_param), - context, - "edg_wll_GetParam(EDG_WLL_PARAM_QUERY_RESULTS)"); - if (qresults_param != EDG_WLL_QUERYRES_LIMITED) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryEvents"); - } - } else { - check_result(result, context,"edg_wll_QueryEvents"); - } - - /* convert output */ - for (i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++) { - edg_wll_Event *ev = (edg_wll_Event *) malloc(sizeof *ev); - memcpy(ev,events+i,sizeof *ev); - Event e(ev); - - eventList.push_back(e); - } - - if (result) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryEvents"); - } - - free(events); - freeQueryRecVector(job_rec); - freeQueryRecVector(event_rec); - delete[] job_rec; - delete[] event_rec; - - } catch(Exception &e) { - freeQueryRecVector(job_rec); - freeQueryRecVector(event_rec); - if(job_rec) delete[] job_rec; - if(event_rec) delete[] event_rec; - if(events) free(events); - if(errstr) free(errstr); - - STACK_ADD; - throw; - } -} - - -const std::vector -ServerConnection::queryEvents(const std::vector& job_cond, - const std::vector& event_cond) const -{ - std::vector eventList; - - queryEvents(job_cond, event_cond,eventList); - return eventList; -} - -const std::list -ServerConnection::queryEventsList(const std::vector& job_cond, - const std::vector& event_cond) const -{ - std::vector events; - - queryEvents(job_cond, event_cond, events); - return std::list(events.begin(),events.end()); -} - -std::string -ServerConnection::queryEventsAggregate(const std::vector& job_cond, - const std::vector& event_cond, - enum AggOp const op, - std::string const attr) const -{ - STACK_ADD; - throw Exception(EXCEPTION_MANDATORY, 0, "method not implemented"); - return ""; // gcc warning; -} - - -void -ServerConnection::queryEvents(const std::vector >& job_cond, - const std::vector >& event_cond, - std::vector& eventList) const -{ - edg_wll_QueryRec **job_rec = NULL, **event_rec = NULL; - edg_wll_Event *events = NULL; - unsigned i; - - /* convert input */ - try { - job_rec = convertQueryVectorExt(job_cond); - event_rec = convertQueryVectorExt(event_cond); - - /* do the query */ - - check_result(edg_wll_QueryEventsExt(context, - (const edg_wll_QueryRec**)job_rec, - (const edg_wll_QueryRec**)event_rec, - &events), - context, - "edg_wll_QueryEvents"); - - /* convert output */ - for (i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++) { - edg_wll_Event *ev = (edg_wll_Event *) malloc(sizeof *ev); - memcpy(ev,events+i,sizeof *ev); - Event e(ev); - - eventList.push_back(e); - } - - free(events); - - freeQueryRecVectorExt(job_rec); - freeQueryRecVectorExt(event_rec); - delete[] job_rec; - delete[] event_rec; - - } catch(Exception &e) { - - freeQueryRecVectorExt(job_rec); - freeQueryRecVectorExt(event_rec); - delete[] job_rec; - delete[] event_rec; - if(events) free(events); - - STACK_ADD; - throw; - } -} - - -const std::vector -ServerConnection::queryEvents(const std::vector >& job_cond, - const std::vector >& event_cond) const -{ - std::vector eventList; - - queryEvents(job_cond, event_cond,eventList); - return eventList; -} - - -void ServerConnection::queryJobs(const std::vector& query, - std::vector & ids) const -{ - edg_wll_QueryRec *cond = NULL; - edg_wlc_JobId *jobs, *j; - int result, qresults_param; - char *errstr = NULL; - - try { - cond = convertQueryVector(query); - - result = edg_wll_QueryJobs(context, cond, 0, &jobs, NULL); - if (result == E2BIG) { - edg_wll_Error(context, NULL, &errstr); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_RESULTS, &qresults_param), - context, - "edg_wll_GetParam(EDG_WLL_PARAM_QUERY_RESULTS)"); - if (qresults_param != EDG_WLL_QUERYRES_LIMITED) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobs"); - } - } else { - check_result(result, context,"edg_wll_QueryJobs"); - } - - for(j = jobs; *j; j++) - ids.push_back(glite::jobid::JobId(*j)); - - if (result) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobs"); - } - - free(jobs); - freeQueryRecVector(cond); - delete[] cond; - - } catch (Exception &e) { - if(cond) { - freeQueryRecVector(cond); - delete[] cond; - } - if (errstr) free(errstr); - - STACK_ADD; - throw; - } -} - - -const std::vector -ServerConnection::queryJobs(const std::vector& query) const -{ - std::vector jobList; - - queryJobs(query, jobList); - return jobList; -} - - -void -ServerConnection::queryJobs(const std::vector >& query, - std::vector& ids) const -{ - edg_wll_QueryRec **cond = NULL; - edg_wlc_JobId *jobs, *j; - int result, qresults_param; - char *errstr = NULL; - - try { - cond = convertQueryVectorExt(query); - - result = edg_wll_QueryJobsExt(context, (const edg_wll_QueryRec**)cond, - 0, &jobs, NULL); - if (result == E2BIG) { - edg_wll_Error(context, NULL, &errstr); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_RESULTS, &qresults_param), - context, - "edg_wll_GetParam(EDG_WLL_PARAM_QUERY_RESULTS)"); - if (qresults_param != EDG_WLL_QUERYRES_LIMITED) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobsExt"); - } - } else { - check_result(result, context,"edg_wll_QueryJobsExt"); - } - - for(j = jobs; *j; j++) - ids.push_back(glite::jobid::JobId(*j)); - - if (result) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobsExt"); - } - - free(jobs); - { - unsigned i; - - for(i = 0; cond[i]; i++) { - freeQueryRecVector(cond[i]); - delete[] cond[i]; - } - delete[] cond; - } - - } catch (Exception &e) { - unsigned i; - if(cond) { - for(i = 0; cond[i]; i++) { - freeQueryRecVector(cond[i]); - delete[] cond[i]; - } - delete[] cond; - } - if (errstr) free(errstr); - - STACK_ADD; - throw; - } -} - - -const -std::vector -ServerConnection::queryJobs(const std::vector >& query) const -{ - std::vector jobList; - - queryJobs(query, jobList); - return jobList; -} - - -void -ServerConnection::queryJobStates(const std::vector& query, - int flags, - std::vector & states) const -{ - edg_wll_QueryRec *cond = NULL; - edg_wll_JobStat *jobs, *j; - int result, qresults_param; - char *errstr = NULL; - - try { - cond = convertQueryVector(query); - - result = edg_wll_QueryJobs(context, cond, flags, NULL, &jobs); - if (result == E2BIG) { - edg_wll_Error(context, NULL, &errstr); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_RESULTS, &qresults_param), - context, - "edg_wll_GetParam(EDG_WLL_PARAM_QUERY_RESULTS)"); - if (qresults_param != EDG_WLL_QUERYRES_LIMITED) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobs"); - } - } else { - check_result(result, context,"edg_wll_QueryJobs"); - } - - for(j = jobs; j->state != EDG_WLL_JOB_UNDEF; j++) { - edg_wll_JobStat *jsep = new edg_wll_JobStat; - if (jsep != NULL) { - memcpy(jsep, j, sizeof(*j)); - states.push_back(JobStatus(*jsep)); - } - } - - if (result) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobs"); - } - - delete jobs; - - freeQueryRecVector(cond); - delete[] cond; - - } catch (Exception &e) { - if(cond) { - freeQueryRecVector(cond); - delete[] cond; - } - if (errstr) free(errstr); - - STACK_ADD; - throw; - } -} - - -const std::vector -ServerConnection::queryJobStates(const std::vector& query, - int flags) const -{ - std::vector states; - - queryJobStates(query, flags, states); - return(states); -} - -const std::list -ServerConnection::queryJobStatesList(const std::vector& query, - int flags) const -{ - std::vector states; - - queryJobStates(query, flags, states); - return std::list(states.begin(),states.end()); -} - - -void -ServerConnection::queryJobStates(const std::vector >& query, - int flags, - std::vector & states) const -{ - edg_wll_QueryRec **cond = NULL; - edg_wll_JobStat *jobs, *j; - int result, qresults_param; - char *errstr = NULL; - - try { - cond = convertQueryVectorExt(query); - - result = edg_wll_QueryJobsExt(context, (const edg_wll_QueryRec**)cond, - flags, NULL, &jobs); - if (result == E2BIG) { - edg_wll_Error(context, NULL, &errstr); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_RESULTS, &qresults_param), - context, - "edg_wll_GetParam(EDG_WLL_PARAM_QUERY_RESULTS)"); - if (qresults_param != EDG_WLL_QUERYRES_LIMITED) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobsExt"); - } - } else { - check_result(result, context,"edg_wll_QueryJobsExt"); - } - - for(j = jobs; j->state != EDG_WLL_JOB_UNDEF; j++) { - edg_wll_JobStat *jsep = new edg_wll_JobStat; - if (jsep != NULL) { - memcpy(jsep, j, sizeof(*j)); - states.push_back(JobStatus(*jsep)); - } - } - - if (result) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobsExt"); - } - - delete jobs; - - { - unsigned i; - - for(i = 0; cond[i]; i++) { - freeQueryRecVector(cond[i]); - delete[] cond[i]; - } - delete[] cond; - } - - - } catch (Exception &e) { - unsigned i; - if(cond) { - for(i = 0; cond[i]; i++) { - freeQueryRecVector(cond[i]); - delete[] cond[i]; - } - delete[] cond; - } - if (errstr) free(errstr); - - STACK_ADD; - throw; - } -} - - -const std::vector -ServerConnection::queryJobStates(const std::vector >& query, - int flags) const -{ - std::vector states; - - queryJobStates(query, flags, states); - return(states); -} - - -void ServerConnection::userJobs(std::vector & ids) const -{ - edg_wlc_JobId *jobs, *j; - int result, qresults_param; - char *errstr = NULL; - - try { - result = edg_wll_UserJobs(context, &jobs, NULL); - if (result == E2BIG) { - edg_wll_Error(context, NULL, &errstr); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_RESULTS, &qresults_param), - context, - "edg_wll_GetParam(EDG_WLL_PARAM_QUERY_RESULTS)"); - if (qresults_param != EDG_WLL_QUERYRES_LIMITED) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_UserJobs"); - } - } else { - check_result(result, context,"edg_wll_UserJobs"); - } - - for(j = jobs; *j; j++) - ids.push_back(glite::jobid::JobId(*j)); - - if (result) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobsExt"); - } - - free(jobs); - - } catch (Exception &e) { - if (errstr) free(errstr); - - STACK_ADD; - throw; - } -} - - -const std::vector -ServerConnection::userJobs() const -{ - std::vector jobList; - - userJobs(jobList); - return jobList; -} - - -void -ServerConnection::userJobStates(std::vector & states) const -{ - edg_wll_JobStat *jobs, *j; - int result, qresults_param; - char *errstr = NULL; - - try { - result = edg_wll_UserJobs(context, NULL, &jobs); - if (result == E2BIG) { - edg_wll_Error(context, NULL, &errstr); - check_result(edg_wll_GetParam(context, - EDG_WLL_PARAM_QUERY_RESULTS, &qresults_param), - context, - "edg_wll_GetParam(EDG_WLL_PARAM_QUERY_RESULTS)"); - if (qresults_param != EDG_WLL_QUERYRES_LIMITED) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_UserJobs"); - } - } else { - check_result(result, context,"edg_wll_UserJobs"); - } - - for(j = jobs; j->state != EDG_WLL_JOB_UNDEF; j++) { - edg_wll_JobStat *jsep = new edg_wll_JobStat; - if (jsep != NULL) { - memcpy(jsep, j, sizeof(*j)); - states.push_back(JobStatus(*jsep)); - } - } - - if (result) { - edg_wll_SetError(context, result, errstr); - check_result(result, context,"edg_wll_QueryJobsExt"); - } - - delete jobs; - - } catch (Exception &e) { - if (errstr) free(errstr); - - STACK_ADD; - throw; - } -} - - -const std::vector -ServerConnection::userJobStates() const -{ - std::vector states; - - userJobStates(states); - return(states); -} - - -edg_wll_Context -ServerConnection::getContext(void) const -{ - return(context); -} - - -void ServerConnection::setParam(edg_wll_ContextParam par, int val) -{ - check_result(edg_wll_SetParamInt(context,par,val), - context, - "edg_wll_SetParamInt()"); -} - -void ServerConnection::setParam(edg_wll_ContextParam par, const std::string &val) -{ - check_result(edg_wll_SetParamString(context,par,val.c_str()), - context, - "edg_wll_SetParamString()"); -} - -void ServerConnection::setParam(edg_wll_ContextParam par, const struct timeval & val) -{ - check_result(edg_wll_SetParamTime(context,par,&val), - context, - "edg_wll_SetParamTime()"); -} - -int ServerConnection::getParamInt(edg_wll_ContextParam par) const -{ - int ret; - check_result(edg_wll_GetParam(context,par,&ret), - context, - "edg_wll_GetParam()"); - return ret; -} - -std::string ServerConnection::getParamString(edg_wll_ContextParam par) const -{ - char *ret; - std::string out; - - check_result(edg_wll_GetParam(context,par,&ret), - context, - "edg_wll_GetParam()"); - - out = ret; - free(ret); - return out; -} - -struct timeval ServerConnection::getParamTime(edg_wll_ContextParam par) const -{ - struct timeval ret; - check_result(edg_wll_GetParam(context,par,&ret), - context, - "edg_wll_GetParam()"); - return ret; -} - -EWL_END_NAMESPACE; diff --git a/org.glite.lb.client/src/StatusAttrNames.pl b/org.glite.lb.client/src/StatusAttrNames.pl deleted file mode 100644 index 3fe6acc..0000000 --- a/org.glite.lb.client/src/StatusAttrNames.pl +++ /dev/null @@ -1,76 +0,0 @@ -# The order of strings in this array determines assigned numeric value in the JobStatus::Attr enum. -# It must not be changed unless API major number is incremented - -@main::StatusAttrNames = qw/ - ACL - CANCEL_REASON - CANCELLING - CE_NODE - CHILDREN - CHILDREN_HIST - CHILDREN_NUM - CHILDREN_STATES - CONDOR_ID - CONDOR_DEST_HOST - CONDOR_ERROR_DESC - CONDOR_JDL - CONDOR_JOB_EXIT_STATUS - CONDOR_JOB_PID - CONDOR_OWNER - CONDOR_PREEMPTING - CONDOR_REASON - CONDOR_SHADOW_EXIT_STATUS - CONDOR_SHADOW_PID - CONDOR_STARTER_EXIT_STATUS - CONDOR_STARTER_PID - CONDOR_STATUS - CONDOR_UNIVERSE - CPU_TIME - DESTINATION - DONE_CODE - EXIT_CODE - EXPECT_FROM - EXPECT_UPDATE - FAILURE_REASONS - GLOBUS_ID - JDL - JOB_ID - JOBTYPE - LAST_UPDATE_TIME - LOCAL_ID - LOCATION - MATCHED_JDL - NETWORK_SERVER - OWNER - PARENT_JOB - PAYLOAD_RUNNING - PBS_DEST_HOST - PBS_ERROR_DESC - PBS_EXIT_STATUS - PBS_NAME - PBS_OWNER - PBS_PID - PBS_QUEUE - PBS_REASON - PBS_RESOURCE_USAGE - PBS_SCHEDULER - PBS_STATE - POSSIBLE_CE_NODES - POSSIBLE_DESTINATIONS - REASON - RESUBMITTED - RSL - SEED - STATE_ENTER_TIME - STATE_ENTER_TIMES - SUBJOB_FAILED - SUSPEND_REASON - SUSPENDED - USER_TAGS - REMOVE_FROM_PROXY - UI_HOST - USER_FQANS - SANDBOX_RETRIEVED - JW_STATUS - JDL_CLASSAD -/; diff --git a/org.glite.lb.client/src/args.c.T b/org.glite.lb.client/src/args.c.T deleted file mode 100644 index d140c2f..0000000 --- a/org.glite.lb.client/src/args.c.T +++ /dev/null @@ -1,562 +0,0 @@ -/* -@@@AUTO -*/ - -@@@LANG: C - -#include "args.h" -#include "glite/lb/events.h" - -#include -#include -#include -#include -#include -#include -#include -#include - - -typedef struct { - int argc; - char** argv; - const char* help; - int idx; - edg_wll_Args list[1000]; - int last; -} opt_ctx_t; - -/* lists of accepted tags */ -@@@{ - gen "static const char * const eventJobCommon\[] = {"; - selectType $event '_common_'; - for (getFieldsOrdered $event) { - my $f = selectField $event $_; - my $fn = $f->{name}; - gen "\"$fn\", "; - } - gen "NULL };\n"; -@@@} -@@@{ - for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } - $event->getTypes) { - gen "static const char * const event$t\[] = {"; - selectType $event $t; - for (getFieldsOrdered $event) { - my $f = selectField $event $_; - my $fn = $f->{name}; - gen "\"$fn\", " - } - gen "NULL };\n"; - } -@@@} - -static const char * const * const eventTags[] = { - eventJobCommon, -@@@{ - for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } - $event->getTypes) { - gen "\tevent$t,\n"; - } - gen "\tNULL\n};\n"; -@@@} - -static int read_bool(const edg_wll_Args* o, char* arg, char* par) -{ - int b = 1; - int rs = 0; - - if (par) - { - if (!strcasecmp(par, "off") || !strcmp(par, "0") - || !strcasecmp(par, "false")) - { - b = 0; - rs = 1; - } - else if (!strcasecmp(par, "on") || !strcmp(par, "1") - || !strcasecmp(par, "true")) - { - rs = 1; - } - } - - if (o->value) - *(int*)o->value = b; - return rs; -} - -static void read_float(const edg_wll_Args* o, char* arg, char* par) -{ - float d; - if (!par) - { - printf("Option: %s - missing float value\n", arg); - exit(1); - } - d = strtof(par,NULL); - if (o->min != o->max) - { - if (d < o->min && d > o->max) - { - printf("Option: %s - value: %f out of range <%d, %d>", - arg, d, o->min, o->max); - exit(1); - } - } - if (o->value) - *(float*)o->value = d; -} - -static void read_double(const edg_wll_Args* o, char* arg, char* par) -{ - double d; - if (!par) - { - printf("Option: %s - missing double value\n", arg); - exit(1); - } - d = strtod(par,NULL); - if (o->min != o->max) - { - if (d < o->min && d > o->max) - { - printf("Option: %s - value: %f out of range <%d, %d>", - arg, d, o->min, o->max); - exit(1); - } - } - if (o->value) - *(double*)o->value = d; -} - -static void read_string(const edg_wll_Args* o, char* arg, char* par) -{ - if (!par) - { - printf("Option: %s - missing string value\n", arg); - exit(1); - } - if (o->value) - { - if (strstr(arg, "-file")) - { - struct stat buf; - int fd = open(par, O_RDONLY); - if (fd >= 0) - { - char* b; - fstat(fd, &buf); - b = (char*) malloc(buf.st_size); - if (b) - { - int p = 0; - printf("Opened & reading %s %lld\n", - par, (long long)buf.st_size); - while (p < buf.st_size) - { - int r = read(fd, b + p, buf.st_size); - if (r < 0) - break; - p += r; - } - - *(char**)o->value = b; - } - close(fd); - } - else - fprintf(stderr, "can't open file: \"%s\" (%s)\n", par, strerror(errno)); - - } - else - *(char**)o->value = strdup(par); - } -} - -static void read_int(const edg_wll_Args* o, char* arg, char* par) -{ - int v = 0; - if (!par) - { - printf("Option: %s - missing integer value\n", arg); - exit(1); - } - sscanf(par, "%i", &v); - if (o->min != o->max) - { - if (v < o->min && v > o->max) - { - printf("Option: %s - value: %d out of range <%d, %d>", - arg, v, o->min, o->max); - exit(1); - } - } - if (o->value) - *(int*)o->value = v; -} - -static void read_uint16(const edg_wll_Args* o, char* arg, char* par) -{ - int v = 0; - if (!par) - { - printf("Option: %s - missing integer value\n", arg); - exit(1); - } - sscanf(par, "%i", &v); - if (o->min != o->max) - { - if (v < o->min && v > o->max) - { - printf("Option: %s - value: %d out of range <%d, %d>", - arg, v, o->min, o->max); - exit(1); - } - } - if (o->value) - *(u_int16_t*)o->value = v; -} - -static void read_event(const edg_wll_Args* o, char* arg, char* par) -{ - edg_wll_EventCode ec = edg_wll_StringToEvent(par); - if (ec == EDG_WLL_EVENT_UNDEF) - { - if (strcmp(par, "help") == 0) - { - // list type - int i; - printf("Available events: extra options\n"); -/* XXX: holes in edg_wll_EventCode */ - for (i = EDG_WLL_EVENT_UNDEF + 1; i < EDG_WLL_EVENT__LAST; i++) - { - char* e = edg_wll_EventToString(i); - if (e) - { - int j = 0; - printf(" %s: ", e); - while (eventTags[i][j]) - printf("%s ", eventTags[i][j++]); - fputc('\n', stdout); - - free(e); - } - } - } - else - fprintf(stderr,"ERROR %s unknown event: %s\n", arg, par); - exit(1); - } - if (o->value) - *(edg_wll_EventCode*)o->value = ec; - -} - -static void read_source(const edg_wll_Args* o, char* arg, char* par) -{ - edg_wll_Source s = edg_wll_StringToSource(par); - if (s == EDG_WLL_SOURCE_NONE) - { - if (strcmp(par, "help") == 0) - { - // list type - int i; - printf("Valid sources:\n"); - for (i = EDG_WLL_SOURCE_NONE + 1; i < EDG_WLL_SOURCE__LAST; i++) - { - char* e = edg_wll_SourceToString(i); - if (e) - { - printf(" %s\n", e); - free(e); - } - } - } - else - fprintf(stderr,"ERROR %s unknown source: %s\n", arg, par); - exit(1); - } - if (o->value) - *(edg_wll_Source*)o->value = s; -} - -static void show_help(const edg_wll_Args* o, int prefix) -{ - unsigned max = 0; - char** l = malloc(sizeof(char*) * 1000); - int li = 0; - unsigned i = 0; - - for (i = 0; o[i].type != EDG_WLL_ARGS_NONE; i++) - { - char b[80]; - unsigned len; - if (o[i].type == EDG_WLL_ARGS_HELP) - sprintf(b, " -h --help"); - else - sprintf(b, " %c%s %s%s", - (o[i].oshort && prefix) ? '-' : ' ', - o[i].oshort ? o[i].oshort : " ", - (o[i].olong && prefix) ? "--" : "", - o[i].olong ? o[i].olong : "" - //opt[i].options ? opt[i].options : "", - //o[i].help ? o[i].help : "" - ); - l[li] = strdup(b); - li++; - len = strlen(b); - if (max < len) - max = len; - } - for (i = 0; o[i].type != EDG_WLL_ARGS_NONE; i++) - { - if (!o[i].oshort && !o[i].olong - && o[i].type != EDG_WLL_ARGS_HELP - && o[i].type != EDG_WLL_ARGS_OPTIONS) - continue; - - if (o[i].type != EDG_WLL_ARGS_OPTIONS) - { - unsigned s; - fputs(l[i], stdout); - for (s = strlen(l[i]); s <= max; s++) - fputc(' ', stdout); - if (o[i].type == EDG_WLL_ARGS_HELP) - fputs("this help message", stdout); - } - - if (o[i].value) - { - switch (o[i].type) - { - case EDG_WLL_ARGS_INT: - if (o[i].help) - printf(o[i].help, *(int*)o[i].value, - o[i].min, o[i].max); - break; - case EDG_WLL_ARGS_STRING: - case EDG_WLL_ARGS_SELECTSTRING: - if (o[i].help) - printf(o[i].help, *(const char**)o[i].value); - break; - case EDG_WLL_ARGS_OPTIONS: - show_help((const edg_wll_Args*)o[i].value, prefix); - continue; - default: - if (o[i].help) - fputs(o[i].help, stdout); - break; - } - } - else if (o[i].help) - fputs(o[i].help, stdout); - - fputs("\n", stdout); - } - while (--li>=0) free(l[li]); - free(l); -} -#if 0 -static void parse_suboptions(const Option* o, const char* oname, char* pars, const char* r) -{ - avm::vector arr; - split(arr, pars); - - if (!arr.size() || strcmp(arr[0], "help") == 0) - { - printf("Available options for '%s' (optA=x:optB=...)\n", oname); - show_help(o, false); - exit(0); - } - for (unsigned i = 0; i < arr.size(); i++) - { - char* par = strchr(arr[i], '='); - if (par) - { - *par = 0; - par++; - } - - for (unsigned j = 0; o[j].type != Args::Option::NONE; j++) - { - if ((o[j].oshort && strcmp(o[j].oshort, arr[i]) == 0) - || (o[j].olong && strcmp(o[j].olong, arr[i]) == 0)) - { - switch(o[j].type) - { - case Args::Option::BOOL: - read_bool(&o[j], arr[i], par, r); - break; - case Args::Option::FLOAT: - read_float(&o[j], arr[i], par, r); - break; - case Args::Option::DOUBLE: - read_double(&o[j], arr[i], par, r); - break; - case Args::Option::INT: - read_int(&o[j], arr[i], par, r); - break; - default: - ; - } - } - } - } -} -#endif - -static int findOpt(opt_ctx_t* ctx, int olong) -{ - char* arg = ctx->argv[ctx->idx] + olong + 1; - char* par = strchr(arg, '='); - const edg_wll_Args* o = NULL; - const edg_wll_Args* ol[200]; - int olb = 0; - int ole = 0; - - char* argnofile = strdup(arg); - char* nofile = strstr(argnofile, "-file"); // should be the ending - if (nofile && (nofile - argnofile) > 2) - nofile[0] = 0; - - olong++; - if (par) - { - *par = 0; - par++; - } - else if ((ctx->idx + 1) < ctx->argc) - { - par = ctx->argv[++ctx->idx]; - } - - ol[ole++] = ctx->list; - while (ole > olb) - { - o = ol[olb++]; - for (; o->type != EDG_WLL_ARGS_NONE; o++) - { - //printf("OPTION %d '%s' %d '%s' '%s'\n", o->type, arg, olong, o->oshort, o->olong); - if (o->type == EDG_WLL_ARGS_HELP - && (strcasecmp(arg, "h") == 0 - || strcmp(arg, "?") == 0 - || strcasecmp(arg, "help") == 0)) - break; - if (o->type == EDG_WLL_ARGS_OPTIONS) - { - ol[ole++] = o->value; - continue; - } - - if (olong < 2) - { - if (o->oshort && - (strcmp(arg, o->oshort) == 0 - || strcmp(argnofile, o->oshort) == 0)) - break; - } - else if (o->olong && (strcmp(arg, o->olong) == 0 - || strcmp(argnofile, o->olong) == 0)) - break; - } - if (o->type != EDG_WLL_ARGS_NONE) - break; - } - - switch (o->type) - { - case EDG_WLL_ARGS_NONE: - return -1; - case EDG_WLL_ARGS_BOOL: - if (!read_bool(o, arg, par)) - ctx->idx--; // no argument given - break; - case EDG_WLL_ARGS_FLOAT: - read_float(o, arg, par); - break; - case EDG_WLL_ARGS_DOUBLE: - read_double(o, arg, par); - break; - case EDG_WLL_ARGS_STRING: - read_string(o, arg, par); - break; - case EDG_WLL_ARGS_INT: - read_int(o, arg, par); - break; - case EDG_WLL_ARGS_UINT16: - read_uint16(o, arg, par); - break; - case EDG_WLL_ARGS_EVENT: - read_event(o, arg, par); - break; - case EDG_WLL_ARGS_SOURCE: - read_source(o, arg, par); - break; - case EDG_WLL_ARGS_HELP: - printf("\nUsage: %s %s\n\n", ctx->argv[0], ctx->help); - show_help(ctx->list, 1); - exit(0); - //case EDG_WLL_ARGS_SUBOPTIONS: - //parse_suboptions((const edg_wll_Args*)o->value, arg, par, regname); - default: - printf("FIXME: unhandle option type %d\n", o->type); - break; - } - - if (argnofile) - free(argnofile); - - return 0; -} - -static void addOptions(opt_ctx_t* ctx, const edg_wll_Args* options) -{ - const edg_wll_Args* o = options; - - while (o->type != EDG_WLL_ARGS_NONE) - { - ctx->list[ctx->last++] = *o; - o++; - } -} - -void edg_wll_ParseArgs(int* argc, char** argv, const edg_wll_Args* options, - const char* help) -{ - int sidx = 1; - opt_ctx_t ctx; - - ctx.argc = *argc; - ctx.argv = argv; - ctx.help = help; - ctx.last = 0; - - addOptions(&ctx, options); - - for (ctx.idx = 1; ctx.idx < ctx.argc; ctx.idx++) - { - if (argv[ctx.idx][0] == '-') - { - int olong = (argv[ctx.idx][1] == '-'); - if (olong && argv[ctx.idx][2] == 0) - break; // end of options - //printf("ARG %d %s\n", ctx.idx, argv[ctx.idx]); - if (findOpt(&ctx, olong) == 0) - continue; - } - else if (sidx != ctx.idx) - { - fprintf(stderr,"SIDX %d %d\n", sidx, ctx.idx); - argv[sidx] = argv[ctx.idx]; - } - sidx++; - } - - while (ctx.idx < *argc && sidx != ctx.idx) - { - argv[sidx++] = argv[ctx.idx++]; - } - - *argc = sidx; -} diff --git a/org.glite.lb.client/src/args.h b/org.glite.lb.client/src/args.h deleted file mode 100644 index 879dc60..0000000 --- a/org.glite.lb.client/src/args.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef __EDG_WORKLOAD_LOGGING_CLIENT_ARGS_H__ - -typedef enum { - EDG_WLL_ARGS_NONE = 0, - EDG_WLL_ARGS_BOOL, - EDG_WLL_ARGS_INT, - EDG_WLL_ARGS_UINT16, - EDG_WLL_ARGS_FLOAT, - EDG_WLL_ARGS_DOUBLE, - EDG_WLL_ARGS_STRING, - EDG_WLL_ARGS_HELP, - EDG_WLL_ARGS_JOBID, - EDG_WLL_ARGS_NOTIFID, - EDG_WLL_ARGS_SOURCE, - EDG_WLL_ARGS_EVENT, - EDG_WLL_ARGS_OPTIONS, - EDG_WLL_ARGS_SUBOPTIONS, - EDG_WLL_ARGS_SELECTSTRING, -} edg_wll_ArgsCode; - -typedef struct { - edg_wll_ArgsCode type; - const char* oshort; - const char* olong; - const char* help; - void* value; - int min; - int max; -} edg_wll_Args; - -void edg_wll_ParseArgs(int* argc, char** argv, const edg_wll_Args* parray, - const char* help); - -#endif /* __EDG_WORKLOAD_LOGGING_CLIENT_ARGS_H__ */ diff --git a/org.glite.lb.client/src/connection.c b/org.glite.lb.client/src/connection.c deleted file mode 100644 index a8f8574..0000000 --- a/org.glite.lb.client/src/connection.c +++ /dev/null @@ -1,792 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/security/glite_gss.h" -#include "glite/lb/context-int.h" -#include "glite/lb/mini_http.h" -#include "glite/lb/connpool.h" - -#include "consumer.h" -#include "connection.h" - - -int CloseConnection(edg_wll_Context ctx, int conn_index) -{ - /* close connection and free its structures */ - int cIndex,ret = 0; - - cIndex = conn_index; - - assert(ctx->connections->connOpened); - - if (ctx->connections->connPool[cIndex].gss.sock >= 0) - ret = edg_wll_gss_close(&ctx->connections->connPool[cIndex].gss, &ctx->p_tmp_timeout); - if (ctx->connections->connPool[cIndex].gsiCred != NULL) - edg_wll_gss_release_cred(&ctx->connections->connPool[cIndex].gsiCred, NULL); - free(ctx->connections->connPool[cIndex].peerName); - free(ctx->connections->connPool[cIndex].buf); - free(ctx->connections->connPool[cIndex].certfile); - - memset(ctx->connections->connPool + cIndex, 0, sizeof(edg_wll_ConnPool)); - ctx->connections->connPool[cIndex].gss.sock = -1; - - ctx->connections->connOpened--; - - return ret; -} - - -int CloseConnectionNotif(edg_wll_Context ctx) -{ - /* close connection and free its structures */ - int cIndex,ret = 0; - - - cIndex = ctx->connNotif->connToUse; - - assert(ctx->connNotif->connOpened); - - if (ctx->connNotif->connPool[cIndex].gss.sock >= 0) - edg_wll_gss_close(&ctx->connNotif->connPool[cIndex].gss, &ctx->p_tmp_timeout); // always returns 0 - if (ctx->connNotif->connPool[cIndex].gsiCred != NULL) - if ( (ret = edg_wll_gss_release_cred(&ctx->connNotif->connPool[cIndex].gsiCred, NULL)) ) - edg_wll_SetError(ctx,ret,"error in edg_wll_gss_release_cred()"); - free(ctx->connNotif->connPool[cIndex].peerName); - free(ctx->connNotif->connPool[cIndex].buf); - free(ctx->connNotif->connPool[cIndex].bufOut); - free(ctx->connNotif->connPool[cIndex].certfile); - - memset(ctx->connNotif->connPool + cIndex, 0, sizeof(edg_wll_ConnPool)); - ctx->connNotif->connPool[cIndex].gss.sock = -1; - - ctx->connNotif->connOpened--; - - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int ConnectionIndex(edg_wll_Context ctx, const char *name, int port) -{ - int i; - struct stat statinfo; - int using_certfile = 0; - - if (ctx->p_proxy_filename || ctx->p_cert_filename) { - stat(ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, &statinfo); - using_certfile = 1; - } - - for (i=0; iconnections->poolSize;i++) { -// printf("*** Testing connection %d: peerName = %s, peerPort = %d, file = %s\n", i, ctx->connections->connPool[i].peerName != NULL ? ctx->connections->connPool[i].peerName : "NULL", ctx->connections->connPool[i].peerPort, ctx->connections->connPool[i].file); - if ((ctx->connections->connPool[i].peerName != NULL) && // Conn Pool record must exist - !strcmp(name, ctx->connections->connPool[i].peerName) && // Server names must be equal - (port == ctx->connections->connPool[i].peerPort) && // Ports must be equal - (!using_certfile || // we are either using the default cert file - ((ctx->connections->connPool[i].certfile) && // or checking which file - (ctx->connections->connPool[i].certfile->st_ino == statinfo.st_ino) && // this conn - (ctx->connections->connPool[i].certfile->st_dev == statinfo.st_dev)))) { // uses to auth. - - - /* TryLock (next line) is in fact used only - to check the mutex status */ - switch (edg_wll_connectionTryLock(ctx, i)) { - case 0: - /* Connection was not locked but now it is. Since we do not - really know wheter we are interested in that connection, we - are simply unlocking it now. */ - edg_wll_connectionUnlock(ctx, i); - return i; - - case EBUSY: - /* Connection locked. Do not consider it */ - // try to find another free connection - break; - default: - /* Some obscure error occured. Need inspection */ - perror("ConnectionIndex() - locking problem \n"); - assert(0); - } - } - } - - return -1; -} - - -int AddConnection(edg_wll_Context ctx, char *name, int port) -{ - int i,index = -1; - - for (i = 0; i < ctx->connections->poolSize; i++) { - if (ctx->connections->connPool[i].peerName == NULL) { - if (!edg_wll_connectionTryLock(ctx, i)) { - index = i; // This connection is free and was not locked. We may lock it and use it. - break; - } - } - } - - if (index < 0) return -1; - - free(ctx->connections->connPool[index].peerName); // should be empty; just to be sure - ctx->connections->connPool[index].peerName = strdup(name); - ctx->connections->connPool[index].peerPort = port; - ctx->connections->connPool[index].gsiCred = NULL; // initial value - ctx->connections->connPool[index].certfile = NULL; - ctx->connections->connOpened++; - - return index; -} - - -int SetFreeConnectionIndexNotif(edg_wll_Context ctx) -{ - int i; - - - ctx->connNotif->connToUse = -1; - - for (i = 0; i < ctx->connNotif->poolSize; i++) - if (ctx->connNotif->connPool[i].gss.sock == -1) { - ctx->connNotif->connToUse = i; - ctx->connNotif->connOpened++; - assert(!ctx->connNotif->connPool[i].buf); - break; - } - - return ctx->connNotif->connToUse; -} - - - -int ReleaseConnection(edg_wll_Context ctx, char *name, int port) -{ - int i, index = 0, foundConnToDrop = 0; - long min; - - - edg_wll_ResetError(ctx); - if (ctx->connections->connOpened == 0) return 0; /* nothing to release */ - - if (name) { - if ((index = ConnectionIndex(ctx, name, port)) >= 0) - CloseConnection(ctx, index); - } - else { /* free the oldest (unlocked) connection */ - for (i=0; iconnections->poolSize; i++) { - assert(ctx->connections->connPool[i].peerName); // Full pool expected - accept non-NULL values only - if (!edg_wll_connectionTryLock(ctx, i)) { - edg_wll_connectionUnlock(ctx, i); // Connection unlocked. Consider releasing it - if (foundConnToDrop) { // This is not the first unlocked connection - if (ctx->connections->connPool[i].lastUsed.tv_sec < min) { - min = ctx->connections->connPool[i].lastUsed.tv_sec; - index = i; - foundConnToDrop++; - } - } - else { // This is the first unlocked connection we have found. - foundConnToDrop++; - index = i; - min = ctx->connections->connPool[i].lastUsed.tv_sec; - } - } - } - if (!foundConnToDrop) return edg_wll_SetError(ctx,EAGAIN,"all connections in the connection pool are locked"); - CloseConnection(ctx, index); - } - return edg_wll_Error(ctx,NULL,NULL); -} - - -int ReleaseConnectionNotif(edg_wll_Context ctx) -{ - int i, index = 0; - long min; - - - edg_wll_ResetError(ctx); - if (ctx->connNotif->connOpened == 0) return 0; /* nothing to release */ - - min = ctx->connNotif->connPool[0].lastUsed.tv_sec; - - /* free the oldest (unlocked) connection */ - for (i=0; iconnNotif->poolSize; i++) { - assert(ctx->connNotif->connPool[i].gss.sock > -1); // Full pool expected - accept non-NULL values only - - if (ctx->connections->connPool[i].lastUsed.tv_sec < min) { - min = ctx->connections->connPool[i].lastUsed.tv_sec; - index = i; - } - } - - ctx->connNotif->connToUse = index; - CloseConnectionNotif(ctx); - - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int edg_wll_close(edg_wll_Context ctx, int* connToUse) -{ - edg_wll_ResetError(ctx); - if (*connToUse == -1) return 0; - - CloseConnection(ctx, *connToUse); - - edg_wll_connectionUnlock(ctx, *connToUse); /* Forgetting the conn. Unlocking is safe. */ - - *connToUse = -1; - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int edg_wll_close_proxy(edg_wll_Context ctx) -{ - edg_wll_plain_close(&ctx->connProxy->conn); - - return edg_wll_ResetError(ctx); -} - - - -int edg_wll_open(edg_wll_Context ctx, int* connToUse) -{ - int index; - edg_wll_GssStatus gss_stat; - time_t lifetime = 0; - struct stat statinfo; - int acquire_cred = 0; - - - edg_wll_ResetError(ctx); - - edg_wll_poolLock(); /* We are going to search the pool, it has better be locked */ - - /* July 12, 2007 - ZS - Searching the pool for srvName/srvPort is not enough. - we also need to check the user identity so that there may be several connections - open to the same server using different identities. */ - - if ( (index = ConnectionIndex(ctx, ctx->srvName, ctx->srvPort)) == -1 ) { - /* no such open connection in pool */ - if (ctx->connections->connOpened == ctx->connections->poolSize) - if(ReleaseConnection(ctx, NULL, 0)) goto end; - - index = AddConnection(ctx, ctx->srvName, ctx->srvPort); - if (index < 0) { - edg_wll_SetError(ctx,EAGAIN,"connection pool size exceeded"); - goto end; - } - - #ifdef EDG_WLL_CONNPOOL_DEBUG - printf("Connection to %s:%d opened as No. %d in the pool\n",ctx->srvName,ctx->srvPort,index); - #endif - - } - /* else - there is cached open connection, reuse it */ - #ifdef EDG_WLL_CONNPOOL_DEBUG - else printf("Connection to %s:%d exists (No. %d in the pool) - reusing\n",ctx->srvName,ctx->srvPort,index); - #endif - - *connToUse = index; - - /* Old Comment: support anonymous connections, perhaps add a flag to the connPool - * struct specifying whether or not this connection shall be authenticated - * to prevent from repeated calls to edg_wll_gss_acquire_cred_gsi() */ - - // In case of using a specifically given cert file, stat it and check for the need to reauthenticate - if (ctx->p_proxy_filename || ctx->p_cert_filename) { - if (ctx->connections->connPool[index].certfile) { // Has the file been stated before? - stat(ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, &statinfo); - if (ctx->connections->connPool[index].certfile->st_mtime != statinfo.st_mtime) - acquire_cred = 1; // File has been modified. Need to acquire new creds. - } - else acquire_cred = 1; - } - - // Check if credentials exist. If so, check validity - if (ctx->connections->connPool[index].gsiCred) { - lifetime = ctx->connections->connPool[index].gsiCred->lifetime; - #ifdef EDG_WLL_CONNPOOL_DEBUG - printf ("Credential exists, lifetime: %d\n", lifetime); - #endif - if (!lifetime) acquire_cred = 1; // Credentials exist and lifetime is OK. No need to authenticate. - } - else { - acquire_cred = 1; // No credentials exist so far, acquire. - } - - - if (acquire_cred) { - edg_wll_GssCred newcred = NULL; - if (edg_wll_gss_acquire_cred_gsi( - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_key_filename, - &newcred, &gss_stat)) { - edg_wll_SetErrorGss(ctx, "failed to load GSI credentials", &gss_stat); - goto err; - } else { - if (ctx->connections->connPool[index].gsiCred != NULL) - edg_wll_gss_release_cred(&ctx->connections->connPool[index].gsiCred,&gss_stat); - ctx->connections->connPool[index].gsiCred = newcred; - newcred = NULL; - - // Credentials Acquired successfully. Storing file identification. - #ifdef EDG_WLL_CONNPOOL_DEBUG - printf("Cert file: %s\n", ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename); - #endif - - if (ctx->p_proxy_filename || ctx->p_cert_filename) { - if (!ctx->connections->connPool[index].certfile) // Allocate space for certfile stats - ctx->connections->connPool[index].certfile = - (struct stat*)calloc(1, sizeof(struct stat)); - stat(ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, ctx->connections->connPool[index].certfile); - } - } - } - - if (acquire_cred && ctx->connections->connPool[index].gss.context != NULL) { - edg_wll_gss_close(&ctx->connections->connPool[index].gss, &ctx->p_tmp_timeout); - } - if (ctx->connections->connPool[index].gss.context == NULL) { - switch (edg_wll_gss_connect(ctx->connections->connPool[index].gsiCred, - ctx->connections->connPool[index].peerName, ctx->connections->connPool[index].peerPort, - &ctx->p_tmp_timeout,&ctx->connections->connPool[index].gss, - &gss_stat)) { - - case EDG_WLL_GSS_OK: - goto ok; - case EDG_WLL_GSS_ERROR_ERRNO: - edg_wll_SetError(ctx,errno,"edg_wll_gss_connect()"); - break; - case EDG_WLL_GSS_ERROR_GSS: - edg_wll_SetErrorGss(ctx, "failed to authenticate to server", &gss_stat); - break; - case EDG_WLL_GSS_ERROR_HERRNO: - { const char *msg1; - char *msg2; - msg1 = hstrerror(errno); - asprintf(&msg2, "edg_wll_gss_connect(): %s", msg1); - edg_wll_SetError(ctx,EDG_WLL_ERROR_DNS, msg2); - free(msg2); - } - break; - case EDG_WLL_GSS_ERROR_EOF: - edg_wll_SetError(ctx,ECONNREFUSED,"edg_wll_gss_connect():" - " server closed the connection, probably due to overload"); - break; - case EDG_WLL_GSS_ERROR_TIMEOUT: - edg_wll_SetError(ctx,ETIMEDOUT,"edg_wll_gss_connect()"); - break; - } - } - else goto ok; - -err: - /* some error occured; close created connection - * and free all fields in connPool[index] */ - if (index >= 0) { - CloseConnection(ctx, index); - edg_wll_connectionUnlock(ctx, index); - } - *connToUse = -1; -ok: - - if (*connToUse>-1) edg_wll_connectionTryLock(ctx, *connToUse); /* Just to be sure we have not forgotten to lock it */ - -end: - - edg_wll_poolUnlock(); /* One way or the other, there are no more pool-wide operations */ - -// xxxxx - - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int edg_wll_open_proxy(edg_wll_Context ctx) -{ - struct sockaddr_un saddr; - int flags; - int err; - char *ed = NULL; - int retries = 0; - - edg_wll_ResetError(ctx); - - edg_wll_ResetError(ctx); - - if (ctx->connProxy->conn.sock > -1) { - // XXX: test path socket here? - return edg_wll_ResetError(ctx); - } - ctx->connProxy->conn.sock = socket(PF_UNIX, SOCK_STREAM, 0); - if (ctx->connProxy->conn.sock < 0) { - edg_wll_SetError(ctx, errno, "socket() error"); - goto err; - } - - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - if (!ctx->p_lbproxy_serve_sock) { - edg_wll_SetError(ctx, EINVAL, "Proxy socket path not set!"); - goto err; - } - - if (strlen(ctx->p_lbproxy_serve_sock) > 108) { // UNIX_PATH_MAX (def. in linux/un.h) - // but not defined in sys/un.h - edg_wll_SetError(ctx, EINVAL, "proxy_filename too long!"); - goto err; - } - strcpy(saddr.sun_path, ctx->p_lbproxy_serve_sock); - - if ((flags = fcntl(ctx->connProxy->conn.sock, F_GETFL, 0)) < 0 || - fcntl(ctx->connProxy->conn.sock, F_SETFL, flags | O_NONBLOCK) < 0) { - edg_wll_SetError(ctx, errno, "fcntl()"); - goto err; - } - - while ((err = connect(ctx->connProxy->conn.sock, (struct sockaddr *)&saddr, sizeof(saddr))) < 0 && - errno == EAGAIN && - ctx->p_tmp_timeout.tv_sec >= 0 && ctx->p_tmp_timeout.tv_usec >= 0 && - !(ctx->p_tmp_timeout.tv_sec == 0 && ctx->p_tmp_timeout.tv_usec == 0) - ) - { - struct timespec ns = { 0, PROXY_CONNECT_RETRY * 1000000 /* 10 ms */ },rem; - - nanosleep(&ns,&rem); - - ctx->p_tmp_timeout.tv_usec -= ns.tv_nsec/1000; - ctx->p_tmp_timeout.tv_usec += rem.tv_nsec/1000; - - ctx->p_tmp_timeout.tv_sec -= ns.tv_sec; - ctx->p_tmp_timeout.tv_sec += rem.tv_sec; - - if (ctx->p_tmp_timeout.tv_usec < 0) { - ctx->p_tmp_timeout.tv_usec += 1000000; - ctx->p_tmp_timeout.tv_sec--; - } - retries++; - } - - /* printf("retries %d\n",retries); */ - - if (err) { - if (errno == EAGAIN) edg_wll_SetError(ctx,ETIMEDOUT, "edg_wll_open_proxy()"); - else edg_wll_SetError(ctx, errno, "connect()"); - goto err; - } - - return 0; - -err: - /* some error occured; close created connection */ - - err = edg_wll_Error(ctx,NULL,&ed); - edg_wll_close_proxy(ctx); - edg_wll_SetError(ctx,err,ed); - free(ed); - - return err; -} - - - -/* transform HTTP error code to ours */ -int http_check_status( - edg_wll_Context ctx, - char *response) - -{ - int code = HTTP_INTERNAL,len = 0; - - edg_wll_ResetError(ctx); - sscanf(response,"HTTP/%*f %n%d",&len,&code); - switch (code) { - case HTTP_OK: - break; - /* soft errors - some useful data may be returned too */ - case HTTP_UNAUTH: /* EPERM */ - case HTTP_NOTFOUND: /* ENOENT */ - case HTTP_NOTIMPL: /* ENOSYS */ - case HTTP_UNAVAIL: /* EAGAIN */ - case HTTP_INVALID: /* EINVAL */ - break; - case EDG_WLL_GSS_ERROR_HERRNO: - { const char *msg1; - char *msg2; - msg1 = hstrerror(errno); - asprintf(&msg2, "edg_wll_gss_connect(): %s", msg1); - edg_wll_SetError(ctx,EDG_WLL_ERROR_DNS, msg2); - free(msg2); - } - break; - case HTTP_NOTALLOWED: - edg_wll_SetError(ctx, ENXIO, "Method Not Allowed"); - break; - case HTTP_UNSUPPORTED: - edg_wll_SetError(ctx, ENOTSUP, "Protocol versions incompatible"); - break; - case HTTP_INTERNAL: - /* fall through */ - default: - edg_wll_SetError(ctx,EDG_WLL_ERROR_SERVER_RESPONSE,response+len); - } - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int edg_wll_http_send_recv( - edg_wll_Context ctx, - char *request, - const char * const *req_head, - char *req_body, - char **response, - char ***resp_head, - char **resp_body) -{ - int ec; - char *ed = NULL; - int connToUse = -1; //Index of the connection to use. Used to be a context member. - - if (edg_wll_open(ctx,&connToUse)) return edg_wll_Error(ctx,NULL,NULL); - - switch (edg_wll_http_send(ctx,request,req_head,req_body,&ctx->connections->connPool[connToUse])) { - case ENOTCONN: - edg_wll_close(ctx,&connToUse); - if (edg_wll_open(ctx,&connToUse) - || edg_wll_http_send(ctx,request,req_head,req_body,&ctx->connections->connPool[connToUse])) - goto err; - /* fallthrough */ - case 0: break; - default: goto err; - } - - switch (edg_wll_http_recv(ctx,response,resp_head,resp_body,&ctx->connections->connPool[connToUse])) { - case ENOTCONN: - edg_wll_close(ctx,&connToUse); - if (edg_wll_open(ctx,&connToUse) - || edg_wll_http_send(ctx,request,req_head,req_body,&ctx->connections->connPool[connToUse]) - || edg_wll_http_recv(ctx,response,resp_head,resp_body,&ctx->connections->connPool[connToUse])) - goto err; - /* fallthrough */ - case 0: break; - default: goto err; - } - - assert(connToUse >= 0); - gettimeofday(&ctx->connections->connPool[connToUse].lastUsed, NULL); - - edg_wll_connectionUnlock(ctx, connToUse); - - return 0; - -err: - ec = edg_wll_Error(ctx,NULL,&ed); - edg_wll_close(ctx,&connToUse); - edg_wll_SetError(ctx,ec,ed); - free(ed); - return ec; -} - - - -int edg_wll_http_send_recv_proxy( - edg_wll_Context ctx, - char *request, - const char * const *req_head, - char *req_body, - char **response, - char ***resp_head, - char **resp_body) -{ - int err; - char *et = NULL; - - if (edg_wll_open_proxy(ctx)) return edg_wll_Error(ctx,NULL,NULL); - - switch (edg_wll_http_send_proxy(ctx,request,req_head,req_body)) { - case ENOTCONN: - edg_wll_close_proxy(ctx); - if (edg_wll_open_proxy(ctx) - || edg_wll_http_send_proxy(ctx,request,req_head,req_body)) - return edg_wll_Error(ctx,NULL,NULL); - /* fallthrough */ - case 0: break; - default: return edg_wll_Error(ctx,NULL,NULL); - } - - if (edg_wll_http_recv_proxy(ctx,response,resp_head,resp_body) == ENOTCONN) { - edg_wll_close_proxy(ctx); - (void) (edg_wll_open_proxy(ctx) - || edg_wll_http_send_proxy(ctx,request,req_head,req_body) - || edg_wll_http_recv_proxy(ctx,response,resp_head,resp_body)); - } - - /* XXX: workaround for bug #25153, don't keep proxy connection at all - * May have slight performance impact, it would be nice to cover proxy - * connections in the pool too. - */ - - err = edg_wll_Error(ctx,NULL,&et); - edg_wll_close_proxy(ctx); - if (err) { - edg_wll_SetError(ctx,err,et); - free(et); - } - - return edg_wll_Error(ctx,NULL,NULL); -} - - -int edg_wll_accept(edg_wll_Context ctx, int fd) -{ - int recv_sock; - edg_wll_GssStatus gss_stat; - time_t lifetime = 0; - struct stat statinfo; - int acquire_cred = 0; - struct sockaddr_in a; - socklen_t alen; - edg_wll_GssStatus gss_code; - - - edg_wll_ResetError(ctx); - assert(fd > 0); - - alen=sizeof(a); - recv_sock = accept(fd,(struct sockaddr *)&a,&alen); - if (recv_sock <0) { - edg_wll_SetError(ctx, errno, "accept() failed"); - goto err; - } - - if (ctx->connNotif->connOpened == ctx->connNotif->poolSize) - if (ReleaseConnectionNotif(ctx)) goto err; - - if (SetFreeConnectionIndexNotif(ctx) < 0) { - edg_wll_SetError(ctx,EAGAIN,"connection pool size exceeded"); - goto err; - } - - #ifdef EDG_WLL_CONNPOOL_DEBUG - printf("Connection with fd %d accepted. %d in the pool\n",>srvName,ctx->srvPort,ctx->connNotif->connToUse); - #endif - - - // In case of using a specifically given cert file, stat it and check for the need to reauthenticate - if (ctx->p_proxy_filename || ctx->p_cert_filename) { - if (ctx->connNotif->connPool[ctx->connNotif->connToUse].certfile) { // Has the file been stated before? - stat(ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, &statinfo); - if (ctx->connNotif->connPool[ctx->connNotif->connToUse].certfile->st_mtime != statinfo.st_mtime) - acquire_cred = 1; // File has been modified. Need to acquire new creds. - } - else acquire_cred = 1; - } - - // Check if credentials exist. If so, check validity - if (ctx->connNotif->connPool[ctx->connNotif->connToUse].gsiCred) { - lifetime = ctx->connNotif->connPool[ctx->connNotif->connToUse].gsiCred->lifetime; - #ifdef EDG_WLL_CONNPOOL_DEBUG - printf ("Credential exists, lifetime: %d\n", lifetime); - #endif - if (!lifetime) acquire_cred = 1; // Credentials exist and lifetime is OK. No need to authenticate. - } - else { - acquire_cred = 1; // No credentials exist so far, acquire. - } - - - if (acquire_cred) { - edg_wll_GssCred newcred = NULL; - if (edg_wll_gss_acquire_cred_gsi( - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_key_filename, - &newcred, &gss_stat)) { - edg_wll_SetErrorGss(ctx, "failed to load GSI credentials", &gss_stat); - goto err; - } else { - if (ctx->connNotif->connPool[ctx->connNotif->connToUse].gsiCred != NULL) - edg_wll_gss_release_cred(&ctx->connNotif->connPool[ctx->connNotif->connToUse].gsiCred,&gss_stat); - ctx->connNotif->connPool[ctx->connNotif->connToUse].gsiCred = newcred; - newcred = NULL; - - // Credentials Acquired successfully. Storing file identification. - #ifdef EDG_WLL_CONNPOOL_DEBUG - printf("Cert file: %s\n", ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename); - #endif - - if (ctx->p_proxy_filename || ctx->p_cert_filename) { - if (!ctx->connNotif->connPool[ctx->connNotif->connToUse].certfile) // Allocate space for certfile stats - ctx->connNotif->connPool[ctx->connNotif->connToUse].certfile = - (struct stat*)calloc(1, sizeof(struct stat)); - stat(ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, ctx->connNotif->connPool[ctx->connNotif->connToUse].certfile); - } - } - } - - assert(ctx->connNotif->connPool[ctx->connNotif->connToUse].gss.context == NULL); - - switch ( edg_wll_gss_accept(ctx->connNotif->connPool[ctx->connNotif->connToUse].gsiCred, recv_sock, - &ctx->p_tmp_timeout, &ctx->connNotif->connPool[ctx->connNotif->connToUse].gss,&gss_code)) { - - case EDG_WLL_GSS_OK: - break; - case EDG_WLL_GSS_ERROR_ERRNO: - edg_wll_SetError(ctx,errno,"failed to receive notification"); - goto err; - case EDG_WLL_GSS_ERROR_GSS: - edg_wll_SetErrorGss(ctx, "failed to authenticate sender", &gss_code); - goto err; - case EDG_WLL_GSS_ERROR_HERRNO: - { const char *msg1; - char *msg2; - msg1 = hstrerror(errno); - asprintf(&msg2, "edg_wll_gss_connect(): %s", msg1); - edg_wll_SetError(ctx,EDG_WLL_ERROR_DNS, msg2); - free(msg2); - } - break; - case EDG_WLL_GSS_ERROR_EOF: - edg_wll_SetError(ctx,ECONNREFUSED,"sender closed the connection"); - goto err; - case EDG_WLL_GSS_ERROR_TIMEOUT: - edg_wll_SetError(ctx,ETIMEDOUT,"accepting notification"); - goto err; - default: - edg_wll_SetError(ctx, ENOTCONN, "failed to accept notification"); - goto err; - } - - return edg_wll_Error(ctx,NULL,NULL); - - -err: - /* some error occured; close created connection - * and free all fields in connPool[ctx->connNotif->connToUse] */ - if (ctx->connNotif->connToUse >= 0) { - CloseConnectionNotif(ctx); - } - - - return edg_wll_Error(ctx,NULL,NULL); -} - diff --git a/org.glite.lb.client/src/consumer.c b/org.glite.lb.client/src/consumer.c deleted file mode 100644 index 73de913..0000000 --- a/org.glite.lb.client/src/consumer.c +++ /dev/null @@ -1,581 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lb/context-int.h" -#include "glite/lb/mini_http.h" -#include "glite/lb/xml_parse.h" -#include "glite/lb/xml_conversions.h" - -#include "consumer.h" -#include "connection.h" - -static const char* const request_headers[] = { - "Cache-Control: no-cache", - "Accept: application/x-dglb", - "User-Agent: edg_wll_Api/" PROTO_VERSION "/" COMP_PROTO, - "Content-Type: application/x-dglb", - NULL -}; - -int set_server_name_and_port(edg_wll_Context, const edg_wll_QueryRec **); - -int edg_wll_QueryEventsExt( - edg_wll_Context ctx, - const edg_wll_QueryRec **job_conditions, - const edg_wll_QueryRec **event_conditions, - edg_wll_Event **eventsOut) -{ - char *response = NULL, - *message = NULL, - *send_mess = NULL; - - edg_wll_ResetError(ctx); - - if ( edg_wll_QueryEventsRequestToXML(ctx, job_conditions, event_conditions, &send_mess) != 0 ) - { - edg_wll_SetError(ctx , (edg_wll_ErrorCode) EINVAL, "Invalid query record."); - goto err; - } - - ctx->p_tmp_timeout = ctx->p_query_timeout; - - if (ctx->isProxy) { - ctx->isProxy = 0; - if (edg_wll_http_send_recv_proxy(ctx, "POST /queryEvents HTTP/1.1", - request_headers,send_mess, &response,NULL,&message)) - goto err; - } - else { - if (set_server_name_and_port(ctx,job_conditions)) - goto err; // XXX is it fatal?? - - if (edg_wll_http_send_recv(ctx, "POST /queryEvents HTTP/1.1", - request_headers,send_mess, &response,NULL,&message)) - goto err; - } - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseQueryEvents(ctx,message,eventsOut); - -err: - free(response); - free(message); - free(send_mess); - return edg_wll_Error(ctx,NULL,NULL); -} - -int edg_wll_QueryEvents( - edg_wll_Context ctx, - const edg_wll_QueryRec *job_conditions, - const edg_wll_QueryRec *event_conditions, - edg_wll_Event **eventsOut) -{ - edg_wll_QueryRec **jconds = NULL, - **econds = NULL; - int i, - njconds, neconds, - ret; - - if ( job_conditions ) - { - for ( njconds = 0; job_conditions[njconds].attr != EDG_WLL_QUERY_ATTR_UNDEF ; njconds++ ) - ; - jconds = (edg_wll_QueryRec **) calloc(njconds+1, sizeof(edg_wll_QueryRec *)); - for ( i = 0; i < njconds; i++ ) - { - jconds[i] = (edg_wll_QueryRec *) calloc(2, sizeof(edg_wll_QueryRec)); - jconds[i][0] = job_conditions[i]; - } - } - - if ( event_conditions ) - { - for ( neconds = 0; event_conditions[neconds].attr != EDG_WLL_QUERY_ATTR_UNDEF ; neconds++ ) - ; - econds = (edg_wll_QueryRec **) calloc(neconds+1, sizeof(edg_wll_QueryRec *)); - for ( i = 0; i < neconds; i++ ) - { - econds[i] = (edg_wll_QueryRec *) calloc(2, sizeof(edg_wll_QueryRec)); - econds[i][0] = event_conditions[i]; - } - } - - if ( econds && jconds ) - ret = edg_wll_QueryEventsExt(ctx, (const edg_wll_QueryRec **) jconds, - (const edg_wll_QueryRec **) econds, eventsOut); - if ( econds && !jconds ) - ret = edg_wll_QueryEventsExt(ctx, NULL, (const edg_wll_QueryRec **) econds, eventsOut); - if ( !econds && jconds ) - ret = edg_wll_QueryEventsExt(ctx, (const edg_wll_QueryRec **) jconds, NULL, eventsOut); - if ( !econds && !jconds ) - ret = edg_wll_QueryEventsExt(ctx, NULL, NULL, eventsOut); - - if ( jconds ) - { - for ( i = 0; i < njconds ; i++ ) - free(jconds[i]); - free(jconds); - } - if ( econds ) - { - for ( i = 0; i < neconds ; i++ ) - free(econds[i]); - free(econds); - } - - return ret; -} - - -int edg_wll_QueryJobsExt( - edg_wll_Context ctx, - const edg_wll_QueryRec ** conditions, - int flags, - edg_wlc_JobId ** jobsOut, - edg_wll_JobStat ** statesOut) -{ - char *response = NULL, *message = NULL, *send_mess = NULL; - - edg_wll_ResetError(ctx); - - if (!jobsOut) flags |= EDG_WLL_STAT_NO_JOBS; - if (!statesOut) {flags = 0; flags |= EDG_WLL_STAT_NO_STATES;} - if (edg_wll_QueryJobsRequestToXML(ctx, conditions, flags, &send_mess) != 0) { - edg_wll_SetError(ctx , (edg_wll_ErrorCode) EINVAL, "Invalid query record."); - goto err; - } - - ctx->p_tmp_timeout = ctx->p_query_timeout; - - if (ctx->isProxy){ - ctx->isProxy = 0; - if (edg_wll_http_send_recv_proxy(ctx, "POST /queryJobs HTTP/1.1", - request_headers,send_mess,&response,NULL,&message)) - goto err; - } - else { - if (set_server_name_and_port(ctx, conditions)) - goto err; - - if (edg_wll_http_send_recv(ctx, "POST /queryJobs HTTP/1.1", - request_headers,send_mess,&response,NULL,&message)) - goto err; - } - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseQueryJobs(ctx,message,jobsOut,statesOut); - -err: - free(response); - free(message); - free(send_mess); - - return edg_wll_Error(ctx,NULL,NULL); -} - -int edg_wll_QueryJobs( - edg_wll_Context ctx, - const edg_wll_QueryRec * conditions, - int flags, - edg_wlc_JobId ** jobsOut, - edg_wll_JobStat ** statesOut) -{ - edg_wll_QueryRec **conds; - int i, nconds, ret; - - if ( !conditions ) - return edg_wll_QueryJobsExt(ctx, NULL, flags, jobsOut, statesOut); - - for ( nconds = 0; conditions[nconds].attr != EDG_WLL_QUERY_ATTR_UNDEF ; nconds++ ) - ; - conds = (edg_wll_QueryRec **) malloc((nconds+1) * sizeof(edg_wll_QueryRec *)); - conds[nconds] = NULL; - for ( i = 0; i < nconds ; i++ ) - { - conds[i] = (edg_wll_QueryRec *) malloc(2 * sizeof(edg_wll_QueryRec)); - conds[i][0] = conditions[i]; - conds[i][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - } - - ret = edg_wll_QueryJobsExt(ctx, (const edg_wll_QueryRec **) conds, flags, jobsOut, statesOut); - - for ( i = 0; i < nconds ; i++ ) - free(conds[i]); - free(conds); - - - return ret; -} - - - -int edg_wll_GetIndexedAttrs( - edg_wll_Context ctx, - edg_wll_QueryRec ***attrs) -{ - char *response = NULL, *send_mess = NULL, *message = NULL; - - edg_wll_ResetError(ctx); - - edg_wll_IndexedAttrsRequestToXML(ctx, &send_mess); - - if (set_server_name_and_port(ctx, NULL)) - goto err; - - ctx->p_tmp_timeout = ctx->p_query_timeout; - - if (edg_wll_http_send_recv(ctx, "POST /indexedAttrs HTTP/1.1",request_headers, send_mess, - &response,NULL,&message)) - goto err; - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseIndexedAttrs(ctx,message,attrs); - -err: - free(response); - free(message); - - return edg_wll_Error(ctx,NULL,NULL); -} - - -/* - * wrappers around edg_wll_Query() - */ - -int edg_wll_UserJobs( - edg_wll_Context ctx, - edg_wlc_JobId **jobsOut, - edg_wll_JobStat **statesOut) -{ - edg_wll_QueryRec j[2]; - - memset(j,0,sizeof j); - - j[0].attr = EDG_WLL_QUERY_ATTR_OWNER; - j[0].op = EDG_WLL_QUERY_OP_EQUAL; - j[0].value.c = ctx->peerName; - - return edg_wll_QueryJobs(ctx,j,0,jobsOut,statesOut); -} - -int edg_wll_JobLog( - edg_wll_Context ctx, - glite_jobid_const_t job, - edg_wll_Event **eventsOut) -{ - edg_wll_QueryRec j[2], e[2]; - - 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 = (glite_jobid_t) job; - - e[0].attr = EDG_WLL_QUERY_ATTR_LEVEL; - e[0].op = EDG_WLL_QUERY_OP_LESS; - e[0].value.i = ctx->p_level + 1; - - return edg_wll_QueryEvents(ctx,j,e,eventsOut); -} - -int edg_wll_JobStatus( - edg_wll_Context ctx, - glite_jobid_const_t job, - int flags, - edg_wll_JobStat *stat) -{ - edg_wll_QueryRec j[2]; - edg_wll_JobStat *statesOut = NULL; - int ret; - - memset(j,0,sizeof j); - - j[0].attr = EDG_WLL_QUERY_ATTR_JOBID; - j[0].op = EDG_WLL_QUERY_OP_EQUAL; - j[0].value.j = (glite_jobid_t) job; - j[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - - ret = edg_wll_QueryJobs(ctx,j,flags,NULL,&statesOut); - - if (ret) return ret; - - if (statesOut) { - if (statesOut[0].state == EDG_WLL_JOB_UNDEF) { - memcpy(stat, statesOut, sizeof(edg_wll_JobStat)); - free(statesOut); - ret = edg_wll_SetError(ctx , (edg_wll_ErrorCode) ENOENT, "Query returned no result."); - } - else { - /* check wheter there is only one field in status reply */ - assert(statesOut[1].state == EDG_WLL_JOB_UNDEF); - /* copy only 1st status */ - memcpy(stat, statesOut, sizeof(edg_wll_JobStat)); - /* release only array of states, keep all links unfreed for the previous copy */ - free(statesOut); - } - } - - return ret; -} - - - -int edg_wll_QueryListener(edg_wll_Context ctx, edg_wlc_JobId job, const char *name, char** host, uint16_t *port) { - - int i; - edg_wll_Event *events = NULL; - int errCode = 0; - edg_wll_QueryRec jr[2],er[2]; - int found = 0; - - memset(jr,0,sizeof jr); - memset(er,0,sizeof er); - jr[0].attr = EDG_WLL_QUERY_ATTR_JOBID; - jr[0].op = EDG_WLL_QUERY_OP_EQUAL; - jr[0].value.j = job; - - er[0].attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE; - er[0].op = EDG_WLL_QUERY_OP_EQUAL; - er[0].value.i = EDG_WLL_EVENT_LISTENER; - - if (edg_wll_QueryEvents(ctx, jr, er, &events)) { - return edg_wll_Error(ctx, NULL, NULL); - } - - for (i=0; events[i].type != EDG_WLL_EVENT_UNDEF; i++) { - if (!strcmp(name, events[i].listener.svc_name)) { - found = 1; - if (host != NULL) - *host = strdup(events[i].listener.svc_host); - if (port != NULL) - *port = events[i].listener.svc_port; - } - edg_wll_FreeEvent(&events[i]); - } - free(events); - - if (!found) - errCode = ENOENT; - - return edg_wll_SetError(ctx, errCode, NULL); -} - - -int set_server_name_and_port(edg_wll_Context ctx, const edg_wll_QueryRec **job_conditions) -{ - int i = 0, j, - found = 0, - error = 0; - unsigned int srvPort = 0, - srvPortTmp; - char *srvName = NULL, - *srvNameTmp; - - - if ( job_conditions ) for ( j = 0; job_conditions[j]; j++ ) - for ( i = 0; (job_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ ) - if ( job_conditions[j][i].attr == EDG_WLL_QUERY_ATTR_JOBID) - { - edg_wlc_JobIdGetServerParts(job_conditions[j][i].value.j,&srvNameTmp,&srvPortTmp); - if ( found ) - { - if ( strcmp(srvName, srvNameTmp) || (srvPort != srvPortTmp) ) - { - free(srvNameTmp); free(srvName); - return edg_wll_SetError(ctx, EINVAL, "Two different servers specifieed in one query"); - } - free(srvNameTmp); - } - else - { - srvName = srvNameTmp; - srvPort = srvPortTmp; - found = 1; - } - } - - if ( found && !ctx->p_query_server_override) - { - if (!ctx->srvName) - { - ctx->srvName = strdup(srvName); - ctx->srvPort = srvPort; - free(srvName); - } - else if (strcmp(srvName, ctx->srvName) || (srvPort != ctx->srvPort)) - { - free(ctx->srvName); - ctx->srvName = strdup(srvName); - ctx->srvPort = srvPort; - free(srvName); - } - } - else if ( !ctx->srvName || !ctx->srvPort ) - { - if (!ctx->p_query_server) - return(edg_wll_SetError(ctx, (edg_wll_ErrorCode) EINVAL, "Hostname of server to query is not set")); - else ctx->srvName = strdup(ctx->p_query_server); - if (!ctx->p_query_server_port) - return(edg_wll_SetError(ctx, (edg_wll_ErrorCode) EINVAL, "Port of server to query is not set")); - else ctx->srvPort = ctx->p_query_server_port; - } - - return(error); -} - -int edg_wll_QuerySequenceCodeProxy(edg_wll_Context ctx, glite_jobid_const_t jobId, char **code) -{ - int error = 0; - char *response = NULL, - *message = NULL, - *send_mess = NULL; - - - ctx->isProxy = 1; - edg_wll_ResetError(ctx); - - if ( edg_wll_QuerySequenceCodeToXML(ctx, jobId, &send_mess) != 0 ) - { - edg_wll_SetError(ctx , (edg_wll_ErrorCode) EINVAL, "Invalid query record."); - goto err; - } - - ctx->p_tmp_timeout = ctx->p_query_timeout; - - error = edg_wll_http_send_recv_proxy(ctx, "POST /querySequenceCode HTTP/1.1", - request_headers, send_mess, &response, NULL, &message); - if ( error != 0 ) - goto err; - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseQuerySequenceCodeResult(ctx,message,code); - -err: - free(response); - free(message); - free(send_mess); - - return edg_wll_Error(ctx,NULL,NULL); -} - - -/****************************************************************** - * Proxy wrappers - */ - - -int edg_wll_QueryEventsExtProxy( - edg_wll_Context ctx, - const edg_wll_QueryRec **job_conditions, - const edg_wll_QueryRec **event_conditions, - edg_wll_Event **eventsOut) -{ - ctx->isProxy = 1; - - return edg_wll_QueryEventsExt(ctx, job_conditions, event_conditions, eventsOut); -} - - - -int edg_wll_QueryEventsProxy( - edg_wll_Context ctx, - const edg_wll_QueryRec *job_conditions, - const edg_wll_QueryRec *event_conditions, - edg_wll_Event **eventsOut) -{ - ctx->isProxy = 1; - - return edg_wll_QueryEvents(ctx, job_conditions, event_conditions, eventsOut); -} - - - -int edg_wll_QueryJobsExtProxy( - edg_wll_Context ctx, - const edg_wll_QueryRec ** conditions, - int flags, - edg_wlc_JobId ** jobsOut, - edg_wll_JobStat ** statesOut) -{ - ctx->isProxy = 1; - - return edg_wll_QueryJobsExt(ctx, conditions, flags, jobsOut, statesOut); -} - - - -int edg_wll_QueryJobsProxy( - edg_wll_Context ctx, - const edg_wll_QueryRec * conditions, - int flags, - edg_wlc_JobId ** jobsOut, - edg_wll_JobStat ** statesOut) -{ - ctx->isProxy = 1; - - return edg_wll_QueryJobs(ctx, conditions, flags, jobsOut, statesOut); -} - - -int edg_wll_UserJobsProxy( - edg_wll_Context ctx, - edg_wlc_JobId **jobsOut, - edg_wll_JobStat **statesOut) -{ - ctx->isProxy = 1; - if ( ctx->p_user_lbproxy ) ctx->peerName = strdup(ctx->p_user_lbproxy); - - return edg_wll_UserJobs(ctx, jobsOut, statesOut); -} - -int edg_wll_JobLogProxy( - edg_wll_Context ctx, - glite_jobid_const_t job, - edg_wll_Event **eventsOut) -{ - ctx->isProxy = 1; - - return edg_wll_JobLog(ctx, job, eventsOut); -} - -int edg_wll_JobStatusProxy( - edg_wll_Context ctx, - glite_jobid_const_t job, - int flags, - edg_wll_JobStat *stat) -{ - ctx->isProxy = 1; - - return edg_wll_JobStatus(ctx, job, flags, stat); -} - - - -int edg_wll_QueryListenerProxy( - edg_wll_Context ctx, - edg_wlc_JobId job, - const char *name, - char** host, - uint16_t *port) -{ - ctx->isProxy = 1; - - return edg_wll_QueryListener(ctx, job, name, host, port); -} diff --git a/org.glite.lb.client/src/export.sh b/org.glite.lb.client/src/export.sh deleted file mode 100644 index ede74c6..0000000 --- a/org.glite.lb.client/src/export.sh +++ /dev/null @@ -1,90 +0,0 @@ -#! /bin/bash - -# -# script for exporing jobs from bkserver which should be periodically run -# together with running jp-importer -# -# it uses configuration from enviroment ==> may require a configuration wrapper -# - -#autodetect the prefix -PREFIX=${GLITE_LOCATION:-`dirname $0`/..} - -if [ -n "$GLITE_HOST_CERT" -a -n "$GLITE_HOST_KEY" ] ;then - creds="-c '$GLITE_HOST_CERT' -k '$GLITE_HOST_KEY'" - X509_USER_CERT="$GLITE_HOST_CERT" - X509_USER_KEY="$GLITE_HOST_KEY" -fi -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" - X509_USER_CERT=/etc/grid-security/hostcert.pem - X509_USER_KEY=/etc/grid-security/hostkey.pem - fi -fi - - -[ -z "$creds" ] && echo $0: WARNING: No credentials specified. Using default lookup which is dangerous. >&2 - - - -# dump directory of bkserver -GLITE_LB_EXPORT_PURGEDIR=${GLITE_LB_EXPORT_PURGEDIR:-$GLITE_LOCATION_VAR/purge} -GLITE_LB_EXPORT_DUMPDIR=${GLITE_LB_EXPORT_DUMPDIR:-$GLITE_LOCATION_VAR/dump} -GLITE_LB_EXPORT_PURGEDIR_KEEP=${GLITE_LB_EXPORT_PURGEDIR_KEEP:-""} -GLITE_LB_EXPORT_DUMPDIR_KEEP=${GLITE_LB_EXPORT_DUMPDIR_KEEP:-""} -# maildir dump directory for jp importer -GLITE_LB_EXPORT_JPDUMP_MAILDIR=${GLITE_LB_EXPORT_JPDUMP_MAILDIR:-$GLITE_LOCATION_VAR/jpdump} -# directory with exported data (file per job) -GLITE_LB_EXPORT_JOBSDIR=${GLITE_LB_EXPORT_JOBSDIR:-$GLITE_LOCATION_VAR/lbexport} -# purge args (timeouts) -GLITE_LB_EXPORT_PURGE_ARGS=${GLITE_LB_EXPORT_PURGE_ARGS:---cleared 2d --aborted 2w --cancelled 2w --other 60d} -# Book Keeping Server -GLITE_LB_SERVER_PORT=${GLITE_LB_SERVER_PORT:-9000} -GLITE_LB_EXPORT_BKSERVER=${GLITE_LB_EXPORT_BKSERVER:-localhost:$GLITE_LB_SERVER_PORT} -GLITE_LB_PURGE_ENABLED=${GLITE_LB_PURGE_ENABLED:-true} -GLITE_LB_EXPORT_ENABLED=${GLITE_LB_EXPORT_ENABLED:-false} - -[ -d $GLITE_LB_EXPORT_JPDUMP_MAILDIR ] || mkdir -p $GLITE_LB_EXPORT_JPDUMP_MAILDIR -[ -d $GLITE_LB_EXPORT_DUMPDIR ] || mkdir -p $GLITE_LB_EXPORT_DUMPDIR -[ -d $GLITE_LB_EXPORT_PURGEDIR ] || mkdir -p $GLITE_LB_EXPORT_PURGEDIR -[ -d $GLITE_LB_EXPORT_DUMPDIR_KEEP ] || mkdir -p $GLITE_LB_EXPORT_DUMPDIR_KEEP -[ -d $GLITE_LB_EXPORT_PURGEDIR_KEEP ] || mkdir -p $GLITE_LB_EXPORT_PURGEDIR_KEEP -[ -d $GLITE_LB_EXPORT_JOBSDIR ] || mkdir -p $GLITE_LB_EXPORT_JOBSDIR - -if [ x"$GLITE_LB_EXPORT_ENABLED" = x"true" -o -d "$GLITE_LB_EXPORT_PURGEDIR_KEEP" ] -then - GLITE_LB_EXPORT_PURGE_ARGS="$GLITE_LB_EXPORT_PURGE_ARGS -s" -fi -if [ ! -z "$GLITE_LB_PURGE_TARGET_RUNTIME" ]; then - GLITE_LB_EXPORT_PURGE_ARGS="$GLITE_LB_EXPORT_PURGE_ARGS --target-runtime $GLITE_LB_PURGE_TARGET_RUNTIME" -fi - -if [ x"$GLITE_LB_PURGE_ENABLED" = x"true" ]; then - X509_USER_CERT="$X509_USER_CERT" X509_USER_KEY="$X509_USER_KEY" $PREFIX/bin/glite-lb-purge $GLITE_LB_EXPORT_PURGE_ARGS -l -m $GLITE_LB_EXPORT_BKSERVER $GLITE_LB_PURGE_OTHER_OPTIONS -fi - - find $GLITE_LB_EXPORT_PURGEDIR/ -type f -name purge_\* 2>/dev/null | \ - while read file; do - if [ -s $file ]; then - if [ x"$GLITE_LB_EXPORT_ENABLED" = x"true" ]; then - $PREFIX/bin/glite-lb-dump_exporter -d $file -s $GLITE_LB_EXPORT_JOBSDIR -m $GLITE_LB_EXPORT_JPDUMP_MAILDIR $GLITE_LB_DUMP_EXPORTER_OTHER_OPTIONS - fi - if [ -n "$GLITE_LB_EXPORT_PURGEDIR_KEEP" ]; then - mv $file $GLITE_LB_EXPORT_PURGEDIR_KEEP - else - rm $file - fi - else - rm $file - fi - done - -if [ x"$GLITE_LB_EXPORT_ENABLED" = x"true" ]; then - if [ -n "$GLITE_LB_EXPORT_DUMPDIR_KEEP" ]; then - ls $GLITE_LB_EXPORT_DUMPDIR | xargs -i'{}' cp $GLITE_LB_EXPORT_DUMPDIR/'{}' $GLITE_LB_EXPORT_DUMPDIR_KEEP; - else - ls $GLITE_LB_EXPORT_DUMPDIR | xargs -i'{}' rm -f $GLITE_LB_EXPORT_DUMPDIR/'{}' - fi -fi diff --git a/org.glite.lb.client/src/logevent.c.T b/org.glite.lb.client/src/logevent.c.T deleted file mode 100644 index 2286b23..0000000 --- a/org.glite.lb.client/src/logevent.c.T +++ /dev/null @@ -1,301 +0,0 @@ -#ident "$Header$" - -@@@LANG: C -/* -@@@AUTO -*/ - -#include -#include -#include -#include -#include -#include // log -#include // isspace - -#include "glite/security/glite_gss.h" -#include "glite/jobid/cjobid.h" -#include "glite/lb/notifid.h" -#include "glite/lb/events.h" - -#include "producer.h" -#include "args.h" - - //" %s -p -l 100000 -j https://localhost/First_JobIV?localhost:7771 -s UserInterface -e jobAbort DG.JOB.ABORT.REASON=\"oops\"\n\n", - -// undefine to disable support for -l option -#define ENABLE_REASON_LENGTH - -int main(int argc, char *argv[]) -{ - char /* *fmt,*fname = NULL,*/ *fmt_arg=NULL; - char *server = NULL, *code = NULL; - char *ff = NULL, *jobid_s = NULL; - char *src_instance = NULL; - int err = 0/*,i,done = 0,fmtlen*/; - int pri = 0, noinc = 0; - int use_lbproxy = 0; - char *lbproxy_user = NULL; - char *lbproxy_store_sock = NULL; - int deb = 0; -#ifdef ENABLE_REASON_LENGTH - int elength = 0; -#endif - edg_wll_Context ctx; - edg_wll_Source src; - edg_wll_EventCode event = EDG_WLL_EVENT_UNDEF; - edg_wlc_JobId jobid = 0; - int (*logev)(edg_wll_Context context, - edg_wll_EventCode event, - char *fmt, ...); - - /* all possible variables */ -@@@{ - my %vars = (); - for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } - $event->getTypes) { - selectType $event $t; - for ($event->getFieldsOrdered) { - my $f = selectField $event $_; - my $fn = $f->getName; - my $type = { - "type" => $f->getType, - "defval" => $f->getDefaultNullValue - }; - - $type = { type=>'char *',defval=>'NULL' } if $f->{codes}; - - $vars{$fn} = $type; - } - } - foreach $name ( sort keys %vars ) { - gen qq{\t$vars{$name}->{"type"} $name = $vars{$name}->{"defval"};\n}; - } -@@@} - - /* all possible arguments */ - edg_wll_Args parray[] = { - { EDG_WLL_ARGS_EVENT, "e", "event", "select event type (see -e help)", &event }, - { EDG_WLL_ARGS_BOOL, "p", "priority", "send as priority event", &pri }, - { EDG_WLL_ARGS_BOOL, "x", "lbproxy", "send directly to L&B Proxy (not locallogger)", &use_lbproxy }, - { EDG_WLL_ARGS_STRING, "S", "lbproxy-store-sock", "L&B Proxy store socket path", &lbproxy_store_sock }, - { EDG_WLL_ARGS_STRING, "U", "lbproxy-user-dn", "User certificate DN L&B Proxy store socket path", &lbproxy_user }, - - { EDG_WLL_ARGS_STRING, "m", "machine", 0, &server }, - { EDG_WLL_ARGS_SOURCE, "s", "source", "event source (see -s help)", &src }, - { EDG_WLL_ARGS_STRING, "i", "source-instance", "event source instance", &src_instance }, - { EDG_WLL_ARGS_STRING, "j", "jobid", "JobId", &jobid_s }, - { EDG_WLL_ARGS_STRING, "c", "sequence", "event sequence code", &code }, - { EDG_WLL_ARGS_BOOL, "d", "debug mode", "enable debug mode", &deb }, -#ifdef ENABLE_REASON_LENGTH - { EDG_WLL_ARGS_INT, "l", "reason-length", "extend 'reason' string to length (debug only)", &elength, 0, 1000000000 }, - { EDG_WLL_ARGS_BOOL, "I", "dont-increment", "don't increment initial seqence code", &noinc }, -#endif -@@@{ - my %typetab = ( - "char *", "EDG_WLL_ARGS_STRING", - "int", "EDG_WLL_ARGS_INT", - "double", "EDG_WLL_ARGS_DOUBLE", - "glite_jobid_t", "EDG_WLL_ARGS_JOBID", - "edg_wll_NotifId", "EDG_WLL_ARGS_NOTIFID", - "edg_wll_Source", "EDG_WLL_ARGS_SOURCE", - "uint16_t", "EDG_WLL_ARGS_UINT16" - ); - my %vars = (); - for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } - $event->getTypes) { - selectType $event $t; - for ($event->getFieldsOrdered) { - my $f = selectField $event $_; - my $ft = $f->{codes} ? 'char *' : $f->getType; - my $fn = $f->getName; - my $fc = $f->getComment; - $namehelp = { "type" => $ft, "help" => $fc }; -# gen qq{ $fn $ft $fc \n}; - $vars{$fn} = $namehelp; - } - } - foreach $name ( sort keys %vars ) { -# gen qq{ $vars{$name} $name \n }; - gen qq{\t \{ $typetab{$vars{$name}->{"type"}}, 0, "$name", "$vars{$name}->{"help"}", &$name \},\n}; - } - -@@@} - { EDG_WLL_ARGS_HELP }, - { EDG_WLL_ARGS_NONE }, - }; - edg_wll_ParseArgs(&argc, argv, parray, - "Usage: %s [-d] [-p] [[-x] [-S sock] [-U user_dn]] [-l eventlen] [-j dg_jobid]" - "[-s source_id] -e event [key=value ...]"); - - - edg_wll_InitContext(&ctx); - - /* log the event - priority/normal/proxy */ - logev = (pri) ? edg_wll_LogEventSync : edg_wll_LogEvent; - logev = (use_lbproxy) ? edg_wll_LogEventProxy : logev; - - /* if no job given - generate some */ - if (jobid_s == 0) { - const char* s; - if (!server) { - s = "localhost"; - err = 1; // result fail if used normaly - } else - s = server; - edg_wlc_JobIdCreate(s, 0, &jobid); - jobid_s = edg_wlc_JobIdUnparse(jobid); - fprintf(stderr, "JobId not given: created %s (server: %s)\n",jobid_s, s); - } - else if ((errno = edg_wlc_JobIdParse(jobid_s,&jobid))) { - perror(jobid_s); - exit(1); - } - - if (event == EDG_WLL_EVENT_UNDEF) { - fprintf(stderr,"%s: unknown or unspecified event\n",argv[0]); - exit(1); - } - edg_wll_SetParam(ctx, EDG_WLL_PARAM_SOURCE, src); - if (src_instance) edg_wll_SetParam(ctx, EDG_WLL_PARAM_INSTANCE, src_instance); - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LEVEL, - (deb) ? EDG_WLL_LEVEL_DEBUG : EDG_WLL_LEVEL_SYSTEM); - - if ( use_lbproxy ) { - if ( !lbproxy_user ) { - edg_wll_GssCred gss_cred = NULL; - edg_wll_GssStatus gss_stat; - if ( edg_wll_gss_acquire_cred_gsi(NULL, NULL, &gss_cred, &gss_stat) ) - lbproxy_user = "anonymous"; - else - lbproxy_user = strdup(gss_cred->name); - if ( gss_cred != NULL ) edg_wll_gss_release_cred(&gss_cred, NULL); - } - if ( lbproxy_store_sock ) - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, lbproxy_store_sock); - if (edg_wll_SetLoggingJobProxy(ctx,jobid,code,lbproxy_user,EDG_WLL_SEQ_NORMAL)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"SetLoggingJobProxy(%s,%s,%s): %s (%s)\n",jobid_s,code,lbproxy_user,et,ed); - exit(1); - } - } else { - if (edg_wll_SetLoggingJob(ctx,jobid,code,EDG_WLL_SEQ_NORMAL)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"SetLoggingJob(%s,%s): %s (%s)\n",jobid_s,code,et,ed); - exit(1); - } - } - - if (noinc) edg_wll_SetSequenceCode(ctx,code,EDG_WLL_SEQ_NORMAL); - -#ifdef ENABLE_REASON_LENGTH - if (elength > 200000000) { - fprintf(stderr,"%s: usupported reason message length: %d\n", argv[0], elength); - } else if (elength > 0) { - int d; - int i = 0; - reason = realloc(reason, elength + 1); - reason[elength] = 0; - while (i < (elength)) { - if ((i % 20) == 0 && (i + 14) < elength) - i += sprintf(reason + i, "%d", i); - reason[i++] = '.'; - } - // amount of decimal digits + "end=" - d = (int)ceil(log(i)/log(10)) + 5; - if (i > d) - sprintf(reason + i - (int)(d), "end=%d",i); - reason[i] = 0; - } -#endif -#if 0 - if (fname) { - FILE *f = fopen(fname,"r"); - long s; - size_t r; - - fmt = "%s FILE.CONTENT=\"%|Us\" "; - - if (!f) { perror(fname); return 1; } - fseek(f,0L,SEEK_END); - s = ftell(f); rewind(f); - ff = (char *) malloc(s+1); if (!ff) { perror(NULL); return 0; } - r = fread(ff,1,s,f); - printf("%s: read %d\n",fname,r); - ff[s] = 0; - fclose(f); - } - else - fmt = "%s "; -#endif - - //err = edg_wll_LogEvent(ctx, event, fmt, fmt_arg, ff); - - switch (event) - { -@@@{ -$indent = "\t"; - for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } - $event->getTypes) { - - my $tu = uc $t; - gen $indent."case EDG_WLL_EVENT_$tu :\n"; - - selectType $event $t; - my $argl = ""; - for ($event->getFieldsOrdered) { - my $f = selectField $event $_; - my $fn = $f->getName; - my $ft; - -# gen { $fn $f->{codes} }; - if ($f->{codes}) { -# $ft = "enum edg_wll\_$t" . ucfirst $fn; - $ft = "char *"; - } else { - $ft = $f->getType; - } - - $fn = $f->getType()."ToString($fn)" if $ULMasString{$f->{type}}; - - $argl = $argl . ", "; - $argl = $argl . $fn; - } -gen qq{\t //edg_wll_Log$t(); -\t err |= logev(ctx, EDG_WLL_EVENT_$tu, EDG_WLL_FORMAT_${tu}$argl); -\t break; -}; - } -@@@} - default: - fprintf(stderr, "unknown event\n"); - } - - edg_wlc_JobIdFree(jobid); - if (jobid_s) free(jobid_s); // add all strings - - if (err) { - char *et,*ed; - - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"%s: edg_wll_LogEvent*(): %s (%s)\n", - argv[0],et,ed); - free(et); free(ed); - } - - code = edg_wll_GetSequenceCode(ctx); - puts(code); - free(code); - - edg_wll_FreeContext(ctx); - - if (ff) free(ff); - if (fmt_arg) free(fmt_arg); -#ifdef ENABLE_REASON_LENGTH - if (reason) free(reason); -#endif - - return err; -} diff --git a/org.glite.lb.client/src/notification.c b/org.glite.lb.client/src/notification.c deleted file mode 100644 index 5cc8348..0000000 --- a/org.glite.lb.client/src/notification.c +++ /dev/null @@ -1,877 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/security/glite_gss.h" -#include "glite/lbu/escape.h" -#include "glite/lb/events.h" -#include "glite/lb/log_proto.h" -#include "glite/lb/mini_http.h" -#include "glite/lb/context-int.h" -#include "glite/lb/xml_parse.h" -#include "glite/lb/events_parse.h" -#include "glite/lb/il_msg.h" - -#include "notification.h" -#include "connection.h" - -#define CON_QUEUE 10 /* listen() queue limit */ - -/* XXX: moving all request_headers to one file would be nice - */ -static const char* const request_headers[] = { - "Cache-Control: no-cache", - "Accept: application/x-dglb", - "User-Agent: edg_wll_Api/" PROTO_VERSION "/" COMP_PROTO, - "Content-Type: application/x-dglb", - NULL -}; - - - - -/* Decrement timeout - */ -static int decrement_timeout(struct timeval *timeout, struct timeval before, struct timeval after) -{ - if (!timeout) - return(0); // wait indefinitely - - (*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); -} - - - -/* Split address to name & port - */ -static void get_name_and_port(const char *address, char **name, int *port) -{ - char *n = NULL, *p; - - n = strdup(address); - p = strchr(n, ':'); - if (p) - { - *port = atoi(p+1); - *p = 0; - } - *name = strdup(n); - free(n); -} - - -static int my_bind(edg_wll_Context ctx, const char *name, int port, int *fd) -{ - struct sockaddr_in a; - socklen_t alen = sizeof(a); - int sock; - - sock = socket(PF_INET,SOCK_STREAM,0); - if (sock<0) - return edg_wll_SetError(ctx, errno, "socket() failed"); - - a.sin_family = AF_INET; - a.sin_port = htons(port); - a.sin_addr.s_addr = name? inet_addr(name): htonl(INADDR_ANY); - -// setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); - if (bind(sock,(struct sockaddr *)&a,alen)) - return edg_wll_SetError(ctx, errno, "bind() failed"); - - - if (listen(sock,CON_QUEUE)) - return edg_wll_SetError(ctx, errno, "listen() failed"); - - *fd = sock; - - return edg_wll_Error(ctx,NULL,NULL); -} - - - -static int set_server_name_and_port(edg_wll_Context ctx) -{ - - if (!ctx->p_notif_server) - return(edg_wll_SetError(ctx, (edg_wll_ErrorCode) EINVAL, - "Hostname of server to notif is not set")); - else { - free(ctx->srvName); - ctx->srvName = strdup(ctx->p_notif_server); - } - if (!ctx->p_notif_server_port) - return(edg_wll_SetError(ctx, (edg_wll_ErrorCode) EINVAL, - "Port of server to notif is not set")); - else ctx->srvPort = ctx->p_notif_server_port; - - return edg_wll_Error(ctx,NULL,NULL); -} - - - -static int get_client_address( - edg_wll_Context ctx, - int fd, - const char *address_override, - char **address) - -{ - struct sockaddr_in a; - socklen_t alen = sizeof(a); - struct hostent *he; - char *name = NULL; - int port = 0; - - - if (address_override) { - struct in_addr in; - - get_name_and_port(address_override, &name, &port); - - if ( (he = gethostbyname((const char *) name)) == NULL) { - edg_wll_SetError(ctx, errno, "gethostbyname() failed"); - goto err; - } - - free(name); - - memmove(&in.s_addr, he->h_addr_list[0], sizeof(in.s_addr)); - name = strdup(inet_ntoa(in)); - - if ( (he = gethostbyname((const char *) name)) == NULL) { - edg_wll_SetError(ctx, errno, "gethostbyname() failed"); - goto err; - } - - /* Test whether open sockket represents the same address as address_override - * if not, close ctx->notifSock and bind to new socket corresponding to - * address_override - */ - if (ctx->notifSock >= 0) { - if (getsockname(ctx->notifSock, (struct sockaddr *) &a, &alen)) - return edg_wll_SetError(ctx, errno, "getsockname() failed"); - - if ( (strcmp(inet_ntoa(a.sin_addr), name)) || (ntohs(a.sin_port) != port) ) { - - if (close(ctx->notifSock)) { - edg_wll_SetError(ctx, errno, "close() failed"); - goto err; - } - ctx->notifSock = -1; - - if (my_bind(ctx, name, port, &(ctx->notifSock))) - goto err; - } - } - else { // create new socket - if (my_bind(ctx, name, port, &(ctx->notifSock))) - goto err; - } - - *address = strdup(address_override); - } - else { // address_override == NULL - - if (fd == -1) { - if (ctx->notifSock == -1) - // create new socket - if (my_bind(ctx, NULL, 0, &(ctx->notifSock))) - goto err; - // else: resue socket - } - - if (getsockname(fd == -1 ? ctx->notifSock : fd,(struct sockaddr *) &a, &alen)) - return edg_wll_SetError(ctx, errno, "getsockname() failed"); - - if (a.sin_addr.s_addr == INADDR_ANY) - asprintf(address,"0.0.0.0:%d", ntohs(a.sin_port)); - else - asprintf(address,"%s:%d", inet_ntoa(a.sin_addr), ntohs(a.sin_port)); - } - -err: - free(name); - - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int edg_wll_NotifNew( - edg_wll_Context ctx, - edg_wll_QueryRec const * const *conditions, - int flags, - int fd, - const char *address_override, - edg_wll_NotifId *id_out, - time_t *valid) -{ - edg_wll_NotifId notifId = NULL; - char *address = NULL, *send_mess = NULL, - *recv_mess = NULL, *response = NULL; - int ret; - - - edg_wll_ResetError(ctx); - - if ( (ret = set_server_name_and_port(ctx)) ) - goto err; - - if ( (ret = edg_wll_NotifIdCreate(ctx->srvName,ctx->srvPort,¬ifId)) ) - goto err; - - if ( (ret = get_client_address(ctx, fd, address_override, &address)) ) - goto err; - - if ( (ret = edg_wll_NotifRequestToXML(ctx, "New", notifId, address, - EDG_WLL_NOTIF_NOOP, *valid, conditions, flags, &send_mess)) ) - goto err; - - ctx->p_tmp_timeout = ctx->p_notif_timeout; - - if ( (ret = edg_wll_http_send_recv(ctx, "POST /notifRequest HTTP/1.1", - request_headers,send_mess, - &response,NULL,&recv_mess)) ) - goto err; - - if ( (ret = http_check_status(ctx,response)) ) - goto err; - - ret = edg_wll_ParseNotifResult(ctx, recv_mess, valid); - - -err: - if (ret != 0) { - if (notifId) edg_wll_NotifIdFree(notifId); - *id_out = NULL; - *valid = -1; - } - else - *id_out = notifId; - - free(address); - free(recv_mess); - free(send_mess); - free(response); - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int edg_wll_NotifBind( - edg_wll_Context ctx, - const edg_wll_NotifId id, - int fd, - const char *address_override, - time_t *valid) -{ - char *address = NULL, *send_mess = NULL, - *recv_mess = NULL, *response = NULL; - - - edg_wll_ResetError(ctx); - - -/* XXX - ??? this should not be there - if fd = -1 then semantic is 'create new socket or _reuse_ old' - // if a local listening socket active, close it - if (ctx->notifSock >= 0) { - if (close(ctx->notifSock)) - return edg_wll_SetError(ctx, errno, "close() failed"); - else - ctx->notifSock = -1; - } -*/ - - if (set_server_name_and_port(ctx)) - goto err; - - if (get_client_address(ctx, fd, address_override, &address)) - goto err; - - if (edg_wll_NotifRequestToXML(ctx, "Bind", id, address, - EDG_WLL_NOTIF_NOOP, *valid, NULL, 0, &send_mess)) - goto err; - - ctx->p_tmp_timeout = ctx->p_notif_timeout; - - if (edg_wll_http_send_recv(ctx, "POST /notifRequest HTTP/1.1", - request_headers,send_mess, - &response,NULL,&recv_mess)) - goto err; - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseNotifResult(ctx, recv_mess, valid); - -err: - free(address); - free(recv_mess); - free(send_mess); - free(response); - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int edg_wll_NotifChange( - edg_wll_Context ctx, - const edg_wll_NotifId id, - edg_wll_QueryRec const * const * conditions, - edg_wll_NotifChangeOp op) -{ - char *send_mess = NULL, *recv_mess = NULL, *response = NULL; - time_t not_used; - - - edg_wll_ResetError(ctx); - - - if (set_server_name_and_port(ctx)) - goto err; - - if (edg_wll_NotifRequestToXML(ctx, "Change", id, NULL, - op, -1, conditions, 0, &send_mess)) - goto err; - - ctx->p_tmp_timeout = ctx->p_notif_timeout; - - if (edg_wll_http_send_recv(ctx, "POST /notifRequest HTTP/1.1", - request_headers,send_mess, - &response,NULL,&recv_mess)) - goto err; - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseNotifResult(ctx, recv_mess, ¬_used); - -err: - free(recv_mess); - free(send_mess); - free(response); - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int edg_wll_NotifRefresh( - edg_wll_Context ctx, - const edg_wll_NotifId id, - time_t *valid) -{ - char *send_mess = NULL, *recv_mess = NULL, *response = NULL; - - - edg_wll_ResetError(ctx); - - - if (set_server_name_and_port(ctx)) - goto err; - - if (edg_wll_NotifRequestToXML(ctx, "Refresh", id, NULL, - EDG_WLL_NOTIF_NOOP, *valid, NULL, 0, &send_mess)) - goto err; - - ctx->p_tmp_timeout = ctx->p_notif_timeout; - - if (edg_wll_http_send_recv(ctx, "POST /notifRequest HTTP/1.1", - request_headers,send_mess, - &response,NULL,&recv_mess)) - goto err; - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseNotifResult(ctx, recv_mess, valid); - -err: - free(recv_mess); - free(send_mess); - free(response); - return edg_wll_Error(ctx,NULL,NULL); -} - - - -int edg_wll_NotifDrop( - edg_wll_Context ctx, - edg_wll_NotifId id) -{ - char *send_mess = NULL, *recv_mess = NULL, *response = NULL; - time_t not_used; - - - edg_wll_ResetError(ctx); - - - if (set_server_name_and_port(ctx)) - goto err; - - if (edg_wll_NotifRequestToXML(ctx, "Drop", id, NULL, - EDG_WLL_NOTIF_NOOP, -1, NULL, 0, &send_mess)) - goto err; - - ctx->p_tmp_timeout = ctx->p_notif_timeout; - - if (edg_wll_http_send_recv(ctx, "POST /notifRequest HTTP/1.1", - request_headers,send_mess, - &response,NULL,&recv_mess)) - goto err; - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseNotifResult(ctx, recv_mess, ¬_used); - -err: - free(recv_mess); - free(send_mess); - free(response); - return edg_wll_Error(ctx,NULL,NULL); -} - - -/* read all data available on active notif connection */ -static int read_data(edg_wll_Context ctx) -{ - edg_wll_GssStatus gss_code; - int ret; - edg_wll_ConnPool *notif = &(ctx->connNotif->connPool[ctx->connNotif->connToUse]); - - - do { - if (notif->bufUse == notif->bufSize) { - notif->bufSize += NOTIF_POOL_BUFFER_BLOCK_SIZE; - notif->buf = realloc(notif->buf, notif->bufSize); - if (!notif->buf) - return edg_wll_SetError(ctx, ENOMEM, "read_data()"); - } - - ret = edg_wll_gss_read(&(notif->gss), notif->buf + notif->bufUse, - notif->bufSize - notif->bufUse, &ctx->p_tmp_timeout, &gss_code); - - if (ret < 0) { - switch(ret) { - case EDG_WLL_GSS_ERROR_TIMEOUT: - edg_wll_SetError(ctx, ETIMEDOUT, "read message"); - break; - case EDG_WLL_GSS_ERROR_EOF: - edg_wll_SetError(ctx, ENOTCONN, NULL); - break; - default: - edg_wll_SetError(ctx, EDG_WLL_ERROR_GSS, "read message"); - break; - } - goto err; - } - notif->bufUse += ret; - - } while (notif->bufSize == notif->bufUse); - -err: - return edg_wll_Error(ctx, NULL, NULL); -} - - -/* copies bytes_to_copy chars from pool buffer to given _allocated_ working buffer - */ -static int buffer_reader(void *user_data, char *buffer, const int bytes_to_copy) -{ - edg_wll_Context tmp_ctx = (edg_wll_Context)user_data; - - - if (tmp_ctx->connNotif->connPool[tmp_ctx->connNotif->connToUse].bufUse < bytes_to_copy) - return(-1); - - memcpy(buffer,tmp_ctx->connNotif->connPool[tmp_ctx->connNotif->connToUse].buf + - tmp_ctx->connNotif->connPool[tmp_ctx->connNotif->connToUse].bufPtr, bytes_to_copy); - tmp_ctx->connNotif->connPool[tmp_ctx->connNotif->connToUse].bufPtr += bytes_to_copy; - - return(bytes_to_copy); -} - - -static int recv_notif(edg_wll_Context ctx, char **message) -{ - int len; - - - len = read_il_data(ctx, message, buffer_reader); - if(len < 0) - return(len); - - return edg_wll_Error(ctx,NULL,NULL); -} - - -static int prepare_reply(const edg_wll_Context ctx) -{ - int len, err_code, err_code_min = 0; - char *err_msg = NULL; - - - err_code = edg_wll_Error(ctx,NULL,&err_msg); - - if (!err_msg) err_msg=strdup("OK"); - - len = encode_il_reply(&(ctx->connNotif->connPool[ctx->connNotif->connToUse].bufOut), - err_code, err_code_min, err_msg); - - if(len < 0) { - edg_wll_SetError(ctx,E2BIG,"create_reply()"); - goto err; - } - - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufSizeOut = len; -err: - free(err_msg); - return edg_wll_Error(ctx,NULL,NULL); -} - - -// send pool output buffer nonblockingly -// XXX: missing partial-sent logic (gss_write does not return written bytes count) -static int send_reply(const edg_wll_Context ctx) -{ - int ret; - edg_wll_GssStatus gss_code; - - - ret = edg_wll_gss_write(&ctx->connNotif->connPool[ctx->connNotif->connToUse].gss, - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufOut, - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufSizeOut, &ctx->p_tmp_timeout, &gss_code); - - if (ret < 0) { - // edg_wll_gss_write does not return how many bytes were written, so - // any error is fatal for us and we can close connection - edg_wll_SetError(ctx, - ret == EDG_WLL_GSS_ERROR_TIMEOUT ? - ETIMEDOUT : EDG_WLL_ERROR_GSS, - "send_reply()"); - goto err; - } - -err: - return edg_wll_Error(ctx,NULL,NULL); -} - - - - -int edg_wll_NotifReceive( - edg_wll_Context ctx, - int fd, - const struct timeval *timeout, - edg_wll_JobStat *state_out, - edg_wll_NotifId *id_out) - -/* NotifReceive */ -{ - int i, j, ret, fd_num = ctx->connNotif->connOpened + 1; - struct _fd_map { - struct pollfd pollfds[fd_num]; - int index[fd_num]; - } fd_map; - edg_wll_Event *event = NULL; - struct timeval start_time,check_time; - char *event_char = NULL, *jobstat_char = NULL, *message = NULL; - struct timeval tv = *timeout; - - - edg_wll_ResetError(ctx); - - /* start timer */ - gettimeofday(&start_time,0); - - if (fd == -1) { - if (ctx->notifSock == -1) { - return edg_wll_SetError(ctx, EINVAL, "No client socket opened."); - } - else { - fd = ctx->notifSock; - } - } - -start: - fd_num = ctx->connNotif->connOpened + 1; - fd_map.pollfds[0].fd = fd; - fd_map.pollfds[0].events = POLLIN; - fd_map.index[0] = -1; - - j = 1; - for (i=0; i < ctx->connNotif->poolSize; i++) { - if (ctx->connNotif->connPool[i].gss.sock != -1) { - fd_map.pollfds[j].fd = ctx->connNotif->connPool[i].gss.sock; - fd_map.pollfds[j].events = POLLIN; - fd_map.index[j] = i; - j++; - } - } - assert(j == fd_num); - - /* XXX notif_send() & notif_receive() should then migrate to */ - /* client/connection.c and use connPool management f-cions */ - - /* XXX: long-lived contexts may have problems, TODO implement credential reload */ - - switch(poll(fd_map.pollfds, fd_num, tv.tv_sec*1000+tv.tv_usec/1000)) { - case -1: - edg_wll_SetError(ctx, errno, "edg_wll_NotifReceive: poll() failed"); - goto err; - case 0: - edg_wll_SetError(ctx, ETIMEDOUT, "edg_wll_NotifReceive: poll() timed out"); - goto err; - default: - for (i=0; i < fd_num; i++) { - if ((fd_map.pollfds[i].revents & POLLIN)) { - break; - } - } - if (fd_num == i) { - /* no events on any socket */ - edg_wll_SetError(ctx, errno, "edg_wll_NotifReceive: error on filedescriptor"); - goto err; - } - break; - } - - /* check time */ - gettimeofday(&check_time,0); - if (decrement_timeout(&tv, start_time, check_time)) { - edg_wll_SetError(ctx, ETIMEDOUT, "edg_wll_NotifReceive()"); - goto err; - } - ctx->p_tmp_timeout = tv; - - // there is some incomming connection(s) - // XXX: what has higher priority? new connection, or data on active connection ? - - if (fd_map.pollfds[0].revents & POLLIN) { /* new connection */ - start_time = check_time; - - if (edg_wll_accept(ctx,fd)) goto err; - - /* check time */ - gettimeofday(&check_time,0); - if (decrement_timeout(&tv, start_time, check_time)) { - edg_wll_SetError(ctx, ETIMEDOUT, "edg_wll_NotifReceive()"); - goto err; - } - ctx->p_tmp_timeout = tv; - } - else { /* data on some of active (NotifPool) connections */ - // XXX: if data arrives for more connections, which one serve first? - // poor-man solution - take first one on which data arrived - for (i=1; i < fd_num; i++) { - if (fd_map.pollfds[i].revents & POLLIN) { - ctx->connNotif->connToUse = fd_map.index[i]; - break; - } - } - assert(i < fd_num); - } - - /****************************************************************/ - /* Communication with notif-interlogger */ - /****************************************************************/ - - start_time = check_time; - - if ( (ret = read_data(ctx)) ) { - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufPtr = 0; - - if ( ret == ENOTCONN ) { - int broken = (ctx->connNotif->connPool[ctx->connNotif->connToUse].bufUse != 0); - /* IL closed connection; remove this connection from pool and go to poll if timeout > 0 */ - - CloseConnectionNotif(ctx); - - /* check time */ - gettimeofday(&check_time,0); - if (decrement_timeout(&tv, start_time, check_time)) { - edg_wll_SetError(ctx, ETIMEDOUT, "edg_wll_NotifReceive()"); - goto err; - } - ctx->p_tmp_timeout = tv; - start_time = check_time; - - if (broken) { - edg_wll_SetError(ctx,ENOTCONN,"IL connection broken in middle of message"); - goto err; - } - - edg_wll_ResetError(ctx); - goto start; - } - - goto err; - } - - /* check time */ - gettimeofday(&check_time,0); - if (decrement_timeout(&tv, start_time, check_time)) { - edg_wll_SetError(ctx, ETIMEDOUT, "edg_wll_NotifReceive()"); - goto err; - } - ctx->p_tmp_timeout = tv; - start_time = check_time; - - if (recv_notif(ctx, &message) < 0) { - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufPtr = 0; - goto err; - } - - /* receive message complete, free input buffer */ - free(ctx->connNotif->connPool[ctx->connNotif->connToUse].buf); - ctx->connNotif->connPool[ctx->connNotif->connToUse].buf = NULL; - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufPtr = 0; - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufUse = 0; - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufSize = 0; - - - if (prepare_reply(ctx) || send_reply(ctx)) { - // fatal error - // XXX: output buffer not used between edg_wll_NotifReceive() calls - CloseConnectionNotif(ctx); - goto err; - } - - /* check time */ - gettimeofday(&check_time,0); - if (decrement_timeout(&tv, start_time, check_time)) { - edg_wll_SetError(ctx, ETIMEDOUT, "edg_wll_NotifReceive()"); - goto err; - } - ctx->p_tmp_timeout = tv; - start_time = check_time; - - /* response sent, free output buffer */ - free(ctx->connNotif->connPool[ctx->connNotif->connToUse].bufOut); - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufOut = NULL; - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufUseOut = 0; - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufSizeOut = 0; - ctx->connNotif->connPool[ctx->connNotif->connToUse].bufPtrOut = 0; - - { - il_octet_string_t ev; - - if ( decode_il_msg(&ev, message) < 0 ) { - CloseConnectionNotif(ctx); - edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "decoding event string"); - goto err; - } - event_char = ev.data; - } - /****************************************************************/ - /* end of notif-interlogger message exchange */ - /****************************************************************/ - - /* check time */ - gettimeofday(&check_time,0); - if (decrement_timeout(&tv, start_time, check_time)) { - edg_wll_SetError(ctx, ETIMEDOUT, "edg_wll_NotifReceive()"); - goto err; - } - ctx->p_tmp_timeout = tv; - start_time = check_time; - - if (edg_wll_ParseNotifEvent(ctx, event_char, &event)) { - goto err; - } - - jobstat_char = glite_lbu_UnescapeXML((const char *) event->notification.jobstat); - if (jobstat_char == NULL) { - edg_wll_SetError(ctx, EINVAL, "glite_lbu_UnescapeXML()"); - goto err; - } - - /* fill in return values - */ - if ( edg_wll_ParseJobStat(ctx, jobstat_char, - strlen(jobstat_char), state_out)) { - goto err; - } - - if (id_out) { - *id_out = event->notification.notifId; - event->notification.notifId = NULL; - } - -err: - if (event) { - edg_wll_FreeEvent(event); - // XXX - konzultovat s honikem; podle meho by to free - // mel delat uz edg_wll_FreeEvent - free(event); - } - - free(event_char); - free(jobstat_char); - free(message); - - // XXX: decrement or not to decrement :) - //*timeout = tv; - - return edg_wll_Error(ctx,NULL,NULL); -} - - -int edg_wll_NotifGetFd( - edg_wll_Context ctx) -{ - if (ctx->notifSock == -1) { - edg_wll_SetError(ctx, EBADF, "Client socket is not opened."); - return -1; - } - - return ctx->notifSock; -} - - -int edg_wll_NotifCloseFd( - edg_wll_Context ctx) -{ - int err; - - if (ctx->notifSock >= 0) { - err = close(ctx->notifSock); - ctx->notifSock = -1; - - if (err) - return edg_wll_SetError(ctx, errno, "close() failed"); - } - - return edg_wll_Error(ctx,NULL,NULL); -} - -int edg_wll_NotifClosePool( - edg_wll_Context ctx) -{ - if (ctx->connNotif->connOpened) { - for (ctx->connNotif->connToUse=0; ctx->connNotif->connToUse < ctx->connNotif->poolSize; - ctx->connNotif->connToUse++) { - if (ctx->connNotif->connPool[ctx->connNotif->connToUse].gss.sock != -1) CloseConnectionNotif(ctx); - - } - } - - return edg_wll_Error(ctx,NULL,NULL); -} diff --git a/org.glite.lb.client/src/notify.c b/org.glite.lb.client/src/notify.c deleted file mode 100644 index 913939d..0000000 --- a/org.glite.lb.client/src/notify.c +++ /dev/null @@ -1,507 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/security/glite_gss.h" -#include "glite/lb/context.h" -#include "notification.h" - -#include "stat_fields.h" - - -static char *me; - -static void usage(char *cmd) -{ - if ( !cmd ) - { - fprintf(stderr,"usage: %s command [options]\n" - " where commands are:\n" - " new Create new notification reg.\n" - " bind Binds an notification reg. to a client.\n" - " change Changes notification reg. params.\n" - " refresh Enlarge notification reg. validity.\n" - " receive Binds to an existing notif. registration and listen to server.\n" - " drop Drop the notification reg.\n" - " help Prints this message\n", - me); - } - if ( !cmd || !strcmp(cmd, "new") ) - fprintf(stderr,"\n'new' command usage: %s new [ { -s socket_fd | -a fake_addr } -t requested_validity -j jobid { -o owner | -O } -n network_server -v virtual_organization --states state1,state2,... -c -f flags]\n" - " jobid Job ID to connect notif. reg. with\n" - " owner Match this owner DN\n" - " requested_validity Validity of notification req. in seconds\n" - " flags 0 - return basic status, 1 - return also JDL in status\n" - " network_server Match only this network server (WMS entry point)\n" - " -O Match owner - credentials are retrieved from environment\n" - " -c Match only on state change\n" - " -S | --state Match on events resulting in listed (coma-delimited) states\n" - , me); - if ( !cmd || !strcmp(cmd, "bind") ) - fprintf(stderr,"\n'bind' command usage: %s bind [ { -s socket_fd | -a fake_addr } -t requested_validity ] notifids \n" - " requested_validity Validity of notification req. in seconds\n" - " notifids One or more notification ID's\n" - " fake_addr Fake the client address\n", me); - - if ( !cmd || !strcmp(cmd, "change") ) - fprintf(stderr,"\n'change' command usage: %s change notifid jobid\n" - " notifid Notification ID.\n" - " jobid Job ID to connect notif. reg. with.\n", me); - - if ( !cmd || !strcmp(cmd, "refresh") ) - fprintf(stderr,"\n'refresh' command usage: %s refresh [-t requested_validity ] notifid\n" - " requested_validity Validity of notification req. in seconds\n" - " notifid Notification ID.\n", me); - if ( !cmd || !strcmp(cmd, "receive") ) { - fprintf(stderr,"\n'receive' command usage: %s receive [ { -s socket_fd | -a fake_addr } ] [-t requested_validity ] [-i timeout] [-r ] [-f field1,field2,...] [notifid]\n" - " requested_validity Validity of notification req. in seconds (default 3600)\n" - " notifid Notification ID (not used if -s specified).\n" - " fake_addr Fake the client address.\n" - " field1,field2,... List of status fields to print (only owner by default)\n" - " timeout Timeout to receive operation in seconds.\n" - " -r Attempt to refresh the notification handle in 1/2 of current validity.\n" - "\n -a, -t, and -r are unusable with -s\n" - , me); - fprintf(stderr,"\navailable fields:\n\t"); - glite_lb_dump_stat_fields(); - putc(10,stderr); - } - if ( !cmd || !strcmp(cmd, "drop") ) - fprintf(stderr,"\n'drop' command usage: %s drop notifid\n" - " notifid Notification to remove.\n", me); -} - -int main(int argc,char **argv) -{ - edg_wll_Context ctx; - edg_wll_QueryRec **conditions = NULL; - time_t valid = time(NULL) + 999999999; - char *errt, *errd; - void *fields = NULL; - - int sock = -1, flags = 0; - char *fake_addr = NULL; - -// sleep(20); - - me = argv[0]; - edg_wll_InitContext(&ctx); - - if ( argc < 2 ) { - usage(NULL); goto cleanup; - } - if ( (argc < 2) || - !strcmp(argv[1], "help") || !strcmp(argv[1], "--help") || - !strcmp(argv[1], "-h") || !strcmp(argv[1], "-?")) - { - usage(NULL); goto cleanup; - } - else if ( !strcmp(argv[1], "new") ) - { - int c; - edg_wlc_JobId jid; - edg_wll_NotifId id_out; - int attr = 0, i = 0, excl = 0; - edg_wll_GssCred mycred; - edg_wll_GssStatus gss_code; - static struct option long_options[] = { - {"state", required_argument, 0, 'S'}, - {0, 0, 0, 0}}; - int option_index = 0; - char *single, *statelist; - edg_wll_JobStatCode single_code; - int statno, stdelims, sti; - - - - conditions = (edg_wll_QueryRec **)calloc(7,sizeof(edg_wll_QueryRec *)); - conditions[0] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); - - while ((c = getopt_long(argc-1,argv+1,"j:o:v:n:s:a:t:f:cOS:",long_options,&option_index)) > 0) switch (c) { - case 'j': - conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); - conditions[i][0].attr = EDG_WLL_QUERY_ATTR_JOBID; - conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; - if (edg_wlc_JobIdParse(optarg, &jid) ) { - fprintf(stderr,"Job ID parameter not set propperly!\n"); - usage("new"); - goto cleanup; - } - conditions[i][0].value.j = jid; - i++; - break; - case 'o': - if (excl) { usage("new"); return EX_USAGE; } else excl = 1; - conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); - conditions[i][0].attr = EDG_WLL_QUERY_ATTR_OWNER; - conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; - conditions[i][0].value.c = optarg; - i++; - break; - case 'v': - conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); - conditions[i][0].attr = EDG_WLL_QUERY_ATTR_JDL_ATTR; - conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; - conditions[i][0].value.c = optarg; - asprintf(&(conditions[i][0].attr_id.tag), "VirtualOrganisation"); - i++; - break; - case 'n': - conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); - conditions[i][0].attr = EDG_WLL_QUERY_ATTR_NETWORK_SERVER; - conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; - conditions[i][0].value.c = optarg; - i++; - break; - case 's': - if (fake_addr) { usage("new"); return EX_USAGE; } - sock = atoi(optarg); break; - case 'a': - if (sock >= 0) { usage("new"); return EX_USAGE; } - fake_addr = optarg; break; - case 't': - valid = time(NULL) + atol(optarg); break; - case 'f': - flags = atoi(optarg); break; - case 'c': - conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); - conditions[i][0].attr = EDG_WLL_QUERY_ATTR_STATUS; - conditions[i][0].op = EDG_WLL_QUERY_OP_CHANGED; - i++; - break; - case 'O': - if (excl) { usage("new"); return EX_USAGE; } else excl = 1; - if ( !edg_wll_gss_acquire_cred_gsi(NULL, NULL, &mycred, &gss_code) ) - { - conditions[i] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); - conditions[i][0].attr = EDG_WLL_QUERY_ATTR_OWNER; - conditions[i][0].op = EDG_WLL_QUERY_OP_EQUAL; - conditions[i][0].value.c = strdup(mycred->name); - edg_wll_gss_release_cred(&mycred, NULL); - i++; - } - else { - fprintf(stderr,"No credentials found! Exiting. \n"); - goto cleanup; - } - break; - case 'S': - statelist = optarg; - - statno = 0; - stdelims = 0; - for (sti = 0; sti < strlen(statelist); sti++) - if (statelist[sti] == ',') stdelims++; - conditions[i] = (edg_wll_QueryRec *)calloc(stdelims+2,sizeof(edg_wll_QueryRec)); - while(single = strtok(statelist, ",")) { - single_code = edg_wll_StringToStat(single); - if (single_code != -1) { - conditions[i][statno].attr = EDG_WLL_QUERY_ATTR_STATUS; - conditions[i][statno].op = EDG_WLL_QUERY_OP_EQUAL; - conditions[i][statno].value.i = single_code; - statelist = NULL; - statno++; - } - else { - fprintf(stderr,"'%s' is not a valid state name! Exitting.\n", single); - goto cleanup; - } - } - i++; - break; - default: - usage("new"); return EX_USAGE; - } - - if ( !edg_wll_NotifNew(ctx, - (edg_wll_QueryRec const* const*)conditions, - flags, sock, fake_addr, &id_out, &valid)) - fprintf(stdout,"notification ID: %s\nvalid: %s (%ld)\n", - edg_wll_NotifIdUnparse(id_out), - TimeToStr(valid), - valid); - edg_wll_NotifIdFree(id_out); - if (attr == EDG_WLL_QUERY_ATTR_JOBID) edg_wlc_JobIdFree(jid); - } - else if ( !strcmp(argv[1], "bind") ) - { - edg_wll_NotifId nid; - int c; - - while ((c = getopt(argc-1,argv+1,"s:a:t:")) > 0) switch (c) { - case 's': - if (fake_addr) { usage("bind"); return EX_USAGE; } - sock = atoi(optarg); break; - case 'a': - if (sock >= 0) { usage("bind"); return EX_USAGE; } - fake_addr = optarg; break; - case 't': - valid = time(NULL) + atol(optarg); break; - default: - usage("bind"); return EX_USAGE; - } - - if ( (optind+1 == argc) || edg_wll_NotifIdParse(argv[optind+1], &nid) ) - { - fprintf(stderr,"Notification ID parameter not set propperly!\n\n"); - usage("bind"); - return EX_USAGE; - } - if ( !edg_wll_NotifBind(ctx, nid, sock, fake_addr, &valid) ) - printf("valid until: %s (%ld)\n", TimeToStr(valid), valid); - edg_wll_NotifIdFree(nid); - } - else if ( !strcmp(argv[1], "receive") ) - { - edg_wll_JobStat stat; - edg_wll_NotifId nid = NULL; - int c; - char *field_arg = "owner",*err; - time_t client_tout = time(NULL) + 600; - int refresh = 0; - struct timeval tout; - time_t opt_valid = 0,do_refresh = client_tout + 999999999,now; - - while ((c = getopt(argc-1,argv+1,"s:a:i:f:t:r")) > 0) switch (c) { - case 's': - if (fake_addr || refresh || opt_valid) { usage("receive"); return EX_USAGE; } - sock = atoi(optarg); break; - case 'a': - if (sock >= 0) { usage("receive"); return EX_USAGE; } - fake_addr = optarg; break; - case 'i': - client_tout = time(NULL) + atoi(optarg); break; - case 'f': - field_arg = optarg; break; - case 't': - if (sock >= 0) { usage("receive"); return EX_USAGE; } - opt_valid = atol(optarg); break; - case 'r': - if (sock >= 0) { usage("receive"); return EX_USAGE; } - refresh = 1; break; - default: - usage("receive"); return EX_USAGE; - } - - if (opt_valid == 0) opt_valid = 3600; - - if ((err = glite_lb_parse_stat_fields(field_arg,&fields))) { - fprintf(stderr,"%s: invalid argument\n",err); - return EX_USAGE; - } - - memset(&stat,0,sizeof stat); - - if (sock == -1) { - int param = optind+1; - - if (param == argc) - { - fprintf(stderr, "Notification ID parameter not set propperly!\n\n"); - usage("receive"); - return EX_USAGE; - } - - valid = time(NULL) + opt_valid; - - while (param < argc) { - if (edg_wll_NotifIdParse(argv[param], &nid)) { - fprintf(stderr, "Notification ID parameter not set propperly!\n\n"); - usage("receive"); - return EX_USAGE; - } - - if (edg_wll_NotifBind(ctx, nid, -1, fake_addr, &valid) ) - goto receive_err; - fprintf(stderr,"notification is valid until: %s (%ld)\n", TimeToStr(valid), valid); - - if (nid) edg_wll_NotifIdFree(nid); nid = NULL; - param++; - } - now = time(NULL); - do_refresh = now + (refresh ? (valid - now)/2 : 999999999); - if (refresh) fprintf(stderr,"next refresh %s (%ld)\n", - TimeToStr(do_refresh),do_refresh); - } - - do { - edg_wll_NotifId recv_nid = NULL; - int err; - - tout.tv_sec = (client_tout < do_refresh ? - client_tout : do_refresh) - - time(NULL); - if (tout.tv_sec < 0) tout.tv_sec = 0; - tout.tv_usec = 0; - - edg_wll_FreeStatus(&stat); - stat.state = EDG_WLL_JOB_UNDEF; - - if ( (err = edg_wll_NotifReceive(ctx, sock, &tout, &stat, &recv_nid)) ) { - edg_wll_NotifIdFree(recv_nid); - recv_nid = NULL; - - if (err != ETIMEDOUT) goto receive_err; - } - else glite_lb_print_stat_fields(fields,&stat); - - if ((now = time(NULL)) >= client_tout) return 0; - - if (refresh && now >= do_refresh) { - valid = now + opt_valid; - if (!edg_wll_NotifRefresh(ctx,nid,&valid)) { - do_refresh = now + (valid - now)/2; - fprintf(stderr,"notification is valid until: %s (%ld)\n",TimeToStr(valid), valid); - fprintf(stderr,"next refresh %s (%ld)\n", TimeToStr(do_refresh),do_refresh); - } - else { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - do_refresh = now + (valid - now)/2; - fprintf(stderr,"warning: edg_wll_NotifRefresh failed (%s, %s)\n" - "next refresh %s (%ld)\n", - et,ed,TimeToStr(do_refresh),do_refresh); - } - } -/* original example */ -#if 0 - printf("\nnotification ID: %s\n", edg_wll_NotifIdUnparse(recv_nid)); - - if (stat.state != EDG_WLL_JOB_UNDEF) { - char *jobid_s; - - jobid_s = edg_wlc_JobIdUnparse(stat.jobId); - printf("Jobid:\t%s\nStatus:\t%s\n", - jobid_s, - edg_wll_StatToString(stat.state)); - edg_wll_FreeStatus(&stat); - free(jobid_s); - stat.state = EDG_WLL_JOB_UNDEF; - } -#endif - - if (recv_nid) { - edg_wll_NotifIdFree(recv_nid); - recv_nid = NULL; - } - } while (1); // till timeout.... - return 0; - -receive_err: - if (stat.state != EDG_WLL_JOB_UNDEF) edg_wll_FreeStatus(&stat); - if (nid) edg_wll_NotifIdFree(nid); - edg_wll_NotifCloseFd(ctx); - edg_wll_NotifClosePool(ctx); - - if (edg_wll_Error(ctx,&errt,&errd)) - fprintf(stderr, "%s: %s (%s)\n", me, errt, errd); - - return EX_IOERR; - } - else if ( !strcmp(argv[1], "change") ) - { - edg_wlc_JobId jid; - edg_wll_NotifId nid; - - if ( (argc < 3) || edg_wll_NotifIdParse(argv[2], &nid) ) - { - printf("Notification ID parameter not set propperly!\n"); - usage("bind"); - return 1; - } - if ( (argc < 4) || edg_wlc_JobIdParse(argv[3], &jid) ) - { - fprintf(stderr,"Job ID parameter not set propperly!\n"); - usage("change"); - goto cleanup; - } - - conditions = (edg_wll_QueryRec **)calloc(2,sizeof(edg_wll_QueryRec *)); - conditions[0] = (edg_wll_QueryRec *)calloc(2,sizeof(edg_wll_QueryRec)); - conditions[1] = (edg_wll_QueryRec *)calloc(3, sizeof(edg_wll_QueryRec)); - - conditions[0][0].attr = EDG_WLL_QUERY_ATTR_JOBID; - conditions[0][0].op = EDG_WLL_QUERY_OP_EQUAL; - conditions[0][0].value.j = jid; - - /*conditions[1][0].attr = EDG_WLL_QUERY_ATTR_STATUS; - conditions[1][0].op = EDG_WLL_QUERY_OP_EQUAL; - conditions[1][0].value.i = EDG_WLL_JOB_DONE; - - conditions[1][1].attr = EDG_WLL_QUERY_ATTR_STATUS; - conditions[1][1].op = EDG_WLL_QUERY_OP_EQUAL; - conditions[1][1].value.i = EDG_WLL_JOB_RUNNING;*/ - - edg_wll_NotifChange(ctx, nid, - (edg_wll_QueryRec const * const *) conditions, - EDG_WLL_NOTIF_REPLACE); - edg_wlc_JobIdFree(jid); - edg_wll_NotifIdFree(nid); - } - else if ( !strcmp(argv[1], "refresh") ) - { - edg_wll_NotifId nid; - int c; - - while ((c = getopt(argc-1,argv+1,"t:")) > 0) switch (c) { - case 't': - valid = time(NULL) + atol(optarg); break; - default: - usage("refresh"); return EX_USAGE; - } - - if ( (optind+1 == argc) || edg_wll_NotifIdParse(argv[optind+1], &nid) ) - { - fprintf(stderr,"Notification ID parameter not set propperly!\n\n"); - usage("refresh"); - return EX_USAGE; - } - - if ( !edg_wll_NotifRefresh(ctx, nid, &valid) ) - printf("valid until: %s (%ld)\n", TimeToStr(valid), valid); - edg_wll_NotifIdFree(nid); - } - else if ( !strcmp(argv[1], "drop") ) - { - edg_wll_NotifId nid; - - if ( (argc < 3) || edg_wll_NotifIdParse(argv[2], &nid) ) - { - fprintf(stderr,"Notification ID parameter not set propperly!\n"); - usage("drop"); - return EX_USAGE; - } - edg_wll_NotifDrop(ctx, nid); - edg_wll_NotifIdFree(nid); - } - else { - usage(NULL); - return EX_USAGE; - } - -cleanup: - - if ( conditions ) - { - /* - for ( i = 0; conditions[i][0].attr; i++ ) - free(conditions[1]); - */ - free(conditions); - } - - edg_wll_NotifCloseFd(ctx); - - if (edg_wll_Error(ctx,&errt,&errd)) - fprintf(stderr, "%s: %s (%s)\n", me, errt, errd); - - edg_wll_FreeContext(ctx); - - - return 0; -} diff --git a/org.glite.lb.client/src/perftest_jobreg.c b/org.glite.lb.client/src/perftest_jobreg.c deleted file mode 100644 index 13aa15c..0000000 --- a/org.glite.lb.client/src/perftest_jobreg.c +++ /dev/null @@ -1,218 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "producer.h" -#include "glite/lb/events.h" - -#define PROXY_SERVER "localhost:9000" - -#define tv_sub(a,b) {\ - (a).tv_usec -= (b).tv_usec;\ - (a).tv_sec -= (b).tv_sec;\ - if ((a).tv_usec < 0) {\ - (a).tv_sec--;\ - (a).tv_usec += 1000000;\ - }\ -} - -#define dprintf(x) { if (verbose) printf x; } - - -extern char *optarg; -extern int opterr,optind; - -static void usage(char *me) -{ - fprintf(stderr,"usage: %s [-m bkserver] [-x scenario] [-n num_subjobs [-S]] [-l jdl_file] [-N num_repeat]\n" - " -m address:port of bkserver\n" - " -x use LBProxy\n" - " 1 use one call (RegisterJobProxyOnly - register only with lbproxy) \n" - " 2 use one call (RegisterJobProxyOld - sequence registration) \n" - " 3 use one call (RegisterJobProxy - dual registration) \n" - " 0 (or anything else) do not register to lbproxy at all\n" - " -n number of subjobs of DAG\n" - " -S register subjobs\n" - " -l file with JDL\n" - " -N repeat whole registration N-times\n" - " -v verbose output\n", - me); -} - -int main(int argc, char *argv[]) -{ - char *server = NULL,*jdl = NULL; - int lbproxy = 0, N = 1, verbose = 0; - int done = 0,num_subjobs = 0,reg_subjobs = 0, i, j; - edg_wll_Context ctx; - edg_wlc_JobId *jobids,*subjobs; - struct timeval start, stop; - - - edg_wll_InitContext(&ctx); - opterr = 0; - - do { - switch (getopt(argc,argv,"x:m:n:Sl:N:v")) { - case 'x': lbproxy = optarg ? atoi(optarg):1; break; - case 'm': server = strdup(optarg); break; - case 'n': num_subjobs = atoi(optarg); break; - case 'S': if (num_subjobs>0) { reg_subjobs = 1; break; } - case 'l': jdl = (char *) strdup(optarg); break; - case 'N': N = atoi(optarg); break; - case 'v': verbose = 1; break; - case '?': usage(argv[0]); exit(EINVAL); - case -1: done = 1; break; - } - } while (!done); - - if ((lbproxy > 3) || (lbproxy < 0)) lbproxy = 1; - - if (!server && !lbproxy) { - fprintf(stderr,"%s: either -m server or -x has to be specified\n",argv[0]); - exit(1); - } - - /* prepare set of N jobid before starting timer */ - jobids = (edg_wlc_JobId *) malloc(N * sizeof(edg_wlc_JobId)); - dprintf(("generating jobids...")); - { - char *name=server?server:strdup(PROXY_SERVER); - char *p = strchr(name,':'); - int port; - - if (p) { *p=0; port = atoi(p+1); } - else port = 0; - for (i=0; i 0; p += c); - if (c<0) { - perror("read()"); - exit (1); - } - jdl[p] = 0; - } - - edg_wll_SetParam(ctx,EDG_WLL_PARAM_SOURCE,edg_wll_StringToSource("Application")); - - /* start measurement */ - gettimeofday(&start, NULL); - - for (i=0; i&2 -} - -my_echo() -{ - echo $1 1>&2 -} - - -start_bkserver() -{ - # production version - usable only when starting as root - # $GLITE_LOCATION/etc/init.d/glite-lb-bkserverd start - - # workaround - [ -n "$GLITE_LB_SERVER_PIDFILE" ] && pidfile=$GLITE_LB_SERVER_PIDFILE || - pidfile=$GLITE_LOCATION_VAR/glite-lb-bkserverd.pid - - [ -z "$GLITE_LB_EXPORT_JPREG_MAILDIR" ] && \ - GLITE_LB_EXPORT_JPREG_MAILDIR=/tmp/jpreg - maildir="--jpreg-dir $GLITE_LB_EXPORT_JPREG_MAILDIR" - [ -d "$GLITE_LB_EXPORT_JPREG_MAILDIR" ] || \ - mkdir -p "$GLITE_LB_EXPORT_JPREG_MAILDIR" - - [ -n "$GLITE_LB_SERVER_PORT" ] && port="-p $GLITE_LB_SERVER_PORT" - [ -n "$GLITE_LB_SERVER_WPORT" ] && wport="-w $GLITE_LB_SERVER_WPORT" - [ -n "$GLITE_LB_SERVER_TRANSACTION" ] && trans="-b $GLITE_LB_SERVER_TRANSACTION" - - if [ -n "$1" ]; then - sink="--perf-sink $1" - else - sink="" - fi - - echo -n "Starting glite-lb-bkserver ..." - $GLITE_LOCATION/bin/glite-lb-bkserverd \ - $creds -i $pidfile $port $wport $maildir $sink $trans\ - --purge-prefix /tmp/purge_new --dump-prefix /tmp/dump_new -s 1\ - && echo " done" || echo " FAILED" - echo -} - - -stop_bkserver() -{ - echo - 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; - kill $pid 2>/dev/null - try=`expr $try + 1` - if [ $try = 19 ]; then - echo "bkserver jammed - sending kill -9" - kill -9 $pid 2>/dev/null - fi - if [ $try = 20 ]; then - echo " giving up after $try retries" - return 1 - fi - done - echo " done" - rm -f $pidfile - rm -rf $GLITE_LB_EXPORT_JPREG_MAILDIR - else - echo $pidfile does not exist - glite-lb-bkserverd not running? >&2 - return 1 - fi - -} - - -start_proxy() -{ - [ -n "$GLITE_LB_PROXY_PIDFILE" ] && proxy_pidfile=$GLITE_LB_PROXY_PIDFILE || - proxy_pidfile=$GLITE_LOCATION_VAR/glite-lb-proxy.pid - - [ -n "$GLITE_LB_PROXY_SOCK_PREFIX" ] && proxy_sock_prefix="-p $GLITE_LB_PROXY_SOCK_PREFIX" || - proxy_sock_prefix="" - - [ -n "$1" ] && sink="-K $1" || sink_mode= - - echo -n Starting glite-lb-proxy ... - $GLITE_LOCATION/bin/glite-lb-proxy \ - -i $proxy_pidfile $proxy_sock_prefix $sink \ - && echo " done" || echo " FAILED" - echo -} - -stop_proxy() -{ - echo - if [ -f $proxy_pidfile ]; then - pid=`cat $proxy_pidfile` - kill $pid - echo -n Stopping glite-lb-proxy \($pid\) ... - try=0 - while ps p $pid >/dev/null 2>&1; do - sleep 1; - kill $pid 2>/dev/null - try=`expr $try + 1` - if [ $try = 20 ]; then - echo " giving up after $try retries" - return 1 - fi - done - echo " done" - rm -f $proxy_pidfile - rm -rf $GLITE_LB_EXPORT_JPREG_MAILDIR - else - echo $proxy_pidfile does not exist - glite-lb-proxy not running? >&2 - return 1 - fi -} - -start_il() -{ - [ -n "$GLITE_LB_IL_SOCK" ] && il_sock="-s $GLITE_LB_PROXY_SOCK" || - il_sock="" - - [ -n "$GLITE_LB_IL_PREFIX" ] && il_prefix="-f $GLITE_LB_IL_PREFIX" || - il_prefix="" - - echo -n Starting glite-lb-interlogger ... - $GLITE_LOCATION/bin/glite-lb-interlogd \ - $creds $il_sock $il_prefix \ - && echo " done" || echo " FAILED" - echo - -} - -stop_il() -{ - killall glite-lb-interlogger -} - - -# - Test types - -# -# i) normally procesed by server & proxy -# ii) server replies immedia success -# iii) proxy replies immediate succes -# a) current implementation -# b) connection pool -# c) parallel communication - -test_ai() -{ - dest= - [ -z "$1" ] && echo "test_ai() - wrong params" && return - [ "$1" = "proxy" ] && dest="-x" - [ "$1" = "server" ] && dest="-m $BKSERVER_HOST" - [ -z "$dest" ] && echo "test_ai() - wrong params" && return - - my_echo "================================================================" - my_echo "Testing LB $1 with sink_mode ${sink_mode[$2]}" - - # single registration - # - my_echo "-n single registration ..." - ai_sr_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest` - mega_actions_per_day=`echo "scale=6; 86400/$ai_sr_lb/1000000" | bc` - my_echo ". $ai_sr_lb seconds ($mega_actions_per_day GU)" - - # average single registration (100 samples) - # - my_echo "-n average single registration (100 samples) ..." - ai_100sr_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest -N 100` - ai_avg_sr_lb=`echo "scale=6; $ai_100sr_lb/100" |bc` - mega_actions_per_day=`echo "scale=6; 86400/$ai_avg_sr_lb/1000000" | bc` - my_echo ". $ai_avg_sr_lb seconds ($mega_actions_per_day GU)" - - # 1000 nodes DAG registration - # - my_echo "-n 1000 nodes DAG registration ..." - ai_dag1000_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest -n 1000` - mega_actions_per_day=`echo "scale=6; 86400/$ai_dag1000_lb/1000000*1001" | bc` - my_echo ". $ai_dag1000_lb seconds ($mega_actions_per_day GU)" - - # 5000 nodes DAG registration - # - my_echo "-n 5000 nodes DAG registration ..." - ai_dag5000_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest -n 5000` - mega_actions_per_day=`echo "scale=6; 86400/$ai_dag5000_lb/1000000*5001" | bc` - my_echo ". $ai_dag5000_lb seconds ($mega_actions_per_day GU)" - - # 10000 nodes DAG registration - # - my_echo "-n 10000 nodes DAG registration ..." - ai_dag10000_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest -n 10000` - mega_actions_per_day=`echo "scale=6; 86400/$ai_dag10000_lb/1000000*10001" | bc` - my_echo ". $ai_dag10000_lb seconds ($mega_actions_per_day GU)" - -} - -quick_test() -{ - dest= - [ -z "$1" ] && echo "test_ai() - wrong params" && return - [ "$1" = "proxy" ] && dest="-x" - [ "$1" = "server" ] && dest="-m $BKSERVER_HOST" - [ -z "$dest" ] && echo "test_ai() - wrong params" && return - - - # 1000 nodes DAG registration - # - my_echo "-n 1000 nodes DAG registration ..." - ai_dag1000_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest -n 1000` - mega_actions_per_day=`echo "scale=6; 86400/$ai_dag1000_lb/1000000*1001" | bc` - my_echo ". $ai_dag1000_lb seconds ($mega_actions_per_day GU)" - -} - -proxy_test() -{ - my_echo "----------------------------------------------------------------" - my_echo "Scenarios:" - my_echo "0) registration only to bkserver (edg_wll_RegisterJobSync)" - my_echo "1) registration only to lbproxy (edg_wll_RegisterJobProxyOnly)" - my_echo "2) old (not dual) registration (edg_wll_RegisterJobProxyOld)" - my_echo "3) dual registration (edg_wll_RegisterJobProxy)" - my_echo "" - - if [ -n "$1" ]; then - repeat="-N $1" - repeated="repeated $1 times" - scale=$1 - else - repeat="" - repeated="" - scale=1 - fi - - # single registration - # - for i in 0 1 2 3; do - dest="-m $BKSERVER_HOST -x $i" - my_echo "-n single registration $repeated (scenario $i)..." - ai_sr_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest $repeat` - mega_actions_per_day=`echo "scale=6; 86400/$ai_sr_lb/1000000*$scale" | bc` - my_echo ". $ai_sr_lb seconds ($mega_actions_per_day GU)" - sleep 3 - sync - sleep 3 - done - - # 1 node DAG registration - # - for i in 0 1 2 3; do - dest="-m $BKSERVER_HOST -x $i" - my_echo "-n 1 node DAG registration $repeated (scenario $i)..." - ai_dag1_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest $repeat -n 1` - mega_actions_per_day=`echo "scale=6; 86400/$ai_dag1_lb/1000000*2*$scale" | bc` - my_echo ". $ai_dag1_lb seconds ($mega_actions_per_day GU)" - sleep 3 - sync - sleep 3 - done - - # 1000 nodes DAG registration - # - for i in 0 1 2 3; do - dest="-m $BKSERVER_HOST -x $i" - my_echo "-n 1000 nodes DAG registration $repeated (scenario $i)..." - ai_dag1000_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest $repeat -n 1000` - mega_actions_per_day=`echo "scale=6; 86400/$ai_dag1000_lb/1000000*1001*$scale" | bc` - my_echo ". $ai_dag1000_lb seconds ($mega_actions_per_day GU)" - sleep 10 - sync - sleep 10 - done - - # 10000 nodes DAG registration - # - for i in 0 1 2 3; do - dest="-m $BKSERVER_HOST -x $i" - my_echo "-n 10000 nodes DAG registration $repeated (scenario $i)..." - ai_dag10000_lb=`$GLITE_LOCATION/sbin/glite-lb-perftest_jobreg $dest $repeat -n 10000` - mega_actions_per_day=`echo "scale=6; 86400/$ai_dag10000_lb/1000000*10001*$scale" | bc` - my_echo ". $ai_dag10000_lb seconds ($mega_actions_per_day GU)" - sleep 10 - sync - sleep 10 - done - - -} - - -################################################################################ - -unset creds port -if [ -z ${BKSERVER_HOST} ]; then - HOST=`hostname -f` - PORT=${GLITE_LB_SERVER_PORT:-9000}; - BKSERVER_HOST=$HOST:$PORT -fi -sink_mode[0]=GLITE_LB_SINK_NONE -sink_mode[1]=GLITE_LB_SINK_PARSE -sink_mode[2]=GLITE_LB_SINK_STORE -sink_mode[3]=GLITE_LB_SINK_STATE -sink_mode[4]=GLITE_LB_SINK_SEND - -test_glite_location; -test_credentials; - -# -# QUICK TEST -# -#start_bkserver 0; -#start_proxy 0; -#my_echo "================================================================" -#my_echo "Testing LB server with sink_mode ${sink_mode[0]}" -#my_echo "Testing LB proxy with sink_mode ${sink_mode[0]}" -#sleep 5 -#sync -#sleep 5 -#for i in `seq 1 10000`; do -# quick_test server 0; -## quick_test proxy 0; -#done -#stop_bkserver; -#stop_proxy; - -# -# SINK TEST -# -#for i in 1 2 3 4; do -# my_echo "================================================================" -# -# my_echo "Testing LB proxy with sink_mode ${sink_mode[$i]}" -# start_proxy $i -# test_ai proxy $i; -# stop_proxy -# -# my_echo "Testing LB server with sink_mode ${sink_mode[$i]}" -# start_bkserver $i; -# test_ai server $i; -# stop_bkserver; -#done - -# -# PROXY TEST -# -#start_proxy 0; -#start_il; -my_echo "================================================================" -my_echo "Testing registrations to bkserver ($BKSERVER_HOST) and to lbproxy" -#sleep 5 -for i in 1 10 100 1000; do - proxy_test $i; -done -#stop_proxy; -#stop_il; - -echo "__________" -echo "GU (goal units) are millons of registrations per day, where registration is" -echo "registration of job or subjob by client or server" -echo diff --git a/org.glite.lb.client/src/perftest_logjobs.c b/org.glite.lb.client/src/perftest_logjobs.c deleted file mode 100644 index 595d812..0000000 --- a/org.glite.lb.client/src/perftest_logjobs.c +++ /dev/null @@ -1,307 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "glite/lb/context-int.h" -#include "glite/lb/lb_perftest.h" -#include "glite/lb/log_proto.h" - -extern int edg_wll_DoLogEvent(edg_wll_Context context, edg_wll_LogLine logline); -extern int edg_wll_DoLogEventProxy(edg_wll_Context context, edg_wll_LogLine logline); -extern int edg_wll_DoLogEventDirect(edg_wll_Context context, edg_wll_LogLine logline); - -#define DEFAULT_SOCKET "/tmp/interlogger.sock" -#define DEFAULT_PREFIX EDG_WLL_LOG_PREFIX_DEFAULT - -/* -extern char *optarg; -extern int opterr,optind; - -Vzorem by mel byt examples/stresslog.c, ovsem s mirnymi upravami: - -1) nacte udalosti jednoho jobu z daneho souboru, rozparsuje a ulozi do pameti -2) je-li pozadan, zaregistruje dany pocet jobid -3) vypise timestamp -4) odesle rozparsovane udalosti pod ruznymi jobid (tolika, kolik ma - byt jobu - argument) na dany cil (localloger, interlogger, bkserver, proxy) -5) odesle specialni ukoncovaci udalost -6) exit - - read_job("small_job",&event_lines); - gettimeoday(&zacatek) - for (i=0; i<1000; i++) { - for (e=0; event_lines[e]; e++) - edg_wll_ParseEvent(event_lines[e],&event[e]); - } - gettimeofday(&konec); - - printf("parsovani",konec-zacatek/1000); - - gettimeofday(&zacatek); - switch (event[e].type) { - ... - edg_wll_LogBlaBla() - - -*/ - -static struct option const long_options[] = { - { "help", no_argument, 0, 'h' }, - { "dst", required_argument, NULL, 'd' }, - { "test", required_argument, NULL, 't' }, - { "file", required_argument, NULL, 'f'}, - { "num", required_argument, NULL, 'n'}, - { "machine", required_argument, NULL, 'm'}, - { "nofile", no_argument, NULL, 'N'}, - { "skip", optional_argument, NULL, 'P'}, - { "sock", required_argument, NULL, 's'}, - { "file-prefix", required_argument, NULL, 'p'}, - { NULL, 0, NULL, 0} -}; - - -int nofile = 0; -char *logfile_prefix = DEFAULT_PREFIX; -char *il_socket = NULL; - -void -usage(char *program_name) -{ - fprintf(stderr, "Usage: %s [-d destname] [-t testname] -f filename -n numjobs \n" - "-h, --help display this help and exit\n" - "-d, --dst destination component\n" - "-s, --sock socket name for IL\n" - "-m, --machine destination host\n" - "-t, --test name of the test\n" - "-f, --file name of the file with prototyped job events\n" - "-n, --num number of jobs to generate\n" - "-P, --skip [] number of events to skip when sending to IL by IPC\n" - "-p, --file-prefix file prefix of event files\n" - "-N, --nofile do not store events in file for interlogger (if dst==IL)\n", - program_name); -} - - -#define FCNTL_ATTEMPTS 5 -#define FCNTL_TIMEOUT 1 - -int edg_wll_DoLogEventIl( - edg_wll_Context context, - edg_wll_LogLine logline, - const char *jobid, - int len, - int skip) -{ - static long filepos = 0; - int ret = 0; - edg_wlc_JobId jid; - char *unique, *event_file; - static int num_event = 0; - char *event; - const char *user = " DG.USER=\"michal\"\n"; - - /* we must fill in DG.USER */ - /* we need room for user (=strlen(user)), terminating \0 (+1), - but we overwrite trailing \n (-1) */ - event = realloc(logline, len + strlen(user)); - if(event == NULL) { - return(edg_wll_SetError(context, ENOMEM, "realloc()")); - } - /* it really does not matter WHERE the key is, so append it at the end */ - memmove(event + len - 1, user, strlen(user) + 1); - len += strlen(user) - 1; - - if(!nofile) { - ret = edg_wlc_JobIdParse(jobid, &jid); - if(ret != 0) - return(edg_wll_SetError(context, ret, "edg_wlc_JobIdParse()")); - unique = edg_wlc_JobIdGetUnique(jid); - if(unique == NULL) { - edg_wlc_JobIdFree(jid); - return(edg_wll_SetError(context, ENOMEM, "edg_wlc_JobIdGetUnique()")); - } - asprintf(&event_file, "%s.%s", logfile_prefix, unique); - if(!event_file) { - free(unique); - edg_wlc_JobIdFree(jid); - return(edg_wll_SetError(context, ENOMEM, "asprintf()")); - } - if(edg_wll_log_event_write(context, event_file, event, - context->p_tmp_timeout.tv_sec > FCNTL_ATTEMPTS ? context->p_tmp_timeout.tv_sec : FCNTL_ATTEMPTS, - FCNTL_TIMEOUT, - &filepos)) { - edg_wll_UpdateError(context, 0, "edg_wll_log_event_write()"); - free(unique); - edg_wlc_JobIdFree(jid); - free(event_file); - } - } - if(nofile || - (skip < 0) || - ((skip > 0) && (++num_event % skip == 0))) - ret = edg_wll_log_event_send(context, il_socket, filepos, - event, len, 1, - &context->p_tmp_timeout); - if(!nofile) { - free(unique); - edg_wlc_JobIdFree(jid); - free(event_file); - } else { - filepos += len; - } - - return(ret); -} - - -int -main(int argc, char *argv[]) -{ - - char *destname= NULL,*hostname=NULL,*testname = NULL,*filename = NULL; - char *event; - int num_jobs = 1; - int opt; - int skip = -1; - edg_wll_Context ctx; - enum { - DEST_UNDEF = 0, - DEST_LL, - DEST_IL, - DEST_PROXY, - DEST_BKSERVER - } dest = 0; - - - edg_wll_InitContext(&ctx); - - opterr = 0; - - while ((opt = getopt_long(argc,argv,"hd:t:f:m:n:Ns:P::p:", - long_options, (int *) 0)) != EOF) { - - switch (opt) { - case 'd': destname = (char *) strdup(optarg); break; - case 't': testname = (char *) strdup(optarg); break; - case 'f': filename = (char *) strdup(optarg); break; - case 'm': hostname = (char *) strdup(optarg); break; - case 'p': logfile_prefix = (char*) strdup(optarg); break; - case 's': il_socket = (char*) strdup(optarg); break; - case 'n': num_jobs = atoi(optarg); break; - case 'N': nofile = 1; break; - case 'P': skip = optarg ? atoi(optarg) : 0; break; - case 'h': - default: - usage(argv[0]); exit(0); - } - } - - if(destname) { - if(!strncasecmp(destname, "pr", 2)) - dest=DEST_PROXY; - else if(!strncasecmp(destname, "lo", 2) || !strncasecmp(destname, "ll", 2)) - dest=DEST_LL; - else if(!strncasecmp(destname, "in", 2) || !strncasecmp(destname, "il", 2)) - dest=DEST_IL; - else if(!strncasecmp(destname, "bk", 2) || !strncasecmp(destname, "se", 2)) - dest=DEST_BKSERVER; - else { - fprintf(stderr,"%s: wrong destination\n",argv[0]); - usage(argv[0]); - exit(1); - } - } - - if((dest == DEST_IL) && (il_socket == NULL)) - il_socket = DEFAULT_SOCKET; - if((dest == DEST_PROXY) && il_socket) { - char store_sock[256], serve_sock[256]; - sprintf(store_sock, "%s%s", il_socket, "store.sock"); - sprintf(serve_sock, "%s%s", il_socket, "serve.sock"); - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_STORE_SOCK, store_sock); - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, serve_sock); - } - - if (num_jobs <= 0) { - fprintf(stderr,"%s: wrong number of jobs\n",argv[0]); - usage(argv[0]); - exit(1); - } - - if (!filename && destname) { - fprintf(stderr,"%s: -f required\n",argv[0]); - usage(argv[0]); - exit(1); - } - - if (glite_wll_perftest_init(hostname, NULL, testname, filename, num_jobs) < 0) { - fprintf(stderr,"%s: glite_wll_perftest_init failed\n",argv[0]); - exit(1); - } - - if(dest) { - char *jobid; - int len; - while ((len=glite_wll_perftest_produceEventString(&event, &jobid)) > 0) { - switch(dest) { - case DEST_PROXY: - ctx->p_tmp_timeout = ctx->p_sync_timeout; - if (edg_wll_DoLogEventProxy(ctx,event)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_DoLogEventProxy(): %s (%s)\n",et,ed); - exit(1); - } - break; - - case DEST_LL: - ctx->p_tmp_timeout = ctx->p_log_timeout; - if (edg_wll_DoLogEvent(ctx,event)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_DoLogEvent(): %s (%s)\n",et,ed); - exit(1); - } - break; - - case DEST_BKSERVER: - ctx->p_tmp_timeout = ctx->p_log_timeout; - edg_wlc_JobIdParse(jobid, &ctx->p_jobid); - if (edg_wll_DoLogEventDirect(ctx, event)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_DoLogEventDirect(): %s (%s)\n",et,ed); - exit(1); - } - break; - - case DEST_IL: - ctx->p_tmp_timeout = ctx->p_log_timeout; - if (edg_wll_DoLogEventIl(ctx, event, jobid, len, skip)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"edg_wll_DoLogEventIl(): %s (%s)\n",et,ed); - exit(1); - } - break; - - default: - break; - } - free(event); - } - } else { - /* no destination - only print jobid's that would be used */ - char *jobid; - - while(jobid = glite_wll_perftest_produceJobId()) { - fprintf(stdout, "%s\n", jobid); - } - } - edg_wll_FreeContext(ctx); - return 0; - -} diff --git a/org.glite.lb.client/src/perftest_query.sh b/org.glite.lb.client/src/perftest_query.sh deleted file mode 100644 index 1905f20..0000000 --- a/org.glite.lb.client/src/perftest_query.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -clients=${1:-3} - -jobs=${2:-/tmp/perftest_10.jobids} - -# XXX - there must be better way to find stage -if [ -z "${GLITE_LOCATION}" ]; then - STAGEDIR=/home/michal/shared/egee/jra1-head/stage -else - STAGEDIR=${GLITE_LOCATION} -fi -JOBSTAT=$STAGEDIR/examples/glite-lb-job_status - -ask() { - $JOBSTAT `cat $jobs` -} - -do_ask() { - while (true) - do - ask - sleep `expr 5 \* $RANDOM / 32767` - done -} - -for i in `seq 1 $clients` -do - do_ask & -done - diff --git a/org.glite.lb.client/src/prod_proto.c b/org.glite.lb.client/src/prod_proto.c deleted file mode 100644 index 90f6785..0000000 --- a/org.glite.lb.client/src/prod_proto.c +++ /dev/null @@ -1,823 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lb/lb_plain_io.h" -#include "glite/lb/il_msg.h" -#include "glite/lb/il_string.h" -#include "glite/lb/connpool.h" - -#include "prod_proto.h" -#include "producer.h" -#include "connection.h" - -static const char* socket_path="/tmp/lb_proxy_store.sock"; - -/** - *---------------------------------------------------------------------- - * Handle GSS failures on the client side - *---------------------------------------------------------------------- - */ -/* TODO: restructuring - move handle_gss_failures to a separate file - and use it both in producer (here) and consumer (connection.c) -*/ -static -int handle_gss_failures(edg_wll_Context ctx, int code, edg_wll_GssStatus *gss_code, const char *text) -{ - static char err[256]; - int myerrno, ret; - - myerrno = errno; - ret = 0; - - edg_wll_ResetError(ctx); - - if(code>0) - return(0); - - switch(code) { - case EDG_WLL_GSS_ERROR_EOF: - snprintf(err, sizeof(err), "%s;; GSS Error: EOF occured;", text); - ret = edg_wll_SetError(ctx,ENOTCONN,err); - break; - case EDG_WLL_GSS_ERROR_TIMEOUT: - snprintf(err, sizeof(err), "%s;; GSS Error: timeout expired;", text); - ret = edg_wll_SetError(ctx,ENOTCONN,err); - break; - case EDG_WLL_GSS_ERROR_ERRNO: - { - const char *msg1; - char *msg2; - msg1 = strerror(myerrno); - asprintf(&msg2, "%s;; System Error: %s", text, msg1); - ret = edg_wll_SetError(ctx,ENOTCONN,msg2); - free(msg2); - } - break; - case EDG_WLL_GSS_ERROR_GSS: - snprintf(err, sizeof(err), "%s;; GSS Error: GSS failure occured", text); - ret = edg_wll_SetErrorGss(ctx,err,gss_code); - break; - case EDG_WLL_GSS_ERROR_HERRNO: - { - const char *msg1; - char *msg2; - msg1 = hstrerror(myerrno); - asprintf(&msg2, "%s;; GSS Error: %s", text, msg1); - ret = edg_wll_SetError(ctx,EDG_WLL_ERROR_DNS, msg2); - free(msg2); - } - break; - default: - snprintf(err, sizeof(err), "%s;; GSS Error: unknown failure", text); - ret = edg_wll_SetError(ctx,ECONNREFUSED,err); - break; - } - return ret; -} - -/* TODO: restructuring - start using the following to provide better error handling when communicating with proxy - and use it also both in producer and consumer -*/ -#if 0 /* unused */ -/** - *---------------------------------------------------------------------- - * Handle UNIX socket failures on the client side - *---------------------------------------------------------------------- - */ -static -int edg_wll_log_proto_handle_plain_failures(edg_wll_Context ctx, int code, const char *text) -{ - return 0; -} -#endif - -/* - *---------------------------------------------------------------------- - * get_reply_plain, get_reply_gss - read reply from server - * - * Returns: -1 - error reading message, - * code > 0 - error code from server - *---------------------------------------------------------------------- - */ -struct reader_data { - edg_wll_Context ctx; - void *conn; -}; - -static -int plain_reader(void *user_data, char *buffer, int max_len) -{ - struct reader_data *data = (struct reader_data *)user_data; - int len; - - len = edg_wll_plain_read_full(data->conn, buffer, max_len, &data->ctx->p_tmp_timeout); - if(len < 0) { - edg_wll_SetError(data->ctx, errno, "edg_wll_plain_read_full()"); - edg_wll_UpdateError(data->ctx, EDG_WLL_IL_PROTO, "plain_reader(): error reading message data"); - } - - return(len); -} - -static -int get_reply_plain(edg_wll_Context ctx, edg_wll_PlainConnection *conn, char **buf, int *code_maj, int *code_min) -{ - char *msg=NULL; - int len; - struct reader_data data; - - data.ctx = ctx; - data.conn = conn; - len = read_il_data(&data, &msg, plain_reader); - if(len < 0) { - edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "get_reply_plain(): error reading message"); - goto get_reply_plain_end; - } - - if(decode_il_reply(code_maj, code_min, buf, msg) < 0) { - edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "get_reply_plain(): error decoding message"); - goto get_reply_plain_end; - } - -get_reply_plain_end: - if(msg) free(msg); - return edg_wll_Error(ctx,NULL,NULL); -} - - -static -int gss_reader(void *user_data, char *buffer, int max_len) -{ - struct reader_data *data = (struct reader_data *)user_data; - int ret; - size_t len; - edg_wll_GssStatus gss_code; - - ret = edg_wll_gss_read_full(data->conn, buffer, max_len, &data->ctx->p_tmp_timeout, - &len, &gss_code); - if(ret < 0) { - handle_gss_failures(data->ctx, ret, &gss_code, "edg_wll_gss_read_full"); - edg_wll_UpdateError(data->ctx, EDG_WLL_IL_PROTO, "gss_reader(): error reading message"); - } - - return(ret); -} - - -static -int get_reply_gss(edg_wll_Context ctx, edg_wll_GssConnection *conn, char **buf, int *code_maj, int *code_min) -{ - char *msg = NULL; - int code; - struct reader_data data; - - data.ctx = ctx; - data.conn = conn; - code = read_il_data(&data, &msg, gss_reader); - if(code < 0) { - edg_wll_UpdateError(ctx, EDG_WLL_IL_PROTO, "get_reply_gss(): error reading reply"); - goto get_reply_gss_end; - } - - if(decode_il_reply(code_maj, code_min, buf, msg) < 0) { - char *et; - asprintf(&et,"get_reply_gss(): error decoding reply \"%s\"", msg); - edg_wll_UpdateError(ctx, EDG_WLL_IL_PROTO, et); - if (et) free(et); - goto get_reply_gss_end; - } - -get_reply_gss_end: - if(msg) free(msg); - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *---------------------------------------------------------------------- - * connect to locallogger - *---------------------------------------------------------------------- - */ -int edg_wll_log_connect(edg_wll_Context ctx, int *conn) -{ - int ret, answer=0, index; - char *my_subject_name = NULL; - edg_wll_GssStatus gss_stat; - - edg_wll_ResetError(ctx); - edg_wll_poolLock(); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_connect: setting connection to local-logger %s:%d (remaining timeout %d.%06d sec)\n", - ctx->p_destination,ctx->p_dest_port, - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - /* check if connection already in pool */ - if ( (index = ConnectionIndex(ctx, ctx->p_destination, ctx->p_dest_port)) == -1 ) { - if (ctx->connections->connOpened == ctx->connections->poolSize) - if (ReleaseConnection(ctx, NULL, 0)) { - answer = edg_wll_SetError(ctx,EAGAIN,"cannot release connection (pool size exceeded)"); - goto edg_wll_log_connect_end; - } - index = AddConnection(ctx, ctx->p_destination, ctx->p_dest_port); - if (index < 0) { - answer = edg_wll_SetError(ctx,EAGAIN,"cannot add connection to pool"); - goto edg_wll_log_connect_end; - } -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_connect: connection to local-logger %s:%d added as No. %d in the pool\n", - ctx->connections->connPool[index].peerName, - ctx->connections->connPool[index].peerPort,index); -#endif - } -#ifdef EDG_WLL_LOG_STUB - else fprintf(stderr,"edg_wll_log_connect: connection to %s:%d exists (No. %d in the pool) - reusing\n", - ctx->connections->connPool[index].peerName, - ctx->connections->connPool[index].peerPort,index); -#endif - -#if 0 - /* acquire gss credentials */ - ret = edg_wll_gss_acquire_cred_gsi( - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_key_filename, - &ctx->connections->connPool[index].gsiCred, &gss_stat); - /* give up if unable to acquire prescribed credentials, otherwise go on anonymously */ - if (ret && ctx->p_proxy_filename) { - answer = edg_wll_SetErrorGss(ctx, "edg_wll_gss_acquire_cred_gsi(): failed to load GSI credentials", &gss_stat); - goto edg_wll_log_connect_err; - } - if (ctx->connections->connPool[index].gsiCred) - my_subject_name = ctx->connections->connPool[index].gsiCred->name; - -#ifdef EDG_WLL_LOG_STUB - if (my_subject_name != NULL) { - fprintf(stderr,"edg_wll_log_connect: using certificate: %s\n",my_subject_name); - } else { - fprintf(stderr,"edg_wll_log_connect: going on anonymously!\n"); - } -#endif -#endif -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_connect: opening connection to local-logger %s:%d\n", - ctx->connections->connPool[index].peerName, - ctx->connections->connPool[index].peerPort); -#endif - /* gss_connect */ - if (ctx->connections->connPool[index].gss.context == NULL) { - int opt; - - /* acquire gss credentials */ - ret = edg_wll_gss_acquire_cred_gsi( - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_key_filename, - &ctx->connections->connPool[index].gsiCred, &gss_stat); - /* give up if unable to acquire prescribed credentials, otherwise go on anonymously */ - if (ret && ctx->p_proxy_filename) { - answer = edg_wll_SetErrorGss(ctx, "edg_wll_gss_acquire_cred_gsi(): failed to load GSI credentials", &gss_stat); - goto edg_wll_log_connect_err; - } - if (ctx->connections->connPool[index].gsiCred) - my_subject_name = ctx->connections->connPool[index].gsiCred->name; - -#ifdef EDG_WLL_LOG_STUB - if (my_subject_name != NULL) { - fprintf(stderr,"edg_wll_log_connect: using certificate: %s\n",my_subject_name); - } else { - fprintf(stderr,"edg_wll_log_connect: going on anonymously!\n"); - } -#endif - if ((answer = edg_wll_gss_connect( - ctx->connections->connPool[index].gsiCred, - ctx->connections->connPool[index].peerName, - ctx->connections->connPool[index].peerPort, - &ctx->p_tmp_timeout, - &ctx->connections->connPool[index].gss, - &gss_stat)) < 0) { - answer = handle_gss_failures(ctx,answer,&gss_stat,"edg_wll_gss_connect()"); - goto edg_wll_log_connect_err; - } - opt = 0; - setsockopt(ctx->connections->connPool[index].gss.sock,IPPROTO_TCP,TCP_CORK,(const void *) &opt,sizeof opt); - opt = 1; - setsockopt(ctx->connections->connPool[index].gss.sock,IPPROTO_TCP,TCP_NODELAY,(const void *) &opt,sizeof opt); - goto edg_wll_log_connect_end; - } else goto edg_wll_log_connect_end; - -edg_wll_log_connect_err: - if (index >= 0) { - CloseConnection(ctx, index); - edg_wll_connectionUnlock(ctx, index); - } - index = -1; - -edg_wll_log_connect_end: - if (index >= 0) edg_wll_connectionTryLock(ctx, index); - - edg_wll_poolUnlock(); - -#ifdef EDG_WLL_LOG_STUB - if (answer) { - fprintf(stderr,"edg_wll_log_connect: error (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); - } else { - fprintf(stderr,"edg_wll_log_connect: done o.k. (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); - } -#endif - *conn = index; - return answer; -} - -/** - *---------------------------------------------------------------------- - * close connection to locallogger - *---------------------------------------------------------------------- - */ -int edg_wll_log_close(edg_wll_Context ctx, int conn) -{ - int ret = 0; - - if (conn == -1) return 0; - ret = CloseConnection(ctx,conn); - edg_wll_connectionUnlock(ctx,conn); - return ret; -} - -/** - *---------------------------------------------------------------------- - * write/send to locallogger - *---------------------------------------------------------------------- - */ -int edg_wll_log_write(edg_wll_Context ctx, int conn, edg_wll_LogLine logline) -{ - char header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH+1]; - int err; - int answer; - size_t count,sent; - int size; - u_int8_t size_end[4]; - edg_wll_GssStatus gss_code; - - errno = err = answer = count = sent = 0; - size = strlen(logline)+1; - size_end[0] = size & 0xff; size >>= 8; - size_end[1] = size & 0xff; size >>= 8; - size_end[2] = size & 0xff; size >>= 8; - size_end[3] = size; - size = strlen(logline)+1; - - edg_wll_ResetError(ctx); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_write: sending header\n"); -#endif - sprintf(header,"%s",EDG_WLL_LOG_SOCKET_HEADER); - header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH]='\0'; - if ((err = edg_wll_gss_write_full(&ctx->connections->connPool[conn].gss, header, EDG_WLL_LOG_SOCKET_HEADER_LENGTH, &ctx->p_tmp_timeout, &count, &gss_code)) < 0) { - answer = handle_gss_failures(ctx,err,&gss_code,"edg_wll_gss_write_full()"); - edg_wll_UpdateError(ctx,answer,"edg_wll_log_write(): error sending header"); - return -1; - } - sent += count; - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_write: sending message size\n"); -#endif - count = 0; - if ((err = edg_wll_gss_write_full(&ctx->connections->connPool[conn].gss, size_end, 4, &ctx->p_tmp_timeout, &count, &gss_code)) < 0) { - answer = handle_gss_failures(ctx,err,&gss_code,"edg_wll_gss_write_full()"); - edg_wll_UpdateError(ctx,answer,"edg_wll_log_write(): error sending message size"); - return -1; - } - sent += count; - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_write: sending message...\n"); -#endif - count = 0; - if (( err = edg_wll_gss_write_full(&ctx->connections->connPool[conn].gss, logline, size, &ctx->p_tmp_timeout, &count, &gss_code)) < 0) { - answer = handle_gss_failures(ctx,err,&gss_code,"edg_wll_gss_write_full()"); - edg_wll_UpdateError(ctx,answer,"edg_wll_log_write(): error sending message"); - return -1; - } - sent += count; - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_write: done (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - return sent; -} - -/** - *---------------------------------------------------------------------- - * read/receive from locallogger - *---------------------------------------------------------------------- - */ -int edg_wll_log_read(edg_wll_Context ctx, int conn) -{ - int err; - int answer; - u_int8_t answer_end[4]; - size_t count; - edg_wll_GssStatus gss_code; - - errno = err = answer = count = 0; - - edg_wll_ResetError(ctx); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_read: reading answer from local-logger\n"); -#endif - count = 0; - if ((err = edg_wll_gss_read_full(&ctx->connections->connPool[conn].gss, answer_end, 4, &ctx->p_tmp_timeout, &count, &gss_code)) < 0 ) { - answer = handle_gss_failures(ctx,err,&gss_code,"edg_wll_gss_read_full()"); - edg_wll_UpdateError(ctx,answer,"edg_wll_log_read(): error reading answer from local-logger"); - return -1; - } else { - answer = answer_end[3]; answer <<=8; - answer |= answer_end[2]; answer <<=8; - answer |= answer_end[1]; answer <<=8; - answer |= answer_end[0]; -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_read: read answer \"%d\"\n",answer); -#endif - edg_wll_SetError(ctx,answer,"edg_wll_log_read(): answer read from locallogger"); - } - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_read: done (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - return count; -} - - -/** - *---------------------------------------------------------------------- - * connect to lbproxy - *---------------------------------------------------------------------- - */ -int edg_wll_log_proxy_connect(edg_wll_Context ctx, edg_wll_PlainConnection *conn) -{ - int answer = 0, retries; - int flags; - struct sockaddr_un saddr; - - edg_wll_ResetError(ctx); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_proxy_connect: setting connection to lbroxy (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - conn->sock = socket(PF_UNIX, SOCK_STREAM, 0); - if (conn->sock < 0) { - edg_wll_SetError(ctx,answer = errno,"edg_wll_log_proxy_connect(): socket() error"); - goto edg_wll_log_proxy_connect_end; - } - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, ctx->p_lbproxy_store_sock? - ctx->p_lbproxy_store_sock: socket_path); - if ((flags = fcntl(conn->sock, F_GETFL, 0)) < 0 || fcntl(conn->sock, F_SETFL, flags | O_NONBLOCK) < 0) { - edg_wll_SetError(ctx,answer = errno,"edg_wll_log_proxy_connect(): fcntl() error"); - close(conn->sock); conn->sock = -1; - goto edg_wll_log_proxy_connect_end; - } -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_proxy_connect: opening connection to lbproxy (socket '%s')\n", - ctx->p_lbproxy_store_sock? ctx->p_lbproxy_store_sock: socket_path); -#endif - retries = 0; - while ((answer = connect(conn->sock, (struct sockaddr *)&saddr, sizeof(saddr))) < 0 && - errno == EAGAIN && - ctx->p_tmp_timeout.tv_sec >= 0 && ctx->p_tmp_timeout.tv_usec >= 0 && - !(ctx->p_tmp_timeout.tv_sec == 0 && ctx->p_tmp_timeout.tv_usec == 0) - ) - { - struct timespec ns = { 0, PROXY_CONNECT_RETRY * 1000000 /* 10 ms */ },rem; - - nanosleep(&ns,&rem); - - ctx->p_tmp_timeout.tv_usec -= ns.tv_nsec/1000; - ctx->p_tmp_timeout.tv_usec += rem.tv_nsec/1000; - - ctx->p_tmp_timeout.tv_sec -= ns.tv_sec; - ctx->p_tmp_timeout.tv_sec += rem.tv_sec; - - if (ctx->p_tmp_timeout.tv_usec < 0) { - ctx->p_tmp_timeout.tv_usec += 1000000; - ctx->p_tmp_timeout.tv_sec--; - } - retries++; - } - - if (answer) { - edg_wll_SetError(ctx,answer = (errno == EAGAIN ? ETIMEDOUT : errno),"edg_wll_log_proxy_connect()"); - close(conn->sock); conn->sock = -1; - } - -#ifdef EDG_WLL_LOG_STUB - if (retries) fprintf(stderr,"edg_wll_log_proxy_connect: there were %d connect retries\n",retries); -#endif - -edg_wll_log_proxy_connect_end: -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_proxy_connect: done (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - return answer; -} - -/** - *---------------------------------------------------------------------- - * close connection to lbproxy - *---------------------------------------------------------------------- - */ -int edg_wll_log_proxy_close(edg_wll_Context ctx, edg_wll_PlainConnection *conn) -{ - return edg_wll_plain_close(conn); -} - -/** - *---------------------------------------------------------------------- - * write/send to lbproxy - *---------------------------------------------------------------------- - */ -int edg_wll_log_proxy_write(edg_wll_Context ctx, edg_wll_PlainConnection *conn, edg_wll_LogLine logline) -{ - int len,count = 0; - char *buffer; - - edg_wll_ResetError(ctx); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_proxy_write: encoding message\n"); -#endif - { - il_octet_string_t ll; - - ll.len = strlen(logline); - ll.data = logline; - len = encode_il_msg(&buffer, &ll); - } - if(len < 0) { - edg_wll_SetError(ctx,errno,"encode_il_msg()"); - edg_wll_UpdateError(ctx,ENOMEM,"edg_wll_log_proto_client_proxy(): error encoding message"); - return -1; - } - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_proxy_write: sending message\n"); -#endif - if ((count = edg_wll_plain_write_full(conn, buffer, len, &ctx->p_tmp_timeout)) < 0) { - edg_wll_SetError(ctx, errno, "edg_wll_plain_write_full()"); - edg_wll_UpdateError(ctx, EDG_WLL_IL_PROTO,"edg_wll_log_proto_client_proxy(): error sending message to socket"); - return -1; - } - - if (buffer) free(buffer); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_proxy_write: done (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - return count; -} - -/** - *---------------------------------------------------------------------- - * read/receive from lbproxy - *---------------------------------------------------------------------- - */ -int edg_wll_log_proxy_read(edg_wll_Context ctx, edg_wll_PlainConnection *conn) -{ - char *answer = NULL; - static char et[256]; - int err; - int code; - int lbproto_code; - int count; - - errno = err = code = count = 0; - lbproto_code = 0; - - edg_wll_ResetError(ctx); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_proxy_read: reading answer from lbproxy\n"); -#endif - if ((err = get_reply_plain(ctx, conn, &answer, &lbproto_code, &code)) != 0 ) { - edg_wll_UpdateError(ctx, EDG_WLL_IL_PROTO,"edg_wll_log_proxy_read(): error reading answer from lbproxy"); - return -1; - } else { -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_proxy_read: read answer \"%d:%d: %s\"\n",lbproto_code,code,answer); -#endif - switch (lbproto_code) { - case LB_OK: break; - case LB_NOMEM: - edg_wll_SetError(ctx, ENOMEM, "edg_wll_log_proxy_read(): proxy out of memory"); - break; - case LB_PROTO: - edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "edg_wll_log_proxy_read(): received protocol error response"); - break; - case LB_DBERR: - snprintf(et, sizeof(et), "edg_wll_log_proxy_read(): error details from L&B Proxy server: %s", answer); - edg_wll_SetError(ctx, code, et); - break; - default: - edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "edg_wll_log_proxy_read(): received unknown protocol response"); - break; - } - } - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_proxy_read: done (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - return 0; -} - - -/** - *---------------------------------------------------------------------- - * connect to bkserver - *---------------------------------------------------------------------- - */ -int edg_wll_log_direct_connect(edg_wll_Context ctx, edg_wll_GssConnection *conn) -{ - int ret,answer; - edg_wll_GssStatus gss_stat; - edg_wll_GssCred cred = NULL; - char *host; - unsigned int port; - - ret = answer = 0; - - edg_wll_ResetError(ctx); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_direct_connect: setting connection to bkserver (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - /* get bkserver location: */ - edg_wlc_JobIdGetServerParts(ctx->p_jobid,&host,&port); - port +=1; - /* acquire gss credentials */ - ret = edg_wll_gss_acquire_cred_gsi( - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_key_filename, - &cred, &gss_stat); - /* give up if unable to acquire prescribed credentials, otherwise go on anonymously */ - if (ret && ctx->p_proxy_filename) { - answer = edg_wll_SetErrorGss(ctx, "edg_wll_gss_acquire_cred_gsi(): failed to load GSI credentials", &gss_stat); - goto edg_wll_log_direct_connect_end; - } -#ifdef EDG_WLL_LOG_STUB - if (cred && cred->name) { -/* TODO: merge - shouldn't be probably ctx->p_user_lbproxy but some new parameter, eg. ctx->p_user - related to the change in producer.c -*/ - edg_wll_SetParamString(ctx, EDG_WLL_PARAM_LBPROXY_USER, cred->name); - fprintf(stderr,"edg_wll_log_direct_connect: using certificate: %s\n", cred->name); - } else { - fprintf(stderr,"edg_wll_log_direct_connect: going on anonymously\n"); - } - fprintf(stderr,"edg_wll_log_direct_connect: opening connection to bkserver (host '%s', port '%d')\n", host, port); -#endif - if ((answer = edg_wll_gss_connect(cred,host,port, - &ctx->p_tmp_timeout, conn, &gss_stat)) < 0) { - answer = handle_gss_failures(ctx,answer,&gss_stat,"edg_wll_gss_connect()"); - goto edg_wll_log_direct_connect_end; - } - -edg_wll_log_direct_connect_end: -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_direct_connect: done (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - if (cred != NULL) - edg_wll_gss_release_cred(&cred, NULL); - if (host) free(host); - - return answer; -} - -/** - *---------------------------------------------------------------------- - * close connection to bkserver - *---------------------------------------------------------------------- - */ -int edg_wll_log_direct_close(edg_wll_Context ctx, edg_wll_GssConnection *conn) -{ - return edg_wll_gss_close(conn,&ctx->p_tmp_timeout); -} - -/** - *---------------------------------------------------------------------- - * write/send to bkserver - *---------------------------------------------------------------------- - */ -int edg_wll_log_direct_write(edg_wll_Context ctx, edg_wll_GssConnection *conn, edg_wll_LogLine logline) -{ - size_t len,count=0; - int err; - char *buffer; - edg_wll_GssStatus gss_code; - - edg_wll_ResetError(ctx); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_direct_write: encoding message\n"); -#endif - { - il_octet_string_t ll; - - ll.len=strlen(logline); ll.data=logline; - len = encode_il_msg(&buffer, &ll); - } - if(len < 0) { - edg_wll_SetError(ctx, errno, "encode_il_msg()"); - edg_wll_UpdateError(ctx, ENOMEM, "edg_wll_log_proto_client_direct(): error encoding message"); - return -1; - } -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_direct_write: sending message\n"); -#endif - count = 0; - if (( err = edg_wll_gss_write_full(conn, buffer, len, &ctx->p_tmp_timeout, &count, &gss_code)) < 0) { - handle_gss_failures(ctx,err,&gss_code,"edg_wll_gss_write_full()"); - edg_wll_UpdateError(ctx, EDG_WLL_IL_PROTO,"edg_wll_log_direct_write(): error sending message"); - return -1; - } - if (buffer) free(buffer); -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_direct_write: done (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - return count; -} - -/** - *---------------------------------------------------------------------- - * read/receive from bkserver - *---------------------------------------------------------------------- - */ -int edg_wll_log_direct_read(edg_wll_Context ctx, edg_wll_GssConnection *con) -{ - char *answer = NULL; - static char et[256]; - int err; - int code, lbproto_code; - int count; - - errno = err = code = count = 0; - - edg_wll_ResetError(ctx); - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_direct_read: reading answer from bkserver\n"); -#endif - if ((err = get_reply_gss(ctx, con, &answer, &lbproto_code, &code)) != 0 ) { - edg_wll_UpdateError(ctx, EDG_WLL_IL_PROTO,"edg_wll_log_proto_client_direct(): error reading answer from L&B direct server"); - if (answer) free(answer); - return -1; - } else { -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_direct_read: read answer \"%d:%d: %s\"\n",lbproto_code,code,answer); -#endif - switch (lbproto_code) { - case LB_OK: break; - case LB_NOMEM: - edg_wll_SetError(ctx, ENOMEM, "edg_wll_log_direct_read(): server out of memory"); - break; - case LB_PROTO: - edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "edg_wll_log_direct_read(): received protocol error response"); - break; - case LB_DBERR: - snprintf(et, sizeof(et), "edg_wll_log_direct_read: error details from L&B server: %s", answer); - edg_wll_SetError(ctx, code, et); - break; - default: - edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "edg_wll_log_direct_read(): received unknown protocol response"); - break; - } - } -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_log_direct_read: done (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - return 0; -} diff --git a/org.glite.lb.client/src/producer.c b/org.glite.lb.client/src/producer.c deleted file mode 100644 index 0cd4e92..0000000 --- a/org.glite.lb.client/src/producer.c +++ /dev/null @@ -1,1241 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/jobid/strmd5.h" -#include "glite/lbu/trio.h" -#include "glite/lb/ulm_parse.h" -#include "glite/lb/context-int.h" - -#include "producer.h" -#include "prod_proto.h" -#include "consumer.h" // for QuerySequenceCode - -#ifdef FAKE_VERSION -int edg_wll_DoLogEvent(edg_wll_Context ctx, edg_wll_LogLine logline); -int edg_wll_DoLogEventProxy(edg_wll_Context ctx, edg_wll_LogLine logline); -int edg_wll_DoLogEventDirect(edg_wll_Context ctx, edg_wll_LogLine logline); -#else - -/** - *---------------------------------------------------------------------- - * handle_errors - handle answers from logging functions - *---------------------------------------------------------------------- - */ -static -int handle_errors(edg_wll_Context ctx, int code, const char *text) -{ - static char err[256]; - - switch(code) { - case 0: - case EINVAL: - case ENOSPC: - case ENOMEM: - case EDG_WLL_ERROR_GSS: - case EDG_WLL_ERROR_DNS: - case ENOTCONN: - case ECONNREFUSED: - case ETIMEDOUT: - case EAGAIN: - case EPERM: - break; - case EDG_WLL_ERROR_PARSE_EVENT_UNDEF: - case EDG_WLL_ERROR_PARSE_MSG_INCOMPLETE: - case EDG_WLL_ERROR_PARSE_KEY_DUPLICITY: - case EDG_WLL_ERROR_PARSE_KEY_MISUSE: -// case EDG_WLL_ERROR_PARSE_OK_WITH_EXTRA_FIELDS: - snprintf(err, sizeof(err), "%s: Error code mapped to EINVAL", text); - edg_wll_UpdateError(ctx,EINVAL,err); - break; - case EDG_WLL_IL_PROTO: - case EDG_WLL_IL_SYS: - case EDG_WLL_IL_EVENTS_WAITING: - snprintf(err, sizeof(err), "%s: Error code mapped to EAGAIN", text); - edg_wll_UpdateError(ctx,EAGAIN,err); - break; - default: - snprintf(err, sizeof(err), "%s: Error code mapped to EAGAIN", text); - edg_wll_UpdateError(ctx,EAGAIN,err); - break; - } - - return edg_wll_Error(ctx, NULL, NULL); -} - -/** - *---------------------------------------------------------------------- - * Open a GSS connection to local-logger, send already formatted ULM string - * and get answer back from local-logger - * \brief connect to local-logger, send message and get answer back - * \param[in,out] ctx context to work with, - * \param[in] logline formated ULM string - *---------------------------------------------------------------------- - */ -int edg_wll_DoLogEvent( - edg_wll_Context ctx, - edg_wll_LogLine logline) -{ - int ret = 0, answer = EAGAIN; - int conn = -1; - int attempt = 1; - - edg_wll_ResetError(ctx); - memset(&conn,0,sizeof(conn)); - - do { - /* connect to local-logger */ - if ((ret = edg_wll_log_connect(ctx,&conn))) { - edg_wll_UpdateError(ctx,EDG_WLL_IL_PROTO,"edg_wll_DoLogEvent(): edg_wll_log_connect error"); - goto edg_wll_DoLogEvent_end; - } - - /* send message */ - if ((ret = edg_wll_log_write(ctx,conn,logline)) == -1) { - answer = edg_wll_Error(ctx, NULL, NULL); - edg_wll_UpdateError(ctx,EDG_WLL_IL_PROTO,"edg_wll_DoLogEvent(): edg_wll_log_write error"); - goto edg_wll_DoLogEvent_end; - } - - /* get answer */ - ret = edg_wll_log_read(ctx,conn); - answer = edg_wll_Error(ctx, NULL, NULL); - if (ret == -1) - edg_wll_UpdateError(ctx,EDG_WLL_IL_PROTO,"edg_wll_DoLogEvent(): edg_wll_log_read error"); - - edg_wll_DoLogEvent_end: - if (ret == -1 && conn >= 0) edg_wll_log_close(ctx,conn); - - } while (++attempt <= 2 && (answer == ENOTCONN || answer == EPIPE)); - - return handle_errors(ctx,answer,"edg_wll_DoLogEvent()"); -} - -/** - *---------------------------------------------------------------------- - * Open a plain (UNIX socket) connection to L&B Proxy, send already formatted ULM string - * and get answer back from L&B Proxy - * \brief connect to lbproxy, send message and get answer back - * \param[in,out] ctx context to work with, - * \param[in] logline formated ULM string - *---------------------------------------------------------------------- - */ -int edg_wll_DoLogEventProxy( - edg_wll_Context ctx, - edg_wll_LogLine logline) -{ - int ret = 0, answer = EAGAIN; - edg_wll_PlainConnection conn; - - edg_wll_ResetError(ctx); - memset(&conn,0,sizeof(conn)); - - /* connect to lbproxy */ - if ((ret = edg_wll_log_proxy_connect(ctx,&conn))) { - edg_wll_UpdateError(ctx,EDG_WLL_IL_PROTO,"edg_wll_DoLogEventProxy(): edg_wll_log_proxy_write error"); - goto edg_wll_DoLogEventProxy_end; - } - - /* send message */ - if ((ret = edg_wll_log_proxy_write(ctx,&conn,logline)) == -1) { - edg_wll_UpdateError(ctx,EDG_WLL_IL_PROTO,"edg_wll_DoLogEventProxy(): edg_wll_log_proxy_write error"); - goto edg_wll_DoLogEventProxy_end; - } - - /* get answer */ - if ((ret = edg_wll_log_proxy_read(ctx,&conn)) == -1) { - edg_wll_UpdateError(ctx,EDG_WLL_IL_PROTO,"edg_wll_DoLogEventProxy(): edg_wll_log_proxy_read error"); - } else { - answer = edg_wll_Error(ctx, NULL, NULL); - } - -edg_wll_DoLogEventProxy_end: - edg_wll_log_proxy_close(ctx,&conn); - - return handle_errors(ctx,answer,"edg_wll_DoLogEventProxy()"); -} - -/** - *---------------------------------------------------------------------- - * Open a GSS connection to L&B server, send already formatted ULM string - * and get answer back from L&B server - * \brief connect to bkserver, send message and get answer back - * \param[in,out] ctx context to work with, - * \param[in] logline formated ULM string - *---------------------------------------------------------------------- - */ -int edg_wll_DoLogEventDirect( - edg_wll_Context ctx, - edg_wll_LogLine logline) -{ - int ret = 0, answer = EAGAIN; - edg_wll_GssConnection conn; - - edg_wll_ResetError(ctx); - memset(&conn,0,sizeof(conn)); - - /* connect to bkserver */ - if ((ret = edg_wll_log_direct_connect(ctx,&conn))) { - edg_wll_UpdateError(ctx,EDG_WLL_IL_PROTO,"edg_wll_DoLogEventDirect(): edg_wll_log_direct_connect error"); - goto edg_wll_DoLogEventDirect_end; - } - - /* send message */ - if ((ret = edg_wll_log_direct_write(ctx,&conn,logline)) == -1) { - edg_wll_UpdateError(ctx,EDG_WLL_IL_PROTO,"edg_wll_DoLogEventDirect(): edg_wll_log_direct_write error"); - goto edg_wll_DoLogEventDirect_end; - } - - /* get answer */ - if ((ret = edg_wll_log_direct_read(ctx,&conn)) == -1) { - edg_wll_UpdateError(ctx,EDG_WLL_IL_PROTO,"edg_wll_DoLogEventDirect(): edg_wll_log_direct_read error"); - } else { - answer = edg_wll_Error(ctx, NULL, NULL); - } - -edg_wll_DoLogEventDirect_end: - edg_wll_log_direct_close(ctx,&conn); - - return handle_errors(ctx,answer,"edg_wll_DoLogEventDirect()"); -} - -#endif /* FAKE_VERSION */ - -/** - *---------------------------------------------------------------------- - * Formats a logging message - * \brief formats a logging message - * \param[in,out] ctx context to work with, - * \param[in] flags as defined by EDG_WLL_LOGFLAG_* - * \param[in] event type of the event, - * \param[out] logline formated logging message - * \param[in] fmt printf()-like format string, - * \param[in] ... event specific values/data according to fmt. - *---------------------------------------------------------------------- - */ -static int edg_wll_FormatLogLine( - edg_wll_Context ctx, - int flags, - edg_wll_EventCode event, - edg_wll_LogLine *logline, - char *fmt, ...) -{ - va_list fmt_args; - int priority; - int ret; - char *fix,*var,*dguser; - char *source,*eventName,*lvl,*fullid,*seq; - struct timeval start_time; - char date[ULM_DATE_STRING_LENGTH+1]; - edg_wll_LogLine out; - size_t size; - int i; - - i = errno = size = ret = 0; - seq = fix = var = dguser = out = source = eventName = lvl = fullid = NULL; - priority = flags; - - edg_wll_ResetError(ctx); - - /* format the message: */ - va_start(fmt_args,fmt); - - gettimeofday(&start_time,0); - if (edg_wll_ULMTimevalToDate(start_time.tv_sec,start_time.tv_usec,date) != 0) { - edg_wll_SetError(ctx,ret = EINVAL,"edg_wll_FormatLogLine(): edg_wll_ULMTimevalToDate() error"); - goto edg_wll_formatlogline_end; - } - source = edg_wll_SourceToString(ctx->p_source); - lvl = edg_wll_LevelToString(ctx->p_level); - eventName = edg_wll_EventToString(event); - if (!eventName) { - edg_wll_SetError(ctx,ret = EINVAL,"edg_wll_FormatLogLine(): event name not specified"); - goto edg_wll_formatlogline_end; - } - if (!(fullid = edg_wlc_JobIdUnparse(ctx->p_jobid))) { - edg_wll_SetError(ctx,ret = EINVAL,"edg_wll_FormatLogLine(): edg_wlc_JobIdUnparse() error"); - goto edg_wll_formatlogline_end; - } - seq = edg_wll_GetSequenceCode(ctx); - - if (trio_asprintf(&fix,EDG_WLL_FORMAT_COMMON, - date,ctx->p_host,lvl,priority, - source,ctx->p_instance ? ctx->p_instance : "", - eventName,fullid,seq) == -1) { - edg_wll_SetError(ctx,ret = ENOMEM,"edg_wll_FormatLogLine(): trio_asprintf() error"); - goto edg_wll_formatlogline_end; - } -/* TODO: merge - add always, probably new ctx->p_user - has this already been agreed? */ - if ( ( (flags & EDG_WLL_LOGFLAG_PROXY) || (flags & EDG_WLL_LOGFLAG_DIRECT) ) && - (ctx->p_user_lbproxy) ) { - if (trio_asprintf(&dguser,EDG_WLL_FORMAT_USER,ctx->p_user_lbproxy) == -1) { - edg_wll_SetError(ctx,ret = ENOMEM,"edg_wll_FormatLogLine(): trio_asprintf() error"); - goto edg_wll_formatlogline_end; - } - } else { - dguser = strdup(""); - } - if (trio_vasprintf(&var,fmt,fmt_args) == -1) { - edg_wll_SetError(ctx,ret = ENOMEM,"edg_wll_FormatLogLine(): trio_vasprintf() error"); - goto edg_wll_formatlogline_end; - } - if (asprintf(&out,"%s%s%s\n",fix,dguser,var) == -1) { - edg_wll_SetError(ctx,ret = ENOMEM,"edg_wll_FormatLogLine(): asprintf() error"); - goto edg_wll_formatlogline_end; - } - size = strlen(out); - - if (priority && (size > EDG_WLL_LOG_SYNC_MAXMSGSIZE)) { - edg_wll_SetError(ctx,ret = ENOSPC,"edg_wll_FormatLogLine(): Message size too large for synchronous transfer"); - goto edg_wll_formatlogline_end; - } - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_FormatLogLine (%d chars): %s",size,out); -#endif - if (out) { - *logline = out; - } else { - *logline = NULL; - } - -edg_wll_formatlogline_end: - va_end(fmt_args); - if (seq) free(seq); - if (fix) free(fix); - if (dguser) free(dguser); - if (var) free(var); - if (source) free(source); - if (lvl) free(lvl); - if (eventName) free(eventName); - if (fullid) free(fullid); - - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *---------------------------------------------------------------------- - * Formats a logging message and sends it to local-logger - * \brief master logging event function - * \param[in,out] ctx context to work with, - * \param[in] flags as defined by EDG_WLL_LOGFLAG_* - * \param[in] event type of the event, - * \param[in] fmt printf()-like format string, - * \param[in] ... event specific values/data according to fmt. - *---------------------------------------------------------------------- - */ -static int edg_wll_LogEventMaster( - edg_wll_Context ctx, - int flags, - edg_wll_EventCode event, - char *fmt, ...) -{ - va_list fmt_args; - int priority; - int ret; - edg_wll_LogLine in = NULL, out = NULL; - - priority = flags; - - edg_wll_ResetError(ctx); - - /* format the message: */ - va_start(fmt_args,fmt); - - if (trio_vasprintf(&in,fmt,fmt_args) == -1) { - edg_wll_UpdateError(ctx,ret = ENOMEM,"edg_wll_LogEventMaster(): trio_vasprintf() error"); - goto edg_wll_logeventmaster_end; - } - - if (edg_wll_FormatLogLine(ctx,flags,event,&out,"%s",in) != 0 ) { - edg_wll_UpdateError(ctx,ret = EINVAL,"edg_wll_LogEventMaster(): edg_wll_FormatLogLine() error"); - goto edg_wll_logeventmaster_end; - } - -#ifdef EDG_WLL_LOG_STUB -// fprintf(stderr,"edg_wll_LogEventMaster (%d chars): %s",strlen(out),out); -#endif - - /* and send the message */ -#ifndef LB_PERF_DROP - if (flags & EDG_WLL_LOGFLAG_LOCAL) { - /* to the local-logger: */ - ctx->p_tmp_timeout = priority ? ctx->p_sync_timeout : ctx->p_log_timeout; - ret = edg_wll_DoLogEvent(ctx, out); - if (ret) goto edg_wll_logeventmaster_end; - } - if (flags & EDG_WLL_LOGFLAG_PROXY) { - /* to the L&B Proxy: */ - ctx->p_tmp_timeout = priority ? ctx->p_sync_timeout : ctx->p_log_timeout; - ret = edg_wll_DoLogEventProxy(ctx, out); - if (ret) goto edg_wll_logeventmaster_end; - } - if (flags & EDG_WLL_LOGFLAG_DIRECT) { - /* directly to the bkserver: */ - ctx->p_tmp_timeout = priority ? ctx->p_sync_timeout : ctx->p_log_timeout; - ret = edg_wll_DoLogEventDirect(ctx, out); - if (ret) goto edg_wll_logeventmaster_end; - } - - if (flags & (EDG_WLL_LOGFLAG_LOCAL|EDG_WLL_LOGFLAG_PROXY|EDG_WLL_LOGFLAG_DIRECT) == 0) { - edg_wll_SetError(ctx,ret = EINVAL,"edg_wll_LogEventMaster(): no known flag specified"); - } -#endif - -edg_wll_logeventmaster_end: - va_end(fmt_args); - if (in) free(in); - if (out) free(out); - - if (!ret) if(edg_wll_IncSequenceCode(ctx)) { - edg_wll_SetError(ctx,ret = EINVAL,"edg_wll_LogEventMaster(): edg_wll_IncSequenceCode failed"); - } - - if (ret) edg_wll_UpdateError(ctx,0,"Logging library ERROR: "); - - return edg_wll_Error(ctx,NULL,NULL); -} - - -/** - *---------------------------------------------------------------------- - * Formats a logging message and sends it asynchronously to local-logger - * \brief generic asynchronous logging function - *---------------------------------------------------------------------- - */ -int edg_wll_LogEvent( - edg_wll_Context ctx, - edg_wll_EventCode event, - char *fmt, ...) -{ - int ret=0; - char *list=NULL; - va_list fmt_args; - - edg_wll_ResetError(ctx); - - va_start(fmt_args,fmt); - if (trio_vasprintf(&list,fmt,fmt_args) == -1) { - edg_wll_SetError(ctx,ret = ENOMEM,"edg_wll_LogEvent(): trio_vasprintf() error"); - goto edg_wll_logevent_end; - } - - ret=edg_wll_LogEventMaster(ctx,EDG_WLL_LOGFLAG_LOCAL | EDG_WLL_LOGFLAG_ASYNC,event,"%s",list); - -edg_wll_logevent_end: - va_end(fmt_args); - if (list) free(list); - - if (ret) edg_wll_UpdateError(ctx,0,"edg_wll_LogEvent(): "); - - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *---------------------------------------------------------------------- - * Formats a logging message and sends it synchronously to local-logger - * \brief generic synchronous logging function - * \note simple wrapper around edg_wll_LogEventMaster() - *---------------------------------------------------------------------- - */ -int edg_wll_LogEventSync( - edg_wll_Context ctx, - edg_wll_EventCode event, - char *fmt, ...) -{ - int ret=0; - char *list=NULL; - va_list fmt_args; - - edg_wll_ResetError(ctx); - - va_start(fmt_args,fmt); - if (trio_vasprintf(&list,fmt,fmt_args) == -1) { - edg_wll_SetError(ctx,ret = ENOMEM,"edg_wll_LogEventSync(): trio_vasprintf() error"); - goto edg_wll_logeventsync_end; - } - - ret=edg_wll_LogEventMaster(ctx,EDG_WLL_LOGFLAG_LOCAL | EDG_WLL_LOGFLAG_SYNC,event,"%s",list); - -edg_wll_logeventsync_end: - va_end(fmt_args); - if (list) free(list); - - if (ret) edg_wll_UpdateError(ctx,0,"edg_wll_LogEventSync(): "); - - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *---------------------------------------------------------------------- - * Formats a logging message and sends it synchronously to L&B Proxy - * \brief generic synchronous logging function - * \note simple wrapper around edg_wll_LogEventMaster() - *---------------------------------------------------------------------- - */ -int edg_wll_LogEventProxy( - edg_wll_Context ctx, - edg_wll_EventCode event, - char *fmt, ...) -{ - int ret=0; - char *list=NULL; - va_list fmt_args; - - edg_wll_ResetError(ctx); - - va_start(fmt_args,fmt); - if (trio_vasprintf(&list,fmt,fmt_args) == -1) { - edg_wll_SetError(ctx,ret = ENOMEM,"edg_wll_LogEventProxy(): trio_vasprintf() error"); - goto edg_wll_logevent_end; - } - - ret=edg_wll_LogEventMaster(ctx,EDG_WLL_LOGFLAG_PROXY | EDG_WLL_LOGFLAG_SYNC, event,"%s",list); - -edg_wll_logevent_end: - va_end(fmt_args); - if (list) free(list); - - if (ret) edg_wll_UpdateError(ctx,0,"edg_wll_LogEventProxy(): "); - - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *----------------------------------------------------------------------- - * Instructs interlogger to to deliver all pending events related to current job - * \brief flush events from interlogger - * \note simple wrapper around edg_wll_LogEventMaster() - *----------------------------------------------------------------------- - */ -int edg_wll_LogFlush( - edg_wll_Context ctx, - struct timeval *timeout) -{ - int ret = 0; - edg_wll_LogLine out = NULL; - char *fullid; - char date[ULM_DATE_STRING_LENGTH+1]; - struct timeval start_time; - - fullid = NULL; - - edg_wll_ResetError(ctx); - - gettimeofday(&start_time, 0); - if (edg_wll_ULMTimevalToDate(start_time.tv_sec, start_time.tv_usec, date) != 0) { - edg_wll_SetError(ctx,ret = EINVAL,"edg_wll_LogFlush(): edg_wll_ULMTimevalToDate() error"); - goto edg_wll_logflush_end; - } - if (!(fullid = edg_wlc_JobIdUnparse(ctx->p_jobid))) { - ret = edg_wll_SetError(ctx,EINVAL,"edg_wll_LogFlush(): edg_wlc_JobIdUnparse() error"); - goto edg_wll_logflush_end; - } - - if (trio_asprintf(&out, "DATE=%s HOST=\"%|Us\" PROG=internal LVL=system DG.PRIORITY=1 DG.TYPE=\"command\" DG.COMMAND=\"flush\" DG.TIMEOUT=\"%d\" DG.JOBID=\"%s\"\n", - date, ctx->p_host, (timeout ? timeout->tv_sec : ctx->p_sync_timeout.tv_sec), fullid) == -1) { - edg_wll_SetError(ctx,ret = EINVAL,"edg_wll_LogFlush(): trio_asprintf() error"); - goto edg_wll_logflush_end; - } - - if (timeout) - ctx->p_tmp_timeout = *timeout; - else - ctx->p_tmp_timeout = ctx->p_sync_timeout; - - ret = edg_wll_DoLogEvent(ctx, out); - -edg_wll_logflush_end: - if(out) free(out); - if(fullid) free(fullid); - - if (ret) edg_wll_UpdateError(ctx,0,"edg_wll_LogFlush(): "); - - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *----------------------------------------------------------------------- - * Instructs interlogger to to deliver all pending events - * \brief flush all events from interlogger - * \note simple wrapper around edg_wll_LogEventMaster() - *----------------------------------------------------------------------- - */ -int edg_wll_LogFlushAll( - edg_wll_Context ctx, - struct timeval *timeout) -{ - int ret = 0; - edg_wll_LogLine out = NULL; - char date[ULM_DATE_STRING_LENGTH+1]; - struct timeval start_time; - - edg_wll_ResetError(ctx); - - gettimeofday(&start_time, 0); - if (edg_wll_ULMTimevalToDate(start_time.tv_sec, start_time.tv_usec, date) != 0) { - edg_wll_SetError(ctx,ret = EINVAL,"edg_wll_LogFlushAll(): edg_wll_ULMTimevalToDate() error"); - goto edg_wll_logflushall_end; - } - - if (trio_asprintf(&out, "DATE=%s HOST=\"%|Us\" PROG=internal LVL=system DG.PRIORITY=1 DG.TYPE=\"command\" DG.COMMAND=\"flush\" DG.TIMEOUT=\"%d\"\n", - date, ctx->p_host, (timeout ? timeout->tv_sec : ctx->p_sync_timeout.tv_sec)) == -1) { - edg_wll_SetError(ctx,ret = ENOMEM,"edg_wll_LogFlushAll(): trio_asprintf() error"); - goto edg_wll_logflushall_end; - } - - if (timeout) - ctx->p_tmp_timeout = *timeout; - else - ctx->p_tmp_timeout = ctx->p_sync_timeout; - - ret = edg_wll_DoLogEvent(ctx, out); - -edg_wll_logflushall_end: - if(out) free(out); - - if (ret) edg_wll_UpdateError(ctx,0,"edg_wll_LogFlushAll(): "); - - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *----------------------------------------------------------------------- - * Set a current job for given context. - * \note Should be called before any logging call. - *----------------------------------------------------------------------- - */ -int edg_wll_SetLoggingJob( - edg_wll_Context ctx, - glite_jobid_const_t job, - const char *code, - int flags) -{ - int err; - - edg_wll_ResetError(ctx); - - if (!job) return edg_wll_SetError(ctx,EINVAL,"edg_wll_SetLoggingJob(): jobid is null"); - - edg_wlc_JobIdFree(ctx->p_jobid); - if ((err = edg_wlc_JobIdDup(job,&ctx->p_jobid))) { - edg_wll_SetError(ctx,err,"edg_wll_SetLoggingJob(): edg_wlc_JobIdDup() error"); - } else if (!edg_wll_SetSequenceCode(ctx,code,flags)) { - edg_wll_IncSequenceCode(ctx); - } - - /* add user credentials to context */ - { - edg_wll_GssStatus gss_stat; - edg_wll_GssCred cred = NULL; - - /* acquire gss credentials */ - err = edg_wll_gss_acquire_cred_gsi( - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_key_filename, - &cred, &gss_stat); - /* give up if unable to acquire prescribed credentials */ - if (err) { - edg_wll_SetErrorGss(ctx, "failed to load GSI credentials", &gss_stat); - - // XXX: stop here - further changes need to be done in - // edg_wll_gss_connect() to support annonymous connetion - return edg_wll_Error(ctx,NULL,NULL); - - edg_wll_SetParamString(ctx, EDG_WLL_PARAM_LBPROXY_USER, EDG_WLL_LOG_USER_DEFAULT); - } else { - edg_wll_SetParamString(ctx, EDG_WLL_PARAM_LBPROXY_USER, cred->name); - } - if (cred != NULL) - edg_wll_gss_release_cred(&cred, NULL); - } - - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *----------------------------------------------------------------------- - * Set a current job for given context. - * \note Should be called before any logging call. - *----------------------------------------------------------------------- - */ -int edg_wll_SetLoggingJobProxy( - edg_wll_Context ctx, - glite_jobid_const_t job, - const char *code, - const char *user, - int flags) -{ - int err; - char *code_loc = NULL; - - edg_wll_ResetError(ctx); - - if (!job) return edg_wll_SetError(ctx,EINVAL,"edg_wll_SetLoggingJobProxy(): jobid is null"); - - edg_wlc_JobIdFree(ctx->p_jobid); - if ((err = edg_wlc_JobIdDup(job,&ctx->p_jobid))) { - edg_wll_SetError(ctx,err,"edg_wll_SetLoggingJobProxy(): edg_wlc_JobIdDup() error"); - goto edg_wll_setloggingjobproxy_end; - } - - /* add user credentials to context */ - if (user) { - edg_wll_SetParamString(ctx, EDG_WLL_PARAM_LBPROXY_USER, user); - } else { - edg_wll_GssStatus gss_stat; - edg_wll_GssCred cred = NULL; - - /* acquire gss credentials */ - err = edg_wll_gss_acquire_cred_gsi( - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_cert_filename, - ctx->p_proxy_filename ? ctx->p_proxy_filename : ctx->p_key_filename, - &cred, &gss_stat); - /* give up if unable to acquire prescribed credentials */ - if (err) { - edg_wll_SetErrorGss(ctx, "failed to load GSI credentials", &gss_stat); - - // XXX: stop here - further changes need to be done in - // edg_wll_gss_connect() to support annonymous connetion - return edg_wll_SetError(ctx, ENOENT, "No credentials found."); - - edg_wll_SetParamString(ctx, EDG_WLL_PARAM_LBPROXY_USER, EDG_WLL_LOG_USER_DEFAULT); - } else { - edg_wll_SetParamString(ctx, EDG_WLL_PARAM_LBPROXY_USER, cred->name); - } - - if (cred != NULL) - edg_wll_gss_release_cred(&cred, NULL); - } - - /* query LBProxyServer for sequence code if not user-suplied */ -/* TODO: merge - check if it is really working properly after the unification of proxy and server */ - if (!code) { - if (edg_wll_QuerySequenceCodeProxy(ctx, job, &code_loc)) - goto edg_wll_setloggingjobproxy_end; - } else { - code_loc = strdup(code); - } - - if (!edg_wll_SetSequenceCode(ctx,code_loc,flags)) { - edg_wll_IncSequenceCode(ctx); - } - -edg_wll_setloggingjobproxy_end: - if (code_loc) free(code_loc); - - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *----------------------------------------------------------------------- - * Register job with L&B service. - *----------------------------------------------------------------------- - */ -static int edg_wll_RegisterJobMaster( - edg_wll_Context ctx, - int flags, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - glite_jobid_const_t parent, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs) -{ - char *seq,*type_s,*parent_s; - int err = 0; - struct timeval sync_to; - - seq = type_s = parent_s = NULL; - - edg_wll_ResetError(ctx); - memcpy(&sync_to, &ctx->p_sync_timeout, sizeof sync_to); - - type_s = edg_wll_RegJobJobtypeToString(type); - if (!type_s) { - edg_wll_SetError(ctx,EINVAL,"edg_wll_RegisterJobMaster(): no jobtype specified"); - goto edg_wll_registerjobmaster_end; - } - if ((type == EDG_WLL_REGJOB_DAG || - type == EDG_WLL_REGJOB_PARTITIONED || - type == EDG_WLL_REGJOB_COLLECTION) - && num_subjobs > 0) { - err = edg_wll_GenerateSubjobIds(ctx,job,num_subjobs,seed,subjobs); - edg_wll_SetSequenceCode(ctx, NULL, EDG_WLL_SEQ_NORMAL); - /* increase log timeout on client (the same as on BK server) */ - ctx->p_sync_timeout.tv_sec += num_subjobs; - if (ctx->p_sync_timeout.tv_sec > 86400) ctx->p_sync_timeout.tv_sec = 86400; - } - if (err) { - edg_wll_UpdateError(ctx,EINVAL,"edg_wll_RegisterJobMaster(): edg_wll_GenerateSubjobIds() error"); - goto edg_wll_registerjobmaster_end; - } - parent_s = parent ? edg_wlc_JobIdUnparse(parent) : strdup(""); - - if ( ((flags & (EDG_WLL_LOGFLAG_DIRECT | EDG_WLL_LOGFLAG_LOCAL)) == - (EDG_WLL_LOGFLAG_DIRECT | EDG_WLL_LOGFLAG_LOCAL)) || - ((flags & (EDG_WLL_LOGFLAG_PROXY | EDG_WLL_LOGFLAG_LOCAL)) == - (EDG_WLL_LOGFLAG_PROXY | EDG_WLL_LOGFLAG_LOCAL)) - ) { - edg_wll_SetError(ctx,EINVAL,"edg_wll_RegisterJobMaster(): wrong flag specified"); - goto edg_wll_registerjobmaster_end; - } - - if (edg_wll_SetLoggingJob(ctx,job,NULL,EDG_WLL_SEQ_NORMAL) == 0) { - err = edg_wll_LogEventMaster(ctx, flags, - EDG_WLL_EVENT_REGJOB, EDG_WLL_FORMAT_REGJOB, - (char *)jdl, ns, parent_s, type_s, num_subjobs, seed); - if (err) { - edg_wll_UpdateError(ctx,0,"edg_wll_RegisterJobMaster(): unable to register with bkserver"); - goto edg_wll_registerjobmaster_end; - } - } else { - edg_wll_UpdateError(ctx,0,"edg_wll_RegisterJobMaster(): unable to set logging job (direct)"); - goto edg_wll_registerjobmaster_end; - } - -edg_wll_registerjobmaster_end: - memcpy(&ctx->p_sync_timeout, &sync_to, sizeof sync_to); - if (seq) free(seq); - if (type_s) free(type_s); - if (parent_s) free(parent_s); - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *----------------------------------------------------------------------- - * Register synchronously one job with L&B service - * \note simple wrapper around edg_wll_RegisterJobMaster() - *----------------------------------------------------------------------- - */ -int edg_wll_RegisterJobSync( - edg_wll_Context ctx, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs) -{ - return edg_wll_RegisterJobMaster(ctx,EDG_WLL_LOGFLAG_DIRECT | EDG_WLL_LOGFLAG_SYNC,job,type,jdl,ns,NULL,num_subjobs,seed,subjobs); -} - -/** - *----------------------------------------------------------------------- - * Register (asynchronously) one job with L&B service - * \note simple wrapper around edg_wll_RegisterJobMaster() - *----------------------------------------------------------------------- - */ -int edg_wll_RegisterJob( - edg_wll_Context ctx, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs) -{ - return edg_wll_RegisterJobMaster(ctx,EDG_WLL_LOGFLAG_DIRECT | EDG_WLL_LOGFLAG_ASYNC,job,type,jdl,ns,NULL,num_subjobs,seed,subjobs); -} - -#ifndef LB_SERIAL_REG - -/** - *----------------------------------------------------------------------- - * Register one job with L&B Proxy service - * \note simple wrapper around edg_wll_RegisterJobMaster() - * this is new (!LB_SERIAL_REG) edg_wll_RegisterJobProxy - *----------------------------------------------------------------------- - */ -int edg_wll_RegisterJobProxy( - edg_wll_Context ctx, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs) -{ - char *seq,*type_s; - edg_wll_LogLine logline = NULL; - int ret = 0,n,count,fd; - struct timeval sync_to; - edg_wll_GssConnection con_bkserver; - edg_wll_PlainConnection con_lbproxy; - fd_set fdset; - - seq = type_s = NULL; - - edg_wll_ResetError(ctx); - memcpy(&sync_to, &ctx->p_sync_timeout, sizeof sync_to); - memset(&con_bkserver, 0, sizeof(con_bkserver)); - memset(&con_lbproxy, 0, sizeof(con_lbproxy)); - - FD_ZERO(&fdset); - - - type_s = edg_wll_RegJobJobtypeToString(type); - if (!type_s) { - edg_wll_SetError(ctx,EINVAL,"edg_wll_RegisterJobProxy(): no jobtype specified"); - goto edg_wll_registerjobproxy_end; - } - if ((type == EDG_WLL_REGJOB_DAG || - type == EDG_WLL_REGJOB_PARTITIONED || - type == EDG_WLL_REGJOB_COLLECTION) - && num_subjobs > 0) { - ret = edg_wll_GenerateSubjobIds(ctx,job,num_subjobs,seed,subjobs); - /* increase log timeout on client (the same as on BK server) */ - ctx->p_sync_timeout.tv_sec += num_subjobs; - if (ctx->p_sync_timeout.tv_sec > 86400) ctx->p_sync_timeout.tv_sec = 86400; - } - if (ret) { - edg_wll_UpdateError(ctx,EINVAL,"edg_wll_RegisterJobProxy(): edg_wll_GenerateSubjobIds() error"); - goto edg_wll_registerjobproxy_end; - } - - edg_wll_SetSequenceCode(ctx, NULL, EDG_WLL_SEQ_NORMAL); - seq = edg_wll_GetSequenceCode(ctx); - if (edg_wll_SetLoggingJobProxy(ctx,job,seq,NULL,EDG_WLL_SEQ_NORMAL) != 0) { - edg_wll_UpdateError(ctx,EINVAL,"edg_wll_RegisterJobProxy(): edg_wll_SetLoggingJobProxy() error"); - goto edg_wll_registerjobproxy_end; - } - - /* format the RegJob event message */ - if (edg_wll_FormatLogLine(ctx,EDG_WLL_LOGFLAG_DIRECT | EDG_WLL_LOGFLAG_PROXY, - EDG_WLL_EVENT_REGJOB,&logline, - EDG_WLL_FORMAT_REGJOB,(char *)jdl,ns,"",type_s,num_subjobs,seed) != 0 ) { - edg_wll_UpdateError(ctx,EINVAL,"edg_wll_RegisterJobProxy(): edg_wll_FormatLogLine() error"); - goto edg_wll_registerjobproxy_end; - } - - /* do not forget to set the timeout!!! */ - ctx->p_tmp_timeout = ctx->p_sync_timeout; - - /* and now do the pseudo-parallel registration: */ - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_RegisterJobProxy: start (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - /* connect to bkserver */ - if ((ret = edg_wll_log_direct_connect(ctx,&con_bkserver))) { - edg_wll_UpdateError(ctx,EAGAIN,"edg_wll_RegisterJobProxy(): edg_wll_log_direct_connect error"); - goto edg_wll_registerjobproxy_end; - } - /* connect to lbproxy */ - if ((ret = edg_wll_log_proxy_connect(ctx,&con_lbproxy))) { - edg_wll_UpdateError(ctx,EAGAIN,"edg_wll_RegisterJobProxy(): edg_wll_log_proxy_connect error"); - goto edg_wll_registerjobproxy_end; - } - /* send to bkserver */ - if ((ret = edg_wll_log_direct_write(ctx,&con_bkserver,logline)) == -1) { - edg_wll_UpdateError(ctx,EAGAIN,"edg_wll_RegisterJobProxy(): edg_wll_log_direct_write error"); - goto edg_wll_registerjobproxy_end; - } - /* send to lbproxy */ - if ((ret = edg_wll_log_proxy_write(ctx,&con_lbproxy,logline)) == -1) { - edg_wll_UpdateError(ctx,EAGAIN,"edg_wll_RegisterJobProxy(): edg_wll_log_proxy_write error"); - goto edg_wll_registerjobproxy_end; - } - /* select and read the answers */ - count = 2; - while (count > 0) { - FD_SET(con_bkserver.sock,&fdset); - n = con_bkserver.sock; - FD_SET(con_lbproxy.sock,&fdset); - if (con_lbproxy.sock > n) n = con_lbproxy.sock; - n += 1; -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_RegisterJobProxy: calling select (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - fd = select(n,&fdset,NULL,NULL,&ctx->p_tmp_timeout); - switch (fd) { - case 0: /* timeout */ - edg_wll_UpdateError(ctx,EAGAIN,"edg_wll_RegisterJobProxy(): select() timeouted"); - count = 0; - break; - case -1: /* error */ - switch(errno) { - case EINTR: - continue; - default: - edg_wll_UpdateError(ctx,errno,"edg_wll_RegisterJobProxy(): select() error"); - } - default: - break; - } - if (FD_ISSET(con_bkserver.sock,&fdset)) { - /* read answer from bkserver */ - if ((ret = edg_wll_log_direct_read(ctx,&con_bkserver)) == -1) { - edg_wll_UpdateError(ctx,EAGAIN,"edg_wll_RegisterJobProxy(): edg_wll_log_direct_read error"); - goto inc_seq_code; - } - count -= 1; - } - if (FD_ISSET(con_lbproxy.sock,&fdset)) { - /* read answer from lbproxy */ - if ((ret = edg_wll_log_proxy_read(ctx,&con_lbproxy)) == -1) { - edg_wll_UpdateError(ctx,EAGAIN,"edg_wll_RegisterJobProxy(): edg_wll_log_proxy_read error"); - goto inc_seq_code; - } - count -= 1; - } - } - - -inc_seq_code: - edg_wll_IncSequenceCode(ctx); /* XXX: should not fail, called second time */ - -edg_wll_registerjobproxy_end: - -#ifdef EDG_WLL_LOG_STUB - fprintf(stderr,"edg_wll_RegisterJobProxy: done (remaining timeout %d.%06d sec)\n", - (int) ctx->p_tmp_timeout.tv_sec, (int) ctx->p_tmp_timeout.tv_usec); -#endif - if (con_bkserver.sock) edg_wll_gss_close(&con_bkserver,&ctx->p_tmp_timeout); - if (con_lbproxy.sock) edg_wll_plain_close(&con_lbproxy); - - memcpy(&ctx->p_sync_timeout, &sync_to, sizeof sync_to); - if (type_s) free(type_s); - if (seq) free(seq); - if (logline) free(logline); - - return edg_wll_Error(ctx,NULL,NULL); -} - -/** - *----------------------------------------------------------------------- - * Register one job with L&B Proxy service - * \note simple wrapper around edg_wll_RegisterJobMaster() - * this is original edg_wll_RegisterJobProxy - *----------------------------------------------------------------------- - */ -int edg_wll_RegisterJobProxyOld( - edg_wll_Context ctx, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs) -{ - /* first register with bkserver and then with L&B Proxy */ - return edg_wll_RegisterJobMaster(ctx,EDG_WLL_LOGFLAG_DIRECT | EDG_WLL_LOGFLAG_PROXY,job,type,jdl,ns,NULL,num_subjobs,seed,subjobs); -} - -#else /* LB_SERIAL_REG */ - -/** - *----------------------------------------------------------------------- - * Register one job with L&B Proxy service - * \note simple wrapper around edg_wll_RegisterJobMaster() - * this is original edg_wll_RegisterJobProxy - *----------------------------------------------------------------------- - */ -int edg_wll_RegisterJobProxy( - edg_wll_Context ctx, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs) -{ - /* first register with bkserver and then with L&B Proxy */ - return edg_wll_RegisterJobMaster(ctx,EDG_WLL_LOGFLAG_DIRECT | EDG_WLL_LOGFLAG_PROXY,job,type,jdl,ns,NULL,num_subjobs,seed,subjobs); -} - -#endif /* LB_SERIAL_REG */ - -/** - *----------------------------------------------------------------------- - * Register one job with L&B Proxy service ONLY - * \note simple wrapper around edg_wll_RegisterJobMaster() - * useful for performace measuring - *----------------------------------------------------------------------- - */ -int edg_wll_RegisterJobProxyOnly( - edg_wll_Context ctx, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs) -{ - return edg_wll_RegisterJobMaster(ctx,EDG_WLL_LOGFLAG_PROXY,job,type,jdl,ns,NULL,num_subjobs,seed,subjobs); -} - -/** - *----------------------------------------------------------------------- - * Register one subjob with L&B service - * \note simple wrapper around edg_wll_RegisterJobMaster() - *----------------------------------------------------------------------- - */ -static -int edg_wll_RegisterSubjob( - edg_wll_Context ctx, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - glite_jobid_const_t parent, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs) -{ - return edg_wll_RegisterJobMaster(ctx,EDG_WLL_LOGFLAG_LOCAL,job,type,jdl,ns,parent,num_subjobs,seed,subjobs); -} - -/** - *----------------------------------------------------------------------- - * Register one subjob with L&B Proxy service - * \note simple wrapper around edg_wll_RegisterJobMaster() - *----------------------------------------------------------------------- - */ -static -int edg_wll_RegisterSubjobProxy( - edg_wll_Context ctx, - glite_jobid_const_t job, - enum edg_wll_RegJobJobtype type, - const char * jdl, - const char * ns, - glite_jobid_const_t parent, - int num_subjobs, - const char * seed, - edg_wlc_JobId ** subjobs) -{ - return edg_wll_RegisterJobMaster(ctx,EDG_WLL_LOGFLAG_PROXY,job,type,jdl,ns,parent,num_subjobs,seed,subjobs); -} - -/** - *----------------------------------------------------------------------- - * Register batch of subjobs with L&B service - * \note simple wrapper around edg_wll_RegisterSubjob() - *----------------------------------------------------------------------- - */ -int edg_wll_RegisterSubjobs( - edg_wll_Context ctx, - glite_jobid_const_t parent, - char const * const * jdls, - const char * ns, - edg_wlc_JobId const * subjobs) -{ - char const * const *pjdl; - edg_wlc_JobId const *psubjob; - edg_wlc_JobId oldctxjob; - char * oldctxseq; - int errcode = 0; - char * errdesc = NULL; - - if (edg_wll_GetLoggingJob(ctx, &oldctxjob)) return edg_wll_Error(ctx, NULL, NULL); - oldctxseq = edg_wll_GetSequenceCode(ctx); - - pjdl = jdls; - psubjob = subjobs; - - while (*pjdl != NULL) { - if (edg_wll_RegisterSubjob(ctx, *psubjob, EDG_WLL_REGJOB_SIMPLE, *pjdl, - ns, parent, 0, NULL, NULL) != 0) { - errcode = edg_wll_Error(ctx, NULL, &errdesc); - goto edg_wll_registersubjobs_end; - } - pjdl++; psubjob++; - } - -edg_wll_registersubjobs_end: - edg_wll_SetLoggingJob(ctx, oldctxjob, oldctxseq, EDG_WLL_SEQ_NORMAL); - - if (errcode) { - edg_wll_SetError(ctx, errcode, errdesc); - free(errdesc); - } - return edg_wll_Error(ctx, NULL, NULL); -} - -/** - *----------------------------------------------------------------------- - * Register batch of subjobs with L&B Proxy service - * \note simple wrapper around edg_wll_RegisterSubjobProxy() - *----------------------------------------------------------------------- - */ -int edg_wll_RegisterSubjobsProxy( - edg_wll_Context ctx, - glite_jobid_const_t parent, - char const * const * jdls, - const char * ns, - edg_wlc_JobId const * subjobs) -{ - char const * const *pjdl; - edg_wlc_JobId const *psubjob; - edg_wlc_JobId oldctxjob; - char * oldctxseq; - int errcode = 0; - char * errdesc = NULL; - - if (edg_wll_GetLoggingJob(ctx, &oldctxjob)) return edg_wll_Error(ctx, NULL, NULL); - oldctxseq = edg_wll_GetSequenceCode(ctx); - - pjdl = jdls; - psubjob = subjobs; - - while (*pjdl != NULL) { - if (edg_wll_RegisterSubjobProxy(ctx, *psubjob, EDG_WLL_REGJOB_SIMPLE, *pjdl, - ns, parent, 0, NULL, NULL) != 0) { - errcode = edg_wll_Error(ctx, NULL, &errdesc); - goto edg_wll_registersubjobsproxy_end; - } - pjdl++; psubjob++; - } - -edg_wll_registersubjobsproxy_end: - edg_wll_SetLoggingJobProxy(ctx, oldctxjob, oldctxseq, NULL, EDG_WLL_SEQ_NORMAL); - - if (errcode) { - edg_wll_SetError(ctx, errcode, errdesc); - free(errdesc); - } - return edg_wll_Error(ctx, NULL, NULL); -} - -/** - *----------------------------------------------------------------------- - * Change ACL for given job - *----------------------------------------------------------------------- - */ -int edg_wll_ChangeACL( - edg_wll_Context ctx, - glite_jobid_const_t jobid, - const char *user_id, - enum edg_wll_ChangeACLUser_id_type user_id_type, - enum edg_wll_ChangeACLPermission permission, - enum edg_wll_ChangeACLPermission_type permission_type, - enum edg_wll_ChangeACLOperation operation) -{ - if ( edg_wll_SetLoggingJob(ctx, jobid, NULL, EDG_WLL_SEQ_NORMAL) == 0 ) { - edg_wll_LogEventMaster(ctx, EDG_WLL_LOGFLAG_LOCAL | EDG_WLL_LOGFLAG_SYNC, - EDG_WLL_EVENT_CHANGEACL, EDG_WLL_FORMAT_CHANGEACL, - user_id, user_id_type, permission, permission_type, operation); - } - - return edg_wll_Error(ctx,NULL,NULL); -} diff --git a/org.glite.lb.client/src/stat_fields.cpp b/org.glite.lb.client/src/stat_fields.cpp deleted file mode 100644 index 2c4f689..0000000 --- a/org.glite.lb.client/src/stat_fields.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include -#include -#include -#include -//#include - -#include "glite/lb/LoggingExceptions.h" -#include "JobStatus.h" -#include "notification.h" - -#include "stat_fields.h" - -using namespace glite::lb; - -typedef std::pair FieldPair; - -char * glite_lb_parse_stat_fields(const char *arg,void **out) -{ - char *aux = strdup(arg),*p; - std::vector *fields = new std::vector; - - for (p = strtok(aux,","); p; p = strtok(NULL,",")) { - /*special treatment for JDL (and possibly other) two-valued fields with ':' used as a separator */ - if (strncasecmp("jdl:", p, 4)) { - try { fields->push_back(std::make_pair(JobStatus::attrByName(p), "")); } - catch (std::runtime_error &e) { delete fields; return p; }; - } - else { - try { fields->push_back(std::make_pair(JobStatus::attrByName("jdl"), p + 4)); } - catch (std::runtime_error &e) { delete fields; return p; }; - } - } - - *out = (void *) fields; - return NULL; -} - - -static std::string & escape(std::string &s) -{ - for (std::string::iterator p = s.begin(); p < s.end(); p++) switch (*p) { - case '\n': - s.insert(p-s.begin(),"\\"); *(++p) = 'n'; - break; - case '\t': - s.insert(p-s.begin(),"\\"); *(++p) = 't'; - break; - default: break; - } - return s; -} - -typedef std::vector > attrs_t; - -void glite_lb_dump_stat_fields(void) -{ - JobStatus s; - attrs_t a = s.getAttrs(); - for (attrs_t::iterator i=a.begin(); i != a.end(); i++) { - switch (i->second) { - case JobStatus::INT_T: - case JobStatus::STRING_T: - case JobStatus::TIMEVAL_T: - std::cerr << JobStatus::getAttrName(i->first) << ", "; - default: break; - } - } -} - -extern "C" { char * TimeToStr(time_t); } - -void glite_lb_print_stat_fields(void **ff,edg_wll_JobStat *s) -{ - std::vector *fields = (std::vector *) ff; - JobStatus stat(*s,0); - attrs_t attrs = stat.getAttrs(); - attrs_t::iterator a; - std::vector::iterator f; - std::string val; - struct timeval t; - JobStatus::Attr attr; - char *jdl_param = NULL,*jobid_s = NULL; - - std::cout << (jobid_s = glite_jobid_unparse(s->jobId)) << '\t' << stat.name() << '\t'; - free(jobid_s); - - for (f = fields->begin(); f != fields->end(); f++) { - for (a = attrs.begin(); a != attrs.end() && a->first != f->first; a++); - if (a != attrs.end() ) { - attr = (a->first); - switch (a->second) { - case (JobStatus::INT_T): - std::cout << stat.getValInt(attr) << '\t'; - break; - case (JobStatus::STRING_T): - if (attr != JobStatus::JDL) { - val = stat.getValString(attr); - std::cout << (val.empty() ? "(null)" : escape(val)) << '\t'; - } - else { - val = f->second; - if ((jdl_param = edg_wll_JDLField(s, val.c_str()))) { - std::string s_param(jdl_param); - - std::cout << escape(s_param); - free(jdl_param); jdl_param = NULL; - } else - std::cout << "(null)"; - std::cout << '\t'; - } - break; - case (JobStatus::TIMEVAL_T): - t = stat.getValTime(attr); - std::cout << TimeToStr(t.tv_sec) << '\t'; - break; - default: - std::cout << "(unsupported)"; - break; - } - } - } - std::cout << std::endl; -} diff --git a/org.glite.lb.client/src/statistics.c b/org.glite.lb.client/src/statistics.c deleted file mode 100644 index b1cd79b..0000000 --- a/org.glite.lb.client/src/statistics.c +++ /dev/null @@ -1,186 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include - -#include "glite/lb/context.h" -#include "glite/lb/context-int.h" -#include "glite/lb/xml_parse.h" -#include "glite/lb/mini_http.h" - -#include "statistics.h" -#include "connection.h" - - - -static const char* const request_headers[] = { - "Cache-Control: no-cache", - "Accept: application/x-dglb", - "User-Agent: edg_wll_Api/" PROTO_VERSION "/" COMP_PROTO, - "Content-Type: application/x-dglb", - NULL -}; - -static int set_server_name_and_port(edg_wll_Context, const edg_wll_QueryRec **); - - - -/** Count the number of jobs which entered the specified state. - */ - -int edg_wll_StateRate( - 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) - -{ - char *response = NULL, *send_mess = NULL, *message = NULL; - float not_returned; - - - edg_wll_ResetError(ctx); - - edg_wll_StatsRequestToXML(ctx, "Rate", group, major, minor, from, to, &send_mess); - - if (set_server_name_and_port(ctx, NULL)) - goto err; - - ctx->p_tmp_timeout = ctx->p_query_timeout; - - if (edg_wll_http_send_recv(ctx, "POST /statsRequest HTTP/1.1",request_headers, send_mess, - &response,NULL,&message)) - goto err; - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseStatsResult(ctx,message, from, to, rate, - ¬_returned, res_from, res_to); - -err: - free(response); - free(message); - - return edg_wll_Error(ctx,NULL,NULL); -} - - - -/** Compute average time for which jobs stay in the specified state. - */ - -int edg_wll_StateDuration( - 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) -{ - char *response = NULL, *send_mess = NULL, *message = NULL; - float not_returned; - - - edg_wll_ResetError(ctx); - - edg_wll_StatsRequestToXML(ctx, "Duration", group, major, minor, from, to, &send_mess); - - if (set_server_name_and_port(ctx, NULL)) - goto err; - - ctx->p_tmp_timeout = ctx->p_query_timeout; - - if (edg_wll_http_send_recv(ctx, "POST /statsRequest HTTP/1.1",request_headers, send_mess, - &response,NULL,&message)) - goto err; - - if (http_check_status(ctx,response)) - goto err; - - edg_wll_ParseStatsResult(ctx,message, from, to, ¬_returned, - duration, res_from, res_to); - -err: - free(response); - free(message); - - return edg_wll_Error(ctx,NULL,NULL); -} - - - -static int set_server_name_and_port(edg_wll_Context ctx, const edg_wll_QueryRec **job_conditions) -{ - int i = 0, j, - found = 0, - error = 0; - unsigned int srvPort = 0, - srvPortTmp; - char *srvName = NULL, - *srvNameTmp; - - - if ( job_conditions ) for ( j = 0; job_conditions[j]; j++ ) - for ( i = 0; (job_conditions[j][i].attr != EDG_WLL_QUERY_ATTR_UNDEF); i++ ) - if ( job_conditions[j][i].attr == EDG_WLL_QUERY_ATTR_JOBID) - { - edg_wlc_JobIdGetServerParts(job_conditions[j][i].value.j,&srvNameTmp,&srvPortTmp); - if ( found ) - { - if ( strcmp(srvName, srvNameTmp) || (srvPort != srvPortTmp) ) - { - free(srvNameTmp); free(srvName); - return edg_wll_SetError(ctx, EINVAL, "Two different servers specifieed in one query"); - } - free(srvNameTmp); - } - else - { - srvName = srvNameTmp; - srvPort = srvPortTmp; - found = 1; - } - } - - if ( found && !ctx->p_query_server_override) - { - if (!ctx->srvName) - { - ctx->srvName = strdup(srvName); - ctx->srvPort = srvPort; - free(srvName); - } - else if (strcmp(srvName, ctx->srvName) || (srvPort != ctx->srvPort)) - { - free(ctx->srvName); - ctx->srvName = strdup(srvName); - ctx->srvPort = srvPort; - free(srvName); - } - } - else if ( !ctx->srvName || !ctx->srvPort ) - { - if (!ctx->p_query_server) - return(edg_wll_SetError(ctx, (edg_wll_ErrorCode) EINVAL, "Hostname of server to query is not set")); - else ctx->srvName = strdup(ctx->p_query_server); - if (!ctx->p_query_server_port) - return(edg_wll_SetError(ctx, (edg_wll_ErrorCode) EINVAL, "Port of server to query is not set")); - else ctx->srvPort = ctx->p_query_server_port; - } - - return(error); -} - - diff --git a/org.glite.lb.client/src/uiwrap.T b/org.glite.lb.client/src/uiwrap.T deleted file mode 100644 index c6c85ca..0000000 --- a/org.glite.lb.client/src/uiwrap.T +++ /dev/null @@ -1,157 +0,0 @@ -# this file is common for producer.h and uiwrap.c -# it generates either protoypes (set $PRINTPROTOTYPESONLY to 1) or implementation - -for my $t (sort { $event->{order}->{$a} <=> $event->{order}->{$b} } - $event->getTypes) { - my $tu = uc $t; - my $func = "edg_wll_Log$t"; # name of generated function - my $funcproxy = $func . "Proxy"; - my $funcc = $func . "CODETOREPLACE"; # name of generated CODE function - my $funccproxy = $funcc . "Proxy"; - my $p = "edg_wll_Context context"; # parameters of generated function - my $pc = $p; # parameters of generated CODE function - my $q = "context,EDG_WLL_EVENT_$tu,EDG_WLL_FORMAT_$tu"; # parameters for LogEvent called in generated function - my $qc = $q; # parameters for LogEvent called in generated CODE function - my $text = ""; # whole text for generated function - my $textproxy = ""; # whole text for generated CODE function - my $doc = " * \\param[in,out] context\tcontext to work with, \n"; # parameters description for generated function - my $docc = $doc; # parameters description for generated CODE function - - my $decl = "\tint ret;\n"; - my $free = ""; - - selectType $event $t; - for ($event->getFieldsOrdered) { - my $f = selectField $event $_; - my $fn = $f->getName; - my $sfn = $fn; - my $ft = "const "; - my $fc = $f->getComment; - if ($ULMasString{$f->{type}}) { - $decl .= "\tchar *s_$fn = ".$f->getType()."ToString($fn);\n"; - $free .= "\tif (s_$fn) free(s_$fn);\n"; - $sfn = "s_$fn"; - } - if ($f->{codes}) { -# XXX: obsolete $ft = "enum edg_wll\_$t" . ucfirst $fn; - $ft = $ft . "char *"; - $qc = $qc . ", CODETOREPLACE"; - } else { - $ft = $ft . $f->getType; - $pc = $pc . ", $ft $fn"; - $qc = $qc . ", $sfn"; - $docc = $docc . " * \\param[in] $fn\t$fc\n"; - } - $p = $p . ", $ft $fn"; - $q = $q . ", $sfn"; - $doc = $doc . " * \\param[in] $fn\t$fc\n"; - } - $text = qq{ -/** - * \\brief $func - * - * $func - simple wrapper around edg_wll_LogEvent for event $t - * -}; - $textproxy = qq{ -/** - * \\brief $funcproxy - * - * $funcproxy - simple wrapper around edg_wll_LogEventProxy for event $t - * -}; - if ($PRINTDOC) { - $text = $text . $doc . " * \\see edg_wll_LogEvent()\n"; - $textproxy = $textproxy . $doc . "* \\see edg_wll_LogEventProxy()\n" - } - $text = $text . " */\n"; - $textproxy = $textproxy . " */\n"; - if ($PRINTPROTOTYPESONLY) { - $text = $text . "\nextern int $func($p);\n"; - $textproxy = $textproxy . "\nextern int $funcproxy($p);\n"; - } else { - $text = $text . qq{ -int $func($p) -\{ -$decl - ret = edg_wll_LogEvent($q); -$free - return ret; -\} -}; - $textproxy = $textproxy . qq{ -int $funcproxy($p) -\{ -$decl - ret = edg_wll_LogEventProxy($q); -$free - return ret; -\} -}; - } - gen "$text"; - gen "$textproxy"; - - # - # generate also CODE functions: - # - for ($event->getFieldsOrdered) { - my $f = selectField $event $_; - my $fn = $f->getName; - if ($f->{codes}) { - for (@{$f->{codes}}) { - my $code = uc $_->{name}; - my $funccc = $funcc; $funccc =~ s/CODETOREPLACE/$code/g; - my $funcccproxy = $funccproxy; $funcccproxy =~ s/CODETOREPLACE/$code/g; - my $qcc = $qc; $qcc =~ s/CODETOREPLACE/"$code"/g; - my $textc = qq{ -/** - * \\brief $funccc - * - * $funccc - simple wrapper around edg_wll_LogEvent for event $t, $fn $code - * -}; - my $textcproxy = qq{ -/** - * \\brief $funcccproxy - * - * $funcccproxy - simple wrapper around edg_wll_LogEventProxy for event $t, $fn $code - * -}; - if ($PRINTDOC) { - $textc = $textc . $docc . " * \\see edg_wll_LogEvent()\n"; - $textcproxy = $textcproxy . $docc . " * \\see edg_wll_LogEventProxy()\n"; - } - $textc = $textc . " */\n"; - $textcproxy = $textcproxy . " */\n"; - if ($PRINTPROTOTYPESONLY) { - $textc = $textc . "\nextern int $funccc($pc);\n"; - $textcproxy = $textcproxy . "\nextern int $funcccproxy($pc);\n"; - } else { - $textc = $textc . qq{ -int $funccc($pc) -\{ -$decl - ret = edg_wll_LogEvent($qcc); -$free - return ret; -\} -}; - $textcproxy = $textcproxy . qq{ -int $funcccproxy($pc) -\{ -$decl - ret = edg_wll_LogEventProxy($qcc); -$free - return ret; -\} -}; - } - gen "$textc"; - gen "$textcproxy"; - } # for codes - } # if - } # for getFields -} - -1; diff --git a/org.glite.lb.client/src/uiwrap.c.T b/org.glite.lb.client/src/uiwrap.c.T deleted file mode 100644 index 6ff0e64..0000000 --- a/org.glite.lb.client/src/uiwrap.c.T +++ /dev/null @@ -1,17 +0,0 @@ -#ident "$Header$" -/* -@@@AUTO -*/ -@@@LANG: C - -#include -#include "glite/jobid/cjobid.h" -#include "producer.h" - -@@@{ -$PRINTPROTOTYPESONLY = 0; -$PRINTDOC = 0; - -require '../src/uiwrap.T'; - -@@@} diff --git a/org.glite.lb.client/test/PLOT b/org.glite.lb.client/test/PLOT deleted file mode 100644 index 5179b0d..0000000 --- a/org.glite.lb.client/test/PLOT +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -for i in /tmp/test_ORG /tmp/test_ORG.LB_BUF /tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC /tmp/test_ORG.LB_DAG_EMBRIONIC /tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_*[0-9] /tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_10; -#for i in /tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_10; -do - - #cat $i | grep 1000| sed 's/(//'| awk 'BEGIN {a=8002}; // {print a " " $8 " " sqrt(500000/a); a=a+16004}' > $i.plot; - lines=`cat $i | wc -l| sed 's/ //g'` - cat $i | grep 1000| sed 's/(//'| awk -v lines=$lines 'BEGIN {a=500}; // {print a " " $8 " " lines*1000/a; a=a+1000}' > $i.plot; -# cat $i | grep 1000| sed 's/(//'| awk -v lines=$lines 'BEGIN {a=500}; // {print a " " $8 " " 1; a=a+1000}' > $i.plot; - - -cat </tmp/plot.gp -f(x) = a*log(x+b) + c -a=0 -b=1 -c=0 -fit f(x) '$i.plot' using 1:2:3 via a, b, c -print "f(100000) = ", f(100000) -EOF - -a=`gnuplot /tmp/plot.gp 2>&1| awk '/^a.*=.*%/ {print $3}'` -b=`gnuplot /tmp/plot.gp 2>&1| awk '/^b.*=.*%/ {print $3}'` -c=`gnuplot /tmp/plot.gp 2>&1| awk '/^c.*=.*%/ {print $3}'` -f100000=`gnuplot /tmp/plot.gp 2>&1| awk '/^f\(100000\)/ {print $3}'` - - -cat </tmp/plot_final.gp -f(x) = a*log(x+b) + c -a=0 -b=1 -c=0 -fit f(x) "$i.plot" using 1:2:3 via a, b, c -set xlabel "Number of jobs in DB" -set ylabel "Millions of registrations per day" -set title "Megajob challenge performance measurement" -set out "$i.ps" -set terminal postscript landscape "Helvetica" 14 -plot '$i.plot', f(x) title "f(x) = a * log(x+b) + c [a=$a b=$b c=$c] ",\ - f(100000) title "f(100000) = $f100000" -print f(100000) -print f(1000000) -print f(10000000) -EOF - -gnuplot /tmp/plot_final.gp - -done diff --git a/org.glite.lb.client/test/TEST b/org.glite.lb.client/test/TEST deleted file mode 100755 index aa30839..0000000 --- a/org.glite.lb.client/test/TEST +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash - -TEST_SCRIPT=/home/mulac/src/ORG/org.glite.lb.client/src/perftest_jobreg.sh - -db_clean() { - mysql -u lbserver -e "delete from users;" lbserver20_test - mysql -u lbserver -e "delete from status_tags;" lbserver20_test - mysql -u lbserver -e "delete from states;" lbserver20_test - mysql -u lbserver -e "delete from short_fields;" lbserver20_test - mysql -u lbserver -e "delete from jobs;" lbserver20_test - mysql -u lbserver -e "delete from events;" lbserver20_test - mysql -u lbserver -e "delete from server_state;" lbserver20_test - mysql -u lbserver -e "delete from notif_registrations;" lbserver20_test - mysql -u lbserver -e "delete from notif_jobs;" lbserver20_test - mysql -u lbserver -e "delete from long_fields;" lbserver20_test - mysql -u lbserver -e "delete from acls;" lbserver20_test -} - - -#db_clean; -GLITE_LOCATION=/home/mulac/src/ORG.LB_BUF_LB_DAG_EMBRIONIC/stage -#killall -9 glite-lb-bkserverd -LB_BUF_BYTES=0 -LB_BUF_LINES=10 -$TEST_SCRIPT 1>>/tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_10 2>>/tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_10 - -exit(0); - -db_clean; -GLITE_LOCATION=/home/mulac/src/ORG/stage -#for i in `seq 1 30`; do $TEST_SCRIPT ; done 2>>/tmp/test_ORG 1>>/tmp/test_ORG -killall -9 glite-lb-bkserverd -$TEST_SCRIPT &>/tmp/test_ORG - -db_clean; -GLITE_LOCATION=/home/mulac/src/ORG.LB_BUF/stage -#for i in `seq 1 30`; do $TEST_SCRIPT ; done &>/tmp/test_ORG.LB_BUF -killall -9 glite-lb-bkserverd -$TEST_SCRIPT &>/tmp/test_ORG.LB_BUF - -db_clean; -GLITE_LOCATION=/home/mulac/src/ORG.LB_DAG_EMBRIONIC/stage -#for i in `seq 1 30`; do $TEST_SCRIPT ; done &>/tmp/test_ORG.LB_DAG_EMBRIONIC -killall -9 glite-lb-bkserverd -$TEST_SCRIPT &>/tmp/test_ORG.LB_DAG_EMBRIONIC - -db_clean; -GLITE_LOCATION=/home/mulac/src/ORG.LB_BUF_LB_DAG_EMBRIONIC/stage -#for i in `seq 1 30`; do $TEST_SCRIPT; done &>/tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC -unset LB_BUF_BYTES -unset LB_BUF_LINES -killall -9 glite-lb-bkserverd -$TEST_SCRIPT &>/tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC - -db_clean; -GLITE_LOCATION=/home/mulac/src/ORG.LB_BUF_LB_DAG_EMBRIONIC/stage -killall -9 glite-lb-bkserverd -LB_BUF_BYTES=0 -LB_BUF_LINES=5 -$TEST_SCRIPT &>/tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_5 - -db_clean; -GLITE_LOCATION=/home/mulac/src/ORG.LB_BUF_LB_DAG_EMBRIONIC/stage -killall -9 glite-lb-bkserverd -LB_BUF_BYTES=0 -LB_BUF_LINES=20 -$TEST_SCRIPT &>/tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_20 - - -db_clean; -GLITE_LOCATION=/home/mulac/src/ORG.LB_BUF_LB_DAG_EMBRIONIC/stage -killall -9 glite-lb-bkserverd -LB_BUF_BYTES=0 -LB_BUF_LINES=100 -$TEST_SCRIPT &>/tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_100 - - -db_clean; -GLITE_LOCATION=/home/mulac/src/ORG.LB_BUF_LB_DAG_EMBRIONIC/stage -killall -9 glite-lb-bkserverd -LB_BUF_BYTES=0 -LB_BUF_LINES=500 -$TEST_SCRIPT &>/tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_500 - - -db_clean; -GLITE_LOCATION=/home/mulac/src/ORG.LB_BUF_LB_DAG_EMBRIONIC/stage -killall -9 glite-lb-bkserverd -LB_BUF_BYTES=0 -LB_BUF_LINES=100 -$TEST_SCRIPT &>/tmp/test_ORG.LB_BUF_LB_DAG_EMBRIONIC_1000 - - -exit 0; - diff --git a/org.glite.lb.client/test/prod_proto_test.c b/org.glite.lb.client/test/prod_proto_test.c deleted file mode 100644 index 46a23b9..0000000 --- a/org.glite.lb.client/test/prod_proto_test.c +++ /dev/null @@ -1,36 +0,0 @@ -#define edg_wll_gss_read_full(a,b,c,d,e,f) test_edg_wll_gss_read_full(a,b,c,d,e,f) -#define edg_wll_gss_write_full(a,b,c,d,e,f) test_edg_wll_gss_write_full(a,b,c,d,e,f) - -#include "glite/lb/prod_proto.h" -#include "glite/lb/producer.h" - -/* virtual read will return all zeroes (answer from logger always without error) */ -int -test_edg_wll_gss_read_full(edg_wll_GssConnection *con, - void *buf, - size_t bufsize, - struct timeval *timeout, - size_t *total, - edg_wll_GssStatus *code) -{ - code->major_status = 0; - code->minor_status = 0; - if (bufsize > 0) memset(buf, 0, bufsize); - return bufsize; -} - -int -test_edg_wll_gss_write_full(edg_wll_GssConnection *con, - const void *buf, - size_t bufsize, - struct timeval *timeout, - size_t *total, - edg_wll_GssStatus *code) -{ - *total = write(*(int *)con, buf, bufsize); - code->major_status = 0; - code->minor_status = *total < 0 ? *total : 0; - return *total < 0 ? *total : 0; -} - -#include "prod_proto.c" diff --git a/org.glite.lb.client/test/producer_test.cpp b/org.glite.lb.client/test/producer_test.cpp deleted file mode 100644 index 9f965ba..0000000 --- a/org.glite.lb.client/test/producer_test.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lb/context-int.h" -#include "glite/lb/log_proto.h" - -extern "C" { -int edg_wll_log_write(edg_wll_Context, int *,char *); -int edg_wll_log_read(edg_wll_Context, int *); -int edg_wll_log_proxy_write(edg_wll_Context, int *,char *); -int edg_wll_log_proxy_read(edg_wll_Context, int *); -int edg_wll_log_direct_write(edg_wll_Context, int *,char *); -int edg_wll_log_direct_read(edg_wll_Context, int *); -} - -class ProducerTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(ProducerTest); - CPPUNIT_TEST(testProtoClient); - CPPUNIT_TEST_SUITE_END(); - -public: - - void setUp() { - pipe(pd); - } - - void tearDown() { - close(pd[0]); - close(pd[1]); - } - - void testProtoClient() { - edg_wll_Context context; - int err; - static char *tst_msg = "DATE=20040831150159.702224 HOST=\"some.host\" PROG=edg-wms LVL=USAGE DG.PRIORITY=0 DG.SOURCE=\"UserInterface\" DG.SRC_INSTANCE=\"\" DG.EVNT=\"RegJob\" DG.JOBID=\"https://some.host:1234/x67qr549qc\" DG.SEQCODE=\"UI=2:NS=0:WM=0:BH=1:JSS=0:LM=0:LRMS=0:APP=0\" DG.REGJOB.JDL=\"\" DG.REGJOB.NS=\"ns address\" DG.REGJOB.PARENT=\"\" DG.REGJOB.JOBTYPE=\"SIMPLE\" DG.REGJOB.NSUBJOBS=\"0\" DG.REGJOB.SEED=\"\""; - int size = strlen(tst_msg)+1+EDG_WLL_LOG_SOCKET_HEADER_LENGTH+sizeof(size); - - err = edg_wll_InitContext(&context); - CPPUNIT_ASSERT(err == 0); - err = edg_wll_log_write(context, &pd[1], tst_msg); - CPPUNIT_ASSERT(err == size); - err = edg_wll_log_read(context, &pd[1]); - CPPUNIT_ASSERT(err == 0); - log_proto_server(pd[0], tst_msg); - edg_wll_FreeContext(context); - } - -private: - int pd[2]; - int sock; - - void log_proto_server(int con, char *logline) { - int i; - char b[5]; - char *buf; - ssize_t size, retsize; - - // read DGLOG - retsize = read(con, b, 5); - CPPUNIT_ASSERT(retsize == 5); - CPPUNIT_ASSERT(b[0] == 'D' && b[1] == 'G' && b[2] == 'L' && b[3] == 'O' && b[4] == 'G'); - - // read size (including '\0', little endian) - for (i = 0; i < 4; i++) - CPPUNIT_ASSERT(read(con, b + i, 1) == 1); - size = 0; - for (i = 0; i < 4; i++) - size = (size << 8) + b[3-i]; - - // read the message - buf = (char *)malloc(size); - retsize = read(con, buf, size); - CPPUNIT_ASSERT(size == retsize); - - CPPUNIT_ASSERT(strcmp(buf, logline) == 0); - free(buf); - } -}; - - -CPPUNIT_TEST_SUITE_REGISTRATION( ProducerTest ); - -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; -} diff --git a/org.glite.lb.logger/.cvsignore b/org.glite.lb.logger/.cvsignore deleted file mode 100644 index 1df717b..0000000 --- a/org.glite.lb.logger/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -.project -.cdtproject \ No newline at end of file diff --git a/org.glite.lb.logger/LICENSE b/org.glite.lb.logger/LICENSE deleted file mode 100644 index 259a91f..0000000 --- a/org.glite.lb.logger/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.lb.logger/Makefile b/org.glite.lb.logger/Makefile deleted file mode 100644 index 40cd218..0000000 --- a/org.glite.lb.logger/Makefile +++ /dev/null @@ -1,224 +0,0 @@ -# defaults -top_srcdir=.. -stagedir=. -globalprefix=glite -lbprefix=lb -package=glite-lb-client -version=0.0.0 -PREFIX=/opt/glite - -nothrflavour=gcc32 -thrflavour=gcc32pthr - --include Makefile.inc --include ../project/version.properties - -version=${module.version} - -CC=gcc - -VPATH:=${top_srcdir}/src:${top_srcdir}/test:${top_srcdir}/doc - -VERSION=-DVERSION=\"GLite-${version}\" - -SUFFIXES=.no - -ifdef LB_STANDALONE - LB_STANDALONE_FLAGS:=-DLB_STANDALONE -endif - -ifdef LB_PERF - LOGD:=glite-lb-logd-perf glite-lb-logd-perf-nofile - INTERLOGD:=glite-lb-interlogd-perf \ - glite-lb-interlogd-perf-empty -# glite-lb-interlogd-perf-inline-empty - NOTIF_INTERLOGD:=glite-lb-notif-interlogd - LB_PERF_FLAGS:=-DLB_PERF -else - LOGD:=glite-lb-logd - INTERLOGD:=glite-lb-interlogd - NOTIF_INTERLOGD:=glite-lb-notif-interlogd - WS_INTERLOGD:=glite-lb-ws-interlogd -endif - -DEBUG:=-g -O0 -CFLAGS:=${DEBUG} \ - -I${stagedir}/include -I${top_srcdir}/src \ - -D_GNU_SOURCE \ - ${COVERAGE_FLAGS} \ - ${VERSION} ${LB_STANDALONE_FLAGS} ${LB_PERF_FLAGS} - -LDFLAGS:=-L${stagedir}/${libdir} \ - ${COVERAGE_FLAGS} -LINK:=libtool --mode=link ${CC} ${LDFLAGS} -LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/${libdir} ${LDFLAGS} -INSTALL:=libtool --mode=install install - -#ifneq (${expat_prefix},/usr) -# EXPAT_LIBS:=-L${expat_prefix}/lib -#endif -#EXPAT_LIBS:=${EXPAT_LIBS} -lexpat -# -#EXT_LIBS:= ${EXPAT_LIBS} - -COMMON_LIB:=-lglite_lb_common - -TRIO_LIB:=-lglite_lbu_trio - -GLITE_GSS_LIB:=-lglite_security_gss - -TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit -TEST_INC:=-I${cppunit_prefix}/include - -LOGD_OBJS:= logd_proto.o logd.o - -LOGD_NOBJS:=${LOGD_OBJS:.o=.no} - -INTERLOG_OBJS:=il_error.o input_queue_socket.o \ - recover.o send_event.o \ - event_queue.o event_store.o il_master.o interlogd.o \ - queue_mgr.o server_msg.o queue_thread.o - -WS_INTERLOG_OBJS:=il_error.o input_queue_socket_http.o \ - recover.o http.o send_event_http.o \ - event_queue.o event_store_http.o il_master.o interlogd.o \ - queue_mgr_http.o server_msg_http.o queue_thread.o - -INTERLOG_NOBJS:=${INTERLOG_OBJS:.o=.no} -INTERLOG_WOBJS:=${WS_INTERLOG_OBJS:.o=.wo} -INTERLOG_PERF_OBJS:=${INTERLOG_OBJS:.o=.perf.o} -INTERLOG_EMPTY_OBJS:=${INTERLOG_OBJS:.o=.empty.o} -#INTERLOG_INLINE_EMPTY_OBJS:=${INTERLOG_OBJS:.o=.io} - -INTERLOG_TEST_OBJS:= \ - il_error.o \ - server_msg.o \ - server_msgTest.o \ - queue_thread.o \ - event_store.o \ - event_storeTest.o \ - queue_mgr.o \ - il_master.o \ - input_queue_socket.o \ - input_queue_socketTest.o \ - send_event.o \ - event_queue.o \ - event_queueTest.o \ - IlTestBase.o \ - il_test.o - -MAN_GZ:=glite-lb-interlogd.8.gz glite-lb-logd.8.gz -MAN = $(MAN_GZ:.gz=) - -default: all - -all compile: $(LOGD) $(INTERLOGD) $(NOTIF_INTERLOGD) ${MAN_GZ} - -glite-lb-logd: ${LOGD_OBJS} - ${LINK} -o $@ ${LOGD_OBJS} ${COMMON_LIB}_${nothrflavour} ${TRIO_LIB} - -glite-lb-logd-perf: ${LOGD_OBJS} - ${LINK} -o $@ ${LOGD_OBJS} ${COMMON_LIB}_${nothrflavour} ${TRIO_LIB} - -glite-lb-logd-nofile: ${LOGD_NOBJS} - ${LINK} -o $@ ${LOGD_NOBJS} ${COMMON_LIB}_${nothrflavour} - -glite-lb-logd-perf-nofile: ${LOGD_NOBJS} - ${LINK} -o $@ ${LOGD_NOBJS} ${COMMON_LIB}_${nothrflavour} - -glite-lb-interlogd: ${INTERLOG_OBJS} - ${LINK} -o $@ ${INTERLOG_OBJS} ${COMMON_LIB}_${thrflavour} - -glite-lb-notif-interlogd: ${INTERLOG_NOBJS} - ${LINK} -o $@ ${INTERLOG_NOBJS} ${COMMON_LIB}_${thrflavour} - -glite-lb-interlogd-perf: ${INTERLOG_PERF_OBJS} - ${LINK} -o $@ ${INTERLOG_PERF_OBJS} ${COMMON_LIB}_${thrflavour} - -glite-lb-interlogd-perf-empty: ${INTERLOG_EMPTY_OBJS} - ${LINK} -o $@ ${INTERLOG_EMPTY_OBJS} ${COMMON_LIB}_${thrflavour} - -glite-lb-ws-interlogd: ${INTERLOG_WOBJS} - ${LINK} -o $@ ${INTERLOG_WOBJS} ${COMMON_LIB}_${thrflavour} - -#glite-lb-interlogd-perf-inline-empty: ${INTERLOG_INLINE_EMPTY_OBJS} -# ${LINK} -o $@ ${INTERLOG_INLINE_EMPTY_OBJS} \ -# ${COMMON_LIB}_${thrflavour} - -${MAN_GZ}: ${MAN} - rm -f ${MAN_GZ} ${MAN} - cp $? . - gzip -f $(notdir $?) - -man: ${MAN_GZ} - -stage: compile - $(MAKE) install PREFIX=${stagedir} - -check: -# do nothing until test/ is really added to CVS -# check.ll check.il - -#check.ll: logd_proto_test.o ll_test.o -# ${LINKXX} -o $@ ${COMMON_LIB}_${nothrflavour} ${EXT_LIBS} ${TEST_LIBS} $+ -# ./check.ll - -check.ll: - -echo commented out -- fix needed - -check.il: ${INTERLOG_TEST_OBJS} - ${LINKXX} -o $@ ${COMMON_LIB}_${thrflavour} ${GLITE_GSS_LIB}_${nothrflavour} ${TEST_LIBS} -lpthread $+ - -install: - -mkdir -p ${PREFIX}/bin - -mkdir -p ${PREFIX}/etc/init.d - -mkdir -p ${PREFIX}/share/doc/${package}-${version} - -mkdir -p ${PREFIX}/share/man/man8 - ${INSTALL} -m 755 ${LOGD} ${PREFIX}/bin - ${INSTALL} -m 755 ${INTERLOGD} ${PREFIX}/bin - ${INSTALL} -m 755 ${NOTIF_INTERLOGD} ${PREFIX}/bin -ifdef LB_PERF - -mkdir -p ${PREFIX}/sbin - ${INSTALL} -m 755 ${top_srcdir}/src/perftest_ll.sh ${PREFIX}/sbin -endif - ${INSTALL} -m 755 ${top_srcdir}/config/startup ${PREFIX}/etc/init.d/glite-lb-locallogger - ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} - ( cd ${top_srcdir}/project && ${INSTALL} -m 644 ChangeLog package.description package.summary ${PREFIX}/share/doc/${package}-${version} ) - ${INSTALL} -m 644 ${MAN_GZ} ${PREFIX}/share/man/man8 - -${INTERLOG_NOBJS}: %.no: %.c - ${CC} ${CFLAGS} -DIL_NOTIFICATIONS -c $< -o $@ - -${INTERLOG_OBJS}: %.o: %.c - ${CC} ${CFLAGS} -c $< -o $@ - -${INTERLOG_WOBJS}: %.wo: %.c - ${CC} ${CFLAGS} -DIL_WS -c $< -o $@ - -${INTERLOG_EMPTY_OBJS}: %.empty.o: %.c - ${CC} ${CFLAGS} -DPERF_EMPTY -c $< -o $@ - -${INTERLOG_PERF_OBJS}: %.perf.o: %.c - ${CC} ${CFLAGS} -c $< -o $@ - -#${INTERLOG_INLINE_EMPTY_OBJS}: %.io: %.c -# ${CC} ${CFLAGS} -DLB_PERF -DPERF_EMPTY -DPERF_EVENTS_INLINE -c $< -o $@ - -${LOGD_NOBJS}: %.no: %.c - ${CC} ${CFLAGS} -DLOGD_NOFILE -c $< -o $@ - -${LOGD_OBJS}: %.o: %.c - ${CC} ${CFLAGS} -c $< -o $@ - -logd_proto_test.o: %.o: %.c - ${CC} ${CFLAGS} -c $< -o $@ - -ll_test.o: %.o: %.cpp - ${CXX} ${CFLAGS} ${TEST_INC} -c $< -o $@ - -il_test.o IlTestBase.o server_msgTest.o event_queueTest.o input_queue_socketTest.o event_storeTest.o: %.o: %.cpp - ${CXX} ${CFLAGS} ${TEST_INC} -c $< -o $@ - -clean: - rm -rvf .libs/ *.o *.no ${LOGD} ${INTERLOGD} ${NOTIF_INTERLOGD} ${MAN_GZ} - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ diff --git a/org.glite.lb.logger/build.xml b/org.glite.lb.logger/build.xml deleted file mode 100755 index e5382ce..0000000 --- a/org.glite.lb.logger/build.xml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb.logger/config/glite-lb-logger.config.xml b/org.glite.lb.logger/config/glite-lb-logger.config.xml deleted file mode 100644 index 897975f..0000000 --- a/org.glite.lb.logger/config/glite-lb-logger.config.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - glite_lb_logd daemon - - - port to listen - - - path and prefix for event files - - - path to local socket - - - location of server certificate - - - location of server private key - - - "directory containing CA certificates" - - - - - - - - glite_lb_interlogd daemon - - - path and prefix for event files - - - path to local socket - - - location of server certificate - - - location of server private key - - - "directory containing CA certificates" - - - - - - - - glite_lb_notif_interlogd daemon - - - path and prefix for event files - - - path to local socket - - - location of server certificate - - - location of server private key - - - "directory containing CA certificates" - - - - - - - diff --git a/org.glite.lb.logger/config/glite-lb-logger.default-properties b/org.glite.lb.logger/config/glite-lb-logger.default-properties deleted file mode 100644 index 202f5aa..0000000 --- a/org.glite.lb.logger/config/glite-lb-logger.default-properties +++ /dev/null @@ -1,18 +0,0 @@ -locallogger.port = 9002 -locallogger.file-prefix = /var/glite/log/dglogd.log -locallogger.socket = /tmp/interlogger.sock -locallogger.cert = /etc/grid-security/hostcert.pem -locallogger.key = /etc/grid-security/hostkey.pem -locallogger.CAdir = /etc/grid-security/certificates -interlogger.file-prefix = /var/glite/log/dglogd.log -interlogger.socket = /tmp/interlogger.sock -interlogger.cert = /etc/grid-security/hostcert.pem -interlogger.key = /etc/grid-security/hostkey.pem -interlogger.CAdir = /etc/grid-security/certificates -notification-interlogger.file-prefix = /tmp/notif_events -notification-interlogger.socket = /tmp/notif_interlogger.sock -notification-interlogger.cert = /etc/grid-security/hostcert.pem -notification-interlogger.key = /etc/grid-security/hostkey.pem -notification-interlogger.CAdir = /etc/grid-security/certificates -log.Priority = DEBUG -log.fileName = /var/glite/log/glite-lb-logger.log diff --git a/org.glite.lb.logger/config/startup b/org.glite.lb.logger/config/startup deleted file mode 100755 index 814f9b8..0000000 --- a/org.glite.lb.logger/config/startup +++ /dev/null @@ -1,87 +0,0 @@ -#!/bin/sh -# chkconfig: 345 76 24 - -GLITE_LOCATION=${GLITE_LOCATION:-/opt/glite} -GLITE_LOCATION_VAR=${GLITE_LOCATION_VAR:-$GLITE_LOCATION/var} - -[ -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 - -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 "$creds" ] && echo $0: WARNING: No credentials specified. Using default lookup which is dangerous. >&2 - - [ -n "$GLITE_LB_LOGGER_PORT" ] && port="--port $GLITE_LB_LOGGER_PORT" - [ -n "$GLITE_LB_IL_SOCK" ] && sock="--socket $GLITE_LB_IL_SOCK" - [ -n "$GLITE_LB_IL_FPREFIX" ] && fprefix="--file-prefix $GLITE_LB_IL_FPREFIX" - - mkdir -p /var/glite/log - chown $GLITE_USER /var/glite/log - echo -n Starting glite-lb-logd ... - (cd /tmp && ls -f /tmp |grep ^dglogd_sock_ |xargs rm -f) - su - $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-logd \ - $creds $port $sock $fprefix" && echo " done" || echo " FAILED" - - echo -n Starting glite-lb-interlogd ... - su - $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-interlogd \ - $creds $sock $fprefix" && echo " done" || echo " FAILED" -} - -stop() -{ - echo -n Stopping glite-lb-logd ... - killall glite-lb-logd - echo " done" - echo -n Stopping glite-lb-interlogd ... - killall glite-lb-interlogd - echo " done" -} - -status() -{ - LC_ALL=C - if netstat -an --inet | grep "^tcp .* 0.0.0.0:${GLITE_LB_LOGGER_PORT:-9002} .*LISTEN" >/dev/null 2>&1 ;then - echo glite-lb-logd running - else - echo glite-lb-logd not running - return 1 - fi - if netstat -an --unix | grep "^unix .* LISTEN.* ${GLITE_LB_IL_SOCK:-/tmp/interlogger.sock}$" >/dev/null 2>&1 ;then - echo glite-lb-interlogd running - else - echo glite-lb-interlogd not running - return 1 - fi -} - -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 diff --git a/org.glite.lb.logger/configure b/org.glite.lb.logger/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lb.logger/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lb.logger/doc/glite-lb-interlogd.8 b/org.glite.lb.logger/doc/glite-lb-interlogd.8 deleted file mode 100644 index d294ec7..0000000 --- a/org.glite.lb.logger/doc/glite-lb-interlogd.8 +++ /dev/null @@ -1,179 +0,0 @@ -.TH GLITE-LB-INTERLOGD 8 "April 2008" "EU EGEE Project" "Logging&Bookkeeping" - -.SH NAME -glite-lb-interlogd - interlogger daemon - -.SH SYNOPSIS -.B glite-lb-interlogd -.RI [ options ] -.br - -.SH DESCRIPTION -.B glite-lb-interlogd -takes over L&B events from glite-lb-logd and -it is responsible for reliable transfer to their target storage - -bookkeeping and logging servers. -Interlogger maintains message queues for each target server -and implements reliable handling in environment with possible communication -failures. - -On startup (and then periodically during operation) interlogger checks the -event files (created by glite-lb-logd, see also the -f option), -spawns a thread for each target server, and populates the queues -with events read from the files. -Then it starts listening for further incoming events on the UNIX socket -(see the -s option). - -The queue threads periodically attempt to contact the destination servers -and to deliver the pending events. - -Eventually, when all events from a file are delivered the file is removed -after a certain timeout by a clean-up thread. -Possible race conditions wrt. glite-lb-logd are prevented by -locking the files appropriately. - -.SH OPTIONS -.TP -.B "-b\fR,\fP --book -Send events only to bookkeeping server. This option has effect only if -the logging server address is specified through the -l option. There is no -implementation of logging server currently. - -.TP -.BI \-c " FILE" "\fR,\fP --cert " FILE -Get certificate from -.I FILE\fR.\fP -This option overrides the -.B \fR$\fPX509_USER_CERT -environment variable. - -.TP -.BI \-k " FILE" "\fR,\fP --key " FILE -Get server private key from -.I FILE\fR.\fP -This option overrides the -.B \fR$\fPX509_USER_KEY -environment variable. - -.TP -.BI \-C " DIR" "\fR,\fP --CAdir " DIR -Look for trusted CA's certificates in -.I DIR\fR.\fP -This option overrides the -.B \fR$\fPX509_CERT_DIR -environment variable. - -.TP -.B "-d\fR,\fP --debug" -Don't run as daemon (do not fork and put itself into background). - -.TP -.BI \-f " PREFIX" "\fR,\fP --file-prefix " PREFIX -.I PREFIX -is path prefix of the event files. - -For each job (jobid) a specific file is created that stores all events -associated with this job. -The job filename is constructed by stripping the -protocol+server prefix from the jobid and appending the rest to this -.I PREFIX. - -.I PREFIX -defaults to /tmp/dglogd.log. - -On startup, interlogger checks all files matching the pattern -.I PREFIX*. - -The value has to be same as used in the cooperating glite-lb-logd. - -.TP -.BI \-k " FILE" "\fR,\fP --key " FILE -Get private key from -.I FILE\fR.\fP -This option overrides the -.B \fR$\fPX509_USER_KEY -environment variable. - -.TP -.BI -l " HOST" "\fR,\fP --log-server " HOST -Use -.I HOST -as address of logging server. -As the logging is not implemented yet this option should not be used. - -.TP -.BI -s " PATH" "\fR,\fP --socket " PATH -Listen for events sent by glite-lb-logd at the UNIX socket -.I PATH. - -.TP -.B "-v\fR,\fP --verbose" -Print extensive debug output. - -.TP -.B "-V\fR,\fP --version" -Print version and exit. - -.TP -.BI -L " TIMEOUT" "\fR,\fP --lazy " TIMEOUT -Be lazy when closing connections to servers (default, -.I TIMEOUT\fR -==0 means turn lazy off). - -.TP -.BI "-h\fR,\fP --help" -Print help and exit. - -.\".SH USAGE -.\" Add any additional description here - -.PP - -.SH FILES -.TP -.I /tmp/interlogger.sock -Default name of local socket. -.TP -.I /tmp/dglogd.log* -Default location of event files. - -.I /tmp/dglogd.log*.ctl -Interlogger's control files keeping the information on status of -the corresponding event file wrt. delivery to the target server. - -.TP -No configuration files needed. - -.SH ENVIRONMENT -.TP -.B X509_USER_KEY -If -.B \fR$\fPX509_USER_KEY -is set, it is used to locate private key file. - -.TP -.B X509_USER_CERT -If -.B \fR$\fPX509_USER_CERT -is set, it is used to locate certificate file. - -.TP -.B X509_CERT_DIR -If -.B \fR$\fPX509_CERT_DIR -is set, it is used to locate the trusted CA's certificates and ca-signing-policy files. - -.TP -.B X509_USER_PROXY -If -.B \fR$\fPX509USER_PROXY -is set, it is used to locate proxy certificate file. - -.SH REPORTING BUGS -Please, report all bugs to EU EGEE Bug Tracking System located at https://savannah.cern.ch - -.SH SEE ALSO -.B te-lb-bkserverd\fR(8),\fP glite-lb-logd\fR(8),\fP glite-lb-logevent\fR(1),\fP - -.SH AUTHOR -EU EGEE, JRA1. diff --git a/org.glite.lb.logger/doc/glite-lb-logd.8 b/org.glite.lb.logger/doc/glite-lb-logd.8 deleted file mode 100644 index a28529a..0000000 --- a/org.glite.lb.logger/doc/glite-lb-logd.8 +++ /dev/null @@ -1,166 +0,0 @@ -.TH GLITE-LB-LOGD 8 "April 2008" "EU EGEE Project" "Logging&Bookkeeping" - -.SH NAME -glite-lb-logd - local logger daemon - -.SH SYNOPSIS -.B glite-lb-logd -.RI [ options ] -.br - -.SH DESCRIPTION -.B glite-lb-logd -accepts the L&B events from their sources (via the producer L&B API). -It is responsible for fast acceptance of the events and their reliable storage -in local files. - -Under normal conditions, the events are forwared to the -.B glite-lb-interlogd -immediately. -The file storage allows the interlogger crash recovery. - -.SH OPTIONS -.TP -.BI \-c " FILE" "\fR,\fP --cert " FILE -Get certificate from -.I FILE\fR.\fP -This option overrides the -.B \fR$\fPX509_USER_CERT -environment variable. - -.TP -.BI \-C " DIR" "\fR,\fP --CAdir " DIR -Look for trusted CA's certificates in -.I DIR\fR.\fP -This option overrides the -.B \fR$\fPX509_CERT_DIR -environment variable. - -.TP -.B "-d\fR,\fP --debug" -Don't run as daemon, print additional diagnostics. - -.TP -.B "-v\fR,\fP --verbose" -Print extensive debug output. - -.TP -.BI \-p " NUM" "\fR,\fP --port " NUM -Listen on the port -.I NUM\fR.\fP - -.TP -.BI \-f " PREFIX" "\fR,\fP --file-prefix " PREFIX -.I PREFIX -is a path prefix of the event files. - -For each job (jobid) a specific file is created that stores all events -associated with this job. -The job filename is constructed by stripping the -protocol+server prefix from the jobid and appending the rest to this -.I PREFIX. - -.I PREFIX -defaults to /tmp/dglogd.log. - -The value has to be same as used in the cooperating glite-lb-logd. - -.TP -.BI \-k " FILE" "\fR,\fP --key " FILE -Get private key from -.I FILE\fR.\fP -This option overrides the -.B \fR$\fPX509_USER_KEY -environment variable. - - -.TP -.BI -s " PATH" "\fR,\fP --socket " PATH -Send the messages to interlogger through the UNIX socket -.I PATH\fR.\fP - -The value has to be same as used in the cooperating glite-lb-interlogd. - -.TP -.B "-V\fR,\fP --version" -Print version and exit. - -.TP -.B "-h\fR,\fP --help" -Print help and exit. - -.TP -.B --noAuth -Don't require valid X509 credentials to run the daemon. -Used for debugging only. - -.TP -.B --noIPC -Don't send messages to interlogger. - -.TP -.B --noParse -Don't parse messages for correctness. -Dangerous, for debugging only! Don't use at all. - - -.\".SH USAGE -.\" Add any additional description here - -.PP - -.SH FILES -.TP -.I /tmp/interlogger.sock -Default name of local socket. - -.TP -.I /tmp/dglogd.log* -Default location of the event storage files. -.TP -No configuration files needed. - -.SH ENVIRONMENT -.TP -.B X509_USER_KEY -If -.B \fR$\fPX509_USER_KEY -is set, it is used to locate private key file. - -.TP -.B X509_USER_CERT -If -.B \fR$\fPX509_USER_CERT -is set, it is used to locate certificate file. - -.TP -.B X509_CERT_DIR -If -.B \fR$\fPX509_CERT_DIR -is set, it is used to locate the trusted CA's certificates and ca-signing-policy files. - -.TP -.B X509_USER_PROXY -If -.B \fR$\fPX509USER_PROXY -is set, it is used to locate proxy certificate file. - - -.SH SIGNALS -.TP -.B USR1 -Increase verbosity of the program. - -.TP -.B USR2 -Decrease verbosity of the program. - - -.SH REPORTING BUGS -Please, report all bugs to EGEE Bug Tracking System located at https://savannah.cern.ch - -.SH SEE ALSO -.B glite-lb-bkserverd\fR(8),\fP glite-lb-interlogd\fR(8),\fP glite-lb-logevent\fR(1),\fP - -.SH AUTHOR -EU EGEE, JRA1. diff --git a/org.glite.lb.logger/project/ChangeLog b/org.glite.lb.logger/project/ChangeLog deleted file mode 100644 index b9eae69..0000000 --- a/org.glite.lb.logger/project/ChangeLog +++ /dev/null @@ -1,53 +0,0 @@ -1.4.6-1 (lb-1.7.0-1) -- let empty notification message get through the output queue to keep - event_store commits in sync -- don't keep event queue mutex while sleeping on error - -1.4.7-1 (lb-1.7.1-1) -- support for message expiration - -1.4.8-1 (lb-1.7.2-1) -- support for notification expiration - -1.4.9-1 (lb-1.7.3-1) -- treat zero event expiration time as "never" - -1.4.9-2 (lb-1.7.4-1) -- rebuild wrt. downgraded security 3.1.57-1 - -1.4.9-3 (lb-1.8.0-1) -- startup script: use grep with ^ rather than fgrep - -1.4.10-1 -- fixed sending empty events -- do not syslog "error reading server reply" unnecessarily - -2.0.0-1 -- LB 2.0 release - -2.0.0-2 -- fixed configure to work in etics - -2.0.0-3 -- Fixed typos in the Makefile - -2.0.0-4 -- configure script update (globus flavors added to configure call) - -2.0.1-1 -- (from 1.4.11-1) Support chconfig in startup scripts (#27055) -- (from 1.4.11-1) Proper kill signal handling (#36470) - -2.0.2-1 -- implemented multi-file event store, avoiding ever-growing files - in the case of heavy traffic notifications - -2.0.3-1 -- Fixed handling messages with destination not set -- Additional logging output - -2.0.4-1 -- Man page update - -2.0.4-2 -- install libraries into $libdir diff --git a/org.glite.lb.logger/project/build.number b/org.glite.lb.logger/project/build.number deleted file mode 100644 index 6dd2f97..0000000 --- a/org.glite.lb.logger/project/build.number +++ /dev/null @@ -1,2 +0,0 @@ -#Fri Aug 18 12:30:51 CEST 2006 -module.build=0243 diff --git a/org.glite.lb.logger/project/build.properties b/org.glite.lb.logger/project/build.properties deleted file mode 100644 index e69de29..0000000 diff --git a/org.glite.lb.logger/project/configure.properties.xml b/org.glite.lb.logger/project/configure.properties.xml deleted file mode 100644 index 3279d84..0000000 --- a/org.glite.lb.logger/project/configure.properties.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - -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} -cppunit_prefix=${with.cppunit.prefix} -thrflavour=${with.globus.thr.flavor} -nothrflavour=${with.globus.nothr.flavor} - - - diff --git a/org.glite.lb.logger/project/package.description b/org.glite.lb.logger/project/package.description deleted file mode 100644 index cd0621b..0000000 --- a/org.glite.lb.logger/project/package.description +++ /dev/null @@ -1 +0,0 @@ -glite-lb-logger is the gLite LB local-logger and inter-logger. This package contains the local-logger (glite-lb-logd), inter-logger (glite-lb-interlogd) and notification inter-logger (glite-lb-notif-interlogd) daemons. diff --git a/org.glite.lb.logger/project/package.summary b/org.glite.lb.logger/project/package.summary deleted file mode 100644 index 089b630..0000000 --- a/org.glite.lb.logger/project/package.summary +++ /dev/null @@ -1 +0,0 @@ -gLite Logging and Bookkeeping local-logger and inter-logger diff --git a/org.glite.lb.logger/project/properties.xml b/org.glite.lb.logger/project/properties.xml deleted file mode 100755 index 44827cf..0000000 --- a/org.glite.lb.logger/project/properties.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb.logger/project/tar_exclude b/org.glite.lb.logger/project/tar_exclude deleted file mode 100644 index e1fcd1a..0000000 --- a/org.glite.lb.logger/project/tar_exclude +++ /dev/null @@ -1,10 +0,0 @@ -tar_exclude -CVS -build.xml -build -build.properties -properties.xml -configure.properties.xml -.cvsignore -.project -.cdtproject diff --git a/org.glite.lb.logger/project/version.properties b/org.glite.lb.logger/project/version.properties deleted file mode 100644 index f217dfa..0000000 --- a/org.glite.lb.logger/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# $Header$ -module.version=2.0.4 -module.age=2 diff --git a/org.glite.lb.logger/src-nt/Connection.H b/org.glite.lb.logger/src-nt/Connection.H deleted file mode 100644 index 808b788..0000000 --- a/org.glite.lb.logger/src-nt/Connection.H +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _CONNECTION_H -#define _CONNECTION_H - - -class Connection { -public: - class Factory { - public: - virtual Connection *newConnection(int fd) const = 0; - virtual Connection *accept(int fd) const = 0; - - virtual ~Factory() {} - }; - - class Endpoint { - }; - - Connection(int a_fd) : fd(a_fd) - {} - - virtual ~Connection() - {} - - virtual int getFD() const - { return fd; } - - virtual int read(char *buf, unsigned int len) = 0; - virtual int write(char *buf, unsigned int len) = 0; - -protected: - int fd; -}; - -#endif diff --git a/org.glite.lb.logger/src-nt/Connection.cpp b/org.glite.lb.logger/src-nt/Connection.cpp deleted file mode 100644 index 7cac943..0000000 --- a/org.glite.lb.logger/src-nt/Connection.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "Connection.H" - -Connection::Factory::~Factory() { -} diff --git a/org.glite.lb.logger/src-nt/EventManager.H b/org.glite.lb.logger/src-nt/EventManager.H deleted file mode 100644 index b1f16ee..0000000 --- a/org.glite.lb.logger/src-nt/EventManager.H +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef _EVENT_MANAGER_H -#define _EVENT_MANAGER_H - -#include - - -// interface - -/** - * Base class of event hierarchy. - */ -class Event { -public: - virtual ~Event() {} -}; - - -/** - * Base class for event handler address. - */ -class EventHandler { -public: - // constants for event handler return codes - static const int NOT_HANDLED = 0; - static const int HANDLED = 1; - static const int HANDLED_FINAL = 2; - static const int HANDLED_NEW = 3; - - virtual int handleEvent(Event* &e) { return NOT_HANDLED; } - virtual ~EventHandler() {} -}; - - -/** - * Holds addres of event handler, ie. pointer to member function of T - * that takes E* & as an argument. - */ -template -class TypedEventHandler: public EventHandler { -public: - typedef int (T::*handlerType)(E* &); - - TypedEventHandler(T *handler, handlerType method) - : m_handler(handler), m_handleEvent(method) { - } - - virtual int handleEvent(Event* &e) { - E *ne = dynamic_cast(e); - int result = EventHandler::NOT_HANDLED; - if(ne) { - result = (m_handler->*m_handleEvent)(ne); - if((result == EventHandler::HANDLED_NEW) && - !(ne == e)) { - delete e; - e = ne; - } - } - return result; - } - -private: - T *m_handler; - handlerType m_handleEvent; -}; - - -class EventManager { -public: - - int postEvent(Event* &event); - - template - EventHandler& registerHandler(T *handler, int (T::*method)(E* &)) { - EventHandler *h = new TypedEventHandler(handler, method); - addHandler(h); - return *h; - } - - template - EventHandler& registerHandler(T *handler) { - return registerHandler(handler, &T::handleEvent); - } - -private: - std::list handlers; - - void addHandler(EventHandler*); - void removeHandler(EventHandler *); -}; - - -#endif diff --git a/org.glite.lb.logger/src-nt/EventManager.cpp b/org.glite.lb.logger/src-nt/EventManager.cpp deleted file mode 100644 index 91efb12..0000000 --- a/org.glite.lb.logger/src-nt/EventManager.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "EventManager.H" - -int -EventManager::postEvent(Event* &e) -{ - for(std::list::iterator i = handlers.begin(); - i != handlers.end(); - i++) { - (*i)->handleEvent(e); - } - return 0; -} - -void -EventManager::addHandler(EventHandler *handler) -{ - handlers.push_back(handler); -} - -void -EventManager::removeHandler(EventHandler *handler) -{ -} diff --git a/org.glite.lb.logger/src-nt/Exception.H b/org.glite.lb.logger/src-nt/Exception.H deleted file mode 100644 index a2c921d..0000000 --- a/org.glite.lb.logger/src-nt/Exception.H +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _EXCEPTION_H -#define _EXCEPTION_H - -class Exception { -}; - -class FatalException { -}; - - -#define E_ASSERT(a) if(!(a)) { throw new FatalException; } - -#endif diff --git a/org.glite.lb.logger/src-nt/HTTPTransport.H b/org.glite.lb.logger/src-nt/HTTPTransport.H deleted file mode 100644 index 05e928b..0000000 --- a/org.glite.lb.logger/src-nt/HTTPTransport.H +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _HTTP_TRANSPORT_H -#define _HTTP_TRANSPORT_H - -#include "ThreadPool.H" -#include "Transport.H" -#include "Singleton.H" - -#include - -class HTTPTransport: - public Transport -{ -public: - - // factory class - class Factory: public Transport::Factory, - public Singleton { - public: - virtual Transport *newTransport() const { - return(new HTTPTransport()); - } - }; - - HTTPTransport() - : Transport(), - state(NONE), - request(), headers(), body(NULL), pos(NULL), - content_length(0) - {} - - virtual ~HTTPTransport(); - - virtual int receive(Connection *conn, Message* &msg); - virtual int send(Connection *conn, Message* msg); - virtual void reset(); - -private: - enum { NONE, - IN_REQUEST, - IN_HEADERS, - IN_BODY } state; - std::string request; - std::string headers; - char *body; - char buffer[256]; - char *pos; - unsigned int content_length; - - int parseHeader(const char *s, unsigned int len); - void serializeHeaders(Message *msg); -}; - - -#endif diff --git a/org.glite.lb.logger/src-nt/HTTPTransport.cpp b/org.glite.lb.logger/src-nt/HTTPTransport.cpp deleted file mode 100644 index 9ed4e16..0000000 --- a/org.glite.lb.logger/src-nt/HTTPTransport.cpp +++ /dev/null @@ -1,255 +0,0 @@ -#include "HTTPTransport.H" -#include "Exception.H" -#include "EventManager.H" - -#include -#include - - -HTTPTransport::~HTTPTransport() -{ - if(body) free(body); -} - - -// read what is available and parse what can be parsed -// returns the result of read operation of the underlying connection, -// ie. the number of bytes read or error code -int -HTTPTransport::receive(Connection *conn, Message* &msg) -{ - int len; - - switch(state) { - case NONE: - state = IN_REQUEST; - pos = buffer; - - case IN_REQUEST: - case IN_HEADERS: - len = conn->read(pos, sizeof(buffer) - (pos - buffer)); - if(len < 0) { - // error during request - // state = NONE; - return len; - } else if(len == 0) { - // other side closed connection - // state = NONE; - return len; - } else { - char *cr = NULL, *p = buffer, *s = buffer; - bool crlf_seen = false; - - // parse buffer, look for CRLFs - // s - start scan position - // p - start of current token - // cr - current CRLF position - // crlf_seen <=> previous block ends with CRLF - while((state != IN_BODY) && - (s < buffer + len) && - (cr = (char*)memchr(s, '\r', len - (s - buffer)))) { - if((cr < buffer + len - 1) && - (cr[1] == '\n')) { - // found CRLF - if(state == IN_REQUEST) { - // found end of request - request.append(p, cr - p); - // change state - state = IN_HEADERS; - // start new tokens - p = cr + 2; - } else { - // headers continue. parse the current one - *cr = 0; - parseHeader(s, cr - s); - *cr = '\r'; - } - if(crlf_seen && (s == cr)) { - // found CRLFCRLF - state = IN_BODY; - } - // next scan starts after CRLF - s = cr + 2; - // we have seen CRLF - crlf_seen = true; - } else { - if(crlf_seen && (s == cr)) { - if(cr < buffer + len - 1) { - // found CRLFCRx - // continue scan behind this - s = cr + 2; - } else { - // found CRLFCR at the end of buffer - // s points behind buffer => scan ends - s = cr + 1; - // cr points at the CRLFCR => it will be left for next pass - cr = cr - 2; - } - } else { - // single '\r' - skip it, - // or '\r' at the end of buffer - skip it, that ends scanning - s = cr + 1; - } - crlf_seen = false; - } - } - // copy the current token into appropriate variable, - // but leave the trailing \r[\n] in buffer - if(!cr) cr = buffer + len; - if(state == IN_REQUEST) - request.append(p, cr - p); - else - headers.append(p, cr - p); - if(state == IN_BODY) { - // we found body - // content-length should be set at the moment - if(content_length > 0) { - body = (char*)malloc(content_length); - if(body == NULL) { - // chyba alokace - } - // move rest of buffer to body - if(s < buffer + len) { - memmove(body, s, buffer + len - s); - pos = body + (buffer + len - s); - } else { - pos = body; - } - } else { - // report error - // XXX - this may happen, do not handle using exceptions - std::cout << "Wrong content length" << std::endl; - throw new Exception(); - } - } else { - // move the trailing characters to the front - if(cr < buffer + len) - memmove(buffer, cr, buffer + len - cr); - // and set pos to point at the first free place - pos = buffer + (buffer + len - cr); - } - } - break; - - case IN_BODY: - len = conn->read(pos, content_length - (pos - body)); - if(len < 0) { - // error reading - // state = NONE; - return len; - } else if(len == 0) { - // no more data - // state = NONE; - return len; - } else { - pos += len; - if(pos == content_length + body) { - // finished reading - state = NONE; - } - } - break; - } - - if(state != NONE) - msg = NULL; - else { - // we have a new message - // XXX - or we have an error, must handle it - msg = new Message(body, content_length); - msg->setProperties( - } - return len; -} - - -int -HTTPTransport::parseHeader(const char *s, unsigned int len) -{ - char *p; - - p = (char*)memccpy((void*)s, (void*)s, ':', len); - - if(!strncasecmp(s, "Content-Length", 14)) { - content_length = p ? atoi(p) : 0 ; - } - return(0); -} - - -int -HTTPTransport::send(Connection *conn, Message* msg) -{ - int len; - switch(state) { - case NONE: - state = IN_REQUEST; - request = "POST " + msg->path() + "HTTP/1.1\r\n"; - pos = request.c_str(); - content_length = msg->getContent(body); - - case IN_REQUEST: - len = conn->send(pos, request.length() - pos + request.c_str()); - if(len < 0) { - return len; - } - pos += len; - if(request.c_str() + request.length() == pos) { - state = IN_HEADERS; - prepareHeaders(msg); - pos = headers.c_str(); - } else { - break; - } - - case IN_HEADERS: - len = conn->send(pos, headers.length() - pos + headers.c_str()); - if(len < 0) { - return len; - } - pos += len; - if(headers.c_str() + headers.length() == pos) { - state = IN_BODY; - pos = body; - } else { - break; - } - - case IN_BODY: - len = conn->send(pos, body, content_length - pos + body); - if(len < 0) { - return len; - } - pos += len; - if(body + content_length == pos) { - state = NONE; - return 0; - } - break; - - default: - } - return len; -} - - -void -HTTPTransport::reset() -{ - state = NONE; - request.clear(); - headers.clear(); - if(body) { - free(body); - body = NULL; - } - content_length = 0; - pos = buffer; -} - - -void -HTTPTransport::serializeHeaders(Message *msg); -{ - for(Properties::iterator i = msg-> -} diff --git a/org.glite.lb.logger/src-nt/InputChannel.H b/org.glite.lb.logger/src-nt/InputChannel.H deleted file mode 100644 index 2bac262..0000000 --- a/org.glite.lb.logger/src-nt/InputChannel.H +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _INPUT_CHANNEL_H_ -#define _INPUT_CHANNEL_H_ - -#include "ThreadPool.H" -#include "Connection.H" -#include "Transport.H" - -class InputChannel - : public ThreadPool::WorkDescription { -public: - - InputChannel(Connection *conn, Transport *trans) - : ThreadPool::WorkDescription(conn->getFD()), - m_connection(conn), m_transport(trans) - {} - - void start(); - -protected: - virtual void onReady(); - virtual void onTimeout(); - virtual void onError(); - -private: - Connection *m_connection; - Transport *m_transport; -}; - -#endif diff --git a/org.glite.lb.logger/src-nt/InputChannel.cpp b/org.glite.lb.logger/src-nt/InputChannel.cpp deleted file mode 100644 index e3ac9c8..0000000 --- a/org.glite.lb.logger/src-nt/InputChannel.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "InputChannel.H" -#include "ThreadPool.H" -#include "EventManager.H" - -extern EventManager theEventManager; - -void -InputChannel::start() -{ - ThreadPool::instance()->queueWorkRead(this); -} - -void -InputChannel::onReady() -{ - Transport::Message *msg = NULL; - int ret = m_transport->receive(m_connection, msg); - if(ret <= 0) { - // no new data read - } else if(msg) { - // we have a new message - - } else { - // still need more data - ThreadPool::instance()->queueWorkRead(this); - } -} - -void -InputChannel::onTimeout() -{ -} - -void -InputChannel::onError() -{ -} diff --git a/org.glite.lb.logger/src-nt/Makefile b/org.glite.lb.logger/src-nt/Makefile deleted file mode 100644 index 8ebe707..0000000 --- a/org.glite.lb.logger/src-nt/Makefile +++ /dev/null @@ -1,51 +0,0 @@ - -CXX = c++ -CC = gcc - -CFLAGS = -g -Wall - -COMPILEPP = $(CXX) $(CXXFLAGS) $(CFLAGS) -COMPILE = $(CC) $(CFLAGS) -LINK = libtool --mode=link g++ $(LDFLAGS) - -THREAD_LIB = -lpthread - -CPPUNIT_ROOT = -CPPUNIT_LIB = -lcppunit -ldl -CPPUNIT_INCLUDE = - -TEST_OBJS= \ - test/ThreadPoolTest.o \ - test/PluginManagerTest.o \ - test/EventManagerTest.o \ - test/SingletonTest.o \ - test/test_main.o - -OBJS = \ - PluginManager.o \ - SocketInput.o \ - Connection.o \ - PlainConnection.o \ - Transport.o \ - HTTPTransport.o \ - ThreadPool.o \ - EventManager.o \ - InputChannel.cpp - -plain: main.o $(OBJS) - $(LINK) -o $@ $+ $(THREAD_LIB) - -utest: ThreadPool.o PluginManager.o EventManager.o $(TEST_OBJS) - $(LINK) -o $@ $+ $(CPPUNIT_LIB) $(THREAD_LIB) - -stest: EventManager.o test/EventManagerTest.o test/test_main.o - $(LINK) -o $@ $+ $(CPPUNIT_LIB) $(THREAD_LIB) - -$(TEST_OBJS): %.o: %.cpp - $(COMPILEPP) -I. $(CPPUNIT_INCLUDE) -o $@ -c $< - -%.o: %.cpp - $(COMPILEPP) -o $@ -c $< - -%.o: %.c - $(COMPILE) -o $@ -c $< \ No newline at end of file diff --git a/org.glite.lb.logger/src-nt/Message.H b/org.glite.lb.logger/src-nt/Message.H deleted file mode 100644 index 725966a..0000000 --- a/org.glite.lb.logger/src-nt/Message.H +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef _MESSAGE_H_ -#define _MESSAGE_H - -#include "Properties.H" -#include "MessageStore.H" - -#include - -class Message: public MessageStore::Storable { -public: - - /** class that holds message state - * - */ - class State : public MessageStore::Storable { - public: - - /** Get size needed for storage (from Storable). - */ - virtual int getStorageSize() const; - - /** Save State (from Storable) - */ - virtual int save(void* data, int len) const; - - /** Load State (from Storable) - */ - virtual int load(void* data, int len); - }; - - - Message(); - - Message(void * data, unsigned int length) - : m_length(length), - m_data(data) - {} - - - int getContent(void* &data) const - { data = m_data; return m_length; } - - int getContentLength() const - { return m_length; } - - std::string getProperty(const std::string &name, std::string &val) - { return m_properties.getProperty(name); } - - void setProperty(const std::string &name, std::string &val) - { m_properties.setProperty(name, val); } - - Properties& getProperties() - { return m_properties; } - - void setProperties(Properties &) - {} - -private: - MessageStore::ID m_id; - unsigned int m_length; - void * m_data; - Properties m_properties; -}; - - -#endif diff --git a/org.glite.lb.logger/src-nt/MessageStore.H b/org.glite.lb.logger/src-nt/MessageStore.H deleted file mode 100644 index ff03a9b..0000000 --- a/org.glite.lb.logger/src-nt/MessageStore.H +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef _MESSAGE_STORE_H_ -#define _MESSAGE_STORE_H_ - -#include - -/** Permanent storage for messages and their states. - */ - -class MessageStore { -public: - - /** Base class for everything that can be stored here. - */ - class Storable { - public: - /** Get size needed for object storage. - */ - virtual int getStorageSize() const = 0; - - /** Save state of object into binary data. - */ - virtual int save(void* data, int len) const = 0; - - /** Load state of object from binary data. - */ - virtual int load(void* data, int len) = 0; - - virtual ~Storable() {} - }; - - - /** Class that uniquely identifies stored content. - */ - class ID: public Storable { - public: - /** Default constructor. - * - * Creates new unique ID. - */ - ID(); - - /** Copy constructor. - */ - ID(const ID& src); - - /** Destructor. - */ - ~ID() {}; - - /** Assignment operator. - */ - ID& operator=(const ID& src); - - /** Return the string suitable for printing. - */ - std::string toString() const; - - /** Comparison operator - */ - int operator==(const ID& second); - - /** Get size needed for storage (from Storable). - */ - virtual int getStorageSize() const; - - /** Save ID (from Storable) - */ - virtual int save(void* data, int len) const; - - /** Load ID (from Storable) - */ - virtual int load(void* data, int len); - - protected: - unsigned long long getID() {return id;} - - private: - static pthread_mutex_t counterLock; - static unsigned counter; - unsigned long long id; - }; -}; - -#endif diff --git a/org.glite.lb.logger/src-nt/MessageStore.cpp b/org.glite.lb.logger/src-nt/MessageStore.cpp deleted file mode 100644 index eb9de7a..0000000 --- a/org.glite.lb.logger/src-nt/MessageStore.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include - -#include "MessageStore.H" - -pthread_mutex_t MessageStore::ID::counterLock = PTHREAD_MUTEX_INITIALIZER; -unsigned MessageStore::ID::counter = 0; - -MessageStore::ID::ID(){ - time_t t; - time(&t); - pthread_mutex_lock(&counterLock); - counter++; - id = ((unsigned long long) counter << 32) + t; - pthread_mutex_unlock(&counterLock); -} - -std::string MessageStore::ID::toString() const{ - std::ostringstream oss; - oss << id; - return oss.str(); -} - diff --git a/org.glite.lb.logger/src-nt/PlainConnection.H b/org.glite.lb.logger/src-nt/PlainConnection.H deleted file mode 100644 index 5536095..0000000 --- a/org.glite.lb.logger/src-nt/PlainConnection.H +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _PLAIN_CONNECTION_H -#define _PLAIN_CONNECTION_H - -#include "Connection.H" -#include "Singleton.H" - -class PlainConnection: - public Connection -{ -public: - class Factory: public Connection::Factory, - public Singleton { - public: - virtual Connection *newConnection(int fd) const { - return new PlainConnection(fd); - } - - virtual Connection *accept(int fd) const; - - virtual ~Factory() {} - }; - - PlainConnection(int a_fd): Connection(a_fd) - {} - - virtual ~PlainConnection(); - - // from Connection - virtual int read(char *buf, unsigned int len); - virtual int write(char *buf, unsigned int len); - -}; - -#endif diff --git a/org.glite.lb.logger/src-nt/PlainConnection.cpp b/org.glite.lb.logger/src-nt/PlainConnection.cpp deleted file mode 100644 index 31ce792..0000000 --- a/org.glite.lb.logger/src-nt/PlainConnection.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "PlainConnection.H" -#include "ThreadPool.H" - -#include -#include - -PlainConnection::~PlainConnection() -{ -} - - -Connection * -PlainConnection::Factory::accept(int fd) const -{ - int nfd; - - nfd = ::accept(fd, NULL, NULL); - return newConnection(nfd); -} - - -int -PlainConnection::read(char *buf, unsigned int len) -{ - int ret; - - ret = ::recv(fd, buf, len, MSG_NOSIGNAL); - return ret; -} - - -int -PlainConnection::write(char *buf, unsigned int len) -{ - int ret; - - ret = ::write(fd, buf, len); - return ret; -} diff --git a/org.glite.lb.logger/src-nt/PluginManager.H b/org.glite.lb.logger/src-nt/PluginManager.H deleted file mode 100644 index 1840536..0000000 --- a/org.glite.lb.logger/src-nt/PluginManager.H +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _PLUGIN_MANAGER_H -#define _PLUGIN_MANAGER_H - -#include -#include - -#include "Singleton.H" - -class PluginManager: public Singleton { - friend class Singleton; -public: - - // base class for plugins - class Plugin { - public: - const char *name; - - Plugin(const char *aname) : name(aname) { - PluginManager::instance()->registerPlugin(this, aname); - } - - virtual bool initialize() = 0; - virtual bool cleanup () = 0; - - virtual ~Plugin(); - }; - - // add plugin with given name to the list of registered plugins - void registerPlugin(Plugin *plugin, const char *name) { - pluginList.push_front(plugin); - } - - // remove plugin from the list - void removePlugin(); - - // initialize all plugins on list - void initialize() { - for(std::list::iterator i = pluginList.begin(); - i != pluginList.end(); - i++) { - (*i)->initialize(); - } - - } - - // cleanup all plugins on list - void cleanup() { - for(std::list::iterator i = pluginList.begin(); - i != pluginList.end(); - i++) { - (*i)->cleanup(); - } - - } - - -protected: - // default constructor - PluginManager() : pluginList() - {}; - -private: - // list of registered plugins - std::list pluginList; - -}; - - -#endif diff --git a/org.glite.lb.logger/src-nt/PluginManager.cpp b/org.glite.lb.logger/src-nt/PluginManager.cpp deleted file mode 100644 index 0200737..0000000 --- a/org.glite.lb.logger/src-nt/PluginManager.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "PluginManager.H" - -PluginManager::Plugin::~Plugin() { -} - - diff --git a/org.glite.lb.logger/src-nt/Properties.H b/org.glite.lb.logger/src-nt/Properties.H deleted file mode 100644 index 77d216d..0000000 --- a/org.glite.lb.logger/src-nt/Properties.H +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _PROPERTIES_H_ -#define _PROPERTIES_H_ - -#include -#include - -class Properties { -public: - - // default constructor - Properties() - : properties() - {} - - // accessors - std::string& getProperty(const std::string &key) - { return properties[key]; } - - void setProperty(const std::string &key, std::string &val) - { properties[key] = val; } - - // iterators - typedef std::map::iterator iterator; - - iterator begin() - { return properties.begin(); } - - iterator end() - { return properties.end(); } - - -private: - std::map properties; -}; - -#endif diff --git a/org.glite.lb.logger/src-nt/Singleton.H b/org.glite.lb.logger/src-nt/Singleton.H deleted file mode 100644 index ce03525..0000000 --- a/org.glite.lb.logger/src-nt/Singleton.H +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _SINGLETON_H -#define _SINGLETON_H - -#include - -#include "Exception.H" - -template -class Singleton { -public: - // obtain the singleton object - static T* instance() { - // XXX - is this really thread safe? - static pthread_mutex_t instance_lock = PTHREAD_MUTEX_INITIALIZER; - - pthread_mutex_lock(&instance_lock); - if(theInstance == NULL) { - theInstance = new T; - } - pthread_mutex_unlock(&instance_lock); - return(theInstance); - } - -protected: - // prevent other's from messing with the instance - Singleton() {} - Singleton(const Singleton &) {} - Singleton& operator=(const Singleton &) {} - ~Singleton() {} - -private: - static T *theInstance; -}; - -template -T *Singleton::theInstance = NULL; - - -#endif diff --git a/org.glite.lb.logger/src-nt/SocketInput.H b/org.glite.lb.logger/src-nt/SocketInput.H deleted file mode 100644 index 0021816..0000000 --- a/org.glite.lb.logger/src-nt/SocketInput.H +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _SOCKET_INPUT_H -#define _SOCKET_INPUT_H - -#include "ThreadPool.H" -#include "Connection.H" -#include "Transport.H" - -#include "sys/un.h" - - -class SocketInput: public ThreadPool::WorkDescription -{ -public: - SocketInput(const char *path, - const Connection::Factory *a_cfactory, - const Transport::Factory *a_tfactory); - virtual ~SocketInput(); - - // from WorkDescription - virtual void onReady(); - virtual void onTimeout(); - virtual void onError(); - -private: - static const int SOCK_QUEUE_MAX = 5; - - struct sockaddr_un saddr; - const Connection::Factory *cFactory; - const Transport::Factory *tFactory; -}; - -#endif diff --git a/org.glite.lb.logger/src-nt/SocketInput.cpp b/org.glite.lb.logger/src-nt/SocketInput.cpp deleted file mode 100644 index e553ec8..0000000 --- a/org.glite.lb.logger/src-nt/SocketInput.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include -#include -#include - -#include "ThreadPool.H" -#include "SocketInput.H" -#include "InputChannel.H" -#include "Exception.H" - - -// create unix domain socket for input -SocketInput::SocketInput(const char *path, - const Connection::Factory *a_cfactory, - const Transport::Factory *a_tfactory) - : ThreadPool::WorkDescription(0), - cFactory(a_cfactory), - tFactory(a_tfactory) -{ - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, path); - fd = socket(PF_UNIX, SOCK_STREAM, 0); - if(fd < 0) throw new Exception; - if(connect(fd, (struct sockaddr*)&saddr, sizeof(saddr.sun_path)) < 0) { - if(errno == ECONNREFUSED) { - unlink(saddr.sun_path); - } - } else { - // another instance running - // throw new Exception - } - if(bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) - throw new Exception; - if(listen(fd, SOCK_QUEUE_MAX) < 0) - throw new Exception; -} - - -// remove the socket -SocketInput::~SocketInput() -{ - if(fd >= 0) - close(fd); - unlink(saddr.sun_path); -} - - -void -SocketInput::onReady() -{ - Connection *conn = cFactory->accept(fd); - Transport *trans = tFactory->newTransport(); - InputChannel *channel = new InputChannel(conn, trans); - channel->start(); -} - - -void -SocketInput::onTimeout() -{ - // nothing special, just sit around -} - - -void -SocketInput::onError() -{ - // should report an error? -} diff --git a/org.glite.lb.logger/src-nt/ThreadPool.H b/org.glite.lb.logger/src-nt/ThreadPool.H deleted file mode 100644 index 1a3b43c..0000000 --- a/org.glite.lb.logger/src-nt/ThreadPool.H +++ /dev/null @@ -1,117 +0,0 @@ -#ifndef _THREAD_POOL_H -#define _THREAD_POOL_H - -#include -#include -#include - -#include - -#include "Singleton.H" - -class ThreadPool : public Singleton { - friend class Singleton; -public: - const static int default_timeout = 5; - - class WorkDescription { - friend class ThreadPool; - public: - int fd; - - WorkDescription(int afd) - : fd(afd), event(NONE) {} - - - virtual ~WorkDescription(); - - protected: - enum Event { NONE, READY, TIMEOUT, ERROR } event; - void doWork(); - - virtual void onReady() - {} - - virtual void onTimeout() - {} - - virtual void onError() - {} - }; - -public: - void startWorkers(unsigned int n); - void stopWorkers(); - - void postWork(WorkDescription *work_unit); - - void queueWorkAccept(WorkDescription *work_unit); - void queueWorkRead(WorkDescription *work_unit); - void queueWorkWrite(WorkDescription *work_unit); - void queueWorkTimeout(WorkDescription *work_unit); - void queueWorkConnect(WorkDescription *work_unit); - - void setWorkAccept(WorkDescription *work_unit); - void setWorkRead(WorkDescription *work_unit); - void setWorkWrite(WorkDescription *work_unit); - void setWorkTimeout(WorkDescription *work_unit); - - void run(); - void exit() - { f_exit = true; pthread_cond_signal(&wait_queue_cond_ready); } - -protected: - ThreadPool(); - ~ThreadPool(); - - WorkDescription *getWork(); - -private: - class WaitDesc { - public: - WorkDescription *wd; - short event; - bool f_permanent; - struct timeval timeout; - - WaitDesc(WorkDescription *w, short e, - bool permanent = false, int t = default_timeout) - : wd(w), event(e), f_permanent(permanent) { - timeout.tv_sec = t; - timeout.tv_usec = 0; - } - - int get_fd() { return wd->fd; }; - void adjustTimeout(const struct timeval &delta); - int timeoutExpired() { return((timeout.tv_sec < 0) || - (timeout.tv_sec == 0 && timeout.tv_usec == 0)); } - }; - -private: - bool f_exit; - int num_workers; - pthread_t *workers; - int work_count; - int wait_count; - int ufds_size; - std::list work_queue; - std::list wait_queue; - pthread_mutex_t work_queue_mutex; - pthread_cond_t work_queue_cond_ready; - pthread_cond_t work_queue_cond_full; - pthread_mutex_t wait_queue_mutex; - pthread_cond_t wait_queue_cond_ready; - struct pollfd *ufds; - int pd[2]; - struct timeval min_timeout; - - void prepareDescriptorArray(); - void removeWaitDesc(std::list::iterator &i); - void removeWorkDesc(); - void queueWork(WaitDesc *); - - static void *threadMain(void *); - static void threadCleanup(void *); -}; - -#endif diff --git a/org.glite.lb.logger/src-nt/ThreadPool.cpp b/org.glite.lb.logger/src-nt/ThreadPool.cpp deleted file mode 100644 index be4045c..0000000 --- a/org.glite.lb.logger/src-nt/ThreadPool.cpp +++ /dev/null @@ -1,413 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "ThreadPool.H" -#include "Exception.H" - - -static inline -void -tv_sub(struct timeval &a, const struct timeval &b) { - a.tv_usec -= b.tv_usec; - a.tv_sec -= b.tv_sec; - if (a.tv_usec < 0) { - a.tv_sec--; - a.tv_usec += 1000000; - } -} - - -static inline -int -tv_cmp(const struct timeval &a, const struct timeval &b) { - if(a.tv_sec < b.tv_sec) { - return -1; - } else if(a.tv_sec > b.tv_sec) { - return 1; - } else { - if (a.tv_usec < b.tv_usec) { - return -1; - } else if(a.tv_usec > b.tv_usec) { - return 1; - } else { - return 0; - } - } -} - - -inline -void -ThreadPool::WorkDescription::doWork() { - switch(event) { - case READY: - onReady(); - break; - case TIMEOUT: - onTimeout(); - break; - case ERROR: - onError(); - break; - default: - break; - } -} - - -inline -void -ThreadPool::WaitDesc::adjustTimeout(const struct timeval &delta) -{ - tv_sub(timeout, delta); -} - - -ThreadPool::WorkDescription::~WorkDescription() { -} - - -ThreadPool::ThreadPool() - : f_exit(false), work_count(0), wait_count(0), ufds_size(0), ufds(NULL) -{ - pthread_mutex_init(&wait_queue_mutex, NULL); - pthread_mutex_init(&work_queue_mutex, NULL); - pthread_cond_init(&work_queue_cond_ready, NULL); - pthread_cond_init(&work_queue_cond_full, NULL); - pthread_cond_init(&wait_queue_cond_ready, NULL); - pipe(pd); - ufds = static_cast(malloc(sizeof(struct pollfd))); - if(ufds == NULL) { - throw new Exception; - } - ufds->fd = pd[0]; - ufds->events = POLLIN; - ufds_size = 1; -} - - -ThreadPool::~ThreadPool() -{ - pthread_cond_destroy(&work_queue_cond_full); - pthread_cond_destroy(&work_queue_cond_ready); - pthread_cond_destroy(&wait_queue_cond_ready); - pthread_mutex_destroy(&work_queue_mutex); - pthread_mutex_destroy(&wait_queue_mutex); -} - - -void -ThreadPool::startWorkers(unsigned int n) -{ - workers = new pthread_t[n]; - - num_workers = n; - for(unsigned int i = 0; i < n; i++) { - // XXX check return - pthread_create(&workers[i], NULL, ThreadPool::threadMain, NULL); - } -} - - -void -ThreadPool::stopWorkers() -{ - for(int i = 0; i < num_workers; i++) { - pthread_cancel(workers[i]); - pthread_join(workers[i], NULL); - } - delete[] workers; -} - - -void -ThreadPool::postWork(WorkDescription *work_unit) -{ - E_ASSERT(pthread_mutex_lock(&work_queue_mutex) >= 0); - work_queue.push_back(work_unit); - work_count++; - E_ASSERT(pthread_cond_signal(&work_queue_cond_ready) >= 0); - E_ASSERT(pthread_mutex_unlock(&work_queue_mutex) >= 0); -} - - -inline -void -ThreadPool::queueWork(WaitDesc *wd) -{ - E_ASSERT(pthread_mutex_lock(&wait_queue_mutex) >= 0); - wait_queue.push_back(wd); - wait_count++; - E_ASSERT(pthread_cond_signal(&wait_queue_cond_ready) >= 0); - E_ASSERT(pthread_mutex_unlock(&wait_queue_mutex) >= 0); - if(write(pd[1], "1", 1) != 1) { - throw new Exception; - } -} - - -void -ThreadPool::queueWorkAccept(WorkDescription *work_unit) -{ - queueWork(new WaitDesc(work_unit, POLLIN)); -} - - -void -ThreadPool::queueWorkRead(WorkDescription *work_unit) -{ - queueWork(new WaitDesc(work_unit, POLLIN)); -} - - -void -ThreadPool::queueWorkWrite(WorkDescription *work_unit) -{ - queueWork(new WaitDesc(work_unit, POLLOUT)); -} - - -void -ThreadPool::queueWorkTimeout(WorkDescription *work_unit) -{ - queueWork(new WaitDesc(work_unit, 0)); -} - - -void -ThreadPool::queueWorkConnect(WorkDescription *work_unit) -{ - queueWork(new WaitDesc(work_unit, POLLIN)); -} - - -void -ThreadPool::setWorkAccept(WorkDescription *work_unit) -{ - queueWork(new WaitDesc(work_unit, POLLIN, true)); -} - - -void -ThreadPool::setWorkRead(WorkDescription *work_unit) -{ - queueWork(new WaitDesc(work_unit, POLLIN, true)); -} - - -void -ThreadPool::setWorkWrite(WorkDescription *work_unit) -{ - queueWork(new WaitDesc(work_unit, POLLOUT, true)); -} - - -void -ThreadPool::setWorkTimeout(WorkDescription *work_unit) -{ - queueWork(new WaitDesc(work_unit, 0, true)); -} - - -ThreadPool::WorkDescription * -ThreadPool::getWork() -{ - WorkDescription *work_unit = NULL; - struct timespec timeout; - - E_ASSERT(pthread_mutex_lock(&work_queue_mutex) >= 0); - if(work_count == 0) { - timeout.tv_sec = 1; - timeout.tv_nsec = 0; -// pthread_cond_timedwait(&work_queue_cond_ready, &work_queue_mutex, &timeout); - E_ASSERT(pthread_cond_wait(&work_queue_cond_ready, &work_queue_mutex) == 0); - } - if(work_count > 0) { - work_count--; - work_unit = work_queue.front(); - work_queue.pop_front(); - } - E_ASSERT(pthread_mutex_unlock(&work_queue_mutex) >= 0); - return work_unit; -} - -void -ThreadPool::threadCleanup(void *data) -{ - ThreadPool *pool = ThreadPool::instance(); - - E_ASSERT(pthread_mutex_unlock(&(pool->work_queue_mutex)) >= 0); -} - - -void * -ThreadPool::threadMain(void *data) -{ - ThreadPool *pool = ThreadPool::instance(); - WorkDescription *work_unit; - - pthread_cleanup_push(ThreadPool::threadCleanup, NULL); - while(true) { - - work_unit = pool->getWork(); - if(work_unit) { - // something to work on - work_unit->doWork(); - } else { - // timed out waiting for work - } - } - pthread_cleanup_pop(1); -} - - -void -ThreadPool::removeWaitDesc(std::list::iterator &i) -{ - std::list::iterator j = i; - - // actually this is safe even for the first element - E_ASSERT(pthread_mutex_lock(&wait_queue_mutex) >= 0); - j--; - wait_queue.erase(i); - wait_count--; - i = j; - E_ASSERT(pthread_mutex_unlock(&wait_queue_mutex) >= 0); -} - - -void -ThreadPool::prepareDescriptorArray() -{ - std::list::iterator theIterator; - struct pollfd *p; - - E_ASSERT(pthread_mutex_lock(&wait_queue_mutex) >= 0); - if(wait_count == 0) { - E_ASSERT(pthread_cond_wait(&wait_queue_cond_ready, &wait_queue_mutex) != 0); - } - if(wait_count == 0) { - E_ASSERT(pthread_mutex_unlock(&wait_queue_mutex) >= 0); - return; - } - if(ufds_size != wait_count + 1) { - ufds = static_cast(realloc(ufds, (1 + wait_count) * sizeof(struct pollfd))); - if(ufds == NULL) { - throw new Exception(); - } - ufds_size = wait_count + 1; - } - min_timeout.tv_sec = default_timeout; - min_timeout.tv_usec = 0; - for(theIterator = wait_queue.begin(), p = ufds + 1; - theIterator != wait_queue.end(); - theIterator++, p++) { - WaitDesc *w = *theIterator; - p->fd = w->get_fd(); - p->events = w->event; - if(tv_cmp(min_timeout, w->timeout) > 0) { - min_timeout = w->timeout; - } - } - E_ASSERT(pthread_mutex_unlock(&wait_queue_mutex) >= 0); -} - - -void -ThreadPool::run() -{ - f_exit = false; - while(!f_exit) { - struct pollfd *p; - struct timeval before, after; - int ret; - - // may block waiting for new work - prepareDescriptorArray(); - - gettimeofday(&before, NULL); - ret = poll(ufds, ufds_size, 1000*min_timeout.tv_sec + min_timeout.tv_usec/1000); - gettimeofday(&after, NULL); - tv_sub(after, before); - - if((ret >= 0) || // ready or timeout - ((ret < 0) && (errno == EINTR))) { // interrupted - std::list::iterator i; - WaitDesc *w; - - // handle the pipe - if(ufds->revents & POLLIN) { - char discard[1]; - read(ufds->fd, discard, 1); - } - - // at least we have to adjust timeouts - E_ASSERT(pthread_mutex_lock(&wait_queue_mutex) >= 0); - i = wait_queue.begin(); - E_ASSERT(pthread_mutex_unlock(&wait_queue_mutex) >= 0); - // the wait queue mutex is unlocked inside the loop - // to allow handlers to add queue new - // WorkDescriptions - these are added at the - // end of the list so we should be safe - for(p = ufds + 1; p - ufds < ufds_size; p++) { - enum WorkDescription::Event event = WorkDescription::NONE; - - w = *i; - // check for consistency - if(p->fd != w->get_fd()) { - // mismatch, what shall we do? - throw new Exception; - } - - // subtract the time passed from timeout - w->adjustTimeout(after); - - // see what happened - if(ret <= 0) { - // timeout or interrupted - if(w->timeoutExpired()) { - event = WorkDescription::TIMEOUT; - } - } else { - // ready or error - if(p->revents & POLLERR) { - event = WorkDescription::ERROR; - } else if(p->revents & w->event) { - event = WorkDescription::READY; - } else if(w->timeoutExpired()) { - event = WorkDescription::TIMEOUT; - } - } - if(event != WorkDescription::NONE) { - WorkDescription *wd; - wd = w->wd; - wd->event = event; - if(!w->f_permanent) { - postWork(wd); - removeWaitDesc(i); - delete w; - } else { - w->wd->doWork(); - // we have to reset the timeout - w->timeout.tv_sec = default_timeout; - w->timeout.tv_usec = 0; - } - } - E_ASSERT(pthread_mutex_lock(&wait_queue_mutex) >= 0); - i++; - E_ASSERT(pthread_mutex_unlock(&wait_queue_mutex) >= 0); - } - } else { - // some nasty error - throw new Exception; - } - } -} - diff --git a/org.glite.lb.logger/src-nt/Transport.H b/org.glite.lb.logger/src-nt/Transport.H deleted file mode 100644 index 1b6516d..0000000 --- a/org.glite.lb.logger/src-nt/Transport.H +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef _TRANSPORT_H -#define _TRANSPORT_H - -#include "Connection.H" -#include "Message.H" - -// Transport implements transport protocol -// - reads/writes messages using Connection interface -// - -class Transport { -public: - - // - class Factory { - public: - virtual Transport *newTransport() const = 0; - - virtual ~Factory() - {} - }; - - // - Transport() - {} - - virtual ~Transport(); - - // - virtual int receive(Connection *conn, Message* &msg) = 0; - virtual int send(Connection *conn, Message* msg) = 0; - virtual void reset() = 0; -}; -#endif diff --git a/org.glite.lb.logger/src-nt/Transport.cpp b/org.glite.lb.logger/src-nt/Transport.cpp deleted file mode 100644 index 2544997..0000000 --- a/org.glite.lb.logger/src-nt/Transport.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "Transport.H" - -Transport::~Transport() -{ -} diff --git a/org.glite.lb.logger/src-nt/main.cpp b/org.glite.lb.logger/src-nt/main.cpp deleted file mode 100644 index b2fed11..0000000 --- a/org.glite.lb.logger/src-nt/main.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "PluginManager.H" -#include "ThreadPool.H" -#include "SocketInput.H" -#include "PlainConnection.H" -#include "HTTPTransport.H" -#include "EventManager.H" - -const int num_threads = 2; -const char *sock_path = "/tmp/il_sock"; - -EventManager theEventManager(); - -int main(int argc, char *argv[]) -{ - SocketInput *input; - - // initialize plugins - PluginManager::instance()->initialize(); - - // create unix socket with plain IO and HTTP transport - input = new SocketInput(sock_path, - PlainConnection::Factory::instance(), - HTTPTransport::Factory::instance()); - // and add the socket to pool - ThreadPool::instance()->setWorkAccept(input); - - // start worker threads - ThreadPool::instance()->startWorkers(num_threads); - - // run the main loop - ThreadPool::instance()->run(); - - // cleanup & exit - delete input; - PluginManager::instance()->cleanup(); - - return 0; -} diff --git a/org.glite.lb.logger/src-nt/test/EventManagerTest.cpp b/org.glite.lb.logger/src-nt/test/EventManagerTest.cpp deleted file mode 100644 index 2d55586..0000000 --- a/org.glite.lb.logger/src-nt/test/EventManagerTest.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include - -#include "EventManager.H" - -class EventA : public Event { -}; - -class EventB : public Event { -}; - -class EventAA : public EventA { -}; - - -class EventManagerTest: public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(EventManagerTest); - CPPUNIT_TEST(handleEventTest); - CPPUNIT_TEST_SUITE_END(); -public: - - void setUp() { - handled = false; - manager.registerHandler(this); - } - - void tearDown() { - } - - void handleEventTest() { - Event *e = new EventAA(); - manager.postEvent(e); - CPPUNIT_ASSERT(handled); - } - - int handleEvent(EventA* &e) { - handled = true; - return 0; - } - -private: - EventManager manager; - bool handled; -}; - -CPPUNIT_TEST_SUITE_REGISTRATION( EventManagerTest ); diff --git a/org.glite.lb.logger/src-nt/test/PluginManagerTest.cpp b/org.glite.lb.logger/src-nt/test/PluginManagerTest.cpp deleted file mode 100644 index 629bbcb..0000000 --- a/org.glite.lb.logger/src-nt/test/PluginManagerTest.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include - -#include "PluginManager.H" - -class TestPlugin : public PluginManager::Plugin { -public: - bool inited, cleaned; - - virtual bool initialize() { - inited = true; - } - - virtual bool cleanup() { - cleaned = true; - } - - static TestPlugin theTestPlugin; - -private: - TestPlugin() : PluginManager::Plugin("test plugin"), - inited(false), - cleaned(false) - {} - - - -}; - - -class PluginManagerTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(PluginManagerTest); - CPPUNIT_TEST(testInit); - CPPUNIT_TEST(testClean); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp() { - } - - void tearDown() { - } - - void testInit() { - PluginManager::instance()->initialize(); - CPPUNIT_ASSERT(TestPlugin::theTestPlugin.inited); - } - - void testClean() { - PluginManager::instance()->cleanup(); - CPPUNIT_ASSERT(TestPlugin::theTestPlugin.cleaned); - } -}; - - -TestPlugin TestPlugin::theTestPlugin; - -CPPUNIT_TEST_SUITE_REGISTRATION( PluginManagerTest ); diff --git a/org.glite.lb.logger/src-nt/test/SingletonTest.cpp b/org.glite.lb.logger/src-nt/test/SingletonTest.cpp deleted file mode 100644 index 734db17..0000000 --- a/org.glite.lb.logger/src-nt/test/SingletonTest.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include - -#include "Singleton.H" - -class one : public Singleton { - friend class Singleton; -}; - -class two : public Singleton { - friend class Singleton; -}; - -class SingletonTest: public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SingletonTest); - CPPUNIT_TEST(getInstance); - CPPUNIT_TEST(pair); - CPPUNIT_TEST(noCreate); - CPPUNIT_TEST_SUITE_END(); -public: - - void setUp() { - } - - void tearDown() { - } - - void getInstance() { - one *p; - one *q; - - p = one::instance(); - q = one::instance(); - CPPUNIT_ASSERT(p != NULL); - CPPUNIT_ASSERT(q != NULL); - CPPUNIT_ASSERT(p == q); - } - - void pair() { - one *p; - two *q; - - p = one::instance(); - q = two::instance(); - CPPUNIT_ASSERT(p != NULL); - CPPUNIT_ASSERT(q != NULL); - CPPUNIT_ASSERT((void*)p != (void*)q); - } - - void noCreate() { - one *p = new one; - - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION( SingletonTest ); diff --git a/org.glite.lb.logger/src-nt/test/ThreadPoolTest.cpp b/org.glite.lb.logger/src-nt/test/ThreadPoolTest.cpp deleted file mode 100644 index 4a205ec..0000000 --- a/org.glite.lb.logger/src-nt/test/ThreadPoolTest.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -#include "ThreadPool.H" - -class TestWork : public ThreadPool::WorkDescription { -public: - int done; - - TestWork(int fd) : ThreadPool::WorkDescription(fd), done(0) {}; - - virtual void onReady() { - done++; - } - -}; - - -class TestConsumer : public ThreadPool::WorkDescription { -public: - char buf[2]; - - TestConsumer(int fd) : ThreadPool::WorkDescription(fd) {}; - - virtual void onReady() { - int r; - - r = read(fd, buf, 1); - buf[1] = 0; - ThreadPool::instance()->exit(); - } - - virtual void onTimeout() { - } - -}; - - -class TestProducer : public ThreadPool::WorkDescription { -public: - TestProducer(int fd) : ThreadPool::WorkDescription(fd) {}; - - virtual void onReady() { - write(fd, "a", 1); - } - - virtual void onTimeout() { - } - -}; - - -class TestSocketRead: public ThreadPool::WorkDescription { -public: - char buffer[10]; - - TestSocketRead(int fd) : ThreadPool::WorkDescription(fd) { - } - - virtual void onReady() { - - int len = recv(fd, buffer, sizeof(buffer), MSG_NOSIGNAL); - ThreadPool::instance()->exit(); - } - - virtual void onError() { - } -}; - - -class TestSocketWrite: public ThreadPool::WorkDescription { -public: - static char buffer[]; - - TestSocketWrite(const char *name) - : ThreadPool::WorkDescription(0) { - struct sockaddr_un saddr; - int ret; - fd = socket(PF_UNIX, SOCK_STREAM, 0); - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, name); - if((ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr))) < 0) { - } - } - - virtual void onReady() { - int ret; - - ret = send(fd, buffer, strlen(buffer)+1, MSG_NOSIGNAL); - close(fd); - } - -}; - -char TestSocketWrite::buffer[] = "ahoj"; - -class TestSocketAccept : public ThreadPool::WorkDescription { -public: - TestSocketRead *reader; - - TestSocketAccept(const char *name) - : ThreadPool::WorkDescription(0) { - struct sockaddr_un saddr; - - fd = socket(PF_UNIX, SOCK_STREAM, 0); - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, name); - bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)); - listen(fd, 1); - } - - virtual void onReady() { - int nfd; - - nfd = accept(fd, NULL, NULL); - if(nfd < 0) { - } else { - ThreadPool *pool = ThreadPool::instance(); - - reader = new TestSocketRead(nfd); - pool->queueWorkRead(reader); - } - } -}; - - -class ThreadPoolTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( ThreadPoolTest ); - CPPUNIT_TEST( testWorkQueue ); - CPPUNIT_TEST( testPoll ); - CPPUNIT_TEST( testAccept ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp() { - pool = ThreadPool::instance(); - unlink("/tmp/smazat.sock"); - pool->startWorkers(2); - } - - void tearDown() { - pool->stopWorkers(); - } - - void testWorkQueue() { - TestWork *work_unit = new TestWork(0); - pool->postWork(work_unit); - } - - void testPoll() { - int fd[2]; - TestProducer *p = new TestProducer(0); - TestConsumer *c = new TestConsumer(0); - - pipe(fd); - c->fd = fd[0]; - p->fd = fd[1]; - pool->queueWorkRead(c); - pool->queueWorkWrite(p); - pool->run(); - CPPUNIT_ASSERT(c->buf[0] == 'a'); - CPPUNIT_ASSERT(c->buf[1] == 0); - } - - void testAccept() { - TestSocketAccept *consumer = new TestSocketAccept("/tmp/smazat.sock"); - TestSocketWrite *producer; - - pool->queueWorkAccept(consumer); - producer = new TestSocketWrite("/tmp/smazat.sock"); - ThreadPool::instance()->queueWorkWrite(producer); - pool->run(); - CPPUNIT_ASSERT(consumer->reader != NULL); - CPPUNIT_ASSERT(strcmp(consumer->reader->buffer, TestSocketWrite::buffer) == 0); - } - -private: - ThreadPool *pool; -}; - - -CPPUNIT_TEST_SUITE_REGISTRATION( ThreadPoolTest ); diff --git a/org.glite.lb.logger/src-nt/test/test_main.cpp b/org.glite.lb.logger/src-nt/test/test_main.cpp deleted file mode 100644 index 1ae6d6a..0000000 --- a/org.glite.lb.logger/src-nt/test/test_main.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -#include -#include -//#include -#include -#include -#include - -int main (int argc,const char *argv[]) -{ - CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - -// assert(argc == 2); -// std::ofstream xml(argv[1]); - - CppUnit::TestResult controller; - CppUnit::TestResultCollector result; - controller.addListener( &result ); - - CppUnit::TestRunner runner; - runner.addTest(suite); - runner.run(controller); - -// CppUnit::XmlOutputter xout( &result, xml ); - CppUnit::CompilerOutputter tout( &result, std::cout); -// xout.write(); - tout.write(); - - return result.wasSuccessful() ? 0 : 1 ; -} diff --git a/org.glite.lb.logger/src/event_queue.c b/org.glite.lb.logger/src/event_queue.c deleted file mode 100644 index 9ce47f6..0000000 --- a/org.glite.lb.logger/src/event_queue.c +++ /dev/null @@ -1,325 +0,0 @@ -#ident "$Header$" - -/* - * - general queue handling routines (insert, get) - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" - -#include "interlogd.h" - -struct event_queue_msg { - struct server_msg *msg; - struct event_queue_msg *prev; -}; - -struct event_queue * -event_queue_create(char *server_name) -{ - struct event_queue *eq; - char *p; - - p = strchr(server_name, ':'); - - if(p) - *p++ = 0; - - if((eq = malloc(sizeof(*eq))) == NULL) { - set_error(IL_NOMEM, ENOMEM, "event_queue_create: error allocating event queue"); - return(NULL); - } - - memset(eq, 0, sizeof(*eq)); - - eq->dest_name = strdup(server_name); - - if(p) - *(p-1) = ':'; - -#if defined(IL_NOTIFICATIONS) || defined(IL_WS) - eq->dest_port = atoi(p); -#else - eq->dest_port = p ? atoi(p)+1 : GLITE_JOBID_DEFAULT_PORT+1; -#endif - /* create all necessary locks */ - if(pthread_rwlock_init(&eq->update_lock, NULL)) { - set_error(IL_SYS, errno, "event_queue_create: error creating update lock"); - free(eq); - return(NULL); - } - if(pthread_mutex_init(&eq->cond_lock, NULL)) { - set_error(IL_SYS, errno, "event_queue_create: error creating cond mutex"); - free(eq); - return(NULL); - } - if(pthread_cond_init(&eq->ready_cond, NULL)) { - set_error(IL_SYS, errno, "event_queue_create: error creating cond variable"); - free(eq); - return(NULL); - } - -#if defined(INTERLOGD_HANDLE_CMD) && defined(INTERLOGD_FLUSH) - if(pthread_cond_init(&eq->flush_cond, NULL)) { - set_error(IL_SYS, errno, "event_queue_create: error creating cond variable"); - free(eq); - return(NULL); - } -#endif - - return(eq); -} - - -int -event_queue_free(struct event_queue *eq) -{ - assert(eq != NULL); - - if(!event_queue_empty(eq)) - return(-1); - - if(eq->thread_id) - pthread_cancel(eq->thread_id); - - - pthread_rwlock_destroy(&eq->update_lock); - pthread_mutex_destroy(&eq->cond_lock); - pthread_cond_destroy(&eq->ready_cond); -#if defined(INTERLOGD_HANDLE_CMD) && defined(INTERLOGD_FLUSH) - pthread_cond_destroy(&eq->flush_cond); -#endif - free(eq); - - return(0); -} - - -int -event_queue_empty(struct event_queue *eq) -{ - int ret; - - assert(eq != NULL); - - event_queue_lock_ro(eq); - ret = (eq->head == NULL); - event_queue_unlock(eq); - - return(ret); -} - - -int -event_queue_insert(struct event_queue *eq, struct server_msg *msg) -{ - struct event_queue_msg *el; -#if defined(INTERLOGD_EMS) - struct event_queue_msg *tail; -#endif - - assert(eq != NULL); - - if((el = malloc(sizeof(*el))) == NULL) - return(set_error(IL_NOMEM, ENOMEM, "event_queue_insert: not enough room for queue element")); - - el->msg = server_msg_copy(msg); - if(el->msg == NULL) { - free(el); - return(-1); - }; - - /* this is critical section */ - event_queue_lock(eq); -#if defined(INTERLOGD_EMS) - if(server_msg_is_priority(msg)) { - /* priority messages go first */ - tail = eq->tail_ems; - if(tail) { - el->prev = tail->prev; - tail->prev = el; - if (tail == eq->tail) - eq->tail = el; - } else { - el->prev = eq->head; - eq->head = el; - if(eq->tail == NULL) - eq->tail = el; - } - eq->tail_ems = el; - } else -#endif - { - /* normal messages */ - if(eq->tail) - eq->tail->prev = el; - else - eq->head = el; - eq->tail = el; - el->prev = NULL; - } -#if defined(INTERLOGD_EMS) - /* if we are inserting message between mark_prev and mark_this, - we have to adjust mark_prev accordingly */ - if(eq->mark_this && (el->prev == eq->mark_this)) - eq->mark_prev = el; -#endif - - if(++eq->cur_len > eq->max_len) - eq->max_len = eq->cur_len; - - event_queue_unlock(eq); - /* end of critical section */ - - return(0); -} - - -int -event_queue_get(struct event_queue *eq, struct server_msg **msg) -{ - struct event_queue_msg *el; - - assert(eq != NULL); - assert(msg != NULL); - - event_queue_lock(eq); - el = eq->head; -#if defined(INTERLOGD_EMS) - /* this message is marked for removal, it is first on the queue */ - eq->mark_this = el; - eq->mark_prev = NULL; -#endif - event_queue_unlock(eq); - - if(el == NULL) - return(-1); - - *msg = el->msg; - - return(0); -} - - -int -event_queue_remove(struct event_queue *eq) -{ - struct event_queue_msg *el; -#if defined(INTERLOGD_EMS) - struct event_queue_msg *prev; -#endif - - assert(eq != NULL); - - /* this is critical section */ - event_queue_lock(eq); -#if defined(INTERLOGD_EMS) - el = eq->mark_this; - prev = eq->mark_prev; - - if(el == NULL) { - event_queue_unlock(eq); - return(-1); - } - - if(prev == NULL) { - /* removing from head of the queue */ - eq->head = el->prev; - } else { - /* removing from middle of the queue */ - prev->prev = el->prev; - } - if(el == eq->tail) { - /* we are removing the last message */ - eq->tail = prev; - } - if(el == eq->tail_ems) { - /* we are removing last priority message */ - eq->tail_ems = prev; - } - - eq->mark_this = NULL; - eq->mark_prev = NULL; -#else - el = eq->head; - if(el == NULL) { - event_queue_unlock(eq); - return(-1); - } - eq->head = el->prev; - if(el == eq->tail) { - eq->tail = NULL; - } -#endif - if(--eq->cur_len == 0) - eq->times_empty++; - - event_queue_unlock(eq); - /* end of critical section */ - - server_msg_free(el->msg); - free(el); - - return(0); -} - -int -event_queue_move_events(struct event_queue *eq_s, - struct event_queue *eq_d, - int (*cmp_func)(struct server_msg *, void *), - void *data) -{ - struct event_queue_msg *p, **source_prev, **dest_tail; - - assert(eq_s != NULL); - - event_queue_lock(eq_s); - if(eq_d) { - event_queue_lock(eq_d); - /* dest tail is set to point to the last (NULL) pointer in the list */ - dest_tail = (eq_d->head == NULL) ? &(eq_d->head) : &(eq_d->tail->prev); - } - source_prev = &(eq_s->head); - p = *source_prev; - eq_s->tail = NULL; - while(p) { - if((*cmp_func)(p->msg, data)) { - il_log(LOG_DEBUG, " moving event at offset %d(%d) from %s:%d to %s:%d\n", - p->msg->offset, p->msg->generation, eq_s->dest_name, eq_s->dest_port, - eq_d ? eq_d->dest_name : "trash", eq_d ? eq_d->dest_port : -1); - /* il_log(LOG_DEBUG, " current: %x, next: %x\n", p, p->prev); */ - /* remove the message from the source list */ - *source_prev = p->prev; - if(eq_d) { - /* append the message at the end of destination list */ - p->prev = NULL; - *dest_tail = p; - dest_tail = &(p->prev); - eq_d->tail = p; - } else { - /* signal that the message was 'delivered' */ - event_store_commit(p->msg->es, p->msg->ev_len, queue_list_is_log(eq_s), - p->msg->generation); - /* free the message */ - server_msg_free(p->msg); - free(p); - } - } else { - /* message stays */ - source_prev = &(p->prev); - eq_s->tail = p; - } - p = *source_prev; - } - if(eq_d) event_queue_unlock(eq_d); - event_queue_unlock(eq_s); - return(0); -} - diff --git a/org.glite.lb.logger/src/event_store.c b/org.glite.lb.logger/src/event_store.c deleted file mode 100644 index e584e89..0000000 --- a/org.glite.lb.logger/src/event_store.c +++ /dev/null @@ -1,1532 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#include - -#include "glite/lb/events_parse.h" - -#include "interlogd.h" - -#ifdef __GNUC__ -#define UNUSED_VAR __attribute__((unused)) -#else -#define UNUSED_VAR -#endif - -static char *file_prefix = NULL; - - -struct event_store_list { - struct event_store *es; - struct event_store_list *next; // LL of event_store's - struct event_store_list *jobid_next; /* double LL of rotated stores - forward */ - struct event_store_list *jobid_prev; /* double LL of rotated stores - backward */ -}; - - -static struct event_store_list *store_list; -static pthread_rwlock_t store_list_lock = PTHREAD_RWLOCK_INITIALIZER; - - -/* ---------------- - * helper functions - * ---------------- - */ -static -char * -astrcat(const char *s1, const char *s2) -{ - char *s = malloc(strlen(s1) + strlen(s2) + 1); - if(s == NULL) - return NULL; - *s = 0; - strcat(s, s1); - strcat(s, s2); - return s; -} - - -static -char * -jobid2eventfile(IL_EVENT_ID_T job_id) -{ - char *buffer; - char *hash; - - if(job_id) { - hash = IL_EVENT_GET_UNIQUE(job_id); - asprintf(&buffer, "%s.%s", file_prefix, hash); - free(hash); - } else - asprintf(&buffer, "%s.default", file_prefix); - - return(buffer); -} - - -static -char * -jobid2controlfile(IL_EVENT_ID_T job_id) -{ - char buffer[256]; - char *hash; - - if(job_id) { - hash = IL_EVENT_GET_UNIQUE(job_id); - snprintf(buffer, 256, "%s.%s.ctl", file_prefix, hash); - free(hash); - } else - snprintf(buffer, 256, "%s.default.ctl", file_prefix); - - return(strdup(buffer)); -} - -static -long long -fname2index(const char *filename) -{ - char *p = rindex(filename, '.'); - char *s; - long long ret; - - if(p == NULL) - return 0; - - for(s = p+1; *s != 0; s++) { - if(*s < '0' || *s > '9') { - return 0; - } - } - - sscanf(p+1,"%lld",&ret); - return ret+1; -} - - -static -char * -read_event_string(FILE *file) -{ - char *buffer, *p, *n; - int len, c; - - buffer=malloc(1024); - if(buffer == NULL) { - set_error(IL_NOMEM, ENOMEM, "read_event_string: no room for event"); - return(NULL); - } - p = buffer; - len = 1024; - - while((c=fgetc(file)) != EOF) { - - /* we have to have free room for one byte */ - /* if(len - (p - buffer) < 1) */ - if(p - buffer >= len) { - n = realloc(buffer, len + 8192); - if(n == NULL) { - free(buffer); - set_error(IL_NOMEM, ENOMEM, "read_event_string: no room for event"); - return(NULL); - } - p = p - buffer + n; - buffer = n; - len += 8192; - } - - if(c == EVENT_SEPARATOR) { - *p++ = 0; - break; - } else - *p++ = (char) c; - } - - if(c != EVENT_SEPARATOR) { - free(buffer); - return(NULL); - } - - return(buffer); -} - - - -/* ------------------------------ - * event_store 'member' functions - * ------------------------------ - */ -static -int -event_store_free(struct event_store *es) -{ - assert(es != NULL); - - if(es->job_id_s) free(es->job_id_s); - if(es->event_file_name) free(es->event_file_name); - if(es->control_file_name) free(es->control_file_name); - pthread_rwlock_destroy(&es->use_lock); - pthread_rwlock_destroy(&es->commit_lock); - pthread_rwlock_destroy(&es->offset_lock); - free(es); - - return(0); -} - - -static -struct event_store * -event_store_create(char *job_id_s, const char *filename) -{ - struct event_store *es; - IL_EVENT_ID_T job_id; - - es = malloc(sizeof(*es)); - if(es == NULL) { - set_error(IL_NOMEM, ENOMEM, "event_store_create: error allocating room for structure"); - return(NULL); - } - - memset(es, 0, sizeof(*es)); - - job_id = NULL; - if(strcmp(job_id_s, "default") && IL_EVENT_ID_PARSE(job_id_s, &job_id)) { - set_error(IL_LBAPI, EDG_WLL_ERROR_PARSE_BROKEN_ULM, "event_store_create: error parsing id"); - free(es); - return(NULL); - } - - es->job_id_s = strdup(job_id_s); - es->event_file_name = filename ? strdup(filename) : jobid2eventfile(job_id); - es->control_file_name = filename ? astrcat(filename, ".ctl") : jobid2controlfile(job_id); - es->rotate_index = filename ? fname2index(filename) : 0; - IL_EVENT_ID_FREE(job_id); - - il_log(LOG_DEBUG, " creating event store for id %s, filename %s, rotate index %lld\n", - job_id_s, es->event_file_name, es->rotate_index); - - if(pthread_rwlock_init(&es->commit_lock, NULL)) - abort(); - if(pthread_rwlock_init(&es->offset_lock, NULL)) - abort(); - if(pthread_rwlock_init(&es->use_lock, NULL)) - abort(); - - return(es); -} - - -static -int -event_store_lock_ro(struct event_store *es) -{ - assert(es != NULL); - - if(pthread_rwlock_rdlock(&es->commit_lock)) - abort(); - - return(0); -} - - -static -int -event_store_lock(struct event_store *es) -{ - assert(es != NULL); - - if(pthread_rwlock_wrlock(&es->commit_lock)) - abort(); - - return(0); -} - - -static -int -event_store_unlock(struct event_store *es) -{ - assert(es != NULL); - - if(pthread_rwlock_unlock(&es->commit_lock)) - abort(); - return(0); -} - - -static -int -event_store_read_ctl(struct event_store *es) -{ - FILE *ctl_file; - - assert(es != NULL); - - event_store_lock(es); - if((ctl_file = fopen(es->control_file_name, "r")) == NULL) { - /* no control file, new event file */ - es->last_committed_ls = 0; - es->last_committed_bs = 0; - } else { - /* read last seen and last committed counts */ - fscanf(ctl_file, "%*s\n%ld\n%ld\n", - &es->last_committed_ls, - &es->last_committed_bs); - fclose(ctl_file); - } - event_store_unlock(es); - - return(0); -} - - -static -int -event_store_write_ctl(struct event_store *es) -{ - FILE *ctl; - - assert(es != NULL); - - ctl = fopen(es->control_file_name, "w"); - if(ctl == NULL) { - set_error(IL_SYS, errno, "event_store_write_ctl: error opening control file"); - return(-1); - } - - if(fprintf(ctl, "%s\n%ld\n%ld\n", - es->job_id_s, - es->last_committed_ls, - es->last_committed_bs) < 0) { - set_error(IL_SYS, errno, "event_store_write_ctl: error writing control record"); - return(-1); - } - - if(fclose(ctl) < 0) { - set_error(IL_SYS, errno, "event_store_write_ctl: error closing control file"); - return(-1); - } - - return(0); -} - - -/* - * event_store_qurantine() - * - rename damaged event store file - * - essentially does the same actions as cleanup, but the event store - * does not have to be empty - * returns 0 on success, -1 on error - */ -static -int -event_store_quarantine(struct event_store *es) -{ - // TODO enable cleanup of quarantined event_store struct - // TODO handle file rotation - - int num; - char newname[MAXPATHLEN+1]; - - /* find available quarantine name */ - /* we give it at most 1024 tries */ - for(num = 0; num < 1024; num++) { - struct stat st; - - snprintf(newname, MAXPATHLEN, "%s.quarantine.%d", es->event_file_name, num); - newname[MAXPATHLEN] = 0; - if(stat(newname, &st) < 0) { - if(errno == ENOENT) { - /* file not found */ - break; - } else { - /* some other error with name, probably permanent */ - set_error(IL_SYS, errno, "event_store_qurantine: error looking for quarantine filename"); - return(-1); - - } - } else { - /* the filename is used already */ - } - } - if(num >= 1024) { - /* new name not found */ - /* XXX - is there more suitable error? */ - set_error(IL_SYS, ENOSPC, "event_store_quarantine: exhausted number of retries looking for quarantine filename"); - return(-1); - } - - /* actually rename the file */ - il_log(LOG_DEBUG, " renaming damaged event file from %s to %s\n", - es->event_file_name, newname); - if(rename(es->event_file_name, newname) < 0) { - set_error(IL_SYS, errno, "event_store_quarantine: error renaming event file"); - return(-1); - } - - /* clear the counters */ - es->last_committed_ls = 0; - es->last_committed_bs = 0; - es->offset = 0; - - /* increase cleanup count, this will invalidate all commits from previous generation */ - es->generation++; - - return(0); -} - - -/* - * event_store_rotate_file() - * returns 0 on success, -1 on error - */ -static -int -event_store_rotate_file(struct event_store *es) -{ - int num; - time_t timestamp = time(NULL); - char newname[MAXPATHLEN+1]; - - /* do not rotate already rotated files */ - if(es->rotate_index > 0) - return 0; - - /* find available name */ - /* we give it at most 256 tries */ - for(num = 0; num < 256; num++) { - struct stat st; - - snprintf(newname, MAXPATHLEN, "%s.%d%03d", es->event_file_name, timestamp, num); - newname[MAXPATHLEN] = 0; - if(stat(newname, &st) < 0) { - if(errno == ENOENT) { - /* file not found */ - break; - } else { - /* some other error with name, probably permanent */ - set_error(IL_SYS, errno, "event_store_rotate_file: error looking for available filename"); - return(-1); - - } - } else { - /* the filename is used already */ - } - } - if(num >= 1024) { - /* new name not found */ - /* XXX - is there more suitable error? */ - set_error(IL_SYS, ENOSPC, "event_store_quarantine: exhausted number of retries looking for quarantine filename"); - return(-1); - } - - /* actually rename the file */ - il_log(LOG_DEBUG, " renaming too large event file from %s to %s\n", - es->event_file_name, newname); - if(rename(es->event_file_name, newname) < 0) { - set_error(IL_SYS, errno, "event_store_rotate_file: error renaming event file"); - return(-1); - } - - /* change names in event_store */ - es->event_file_name = strdup(newname); - es->control_file_name = astrcat(newname, ".ctl"); - es->rotate_index = 1000*timestamp + num + 1; - - return(0); -} - - -/* - * event_store_recover_jobid() - * - recover all event stores for given jobid - */ -static -int -event_store_recover_jobid(struct event_store *es) -{ - // es is locked for use already - struct event_store_list *p = es->le; - - do { - event_store_recover(p->es); - if(p != es->le ) { - event_store_release(p->es); - } - - if(pthread_rwlock_rdlock(&store_list_lock)) - abort(); - p = p->jobid_next; - if(p != es->le) { - if(pthread_rwlock_rdlock(&p->es->use_lock)) - abort(); - } - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - - - } while(p != es->le); - - return 0; -} - - -/* - * event_store_recover() - * - recover after restart or catch up when events missing in IPC - * - if offset > 0, read everything behind it - * - if offset == 0, read everything behind min(last_committed_bs, last_committed_es) - */ -int -event_store_recover(struct event_store *es) -{ - struct event_queue *eq_l = NULL, *eq_b = NULL; - struct server_msg *msg; - char *event_s; - int fd, ret; - long last; - FILE *ef; - struct flock efl; - char err_msg[128]; - struct stat stbuf; - - assert(es != NULL); - -#if defined(IL_NOTIFICATIONS) - /* destination queue has to be found for each message separately */ -#else - /* find bookkeeping server queue */ - eq_b = queue_list_get(es->job_id_s); - if(eq_b == NULL) - return(-1); -#endif - -#if !defined(IL_NOTIFICATIONS) - /* get log server queue */ - eq_l = queue_list_get(NULL); -#endif - - /* lock the event_store and offset locks */ - event_store_lock(es); - if(pthread_rwlock_wrlock(&es->offset_lock)) - abort(); - - il_log(LOG_DEBUG, " reading events from %s\n", es->event_file_name); - - /* open event file */ - ef = fopen(es->event_file_name, "r"); - if(ef == NULL) { - snprintf(err_msg, sizeof(err_msg), - "event_store_recover: error opening event file %s", - es->event_file_name); - set_error(IL_SYS, errno, err_msg); - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - return(-1); - } - - /* lock the file for reading (we should not read while dglogd is writing) */ - fd = fileno(ef); - efl.l_type = F_RDLCK; - efl.l_whence = SEEK_SET; - efl.l_start = 0; - efl.l_len = 0; - if(fcntl(fd, F_SETLKW, &efl) < 0) { - snprintf(err_msg, sizeof(err_msg), - "event_store_recover: error locking event file %s", - es->event_file_name); - set_error(IL_SYS, errno, err_msg); - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - fclose(ef); - return(-1); - } - - /* check the file modification time and size to avoid unnecessary operations */ - memset(&stbuf, 0, sizeof(stbuf)); - if(fstat(fd, &stbuf) < 0) { - il_log(LOG_ERR, " could not stat event file %s: %s\n", es->event_file_name, strerror(errno)); - fclose(ef); - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - return -1; - } else { - if((es->offset == stbuf.st_size) && (es->last_modified == stbuf.st_mtime)) { - il_log(LOG_DEBUG, " event file not modified since last visit, skipping\n"); - fclose(ef); - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - return(0); - } - } - - /* check the file size, rename it if it is bigger than max_store_size */ - if(max_store_size > 0 && stbuf.st_size > max_store_size) { - event_store_rotate_file(es); - } - - while(1) { /* try, try, try */ - - /* get the position in file to be sought */ - if(es->offset) - last = es->offset; - else { -#if !defined(IL_NOTIFICATIONS) - if(eq_b == eq_l) - last = es->last_committed_ls; - else -#endif - /* last = min(ls, bs) */ - /* I took the liberty to optimize this, - since LS is not used. */ - /* last = (es->last_committed_bs < - es->last_committed_ls) ? es->last_committed_bs : - es->last_committed_ls; */ - last = es->last_committed_bs; - } - - il_log(LOG_DEBUG, " setting starting file position to %ld\n", last); - il_log(LOG_DEBUG, " bytes sent to logging server: %d\n", es->last_committed_ls); - il_log(LOG_DEBUG, " bytes sent to bookkeeping server: %d\n", es->last_committed_bs); - - if(last > 0) { - int c; - - /* skip all committed or already enqueued events */ - /* be careful - check, if the offset really points to the - beginning of event string */ - if(fseek(ef, last-1, SEEK_SET) < 0) { - set_error(IL_SYS, errno, "event_store_recover: error setting position for read"); - event_store_unlock(es); - fclose(ef); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - return(-1); - } - /* the last enqueued event MUST end with EVENT_SEPARATOR, - even if the offset points at EOF */ - if((c=fgetc(ef)) != EVENT_SEPARATOR) { - /* Houston, we have got a problem */ - il_log(LOG_WARNING, - " file position %ld does not point at the beginning of event string, backing off!\n", - last); - /* now, where were we? */ - if(es->offset) { - /* next try will be with - last_commited_bs */ - es->offset = 0; - } else { - /* this is really weird... back off completely */ - es->last_committed_ls = es->last_committed_bs = 0; - } - } else { - /* OK, break out of the loop */ - break; - } - } else { - /* this breaks out of the loop, we are starting at - * the beginning of file - */ - if(fseek(ef, 0, SEEK_SET) < 0) { - set_error(IL_SYS, errno, "event_store_recover: error setting position for read"); - event_store_unlock(es); - fclose(ef); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - return(-1); - } - break; - } - } - - /* now we have: - * - event file opened at position 'last' - * - offset and last_committed_* potentially reset to zero - */ - - /* release lock on commits, offset remains locked; - * other threads are allowed to send/remove events, but not insert - */ - event_store_unlock(es); - - /* enqueue all remaining events */ - ret = 1; - msg = NULL; - while((event_s=read_event_string(ef)) != NULL) { - long last_ls, last_bs; - - /* last holds the starting position of event_s in file */ - il_log(LOG_DEBUG, " reading event at %ld\n", last); - - last_ls = es->last_committed_ls; - last_bs = es->last_committed_bs; - - /* break from now on means there was some error */ - ret = -1; - - /* create message for server */ - { - il_octet_string_t e; - - e.data = event_s; - e.len = strlen(event_s); - msg = server_msg_create(&e, last); - free(event_s); - } - if(msg == NULL) { - il_log(LOG_ALERT, " event file corrupted! I will try to move it to quarantine (ie. rename it).\n"); - /* actually do not bother if quarantine succeeded or not - we could not do more */ - event_store_quarantine(es); - fclose(ef); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - return(-1); - } - msg->es = es; - msg->generation = es->generation; - - /* first enqueue to the LS */ - if(!bs_only && (last >= last_ls)) { - - il_log(LOG_DEBUG, " queuing event at %ld to logging server\n", last); - -#if !defined(IL_NOTIFICATIONS) - if(enqueue_msg(eq_l, msg) < 0) - break; -#endif - } - -#ifdef IL_NOTIFICATIONS - eq_b = queue_list_get(msg->dest); - /* if the message does not have destination itself, use destination cached for notification id */ - if(eq_b == NULL) { - eq_b = notifid_map_get_dest(msg->job_id_s); - if(eq_b == NULL) { - /* message has no destination and no destination is known for notification id, - * commit it immediately - */ - il_log(LOG_DEBUG, " message has no known destination, will not be sent\n"); - event_store_commit(es, msg->ev_len, 0, msg->generation); - /* if the expiration changed, set new one now, message will be discarded soon */ - if(msg->expires != notifid_map_get_expiration(msg->job_id_s)) { - notifid_map_set_expiration(msg->job_id_s, msg->expires); - } - } - } -#endif - - /* now enqueue to the BS, if neccessary */ - if((eq_b != eq_l) && - (last >= last_bs)) { - - il_log(LOG_DEBUG, " queueing event at %ld to bookkeeping server\n", last); - - if(enqueue_msg(eq_b, msg) < 0) - break; - } - server_msg_free(msg); - msg = NULL; - - /* now last is also the offset behind the last successfully queued event */ - last = ftell(ef); - - /* ret == 0 means EOF or incomplete event found */ - ret = 0; - - } /* while */ - - es->offset = last; - es->last_modified = stbuf.st_mtime; - il_log(LOG_DEBUG, " event store offset set to %ld\n", last); - - if(msg) - server_msg_free(msg); - - fclose(ef); - il_log(LOG_DEBUG, " finished reading events with %d\n", ret); - - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - - return(ret); -} - - -/* - * event_store_sync() - * - check the position of event and fill holes from file - * - return 1 if the event is new, - * 0 if it was seen before, - * -1 if there was an error - */ -int -event_store_sync(struct event_store *es, long offset) -{ - int ret; - - assert(es != NULL); - - /* Commented out due to the fact that offset as received on socket - * has little to do with the real event file at the moment. The - * event will be read from file, socket now serves only to notify - * about possible event file change. - */ - ret = event_store_recover_jobid(es); - ret = (ret < 0) ? ret : 0; - return(ret); - -#if 0 - event_store_lock_ro(es); - if(es->offset == offset) - /* we are up to date */ - ret = 1; - else if(es->offset > offset) - /* we have already seen this event */ - ret = 0; - else { - /* es->offset < offset, i.e. we have missed some events */ - event_store_unlock(es); - ret = event_store_recover(es); - /* XXX possible room for intervention by another thread - is there - * any other thread messing with us? - * 1) After recover() es->offset is set at the end of file. - * 2) es->offset is set only by recover() and next(). - * 3) Additional recover can not do much harm. - * 4) And next() is only called by the same thread as sync(). - * 5) use_lock is in place, so no cleanup possible - * => no one is messing with us right now */ - event_store_lock_ro(es); - if(ret < 0) - ret = -1; - else - if(es->offset <= offset) { - /* Apparently there is something wrong - we are receiving an event - * which is beyond the end of file. Someone must have removed the file - * when we were not looking. The question is - what should we do with the event? - * We have to send it, as this is the only one occasion when we see it. - * However, we must not allow the es->offset to be set using this event, - * as it would point after the end of file. Sort this out in event_store_next(). - */ - ret = 1; - } else if(es->offset > offset) { - /* we have seen at least this event */ - ret = 0; - } - } - event_store_unlock(es); - return(ret); -#endif -} - - -int -event_store_next(struct event_store *es, long offset, int len) -{ - assert(es != NULL); - - /* Commented out due to the fact that offset as received on socket - * has little to do with real event file at the moment. es->offset - * handling is left solely to the event_store_recover(). - */ - -#if 0 - event_store_lock(es); - /* Whoa, be careful now. The es->offset points right after the last enqueued event, - * but it may not be the offset of the event WE have just enqueued, because:! - * 1) someone could have removed the event file behind our back - * 2) the file could have been recover()ed and more events read - * In either case the offset should not be moved. - */ - if(es->offset == offset) { - es->offset += len; - } - event_store_unlock(es); -#endif - - return(0); -} - - -/* - * event_store_commit() - * - */ -int -event_store_commit(struct event_store *es, int len, int ls, int generation) -{ - assert(es != NULL); - - /* do not move counters if event store with this message was cleaned up - * (this can happen only when moving to quarantine) - */ - /* XXX - assume int access is atomic */ - if(generation != es->generation) - return 0; - - event_store_lock(es); - - if(ls) - es->last_committed_ls += len; - else { - es->last_committed_bs += len; - if (bs_only) es->last_committed_ls += len; - } - - if(event_store_write_ctl(es) < 0) { - event_store_unlock(es); - return(-1); - } - - event_store_unlock(es); - - - return(0); -} - - -/* - * event_store_clean() - * - remove the event files (event and ctl), if they are not needed anymore - * - returns 0 if event_store is in use, 1 if it was removed and -1 on error - * - * Q: How do we know that we can safely remove the files? - * A: When all events from file have been committed both by LS and BS. - */ -static -int -event_store_clean(struct event_store *es) -{ - long last; - int fd; - FILE *ef; - struct flock efl; - - assert(es != NULL); - - /* prevent sender threads from updating */ - event_store_lock(es); - - il_log(LOG_DEBUG, " trying to cleanup event store %s\n", es->job_id_s); - il_log(LOG_DEBUG, " bytes sent to logging server: %d\n", es->last_committed_ls); - il_log(LOG_DEBUG, " bytes sent to bookkeeping server: %d\n", es->last_committed_bs); - - /* preliminary check to avoid opening event file */ - /* if the positions differ, some events still have to be sent */ - if(es->last_committed_ls != es->last_committed_bs) { - event_store_unlock(es); - il_log(LOG_DEBUG, " not all events sent, cleanup aborted\n"); - return(0); - } - - if(fd = pthread_rwlock_wrlock(&es->offset_lock)) { - fprintf(stderr, "Fatal locking error: %s\n", strerror(fd)); - abort(); - } - - /* the file can only be removed when all the events were succesfully sent - (ie. committed both by LS and BS */ - /* That also implies that the event queues are 'empty' at the moment. */ - ef = fopen(es->event_file_name, "r+"); - if(ef == NULL) { - /* if we can not open the event store, it is an error and the struct should be removed */ - /* XXX - is it true? */ - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - il_log(LOG_ERR, " event_store_clean: error opening event file: %s\n", strerror(errno)); - return(1); - } - - fd = fileno(ef); - - /* prevent local-logger from writing into event file */ - efl.l_type = F_WRLCK; - efl.l_whence = SEEK_SET; - efl.l_start = 0; - efl.l_len = 0; - if(fcntl(fd, F_SETLK, &efl) < 0) { - il_log(LOG_DEBUG, " could not lock event file, cleanup aborted\n"); - fclose(ef); - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - if(errno != EACCES && - errno != EAGAIN) { - set_error(IL_SYS, errno, "event_store_clean: error locking event file"); - return(-1); - } - return(0); - } - - /* now the file should not contain partially written event, so it is safe - to get offset behind last event by seeking the end of file */ - if(fseek(ef, 0, SEEK_END) < 0) { - set_error(IL_SYS, errno, "event_store_clean: error seeking the end of file"); - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - fclose(ef); - return(-1); - } - - last = ftell(ef); - il_log(LOG_DEBUG, " total bytes in file: %d\n", last); - - if(es->last_committed_ls < last) { - fclose(ef); - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - il_log(LOG_DEBUG, " events still waiting in queue, cleanup aborted\n"); - return(0); - } else if( es->last_committed_ls > last) { - il_log(LOG_WARNING, " warning: event file seems to shrink!\n"); - /* XXX - in that case we can not continue because there may be - some undelivered events referring to that event store */ - fclose(ef); - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - return(0); - } - - /* now we are sure that all events were sent and the event queues are empty */ - il_log(LOG_INFO, " removing event file %s\n", es->event_file_name); - - /* remove the event file */ - unlink(es->event_file_name); - unlink(es->control_file_name); - - /* clear the counters */ - es->last_committed_ls = 0; - es->last_committed_bs = 0; - es->offset = 0; - - /* increasing the generation count is rather pointless here, because there - are no messages waiting in the queue that would be invalidated */ - /* es->generation++ */ - - /* unlock the event_store even if it is going to be removed */ - event_store_unlock(es); - if(pthread_rwlock_unlock(&es->offset_lock)) - abort(); - - /* close the event file (that unlocks it as well) */ - fclose(ef); - - /* indicate that it is safe to remove this event_store */ - return(1); -} - - -/* -------------------------------- - * event store management functions - * -------------------------------- - */ -struct event_store * -event_store_find(char *job_id_s, const char *filename) -{ - struct event_store_list *q, *p, *d; - struct event_store *es; - - if(pthread_rwlock_wrlock(&store_list_lock)) { - abort(); - } - - es = NULL; - - d = NULL; - p = store_list; - - while(p) { - if(strcmp(p->es->job_id_s, job_id_s) == 0) { - es = p->es; - d = p; - // if filename was given, compare it as well - if((filename == NULL && p->es->rotate_index == 0) || - (filename != NULL && strcmp(p->es->event_file_name, filename) == 0)) { - if(pthread_rwlock_rdlock(&es->use_lock)) - abort(); - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - return(es); - } - } - p = p->next; - } - - // event store for given jobid and filename was not found, create one - es = event_store_create(job_id_s, filename); - if(es == NULL) { - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - return(NULL); - } - - p = malloc(sizeof(*p)); - if(p == NULL) { - set_error(IL_NOMEM, ENOMEM, "event_store_find: no room for new event store"); - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - return(NULL); - } - p->es = es; - p->jobid_next = p; - p->jobid_prev = p; - es->le = p; - - if(filename != NULL && d != NULL) { - // there is another event store for this jobid; - // d points to the last event store for this jobid in LL - // find proper place to insert new event store - if(p->es->rotate_index == 0) { - // insert behind d in LL - p->next = d->next; - d->next = p; - // insert behind d in jobid LL - p->jobid_next = d->jobid_next; - p->jobid_prev = d; - d->jobid_next->jobid_prev = p; - d->jobid_next = p; - } else { - struct event_store_list *r; - q = NULL; - for(r = d->jobid_next; r != d->jobid_next; r = r->jobid_next) { - if(p->es->rotate_index < r->es->rotate_index) - break; - if(r->es->rotate_index > 0) - q = r; - } - // q has the last lesser non-zero index than p - if(q == NULL) { - p->next = store_list; - store_list = p; - // insert behind d - p->jobid_next = d->jobid_next; - p->jobid_prev = d; - d->jobid_next->jobid_prev = p; - d->jobid_next = p; - } else { - p->next = q->next; - q->next = p; - // insert behind q - p->jobid_next = q->jobid_next; - p->jobid_prev = q; - q->jobid_next->jobid_prev = p; - q->jobid_next = p; - } - } - } else { - // insert at the beginning - p->next = store_list; - store_list = p; - } - - if(pthread_rwlock_rdlock(&es->use_lock)) - abort(); - - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - - return(es); -} - - -int -event_store_release(struct event_store *es) -{ - assert(es != NULL); - - if(pthread_rwlock_unlock(&es->use_lock)) - abort(); - il_log(LOG_DEBUG, " released lock on %s (%s)\n", es->job_id_s, es->event_file_name); - return(0); -} - - -static -int -event_store_from_file(char *filename) -{ - struct event_store *es; - FILE *event_file; - char *event_s, *job_id_s = NULL; - int ret; -#if defined(IL_NOTIFICATIONS) - edg_wll_Event *notif_event; - edg_wll_Context context; - char *dest_name = NULL; - -#endif - - il_log(LOG_INFO, " attaching to event file: %s\n", filename); - - if(strstr(filename, "quarantine") != NULL) { - il_log(LOG_INFO, " file name belongs to quarantine, not touching that.\n"); - return(0); - } - - event_file = fopen(filename, "r"); - if(event_file == NULL) { - set_error(IL_SYS, errno, "event_store_from_file: error opening event file"); - return(-1); - } - event_s = read_event_string(event_file); - fclose(event_file); - if(event_s == NULL) - return(0); - -#if defined(IL_NOTIFICATIONS) - edg_wll_InitContext(&context); - ret=edg_wll_ParseNotifEvent(context, event_s, ¬if_event); - edg_wll_FreeContext(context); - if(ret) { - set_error(IL_LBAPI, ret, "event_store_from_file: could not parse event"); - ret = -1; - goto out; - } - if(notif_event->notification.notifId == NULL) { - set_error(IL_LBAPI, EDG_WLL_ERROR_PARSE_BROKEN_ULM, - "event_store_from_file: parse error - no notif id"); - ret = -1; - goto out; - } - if((job_id_s = edg_wll_NotifIdUnparse(notif_event->notification.notifId)) == NULL) { - set_error(IL_SYS, ENOMEM, "event_store_from_file: could not copy id"); - ret = -1; - goto out; - } - /* XXX: what was that good for? - if(notif_event->notification.dest_host && - (strlen(notif_event->notification.dest_host) > 0)) { - asprintf(&dest_name, "%s:%d", notif_event->notification.dest_host, notif_event->notification.dest_port); - } - */ - -#else - job_id_s = edg_wll_GetJobId(event_s); -#endif - il_log(LOG_DEBUG, " event id: '%s'\n", job_id_s); - if(job_id_s == NULL) { - il_log(LOG_NOTICE, " skipping file, could not parse event\n"); - ret = 0; - goto out; - } - - es = event_store_find(job_id_s, filename); - - if(es == NULL) { - ret = -1; - goto out; - } - - if((es->last_committed_ls == 0) && - (es->last_committed_bs == 0) && - (es->offset == 0)) { - ret = event_store_read_ctl(es); - } else - ret = 0; - - event_store_release(es); - -out: -#if defined(IL_NOTIFICATIONS) - if(notif_event) { - edg_wll_FreeEvent(notif_event); - free(notif_event); - } -#endif - if(event_s) free(event_s); - if(job_id_s) free(job_id_s); - return(ret); -} - - -int -event_store_init(char *prefix) -{ - if(file_prefix == NULL) { - file_prefix = strdup(prefix); - store_list = NULL; - } - - /* read directory and get a list of event files */ - { - int len; - - char *p, *dir; - DIR *event_dir; - struct dirent *entry; - - - /* get directory name */ - p = strrchr(file_prefix, '/'); - if(p == NULL) { - dir = strdup("."); - p = ""; - len = 0; - } else { - *p = '\0'; - dir = strdup(file_prefix); - *p++ = '/'; - len = strlen(p); - } - - event_dir = opendir(dir); - if(event_dir == NULL) { - free(dir); - set_error(IL_SYS, errno, "event_store_init: error opening event directory"); - return(-1); - } - - while((entry=readdir(event_dir))) { - char *s; - - /* skip all files that do not match prefix */ - if(strncmp(entry->d_name, p, len) != 0) - continue; - - /* skip all control files */ - if((s=strstr(entry->d_name, ".ctl")) != NULL && - s[4] == '\0') - continue; - - s = malloc(strlen(dir) + strlen(entry->d_name) + 2); - if(s == NULL) { - free(dir); - set_error(IL_NOMEM, ENOMEM, "event_store_init: no room for file name"); - return(-1); - } - - *s = '\0'; - strcat(s, dir); - strcat(s, "/"); - strcat(s, entry->d_name); - - if(event_store_from_file(s) < 0) { - free(dir); - free(s); - closedir(event_dir); - return(-1); - } - - free(s); - } - closedir(event_dir); - - /* one more pass - this time remove stale .ctl files */ - event_dir = opendir(dir); - if(event_dir == NULL) { - free(dir); - set_error(IL_SYS, errno, "event_store_init: error opening event directory"); - return(-1); - } - - while((entry=readdir(event_dir))) { - char *s; - - /* skip all files that do not match prefix */ - if(strncmp(entry->d_name, p, len) != 0) - continue; - - /* find all control files */ - if((s=strstr(entry->d_name, ".ctl")) != NULL && - s[4] == '\0') { - char *ef; - struct stat st; - - /* is there corresponding event file? */ - ef = malloc(strlen(dir) + strlen(entry->d_name) + 2); - if(ef == NULL) { - free(dir); - set_error(IL_NOMEM, ENOMEM, "event_store_init: no room for event file name"); - return(-1); - } - - s[0] = 0; - *ef = '\0'; - strcat(ef, dir); - strcat(ef, "/"); - strcat(ef, entry->d_name); - s[0] = '.'; - - if(stat(ef, &st) == 0) { - /* something is there */ - /* XXX - it could be something else than event file, but do not bother now */ - } else { - /* could not stat file, remove ctl */ - strcat(ef, s); - il_log(LOG_DEBUG, " removing stale file %s\n", ef); - if(unlink(ef)) - il_log(LOG_ERR, " could not remove file %s: %s\n", ef, strerror(errno)); - - } - free(ef); - - } - } - closedir(event_dir); - free(dir); - } - - return(0); -} - - -int -event_store_recover_all() -{ - struct event_store_list *sl; - - - if(pthread_rwlock_rdlock(&store_list_lock)) - abort(); - - /* recover all event stores */ - sl = store_list; - while(sl != NULL) { - - /* recover this event store */ - /* no need to lock use_lock in event_store, the store_list_lock is in place */ - if(event_store_recover(sl->es) < 0) { - il_log(LOG_ERR, " error recovering event store %s:\n %s\n", sl->es->event_file_name, error_get_msg()); - clear_error(); - } - sl = sl->next; - } - - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - - return(0); -} - - -#if 0 -int -event_store_remove(struct event_store *es) -{ - struct event_store_list *p, **q; - - assert(es != NULL); - - switch(event_store_clean(es)) { - case 0: - il_log(LOG_DEBUG, " event store not removed, still used\n"); - return(0); - - case 1: - if(pthread_rwlock_wrlock(&store_list_lock) < 0) { - set_error(IL_SYS, errno, " event_store_remove: error locking event store list"); - return(-1); - } - - p = store_list; - q = &store_list; - - while(p) { - if(p->es == es) { - (*q) = p->next; - event_store_free(es); - free(p); - break; - } - q = &(p->next); - p = p->next; - } - - if(pthread_rwlock_unlock(&store_list_lock) < 0) { - set_error(IL_SYS, errno, " event_store_remove: error unlocking event store list"); - return(-1); - } - return(1); - - default: - return(-1); - } - /* not reached */ - return(0); -} -#endif - -int -event_store_cleanup() -{ - struct event_store_list *sl; - struct event_store_list *slnext; - struct event_store_list **prev; - - /* try to remove event files */ - - if(pthread_rwlock_wrlock(&store_list_lock)) - abort(); - - sl = store_list; - prev = &store_list; - - while(sl != NULL) { - int ret; - - slnext = sl->next; - - /* one event store at time */ - ret = pthread_rwlock_trywrlock(&sl->es->use_lock); - if(ret == EBUSY) { - il_log(LOG_DEBUG, " event_store %s is in use by another thread\n", - sl->es->job_id_s); - sl = slnext; - continue; - } else if (ret < 0) - abort(); - - switch(event_store_clean(sl->es)) { - - case 1: - /* remove this event store from LL */ - (*prev) = slnext; - /* remove this event store from jobid's LL */ - if(sl->jobid_next != sl) { - sl->jobid_prev->jobid_next = sl->jobid_next; - sl->jobid_next->jobid_prev = sl->jobid_prev; - } - event_store_free(sl->es); - free(sl); - break; - - case -1: - il_log(LOG_ERR, " error removing event store %s (file %s):\n %s\n", - sl->es->job_id_s, sl->es->event_file_name, error_get_msg()); - /* event_store_release(sl->es); */ - clear_error(); - /* go on to the next */ - - default: - event_store_release(sl->es); - prev = &(sl->next); - break; - } - - sl = slnext; - } - - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - - return(0); -} - diff --git a/org.glite.lb.logger/src/event_store_http.c b/org.glite.lb.logger/src/event_store_http.c deleted file mode 100644 index ebd5523..0000000 --- a/org.glite.lb.logger/src/event_store_http.c +++ /dev/null @@ -1,1113 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#include - -#include "glite/lb/events_parse.h" - -#include "interlogd.h" - -#ifdef __GNUC__ -#define UNUSED_VAR __attribute__((unused)) -#else -#define UNUSED_VAR -#endif - -static char *file_prefix = NULL; - - -struct event_store_list { - struct event_store *es; - struct event_store_list *next; -}; - - -static struct event_store_list *store_list; -static pthread_rwlock_t store_list_lock = PTHREAD_RWLOCK_INITIALIZER; - - -/* ---------------- - * helper functions - * ---------------- - */ -static -char * -jobid2eventfile(const char *job_id_s) -{ - char *buffer; - - if(job_id_s) { - asprintf(&buffer, "%s.%s", file_prefix, job_id_s); - } else - asprintf(&buffer, "%s.default", file_prefix); - - return(buffer); -} - - -static -char * -jobid2controlfile(char *job_id_s) -{ - char *buffer; - char *hash; - - if(job_id_s) { - asprintf(&buffer, "%s.%s.ctl", file_prefix, job_id_s); - } else - asprintf(&buffer, "%s.default.ctl", file_prefix); - - return(buffer); -} - -static -int -file_reader(void *user_data, char *buffer, const int len) -{ - size_t ret = 0; - - if(len > 0) { - ret = fread(buffer, 1, len, (FILE*)user_data); - if(ret == 0 && ferror((FILE*)user_data)) { - return -1; - } - } - return ret; -} - - -static -int -read_event_string(FILE *file, il_http_message_t *msg) -{ - int len, ret; - int fd = fileno(file); - long start; - - /* remember the start position */ - start = ftell(file); - ret = receive_http(file, file_reader, msg); - if(ret < 0) return ret; - /* seek at the end of message in case the reader read ahead */ - len = fseek(file, start + msg->len, SEEK_SET); - len = fgetc(file); - if(len != '\n') { - il_log(LOG_ERR, "error reading event from file, missing terminator character at %d, found %c(%d))\n", - start+msg->len, len, len); - if(msg->data) { free(msg->data); msg->data = NULL; } - if(msg->host) { free(msg->host); msg->host = NULL; } - return EINVAL; - } - return ret; -} - - - -/* ------------------------------ - * event_store 'member' functions - * ------------------------------ - */ -static -int -event_store_free(struct event_store *es) -{ - assert(es != NULL); - - if(es->job_id_s) free(es->job_id_s); - if(es->event_file_name) free(es->event_file_name); - if(es->control_file_name) free(es->control_file_name); - pthread_rwlock_destroy(&es->use_lock); - pthread_rwlock_destroy(&es->commit_lock); - free(es); - - return(0); -} - - -static -struct event_store * -event_store_create(char *job_id_s) -{ - struct event_store *es; - - es = malloc(sizeof(*es)); - if(es == NULL) { - set_error(IL_NOMEM, ENOMEM, "event_store_create: error allocating room for structure"); - return(NULL); - } - - memset(es, 0, sizeof(*es)); - - il_log(LOG_DEBUG, " creating event store for id %s\n", job_id_s); - - es->job_id_s = strdup(job_id_s); - es->event_file_name = jobid2eventfile(job_id_s); - es->control_file_name = jobid2controlfile(job_id_s); - - if(pthread_rwlock_init(&es->commit_lock, NULL)) - abort(); - if(pthread_rwlock_init(&es->use_lock, NULL)) - abort(); - - return(es); -} - - -static -int -event_store_lock_ro(struct event_store *es) -{ - assert(es != NULL); - - if(pthread_rwlock_rdlock(&es->commit_lock)) - abort(); - - return(0); -} - - -static -int -event_store_lock(struct event_store *es) -{ - assert(es != NULL); - - if(pthread_rwlock_wrlock(&es->commit_lock)) - abort(); - - return(0); -} - - -static -int -event_store_unlock(struct event_store *es) -{ - assert(es != NULL); - - if(pthread_rwlock_unlock(&es->commit_lock)) - abort(); - return(0); -} - - -static -int -event_store_read_ctl(struct event_store *es) -{ - FILE *ctl_file; - - assert(es != NULL); - - event_store_lock(es); - if((ctl_file = fopen(es->control_file_name, "r")) == NULL) { - /* no control file, new event file */ - es->last_committed_ls = 0; - es->last_committed_bs = 0; - } else { - /* read last seen and last committed counts */ - fscanf(ctl_file, "%*s\n%ld\n%ld\n", - &es->last_committed_ls, - &es->last_committed_bs); - fclose(ctl_file); - } - event_store_unlock(es); - - return(0); -} - - -static -int -event_store_write_ctl(struct event_store *es) -{ - FILE *ctl; - - assert(es != NULL); - - ctl = fopen(es->control_file_name, "w"); - if(ctl == NULL) { - set_error(IL_SYS, errno, "event_store_write_ctl: error opening control file"); - return(-1); - } - - if(fprintf(ctl, "%s\n%ld\n%ld\n", - es->job_id_s, - es->last_committed_ls, - es->last_committed_bs) < 0) { - set_error(IL_SYS, errno, "event_store_write_ctl: error writing control record"); - return(-1); - } - - if(fclose(ctl) < 0) { - set_error(IL_SYS, errno, "event_store_write_ctl: error closing control file"); - return(-1); - } - - return(0); -} - - -/* - * event_store_qurantine() - * - rename damaged event store file - * - essentially does the same actions as cleanup, but the event store - * does not have to be empty - * returns 0 on success, -1 on error - */ -static -int -event_store_quarantine(struct event_store *es) -{ - int num; - char newname[MAXPATHLEN+1]; - - /* find available qurantine name */ - /* we give it at most 1024 tries */ - for(num = 0; num < 1024; num++) { - struct stat st; - - snprintf(newname, MAXPATHLEN, "%s.quarantine.%d", es->event_file_name, num); - newname[MAXPATHLEN] = 0; - if(stat(newname, &st) < 0) { - if(errno == ENOENT) { - /* file not found */ - break; - } else { - /* some other error with name, probably permanent */ - set_error(IL_SYS, errno, "event_store_qurantine: error looking for qurantine filename"); - return(-1); - - } - } else { - /* the filename is used already */ - } - } - if(num >= 1024) { - /* new name not found */ - /* XXX - is there more suitable error? */ - set_error(IL_SYS, ENOSPC, "event_store_quarantine: exhausted number of retries looking for quarantine filename"); - return(-1); - } - - /* actually rename the file */ - il_log(LOG_DEBUG, " renaming damaged event file from %s to %s\n", - es->event_file_name, newname); - if(rename(es->event_file_name, newname) < 0) { - set_error(IL_SYS, errno, "event_store_quarantine: error renaming event file"); - return(-1); - } - - /* clear the counters */ - es->last_committed_ls = 0; - es->last_committed_bs = 0; - es->offset = 0; - - return(0); -} - - -/* - * event_store_recover() - * - recover after restart or catch up when events missing in IPC - * - if offset > 0, read everything behind it - * - if offset == 0, read everything behind min(last_committed_bs, last_committed_es) - */ -int -event_store_recover(struct event_store *es) -{ - struct event_queue *eq_l = NULL, *eq_b = NULL; - struct server_msg *msg; - il_http_message_t hmsg; - char *event_s; - int fd, ret; - long last; - FILE *ef; - struct flock efl; - char err_msg[128]; - struct stat stbuf; - - assert(es != NULL); - -#if defined(IL_NOTIFICATIONS) - /* destination queue has to be found for each message separately */ -#else - /* find bookkepping server queue */ - eq_b = queue_list_get(es->job_id_s); - if(eq_b == NULL) - return(-1); -#endif - -#if !defined(IL_NOTIFICATIONS) - /* get log server queue */ - eq_l = queue_list_get(NULL); -#endif - - event_store_lock(es); - - il_log(LOG_DEBUG, " reading events from %s\n", es->event_file_name); - - /* open event file */ - ef = fopen(es->event_file_name, "r"); - if(ef == NULL) { - snprintf(err_msg, sizeof(err_msg), - "event_store_recover: error opening event file %s", - es->event_file_name); - set_error(IL_SYS, errno, err_msg); - event_store_unlock(es); - return(-1); - } - - /* lock the file for reading (we should not read while dglogd is writing) */ - fd = fileno(ef); - efl.l_type = F_RDLCK; - efl.l_whence = SEEK_SET; - efl.l_start = 0; - efl.l_len = 0; - if(fcntl(fd, F_SETLKW, &efl) < 0) { - snprintf(err_msg, sizeof(err_msg), - "event_store_recover: error locking event file %s", - es->event_file_name); - set_error(IL_SYS, errno, err_msg); - event_store_unlock(es); - fclose(ef); - return(-1); - } - - /* check the file modification time and size to avoid unnecessary operations */ - memset(&stbuf, 0, sizeof(stbuf)); - if(fstat(fd, &stbuf) < 0) { - il_log(LOG_ERR, " could not stat event file %s: %s\n", es->event_file_name, strerror(errno)); - fclose(ef); - event_store_unlock(es); - return -1; - } else { - if((es->offset == stbuf.st_size) && (es->last_modified == stbuf.st_mtime)) { - il_log(LOG_DEBUG, " event file not modified since last visit, skipping\n"); - fclose(ef); - event_store_unlock(es); - return(0); - } - } - - while(1) { /* try, try, try */ - - /* get the position in file to be sought */ - if(es->offset) - last = es->offset; - else { - last = es->last_committed_bs; - } - - il_log(LOG_DEBUG, " setting starting file position to %ld\n", last); - il_log(LOG_DEBUG, " bytes sent to destination: %d\n", es->last_committed_bs); - - if(last > 0) { - int c; - - /* skip all committed or already enqueued events */ - /* be careful - check, if the offset really points to the - beginning of event string */ - if(fseek(ef, last - 1, SEEK_SET) < 0) { - set_error(IL_SYS, errno, "event_store_recover: error setting position for read"); - event_store_unlock(es); - fclose(ef); - return(-1); - } - /* the last enqueued event MUST end with \n */ - if((c=fgetc(ef)) != '\n') { - /* Houston, we have got a problem */ - il_log(LOG_WARNING, - " file position %ld does not point at the beginning of event string, backing off!\n", - last); - /* now, where were we? */ - if(es->offset) { - /* next try will be with - last_commited_bs */ - es->offset = 0; - } else { - /* this is really weird... back off completely */ - es->last_committed_ls = es->last_committed_bs = 0; - } - } else { - /* OK, break out of the loop */ - break; - } - } else { - /* this breaks out of the loop, we are starting at - * the beginning of file - */ - if(fseek(ef, 0, SEEK_SET) < 0) { - set_error(IL_SYS, errno, "event_store_recover: error setting position for read"); - event_store_unlock(es); - fclose(ef); - return(-1); - } - break; - } - } - - /* enqueue all remaining events */ - ret = 1; - msg = NULL; - while(read_event_string(ef, &hmsg) >= 0) { - - /* last holds the starting position of event_s in file */ - il_log(LOG_DEBUG, " reading event at %ld\n", last); - - /* break from now on means there was some error */ - ret = -1; - - /* create message for server */ - msg = server_msg_create((il_octet_string_t*)&hmsg, last); - if(msg == NULL) { - il_log(LOG_ALERT, " event file corrupted! I will try to move it to quarantine (ie. rename it).\n"); - /* actually do not bother if quarantine succeeded or not - we could not do more */ - event_store_quarantine(es); - fclose(ef); - event_store_unlock(es); - return(-1); - } - msg->es = es; - - /* first enqueue to the LS */ - if(!bs_only && (last >= es->last_committed_ls)) { - - il_log(LOG_DEBUG, " queueing event at %ld to server %s\n", last, eq_l->dest_name); - -#if !defined(IL_NOTIFICATIONS) - if(enqueue_msg(eq_l, msg) < 0) - break; -#endif - } - -#ifdef IL_NOTIFICATIONS - eq_b = queue_list_get(msg->dest); -#endif - - /* now enqueue to the BS, if neccessary */ - if((eq_b != eq_l) && - (last >= es->last_committed_bs)) { - - il_log(LOG_DEBUG, " queueing event at %ld to server %s\n", last, eq_b->dest_name); - - if(enqueue_msg(eq_b, msg) < 0) - break; - } - server_msg_free(msg); - msg = NULL; - - /* now last is also the offset behind the last successfully queued event */ - last = ftell(ef); - - /* ret == 0 means EOF or incomplete event found */ - ret = 0; - - } /* while */ - - /* due to this little assignment we had to lock the event_store for writing */ - es->offset = last; - es->last_modified = stbuf.st_mtime; - il_log(LOG_DEBUG, " event store offset set to %ld\n", last); - - if(msg) - server_msg_free(msg); - - fclose(ef); - il_log(LOG_DEBUG, " finished reading events with %d\n", ret); - - event_store_unlock(es); - return(ret); -} - - -/* - * event_store_sync() - * - check the position of event and fill holes from file - * - return 1 if the event is new, - * 0 if it was seen before, - * -1 if there was an error - */ -int -event_store_sync(struct event_store *es, long offset) -{ - int ret; - - assert(es != NULL); - - /* all events are actually read from file, the event on socket - * is ignored and serves just to notify us about file change - */ - ret = event_store_recover(es); - ret = (ret < 0) ? ret : 0; - return(ret); -} - - -int -event_store_next(struct event_store *es, long offset, int len) -{ - assert(es != NULL); - - /* offsets are good only to detect losses (differences between socket and file), - which is not possible now */ - return 0; -} - - -/* - * event_store_commit() - * - */ -int -event_store_commit(struct event_store *es, int len, int ls) -{ - assert(es != NULL); - - event_store_lock(es); - - if(ls) - es->last_committed_ls += len; - else { - es->last_committed_bs += len; - if (bs_only) es->last_committed_ls += len; - } - - if(event_store_write_ctl(es) < 0) { - event_store_unlock(es); - return(-1); - } - - event_store_unlock(es); - - - return(0); -} - - -/* - * event_store_clean() - * - remove the event files (event and ctl), if they are not needed anymore - * - returns 0 if event_store is in use, 1 if it was removed and -1 on error - * - * Q: How do we know that we can safely remove the files? - * A: When all events from file have been committed both by LS and BS. - */ -static -int -event_store_clean(struct event_store *es) -{ - long last; - int fd; - FILE *ef; - struct flock efl; - - assert(es != NULL); - - /* prevent sender threads from updating */ - event_store_lock(es); - - il_log(LOG_DEBUG, " trying to cleanup event store %s\n", es->job_id_s); - il_log(LOG_DEBUG, " bytes sent to logging server: %d\n", es->last_committed_ls); - il_log(LOG_DEBUG, " bytes sent to bookkeeping server: %d\n", es->last_committed_bs); - - /* preliminary check to avoid opening event file */ - /* if the positions differ, some events still have to be sent */ - if(es->last_committed_ls != es->last_committed_bs) { - event_store_unlock(es); - il_log(LOG_DEBUG, " not all events sent, cleanup aborted\n"); - return(0); - } - - /* the file can only be removed when all the events were succesfully sent - (ie. committed both by LS and BS */ - /* That also implies that the event queues are 'empty' at the moment. */ - ef = fopen(es->event_file_name, "r+"); - if(ef == NULL) { - /* if we can not open the event store, it is an error and the struct should be removed */ - /* XXX - is it true? */ - event_store_unlock(es); - il_log(LOG_ERR, " event_store_clean: error opening event file: %s\n", strerror(errno)); - return(1); - } - - fd = fileno(ef); - - /* prevent local-logger from writing into event file */ - efl.l_type = F_WRLCK; - efl.l_whence = SEEK_SET; - efl.l_start = 0; - efl.l_len = 0; - if(fcntl(fd, F_SETLK, &efl) < 0) { - il_log(LOG_DEBUG, " could not lock event file, cleanup aborted\n"); - fclose(ef); - event_store_unlock(es); - if(errno != EACCES && - errno != EAGAIN) { - set_error(IL_SYS, errno, "event_store_clean: error locking event file"); - return(-1); - } - return(0); - } - - /* now the file should not contain partially written event, so it is safe - to get offset behind last event by seeking the end of file */ - if(fseek(ef, 0, SEEK_END) < 0) { - set_error(IL_SYS, errno, "event_store_clean: error seeking the end of file"); - event_store_unlock(es); - fclose(ef); - return(-1); - } - - last = ftell(ef); - il_log(LOG_DEBUG, " total bytes in file: %d\n", last); - - if(es->last_committed_ls < last) { - fclose(ef); - event_store_unlock(es); - il_log(LOG_DEBUG, " events still waiting in queue, cleanup aborted\n"); - return(0); - } else if( es->last_committed_ls > last) { - il_log(LOG_WARNING, " warning: event file seems to shrink!\n"); - /* XXX - in that case we can not continue because there may be - some undelivered events referring to that event store */ - fclose(ef); - event_store_unlock(es); - return(0); - } - - /* now we are sure that all events were sent and the event queues are empty */ - il_log(LOG_INFO, " removing event file %s\n", es->event_file_name); - - /* remove the event file */ - unlink(es->event_file_name); - unlink(es->control_file_name); - - /* clear the counters */ - es->last_committed_ls = 0; - es->last_committed_bs = 0; - es->offset = 0; - - /* unlock the event_store even if it is going to be removed */ - event_store_unlock(es); - - /* close the event file (that unlocks it as well) */ - fclose(ef); - - /* indicate that it is safe to remove this event_store */ - return(1); -} - - -/* -------------------------------- - * event store management functions - * -------------------------------- - */ -struct event_store * -event_store_find(char *job_id_s) -{ - struct event_store_list *q, *p; - struct event_store *es; - - if(pthread_rwlock_wrlock(&store_list_lock)) { - abort(); - } - - es = NULL; - - q = NULL; - p = store_list; - - while(p) { - if(strcmp(p->es->job_id_s, job_id_s) == 0) { - es = p->es; - if(pthread_rwlock_rdlock(&es->use_lock)) - abort(); - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - return(es); - } - - q = p; - p = p->next; - } - - es = event_store_create(job_id_s); - if(es == NULL) { - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - return(NULL); - } - - p = malloc(sizeof(*p)); - if(p == NULL) { - set_error(IL_NOMEM, ENOMEM, "event_store_find: no room for new event store"); - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - return(NULL); - } - - p->next = store_list; - store_list = p; - - p->es = es; - - if(pthread_rwlock_rdlock(&es->use_lock)) - abort(); - - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - - return(es); -} - - -int -event_store_release(struct event_store *es) -{ - assert(es != NULL); - - if(pthread_rwlock_unlock(&es->use_lock)) - abort(); - il_log(LOG_DEBUG, " released lock on %s\n", es->job_id_s); - return(0); -} - - -event_store_from_file(char *filename) -{ - struct event_store *es; - FILE *event_file; - char *job_id_s = NULL, *p; - il_http_message_t hmsg; - int ret; - - il_log(LOG_INFO, " attaching to event file: %s\n", filename); - - if(strstr(filename, "quarantine") != NULL) { - il_log(LOG_INFO, " file name belongs to quarantine, not touching that.\n"); - return(0); - } - - event_file = fopen(filename, "r"); - if(event_file == NULL) { - set_error(IL_SYS, errno, "event_store_from_file: error opening event file"); - return(-1); - } - ret = read_event_string(event_file, &hmsg); - fclose(event_file); - if(ret < 0) - return(0); - - /* get id aka dest */ - job_id_s = hmsg.host; - - il_log(LOG_DEBUG, " message dest: '%s'\n", job_id_s); - if(job_id_s == NULL) { - il_log(LOG_NOTICE, " skipping file, could not parse event\n"); - ret = 0; - goto out; - } - - es=event_store_find(job_id_s); - - if(es == NULL) { - ret = -1; - goto out; - } - - if((es->last_committed_ls == 0) && - (es->last_committed_bs == 0) && - (es->offset == 0)) { - ret = event_store_read_ctl(es); - } else - ret = 0; - - event_store_release(es); - -out: - if(hmsg.data) free(hmsg.data); - if(job_id_s) free(job_id_s); - return(ret); -} - - -int -event_store_init(char *prefix) -{ - if(file_prefix == NULL) { - file_prefix = strdup(prefix); - store_list = NULL; - } - - /* read directory and get a list of event files */ - { - int len; - - char *p, *dir; - DIR *event_dir; - struct dirent *entry; - - - /* get directory name */ - p = strrchr(file_prefix, '/'); - if(p == NULL) { - dir = strdup("."); - p = ""; - len = 0; - } else { - *p = '\0'; - dir = strdup(file_prefix); - *p++ = '/'; - len = strlen(p); - } - - event_dir = opendir(dir); - if(event_dir == NULL) { - free(dir); - set_error(IL_SYS, errno, "event_store_init: error opening event directory"); - return(-1); - } - - while((entry=readdir(event_dir))) { - char *s; - - /* skip all files that do not match prefix */ - if(strncmp(entry->d_name, p, len) != 0) - continue; - - /* skip all control files */ - if((s=strstr(entry->d_name, ".ctl")) != NULL && - s[4] == '\0') - continue; - - s = malloc(strlen(dir) + strlen(entry->d_name) + 2); - if(s == NULL) { - free(dir); - set_error(IL_NOMEM, ENOMEM, "event_store_init: no room for file name"); - return(-1); - } - - *s = '\0'; - strcat(s, dir); - strcat(s, "/"); - strcat(s, entry->d_name); - - if(event_store_from_file(s) < 0) { - free(dir); - free(s); - closedir(event_dir); - return(-1); - } - - free(s); - } - closedir(event_dir); - - /* one more pass - this time remove stale .ctl files */ - event_dir = opendir(dir); - if(event_dir == NULL) { - free(dir); - set_error(IL_SYS, errno, "event_store_init: error opening event directory"); - return(-1); - } - - while((entry=readdir(event_dir))) { - char *s; - - /* skip all files that do not match prefix */ - if(strncmp(entry->d_name, p, len) != 0) - continue; - - /* find all control files */ - if((s=strstr(entry->d_name, ".ctl")) != NULL && - s[4] == '\0') { - char *ef; - struct stat st; - - /* is there corresponding event file? */ - ef = malloc(strlen(dir) + strlen(entry->d_name) + 2); - if(ef == NULL) { - free(dir); - set_error(IL_NOMEM, ENOMEM, "event_store_init: no room for event file name"); - return(-1); - } - - s[0] = 0; - *ef = '\0'; - strcat(ef, dir); - strcat(ef, "/"); - strcat(ef, entry->d_name); - s[0] = '.'; - - if(stat(ef, &st) == 0) { - /* something is there */ - /* XXX - it could be something else than event file, but do not bother now */ - } else { - /* could not stat file, remove ctl */ - strcat(ef, s); - il_log(LOG_DEBUG, " removing stale file %s\n", ef); - if(unlink(ef)) - il_log(LOG_ERR, " could not remove file %s: %s\n", ef, strerror(errno)); - - } - free(ef); - - } - } - closedir(event_dir); - free(dir); - } - - return(0); -} - - -int -event_store_recover_all() -{ - struct event_store_list *sl; - - - if(pthread_rwlock_rdlock(&store_list_lock)) - abort(); - - /* recover all event stores */ - sl = store_list; - while(sl != NULL) { - - /* recover this event store */ - /* no need to lock use_lock in event_store, the store_list_lock is in place */ - if(event_store_recover(sl->es) < 0) { - il_log(LOG_ERR, " error recovering event store %s:\n %s\n", sl->es->event_file_name, error_get_msg()); - clear_error(); - } - sl = sl->next; - } - - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - - return(0); -} - - -#if 0 -int -event_store_remove(struct event_store *es) -{ - struct event_store_list *p, **q; - - assert(es != NULL); - - switch(event_store_clean(es)) { - case 0: - il_log(LOG_DEBUG, " event store not removed, still used\n"); - return(0); - - case 1: - if(pthread_rwlock_wrlock(&store_list_lock) < 0) { - set_error(IL_SYS, errno, " event_store_remove: error locking event store list"); - return(-1); - } - - p = store_list; - q = &store_list; - - while(p) { - if(p->es == es) { - (*q) = p->next; - event_store_free(es); - free(p); - break; - } - q = &(p->next); - p = p->next; - } - - if(pthread_rwlock_unlock(&store_list_lock) < 0) { - set_error(IL_SYS, errno, " event_store_remove: error unlocking event store list"); - return(-1); - } - return(1); - - default: - return(-1); - } - /* not reached */ - return(0); -} -#endif - -int -event_store_cleanup() -{ - struct event_store_list *sl; - struct event_store_list *slnext; - struct event_store_list **prev; - - /* try to remove event files */ - - if(pthread_rwlock_wrlock(&store_list_lock)) - abort(); - - sl = store_list; - prev = &store_list; - - while(sl != NULL) { - int ret; - - slnext = sl->next; - - /* one event store at time */ - ret = pthread_rwlock_trywrlock(&sl->es->use_lock); - if(ret == EBUSY) { - il_log(LOG_DEBUG, " event_store %s is in use by another thread\n", - sl->es->job_id_s); - sl = slnext; - continue; - } else if (ret < 0) - abort(); - - switch(event_store_clean(sl->es)) { - - case 1: - /* remove this event store */ - (*prev) = slnext; - event_store_free(sl->es); - free(sl); - break; - - case -1: - il_log(LOG_ERR, " error removing event store %s (file %s):\n %s\n", - sl->es->job_id_s, sl->es->event_file_name, error_get_msg()); - /* event_store_release(sl->es); */ - clear_error(); - /* go on to the next */ - - default: - event_store_release(sl->es); - prev = &(sl->next); - break; - } - - sl = slnext; - } - - if(pthread_rwlock_unlock(&store_list_lock)) - abort(); - - return(0); -} - diff --git a/org.glite.lb.logger/src/http.c b/org.glite.lb.logger/src/http.c deleted file mode 100644 index c9fb89b..0000000 --- a/org.glite.lb.logger/src/http.c +++ /dev/null @@ -1,197 +0,0 @@ -#ident "$Header$" - -#include -#include - -#include "interlogd.h" - - -int -parse_request(const char *s, il_http_message_t *msg) -{ - if(!strncasecmp(s, "HTTP", 4)) { - msg->msg_type = IL_HTTP_REPLY; - } else if(!strncasecmp(s, "POST", 4)) { - msg->msg_type = IL_HTTP_POST; - } else if(!strncasecmp(s, "GET", 3)) { - msg->msg_type = IL_HTTP_GET; - } else { - msg->msg_type = IL_HTTP_OTHER; - } - if(msg->msg_type == IL_HTTP_REPLY) { - char *p = strchr(s, ' '); - - if(!p) goto parse_end; - p++; - msg->reply_code=atoi(p); - p = strchr(p, ' '); - if(!p) goto parse_end; - p++; - msg->reply_string = strdup(p); - - parse_end: - ; - } -} - - -int -parse_header(const char *s, il_http_message_t *msg) -{ - if(!strncasecmp(s, "Content-Length:", 15)) { - msg->content_length = atoi(s + 15); - } else if(!strncasecmp(s, "Host:", 5)) { - const char *p = s + 4; - while(*++p == ' '); /* skip spaces */ - msg->host = strdup(p); - } - return(0); -} - - -#define DEFAULT_CHUNK_SIZE 1024 - -// read what is available and parse what can be parsed -// returns the result of read operation of the underlying connection, -// ie. the number of bytes read or error code -int -receive_http(void *user_data, int (*reader)(void *, char *, const int), il_http_message_t *msg) -{ - static enum { NONE, IN_REQUEST, IN_HEADERS, IN_BODY } state = NONE; - int len, alen, clen, i, buffer_free, min_buffer_free = DEFAULT_CHUNK_SIZE; - char *buffer, *p, *s, *cr; - - memset(msg, 0, sizeof(*msg)); - // msg->data = NULL; - // msg->len = 0; - state = IN_REQUEST; - alen = 0; - buffer = NULL; - buffer_free = 0; - p = NULL; - s = NULL; - - do { - /* p - first empty position in buffer - alen - size of allocated buffer - len - number of bytes received in last read - s - points behind last scanned CRLF or at buffer start - buffer_free = alen - (p - buffer) - */ - - /* prepare at least chunk_size bytes for next data */ - if(buffer_free < min_buffer_free) { - char *n; - - alen += min_buffer_free; - n = realloc(buffer, alen); - if(n == NULL) { - free(buffer); - set_error(IL_NOMEM, ENOMEM, "read_event: no room for event"); - return(-1); - } - buffer_free += min_buffer_free; - p = n + (p - buffer); - s = n + (s - buffer); - buffer = n; - } - - if(buffer_free > 0) { - len = (*reader)(user_data, p, buffer_free); - if(len < 0) { - // error - free(buffer); - // set_error(IL_SYS, errno, "receive_http: error reading data"); - return -1; - } else if(len == 0) { - // EOF - free(buffer); - set_error(IL_PROTO, errno, "receive_http: error reading data - premature EOF"); - return -1; - } - buffer_free -= len; - p+= len; - } - - - switch(state) { - - // parse buffer, look for CRLFs - // s - start scan position - // p - start of current token - // cr - current CRLF position - - case IN_REQUEST: - if((s < p - 1) && - (cr = (char*)memchr(s, '\r', p - s - 1)) && - (cr[1] == '\n')) { - *cr = 0; - parse_request(s, msg); - *cr = '\r'; - // change state - state = IN_HEADERS; - // start new tokens (cr < p - 1 -> s < p + 1 <-> s <= p) - s = cr + 2; - } else { - break; - } - - case IN_HEADERS: - while((state != IN_BODY) && - (s < p - 1) && - (cr = (char*)memchr(s, '\r', p - s - 1)) && - (cr[1] == '\n')) { - if(s == cr) { /* do not consider request starting with CRLF */ - // found CRLFCRLF - state = IN_BODY; - } else { - *cr = 0; - parse_header(s, msg); - *cr = '\r'; - } - // next scan starts after CRLF - s = cr + 2; - } - if(state == IN_BODY) { - // we found body - // content-length should be set at the moment - if(msg->content_length > 0) { - int need_free = msg->content_length - (p - s); - char *n; - - alen += need_free - buffer_free + 1; - n = realloc(buffer, alen); - if(n == NULL) { - free(buffer); - set_error(IL_NOMEM, ENOMEM, "read_event: no room for event"); - return(-1); - } - buffer_free = need_free; - min_buffer_free = 0; - p = n + (p - buffer); - s = n + (s - buffer); - buffer = n; - } else { - // report error - free(buffer); - set_error(IL_PROTO, EINVAL, "receive_http: error reading data - no content length specified\n"); - return -1; - } - } - break; - - case IN_BODY: - if(buffer_free == 0) { - // finished reading - *p = 0; - state = NONE; - } - break; - } - } while(state != NONE); - - msg->data = buffer; - msg->len = p - buffer; - - return 0; -} diff --git a/org.glite.lb.logger/src/il_error.c b/org.glite.lb.logger/src/il_error.c deleted file mode 100644 index 630bd75..0000000 --- a/org.glite.lb.logger/src/il_error.c +++ /dev/null @@ -1,190 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include - -#ifdef LB_PROF -#include -extern void _start (void), etext (void); -#endif - -#include "glite/security/glite_gss.h" - -#include "il_error.h" - - -extern int log_level; - -static pthread_key_t err_key; - -static int IL_ERR_MSG_LEN = 1024; - -static -void -error_key_delete(void *err) -{ - if(((struct error_inf*)err)->msg) - free(((struct error_inf*)err)->msg); - free(err); -} - -static -void -error_key_create() -{ - pthread_key_create(&err_key, error_key_delete); -} - -static -struct error_inf * -error_get_err () -{ - struct error_inf *err; - - /* get thread specific error structure */ - err = (struct error_inf *)pthread_getspecific(err_key); - assert(err != NULL); - - return(err); -} - - -int -init_errors(int level) -{ - static pthread_once_t error_once = PTHREAD_ONCE_INIT; - struct error_inf *err; - - /* create the key for thread specific error only once */ - pthread_once(&error_once, error_key_create); - - /* there is no thread error yet, try to create one */ - if((err = (struct error_inf *)malloc(sizeof(*err)))) { - /* allocation successfull, make it thread specific data */ - if(pthread_setspecific(err_key, err)) { - free(err); - return(-1); - } - } else - return(-1); - - err->code_maj = 0; - err->code_min = 0; - err->msg = malloc(IL_ERR_MSG_LEN + 1); - if(err->msg == NULL) - return(-1); - - if(level) - log_level = level; - -#ifdef LB_PROF - monstartup((u_long)&_start, (u_long)&etext); -#endif - - return(0); -} - -int -set_error(int code, long minor, char *msg) -{ - struct error_inf *err; - - err = error_get_err(); - - err->code_maj = code; - err->code_min = minor; - - switch(code) { - - case IL_SYS: - snprintf(err->msg, IL_ERR_MSG_LEN, "%s: %s", msg, strerror(err->code_min)); - break; - - case IL_HOST: - snprintf(err->msg, IL_ERR_MSG_LEN, "%s: %s", msg, hstrerror(err->code_min)); - break; - - case IL_DGGSS: - switch(err->code_min) { - - case EDG_WLL_GSS_ERROR_GSS: - snprintf(err->msg, IL_ERR_MSG_LEN, "%s", msg); - break; - - case EDG_WLL_GSS_ERROR_TIMEOUT: - snprintf(err->msg, IL_ERR_MSG_LEN, "%s: Timeout in GSS connection.", msg); - break; - - case EDG_WLL_GSS_ERROR_EOF: - snprintf(err->msg, IL_ERR_MSG_LEN, "%s: Connection lost.", msg); - break; - - case EDG_WLL_GSS_ERROR_ERRNO: - snprintf(err->msg, IL_ERR_MSG_LEN, "%s: %s", msg, strerror(errno)); - break; - - case EDG_WLL_GSS_ERROR_HERRNO: - snprintf(err->msg, IL_ERR_MSG_LEN, "%s: %s", msg, hstrerror(errno)); - break; - } - - default: - strncpy(err->msg, msg, IL_ERR_MSG_LEN); - } - - err->msg[IL_ERR_MSG_LEN] = 0; /* OK, malloc()ed IL_ERR_MSG_LEN + 1 */ - - return(code); -} - - -int -clear_error() { - struct error_inf *err; - - err = error_get_err(); - - err->code_maj = IL_OK; - err->code_min = 0; - *(err->msg) = 0; - - return(0); -} - - -int -error_get_maj() -{ - struct error_inf *err; - - err = error_get_err(); - - return(err->code_maj); -} - - -long -error_get_min() -{ - struct error_inf *err; - - err = error_get_err(); - - return(err->code_min); -} - - -char * -error_get_msg() -{ - struct error_inf *err; - - err = error_get_err(); - - return(err->msg); -} diff --git a/org.glite.lb.logger/src/il_error.h b/org.glite.lb.logger/src/il_error.h deleted file mode 100644 index 09c593e..0000000 --- a/org.glite.lb.logger/src/il_error.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef IL_ERROR_H -#define IL_ERROR_H - -#ident "$Header$" - -#include - -enum err_code_maj { /* minor = */ - IL_OK, /* 0 */ - IL_SYS, /* errno */ - IL_NOMEM, /* ENOMEM */ - IL_PROTO, /* LB_* */ - IL_LBAPI, /* dgLBErrCode */ - IL_DGGSS, /* EDG_WLL_GSS_* */ - IL_HOST /* h_errno */ -}; - -struct error_inf { - int code_maj; - long code_min; - char *msg; -}; - -int init_errors(int); -int set_error(int, long, char *); -int clear_error(); -int error_get_maj(); -long error_get_min(); -char *error_get_msg(); - -int il_log(int, char *, ...); - -#endif diff --git a/org.glite.lb.logger/src/il_master.c b/org.glite.lb.logger/src/il_master.c deleted file mode 100644 index 384c89a..0000000 --- a/org.glite.lb.logger/src/il_master.c +++ /dev/null @@ -1,483 +0,0 @@ -#ident "$Header$" - -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lb/context.h" -#include "glite/lb/events_parse.h" -#include "glite/lb/il_string.h" - -#include "interlogd.h" - -#ifdef LB_PERF -#include "glite/lb/lb_perftest.h" -#endif - -static -int -cmp_jobid(struct server_msg *msg, void *data) -{ - char *job_id_s = (char*)data; - return strcmp(msg->job_id_s, job_id_s) == 0; -} - -static -int -cmp_jobid_set_exp(struct server_msg *msg, void *data) -{ - struct server_msg *m = (struct server_msg *)data; - - if(strcmp(msg->job_id_s, m->job_id_s) == 0) { - msg->expires = m->expires; - } - return 0; -} - - -int -enqueue_msg(struct event_queue *eq, struct server_msg *msg) -{ -#if defined(IL_NOTIFICATIONS) - struct event_queue *eq_known; - - /* now we have a new event with possibly changed destination, - so check for the already known destination and possibly move - events from the original output queue to a new one */ - eq_known = notifid_map_get_dest(msg->job_id_s); - if(eq != eq_known) { - /* client has changed delivery address for this notification */ - if(notifid_map_set_dest(msg->job_id_s, eq) < 0) - return(-1); - /* move all events with this notif_id from eq_known to eq */ - if(eq_known != NULL) { - event_queue_move_events(eq_known, eq, cmp_jobid, msg->job_id_s); - /* XXX - we should kill the old queue too */ - } - } - - /* if the expiration changed, set new one */ - if(msg->expires != notifid_map_get_expiration(msg->job_id_s)) { - notifid_map_set_expiration(msg->job_id_s, msg->expires); - /* set expiration for all events with this notif id */ - event_queue_move_events(eq, NULL, cmp_jobid_set_exp, msg); - } -#endif - - /* fire thread to take care of this queue */ - if(event_queue_create_thread(eq) < 0) - return(-1); - -#if defined(IL_NOTIFICATIONS) - /* if there are no data to send, do not send anything - (messsage was just to change the delivery address) */ - /* CORRECTION - let the message pass through the output queue - to commit it properly and keep event_store in sync */ - /* if(msg->len == 0) - return(0); - */ -#endif - /* avoid losing signal to thread */ - event_queue_cond_lock(eq); - - /* insert new event */ - if(event_queue_insert(eq, msg) < 0) { - event_queue_cond_unlock(eq); - return(-1); - } - - /* signal thread that we have a new message */ - event_queue_signal(eq); - - /* allow thread to continue */ - event_queue_cond_unlock(eq); - - return(0); -} - - -#if defined(INTERLOGD_HANDLE_CMD) && defined(INTERLOGD_FLUSH) -pthread_mutex_t flush_lock = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t flush_cond = PTHREAD_COND_INITIALIZER; -#endif /* INTERLOGD_FLUSH */ - -#ifdef INTERLOGD_HANDLE_CMD -static -int -parse_cmd(char *event, char **job_id_s, long *receipt, int *timeout) -{ - char *token, *r; - int ret; - - if(strstr(event, "DG.TYPE=\"command\"") == NULL) - return(-1); - - *job_id_s = NULL; - *timeout = 0; - *receipt = 0; - ret = 0; - - for(token = strtok(event, " "); token != NULL; token = strtok(NULL, " ")) { - r = index(token, '='); - if(r == NULL) { - ret = -1; - continue; - } - if(strncmp(token, "DG.COMMAND", r - token) == 0) { -#if defined(INTERLOGD_FLUSH) - if(strcmp(++r, "\"flush\"")) { -#endif - il_log(LOG_WARNING, " command %s not implemented\n", r); - ret = -1; - continue; -#if defined(INTERLOGD_FLUSH) - } -#endif - } else if(strncmp(token, "DG.JOBID", r - token) == 0) { - char *p; - - r += 2; /* skip =" */ - p = index(r, '"'); - if(p == NULL) { ret = -1; continue; } - *job_id_s = strndup(r, p-r); - - } else if(strncmp(token, "DG.TIMEOUT", r - token) == 0) { - sscanf(++r, "\"%d\"", timeout); - } else if(strncmp(token, "DG.LLLID", r - token) == 0) { - sscanf(++r, "%ld", receipt); - } - - } - return(0); -} - - -/* return value: - * 0 - not command - * 1 - success - * -1 - failure - */ - -static -int -handle_cmd(il_octet_string_t *event, long offset) -{ - char *job_id_s; - struct event_queue *eq; - int num_replies, num_threads = 0; - int timeout, result; - long receipt; - struct timespec endtime; - struct timeval tv; - - /* parse command */ - if(parse_cmd(event->data, &job_id_s, &receipt, &timeout) < 0) - return(0); - -#if defined(INTERLOGD_FLUSH) - il_log(LOG_DEBUG, " received FLUSH command\n"); - - /* catchup with all neccessary event files */ - if(job_id_s) { - struct event_store *es = event_store_find(job_id_s, NULL); - - if(es == NULL) { - goto cmd_error; - } - result = event_store_recover(es); - /* NOTE: if flush had been stored in file, there would have been - no need to lock the event_store at all */ - event_store_release(es); - if(result < 0) { - il_log(LOG_ERR, " error trying to catch up with event file: %s\n", - error_get_msg()); - clear_error(); - } - } else - /* this call does not fail :-) */ - event_store_recover_all(); - - il_log(LOG_DEBUG, " alerting threads to report status\n"); - - /* prevent threads from reporting too early */ - if(pthread_mutex_lock(&flush_lock) < 0) { - /*** this error is considered too serious to allow the program run anymore! - set_error(IL_SYS, errno, "pthread_mutex_lock: error locking flush lock"); - goto cmd_error; - */ - abort(); - } - - /* wake up all threads */ - if(job_id_s) { - /* find appropriate queue */ - eq = queue_list_get(job_id_s); - if(eq == NULL) goto cmd_error; - if(!event_queue_empty(eq) && !queue_list_is_log(eq)) { - num_threads++; - event_queue_cond_lock(eq); - eq->flushing = 1; - event_queue_wakeup(eq); - event_queue_cond_unlock(eq); - } - } else { - /* iterate over event queues */ - for(eq=queue_list_first(); eq != NULL; eq=queue_list_next()) { - if(!event_queue_empty(eq) && !queue_list_is_log(eq)) { - num_threads++; - event_queue_cond_lock(eq); - eq->flushing = 1; - event_queue_wakeup(eq); - event_queue_cond_unlock(eq); - } - } - } - if(!bs_only) { - eq = queue_list_get(NULL); - if(eq == NULL) goto cmd_error; - if(!event_queue_empty(eq)) { - num_threads++; - event_queue_cond_lock(eq); - eq->flushing = 1; - event_queue_wakeup(eq); - event_queue_cond_unlock(eq); - } - } - - /* wait for thread replies */ - num_replies = 0; - result = 1; - gettimeofday(&tv, NULL); - endtime.tv_sec = tv.tv_sec + timeout; - endtime.tv_nsec = 1000 * tv.tv_usec; - while(num_replies < num_threads) { - int ret; - if((ret=pthread_cond_timedwait(&flush_cond, &flush_lock, &endtime)) < 0) { - il_log(LOG_ERR, " error waiting for thread reply: %s\n", strerror(errno)); - result = (ret == ETIMEDOUT) ? 0 : -1; - break; - } - - /* collect results from reporting threads */ - if(job_id_s) { - /* find appropriate queue */ - eq = queue_list_get(job_id_s); - if(eq == NULL) goto cmd_error; - if(!queue_list_is_log(eq)) { - event_queue_cond_lock(eq); - if(eq->flushing == 2) { - eq->flushing = 0; - num_replies++; - result = ((result == 1) || (eq->flush_result < 0)) ? - eq->flush_result : result; - } - event_queue_cond_unlock(eq); - } - } else { - /* iterate over event queues */ - for(eq=queue_list_first(); eq != NULL; eq=queue_list_next()) { - if(!queue_list_is_log(eq)) { - event_queue_cond_lock(eq); - if(eq->flushing == 2) { - eq->flushing = 0; - num_replies++; - il_log(LOG_DEBUG, " thread reply: %d\n", eq->flush_result); - result = ((result == 1) || (eq->flush_result < 0)) ? - eq->flush_result : result; - } - event_queue_cond_unlock(eq); - } - } - } - if(!bs_only) { - eq = queue_list_get(NULL); - if(eq == NULL) goto cmd_error; - event_queue_cond_lock(eq); - if(eq->flushing == 2) { - eq->flushing = 0; - num_replies++; - result = ((result == 1) || (eq->flush_result < 0)) ? - eq->flush_result : result; - } - event_queue_cond_unlock(eq); - } - } - - /* prevent deadlock in next flush */ - if(pthread_mutex_unlock(&flush_lock) < 0) - abort(); - - - /* report back to local logger */ - switch(result) { - case 1: - result = 0; break; - case 0: - result = EDG_WLL_IL_EVENTS_WAITING; break; - default: - result = EDG_WLL_IL_SYS; break; - } - if(job_id_s) free(job_id_s); - result = send_confirmation(receipt, result); - if(result <= 0) - il_log(LOG_ERR, "handle_cmd: error sending status: %s\n", error_get_msg()); - return(1); - - -cmd_error: - if(job_id_s) free(job_id_s); - return(-1); -#else - return(0); -#endif /* INTERLOGD_FLUSH */ -} -#endif /* INTERLOGD_HANDLE_CMD */ - - -static -int -handle_msg(il_octet_string_t *event, long offset) -{ - struct server_msg *msg = NULL; -#if !defined(IL_NOTIFICATIONS) - struct event_queue *eq_l; -#endif - struct event_queue *eq_s; - struct event_store *es; - - int ret; - - /* convert event to message for server */ - if((msg = server_msg_create(event, offset)) == NULL) { - il_log(LOG_ERR, " handle_msg: error parsing event '%s':\n %s\n", event, error_get_msg()); - return(0); - } - - /* sync event store with IPC (if neccessary) - * This MUST be called before inserting event into output queue! */ - if((es = event_store_find(msg->job_id_s, NULL)) == NULL) - return(-1); - msg->es = es; - -#ifdef LB_PERF - if(nosync) - ret = 1; - else -#endif - ret = event_store_sync(es, offset); - /* no longer informative: - il_log(LOG_DEBUG, " syncing event store at %d with event at %d, result %d\n", es->offset, offset, ret); - */ - if(ret < 0) { - il_log(LOG_ERR, " handle_msg: error syncing event store:\n %s\n", error_get_msg()); - /* XXX should error during event store recovery cause us to drop the message? */ - /* Probably no, because the attempt to recover means we have missed some events, - and delivery of this one will not move offset ahead. So try our best and deliver it - even if it may cause duplicates on server. */ - /* COMMENTED OUT: uncommented again */ - server_msg_free(msg); - event_store_release(es); - return(0); - /* */ - } else if(ret == 0) { - /* we have seen this event already */ - server_msg_free(msg); - event_store_release(es); - return(1); - } - - /* find apropriate queue for this event */ -#if defined(IL_NOTIFICATIONS) - eq_s = queue_list_get(msg->dest); -#else - eq_s = queue_list_get(msg->job_id_s); -#endif - if(eq_s == NULL) { - il_log(LOG_ERR, " handle_msg: apropriate queue not found: %s\n", error_get_msg()); - clear_error(); - } else { - if(enqueue_msg(eq_s, msg) < 0) - goto err; - } - -#if !defined(IL_NOTIFICATIONS) - eq_l = queue_list_get(NULL); - if(!bs_only && eq_l != eq_s) { - /* send to default queue (logging server) as well */ - if(enqueue_msg(eq_l, msg) < 0) - goto err; - } -#endif - - /* if there was no error, set the next expected event offset */ - event_store_next(es, offset, msg->ev_len); - - /* allow cleanup thread to check on this event_store */ - event_store_release(es); - - /* free the message */ - server_msg_free(msg); - return(1); - -err: - event_store_release(es); - server_msg_free(msg); - return(-1); -} - - - -int -loop() -{ - /* receive events */ - while(1) { - il_octet_string_t *msg; - long offset; - int ret; - - if(killflg) - exit(0); - - clear_error(); - if((ret = input_queue_get(&msg, &offset, INPUT_TIMEOUT)) < 0) - { - if(error_get_maj() == IL_PROTO) { - il_log(LOG_DEBUG, " premature EOF while receiving event\n"); - /* problems with socket input, try to catch up from files */ -#ifndef PERF_EMPTY - event_store_recover_all(); -#endif - continue; - } else - return(-1); - } - else if(ret == 0) { - continue; - } - -#ifdef PERF_EMPTY - glite_wll_perftest_consumeEventString(msg->data); - free(msg->data); - continue; -#endif - -#ifdef INTERLOGD_HANDLE_CMD - ret = handle_cmd(msg, offset); - if(ret == 0) -#endif - ret = handle_msg(msg, offset); - if(msg->data) free(msg->data); - if(ret < 0) - switch (error_get_maj()) { - case IL_SYS: - case IL_NOMEM: - return (ret); - break; - default: - il_log(LOG_ERR, "Error: %s\n", error_get_msg()); - break; - } - } /* while */ -} diff --git a/org.glite.lb.logger/src/input_queue_socket.c b/org.glite.lb.logger/src/input_queue_socket.c deleted file mode 100644 index 05a0034..0000000 --- a/org.glite.lb.logger/src/input_queue_socket.c +++ /dev/null @@ -1,323 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include - -#include "interlogd.h" - - -static const int SOCK_QUEUE_MAX = 50; -extern char *socket_path; - -static int sock; -static int accepted; - -int -input_queue_attach() -{ - struct sockaddr_un saddr; - - if((sock=socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { - set_error(IL_SYS, errno, "input_queue_attach: error creating socket"); - return(-1); - } - - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, socket_path); - - /* test for the presence of the socket and another instance - of interlogger listening */ - if(connect(sock, (struct sockaddr *)&saddr, sizeof(saddr.sun_path)) < 0) { - if(errno == ECONNREFUSED) { - /* socket present, but no one at the other end; remove it */ - il_log(LOG_WARNING, " removing stale input socket %s\n", socket_path); - unlink(socket_path); - } - /* ignore other errors for now */ - } else { - /* connection was successful, so bail out - there is - another interlogger running */ - set_error(IL_SYS, EADDRINUSE, "input_queue_attach: another instance of interlogger is running"); - return(-1); - } - - if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { - set_error(IL_SYS, errno, "input_queue_attach: error binding socket"); - return(-1); - } - - if (listen(sock, SOCK_QUEUE_MAX)) { - set_error(IL_SYS, errno, "input_queue_attach: error listening on socket"); - return -1; - } - - return(0); -} - -void input_queue_detach() -{ - if (sock >= 0) - close(sock); - unlink(socket_path); -} - - -#define DEFAULT_CHUNK_SIZE 1024 - -static -int -read_event(int sock, long *offset, il_octet_string_t *msg) -{ - char *buffer, *p, *n; - int len, alen, i, chunk_size = DEFAULT_CHUNK_SIZE; - static char buf[1024]; - - msg->data = NULL; - msg->len = 0; - - /* receive offset */ - len = recv(sock, offset, sizeof(*offset), MSG_NOSIGNAL); - if(len < sizeof(*offset)) { - set_error(IL_PROTO, errno, "read_event: error reading offset"); - return(-1); - } - - /* receive event string */ - buffer=malloc(8*chunk_size); - if(buffer == NULL) { - set_error(IL_NOMEM, ENOMEM, "read_event: no room for event"); - return(-1); - } - p = buffer; - alen = 8*chunk_size; - - /* Variables used here: - - buffer points to allocated memory, - - alen is the allocated memory size, - - p points to the first free location in buffer, - - len is the amount actually read by recv, - - i is the amount of data belonging to the current event (including separator). - - n points to event separator or is NULL - Hence: - (p - buffer) gives the amount of valid data read so far, - (alen - (p - buffer)) is the free space, - */ - -#if 1 - /* Reading events - optimized version. Attempts to increase chunks read by recv - * when there are more data, reads directly into destination memory (instead of - * copying from static buffer) etc. - * - * For some reason it is not much faster than the old variant. - */ - do { - /* prepare at least chunk_size bytes for next data */ - if(alen - (p - buffer) < chunk_size) { - alen += (chunk_size < 8192) ? 8192 : 8*chunk_size; - n = realloc(buffer, alen); - if(n == NULL) { - free(buffer); - set_error(IL_NOMEM, ENOMEM, "read_event: no room for event"); - return(-1); - } - p = n + (p - buffer); - buffer = n; - } - - /* read chunk */ - if((len=recv(sock, p, chunk_size, MSG_PEEK | MSG_NOSIGNAL)) > 0) { - /* find the end of event, if any */ - /* faster (and dirty) way of doing strnchr (which is not in libc, anyway) */ - if((n=memccpy(p, p, EVENT_SEPARATOR, len)) != NULL) { - i = n - p; /* length including separator */ - } else { - i = len; - /* long event, huh? try reading more data at once */ - chunk_size += 1024; - } - /* remove the relevant data from input */ - /* i > 0 */ - if(recv(sock, p, i, MSG_NOSIGNAL) != i) { - set_error(IL_SYS, errno, "read_event: error reading data"); - free(buffer); - return(-1); - } - /* move the pointer to the first free place, separator is considered free space */ - p = (n == NULL) ? p + len : n - 1; - } - } while ( (len > 0) && (n == NULL) ); - -#else - /* Reading events - original version. - * Appears to behave quite good, anyway. - */ - while((len=recv(sock, buf, sizeof(buf), MSG_PEEK | MSG_NOSIGNAL)) > 0) { - - /* we have to be prepared for sizeof(buf) bytes */ - if(alen - (p - buffer) < (int)sizeof(buf)) { - alen += 8192; - n = realloc(buffer, alen); - if(n == NULL) { - free(buffer); - set_error(IL_NOMEM, ENOMEM, "read_event: no room for event"); - return(-1); - } - p = p - buffer + n; - buffer = n; - } - - /* copy all relevant bytes from buffer */ - n = (char*)memccpy(p, buf, EVENT_SEPARATOR, len); - if(n) { - /* separator found */ - n--; /* but do not preserve it */ - i = n - p; - p = n; - } else { - /* separator not found */ - i = len; - p += len; - } - /* This was definitely slowing us down: - * for(i=0; (i < len) && (buf[i] != EVENT_SEPARATOR); i++) - * *p++ = buf[i]; - */ - - /* remove the data from queue */ - if(i > 0) - if(recv(sock, buf, i, MSG_NOSIGNAL) != i) { - set_error(IL_SYS, errno, "read_event: error reading data"); - free(buffer); - return(-1); - } - if(i < len) - /* the event is complete */ - break; - } -#endif - - /* terminate buffer */ - *p = 0; - - if(len < 0) { - set_error(IL_SYS, errno, "read_event: error reading data"); - free(buffer); - return(-1); - } - - /* if len == 0, we have not encountered EVENT_SEPARATOR and thus the event is not complete */ - if(len == 0) { - set_error(IL_PROTO, errno, "read_event: error reading data - premature EOF"); - free(buffer); - return(-1); - } - -#if 0 - /* this is probably not necessary at all: - either len <=0, which was covered before, - or 0 <= i < len => p > buffer; - I would say this condition can not be satisfied. - */ - if(p == buffer) { - set_error(IL_PROTO, errno, "read_event: error reading data - no data received"); - free(buffer); - return(-1); - } -#endif - - msg->data = buffer; - msg->len = p - buffer; - return(msg->len); -} - - -/* - * Returns: -1 on error, 0 if no message available, message length otherwise - * - */ -#ifdef PERF_EVENTS_INLINE -int -input_queue_get(il_octet_string **buffer, long *offset, int timeout) -{ - static long o = 0; - int len; - char *jobid; - static il_octet_string_t my_buffer; - - assert(buffer != NULL); - - *buffer = &my_buffer; - - len = glite_wll_perftest_produceEventString(&my_buffer.data, &jobid); - my_buffer.len = len; - if(len) { - o += len; - *offset = o; - } else if (len == 0) { - sleep(timeout); - } - return(len); -} -#else -int -input_queue_get(il_octet_string_t **buffer, long *offset, int timeout) -{ - fd_set fds; - struct timeval tv; - int msg_len; - static il_octet_string_t my_buffer; - - assert(buffer != NULL); - - *buffer = &my_buffer; - - FD_ZERO(&fds); - FD_SET(sock, &fds); - - tv.tv_sec = timeout; - tv.tv_usec = 0; - - msg_len = select(sock + 1, &fds, NULL, NULL, timeout >= 0 ? &tv : NULL); - switch(msg_len) { - - case 0: /* timeout */ - return(0); - - case -1: /* error */ - switch(errno) { - case EINTR: - il_log(LOG_DEBUG, " interrupted while waiting for event!\n"); - return(0); - - default: - set_error(IL_SYS, errno, "input_queue_get: error waiting for event"); - return(-1); - } - default: - break; - } - - if((accepted=accept(sock, NULL, NULL)) < 0) { - set_error(IL_SYS, errno, "input_queue_get: error accepting connection"); - return(-1); - } - - read_event(accepted, offset, &my_buffer); - close(accepted); - - if(my_buffer.data == NULL) { - if(error_get_maj() != IL_OK) - return(-1); - else - return(0); - } - - return(my_buffer.len); -} -#endif diff --git a/org.glite.lb.logger/src/input_queue_socket_http.c b/org.glite.lb.logger/src/input_queue_socket_http.c deleted file mode 100644 index 939c45f..0000000 --- a/org.glite.lb.logger/src/input_queue_socket_http.c +++ /dev/null @@ -1,167 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "interlogd.h" - -static const int SOCK_QUEUE_MAX = 50; -extern char *socket_path; -extern char *file_prefix; - -static int sock; -static int accepted; - -static -int plain_reader(void *user_data, char *buffer, const int len) -{ - return (recv(*(int*)user_data, buffer, len, MSG_NOSIGNAL)); -} - - -int -input_queue_attach() -{ - struct sockaddr_un saddr; - - if((sock=socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { - set_error(IL_SYS, errno, "input_queue_attach: error creating socket"); - return(-1); - } - - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, socket_path); - - /* test for the presence of the socket and another instance - of interlogger listening */ - if(connect(sock, (struct sockaddr *)&saddr, sizeof(saddr.sun_path)) < 0) { - if(errno == ECONNREFUSED) { - /* socket present, but no one at the other end; remove it */ - il_log(LOG_WARNING, " removing stale input socket %s\n", socket_path); - unlink(socket_path); - } - /* ignore other errors for now */ - } else { - /* connection was successful, so bail out - there is - another interlogger running */ - set_error(IL_SYS, EADDRINUSE, "input_queue_attach: another instance of interlogger is running"); - return(-1); - } - - if(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) { - set_error(IL_SYS, errno, "input_queue_attach: error binding socket"); - return(-1); - } - - if (listen(sock, SOCK_QUEUE_MAX)) { - set_error(IL_SYS, errno, "input_queue_attach: error listening on socket"); - return -1; - } - - return(0); -} - - -void input_queue_detach() -{ - if (sock >= 0) - close(sock); - unlink(socket_path); -} - - - -/* - * Returns: -1 on error, 0 if no message available, message length otherwise - * - */ -#ifdef PERF_EVENTS_INLINE -int -input_queue_get(il_octet_string_t **buffer, long *offset, int timeout) -{ - static long o = 0; - int len; - char *jobid; - static il_octet_string_t my_buffer; - - assert(buffer != NULL); - - *buffer = &my_buffer; - - len = glite_wll_perftest_produceEventString(&my_buffer.data, &jobid); - my_buffer.len = len; - if(len) { - o += len; - *offset = o; - } else if (len == 0) { - sleep(timeout); - } - return(len); -} -#else -int -input_queue_get(il_octet_string_t **buffer, long *offset, int timeout) -{ - fd_set fds; - struct timeval tv; - int msg_len; - static il_http_message_t msg; - - assert(buffer != NULL); - - *buffer = (il_octet_string_t *)&msg; - - FD_ZERO(&fds); - FD_SET(sock, &fds); - - tv.tv_sec = timeout; - tv.tv_usec = 0; - - msg_len = select(sock + 1, &fds, NULL, NULL, timeout >= 0 ? &tv : NULL); - switch(msg_len) { - - case 0: /* timeout */ - return(0); - - case -1: /* error */ - switch(errno) { - case EINTR: - il_log(LOG_DEBUG, " interrupted while waiting for event!\n"); - return(0); - - default: - set_error(IL_SYS, errno, "input_queue_get: error waiting for event"); - return(-1); - } - default: - break; - } - - if((accepted=accept(sock, NULL, NULL)) < 0) { - set_error(IL_SYS, errno, "input_queue_get: error accepting connection"); - return(-1); - } - - msg_len = receive_http(&accepted, plain_reader, &msg); - - if(msg_len < 0) { - close(accepted); - if(error_get_maj() != IL_OK) - return -1; - else - return 0; - } - - close(accepted); - *offset = -1; - return(msg.len); -} -#endif - diff --git a/org.glite.lb.logger/src/interlogd.c b/org.glite.lb.logger/src/interlogd.c deleted file mode 100644 index e6ebded..0000000 --- a/org.glite.lb.logger/src/interlogd.c +++ /dev/null @@ -1,405 +0,0 @@ -#ident "$Header$" - -/* - interlogger - collect events from local-logger and send them to logging and bookkeeping servers - -*/ -#include -#include -#include -#include -#include -#include - -#include "interlogd.h" -#include "glite/lb/log_proto.h" -#include "glite/security/glite_gss.h" -#ifdef LB_PERF -#include "glite/lb/lb_perftest.h" -#endif - -#define EXIT_FAILURE 1 -#if defined(IL_NOTIFICATIONS) -#define DEFAULT_PREFIX "/tmp/notif_events" -#define DEFAULT_SOCKET "/tmp/notif_interlogger.sock" -#else -#define DEFAULT_PREFIX EDG_WLL_LOG_PREFIX_DEFAULT -#define DEFAULT_SOCKET "/tmp/interlogger.sock" -#endif - - -/* The name the program was run with, stripped of any leading path. */ -char *program_name; -int killflg = 0; - -int TIMEOUT = DEFAULT_TIMEOUT; - -cred_handle_t *cred_handle = NULL; -pthread_mutex_t cred_handle_lock = PTHREAD_MUTEX_INITIALIZER; - -time_t key_mtime = 0, cert_mtime = 0; - -static void usage (int status) -{ - printf("%s - \n" - " collect events from local-logger and send them to logging and bookkeeping servers\n" - "Usage: %s [OPTION]... [FILE]...\n" - "Options:\n" - " -h, --help display this help and exit\n" - " -V, --version output version information and exit\n" - " -d, --debug do not run as daemon\n" - " -v, --verbose print extensive debug output\n" - " -f, --file-prefix path and prefix for event files\n" - " -c, --cert location of server certificate\n" - " -k, --key location of server private key\n" - " -C, --CAdir directory containing CA certificates\n" - " -b, --book send events to bookkeeping server only\n" - " -l, --log-server specify address of log server\n" - " -s, --socket non-default path of local socket\n" - " -L, --lazy [] be lazy when closing connections to servers (default, timeout==0 means turn lazy off)\n" - " -p, --parallel [] use parallel streams to the same server\n" -#ifdef LB_PERF - " -n, --nosend PERFTEST: consume events instead of sending\n" - " -S, --nosync PERFTEST: do not check logd files for lost events\n" - " -R, --norecover PERFTEST: do not start recovery thread\n" - " -P, --noparse PERFTEST: do not parse messages, use built-in server address\n" -#ifdef PERF_EVENTS_INLINE - " -e, --event_file PERFTEST: file to read test events from\n" - " -j, --njobs PERFTEST: number of jobs to send\n" -#endif -#endif - , program_name, program_name); - exit(status); -} - - -/* Option flags and variables */ -static int debug; -static int verbose = 0; -char *file_prefix = DEFAULT_PREFIX; -int bs_only = 0; -int lazy_close = 1; -int default_close_timeout; -size_t max_store_size; -int parallel = 0; -#ifdef LB_PERF -int nosend = 0, norecover=0, nosync=0, noparse=0; -char *event_source = NULL; -int njobs = 0; -#endif - -char *cert_file = NULL; -char *key_file = NULL; -char *CAcert_dir = NULL; -char *log_server = NULL; -char *socket_path = DEFAULT_SOCKET; - -static struct option const long_options[] = -{ - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {"verbose", no_argument, 0, 'v'}, - {"debug", no_argument, 0, 'd'}, - {"file-prefix", required_argument, 0, 'f'}, - {"cert", required_argument, 0, 'c'}, - {"key", required_argument, 0, 'k'}, - {"book", no_argument, 0, 'b'}, - {"CAdir", required_argument, 0, 'C'}, - {"log-server", required_argument, 0, 'l'}, - {"socket", required_argument, 0, 's'}, - {"lazy", optional_argument, 0, 'L'}, - {"max-store", required_argument, 0, 'M'}, - {"parallel", optional_argument, 0, 'p'}, -#ifdef LB_PERF - {"nosend", no_argument, 0, 'n'}, - {"nosync", no_argument, 0, 'S'}, - {"norecover", no_argument, 0, 'R'}, - {"noparse", no_argument, 0, 'P'}, -#ifdef PERF_EVENTS_INLINE - {"event_file", required_argument, 0, 'e'}, - {"njobs", required_argument, NULL, 'j'}, -#endif -#endif - {NULL, 0, NULL, 0} -}; - - - -/* Set all the option flags according to the switches specified. - Return the index of the first non-option argument. */ -static int -decode_switches (int argc, char **argv) -{ - int c; - - debug = 0; - - while ((c = getopt_long (argc, argv, - "f:" /* file prefix */ - "h" /* help */ - "V" /* version */ - "v" /* verbose */ - "c:" /* certificate */ - "k:" /* key */ - "C:" /* CA dir */ - "b" /* only bookeeping */ - "l:" /* log server */ - "d" /* debug */ - "p" /* parallel */ -#ifdef LB_PERF - "n" /* nosend */ - "S" /* nosync */ - "R" /* norecover */ - "P" /* noparse */ -#ifdef PERF_EVENTS_INLINE - "e:" /* event file */ - "j:" /* num jobs */ -#endif -#endif - "L::" /* lazy */ - "s:" /* socket */ - "M:" /* max-store */, - long_options, (int *) 0)) != EOF) - { - switch (c) - { - case 'V': - printf ("interlogger %s\n", VERSION); - exit (0); - - case 'v': - verbose = 1; - break; - - case 'h': - usage (0); - - case 'd': - debug = 1; - break; - - case 'f': - file_prefix = strdup(optarg); - break; - - case 'c': - cert_file = strdup(optarg); - break; - - case 'k': - key_file = strdup(optarg); - break; - - case 'b': - bs_only = 1; - break; - - case 'l': - log_server = strdup(optarg); - break; - - case 'C': - CAcert_dir = strdup(optarg); - break; - - case 's': - socket_path = strdup(optarg); - break; - - case 'L': - lazy_close = 1; - if(optarg) - default_close_timeout = atoi(optarg); - if(default_close_timeout == 0) { - default_close_timeout = TIMEOUT; - lazy_close = 0; - } - else - default_close_timeout = TIMEOUT; - break; - - case 'M': - max_store_size = atoi(optarg); - break; - - case 'p': - if(optarg) - parallel = atoi(optarg); - else - parallel = 4; - break; - -#ifdef LB_PERF - case 'n': - nosend = 1; - break; - - case 'R': - norecover = 1; - break; - - case 'S': - nosync = 1; - break; - - case 'P': - noparse = 1; - break; - -#ifdef PERF_EVENTS_INLINE - case 'e': - event_source = strdup(optarg); - break; - - case 'j': - njobs = atoi(optarg); - break; -#endif -#endif - - default: - usage (EXIT_FAILURE); - } - } - - return optind; -} - - -void handle_signal(int num) { - il_log(LOG_DEBUG, "Received signal %d\n", num); - killflg++; -} - - -int -main (int argc, char **argv) -{ - int i; - char *p; - edg_wll_GssStatus gss_stat; - int ret; - - program_name = argv[0]; - - setlinebuf(stdout); - setlinebuf(stderr); - - if ((p = getenv("EDG_WL_INTERLOG_TIMEOUT"))) TIMEOUT = atoi(p); - - i = decode_switches (argc, argv); - - /* force -b if we do not have log server */ - if(log_server == NULL) { - log_server = strdup(DEFAULT_LOG_SERVER); - bs_only = 1; - } - - if(init_errors(verbose ? LOG_DEBUG : LOG_WARNING)) { - fprintf(stderr, "Failed to initialize error message subsys. Exiting.\n"); - exit(EXIT_FAILURE); - } - - if (signal(SIGPIPE, SIG_IGN) == SIG_ERR - || signal(SIGABRT, handle_signal) == SIG_ERR - || signal(SIGTERM, handle_signal) == SIG_ERR - || signal(SIGINT, handle_signal) == SIG_ERR) { - perror("signal"); - exit(EXIT_FAILURE); - } - - if(!debug && - (daemon(0,0) < 0)) { - perror("daemon"); - exit(EXIT_FAILURE); - } - -#ifdef LB_PERF - /* this must be called after installing signal handlers */ - glite_wll_perftest_init(NULL, /* host */ - NULL, /* user */ - NULL, /* test name */ - event_source, - njobs); -#endif - - il_log(LOG_INFO, "Initializing input queue...\n"); - if(input_queue_attach() < 0) { - il_log(LOG_CRIT, "Failed to initialize input queue: %s\n", error_get_msg()); - exit(EXIT_FAILURE); - } - - /* initialize output queues */ - il_log(LOG_INFO, "Initializing event queues...\n"); - if(queue_list_init(log_server) < 0) { - il_log(LOG_CRIT, "Failed to initialize output event queues: %s\n", error_get_msg()); - exit(EXIT_FAILURE); - } - if(lazy_close) - il_log(LOG_DEBUG, " using lazy mode when closing connections, timeout %d\n", - default_close_timeout); - - /* get credentials */ - if (CAcert_dir) - setenv("X509_CERT_DIR", CAcert_dir, 1); - edg_wll_gss_watch_creds(cert_file,&cert_mtime); - cred_handle = malloc(sizeof(*cred_handle)); - if(cred_handle == NULL) { - il_log(LOG_CRIT, "Failed to allocate structure for credentials.\n"); - exit(EXIT_FAILURE); - } - cred_handle->creds = NULL; - cred_handle->counter = 0; - ret = edg_wll_gss_acquire_cred_gsi(cert_file, key_file, &cred_handle->creds, &gss_stat); - if (ret) { - char *gss_err = NULL; - char *str; - - if (ret == EDG_WLL_GSS_ERROR_GSS) - edg_wll_gss_get_error(&gss_stat, "edg_wll_gss_acquire_cred_gsi()", &gss_err); - asprintf(&str, "Failed to load GSI credential: %s\n", - (gss_err) ? gss_err : "edg_wll_gss_acquire_cred_gsi() failed"); - il_log(LOG_CRIT, str); - free(str); - if (gss_err) - free(gss_err); - exit(EXIT_FAILURE); - } - -#ifndef PERF_EMPTY - /* find all unsent events waiting in files */ -#ifdef LB_PERF - if(norecover) { - if(event_store_init(file_prefix) < 0) { - il_log(LOG_CRIT, "Failed to init event stores: %s\n", error_get_msg()); - exit(EXIT_FAILURE); - } - } else -#endif - { - pthread_t rid; - - il_log(LOG_INFO, "Starting recovery thread...\n"); - if(pthread_create(&rid, NULL, recover_thread, NULL) < 0) { - il_log(LOG_CRIT, "Failed to start recovery thread: %s\n", strerror(errno)); - exit(EXIT_FAILURE); - } - pthread_detach(rid); - } -#endif - - il_log(LOG_INFO, "Entering main loop...\n"); - - /* do the work */ - if(loop() < 0) { - il_log(LOG_CRIT, "Fatal error: %s\n", error_get_msg()); - if (killflg) { - input_queue_detach(); - exit(EXIT_FAILURE); - } - } - il_log(LOG_INFO, "Done!\n"); - input_queue_detach(); - - exit (0); -} diff --git a/org.glite.lb.logger/src/interlogd.h b/org.glite.lb.logger/src/interlogd.h deleted file mode 100644 index b2fdde4..0000000 --- a/org.glite.lb.logger/src/interlogd.h +++ /dev/null @@ -1,270 +0,0 @@ -#ifndef INTERLOGGER_P_H -#define INTERLOGGER_P_H - -#ident "$Header$" - -#include "il_error.h" -#include "glite/security/glite_gss.h" -#include "glite/lb/il_msg.h" - -#include -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#ifdef HAVE_DMALLOC_H -#include -#endif - -#define INTERLOGD_HANDLE_CMD -#define INTERLOGD_FLUSH -#define INTERLOGD_EMS - -#define DEFAULT_USER "michal" -#define DEFAULT_LOG_SERVER "localhost" -#define DEFAULT_TIMEOUT 60 - -#ifdef LB_PERF -#include "glite/lb/lb_perftest.h" -#endif - -#if defined(IL_NOTIFICATIONS) - -#include "glite/lb/notifid.h" - -#undef INTERLOGD_HANDLE_CMD -#undef INTERLOGD_FLUSH -#undef INTERLOGD_EMS -#define IL_EVENT_ID_T edg_wll_NotifId -#define IL_EVENT_GET_UNIQUE(a) edg_wll_NotifIdGetUnique((a)) -#define IL_EVENT_ID_FREE(a) edg_wll_NotifIdFree((a)) -#define IL_EVENT_ID_PARSE(a,b) edg_wll_NotifIdParse((a),(b)) - -#else - -#define INTERLOGD_HANDLE_CMD -#define INTERLOGD_FLUSH -#define INTERLOGD_EMS -#define IL_EVENT_ID_T edg_wlc_JobId -#define IL_EVENT_GET_UNIQUE(a) edg_wlc_JobIdGetUnique((a)) -#define IL_EVENT_ID_FREE(a) edg_wlc_JobIdFree((a)) -#define IL_EVENT_ID_PARSE(a,b) edg_wlc_JobIdParse((a),(b)) - -#endif - - -#define EVENT_SEPARATOR '\n' - -// #define TIMEOUT 5 -extern int TIMEOUT; -#define INPUT_TIMEOUT (60) -#define EXIT_TIMEOUT (1*60) - -typedef struct cred_handle { - edg_wll_GssCred creds; - int counter; -} cred_handle_t; -extern cred_handle_t *cred_handle; - -extern pthread_mutex_t cred_handle_lock; -extern pthread_key_t cred_handle_key; -extern char *cert_file; -extern char *key_file; -extern char *CAcert_dir; -extern int bs_only; -extern int killflg; -extern int lazy_close; -extern int default_close_timeout; -extern size_t max_store_size; -extern int parallel; -#ifdef LB_PERF -extern int nosend, nosync, norecover, noparse; -#ifdef PERF_EVENTS_INLINE -extern char *event_source; -#endif -#endif - -/* shared data for thread communication */ -#ifdef INTERLOGD_FLUSH -extern pthread_mutex_t flush_lock; -extern pthread_cond_t flush_cond; -#endif - -typedef struct { - /* il_octet_string_t */ - int len; - char *data; - /* http message specific */ - enum { IL_HTTP_OTHER, - IL_HTTP_GET, - IL_HTTP_POST, - IL_HTTP_REPLY - } msg_type; - int reply_code; - char *reply_string; - size_t content_length; - char *host; -} il_http_message_t; - -/* this struct can be passed instead of il_octet_string as parameter */ -typedef union { - il_octet_string_t bin_msg; - il_http_message_t http_msg; -} il_message_t; - - -struct event_store { - char *event_file_name; /* file with events from local logger */ - char *control_file_name; /* file with control information */ - char *job_id_s; /* string form of the job id */ - long last_committed_bs; /* offset behind event that was last committed by BS */ - long last_committed_ls; /* -"- LS */ - long offset; /* expected file position of next event */ - time_t last_modified; /* time of the last file modification */ - int generation; /* cleanup counter, scopes the offset */ - long long rotate_index; /* rotation counter */ - struct event_store_list *le; /* points back to the list */ - pthread_rwlock_t commit_lock; /* lock to prevent simultaneous updates to last_committed_* */ - pthread_rwlock_t offset_lock; /* lock to prevent simultaneous updates offset */ - pthread_rwlock_t use_lock; /* lock to prevent struct deallocation */ -#if defined(IL_NOTIFICATIONS) - char *dest; /* host:port destination */ -#endif -}; - - -struct server_msg { - char *job_id_s; /* necessary for commit */ - long offset; /* just for printing more information to debug */ - char *msg; - int len; - int ev_len; - struct event_store *es; /* cache for corresponding event store */ - int generation; /* event store genereation */ - long receipt_to; /* receiver (long local-logger id - LLLID) of delivery confirmation (for priority messages) */ -#if defined(IL_NOTIFICATIONS) - char *dest_name; - int dest_port; - char *dest; -#endif - time_t expires; /* time (in seconds from epoch) the message expires */ -}; - - -struct event_queue { - edg_wll_GssConnection gss; /* GSS connection */ - char *dest_name; - int dest_port; - int timeout; /* queue timeout */ - struct event_queue_msg *tail; /* last message in the queue */ - struct event_queue_msg *head; /* first message in the queue */ -#if defined(INTERLOGD_EMS) - struct event_queue_msg *tail_ems; /* last priority message in the queue (or NULL) */ - struct event_queue_msg *mark_this; /* mark message for removal */ - struct event_queue_msg *mark_prev; /* predecessor of the marked message */ -#endif - pthread_t thread_id; /* id of associated thread */ - pthread_rwlock_t update_lock; /* mutex for queue updates */ - pthread_mutex_t cond_lock; /* mutex for condition variable */ - pthread_cond_t ready_cond; /* condition variable for message arrival */ -#if defined(INTERLOGD_HANDLE_CMD) && defined(INTERLOGD_FLUSH) - int flushing; - int flush_result; /* result of flush operation */ - pthread_cond_t flush_cond; /* condition variable for flush operation */ -#endif - /* statistics */ - int times_empty; /* number of times the queue was emptied */ - int max_len; /* max queue length */ - int cur_len; /* current length */ -}; - - -/* credential destructor */ -void cred_handle_destroy(void *); - -/* server msg methods */ -struct server_msg *server_msg_create(il_octet_string_t *, long); -struct server_msg *server_msg_copy(struct server_msg *); -int server_msg_init(struct server_msg *, il_octet_string_t *); -#if defined(INTERLOGD_EMS) -int server_msg_is_priority(struct server_msg *); -#endif -int server_msg_free(struct server_msg *); - -/* general event queue methods */ -struct event_queue *event_queue_create(char *); -int event_queue_free(struct event_queue *); -int event_queue_empty(struct event_queue *); -int event_queue_insert(struct event_queue *, struct server_msg *); -int event_queue_get(struct event_queue *, struct server_msg **); -int event_queue_remove(struct event_queue *); -int event_queue_enqueue(struct event_queue *, char *); -/* helper */ -int enqueue_msg(struct event_queue *, struct server_msg *); -int event_queue_move_events(struct event_queue *, struct event_queue *, int (*)(struct server_msg *, void *), void *); - -/* protocol event queue methods */ -int event_queue_connect(struct event_queue *); -int event_queue_send(struct event_queue *); -int event_queue_close(struct event_queue *); -int send_confirmation(long, int); - -/* thread event queue methods */ -int event_queue_create_thread(struct event_queue *); -int event_queue_lock(struct event_queue *); -int event_queue_unlock(struct event_queue *); -int event_queue_lock_ro(struct event_queue *); -int event_queue_signal(struct event_queue *); -int event_queue_wait(struct event_queue *, int); -int event_queue_sleep(struct event_queue *); -int event_queue_wakeup(struct event_queue *); -int event_queue_cond_lock(struct event_queue *); -int event_queue_cond_unlock(struct event_queue *); - -/* input queue */ -int input_queue_attach(); -void input_queue_detach(); -int input_queue_get(il_octet_string_t **, long *, int); - -/* queue management functions */ -int queue_list_init(char *); -struct event_queue *queue_list_get(char *); -struct event_queue *queue_list_first(); -struct event_queue *queue_list_next(); -int queue_list_is_log(struct event_queue *); - -#if defined(IL_NOTIFICATIONS) -struct event_queue *notifid_map_get_dest(const char *); -int notifid_map_set_dest(const char *, struct event_queue *); -time_t notifid_map_get_expiration(const char *); -int notifid_map_set_expiration(const char *, time_t); -#endif - -/* event store functions */ -int event_store_init(char *); -int event_store_cleanup(); -int event_store_recover_all(void); -struct event_store *event_store_find(char *, const char *); -int event_store_sync(struct event_store *, long); -int event_store_next(struct event_store *, long, int); -int event_store_commit(struct event_store *, int, int, int); -int event_store_recover(struct event_store *); -int event_store_release(struct event_store *); -/* int event_store_remove(struct event_store *); */ - -#if defined(IL_WS) -/* http functions */ -int parse_header(const char *, il_http_message_t *); -int receive_http(void *, int (*)(void *, char *, const int), il_http_message_t *); -#endif - -/* master main loop */ -int loop(); - -/* recover thread */ -void *recover_thread(void*); - -#endif diff --git a/org.glite.lb.logger/src/logd.c b/org.glite.lb.logger/src/logd.c deleted file mode 100644 index 9197bad..0000000 --- a/org.glite.lb.logger/src/logd.c +++ /dev/null @@ -1,486 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lb/context-int.h" -#include "glite/lb/timeouts.h" -#include "logd_proto.h" -#include "glite/security/glite_gss.h" -#ifdef LB_PERF -#include "glite/lb/lb_perftest.h" -#endif - -static const char rcsid[] = "@(#)$Id$"; -static int verbose = 0; -static int debug = 0; -static int port = EDG_WLL_LOG_PORT_DEFAULT; -static char *prefix = EDG_WLL_LOG_PREFIX_DEFAULT; -static char *cert_file = NULL; -static char *key_file = NULL; -static char *CAcert_dir = NULL; -static int noAuth = 0; -static int noIPC = 0; -static int noParse = 0; - -#define DEFAULT_SOCKET "/tmp/interlogger.sock" -char *socket_path = DEFAULT_SOCKET; - -extern int confirm_sock; -extern char confirm_sock_name[256]; - -static struct option const long_options[] = { - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'V' }, - { "verbose", no_argument, 0, 'v' }, - { "debug", no_argument, 0, 'd' }, - { "port", required_argument, 0, 'p' }, - { "file-prefix", required_argument, 0, 'f' }, - { "cert", required_argument, 0, 'c' }, - { "key", required_argument, 0, 'k' }, - { "CAdir", required_argument, 0, 'C' }, - { "socket",required_argument, 0, 's' }, - { "noAuth", no_argument, 0, 'x' }, - { "noIPC", no_argument, 0, 'y' }, - { "noParse", no_argument, 0, 'z' }, - { NULL, 0, NULL, 0} -}; - -/* - *---------------------------------------------------------------------- - * - * usage - print usage - * - *---------------------------------------------------------------------- - */ - -static void -usage(char *program_name) { - fprintf(stdout,"%s\n" - "- collect events from logging API calls,\n" - "- save them to files and\n" - "- send them to inter-logger\n\n" - "Usage: %s [option]\n" - "-h, --help display this help and exit\n" - "-V, --version output version information and exit\n" - "-d, --debug do not run as daemon\n" - "-v, --verbose print extensive debug output\n" - "-p, --port port to listen\n" - "-f, --file-prefix path and prefix for event files\n" - "-c, --cert location of server certificate\n" - "-k, --key location of server private key\n" - "-C, --CAdir directory containing CA certificates\n" - "-s, --socket interlogger's socket to send messages to\n" - "--noAuth do not check caller's identity\n" - "--noIPC do not send messages to inter-logger\n" - "--noParse do not parse messages for correctness\n", - program_name,program_name); -} - -static sighandler_t mysignal(int num,sighandler_t handler) -{ - struct sigaction sa,osa; - - memset(&sa,0,sizeof(sa)); - sa.sa_handler = handler; - sa.sa_flags = SA_RESTART; - return sigaction(num,&sa,&osa) ? SIG_ERR : osa.sa_handler; -} - -/* - *---------------------------------------------------------------------- - * - * handle_signal - - * USR1 - increase the verbosity of the program - * USR2 - decrease the verbosity of the program - * - *---------------------------------------------------------------------- - */ -void handle_signal(int num) { - if (num != SIGCHLD) edg_wll_ll_log(LOG_NOTICE,"Received signal %d\n", num); - switch (num) { - case SIGUSR1: - if (edg_wll_ll_log_level < LOG_DEBUG) edg_wll_ll_log_level++; - edg_wll_ll_log(LOG_NOTICE,"Logging level is now %d\n", edg_wll_ll_log_level); - break; - case SIGUSR2: - if (edg_wll_ll_log_level > LOG_EMERG) edg_wll_ll_log_level--; - edg_wll_ll_log(LOG_NOTICE,"Logging level is now %d\n", edg_wll_ll_log_level); - break; - case SIGPIPE: - edg_wll_ll_log(LOG_NOTICE,"Broken pipe, lost communication channel.\n"); - break; - case SIGCHLD: - while (wait3(NULL,WNOHANG,NULL) > 0); - break; - case SIGINT: - case SIGTERM: - case SIGQUIT: - if (confirm_sock) { - edg_wll_ll_log(LOG_NOTICE,"Closing confirmation socket.\n"); - close(confirm_sock); - unlink(confirm_sock_name); - } - exit(1); - break; - default: break; - } -} - -/* - *---------------------------------------------------------------------- - * - * doit - do all the dirty work - * - *---------------------------------------------------------------------- - */ -static int -doit(int socket, edg_wll_GssCred cred_handle, char *file_name_prefix, int noipc, int noparse) -{ - char *subject; - int ret,fd,count; - struct timeval timeout; - edg_wll_GssConnection con; - edg_wll_GssStatus gss_stat; - edg_wll_GssPrincipal client = NULL; - fd_set fdset; - struct sockaddr_in peer; - socklen_t alen = sizeof peer; - - ret = count = 0; - FD_ZERO(&fdset); - - /* accept */ - timeout.tv_sec = ACCEPT_TIMEOUT; - timeout.tv_usec = 0; - getpeername(socket,(struct sockaddr *) &peer,&alen); - edg_wll_ll_log(LOG_DEBUG,"Accepting connection (remaining timeout %d.%06d sec)\n", - (int)timeout.tv_sec, (int) timeout.tv_usec); - if ((ret = edg_wll_gss_accept(cred_handle,socket,&timeout,&con, &gss_stat)) < 0) { - edg_wll_ll_log(LOG_DEBUG,"timeout after gss_accept is %d.%06d sec\n", - (int)timeout.tv_sec, (int) timeout.tv_usec); - edg_wll_ll_log(LOG_ERR,"%s: edg_wll_gss_accept() failed\n",inet_ntoa(peer.sin_addr)); - return edg_wll_log_proto_server_failure(ret,&gss_stat,"edg_wll_gss_accept() failed\n"); - } - - /* authenticate */ - edg_wll_ll_log(LOG_INFO,"Processing authentication:\n"); - ret = edg_wll_gss_get_client_conn(&con, &client, &gss_stat); - if (ret) { - char *gss_err; - edg_wll_gss_get_error(&gss_stat, "Cannot read client identification", &gss_err); - edg_wll_ll_log(LOG_WARNING, "%s: %s\n", inet_ntoa(peer.sin_addr),gss_err); - free(gss_err); - } - - if (ret || client->flags & EDG_WLL_GSS_FLAG_ANON) { - edg_wll_ll_log(LOG_INFO," User not authenticated, setting as \"%s\". \n",EDG_WLL_LOG_USER_DEFAULT); - subject=strdup(EDG_WLL_LOG_USER_DEFAULT); - } else { - edg_wll_ll_log(LOG_INFO," User successfully authenticated as:\n"); - edg_wll_ll_log(LOG_INFO, " %s\n", client->name); - subject=strdup(client->name); - } - if (client) - edg_wll_gss_free_princ(client); - - /* get and process the data */ - timeout.tv_sec = CONNECTION_TIMEOUT; - timeout.tv_usec = 0; - - while (timeout.tv_sec > 0) { - count++; - edg_wll_ll_log(LOG_DEBUG,"Waiting for data delivery no. %d (remaining timeout %d.%06d sec)\n", - count, (int)timeout.tv_sec, (int) timeout.tv_usec); - FD_SET(con.sock,&fdset); - fd = select(con.sock+1,&fdset,NULL,NULL,&timeout); - switch (fd) { - case 0: /* timeout */ - edg_wll_ll_log(LOG_DEBUG,"Connection timeout expired\n"); - timeout.tv_sec = 0; - break; - case -1: /* error */ - switch(errno) { - case EINTR: - edg_wll_ll_log(LOG_DEBUG,"XXX: Waking up (remaining timeout %d.%06d sec)\n", - (int)timeout.tv_sec, (int) timeout.tv_usec); - continue; - default: - SYSTEM_ERROR("select"); - timeout.tv_sec = 0; - break; - } - break; - default: - edg_wll_ll_log(LOG_DEBUG,"Waking up (remaining timeout %d.%06d sec)\n", - (int)timeout.tv_sec, (int) timeout.tv_usec); - break; - } - if (FD_ISSET(con.sock,&fdset)) { - ret = edg_wll_log_proto_server(&con,&timeout,subject,file_name_prefix,noipc,noparse); - if (ret != 0) { - edg_wll_ll_log(LOG_DEBUG,"timeout after edg_wll_log_proto_server is %d.%06d sec\n", - (int)timeout.tv_sec, (int) timeout.tv_usec); - if (ret != EDG_WLL_GSS_ERROR_EOF) - edg_wll_ll_log(LOG_ERR,"edg_wll_log_proto_server(): Error\n"); - else if (count == 1) - edg_wll_ll_log(LOG_ERR,"edg_wll_log_proto_server(): Error. EOF occured.\n"); - timeout.tv_sec = 0; - timeout.tv_usec = 0; - break; - } else { - timeout.tv_sec = CONNECTION_TIMEOUT; - timeout.tv_usec = 0; - } - } - - } - -doit_end: - edg_wll_ll_log(LOG_DEBUG, "Closing descriptor '%d'...",con.sock); - edg_wll_gss_close(&con, NULL); - if (con.sock == -1) - edg_wll_ll_log(LOG_DEBUG, "o.k.\n"); - if (subject) free(subject); - return ret; -} - -/* - *---------------------------------------------------------------------- - * - * Main - - * - *---------------------------------------------------------------------- - */ -int main(int argc, char *argv[]) -{ - int ret; - int childpid; - int opt; - - int listener_fd; - int client_fd; - struct sockaddr_in client_addr; - int client_addr_len; - - time_t cert_mtime = 0, key_mtime = 0; - edg_wll_GssStatus gss_stat; - edg_wll_GssCred cred = NULL; - - - setlinebuf(stdout); - setlinebuf(stderr); - - /* welcome */ - fprintf(stdout,"\ -This is LocalLogger, part of Workload Management System in EU DataGrid & EGEE.\n"); - - /* get arguments */ - while ((opt = getopt_long(argc,argv, - "h" /* help */ - "V" /* version */ - "v" /* verbose */ - "d" /* debug */ - "p:" /* port */ - "f:" /* file prefix */ - "c:" /* certificate */ - "k:" /* key */ - "C:" /* CA dir */ - "s:" /* socket */ - "x" /* noAuth */ - "y" /* noIPC */ - "z", /* noParse */ - long_options, (int *) 0)) != EOF) { - - switch (opt) { - case 'V': fprintf(stdout,"%s:\t%s\n",argv[0],rcsid); exit(0); - case 'v': verbose = 1; break; - case 'd': debug = 1; break; - case 'p': port = atoi(optarg); break; - case 'f': prefix = optarg; break; - case 'c': cert_file = optarg; break; - case 'k': key_file = optarg; break; - case 'C': CAcert_dir = optarg; break; - case 's': socket_path = optarg; break; - case 'x': noAuth = 1; break; - case 'y': noIPC = 1; break; - case 'z': noParse = 1; break; - case 'h': - default: - usage(argv[0]); exit(0); - } - } -#ifdef LB_PERF - edg_wll_ll_log_init(verbose ? LOG_INFO : LOG_ERR); -#else - edg_wll_ll_log_init(verbose ? LOG_DEBUG : LOG_INFO); -#endif - edg_wll_ll_log(LOG_INFO,"Initializing...\n"); - - /* check noParse */ - if (noParse) { - edg_wll_ll_log(LOG_INFO,"Parse messages for correctness... [no]\n"); - } else { - edg_wll_ll_log(LOG_INFO,"Parse messages for correctness... [yes]\n"); - } - - /* check noIPC */ - if (noIPC) { - edg_wll_ll_log(LOG_INFO,"Send messages also to inter-logger... [no]\n"); - } else { - edg_wll_ll_log(LOG_INFO,"Send messages also to inter-logger... [yes]\n"); - } - - /* check prefix correctness */ - if (strlen(prefix) > FILENAME_MAX - 34) { - edg_wll_ll_log(LOG_CRIT,"Too long prefix (%s) for file names, would not be able to write to log files. Exiting.\n",prefix); - exit(1); - } - /* TODO: check for write permisions */ - edg_wll_ll_log(LOG_INFO,"Messages will be stored with the filename prefix \"%s\".\n",prefix); - - if (CAcert_dir) - setenv("X509_CERT_DIR", CAcert_dir, 1); - - /* initialize signal handling */ - if (mysignal(SIGUSR1, handle_signal) == SIG_ERR) { perror("signal"); exit(1); } - if (mysignal(SIGUSR2, handle_signal) == SIG_ERR) { perror("signal"); exit(1); } - if (mysignal(SIGPIPE, handle_signal) == SIG_ERR) { perror("signal"); exit(1); } - if (mysignal(SIGHUP, SIG_DFL) == SIG_ERR) { perror("signal"); exit(1); } - if (mysignal(SIGINT, handle_signal) == SIG_ERR) { perror("signal"); exit(1); } - if (mysignal(SIGQUIT, handle_signal) == SIG_ERR) { perror("signal"); exit(1); } - if (mysignal(SIGTERM, handle_signal) == SIG_ERR) { perror("signal"); exit(1); } - if (mysignal(SIGCHLD, handle_signal) == SIG_ERR) { perror("signal"); exit(1); } - -#ifdef LB_PERF - glite_wll_perftest_init(NULL, NULL, NULL, NULL, 0); -#endif - - edg_wll_gss_watch_creds(cert_file,&cert_mtime); - /* XXX DK: support noAuth */ - ret = edg_wll_gss_acquire_cred_gsi(cert_file, key_file, &cred, &gss_stat); - if (ret) { - /* XXX DK: call edg_wll_gss_get_error() */ - edg_wll_ll_log(LOG_CRIT,"Failed to get GSI credentials. Exiting.\n"); - exit(1); - } - - if (cred->name!=NULL) { - edg_wll_ll_log(LOG_INFO,"Server running with certificate: %s\n",cred->name); - } else if (noAuth) { - edg_wll_ll_log(LOG_INFO,"Server running without certificate\n"); - } - - /* do listen */ - edg_wll_ll_log(LOG_INFO,"Listening on port %d\n",port); - listener_fd = do_listen(port); - if (listener_fd == -1) { - edg_wll_ll_log(LOG_CRIT,"Failed to listen on port %d\n",port); - edg_wll_gss_release_cred(&cred, NULL); - exit(-1); - } else { - edg_wll_ll_log(LOG_DEBUG,"Listener's socket descriptor is '%d'\n",listener_fd); - } - - client_addr_len = sizeof(client_addr); - bzero((char *) &client_addr, client_addr_len); - - /* daemonize */ - if (debug) { - edg_wll_ll_log(LOG_INFO,"Running as daemon... [no]\n"); - } else { - edg_wll_ll_log(LOG_INFO,"Running as daemon... [yes]\n"); - if (daemon(0,0) < 0) { - edg_wll_ll_log(LOG_CRIT,"Failed to run as daemon. Exiting.\n"); - SYSTEM_ERROR("daemon"); - exit(1); - } - } - - /* - * Main loop - */ - while (1) { - int opt; - - edg_wll_ll_log(LOG_INFO,"Accepting incomming connections...\n"); - client_fd = accept(listener_fd, (struct sockaddr *) &client_addr, - &client_addr_len); - if (client_fd < 0) { - close(listener_fd); - edg_wll_ll_log(LOG_CRIT,"Failed to accept incomming connections\n"); - SYSTEM_ERROR("accept"); - edg_wll_gss_release_cred(&cred, NULL); - exit(-1); - } else { - edg_wll_ll_log(LOG_DEBUG,"Incomming connection on socket '%d'\n",client_fd); - } - - opt = 0; - if (setsockopt(client_fd,IPPROTO_TCP,TCP_CORK,(const void *) &opt,sizeof opt)) { - edg_wll_ll_log(LOG_WARNING,"Can't reset TCP_CORK\n"); - } - opt = 1; - if (setsockopt(client_fd,IPPROTO_TCP,TCP_NODELAY,(const void *) &opt,sizeof opt)) { - edg_wll_ll_log(LOG_WARNING,"Can't set TCP_NODELAY\n"); - } - - switch (edg_wll_gss_watch_creds(cert_file,&cert_mtime)) { - edg_wll_GssCred newcred; - case 0: break; - case 1: - ret = edg_wll_gss_acquire_cred_gsi(cert_file,key_file,&newcred,&gss_stat); - if (ret) { - edg_wll_ll_log(LOG_WARNING,"Reloading credentials failed, continue with older\n"); - } else { - edg_wll_ll_log(LOG_DEBUG,"Reloading credentials succeeded\n"); - edg_wll_gss_release_cred(&cred, NULL); - cred = newcred; - } - break; - case -1: - edg_wll_ll_log(LOG_WARNING,"edg_wll_gss_watch_creds failed\n"); - break; - } - - /* FORK - change next line if fork() is not needed (for debugging for example) */ -#if 1 - if ((childpid = fork()) < 0) { - SYSTEM_ERROR("fork"); - if (client_fd) close(client_fd); - } - if (childpid == 0) { - ret = doit(client_fd,cred,prefix,noIPC,noParse); - if (client_fd) close(client_fd); - edg_wll_ll_log(LOG_DEBUG,"Exiting.\n", - CONNECTION_TIMEOUT); - exit(0); - } - if (childpid > 0) { - edg_wll_ll_log(LOG_DEBUG,"Forked a new child with PID %d\n",childpid); - if (client_fd) close(client_fd); - } -#else - ret = doit(client_fd,cred,prefix,noIPC,noParse); - if (client_fd) close(client_fd); - -#endif - } /* while */ - -end: - if (listener_fd) close(listener_fd); - edg_wll_gss_release_cred(&cred, NULL); - exit(ret); -} diff --git a/org.glite.lb.logger/src/logd_proto.c b/org.glite.lb.logger/src/logd_proto.c deleted file mode 100644 index 6c4015d..0000000 --- a/org.glite.lb.logger/src/logd_proto.c +++ /dev/null @@ -1,661 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lbu/escape.h" -#include "glite/lb/context-int.h" -#include "glite/lb/events_parse.h" - -#include "logd_proto.h" - -static const int one = 1; - -extern char* socket_path; - -int edg_wll_ll_log_level; - -#define tv_sub(a,b) {\ - (a).tv_usec -= (b).tv_usec;\ - (a).tv_sec -= (b).tv_sec;\ - if ((a).tv_usec < 0) {\ - (a).tv_sec--;\ - (a).tv_usec += 1000000;\ - }\ -} - -/* - *---------------------------------------------------------------------- - * - * send_answer_back - - * - *---------------------------------------------------------------------- - */ -static int send_answer_back(edg_wll_GssConnection *con, int answer, struct timeval *timeout) { - size_t count = 0; - int err = 0; - int ans = answer; - u_int8_t ans_end[4]; - edg_wll_GssStatus gss_stat; - - edg_wll_ll_log(LOG_INFO,"Sending answer \"%d\" back to client...",answer); - ans_end[0] = ans & 0xff; ans >>= 8; - ans_end[1] = ans & 0xff; ans >>= 8; - ans_end[2] = ans & 0xff; ans >>= 8; - ans_end[3] = ans; - if ((err = edg_wll_gss_write_full(con,ans_end,4,timeout,&count, &gss_stat)) < 0 ) { - edg_wll_ll_log(LOG_INFO,"error.\n"); - return edg_wll_log_proto_server_failure(err,&gss_stat,"Error sending answer"); - } else { - edg_wll_ll_log(LOG_INFO,"o.k.\n"); - return 0; - } -} - -/* - *---------------------------------------------------------------------- - * - * wait_for_confirmation - - * - * Args: timeout - number of seconds to wait, 0 => wait indefinitely - * - * Returns: 1 => OK, *code contains error code sent by interlogger - * 0 => timeout expired before anything interesting happened - * -1 => some error (see errno for details) - * - *---------------------------------------------------------------------- - */ -int confirm_sock; -char confirm_sock_name[256]; - -static -int init_confirmation() -{ - struct sockaddr_un saddr; - - /* create socket */ - if((confirm_sock=socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { - SYSTEM_ERROR("socket"); - edg_wll_ll_log(LOG_ERR,"init_confirmation(): error creating socket\n"); - return(-1); - } - - /* set the socket parameters */ - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, confirm_sock_name); - - /* bind the socket */ - if(bind(confirm_sock, (struct sockaddr *)&saddr, sizeof(saddr.sun_path)) < 0) { - SYSTEM_ERROR("bind"); - edg_wll_ll_log(LOG_ERR,"init_confirmation(): error binding socket\n"); - close(confirm_sock); - unlink(confirm_sock_name); - return(-1); - } - - /* and listen */ - if(listen(confirm_sock, 5) < 0) { - SYSTEM_ERROR("listen"); - edg_wll_ll_log(LOG_ERR,"init_confirmation(): error listening on socket\n"); - close(confirm_sock); - unlink(confirm_sock_name); - return(-1); - } - - return(0); -} - - -int wait_for_confirmation(struct timeval *timeout, int *code) -{ - fd_set fds; - struct timeval to,before,after; - int ret = 0, tmp = 0; - - *code = 0; - - FD_ZERO(&fds); - FD_SET(confirm_sock, &fds); - - /* set timeout */ - if (timeout) { - memcpy(&to,timeout,sizeof to); - gettimeofday(&before,NULL); - } - - /* wait for confirmation at most timeout seconds */ - if ((tmp=select(confirm_sock+1, &fds, NULL, NULL, timeout?&to:NULL)) < 0) { - SYSTEM_ERROR("select"); - edg_wll_ll_log(LOG_ERR,"wait_for_confirmation(): error selecting socket\n"); - ret = -1; - } else { - if (tmp == 0) - ret = 0; - else { - int nsd = accept(confirm_sock, NULL, NULL); - ret = 1; - if(nsd < 0) { - SYSTEM_ERROR("accept"); - edg_wll_ll_log(LOG_ERR,"wait_for_confirmation(): error accepting a connection on a socket\n"); - ret = -1; - } else { - if(recv(nsd, code, sizeof(*code), MSG_NOSIGNAL) < 0) { - SYSTEM_ERROR("recv"); - edg_wll_ll_log(LOG_ERR,"wait_for_confirmation(): error receiving a message from a socket\n"); - ret = -1; - } - close(nsd); - } - } - } - close(confirm_sock); - unlink(confirm_sock_name); - if (timeout) { - gettimeofday(&after,NULL); - tv_sub(after,before); - tv_sub(*timeout,after); - if (timeout->tv_sec < 0) { - timeout->tv_sec = 0; - timeout->tv_usec = 0; - } - } - return ret; -} - -/* - *---------------------------------------------------------------------- - * - * do_listen - listen on given port - * - * Returns: socket handle or -1 if something fails - * - * Calls: socket, bind, listen - * - * Algorithm: - * - *---------------------------------------------------------------------- - */ -int do_listen(int port) -{ - int ret; - int sock; - struct sockaddr_in my_addr; - - memset(&my_addr, 0, sizeof(my_addr)); - my_addr.sin_family = AF_INET; - my_addr.sin_addr.s_addr = INADDR_ANY; - my_addr.sin_port = htons(port); - - sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sock == -1) { - SYSTEM_ERROR("socket"); - edg_wll_ll_log(LOG_ERR,"do_listen(): error creating socket\n"); - return -1; - } - - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); - ret = bind(sock, (struct sockaddr *)&my_addr, sizeof(my_addr)); - if (ret == -1) { - SYSTEM_ERROR("bind"); - edg_wll_ll_log(LOG_ERR,"do_listen(): error binding socket\n"); - return -1; - } - - ret = listen(sock, 5); - if (ret == -1) { - SYSTEM_ERROR("listen"); - edg_wll_ll_log(LOG_ERR,"do_listen(): error listening on socket\n"); - close(sock); - return -1; - } - - return sock; -} - -/* - *---------------------------------------------------------------------- - * - * edg_wll_log_proto_server - handle incoming data - * - * Returns: 0 if done properly or errno - * - * Calls: - * - * Algorithm: - * - *---------------------------------------------------------------------- - */ -int edg_wll_log_proto_server(edg_wll_GssConnection *con, struct timeval *timeout, char *name, char *prefix, int noipc, int noparse) -{ - char *buf,*dglllid,*dguser,*jobId,*name_esc; - char header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH+1]; - char outfilename[FILENAME_MAX]; - size_t count; - int count_total,size; - u_int8_t size_end[4]; - size_t msg_size,dglllid_size,dguser_size; - int i,answer,answer_sent; - int msg_sock; - char *msg,*msg_begin; - FILE *outfile; - int filedesc,filelock_status,flags; - long filepos; - struct flock filelock; - int priority; - long lllid; - int unique; - int err; - edg_wll_Context context; - edg_wll_Event *event; - edg_wlc_JobId j; - edg_wll_GssStatus gss_stat; - - errno = i = answer = answer_sent = size = msg_size = dglllid_size = dguser_size = count = count_total = msg_sock = filedesc = filelock_status = /* priority */ unique = err = 0; - buf = dglllid = dguser = jobId = name_esc = msg = msg_begin = NULL; - event = NULL; - - /* init */ - if (edg_wll_InitContext(&context) != 0) { - edg_wll_ll_log(LOG_ERR,"edg_wll_InitContex(): error.\n"); - answer = ENOMEM; - goto edg_wll_log_proto_server_end; - } - if (edg_wll_ResetError(context) != 0) { - edg_wll_ll_log(LOG_ERR,"edg_wll_ResetError(): error.\n"); - answer = ENOMEM; - goto edg_wll_log_proto_server_end; - } - - /* look for the unique unused long local-logger id (LLLID) */ - lllid = 1000*getpid(); - for (i=0; (i<1000)&&(!unique); i++) { - lllid += i; - snprintf(confirm_sock_name, sizeof(confirm_sock_name), "/tmp/dglogd_sock_%ld", lllid); - if ((filedesc = open(confirm_sock_name,O_CREAT)) == -1) { - if (errno == EEXIST) { - edg_wll_ll_log(LOG_WARNING,"Warning: LLLID %ld already in use.\n",lllid); - } else { - SYSTEM_ERROR("open"); - } - } else { - unique = 1; - close(filedesc); filedesc = 0; - unlink(confirm_sock_name); - } - } - if (!unique) { - edg_wll_ll_log(LOG_ERR,"Cannot determine the unique long local-logger id (LLLID)!\n",lllid); - return EAGAIN; - } - edg_wll_ll_log(LOG_INFO,"Long local-logger id (LLLID): %ld\n",lllid); - - /* receive socket header */ - edg_wll_ll_log(LOG_INFO,"Reading socket header..."); - memset(header, 0, EDG_WLL_LOG_SOCKET_HEADER_LENGTH+1); - if ((err = edg_wll_gss_read_full(con, header, EDG_WLL_LOG_SOCKET_HEADER_LENGTH, timeout, &count, &gss_stat)) < 0) { - if (err == EDG_WLL_GSS_ERROR_EOF) { - edg_wll_ll_log(LOG_INFO,"no data available.\n"); - answer = err; - answer_sent = 1; /* i.e. do not try to send answer back */ - } else { - edg_wll_ll_log(LOG_INFO,"error.\n"); - answer = edg_wll_log_proto_server_failure(err,&gss_stat,"Error receiving header"); - } - goto edg_wll_log_proto_server_end; - } else { - edg_wll_ll_log(LOG_INFO,"o.k.\n"); - } - - edg_wll_ll_log(LOG_DEBUG,"Checking socket header..."); - header[EDG_WLL_LOG_SOCKET_HEADER_LENGTH] = '\0'; - if (strncmp(header,EDG_WLL_LOG_SOCKET_HEADER,EDG_WLL_LOG_SOCKET_HEADER_LENGTH)) { - /* not the proper socket header text */ - edg_wll_ll_log(LOG_DEBUG,"error.\n"); - edg_wll_ll_log(LOG_ERR,"edg_wll_log_proto_server(): invalid socket header\n"); - edg_wll_ll_log(LOG_DEBUG,"edg_wll_log_proto_server(): read header '%s' instead of '%s'\n", - header,EDG_WLL_LOG_SOCKET_HEADER); - answer = EINVAL; - goto edg_wll_log_proto_server_end; - } else { - edg_wll_ll_log(LOG_DEBUG,"o.k.\n"); - } - -/* XXX: obsolete - edg_wll_ll_log(LOG_DEBUG,"Reading message priority..."); - count = 0; - if ((err = edg_wll_gss_read_full(con, &priority, sizeof(priority), timeout, &count, &gss_stat)) < 0) { - edg_wll_ll_log(LOG_DEBUG,"error.\n"); - answer = edg_wll_log_proto_server_failure(err,&gss_stat,"Error receiving message priority"); - goto edg_wll_log_proto_server_end; - } else { - edg_wll_ll_log(LOG_DEBUG,"o.k.\n"); - } -*/ - - edg_wll_ll_log(LOG_DEBUG,"Reading message size..."); - count = 0; - if ((err = edg_wll_gss_read_full(con, size_end, 4, timeout, &count,&gss_stat)) < 0) { - edg_wll_ll_log(LOG_DEBUG,"error.\n"); - answer = edg_wll_log_proto_server_failure(err,&gss_stat,"Error receiving message size"); - goto edg_wll_log_proto_server_end; - } else { - edg_wll_ll_log(LOG_DEBUG,"o.k.\n"); - } - size = size_end[3]; size <<=8; - size |= size_end[2]; size <<=8; - size |= size_end[1]; size <<=8; - size |= size_end[0]; - edg_wll_ll_log(LOG_DEBUG,"Checking message size..."); - if (size <= 0) { - edg_wll_ll_log(LOG_DEBUG,"error.\n"); - /* probably wrong size in the header or nothing to read */ - edg_wll_ll_log(LOG_ERR,"edg_wll_log_proto_server(): invalid size read from socket header\n"); - edg_wll_ll_log(LOG_DEBUG,"Read size '%d'.\n",size); - answer = EINVAL; - goto edg_wll_log_proto_server_end; - } else { - edg_wll_ll_log(LOG_DEBUG,"o.k.\n"); - edg_wll_ll_log(LOG_DEBUG,"- Size read from header: %d bytes.\n",size); - } - - /* format the DG.LLLID string */ - if (asprintf(&dglllid,"DG.LLLID=%ld ",lllid) == -1) { - SYSTEM_ERROR("asprintf"); - edg_wll_ll_log(LOG_ERR,"edg_wll_log_proto_server(): nomem for DG.LLLID\n"); - answer = ENOMEM; - goto edg_wll_log_proto_server_end; - } - dglllid_size = strlen(dglllid); - - /* format the DG.USER string */ - name_esc = glite_lbu_EscapeULM(name); - if (asprintf(&dguser,"DG.USER=\"%s\" ",name_esc) == -1) { - SYSTEM_ERROR("asprintf"); - edg_wll_ll_log(LOG_ERR,"edg_wll_log_proto_server(): nomem for DG.USER\n"); - answer = ENOMEM; - goto edg_wll_log_proto_server_end; - } - dguser_size = strlen(dguser); - - /* allocate enough memory for all data */ - msg_size = dglllid_size + dguser_size + size + 1; - if ((msg = malloc(msg_size)) == NULL) { - SYSTEM_ERROR("malloc"); - edg_wll_ll_log(LOG_ERR,"edg_wll_log_proto_server(): out of memory for allocating message\n"); - answer = ENOMEM; - goto edg_wll_log_proto_server_end; - } - strncpy(msg,dglllid,dglllid_size); - msg_begin = msg + dglllid_size; // this is the "official" beginning of the message - strncpy(msg_begin,dguser,dguser_size); - - /* receive message */ - edg_wll_ll_log(LOG_INFO,"Reading message from socket..."); - buf = msg_begin + dguser_size; - count = 0; - if ((err = edg_wll_gss_read_full(con, buf, size, timeout, &count, &gss_stat)) < 0) { - edg_wll_ll_log(LOG_INFO,"error.\n"); - answer = edg_wll_log_proto_server_failure(err,&gss_stat,"Error receiving message"); - goto edg_wll_log_proto_server_end; - } else { - edg_wll_ll_log(LOG_INFO,"o.k.\n"); - } - - if (buf[count] != '\0') buf[count] = '\0'; - - /* parse message and get jobId and priority from it */ - if (!noparse && strstr(msg, "DG.TYPE=\"command\"") == NULL) { - edg_wll_ll_log(LOG_INFO,"Parsing message for correctness..."); - if (edg_wll_ParseEvent(context,msg_begin,&event) != 0) { - edg_wll_ll_log(LOG_INFO,"error.\n"); - edg_wll_ll_log(LOG_ERR,"edg_wll_log_proto_server(): edg_wll_ParseEvent error\n"); - edg_wll_ll_log(LOG_ERR,"edg_wll_ParseEvent(): %s\n",context->errDesc); - answer = edg_wll_Error(context,NULL,NULL); - goto edg_wll_log_proto_server_end; - } else { - edg_wll_ll_log(LOG_INFO,"o.k.\n"); - } - edg_wll_ll_log(LOG_DEBUG,"Getting jobId from message..."); - jobId = edg_wlc_JobIdGetUnique(event->any.jobId); - priority = event->any.priority; - edg_wll_FreeEvent(event); - event->any.priority = priority; - edg_wll_ll_log(LOG_DEBUG,"o.k.\n"); - } else { - if ((event = edg_wll_InitEvent(EDG_WLL_EVENT_UNDEF)) == NULL) { - edg_wll_ll_log(LOG_ERR, "edg_wll_InitEvent(): out of memory\n"); - answer = ENOMEM; - goto edg_wll_log_proto_server_end; - } - edg_wll_ll_log(LOG_DEBUG,"Getting jobId from message..."); - jobId = edg_wll_GetJobId(msg); - if (!jobId || edg_wlc_JobIdParse(jobId,&j)) { - edg_wll_ll_log(LOG_DEBUG,"error.\n"); - edg_wll_ll_log(LOG_ERR,"ParseJobId(%s)\n",jobId?jobId:"NULL"); - answer = EINVAL; - goto edg_wll_log_proto_server_end; - } else { - edg_wll_ll_log(LOG_DEBUG,"o.k.\n"); - } - free(jobId); - jobId = edg_wlc_JobIdGetUnique(j); - edg_wlc_JobIdFree(j); - -/* TODO: get the priority from message some better way */ - if (strstr(msg, "DG.PRIORITY=1") != NULL) - event->any.priority = 1; - else event->any.priority = 0; - } - - - /* if not command, save message to file */ - if(strstr(msg, "DG.TYPE=\"command\"") == NULL) { - /* compose the name of the log file */ -// edg_wll_ll_log(LOG_DEBUG,"Composing filename from prefix \"%s\" and unique jobId \"%s\"...",prefix,jobId); - count = strlen(prefix); - strncpy(outfilename,prefix,count); count_total=count; - strncpy(outfilename+count_total,".",1); count_total+=1; count=strlen(jobId); - strncpy(outfilename+count_total,jobId,count); count_total+=count; - outfilename[count_total]='\0'; -// edg_wll_ll_log(LOG_DEBUG,"o.k.\n"); - - /* fopen and properly handle the filelock */ -#ifdef LOGD_NOFILE - edg_wll_ll_log(LOG_NOTICE,"NOT writing message to \"%s\".\n",outfilename); - filepos = 0; -#else - edg_wll_ll_log(LOG_INFO,"Writing message to \"%s\"...",outfilename); - if ( edg_wll_log_event_write(context, outfilename, msg, FCNTL_ATTEMPTS, FCNTL_TIMEOUT, &filepos) ) { - char *errd; - SYSTEM_ERROR("edg_wll_log_event_write"); - answer = edg_wll_Error(context, NULL, &errd); - edg_wll_ll_log(LOG_ERR,"edg_wll_log_event_write error: %s\n",errd); - free(errd); - goto edg_wll_log_proto_server_end; - } else edg_wll_ll_log(LOG_INFO,"o.k.\n"); -#endif - } else { - filepos = 0; - } - -#ifdef LB_PERF - edg_wll_ll_log(LOG_INFO,"Calling perftest\n"); - glite_wll_perftest_consumeEventString(msg); - edg_wll_ll_log(LOG_INFO,"o.k.\n"); -#endif - - /* if not priority send now the answer back to client */ - if (!(event->any.priority & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT))) { - if (!send_answer_back(con,answer,timeout)) { - answer_sent = 1; - } - } - - /* send message via IPC (UNIX socket) */ - if (!noipc) { - if (event->any.priority & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT)) { - edg_wll_ll_log(LOG_DEBUG,"Initializing 2nd UNIX socket (%s) for priority messages confirmation...",confirm_sock_name); - if(init_confirmation() < 0) { - edg_wll_ll_log(LOG_DEBUG,"error.\n"); - answer = errno; - goto edg_wll_log_proto_server_end; - } else { - edg_wll_ll_log(LOG_DEBUG,"o.k.\n"); - } - } - - edg_wll_ll_log(LOG_DEBUG, - "Sending via IPC (UNIX socket \"%s\")\n\t" - "the message position %ld (%d bytes)", - socket_path, filepos, sizeof(filepos)); - if ( edg_wll_log_event_send(context, socket_path, filepos, msg, msg_size, CONNECT_ATTEMPTS, timeout) ) { - char *errd; - SYSTEM_ERROR("edg_wll_log_event_send"); - answer = edg_wll_Error(context, NULL, &errd); - edg_wll_ll_log(LOG_ERR,"edg_wll_log_event_send error: %s\n",errd); - free(errd); - goto edg_wll_log_proto_server_end_1; - } else edg_wll_ll_log(LOG_DEBUG,"o.k.\n"); - - if (event->any.priority & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT)) { - edg_wll_ll_log(LOG_INFO,"Waiting for confirmation..."); - if ((count = wait_for_confirmation(timeout, &answer)) < 0) { - edg_wll_ll_log(LOG_INFO,"error.\n"); - edg_wll_ll_log(LOG_ERR,"wait_for_confirmation(): error.\n"); - answer = errno; - } else { - edg_wll_ll_log(LOG_INFO,"o.k.\n"); - if (count == 0) { - edg_wll_ll_log(LOG_DEBUG,"Waking up, timeout expired.\n"); - answer = EAGAIN; - } else { - edg_wll_ll_log(LOG_DEBUG,"Confirmation received, waking up.\n"); - } - } - } - } else { - edg_wll_ll_log(LOG_DEBUG,"NOT sending via IPC.\n"); - } - -edg_wll_log_proto_server_end: - /* if not sent already, send the answer back to client */ - if (!answer_sent) { - answer = send_answer_back(con,answer,timeout); - } - /* clean */ - edg_wll_FreeContext(context); - if (name_esc) free(name_esc); - if (dglllid) free(dglllid); - if (dguser) free(dguser); - if (jobId) free(jobId); - if (msg) free(msg); - if (event) free(event); - -// edg_wll_ll_log(LOG_INFO,"Done.\n"); - - return answer; - -edg_wll_log_proto_server_end_1: - if (event->any.priority) { - close(confirm_sock); - unlink(confirm_sock_name); - } - goto edg_wll_log_proto_server_end; -} - -/* - *---------------------------------------------------------------------- - * - * edg_wll_log_proto_server_failure - handle protocol failures on the server side - * - * Returns: errno - * - *---------------------------------------------------------------------- - */ -int edg_wll_log_proto_server_failure(int code, edg_wll_GssStatus *gss_code, const char *text) -{ - const char *func = "edg_wll_log_proto_server()"; - int ret = 0; - - if(code>0) { - return(0); - } - switch(code) { - case EDG_WLL_GSS_ERROR_EOF: - edg_wll_ll_log(LOG_ERR,"%s: %s, EOF occured\n", func, text); - ret = EAGAIN; - break; - case EDG_WLL_GSS_ERROR_TIMEOUT: - edg_wll_ll_log(LOG_ERR,"%s: %s, timeout expired\n", func, text); - ret = EAGAIN; - break; - case EDG_WLL_GSS_ERROR_ERRNO: - SYSTEM_ERROR(func); - edg_wll_ll_log(LOG_ERR,"%s: %s, system error occured\n", func, text); - ret = EAGAIN; - break; - case EDG_WLL_GSS_ERROR_GSS: - { - char *gss_err; - - edg_wll_gss_get_error(gss_code, "GSS error occured", &gss_err); - edg_wll_ll_log(LOG_ERR,"%s: %s, %s\n", func, text, gss_err); - free(gss_err); - ret = EAGAIN; - break; - } - default: - edg_wll_ll_log(LOG_ERR,"%s: %s, unknown error occured\n"); - break; - } - return ret; -} - -/* - *---------------------------------------------------------------------- - * - * edg_wll_ll_log_init - initialize the logging level - * - *---------------------------------------------------------------------- - */ -void edg_wll_ll_log_init(int level) { - edg_wll_ll_log_level = level; -} - -/* - *---------------------------------------------------------------------- - * - * edg_wll_ll_log - print to stderr according to logging level - * serious messages are also written to syslog - * - *---------------------------------------------------------------------- - */ -void edg_wll_ll_log(int level, const char *fmt, ...) { - char *err_text; - va_list fmt_args; - - va_start(fmt_args, fmt); - vasprintf(&err_text, fmt, fmt_args); - va_end(fmt_args); - - if(level <= edg_wll_ll_log_level) - fprintf(stderr, "[%d] %s", (int) getpid(), err_text); - if(level <= LOG_ERR) { - openlog(NULL, LOG_PID | LOG_CONS, LOG_DAEMON); - syslog(level, "%s", err_text); - closelog(); - } - - if (err_text) free(err_text); -} diff --git a/org.glite.lb.logger/src/logd_proto.h b/org.glite.lb.logger/src/logd_proto.h deleted file mode 100644 index 2754e4a..0000000 --- a/org.glite.lb.logger/src/logd_proto.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef __EDG_WORKLOAD_LOGGING_LOCALLOGGER_LOGD_PROTO_H__ -#define __EDG_WORKLOAD_LOGGING_LOCALLOGGER_LOGD_PROTO_H__ - -#ident "$Header$" - -/** - * \file edg/workload/logging/locallogger/logd_proto.h - * \brief server part of the logging protocol - * \note private - */ - -#ifdef __cplusplus -extern "C" { -#endif - - -#include - -#include "glite/lb/log_proto.h" -#include "glite/security/glite_gss.h" - -int edg_wll_log_proto_server(edg_wll_GssConnection *con, struct timeval *timeout, char *name, char *prefix, int noipc, int noparse); -int edg_wll_log_proto_server_failure(int code, edg_wll_GssStatus *gss_code, const char *text); - -#define SYSTEM_ERROR(my_err) { \ - if (errno !=0 ) \ - edg_wll_ll_log(LOG_ERR,"%s: %s\n",my_err,strerror(errno)); \ - else \ - edg_wll_ll_log(LOG_ERR,"%s\n",my_err); } - -/* locallogger daemon error handling */ -extern int edg_wll_ll_log_level; -void edg_wll_ll_log_init(int level); -void edg_wll_ll_log(int level, const char *fmt, ...); - - -/* fcntl defaults */ -#define FCNTL_ATTEMPTS 5 -#define FCNTL_TIMEOUT 1 - -/* connect defaults */ -#define CONNECT_ATTEMPTS 5 - -/* accept defaults */ -#define ACCEPT_TIMEOUT 30 - -/* connection defaults */ -#define CONNECTION_TIMEOUT EDG_WLL_LOG_SYNC_TIMEOUT_MAX - -/* locallogger daemon listen and connect functions prototypes */ -int do_listen(int port); -int do_connect(char *hostname, int port); - - -#ifdef __cplusplus -} -#endif - -#endif /* __EDG_WORKLOAD_LOGGING_LOCALLOGGER_LOGD_PROTO_H__ */ diff --git a/org.glite.lb.logger/src/perftest_il.sh b/org.glite.lb.logger/src/perftest_il.sh deleted file mode 100644 index e9d2ee5..0000000 --- a/org.glite.lb.logger/src/perftest_il.sh +++ /dev/null @@ -1,365 +0,0 @@ -#!/bin/bash - -numjobs=10 - -# XXX - there must be better way to find stage -if [ -z "${GLITE_LOCATION}" ]; then - STAGEDIR=/home/michal/shared/egee/jra1-head/stage -else - STAGEDIR=${GLITE_LOCATION} -fi - -. $STAGEDIR/sbin/perftest_common.sh - -DEBUG=${DEBUG:-0} -# CONSUMER_ARGS= -# PERFTEST_COMPONENT= -# COMPONENT_ARGS= -LOGJOBS_ARGS="-s /tmp/interlogger.perftest" - -check_test_files || exit 1 - -COMM_ARGS="-s /tmp/interlogger.perftest --file-prefix=/tmp/perftest.log" - -#TEST_GROUP= -#TEST_VARIANT= - -SILENT=0 -while getopts "G:t:n:s" OPTION -do - case "$OPTION" in - "G") TEST_GROUP=$OPTARG - ;; - - "t") TEST_VARIANT=$OPTARG - ;; - - "n") numjobs=$OPTARG - ;; - - "s") SILENT=1 - ;; - - esac -done - - -group_a () -{ -if [[ $SILENT -eq 0 ]] -then -echo "-------------------------------------------" -echo "Logging test:" -echo " - events sent through IPC and/or files" -echo " - events discarded by IL immediately" -echo "-------------------------------------------" -echo "a) events sent only by IPC" -echo "b) events stored to files and sent by IPC" -echo "" -fi - -PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-interlogd-perf-empty -CONSUMER_ARGS="-d $COMM_ARGS" -} - -group_a_test_a () -{ - LOGJOBS_ARGS="--nofile $COMM_ARGS" - echo -n "a)" - run_test il $numjobs - print_result -} - -group_a_test_b () { - LOGJOBS_ARGS=" $COMM_ARGS" - echo -n "b)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - - - -# echo "--------------------------------" -# echo "Interlogger test:" -# echo " - events sent through IPC only" -# echo " - events discarded in IL" -# echo "--------------------------------" -# echo "a) disabled event parsing, the server address (jobid) is hardcoded" -# echo "b) disabled event synchronization from files" -# echo "c) disabled recovery thread" -# echo "d) lazy bkserver connection close" -# echo "e) normal operation" -# echo "" -# echo -e "\tavg_job \t big_job \t avg_dag \t big_dag" - -# PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-interlogd-perf -# LOGJOBS_ARGS="--nofile $COMM_ARGS" - -# CONSUMER_ARGS="-d --nosend --noparse $COMM_ARGS" -# echo -n "a)" -# run_test il $numjobs -# print_result - -# CONSUMER_ARGS="-d --nosend --nosync $COMM_ARGS" -# echo -n "b)" -# run_test il $numjobs -# print_result - -# CONSUMER_ARGS="-d --nosend --norecover $COMM_ARGS" -# echo -n "c)" -# run_test il $numjobs -# print_result - -# echo "d) this test is not yet implemented" - -# CONSUMER_ARGS="-d --nosend $COMM_ARGS" -# echo -n "e)" -# run_test il $numjobs -# print_result - - -group_b () { -if [[ $SILENT -eq 0 ]] -then -echo "-----------------------------------" -echo "Interlogger test:" -echo " - events sent through IPC & files" -echo " - events discarded in IL" -echo "-----------------------------------" -echo "a) disabled event parsing, the server address (jobid) is hardcoded" -echo "b) disabled event synchronization from files" -echo "c) disabled recovery thread" -echo "x) disabled sync and recovery" -echo "d) lazy bkserver connection close" -echo "e) normal operation" -echo "" -fi -PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-interlogd-perf -LOGJOBS_ARGS=" $COMM_ARGS" -} - -group_b_test_a () -{ - CONSUMER_ARGS="-d --nosend --noparse $COMM_ARGS" - echo -n "a)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -group_b_test_b () -{ - CONSUMER_ARGS="-d --nosend --nosync $COMM_ARGS" - echo -n "b)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -group_b_test_c () -{ - CONSUMER_ARGS="-d --nosend --norecover $COMM_ARGS" - echo -n "c)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -group_b_test_x () -{ - CONSUMER_ARGS="-d --nosend --nosync --norecover $COMM_ARGS" - echo -n "x)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -group_b_test_d () -{ - echo "d) this test is not applicable" -} - -group_b_test_e () -{ - CONSUMER_ARGS="-d --nosend $COMM_ARGS" - echo -n "e)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -# echo "-------------------------------" -# echo "Interlogger test:" -# echo " - events sent through IPC" -# echo " - events consumed by empty BS" -# echo "-------------------------------" -# echo "a) disabled event parsing, the server address (jobid) is hardcoded" -# echo "b) disabled event synchronization from files" -# echo "c) disabled recovery thread" -# echo "d) lazy bkserver connection close" -# echo "e) normal operation" -# echo "" -# echo -e "\tavg_job \t big_job \t avg_dag \t big_dag" - -# PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-bkserverd -# CONSUMER_ARGS="-d --perf-sink=1" -# PERFTEST_COMPONENT=$STAGEDIR/bin/glite-lb-interlogd-perf -# LOGJOBS_ARGS="--nofile $COMM_ARGS" - - -# COMPONENT_ARGS="-d --noparse $COMM_ARGS" -# echo -n "a)" -# run_test il $numjobs -# print_result -# rm -f /tmp/perftest.log.* - -# COMPONENT_ARGS="-d --nosync $COMM_ARGS" -# echo -n "b)" -# run_test il $numjobs -# print_result -# rm -f /tmp/perftest.log.* - -# COMPONENT_ARGS="-d --norecover $COMM_ARGS" -# echo -n "c)" -# run_test il $numjobs -# print_result -# rm -f /tmp/perftest.log.* - -# echo "d) this test is not yet implemented" - -# COMPONENT_ARGS="-d $COMM_ARGS" -# echo -n "e)" -# run_test il $numjobs -# print_result -# rm -f /tmp/perftest.log.* - - -group_c () -{ -if [[ $SILENT -eq 0 ]] -then -echo "-----------------------------------" -echo "Interlogger test:" -echo " - events sent through IPC & files" -echo " - events consumed by empty BS" -echo "-----------------------------------" -echo "a) disabled event parsing, the server address (jobid) is hardcoded" -echo "b) disabled event synchronization from files" -echo "c) disabled recovery thread" -echo "x) disabled sync and recovery" -echo "d) lazy bkserver connection close" -echo "e) normal operation" -echo "" -fi - -PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-bkserverd -CONSUMER_ARGS="-d --perf-sink=1 -p 10500 -w 10503" -PERFTEST_COMPONENT=$STAGEDIR/bin/glite-lb-interlogd-perf -LOGJOBS_ARGS=" -m localhost:10500 $COMM_ARGS" -} - -group_c_test_a () -{ - COMPONENT_ARGS="-d --noparse $COMM_ARGS" - echo -n "a)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -group_c_test_b () -{ - COMPONENT_ARGS="-d --nosync $COMM_ARGS" - echo -n "b)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -group_c_test_c () -{ - COMPONENT_ARGS="-d --norecover $COMM_ARGS" - echo -n "c)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -group_c_test_x () -{ - COMPONENT_ARGS="-d --nosync --norecover $COMM_ARGS" - echo -n "x)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -group_c_test_d () -{ - COMPONENT_ARGS="-d --lazy=10 --nosync --norecover $COMM_ARGS" - echo -n "d)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - -group_c_test_e () -{ - COMPONENT_ARGS="-d $COMM_ARGS" - echo -n "e)" - run_test il $numjobs - print_result - rm -f /tmp/perftest.log.* -} - - -if [[ $SILENT -eq 0 ]] -then - while [[ -z $TEST_GROUP ]] - do - echo "Choose test group:" - echo " a) logging source tests" - echo " b) interlogger tests" - echo " c) interlogger with external consumer tests" - echo -n "Your choice: " - read TEST_GROUP - done -fi -TEST_GROUP=`echo $TEST_GROUP | tr '[A-Z]' '[a-z]'` - -if [[ "x$TEST_GROUP" = "x*" ]] -then - TEST_GROUP="a b c" -fi - -for group in $TEST_GROUP -do - group_$group - - if [[ $SILENT -eq 0 ]] - then - while [[ -z $TEST_VARIANT ]] - do - echo -n "Your choice: " - read -e TEST_VARIANT - done - echo -e "\tavg_job \t big_job \t avg_dag \t big_dag" - fi - - if [[ "x$TEST_VARIANT" = "x*" ]] - then - case $TEST_GROUP in - "a") TEST_VARIANT="a b" ;; - *) TEST_VARIANT="a b c x d e" ;; - esac - fi - - for variant in $TEST_VARIANT - do - group_${group}_test_${variant} - done -done - -exit; - diff --git a/org.glite.lb.logger/src/perftest_ll.sh b/org.glite.lb.logger/src/perftest_ll.sh deleted file mode 100644 index d6fc67d..0000000 --- a/org.glite.lb.logger/src/perftest_ll.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash - -numjobs=1 - -# XXX - there must be better way to find stage -if [ -z "${GLITE_LOCATION}" ]; then - STAGEDIR=/home/michal/shared/egee/jra1-head/stage -else - STAGEDIR=${GLITE_LOCATION} -fi - -. $STAGEDIR/sbin/perftest_common.sh - -SILENT=0 -while getopts "t:n:s" OPTION -do - case "$OPTION" in - "t") TEST_VARIANT=$OPTARG - ;; - - "n") numjobs=$OPTARG - ;; - - "s") SILENT=1 - ;; - - esac -done - -DEBUG=${DEBUG:-0} -# CONSUMER_ARGS= -# PERFTEST_COMPONENT= -# COMPONENT_ARGS= -# LOGJOBS_ARGS="" -COMM_ARGS="--file-prefix /tmp/perftest.log -p 45678" -export EDG_WL_LOG_DESTINATION="localhost:45678" - -check_test_files || exit 1 - -group_a () { -echo "---------------- -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: $numjobs -" -} - - -# a) -group_a_test_a () -{ -echo -n "a)" -PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-logd-perf-nofile -CONSUMER_ARGS="-d --noIPC --noParse $COMM_ARGS" -init_result -run_test ll $numjobs -#print_result_ev -print_result -} - -# b) -group_a_test_b () -{ -echo -n "b)" -PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-logd-perf-nofile -CONSUMER_ARGS="-d --noIPC $COMM_ARGS" -init_result -run_test ll $numjobs -#print_result_ev -print_result -} - -# c) -group_a_test_c () -{ -echo -n "c)" -PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-logd-perf -CONSUMER_ARGS="-d --noIPC $COMM_ARGS" -init_result -run_test ll $numjobs -#print_result_ev -print_result -rm -f /tmp/perftest.log.* -} - -# d) -group_a_test_d () -{ -echo -n "d)" -PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-interlogd-perf-empty -CONSUMER_ARGS="-d -s /tmp/perftest.sock" -PERFTEST_COMPONENT=$STAGEDIR/bin/glite-lb-logd-perf -COMPONENT_ARGS="-d -s /tmp/perftest.sock $COMM_ARGS" -init_result -run_test ll $numjobs -#print_result_ev -print_result -rm -f /tmp/perftest.log.* -} - -group="a" - -group_$group - -if [[ $SILENT -eq 0 ]] -then - while [[ -z $TEST_VARIANT ]] - do - echo -n "Your choice: " - read -e TEST_VARIANT - done - echo -e "\tavg_job \t big_job \t avg_dag \t big_dag" -fi - -if [[ "x$TEST_VARIANT" = "x*" ]] -then - TEST_VARIANT="a b c d" -fi - -for variant in $TEST_VARIANT -do - group_${group}_test_${variant} -done diff --git a/org.glite.lb.logger/src/queue_mgr.c b/org.glite.lb.logger/src/queue_mgr.c deleted file mode 100644 index 2879e14..0000000 --- a/org.glite.lb.logger/src/queue_mgr.c +++ /dev/null @@ -1,269 +0,0 @@ -#ident "$Header$" - -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lb/context.h" - -#include "interlogd.h" - -struct queue_list { - struct event_queue *queue; - char *dest; - struct queue_list *next; -#if defined(IL_NOTIFICATIONS) - time_t expires; -#endif -}; - -static struct event_queue *log_queue; -static struct queue_list *queues; - - -static -int -queue_list_create() -{ - queues = NULL; - - return(0); -} - - -static -int -queue_list_find(struct queue_list *ql, const char *dest, struct queue_list **el, struct queue_list **prev) -{ - struct queue_list *q, *p; - - assert(el != NULL); - - *el = NULL; - if(prev) - *prev = NULL; - - if(ql == NULL) - return(0); - - q = NULL; - p = ql; - - while(p) { - if(strcmp(p->dest, dest) == 0) { - *el = p; - if(prev) - *prev = q; - return(1); - } - - q = p; - p = p->next; - }; - - return(0); -} - - -static -int -queue_list_add(struct queue_list **ql, const char *dest, struct event_queue *eq) -{ - struct queue_list *el; - - assert(dest != NULL); - assert(eq != NULL); - assert(ql != NULL); - - el = malloc(sizeof(*el)); - if(el == NULL) { - set_error(IL_NOMEM, ENOMEM, "queue_list_add: not enough room for new queue"); - return(-1); - } - - el->dest = strdup(dest); - if(el->dest == NULL) { - free(el); - set_error(IL_NOMEM, ENOMEM, "queue_list_add: not enough memory for new queue"); - return(-1); - } - el->queue = eq; - el->next = *ql; - *ql = el; - return 0; -} - - -#if !defined(IL_NOTIFICATIONS) -static -char * -jobid2dest(edg_wlc_JobId jobid) -{ - char *server_name,*out; - unsigned int server_port; - - if (!jobid) { - set_error(IL_PROTO, EDG_WLL_ERROR_PARSE_BROKEN_ULM, "jobid2dest: invalid job id"); - return(NULL); - } - edg_wlc_JobIdGetServerParts(jobid,&server_name,&server_port); - - asprintf(&out,"%s:%d",server_name,server_port); - free(server_name); - if(!out) - set_error(IL_SYS, ENOMEM, "jobid2dest: error creating server name"); - return(out); -} -#endif - -struct event_queue * -queue_list_get(char *job_id_s) -{ - char *dest; - struct queue_list *q; - struct event_queue *eq; -#if !defined(IL_NOTIFICATIONS) - IL_EVENT_ID_T job_id; - - if(job_id_s == NULL || strcmp(job_id_s, "default") == 0) - return(log_queue); - - if(edg_wlc_JobIdParse(job_id_s, &job_id)) { - set_error(IL_LBAPI, EDG_WLL_ERROR_PARSE_BROKEN_ULM, "queue_list_get: invalid job id"); - return(NULL); - } - - dest = jobid2dest(job_id); - edg_wlc_JobIdFree(job_id); -#else - dest = job_id_s; -#endif - - if(dest == NULL) - return(NULL); - - if(queue_list_find(queues, dest, &q, NULL)) { -#if !defined(IL_NOTIFICATIONS) - free(dest); -#endif - return(q->queue); - } else { - eq = event_queue_create(dest); - if(eq) - queue_list_add(&queues, dest, eq); -#if !defined(IL_NOTIFICATIONS) - free(dest); -#endif - return(eq); - } -} - - -int -queue_list_is_log(struct event_queue *eq) -{ - return(eq == queue_list_get(NULL)); -} - - -int -queue_list_init(char *ls) -{ -#if !defined(IL_NOTIFICATIONS) - /* create queue for log server */ - log_queue = event_queue_create(ls); - if(log_queue == NULL) - return(-1); -#endif - - return(queue_list_create()); -} - - -static struct queue_list *current; - - -struct event_queue * -queue_list_first() -{ - current = queues; - return(current ? current->queue : NULL); -} - - -struct event_queue * -queue_list_next() -{ - current = current ? current->next : NULL; - return(current ? current->queue : NULL); -} - - -int -queue_list_remove_queue(struct event_queue *eq) -{ - assert(eq != NULL); - - free(eq); - return(1); -} - - -#if defined(IL_NOTIFICATIONS) - -static struct queue_list *notifid_map = NULL; - -struct event_queue * -notifid_map_get_dest(const char * notif_id) -{ - struct queue_list *q = NULL; - - queue_list_find(notifid_map, notif_id, &q, NULL); - return(q ? q->queue : NULL); -} - - -/* returns 1 if mapping was changed, 0 if new one had to be created, -1 on error */ -int -notifid_map_set_dest(const char *notif_id, struct event_queue *eq) -{ - struct queue_list *q; - - if(queue_list_find(notifid_map, notif_id, &q, NULL)) { - q->queue = eq; - return(1); - } else { - return(queue_list_add(¬ifid_map, notif_id, eq)); - } -} - - -time_t -notifid_map_get_expiration(const char * notif_id) -{ - struct queue_list *q; - - queue_list_find(notifid_map, notif_id, &q, NULL); - return(q ? q->expires : 0); -} - - -int -notifid_map_set_expiration(const char *notif_id, time_t exp) -{ - struct queue_list *q; - - if(queue_list_find(notifid_map, notif_id, &q, NULL)) { - q->expires = exp; - return(1); - } else { - return(0); - } -} - -#endif - -/* Local Variables: */ -/* c-indentation-style: gnu */ -/* End: */ diff --git a/org.glite.lb.logger/src/queue_mgr_http.c b/org.glite.lb.logger/src/queue_mgr_http.c deleted file mode 100644 index 777e620..0000000 --- a/org.glite.lb.logger/src/queue_mgr_http.c +++ /dev/null @@ -1,164 +0,0 @@ -#ident "$Header$" - -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lb/context.h" - -#include "interlogd.h" - -struct queue_list { - struct event_queue *queue; - char *dest; - struct queue_list *next; - time_t expires; -}; - -static struct event_queue *log_queue; -static struct queue_list *queues; - - -static -int -queue_list_create() -{ - queues = NULL; - - return(0); -} - - -static -int -queue_list_find(struct queue_list *ql, const char *dest, struct queue_list **el, struct queue_list **prev) -{ - struct queue_list *q, *p; - - assert(el != NULL); - - *el = NULL; - if(prev) - *prev = NULL; - - if(ql == NULL) - return(0); - - q = NULL; - p = ql; - - while(p) { - if(strcmp(p->dest, dest) == 0) { - *el = p; - if(prev) - *prev = q; - return(1); - } - - q = p; - p = p->next; - }; - - return(0); -} - - -static -int -queue_list_add(struct queue_list **ql, const char *dest, struct event_queue *eq) -{ - struct queue_list *el; - - assert(dest != NULL); - assert(eq != NULL); - assert(ql != NULL); - - el = malloc(sizeof(*el)); - if(el == NULL) { - set_error(IL_NOMEM, ENOMEM, "queue_list_add: not enough room for new queue"); - return(-1); - } - - el->dest = strdup(dest); - if(el->dest == NULL) { - free(el); - set_error(IL_NOMEM, ENOMEM, "queue_list_add: not enough memory for new queue"); - return(-1); - } - el->queue = eq; - el->next = *ql; - *ql = el; - return 0; -} - - -struct event_queue * -queue_list_get(char *job_id_s) -{ - char *dest; - struct queue_list *q; - struct event_queue *eq; - dest = job_id_s; - - if(dest == NULL) - return(NULL); - - if(queue_list_find(queues, dest, &q, NULL)) { - return(q->queue); - } else { - eq = event_queue_create(dest); - if(eq) - queue_list_add(&queues, dest, eq); - return(eq); - } -} - - -int -queue_list_is_log(struct event_queue *eq) -{ - return(eq == queue_list_get(NULL)); -} - - -int -queue_list_init(char *ls) -{ - return(queue_list_create()); -} - - -static struct queue_list *current; - - -struct event_queue * -queue_list_first() -{ - current = queues; - return(current ? current->queue : NULL); -} - - -struct event_queue * -queue_list_next() -{ - current = current ? current->next : NULL; - return(current ? current->queue : NULL); -} - - -int -queue_list_remove_queue(struct event_queue *eq) -{ - assert(eq != NULL); - - free(eq); - return(1); -} - - - -/* Local Variables: */ -/* c-indentation-style: gnu */ -/* End: */ diff --git a/org.glite.lb.logger/src/queue_thread.c b/org.glite.lb.logger/src/queue_thread.c deleted file mode 100644 index 20c25e7..0000000 --- a/org.glite.lb.logger/src/queue_thread.c +++ /dev/null @@ -1,426 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include - -#include "interlogd.h" - -static -void -queue_thread_cleanup(void *q) -{ - struct event_queue *eq = (struct event_queue *)q; - - il_log(LOG_WARNING, "thread %d exits\n", eq->thread_id); - - /* unlock all held locks */ - /* FIXME: check that the thread always exits when holding these locks; - unlock them at appropriate places if this condition is not met - event_queue_unlock(eq); - event_queue_cond_unlock(eq); - */ - - /* clear thread id */ - eq->thread_id = 0; -} - - -static time_t now; - -static -int -cmp_expires(struct server_msg *msg, void *data) -{ - time_t *t = (time_t*)data; - return (msg->expires > 0) && (msg->expires < *t); -} - -static -void * -queue_thread(void *q) -{ - struct event_queue *eq = (struct event_queue *)q; - int ret, exit; - int retrycnt; - int close_timeout = 0; - int exit_timeout = EXIT_TIMEOUT; - - if(init_errors(0) < 0) { - il_log(LOG_ERR, "Error initializing thread specific data, exiting!"); - pthread_exit(NULL); - } - - il_log(LOG_DEBUG, " started new thread for delivery to %s:%d\n", eq->dest_name, eq->dest_port); - - pthread_cleanup_push(queue_thread_cleanup, q); - - event_queue_cond_lock(eq); - - exit = 0; - retrycnt = 0; - while(!exit) { - - clear_error(); - - /* if there are no events, wait for them */ - ret = 0; - while (event_queue_empty(eq) -#if defined(INTERLOGD_HANDLE_CMD) && defined(INTERLOGD_FLUSH) - && (eq->flushing != 1) -#endif - ) { - if(lazy_close && close_timeout) { - ret = event_queue_wait(eq, close_timeout); - if(ret == 1) {/* timeout? */ - event_queue_close(eq); - il_log(LOG_DEBUG, " connection to %s:%d closed\n", - eq->dest_name, eq->dest_port); - } - close_timeout = 0; - } else { - ret = event_queue_wait(eq, exit_timeout); - if(ret == 1) { - il_log(LOG_INFO, " thread idle for more than %d seconds, exiting\n", exit_timeout); - event_queue_close(eq); - event_queue_cond_unlock(eq); - pthread_exit((void*)0); - } - } - if(ret < 0) { - /* error waiting */ - il_log(LOG_ERR, "queue_thread: %s\n", error_get_msg()); - event_queue_cond_unlock(eq); - pthread_exit((void*)-1); - } - } /* END while(empty) */ - - - /* allow other threads to signal us, ie. insert new events while - * we are sending or request flush operation - */ - event_queue_cond_unlock(eq); - - /* discard expired events */ - il_log(LOG_DEBUG, " discarding expired events\n"); - now = time(NULL); - event_queue_move_events(eq, NULL, cmp_expires, &now); - if(!event_queue_empty(eq)) { - - /* deliver pending events */ - il_log(LOG_DEBUG, " attempting delivery to %s:%d\n", eq->dest_name, eq->dest_port); - /* connect to server */ - if((ret=event_queue_connect(eq)) == 0) { - /* not connected */ - if(error_get_maj() != IL_OK) - il_log(LOG_ERR, "queue_thread: %s\n", error_get_msg()); -#if defined(IL_NOTIFICATIONS) - il_log(LOG_INFO, " could not connect to client %s, waiting for retry\n", eq->dest_name); -#else - il_log(LOG_INFO, " could not connect to bookkeeping server %s, waiting for retry\n", eq->dest_name); -#endif - retrycnt++; - } else { - retrycnt = 0; - /* connected, send events */ - switch(ret=event_queue_send(eq)) { - - case 0: - /* there was an error and we still have events to send */ - if(error_get_maj() != IL_OK) - il_log(LOG_ERR, "queue_thread: %s\n", error_get_msg()); - il_log(LOG_DEBUG, " events still waiting\n"); - break; - - case 1: - /* hey, we are done for now */ - il_log(LOG_DEBUG, " all events for %s sent\n", eq->dest_name); - break; - - default: - /* internal error */ - il_log(LOG_ERR, "queue_thread: %s\n", error_get_msg()); - exit = 1; - break; - - } /* switch */ - - /* we are done for now anyway, so close the queue */ - if((ret == 1) && lazy_close) - close_timeout = default_close_timeout; - else { - event_queue_close(eq); - il_log(LOG_DEBUG, " connection to %s:%d closed\n", - eq->dest_name, eq->dest_port); - } - } - } - -#if defined(INTERLOGD_HANDLE_CMD) && defined(INTERLOGD_FLUSH) - if(pthread_mutex_lock(&flush_lock) < 0) - abort(); - event_queue_cond_lock(eq); - - /* Check if we are flushing and if we are, report status to master */ - if(eq->flushing == 1) { - il_log(LOG_DEBUG, " flushing mode detected, reporting status\n"); - /* 0 - events waiting, 1 - events sent, < 0 - some error */ - eq->flush_result = ret; - eq->flushing = 2; - if(pthread_cond_signal(&flush_cond) < 0) - abort(); - } - if(pthread_mutex_unlock(&flush_lock) < 0) - abort(); -#else -#endif - - /* if there was some error with server, sleep for a while */ - /* iff !event_queue_empty() */ - /* also allow for one more try immediately after server disconnect, - which may cure server kicking us out after given number of connections */ -#ifndef LB_PERF - if((ret == 0) && (retrycnt > 0)) { - il_log(LOG_WARNING, " sleeping\n"); - event_queue_sleep(eq); - } -#endif - -#if defined(INTERLOGD_HANDLE_CMD) && defined(INTERLOGD_FLUSH) -#else - event_queue_cond_lock(eq); -#endif - - if(exit) { - /* we have to clean up before exiting */ - event_queue_cond_unlock(eq); - } - - } /* while */ - - pthread_cleanup_pop(1); - - return(eq); -} - - -int -event_queue_create_thread(struct event_queue *eq) -{ - assert(eq != NULL); - - event_queue_lock(eq); - - /* if there is a thread already, just return */ - if(eq->thread_id > 0) { - event_queue_unlock(eq); - return(0); - } - - /* create the thread itself */ - if(pthread_create(&eq->thread_id, NULL, queue_thread, eq) < 0) { - eq->thread_id = 0; - set_error(IL_SYS, errno, "event_queue_create_thread: error creating new thread"); - event_queue_unlock(eq); - return(-1); - } - - /* the thread is never going to be joined */ - pthread_detach(eq->thread_id); - - event_queue_unlock(eq); - - return(1); -} - - - -int -event_queue_lock(struct event_queue *eq) -{ - assert(eq != NULL); - - if(pthread_rwlock_wrlock(&eq->update_lock)) { - /*** abort instead, this is too serious - set_error(IL_SYS, errno, "event_queue_lock: error acquiring write lock"); - return(-1); - */ - abort(); - } - - return(0); -} - - -int -event_queue_lock_ro(struct event_queue *eq) -{ - assert(eq != NULL); - - if(pthread_rwlock_rdlock(&eq->update_lock)) { - /*** abort instead, this is too serious - set_error(IL_SYS, errno, "event_queue_lock_ro: error acquiring read lock"); - return(-1); - */ - abort(); - } - - return(0); -} - - -int -event_queue_unlock(struct event_queue *eq) -{ - assert(eq != NULL); - - if(pthread_rwlock_unlock(&eq->update_lock)) { - /*** abort instead, this is too serious - set_error(IL_SYS, errno, "event_queue_unlock: error releasing lock"); - return(-1); - */ - abort(); - } - - return(0); -} - - -int -event_queue_signal(struct event_queue *eq) -{ - assert(eq != NULL); - - if(pthread_cond_signal(&eq->ready_cond)) { - /*** abort instead, this is too serious - set_error(IL_SYS, errno, "event_queue_signal: error signaling queue thread"); - return(-1); - */ - abort(); - } - return(0); -} - - -int -event_queue_wait(struct event_queue *eq, int timeout) -{ - assert(eq != NULL); - - if(timeout) { - struct timespec endtime; - int ret = 0; - - endtime.tv_sec = time(NULL) + timeout; - endtime.tv_nsec = 0; - - if((ret=pthread_cond_timedwait(&eq->ready_cond, &eq->cond_lock, &endtime))) { - if(ret == ETIMEDOUT) - return(1); - /*** abort instead, this is too serious - set_error(IL_SYS, errno, "event_queue_wait: error waiting on condition variable"); - return(-1); - */ - abort(); - } - } else { - if(pthread_cond_wait(&eq->ready_cond, &eq->cond_lock)) { - /*** abort instead, this is too serious - set_error(IL_SYS, errno, "event_queue_wait: error waiting on condition variable"); - return(-1); - */ - abort(); - } - } - return(0); -} - - -int event_queue_sleep(struct event_queue *eq) -{ -#if defined(INTERLOGD_HANDLE_CMD) && defined(INTERLOGD_FLUSH) - struct timespec ts; - struct timeval tv; - int ret; - - assert(eq != NULL); - - gettimeofday(&tv, NULL); - ts.tv_sec = tv.tv_sec + eq->timeout; - ts.tv_nsec = 1000 * tv.tv_usec; - if((ret=pthread_cond_timedwait(&eq->flush_cond, &eq->cond_lock, &ts)) < 0) { - if(ret != ETIMEDOUT) { - /*** abort instead, this is too serious - set_error(IL_SYS, errno, "event_queue_sleep: error waiting on condition"); - return(-1); - */ - abort(); - } - } -#else - sleep(eq->timeout); -#endif - return(0); -} - - -#if defined(INTERLOGD_HANDLE_CMD) -int event_queue_wakeup(struct event_queue *eq) -{ - assert(eq != NULL); - - if(pthread_cond_signal(&eq->ready_cond)) { - /** - set_error(IL_SYS, errno, "event_queue_wakeup: error signaling queue thread"); - return(-1); - */ - abort(); - } -#if defined(INTERLOGD_FLUSH) - if(pthread_cond_signal(&eq->flush_cond)) { - /** - set_error(IL_SYS, errno, "event_queue_wakeup: error signaling queue thread"); - return(-1); - */ - abort(); - } -#endif - return(0); -} -#endif - -int event_queue_cond_lock(struct event_queue *eq) -{ - assert(eq != NULL); - - if(pthread_mutex_lock(&eq->cond_lock)) { - /** - set_error(IL_SYS, errno, "event_queue_cond_lock: error locking condition mutex"); - return(-1); - */ - abort(); - } - - return(0); -} - - -int event_queue_cond_unlock(struct event_queue *eq) -{ - assert(eq != NULL); - - if(pthread_mutex_unlock(&eq->cond_lock)) { - /** - set_error(IL_SYS, errno, "event_queue_cond_unlock: error locking condition mutex"); - return(-1); - */ - abort(); - } - - return(0); -} - -/* Local Variables: */ -/* c-indentation-style: linux */ -/* End: */ diff --git a/org.glite.lb.logger/src/recover.c b/org.glite.lb.logger/src/recover.c deleted file mode 100644 index 18fc3b4..0000000 --- a/org.glite.lb.logger/src/recover.c +++ /dev/null @@ -1,65 +0,0 @@ -#ident "$Header$" - -#include -#include -#include - -#include "interlogd.h" - -extern char *file_prefix; - -extern time_t cert_mtime, key_mtime; - -void * -recover_thread(void *q) -{ - if(init_errors(0) < 0) { - il_log(LOG_ERR, "Error initializing thread specific data, exiting!"); - pthread_exit(NULL); - } - - while(1) { - il_log(LOG_INFO, "Looking up event files...\n"); - if(event_store_init(file_prefix) < 0) { - il_log(LOG_ERR, "recover_thread: %s\n", error_get_msg()); - exit(1); - } - if(event_store_recover_all() < 0) { - il_log(LOG_ERR, "recover_thread: %s\n", error_get_msg()); - exit(1); - } - if(event_store_cleanup() < 0) { - il_log(LOG_ERR, "recover_thread: %s\n", error_get_msg()); - exit(1); - } - il_log(LOG_INFO, "Reloading certificate...\n"); - if (edg_wll_gss_watch_creds(cert_file, &cert_mtime) > 0) { - edg_wll_GssCred new_creds = NULL; - int ret; - - ret = edg_wll_gss_acquire_cred_gsi(cert_file,key_file, - &new_creds, NULL); - if (new_creds != NULL) { - if(pthread_mutex_lock(&cred_handle_lock) < 0) - abort(); - /* if no one is using the old credentials, release them */ - if(cred_handle && cred_handle->counter == 0) { - edg_wll_gss_release_cred(&cred_handle->creds, NULL); - free(cred_handle); - il_log(LOG_DEBUG, " freed old credentials\n"); - } - cred_handle = malloc(sizeof(*cred_handle)); - if(cred_handle == NULL) { - il_log(LOG_CRIT, "Failed to allocate structure for credentials.\n"); - exit(EXIT_FAILURE); - } - cred_handle->creds = new_creds; - cred_handle->counter = 0; - if(pthread_mutex_unlock(&cred_handle_lock) < 0) - abort(); - il_log(LOG_INFO, "New certificate found and deployed.\n"); - } - } - sleep(INPUT_TIMEOUT); - } -} diff --git a/org.glite.lb.logger/src/send_event.c b/org.glite.lb.logger/src/send_event.c deleted file mode 100644 index 4796859..0000000 --- a/org.glite.lb.logger/src/send_event.c +++ /dev/null @@ -1,365 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#include -#include -#include - - -/* - * - L/B server protocol handling routines - */ - -#include "glite/jobid/cjobid.h" -#include "glite/lb/il_string.h" -#include "glite/lb/context.h" - -#include "interlogd.h" - -#if defined(INTERLOGD_EMS) || (defined(INTERLOGD_HANDLE_CMD) && defined(INTERLOGD_FLUSH)) -/* - * Send confirmation to client. - * - */ -int -send_confirmation(long lllid, int code) -{ - struct sockaddr_un saddr; - char sname[256]; - int sock, ret; - - if((sock=socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { - set_error(IL_SYS, errno, "send_confirmation: error creating socket"); - return(-1); - } - - if(fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { - set_error(IL_SYS, errno, "send_confirmation: error setting socket options"); - return(-1); - } - - ret = 0; - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - snprintf(sname, sizeof(sname), "/tmp/dglogd_sock_%ld", lllid); - strcpy(saddr.sun_path, sname); - if(connect(sock, (struct sockaddr *)&saddr, sizeof(saddr.sun_path)) < 0) { - set_error(IL_SYS, errno, "send_confirmation: error connecting socket"); - goto out; - } - - if(send(sock, &code, sizeof(code), MSG_NOSIGNAL) < 0) { - set_error(IL_SYS, errno, "send_confirmation: error sending data"); - goto out; - } - ret = 1; - - il_log(LOG_DEBUG, " sent code %d back to client\n", code); - - out: - close(sock); - return(ret); -} - - -static -int -confirm_msg(struct server_msg *msg, int code, int code_min) -{ - switch(code) { - case LB_OK: - code_min = 0; - break; - case LB_DBERR: - /* code_min already contains apropriate error code */ - break; - case LB_PROTO: - code_min = EDG_WLL_IL_PROTO; - break; - default: - code_min = EDG_WLL_IL_SYS; - break; - } - - return(send_confirmation(msg->receipt_to, code_min)); -} -#endif - - - -struct reader_data { - edg_wll_GssConnection *gss; - struct timeval *timeout; -}; - - -static -int -gss_reader(void *user_data, char *buffer, int max_len) -{ - int ret; - size_t len; - struct reader_data *data = (struct reader_data *)user_data; - edg_wll_GssStatus gss_stat; - - ret = edg_wll_gss_read_full(data->gss, buffer, max_len, data->timeout, &len, &gss_stat); - if(ret < 0) { - char *gss_err = NULL; - - if(ret == EDG_WLL_GSS_ERROR_GSS) { - edg_wll_gss_get_error(&gss_stat, "get_reply", &gss_err); - set_error(IL_DGGSS, ret, gss_err); - free(gss_err); - } else - set_error(IL_DGGSS, ret, "get_reply"); - } - return(ret); -} - - -/* - * Read reply from server. - * Returns: -1 - error reading message, - * code > 0 - error code from server - */ -static -int -get_reply(struct event_queue *eq, char **buf, int *code_min) -{ - char *msg=NULL; - int ret, code; - int len, l; - struct timeval tv; - struct reader_data data; - - tv.tv_sec = TIMEOUT; - tv.tv_usec = 0; - data.gss = &eq->gss; - data.timeout = &tv; - len = read_il_data(&data, &msg, gss_reader); - if(len < 0) { - set_error(IL_PROTO, LB_PROTO, "get_reply: error reading server reply"); - return(-1); - } - ret = decode_il_reply(&code, code_min, buf, msg); - if(msg) free(msg); - if(ret < 0) { - set_error(IL_PROTO, LB_PROTO, "get_reply: error decoding server reply"); - return(-1); - } - return(code); -} - - - -/* - * Returns: 0 - not connected, timeout set, 1 - OK - */ -int -event_queue_connect(struct event_queue *eq) -{ - int ret; - struct timeval tv; - edg_wll_GssStatus gss_stat; - cred_handle_t *local_cred_handle; - - assert(eq != NULL); - -#ifdef LB_PERF - if(!nosend) { -#endif - - if(eq->gss.context == NULL) { - - tv.tv_sec = TIMEOUT; - tv.tv_usec = 0; - - /* get pointer to the credentials */ - if(pthread_mutex_lock(&cred_handle_lock) < 0) - abort(); - local_cred_handle = cred_handle; - local_cred_handle->counter++; - if(pthread_mutex_unlock(&cred_handle_lock) < 0) - abort(); - - il_log(LOG_DEBUG, " trying to connect to %s:%d\n", eq->dest_name, eq->dest_port); - ret = edg_wll_gss_connect(local_cred_handle->creds, eq->dest_name, eq->dest_port, &tv, &eq->gss, &gss_stat); - if(pthread_mutex_lock(&cred_handle_lock) < 0) - abort(); - /* check if we need to release the credentials */ - --local_cred_handle->counter; - if(local_cred_handle != cred_handle && local_cred_handle->counter == 0) { - edg_wll_gss_release_cred(&local_cred_handle->creds, NULL); - free(local_cred_handle); - il_log(LOG_DEBUG, " freed credentials, not used anymore\n"); - } - if(pthread_mutex_unlock(&cred_handle_lock) < 0) - abort(); - - if(ret < 0) { - char *gss_err = NULL; - - if (ret == EDG_WLL_GSS_ERROR_GSS) - edg_wll_gss_get_error(&gss_stat, "event_queue_connect: edg_wll_gss_connect", &gss_err); - set_error(IL_DGGSS, ret, - (ret == EDG_WLL_GSS_ERROR_GSS) ? gss_err : "event_queue_connect: edg_wll_gss_connect"); - if (gss_err) free(gss_err); - eq->gss.context = NULL; - eq->timeout = TIMEOUT; - return(0); - } - } - -#ifdef LB_PERF - } -#endif - - return(1); -} - - -int -event_queue_close(struct event_queue *eq) -{ - assert(eq != NULL); - -#ifdef LB_PERF - if(!nosend) { -#endif - - if(eq->gss.context != NULL) { - edg_wll_gss_close(&eq->gss, NULL); - eq->gss.context = NULL; - } -#ifdef LB_PERF - } -#endif - return(0); -} - - -/* - * Send all events from the queue. - * Returns: -1 - system error, 0 - not send, 1 - queue empty - */ -int -event_queue_send(struct event_queue *eq) -{ - int events_sent = 0; - assert(eq != NULL); - -#ifdef LB_PERF - if(!nosend) { -#endif - if(eq->gss.context == NULL) - return(0); -#ifdef LB_PERF - } -#endif - - /* feed the server with events */ - while (!event_queue_empty(eq)) { - struct server_msg *msg; - char *rep; - int ret, code, code_min; - size_t bytes_sent; - struct timeval tv; - edg_wll_GssStatus gss_stat; - - clear_error(); - - if(event_queue_get(eq, &msg) < 0) - return(-1); - - il_log(LOG_DEBUG, " trying to deliver event at offset %d for job %s\n", msg->offset, msg->job_id_s); - -#ifdef LB_PERF - if(!nosend) { -#endif - if (msg->len) { - tv.tv_sec = TIMEOUT; - tv.tv_usec = 0; - ret = edg_wll_gss_write_full(&eq->gss, msg->msg, msg->len, &tv, &bytes_sent, &gss_stat); - if(ret < 0) { - if (ret == EDG_WLL_GSS_ERROR_ERRNO && errno == EPIPE && events_sent > 0) - eq->timeout = 0; - else - eq->timeout = TIMEOUT; - return(0); - } - - if((code = get_reply(eq, &rep, &code_min)) < 0) { - /* could not get the reply properly, so try again later */ - if (events_sent>0) { - /* could be expected server connection preemption */ - clear_error(); - eq->timeout = 1; - } else { - eq->timeout = TIMEOUT; - il_log(LOG_ERR, " error reading server %s reply:\n %s\n", eq->dest_name, error_get_msg()); - } - return(0); - } - } - else { code = LB_OK; code_min = 0; rep = strdup("not sending empty message"); } -#ifdef LB_PERF - } else { - glite_wll_perftest_consumeEventIlMsg(msg->msg+17); - code = LB_OK; - rep = strdup("OK"); - } -#endif - - il_log(LOG_DEBUG, " event sent, server %s replied with %d, %s\n", eq->dest_name, code, rep); - free(rep); - - /* the reply is back here */ - switch(code) { - - /* NOT USED: case LB_TIME: */ - case LB_NOMEM: - /* NOT USED: case LB_SYS: */ - /* NOT USED: case LB_AUTH: */ - /* non fatal errors (for us) */ - eq->timeout = TIMEOUT; - return(0); - - case LB_OK: - /* event succesfully delivered */ - - default: /* LB_DBERR, LB_PROTO */ - /* the event was not accepted by the server */ - /* update the event pointer */ - if(event_store_commit(msg->es, msg->ev_len, queue_list_is_log(eq), msg->generation) < 0) - /* failure committing message, this is bad */ - return(-1); - /* if we have just delivered priority message from the queue, send confirmation */ - ret = 1; -#if defined(INTERLOGD_EMS) - if(server_msg_is_priority(msg) && - ((ret=confirm_msg(msg, code, code_min)) < 0)) - return(ret); -#endif - - if((ret == 0) && - (error_get_maj() != IL_OK)) - il_log(LOG_ERR, "send_event: %s\n", error_get_msg()); - - event_queue_remove(eq); - events_sent++; - break; - - } /* switch */ - } /* while */ - - return(1); - -} /* send_events */ - - diff --git a/org.glite.lb.logger/src/send_event_http.c b/org.glite.lb.logger/src/send_event_http.c deleted file mode 100644 index 3c90562..0000000 --- a/org.glite.lb.logger/src/send_event_http.c +++ /dev/null @@ -1,282 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include -#include -#include -#include - - -/* - * - L/B server protocol handling routines - */ - -#include "glite/jobid/cjobid.h" -#include "glite/lb/il_string.h" -#include "glite/lb/context.h" - -#include "interlogd.h" - -struct reader_data { - edg_wll_GssConnection *gss; - struct timeval *timeout; -}; - - -static -int -gss_reader(void *user_data, char *buffer, int max_len) -{ - int ret; - struct reader_data *data = (struct reader_data *)user_data; - edg_wll_GssStatus gss_stat; - - ret = edg_wll_gss_read(data->gss, buffer, max_len, data->timeout, &gss_stat); - if(ret < 0) { - char *gss_err = NULL; - - if(ret == EDG_WLL_GSS_ERROR_GSS) { - edg_wll_gss_get_error(&gss_stat, "get_reply", &gss_err); - set_error(IL_DGGSS, ret, gss_err); - free(gss_err); - } else - set_error(IL_DGGSS, ret, "get_reply"); - } - return(ret); -} - - -/* - * Read reply from server. - * Returns: -1 - error reading message, - * code > 0 - http status code from server - */ -static -int -get_reply(struct event_queue *eq, char **buf, int *code_min) -{ - int ret, code; - int len; - struct timeval tv; - struct reader_data data; - il_http_message_t msg; - - tv.tv_sec = TIMEOUT; - tv.tv_usec = 0; - data.gss = &eq->gss; - data.timeout = &tv; - len = receive_http(&data, gss_reader, &msg); - if(len < 0) { - set_error(IL_PROTO, LB_PROTO, "get_reply: error reading server reply"); - return(-1); - } - if(msg.data) free(msg.data); - if(msg.reply_string) *buf = msg.reply_string; - *code_min = 0; /* XXX fill in flag for fault */ - return(msg.reply_code); -} - - - -/* - * Returns: 0 - not connected, timeout set, 1 - OK - */ -int -event_queue_connect(struct event_queue *eq) -{ - int ret; - struct timeval tv; - edg_wll_GssStatus gss_stat; - cred_handle_t *local_cred_handle; - - assert(eq != NULL); - -#ifdef LB_PERF - if(!nosend) { -#endif - - if(eq->gss.context == NULL) { - - tv.tv_sec = TIMEOUT; - tv.tv_usec = 0; - - /* get pointer to the credentials */ - if(pthread_mutex_lock(&cred_handle_lock) < 0) - abort(); - local_cred_handle = cred_handle; - local_cred_handle->counter++; - if(pthread_mutex_unlock(&cred_handle_lock) < 0) - abort(); - - il_log(LOG_DEBUG, " trying to connect to %s:%d\n", eq->dest_name, eq->dest_port); - ret = edg_wll_gss_connect(local_cred_handle->creds, eq->dest_name, eq->dest_port, &tv, &eq->gss, &gss_stat); - if(pthread_mutex_lock(&cred_handle_lock) < 0) - abort(); - /* check if we need to release the credentials */ - --local_cred_handle->counter; - if(local_cred_handle != cred_handle && local_cred_handle->counter == 0) { - edg_wll_gss_release_cred(&local_cred_handle->creds, NULL); - free(local_cred_handle); - il_log(LOG_DEBUG, " freed credentials, not used anymore\n"); - } - if(pthread_mutex_unlock(&cred_handle_lock) < 0) - abort(); - - if(ret < 0) { - char *gss_err = NULL; - - if (ret == EDG_WLL_GSS_ERROR_GSS) - edg_wll_gss_get_error(&gss_stat, "event_queue_connect: edg_wll_gss_connect", &gss_err); - set_error(IL_DGGSS, ret, - (ret == EDG_WLL_GSS_ERROR_GSS) ? gss_err : "event_queue_connect: edg_wll_gss_connect"); - if (gss_err) free(gss_err); - eq->gss.context = NULL; - eq->timeout = TIMEOUT; - return(0); - } - } - -#ifdef LB_PERF - } -#endif - - return(1); -} - - -int -event_queue_close(struct event_queue *eq) -{ - assert(eq != NULL); - -#ifdef LB_PERF - if(!nosend) { -#endif - - if(eq->gss.context != NULL) { - edg_wll_gss_close(&eq->gss, NULL); - eq->gss.context = NULL; - } -#ifdef LB_PERF - } -#endif - return(0); -} - - -/* - * Send all events from the queue. - * Returns: -1 - system error, 0 - not sent, 1 - queue empty - */ -int -event_queue_send(struct event_queue *eq) -{ - int events_sent = 0; - assert(eq != NULL); - -#ifdef LB_PERF - if(!nosend) { -#endif - if(eq->gss.context == NULL) - return(0); -#ifdef LB_PERF - } -#endif - - /* feed the server with events */ - while (!event_queue_empty(eq)) { - struct server_msg *msg; - char *rep; - int ret, code, code_min; - size_t bytes_sent; - struct timeval tv; - edg_wll_GssStatus gss_stat; - - clear_error(); - - if(event_queue_get(eq, &msg) < 0) - return(-1); - - il_log(LOG_DEBUG, " trying to deliver event at offset %d for job %s\n", msg->offset, msg->job_id_s); - -#ifdef LB_PERF - if(!nosend) { -#endif - /* XXX: ljocha -- does it make sense to send empty messages ? */ - if (msg->len) { - tv.tv_sec = TIMEOUT; - tv.tv_usec = 0; - ret = edg_wll_gss_write_full(&eq->gss, msg->msg, msg->len, &tv, &bytes_sent, &gss_stat); - if(ret < 0) { - if (ret == EDG_WLL_GSS_ERROR_ERRNO && errno == EPIPE && events_sent > 0) { - eq->timeout = 0; - } else { - il_log(LOG_ERR, "send_event: %s\n", error_get_msg()); - eq->timeout = TIMEOUT; - } - return(0); - } - if((code = get_reply(eq, &rep, &code_min)) < 0) { - /* could not get the reply properly, so try again later */ - if (events_sent>0) - eq->timeout = 1; - else { - eq->timeout = TIMEOUT; - il_log(LOG_ERR, " error reading server %s reply:\n %s\n", eq->dest_name, error_get_msg()); - } - return(0); - } - } - else { code = 200; code_min = 0; rep = strdup("not sending empty message"); } -#ifdef LB_PERF - } else { - glite_wll_perftest_consumeEventIlMsg(msg->msg+17); - code = 200; - rep = strdup("OK"); - } -#endif - - il_log(LOG_DEBUG, " event sent, server %s replied with %d, %s\n", eq->dest_name, code, rep); - free(rep); - - /* the reply is back here, decide what to do with message */ - /* HTTP error codes: - 1xx - informational (eg. 100 Continue) - 2xx - successful (eg. 200 OK) - 3xx - redirection (eg. 301 Moved Permanently) - 4xx - client error (eq. 400 Bad Request) - 5xx - server error (eq. 500 Internal Server Error) - */ - if(code >= 100 && code < 200) { - - /* non fatal errors (for us), try to deliver later */ - eq->timeout = TIMEOUT; - return(0); - } - - /* the message was consumed (successfully or not) */ - /* update the event pointer */ - if(event_store_commit(msg->es, msg->ev_len, queue_list_is_log(eq)) < 0) - /* failure committing message, this is bad */ - return(-1); - - event_queue_remove(eq); - events_sent++; - } /* while */ - - return(1); - -} /* send_events */ - - -/* this is just not used */ -int -send_confirmation(long lllid, int code) -{ - return 0; -} diff --git a/org.glite.lb.logger/src/server_msg.c b/org.glite.lb.logger/src/server_msg.c deleted file mode 100644 index 84ae833..0000000 --- a/org.glite.lb.logger/src/server_msg.c +++ /dev/null @@ -1,222 +0,0 @@ -#ident "$Header$" - -#include -#include -#include - -#include "interlogd.h" -#include "glite/lb/il_msg.h" -#include "glite/lb/events_parse.h" -#include "glite/lb/context.h" - -static -int -create_msg(il_octet_string_t *ev, char **buffer, long *receipt, time_t *expires) -{ - char *p; int len; - char *event = ev->data; - - *receipt = 0L; - -#if defined(INTERLOGD_EMS) - /* find DG.LLLID */ - if(strncmp(event, "DG.LLLID",8) == 0 || - strncmp(event, "DG.LLPID",8) == 0) { /* 8 == strlen("DG.LLLID") */ - - /* skip the key */ - event += 9; /* 9 = strlen("DG.LLLID=") */ - *receipt = atol(event); - p = strchr(event, ' '); - if(!p) { - set_error(IL_LBAPI, EDG_WLL_ERROR_PARSE_BROKEN_ULM, - "create_msg: error parsing locallogger PID"); - return(-1); - } - /* skip the value */ - event = p + 1; - - /* find DG.PRIORITY */ - p = strstr(event, "DG.PRIORITY"); - if(p) { - int n; - - p += 12; /* skip the key and = */ - n = atoi(p); - if((n & (EDG_WLL_LOGFLAG_SYNC|EDG_WLL_LOGFLAG_SYNC_COMPAT)) == 0) { - /* normal asynchronous message */ - *receipt = 0L; - } - } else { - /* could not find priority key */ - *receipt = 0L; - } - - } else { - /* could not find local logger PID, confirmation can not be sent */ - *receipt = 0L; - } -#endif - - if(p = strstr(event, "DG.EXPIRES")) { - int n; - - p += 11; - *expires = atoi(p); - } - len = encode_il_msg(buffer, ev); - if(len < 0) { - set_error(IL_NOMEM, ENOMEM, "create_msg: out of memory allocating message"); - return(-1); - } - return(len); -} - - -struct server_msg * -server_msg_create(il_octet_string_t *event, long offset) -{ - struct server_msg *msg; - - msg = malloc(sizeof(*msg)); - if(msg == NULL) { - set_error(IL_NOMEM, ENOMEM, "server_msg_create: out of memory allocating message"); - return(NULL); - } - - if(server_msg_init(msg, event) < 0) { - server_msg_free(msg); - return(NULL); - } - msg->offset = offset; - - return(msg); -} - - -struct server_msg * -server_msg_copy(struct server_msg *src) -{ - struct server_msg *msg; - - msg = malloc(sizeof(*msg)); - if(msg == NULL) { - set_error(IL_NOMEM, ENOMEM, "server_msg_copy: out of memory allocating message"); - return(NULL); - } - - msg->msg = malloc(src->len); - if(msg->msg == NULL) { - set_error(IL_NOMEM, ENOMEM, "server_msg_copy: out of memory allocating server message"); - server_msg_free(msg); - return(NULL); - } - msg->len = src->len; - memcpy(msg->msg, src->msg, src->len); - - msg->job_id_s = strdup(src->job_id_s); - msg->ev_len = src->ev_len; - msg->es = src->es; - msg->receipt_to = src->receipt_to; - msg->offset = src->offset; -#if defined(IL_NOTIFICATIONS) - msg->dest_name = src->dest_name ? strdup(src->dest_name) : NULL; - msg->dest_port = src->dest_port; - msg->dest = src->dest ? strdup(src->dest) : NULL; -#endif - msg->expires = src->expires; - msg->generation = src->generation; - return(msg); -} - - -int -server_msg_init(struct server_msg *msg, il_octet_string_t *event) -{ -#if defined(IL_NOTIFICATIONS) - edg_wll_Context context; - edg_wll_Event *notif_event; - int ret; -#endif - - assert(msg != NULL); - assert(event != NULL); - - memset(msg, 0, sizeof(*msg)); - - -#if defined(IL_NOTIFICATIONS) - - /* parse the notification event */ - edg_wll_InitContext(&context); - ret=edg_wll_ParseNotifEvent(context, event->data, ¬if_event); - edg_wll_FreeContext(context); - if(ret) { - set_error(IL_LBAPI, ret, "server_msg_init: error parsing notification event"); - return(-1); - } - - /* FIXME: check for allocation error */ - if(notif_event->notification.dest_host && - (strlen(notif_event->notification.dest_host) > 0)) { - msg->dest_name = strdup(notif_event->notification.dest_host); - msg->dest_port = notif_event->notification.dest_port; - asprintf(&msg->dest, "%s:%d", msg->dest_name, msg->dest_port); - } - msg->job_id_s = edg_wll_NotifIdUnparse(notif_event->notification.notifId); - if(notif_event->notification.jobstat && - (strlen(notif_event->notification.jobstat) > 0)) { - msg->len = create_msg(event, &msg->msg, &msg->receipt_to, &msg->expires); - } - msg->expires = notif_event->notification.expires; - edg_wll_FreeEvent(notif_event); - free(notif_event); - if(msg->len < 0) { - return(-1); - } -#else - msg->len = create_msg(event, &msg->msg, &msg->receipt_to, &msg->expires); - if(msg->len < 0) { - return(-1); - } -#ifdef LB_PERF - if(noparse) { - msg->job_id_s = strdup("https://localhost:9000/not_so_unique_string"); - } else -#endif - msg->job_id_s = edg_wll_GetJobId(event->data); -#endif - /* remember to add event separator to the length */ - msg->ev_len = event->len + 1; - - if(msg->job_id_s == NULL) { - set_error(IL_LBAPI, EDG_WLL_ERROR_PARSE_BROKEN_ULM, "server_msg_init: error getting id"); - return(-1); - } - - return(0); -} - - -int -server_msg_is_priority(struct server_msg *msg) -{ - assert(msg != NULL); - - return(msg->receipt_to != 0); -} - - -int -server_msg_free(struct server_msg *msg) -{ - assert(msg != NULL); - - if(msg->msg) free(msg->msg); - if(msg->job_id_s) free(msg->job_id_s); -#if defined(IL_NOTIFICATIONS) - if(msg->dest_name) free(msg->dest_name); - if(msg->dest) free(msg->dest); -#endif - free(msg); - return 0; -} diff --git a/org.glite.lb.logger/src/server_msg_http.c b/org.glite.lb.logger/src/server_msg_http.c deleted file mode 100644 index 8bd3623..0000000 --- a/org.glite.lb.logger/src/server_msg_http.c +++ /dev/null @@ -1,128 +0,0 @@ -#ident "$Header$" - -#include -#include -#include - -#include "interlogd.h" -#include "glite/lb/il_msg.h" -#include "glite/lb/events_parse.h" -#include "glite/lb/context.h" - -static -int -create_msg(il_http_message_t *ev, char **buffer, long *receipt, time_t *expires) -{ - char *event = ev->data; - - *receipt = 0; - *expires = 0; - - *buffer = ev->data; - return ev->len;; -} - - -struct server_msg * -server_msg_create(il_octet_string_t *event, long offset) -{ - struct server_msg *msg; - - msg = malloc(sizeof(*msg)); - if(msg == NULL) { - set_error(IL_NOMEM, ENOMEM, "server_msg_create: out of memory allocating message"); - return(NULL); - } - - if(server_msg_init(msg, event) < 0) { - server_msg_free(msg); - return(NULL); - } - msg->offset = offset; - - return(msg); -} - - -struct server_msg * -server_msg_copy(struct server_msg *src) -{ - struct server_msg *msg; - - msg = malloc(sizeof(*msg)); - if(msg == NULL) { - set_error(IL_NOMEM, ENOMEM, "server_msg_copy: out of memory allocating message"); - return(NULL); - } - - msg->msg = malloc(src->len); - if(msg->msg == NULL) { - set_error(IL_NOMEM, ENOMEM, "server_msg_copy: out of memory allocating server message"); - server_msg_free(msg); - return(NULL); - } - msg->len = src->len; - memcpy(msg->msg, src->msg, src->len); - - msg->job_id_s = strdup(src->job_id_s); - msg->ev_len = src->ev_len; - msg->es = src->es; - msg->receipt_to = src->receipt_to; - msg->offset = src->offset; -#if defined(IL_NOTIFICATIONS) - msg->dest_name = strdup(src->dest_name); - msg->dest_port = src->dest_port; - msg->dest = strdup(src->dest); -#endif - msg->expires = src->expires; - return(msg); -} - - -int -server_msg_init(struct server_msg *msg, il_octet_string_t *event) -{ - il_http_message_t *hmsg = (il_http_message_t *)event; - - assert(msg != NULL); - assert(event != NULL); - - memset(msg, 0, sizeof(*msg)); - - - msg->job_id_s = hmsg->host; - if(msg->job_id_s == NULL) { - set_error(IL_LBAPI, EDG_WLL_ERROR_PARSE_BROKEN_ULM, "server_msg_init: error getting id"); - return -1; - } - msg->len = create_msg(hmsg, &msg->msg, &msg->receipt_to, &msg->expires); - if(msg->len < 0) - return -1; - /* set this to indicate new data owner */ - hmsg->data = NULL; - hmsg->host = NULL; - msg->ev_len = hmsg->len + 1; /* must add separator size too */ - return 0; - -} - - -int -server_msg_is_priority(struct server_msg *msg) -{ - assert(msg != NULL); - - return(msg->receipt_to != 0); -} - - -int -server_msg_free(struct server_msg *msg) -{ - assert(msg != NULL); - - if(msg->msg) free(msg->msg); - if(msg->job_id_s) free(msg->job_id_s); - free(msg); - return 0; -} diff --git a/org.glite.lb.logger/test/IlTestBase.cpp b/org.glite.lb.logger/test/IlTestBase.cpp deleted file mode 100644 index a6b4624..0000000 --- a/org.glite.lb.logger/test/IlTestBase.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "IlTestBase.h" - -#include - -const char *IlTestBase::msg = "DATE=20040831150159.702224 HOST=\"some.host\" PROG=edg-wms LVL=USAGE DG.PRIORITY=0 DG.SOURCE=\"UserInterface\" DG.SRC_INSTANCE=\"\" DG.EVNT=\"RegJob\" DG.JOBID=\"https://some.host:1234/x67qr549qc\" DG.SEQCODE=\"UI=2:NS=0:WM=0:BH=1:JSS=0:LM=0:LRMS=0:APP=0\" DG.USER=\"/C=CZ/O=Cesnet/CN=Michal Vocu\" DG.REGJOB.JDL=\"\" DG.REGJOB.NS=\"ns address\" DG.REGJOB.PARENT=\"\" DG.REGJOB.JOBTYPE=\"SIMPLE\" DG.REGJOB.NSUBJOBS=\"0\" DG.REGJOB.SEED=\"\""; - -const char *IlTestBase::msg_enc = " 429\n6 michal\n415 DATE=20040831150159.702224 HOST=\"some.host\" PROG=edg-wms LVL=USAGE DG.PRIORITY=0 DG.SOURCE=\"UserInterface\" DG.SRC_INSTANCE=\"\" DG.EVNT=\"RegJob\" DG.JOBID=\"https://some.host:1234/x67qr549qc\" DG.SEQCODE=\"UI=2:NS=0:WM=0:BH=1:JSS=0:LM=0:LRMS=0:APP=0\" DG.USER=\"/C=CZ/O=Cesnet/CN=Michal Vocu\" DG.REGJOB.JDL=\"\" DG.REGJOB.NS=\"ns address\" DG.REGJOB.PARENT=\"\" DG.REGJOB.JOBTYPE=\"SIMPLE\" DG.REGJOB.NSUBJOBS=\"0\" DG.REGJOB.SEED=\"\"\n"; - -const struct server_msg IlTestBase::smsg = { - "https://some.host:1234/x67qr549qc", - (char*)IlTestBase::msg_enc, - strlen(IlTestBase::msg_enc), - strlen(IlTestBase::msg) + 1, - NULL -}; diff --git a/org.glite.lb.logger/test/IlTestBase.h b/org.glite.lb.logger/test/IlTestBase.h deleted file mode 100644 index 69bf347..0000000 --- a/org.glite.lb.logger/test/IlTestBase.h +++ /dev/null @@ -1,10 +0,0 @@ -extern "C" { -#include "interlogd.h" -} - -class IlTestBase { -public: - static const char *msg; - static const char *msg_enc; - static const struct server_msg smsg; -}; diff --git a/org.glite.lb.logger/test/event_queueTest.cpp b/org.glite.lb.logger/test/event_queueTest.cpp deleted file mode 100644 index 86a6be1..0000000 --- a/org.glite.lb.logger/test/event_queueTest.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include - -#include "IlTestBase.h" - -extern "C" { -struct event_queue_msg { - struct server_msg *msg; - struct event_queue_msg *prev; -}; -} - -#include -using namespace std; - -class event_queueTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( event_queueTest ); - CPPUNIT_TEST( testEventQueueCreate ); - CPPUNIT_TEST( testEventQueueInsert ); - CPPUNIT_TEST( testEventQueueGet ); - CPPUNIT_TEST( testEventQueueRemove ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp() { - server = strdup("localhost:8080"); - eq = event_queue_create(server); - free(server); - } - - void tearDown() { - struct event_queue_msg *mp; - struct server_msg *m; - - for(mp = eq->head; mp != NULL; ) { - struct event_queue_msg *mq; - - server_msg_free(mp->msg); - mq = mp; - mp = mp->prev; - free(mq); - } - eq->head = NULL; - event_queue_free(eq); - } - - void testEventQueueCreate() { - CPPUNIT_ASSERT( eq != NULL ); - CPPUNIT_ASSERT_EQUAL( string(eq->dest_name), string("localhost") ); - CPPUNIT_ASSERT_EQUAL( eq->dest_port, 8081 ); - CPPUNIT_ASSERT( eq->tail == NULL ); - CPPUNIT_ASSERT( eq->head == NULL ); - CPPUNIT_ASSERT( eq->tail_ems == NULL ); - CPPUNIT_ASSERT( eq->mark_this == NULL ); - CPPUNIT_ASSERT( eq->mark_prev == NULL ); - CPPUNIT_ASSERT( eq->thread_id == 0 ); - CPPUNIT_ASSERT( eq->flushing == 0 ); - CPPUNIT_ASSERT( eq->flush_result == 0 ); - } - - void testEventQueueInsert() { - struct event_queue_msg *mp; - struct server_msg *m; - - doSomeInserts(); - mp = eq->head; - m = mp->msg; - CPPUNIT_ASSERT_EQUAL( string(m->job_id_s), string("2") ); - CPPUNIT_ASSERT_EQUAL( mp, eq->tail_ems ); - mp = mp->prev; - m = mp->msg; - CPPUNIT_ASSERT_EQUAL( string(m->job_id_s), string("1") ); - mp = mp->prev; - m = mp->msg; - CPPUNIT_ASSERT_EQUAL( string(m->job_id_s), string("3") ); - CPPUNIT_ASSERT_EQUAL( mp, eq->tail ); - CPPUNIT_ASSERT( mp->prev == NULL ); - } - - void testEventQueueGet() { - struct event_queue_msg *mp; - struct server_msg *m,sm; - int ret; - - doSomeInserts(); - mp = eq->head; - eq->head = mp->prev; - eq->tail_ems = NULL; - server_msg_free(mp->msg); - free(mp); - ret = event_queue_get(eq, &m); - CPPUNIT_ASSERT( ret == 0 ); - CPPUNIT_ASSERT( eq->mark_this == eq->head ); - CPPUNIT_ASSERT( eq->mark_prev == NULL ); - CPPUNIT_ASSERT_EQUAL( string("1"), string(m->job_id_s) ); - sm = IlTestBase::smsg; - sm.job_id_s = "4"; - sm.receipt_to = 1; - ret = event_queue_insert(eq, &sm); - CPPUNIT_ASSERT( ret == 0 ); - CPPUNIT_ASSERT( eq->mark_prev == eq->head ); - CPPUNIT_ASSERT( eq->mark_this == eq->head->prev ); - ret = event_queue_insert(eq, &sm); - CPPUNIT_ASSERT( ret == 0 ); - CPPUNIT_ASSERT( eq->mark_prev == eq->head->prev ); - CPPUNIT_ASSERT( eq->mark_this == eq->head->prev->prev ); - } - - void testEventQueueRemove() { - struct event_queue_msg *mp; - struct server_msg *m,sm; - int ret; - - doSomeInserts(); - ret = event_queue_get(eq, &m); - mp = eq->mark_this->prev; - sm = IlTestBase::smsg; - sm.job_id_s = "4"; - sm.receipt_to = 1; - event_queue_insert(eq, &sm); - ret = event_queue_remove(eq); - CPPUNIT_ASSERT( eq->head->prev == mp ); - CPPUNIT_ASSERT( eq->mark_this == NULL ); - CPPUNIT_ASSERT( eq->mark_prev == NULL ); - } - -protected: - char *server; - struct event_queue *eq; - - void doSomeInserts() { - struct server_msg m = IlTestBase::smsg; - - m.job_id_s = "1"; - event_queue_insert(eq, &m); - m.receipt_to = 1; - m.job_id_s = "2"; - event_queue_insert(eq, &m); - m.job_id_s = "3"; - m.receipt_to = 0; - event_queue_insert(eq, &m); - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION( event_queueTest ); diff --git a/org.glite.lb.logger/test/event_storeTest.cpp b/org.glite.lb.logger/test/event_storeTest.cpp deleted file mode 100644 index 8364cf4..0000000 --- a/org.glite.lb.logger/test/event_storeTest.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include - -#include "IlTestBase.h" - -class event_storeTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( event_storeTest ); - CPPUNIT_TEST( event_store_recoverTest ); - CPPUNIT_TEST( event_store_syncTest ); - CPPUNIT_TEST( event_store_nextTest ); - CPPUNIT_TEST( event_store_commitTest ); - CPPUNIT_TEST( event_store_cleanTest ); - CPPUNIT_TEST( event_store_findTest ); - CPPUNIT_TEST( event_store_releaseTest ); - CPPUNIT_TEST( event_store_initTest ); - CPPUNIT_TEST( event_store_recover_allTest ); - CPPUNIT_TEST( event_store_cleanupTest ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp() { - } - - void tearDown() { - } - - void event_store_recoverTest() { - } - - void event_store_syncTest() { - } - - void event_store_nextTest() { - } - - void event_store_commitTest() { - } - - void event_store_cleanTest() { - } - - void event_store_findTest() { - } - - void event_store_releaseTest() { - } - - void event_store_initTest() { - } - - void event_store_recover_allTest() { - } - - void event_store_cleanupTest() { - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION( event_storeTest ); diff --git a/org.glite.lb.logger/test/il_test.cpp b/org.glite.lb.logger/test/il_test.cpp deleted file mode 100644 index cd97a73..0000000 --- a/org.glite.lb.logger/test/il_test.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include - -extern "C" { -#include -#include "glite/wmsutils/tls/ssl_helpers/ssl_inits.h" -#include "glite/wmsutils/tls/ssl_helpers/ssl_pthreads.h" -#include "glite/security/glite_gss.h" -#include "interlogd.h" -#include "glite/lb/consumer.h" -} - -#if defined(IL_NOTIFICATIONS) -#define DEFAULT_PREFIX "/tmp/notif_events" -#define DEFAULT_SOCKET "/tmp/notif_interlogger.sock" -#else -#define DEFAULT_PREFIX "/tmp/dglogd.log" -#define DEFAULT_SOCKET "/tmp/interlogger.sock" -#endif - -int TIMEOUT = DEFAULT_TIMEOUT; - -gss_cred_id_t cred_handle = GSS_C_NO_CREDENTIAL; -pthread_mutex_t cred_handle_lock = PTHREAD_MUTEX_INITIALIZER; - -char *file_prefix = DEFAULT_PREFIX; -int bs_only = 0; - -char *cert_file = NULL; -char *key_file = NULL; -char *CAcert_dir = NULL; -char *log_server = NULL; -char *socket_path = DEFAULT_SOCKET; - - -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; -} diff --git a/org.glite.lb.logger/test/input_queue_socketTest.cpp b/org.glite.lb.logger/test/input_queue_socketTest.cpp deleted file mode 100644 index d29e2cc..0000000 --- a/org.glite.lb.logger/test/input_queue_socketTest.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include - -#include "IlTestBase.h" - -extern "C" { -#include -#include -#include - -#include "interlogd.h" - - extern char *socket_path; -} - -#include -using namespace std; - -class input_queue_socketTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( input_queue_socketTest ); - CPPUNIT_TEST( input_queue_getTest ); - CPPUNIT_TEST_SUITE_END(); - -public: - - void setUp() { - struct sockaddr_un saddr; - int sock; - long offset = 0; - - int ret = input_queue_attach(); - CPPUNIT_ASSERT(ret == 0); - - sock=socket(PF_UNIX, SOCK_STREAM, 0); - CPPUNIT_ASSERT(sock >= 0); - - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, socket_path); - ret = connect(sock, (struct sockaddr *)&saddr, sizeof(saddr.sun_path)); - CPPUNIT_ASSERT(ret >= 0); - - ret = write(sock, &offset, sizeof(offset)); - CPPUNIT_ASSERT( ret == sizeof(offset) ); - ret = write(sock, IlTestBase::msg, strlen(IlTestBase::msg)); - CPPUNIT_ASSERT( ret == strlen(IlTestBase::msg) ); - ret = write(sock, "\n", 1); - CPPUNIT_ASSERT( ret == 1 ); - } - - void tearDown() { - input_queue_detach(); - } - - - void input_queue_getTest() { - char *event; - long offset; - int ret; - - ret = input_queue_get(&event, &offset, 10); - CPPUNIT_ASSERT( ret >= 0 ); - CPPUNIT_ASSERT_EQUAL( 0L, offset ); - CPPUNIT_ASSERT_EQUAL( string(IlTestBase::msg), string(event) ); - free(event); - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(input_queue_socketTest); diff --git a/org.glite.lb.logger/test/ll_test.cpp b/org.glite.lb.logger/test/ll_test.cpp deleted file mode 100644 index 1e8dce6..0000000 --- a/org.glite.lb.logger/test/ll_test.cpp +++ /dev/null @@ -1,119 +0,0 @@ -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -extern "C" { -#define DEFAULT_SOCKET "/tmp/interlogger.sock" -char *socket_path = DEFAULT_SOCKET; -int edg_wll_log_proto_server(int *,char *,char *,int,int); -void edg_wll_ll_log_init(int); -} - -class LLTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(LLTest); - CPPUNIT_TEST(testProtoServer); - CPPUNIT_TEST_SUITE_END(); - -public: - - void setUp() { - char *msg = "DATE=20040831150159.702224 HOST=\"some.host\" PROG=edg-wms LVL=USAGE DG.PRIORITY=0 DG.SOURCE=\"UserInterface\" DG.SRC_INSTANCE=\"\" DG.EVNT=\"RegJob\" DG.JOBID=\"https://some.host:1234/x67qr549qc\" DG.SEQCODE=\"UI=2:NS=0:WM=0:BH=1:JSS=0:LM=0:LRMS=0:APP=0\" DG.REGJOB.JDL=\"\" DG.REGJOB.NS=\"ns address\" DG.REGJOB.PARENT=\"\" DG.REGJOB.JOBTYPE=\"SIMPLE\" DG.REGJOB.NSUBJOBS=\"0\" DG.REGJOB.SEED=\"\""; - pipe(pd); - log_proto_client(pd[1], msg); - input_queue_attach(); - } - - void tearDown() { - close(pd[0]); - close(pd[1]); - input_queue_detach(); - } - - void testProtoServer() { - int ret; - edg_wll_ll_log_init(255); - ret = edg_wll_log_proto_server(&pd[0], - "michal", - "/tmp/dglogd.log", - 0, - 0); - CPPUNIT_ASSERT( ret == 0 ); - } - -private: - int pd[2]; - - int log_proto_client(int con, char *logline) { - char header[32]; - int err; - int size; - u_int8_t size_end[4]; - - err = 0; - size = strlen(logline)+1; - size_end[0] = size & 0xff; size >>= 8; - size_end[1] = size & 0xff; size >>= 8; - size_end[2] = size & 0xff; size >>= 8; - size_end[3] = size; - size = strlen(logline)+1; - - err = write(con, "DGLOG", 5); - CPPUNIT_ASSERT(err == 5); - err = write(con, size_end, 4); - CPPUNIT_ASSERT(err == 4); - err = write(con, logline, size); - CPPUNIT_ASSERT( err == size ); -} - - int sock; - int accepted; - -int -input_queue_attach() -{ - struct sockaddr_un saddr; - - CPPUNIT_ASSERT((sock=socket(PF_UNIX, SOCK_STREAM, 0)) >= 0); - - memset(&saddr, 0, sizeof(saddr)); - saddr.sun_family = AF_UNIX; - strcpy(saddr.sun_path, socket_path); - - CPPUNIT_ASSERT(bind(sock, (struct sockaddr *)&saddr, sizeof(saddr)) >= 0); - CPPUNIT_ASSERT(listen(sock, 5) >= 0 ); - return(0); -} - -void input_queue_detach() -{ - if (sock >= 0) - close(sock); - unlink(socket_path); -} - -}; - - -CPPUNIT_TEST_SUITE_REGISTRATION( LLTest ); - -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; -} diff --git a/org.glite.lb.logger/test/logd_proto_test.c b/org.glite.lb.logger/test/logd_proto_test.c deleted file mode 100644 index 9ee0b44..0000000 --- a/org.glite.lb.logger/test/logd_proto_test.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define edg_wll_gss_read_full(a,b,c,d,e,f) test_edg_wll_gss_read_full(a,b,c,d,e,f) -#define edg_wll_gss_write_full(a,b,c,d,e,f) test_edg_wll_gss_write_full(a,b,c,d,e,f) -#define edg_wll_GssConnection int - -#include "logd_proto.h" -#include "glite/lb/context-int.h" -#include "glite/lb/escape.h" -#include "glite/lb/events_parse.h" - -int -test_edg_wll_gss_read_full(int *fd, - void *buf, - size_t bufsize, - struct timeval *timeout, - size_t *total, - edg_wll_GssStatus *code) -{ - *total = read(*fd, buf, bufsize); - return(*total < 0 ? *total : 0); -} - -int -test_edg_wll_gss_write_full(int *fd, - const void *buf, - size_t bufsize, - struct timeval *timeout, - size_t *total, - edg_wll_GssStatus *code) -{ - return(0); -} - -#include "logd_proto.c" diff --git a/org.glite.lb.logger/test/server_msgTest.cpp b/org.glite.lb.logger/test/server_msgTest.cpp deleted file mode 100644 index e669ea1..0000000 --- a/org.glite.lb.logger/test/server_msgTest.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#include - -#include "IlTestBase.h" - -#include - -using namespace std; - -class server_msgTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(server_msgTest); - CPPUNIT_TEST( server_msg_createTest ); - CPPUNIT_TEST( server_msg_copyTest ); - CPPUNIT_TEST_SUITE_END(); - -public: - - void setUp() { - msg = server_msg_create((char *)IlTestBase::msg); - } - - void tearDown() { - server_msg_free(msg); - } - - void server_msg_createTest() { - CPPUNIT_ASSERT( msg != NULL ); - CPPUNIT_ASSERT_EQUAL( string(msg->job_id_s), string(IlTestBase::smsg.job_id_s) ); - CPPUNIT_ASSERT_EQUAL( string(msg->msg), string(IlTestBase::smsg.msg) ); - CPPUNIT_ASSERT_EQUAL( msg->len, IlTestBase::smsg.len ); - CPPUNIT_ASSERT_EQUAL( msg->ev_len, IlTestBase::smsg.ev_len ); - CPPUNIT_ASSERT_EQUAL( msg->es, IlTestBase::smsg.es ); - CPPUNIT_ASSERT( !server_msg_is_priority(msg) ); - } - - void server_msg_copyTest() { - struct server_msg *msg2; - - msg2 = server_msg_copy(msg); - CPPUNIT_ASSERT( msg2 != NULL ); - CPPUNIT_ASSERT( msg2 != msg ); - CPPUNIT_ASSERT_EQUAL( string(msg->job_id_s), string(msg2->job_id_s) ); - CPPUNIT_ASSERT( msg->job_id_s != msg2->job_id_s); - CPPUNIT_ASSERT_EQUAL( string(msg->msg), string(msg2->msg) ); - CPPUNIT_ASSERT( msg->msg != msg2->msg ); - CPPUNIT_ASSERT_EQUAL( msg->len, msg2->len ); - CPPUNIT_ASSERT_EQUAL( msg->ev_len, msg2->ev_len ); - CPPUNIT_ASSERT_EQUAL( msg->es, msg2->es ); - server_msg_free(msg2); - } - -private: - struct server_msg *msg; -}; - - -CPPUNIT_TEST_SUITE_REGISTRATION(server_msgTest); diff --git a/org.glite.lb.server/.cvsignore b/org.glite.lb.server/.cvsignore deleted file mode 100644 index 1df717b..0000000 --- a/org.glite.lb.server/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -.project -.cdtproject \ No newline at end of file diff --git a/org.glite.lb.server/LICENSE b/org.glite.lb.server/LICENSE deleted file mode 100644 index 259a91f..0000000 --- a/org.glite.lb.server/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.lb.server/Makefile b/org.glite.lb.server/Makefile deleted file mode 100644 index 8af132c..0000000 --- a/org.glite.lb.server/Makefile +++ /dev/null @@ -1,413 +0,0 @@ -# defaults -top_srcdir=.. -stagedir=. -globalprefix=glite -lbprefix=lb -package=glite-lb-server -version=0.2.0 -PREFIX=/opt/glite - -# gridsite requires openssl libraries, we want to include the ones from globus -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/glite -lcas_prefix=/opt/glite -gridsite_prefix=/opt/glite - --include Makefile.inc --include ../project/version.properties - -version=${module.version} - -default all: compile - -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 - -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 -CXX=g++ - -ifeq ($(gsoap_version),2.7.0) - VPATH=${top_srcdir}/interface:${top_srcdir}/src:${top_srcdir}/test:${top_srcdir}/doc:${top_srcdir}/examples:${top_srcdir}/project:${gsoap_prefix} -else - VPATH=${top_srcdir}/interface:${top_srcdir}/src:${top_srcdir}/test:${top_srcdir}/doc:${top_srcdir}/examples:${top_srcdir}/project -endif -AT3=${stagedir}/sbin/glite-lb-at3 - -SUFFIXES = .T - -DEBUG:=-g -O0 -Wall - -GRIDSITE_CFLAGS = -I${gridsite_prefix}/include `xml2-config --cflags` -GRIDSITE_LIBS = -L${gridsite_prefix}/${libdir} -L${gridsite_prefix}/lib -lgridsite_globus `xml2-config --libs` - -LCAS_CFLAGS=-I${lcas_prefix}/include - -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${classads_prefix}/include/classad \ - -I${voms_prefix}/include \ - ${COVERAGE_FLAGS} \ - $(GRIDSITE_CFLAGS) ${LCAS_CFLAGS}\ - -D_GNU_SOURCE ${LB_STANDALONE_FLAGS} ${LB_PERF_FLAGS} -DLB_EVENTS_BLOB \ - -I${globus_prefix}/include/${nothrflavour} #gridsite needs this - -CXXFLAGS:=${CFLAGS} - -ifdef LB_PROF - SRVBONES_LIB:= ${stagedir}/${libdir}/libglite_lbu_server_bones.la - LB_COMMON_LIB:=${stagedir}/${libdir}/libglite_lb_common_${nothrflavour}.la - LB_UTILS_DB_LIB:=${stagedir}/${libdir}/libglite_lbu_db.la - CFLAGS:=${CFLAGS} -pg -g - LDFLAGS:=${LDFLAGS} -pg -else - SRVBONES_LIB:= -L${stagedir}/${libdir} -lglite_lbu_server_bones - LB_COMMON_LIB:=-L${stagedir}/${libdir} -lglite_lb_common_${nothrflavour} - LB_UTILS_DB_LIB:=-L${stagedir}/${libdir} -lglite_lbu_db - LDFLAGS:= -L${stagedir}/${libdir} -endif - -# LB_MACHINE_LIB:=${stagedir}/${libdir}/libglite_lb_statemachine.a -LB_MACHINE_LIB:=-L${stagedir}/${libdir} -lglite_lb_statemachine - -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} -CXXCOMPILE:=libtool --mode=compile ${CXX} ${CXXFLAGS} -LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/${libdir} ${LDFLAGS} -SOLINK:=libtool --mode=link ${CC} -module ${LDFLAGS} -rpath ${stagedir}/${libdir} -# XXX: not used? LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS} -INSTALL:=libtool --mode=install install -LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/${libdir} ${LDFLAGS} -XSLTPROC:=xsltproc --novalid - -#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 } - -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}/${libdir} -lvomsapi${vomsflavour} -LCAS_LIBS:=-L${lcas_prefix}/${libdir} -llcas - -#EXT_LIBS:= \ -# ${expatlib} -lexpat \ -# ${GRIDSITE_LIBS} \ -# -lvomsc${vomsflavour} \ - -ifneq (${classads_prefix},/usr) - classadslib := -L${classads_prefix}/${libdir} -L${classads_prefix}/lib -endif - -classadslib := ${classadslib} -lclassad - -EXT_LIBS:= \ - -lz -lcares\ - ${GRIDSITE_LIBS} \ - ${classadslib} \ - ${LCAS_LIBS} \ - ${VOMS_LIBS} - -COMMON_LIBS:= -L${stagedir}/${libdir} -lglite_lb_common_${nothrflavour} -lglite_security_gss_${nothrflavour} -lglite_lbu_trio -lglite_lbu_maildir - -BKSERVER_BASE_OBJS:= \ - bkserverd.o il_lbproxy.o get_events.o index.o jobstat.o jobstat_supp.o \ - seqcode.o write2rgma.o lb_html.o lb_http.o lb_proto.o cond_dump.o lb_xml_parse.o \ - lb_xml_parse_V21.o lb_text.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 db_calls.o db_supp.o lb_rss.o pretty_print_wrapper.o - -gsoap_version ?= ${gsoap_default_version} - -dotless_gsoap_ver:=${shell echo ${gsoap_version} | tr -d . } -ifeq ($(shell test -f ${stagedir}/${libdir}/libglite_security_gsoap_plugin_${dotless_gsoap_ver}_${nothrflavour}_c.so && echo ok),ok) - langflavour:=_c -endif -GSOAP_LIB:=-L${stagedir}/${libdir} -lglite_security_gsoap_plugin_${dotless_gsoap_ver}_${nothrflavour}${langflavour} - -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} \ - ${LB_MACHINE_LIB} \ - ${LB_UTILS_DB_LIB} \ - ${GSOAP_LIB} \ - ${EXT_LIBS} \ - ${classadslib} \ - -lglite_lbu_maildir -else - BKSERVER_OBJS:= ${BKSERVER_BASE_OBJS} - - BKSERVER_LIBS= \ - ${SRVBONES_LIB} \ - ${LB_COMMON_LIB} \ - ${LB_MACHINE_LIB} \ - ${LB_UTILS_DB_LIB} \ - -lglite_security_gss_${nothrflavour} \ - ${EXT_LIBS} \ - ${classadslib} \ - -lglite_lbu_maildir -endif - -INDEX_OBJS:= index.o index_parse.o jobstat_supp.o openserver.o \ - jobstat.o query.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 lb_text.o server_state.o lb_xml_parse_V21.o lb_html.o cond_dump.o notification.o seqcode.o userjobs.o load.o db_calls.o db_supp.o lb_rss.o pretty_print_wrapper.o - -INDEX_LIBS:= ${SRVBONES_LIB} ${COMMON_LIBS} ${LB_MACHINE_LIB} ${EXT_LIBS} ${LB_UTILS_DB_LIB} - -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}/${libdir} \ -# -lglite_lb_client_${nothrflavour} \ -# -lglite_lb_common_${nothrflavour} \ -# -L${gsoap_prefix}/${libdir} -lgsoap \ -# -lglite_security_gsoap_plugin_${nothrflavour} \ -# ${EXT_LIBS} -# - -HDRS=index.h lb_authz.h store.h - -MAN_GZ:=glite-lb-bkindex.8.gz glite-lb-bkserverd.8.gz glite-lb-mon-db.1.gz -MAN = $(MAN_GZ:.gz=) - -LIB_OBJS_BK:= \ - il_lbproxy.o get_events.o index.o jobstat.o jobstat_supp.o \ - seqcode.o lb_html.o lb_http.o lb_proto.o cond_dump.o lb_xml_parse.o \ - lb_xml_parse_V21.o lb_text.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 write2rgma.o \ - db_calls.o db_supp.o lb_rss.o pretty_print_wrapper.o - -MONDB_OBJS:=mon-db.o ${LIB_OBJS_BK} -MONDB_LIBS:=${COMMON_LIBS} ${LB_MACHINE_LIB} ${LB_UTILS_DB_LIB} ${EXT_LIBS} - -LCAS_PLUGIN_OBJS:=lcas_lb.o -LCAS_PLUGIN_LOBJS:=${LCAS_PLUGIN_OBJS:.o=.lo} -LCAS_PLUGIN_LIB:=liblcas_lb.la - -EXAMPLES= - -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-mon-db: ${MONDB_OBJS} - ${LINKXX} -o $@ ${MONDB_OBJS} ${MONDB_LIBS} - -compile: generate glite-lb-bkserverd glite-lb-bkindex glite-lb-mon-db ${STATIC_LIB_BK} ${LCAS_PLUGIN_LIB} ${MAN_GZ} - -generate: store.c index.c - -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 - LD_LIBRARY_PATH=${cares_prefix}/${libdir}:${classads_prefix}/${libdir}:${LD_LIBRARY_PATH} ./test_xml - -test_xml: test_xml.cpp - ${CXX} -c ${CFLAGS} ${TEST_INC} $< - ${LINKXX} -o $@ test_xml.o lb_xml_parse.o ${LB_COMMON_LIB} ${TEST_LIBS} - -test.query: test_query_events - # XXX coredumps ./test_query_events - -#query_events_objs:=`echo ${BKSERVER_BASE_OBJS} |sed '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 := test_query_events.o query.o get_events.o jobstat_supp.o index.o db_supp.o - -test_query_events: ${query_events_objs} - ${LINKXX} -o $@ ${query_events_objs} \ - ${TEST_LIBS} ${LB_COMMON_LIB} ${LB_MACHINE_LIB} ${classadslib} - -test.soapconv: test_soap_conv - LD_LIBRARY_PATH=${cares_prefix}/${libdir}:${classads_prefix}/${libdir}:${LD_LIBRARY_PATH} ./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: ${EXAMPLES} - -${STATIC_LIB_BK}: ${LIB_OBJS_BK} - ar crv $@ ${LIB_OBJS_BK} - ranlib $@ - -${LCAS_PLUGIN_LIB}: ${LCAS_PLUGIN_LOBJS} - ${LINK} -o $@ $< - -doc: ${MAN_GZ} - -man: ${MAN_GZ} - -${MAN_GZ}: ${MAN} - cp $? . - gzip -f $(notdir $?) - -stage: compile - $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes - -install: - -mkdir -p ${PREFIX}/bin ${PREFIX}/etc ${PREFIX}/etc/init.d ${PREFIX}/interface - -mkdir -p ${PREFIX}/share/doc/${package}-${version} - -mkdir -p ${PREFIX}/share/man/man1 - -mkdir -p ${PREFIX}/${libdir} - -mkdir -p ${PREFIX}/include/${globalprefix}/${lbprefix} - mkdir -p ${PREFIX}/share/man/man8 - ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} - ( cd ${top_srcdir}/project && ${INSTALL} -m 644 ChangeLog package.description package.summary ${PREFIX}/share/doc/${package}-${version} ) - ${INSTALL} -m 644 ${MAN_GZ} ${PREFIX}/share/man/man1 - for p in bkserverd bkindex mon-db; do \ - ${INSTALL} -m 755 "glite-lb-$$p" "${PREFIX}/bin/glite-lb-$$p"; \ - done - -mkdir -p ${PREFIX}/${libdir}/modules - ${INSTALL} -m 755 ${LCAS_PLUGIN_LIB} ${PREFIX}/${libdir}/modules - ln -sf liblcas_lb.so ${PREFIX}/${libdir}/modules/lcas_lb.mod - - for f in dbsetup.sql index.conf.template; do \ - ${INSTALL} -m 644 ${top_srcdir}/config/"glite-lb-$$f" ${PREFIX}/etc; \ - done - ${INSTALL} -m 755 ${top_srcdir}/config/glite-lb-migrate_db2version20 ${PREFIX}/etc - - ${INSTALL} -m 755 ${top_srcdir}/config/startup ${PREFIX}/etc/init.d/glite-lb-bkserverd - - 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}/${libdir} - ${INSTALL} -m 644 ${top_srcdir}/interface/srv_perf.h ${PREFIX}/include/${globalprefix}/${lbprefix} - ${INSTALL} -m 644 ${MAN_GZ} ${PREFIX}/share/man/man8 -ifdef LB_PERF - -mkdir -p ${PREFIX}/sbin - ${INSTALL} -m 755 ${top_srcdir}/src/perftest_proxy.sh ${PREFIX}/sbin -endif - -clean: - rm -rvf *.c *.h *.ch *.xh *.xml *.nsmap *.o *.lo .libs glite-lb-* ${STATIC_LIB_BK} ${LCAS_PLUGIN_LIB} test* ${MAN_GZ} ${EXAMPLES} - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - -%.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 $< - -%.o %.lo: %.cpp - ${CXXCOMPILE} -c $< - -test_query_events.o: %.o: %.cpp - ${CXX} -c ${CFLAGS} ${TEST_INC} $< - - -%.lo: %.c - ${COMPILE} -o $@ -c $< - -soap_version.h: - ${gsoap_bin_prefix}/soapcpp2 /dev/null - perl -ne '$$. == 2 && /.*([0-9]+)\.([0-9]+)\.([0-9]+)([a-z]?).*/ && printf "#define GSOAP_VERSION %d%02d%02d\n#define GSOAP_VERSION_LETTER '\''".($$4?$$4:"\\0")."'\''\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 - diff --git a/org.glite.lb.server/build.xml b/org.glite.lb.server/build.xml deleted file mode 100755 index ca199d2..0000000 --- a/org.glite.lb.server/build.xml +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb.server/config/glite-lb-dbsetup.sql b/org.glite.lb.server/config/glite-lb-dbsetup.sql deleted file mode 100644 index 72513ba..0000000 --- a/org.glite.lb.server/config/glite-lb-dbsetup.sql +++ /dev/null @@ -1,158 +0,0 @@ -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, - proxy bool not null, - server bool not null, - grey bool not null, - nevents int not null, - - primary key (jobid), - unique (dg_jobid), - index (userid) -) 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, - seqcode varchar(255) binary not null, - - primary key (jobid,event), - index (time_stamp), - index (host), - index (arrived) -) engine=innodb; - -create table events_flesh ( - jobid char(32) binary not null, - event int not null, - ulm mediumblob not null, - - primary key (jobid,event) -) engine=innodb; - --- for compatibility -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; - --- for compatibility -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, - flags int not null, - - `STD_owner` varchar(200) null, - `STD_network_server` varchar(200) null, - `JDL_VirtualOrganisation` varchar(200) null, - - primary key (notifid), - index (`STD_owner`), - index (`STD_network_server`), - index (`JDL_VirtualOrganisation`) -) 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; - -create table zombie_jobs ( - jobid varchar(32) not null, - prefix_id tinyint unsigned not null, - suffix_id tinyint unsigned not null, - - primary key (jobid) -) engine=innodb; - -create table zombie_prefixes ( - prefix_id tinyint unsigned not null auto_increment, - prefix varchar(255) binary not null, - - primary key (prefix_id) -) engine=innodb; - -create table zombie_suffixes ( - suffix_id tinyint unsigned not null auto_increment, - suffix varchar(255) binary not null, - - primary key (suffix_id) -) engine=innodb; - - diff --git a/org.glite.lb.server/config/glite-lb-index.conf.template b/org.glite.lb.server/config/glite-lb-index.conf.template deleted file mode 100644 index 915df1f..0000000 --- a/org.glite.lb.server/config/glite-lb-index.conf.template +++ /dev/null @@ -1,8 +0,0 @@ -[ - JobIndices = { - [ type = "system"; name = "owner" ], - [ type = "system"; name = "location" ], - [ type = "system"; name = "destination" ], - [ type = "system"; name = "lastUpdateTime" ] - } -] diff --git a/org.glite.lb.server/config/glite-lb-migrate_db2version20 b/org.glite.lb.server/config/glite-lb-migrate_db2version20 deleted file mode 100644 index a547fbf..0000000 --- a/org.glite.lb.server/config/glite-lb-migrate_db2version20 +++ /dev/null @@ -1,166 +0,0 @@ -# This script is intendent to be used to extend bkserver database to -# to be able to hold both bkserver and lbproxy jobs. -# The operation should be non-destructive, i.e. all data should persist -# and continue to be fully usable. - -#!/bin/bash - -usage() { -cat </dev/null - if [ $? != 0 ]; then - echo "ALTER TABLE $table ENGINE=InnoDB" | mysql -u lbserver $DB_NAME - fi -done - - -# add new columns -mysql -u lbserver $DB_NAME -e "ALTER TABLE jobs ADD proxy bool not null" -mysql -u lbserver $DB_NAME -e "ALTER TABLE jobs ADD server bool not null" -mysql -u lbserver $DB_NAME -e "ALTER TABLE jobs ADD grey bool not null" -mysql -u lbserver $DB_NAME -e "ALTER TABLE jobs ADD nevents int not null" - - -# flag all jobs as server jobs -if [ "$SERVER" ]; then - mysql -u lbserver $DB_NAME -e "UPDATE jobs SET proxy='0'" - mysql -u lbserver $DB_NAME -e "UPDATE jobs SET server='1'" -else - mysql -u lbserver $DB_NAME -e "UPDATE jobs SET proxy='1'" - mysql -u lbserver $DB_NAME -e "UPDATE jobs SET server='0'" -fi - - -# for all greyjobs set a flag -mysql -u lbserver $DB_NAME -e "UPDATE jobs,grey_jobs SET jobs.grey='1' WHERE jobs.jobid=grey_jobs.jobid" - - -# erase grey_jobs table -mysql -u lbserver $DB_NAME -e "DROP TABLE grey_jobs" - - -# set nevents field -mysql -u lbserver $DB_NAME -e "UPDATE jobs SET nevents=(SELECT max(event) FROM events where events.jobid=jobs.jobid)+1" - - -# seqcode -mysql -u lbserver $DB_NAME -e "ALTER TABLE events ADD seqcode varchar(255) binary not null" -mysql -u lbserver $DB_NAME -e "UPDATE events,short_fields SET events.seqcode=short_fields.value WHERE events.event=short_fields.event AND events.jobid=short_fields.jobid AND short_fields.name='SEQCODE'" -mysql -u lbserver $DB_NAME -e "DELETE FROM short_fields where name='SEQCODE'" - - -# create events_flesh table -mysql -u lbserver $DB_NAME -e "\ -\ -create table events_flesh (\ - jobid char(32) binary not null,\ - event int not null,\ - ulm mediumblob not null,\ -\ - primary key (jobid,event)\ -) engine=innodb" - - -# notif_registrations UPDATE -mysql -u lbserver $DB_NAME -e "ALTER TABLE notif_registrations ADD flags int not null" - -mysql -u lbserver $DB_NAME -e "ALTER TABLE notif_registrations ADD STD_owner varchar(200) null" && \ -mysql -u lbserver $DB_NAME -e "ALTER TABLE notif_registrations ADD index(STD_owner)" - -mysql -u lbserver $DB_NAME -e "ALTER TABLE notif_registrations ADD STD_network_server varchar(200) null" && \ -mysql -u lbserver $DB_NAME -e "ALTER TABLE notif_registrations ADD index(STD_network_server)" - -mysql -u lbserver $DB_NAME -e "ALTER TABLE notif_registrations ADD JDL_VirtualOrganisation varchar(200) null" && \ -mysql -u lbserver $DB_NAME -e "ALTER TABLE notif_registrations ADD index(JDL_VirtualOrganisation)" - - -# zombie jobs -mysql -u lbserver $DB_NAME -e "\ -\ -create table zombie_jobs (\ - jobid varchar(32) not null,\ - prefix_id tinyint unsigned not null,\ - suffix_id tinyint unsigned not null,\ -\ - primary key (jobid)\ -) engine=innodb" - -mysql -u lbserver $DB_NAME -e "\ -\ -create table zombie_prefixes (\ - prefix_id tinyint unsigned not null auto_increment,\ - prefix varchar(255) binary not null,\ -\ - primary key (prefix_id)\ -) engine=innodb" - -mysql -u lbserver $DB_NAME -e "\ -\ -create table zombie_suffixes (\ - suffix_id tinyint unsigned not null auto_increment,\ - suffix varchar(255) binary not null,\ -\ - primary key (suffix_id)\ -) engine=innodb" - diff --git a/org.glite.lb.server/config/startup b/org.glite.lb.server/config/startup deleted file mode 100755 index e920349..0000000 --- a/org.glite.lb.server/config/startup +++ /dev/null @@ -1,208 +0,0 @@ -#!/bin/sh -# chkconfig: 345 75 25 - -GLITE_LOCATION=${GLITE_LOCATION:-/opt/glite} -GLITE_LOCATION_VAR=${GLITE_LOCATION_VAR:-/var/glite} -GLITE_JP_LOCATION=${GLITE_JP_LOCATION:-$GLITE_LOCATION} - -[ -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" -[ -n "$GLITE_JP_IMPORTER_PIDFILE" ] && jp_importer_pidfile=$GLITE_JP_IMPORTER_PIDFILE || - jp_importer_pidfile=$GLITE_LOCATION_VAR/glite-jp-importer.pid - -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=$GLITE_LOCATION_VAR/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=$GLITE_LOCATION_VAR/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 - if [ ! -x $GLITE_JP_LOCATION/bin/glite-jp-importer ]; then - echo "glite-jp-importer needed for export to Job Provenace, install glite-jp-client package too." - exit 1 - fi - - # registrations - [ -z "$GLITE_LB_EXPORT_JPREG_MAILDIR" ] && GLITE_LB_EXPORT_JPREG_MAILDIR=$GLITE_LOCATION_VAR/jpreg - jpreg_maildir="--reg-mdir $GLITE_LB_EXPORT_JPREG_MAILDIR" - lbreg_maildir="--jpreg-dir $GLITE_LB_EXPORT_JPREG_MAILDIR" - [ -d "$GLITE_LB_EXPORT_JPREG_MAILDIR" ] || mkdir -p "$GLITE_LB_EXPORT_JPREG_MAILDIR" && chown $GLITE_USER:$GLITE_GROUP -R "$GLITE_LB_EXPORT_JPREG_MAILDIR" - - # dumps - [ -z "$GLITE_LB_EXPORT_JPDUMP_MAILDIR" ] && GLITE_LB_EXPORT_JPDUMP_MAILDIR=$GLITE_LOCATION_VAR/jpdump - jpdump_maildir="--dump-mdir $GLITE_LB_EXPORT_JPDUMP_MAILDIR" - [ -d "$GLITE_LB_EXPORT_JPDUMP_MAILDIR" ] || mkdir -p "$GLITE_LB_EXPORT_JPDUMP_MAILDIR" && chown $GLITE_USER:$GLITE_GROUP -R "$GLITE_LB_EXPORT_JPDUMP_MAILDIR" - - # sandboxes - [ -z "$GLITE_LB_EXPORT_SANDBOX_MAILDIR" ] && GLITE_LB_EXPORT_SANDBOX_MAILDIR=$GLITE_LOCATION_VAR/sandbox - sandbox_maildir="--sandbox-mdir $GLITE_LB_EXPORT_SANDBOX_MAILDIR" - [ -d "$GLITE_LB_EXPORT_SANDBOX_MAILDIR" ] || mkdir -p "$GLITE_LB_EXPORT_SANDBOX_MAILDIR" && chown $GLITE_USER:$GLITE_GROUP -R "$GLITE_LB_EXPORT_SANDBOX_MAILDIR" - - # target Job Provenance - [ -n "$GLITE_LB_EXPORT_JPPS" ] && jpps="--jpps $GLITE_LB_EXPORT_JPPS" - 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" - if [ -n "$GLITE_LB_SERVER_DEBUG" ] ; then - if which tscat >/dev/null; then - GLITE_LB_SERVER_OTHER_OPTIONS="$GLITE_LB_SERVER_OTHER_OPTIONS -d -s 1 2>&1 | tscat >> $GLITE_LOCATION_VAR/lb.log &" - GLITE_LB_NOTIF_OTHER_OPTIONS="$GLITE_LB_NOTIF_OTHER_OPTIONS -v -d 2>&1 | tscat >> $GLITE_LOCATION_VAR/notif-il.log &" - else - GLITE_LB_SERVER_OTHER_OPTIONS="$GLITE_LB_SERVER_OTHER_OPTIONS -d -s 1 >> $GLITE_LOCATION_VAR/lb.log 2>&1 &" - GLITE_LB_NOTIF_OTHER_OPTIONS="$GLITE_LB_NOTIF_OTHER_OPTIONS -v -d >> $GLITE_LOCATION_VAR/notif-il.log 2>&1 &" - fi - fi - - echo -n Starting glite-lb-bkserverd ... - su - $GLITE_USER -c "$GLITE_LOCATION/bin/glite-lb-bkserverd \ - --notif-il-sock=$GLITE_LB_NOTIF_SOCK \ - --notif-il-fprefix=$GLITE_LB_NOTIF_FPREFIX \ - $super $creds -i $pidfile $port $wport $dumpdir $purgedir $lbreg_maildir\ - $GLITE_LB_SERVER_OTHER_OPTIONS" \ - && echo " done" || echo " FAILED" - - if test -x $GLITE_LOCATION/bin/glite-lb-notif-interlogd; then - 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 \ - -M 10485760 \ - $creds $GLITE_LB_NOTIF_OTHER_OPTIONS" && echo " done" || echo " FAILED" - else - echo Warning: glite-lb-notif-interlogd not installed, LB notifications will not work - fi - - if test x"$GLITE_LB_EXPORT_ENABLED" = x"true" ; then - echo -n Starting glite-jp-importer ... - su - $GLITE_USER -c "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GLITE_JP_LOCATION/lib $GLITE_JP_LOCATION/bin/glite-jp-importer \ - -i $jp_importer_pidfile $jpreg_maildir $jpdump_maildir $sandbox_maildir \ - $jpps $creds $GLITE_JP_IMPORTER_ARGS" \ - && echo " done" || echo " FAILED" - fi -} - -stop_daemon() -{ - name="$1" - pidfile="$2" - - if [ -f "$pidfile" ]; then - pid=`cat "$pidfile"` - kill $pid - echo -n Stopping $name \($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 - $name not running? >&2 - return 1 - fi -} - -status_daemon() -{ - name="$1" - pidfile="$2" - - if [ -f "$pidfile" ]; then - pid=`cat "$pidfile"` - if ps p $pid >/dev/null 2>&1; then - echo $name running as $pid - else - echo $name not running - return 1 - fi - else - echo $name not running - return 1 - fi - - return 0 -} - -stop() -{ - echo -n Stopping glite-lb-notif-interlogd ... - killall glite-lb-notif-interlogd - echo done - - stop_daemon "glite-lb-bkserverd" $pidfile - if test x"$GLITE_LB_EXPORT_ENABLED" = x"true"; then - stop_daemon "glite-jp-importer" $jp_importer_pidfile - 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 - - status_daemon "glite-lb-bkserverd" "$pidfile" || retval=1 - if test x"$GLITE_LB_EXPORT_ENABLED" = x"true"; then - status_daemon "glite-jp-importer" "$jp_importer_pidfile" || 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 diff --git a/org.glite.lb.server/configure b/org.glite.lb.server/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lb.server/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lb.server/doc/glite-lb-bkindex.8 b/org.glite.lb.server/doc/glite-lb-bkindex.8 deleted file mode 100644 index 0d43e51..0000000 --- a/org.glite.lb.server/doc/glite-lb-bkindex.8 +++ /dev/null @@ -1,171 +0,0 @@ -.TH GLITE-LB-BKINDEX 8 "April 2008" "EU EGEE Project" "Logging&Bookkeeping" - -.SH NAME -glite-lb-bkindex - dump or rebuild bookkeeping server indices - -.SH SYNOPSIS -.B glite-lb-bkindex -.RB [\| -mrv\| ] -.RI [ FILE ] -.br -.B glite-lb-bkindex -.RB [\| -dmv\| ] - - -.SH DESCRIPTION -The bookkeeping server -.B glite-lb-bkserverd -uses database indices to support various types of user queries efficiently. -.B glite-lb-bkindex -is a tool for dumping and manipulating the indices. -Both single- and multiple-column indices are supported. - -Due to performance reasons (reindexing may take rather long time) -the default invocation performs only "dry run" - the input is checked and intended actions -reported but not really performed. -The option -r has to be specified to do the real work. - -.B glite-lb-bkindex -should not be run while there is a running -.B glite-lb-bkserverd -on top of the same database. - -.PP -By default the L&B server indexes data according to JobId only. Because -the querying capabilities of L&B release 2 were considerably extended, -the server refuses to process a query which would not utilize any index. -This prevent overloading the underlying database engine. Consequently, even a trivial query 'give me all my jobs' results in an error in the default setup because under certain conditions processing such query may require handling gigabytes of data. - -.PP -The server administrator can create and modify the set of indices and control the set of supported queries. The description of columns to be indexed is given to -.B glite-lb-bkindex -utility via -.I FILE -that follows this syntax (subset of ClassAd syntax): - -.PP -.IP -.I FILE -::= -.BI [\ JobIndices\ =\ {\ index-description\ \fR[\fP ,\ index-description\fR]*\fP -.B } ] -.br -.I index-description -::= -.I column-description \fR|\fP list-of-columns -.br -.I list-of-columns -::= -.BI {\ column-description\ \fR+\fP\ } -.br -.I column-description -::= -.BI [\ column-type ;\ column-name ;\ prefix-len\ \fR?\fP\ ] -.br -.I column-type -::= -.B type = """user""" \fR|\fP type = """system""" \fR|\fP type = """time""" -.br -.I column-name -::= -.B name = """\fIactual_column_name\fP""" -.br -.I prefix-len -::= -.BI prefixlen\ =\ integer - -.PP -The only top-level attribute -.B JobIndices -is a list (possibly empty) of index descriptions. Each index description is either a single column or a list of columns (where the order is important). The column is described by mandatory attributes -.B type -and -.B name\fR,\fP -and an optional attribute -.B prefixlen\fR.\fP -Possible values of type are -.B """system""" -(L&B internal attributes) -.B """time""" -("state entered" timestamps), and -.B """user""" -(user tags). -Currently supported system column names are -.I owner\fR,\fP destination \fRand\fP location\fR.\fP -and valid timestamps are the job states, i.e. -.I submitted, waiting, ready, scheduled, running, done, cleared, cancelled, aborted\fR. -Names of user tags are arbitrary as long as their length is less than 60 characters and they contain only ASCII printable characters excluding backtick (`). -The -.B prefixlen -value may be used to restrict indexing of columns, which may grow rather long, to a fixed size. This becomes necessary with compound indices as MySQL limits the total size of index to 250 bytes only. - -.PP -In the following example the index file contains two indices, the first -one on a single system attribute -- , the second one composed -from system attribute (job) and user tag called : - -.IP -[ -.br -\ \ JobIndices = { -.br -\ \ \ \ [ type = "system"; name = "owner" ], -.br -\ \ \ \ { -.br -\ \ \ \ \ \ [ type = "system"; name = "destination"; -.br -\ \ \ \ \ \ \ \ prefixlen = 100 ], -.br -\ \ \ \ \ \ [ type = "user"; name = "experiment number"; -.br -\ \ \ \ \ \ \ \ prefixlen = 100 ] -.br -\ \ \ \ } -.br -\ \ } -.br -] - -.SH OPTIONS -.TP -.B "-d\fR,\fP --dump" -Print current setup on -.I stdout\fR.\fP - -.TP -.BI \-m " STRING" "\fR,\fP --mysql " STRING -.I STRING -is the database connect string in the form - -USER_NAME/PASSWORD@DB_HOSTNAME:DB_NAME - -It defaults to lbserver/@localhost:lbserver20 (common with -.B glite-lb-bkserverd\fR). - -.TP -.B "-r, --really" -Really perform reindexing. - -.TP -.B "-R, --remove" -Remove all indexes from server. - -.TP -.B "-v, --verbose" -Increase verbosity. - - -.\".SH USAGE -.\" Add any additional description here - -.PP - -.SH REPORTING BUGS -Please, report all bugs to EU EGEE Bug Tracking System located at https://savannah.cern.ch - -.SH SEE ALSO -.B glite-lb-purge\fR(8),\fP glite-lb-bkserverd\fR(8) - -.SH AUTHOR -EU EGEE, JRA1. diff --git a/org.glite.lb.server/doc/glite-lb-bkserverd.8 b/org.glite.lb.server/doc/glite-lb-bkserverd.8 deleted file mode 100644 index 94066c6..0000000 --- a/org.glite.lb.server/doc/glite-lb-bkserverd.8 +++ /dev/null @@ -1,330 +0,0 @@ -.TH GLITE-LB-BKSERVERD 8 "April 2008" "EU EGEE Project" "Logging&Bookkeeping" - -.SH NAME -glite-lb-bkserverd - bookkeeping server daemon - -.SH SYNOPSIS -.B glite-lb-bkserverd -.RI [ options ] -.br - -.SH DESCRIPTION -.B glite-lb-bkserverd -accepts L&B events from interlogger, manages the data storage, -and serves user queries (L&B consumer clients). - -Currently, the data are stored in MySQL database. - -.PP -The main process spawns several -.I slave -processes. Then it listens on -.I port -(default value is 9000) for consumer queries and -.I port+1 -for interlogger daemon requests to store events to database. -Requests are redirected to the slaves -(and picked up by the first free slave process). -All the connection handling and data processing (including SSL handshake) -is performed by the slaves. - -The slaves voluntarily die and are resurrected periodically to workaround -potential resource leakage. - - -.SH OPTIONS -.TP -.BI \-a " HOST:PORT" "\fR,\fP --address " HOST:PORT -Make the server pretend (wrt. data handling) it listens on -.I HOST:PORT -instead of the real listening address. -This is used for debugging and various administrative purposes -(e.g. computing usage statistics on data dumped from another server). - -.TP -.BI \-c " FILE" "\fR,\fP --cert " FILE -Get certificate from -.I FILE\fR.\fP -This option overrides the -.B \fR$\fPX509_USER_CERT -environment variable. - -.TP -.BI \-b " SWITCH" "\fR,\fP --transactions " SWITCH -Set transaction on/off. -.I SWITCH -is true where its value is not 0. - -.TP -.BI \-C " DIR" "\fR,\fP --CAdir " DIR -Trusted CA's certificates directory. -.I DIR\fR.\fP -This option overrides the -.B \fR$\fPX509_CERT_DIR -environment variable. - -.TP -.BI \-V " DIR" "\fR,\fP --VOMSdir " DIR -Trusted VOMS server's certificates directory. -.I DIR\fR.\fP -This option overrides the -.B \fR$\fPX509_VOMS_DIR -environment variable. - -.TP -.B "-d\fR,\fP --debug" -Don't run as daemon, print additional diagnostics. - -.TP -.B "-r\fR,\fP --rgmaexport" -Write state info to RGMA interface. - -.TP -.BI \-i " FILE" "\fR,\fP --pidfile " FILE -Store master pid into -.I FILE -instead of the default pidfile location. -Unless unavoidable it is not recommended to change the pidfile location -as it is also used for locking to prevent starting up multiple server instances -and to generate the semaphore set unique key (see option -l). - - -.TP -.BI \-k " FILE" "\fR,\fP --key " FILE -Get private key from -.I FILE\fR.\fP -This option overrides the -.B \fR$\fPX509_USER_KEY -environment variable. - -.TP -.BI -l " NUM" "\fR,\fP --semaphores " NUM -Use -.I NUM -semaphores (job locks). - -To prevent race conditions on simultaneous event storage and job-state updates -.B glite-lb-bkserverd -uses a set of semaphores to lock jobs. -Jobids are hashed to the semaphores and only one of the set of jobs that map -to a particular semaphore may be updated at any given time. -Therefore -.I NUM -is a limit on potential processing parallelism. - -.I NUM -defaults to the number of slaves (see -s). - - -.TP -.BI -L " NUM:NUM:NUM" "\fR,\fP --limits " NUM:NUM:NUM -Limit the maximum number of returned jobs/events that match user query to -.I NUM:NUM:NUM\fP in format events_limit:jobs_limit:size_limit.\ - -.TP -.BI -N " NUM" "\fR,\fP --notif-dur " NUM -Maximal duration of notification registrations in hours -.I NUM\fR.\fP - -.TP -.BI -S " PREFIX" "\fR,\fP --purge-prefix " PREFIX -Purge files full-path prefix -.I PREFIX\fR.\fP - -.TP -.BI -D " PREFIX" "\fR,\fP --dump-prefix " PREFIX -Dump files full-path prefix -.I PREFIX\fR.\fP - -.TP -.BI -J " DIR" "\fR,\fP --jpreg-dir " DIR -JP registration temporary files prefix (implies '-j'). -.I DIR\fR.\fP - -.TP -.BI "-j \fR,\fP --enable-jpreg-export" -Enable JP registration export (disabled by default). - -.TP -.BI \-m " STRING" "\fR,\fP --mysql " STRING -.I STRING -is a database connect string in the form - -USER_NAME/PASSWORD@DB_HOSTNAME:DB_NAME - -It defaults to lbserver/@localhost:lbserver20. - -.TP -.B "-n, --noauth" -Turn off any authorization. - -.TP -.BI \-p " NUM" "\fR,\fP --port " NUM -Listen on the port -.I NUM\fR.\fP - -.TP -.BI \-w " NUM" "\fR,\fP --wsport " NUM -Set port to serve the web services requests to -.I NUM\fR. - -.TP -.B "-r\fR,\fP --rgmaexport" -Write state info into the RGMA interface. Experimental. - -.TP -.BI -s " NUM" "\fR,\fP --slaves " NUM -Fork -.I NUM -slaves. - -.TP -.BI --super-user " USER" "\fR,\fP --super-user-file " FILE -Bypass query authorization (i.e. return results anyway) when -USER (or users listed in FILE) connect. - -.TP -.BI --no-index " NUM" -Disable checking the indices for superusers (NUM=1) or entirely (NUM=2). - -.TP -.BI --strict-locking -.I (not recommended). -Use a more strict locking strategy -- lock jobs sooner, when events -are stored, not just for status update. -This prevents a non-probable but still possible race -condition with parallel purge but may slow down processing on -heavy loaded servers. Anyway, the only consequence of the race condition -is a little garbage left in the database which is cleaned -form time to time anyway. - -.TP -.BI --notif-il-sock " SOCK -Socket -.I SOCK -to send notifications. - -.TP -.BI --notif-il-sock " PREFIX -File -.I PREFIX -for notifications. - -.TP -.BI --count-statistics " NUM -Count certain statistics on jobs for superusers (NUM=1) or for all (NUM=2). - -.TP -.BI -t " NUM" "\fR,\fP --request-timeout " NUM -Request timeout -.I NUM -for one client. - -.TP -.BI --silent -Do not print diagnostic, even if -d is on. - -.TP -.BI -g \fP --greyjobs -Allow delayed registration (grey jobs), implies --strict-locking. - -.TP -.BI -A\fR,\fP --enable-lcas -Activate LCAS-based authorization. - -.TP -.BI -I\fR,\fP --rss-time " NUM" -Set the maximal age (in seconds) of states published via RSS. - -.TP -.BI -P\fR,\fP --proxyonly -Run only proxy service. - -.TP -.BI -B\fR,\fP --withproxy -Run both server and proxy service. - -.TP -.BI -o\fR,\fP --sock -Path-name to the local socket for communication with LB proxy. - -.TP -.BI -q\fR,\fP --con-queue -Size of the connection queue (accept). - -.TP -.BI -W\fR,\fP --proxy-il-sock -Socket to send events to. - -.TP -.BI -Z\fR,\fP --proxy-il-fprefix -File prefix for events. - -.\".SH USAGE -.\" Add any additional description here - -.PP - -.SH FILES -.TP -.I /var/run/edg-bkserverd.pid -if running as root (not recommended). - -.TP -.I $HOME/edg-bkserverd.pid -otherwise. - -.TP -File to store pid and to generate semaphores key. - -.TP -No configuration files needed. - -.SH ENVIRONMENT -.TP -.B X509_USER_KEY -If -.B \fR$\fPX509_USER_KEY -is set, it is used to locate private key file. - -.TP -.B X509_USER_CERT -If -.B \fR$\fPX509_USER_CERT -is set, it is used to locate certificate file. - -.TP -.B X509_CERT_DIR -If -.B \fR$\fPX509_CERT_DIR -is set, it is used to locate the trusted CA's certificates and ca-signing-policy files. - -.TP -.B X509_USER_PROXY -If -.B \fR$\fPX509USER_PROXY -is set, it is used to locate proxy certificate file. - -.TP -.B EDG_WL_RGMA_FILE -If -.B \fR$\fPEDG_WL_RGMA_FILE -is set, it is used as name of file for sharing data with RGMA services. - -.TP -.B EDG_WL_RGMA_SOCK -If -.B \fR$\fPEDG_WL_RGMA_SOCK -is set, it is used as name of socket for communication with RGMA. - -.SH BUGS -In a case of a sudden crash, alive slave processes may survive or some resources (IPC locks, open ports) may stay allocated. Please, deal with such problems via standard commands -.B kill\fR and\fP ipcrm\fR.\fP - -Please, report all bugs to EU EGEE Bug Tracking System located at https://savannah.cern.ch - -.SH SEE ALSO -.B glite-lb-bkindex\fR(8),\fP glite-lb-purge\fR(8),\fP glite-lb-interlogd\fR(8),\fP glite-lb-logd\fR(8),\fP glite-lb-logevent\fR(1),\fP - -.SH AUTHOR -EU EGEE, JRA1. diff --git a/org.glite.lb.server/doc/glite-lb-mon-db.1 b/org.glite.lb.server/doc/glite-lb-mon-db.1 deleted file mode 100644 index ab0eefd..0000000 --- a/org.glite.lb.server/doc/glite-lb-mon-db.1 +++ /dev/null @@ -1,57 +0,0 @@ -.TH GLITE-LB-MON-DB 1 "Mar 2006" "EU EGEE Project" "Logging & Bookkeeping Utils" - -.SH NAME -glite-lb-mon-db - program for monitoring the number of jobs in the LB system - -.SH SYNOPSIS -.B glite-lb-mon-db -.B [-m dbstring -d -v -h] -.br - -.SH DESCRIPTION -.B glite-lb-mon-db -is a low-level program for monitoring the the number of jobs in the LB system. -Using the LB internals, it connects directly to the underlying MySQL database and reads -the number of jobs in each state. - -.SH OPTIONS -.TP -.B \-m dbstring, \-\-mysql=dbstring -Use non-default database connection string. - -.TP -.B \-d, \-\-debug -Print debug info (if any). - -.TP -.B \-v, \-\-verbose -Be verbose. - -.TP -.B \-h, \-\-help -Display help and exit. - -.SH EXAMPLES -.TP -.BI glite-lb-mon-db -this is the default usage -.TP -.BI glite-lb-mon-db \ -m \ lbserver/@localhost:lbproxy -use this dbstring to query the LB Proxy database. WARNING: the data in the LB Proxy may be incomplete! - -.SH ENVIRONMENT -.TP -.B MYSQL_UNIX_PORT -set this environment variable to specify the path to the non-default MySQL socket path -.TP -.B LBDB -you can set this environment variable as an alternative to specify the non-default database connection string - -.SH REPORTING BUGS -Please, report all bugs to EU EGEE Bug Tracking System located at https://savannah.cern.ch/bugs/?func=additem&group=jra1mdw - -.SH SEE ALSO -.BR glite-lb-mon (1) - -.SH AUTHOR -EU EGEE JRA1, CESNET group. diff --git a/org.glite.lb.server/examples/stdsoap2_2.6.0.c b/org.glite.lb.server/examples/stdsoap2_2.6.0.c deleted file mode 100644 index b4d6102..0000000 --- a/org.glite.lb.server/examples/stdsoap2_2.6.0.c +++ /dev/null @@ -1,10775 +0,0 @@ -/* - -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 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, "")) - 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, "", 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, "", 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, "", 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 - diff --git a/org.glite.lb.server/examples/stdsoap2_2.6.2.c b/org.glite.lb.server/examples/stdsoap2_2.6.2.c deleted file mode 100644 index 78c4872..0000000 --- a/org.glite.lb.server/examples/stdsoap2_2.6.2.c +++ /dev/null @@ -1,11020 +0,0 @@ -/* - -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 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, "")) - 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, "", 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, "", 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, "", 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 - diff --git a/org.glite.lb.server/examples/stdsoap2_2.7.0c.c b/org.glite.lb.server/examples/stdsoap2_2.7.0c.c deleted file mode 100644 index 2f97766..0000000 --- a/org.glite.lb.server/examples/stdsoap2_2.7.0c.c +++ /dev/null @@ -1,11629 +0,0 @@ -/* - -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_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 : "")) - 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, "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, "", 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, "", 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 = ""; -} -#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 - diff --git a/org.glite.lb.server/examples/stdsoap2_2.7.0d.c b/org.glite.lb.server/examples/stdsoap2_2.7.0d.c deleted file mode 100644 index fab9eee..0000000 --- a/org.glite.lb.server/examples/stdsoap2_2.7.0d.c +++ /dev/null @@ -1,11692 +0,0 @@ -/* - -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_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 : "")) - 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, "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, "", 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, "", 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 = ""; -} -#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 - diff --git a/org.glite.lb.server/interface/index.h b/org.glite.lb.server/interface/index.h deleted file mode 100644 index 2a6b9ad..0000000 --- a/org.glite.lb.server/interface/index.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef GLITE_LB_INDEX_H -#define GLITE_LB_INDEX_H - -#ident "$Header$" - -#include "glite/lb/query_rec.h" - -int edg_wll_QueryJobIndices(edg_wll_Context,edg_wll_QueryRec ***,char ***); -int edg_wll_QueryNotifIndices(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 *); - -char *edg_wll_StatToSQL(edg_wll_JobStat const *stat,edg_wll_QueryAttr attr); -char *edg_wll_JDLStatToSQL(edg_wll_JobStat const *stat, edg_wll_QueryRec col_rec); - - -typedef struct _edg_wll_IColumnRec { - edg_wll_QueryRec qrec; - char * colname; -} edg_wll_IColumnRec; - -void edg_wll_FreeIColumnRec(edg_wll_IColumnRec *); -edg_wll_ErrorCode edg_wll_IColumnsSQLPart(edg_wll_Context, void *, edg_wll_JobStat*, int , char **, char **); - -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_" -#define JDL_PREFIX "JDL_" - -#endif /* GLITE_LB_INDEX_H */ diff --git a/org.glite.lb.server/interface/lb_authz.h b/org.glite.lb.server/interface/lb_authz.h deleted file mode 100644 index fb078b9..0000000 --- a/org.glite.lb.server/interface/lb_authz.h +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef GLITE_LB_LB_AUTHZ_H -#define GLITE_LB_LB_AUTHZ_H - -#ident "$Header$" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef NO_GACL -#include -#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, glite_jobid_const_t, 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, glite_jobid_const_t, 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 *); - -extern int -check_store_authz(edg_wll_Context ctx, edg_wll_Event *ev); - -int edg_wll_amIroot(const char *subj, char **fqans,char **super_users); - - -#ifdef __cplusplus -} -#endif - -#endif /* GLITE_LB_LB_AUTHZ_H */ diff --git a/org.glite.lb.server/interface/pretty_print_wrapper.h b/org.glite.lb.server/interface/pretty_print_wrapper.h deleted file mode 100644 index e99a2af..0000000 --- a/org.glite.lb.server/interface/pretty_print_wrapper.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifdef __cplusplus -extern "C" { -#endif - -int pretty_print(char *jdl, char **formated_print); - -#ifdef __cplusplus -} -#endif - diff --git a/org.glite.lb.server/interface/query.h b/org.glite.lb.server/interface/query.h deleted file mode 100644 index e93a4a2..0000000 --- a/org.glite.lb.server/interface/query.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef GLITE_LB_QUERY_H -#define GLITE_LB_QUERY_H - -#ident "$Header$" - -#include "glite/jobid/cjobid.h" -#include "glite/lb/context.h" -#include "glite/lb/events.h" -#include "glite/lb/jobstat.h" -#include "glite/lb/query_rec.h" - -int convert_event_head(edg_wll_Context,char **,edg_wll_Event *); -int check_strict_jobid(edg_wll_Context, glite_jobid_const_t); -int match_status(edg_wll_Context, const edg_wll_JobStat *oldstat, const edg_wll_JobStat *stat,const edg_wll_QueryRec **conditions); -int check_job_query_index(edg_wll_Context, const edg_wll_QueryRec **); - -#define NOTIF_ALL_JOBS "all_jobs" - -#endif /* GLITE_LB_QUERY_H */ diff --git a/org.glite.lb.server/interface/srv_perf.h b/org.glite.lb.server/interface/srv_perf.h deleted file mode 100644 index feb315b..0000000 --- a/org.glite.lb.server/interface/srv_perf.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef GLITE_LB_SRV_PERF_H -#define GLITE_LB_SRV_PERF_H - -#ident "$Header$" - -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; - -#endif /* GLITE_LB_SRV_PERF_H */ diff --git a/org.glite.lb.server/interface/store.h b/org.glite.lb.server/interface/store.h deleted file mode 100644 index f620b5d..0000000 --- a/org.glite.lb.server/interface/store.h +++ /dev/null @@ -1,52 +0,0 @@ -#ident "$Header$" - -#ifndef GLITE_LB_STORE_H -#define GLITE_LB_STORE_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 */ - const char *, /* IN */ - int * -); - -void edg_wll_StoreAnonymous( - edg_wll_Context, /* INOUT */ - int /* IN (boolean) */ -); - -int db_store(edg_wll_Context, char *); -int db_parent_store(edg_wll_Context, edg_wll_Event *, intJobStat *); -int handle_request(edg_wll_Context,char *); -int handle_il_message(edg_wll_Context,char *); -int create_reply(const edg_wll_Context,char **); -int is_job_local(edg_wll_Context, glite_jobid_const_t jobId); -int store_job_server_proxy(edg_wll_Context ctx, edg_wll_Event *event, int *register_to_JP); -int register_subjobs_embryonic(edg_wll_Context,const edg_wll_RegJobEvent *); -edg_wll_ErrorCode intJobStat_embryonic(edg_wll_Context ctx, glite_jobid_const_t jobid, const edg_wll_RegJobEvent *e, intJobStat *stat); - - -int edg_wll_delete_event(edg_wll_Context,const char *, int); - - -#define USER_UNKNOWN "unknown" - -/* flags for JP registrations */ -#define REG_JOB_TO_JP 1 -#define REG_SUBJOBS_TO_JP 2 - - -#ifdef __cplusplus -} -#endif - -#endif /* GLITE_LB_STORE_H */ diff --git a/org.glite.lb.server/project/.cvsignore b/org.glite.lb.server/project/.cvsignore deleted file mode 100644 index 2b56473..0000000 --- a/org.glite.lb.server/project/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -MultiStruct.pm -StructField.pm -at3 -events.T -status.T -types.T diff --git a/org.glite.lb.server/project/ChangeLog b/org.glite.lb.server/project/ChangeLog deleted file mode 100644 index 62b4165..0000000 --- a/org.glite.lb.server/project/ChangeLog +++ /dev/null @@ -1,108 +0,0 @@ -1.8.0-1 (lb-1.7.0-1) -- add FQAN-based specification of superusers -- avoid giving no answer to client on some errors during purge (bug #30256) - -1.8.1-1 (lb-1.7.1-1) -- don't propagate errors from sent notifications to IL -- added man pages (not perfect yet) -- allow setting debug flags in startup script -- added run-time dependence on mysql-server -- fixed several memleaks -- ignore shallow branch seqence code for events coming from UI and NS - (fixes impossibility to clear jobs with ReallyRunning events) - -1.8.2-1 (lb-1.7.2-1) -- fix debug output redirection without tscat in startup script -- support notification expiration in interlogger -- implement expired notification purging on server -- rewrite internal event number increment code to avoid race & inifinit loop - with read-consistent transactional database (should fix bug #27555) -- revert enforced "strict locking" with transcactions (not needed anymore) - -1.8.3-1 (lb-1.7.4-1) -- JP plugin: implementation of finalDoneStatus and history status attributes -- fix double-free in state machine - -1.9.0-1 (lb-1.8.0-1) -- store dumps in GLITE_LOCATION_VAR rather than /tmp -- don't waste memory while reindexing -- handle subjob embryos in reindexing -- unify error handling for store and query -- don't clobber store errors with job unlocking -- don't send CollectionState from lb proxy to server -- export UI host and VOMS FQAN to RGMA -- don't coredump on requesting notifications that are denied -- don't return empty results for some non-indexed queries - -1.9.1-1 -- clarified soap error messages - -2.0.0-1 -- LB 2.0 release - -2.0.0-2 -- fixed configure to work in etics - -2.0.0-3 -- configure script update (globus flavors added to configure call) - -2.0.0-4 -- fixed server dependency on voms-api-cpp instead of voms-api-c in configure - -2.0.0-5 -- fixed credential setting via gsoap-plugin (switching to a newly introduced API call) -- minor initialization/freeing fixes -- printout typo fix - -2.0.1-1 -- (from 1.9.2-1) Support for chconfig in startup scripts (#27055) -- (from 1.9.2-1) Support for JP importer in startup scripts -- (from 1.9.2-1) Support for variant DN certificates (workaround for #41820) -- (from 1.9.2-1) Recalculate subjob states after DB version upgrade (#25871) -- (from 1.9.2-1) Ignore reseource_usage events when computing job states (#43767) -- (from 1.9.2-1) Fix sequence code processing for Change ACL events -- (from 1.9.2-1) WS example fix -- Reflect job conditions while processing queries for events (#32390) -- Support for 'greater' and 'smalleer' comparisons in jobids -- Modified handling of state-dependent timeouts. - -2.0.1-2 -- Notif IL installation removed from makefile -- configure script updated - -2.0.2-1 -- RSS feed implementation -- Fixed notification expiry -- Fixes to ACL handling -- Fixed authorization in simple interface -- Support for JDL changes in JDL-based notifications -- Initial implementation of WS notifications - -2.0.2-2 -- build wrt. voms 1.9.8 (globus-less) - -2.0.2-3 -- Makefile relies on the libdir variable -- New configure script - -2.0.3-1 -- Updated migration script -- Memleak fixes -- Support for background purge funcionality - -2.0.3-2 -- Rebuild with lb.state-machine 1.0.2-1 - ---- -Crystal ball: -2.0.4-1 -- Consider arch libdir when linking c-ares -- Checking the c-ares version, fix for c-ares >= 1.5.0. - -2.0.5-1 -- Reflect updates in the database module -- Adjusted grey job purges (purge undefined jobs etc.) - -2.0.3-3 -- install libraries into $libdir -- buildtime dependency pn c-ares diff --git a/org.glite.lb.server/project/build.number b/org.glite.lb.server/project/build.number deleted file mode 100644 index 10fccab..0000000 --- a/org.glite.lb.server/project/build.number +++ /dev/null @@ -1,2 +0,0 @@ -#Fri Aug 18 12:32:02 CEST 2006 -module.build=0245 diff --git a/org.glite.lb.server/project/build.properties b/org.glite.lb.server/project/build.properties deleted file mode 100644 index e69de29..0000000 diff --git a/org.glite.lb.server/project/configure.properties.xml b/org.glite.lb.server/project/configure.properties.xml deleted file mode 100644 index 3a73336..0000000 --- a/org.glite.lb.server/project/configure.properties.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - -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} - - - diff --git a/org.glite.lb.server/project/package.description b/org.glite.lb.server/project/package.description deleted file mode 100644 index 9468cb5..0000000 --- a/org.glite.lb.server/project/package.description +++ /dev/null @@ -1 +0,0 @@ -glite-lb-server is the gLite LB server. This package contains the LB server daemon (glite-lb-bkserverd) and a tool for rebuilding server indices (glite-lb-bkindex). diff --git a/org.glite.lb.server/project/package.summary b/org.glite.lb.server/project/package.summary deleted file mode 100644 index c5ac102..0000000 --- a/org.glite.lb.server/project/package.summary +++ /dev/null @@ -1 +0,0 @@ -gLite Logging and Bookkeeping server diff --git a/org.glite.lb.server/project/properties.xml b/org.glite.lb.server/project/properties.xml deleted file mode 100755 index 781ad01..0000000 --- a/org.glite.lb.server/project/properties.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/org.glite.lb.server/project/tar_exclude b/org.glite.lb.server/project/tar_exclude deleted file mode 100644 index b3133e4..0000000 --- a/org.glite.lb.server/project/tar_exclude +++ /dev/null @@ -1,10 +0,0 @@ -tar_exclude -CVS -build.xml -build -build.properties -properties.xml -configure-options.xml -.cvsignore -.project -.cdtproject diff --git a/org.glite.lb.server/project/version.properties b/org.glite.lb.server/project/version.properties deleted file mode 100644 index 69f2f17..0000000 --- a/org.glite.lb.server/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# : /cvs/jra1mw/org.glite.lb.server/project/version.properties,v 1.185 2008/06/25 13:12:58 akrenek Exp $ -module.version=2.0.3 -module.age=3 diff --git a/org.glite.lb.server/src/bkindex.c b/org.glite.lb.server/src/bkindex.c deleted file mode 100644 index acd7894..0000000 --- a/org.glite.lb.server/src/bkindex.c +++ /dev/null @@ -1,443 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/strmd5.h" -#include "glite/lbu/trio.h" -#include "glite/lb/context-int.h" -#include "index.h" -#include "jobstat.h" -#include "db_supp.h" -#include "openserver.h" -#include "db_calls.h" - -#ifdef LB_PERF -#include "glite/lb/lb_perftest.h" -#include "srv_perf.h" - -enum lb_srv_perf_sink sink_mode; -#endif - -/* XXX: referenced global variables, unsed in bkindex */ -char *server_key,*server_cert; -int enable_lcas; - -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 *); -static edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context, void *); - -/* 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 = NULL,**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 = NULL; - int i,j,k; - int nnew,nold,nadd,ndrop; - char *stmt; - - for (i=0; idbcaps = glite_lbu_DBQueryCaps(ctx->dbctx)) == -1) do_exit(ctx, EX_SOFTWARE); - if (!(ctx->dbcaps & GLITE_LBU_DB_CAP_INDEX)) { - edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_CALL, "index capability not available"); - do_exit(ctx, EX_SOFTWARE); - } - if (!(ctx->dbcaps & GLITE_LBU_DB_CAP_TRANSACTIONS)) { - edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_CALL, "transactions capability not available"); - do_exit(ctx, EX_SOFTWARE); - } - glite_lbu_DBSetCaps(ctx->dbctx, ctx->dbcaps); - - 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 ) goto quit; - } - - 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_ExecSQL(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_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); - free(stmt); - free(cname); - } - if (verbose) puts(" done"); - goto quit; - } - - 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= 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_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); - free(stmt); - } - if (verbose) puts(really ? "done" : ""); - } - - if (verbose) puts("Dropping columns ..."); - for (i=0; iattr == 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); - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) do_exit(ctx,EX_SOFTWARE); - free(stmt); - } - free(n); free(l); - if (verbose) puts(really ? "done" : ""); - } - -quit: - if (index_names) { - for (i = 0; index_names[i]; i++) free(index_names[i]); - free(index_names); - } - if (old_indices) { - for (i = 0; old_indices[i]; i++) { - for (j = 0; old_indices[i][j].attr; j++) edg_wll_QueryRecFree(&old_indices[i][j]); - free(old_indices[i]); - } - free(old_indices); - } - edg_wll_Close(ctx); - edg_wll_FreeContext(ctx); - - 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: - case EDG_WLL_QUERY_ATTR_NETWORK_SERVER: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - /* XXX: 255 may not be enough for location or destination */ - return "varchar(255) binary null"; - - case EDG_WLL_QUERY_ATTR_TIME: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - 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,"glite-lb-bkindex: %s (%s)\n",et,ed); - edg_wll_Close(ctx); - edg_wll_FreeContext(ctx); - exit(code); -} - -static void usage(const char *me) -{ - fprintf(stderr,"usage: %s [file]\n" - " -m,--mysql 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) - */ - -static edg_wll_ErrorCode edg_wll_RefreshIColumns(edg_wll_Context ctx, void *job_index_cols) { - - glite_lbu_Statement sh; - glite_lbu_Statement sh0; - int njobs, ret = -1; - intJobStat *stat; - edg_wlc_JobId jobid; - char *res[5]; - char *res0[1]; - char *rest; - char *icvalues, *stmt; - int i; - - edg_wll_ResetError(ctx); - if (!job_index_cols) return 0; - - if ((njobs = edg_wll_ExecSQL(ctx, "select jobid from states", &sh0)) < 0) { - glite_lbu_FreeStmt(&sh0); - return edg_wll_Error(ctx, NULL, NULL); - } - while ((ret=edg_wll_FetchRow(ctx,sh0,sizeof(res0)/sizeof(res0[0]),NULL,res0)) >0) { - do { - if (edg_wll_Transaction(ctx)) goto rollback; - trio_asprintf(&stmt, "select s.jobid,s.int_status,s.seq,s.version,j.dg_jobid" - " from states s, jobs j where s.jobid='%|Ss' and s.jobid=j.jobid" - " for update", - res0[0]); - if ((edg_wll_ExecSQL(ctx, stmt ,&sh)) < 1) { - glite_lbu_FreeStmt(&sh); - free(stmt); stmt = NULL; - goto rollback; - } - free(stmt); stmt = NULL; - if ((ret=edg_wll_FetchRow(ctx,sh,sizeof(res)/sizeof(res[0]),NULL,res)) <= 0) { - glite_lbu_FreeStmt(&sh); - goto rollback; - } - - if (strcmp(res[3], INTSTAT_VERSION)) { - stat = NULL; - if (!edg_wlc_JobIdParse(res[4], &jobid)) { - if ((stat = malloc(sizeof(intJobStat))) != NULL) { - if (!edg_wll_LoadIntState(ctx, jobid, 0 /* DONT_LOCK */, -1 /*all events*/, &stat)) { - destroy_intJobStat_extension(stat); - free(stat); - stat = NULL; - } else { - if (edg_wll_intJobStatus(ctx, jobid, 0, stat, 1, 0)) { - free(stat); - stat = NULL; - if (edg_wll_Error(ctx,NULL,NULL) != ENOENT) do_exit(ctx, EX_SOFTWARE); - } - } - } - edg_wlc_JobIdFree(jobid); - } - } else { - stat = dec_intJobStat(res[1], &rest); - if (rest == NULL) stat = NULL; - if (stat == NULL) fprintf(stderr,"glite-lb-bkindex: warning: " - "cannot decode int_status for %s\n",res[4]); - } - if (stat != NULL) { - edg_wll_IColumnsSQLPart(ctx, job_index_cols, &stat->pub, 0, NULL, &icvalues); - trio_asprintf(&stmt, "update states set seq=%s%s where jobid='%|Ss'", res[2], icvalues, res[0]); - ret = edg_wll_ExecSQL(ctx, stmt, NULL); - free(icvalues); - free(stmt); - destroy_intJobStat(stat); free(stat); - } - - for (i = 0; i < 5; i++) free(res[i]); - free(res0[0]); - glite_lbu_FreeStmt(&sh); - - if (ret < 0) goto rollback; -rollback:; - } while (edg_wll_TransNeedRetry(ctx)); - if (edg_wll_Error(ctx, NULL, NULL)) goto err; - } -err: - glite_lbu_FreeStmt(&sh0); - return edg_wll_Error(ctx, NULL, NULL); -} - diff --git a/org.glite.lb.server/src/bkserverd.c b/org.glite.lb.server/src/bkserverd.c deleted file mode 100644 index 8f8e62a..0000000 --- a/org.glite.lb.server/src/bkserverd.c +++ /dev/null @@ -1,1791 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef GLITE_LB_SERVER_WITH_WS -#include "soap_version.h" -#include -#include "glite/security/glite_gsplugin.h" -#endif /* GLITE_LB_SERVER_WITH_WS */ - -#include "glite/jobid/cjobid.h" -#include "glite/security/glite_gss.h" -#include "glite/lbu/srvbones.h" -#include "glite/lbu/maildir.h" -#include "glite/lb/context.h" -#include "glite/lb/mini_http.h" -#include "glite/lb/context-int.h" - -#ifdef LB_PERF -#include "glite/lb/lb_perftest.h" -#include "srv_perf.h" - -enum lb_srv_perf_sink sink_mode; -#endif - -#include "lb_http.h" -#include "lb_proto.h" -#include "index.h" -#include "lb_authz.h" -#include "il_notification.h" -#include "stats.h" -#include "db_calls.h" -#include "db_supp.h" -#include "openserver.h" - -#ifdef GLITE_LB_SERVER_WITH_WS -# if GSOAP_VERSION < 20700 - /* defined in 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 int edg_wll_StoreProtoProxy(edg_wll_Context ctx); - -extern char *lbproxy_ilog_socket_path; -extern char *lbproxy_ilog_file_prefix; - - -#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/glite-lb-bkserverd.pid" -#endif - -#ifndef GLITE_LBPROXY_SOCK_PREFIX -#define GLITE_LBPROXY_SOCK_PREFIX "/tmp/lb_proxy_" -#endif - -#ifndef dprintf -#define dprintf(x) { if (debug) printf x; } -#endif - -#define sizofa(a) (sizeof(a)/sizeof((a)[0])) - -#define SERVICE_PROXY DB_PROXY_JOB -#define SERVICE_SERVER DB_SERVER_JOB -#define SERVICE_PROXY_SERVER SERVICE_PROXY+SERVICE_SERVER - - - -int enable_lcas = 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; -int use_dbcaps = 0; -static int fake_port = 0; -static char **super_users = NULL; -static int slaves = 10; -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_max = 60*60*24, - notif_duration = 60*60*2; - -static edg_wll_GssCred mycred = NULL; -time_t cert_mtime = 0; -char *cadir = NULL, - *vomsdir = NULL, - *server_key = NULL, - *server_cert = NULL; -static int mode = SERVICE_SERVER; -static char sock_store[PATH_MAX], - sock_serve[PATH_MAX]; -static int con_queue = CON_QUEUE; -static char host[300]; -static char * port; -static time_t rss_time = 60*60; - - - - -static struct option opts[] = { - {"enable-lcas", 0, NULL, 'A'}, - {"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'}, - {"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, 'O'}, - {"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'}, - {"withproxy", 0, NULL, 'B'}, - {"proxyonly", 0, NULL, 'P'}, - {"sock", 1, NULL, 'o'}, - {"con-queue", 1, NULL, 'q'}, - {"proxy-il-sock", 1, NULL, 'W'}, - {"proxy-il-fprefix", 1, NULL, 'Z'}, - {"rss-time", 1, NULL, 'I'}, - {NULL,0,NULL,0} -}; - -static const char *get_opt_string = "Ac:k:C:V:p:a:drm:ns:i:S:D:J:jR:F:xOL:N:X:Y:T:t:zb:gPBo:q:W:Z:I:" -#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, --enable-lcas\t activate LCAS-based authorization\n" - "\t-a, --address\t use this server address (may be faked for debugging)\n" - "\t-b, --transactions\t transactions switch (0, 1)\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-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 default[:max]\t Duration of notification registrations in seconds (default and maximal)\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-K, --perf-sink\t where to sink events\n" -#endif - "\t-g,--greyjobs\t allow delayed registration (grey jobs), implies --strict-locking\n" - "\t-P,--proxyonly\t run only proxy service\n" - "\t-B,--withproxy\t run both server and proxy service\n" - "\t-o,--sock\t path-name to the local socket for communication with LB proxy\n" - "\t-q,--con-queue\t size of the connection queue (accept)\n" - "\t-W,--proxy-il-sock\t socket to send events to\n" - "\t-Z,--proxy-il-fprefix\t file prefix for events\n" - "\t-I,--rss-time age\t (in seconds) of job states published via RSS\n" - - ,me); -} - -static int wait_for_open(edg_wll_Context,const char *); -static int decrement_timeout(struct timeval *, struct timeval, struct timeval); -static int add_root(char *); -static int read_roots(const char *); -static int asyn_gethostbyaddr(char **, const char *, int, int, struct timeval *); -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 */ - - /* - * Proxy handlers - */ -int bk_clnt_reject_proxy(int); -int bk_handle_connection_proxy(int, struct timeval *, void *); -int bk_clnt_disconnect_proxy(int, struct timeval *, void *); - - - #define SERVICE_SERVER_START 0 - #define SRV_SERVE 0 - #define SRV_STORE 1 -#ifdef GLITE_LB_SERVER_WITH_WS - #define SRV_WS 2 - #define SERVICE_SERVER_SIZE 3 - - #define SERVICE_PROXY_START 3 - #define SRV_SERVE_PROXY 3 - #define SRV_STORE_PROXY 4 - #define SERVICE_PROXY_SIZE 2 -#else - #define SERVICE_SERVER_SIZE 2 - - #define SERVICE_PROXY_START 2 - #define SRV_SERVE_PROXY 2 - #define SRV_STORE_PROXY 3 - #define SERVICE_PROXY_SIZE 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 */ - { "serve_proxy", -1, bk_handle_connection_proxy, bk_accept_serve, bk_clnt_reject_proxy, bk_clnt_disconnect_proxy }, - { "store_proxy", -1, bk_handle_connection_proxy, bk_accept_store, bk_clnt_reject_proxy, bk_clnt_disconnect_proxy } -}; - -struct clnt_data_t { - edg_wll_Context ctx; -#ifdef GLITE_LB_SERVER_WITH_WS - struct soap *soap; -#endif /* GLITE_LB_SERVER_WITH_WS */ - glite_lbu_DBContext dbctx; - int dbcaps; - edg_wll_QueryRec **job_index,**notif_index; - edg_wll_IColumnRec *job_index_cols,*notif_index_cols;; - int mode; -}; - - - -int main(int argc, char *argv[]) -{ - int i; - struct sockaddr_in a; - int opt, pidfile_forced = 0; - char pidfile[PATH_MAX] = EDG_BKSERVERD_PIDFILE, - *name; -#ifdef GLITE_LB_SERVER_WITH_WS - char *ws_port; -#endif /* GLITE_LB_SERVER_WITH_WS */ - FILE *fpid; - edg_wll_Context ctx; - edg_wll_GssStatus gss_code; - struct timeval to; - int request_timeout = REQUEST_TIMEOUT; - int silent = 0; - char socket_path_prefix[PATH_MAX] = GLITE_LBPROXY_SOCK_PREFIX; - - - name = strrchr(argv[0],'/'); - if (name) name++; else name = argv[0]; - - memset(host, 0, sizeof host); - edg_wll_gss_gethostname(host,sizeof host); - host[sizeof host - 1] = 0; - - asprintf(&port, "%d", GLITE_JOBID_DEFAULT_PORT); -#ifdef GLITE_LB_SERVER_WITH_WS - asprintf(&ws_port, "%d", GLITE_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 */ - for (i=0; i < EDG_WLL_NUMBER_OF_STATCODES; i++) purge_timeout[i] = 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; - - while ((opt = getopt_long(argc,argv,get_opt_string,opts,NULL)) != EOF) switch (opt) { - case 'A': enable_lcas = 1; break; - 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 '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': { - int std,max; - switch (sscanf(optarg,"%d:%d",&std,&max)) { - case 2: notif_duration_max = max; - /* fallthrough */ - case 1: notif_duration = std; - break; - default: - usage(name); - return 1; - } - } break; - case 'X': notif_ilog_socket_path = strdup(optarg); break; - case 'Y': notif_ilog_file_prefix = strdup(optarg); break; - case 'i': strcpy(pidfile,optarg); pidfile_forced = 1; break; - case 'R': add_root(optarg); break; - case 'F': if (read_roots(optarg)) return 1; - break; - case 'x': noIndex = atoi(optarg); - if (noIndex < 0 || noIndex > 2) { usage(name); return 1; } - break; - case 'O': 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 'P': mode = SERVICE_PROXY; - break; - case 'B': mode = SERVICE_PROXY_SERVER; - break; - case 'o': strcpy(socket_path_prefix, optarg); - break; - case 'q': con_queue = atoi(optarg); - break; - case 'W': lbproxy_ilog_socket_path = strdup(optarg); - break; - case 'Z': lbproxy_ilog_file_prefix = strdup(optarg); - break; - case 'I': rss_time = atol(optarg); - break; - case '?': usage(name); return 1; - } - - if ( optind < argc ) { usage(name); return 1; } - - setlinebuf(stdout); - setlinebuf(stderr); - - dprintf(("\n")); - if (mode & SERVICE_PROXY) dprintf(("Starting LB proxy service\n")); - if (mode & SERVICE_SERVER) dprintf(("Starting LB server service\n")); - dprintf(("\n")); - - // XXX: workaround for only preudoparallel job registration - // we need at least 2 slaves to avoid locking misbehaviour - if ((mode == SERVICE_PROXY_SERVER) && (slaves == 1)) { - dprintf(("WARNING: Running both proxy and server services enforces at least 2 slaves\n")); - dprintf(("Starting 2 slaves\n")); - slaves = 2; - } - - if (!pidfile_forced && geteuid()) - snprintf(pidfile,sizeof pidfile, "%s/glite-lb-bkserverd.pid", getenv("HOME")); - - 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; } - - if (mode & SERVICE_SERVER) { - if (check_mkdir(dumpStorage)) exit(1); - if (check_mkdir(purgeStorage)) exit(1); - if ( jpreg ) { - if ( glite_lbu_MaildirInit(jpregDir) ) { - dprintf(("[%d] glite_lbu_MaildirInit failed: %s\n", getpid(), lbm_errdesc)); - if (!debug) syslog(LOG_CRIT, "glite_lbu_MaildirInit failed: %s", lbm_errdesc); - exit(1); - } - } - } - - if (mode & SERVICE_SERVER) { - if ( fake_host ) - { - char *p = strchr(fake_host,':'); - - if (p) - { - *p = 0; - fake_port = atoi(p+1); - } - else fake_port = atoi(port); - } - else { - fake_host = strdup(host); - fake_port = atoi(port); - } - - dprintf(("Server address: %s:%d\n", fake_host, fake_port)); - } - if ((mode & SERVICE_SERVER)) { - 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, &gss_code) ) - { - int i; - - dprintf(("Server identity: %s\n",mycred->name)); - server_subject = strdup(mycred->name); - for ( i = 0; super_users && super_users[i]; i++ ) ; - super_users = realloc(super_users, (i+2)*sizeof(*super_users)); - super_users[i] = strdup(mycred->name); - super_users[i+1] = NULL; - } - else { - dprintf(("Server running unauthenticated\n")); - server_subject = strdup("anonymous LB"); - } - - if ( noAuth ) dprintf(("Server in promiscuous mode\n")); - dprintf(("Server listening at %d,%d (accepting protocols: " COMP_PROTO " and compatible) ...\n",atoi(port),atoi(port)+1)); - -#ifdef GLITE_LB_SERVER_WITH_WS - dprintf(("Server listening at %d (accepting web service protocol) ...\n", atoi(ws_port))); -#endif /* GLITE_LB_SERVER_WITH_WS */ - - } -#ifdef GLITE_LB_SERVER_WITH_WS - free(ws_port); - ws_port = NULL; -#endif - if (mode & SERVICE_PROXY) { /* proxy stuff */ - struct sockaddr_un a; - - service_table[SRV_SERVE_PROXY].conn = socket(PF_UNIX, SOCK_STREAM, 0); - if ( service_table[SRV_SERVE_PROXY].conn < 0 ) { perror("socket()"); return 1; } - memset(&a, 0, sizeof(a)); - a.sun_family = AF_UNIX; - sprintf(sock_serve, "%s%s", socket_path_prefix, "serve.sock"); - strcpy(a.sun_path, sock_serve); - - if( connect(service_table[SRV_SERVE_PROXY].conn, (struct sockaddr *)&a, sizeof(a.sun_path)) < 0) { - if( errno == ECONNREFUSED ) { - dprintf(("removing stale input socket %s\n", sock_serve)); - unlink(sock_serve); - } - } else { perror("another instance of lb-proxy is running"); return 1; } - - if ( bind(service_table[SRV_SERVE_PROXY].conn, (struct sockaddr *) &a, sizeof(a)) < 0 ) { - char buf[100]; - - snprintf(buf, sizeof(buf), "bind(%s)", sock_serve); - perror(buf); - return 1; - } - - if ( listen(service_table[SRV_SERVE_PROXY].conn, con_queue) ) { perror("listen()"); return 1; } - - service_table[SRV_STORE_PROXY].conn = socket(PF_UNIX, SOCK_STREAM, 0); - if ( service_table[SRV_STORE_PROXY].conn < 0 ) { perror("socket()"); return 1; } - memset(&a, 0, sizeof(a)); - a.sun_family = AF_UNIX; - sprintf(sock_store, "%s%s", socket_path_prefix, "store.sock"); - strcpy(a.sun_path, sock_store); - - if( connect(service_table[SRV_STORE_PROXY].conn, (struct sockaddr *)&a, sizeof(a.sun_path)) < 0) { - if( errno == ECONNREFUSED ) { - dprintf(("removing stale input socket %s\n", sock_store)); - unlink(sock_store); - } - } else { perror("another instance of lb-proxy is running"); return 1; } - - if ( bind(service_table[SRV_STORE_PROXY].conn, (struct sockaddr *) &a, sizeof(a))) { - char buf[100]; - - snprintf(buf, sizeof(buf), "bind(%s)", sock_store); - perror(buf); - return 1; - } - if ( listen(service_table[SRV_STORE_PROXY].conn, con_queue) ) { perror("listen()"); return 1; } - - dprintf(("Proxy listening at %s, %s ...\n", sock_store, sock_serve)); - } - - if (!dbstring) dbstring = getenv("LBDB"); - if (!dbstring) dbstring = strdup(DEFAULTCS); - - /* Just check the database and let it be. The slaves do the job. */ - edg_wll_InitContext(&ctx); - if (wait_for_open(ctx, dbstring)) { - edg_wll_Close(ctx); - edg_wll_FreeContext(ctx); - return 1; - } - - if ((ctx->dbcaps = glite_lbu_DBQueryCaps(ctx->dbctx)) == -1) - { - char *et,*ed; - glite_lbu_DBError(ctx->dbctx,&et,&ed); - - fprintf(stderr,"%s: open database: %s (%s)\n",argv[0],et,ed); - free(et); free(ed); - return 1; - } - edg_wll_Close(ctx); - ctx->dbctx = NULL; - fprintf(stderr, "[%d]: DB '%s'\n", getpid(), dbstring); - - if ((ctx->dbcaps & GLITE_LBU_DB_CAP_INDEX) == 0) { - fprintf(stderr,"%s: missing index support in DB layer\n",argv[0]); - return 1; - } - if ((ctx->dbcaps & GLITE_LBU_DB_CAP_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->dbcaps & GLITE_LBU_DB_CAP_TRANSACTIONS ? 1 : 0, transactions); - ctx->dbcaps &= ~GLITE_LBU_DB_CAP_TRANSACTIONS; - ctx->dbcaps |= transactions ? GLITE_LBU_DB_CAP_TRANSACTIONS : 0; - } - use_dbcaps = ctx->dbcaps; - - if (count_statistics) edg_wll_InitStatistics(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); - - if (mode & SERVICE_SERVER) { - to = (struct timeval){CONNECT_TIMEOUT, 0}; - glite_srvbones_set_param(GLITE_SBPARAM_CONNECT_TIMEOUT, &to); - to.tv_sec = request_timeout; - } - // proxy using default from srvbones, 5s - - glite_srvbones_set_param(GLITE_SBPARAM_REQUEST_TIMEOUT, &to); - to = (struct timeval){IDLE_TIMEOUT, 0}; - glite_srvbones_set_param(GLITE_SBPARAM_IDLE_TIMEOUT, &to); - - switch (mode) { - case SERVICE_PROXY: - glite_srvbones_run(bk_clnt_data_init,service_table+SERVICE_PROXY_START, - SERVICE_PROXY_SIZE, debug); - break; - case SERVICE_SERVER: - glite_srvbones_run(bk_clnt_data_init,service_table+SERVICE_SERVER_START, - SERVICE_SERVER_SIZE, debug); - break; - case SERVICE_PROXY_SERVER: - glite_srvbones_run(bk_clnt_data_init,service_table+SERVICE_SERVER_START, - SERVICE_PROXY_SIZE+SERVICE_SERVER_SIZE, debug); - break; - default: - assert(0); - break; - } - - - unlink(pidfile); - - for ( i = 0; i < sizofa(service_table); i++ ) - if ( service_table[i].conn >= 0 ) close(service_table[i].conn); - - if (mode & SERVICE_PROXY) { - unlink(sock_serve); - unlink(sock_store); - } - - if (port) free(port); - edg_wll_gss_release_cred(&mycred, NULL); - - - return 0; -} - -static void list_index_cols(edg_wll_QueryRec **index,edg_wll_IColumnRec **index_cols_out) -{ - int i,j, k, maxncol, ncol; - edg_wll_IColumnRec *index_cols; - - ncol = maxncol = 0; - for ( i = 0; index[i]; i++ ) - for ( j = 0; index[i][j].attr; j++ ) - maxncol++; - - index_cols = calloc(maxncol+1, sizeof(edg_wll_IColumnRec)); - for ( i = 0; index[i]; i++ ) - { - for ( j = 0; index[i][j].attr; j++) - { - for ( k = 0; - k < ncol && edg_wll_CmpColumn(&index_cols[k].qrec, &index[i][j]); - k++); - - if ( k == ncol) - { - index_cols[ncol].qrec = index[i][j]; - if ( index[i][j].attr == EDG_WLL_QUERY_ATTR_USERTAG ) - { - index_cols[ncol].qrec.attr_id.tag = - strdup(index[i][j].attr_id.tag); - } - index_cols[ncol].colname = - edg_wll_QueryRecToColumn(&index_cols[ncol].qrec); - ncol++; - } - } - } - index_cols[ncol].qrec.attr = EDG_WLL_QUERY_ATTR_UNDEF; - index_cols[ncol].colname = NULL; - *index_cols_out = index_cols; -} - -int bk_clnt_data_init(void **data) -{ - edg_wll_Context ctx; - struct clnt_data_t *cdata; - edg_wll_QueryRec **job_index,**notif_index; - - - if ( !(cdata = calloc(1, sizeof(*cdata))) ) - return -1; - - cdata->mode = mode; - - if ( edg_wll_InitContext(&ctx) ) - { - free(cdata); - return -1; - } - - dprintf(("[%d] opening database ...\n", getpid())); - wait_for_open(ctx, dbstring); - glite_lbu_DBSetCaps(ctx->dbctx, use_dbcaps); - cdata->dbctx = ctx->dbctx; - cdata->dbcaps = use_dbcaps; - - 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); - } - cdata->job_index = job_index; - if ( job_index ) list_index_cols(job_index,&cdata->job_index_cols); - - if (edg_wll_QueryNotifIndices(ctx,¬if_index,NULL)) { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - - dprintf(("[%d]: query notif indices: %s: %s\n",getpid(),et,ed)); - free(et); free(ed); - } - cdata->notif_index = notif_index; - if (notif_index) list_index_cols(notif_index,&cdata->notif_index_cols); - - edg_wll_FreeContext(ctx); - -#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; - edg_wll_GssPrincipal client = NULL; - edg_wll_GssCred newcred = NULL; - edg_wll_GssStatus gss_code; - struct timeval dns_to = {DNS_TIMEOUT, 0}, - conn_start, now; - struct sockaddr_in a; - socklen_t alen; - char *server_name = NULL, - *name = NULL; - int h_errno, ret; - - - - 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, &gss_code) ) { - dprintf(("[%d] reloading credentials successful\n", getpid())); - edg_wll_gss_release_cred(&mycred, NULL); - 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->serverRunning = cdata->mode & SERVICE_SERVER; - ctx->proxyRunning = cdata->mode & SERVICE_PROXY; - ctx->dbctx = cdata->dbctx; - ctx->dbcaps = cdata->dbcaps; - ctx->job_index_cols = cdata->job_index_cols; - ctx->job_index = cdata->job_index; - ctx->notif_index_cols = cdata->notif_index_cols; - ctx->notif_index = cdata->notif_index; - - /* set globals - */ - ctx->notifDuration = notif_duration; - ctx->notifDurationMax = notif_duration_max; - 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; - 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); - - ctx->rssTime = rss_time; - - 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; - } - - ret = edg_wll_gss_get_client_conn(&ctx->connections->serverConnection->gss, &client, NULL); - if (ret || client->flags & EDG_WLL_GSS_FLAG_ANON) { - dprintf(("[%d] anonymous client\n",getpid())); - ctx->peerName = NULL; - } else { - if (ctx->peerName) free(ctx->peerName); - ctx->peerName = strdup(client->name); - edg_wll_gss_free_princ(client); - - dprintf(("[%d] client DN: %s\n",getpid(),ctx->peerName)); - } - - 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)); - } - if (debug && ctx->fqans && *(ctx->fqans)) - { - char **f; - - dprintf(("[%d] client's FQANs:\n",getpid())); - for (f = ctx->fqans; f && *f; f++) - dprintf(("\t%s\n", *f)); - } - - /* used also to reset start_time after edg_wll_ssl_accept! */ - /* gettimeofday(&start_time,0); */ - - ctx->noAuth = noAuth || edg_wll_amIroot(ctx->peerName, ctx->fqans,super_users); - switch ( noIndex ) - { - case 0: ctx->noIndex = 0; break; - case 1: ctx->noIndex = edg_wll_amIroot(ctx->peerName, ctx->fqans,super_users); break; - case 2: ctx->noIndex = 1; break; - } - ctx->strict_locking = strict_locking; - ctx->greyjobs = greyjobs; - - ctx->super_users = super_users; - - 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; - } - glite_gsplugin_set_connection(gsplugin_ctx, &cdata->ctx->connections->serverConnection->gss); - glite_gsplugin_use_credential(gsplugin_ctx, 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_handle_connection_proxy(int conn, struct timeval *timeout, void *data) -{ - struct clnt_data_t *cdata = (struct clnt_data_t *)data; - edg_wll_Context ctx; - struct timeval conn_start, now; - - if ( edg_wll_InitContext(&ctx) ) { - dprintf(("Couldn't create context")); - return -1; - } - cdata->ctx = ctx; - - /* Shared structures (pointers) - */ - ctx->serverRunning = cdata->mode & SERVICE_SERVER; - ctx->proxyRunning = cdata->mode & SERVICE_PROXY; - ctx->dbctx = cdata->dbctx; - ctx->dbcaps = cdata->dbcaps; - - /* set globals - */ - ctx->notifDuration = notif_duration; - ctx->notifDurationMax = notif_duration_max; - if ( jpreg ) ctx->jpreg_dir = strdup(jpregDir); else ctx->jpreg_dir = NULL; - ctx->allowAnonymous = 1; - ctx->isProxy = 1; - ctx->noAuth = 1; - ctx->noIndex = 1; - - /* required to match superuser-authorized notifications */ - ctx->super_users = super_users; - - if (fake_host) - { - ctx->srvName = strdup(fake_host); - ctx->srvPort = fake_port; - } - else { - ctx->srvName = strdup(host); - ctx->srvPort = atoi(port); - } - - ctx->connProxy = (edg_wll_ConnProxy *) calloc(1, sizeof(edg_wll_ConnProxy)); - if ( !ctx->connProxy ) { - perror("calloc"); - edg_wll_FreeContext(ctx); - - return -1; - } - - gettimeofday(&conn_start, 0); - if ( edg_wll_plain_accept(conn, &ctx->connProxy->conn) ) { - perror("accept"); - edg_wll_FreeContext(ctx); - - return -1; - } - - gettimeofday(&now, 0); - if ( decrement_timeout(timeout, conn_start, now) ) { - if (debug) fprintf(stderr, "edg_wll_plain_accept() timeout"); - else syslog(LOG_ERR, "edg_wll_plain_accept(): timeout"); - - return -1; - } - - ctx->rssTime = rss_time; - - return 0; -} - - -static int handle_server_error(edg_wll_Context ctx) -{ - char *errt = NULL, *errd = NULL; - int err,ret = 0; - - - errt = errd = NULL; - switch ( (err = edg_wll_Error(ctx, &errt, &errd)) ) - { - case ETIMEDOUT: - case EDG_WLL_ERROR_GSS: - case EPIPE: - case EIO: - case EDG_WLL_IL_PROTO: - dprintf(("[%d] %s (%s)\n", getpid(), errt, errd)); - if (!debug) syslog(LOG_ERR,"%s (%s)", errt, errd); - /* fallthrough - */ - case ENOTCONN: - case ECONNREFUSED: - /* - * "recoverable" error - return (>0) - */ - ret = err; - break; - - case ENOENT: - case EPERM: - case EEXIST: - case EDG_WLL_ERROR_NOINDEX: - case E2BIG: - dprintf(("[%d] %s (%s)\n", getpid(), errt, errd)); - break; - case EINVAL: - case EDG_WLL_ERROR_PARSE_BROKEN_ULM: - case EDG_WLL_ERROR_PARSE_EVENT_UNDEF: - case EDG_WLL_ERROR_PARSE_MSG_INCOMPLETE: - case EDG_WLL_ERROR_PARSE_KEY_DUPLICITY: - case EDG_WLL_ERROR_PARSE_KEY_MISUSE: - case EDG_WLL_ERROR_PARSE_OK_WITH_EXTRA_FIELDS: - case EDG_WLL_ERROR_JOBID_FORMAT: - case EDG_WLL_ERROR_MD5_CLASH: - dprintf(("[%d] %s (%s)\n", getpid(), errt, errd)); - if ( !debug ) syslog(LOG_ERR,"%s (%s)", errt, errd); - /* - * no action for non-fatal errors - */ - break; - - case EDG_WLL_ERROR_DB_INIT: - case EDG_WLL_ERROR_DB_CALL: - case EDG_WLL_ERROR_SERVER_RESPONSE: - 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) - */ - ret = -EIO; - } - free(errt); free(errd); - return ret; -} - -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; - int err; - - /* - * serve the request - */ - memcpy(&ctx->p_tmp_timeout, timeout, sizeof(ctx->p_tmp_timeout)); - gettimeofday(&before, NULL); - if ( edg_wll_StoreProto(ctx) && (err = handle_server_error(ctx))) return err; - - 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; - int err; - - /* - * serve the request - */ - memcpy(&ctx->p_tmp_timeout, timeout, sizeof(ctx->p_tmp_timeout)); - gettimeofday(&before, NULL); - if ( edg_wll_ServerHTTP(ctx) && (err = handle_server_error(ctx))) return err; - - 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 != NULL) - 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); - glite_gsplugin_set_connection(gsplugin_ctx, NULL); - glite_gsplugin_use_credential(gsplugin_ctx, 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_disconnect_proxy(int conn, struct timeval *timeout, void *cdata) -{ - edg_wll_Context ctx = ((struct clnt_data_t *) cdata)->ctx; - - /* XXX: handle the timeout - */ - if ( ctx->connProxy && ctx->connProxy->conn.sock >= 0 ) - edg_wll_plain_close(&ctx->connProxy->conn); - - edg_wll_FreeContext(ctx); - ctx = NULL; - - return 0; -} - -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 */ - -int bk_clnt_reject_proxy(int conn) -{ - return 0; -} - - -static int wait_for_open(edg_wll_Context ctx, const char *dbstring) -{ - char *dbfail_string1, *dbfail_string2; - char *errt,*errd; - int err; - - dbfail_string1 = dbfail_string2 = NULL; - - while (((err = edg_wll_Open(ctx, (char *) dbstring)) != EDG_WLL_ERROR_DB_INIT) && err) { - if (dbfail_string1) free(dbfail_string1); - edg_wll_Error(ctx,&errt,&errd); - asprintf(&dbfail_string1,"%s (%s)\n",errt,errd); - free(errt); - free(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"); - } - - if (err) { - edg_wll_Error(ctx,&errt,&errd); - asprintf(&dbfail_string1,"%s (%s)\n",errt,errd); - free(errt); - free(errd); - dprintf(("[%d]: %s\n", getpid(), dbfail_string1)); - if (!debug) syslog(LOG_ERR,dbfail_string1); - free(dbfail_string1); - } - - return err; -} - -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 add_root(char *root) -{ - char *null_suffix, **tmp; - int i, cnt; - - for (cnt = 0; super_users && super_users[cnt]; cnt++) - ; - /* try to be compliant with the new FQAN format that excludes - the Capability and empty Role components */ - null_suffix = strstr(root, "/Role=NULL/Capability=NULL"); - if (null_suffix == NULL) - null_suffix = strstr(root, "/Capability=NULL"); - i = (null_suffix == NULL) ? 0 : 1; - - tmp = realloc(super_users, (cnt+2+i) * sizeof super_users[0]); - if (tmp == NULL) - return ENOMEM; - super_users = tmp; - super_users[cnt] = strdup(root); - if (null_suffix) { - *null_suffix = '\0'; /* changes the input, should be harmless */ - super_users[++cnt] = strdup(root); - } - super_users[++cnt] = NULL; - - return 0; -} - -static int read_roots(const char *file) -{ - FILE *roots = fopen(file,"r"); - char buf[BUFSIZ]; - - 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; - add_root(buf); - } - - fclose(roots); - - 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); -} - diff --git a/org.glite.lb.server/src/cond_dump.c b/org.glite.lb.server/src/cond_dump.c deleted file mode 100644 index fbf72e9..0000000 --- a/org.glite.lb.server/src/cond_dump.c +++ /dev/null @@ -1,214 +0,0 @@ -#ident "$Header$" - -#include "glite/lb/context-int.h" -#include "lb_proto.h" - -#include -#include -#include -#include -#include - -#define TR(name,type,field) \ - if (field) { \ - asprintf(&pomA,"%s" name ":" \ - "" type "",pomB,(field)); \ - free(pomB); \ - pomB = pomA; \ - } - -#define GS(string){ \ - asprintf(&pomA, "%s %s", pomB, (string)); \ - free(pomB); \ - pomB = pomA; \ -} - -int edg_wll_Condition_Dump(notifInfo *ni, char **output, int oneline){ - if (! ni->conditions){ - *output = strdup(""); - return -1; - } - - char *pomA = NULL, *pomB; - pomB = strdup(""); - - edg_wll_QueryRec **l1; - edg_wll_QueryRec *l2; - for (l1 = ni->conditions; *l1; l1++){ - if (l1 != ni->conditions) - GS ("and"); - if (oneline) - GS("("); - l2 = *l1; - switch (l2->attr){ - case EDG_WLL_QUERY_ATTR_JOBID: GS("jobId"); - break; - case EDG_WLL_QUERY_ATTR_OWNER: GS("owner"); - break; - case EDG_WLL_QUERY_ATTR_STATUS: GS("status"); - break; - case EDG_WLL_QUERY_ATTR_LOCATION: GS("location"); - break; - case EDG_WLL_QUERY_ATTR_DESTINATION: GS("destination"); - break; - case EDG_WLL_QUERY_ATTR_DONECODE: GS("donecode"); - break; - case EDG_WLL_QUERY_ATTR_USERTAG: - GS(l2->attr_id.tag); - break; - case EDG_WLL_QUERY_ATTR_TIME: GS("time"); - break; - case EDG_WLL_QUERY_ATTR_LEVEL: GS("level"); - break; - case EDG_WLL_QUERY_ATTR_HOST: GS("host"); - break; - case EDG_WLL_QUERY_ATTR_SOURCE: GS("source"); - break; - case EDG_WLL_QUERY_ATTR_INSTANCE: GS("instance"); - break; - case EDG_WLL_QUERY_ATTR_EVENT_TYPE: GS("eventtype"); - break; - case EDG_WLL_QUERY_ATTR_CHKPT_TAG: GS("chkpttag"); - break; - case EDG_WLL_QUERY_ATTR_RESUBMITTED: GS("resubmitted"); - break; - case EDG_WLL_QUERY_ATTR_PARENT: GS("parent_job"); - break; - case EDG_WLL_QUERY_ATTR_EXITCODE: GS("exitcode"); - break; - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - GS(l2->attr_id.tag); //get JDL attribute name - break; - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: GS("stateentertime"); - break; - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: GS("lastupdatetime"); - break; - case EDG_WLL_QUERY_ATTR_NETWORK_SERVER: GS("networkserver"); - break; - default: - assert(! "Unknown attribute!"); - break; - } - for (l2 = *l1; l2->attr; l2++){ - if (l2 != *l1 && !oneline) GS (" or"); - if (l2 != *l1 && oneline) GS("or"); - switch(l2->op){ - case EDG_WLL_QUERY_OP_EQUAL: GS("="); - break; - case EDG_WLL_QUERY_OP_LESS: GS ("<"); - break; - case EDG_WLL_QUERY_OP_GREATER: GS ("<"); - break; - case EDG_WLL_QUERY_OP_WITHIN: GS ("within"); - break; - case EDG_WLL_QUERY_OP_UNEQUAL: GS ("!="); - } - char *buf; - switch (l2->attr){ - case EDG_WLL_QUERY_ATTR_JOBID: - case EDG_WLL_QUERY_ATTR_PARENT: - GS(edg_wlc_JobIdUnparse(l2->value.j)); - break; - case EDG_WLL_QUERY_ATTR_DESTINATION: - case EDG_WLL_QUERY_ATTR_LOCATION: - case EDG_WLL_QUERY_ATTR_OWNER: - case EDG_WLL_QUERY_ATTR_HOST: - case EDG_WLL_QUERY_ATTR_INSTANCE: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - case EDG_WLL_QUERY_ATTR_NETWORK_SERVER: - GS(l2->value.c); - break; - case EDG_WLL_QUERY_ATTR_STATUS: - if (l2->op == EDG_WLL_QUERY_OP_WITHIN) - asprintf(&buf, "%i and %i", - edg_wll_StatToString((edg_wll_JobStatCode)l2->value.i), - edg_wll_StatToString((edg_wll_JobStatCode)l2->value2.i)); - else - asprintf(&buf, "%i", edg_wll_StatToString((edg_wll_JobStatCode)l2->value.i)); - GS(buf); - free(buf); - break; - case EDG_WLL_QUERY_ATTR_DONECODE: - case EDG_WLL_QUERY_ATTR_EXITCODE: - if (l2->op == EDG_WLL_QUERY_OP_WITHIN) - asprintf(&buf, "%i and %i", - l2->value.i, l2->value2.i); - else - asprintf(&buf, "%i", l2->value.i); - GS(buf); - free(buf); - break; - case EDG_WLL_QUERY_ATTR_EVENT_TYPE: - if (l2->op == EDG_WLL_QUERY_OP_WITHIN) - asprintf(&buf, "%s and %s", - edg_wll_EventToString((edg_wll_EventCode)l2->value.i), - edg_wll_EventToString((edg_wll_EventCode)l2->value2.i)); - else - asprintf(&buf, "%s", - edg_wll_EventToString((edg_wll_EventCode)l2->value.i)); - GS(buf); - free(buf); - break; - case EDG_WLL_QUERY_ATTR_USERTAG: - GS(l2->attr_id.tag); - break; - case EDG_WLL_QUERY_ATTR_TIME: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - buf = strdup(ctime(&(l2->value.t.tv_sec))); - buf[strlen(buf)-1] = 0; // cut out '\n' - if (l2->op == EDG_WLL_QUERY_OP_WITHIN){ - char *buf_ptr = buf; - asprintf(&buf, "%s and %s", buf_ptr, ctime(&(l2->value2.t.tv_sec))); - free(buf_ptr); - buf[strlen(buf)-1] = 0; - GS(buf); - } - else - GS(buf); - free(buf); - break; - case EDG_WLL_QUERY_ATTR_LEVEL: - if (l2->op == EDG_WLL_QUERY_OP_WITHIN) - asprintf(&buf, "%i and %i", - l2->value.i, l2->value2.i); - else - asprintf(&buf, "%i", l2->value.i); - GS(buf); - free(buf); - break; - case EDG_WLL_QUERY_ATTR_SOURCE: - buf = edg_wll_SourceToString(l2->value.i); - GS(buf); - free(buf); - if (l2->op == EDG_WLL_QUERY_OP_WITHIN){ - GS("and"); - buf = edg_wll_SourceToString(l2->value2.i); - GS(buf); - free(buf); - } - break; - case EDG_WLL_QUERY_ATTR_CHKPT_TAG: - //XXX: what kind of data is it? - break; - case EDG_WLL_QUERY_ATTR_RESUBMITTED: - asprintf(&buf, "%i", l2->value.i); - GS(buf); - free(buf); - break; - default: - assert(! "Unknown condition attribute!"); - break; - } - if (! oneline) - GS("\n"); - } - if (oneline) - GS(")"); - } - - *output = pomA; - - return 0; -} - diff --git a/org.glite.lb.server/src/cond_dump.h b/org.glite.lb.server/src/cond_dump.h deleted file mode 100644 index 7a31251..0000000 --- a/org.glite.lb.server/src/cond_dump.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef GLITE_NOPTIF_DUMP_H -#define GLITE_NOTIF_DUMP_H - -#include "lb_proto.h" - -int edg_wll_Condition_Dump(notifInfo *ni, char **output, int oneline); - -#endif /* GLITE_NOTIF_DUMP */ - diff --git a/org.glite.lb.server/src/db_calls.c b/org.glite.lb.server/src/db_calls.c deleted file mode 100644 index 4ef3e96..0000000 --- a/org.glite.lb.server/src/db_calls.c +++ /dev/null @@ -1,92 +0,0 @@ -#ident "$Header: " - -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lbu/trio.h" - -#include "glite/lb/context-int.h" - -#include "db_calls.h" -#include "db_supp.h" - -/** Returns bitmask of job membership in common server/proxy database - */ -int edg_wll_jobMembership(edg_wll_Context ctx, glite_jobid_const_t job) -{ - char *dbjob; - char *stmt = NULL; - glite_lbu_Statement q; - int ret, result = -1; - char *res[2] = { NULL, NULL}; - - edg_wll_ResetError(ctx); - - dbjob = edg_wlc_JobIdGetUnique(job); - - trio_asprintf(&stmt,"select proxy,server from jobs where jobid = '%|Ss' for update",dbjob); - ret = edg_wll_ExecSQL(ctx,stmt,&q); - if (ret <= 0) { - if (ret == 0) { - fprintf(stderr,"%s: no such job\n",dbjob); - edg_wll_SetError(ctx,ENOENT,dbjob); - } - goto clean; - } - free(stmt); stmt = NULL; - - if ((ret = edg_wll_FetchRow(ctx,q,sizeof(res)/sizeof(res[0]),NULL,res)) > 0) { - result = 0; - if (strcmp(res[0],"0")) result += DB_PROXY_JOB; - if (strcmp(res[1],"0")) result += DB_SERVER_JOB; - } - else { - fprintf(stderr,"Error retrieving proxy&server fields of jobs table. Missing column?\n"); - edg_wll_SetError(ctx,ENOENT,dbjob); - } - -clean: - glite_lbu_FreeStmt(&q); - - free(res[0]); free(res[1]); - free(dbjob); - free(stmt); - return(result); -} - - -/* just lock one row corresponding to job in table jobs - * lock_mode: 0 = lock in share mode / 1 = for update - */ -int edg_wll_LockJobRow(edg_wll_Context ctx, const char *job, int lock_mode) -{ - char *stmt = NULL; - glite_lbu_Statement sh; - int nr; - - - edg_wll_ResetError(ctx); - - if (lock_mode) - trio_asprintf(&stmt, "select * from jobs where jobid='%|Ss' for update", job); - else - trio_asprintf(&stmt, "select * from jobs where jobid='%|Ss' lock in share mode", job); - - if ((nr = edg_wll_ExecSQL(ctx,stmt,&sh)) < 0) goto cleanup; - if (nr == 0) { - char *err; - - asprintf(&err,"jobid='%s' not registered in DB", job); - edg_wll_SetError(ctx,ENOENT, err); - free(err); - goto cleanup; - } - -cleanup: - if (sh) glite_lbu_FreeStmt(&sh); - free(stmt); stmt = NULL; - - return edg_wll_Error(ctx, NULL, NULL); -} - diff --git a/org.glite.lb.server/src/db_calls.h b/org.glite.lb.server/src/db_calls.h deleted file mode 100644 index ff4910d..0000000 --- a/org.glite.lb.server/src/db_calls.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GLITE_LB_LB_CALLS_H -#define GLITE_LB_LB_CALLS_H - -#ident "$Header:" - -#define DB_PROXY_JOB 1 -#define DB_SERVER_JOB 2 - -int edg_wll_jobMembership(edg_wll_Context ctx, glite_jobid_const_t job); - -#define edg_wll_LockJobRowInShareMode(X,Y) edg_wll_LockJobRow(X,Y,0) -#define edg_wll_LockJobRowForUpdate(X,Y) edg_wll_LockJobRow(X,Y,1) -int edg_wll_LockJobRow(edg_wll_Context ctx, const char *job, int lock_mode); - - -#endif /* GLITE_LB_LB_CALLS_H */ diff --git a/org.glite.lb.server/src/db_store.c b/org.glite.lb.server/src/db_store.c deleted file mode 100644 index dde7ce4..0000000 --- a/org.glite.lb.server/src/db_store.c +++ /dev/null @@ -1,307 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include - -#include "glite/lbu/maildir.h" -#include "glite/lb/context-int.h" -#include "glite/lb/events.h" -#include "glite/lb/events_parse.h" -#include "purge.h" -#include "store.h" -#include "il_lbproxy.h" -#include "jobstat.h" -#include "db_supp.h" - -#ifdef LB_PERF -#include "glite/lb/lb_perftest.h" -#include "srv_perf.h" -#endif - - -extern int unset_proxy_flag(edg_wll_Context, edg_wlc_JobId); -extern int edg_wll_NotifMatch(edg_wll_Context, const edg_wll_JobStat *, const edg_wll_JobStat *); -extern int enable_lcas; - - -static int db_store_finalize(edg_wll_Context ctx, char *event, edg_wll_Event *ev, edg_wll_JobStat *oldstat, edg_wll_JobStat *newstat, int reg_to_JP); - - -int -db_store(edg_wll_Context ctx, char *event) -{ - edg_wll_Event *ev = NULL; - int seq, reg_to_JP = 0, local_job; - edg_wll_JobStat newstat; - edg_wll_JobStat oldstat; - - - edg_wll_ResetError(ctx); - memset(&newstat,0,sizeof newstat); - memset(&oldstat,0,sizeof oldstat); - - if(edg_wll_ParseEvent(ctx, event, &ev)) goto err; - - local_job = is_job_local(ctx, ev->any.jobId); - - if (enable_lcas && check_store_authz(ctx, ev) != 0) - 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 - - do { - if (edg_wll_Transaction(ctx)) goto err; - - if (store_job_server_proxy(ctx, ev, ®_to_JP)) goto rollback; - - /* events logged to proxy and server (DIRECT flag) may be ignored on proxy - * if jobid prefix hostname matches server hostname -> they will - * sooner or later arrive to server too and are stored in common DB - */ - if (ctx->isProxy && local_job && (ev->any.priority & EDG_WLL_LOGFLAG_DIRECT)) { - goto commit; - } - - if (edg_wll_StoreEvent(ctx, ev, event, &seq)) goto rollback; - - if ( ev->any.type == EDG_WLL_EVENT_CHANGEACL ) { - if (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)) goto rollback; - - } - else { -#ifdef LB_PERF - if(sink_mode == GLITE_LB_SINK_STATE) { - glite_wll_perftest_consumeEvent(ev); - goto commit; - } -#endif - - if ( newstat.state ) { /* prevent memleaks in case of transaction retry */ - edg_wll_FreeStatus(&newstat); - newstat.state = EDG_WLL_JOB_UNDEF; - } - if (edg_wll_StepIntState(ctx,ev->any.jobId, ev, seq, &oldstat, &newstat)) goto rollback; - - if (newstat.remove_from_proxy) - if (edg_wll_PurgeServerProxy(ctx, ev->any.jobId)) goto rollback; - } - - - if (ev->any.type == EDG_WLL_EVENT_REGJOB && - (ev->regJob.jobtype == EDG_WLL_REGJOB_DAG || - ev->regJob.jobtype == EDG_WLL_REGJOB_PARTITIONED || - ev->regJob.jobtype == EDG_WLL_REGJOB_COLLECTION) && - ev->regJob.nsubjobs > 0) { - - if (register_subjobs_embryonic(ctx,&ev->regJob)) goto rollback; - reg_to_JP |= REG_SUBJOBS_TO_JP; - } - -commit: -rollback:; - } while (edg_wll_TransNeedRetry(ctx)); - - if (edg_wll_Error(ctx, NULL, NULL)) goto err; - - - db_store_finalize(ctx, event, ev, &oldstat, &newstat, reg_to_JP); - - -err: - if(ev) { edg_wll_FreeEvent(ev); free(ev); } - if ( newstat.state ) edg_wll_FreeStatus(&newstat); - if ( oldstat.state ) edg_wll_FreeStatus(&oldstat); - - return edg_wll_Error(ctx,NULL,NULL); -} - - - -/* Called only when CollectionStateEvent generated */ -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_JobStat oldstat; - - - edg_wll_ResetError(ctx); - memset(&newstat,0,sizeof newstat); - memset(&oldstat,0,sizeof oldstat); - - /* Transaction opened from db_store */ - -#ifdef LB_PERF - if (sink_mode == GLITE_LB_SINK_STORE) { - glite_wll_perftest_consumeEvent(ev); - edg_wll_FreeEvent(ev); - free(ev); - return 0; - } -#endif - - - assert(ev->any.user); - - // locked from edg_wll_LoadIntState() <- load_parent_intJobStat() <- update_parent_status() - // XXX: maybe it can be locked InShareMode there and re-locked ForUpdate here? - - if(edg_wll_StoreEvent(ctx, ev, NULL, &seq)) - goto err; - -#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, &oldstat, ctx->isProxy? NULL: &newstat); - - if (err) goto err; - - if ( ctx->isProxy ) { - event = edg_wll_UnparseEvent(ctx, ev); - assert(event); - } - - db_store_finalize(ctx, event, ev, &oldstat, &newstat, 0); - -err: - - free(event); - if ( newstat.state ) edg_wll_FreeStatus(&newstat); - if ( oldstat.state ) edg_wll_FreeStatus(&oldstat); - - return edg_wll_Error(ctx,NULL,NULL); -} - - -/* Send regitration to JP - */ -static int register_to_JP(edg_wll_Context ctx, edg_wlc_JobId jobid, char *user) -{ - char *jids, *msg; - - - if ( !(jids = edg_wlc_JobIdUnparse(jobid)) ) { - return edg_wll_SetError(ctx, errno, "Can't unparse jobid when registering to JP"); - } - if ( !(msg = calloc(strlen(jids)+strlen(user)+2, sizeof(char) )) ) { - free(jids); - return edg_wll_SetError(ctx, errno, "Can't allocate buffer when registering to JP"); - } - strcat(msg, jids); - free(jids); - strcat(msg, "\n"); - strcat(msg, user); - if ( glite_lbu_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); -} - - -static int register_subjobs_to_JP(edg_wll_Context ctx, edg_wll_Event *ev) -{ - edg_wlc_JobId *subjobs = NULL; - int i = 0, j; - - - if (edg_wll_GenerateSubjobIds(ctx, ev->regJob.jobId, - ev->regJob.nsubjobs, ev->regJob.seed, &subjobs)) - goto err; - - for (i=0; iregJob.nsubjobs; i++) { - if (register_to_JP(ctx, subjobs[i], ev->any.user)) - goto err; - } - -err: - for (j=i; jregJob.nsubjobs; j++) edg_wlc_JobIdFree(subjobs[j]); - free(subjobs); - - return edg_wll_Error(ctx,NULL,NULL); -} - - -static int forward_event_to_server(edg_wll_Context ctx, char *event, edg_wll_Event *ev, int local_job) -{ - if ( ctx->isProxy ) { - /* - * send event to the proper BK server - * event with priority flag EDG_WLL_LOGFLAG_DIRECT (typically RegJob) is not sent - */ - - /* XXX: ending here may break the backward compatibility */ - if (!(ev->any.priority & EDG_WLL_LOGFLAG_PROXY)) { - edg_wll_UpdateError(ctx, 0, "db_actual_store() WARNING: the event is not PROXY"); - //return edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "db_actual_store() ERROR: the event is not PROXY"); - } - - if (!(ev->any.priority & (EDG_WLL_LOGFLAG_DIRECT | EDG_WLL_LOGFLAG_INTERNAL)) && !local_job) { - if (edg_wll_EventSendProxy(ctx, ev->any.jobId, event) ) { - return edg_wll_SetError(ctx, EDG_WLL_IL_PROTO, "edg_wll_EventSendProxy() error."); - } - } - } - - return edg_wll_Error(ctx,NULL,NULL); -} - - -static int db_store_finalize(edg_wll_Context ctx, char *event, edg_wll_Event *ev, edg_wll_JobStat *oldstat, edg_wll_JobStat *newstat, int reg_to_JP) -{ - int local_job = is_job_local(ctx, ev->any.jobId); - - -#ifdef LB_PERF - if( sink_mode == GLITE_LB_SINK_SEND ) { - glite_wll_perftest_consumeEvent(ev); - return edg_wll_Error(ctx,NULL,NULL); - } -#endif - - if (ctx->jpreg_dir) { - if (reg_to_JP & REG_JOB_TO_JP) - if (register_to_JP(ctx,ev->any.jobId,ev->any.user)) goto err; - if (reg_to_JP & REG_SUBJOBS_TO_JP) - if (register_subjobs_to_JP(ctx,ev)) goto err; - } - - if (forward_event_to_server(ctx, event, ev, local_job)) goto err; - - if (newstat->state) { - if ( ctx->isProxy ) { - if ((ev->any.priority & EDG_WLL_LOGFLAG_DIRECT) || local_job) - /* event will not arrive to server, only flag was set */ - /* check whether some pending notifications are not triggered */ - edg_wll_NotifMatch(ctx, oldstat, newstat); - } - else { - edg_wll_NotifMatch(ctx, oldstat, newstat); - } - } - -err: - return edg_wll_Error(ctx,NULL,NULL); -} diff --git a/org.glite.lb.server/src/db_supp.c b/org.glite.lb.server/src/db_supp.c deleted file mode 100644 index 3577037..0000000 --- a/org.glite.lb.server/src/db_supp.c +++ /dev/null @@ -1,131 +0,0 @@ -#include -#include -#include -#include -#include - - -#include "glite/lbu/db.h" -#include "glite/lb/context-int.h" - -extern int debug; // declared and set in bkserver.c - - -int edg_wll_SetErrorDB(edg_wll_Context ctx) { - int code; - char *ed; - - if (ctx->dbctx) { - code = glite_lbu_DBError(ctx->dbctx, NULL, &ed); - if (code == EDEADLOCK) code = EDG_WLL_ERROR_DB_TRANS_DEADLOCK; - if (code == ERESTART) code = EDG_WLL_ERROR_DB_LOST_CONNECTION; - edg_wll_SetError(ctx, code, ed); - free(ed); - } else { - code = EINVAL; - edg_wll_SetError(ctx, EINVAL, "DB context isn't created"); - } - - return code; -} - - -int edg_wll_ExecSQL(edg_wll_Context ctx, const char *cmd, glite_lbu_Statement *stmt) { - int retval; - - if ((retval = glite_lbu_ExecSQL(ctx->dbctx, cmd, stmt)) < 0) edg_wll_SetErrorDB(ctx); - return retval; -} - - -int edg_wll_FetchRow(edg_wll_Context ctx, glite_lbu_Statement stmt, unsigned int n, unsigned long *lengths, char **results) { - int retval; - - if ((retval = glite_lbu_FetchRow(stmt, n, lengths, results)) < 0) edg_wll_SetErrorDB(ctx); - return retval; -} - -int edg_wll_bufferedInsertInit(edg_wll_Context ctx, glite_lbu_bufInsert *bi, const char *table_name, long size_limit, long record_limit, const char *columns) { - int retval; - - if ((retval = glite_lbu_bufferedInsertInit(ctx->dbctx, bi, table_name, size_limit, record_limit, columns)) != 0) edg_wll_SetErrorDB(ctx); - return retval; -} - -int edg_wll_bufferedInsert(edg_wll_Context ctx, glite_lbu_bufInsert bi, const char *row) { - int retval; - - if ((retval = glite_lbu_bufferedInsert(bi, row)) != 0) edg_wll_SetErrorDB(ctx); - return retval; -} - -int edg_wll_bufferedInsertClose(edg_wll_Context ctx, glite_lbu_bufInsert bi) { - int retval; - - if ((retval = glite_lbu_bufferedInsertClose(bi)) != 0) edg_wll_SetErrorDB(ctx); - return retval; -} - -int edg_wll_Transaction(edg_wll_Context ctx) { - int retval; - - if ((retval = glite_lbu_Transaction(ctx->dbctx)) != 0) edg_wll_SetErrorDB(ctx); - -// printf("edg_wll_Transaction(%d)\n", retval); - return retval; -} - -int edg_wll_Commit(edg_wll_Context ctx) { - int retval; - - if ((retval = glite_lbu_Commit(ctx->dbctx)) != 0) edg_wll_SetErrorDB(ctx); -// printf("edg_wll_Commit(%d)\n", retval); - return retval; -} - -int edg_wll_Rollback(edg_wll_Context ctx) { - int retval; - - if ((retval = glite_lbu_Rollback(ctx->dbctx)) != 0) edg_wll_SetErrorDB(ctx); -// printf("edg_wll_Rollback(%d)\n", retval); - return retval; -} - -int edg_wll_TransNeedRetry(edg_wll_Context ctx) { - int ret; - char *errd; - - ret = edg_wll_Error(ctx,NULL,NULL); - - if (ret == EDG_WLL_ERROR_DB_TRANS_DEADLOCK) { - if (debug) - printf("[%d]: DB deadlock detected. Rolling back transaction and retrying... \n",getpid()); - else - syslog(LOG_INFO,"[%d]: DB deadlock detected. Rolling back transaction and retrying... \n",getpid()); - - edg_wll_ResetError(ctx); - return !edg_wll_Rollback(ctx); - } - if (ret == EDG_WLL_ERROR_DB_LOST_CONNECTION) { - if (debug) - printf("[%d]: Lost connection to DB. " - "Rolling back transaction and retrying... \n",getpid()); - else - syslog(LOG_INFO,"[%d]: Lost connection to DB. " - "Rolling back transaction and retrying... \n",getpid()); - - edg_wll_ResetError(ctx); - return !edg_wll_Rollback(ctx); - } else if (ret==0) { - edg_wll_Commit(ctx); /* errors propagated further */ - return 0; - } else { - edg_wll_Error(ctx, NULL, &errd); - edg_wll_Rollback(ctx); - edg_wll_SetError(ctx, ret, errd); - free(errd); - return 0; - } -} - - diff --git a/org.glite.lb.server/src/db_supp.h b/org.glite.lb.server/src/db_supp.h deleted file mode 100644 index 2abf777..0000000 --- a/org.glite.lb.server/src/db_supp.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef EDG_WLL_DB_SUPP_H -#define EDG_WLL_DB_SUPP_H - -#ident "$Header:" - -#include "glite/lbu/db.h" - -#define DEFAULTCS "lbserver/@localhost:lbserver20" - -/** - * Set the current database error. - */ -int edg_wll_SetErrorDB(edg_wll_Context ctx); - -int edg_wll_ExecSQL(edg_wll_Context ctx, const char *cmd, glite_lbu_Statement *stmt); -int edg_wll_FetchRow(edg_wll_Context ctx, glite_lbu_Statement stmt, unsigned int n, unsigned long *lengths, char **results); - -int edg_wll_bufferedInsertInit(edg_wll_Context ctx, glite_lbu_bufInsert *bi, const char *table_name, long size_limit, long record_limit, const char *columns); -int edg_wll_bufferedInsert(edg_wll_Context ctx, glite_lbu_bufInsert bi, const char *row); -int edg_wll_bufferedInsertClose(edg_wll_Context ctx, glite_lbu_bufInsert bi); - -int edg_wll_Transaction(edg_wll_Context ctx); -int edg_wll_Commit(edg_wll_Context ctx); -int edg_wll_Rollback(edg_wll_Context ctx); -int edg_wll_TransNeedRetry(edg_wll_Context ctx); - -#endif diff --git a/org.glite.lb.server/src/dump.c b/org.glite.lb.server/src/dump.c deleted file mode 100644 index 1b6771e..0000000 --- a/org.glite.lb.server/src/dump.c +++ /dev/null @@ -1,198 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lbu/trio.h" -#include "glite/jobid/cjobid.h" - -#include "glite/lb/context-int.h" -#include "glite/lb/events_parse.h" -#include "glite/lb/ulm_parse.h" - -#include "query.h" -#include "get_events.h" -#include "server_state.h" -#include "purge.h" -#include "db_supp.h" -#include "lb_proto.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_DumpEventsServer(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; - glite_lbu_Statement 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); - } - - glite_lbu_TimeToDB(from, &from_s); - glite_lbu_TimeToDB(to, &to_s); - - 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_ExecSQL(ctx,stmt,&q) < 0) goto clean; - - while ((ret = edg_wll_FetchRow(ctx,q,sizeof(res)/sizeof(res[0]),NULL,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; ifrom = from; - result->to = to; - - edg_wll_CreateDumpFileFromTmp(ctx, tmpfname, &(result->server_file)); - unlink(tmpfname); - -clean: - edg_wll_FreeEvent(&e); - glite_lbu_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 = glite_lbu_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; - - glite_lbu_TimeToDB(t, &s); - s[strlen(s) - 1] = '\0'; - *ptr = s; - - return s + 1; -} diff --git a/org.glite.lb.server/src/get_events.c.T b/org.glite.lb.server/src/get_events.c.T deleted file mode 100644 index c7c245e..0000000 --- a/org.glite.lb.server/src/get_events.c.T +++ /dev/null @@ -1,182 +0,0 @@ -#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 -#include -#include -#include -#include -#include - -#include "glite/lbu/trio.h" -#include "get_events.h" -#include "glite/lb/context-int.h" -#include "glite/lb/events_parse.h" -#include "db_supp.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]; - glite_lbu_Statement sh; - int ret,t; - const char *tables[] = { "short_fields","long_fields" }; - edg_wll_Event *f; - - edg_wll_ResetError(ctx); - - trio_asprintf(&q, "select ulm from events_flesh where jobid = '%|Ss' and event = %d", jobid, n); - if ((ret=edg_wll_ExecSQL(ctx,q,&sh)) < 0) goto cleanup; - if (edg_wll_FetchRow(ctx,sh,1,NULL,&nameval[0]) == 1) { - //fprintf(stderr, "got ulm: '%s'\n", nameval[0]); - // nasty ;-) - edg_wll_ParseEvent(ctx,nameval[0],&f); - free(nameval[0]); - - f->any.arrived = e->any.arrived; - edg_wll_FreeEvent(e); - - memcpy(e, f, sizeof *e); - free(f); - ret=edg_wll_CheckEvent(ctx,e); - } else ret = ENOENT; - free(q); q = NULL; - glite_lbu_FreeStmt(&sh); - - // old way keeped for compatibility/slow migration - if (ret != 0) { - 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_ExecSQL(ctx,q,&sh)) < 0) goto cleanup; - - while ((ret=edg_wll_FetchRow(ctx,sh,sizeof(nameval)/sizeof(nameval[0]),NULL,nameval)) > 0) { - assert(ret == 2); - 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; - glite_lbu_FreeStmt(&sh); - free(q); q=NULL; - } - ret=edg_wll_CheckEvent(ctx,e); - } - -cleanup: - if (sh) glite_lbu_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; -} diff --git a/org.glite.lb.server/src/get_events.h b/org.glite.lb.server/src/get_events.h deleted file mode 100644 index a45ac7f..0000000 --- a/org.glite.lb.server/src/get_events.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GLITE_LB_GET_EVENTS_H -#define GLITE_LB_GET_EVENTS_H -#ident "$Header$" - -#include "glite/lb/context.h" -#include "glite/lb/events.h" -#include "glite/lb/query_rec.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 - -#endif /* GLITE_LB_GET_EVENTS_H */ diff --git a/org.glite.lb.server/src/il_lbproxy.c b/org.glite.lb.server/src/il_lbproxy.c deleted file mode 100644 index 29ab93b..0000000 --- a/org.glite.lb.server/src/il_lbproxy.c +++ /dev/null @@ -1,82 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#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, - glite_jobid_const_t 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); - } -} diff --git a/org.glite.lb.server/src/il_lbproxy.h b/org.glite.lb.server/src/il_lbproxy.h deleted file mode 100644 index 7399567..0000000 --- a/org.glite.lb.server/src/il_lbproxy.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef GLITE_LB_IL_LBPROXY_H -#define GLITE_LB_IL_LBPROXY_H - -#include "glite/lb/context.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, glite_jobid_const_t jobid, const char *event); - -#ifdef __cplusplus -} -#endif - -#endif /* GLITE_LB_IL_LBPROXY_H */ diff --git a/org.glite.lb.server/src/il_notification.c b/org.glite.lb.server/src/il_notification.c deleted file mode 100644 index a9708db..0000000 --- a/org.glite.lb.server/src/il_notification.c +++ /dev/null @@ -1,218 +0,0 @@ -#ident "$Header$" -/** - * il_notification.c - * - implementation of IL API calls for notifications - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lbu/escape.h" -#include "glite/lb/context-int.h" -#include "glite/lb/notifid.h" -#include "glite/lb/events_parse.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" -#define NOTIF_TIMEOUT 1 - -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, - int expires, - 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); - - event->notification.expires = expires; - - 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, - int expires, - const char *notif_data) -{ - struct timeval timeout = {NOTIF_TIMEOUT, 0}; - int ret; - long filepos; - char *ulm_data, - *reg_id_s, - *event_file; - - if((ret=notif_create_ulm(context, - reg_id, - host, - port, - owner, - expires, - 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, - int flags, - int expires, - const edg_wll_JobStat notif_job_stat) -{ - int ret=0; - char *xml_data, *xml_esc_data=NULL; - edg_wll_JobStat stat = notif_job_stat; - - - if (flags == 0) { - stat.jdl = NULL; - stat.matched_jdl = NULL; - stat.condor_jdl = NULL; - stat.rsl = NULL; - } - - if(edg_wll_JobStatusToXML(context, stat, &xml_data)) - goto out; - - if((xml_esc_data = glite_lbu_EscapeXML(xml_data)) == NULL) { - edg_wll_SetError(context, ret=ENOMEM, "glite_lbu_EscapeXML()"); - goto out; - } - - if ((ret=edg_wll_NotifSend(context, reg_id, host, port, owner, expires, xml_esc_data))) { - char *ed = NULL, *et = NULL; - - if(ret) edg_wll_UpdateError(context, ret, "edg_wll_NotifJobStatus()"); - edg_wll_Error(context,&et,&ed); - fprintf(stderr,"%s - %s\n", ed, et); - syslog(LOG_INFO,"%s - %s\n", ed, et); - edg_wll_ResetError(context); - free(et); - free(ed); - } - -out: - if(xml_data) free(xml_data); - if(xml_esc_data) free(xml_esc_data); - return(edg_wll_Error(context,NULL,NULL)); -} - - -int -edg_wll_NotifChangeIL(edg_wll_Context context, - edg_wll_NotifId reg_id, - const char *host, - int port, - int expires) -{ - return(edg_wll_NotifSend(context, reg_id, host, port, "", expires, "")); -} - - -int -edg_wll_NotifCancelRegId(edg_wll_Context context, - edg_wll_NotifId reg_id) -{ -/* XXX: Jan 1 1970 00:00:01 -- quite sure to make it expire immediately */ - return(edg_wll_NotifSend(context, reg_id, NULL, 0, "", 1, "")); -} - diff --git a/org.glite.lb.server/src/il_notification.h b/org.glite.lb.server/src/il_notification.h deleted file mode 100644 index 45b396e..0000000 --- a/org.glite.lb.server/src/il_notification.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef GLITE_LB_IL_NOTIFICATION_H -#define GLITE_LB_IL_NOTIFICATION_H - -#ident "$Header$" - -/* needed for the edg_wll_NotifId */ -#include "glite/lb/notifid.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, - int expires, - 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 flags verbosity of returned status - * \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, - int flags, - int expires, - 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_NotifChangeIL(edg_wll_Context context, - edg_wll_NotifId reg_id, - const char *host, - int port, - int expires); - -/** 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 /* GLITE_LB_IL_NOTIFICATION_H */ diff --git a/org.glite.lb.server/src/index.c.T b/org.glite.lb.server/src/index.c.T deleted file mode 100644 index de8a715..0000000 --- a/org.glite.lb.server/src/index.c.T +++ /dev/null @@ -1,435 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "glite/lb/context-int.h" -#include "glite/lbu/trio.h" -#include "db_supp.h" -#include "index.h" - -extern int debug; - -#define const_len(c) (sizeof((c))-1) - -static int parse_indices(edg_wll_Context ctx,char **keys,char ***column_names,const char **built_in_indices,edg_wll_QueryRec *** index_out,char ***keys_out); - -int edg_wll_QueryJobIndices(edg_wll_Context ctx,edg_wll_QueryRec *** index_out,char ***keys_out) -{ - static const char *built_in_indices[] = { - "PRIMARY", - "parent_job", - NULL - }; - char **keys = NULL; - char ***column_names = NULL; - - if (glite_lbu_QueryIndices(ctx->dbctx, "states", &keys, &column_names) != 0) { - edg_wll_SetErrorDB(ctx); - return EIO; - } - - if (!keys) { - *index_out = NULL; - if (keys_out) *keys_out = NULL; - return edg_wll_ResetError(ctx); - } - -/* XXX: keys are passed up or freed, column_names are freed there */ - if (parse_indices(ctx,keys,column_names,built_in_indices,index_out,keys_out)) - return edg_wll_Error(ctx,NULL,NULL); - else return edg_wll_ResetError(ctx); - -} - -int edg_wll_QueryNotifIndices(edg_wll_Context ctx,edg_wll_QueryRec *** index_out,char ***keys_out) -{ - static const char *built_in_indices[] = { - "PRIMARY", - NULL - }; - char **keys = NULL; - char ***column_names = NULL; - - if (glite_lbu_QueryIndices(ctx->dbctx, "notif_registrations", &keys, &column_names) != 0) { - edg_wll_SetErrorDB(ctx); - return EIO; - } - - if (!keys) { - *index_out = NULL; - if (keys_out) *keys_out = NULL; - return edg_wll_ResetError(ctx); - } - -/* XXX: keys are passed up or freed, column_names are freed there */ - if (parse_indices(ctx,keys,column_names,built_in_indices,index_out,keys_out)) - return edg_wll_Error(ctx,NULL,NULL); - else return edg_wll_ResetError(ctx); - -} - -/* TODO: - - better error recovery (skip unrecognised indices etc.) - - leaks memory on errors -*/ - -static int parse_indices(edg_wll_Context ctx,char **keys,char ***column_names,const char **built_in_indices,edg_wll_QueryRec *** index_out,char ***keys_out) -{ - - edg_wll_QueryRec **idx = NULL; - - int *cols = NULL; - - int i, j; - int nkeys = 0; - - - - for (i = 0; keys[i]; i++) { - // skip builtin indices - for (j = 0; built_in_indices[j]; j++) { - if (strcasecmp(keys[i], built_in_indices[j]) == 0) - goto next_index; - } - - cols = realloc(cols,(nkeys+1) * sizeof cols[0]); - cols[nkeys] = 0; - idx = realloc(idx,(nkeys+2) * sizeof idx[0]); - idx[nkeys] = idx[nkeys+1] = NULL; - if (keys_out) { - *keys_out = realloc(*keys_out, (nkeys + 2) * sizeof(char *)); - (*keys_out)[nkeys] = strdup(keys[i]); - (*keys_out)[nkeys + 1] = NULL; - } - - for (j = 0; column_names[i][j]; j++) { - if (cols[nkeys] <= j) { - cols[nkeys] = j+1; - idx[nkeys] = realloc(idx[nkeys],(j+2)*sizeof idx[nkeys][0]); - memset(&idx[nkeys][j+1],0,sizeof idx[nkeys][0]); - } - - if (edg_wll_ColumnToQueryRec(column_names[i][j],&idx[nkeys][j])) { - int code; - char *ed; - - asprintf(&ed, "%s(%s): unsupported column", keys[i], column_names[i][j]); - code = edg_wll_SetError(ctx, EINVAL, ed); - free(ed); - return code; - } -#warning: TODO: needed Sub_part in value??? -// else idx[nkeys][j].value.i = atoi(showcol[Sub_part]); - } - nkeys++; -next_index: - for (j = 0; column_names[i][j]; j++) free(column_names[i][j]); - free(column_names[i]); - column_names[i] = NULL; - free(keys[i]); - keys[i] = NULL; - - // just for escaping from nested cycles - ; /* prevent compiler to complain */ - } - free(column_names); - free(keys); - free(cols); - *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_JDL_ATTR: - 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 char *to_sql_string(edg_wll_JobStat const *stat,int offset) -{ - char *out = NULL, - *in = *((char **) (((char *) stat) + offset)); - - if (in) trio_asprintf(&out,"'%|Ss'",in); - return out; -} - -static char *to_sql_timeval(edg_wll_JobStat const *stat,int offset) -{ - char *out; - glite_lbu_TimeToDB( ((struct timeval *) (((char *) stat) + offset))->tv_sec, &out ); - return out; -} - -static edg_wll_JobStat fakestat; - -static struct { - const char *name; - edg_wll_QueryAttr attr; - int offset; - char * (*to_sql)(edg_wll_JobStat const *,int); -} std_attrs[] = -{ -@@@{ - for my $n ($status->getAllFieldsOrdered) { - my $f = selectField $status $n; - next unless $f->{index}; - my $u = uc $n; - gen "\t{ \"$n\", EDG_WLL_QUERY_ATTR_$u, ((char *) \&fakestat.$n) - ((char *) \&fakestat),\&to_sql_$f->{type} },\n"; - } -@@@} - { NULL, }, -}; - -/* TODO: use in queries */ -char *edg_wll_StatToSQL(edg_wll_JobStat const *stat,edg_wll_QueryAttr attr) -{ - int i; - - for (i=0; std_attrs[i].attr && std_attrs[i].attr != attr; i++); - - return std_attrs[i].attr ? std_attrs[i].to_sql(stat,std_attrs[i].offset) : (char *) -1; -} - -char *edg_wll_JDLStatToSQL(edg_wll_JobStat const *stat,edg_wll_QueryRec col_rec) -{ - struct cclassad *ad = NULL; - char *extr_val = NULL; - char *extr_val_apostrophed = NULL; - - ad = cclassad_create(stat->jdl); - if (ad) { - if (!cclassad_evaluate_to_string(ad, col_rec.attr_id.tag, &extr_val)) { // Extract attribute value - extr_val = NULL; - cclassad_delete(ad); - } - } - - if (extr_val) { - trio_asprintf(&extr_val_apostrophed,"'%|Ss'", extr_val); - free(extr_val); - } - - return extr_val_apostrophed; -} - -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; - } - else if (strncasecmp(col_name,JDL_PREFIX,const_len(JDL_PREFIX)) == 0) { - rec->attr = EDG_WLL_QUERY_ATTR_JDL_ATTR; - rec->attr_id.tag = strdup(col_name+const_len(JDL_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 if (rec->attr == EDG_WLL_QUERY_ATTR_JDL_ATTR) { - strcpy(col,JDL_PREFIX); - strcat(col,rec->attr_id.tag); - } - 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); -} - - -/* - * 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, - edg_wll_JobStat *stat, - int is_insert, - char **names_out, - char **values_out) -{ - int i; - char *names, *values; - char *data; - char *tmp; - char *tmpval; - 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->owner) { - tmpval = edg_wll_gss_normalize_subj(stat->owner, 0); - trio_asprintf(&data, "'%|Ss'", tmpval); - free(tmpval); - } else data = strdup("''"); - break; - case EDG_WLL_QUERY_ATTR_LOCATION: - if (stat->location) - trio_asprintf(&data, "'%|Ss'", stat->location); - else data = strdup("''"); - break; - case EDG_WLL_QUERY_ATTR_DESTINATION: - if (stat->destination) - trio_asprintf(&data, "'%|Ss'", stat->destination); - else data = strdup("''"); - break; - case EDG_WLL_QUERY_ATTR_DONECODE: - asprintf(&data, "%d", stat->done_code); - break; - case EDG_WLL_QUERY_ATTR_USERTAG: - if (stat->user_tags) { - int k; - for (k=0; stat->user_tags[k].tag && - strcmp(stat->user_tags[k].tag,job_index_cols[i].qrec.attr_id.tag); - k++); - if (stat->user_tags[k].tag != NULL) { - trio_asprintf(&data, "'%|Ss'", stat->user_tags[k].value); - } else data = strdup("''"); - } else data = strdup("''"); - break; - case EDG_WLL_QUERY_ATTR_TIME: - if (stat->stateEnterTimes) - glite_lbu_TimeToDB(stat->stateEnterTimes[job_index_cols[i].qrec.attr_id.state+1], &data); - else data = strdup("0"); - break; - case EDG_WLL_QUERY_ATTR_RESUBMITTED: - asprintf(&data, "%d", stat->resubmitted); - break; - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - glite_lbu_TimeToDB(stat->stateEnterTime.tv_sec, &data); - break; - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - glite_lbu_TimeToDB(stat->lastUpdateTime.tv_sec, &data); - break; - case EDG_WLL_QUERY_ATTR_JDL_ATTR: // This is not the correct way to handle jdl searches. - /* There's no way to index individual JDL attributes */ - if (stat->jdl) - trio_asprintf(&data, "'%|Ss'", stat->jdl); - else data = strdup("''"); - break; -/* case EDG_WLL_QUERY_ATTR_STATEENTERTIME: /// XXX: Which way of handling this is correct? - if (stat->stateEnterTime) - glite_lbu_TimeToDB(stat->stateEnterTime, &data); - else data = strdup("0"); - break; - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - if (stat->lastUpdateTime) - glite_lbu_TimeToDB(stat->lastUpdateTime, &data); - else data = strdup("0"); - 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); -} diff --git a/org.glite.lb.server/src/index_lex.l b/org.glite.lb.server/src/index_lex.l deleted file mode 100644 index fa552a1..0000000 --- a/org.glite.lb.server/src/index_lex.l +++ /dev/null @@ -1,47 +0,0 @@ -%{ -#ident "$Header$" - -#include - -#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; - diff --git a/org.glite.lb.server/src/index_parse.y b/org.glite.lb.server/src/index_parse.y deleted file mode 100644 index 50d74d9..0000000 --- a/org.glite.lb.server/src/index_parse.y +++ /dev/null @@ -1,242 +0,0 @@ -%{ -#ident "$Header$" - - -#include -#include -#include - -#include "glite/lb/context-int.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 string -%type int -%type job_index_elem -%type job_index job_index_elem_list -%type job_index_list job_indices; -%type 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"); -} - - diff --git a/org.glite.lb.server/src/jobstat.c b/org.glite.lb.server/src/jobstat.c deleted file mode 100644 index 5798301..0000000 --- a/org.glite.lb.server/src/jobstat.c +++ /dev/null @@ -1,1319 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lbu/trio.h" -#include "glite/lb/events.h" -#include "glite/lb/context-int.h" -#include "glite/lb/intjobstat.h" -#include "glite/lb/process_event.h" - -#include "get_events.h" -#include "store.h" -#include "index.h" -#include "jobstat.h" -#include "lb_authz.h" -#include "stats.h" -#include "db_supp.h" -#include "db_calls.h" - -#define DAG_ENABLE 1 - -#define DONT_LOCK 0 -#define LOCK 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 *); -static edg_wll_ErrorCode get_job_parent(edg_wll_Context ctx, glite_jobid_const_t job, glite_jobid_t *parent); - - -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_JobStatusServer( - edg_wll_Context ctx, - glite_jobid_const_t job, - int flags, - edg_wll_JobStat *stat) -{ - -/* Local variables */ - char *string_jobid = NULL; - char *md5_jobid = NULL; - - intJobStat jobstat; - intJobStat *ijsp; - int whole_cycle; - edg_wll_Acl acl = NULL; -#if DAG_ENABLE - char *stmt = NULL; -#endif - char *s_out; - intJobStat *js; - char *out[1], *out_stat[3]; - glite_lbu_Statement sh = NULL; - int num_sub, num_f, i, ii; - - - edg_wll_ResetError(ctx); - - memset(&jobstat, 0, sizeof(jobstat)); - 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); - - do { - whole_cycle = 0; - - if (edg_wll_Transaction(ctx)) goto rollback; - if (edg_wll_LockJobRowInShareMode(ctx, md5_jobid)) goto rollback; - - - if (!edg_wll_LoadIntState(ctx, job, DONT_LOCK, -1 /*all events*/, &ijsp)) { - memcpy(stat, &(ijsp->pub), sizeof(ijsp->pub)); - destroy_intJobStat_extension(ijsp); - free(ijsp); - } else { - if (edg_wll_intJobStatus(ctx, job, flags,&jobstat, js_enable_store, 0)) { - goto rollback; - } - memcpy(stat, &(jobstat.pub), sizeof(jobstat.pub)); - } - - if (edg_wll_GetACL(ctx, job, &acl)) goto rollback; - - /* authorization check */ - if ( !(ctx->noAuth) && - (!(ctx->peerName) || !edg_wll_gss_equal_subj(ctx->peerName, stat->owner))) { - if ((acl == NULL) || edg_wll_CheckACL(ctx, acl, EDG_WLL_CHANGEACL_READ)) { - if (acl) { - goto rollback; - } else { - edg_wll_SetError(ctx,EPERM, "not owner, no ACL is set"); - goto rollback; - } - } - } - - if (acl) { - stat->acl = strdup(acl->string); - edg_wll_FreeAcl(acl); - acl = NULL; - } - - 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 adding something here, add it also to edg_wll_NotifJobStatus() !! - } - - #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 version,int_status,jobid FROM states WHERE parent_job='%|Ss'", md5_jobid); - if (stmt != NULL) { - num_sub = edg_wll_ExecSQL(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_SetError(ctx, ENOMEM, "edg_wll_JobStatusServer() calloc children_states failed!"); - goto rollback; - } - while ((num_f = edg_wll_FetchRow(ctx, sh, sizeof(out_stat), NULL, out_stat)) == 3 - && i < num_sub) { - if (!strcmp(INTSTAT_VERSION,out_stat[0])) { - js = dec_intJobStat(out_stat[1], &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 - } - } - else { // recount state - glite_jobid_t subjob; - intJobStat js_real; - char *name; - int port; - - - js = &js_real; - glite_jobid_getServerParts(job, &name, &port); - if (glite_jobid_recreate(name, port, out_stat[2], &subjob)) { - goto rollback; - } - free(name); - - if (edg_wll_intJobStatus(ctx, subjob, flags, js, js_enable_store, 0)) { - goto rollback; - } - glite_jobid_free(subjob); - stat->children_states[i] = js->pub; - destroy_intJobStat_extension(js); - i++; // Careful, this value will also be used further - } - free(out_stat[0]); out_stat[0] = NULL; - free(out_stat[1]); out_stat[1] = NULL; - free(out_stat[2]); out_stat[2] = NULL; - } - if (num_f < 0) goto rollback; - - glite_lbu_FreeStmt(&sh); sh = NULL; - } - else goto rollback; - - free(stmt); stmt = NULL; - } else { - edg_wll_SetError(ctx, ENOMEM, "edg_wll_JobStatusServer() trio_asprintf failed!"); - goto rollback; - } - } - - - 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)); - if (stat->children_hist == NULL) { - edg_wll_SetError(ctx, ENOMEM, "edg_wll_JobStatusServer() calloc children_hist failed!"); - goto rollback; - } - - 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 version,status,jobid FROM states WHERE parent_job='%|Ss'", md5_jobid); - if (stmt != NULL) { - num_sub = edg_wll_ExecSQL(ctx, stmt, &sh); - if (num_sub >=0 ) { - while ((num_f = edg_wll_FetchRow(ctx, sh, sizeof(out_stat)/sizeof(out_stat[0]), NULL, out_stat)) == 3 ) { - if (!strcmp(INTSTAT_VERSION,out_stat[0])) { - num_f = atoi(out_stat[1]); - if (num_f > EDG_WLL_JOB_UNDEF && num_f < EDG_WLL_NUMBER_OF_STATCODES) - stat->children_hist[num_f+1]++; - } - else { // recount state - glite_jobid_t subjob; - intJobStat js_real; - char *name; - int port; - - - js = &js_real; - glite_jobid_getServerParts(job, &name, &port); - if (glite_jobid_recreate(name, port, out_stat[2], &subjob)) { - goto rollback; - } - free(name); - - if (edg_wll_intJobStatus(ctx, subjob, flags, js, js_enable_store, 0)) { - goto rollback; - } - glite_jobid_free(subjob); - num_f = js->pub.state; - if (num_f > EDG_WLL_JOB_UNDEF && num_f < EDG_WLL_NUMBER_OF_STATCODES) - stat->children_hist[num_f+1]++; - - destroy_intJobStat(js); - } - free(out_stat[0]); out_stat[0] = NULL; - free(out_stat[1]); out_stat[1] = NULL; - free(out_stat[2]); out_stat[2] = NULL; - } - if (num_f < 0) goto rollback; - - glite_lbu_FreeStmt(&sh); sh = NULL; - } - else goto rollback; - - free(stmt); stmt = NULL; - } else { - edg_wll_SetError(ctx, ENOMEM, "edg_wll_JobStatusServer() trio_asprintf failed!"); - goto rollback; - } - } - } - 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)); - if (stat->children_hist == NULL) { - edg_wll_SetError(ctx, ENOMEM, "edg_wll_JobStatusServer() calloc children_hist failed!"); - goto rollback; - } - - if (edg_wll_GetSubjobHistogram(ctx, job, stat->children_hist)) - goto rollback; - } - } - 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.jobid=j.jobid", - md5_jobid); - if (stmt != NULL) { - num_sub = edg_wll_ExecSQL(ctx, stmt, &sh); - if (num_sub >=0 ) { - while ((num_f = edg_wll_FetchRow(ctx, sh, sizeof(out)/sizeof(out[0]), NULL, out)) == 1 ) { - add_stringlist(&stat->children, out[0]); - free(out[0]); - } - if (num_f < 0) goto rollback; - - glite_lbu_FreeStmt(&sh); sh = NULL; - } - else goto rollback; - - free(stmt); stmt = NULL; - } else { - edg_wll_SetError(ctx, ENOMEM, "edg_wll_JobStatusServer() trio_asprintf failed!"); - goto rollback; - } - } - } -#endif - - whole_cycle = 1; -rollback: - if (!whole_cycle) { - edg_wll_FreeStatus(&jobstat.pub); - memset(stat, 0, sizeof(*stat)); - } - destroy_intJobStat_extension(&jobstat); - if (acl) { edg_wll_FreeAcl(acl); acl = NULL; } - if (stmt) { free(stmt); stmt = NULL; } - if (sh) { glite_lbu_FreeStmt(&sh); sh = NULL; } - - } while (edg_wll_TransNeedRetry(ctx)); - - free(string_jobid); - free(md5_jobid); - - return edg_wll_Error(ctx, NULL, NULL); -} - -int edg_wll_intJobStatus( - edg_wll_Context ctx, - glite_jobid_const_t job, - int flags, - intJobStat *intstat, - int update_db, - int add_fqans) -{ - -/* 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) { - free(string_jobid); - return edg_wll_SetError(ctx,EINVAL, NULL); - } - free(string_jobid); - - /* 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); - return edg_wll_Error(ctx,NULL,NULL); - } - } - - /* re-lock job from InShareMode to ForUpdate - * needed by edg_wll_RestoreSubjobState and edg_wll_StoreIntState - */ - res = edg_wll_LockJobRowForUpdate(ctx, md5_jobid); - free(md5_jobid); - if (res) return edg_wll_Error(ctx, NULL, NULL); - - jqr[0].attr = EDG_WLL_QUERY_ATTR_JOBID; - jqr[0].op = EDG_WLL_QUERY_OP_EQUAL; - jqr[0].value.j = (glite_jobid_t)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)) { - if (edg_wll_Error(ctx, NULL, NULL) == ENOENT) { - if (edg_wll_RestoreSubjobState(ctx, job, intstat)) { - destroy_intJobStat(intstat); - free(jqra); - free(intstat->pub.owner); intstat->pub.owner = NULL; - return edg_wll_Error(ctx, NULL, NULL); - } - } - else { - free(jqra); - free(intstat->pub.owner); intstat->pub.owner = NULL; - return edg_wll_Error(ctx, NULL, NULL); - } - } - else { - free(jqra); - - for (num_events = 0; events[num_events].type != EDG_WLL_EVENT_UNDEF; - num_events++); - - if (num_events == 0) { - free(intstat->pub.owner); intstat->pub.owner = NULL; - return edg_wll_SetError(ctx,ENOENT,NULL); - } - - 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; - } - - - 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) return edg_wll_SetError(ctx, intErr, NULL); - - if (update_db) { - int tsq = num_events - 1; - if (add_fqans && tsq == 0 && ctx->fqans != NULL) { - for (i=0; ctx->fqans[i]; i++); - intstat->pub.user_fqans = malloc(sizeof(*ctx->fqans)*(i+1)); - for (i=0; ctx->fqans[i]; i++) { - intstat->pub.user_fqans[i] = strdup(ctx->fqans[i]); - } - intstat->pub.user_fqans[i] = NULL; - } - - edg_wll_StoreIntState(ctx, intstat, tsq); - /* recheck - * intJobStat *reread; - * edg_wll_LoadIntState(ctx, job, tsq, &reread); - * destroy_intJobStat(reread); - */ - } - } - - return edg_wll_Error(ctx, NULL, NULL); -} - - -/* - * Regenarate state of subjob without any event from its parent JobReg Event - */ -edg_wll_ErrorCode edg_wll_RestoreSubjobState( - edg_wll_Context ctx, - glite_jobid_const_t job, - intJobStat *intstat) -{ - glite_jobid_t parent_job = NULL; - edg_wll_QueryRec jqr_p1[2], jqr_p2[2]; - edg_wll_QueryRec **ec, **jc; - edg_wll_Event *events_p; - int err, i; - - - /* find job parent */ - if (get_job_parent(ctx, job, &parent_job)) goto err; - - /* get registration event(s) of parent*/ - jqr_p1[0].attr = EDG_WLL_QUERY_ATTR_JOBID; - jqr_p1[0].op = EDG_WLL_QUERY_OP_EQUAL; - jqr_p1[0].value.j = parent_job; - jqr_p1[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - - jqr_p2[0].attr = EDG_WLL_QUERY_ATTR_EVENT_TYPE; - jqr_p2[0].op = EDG_WLL_QUERY_OP_EQUAL; - jqr_p2[0].value.i = EDG_WLL_EVENT_REGJOB; - jqr_p2[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - - jc = (edg_wll_QueryRec **) malloc (2 * sizeof(edg_wll_QueryRec **)); - jc[0] = jqr_p1; - jc[1] = NULL; - - ec = (edg_wll_QueryRec **) malloc (2 * sizeof(edg_wll_QueryRec **)); - ec[0] = jqr_p2; - ec[1] = NULL; - - if (edg_wll_QueryEventsServer(ctx,1, (const edg_wll_QueryRec **)jc, - (const edg_wll_QueryRec **)ec, &events_p)) { - glite_jobid_free(parent_job); - free(jc); - free(ec); - return edg_wll_Error(ctx, NULL, NULL); - } - glite_jobid_free(parent_job); - free(jc); - free(ec); - - /* recreate job status of subjob */ - err = intJobStat_embryonic(ctx, job, (const edg_wll_RegJobEvent *) &(events_p[0]), intstat); - - for (i=0; events_p[i].type != EDG_WLL_EVENT_UNDEF ; i++) - edg_wll_FreeEvent(&events_p[i]); - free(events_p); - - if (err) goto err; - -err: - return edg_wll_Error(ctx, NULL, 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; - glite_lbu_Statement 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_ExecSQL(ctx,stmt,&sh) >= 0) { - f=edg_wll_FetchRow(ctx,sh,1,NULL,&out); - if (f == 0) { - if (out) free(out); - out = NULL; - edg_wll_SetError(ctx,ENOENT,md5_jobid); - } - } - glite_lbu_FreeStmt(&sh); - free(stmt); - - return out; -} - - -static edg_wll_ErrorCode get_job_parent(edg_wll_Context ctx, glite_jobid_const_t job, glite_jobid_t *parent) -{ - glite_lbu_Statement sh = NULL; - char *stmt = NULL, *out = NULL; - char *md5_jobid = edg_wlc_JobIdGetUnique(job); - int ret; - - - edg_wll_ResetError(ctx); - trio_asprintf(&stmt,"select parent_job from states " - "where jobid = '%|Ss'" ,md5_jobid); - - if (stmt==NULL) { - edg_wll_SetError(ctx,ENOMEM, NULL); - goto err; - } - - if (edg_wll_ExecSQL(ctx,stmt,&sh) < 0) goto err; - - if (!edg_wll_FetchRow(ctx,sh,1,NULL,&out)) { - edg_wll_SetError(ctx,ENOENT,md5_jobid); - goto err; - } - - ret = glite_jobid_recreate((const char*) ctx->srvName, - ctx->srvPort, (const char *) out, parent); - - if (ret) { - edg_wll_SetError(ctx,ret,"Error creating jobid"); - goto err; - } - -err: - if (sh) glite_lbu_FreeStmt(&sh); - free(md5_jobid); - free(stmt); - free(out); - - return edg_wll_Error(ctx,NULL,NULL); -} - - -#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; - - - /* check size of intstat version, its only varchar(32) */ - assert(strlen(INTSTAT_VERSION) <= 32); - - 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_ExecSQL(ctx,stmt,NULL) < 0) { - if (EEXIST == edg_wll_Error(ctx, NULL, NULL)) { - /* XXX: this should not happen */ - edg_wll_ResetError(ctx); - free(stmt); stmt = NULL; - tagp++; - continue; - } - else - goto cleanup; - } - free(stmt); stmt = NULL; - 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->pub, 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_ExecSQL(ctx,stmt,NULL)) < 0) goto cleanup; - free(stmt); stmt = NULL; - - if (dbret == 0) { - edg_wll_IColumnsSQLPart(ctx, ctx->job_index_cols, &stat->pub, 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_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup; - free(stmt); stmt = NULL; - } - - 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_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup; - free(stmt); stmt = NULL; - } - if (update) { - trio_asprintf(&stmt, "delete from status_tags " - "where jobid ='%|Ss' and seq<%d", jobid_md5, seq); - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup; - free(stmt); stmt = NULL; - } - -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, - char *icnames, - char *values) -{ - char *stmt = NULL; - -/* TODO - edg_wll_UpdateStatistics(ctx, NULL, e, &jobstat.pub); - if (ctx->rgma_export) write2rgma_status(&jobstat); -*/ - - trio_asprintf(&stmt, - "insert into states" - "(jobid,status,seq,int_status,version" - ",parent_job%s) " - "values (%s)", - icnames, values); - - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto cleanup; - -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, - glite_jobid_const_t jobid, - int lock, - int seq, - intJobStat **stat) -{ - char *jobid_md5; - char *stmt; - glite_lbu_Statement sh; - char *res, *res_rest; - int nstates; - - edg_wll_ResetError(ctx); - jobid_md5 = edg_wlc_JobIdGetUnique(jobid); - - if (lock) { - edg_wll_LockJobRowForUpdate(ctx,jobid_md5); - } - - 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_ExecSQL(ctx,stmt,&sh)) < 0) goto cleanup; - if (nstates == 0) { - edg_wll_SetError(ctx,ENOENT,"no state in DB"); - goto cleanup; - } - if (edg_wll_FetchRow(ctx,sh,1,NULL,&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); - if (sh) glite_lbu_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; ipub.parent_job, LOCK, - 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); - - event->any.priority = EDG_WLL_LOGFLAG_INTERNAL; - - 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 = db_parent_store(ctx, event, pis); - - edg_wll_FreeEvent(event); - free(event); - - return ret; -} - - -/* returns state class of subjob of job collection */ -static subjobClassCodes class(edg_wll_JobStat *stat) -{ - switch (stat->state) { - case EDG_WLL_JOB_RUNNING: - return(SUBJOB_CLASS_RUNNING); - break; - case EDG_WLL_JOB_DONE: - if (stat->done_code == EDG_WLL_STAT_OK) - return(SUBJOB_CLASS_DONE); - else - // failed & cancelled - return(SUBJOB_CLASS_REST); - break; - case EDG_WLL_JOB_ABORTED: - return(SUBJOB_CLASS_ABORTED); - break; - case EDG_WLL_JOB_CLEARED: - return(SUBJOB_CLASS_CLEARED); - break; - default: - return(SUBJOB_CLASS_REST); - break; - } -} - -/* Mapping of subjob class to some field in childen_hist */ -static edg_wll_JobStatCode class_to_statCode(subjobClassCodes code) -{ - switch (code) { - case SUBJOB_CLASS_RUNNING: return(EDG_WLL_JOB_RUNNING); break; - case SUBJOB_CLASS_DONE: return(EDG_WLL_JOB_DONE); break; - case SUBJOB_CLASS_ABORTED: return(EDG_WLL_JOB_ABORTED); break; - case SUBJOB_CLASS_CLEARED: return(EDG_WLL_JOB_CLEARED); break; - case SUBJOB_CLASS_REST: return(EDG_WLL_JOB_UNKNOWN); break; - default: assert(0); break; - } -} - -/* count parent state from subjob histogram */ -static edg_wll_JobStatCode process_Histogram(intJobStat *pis) -{ - if (pis->pub.children_hist[class_to_statCode(SUBJOB_CLASS_RUNNING)+1] > 0) { - return EDG_WLL_JOB_RUNNING; - } - else if (pis->pub.children_hist[class_to_statCode(SUBJOB_CLASS_CLEARED)+1] == pis->pub.children_num) { - return EDG_WLL_JOB_CLEARED; - } - else if (pis->pub.children_hist[class_to_statCode(SUBJOB_CLASS_DONE)+1] - + pis->pub.children_hist[class_to_statCode(SUBJOB_CLASS_CLEARED)+1] == pis->pub.children_num) { - return EDG_WLL_JOB_DONE; - } - else if (pis->pub.children_hist[class_to_statCode(SUBJOB_CLASS_ABORTED)+1] - + pis->pub.children_hist[class_to_statCode(SUBJOB_CLASS_DONE)+1] - + pis->pub.children_hist[class_to_statCode(SUBJOB_CLASS_CLEARED)+1] == pis->pub.children_num) { - return EDG_WLL_JOB_ABORTED; - } - else - return EDG_WLL_JOB_WAITING; -} - -static edg_wll_ErrorCode update_parent_status(edg_wll_Context ctx, edg_wll_JobStat *subjob_stat_old, intJobStat *cis, edg_wll_Event *ce) -{ - intJobStat *pis = NULL; - subjobClassCodes subjob_class, subjob_class_old; - edg_wll_JobStatCode parent_new_state; - - - subjob_class = class(&cis->pub); - subjob_class_old = class(subjob_stat_old); - - - if (subjob_class_old != subjob_class) { - if (load_parent_intJobStat(ctx, cis, &pis)) goto err; - - pis->pub.children_hist[class_to_statCode(subjob_class)+1]++; - pis->pub.children_hist[class_to_statCode(subjob_class_old)+1]--; - - edg_wll_StoreSubjobHistogram(ctx, cis->pub.parent_job, pis); - - - if (pis->pub.jobtype == EDG_WLL_STAT_COLLECTION) { - parent_new_state = process_Histogram(pis); - if (pis->pub.state != parent_new_state) { - // XXX: we do not need EDG_WLL_STAT_code any more - // doneFailed subjob is stored in REST class and - // inducting collection Waiting state - // -> in future may be removed from collectionState event - // supposing collection Done state to be always DoneOK - if (log_collectionState_event(ctx, parent_new_state, EDG_WLL_STAT_OK, cis, pis, ce)) - goto err; - } - } - } - -err: - 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, - glite_jobid_const_t job, - edg_wll_Event *e, - int seq, - intJobStat *ijsp, - edg_wll_JobStat *oldstat, - edg_wll_JobStat *stat_out) -{ - int res; - int be_strict = 0; - char *errstring = NULL; - char *oldstat_rgmaline = NULL; - - - edg_wll_CpyStatus(&ijsp->pub,oldstat); - - if (ctx->rgma_export) oldstat_rgmaline = write2rgma_statline(ijsp); - - res = processEvent(ijsp, e, seq, be_strict, &errstring); - if (res == RET_FATAL || res == RET_INTERNAL) { /* !strict */ - edg_wll_FreeStatus(oldstat); - memset(oldstat,0,sizeof *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, oldstat_rgmaline); - - if (stat_out) { - edg_wll_CpyStatus(&ijsp->pub, stat_out); - } - - 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, - glite_jobid_const_t job, - edg_wll_Event *e, - int seq, - edg_wll_JobStat *oldstat, - edg_wll_JobStat *stat_out) -{ - intJobStat *ijsp; - int flags = 0; - int res; - int be_strict = 0; - char *errstring = NULL; - intJobStat jobstat; - char *oldstat_rgmaline = NULL; - - - if (!edg_wll_LoadIntState(ctx, job, DONT_LOCK, seq - 1, &ijsp)) { - edg_wll_CpyStatus(&ijsp->pub,oldstat); - - if (ctx->rgma_export) oldstat_rgmaline = write2rgma_statline(ijsp); - - res = processEvent(ijsp, e, seq, be_strict, &errstring); - if (res == RET_FATAL || res == RET_INTERNAL) { /* !strict */ - edg_wll_FreeStatus(oldstat); - memset(oldstat,0,sizeof *oldstat); - return edg_wll_SetError(ctx, EINVAL, errstring); - } - edg_wll_StoreIntState(ctx, ijsp, seq); - - 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, ijsp, e)) { - edg_wll_FreeStatus(oldstat); - memset(oldstat,0,sizeof *oldstat); - return edg_wll_SetError(ctx, EINVAL, "update_parent_status()"); - } - } - - if (ctx->rgma_export) write2rgma_chgstatus(ijsp, oldstat_rgmaline); - - if (stat_out) { - memcpy(stat_out,&ijsp->pub,sizeof *stat_out); - destroy_intJobStat_extension(ijsp); - } - else destroy_intJobStat(ijsp); - free(ijsp); - } - else if (!edg_wll_intJobStatus(ctx, job, flags,&jobstat, js_enable_store, 1)) - { - /* 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. - */ - - edg_wll_UpdateStatistics(ctx,NULL,e,&jobstat.pub); - - if (ctx->rgma_export) write2rgma_status(&jobstat); - - if (stat_out) { - memcpy(stat_out,&jobstat.pub,sizeof *stat_out); - destroy_intJobStat_extension(&jobstat); - } - else destroy_intJobStat(&jobstat); - } - - return edg_wll_Error(ctx, NULL, NULL); -} - - -edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context ctx, glite_jobid_const_t parent_jobid, int *hist) -{ - - char *stmt = NULL,*out = NULL, *rest = NULL; - glite_lbu_Statement 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_ExecSQL(ctx,stmt,&sh) >= 0) { - f=edg_wll_FetchRow(ctx,sh,1,NULL,&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]; - } - } - glite_lbu_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, glite_jobid_const_t 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_ExecSQL(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); - -} - - diff --git a/org.glite.lb.server/src/jobstat.h b/org.glite.lb.server/src/jobstat.h deleted file mode 100644 index 8494a60..0000000 --- a/org.glite.lb.server/src/jobstat.h +++ /dev/null @@ -1,46 +0,0 @@ -#ident "$Header$" - -#ifndef GLITE_LB_LBS_JOBSTAT_H -#define GLITE_LB_LBS_JOBSTAT_H - -#include "glite/lb/jobstat.h" -#include "glite/lb/intjobstat.h" -#include "glite/lbu/db.h" - -int edg_wll_JobStatusServer(edg_wll_Context, glite_jobid_const_t, int, edg_wll_JobStat *); - - -int edg_wll_intJobStatus( edg_wll_Context, glite_jobid_const_t, int, intJobStat *, int, int); -edg_wll_ErrorCode edg_wll_StoreIntState(edg_wll_Context, intJobStat *, int); -edg_wll_ErrorCode edg_wll_StoreIntStateEmbryonic(edg_wll_Context, char *icnames, char *values); -edg_wll_ErrorCode edg_wll_LoadIntState(edg_wll_Context , glite_jobid_const_t , int, int, intJobStat **); -edg_wll_ErrorCode edg_wll_RestoreSubjobState(edg_wll_Context , glite_jobid_const_t , intJobStat *); - - -/* update stored job state according to new event */ -edg_wll_ErrorCode edg_wll_StepIntState(edg_wll_Context ctx, glite_jobid_const_t job, edg_wll_Event *e, int seq, edg_wll_JobStat *old_stat, edg_wll_JobStat *stat_out); - -edg_wll_ErrorCode edg_wll_StepIntStateParent(edg_wll_Context,glite_jobid_const_t,edg_wll_Event *,int,intJobStat *, edg_wll_JobStat *old_stat, 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 */ -); - - - -intJobStat* dec_intJobStat(char *, char **); -char *enc_intJobStat(char *, intJobStat* ); - -void write2rgma_status(intJobStat *); -void write2rgma_chgstatus(intJobStat *, char *); -char* write2rgma_statline(intJobStat *); - -int add_stringlist(char ***, const char *); - -edg_wll_ErrorCode edg_wll_GetSubjobHistogram(edg_wll_Context, glite_jobid_const_t parent_jobid, int *hist); -edg_wll_ErrorCode edg_wll_StoreSubjobHistogram(edg_wll_Context, glite_jobid_const_t parent_jobid, intJobStat *ijs); - -#endif /* GLITE_LB_LBS_JOBSTAT_H*/ diff --git a/org.glite.lb.server/src/jobstat_supp.c b/org.glite.lb.server/src/jobstat_supp.c deleted file mode 100644 index 2619550..0000000 --- a/org.glite.lb.server/src/jobstat_supp.c +++ /dev/null @@ -1,728 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lbu/trio.h" -#include "glite/lbu/db.h" -#include "glite/lb/context-int.h" -#include "glite/lb/intjobstat.h" -#include "glite/lb/seqcode_aux.h" - -#include "store.h" -#include "index.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+strlen(strpom),"%d%s", 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 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); - if (ret) ret = enc_int_array(ret, stat->children_hist, EDG_WLL_NUMBER_OF_STATCODES); - /* children histogram stored in the DB, 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_timeval(ret, stat->lastUpdateTime); - if (ret) ret = enc_intlist(ret, stat->stateEnterTimes); - if (ret) ret = enc_int(ret, stat->expectUpdate); - if (ret) ret = enc_string(ret, stat->expectFrom); - if (ret) ret = enc_string(ret, stat->acl); - 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(ret, stat->suspended); - if (ret) ret = enc_string(ret, stat->suspend_reason); - if (ret) ret = enc_string(ret, stat->failure_reasons); - if (ret) ret = enc_int(ret, stat->remove_from_proxy); - if (ret) ret = enc_string(ret, stat->ui_host); - if (ret) ret = enc_strlist(ret, stat->user_fqans); - if (ret) ret = enc_int(ret, stat->sandbox_retrieved); - if (ret) ret = enc_int(ret, stat->jw_status); - 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_string(ret, stat->pbs_resource_usage); - if (ret) ret = enc_int(ret, stat->pbs_exit_status); - if (ret) ret = enc_string(ret, stat->pbs_error_desc); - if (ret) ret = enc_string(ret, stat->condor_status); - if (ret) ret = enc_string(ret, stat->condor_universe); - if (ret) ret = enc_string(ret, stat->condor_owner); - if (ret) ret = enc_string(ret, stat->condor_preempting); - if (ret) ret = enc_int(ret, stat->condor_shadow_pid); - if (ret) ret = enc_int(ret, stat->condor_shadow_exit_status); - if (ret) ret = enc_int(ret, stat->condor_starter_pid); - if (ret) ret = enc_int(ret, stat->condor_starter_exit_status); - if (ret) ret = enc_int(ret, stat->condor_job_pid); - if (ret) ret = enc_int(ret, stat->condor_job_exit_status); - if (ret) ret = enc_string(ret, stat->condor_dest_host); - if (ret) ret = enc_string(ret, stat->condor_reason); - if (ret) ret = enc_string(ret, stat->condor_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); - 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); - } - /* children histogram stored in the DB, 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->lastUpdateTime = dec_timeval(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->stateEnterTimes = dec_intlist(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->acl = 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->suspended = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->suspend_reason = dec_string(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->failure_reasons = dec_string(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->remove_from_proxy = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->ui_host = dec_string(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->user_fqans = dec_strlist(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->sandbox_retrieved = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->jw_status = dec_int(tmp_in, &tmp_in); - 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_resource_usage = dec_string(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); - if (tmp_in != NULL) stat->condor_status = dec_string(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_universe = dec_string(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_owner = dec_string(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_preempting = dec_string(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_shadow_pid = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_shadow_exit_status = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_starter_pid = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_starter_exit_status = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_job_pid = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_job_exit_status = dec_int(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_dest_host = dec_string(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_reason = dec_string(tmp_in, &tmp_in); - if (tmp_in != NULL) stat->condor_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_timeval(ret, stat->last_pbs_event_timestamp); - if (ret) ret = enc_int(ret, stat->pbs_reruning); - if (ret) ret = enc_strlist(ret, stat->tag_seq_codes); - 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) { - stat->last_pbs_event_timestamp = dec_timeval(tmp_in, &tmp_in); - } - if (tmp_in != NULL) { - stat->pbs_reruning = dec_int(tmp_in, &tmp_in); - } - if (tmp_in != NULL) { - stat->tag_seq_codes = dec_strlist(tmp_in, &tmp_in); - } - } else if (tmp_in != NULL) { - edg_wll_FreeStatus(pubstat); - free(pubstat); - } - - *rest = tmp_in; - return stat; -} - - -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); -} - - diff --git a/org.glite.lb.server/src/lb_authz.c b/org.glite.lb.server/src/lb_authz.c deleted file mode 100644 index c4ac82c..0000000 --- a/org.glite.lb.server/src/lb_authz.c +++ /dev/null @@ -1,941 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include - -#include "glite/lb/context-int.h" -#include "lb_authz.h" - -#ifndef NO_VOMS - -#include -#undef WITHOUT_TRIO - -#include "glite/jobid/strmd5.h" -#include "glite/jobid/cjobid.h" -#include "glite/lbu/trio.h" -#include "db_supp.h" -#include - -#include "glite/security/voms/voms_apic.h" - -/* XXX should be defined in gridsite-gacl.h */ -GRSTgaclEntry *GACLparseEntry(xmlNodePtr cur); - -extern char *server_key; -extern char *server_cert; - -static int -get_fqans(edg_wll_Context ctx, struct vomsdata *voms_info, - char ***fqans) -{ - struct voms **voms_cert = NULL; - char **f, **attrs, **tmp; - int num; - - attrs = NULL; - num = 0; - - for (voms_cert = voms_info->data; voms_cert && *voms_cert; voms_cert++) { - for (f = (*voms_cert)->fqan; f && *f; f++) { - tmp = realloc(attrs, (num + 1) * sizeof(*attrs)); - if (tmp == NULL) { - free(attrs); - return ENOMEM; - } - attrs = tmp; - attrs[num++] = strdup(*f); - } - } - if (attrs) { - tmp = realloc(attrs, (num + 1) * sizeof(*attrs)); - if (tmp == NULL) { - free(attrs); - return ENOMEM; - } - attrs = tmp; - attrs[num++] = NULL; - } - - *fqans = attrs; - return 0; -} - -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 edg_wll_SetError(ctx, ENOMEM, "not enough memory"); - 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; -} - -int -edg_wll_SetVomsGroups(edg_wll_Context ctx, edg_wll_GssConnection *gss, char *server_cert, char *server_key, char *voms_dir, char *ca_dir) -{ - int ret; - int err = 0; - struct vomsdata *voms_info = NULL; - edg_wll_GssPrincipal principal; - edg_wll_GssStatus gss_code; - - - /* XXX DK: correct cleanup ?? */ - memset (&ctx->vomsGroups, 0, sizeof(ctx->vomsGroups)); - edg_wll_ResetError(ctx); - - if (ctx->fqans) { - char **f; - for (f = ctx->fqans; f && *f; f++) - free(*f); - free(ctx->fqans); - ctx->fqans = NULL; - } - - ret = edg_wll_gss_get_client_conn(gss, &principal, &gss_code); - if (ret) { - if (ret == EDG_WLL_GSS_ERROR_GSS) { - edg_wll_SetErrorGss(ctx,"edg_wll_SetVomsGroups()",&gss_code); - } - edg_wll_SetError(ctx, ret, "edg_wll_SetVomsGroups() - failed to get peer credentials"); - 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_RetrieveFromCtx(gss->context, 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); - if (ret) - goto end; - - ret = get_fqans(ctx, voms_info, &ctx->fqans); - -end: - edg_wll_gss_free_princ(principal); - - if (voms_info) - VOMS_Destroy(voms_info); - - 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_Context ctx, edg_wll_VomsGroups *groups, char **fqans, - char *subject, GRSTgaclUser **gacl_user) -{ - GRSTgaclCred *cred = NULL; - GRSTgaclUser *user = NULL; - int i; - char **f; - - edg_wll_ResetError(ctx); - - GRSTgaclInit(); - - cred = GRSTgaclCredNew("person"); - if (cred == NULL) - return edg_wll_SetError(ctx, ENOMEM, "Failed to create GACL person"); - - if (!GRSTgaclCredAddValue(cred, "dn", subject)) { - edg_wll_SetError(ctx, EINVAL, "Failed to create GACL DN credential"); - goto fail; - } - - user = GRSTgaclUserNew(cred); - if (user == NULL) { - edg_wll_SetError(ctx, ENOMEM, "Failed to create GACL user"); - 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) { - edg_wll_SetError(ctx, ENOMEM, "Failed to create GACL voms-cred credential"); - goto fail; - } - if (!GRSTgaclCredAddValue(cred, "vo", groups->val[i].vo) || - !GRSTgaclCredAddValue(cred, "group", groups->val[i].name)) { - edg_wll_SetError(ctx, EINVAL, "Failed to populate GACL voms-cred credential"); - goto fail; - } - if (!GRSTgaclUserAddCred(user, cred)) { - edg_wll_SetError(ctx, EINVAL, "Failed to add GACL voms-cred credential"); - goto fail; - } - cred = NULL; - /* GACLuserAddCred() doesn't copy content, just store the pointer. Cred - * mustn't be free()ed */ - } - - for (f = fqans; f && *f; f++) { - cred = GRSTgaclCredNew("voms"); - if (cred == NULL) { - edg_wll_SetError(ctx, ENOMEM, "Failed to create GACL voms credential"); - goto fail; - } - if (!GRSTgaclCredAddValue(cred, "fqan", *f)) { - edg_wll_SetError(ctx, EINVAL, "Failed to populate GACL voms credential"); - goto fail; - } - if (!GRSTgaclUserAddCred(user, cred)) { - edg_wll_SetError(ctx, EINVAL, "Failed to add GACL voms credential"); - goto fail; - } - cred = NULL; - } - - *gacl_user = user; - - return 0; - -fail: - if (cred) - GRSTgaclCredFree(cred); - if (user) - GRSTgaclUserFree(user); - - return edg_wll_Error(ctx,NULL,NULL); -} - -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) -{ - /* XXX the GRSTgaclCred contains a bit more information to handle */ - return (strcmp(c1->auri, c2->auri) == 0); -} - -static int -addEntry(edg_wll_Context ctx, 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 edg_wll_SetError(ctx,EEXIST,"ACL entry already exists");; - - return (GRSTgaclAclAddEntry(acl, entry) == 0) ? -1 /* GACL_ERR */ : 0; -} - -static int -delEntry(edg_wll_Context ctx, 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 : edg_wll_SetError(ctx,EINVAL,"ACL entry doesn't exist"); -} - -static int -create_cred(edg_wll_Context ctx, char *userid, int user_type, GRSTgaclCred **cred) -{ - GRSTgaclCred *c = NULL; - char *group = NULL; - - if (user_type == EDG_WLL_CHANGEACL_DN) { - c = GRSTgaclCredNew("person"); - if (c == NULL) - return ENOMEM; - if (!GRSTgaclCredAddValue(c, "dn", userid)) { - GRSTgaclCredFree(c); - return -1; /* GACL_ERR */ - } - } else if(user_type == EDG_WLL_CHANGEACL_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)) { - GRSTgaclCredFree(c); - return -1; /* GACL_ERR */ - } - } else if (user_type == EDG_WLL_CHANGEACL_FQAN) { - c = GRSTgaclCredNew("voms"); - if (c == NULL) - return ENOMEM; - if (!GRSTgaclCredAddValue(c, "fqan", userid)) { - GRSTgaclCredFree(c); - return -1; /* GACL_ERR */ - } - } else - return edg_wll_SetError(ctx,EINVAL,"Unknown user type for ACL"); - - *cred = c; - - return 0; -} - -static int -change_acl(edg_wll_Context ctx, GRSTgaclAcl *acl, GRSTgaclEntry *entry, int operation) - /* creds, permission, permission_type */ -{ - if (operation == EDG_WLL_CHANGEACL_ADD) - return addEntry(ctx, acl, entry); - - if (operation == EDG_WLL_CHANGEACL_REMOVE) - return delEntry(ctx, acl, entry); - - return edg_wll_SetError(ctx,EINVAL,"Unknown ACL operation requested"); -} - -static int -edg_wll_change_acl(edg_wll_Context ctx, 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,p; - - GRSTgaclInit(); - - if (acl == NULL || acl->value == NULL) - return edg_wll_SetError(ctx,EINVAL,"Change ACL"); - - ret = create_cred(ctx, user_id, user_id_type, &cred); - if (ret) - return ret; - - entry = GRSTgaclEntryNew(); - if (entry == NULL) { - ret = edg_wll_SetError(ctx,ENOMEM,"Change ACL"); - goto end; - } - - if (!GRSTgaclEntryAddCred(entry, cred)) { - ret = edg_wll_SetError(ctx,EINVAL,"Can't create ACL"); - goto end; - } - - switch (permission) { - case EDG_WLL_CHANGEACL_READ: - p = EDG_WLL_CHANGEACL_READ; - break; - default: - ret = edg_wll_SetError(ctx,EINVAL,"Unknown permission for ACL"); - goto end; - } - - if (perm_type == EDG_WLL_CHANGEACL_ALLOW) - GRSTgaclEntryAllowPerm(entry, p); - else if (perm_type == EDG_WLL_CHANGEACL_DENY) - GRSTgaclEntryDenyPerm(entry, p); - else { - ret = edg_wll_SetError(ctx,EINVAL,"Unknown permission type"); - goto end; - } - - ret = change_acl(ctx, 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, &ctx->vomsGroups, ctx->fqans, ctx->peerName, &user); - if (ret) - return edg_wll_Error(ctx,NULL,NULL); - - perm = GRSTgaclAclTestUser(acl->value, user); - - 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) -{ - 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_ExecSQL(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_ExecSQL(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_ExecSQL(ctx, q1, NULL) > 0 ) - { - trio_asprintf(&q2, - "delete from acls " - "where aclid='%|Ss' and refcnt=0", - aclid); - edg_wll_ExecSQL(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, glite_jobid_const_t 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(ctx, acl, user_id, user_id_type, - permission, perm_type, operation); - if (ret) - { - if ( ret == EEXIST ) - ret = edg_wll_ResetError(ctx); - 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_ExecSQL(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, glite_jobid_const_t jobid, edg_wll_Acl *acl) -{ - char *q = NULL; - char *acl_id = NULL; - char *acl_str = NULL; - glite_lbu_Statement 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_ExecSQL(ctx, q, &stmt) < 0 || - edg_wll_FetchRow(ctx, stmt, 1, NULL, &acl_id) < 0) { - goto end; - } - glite_lbu_FreeStmt(&stmt); stmt = NULL; - free(q); q = NULL; - - if (acl_id == NULL || *acl_id == '\0') { - free(acl_id); - free(jobstr); - *acl = NULL; - return 0; - } - - trio_asprintf(&q, - "select value from acls where aclid = '%|Ss'", acl_id); - if (edg_wll_ExecSQL(ctx, q, &stmt) < 0 || - edg_wll_FetchRow(ctx, stmt, 1, NULL, &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) glite_lbu_FreeStmt(&stmt); - if (acl_id) free(acl_id); - if (acl_str) free(acl_str); - if (gacl) GRSTgaclAclFree(gacl); - if (jobstr) free(jobstr); - - return edg_wll_Error(ctx, NULL, NULL); -} - -int -check_store_authz(edg_wll_Context ctx, edg_wll_Event *ev) -{ - char *pem_string = NULL; - char *request = NULL; - int ret; - - /* XXX make a real RSL ? */ - request = edg_wll_EventToString(ev->any.type); - if (request == NULL) - return edg_wll_SetError(ctx, EINVAL, "Unknown event type"); - - ret = edg_wll_gss_get_client_pem(&ctx->connections->serverConnection->gss, - server_cert, server_key, - &pem_string); - if (ret) - return edg_wll_SetError(ctx, ret, "Failed to extract client's PEM string"); - - ret = lcas_pem(pem_string, request); - if (ret) - ret = edg_wll_SetError(ctx, EPERM, "Not allowed to log events here"); - - free(pem_string); - - return ret; -} - -#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, glite_jobid_const_t 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, glite_jobid_const_t jobid, edg_wll_Acl *acl) { return 0; } - - -#endif - - -int edg_wll_amIroot(const char *subj, char **fqans,char **super_users) -{ - int i; - char **f; - - if (!subj && !fqans ) return 0; - for (i=0; super_users && super_users[i]; i++) - if (strncmp(super_users[i], "FQAN:", 5) == 0) { - for (f = fqans; f && *f; f++) - if (strcmp(*f, super_users[i]+5) == 0) return 1; - } else - if (edg_wll_gss_equal_subj(subj,super_users[i])) return 1; - - return 0; -} - diff --git a/org.glite.lb.server/src/lb_html.c b/org.glite.lb.server/src/lb_html.c deleted file mode 100644 index 30f3cad..0000000 --- a/org.glite.lb.server/src/lb_html.c +++ /dev/null @@ -1,267 +0,0 @@ -#ident "$Header$" - -#include "lb_html.h" -#include "lb_proto.h" -#include "cond_dump.h" -#include "pretty_print_wrapper.h" - -#include "glite/lb/context-int.h" - -#include -#include -#include -#include -#include - -#ifdef __GNUC__ -#define UNUSED_VAR __attribute__((unused)) -#else -#define UNUSED_VAR -#endif - -static char *xmlToHTML(char *xml) { - char *html = strdup(""); - int i = 0; - int j = 0; - while (xml[i]){ - if (xml[i] == '<'){ - html = realloc(html, (j+strlen("<")+1)*sizeof(*html) ); - strcpy(html+j, "<"); - j += strlen("<"); - } - else if (xml[i] == '>'){ - html = realloc(html, (j+strlen(">")+1)*sizeof(*html) ); - strcpy(html+j, ">"); - j += strlen(">"); - } - else{ - html = realloc(html, (j+2)*sizeof(*html)); - html[j] = xml[i]; - j++; - } - i++; - } - html[j] = 0; - - return html; -} - -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_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOut, char **message) -{ - char *pomA = NULL, *pomB; - int i = 0; - - /* head */ - pomB = strdup(""); - - while (jobsOut && jobsOut[i]) { - char *chid = edg_wlc_JobIdUnparse(jobsOut[i]); - - asprintf(&pomA,"%s\t\t
  • %s\r\n", - pomB, chid,chid); - - free(chid); - free(pomB); - pomB = pomA; - i++; - } - - char *ret; - asprintf(&ret, "\r\n\t\r\n"); - pomA = ret; - if (pomB[0]){ - asprintf(&ret, "%s

    User jobs

    \r\n" - "
      %s
    ", - pomA, pomB - ); - free(pomA); - free(pomB); - } - pomA = ret; - asprintf(&ret, "%sUser subject: %s

    " - "\t\r\n", - pomA, ctx->peerName?ctx->peerName: "<anonymous>" - ); - free(pomA); - - *message = ret; - - return 0; -} - -int edg_wll_UserNotifsToHTML(edg_wll_Context ctx UNUSED_VAR, char **notifids, char **message){ - char *pomA = NULL, *pomB = NULL; - pomB = strdup(""); - - int i = 0; - while(notifids && notifids[i]){ - asprintf(&pomA, "%s\t\t

  • %s\r\n", - pomB, - notifids[i], - notifids[i] - ); - free(pomB); - pomB = pomA; - i++; - } - - char *ret; - asprintf(&ret, "\r\n\t\r\n"); - asprintf(&ret, "\r\n\t\r\n" - "

    User notifications

    \r\n" - "
      %s
    " - "\t\r\n", - pomA - ); - free(pomA); - - *message = ret; - - return 0; -} - -#define TR(name,type,field) \ -{ \ - int l; \ - if (field){ \ - l = asprintf(&pomA,"" name ":" \ - "" type "", (field)); \ - } \ - else{ \ - l = asprintf(&pomA,"" name \ - ""); \ - } \ - pomB = realloc(pomB, sizeof(*pomB)*(pomL+l+1)); \ - strcpy(pomB+pomL, pomA); \ - pomL += l; \ - free(pomA); pomA=NULL; \ -} - -int edg_wll_NotificationToHTML(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, char **message){ - char *pomA = NULL, *pomB = NULL, *flags, *cond; - int pomL = 0; - - flags = edg_wll_stat_flags_to_string(ni->flags); - printf("flags %d - %s", ni->flags, flags); - - TR("Destination", "%s", ni->destination); - TR("Valid until", "%s", ni->valid); - TR("Flags", "%s", flags); - free(flags); - - if (! edg_wll_Condition_Dump(ni, &cond, 0)){ - asprintf(&pomA, "%s

    Conditions

    \r\n
    %s
    \r\n", - pomB, cond); - free(pomB); - pomB = pomA; - pomL = strlen(pomB); - - } - free(cond); - - asprintf(&pomA, "\r\n\t\r\n" - "

    Notification %s

    \r\n" - "%s
    " - "\t\r\n", - ni->notifid, 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 = NULL, *pomB = NULL; - int pomL = 0; - char *chid,*chstat; - char *jdl,*rsl; - - jdl = strdup(""); - rsl = strdup(""); - - chid = edg_wlc_JobIdUnparse(stat.jobId); - - 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)); - } - else - TR("State entered", "%s", NULL); - if ( (stat.lastUpdateTime.tv_sec) || (stat.lastUpdateTime.tv_usec) ) { - time_t time = stat.lastUpdateTime.tv_sec; - TR("Last update","%s",ctime(&time)); - } - else - TR("Last update", "%s", NULL); - 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"); - 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){ - char *jdl_unp; - if (pretty_print(stat.jdl, &jdl_unp) == 0) - asprintf(&jdl,"

    Job description

    \r\n" - "
    %s
    \r\n",jdl_unp); - else - asprintf(&jdl,"

    Job description (not a ClassAd)" - "

    \r\n
    %s
    \r\n",stat.jdl); - } - - if (stat.rsl) asprintf(&rsl,"

    RSL

    \r\n" - "
    %s
    \r\n",stat.rsl); - - - asprintf(&pomA, "\r\n\t\r\n" - "

    %s

    \r\n" - "%s
    " - "%s%s" - "\t\r\n", - 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,"Error\n" - "

    %s

    \n" - "%d: %s (%s)",msg,e,et,ed); - - free(et); free(ed); - return out; -} diff --git a/org.glite.lb.server/src/lb_html.h b/org.glite.lb.server/src/lb_html.h deleted file mode 100644 index ac1d0e1..0000000 --- a/org.glite.lb.server/src/lb_html.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef GLITE_LB_HTML_H -#define GLITE_LB_HTML_H - -#ident "$Header$" - -#include "glite/lb/context.h" -#include "glite/lb/events.h" -#include "glite/lb/jobstat.h" -#include "lb_proto.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_UserInfoToHTML(edg_wll_Context, edg_wlc_JobId *, char **); -int edg_wll_UserNotifsToHTML(edg_wll_Context ctx, char **notifids, char **message); -int edg_wll_NotificationToHTML(edg_wll_Context ctx, notifInfo *ni, char **message); -char *edg_wll_ErrorToHTML(edg_wll_Context,int); - -#endif /* GLITE_LB_HTML_H */ diff --git a/org.glite.lb.server/src/lb_http.c b/org.glite.lb.server/src/lb_http.c deleted file mode 100644 index 99439d2..0000000 --- a/org.glite.lb.server/src/lb_http.c +++ /dev/null @@ -1,63 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include - -#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); - - if (req) { - dprintf(("[%d] request: %s\n",getpid(),req)); - } else { - dprintf(("no request\n")); - } - if (body) dprintf(("request body:\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; -} diff --git a/org.glite.lb.server/src/lb_http.h b/org.glite.lb.server/src/lb_http.h deleted file mode 100644 index 421beea..0000000 --- a/org.glite.lb.server/src/lb_http.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef GLITE_LB_HTTP_H -#define GLITE_LB_HTTP_H - -#ident "$Header$" - -#include "glite/lb/context.h" - -int edg_wll_ServerHTTP(edg_wll_Context); -int edg_wll_ServerHTTPProxy(edg_wll_Context); - -#endif /* GLITE_LB_HTTP_H */ diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c deleted file mode 100644 index 649592a..0000000 --- a/org.glite.lb.server/src/lb_proto.c +++ /dev/null @@ -1,1247 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "glite/lb/context-int.h" -#include "glite/lb/mini_http.h" -#include "glite/lb/xml_conversions.h" -#include "glite/jobid/strmd5.h" -#include "glite/lbu/trio.h" - -#include "lb_proto.h" -#include "lb_text.h" -#include "lb_html.h" -#include "stats.h" -#include "jobstat.h" -#include "get_events.h" -#include "purge.h" -#include "lb_xml_parse.h" -#include "lb_xml_parse_V21.h" -#include "db_supp.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" - - -static const char* const response_headers_dglb[] = { - "Cache-Control: no-cache", - "Server: edg_wll_Server/" PROTO_VERSION "/" COMP_PROTO, - "Content-Type: application/x-dglb", - NULL -}; - -static const char* const response_headers_html[] = { - "Cache-Control: no-cache", - "Server: edg_wll_Server/" PROTO_VERSION "/" COMP_PROTO, - "Content-Type: text/html", - NULL -}; - -volatile sig_atomic_t purge_quit = 0; - -extern int edg_wll_NotifNewServer(edg_wll_Context, - edg_wll_QueryRec const * const *, int flags, 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_ACCEPTED: msg = "Accepted"; 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; - -} - - -static int drain_text_request(char *request){ - int i = 0; - while (!isspace(request[i])) i++; - if (i < 5) - return 0; - if (! strncmp(request+i-5, "?text", 5)){ - if (i == 5) - strcpy(request+i-4, request+i); // keep '/' - else - strcpy(request+i-5, request+i); - return 1; - } - else - return 0; -} - -static int getUserNotifications(edg_wll_Context ctx, char *user, char ***notifids){ - char *q = NULL; - glite_lbu_Statement notifs = NULL; - char *notifc[1] = {NULL}; - - trio_asprintf(&q, "select notifid " - "from notif_registrations " - "where userid='%s'", - user); - if (edg_wll_ExecSQL(ctx, q, ¬ifs) < 0) goto err; - free(q); q = NULL; - - int n = 0; - *notifids = NULL; - while(edg_wll_FetchRow(ctx, notifs, sizeof(notifc)/sizeof(notifc[0]), NULL, notifc)){ - n++; - *notifids = realloc(*notifids, n*sizeof(**notifids)); - (*notifids)[n-1] = strdup(notifc[n-1]); - printf("Notif %s found\n", notifc[n-1]); - } - if (n){ - *notifids = realloc(*notifids, (n+1)*sizeof(**notifids)); - (*notifids)[n] = NULL; - } - return n; - -err: - return 0; -} - -static int getNotifInfo(edg_wll_Context ctx, char *notifId, notifInfo *ni){ - char *q = NULL; - glite_lbu_Statement notif = NULL; - char *notifc[4] = {NULL, NULL, NULL, NULL}; - - trio_asprintf(&q, "select destination, valid, conditions, flags " - "from notif_registrations " - "where notifid='%s'", - notifId); - if (edg_wll_ExecSQL(ctx, q, ¬if) < 0) goto err; - free(q); q = NULL; - - ni->notifid = strdup(notifId); - if (edg_wll_FetchRow(ctx, notif, sizeof(notifc)/sizeof(notifc[0]), NULL, notifc)){ - ni->destination = notifc[0]; - ni->valid = notifc[1]; - ni->conditions_text = notifc[2]; - parseJobQueryRec(ctx, notifc[2], strlen(notifc[2]), &(ni->conditions)); - ni->flags = atoi(notifc[3]); - } - else - goto err; - - return 0; - -err: - return -1; -} - -static void freeNotifInfo(notifInfo *ni){ - if (ni->notifid) free(ni->notifid); - if (ni->destination) free(ni->destination); - if (ni->valid) free(ni->valid); - if (ni->conditions){ - edg_wll_QueryRec **p; - int i; - for (p = ni->conditions; *p; p++){ - for (i = 0; (*p)[i].attr; i++) - edg_wll_QueryRecFree((*p)+i); - free(*p); - } - free(ni->conditions); - } - if (ni->conditions_text) free(ni->conditions_text); -} - -static int getJobsRSS(edg_wll_Context ctx, char *feedType, edg_wll_JobStat **statesOut){ - edg_wlc_JobId *jobsOut; - //edg_wll_JobStat *statesOut; - edg_wll_QueryRec **conds; - int i; - - char *can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); - - if (strncmp(feedType, "finished", strlen("finished")) == 0){ - conds = malloc(4*sizeof(*conds)); - conds[0] = malloc(2*sizeof(**conds)); - conds[0][0].attr = EDG_WLL_QUERY_ATTR_OWNER; - conds[0][0].op = EDG_WLL_QUERY_OP_EQUAL; - conds[0][0].value.c = can_peername; - conds[0][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - conds[1] = malloc(4*sizeof(**conds)); - conds[1][0].attr = EDG_WLL_QUERY_ATTR_STATUS; - conds[1][0].op = EDG_WLL_QUERY_OP_EQUAL; - conds[1][0].value.i = EDG_WLL_JOB_DONE; - conds[1][1].attr = EDG_WLL_QUERY_ATTR_STATUS; - conds[1][1].op = EDG_WLL_QUERY_OP_EQUAL; - conds[1][1].value.i = EDG_WLL_JOB_ABORTED; - conds[1][2].attr = EDG_WLL_QUERY_ATTR_STATUS; - conds[1][2].op = EDG_WLL_QUERY_OP_EQUAL; - conds[1][2].value.i = EDG_WLL_JOB_CANCELLED; - conds[1][3].attr = EDG_WLL_QUERY_ATTR_UNDEF; - conds[2] = malloc(2*sizeof(**conds)); - conds[2][0].attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME; - conds[2][0].op = EDG_WLL_QUERY_OP_GREATER; - conds[2][0].value.t.tv_sec = time(NULL) - ctx->rssTime; - conds[2][0].value.t.tv_usec = 0; - conds[2][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - conds[3] = NULL; - } - else if (strncmp(feedType, "running", strlen("running")) == 0){ - conds = malloc(4*sizeof(*conds)); - conds[0] = malloc(2*sizeof(**conds)); - conds[0][0].attr = EDG_WLL_QUERY_ATTR_OWNER; - conds[0][0].op = EDG_WLL_QUERY_OP_EQUAL; - conds[0][0].value.c = can_peername; - conds[0][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - conds[1] = malloc(2*sizeof(**conds)); - conds[1][0].attr = EDG_WLL_QUERY_ATTR_STATUS; - conds[1][0].op = EDG_WLL_QUERY_OP_EQUAL; - conds[1][0].value.i = EDG_WLL_JOB_RUNNING; - conds[1][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - conds[2] = malloc(2*sizeof(**conds)); - conds[2][0].attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME; - conds[2][0].op = EDG_WLL_QUERY_OP_GREATER; - conds[2][0].value.t.tv_sec = time(NULL) - ctx->rssTime; - conds[2][0].value.t.tv_usec = 0; - conds[2][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - conds[3] = NULL; - } - else if (strncmp(feedType, "aborted", strlen("aborted")) == 0){ - conds = malloc(4*sizeof(*conds)); - conds[0] = malloc(2*sizeof(**conds)); - conds[0][0].attr = EDG_WLL_QUERY_ATTR_OWNER; - conds[0][0].op = EDG_WLL_QUERY_OP_EQUAL; - conds[0][0].value.c = can_peername; - conds[0][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - conds[1] = malloc(2*sizeof(**conds)); - conds[1][0].attr = EDG_WLL_QUERY_ATTR_STATUS; - conds[1][0].op = EDG_WLL_QUERY_OP_EQUAL; - conds[1][0].value.i = EDG_WLL_JOB_ABORTED; - conds[1][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - conds[2] = malloc(2*sizeof(**conds)); - conds[2][0].attr = EDG_WLL_QUERY_ATTR_LASTUPDATETIME; - conds[2][0].op = EDG_WLL_QUERY_OP_GREATER; - conds[2][0].value.t.tv_sec = time(NULL) - ctx->rssTime; - conds[2][0].value.t.tv_usec = 0; - conds[2][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - conds[3] = NULL; - } - else{ - *statesOut = NULL; - return -1; - } - - edg_wll_QueryJobsServer(ctx, conds, 0, &jobsOut, statesOut); - - for (i = 0; conds[i]; i++) - free(conds[i]); - free(conds); - free(can_peername); - - return 0; -} - -static int hup_handler(int sig) { - purge_quit = 1; - return 0; -} - -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 **) (html? response_headers_html : response_headers_dglb); - 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 = NULL, *message = NULL; - int ret = HTTP_OK; - int html = outputHTML(headers); - int text = 0; //XXX: Plain text communication is special case of html here, hence when text=1, html=1 too - 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 */ - if (!html) { - 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 = strdup(request + sizeof(METHOD_GET)-1); - if (html) text = drain_text_request(requestPTR); - - - /* Is user authorised? */ - if (!ctx->peerName){ - ret = HTTP_UNAUTH; - edg_wll_SetError(ctx, EPERM, "user not authenticated"); - } - - /* GET /: Current User Jobs */ - else 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 - switch (edg_wll_UserJobsServer(ctx,&jobsOut,NULL)) { - case 0: if (text) - edg_wll_UserInfoToText(ctx, jobsOut, &message); - else if (html) - edg_wll_UserInfoToHTML(ctx, jobsOut, &message); - else ret = HTTP_OK; - break; - case ENOENT: ret = HTTP_NOTFOUND; break; - case EPERM: ret = HTTP_UNAUTH; break; - case EDG_WLL_ERROR_NOINDEX: ret = HTTP_UNAVAIL; 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=='/' - && strncmp(requestPTR, "/RSS", strlen("/RSS")) - && strncmp(requestPTR, "/NOTIF", strlen("/NOTIF")) - && *(requestPTR+strlen("/NOTIF")-1) != ':' - && !isspace(*(requestPTR+strlen("/NOTIF")-1))) { - 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_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_JobStatusServer(ctx,jobId,EDG_WLL_STAT_CLASSADS,&stat)) { - case 0: if (text) - edg_wll_JobStatusToText(ctx,stat,&message); - else 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 /NOTIF: All user's notifications*/ - } else if (strncmp(requestPTR, "/NOTIF", strlen("/NOTIF")) == 0 && (isspace(*(requestPTR+strlen("/NOTIF"))) - || isspace(*(requestPTR+strlen("/NOTIF:"))))){ - char **notifids = NULL; - char *can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); - char *userid = strmd5(can_peername, NULL); - getUserNotifications(ctx, userid, ¬ifids); - free(can_peername); - if (text) - edg_wll_UserNotifsToText(ctx, notifids, &message); - else if (html) - edg_wll_UserNotifsToHTML(ctx, notifids, &message); - else ret = HTTP_OK; - - /*GET /NOTIF:[notifId]: Notification info*/ - } else if (strncmp(requestPTR, "/NOTIF:", strlen("/NOTIF:")) == 0){ - notifInfo ni; - char *pomCopy, *pom; - pomCopy = strdup(requestPTR + 1); - for (pom=pomCopy; *pom && !isspace(*pom); pom++); - *pom = 0; - if (getNotifInfo(ctx, strrchr(pomCopy, ':')+1, &ni)){ - ret = HTTP_NOTFOUND; - goto err; - } - free(pomCopy); - - if (text) - edg_wll_NotificationToText(ctx, &ni, &message); - else - edg_wll_NotificationToHTML(ctx, &ni, &message); - - freeNotifInfo(&ni); - - /*GET /RSS:[feed type] RSS feed */ - } else if (strncmp(requestPTR, "/RSS:", strlen("/RSS:")) == 0){ - edg_wll_JobStat *states; - char *feedType; - int i; - int idx; - - feedType = requestPTR + strlen("/RSS:"); - if (getJobsRSS(ctx, feedType, &states) < 0){ - ret = HTTP_INTERNAL; - goto err; - } - - // check if owner and lastupdatetime is indexed - idx = 0; - for (i = 0; ctx->job_index[i]; i++) - if (ctx->job_index[i]->attr == EDG_WLL_QUERY_ATTR_OWNER) - idx++; - else if (ctx->job_index[i]->attr == EDG_WLL_QUERY_ATTR_LASTUPDATETIME) - idx++; - if (idx < 2){ - ret = HTTP_NOTFOUND; - edg_wll_SetError(ctx, ENOENT, "current index configuration does not support RSS feeds"); - } - edg_wll_RSSFeed(ctx, states, requestPTR, &message); - - /* GET [something else]: not understood */ - } else ret = HTTP_BADREQ; - free(requestPTR); requestPTR = NULL; - -/* POST */ - } else if (!strncmp(request,METHOD_POST,sizeof(METHOD_POST)-1)) { - - requestPTR = strdup(request + sizeof(METHOD_POST)-1); - if (html) text = drain_text_request(requestPTR); - - 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 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; - edg_wll_PurgeResult result; - struct sigaction sa; - sigset_t sset; - int fatal = 0, retval; - - ctx->p_tmp_timeout.tv_sec = 86400; - - memset(&request,0,sizeof(request)); - memset(&result,0,sizeof(result)); - - if ( !parsePurgeRequest(ctx,messageBody,(int (*)()) edg_wll_StringToStat,&request) ) { - /* do throttled purge on background if requested */ - if ((request.flags & EDG_WLL_PURGE_BACKGROUND)) { - retval = fork(); - - switch (retval) { - case 0: /* forked cleaner */ - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = hup_handler; - sigaction(SIGTERM, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - - sigemptyset(&sset); - sigaddset(&sset, SIGTERM); - sigaddset(&sset, SIGINT); - sigprocmask(SIG_UNBLOCK, &sset, NULL); - sigemptyset(&sset); - sigaddset(&sset, SIGCHLD); - sigprocmask(SIG_BLOCK, &sset, NULL); - break; - case -1: /* err */ - ret = HTTP_INTERNAL; - edg_wll_SetError(ctx, errno, "can't fork purge process"); - goto err; - default: /* client request handler */ - ret = HTTP_ACCEPTED; - /* to end this parent */ - edg_wll_SetError(ctx, EDG_WLL_ERROR_SERVER_RESPONSE, edg_wll_HTTPErrorMessage(ret)); - goto err; - } - } - - switch ( edg_wll_PurgeServer(ctx, (const edg_wll_PurgeRequest *)&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 EINVAL: ret = HTTP_INVALID; break; - case ENOMEM: fatal = 1; ret = HTTP_INTERNAL; break; - default: ret = HTTP_INTERNAL; break; - } - if (!html && !fatal) { - if (edg_wll_PurgeResultToXML(ctx, &result, &message)) - ret = HTTP_INTERNAL; - else - printf("%s", message); - } - - /* result is now packed in message, free it */ - 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); - } - - /* forked cleaner sends no results */ - if ((request.flags & EDG_WLL_PURGE_BACKGROUND)) { - *response = NULL; - free(message); - message = NULL; - if (requestPTR) free(requestPTR); - exit(0); - } - - } - - if ( request.jobs ) - { - int i; - for ( i = 0; request.jobs[i]; i++ ) - free(request.jobs[i]); - free(request.jobs); - } - - } - 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_DumpEventsServer(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_LoadEventsServer(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; - int flags; - time_t validity = -1; - int i,j; - - - if (parseNotifRequest(ctx, messageBody, &function, ¬ifId, - &address, &op, &validity, &conditions, &flags)) - 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, flags, - 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; - - free(requestPTR); requestPTR = NULL; - -/* other HTTP methods */ - } else ret = HTTP_NOTALLOWED; - -err: asprintf(response,"HTTP/1.1 %d %s",ret,edg_wll_HTTPErrorMessage(ret)); - *headersOut = (char **) (html ? response_headers_html : response_headers_dglb); - if ((ret != HTTP_OK && ret != HTTP_ACCEPTED) && text) - *bodyOut = edg_wll_ErrorToText(ctx,ret); - else if ((ret != HTTP_OK && ret != HTTP_ACCEPTED) && html) - *bodyOut = edg_wll_ErrorToHTML(ctx,ret); - else - *bodyOut = message; - - if (requestPTR) free(requestPTR); - - return edg_wll_Error(ctx,NULL,NULL); -} diff --git a/org.glite.lb.server/src/lb_proto.h b/org.glite.lb.server/src/lb_proto.h deleted file mode 100644 index b3aaba0..0000000 --- a/org.glite.lb.server/src/lb_proto.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef GLITE_LB_PROTO_H -#define GLITE_LB_PROTO_H - -#ident "$Header$" - -#include "glite/lb/context.h" -#include "glite/lb/query_rec.h" - -/* 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 */ -); - -typedef struct _notifInfo{ - char *notifid; - char *destination; - char *valid; - edg_wll_QueryRec **conditions; - char *conditions_text; - int flags; -} notifInfo; - -extern char *edg_wll_HTTPErrorMessage(int); - -extern int edg_wll_UserJobsServer(edg_wll_Context ctx, edg_wlc_JobId **jobs, edg_wll_JobStat **states); - -extern int edg_wll_QuerySequenceCodeServer(edg_wll_Context ctx, edg_wlc_JobId jobid, const char *source, char **seqcode); - -#endif /* GLITE_LB_PROTO_H */ diff --git a/org.glite.lb.server/src/lb_rss.c b/org.glite.lb.server/src/lb_rss.c deleted file mode 100644 index bbf88da..0000000 --- a/org.glite.lb.server/src/lb_rss.c +++ /dev/null @@ -1,77 +0,0 @@ -#ident "$Header:" - -#include "lb_rss.h" -#include "lb_proto.h" - -#include "glite/lb/context-int.h" - -#include -#include -#include -#include -#include - -#ifdef __GNUC__ -#define UNUSED_VAR __attribute__((unused)) -#else -#define UNUSED_VAR -#endif - -#define TR(type, field) \ - if (field){ \ - int l = asprintf(&pomA, type, (field)); \ - pomB = realloc(pomB, sizeof(*pomB)*(pomL+l+1)); \ - strcpy(pomB+pomL, pomA); \ - pomL += l; \ - free(pomA); pomA = NULL; \ - } - -#define TRC(str) \ - { \ - int l = asprintf(&pomA, str); \ - pomB = realloc(pomB, sizeof(*pomB)*(pomL+l+1)); \ - strcpy(pomB+pomL, pomA); \ - pomL += l; \ - free(pomA); pomA = NULL; \ - } - - -int edg_wll_RSSFeed(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat *states, char *request, char **message){ - char *pomA = NULL, *pomB = NULL; - int pomL = 0; - int i; - char *chid, *chstat, *rss_link, *tmp; - time_t time; - - TRC("\n\n\n"); - TRC("LB feed\n"); - asprintf(&rss_link, "https://%s:%i%s", ctx->srvName, ctx->srvPort, request); - for (tmp = rss_link; *tmp && !isspace(*tmp); tmp++); - *tmp = 0; - TR("%s\n", rss_link); - TRC("List of jobs."); - if (states) for (i = 0; states[i].state != EDG_WLL_JOB_UNDEF; i++){ - TRC("\n"); - TR("%s\n", (chid = edg_wlc_JobIdUnparse(states[i].jobId))); - TR("%s\n", chid); - TR("%s\n", chid); - // strip description to allow new lines - TR("Status: %s\n", (chstat = edg_wll_StatToString(states[i].state))); - TRC("]]>\n"); - time = states[i].stateEnterTime.tv_sec; - TR("State entered: %s\n", ctime(&time)); - TRC("]]>\n"); - TR("Destination: %s\n", states[i].destination); - TRC("\n"); - - - free(chid); - free(chstat); - } - TRC("\n"); - - *message = pomB; - - return 0; -} - diff --git a/org.glite.lb.server/src/lb_rss.h b/org.glite.lb.server/src/lb_rss.h deleted file mode 100644 index e690ee7..0000000 --- a/org.glite.lb.server/src/lb_rss.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef GLITE_LB_RSS_H -#define GLITE_LB_RSS_H - -#include "glite/lb/context-int.h" -#include "glite/lb/jobstat.h" - -int edg_wll_RSSFeed(edg_wll_Context ctx, edg_wll_JobStat *states, char *request, char **message); - -#endif /* GLITE_LB_RSS_H */ diff --git a/org.glite.lb.server/src/lb_text.c b/org.glite.lb.server/src/lb_text.c deleted file mode 100644 index 510441c..0000000 --- a/org.glite.lb.server/src/lb_text.c +++ /dev/null @@ -1,243 +0,0 @@ -#ident "$Header$" - -#include "lb_text.h" -#include "lb_proto.h" -#include "cond_dump.h" - -#include "glite/lb/context-int.h" -#include "glite/lb/xml_conversions.h" -#include "glite/lbu/trio.h" -#include "glite/lbu/db.h" - -#include -#include -#include -#include - -#ifdef __GNUC__ -#define UNUSED_VAR __attribute__((unused)) -#else -#define UNUSED_VAR -#endif - -static char *escape_text(char *text){ - int len = strlen(text); - char *ret = malloc((len+1)*sizeof(char)); - int reti = 0; - int retlen = len; - int i; - for (i = 0; i < len; i++){ - // escape '\' - if (text[i] == '\\'){ - ret[reti] = '\\'; - reti++; - retlen++; - ret = realloc(ret, (retlen+1)*sizeof(char)); - } - // replace newline by '\\n' - if (text[i] == '\n'){ - ret[reti] = '\\'; - reti++; - ret[reti] = 'n'; - retlen++; - ret = realloc(ret, (retlen+1)*sizeof(char)); - } - else - ret[reti] = text[i]; - reti++; - } - ret[reti] = 0; - return ret; -} - -int edg_wll_QueryToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut UNUSED_VAR, char **message UNUSED_VAR) -{ -/* not implemented yet */ - return -1; -} - -#define TR(name,type,field) \ -{ \ - int l; \ - if (field) \ - l = asprintf(&a,"%s=" type "\n", \ - name, field); \ - else \ - l = asprintf(&a,"%s=\n", name); \ - b = realloc(b, sizeof(*b)*(pomL+l+1)); \ - strcpy(b+pomL, a); \ - pomL += l; \ - free(a); a=NULL; \ -} - -int edg_wll_UserInfoToText(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message) -{ - char *a = NULL, *b; - int i = 0; - b = strdup(""); - - while (jobsOut[i]){ - char *chid = edg_wlc_JobIdUnparse(jobsOut[i]); - - if (i == 0) - asprintf(&a, "%s%s", b, chid); - else - asprintf(&a, "%s,%s", b, chid); - - free(chid); - free(b); - b = a; - i++; - } - - if (a){ - asprintf(&a, "User_jobs=%s\n", b); - free(b); - b = a; - } - b = a; - - asprintf(&a, "%sUser_subject=%s\n", b, ctx->peerName ? ctx->peerName: ""); - - *message = a; - - return 0; -} - -int edg_wll_UserNotifsToText(edg_wll_Context ctx, char **notifids, char **message){ - char *a = NULL, *b; - int i = 0; - b = strdup(""); - - while(notifids[i]){ - if (i == 0) - asprintf(&a, "%s", notifids[i]); - else - asprintf(&a, "%s,%s", b, notifids[i]); - free(b); - b = a; - i++; - } - if (b) - asprintf(&a, "User_notifications=%s\n", b); - - *message = a; - - return 0; -} - -int edg_wll_NotificationToText(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, char **message){ - char *a = NULL, *b = NULL, *cond, *flags; - int pomL = 0; - - TR("Notif_id", "%s", ni->notifid); - TR("Destination", "%s", ni->destination); - TR("Valid_until", "%s", ni->valid); - flags = edg_wll_stat_flags_to_string(ni->flags); - TR("Flags", "%s", flags); - free(flags); - if (! edg_wll_Condition_Dump(ni, &cond, 1)){ - TR("Conditions", "%s", cond); - } - free(cond); - - *message = b; - - return 0; -} - -/* construct Message-Body of Response-Line for edg_wll_JobStatus */ -int edg_wll_JobStatusToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat, char **message) -{ - char *a = NULL, *b = NULL; - char *chid,*chstat; - char *jdl,*rsl; - - jdl = strdup(""); - rsl = strdup(""); - - int pomL = 0; - - chid = edg_wlc_JobIdUnparse(stat.jobId); - - TR("Status","%s",(chstat = edg_wll_StatToString(stat.state))); - free(chstat); - TR("owner","%s",stat.owner); - TR("condorId","%s",stat.condorId); - TR("globusId","%s",stat.globusId); - TR("localId","%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)); - asprintf(&a, "%sstateEnterTime=%s", b, ctime(&time)); - free(b); b = a; - } - else{ - asprintf(&a, "%sstateEnterTime=", b); - free(b); b = a; - } - if ( (stat.lastUpdateTime.tv_sec) || (stat.lastUpdateTime.tv_usec) ) { - time_t time = stat.lastUpdateTime.tv_sec; - //TR("Last_update","%s",ctime(&time)); - asprintf(&a, "%slastUpdateTime=%s", b, ctime(&time)); - free(b); b = a; - } - else{ - asprintf(&a, "%slastUpdateTime=", b); - free(b); b = a; - } - TR("expectUpdate","%s",stat.expectUpdate ? "YES" : "NO"); - TR("expectFrom","%s",stat.expectFrom); - TR("location","%s",stat.location); - TR("destination","%s",stat.destination); - TR("cancelling","%s",stat.cancelling>0 ? "YES" : "NO"); - TR("cancelReason","%s",stat.cancelReason); - TR("cpuTime","%d",stat.cpuTime); - - TR("done_code","%d",stat.done_code); - TR("exit_code","%d",stat.exit_code); - - if (stat.jdl){ - char* my_jdl = escape_text(stat.jdl); - asprintf(&jdl,"jdl=%s\n", my_jdl); - free(my_jdl); - } - else - asprintf(&jdl,"jdl=\n"); - if (stat.rsl) - asprintf(&rsl,"rsl=%s\n", stat.rsl); - else - asprintf(&rsl,"rsl=\n"); - - asprintf(&a, "Job=%s\n" - "%s" - "%s" - "%s", - chid,b,jdl,rsl); - free(b); - - *message = a; - - free(chid); - free(jdl); - free(rsl); - return 0; -} - -char *edg_wll_ErrorToText(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,"Error=%s\n" - "Code=%d\n" - "Description=%s (%s)\n" - ,msg,e,et,ed); - - free(et); free(ed); - return out; -} - diff --git a/org.glite.lb.server/src/lb_text.h b/org.glite.lb.server/src/lb_text.h deleted file mode 100644 index c72de74..0000000 --- a/org.glite.lb.server/src/lb_text.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef GLITE_LB_TEXT_H -#define GLITE_LB_TEXT_H - -#include "glite/lb/context.h" -#include "glite/lb/events.h" -#include "glite/lb/jobstat.h" -#include "lb_proto.h" - -int edg_wll_QueryToText(edg_wll_Context,edg_wll_Event *,char **); -int edg_wll_JobStatusToText(edg_wll_Context, edg_wll_JobStat, char **); -int edg_wll_UserInfoToText(edg_wll_Context, edg_wlc_JobId *, char **); -int edg_wll_UserNotifsToText(edg_wll_Context ctx, char **notifids, char **message); -int edg_wll_NotificationToText(edg_wll_Context ctx, notifInfo *ni, char **message); -char *edg_wll_ErrorToText(edg_wll_Context,int); - -#endif /* GLITE_LB_TEXT */ diff --git a/org.glite.lb.server/src/lb_xml_parse.c.T b/org.glite.lb.server/src/lb_xml_parse.c.T deleted file mode 100644 index 88178dc..0000000 --- a/org.glite.lb.server/src/lb_xml_parse.c.T +++ /dev/null @@ -1,2079 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lbu/trio.h" -#include "glite/lbu/escape.h" - -#include "glite/lb/context-int.h" -#include "glite/lb/xml_conversions.h" - -#include "lb_xml_parse.h" - -#ifdef __GNUC__ -#define UNUSED_VAR __attribute__((unused)) -#else -#define UNUSED_VAR -#endif - -#define QUERY_EVENTS_BEGIN "\r\n" -#define QUERY_JOBS_BEGIN "\r\n" -#define PURGE_RESULT_BEGIN "\r\n" -#define DUMP_RESULT_BEGIN "\r\n" -#define LOAD_RESULT_BEGIN "\r\n" -#define INDEXED_ATTRS_BEGIN "\r\n" -#define NOTIF_RESULT_BEGIN "\r\n" -#define QUERY_SEQUENCE_CODE_RESULT_BEGIN "\r\n" - -#define STATS_RESULT_BEGIN "\r\n" - - -// XXX will be redundant soon -#define USERJOBS_BEGIN "\r\n" - - -static char *ops[] = { "equal","less","greater","within","unequal","changed" }, - *attrs[] = { "jobid","owner","status","location","destination", - "donecode","usertag","time","level","host","source", - "instance","type","chkpt_tag", "resubmitted", "parent_job", - "exitcode", "jdl", "stateentertime", "lastupdatetime", - "networkserver" }; - -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; ijob_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; ijob_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]); - } - if ( (i+1) == EDG_WLL_QUERY_ATTR_JDL_ATTR) { - if (!attr[0] || !attr[1]) - XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = NULL; - else if (strcmp(attr[0],"name")) { unexp() break;} - else XMLCtx->job_conditions[XMLCtx->row][XMLCtx->position].attr_id.tag = strdup(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; itype == 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; itype == 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") && strcasecmp(el,"target_runtime")) 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")) && (strcasecmp(el,"requestedValidity")) && - (strcasecmp(el,"flags")) ) 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; ichar_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 = glite_lbu_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_NETWORK_SERVER: - case EDG_WLL_QUERY_ATTR_USERTAG: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - 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: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - 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 = glite_lbu_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; - } - } - edg_wll_freeBuf(XMLCtx); - 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 = glite_lbu_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); - } - } - edg_wll_freeBuf(XMLCtx); - 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 = glite_lbu_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: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - 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: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - 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 = glite_lbu_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: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - 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 = glite_lbu_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; - } - } - - edg_wll_freeBuf(XMLCtx); - } - 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 = glite_lbu_UnescapeXML((const char *) XMLCtx->char_buf); - XMLCtx->purgeRequestGlobal.flags = edg_wll_string_to_purge_flags(s); - free(s); - } else if (!strcmp(XMLCtx->element,"target_runtime")) { - XMLCtx->purgeRequestGlobal.target_runtime = edg_wll_from_string_to_time_t(XMLCtx); - } - } - 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); - } - } - - edg_wll_freeBuf(XMLCtx); - 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 = glite_lbu_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[0])) - XMLCtx->dumpRequestGlobal.to = edg_wll_from_string_to_time_t(XMLCtx); - else - XMLCtx->dumpRequestGlobal.to = edg_wll_StringToDumpConst(s); - } - free(s); - } - - edg_wll_freeBuf(XMLCtx); - 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); - } - - edg_wll_freeBuf(XMLCtx); - 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(XMLCtx->element,"requestedValidity")) { - XMLCtx->notifValidity = 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->job_conditions); - } - else if (!strcmp(XMLCtx->element,"flags") && XMLCtx->char_buf) { - char *s; - - s = glite_lbu_UnescapeXML((const char *) XMLCtx->char_buf); - // XXX: check if it works - XMLCtx->flags = edg_wll_string_to_stat_flags(s); - free(s); - } - - } - - edg_wll_freeBuf(XMLCtx); - 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); - } - } - - edg_wll_freeBuf(XMLCtx); - 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); - } - } - - edg_wll_freeBuf(XMLCtx); - 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, time_t *validity, edg_wll_QueryRec ***conditions, int *flags) -{ - 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; - *validity = 0; - *conditions = NULL; - *flags = 0; - } else { - *function = XMLCtx.notifFunction; - *notifId = XMLCtx.notifId; - *address = XMLCtx.notifClientAddress; - *op = XMLCtx.notifChangeOp; - *validity = XMLCtx.notifValidity; - *conditions = XMLCtx.job_conditions; - *flags = XMLCtx.flags; - } - - - 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," \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 \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\r\n"); - pomB = pomA; - - if (jobsIn) { - trio_asprintf(&pomA,"%s\t\t%|Xs\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\r\n\r\n\t\t\r\n", - pomB, pomC); - } - - free(pomB); - free(pomC); - pomB = pomA; - - - len = asprintf(&pomA,"%s\t\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," %|Xs\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\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,"\r\n%s", - pomC, ctx->errCode,ctx->errDesc, pomB); - else - trio_asprintf(&pomA,"\r\n%s", - 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,""); - 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,""); - 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); - - if (ctx->job_index[i][j].attr == EDG_WLL_QUERY_ATTR_JDL_ATTR) - 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,""); - free(pomA); - pomA = pomB; - } - - asprintf(&pomB, "%s\t%s\r\n",pomA,""); - 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; -} - - diff --git a/org.glite.lb.server/src/lb_xml_parse.h b/org.glite.lb.server/src/lb_xml_parse.h deleted file mode 100644 index 5ea1e3d..0000000 --- a/org.glite.lb.server/src/lb_xml_parse.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef GLITE_LB_LB_XML_PARSE_H -#define GLITE_LB_LB_XML_PARSE_H - -#ident "$Header$" - -#include "glite/lb/context.h" -#include "glite/lb/jobstat.h" -#include "glite/lb/notif_rec.h" -#include "glite/lb/query_rec.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, time_t *validity, edg_wll_QueryRec ***conditions, int *flags); -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 /* GLITE_LB_LB_XML_PARSE_H */ diff --git a/org.glite.lb.server/src/lb_xml_parse_V21.c.T b/org.glite.lb.server/src/lb_xml_parse_V21.c.T deleted file mode 100644 index 0aa51e5..0000000 --- a/org.glite.lb.server/src/lb_xml_parse_V21.c.T +++ /dev/null @@ -1,1244 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lbu/trio.h" -#include "glite/lbu/escape.h" - -#include "glite/lb/context-int.h" -#include "glite/lb/xml_conversions.h" - -#include "lb_xml_parse_V21.h" - -#ifdef __GNUC__ -#define UNUSED_VAR __attribute__((unused)) -#else -#define UNUSED_VAR -#endif - -#define QUERY_EVENTS_BEGIN "\r\n" -#define QUERY_JOBS_BEGIN "\r\n" -#define PURGE_RESULT_BEGIN "\r\n" -#define DUMP_RESULT_BEGIN "\r\n" - -// XXX will be redundant soon -#define USERJOBS_BEGIN "\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; iconditions[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; iconditions[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; itype == 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; itype == 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; ichar_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 = glite_lbu_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 = glite_lbu_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 = glite_lbu_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 = glite_lbu_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 = glite_lbu_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 = glite_lbu_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," \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 \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\r\n"); - pomB = pomA; - - if (jobsIn) { - trio_asprintf(&pomA,"%s\t\t%|Xs\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\r\n\r\n\t\t\r\n", - pomB, pomC); - } - - free(pomB); - free(pomC); - pomB = pomA; - - - len = asprintf(&pomA,"%s\t\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," %|Xs\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\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,"\r\n%s", - pomC, ctx->errCode,ctx->errDesc, pomB); - else - trio_asprintf(&pomA,"\r\n%s", - 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; -} diff --git a/org.glite.lb.server/src/lb_xml_parse_V21.h b/org.glite.lb.server/src/lb_xml_parse_V21.h deleted file mode 100644 index 617ed45..0000000 --- a/org.glite.lb.server/src/lb_xml_parse_V21.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef GLITE_LB_LB_XML_PARSE_V21_H -#define GLITE_LB_LB_XML_PARSE_V21_H - -#ident "$Header$" - -#include "glite/lb/context.h" -#include "glite/lb/jobstat.h" -#include "glite/lb/query_rec.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 /* GLITE_LB_LB_XML_PARSE_V21_H */ diff --git a/org.glite.lb.server/src/lcas_lb.c b/org.glite.lb.server/src/lcas_lb.c deleted file mode 100644 index f216755..0000000 --- a/org.glite.lb.server/src/lcas_lb.c +++ /dev/null @@ -1,167 +0,0 @@ -#ident "$Header$" - -#include - -static char *modname = "lcas_lb"; -static char *authfile = NULL; - -int -plugin_initialize(int argc, char *argv[]) -{ - int i; - - lcas_log_debug(1, "%s-plugin_initialize(): passed arguments:\n",modname); - for (i=0; i < argc; i++) - lcas_log_debug(1, "\targ %d is %s\n", i,argv[i]); - - if (argc > 1) - authfile = lcas_findfile(argv[1]); - - if (authfile == NULL) { - lcas_log(0,"\t%s-plugin_initialize() error:" - ":access control policy file required!\n", - modname); - return LCAS_MOD_NOFILE; - } - - if (lcas_getfexist(1, authfile) == NULL) { - lcas_log(0, "\t%s-plugin_initialize() error:" - "Cannot find access control policy file: %s\n", - modname, authfile); - return LCAS_MOD_NOFILE; - } - - return LCAS_MOD_SUCCESS; -} - -static char * -get_event_name(lcas_request_t request) -{ - char *rsl = (char *) request; - - if (request == NULL) - return NULL; - - return strdup(rsl); -} - -static int -check_db_file(char *event, char *user_dn) -{ - FILE *db_file = NULL; - char line[1024]; - int found = 0, inside_block = 0, found_event = 0; - char *p, *q; - int ret; - - if (event == NULL || user_dn == NULL) - return LCAS_MOD_FAIL; - - db_file = fopen(authfile, "r"); - if (db_file == NULL) { - lcas_log_debug(1, "Failed to open policy file %s: %s\n", - authfile, strerror(errno)); - return LCAS_MOD_FAIL; - } - - ret = LCAS_MOD_FAIL; - while (fgets(line, sizeof(line), db_file) != NULL) { - p = strchr(line, '\n'); - if (p) - *p = '\0'; - p = line; - if (*p == '#') - continue; - - while (*p == ' ') - p++; - - if (inside_block) { - q = strchr(p, '}'); - if (q) - *q = '\0'; - if (found_event && ((strcmp(p, user_dn) == 0) || *p == '*')) { - found = 1; - break; - } - if (q) { - inside_block = 0; - } - } else { - q = strchr(p, '='); - if (q == NULL) - continue; - *q = '\0'; - inside_block = 1; - if (strncmp(p, event, strlen(event)) == 0 || *p == '*') - found_event = 1; - } - } - fclose(db_file); - - if (found) - ret = LCAS_MOD_SUCCESS; - - lcas_log_debug(1, "access %s\n", - (ret == LCAS_MOD_SUCCESS) ? "granted" : "denied"); - - return ret; -} - -int -plugin_confirm_authorization(lcas_request_t request, lcas_cred_id_t lcas_cred) -{ - char *user_dn; - char *event = NULL; - int ret; - - lcas_log_debug(1,"\t%s-plugin: checking LB access policy\n", - modname); - - event = get_event_name(request); - if (event == NULL) { - lcas_log_debug(1,"\t%s-plugin_confirm_authorization(): no event name specified\n", - modname); - return LCAS_MOD_FAIL; - } - - user_dn = lcas_get_dn(lcas_cred); - if (user_dn == NULL) { - lcas_log(0, "lcas.mod-lcas_get_fabric_authorization() error: user DN empty\n"); - ret = LCAS_MOD_FAIL; - goto end; - } - - ret = check_db_file(event, user_dn); - -end: - if (event) - free(event); - - return ret; -} - -int -plugin_terminate() -{ - lcas_log_debug(1, "%s-plugin_terminate(): terminating\n",modname); - - if (authfile) { - free(authfile); - authfile = NULL; - } - - return LCAS_MOD_SUCCESS; -} - -#if 0 -int -main(int argc, char *argv[]) -{ - authfile = "lcas_lb.db"; - - check_db_file(argv[1], argv[2]); - - return 0; -} -#endif diff --git a/org.glite.lb.server/src/load.c b/org.glite.lb.server/src/load.c deleted file mode 100644 index 5774af9..0000000 --- a/org.glite.lb.server/src/load.c +++ /dev/null @@ -1,223 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lbu/trio.h" - -#include "glite/lb/context-int.h" -#include "glite/lb/events_parse.h" -#include "glite/lb/ulm_parse.h" -#include "glite/lb/events.h" - -#include "store.h" -#include "purge.h" -#include "query.h" -#include "get_events.h" -#include "server_state.h" -#include "db_supp.h" -#include "lb_proto.h" - -static int read_line(char **buff, size_t *maxsize, int fd); - -int edg_wll_LoadEventsServer(edg_wll_Context ctx,const edg_wll_LoadRequest *req,edg_wll_LoadResult *result) -{ - int fd, - reject_fd = -1, - readret, i, ret; - size_t maxsize; - char *line = NULL, *errdesc, - 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"); - - memset(result,0,sizeof(*result)); - i = 0; - while ( 1 ) - { - /* Read one line - */ - if ( (readret = read_line(&line, &maxsize, fd)) == -1 ) { - 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; - - do { - if (edg_wll_Transaction(ctx)) goto err; - - edg_wll_StoreEvent(ctx, event, line, NULL); - - } while (edg_wll_TransNeedRetry(ctx)); - - if ((ret = edg_wll_Error(ctx, NULL, &errdesc)) != 0) { - int len = strlen(line), - total = 0, - written; - - 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_JobStatusServer(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); - } - -err: - if ( jobid ) - { - edg_wll_JobStat st; - - edg_wll_JobStatusServer(ctx, jobid, 0, &st); - edg_wll_FreeStatus(&st); - edg_wlc_JobIdFree(jobid); - } - - if ( reject_fd != -1 ) - close(reject_fd); - - 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++; - } -} diff --git a/org.glite.lb.server/src/mon-db.c b/org.glite.lb.server/src/mon-db.c deleted file mode 100644 index 553fc50..0000000 --- a/org.glite.lb.server/src/mon-db.c +++ /dev/null @@ -1,111 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/strmd5.h" -#include "glite/lb/context-int.h" -#include "glite/lb/jobstat.h" -#include "db_supp.h" -#include "openserver.h" - -#ifdef LB_PERF -#include "glite/lb/lb_perftest.h" -#include "srv_perf.h" - -enum lb_srv_perf_sink sink_mode; -#endif - -/* XXX: referenced global variables, unsed in mon */ -char *server_key,*server_cert; -int enable_lcas; - -static struct option opts[] = { - { "mysql",1,NULL,'m' }, - { "debug",0,NULL,'d' }, - { "verbose",0,NULL,'v' }, - { NULL, 0, NULL, 0 } -}; - -int debug = 0; - -static void usage(); -static void do_exit(edg_wll_Context,int); -static const char *me; - -int main(int argc,char **argv) -{ - int opt, caps; - char *dbstring = getenv("LBDB"); - int verbose = 0, rows = 0, fields = 0, njobs = 0, i; - edg_wll_Context ctx; - char *stmt = NULL, *status = NULL; - char *str[2]; - glite_lbu_Statement sh; - int jobs[EDG_WLL_NUMBER_OF_STATCODES]; - - me = strdup(argv[0]); - - while ((opt = getopt_long(argc,argv,"m:dv",opts,NULL)) != EOF) switch (opt) { - case 'm': dbstring = optarg; break; - case 'd': debug++; verbose++; break; - case 'v': verbose++; break; - case '?': usage(); exit(EX_USAGE); - } - - edg_wll_InitContext(&ctx); - for (i = 1; idbctx)) < 0 || !(caps & GLITE_LBU_DB_CAP_INDEX)) do_exit(ctx,EX_SOFTWARE); - if (asprintf(&stmt,"SELECT status,count(status) FROM states GROUP BY status;") < 0) do_exit(ctx,EX_OSERR); - if (verbose) fprintf(stderr,"mysql query: %s\n",stmt); - if ((rows = edg_wll_ExecSQL(ctx,stmt,&sh)) < 0) do_exit(ctx,EX_SOFTWARE); - if (verbose) fprintf(stderr,"number of states returned: %d\n",rows); - if (rows > 0) fprintf(stdout,"Number of jobs in each state: \n"); - for (i = 0; i < rows; i++) { - fields = edg_wll_FetchRow(ctx, sh, sizeof(str)/sizeof(str[0]),NULL,str); - if (fields != 2) { - glite_lbu_FreeStmt(&sh); - do_exit(ctx,EX_SOFTWARE); - } - jobs[atoi(str[0])] = atoi(str[1]); - if (str[0]) free(str[0]); - if (str[1]) free(str[1]); - } - for (i = 1; i\n" - " -m,--mysql use non-default database connection\n" - " -d,--debug print debug info (if any)\n" - " -v,--verbose be verbose\n", - me); -} diff --git a/org.glite.lb.server/src/notif_match.c b/org.glite.lb.server/src/notif_match.c deleted file mode 100644 index f351605..0000000 --- a/org.glite.lb.server/src/notif_match.c +++ /dev/null @@ -1,232 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lb/context-int.h" -#include "glite/lbu/trio.h" - -#include "lb_authz.h" -#include "lb_xml_parse.h" -#include "query.h" -#include "il_notification.h" -#include "db_supp.h" -#include "index.h" - -static int notif_match_conditions(edg_wll_Context,const edg_wll_JobStat *,const edg_wll_JobStat *,const char *); -static int notif_check_acl(edg_wll_Context,const edg_wll_JobStat *,const char *); - -extern int debug; - -int edg_wll_NotifExpired(edg_wll_Context,const char *); - -int edg_wll_NotifMatch(edg_wll_Context ctx, const edg_wll_JobStat *oldstat, const edg_wll_JobStat *stat) -{ - edg_wll_NotifId nid = NULL; - char *jobq,*ju = NULL,*jobc[6]; - glite_lbu_Statement jobs = NULL; - int ret,i; - time_t expires,now = time(NULL); - - char *cond_where = NULL; - char *cond_and_where = NULL; - - edg_wll_ResetError(ctx); - - if (ctx->notif_index) { - edg_wll_IColumnRec *notif_index_cols = ctx->notif_index_cols; - - for (i=0; notif_index_cols[i].qrec.attr; i++) { - char *val = NULL; - - if (notif_index_cols[i].qrec.attr != EDG_WLL_QUERY_ATTR_JDL_ATTR) { - val = edg_wll_StatToSQL(stat,notif_index_cols[i].qrec.attr); - assert(val != (char *) -1); - } - else { // Special Treatment for JDL attributes - val = edg_wll_JDLStatToSQL(stat,notif_index_cols[i].qrec); - } - - if (val) { - char *aux; - if (!cond_where) cond_where = strdup(""); - trio_asprintf(&aux, "%s or %s = %s",cond_where, - notif_index_cols[i].colname,val); - free(cond_where); - cond_where = aux; - free(val); - } - else if (notif_index_cols[i].qrec.attr == EDG_WLL_QUERY_ATTR_JDL_ATTR) { - char *aux; - if (!cond_and_where) cond_and_where = strdup(""); - trio_asprintf(&aux, "%s AND %s is NULL",cond_and_where, - notif_index_cols[i].colname); - free(cond_and_where); - cond_and_where = aux; - free(val); - } - } - } - - 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,n.flags " - "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' %s) %s", - ju = edg_wlc_JobIdGetUnique(stat->jobId),NOTIF_ALL_JOBS,cond_where ? cond_where : "",cond_and_where ? cond_and_where : ""); - - free(ju); ju = NULL; - - if (edg_wll_ExecSQL(ctx,jobq,&jobs) < 0) goto err; - - while ((ret = edg_wll_FetchRow(ctx,jobs,sizeof(jobc)/sizeof(jobc[0]),NULL,jobc)) > 0) { - if (now > (expires = glite_lbu_DBToTime(jobc[2]))) { - edg_wll_NotifExpired(ctx,jobc[0]); - if (debug) fprintf(stderr,"[%d] NOTIFY:%s expired at %s UTC\n", - getpid(),jobc[0],asctime(gmtime(&expires))); - } - else if (notif_match_conditions(ctx,oldstat,stat,jobc[4]) && - notif_check_acl(ctx,stat,jobc[3])) - { - char *dest, *aux; - int port; - - if (debug) { - fprintf(stderr,"NOTIFY: %s, job %s\n",jobc[0], - ju = edg_wlc_JobIdGetUnique(stat->jobId)); - free(ju); ju = NULL; - } - - dest = strdup(jobc[1]); - if ( !(aux = strchr(dest, ':')) ) - { - edg_wll_SetError(ctx, EINVAL, "Can't parse notification destination"); - free(dest); - for (i=0; ip_instance = strdup(""); - if ( edg_wll_NotifJobStatus(ctx, nid, dest, port, jobc[3], atoi(jobc[5]), expires, *stat) ) - { - free(dest); - for (i=0; ip_instance); ctx->p_instance = NULL; - if ( nid ) edg_wll_NotifIdFree(nid); - free(jobq); - glite_lbu_FreeStmt(&jobs); - return edg_wll_Error(ctx,NULL,NULL); -} - -int edg_wll_NotifExpired(edg_wll_Context ctx,const char *notif) -{ - char *dn = NULL,*dj = NULL; - - trio_asprintf(&dn,"delete from notif_registrations where notifid='%|Ss'",notif); - trio_asprintf(&dj,"delete from notif_jobs where notifid='%|Ss'",notif); - - if (edg_wll_ExecSQL(ctx,dn,NULL) < 0 || - edg_wll_ExecSQL(ctx,dj,NULL) < 0) - { - char *et,*ed; - edg_wll_Error(ctx,&et,&ed); - - syslog(LOG_WARNING,"delete notification %s: %s (%s)",notif,et,ed); - free(et); free(ed); - } - - free(dn); - free(dj); - return edg_wll_ResetError(ctx); -} - - -static int notif_match_conditions(edg_wll_Context ctx,const edg_wll_JobStat *oldstat, 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,oldstat,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); - int ret; - - edg_wll_ResetError(ctx); - if (strcmp(stat->owner,recip) == 0 - || edg_wll_amIroot(recip,NULL,ctx->super_users)) return 1; - - if (stat->acl == NULL) return 0; - - ret = edg_wll_DecodeACL(stat->acl,&acl->value); - if (ret) { - edg_wll_FreeAcl(acl); - edg_wll_SetError(ctx,EINVAL,"decoding ACL"); - return 0; - } - - acl->string = stat->acl; - - ret = edg_wll_CheckACL(ctx, acl, EDG_WLL_CHANGEACL_READ); - - acl->string = NULL; - edg_wll_FreeAcl(acl); - - return !ret; -} diff --git a/org.glite.lb.server/src/notification.c b/org.glite.lb.server/src/notification.c deleted file mode 100644 index 024b932..0000000 --- a/org.glite.lb.server/src/notification.c +++ /dev/null @@ -1,842 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/strmd5.h" -#include "glite/lbu/trio.h" -#include "glite/lb/context-int.h" -#include "glite/lb/xml_parse.h" - -#include "il_notification.h" -#include "query.h" -#include "db_supp.h" -#include "index.h" - - -static char *get_user(edg_wll_Context ctx, int create); -static int check_notif_request(edg_wll_Context, const edg_wll_NotifId, char **, 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 *); - -static int get_indexed_cols(edg_wll_Context,char const *,edg_wll_QueryRec **,char **); -static void adjust_validity(edg_wll_Context,time_t *); -static int drop_notif_request(edg_wll_Context, const edg_wll_NotifId); -static int check_notif_age(edg_wll_Context, const edg_wll_NotifId); - - -int edg_wll_NotifNewServer( - edg_wll_Context ctx, - edg_wll_QueryRec const * const *conditions, - int flags, - 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; - char *add_index = 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 - */ - - if (*valid == 0) - *valid = time(NULL) + ctx->notifDuration; - adjust_validity(ctx,valid); - - glite_lbu_TimeToDB(*valid, &time_s); - if ( !time_s ) - { - 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); - } - - do { - if (edg_wll_Transaction(ctx) != 0) goto cleanup; - - /* Format DB insert statement - */ - trio_asprintf(&q, - "insert into notif_registrations(notifid,destination,valid,userid,conditions,flags) " - "values ('%|Ss','%|Ss',%s,'%|Ss', '%|Ss', '%d')", - nid_s, addr_s? addr_s: address_override, time_s, owner, xml_conds, flags); - - if ( edg_wll_ExecSQL(ctx, q, NULL) < 0 ) - goto rollback; - - if (get_indexed_cols(ctx,nid_s,nconds,&add_index) || - (add_index && edg_wll_ExecSQL(ctx,add_index,NULL) < 0) - ) goto rollback; - - - 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_ExecSQL(ctx, q, NULL) < 0 ) - goto rollback; - } - else { - trio_asprintf(&q,"insert into notif_jobs(notifid,jobid) values ('%|Ss','%|Ss')", - nid_s,NOTIF_ALL_JOBS); - if ( edg_wll_ExecSQL(ctx, q, NULL) < 0 ) goto rollback; - - } - -rollback: - free(q); q= NULL; - free(add_index); add_index = NULL; - - } while (edg_wll_TransNeedRetry(ctx)); - -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); - free(add_index); - - 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 err; - } - - do { - if (edg_wll_Transaction(ctx) != 0) goto err; - - if ( check_notif_request(ctx, nid, NULL, NULL) ) - goto rollback; - - if ( check_notif_age(ctx, nid) ) { - drop_notif_request(ctx, nid); - goto rollback; - } - - /* Format time of validity - */ - - if (*valid == 0) - *valid = time(NULL) + ctx->notifDuration; - adjust_validity(ctx,valid); - - glite_lbu_TimeToDB(*valid, &time_s); - if ( !time_s ) - { - edg_wll_SetError(ctx, errno, "Formating validity time"); - goto rollback; - } - - /* 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 rollback; - } - 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)); - -rollback: - free(time_s); time_s = NULL; - free(addr_s); addr_s = NULL; - - } while (edg_wll_TransNeedRetry(ctx)); - -err: - 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 err; - - do { - if (edg_wll_Transaction(ctx) != 0) goto err; - - if ( check_notif_request(ctx, nid, NULL, NULL) ) - goto rollback; - - if ( check_notif_age(ctx, nid) ) { - drop_notif_request(ctx, nid); - goto rollback; - } - - 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 rollback; - - /* - * 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 rollback; - } - - /* Format DB insert statement - */ - if ( update_notif(ctx, nid, xml_conds, NULL, NULL) ) - goto rollback; - - if ( jobs ) - { - /* Format DB insert statement - */ - trio_asprintf(&q, "delete from notif_jobs where notifid='%|Ss'", nid_s); - if ( edg_wll_ExecSQL(ctx, q, NULL) < 0 ) - goto rollback; - - 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_ExecSQL(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_ExecSQL(ctx, q, NULL); - free(q); - trio_asprintf(&q,"delete from notif_registrations where notifid='%|Ss'", nid_s); - edg_wll_ExecSQL(ctx, q, NULL); - goto rollback; - } - } - } - break; - - case EDG_WLL_NOTIF_ADD: - break; - case EDG_WLL_NOTIF_REMOVE: - break; - default: - break; - } - -rollback: - free(q); q = NULL; - free(xml_conds); xml_conds = NULL; - free(nid_s); nid_s = NULL; - if ( jobs ) { - for ( i = 0; jobs[i]; i++ ) - free(jobs[i]); - free(jobs); jobs = NULL; - } - free(nconds); nconds = NULL; - - } while (edg_wll_TransNeedRetry(ctx)); - -err: - 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, *dest = NULL; - - do { - if (edg_wll_Transaction(ctx) != 0) goto err; - - if ( check_notif_request(ctx, nid, NULL, &dest) ) - goto rollback; - - if ( check_notif_age(ctx, nid) ) { - drop_notif_request(ctx, nid); - goto rollback; - } - - /* Format time of validity - */ - - if (*valid == 0) - *valid = time(NULL) + ctx->notifDuration; - adjust_validity(ctx,valid); - - glite_lbu_TimeToDB(*valid, &time_s); - if ( !time_s ) - { - edg_wll_SetError(ctx, errno, "Formating validity time"); - goto rollback; - } - - update_notif(ctx, nid, NULL, dest, time_s); - -rollback: - free(time_s); time_s = NULL; - free(dest); dest = NULL; - - } while (edg_wll_TransNeedRetry(ctx)); - -err: - return edg_wll_Error(ctx, NULL, NULL); -} - -int edg_wll_NotifDropServer( - edg_wll_Context ctx, - edg_wll_NotifId nid) -{ - do { - if (edg_wll_Transaction(ctx) != 0) goto err; - - if ( check_notif_request(ctx, nid, NULL, NULL) ) - goto rollback; - - if ( drop_notif_request(ctx, nid) ) - goto rollback; - -rollback: - ; - } while (edg_wll_TransNeedRetry(ctx)); - -err: - return edg_wll_Error(ctx, NULL, NULL); -} - - -static char *get_user(edg_wll_Context ctx, int create) -{ - glite_lbu_Statement stmt = NULL; - char *userid = NULL, - *q = NULL; - int ret; - char *can_peername = NULL; - - if ( !ctx->peerName ) - { - edg_wll_SetError(ctx, EPERM, "Annonymous access not allowed"); - goto cleanup; - } - can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); - trio_asprintf(&q, "select userid from users where cert_subj='%|Ss'", can_peername); - if ( edg_wll_ExecSQL(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(ctx, stmt, 1, NULL, &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, can_peername); - if ( edg_wll_ExecSQL(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 ) glite_lbu_FreeStmt(&stmt); - free(can_peername); - - return userid; -} - - -static int check_notif_request( - edg_wll_Context ctx, - const edg_wll_NotifId nid, - char **owner, - char **destination) -{ - char *nid_s = NULL, - *stmt, *user, *dest = NULL; - int ret; - glite_lbu_Statement s = NULL; - - - /* XXX: rewrite select below in order to handle cert_subj format changes */ - 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 destination from notif_registrations " - "where notifid='%|Ss' and userid='%|Ss' FOR UPDATE", - nid_s, user); - - if ( (ret = edg_wll_ExecSQL(ctx, stmt, &s)) < 0 ) - goto cleanup; - if ( ret == 0 ) - { - free(stmt); - trio_asprintf(&stmt, - "select notifid from notif_registrations where notifid='%|Ss'", nid_s); - ret = edg_wll_ExecSQL(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"); - goto cleanup; - } - else edg_wll_FetchRow(ctx,s,1,NULL,&dest); - -cleanup: - if ( !edg_wll_Error(ctx, NULL, NULL)) { - if (owner) *owner = user; else free(user); - if (destination) *destination = dest; else free(dest); - } - - if ( nid_s ) free(nid_s); - if ( stmt ) free(stmt); - glite_lbu_FreeStmt(&s); - - 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 = NULL, *aux = NULL; - int ret, port = 0; - - - if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) ) - { - edg_wll_SetError(ctx, EINVAL, "Malformed notification ID."); - 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='%|Ss'", - 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_ExecSQL(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_ExecSQL(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 || valid) { - char *v = strdup(valid),*v2 = strchr(v+1,'\''); - int expires; - - *v2 = 0; - expires = glite_lbu_DBToTime(v+1); -/* - printf("edg_wll_NotifChangeIL(ctx, %s, %s, %d)\n", - nid_s? nid_s: "nid", host, port); -*/ - if ( edg_wll_NotifChangeIL(ctx, nid, host, port, expires) ) { - char *errt, *errd; - - edg_wll_Error(ctx, &errt, &errd); - fprintf(stderr,"edg_wll_NotifChangeIL(): %s (%s)\n", errt, errd); - free(errt); - free(errd); - } - free(v); - } - - -cleanup: - if ( nid_s ) free(nid_s); - if ( stmt ) free(stmt); - if ( host ) free(host); - - return edg_wll_Error(ctx, NULL, NULL); -} - -static int get_indexed_cols(edg_wll_Context ctx,char const *notif,edg_wll_QueryRec **conds,char **update_out) -{ - int i,j; - edg_wll_IColumnRec * notif_cols = ctx->notif_index_cols; - char *cols = NULL,*aux; - - for (i=0; conds && conds[i]; i++) { - for (j=0; notif_cols[j].qrec.attr && - (notif_cols[j].qrec.attr != conds[i]->attr || - (notif_cols[j].qrec.attr == EDG_WLL_QUERY_ATTR_JDL_ATTR && - (!conds[i]->attr_id.tag || strcmp(notif_cols[j].qrec.attr_id.tag,conds[i]->attr_id.tag)) - ) - ); j++); - if (notif_cols[j].qrec.attr) { - if (conds[i][1].attr && conds[i][0].op != EDG_WLL_QUERY_OP_EQUAL) { - char buf[1000]; - sprintf(buf,"%s: indexed, only one and only `equals' condition supported", - notif_cols[j].colname); - - return edg_wll_SetError(ctx,EINVAL,buf); - } - trio_asprintf(&aux,"%s%c %s = '%|Ss'", - cols ? cols : "", - cols ? ',': ' ', - notif_cols[j].colname,conds[i]->value.c - ); - free(cols); - cols = aux; - - } - } - if (cols) trio_asprintf(&aux,"update notif_registrations set %s where notifid = '%s'", - cols,notif); - else aux = NULL; - - free(cols); - *update_out = aux; - return edg_wll_ResetError(ctx); -} - -static void adjust_validity(edg_wll_Context ctx,time_t *valid) -{ - time_t now; - - time(&now); - - if (*valid <= 0) { - *valid = now + ctx->notifDuration; - } - - if (ctx->peerProxyValidity && ctx->peerProxyValidity < *valid) - *valid = ctx->peerProxyValidity; - - if (*valid - now > ctx->notifDurationMax) - *valid = now + ctx->notifDurationMax; -} - -static int drop_notif_request(edg_wll_Context ctx, const edg_wll_NotifId nid) { - char *nid_s = NULL, - *stmt = NULL, - *errDesc; - int errCode; - - errCode = edg_wll_Error(ctx, NULL, &errDesc); - - if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) ) - goto rollback; - - trio_asprintf(&stmt, "delete from notif_registrations where notifid='%|Ss'", nid_s); - if ( edg_wll_ExecSQL(ctx, stmt, NULL) < 0 ) - goto rollback; - free(stmt); - trio_asprintf(&stmt, "delete from notif_jobs where notifid='%|Ss'", nid_s); - if ( edg_wll_ExecSQL(ctx, stmt, NULL) < 0 ) - goto rollback; - edg_wll_NotifCancelRegId(ctx, nid); - if (edg_wll_Error(ctx, NULL, NULL) == ECONNREFUSED) { - /* Let notification erase from DB, - * on notif-IL side it will be autopurged later anyway */ - - fprintf(stderr,"[%d] edg_wll_NotifDropServer() - NotifID found and dropped,"\ - " however, connection to notif-IL was refused (notif-IL not running?)\n", getpid()); - syslog(LOG_INFO,"edg_wll_NotifDropServer() - NotifID found and dropped,"\ - " however, connection to notif-IL was refused (notif-IL not running?)"); - - edg_wll_ResetError(ctx); - } - -rollback: - free(nid_s); nid_s = NULL; - free(stmt); stmt = NULL; - /* take precedence to previous error */ - if (errCode || errDesc) { - edg_wll_SetError(ctx, errCode, errDesc); - free(errDesc); - } - - return edg_wll_Error(ctx, NULL, NULL); -} - -static int check_notif_age(edg_wll_Context ctx, const edg_wll_NotifId nid) { - time_t now = time(NULL); - char *time_s = NULL, - *nid_s = NULL, - *q = NULL; - int ret; - - if ( !(nid_s = edg_wll_NotifIdGetUnique(nid)) ) - goto cleanup; - - glite_lbu_TimeToDB(now, &time_s); - if ( !time_s ) - { - edg_wll_SetError(ctx, errno, NULL); - goto cleanup; - } - - trio_asprintf(&q, "select notifid from notif_registrations WHERE notifid='%|Ss' AND valid < %s", nid_s, time_s); - if ( (ret = edg_wll_ExecSQL(ctx, q, NULL)) < 0 ) - goto cleanup; - - if (ret > 0) - edg_wll_SetError(ctx, EINVAL, "Notification expired."); - -cleanup: - free(q); - free(nid_s); - free(time_s); - return edg_wll_Error(ctx, NULL, NULL); -} diff --git a/org.glite.lb.server/src/openserver.c b/org.glite.lb.server/src/openserver.c deleted file mode 100644 index 8580ff5..0000000 --- a/org.glite.lb.server/src/openserver.c +++ /dev/null @@ -1,98 +0,0 @@ -#ident "$Header$" - -#include -#include -#include - -#include "glite/lb/context-int.h" -#include "openserver.h" -#include "db_supp.h" - -edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs) -{ - int ret, hit = 0, i; - char *table[1]; - char *cols[20]; - glite_lbu_Statement stmt; - - if (!ctx->dbctx && glite_lbu_InitDBContext((glite_lbu_DBContext*) &ctx->dbctx) != 0) { - char *ed; - - glite_lbu_DBError(ctx->dbctx, NULL, &ed); - edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_INIT, ed); - free(ed); - return EDG_WLL_ERROR_DB_INIT; - } - if (glite_lbu_DBConnect(ctx->dbctx,cs) != 0) return edg_wll_SetErrorDB(ctx); - - hit = 0; - // new columns added to jobs - if ((ret = glite_lbu_ExecSQL(ctx->dbctx, "DESC jobs", &stmt)) <= 0) goto err; - while (hit < 4 && (ret = glite_lbu_FetchRow(stmt, 1, NULL, cols)) > 0) { - assert(ret <= (int)(sizeof cols/sizeof cols[0])); - if (strcasecmp(cols[0], "proxy") == 0 || - strcasecmp(cols[0], "server") == 0 || - strcasecmp(cols[0], "grey") == 0 || - strcasecmp(cols[0], "nevents") == 0) hit++; - for (i = 0; i < ret; i++) free(cols[i]); - } - if (ret < 0) goto err; - glite_lbu_FreeStmt(&stmt); - // new columns added to events - if (glite_lbu_ExecSQL(ctx->dbctx, "DESC events", &stmt) <= 0) goto err; - while (hit < 5 && (ret = glite_lbu_FetchRow(stmt, 1, NULL, cols)) > 0) { - assert(ret <= (int)(sizeof cols/sizeof cols[0])); - if (strcasecmp(cols[0], "seqcode") == 0) hit++; - for (i = 0; i < ret; i++) free(cols[i]); - } - if (ret < 0) goto err; - glite_lbu_FreeStmt(&stmt); - // new columns added to notif_registrations - if (glite_lbu_ExecSQL(ctx->dbctx, "DESC notif_registrations", &stmt) <= 0) goto err; - while (hit < 6 && (ret = glite_lbu_FetchRow(stmt, 1, NULL, cols)) > 0) { - assert(ret <= (int)(sizeof cols/sizeof cols[0])); - if (strcasecmp(cols[0], "flags") == 0) hit++; - for (i = 0; i < ret; i++) free(cols[i]); - } - if (ret < 0) goto err; - glite_lbu_FreeStmt(&stmt); - - if (hit != 6) { - ret = edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_INIT, "old DB schema found, migration to new schema needed"); - goto close_db; - } - - // events_flesh table added - if (glite_lbu_ExecSQL(ctx->dbctx, "SHOW TABLES", &stmt) <= 0) goto err; - hit = 0; - while (hit < 3 && (ret = glite_lbu_FetchRow(stmt, 1, NULL, table)) > 0) { - if (strcasecmp(table[0], "events_flesh") == 0 || - strcasecmp(table[0], "zombie_jobs") == 0 || - strcasecmp(table[0], "zombie_suffixes") == 0 || - strcasecmp(table[0], "zombie_prefixes") == 0) hit++; - free(table[0]); - } - if (ret < 0) goto err; - glite_lbu_FreeStmt(&stmt); - if (hit != 3) { - ret = edg_wll_SetError(ctx, EDG_WLL_ERROR_DB_INIT, "events_flesh or zombie_jobs or zombie_prefixes or zombie_suffixes table not found, migration to new schema needed"); - goto close_db; - } - - return 0; - -err: - edg_wll_SetErrorDB(ctx); - glite_lbu_FreeStmt(&stmt); -close_db: - glite_lbu_DBClose(ctx->dbctx); - return ret; -} - -edg_wll_ErrorCode edg_wll_Close(edg_wll_Context ctx) -{ - glite_lbu_DBClose(ctx->dbctx); - glite_lbu_FreeDBContext(ctx->dbctx); - ctx->dbctx = NULL; - return edg_wll_ResetError(ctx); -} diff --git a/org.glite.lb.server/src/openserver.h b/org.glite.lb.server/src/openserver.h deleted file mode 100644 index 574e403..0000000 --- a/org.glite.lb.server/src/openserver.h +++ /dev/null @@ -1,6 +0,0 @@ -#ident "$Header$" - -#include "glite/lb/context.h" - -edg_wll_ErrorCode edg_wll_Open(edg_wll_Context ctx, char *cs); -edg_wll_ErrorCode edg_wll_Close(edg_wll_Context ctx); diff --git a/org.glite.lb.server/src/perftest_proxy.sh b/org.glite.lb.server/src/perftest_proxy.sh deleted file mode 100755 index 96d5094..0000000 --- a/org.glite.lb.server/src/perftest_proxy.sh +++ /dev/null @@ -1,128 +0,0 @@ -#!/bin/bash - -numjobs=10 - -# XXX - there must be better way to find stage -STAGEDIR=/home/michal/shared/egee/jra1-head/stage -. $STAGEDIR/sbin/perftest_common.sh - -LOGEVENT=${LOGEVENT:-$STAGEDIR/bin/glite-lb-logevent} - -DEBUG=${DEBUG:-0} - -SILENT=0 -while getopts "t:n:s" OPTION -do - case "$OPTION" in - "t") TEST_VARIANT=$OPTARG - ;; - - "n") numjobs=$OPTARG - ;; - - "s") SILENT=1 - ;; - - esac -done - -# CONSUMER_ARGS= -# PERFTEST_COMPONENT= -# COMPONENT_ARGS= -#LOGJOBS_ARGS="" - -check_test_files || exit 1 -check_file_executable $LOGEVENT || exit 1 - -SEQCODE="UI=999990:NS=9999999990:WM=999990:BH=9999999990:JSS=999990:LM=999990:LRMS=999990:APP=999990" - -purge_proxy () -{ - for jobid in $@ - do - $LOGEVENT -x -S /tmp/proxy.perfstore.sock -c $SEQCODE -j $jobid -s UserInterface -e Abort --reason Purge > /dev/null 2>&1 - done -} - -group_a () { -echo "----------------------------------" -echo "LB Proxy test" -echo "----------------------------------" -echo "Events are consumed:" -echo "1) before parsing" -echo "2) after parsing, before storing into database" -echo "3) after storing into db, before computing state" -echo "4) after computing state, before sending to IL" -echo "5) by IL" -echo "" -LOGJOBS_ARGS="-s /tmp/proxy.perf" -} - -echo -e "\tavg_job \t big_job \t avg_dag \t big_dag" - - -group_a_test_n () -{ - PERFTEST_CONSUMER=$STAGEDIR/bin/glite-lb-proxy - i=$1 - CONSUMER_ARGS="-d --perf-sink $i -p /tmp/proxy.perf" - export PERFTEST_NAME="proxy_test_$i" - echo -n "${i})" - run_test proxy $numjobs - print_result - # purge jobs from database - # we have to start proxy again - $PERFTEST_CONSUMER -d -p /tmp/proxy.perf -s 1 >/dev/null 2>&1 & - PID=$! - purge_proxy `$LOGJOBS -n $numjobs` - sleep 2 - shutdown $PID -} - -group_a_test_5 () -{ - PERFTEST_COMPONENT="$STAGEDIR/bin/glite-lb-proxy" - COMPONENT_ARGS="-d -p /tmp/proxy.perf --proxy-il-sock /tmp/interlogger.perf --proxy-il-fprefix /tmp/perftest.log" - - PERFTEST_CONSUMER="$STAGEDIR/bin/glite-lb-interlogd-perf-empty" - CONSUMER_ARGS="-d -s /tmp/interlogger.perf --file-prefix=/tmp/perftest.log" - export PERFTEST_NAME="proxy_test_5" - echo -n "5)" - run_test proxy $numjobs - print_result - $PERFTEST_COMPONENT -d -p /tmp/proxy.perf -s 1 >/dev/null 2>&1 & - PID=$! - purge_proxy `$LOGJOBS -n $numjobs` - sleep 2 - shutdown $PID - rm -f /tmp/perftest.log.* -} - -group="a" - -group_$group - -if [[ $SILENT -eq 0 ]] -then - while [[ -z $TEST_VARIANT ]] - do - echo -n "Your choice: " - read -e TEST_VARIANT - done - echo -e "\tavg_job \t big_job \t avg_dag \t big_dag" -fi - -if [[ "x$TEST_VARIANT" = "x*" ]] -then - TEST_VARIANT="1 2 3 4 5" -fi - -for variant in $TEST_VARIANT -do - if [[ "$variant" = "5" ]] - then - group_${group}_test_${variant} - else - group_${group}_test_n $variant - fi -done diff --git a/org.glite.lb.server/src/pretty_print_wrapper.cpp b/org.glite.lb.server/src/pretty_print_wrapper.cpp deleted file mode 100644 index df7c806..0000000 --- a/org.glite.lb.server/src/pretty_print_wrapper.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "pretty_print_wrapper.h" - -#include -#include -#include - -int pretty_print(char *jdl, char **formated_print){ - ClassAd *classad; - ClassAdParser parser; - - classad = parser.ParseClassAd(std::string(jdl), true); - if (! classad){ - *formated_print = NULL; - return -1; // not ClassAd data - } - - PrettyPrint pp; - std::string buf; - pp.Unparse(buf, classad); - *formated_print = strdup(buf.c_str()); - - return 0; -} - diff --git a/org.glite.lb.server/src/purge.h b/org.glite.lb.server/src/purge.h deleted file mode 100644 index 4252fdd..0000000 --- a/org.glite.lb.server/src/purge.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef GLITE_LB_PURGE_H -#define GLITE_LB_PURGE_H - -#ident "$Header" - -#include -#include "glite/lb/context.h" - -extern volatile sig_atomic_t purge_quit; - -/** 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, - edg_wll_PurgeResult *result -); - -/** LB Proxy purge implementation - * it gives no output - purge only one job from LB Proxy DB - */ -int edg_wll_PurgeServerProxy( - edg_wll_Context ctx, - glite_jobid_const_t 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 -); - -extern int edg_wll_DumpEventsServer(edg_wll_Context ctx,const edg_wll_DumpRequest *req,edg_wll_DumpResult *result); - -extern int edg_wll_LoadEventsServer(edg_wll_Context ctx,const edg_wll_LoadRequest *req,edg_wll_LoadResult *result); - -#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 /* GLITE_LB_PURGE_H */ diff --git a/org.glite.lb.server/src/query.c b/org.glite.lb.server/src/query.c deleted file mode 100644 index 737a860..0000000 --- a/org.glite.lb.server/src/query.c +++ /dev/null @@ -1,1757 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include "glite/jobid/strmd5.h" -#include "glite/lbu/trio.h" - -#include "glite/lb/context-int.h" -#include "glite/lb/xml_conversions.h" - - -#include "get_events.h" -#include "index.h" -#include "query.h" -#include "store.h" -#include "lb_authz.h" -#include "db_supp.h" -#include "jobstat.h" - -#define FL_SEL_STATUS 1 -#define FL_SEL_TAGS (1<<1) -#define FL_SEL_JOB (1<<2) -#define FL_FILTER (1<<3) // DB query result needs further filtering -#define FL_SEL_JDL (1<<4) // Retrieve classads while filtering - - -static int check_event_query_index(edg_wll_Context,const edg_wll_QueryRec **,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[12]; - edg_wll_Event *out = NULL; - glite_lbu_Statement sh = NULL; - int i = 0, - ret = 0, - offset = 0, limit = 0, - limit_loop = 1, - eperm = 0, - where_flags = 0; - char *peerid = NULL; - char *can_peername = NULL, *can_peerid = NULL; - char *j_old = NULL; - int match_status_old = 0; - edg_wll_JobStat state_out; - - edg_wll_ResetError(ctx); - memset(&state_out, 0, sizeof(edg_wll_JobStat)); - - 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) - if (!ctx->noIndex) goto cleanup; - - if ( job_conditions && *job_conditions && (*job_conditions)->attr && - !(job_where = jc_to_head_where(ctx, job_conditions, &where_flags)) && - edg_wll_Error(ctx,NULL,NULL) != 0 ) - /* XXX: covered with error check above: if (!ctx->noIndex) */ - goto cleanup; - - if (ctx->peerName) peerid = strdup(strmd5(ctx->peerName,NULL)); - can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); - if (can_peername) can_peerid = strdup(strmd5(can_peername,NULL)); - -/* 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,e.seqcode " - "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 %s %s", - where_flags & FL_SEL_STATUS ? ",states s" : "", - where_flags & 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 : "", - (ctx->isProxy) ? "AND j.proxy='1'" : "AND j.server='1'", - (where_flags & FL_FILTER) ? "order by j.dg_jobid" : ""); - - 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_ExecSQL(ctx, q, &sh); - if ( limit ) - free(q); - if ( ret < 0 ) - { - glite_lbu_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(ctx, sh, sizofa(res), NULL, res)) == sizofa(res) ) - { - int n = atoi(res[0]); - free(res[0]); - - /* Check non-indexed event conditions */ - if ( convert_event_head(ctx, res+2, out+i) || edg_wll_get_event_flesh(ctx, n, out+i) ) - { - char *et,*ed, *dbjob; - - /* Most likely sort of internal inconsistency. - * Must not be fatal -- just complain - */ - edg_wll_Error(ctx,&et,&ed); - - dbjob = res[2]; - fprintf(stderr,"%s event %d: %s (%s)\n",dbjob,n,et,ed); - syslog(LOG_WARNING,"%s event %d: %s (%s)",dbjob,n,et,ed); - free(et); free(ed); - edg_wll_ResetError(ctx); - - goto fetch_cycle_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; - } - - /* Check non-indexed job conditions */ - if (where_flags & FL_FILTER) { - if (!j_old || strcmp(res[2], j_old)) { - // event of different jobId than last time? - // => count jobStatus for this jobId - - if (j_old) edg_wll_FreeStatus(&state_out); - - if ( edg_wll_JobStatusServer(ctx, out[i].any.jobId, 0, &state_out) ) - { - edg_wll_FreeEvent(out+i); - if (edg_wll_Error(ctx,NULL,NULL) == EPERM) eperm = 1; - goto fetch_cycle_cleanup; - } - - if ( !(match_status_old = match_status(ctx, NULL, (&state_out), job_conditions)) ) - { - edg_wll_FreeEvent(out+i); - edg_wll_ResetError(ctx); /* check_strict_jobid() sets it */ - goto fetch_cycle_cleanup; - } - } - else - // the same jobId => the same jobStatus - // => the same result of match_status() - - if (!match_status_old) { - edg_wll_FreeEvent(out+i); - edg_wll_ResetError(ctx); /* check_strict_jobid() sets it */ - goto fetch_cycle_cleanup; - } - } - - // Auth checked in edg_wll_JobStatusServer above - if ( !(where_flags & FL_FILTER) && !noAuth ) - { - if (!ctx->peerName || (strcmp(res[1],peerid) && strcmp(res[1], can_peerid))) { - 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_CHANGEACL_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]); - free(j_old); - j_old=res[2]; - } -limit_cycle_cleanup: - glite_lbu_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); - free(j_old); - if (state_out.jobId) edg_wll_FreeStatus(&state_out); - free(peerid); - free(can_peername); free(can_peerid); - - return edg_wll_Error(ctx,NULL,NULL); -} - -int jobid_only_query(const edg_wll_QueryRec **conditions) { - int i = 0, j; - int jobid_in_this_or; - int not_jobid_only = 0; - - while(conditions[i]) { - jobid_in_this_or = 0; - j = 0; - while(conditions[i][j].attr) { - if(conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID) jobid_in_this_or++; - j++; - } - if (!jobid_in_this_or) not_jobid_only++; - i++; - } - - return not_jobid_only; -} - -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, - *zquery = NULL, - *res[3], - *dbjob, - *zomb_where = NULL, - *zomb_where_temp = NULL; - edg_wlc_JobId *jobs_out = NULL; - edg_wll_JobStat *states_out = NULL; - glite_lbu_Statement sh; - int i = 0, - j = 0, - ret = 0, - eperm = 0, - limit = 0, offset = 0, - limit_loop = 1, - where_flags = 0, - first_or; - - 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, &where_flags)) && edg_wll_Error(ctx,NULL,NULL) != 0) - /* XXX: covered with error check above: if (!ctx->noIndex) */ - goto cleanup; - - if ( (where_flags & FL_SEL_STATUS) ) - trio_asprintf(&qbase,"SELECT DISTINCT j.dg_jobid,j.userid " - "FROM jobs j, states s WHERE j.jobid=s.jobid %s %s AND %s ORDER BY j.jobid", - (job_where) ? "AND" : "", - (job_where) ? job_where : "", - (ctx->isProxy) ? "j.proxy='1'" : "j.server='1'"); - else - trio_asprintf(&qbase,"SELECT DISTINCT j.dg_jobid,j.userid " - "FROM jobs j WHERE %s %s %s " - "ORDER BY j.jobid", - (job_where) ? job_where : "", - (job_where) ? "AND" : "", - (ctx->isProxy) ? "j.proxy='1'" : "j.server='1'"); - - 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_ExecSQL(ctx, q, &sh); - if ( limit ) - free(q); - if ( ret < 0 ) - { - glite_lbu_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(ctx,sh,sizofa(res),NULL,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 some condition hits unindexed column or states of matching jobs wanted - - if ((where_flags & FL_FILTER) || !(flags & EDG_WLL_STAT_NO_STATES)) { - if ( edg_wll_JobStatusServer(ctx, jobs_out[i], (where_flags & FL_SEL_JDL)?(flags|EDG_WLL_STAT_CLASSADS):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 (where_flags & FL_FILTER) { - if ( !match_status(ctx, NULL, 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: - glite_lbu_FreeStmt(&sh); - } while ( limit_loop ); - - if ( !*jobs_out ) { - if(!jobid_only_query(conditions)) { - i = 0; - while(conditions[i]) { - asprintf(&zomb_where_temp,"%s%s", zomb_where ? zomb_where : "(", zomb_where ? " AND (" : ""); - free(zomb_where); - zomb_where = zomb_where_temp; zomb_where_temp = NULL; - - first_or = 0; - j = 0; - while(conditions[i][j].attr) { - - if(conditions[i][j].attr == EDG_WLL_QUERY_ATTR_JOBID) { - dbjob = glite_jobid_unparse(conditions[i][j].value.j); - trio_asprintf(&zomb_where_temp,"%s%s(result.dg_jobid='%|Ss')", - zomb_where, - first_or ? " OR " : "", - dbjob); - free(dbjob); - free(zquery); - free(zomb_where); - zomb_where = zomb_where_temp; zomb_where_temp = NULL; - first_or++; - } - j++; - } - asprintf(&zomb_where_temp,"%s)", zomb_where ? zomb_where : ""); - free(zomb_where); - zomb_where = zomb_where_temp; zomb_where_temp = NULL; - i++; - } - - trio_asprintf(&zquery,"SELECT * FROM " - "(SELECT concat('https://',p.prefix,j.jobid,s.suffix) AS dg_jobid FROM " - "zombie_suffixes AS s, zombie_jobs AS j, zombie_prefixes AS p WHERE " - "(s.suffix_id = j.suffix_id) AND (p.prefix_id = j.prefix_id)) AS result " - "WHERE %s", zomb_where); - - - j = edg_wll_ExecSQL(ctx,zquery,&sh); - - if (j > 0) { - jobs_out = (edg_wlc_JobId *) calloc(j+1, sizeof(*jobs_out)); - states_out = (edg_wll_JobStat *) calloc(j+1, sizeof(*states_out)); - - i = 0; - while ( (ret=edg_wll_FetchRow(ctx,sh,sizofa(res),NULL,res)) > 0 ) { - edg_wlc_JobIdParse(res[0], jobs_out+i); - edg_wlc_JobIdParse(res[0], &(states_out[i].jobId)); - states_out[i].state = EDG_WLL_JOB_PURGED; - free(res[0]); free(res[1]); free(res[2]); - - i++; - } - } - glite_lbu_FreeStmt(&sh); - } - } - - 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); -} - -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_JDL_ATTR: - 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 jdl_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: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - /* 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: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - glite_lbu_TimeToDB(ec[m][n].value.t.tv_sec, &dbt); - if ( conds ) - { - if ( ec[m][n].op == EDG_WLL_QUERY_OP_WITHIN ) - { - trio_asprintf(&aux, "%s", dbt); - free(dbt); - glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt); - 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); - free(dbt); - glite_lbu_TimeToDB(ec[m][n].value2.t.tv_sec, &dbt); - 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); - } - free(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, - *tmps2, - *dbt, - *cname = NULL, - msg[100]; - char *conds, *retconds; - char *can_peername = NULL; - - 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 && jc[m][n].op != EDG_WLL_QUERY_OP_GREATER) - { - 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: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - ct++; - break; - - case EDG_WLL_QUERY_ATTR_USERTAG: - ct++; - break; - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - 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 JDL attributes"); - return NULL; - } - 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: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - if ( !is_indexed(&(jc[m][n]), ctx) - || !(cname = edg_wll_QueryRecToColumn(&(jc[m][n]))) ) - { - *where_flags |= FL_FILTER; - break; - } - - *where_flags |= FL_SEL_STATUS; - - glite_lbu_TimeToDB(jc[m][n].value.t.tv_sec, &dbt); - if ( conds ) - { - if ( jc[m][n].op == EDG_WLL_QUERY_OP_WITHIN ) - { - trio_asprintf(&aux, "%s", dbt); - free(dbt); - glite_lbu_TimeToDB(jc[m][n].value2.t.tv_sec, &dbt); - trio_asprintf(&tmps, "%s OR (s.%s >= %s AND s.%s <= %s)", conds, cname, aux, cname, dbt); - free(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); - free(dbt); - glite_lbu_TimeToDB(jc[m][n].value2.t.tv_sec, &dbt); - trio_asprintf(&conds, "(s.%s >= %s AND s.%s <= %s)", cname, aux, cname, dbt); - free(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]))) ) - { - *where_flags |= FL_FILTER; - 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]))) ) - { - *where_flags |= FL_FILTER; - 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; - } - - tmps2 = edg_wll_gss_normalize_subj(jc[m][n].value.c, 0); - if (!jc[m][n].value.c && !can_peername) { - can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); - } - - *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), tmps2); - else - trio_asprintf(&tmps, "%s OR s.%s%s'%|Ss'", conds, cname, opToString(jc[m][n].op), can_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), tmps2); - else - trio_asprintf(&conds, "s.%s%s'%|Ss'", cname, opToString(jc[m][n].op), can_peername); - } - free(tmps2); - 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]))) ) - { - *where_flags |= FL_FILTER; - 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: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - if ( !is_indexed(&(jc[m][n]), ctx) - || !(cname = edg_wll_QueryRecToColumn(&(jc[m][n]))) ) - { - *where_flags |= FL_FILTER | FL_SEL_JDL; - 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 */ - *where_flags |= FL_FILTER; // just to be sure - 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; - } - } - - free(can_peername); - 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 = glite_lbu_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 = glite_lbu_DBToTime(f[8]); - e->any.arrived.tv_usec = 0; - free(f[8]); f[8] = NULL; - - e->any.seqcode = f[9]; - f[9] = 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 *oldstat, 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++ ) - { - // ignore operator CHANGED for non-notification matches - if ( (conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED) && !oldstat) continue; - - 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; - case EDG_WLL_QUERY_OP_CHANGED: - if ( oldstat->state != 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 (edg_wll_gss_equal_subj(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 (edg_wll_gss_equal_subj(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; - } - case EDG_WLL_QUERY_ATTR_NETWORK_SERVER: - if ( stat->network_server ) - { - if ( !strcmp(conds[i][j].value.c, stat->network_server) ) { - 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; - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - if (conds[i][j].op == EDG_WLL_QUERY_OP_CHANGED && - conds[i][j].attr_id.tag == NULL && - oldstat && - (oldstat->jdl == NULL || - (stat->jdl && strcmp(oldstat->jdl,stat->jdl)) - ) - ) goto or_satisfied; - - if (stat->jdl != NULL && conds[i][j].attr_id.tag) { - struct cclassad *ad = NULL; - char *extr_val = NULL; - - // Jobs that do not have a JDL come with blabla: - if (!strcmp(stat->jdl,"blabla")) break; - - ad = cclassad_create(stat->jdl); - if (ad) { - if (!cclassad_evaluate_to_string(ad, conds[i][j].attr_id.tag, &extr_val)) // Extract attribute value - extr_val = NULL; - cclassad_delete(ad); - } - if (extr_val) { - - if ( !strcmp(conds[i][j].value.c, extr_val) ) { - 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_STATEENTERTIME: - if ( !stat->stateEnterTime.tv_sec ) - break; - switch ( conds[i][j].op ) - { - case EDG_WLL_QUERY_OP_EQUAL: - if ( conds[i][j].value.t.tv_sec == stat->stateEnterTime.tv_sec ) goto or_satisfied; - break; - case EDG_WLL_QUERY_OP_UNEQUAL: - if ( conds[i][j].value.t.tv_sec != stat->stateEnterTime.tv_sec ) goto or_satisfied; - break; - case EDG_WLL_QUERY_OP_LESS: - if ( conds[i][j].value.t.tv_sec > stat->stateEnterTime.tv_sec ) goto or_satisfied; - break; - case EDG_WLL_QUERY_OP_GREATER: - if ( conds[i][j].value.t.tv_sec < stat->stateEnterTime.tv_sec ) goto or_satisfied; - break; - case EDG_WLL_QUERY_OP_WITHIN: - if ( conds[i][j].value.t.tv_sec <= stat->stateEnterTime.tv_sec - && conds[i][j].value2.t.tv_sec >= stat->stateEnterTime.tv_sec ) goto or_satisfied; - break; - } - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - if ( !stat->lastUpdateTime.tv_sec ) - break; - switch ( conds[i][j].op ) - { - case EDG_WLL_QUERY_OP_EQUAL: - if ( conds[i][j].value.t.tv_sec == stat->lastUpdateTime.tv_sec ) goto or_satisfied; - break; - case EDG_WLL_QUERY_OP_UNEQUAL: - if ( conds[i][j].value.t.tv_sec != stat->lastUpdateTime.tv_sec ) goto or_satisfied; - break; - case EDG_WLL_QUERY_OP_LESS: - if ( conds[i][j].value.t.tv_sec > stat->lastUpdateTime.tv_sec ) goto or_satisfied; - break; - case EDG_WLL_QUERY_OP_GREATER: - if ( conds[i][j].value.t.tv_sec < stat->lastUpdateTime.tv_sec ) goto or_satisfied; - break; - case EDG_WLL_QUERY_OP_WITHIN: - if ( conds[i][j].value.t.tv_sec <= stat->lastUpdateTime.tv_sec - && conds[i][j].value2.t.tv_sec >= stat->lastUpdateTime.tv_sec ) goto or_satisfied; - 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, glite_jobid_const_t 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 (%s:%d)",jobid,ctx->srvName,ctx->srvPort); - 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; -} diff --git a/org.glite.lb.server/src/request.c b/org.glite.lb.server/src/request.c deleted file mode 100644 index 99c54e8..0000000 --- a/org.glite.lb.server/src/request.c +++ /dev/null @@ -1,81 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include - -#include "glite/lb/il_string.h" -#include "glite/lb/il_msg.h" -#include "glite/lb/context-int.h" - -#include "store.h" -#include "db_supp.h" - -#ifdef __GNUC__ -#define UNUSED_VAR __attribute__((unused)) -#else -#define UNUSED_VAR -#endif - - -int -handle_il_message(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 = db_store(ctx, event.data); - - 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); -} - - diff --git a/org.glite.lb.server/src/seqcode.c b/org.glite.lb.server/src/seqcode.c deleted file mode 100644 index a9f18f3..0000000 --- a/org.glite.lb.server/src/seqcode.c +++ /dev/null @@ -1,65 +0,0 @@ -#ident "$Header$" - -#include - -#include "glite/lbu/trio.h" -#include "glite/lb/context-int.h" - -#include "get_events.h" -#include "store.h" -#include "jobstat.h" -/* -#include "lb_authz.h" -*/ -#include "db_supp.h" -#include "lb_proto.h" - - -int edg_wll_QuerySequenceCodeServer(edg_wll_Context ctx, edg_wlc_JobId jobid, const char *source, char **seqcode) -{ - glite_lbu_Statement 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_ExecSQL(ctx, stmt, &sh)) < 0 ) goto cleanup; - if ( nstates == 0 ) { - edg_wll_SetError(ctx, ENOENT, "no state in DB"); - goto cleanup; - } - if ( edg_wll_FetchRow(ctx, sh, 1, NULL, &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); - glite_lbu_FreeStmt(&sh); - if ( istat ) { - destroy_intJobStat(istat); - free(istat); - } - - return edg_wll_Error(ctx, NULL, NULL); -} diff --git a/org.glite.lb.server/src/server_state.c b/org.glite.lb.server/src/server_state.c deleted file mode 100644 index c2bd7bf..0000000 --- a/org.glite.lb.server/src/server_state.c +++ /dev/null @@ -1,56 +0,0 @@ -#ident "$Header$" - -#include - -#include "glite/lbu/trio.h" -#include "glite/lb/context-int.h" - -#include "server_state.h" -#include "db_supp.h" - -int edg_wll_GetServerState(edg_wll_Context ctx,const char *name,char **val) -{ - char *stmt = NULL; - glite_lbu_Statement 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_ExecSQL(ctx,stmt,&q)) { - case 0: edg_wll_SetError(ctx,ENOENT,name); break; - case -1: break; - default: edg_wll_FetchRow(ctx,q,sizeof(val)/sizeof(val[0]),NULL,val); break; - } - - glite_lbu_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_ExecSQL(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_ExecSQL(ctx,stmt,NULL); - } - break; - - default: abort(); - } - free(stmt); - return edg_wll_Error(ctx,NULL,NULL); -} diff --git a/org.glite.lb.server/src/server_state.h b/org.glite.lb.server/src/server_state.h deleted file mode 100644 index c3ded6d..0000000 --- a/org.glite.lb.server/src/server_state.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef GLITE_LB_SERVER_STATE_H -#define GLITE_LB_SERVER_STATE_H - -#ident "$Header$" - -#define EDG_WLL_STATE_DUMP_START "StartDump" -#define EDG_WLL_STATE_DUMP_END "EndDump" - -int edg_wll_GetServerState(edg_wll_Context,const char *,char **); -int edg_wll_SetServerState(edg_wll_Context,const char *,const char *); - -#endif /* GLITE_LB_SERVER_STATE_H */ diff --git a/org.glite.lb.server/src/srv_purge.c b/org.glite.lb.server/src/srv_purge.c deleted file mode 100644 index b09e62a..0000000 --- a/org.glite.lb.server/src/srv_purge.c +++ /dev/null @@ -1,900 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lbu/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 "query.h" -#include "get_events.h" -#include "purge.h" -#include "lb_xml_parse.h" -#include "db_calls.h" -#include "db_supp.h" -#include "jobstat.h" - - -#define DUMP_FILE_STORAGE "/tmp/" - -#define sizofa(a) (sizeof(a)/sizeof((a)[0])) - -extern volatile sig_atomic_t purge_quit; - -static const char* const resp_headers[] = { - "Cache-Control: no-cache", - "Server: edg_wll_Server/" PROTO_VERSION "/" COMP_PROTO, - "Content-Type: application/x-dglb", - NULL -}; - -static int purge_one(edg_wll_Context ctx,glite_jobid_const_t,int,int,int); -int unset_proxy_flag(edg_wll_Context ctx, glite_jobid_const_t job); -static int unset_server_flag(edg_wll_Context ctx, glite_jobid_const_t job); -static void purge_throttle(int jobs_to_exa, double purge_end, double *time_per_job, time_t *target_runtime); - - -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, glite_jobid_const_t job) -{ - switch ( purge_one(ctx, job, -1, 1, 1) ) { - case 0: - case ENOENT: - return(edg_wll_ResetError(ctx)); - break; - default: - return(edg_wll_Error(ctx,NULL,NULL)); - break; - } -} - -int edg_wll_PurgeServer(edg_wll_Context ctx,const edg_wll_PurgeRequest *request, edg_wll_PurgeResult *result) -{ - int i,parse = 0,dumpfile = -1; - edg_wlc_JobId job; - char *tmpfname = NULL; - int naffected_jobs = 0, ret; - double now, time_per_job, purge_end; - struct timeval tp; - int jobs_to_exa; - time_t target_runtime; - - - if (!ctx->noAuth) { - edg_wll_SetError(ctx,EPERM,"only superusers may purge"); - goto abort; - } - - edg_wll_ResetError(ctx); - memset(result, 0, sizeof(*result)); - - - if ( (request->flags & EDG_WLL_PURGE_SERVER_DUMP) && - ((dumpfile = edg_wll_CreateTmpPurgeFile(ctx, &tmpfname)) == -1 ) ) - goto abort; - - /* - should be changed so that only purged events are sent to whole-server dumps - (with this commented out, severely delayed events (>purge interval) can miss - whole-server dumps, but it is more acceptable than invoking whole-server dump - on each purge request (whole-server dumps are used rarely if at all) - 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_DumpEventsServer(ctx,&req,&res)) - { - if ( request->flags & EDG_WLL_PURGE_SERVER_DUMP ) - unlink(tmpfname); - goto abort; - } - } - */ - - /* throttle parameters */ - gettimeofday(&tp, NULL); - now = tp.tv_sec + (double)tp.tv_usec / 1000000.0; - purge_end = now + request->target_runtime; - target_runtime = request->target_runtime; - time_per_job = -1.0; - - if (request->jobs) { - - for (jobs_to_exa=0; request->jobs[jobs_to_exa]; jobs_to_exa++); - for (i=0; request->jobs[i] && !purge_quit; 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 { - purge_throttle(jobs_to_exa, purge_end, &time_per_job, &target_runtime); - if (purge_quit) break; - - switch (purge_one(ctx,job,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) { - 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: /* job does not exist, consider purged and ignore */ - edg_wll_ResetError(ctx); - break; - default: goto abort; - } - - } - edg_wlc_JobIdFree(job); - } - jobs_to_exa--; - } - } - else { - glite_lbu_Statement s; - char *job_s; - time_t timeout[EDG_WLL_NUMBER_OF_STATCODES], - start = time(NULL); - - for (i=0; itimeout[i] < 0) { // no specific timeout - if (request->timeout[i] == -2) //no purge - timeout[i] = request->timeout[i]; - else {// use server default - timeout[i] = ctx->purge_timeout[i]; - } - } - else timeout[i] = request->timeout[i]; //specific given - - if ((jobs_to_exa = edg_wll_ExecSQL(ctx, (ctx->isProxy) ? "select dg_jobid from jobs where proxy='1'" : - "select dg_jobid from jobs where server='1'", &s)) < 0) goto abort; - - while (edg_wll_FetchRow(ctx,s,1,NULL,&job_s) > 0 && !purge_quit) { - 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; - } - - purge_throttle(jobs_to_exa, purge_end, &time_per_job, &target_runtime); - if (purge_quit) break; - - memset(&stat,0,sizeof stat); - if (edg_wll_JobStatusServer(ctx,job,0,&stat)) { /* FIXME: replace by intJobStatus ?? */ - if (edg_wll_Error(ctx, NULL, NULL) == ENOENT) { - /* job purged meanwhile, ignore */ - edg_wll_ResetError(ctx); - continue; - } - edg_wll_FreeStatus(&stat); - goto abort; - } - - if (timeout[stat.state] >=0 && stat.lastUpdateTime.tv_sec && start-stat.lastUpdateTime.tv_sec > timeout[stat.state] && !check_strict_jobid(ctx,job)) - { - if (purge_one(ctx,job,dumpfile,request->flags&EDG_WLL_PURGE_REALLY_PURGE,ctx->isProxy)) { - edg_wll_FreeStatus(&stat); - if (edg_wll_Error(ctx, NULL, NULL) == ENOENT) { - /* job purged meanwhile, ignore */ - edg_wll_ResetError(ctx); - continue; - } - 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); - } - jobs_to_exa--; - } - glite_lbu_FreeStmt(&s); - } - -abort: - 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."); - } - } - - ret = edg_wll_Error(ctx,NULL,NULL); - if (ret == 0 || ret == ENOENT || ret == EPERM || ret == EINVAL) { - if ( request->flags & EDG_WLL_PURGE_SERVER_DUMP && tmpfname ) - { - edg_wll_CreatePurgeFileFromTmp(ctx, tmpfname, &(result->server_file)); - unlink(tmpfname); - } - } - - return edg_wll_Error(ctx,NULL,NULL); -} - -/* FIXME: defined but not used */ -#if 0 -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); - } -} -#endif - -static int dump_events(edg_wll_Context ctx, glite_jobid_const_t job, int dump, char **res) -{ - edg_wll_Event e; - int event; - - - event = atoi(res[0]); - free(res[0]); res[0] = NULL; - - res[0] = edg_wlc_JobIdUnparse(job); - if (convert_event_head(ctx,res,&e) || edg_wll_get_event_flesh(ctx,event,&e)) - { - char *et,*ed, *dbjob; - - - /* Most likely sort of internal inconsistency. - * Must not be fatal -- just complain - */ - edg_wll_Error(ctx,&et,&ed); - dbjob = edg_wlc_JobIdGetUnique(job); - 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); free(dbjob); - 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); - return edg_wll_Error(ctx,NULL,NULL); - } - 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); - - - return edg_wll_Error(ctx,NULL,NULL); -} - -static enum edg_wll_StatJobtype get_job_type(edg_wll_Context ctx, glite_jobid_const_t job) -{ - edg_wll_JobStat stat; - enum edg_wll_StatJobtype type; - - memset(&stat, 0, sizeof(stat)); - if (edg_wll_JobStatusServer(ctx, job, 0 /*no flags*/, &stat)) { - edg_wll_FreeStatus(&stat); - return(EDG_WLL_NUMBER_OF_JOBTYPES); - } - - type = stat.jobtype; - edg_wll_FreeStatus(&stat); - - return(type); -} - -static int get_jobid_suffix(edg_wll_Context ctx, glite_jobid_const_t job, enum edg_wll_StatJobtype jobtype, char **unique, char **suffix) -{ - char *ptr = NULL, *dbjob = NULL; - - - dbjob = glite_jobid_getUnique(job); - - switch (jobtype) { - case EDG_WLL_STAT_SIMPLE: - case EDG_WLL_STAT_DAG: - case EDG_WLL_STAT__PARTITIONABLE_UNUSED: - case EDG_WLL_STAT__PARTITIONED_UNUSED: - case EDG_WLL_STAT_COLLECTION: - // glite jobs, no suffix - *suffix = strdup(""); - *unique = strdup(dbjob); - break; - - case EDG_WLL_STAT_PBS: - // PBS jobs; suffix is everything starting from first '.' - ptr = strchr(dbjob,'.'); - if (ptr) { - *suffix = strdup(ptr); - ptr[0] = '\0'; - *unique = strdup(dbjob); - ptr[0] = '.'; - } - else { - edg_wll_SetError(ctx,EINVAL,"Uknown PBS job format"); - goto err; - } - break; - - case EDG_WLL_STAT_CONDOR: - // condor jobs - assert(0); // XXX: todo - break; - default: - edg_wll_SetError(ctx,EINVAL,"Uknown job type"); - goto err; - break; - } - -err: - free(dbjob); - - return edg_wll_Error(ctx, NULL, NULL); -} - -static int get_jobid_prefix(edg_wll_Context ctx, glite_jobid_const_t job, enum edg_wll_StatJobtype jobtype, char **prefix) -{ - char *ser = NULL; - - - switch (jobtype) { - case EDG_WLL_STAT_SIMPLE: - case EDG_WLL_STAT_DAG: - case EDG_WLL_STAT__PARTITIONABLE_UNUSED: - case EDG_WLL_STAT__PARTITIONED_UNUSED: - case EDG_WLL_STAT_COLLECTION: - // glite job prefix - ser = glite_jobid_getServer(job); - asprintf(prefix,"%s/",ser); - free(ser); - break; - - case EDG_WLL_STAT_PBS: - // PBS jobs; prefix same as glite job prefix - ser = glite_jobid_getServer(job); - asprintf(prefix,"%s/",ser); - free(ser); - break; - - case EDG_WLL_STAT_CONDOR: - // condor jobs - assert(0); // XXX: todo - break; - default: - edg_wll_SetError(ctx,EINVAL,"Uknown job type"); - goto err; - break; - } - -err: - return edg_wll_Error(ctx, NULL, NULL); -} - - -int purge_one(edg_wll_Context ctx,glite_jobid_const_t job,int dump, int purge, int purge_from_proxy_only) -{ - char *dbjob = NULL; - char *stmt = NULL; - glite_lbu_Statement q = NULL; - int ret,dumped = 0; - char *res[10]; - char *prefix = NULL, *suffix = NULL, *root = NULL; - char *prefix_id = NULL, *suffix_id = NULL; - int sql_retval; - - edg_wll_ResetError(ctx); - if ( !purge && dump < 0 ) return 0; - - do { - if (edg_wll_Transaction(ctx)) goto err; - - switch (edg_wll_jobMembership(ctx, job)) { - case DB_PROXY_JOB: - if (!ctx->isProxy) { - /* should not happen */ - goto commit; - } - /* continue */ - break; - case DB_SERVER_JOB: - if (purge_from_proxy_only) { - /* no action needed */ - goto commit; - } - if (ctx->isProxy) { - /* should not happen */ - goto commit; - } - /* continue */ - break; - case DB_PROXY_JOB+DB_SERVER_JOB: - if (ctx->isProxy) { - purge = 0; - if (unset_proxy_flag(ctx, job) < 0) { - goto rollback; - } - } - else { - purge = 0; - /* if server&proxy DB is shared ... */ - if (is_job_local(ctx,job) && purge_from_proxy_only) { - if (unset_proxy_flag(ctx, job) < 0) { - goto rollback; - } - } - else { - if (unset_server_flag(ctx, job) < 0) { - goto rollback; - } - } - } - break; - case 0: - // Zombie job (server=0, proxy=0)? should not happen; - // clear it to keep DB healthy - break; - default: - goto rollback; - break; - } - - dbjob = edg_wlc_JobIdGetUnique(job); /* XXX: strict jobid already checked */ - - if ( purge ) - { - enum edg_wll_StatJobtype jobtype = get_job_type(ctx, job); - - // get job prefix/suffix before its state is deleted - if ( jobtype == EDG_WLL_NUMBER_OF_JOBTYPES) goto rollback; - if ( get_jobid_suffix(ctx, job, jobtype, &root, &suffix) ) goto rollback; - if ( get_jobid_prefix(ctx, job, jobtype, &prefix) ) goto rollback; - - - } - - if ( purge ) - { - trio_asprintf(&stmt,"delete from jobs where jobid = '%|Ss'",dbjob); - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto rollback; - free(stmt); stmt = NULL; - - trio_asprintf(&stmt,"delete from states where jobid = '%|Ss'",dbjob); - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto rollback; - free(stmt); stmt = NULL; - } - - if ( purge ) - { - trio_asprintf(&stmt,"delete from status_tags where jobid = '%|Ss'",dbjob); - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto rollback; - free(stmt); stmt = NULL; - } - - if ( purge ) - { - /* Store zombie prefix */ - - // See if that prefix is already stored in the database - trio_asprintf(&stmt,"select prefix_id from zombie_prefixes where prefix = '%|Ss'", prefix); - - sql_retval = edg_wll_ExecSQL(ctx,stmt,&q); - free(stmt); stmt = NULL; - - if (sql_retval < 0) goto rollback; - - if (sql_retval == 0) { //prefix does not exist yet - glite_lbu_FreeStmt(&q); - - trio_asprintf(&stmt,"insert into zombie_prefixes (prefix) VALUES ('%|Ss')", prefix); - - if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback; - - free(stmt); stmt = NULL; - glite_lbu_FreeStmt(&q); - - // The record should exist now, however we need to look up the prefix_id - trio_asprintf(&stmt,"select prefix_id from zombie_prefixes where prefix = '%|Ss'", prefix); - - if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback; - free(stmt); stmt = NULL; - } - ret = edg_wll_FetchRow(ctx,q, 1, NULL, &prefix_id); - glite_lbu_FreeStmt(&q); - - - /* Store zombie suffix */ - - // See if that suffix is already stored in the database - trio_asprintf(&stmt,"select suffix_id from zombie_suffixes where suffix = '%|Ss'", suffix); - - sql_retval = edg_wll_ExecSQL(ctx,stmt,&q); - free(stmt); stmt = NULL; - - if (sql_retval < 0) goto rollback; - - if (sql_retval == 0) { //suffix does not exist yet - glite_lbu_FreeStmt(&q); - - trio_asprintf(&stmt,"insert into zombie_suffixes (suffix) VALUES ('%|Ss')", suffix); - - if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback; - - free(stmt); stmt = NULL; - glite_lbu_FreeStmt(&q); - - // The record should exist now, however we need to look up the suffix_id - trio_asprintf(&stmt,"select suffix_id from zombie_suffixes where suffix = '%|Ss'", suffix); - - if (edg_wll_ExecSQL(ctx,stmt,&q) <= 0) goto rollback; - free(stmt); stmt = NULL; - } - ret = edg_wll_FetchRow(ctx,q, 1, NULL, &suffix_id); - glite_lbu_FreeStmt(&q); - - - /* Store zombie job */ - - trio_asprintf(&stmt,"insert into zombie_jobs (jobid, prefix_id, suffix_id)" - " VALUES ('%|Ss', '%|Ss', '%|Ss')", root, prefix_id, suffix_id); - - if (edg_wll_ExecSQL(ctx,stmt,&q) < 0) { - if (edg_wll_Error(ctx, NULL, NULL) == EEXIST) { - /* job already among zombies */ - /* print warning but continue */ - /* erasing other jobs */ - char *et, *ed, *msg, *job_s; - - edg_wll_Error(ctx, &et, &ed); - job_s = glite_jobid_unparse(job); - - asprintf(&msg,"Warning: erasing job %s that already existed in this LB " - "(reused jobid or corruped DB) (%s: %s)",job_s,et,ed); - fprintf(stderr,"[%d] %s\n", getpid(), msg); - syslog(LOG_INFO,msg); - free(et); free(ed); free(msg); free(job_s); - edg_wll_ResetError(ctx); - } - else goto rollback; - } - glite_lbu_FreeStmt(&q); - free(stmt); stmt = NULL; - } - - if (dump >= 0) - trio_asprintf(&stmt, - "select event,code,prog,host,u.cert_subj,time_stamp,usec,level,arrived,seqcode " - "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); - - if (edg_wll_ExecSQL(ctx,stmt,&q) < 0) goto rollback; - free(stmt); stmt = NULL; - - dumped = 1; - while ((ret = edg_wll_FetchRow(ctx,q,sizofa(res),NULL,res)) > 0) { - int event; - - - event = atoi(res[0]); - - if (dump >= 0) { - int ret_dump, i; - - assert(ret == 10); - ret_dump = dump_events( ctx, job, dump, (char **) &res); - for (i=0; i now) { /* enough time */ - //fprintf(stderr, "[%d] sleeping for %lf second...\n", getpid(), target_this - now); - usleep(1e6*(target_this - now)); - } - if (target_this < now) { /* speed up */ - *time_per_job = (purge_end-now)/jobs_to_exa; - /* limit not catched, maximal speed */ - if (*time_per_job <= 0) { - *time_per_job = 0.0; - *target_runtime = 0; - } - } - //fprintf(stderr, "[%d] tpj: %lf\n", getpid(), *time_per_job); - } - -} diff --git a/org.glite.lb.server/src/stats.c b/org.glite.lb.server/src/stats.c deleted file mode 100644 index 187672a..0000000 --- a/org.glite.lb.server/src/stats.c +++ /dev/null @@ -1,453 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lb/events.h" -#include "glite/lb/jobstat.h" -#include "glite/lb/context-int.h" - -#include "glite/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, } - -}; - -extern int debug; - -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,stats[i].grpsize,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_remap(edg_wll_Stats *stats) -{ - int newgrpno = stats->map->grpno; - dprintf(("stats_remap: size changed (%d != %d), remap",stats->grpno,newgrpno)); - 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) { - if (debug) abort(); - return -1; - } - assert(stats->map->grpno == newgrpno); - stats->grpno = newgrpno; - return 0; -} - - -static int stats_inc_counter(edg_wll_Context ctx,const edg_wll_JobStat *jobstat,edg_wll_Stats *stats) -{ - int i,j; - char *sig = NULL; - 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 && stats_remap(stats)) { - edg_wll_SetError(ctx,errno,"shmem remap failed"); - goto cleanup; - } - - sig = str2md5base64(jobstat->destination); - - for (i=0; igrpno; 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+1) * 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; jarchives[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; jarchives[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"); - - /* remap the file if someone changed its size */ - if (stats->map->grpno != stats->grpno) - { - if (flock(stats->fd,LOCK_EX)) return edg_wll_SetError(ctx,errno,"flock()"); - if (stats_remap(stats)) { - edg_wll_SetError(ctx,errno,"shmem remap failed"); - goto cleanup; - } - } - - 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; igrpno; i++) { - if (!strcmp(sig,g->sig)) break; - g = (struct edg_wll_stats_group *) (((char *) g) + stats->grpsize); - } - - if (i == stats->grpno) { - dprintf(("no match: %s\n",sig)); - 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; jarchives[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; jarchives[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); -} - diff --git a/org.glite.lb.server/src/stats.h b/org.glite.lb.server/src/stats.h deleted file mode 100644 index 05d79e7..0000000 --- a/org.glite.lb.server/src/stats.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef GLITE_LB_STATS_H -#define GLITE_LB_STATS_H - -#ident "$Header$" - -#include "glite/lb/context.h" -#include "glite/lb/events.h" -#include "glite/lb/jobstat.h" -#include "glite/lb/query_rec.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 /* GLITE_LB_STATS_H */ diff --git a/org.glite.lb.server/src/store.c.T b/org.glite.lb.server/src/store.c.T deleted file mode 100644 index 365268f..0000000 --- a/org.glite.lb.server/src/store.c.T +++ /dev/null @@ -1,795 +0,0 @@ -#ident "$Header$" - -/* - -@@@AUTO - - * XXX: still lots of hardcoded stuff - * there's mapping db.column <-> event struct field - */ - -@@@LANG: C - -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/strmd5.h" -#include "glite/lbu/trio.h" - -#include "glite/lb/events_parse.h" -#include "glite/lb/context-int.h" -#include "glite/lb/log_proto.h" /* for EDG_WLL_LOG_USER_DEFAULT */ - -#include "store.h" -#include "get_events.h" -#include "lb_authz.h" -#include "jobstat.h" -#include "db_calls.h" -#include "db_supp.h" -#include "index.h" - -static int store_user(edg_wll_Context,const char *,const char *); -static int store_job(edg_wll_Context,glite_jobid_const_t,const char *, int, int, int, int); -/* FIXME: 'set_job_grey' defined but not used */ -static int set_job_grey(edg_wll_Context ctx, char *jobid); -static int store_flesh(edg_wll_Context,edg_wll_Event *,const char *ulm, char *,int); -/* FIXME: 'check_dup' defined but not used */ -static int check_dup(edg_wll_Context,edg_wll_Event *); -static int check_auth(edg_wll_Context,edg_wll_Event *e); -static void lowercase_usertag(edg_wll_Event *ev); - -void edg_wll_StoreAnonymous(edg_wll_Context ctx,int anon) { - ctx->allowAnonymous = anon; -} - - -/* !!! to be called from OPEN TRANSACTION only !!! - */ -int edg_wll_StoreEvent(edg_wll_Context ctx,edg_wll_Event *e,const char *ulm,int *seq) -{ - char *userid, *jobid, *stmt, *ssrc, *now_s, *stamp, *dummy, *max; - glite_lbu_Statement sh = NULL; - int next = 0xDEAD, nr; - - - userid = ssrc = jobid = stmt = now_s = stamp = dummy = max = NULL; - - lowercase_usertag(e); - jobid = edg_wlc_JobIdGetUnique(e->any.jobId); - glite_lbu_TimeToDB(e->any.timestamp.tv_sec, &stamp); - ssrc = edg_wll_SourceToString(e->any.source); - - if ( ctx->event_load ) - glite_lbu_TimeToDB(e->any.arrived.tv_sec, &now_s); - else - glite_lbu_TimeToDB(time(NULL), &now_s); - - edg_wll_ResetError(ctx); - switch (check_auth(ctx,e)) { - case 0: break; - case ENOENT: - /* job not registered */ - // should not happen, store_job_server_proxy() miscoded or going thu load? - goto clean; - break; - case EPERM: - if (!ctx->noAuth) goto clean; - edg_wll_ResetError(ctx); - break; - default: goto clean; - } - - trio_asprintf(&stmt,"select userid from jobs where jobid='%|Ss'", jobid); - - if (edg_wll_ExecSQL(ctx,stmt,&sh) < 0 || edg_wll_FetchRow(ctx,sh,1,NULL,&userid) < 0) goto clean; - if (sh) glite_lbu_FreeStmt(&sh); - free(stmt); stmt = NULL; - - -/* check duplicity */ - trio_asprintf(&stmt, - "select arrived from events where jobid='%|Ss' and code='%d'" - " and prog='%|Ss' and host='%|Ss' and time_stamp=%s and usec='%d'" - " and level='%d' and userid='%|Ss' and seqcode='%|Ss'", - jobid, (int) e->any.type, - ssrc,e->any.host, - stamp,e->any.timestamp.tv_usec, - e->any.level,userid, e->any.seqcode); - - if (edg_wll_ExecSQL(ctx,stmt,&sh) < 0) goto clean; - nr = edg_wll_FetchRow(ctx,sh,1,NULL,&dummy); - if (sh) glite_lbu_FreeStmt(&sh); - free(stmt); stmt = NULL; - free(dummy); - - if (nr < 0) goto clean; - if (nr > 0) { - /* possible duplicity (99%) */ - // XXX: check event flesh to be 100% sure - edg_wll_SetError(ctx,EEXIST,"duplicate event"); - goto clean; - } - /* else (nr == 0) -> unique event, continue */ - - -/* obtain number of stored events */ - trio_asprintf(&stmt, - "select nevents from jobs " - "where jobid = '%|Ss'",jobid); - - if (edg_wll_ExecSQL(ctx,stmt,&sh) < 0 || - edg_wll_FetchRow(ctx,sh,1,NULL,&max) < 0) goto clean; - glite_lbu_FreeStmt(&sh); - - next = (max && *max) ? atoi(max) : 0; - free(max); - - -/* store event */ - trio_asprintf(&stmt, - "insert into events(jobid,event,code,prog,host,time_stamp,usec,arrived,level,userid,seqcode) " - "values ('%|Ss',%d,%d,'%|Ss','%|Ss',%s,%d,%s,%d,'%|Ss','%|Ss')", - jobid,next, - (int) e->any.type, - ssrc,e->any.host, - stamp,e->any.timestamp.tv_usec, - now_s, e->any.level,userid, e->any.seqcode); - - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto clean; - free(stmt); stmt = NULL; - -/* increase number of stored events */ - trio_asprintf(&stmt, - "update jobs set nevents='%d'" - "where jobid = '%|Ss'", next+1, jobid); - - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) goto clean; - free(stmt); stmt = NULL; - - -/* store event record */ - if (store_flesh(ctx,e,ulm,jobid,next)) goto clean; - -clean: - free(now_s); - free(userid); - free(jobid); - free(stmt); - free(ssrc); - if (sh) glite_lbu_FreeStmt(&sh); - if (!edg_wll_Error(ctx,NULL,NULL) && seq) *seq = next; - free(stamp); - return edg_wll_Error(ctx,NULL,NULL); -} - -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_ExecSQL(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,glite_jobid_const_t job,const char *userid, int proxy, int server,int grey, int update) -{ - char *jobstr = edg_wlc_JobIdUnparse(job); - char *jobid = edg_wlc_JobIdGetUnique(job); - char *stmt; - char *srvName; - unsigned int srvPort; - -/* 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); - - if (ctx->isProxy) { - proxy = 1; - - /* If host&port in jobId match bkserver hostname and port and bkserver - * runs server service, mark the proxy job to belong to bkserver too - */ - edg_wlc_JobIdGetServerParts(job, &srvName, &srvPort); - if ( (ctx->serverRunning) && (ctx->srvPort == srvPort) && - !strcmp(ctx->srvName, srvName)) { - server=1; - } - } - else { - server = 1; - } - - if (update) { - trio_asprintf(&stmt,"update jobs set userid='%|Ss', proxy='%|Sd', server='%|Sd', grey='%|Sd' where jobid='%|Ss'", - userid,proxy,server,grey,jobid); - } - else { - trio_asprintf(&stmt,"insert into jobs(jobid,dg_jobid,userid,proxy,server,grey) " - "values ('%|Ss','%|Ss','%|Ss', '%|Sd', '%|Sd', '%|Sd')",jobid,jobstr,userid,proxy,server,grey); - } - - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) { - if (edg_wll_Error(ctx,NULL,NULL) == EEXIST && !update) - edg_wll_ResetError(ctx); - else - goto err; - } - free(stmt); stmt = NULL; - -err: - free(stmt); - free(jobstr); - free(jobid); - return edg_wll_Error(ctx,NULL,NULL); -} - - -static int set_job_grey(edg_wll_Context ctx, char *jobid) -{ - char *stmt; - - trio_asprintf(&stmt,"update jobs set grey='1' where jobid='%|Ss'", jobid); - edg_wll_ExecSQL(ctx,stmt,NULL); - - free(stmt); - return edg_wll_Error(ctx,NULL,NULL); -} - -/* test whether job shares LB proxy and server DB or not */ -int is_job_local(edg_wll_Context ctx, glite_jobid_const_t jobId) -{ - char *srvName = NULL; - unsigned int srvPort; - int ret; - - if (!ctx->serverRunning) return 0; /* XXX */ - - edg_wlc_JobIdGetServerParts(jobId, &srvName, &srvPort); - ret = ((ctx->srvPort == srvPort) && ctx->srvName && !strcmp(srvName,ctx->srvName)); - free(srvName); - - return(ret); -} - -int store_job_server_proxy(edg_wll_Context ctx, edg_wll_Event *event, int *register_to_JP) -{ - char *unique = edg_wlc_JobIdGetUnique(event->any.jobId); - char *q = NULL, *userid = NULL, *subj = NULL, *owner = NULL; - glite_lbu_Statement stmt = NULL; - int nar, grey = 0; - char *can_peername = NULL; - int local_job = is_job_local(ctx, event->any.jobId); - char *res[3] = {NULL, NULL, NULL}; - - - /* check auth */ - if (!ctx->isProxy && !ctx->peerName) - return edg_wll_SetError(ctx,EPERM,"LB server can't store using unauthenticated connection"); - if (ctx->isProxy && (!event->any.user || !strcmp(event->any.user,EDG_WLL_LOG_USER_DEFAULT)) ) - return edg_wll_SetError(ctx,EPERM,"LB proxy can't store using unauthenticated connection"); - - - trio_asprintf(&q,"select proxy,server,grey from jobs where jobid='%|Ss' for update", unique); - - nar = edg_wll_ExecSQL(ctx,q,&stmt); - free(q); q = NULL; - -/* XXX: greyjobs semantics is overloaded here: - * we trust the registration event content to specify job owner unconditionally. - * It's fine for the time being but should be solved with new authz. - * */ - - if (nar < 0) goto err; - else if (nar == 0) { - /* Job not stored yet */ - - if (event->any.type == EDG_WLL_EVENT_REGJOB) { - - /* XXX: directness is checked by any.user == peerName. Not perfect but better than event flags. */ - - if (!ctx->isProxy && !edg_wll_gss_equal_subj(event->any.user, ctx->peerName) && !ctx->greyjobs) { - edg_wll_SetError(ctx,EPERM,"job registration must go directly"); - goto err; - - } - /* else OK */ - } - else { - if (ctx->greyjobs) grey = 1; - else { - edg_wll_SetError(ctx, ENOENT, "job not registered"); - goto err; - } - } - - can_peername = grey ? strdup("GREY JOB") : edg_wll_gss_normalize_subj(event->any.user, 0); - userid = strdup(strmd5(can_peername, NULL)); - if (store_user(ctx,userid,can_peername)) goto err; - if (store_job(ctx,(glite_jobid_const_t) event->any.jobId, - userid, ctx->isProxy, local_job, grey, 0 )) goto err; - *register_to_JP = (local_job) ? REG_JOB_TO_JP : 0; - } - else { - /* Job already stored */ - - if (edg_wll_FetchRow(ctx,stmt,sizeof(res)/sizeof(res[0]),NULL,res) < 0) goto err; - if (stmt) { glite_lbu_FreeStmt(&stmt); stmt = NULL; } - - - if (ctx->greyjobs && !strcmp(res[2],"1") && - (event->any.type == EDG_WLL_EVENT_REGJOB)) - { - can_peername = edg_wll_gss_normalize_subj(event->any.user, 0); - userid = strdup(strmd5(can_peername, NULL)); - if (store_user(ctx,userid,can_peername)) goto err; - if (store_job(ctx,(glite_jobid_const_t) event->any.jobId, - userid, (ctx->isProxy || !strcmp(res[0],"1")), - !strcmp(res[1],"1") || (local_job ? ctx->serverRunning : 0), 0, 1)) goto err; - } - else { - /* check possible server vs. proxy registration ownership clash */ - if (event->any.type == EDG_WLL_EVENT_REGJOB) - { - trio_asprintf(&q,"select u.cert_subj from jobs j, users u " - "where j.jobid='%|Ss' and u.userid=j.userid",unique); - - if (edg_wll_ExecSQL(ctx,q,&stmt) < 0 - || edg_wll_FetchRow(ctx,stmt,1,NULL,&owner) < 0 - ) goto err; - - if (!edg_wll_gss_equal_subj(event->any.user, owner)) { - edg_wll_SetError(ctx,EPERM,"Job already registered with different owner. Rejecting event."); - goto err; - } - } - - /* update job membership if needed */ - // if (!strcmp(res[0],"1") && !strcmp(res[1],"1") ) /*nothing to do */; - if ( (!strcmp(res[0],"0") && ctx->isProxy) || (!strcmp(res[1],"0") && !ctx->isProxy) ) { - trio_asprintf(&q,"update jobs set server='1', proxy='1' where jobid='%|Ss'", - unique); - if (edg_wll_ExecSQL(ctx,q,NULL) < 0) goto err; - free(q); q = NULL; - } - } - } - -err: - free(res[0]); free(res[1]); free(res[2]); - if (stmt) glite_lbu_FreeStmt(&stmt); - free(subj); - free(userid); - if (q) free(q); - if (owner) free(owner); - - return 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,const char *ulm,char *jobid,int no) -{ -#ifndef LB_EVENTS_BLOB - struct { - char *key; - char *val; - } f[20]; - unsigned int i; -#endif - - char *stmt; - int err = 0; - - assert(ulm || e); - edg_wll_ResetError(ctx); - if (!ulm) ulm = edg_wll_UnparseEvent(ctx, e); - if (!ulm) return edg_wll_Error(ctx, NULL, NULL); - -#ifndef LB_EVENTS_BLOB - // in both ways if some preparsed flesh fields in events too - if (!e) { - if (edg_wll_ParseEvent(ctx, (char *)ulm, &e) != 0) return edg_wll_Error(ctx, NULL, NULL); - } - - 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($idxany.src_instance); - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL); - free(stmt); - } -#else - if (!ulm) ulm = edg_wll_UnparseEvent(ctx, e); - trio_asprintf(&stmt, "insert into events_flesh (jobid, event, ulm) values ('%|Ss', %d, '%|Ss')", jobid, no, ulm); - if (edg_wll_ExecSQL(ctx,stmt,NULL) < 0) err = edg_wll_Error(ctx,NULL,NULL); -#endif - - 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; - glite_lbu_Statement stmt = NULL; - - edg_wll_ResetError(ctx); - - if (!ctx->isProxy && !ctx->peerName) - return edg_wll_SetError(ctx,EPERM,"can't store using unauthenticated connection"); - - trio_asprintf(&q,"select u.cert_subj from jobs j, users u " - "where j.jobid='%|Ss' and u.userid=j.userid",jobid); - - if (edg_wll_ExecSQL(ctx,q,&stmt) < 0 - || edg_wll_FetchRow(ctx,stmt,1,NULL,&owner) < 0 - ) goto clean; - - if (!owner) { - 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: - if (!edg_wll_gss_equal_subj(owner,e->any.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) glite_lbu_FreeStmt(&stmt); - free(q); - free(owner); - return edg_wll_Error(ctx,NULL,NULL); -} - - -edg_wll_ErrorCode intJobStat_embryonic( - edg_wll_Context ctx, - glite_jobid_const_t jobid, - const edg_wll_RegJobEvent *e, - 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; - stat->pub.lastUpdateTime = e->timestamp; - -err: - return edg_wll_Error(ctx,NULL,NULL); -} - -/* - * Returns encoded SQL table states record for embryonic DAG subjob - */ - -static edg_wll_ErrorCode states_values_embryonic( - edg_wll_Context ctx, - glite_jobid_const_t 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 (intJobStat_embryonic(ctx, jobid, e, stat)) goto err; - - 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->pub, 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); -} - - -int register_subjobs_embryonic(edg_wll_Context ctx,const edg_wll_RegJobEvent *e) -{ - int i, j, err = 0; - edg_wlc_JobId *subjobs = NULL; - char *jobid = NULL, *jobid_md5 = NULL, *jobid_md5_old = NULL; - size_t jobid_len; - char *icnames = NULL, *values = NULL, *userid = NULL, *stmt = NULL; - int server, proxy, membership = 0; - glite_lbu_Statement sh = NULL; - - - 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); - - - /* 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; - - if ((membership = edg_wll_jobMembership(ctx, e->jobId)) < 0) goto err; - - proxy = membership & DB_PROXY_JOB; - server = membership & DB_SERVER_JOB; - - /* get userid of parent job */ - jobid = edg_wlc_JobIdGetUnique(e->jobId); - trio_asprintf(&stmt,"select userid from jobs where jobid='%|Ss'", jobid); - if (edg_wll_ExecSQL(ctx,stmt,&sh) < 0 || edg_wll_FetchRow(ctx,sh,1,NULL,&userid) < 0) goto err; - - for (i=0; insubjobs; i++) { - char *et,*ed,*job_s,*p,*p1; - - /* save jobid-userid relation into jobs table */ - if ((err = store_job(ctx, subjobs[i], userid, proxy, server, 0, 0))) - if (edg_wll_Error(ctx,&et,&ed) == EDEADLOCK) goto err; - - /* 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, icnames, values))) - edg_wll_Error(ctx,&et,&ed); - - 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]); - } - -err: - free(jobid_md5_old); //free the last one - free(icnames); - free(values); - /* free the rest of subjobs if DEADLOCK occurs */ - for (j=i; jnsubjobs; j++) edg_wlc_JobIdFree(subjobs[j]); - free(subjobs); - if (sh) glite_lbu_FreeStmt(&sh); - free(stmt); - - 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_ExecSQL(ctx,stmt,NULL); - free(stmt); - - trio_asprintf(&stmt, - "delete from long_fields where jobid='%|Ss' and event=%d", - jobid,event); - edg_wll_ExecSQL(ctx,stmt,NULL); - free(stmt); - - trio_asprintf(&stmt, - "delete from events_flesh where jobid='%|Ss' and event=%d", - jobid,event); - edg_wll_ExecSQL(ctx,stmt,NULL); - free(stmt); - - trio_asprintf(&stmt, - "delete from events where jobid='%|Ss' and event=%d", - jobid,event); - edg_wll_ExecSQL(ctx,stmt,NULL); - free (stmt); - - return edg_wll_Error(ctx,NULL,NULL); -} - - -/* 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') - */ -static void lowercase_usertag(edg_wll_Event *ev) -{ - int i; - - if ( ev->any.type == EDG_WLL_EVENT_USERTAG ) { - - for ( i = 0; ev->userTag.name[i] != '\0'; i++ ) - ev->userTag.name[i] = tolower(ev->userTag.name[i]); - } -} diff --git a/org.glite.lb.server/src/stored_master.c b/org.glite.lb.server/src/stored_master.c deleted file mode 100644 index f039a5e..0000000 --- a/org.glite.lb.server/src/stored_master.c +++ /dev/null @@ -1,168 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include - -#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; - size_t 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_GSS: - edg_wll_SetErrorGss(tmp_ctx,"gss_reader",&gss_code); - break; - - case EDG_WLL_GSS_ERROR_TIMEOUT: - edg_wll_SetError(tmp_ctx, ETIMEDOUT, "gss_reader"); - break; - - case EDG_WLL_GSS_ERROR_EOF: - edg_wll_SetError(tmp_ctx, ENOTCONN, NULL); - break; - - case EDG_WLL_GSS_ERROR_ERRNO: - edg_wll_SetError(tmp_ctx, errno, "gss_reader"); - break; - - default: - edg_wll_SetError(tmp_ctx, EDG_WLL_ERROR_GSS, "gss_reader"); - break; - } - ret = -2; /* -1 is used by read_il_data internals */ - } - - return(ret); -} - - -// XXX: for easier merge from RC31_3 -// after merge, it would be possible to glue -// edg_wll_StoreProtoProxy and edg_wll_StoreProtoServer together -int edg_wll_StoreProto(edg_wll_Context ctx) -{ - if (ctx->isProxy) return(edg_wll_StoreProtoProxy(ctx)); - else return(edg_wll_StoreProtoServer(ctx)); -} - - -int edg_wll_StoreProtoServer(edg_wll_Context ctx) -{ - char *buf; - size_t len; - int ret; - size_t total; - edg_wll_GssStatus gss_code; - - edg_wll_ResetError(ctx); - ret = read_il_data(ctx, &buf, gss_reader); - if (ret == -1) - return edg_wll_SetError(ctx,EIO,"interlogger protocol error"); - if (ret < 0) - return edg_wll_Error(ctx,NULL,NULL); -#ifdef LB_PERF - if (sink_mode == GLITE_LB_SINK_PARSE) glite_wll_perftest_consumeEventIlMsg(buf); - else -#endif - - handle_il_message(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, "gss_plain_reader"); - return -2; - } - - 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 == -1) - return edg_wll_SetError(ctx,EIO,"interlogger protocol error"); - if (ret < 0) - return edg_wll_Error(ctx,NULL,NULL); -#ifdef LB_PERF - if (sink_mode == GLITE_LB_SINK_PARSE) glite_wll_perftest_consumeEventIlMsg(buf); - else -#endif - if ( !(ret = handle_il_message(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; -} diff --git a/org.glite.lb.server/src/userjobs.c b/org.glite.lb.server/src/userjobs.c deleted file mode 100644 index fe91812..0000000 --- a/org.glite.lb.server/src/userjobs.c +++ /dev/null @@ -1,108 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/jobid/strmd5.h" -#include "glite/lbu/trio.h" -#include "glite/lb/context-int.h" - -#include "jobstat.h" -#include "db_supp.h" -#include "query.h" -#include "lb_proto.h" - -int edg_wll_UserJobsServer( - edg_wll_Context ctx, - edg_wlc_JobId **jobs, - edg_wll_JobStat **states) -{ - char *userid, *stmt = NULL, - *res = NULL; - char *can_peername; - int njobs = 0,ret,i,idx; - edg_wlc_JobId *out = NULL; - glite_lbu_Statement sth = NULL; - edg_wll_ErrorCode err = 0; - - edg_wll_ResetError(ctx); - - if (!ctx->peerName) { - return edg_wll_SetError(ctx,EPERM, "user not authenticated (edg_wll_UserJobs)"); - } - can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); - userid = strmd5(can_peername,NULL); - free(can_peername); - - trio_asprintf(&stmt,"select cert_subj from users where userid = '%|Ss'",userid); - - switch (edg_wll_ExecSQL(ctx,stmt,&sth)) { - case 0: edg_wll_SetError(ctx,ENOENT,ctx->peerName); - case -1: goto err; - default: - if (edg_wll_FetchRow(ctx,sth,1,NULL,&res) < 0) goto err; - if (!edg_wll_gss_equal_subj(ctx->peerName,res)) { - edg_wll_SetError(ctx,EDG_WLL_ERROR_MD5_CLASH,ctx->peerName); - goto err; - } - } - - glite_lbu_FreeStmt(&sth); - free(stmt); stmt = NULL; - free(res); res = NULL; - - trio_asprintf(&stmt,"select dg_jobid from jobs where userid = '%|Ss' and grey='0'",userid); - switch (njobs = edg_wll_ExecSQL(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(ctx,sth,1,NULL,&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; - } - - if (states) { - edg_wll_QueryRec oc[2],*ocp[2] = { oc, NULL }; - - oc[0].attr = EDG_WLL_QUERY_ATTR_OWNER; - oc[1].attr = EDG_WLL_QUERY_ATTR_UNDEF; - - if (check_job_query_index(ctx,ocp)) { - edg_wll_ResetError(ctx); - *states = NULL; - goto err; - } - - *states = calloc(njobs+1, sizeof(**states)); - idx = 0; - for (i = 0; i < njobs; i++) { - if (edg_wll_JobStatusServer(ctx, out[idx], -1, &(*states)[idx]) != 0) - edg_wll_ResetError(ctx); - idx++; - } - } -err: - free(res); - free(stmt); - glite_lbu_FreeStmt(&sth); - if ((err = edg_wll_Error(ctx,NULL,NULL))) { - if (out) { - for (i=0; i -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include - -#include "glite/lbu/trio.h" -#include "glite/lb/context-int.h" -#include "glite/lb/jobstat.h" - -#include "get_events.h" -#include "store.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; -} - -static char* format_strlist(char **list, char sep) -{ - char *a, *b; - int i; - - if (list && list[0]) { - a = strdup(list[0]); - for (i = 1; list[i]; i++) { - b = NULL; - trio_asprintf(&b,"%s%c%s",a,sep,list[i]); - free(a); - if (!b) { return strdup(""); } - a = b; - } - return a; - } else { - return strdup(""); - } -} - -char* write2rgma_statline(intJobStat *intstat) -{ - edg_wll_JobStat *stat = &intstat->pub; - char *stmt = NULL; - char *string_jobid, *string_stat, *string_server; - char *string_vo = NULL; - char *string_fqans = NULL; - - string_jobid = edg_wlc_JobIdUnparse(stat->jobId); - string_stat = edg_wll_StatToString(stat->state); - string_server = edg_wlc_JobIdGetServer(stat->jobId); - string_fqans = format_strlist(intstat->pub.user_fqans, '|'); - - 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 " - "UIHOST=%s " - "VOMS=%s " - "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->ui_host) ? (stat->ui_host) : "", - string_fqans ? string_fqans : "", - (stat->reason) ? (stat->reason) : "" - ); - - free(string_vo); - free(string_jobid); - free(string_stat); - free(string_server); - free(string_fqans); - - return stmt; -} - -void write2rgma_status(intJobStat *intstat) -{ - char *line; - int lcgmon = 0; - - if (rgma_fd < -1) return; - - line = write2rgma_statline(intstat); - 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(intJobStat *intstat, char *prev_statline) -{ - char *line; - int lcgmon = 0; - - if (rgma_fd < -1) return; - - line = write2rgma_statline(intstat); - 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 diff --git a/org.glite.lb.server/src/ws_fault.c b/org.glite.lb.server/src/ws_fault.c deleted file mode 100644 index 72107ac..0000000 --- a/org.glite.lb.server/src/ws_fault.c +++ /dev/null @@ -1,91 +0,0 @@ -#include - -#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 GFNUM SOAP_TYPE_lbt__genericFault -#else - #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; -#if GSOAP_VERSION >= 20709 - struct lbt__genericFault *f = soap_malloc(soap,sizeof *f); - struct lbt__genericFault *item = f; -#else - struct _genericFault *f = soap_malloc(soap,sizeof *f); - struct lbt__genericFault *item = f->lbe__genericFault = soap_malloc(soap, sizeof *item); -#endif - - memset(item, 0, sizeof(*item)); - - item->code = edg_wll_Error(ctx,&et,&ed); - item->text = soap_malloc(soap,strlen(et)+1); - strcpy(item->text, et); - free(et); - if (ed) { - item->description = soap_malloc(soap,strlen(ed)+1); - strcpy(item->description,ed); - free(ed); - } - -/* FIXME: assignment from incompatible pointer type */ - detail = soap_faultdetail(soap); - detail->__type = GFNUM; -#if GSOAP_VERSION >= 20700 - detail->fault = f; -#else - detail->value = f; -#endif - detail->__any = NULL; - - soap_receiver_fault(soap,"An error occurred, see detail",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 = (struct lbt__genericFault *)detail->fault; -#elif GSOAP_VERSION >= 20700 - f = ((struct _genericFault *) detail->fault) - ->lbe__genericFault; -#else - f = ((struct _genericFault *) detail->value) - ->lbe__genericFault; -#endif - if (f) edg_wll_SetError(ctx,f->code,f->description); - else edg_wll_SetError(ctx, EIO, "no or not parsable error from SOAP"); - } - else { - char *s; - - if (detail->__any) asprintf(&s, "SOAP: %s", detail->__any); - else asprintf(&s,"SOAP: %s", soap->version == 2 ? - GLITE_SECURITY_GSOAP_REASON(soap) : soap->fault->faultstring); - edg_wll_SetError(ctx,EINVAL,s); - free(s); - } -} diff --git a/org.glite.lb.server/src/ws_fault.h b/org.glite.lb.server/src/ws_fault.h deleted file mode 100644 index e6988e8..0000000 --- a/org.glite.lb.server/src/ws_fault.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef GLITE_LB_WS_FAULT_H -#define GLITE_LB_WS_FAULT_H - -#ident "$Header$" - -#include "glite/lb/context.h" - -extern void edg_wll_ErrToFault(const edg_wll_Context, struct soap *); -extern void edg_wll_FaultToErr(const struct soap *, edg_wll_Context); - -#endif /* GLITE_LB_WS_FAULT_H */ diff --git a/org.glite.lb.server/src/ws_query.c b/org.glite.lb.server/src/ws_query.c deleted file mode 100644 index cc8812b..0000000 --- a/org.glite.lb.server/src/ws_query.c +++ /dev/null @@ -1,449 +0,0 @@ -#include -#include - -#include "glite/lb/context-int.h" -#include "glite/lb/xml_parse.h" -#include "glite/lb/xml_conversions.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" -#include "lb_proto.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 - -extern int debug; -#define dprintf(x) if (debug) printf x - -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) -{ - dprintf(("[%d] WS call %s\n",getpid(),__FUNCTION__)); - - 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; - - - dprintf(("[%d] WS call %s\n",getpid(),__FUNCTION__)); - - 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 (debug) { - char *cjobid = NULL, *cflags = NULL; - - cjobid = edg_wlc_JobIdUnparse(j); - cflags = edg_wll_stat_flags_to_string(flags); - dprintf(("[%d] \n\t%s\n\t%s\n\n",getpid(),cflags,cjobid)); - free(cjobid); - free(cflags); - } - - if ( edg_wll_JobStatusServer(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 = SOAP_FAULT; - - - dprintf(("[%d] WS call %s\n",getpid(),__FUNCTION__)); - - 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; - - edg_wll_ResetError(ctx); - if ( edg_wll_SoapToQueryCondsExt(in->conditions, in->__sizeconditions, &conditions) ) { - edg_wll_SetError(ctx, ENOMEM, "Couldn't create internal structures"); - goto err; - } - edg_wll_SoapToJobStatFlags(in->flags, &flags); - - if (debug) { - char *message = NULL; - - if (edg_wll_QueryJobsRequestToXML(ctx, - (const edg_wll_QueryRec **) conditions, - flags, &message)) { - dprintf(("[%d] %s\n",getpid(),"edg_wll_QueryJobsRequestToXML() returned error")); - } - else { - dprintf(("[%d] \n%s\n\n",getpid(),message)); - } - free(message); - } - - if (edg_wll_QueryJobsServer(ctx, (const edg_wll_QueryRec **)conditions, flags, &jobs, &states) != 0) goto err; - - if (edg_wll_JobsQueryResToSoap(soap, jobs, states, out) != SOAP_OK) goto err; - ret = SOAP_OK; - -err: - if ( ret == SOAP_FAULT ) edg_wll_ErrToFault(ctx, soap); -cleanup: - freeQueryRecsExt(conditions); - freeJobIds(jobs); - freeJobStats(states); - - return ret; -} - - -SOAP_FMAC5 int SOAP_FMAC6 __lb__UserJobs( - struct soap *soap, - struct _lbe__UserJobs *in, - struct _lbe__UserJobsResponse *out) -{ - edg_wll_Context ctx; - edg_wlc_JobId *jobs; - edg_wll_JobStat *states; - - - dprintf(("[%d] WS call %s\n",getpid(),__FUNCTION__)); - - ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap); - memset(out, 0, sizeof *out); - if (edg_wll_UserJobsServer(ctx, &jobs, &states) != 0) goto fault; - if (edg_wll_UserJobsResToSoap(soap, jobs, states, out) != SOAP_OK) { - edg_wll_SetError(ctx, ENOMEM, "Couldn't create internal structures"); - goto freefault; - } - freeJobIds(jobs); - freeJobStats(states); - return SOAP_OK; -freefault: - freeJobIds(jobs); - freeJobStats(states); -fault: - edg_wll_ErrToFault(ctx, soap); - return SOAP_FAULT; -} - - -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; - - - dprintf(("[%d] WS call %s\n",getpid(),__FUNCTION__)); - - 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 (debug) { - char *message = NULL; - - if (edg_wll_QueryEventsRequestToXML(ctx, - (const edg_wll_QueryRec **) job_conditions, - (const edg_wll_QueryRec **) event_conditions, - &message)) { - dprintf(("[%d] %s\n",getpid(),"edg_wll_QueryEventsRequestToXML() returned error")); - } - else { - dprintf(("[%d] \n%s\n\n",getpid(),message)); - } - free(message); - } - - 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; -} - -SOAP_FMAC5 int SOAP_FMAC6 __lb__GetServerLimit( - struct soap *soap, - struct _lbe__GetServerLimit *in, - struct _lbe__GetServerLimitResponse *out -) -{ - edg_wll_Context ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap); - - out->limit = ctx->hardJobsLimit; - return SOAP_OK; -} - -SOAP_FMAC5 int SOAP_FMAC6 __lb__GetIndexedAttrs( - struct soap *soap, - struct _lbe__GetIndexedAttrs *in, - struct _lbe__GetIndexedAttrsResponse *out -) -{ - edg_wll_Context ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap); - - if (ctx->job_index) - return edg_wll_QueryCondsExtToSoap(soap, - (const edg_wll_QueryRec **) ctx->job_index, - &out->__sizeattrs,&out->attrs); - else { - edg_wll_SetError(ctx,ENOENT,"no indexed attributes"); - edg_wll_ErrToFault(ctx, soap); - return SOAP_FAULT; - } -} - -SOAP_FMAC5 int SOAP_FMAC6 __lb__NotifNew( - struct soap *soap, - struct _lbe__NotifNew *in, - struct _lbe__NotifNewResponse *out -) { - edg_wll_Context ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap); - edg_wll_QueryRec **conditions = NULL; - int flags; - edg_wll_NotifId nid = NULL; - int ret = SOAP_OK; - - dprintf(("[%d] WS call %s\n",getpid(),__FUNCTION__)); - - edg_wll_ResetError(ctx); - if ( edg_wll_SoapToQueryCondsExt(in->conditions, in->__sizeconditions, &conditions) ) - { - edg_wll_SetError(ctx, ENOMEM, "Couldn't create internal structures"); - edg_wll_ErrToFault(ctx, soap); - ret = SOAP_FAULT; - goto cleanup; - } - edg_wll_SoapToJobStatFlags(in->flags, &flags); - - if (edg_wll_NotifIdParse(in->notifId,&nid)) { - edg_wll_SetError(ctx,EINVAL,"Parse notifid"); - edg_wll_ErrToFault(ctx, soap); - ret = SOAP_FAULT; - goto cleanup; - } - - out->valid = in->valid ? *in->valid : 0; - if (edg_wll_NotifNewServer(ctx,conditions,flags,in->destination,nid,&out->valid)) { - edg_wll_ErrToFault(ctx, soap); - ret = SOAP_FAULT; - goto cleanup; - } - - -cleanup: - edg_wll_NotifIdFree(nid); - freeQueryRecsExt(conditions); - return ret; -} - -SOAP_FMAC5 int SOAP_FMAC6 __lb__NotifBind( - struct soap *soap, - struct _lbe__NotifBind *in, - struct _lbe__NotifBindResponse *out -) { - edg_wll_Context ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap); - edg_wll_NotifId nid = NULL; - - if (edg_wll_NotifIdParse(in->notifId,&nid)) { - edg_wll_SetError(ctx,EINVAL,"Parse notifid"); - edg_wll_ErrToFault(ctx, soap); - return SOAP_FAULT; - } - out->valid = in->valid ? *in->valid : 0; - - if (edg_wll_NotifBindServer(ctx,nid,in->destination,&out->valid)) { - edg_wll_ErrToFault(ctx, soap); - edg_wll_NotifIdFree(nid); - return SOAP_FAULT; - } - return SOAP_OK; -} - -SOAP_FMAC5 int SOAP_FMAC6 __lb__NotifRefresh( - struct soap *soap, - struct _lbe__NotifRefresh *in, - struct _lbe__NotifRefreshResponse *out -) { - edg_wll_Context ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap); - edg_wll_NotifId nid = NULL; - - if (edg_wll_NotifIdParse(in->notifId,&nid)) { - edg_wll_SetError(ctx,EINVAL,"Parse notifid"); - edg_wll_ErrToFault(ctx, soap); - return SOAP_FAULT; - } - out->valid = in->valid ? *in->valid : 0; - - if (edg_wll_NotifRefreshServer(ctx,nid,&out->valid)) { - edg_wll_ErrToFault(ctx, soap); - edg_wll_NotifIdFree(nid); - return SOAP_FAULT; - } - return SOAP_OK; -} - -SOAP_FMAC5 int SOAP_FMAC6 __lb__NotifDrop( - struct soap *soap, - struct _lbe__NotifDrop *in, - struct _lbe__NotifDropResponse *out -) { - edg_wll_Context ctx = (edg_wll_Context) glite_gsplugin_get_udata(soap); - edg_wll_NotifId nid = NULL; - - if (edg_wll_NotifIdParse(in->notifId,&nid)) { - edg_wll_SetError(ctx,EINVAL,"Parse notifid"); - edg_wll_ErrToFault(ctx, soap); - return SOAP_FAULT; - } - - if (edg_wll_NotifDropServer(ctx,nid)) { - edg_wll_ErrToFault(ctx, soap); - edg_wll_NotifIdFree(nid); - return SOAP_FAULT; - } - return SOAP_OK; -} - -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); - } -} diff --git a/org.glite.lb.server/src/ws_typemap.dat b/org.glite.lb.server/src/ws_typemap.dat deleted file mode 100644 index 0c3e085..0000000 --- a/org.glite.lb.server/src/ws_typemap.dat +++ /dev/null @@ -1,3 +0,0 @@ -lb = http://glite.org/wsdl/services/lb -lbt = http://glite.org/wsdl/types/lb -lbe = http://glite.org/wsdl/elements/lb diff --git a/org.glite.lb.server/src/ws_typemap.h b/org.glite.lb.server/src/ws_typemap.h deleted file mode 100644 index 44d9c39..0000000 --- a/org.glite.lb.server/src/ws_typemap.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef GLITE_LB_WS_TYPEMAP_H -#define GLITE_LB_WS_TYPEMAP_H - -#ident "$Header" - -#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 JDLATTR lbt__queryAttr__JDLATTR -#define STATEENTERTIME lbt__queryAttr__STATEENTERTIME -#define LASTUPDATETIME lbt__queryAttr__LASTUPDATETIME -#define NETWORKSERVER lbt__queryAttr__NETWORKSERVER - -#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 CHANGED lbt__queryOp__CHANGED - -#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 CHILDHIST_FAST lbt__jobFlagsValue__CHILDHIST_USCOREFAST -#define CHILDHIST_THOROUGH lbt__jobFlagsValue__CHILDHIST_USCORETHOROUGH - -#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 - -#endif /* GLITE_LB_WS_TYPEMAP_H */ diff --git a/org.glite.lb.server/src/ws_typeref.c.T b/org.glite.lb.server/src/ws_typeref.c.T deleted file mode 100644 index b07cbb5..0000000 --- a/org.glite.lb.server/src/ws_typeref.c.T +++ /dev/null @@ -1,1198 +0,0 @@ -#include -#include -#include -#include - -#include "soap_version.h" -#include "bk_ws_H.h" -#include "ws_typemap.h" - -#include "glite/lb/events.h" -#include "glite/lb/query_rec.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$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; istate); -! GLITE_SECURITY_GSOAP_LIST_GET(h, i-1)->$fmap{$_} = src->$_\[i+1]; -! } -! } -! 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$_+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__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(src->__size$usuc + 1, sizeof *dest->$_); -! dest->$_\[0] = src->__size$usuc + 2; -! for (i=0; i__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$_\[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__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__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(out); - *out = 0; - if (in) 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; - case CHILDHIST_FAST: *out |= EDG_WLL_STAT_CHILDHIST_FAST; break; - case CHILDHIST_THOROUGH: *out |= EDG_WLL_STAT_CHILDHIST_THOROUGH; 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 ( in & EDG_WLL_STAT_CHILDHIST_FAST ) out->__sizeflag++; - if ( in & EDG_WLL_STAT_CHILDHIST_THOROUGH ) 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; - if ( in & EDG_WLL_STAT_CHILDHIST_FAST ) out->flag[i++] = CHILDHIST_FAST; - if ( in & EDG_WLL_STAT_CHILDHIST_THOROUGH ) out->flag[i++] = CHILDHIST_THOROUGH; - - return SOAP_OK; -} - -int edg_wll_SoapToAttr(const enum lbt__queryAttr in, edg_wll_QueryAttr *out) -{ - assert(EDG_WLL_QUERY_ATTR_NETWORK_SERVER + 1 == EDG_WLL_QUERY_ATTR__LAST); - - switch ( in ) - { - 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; - case JDLATTR: *out = EDG_WLL_QUERY_ATTR_JDL_ATTR; break; - case STATEENTERTIME: *out = EDG_WLL_QUERY_ATTR_STATEENTERTIME; break; - case LASTUPDATETIME: *out = EDG_WLL_QUERY_ATTR_LASTUPDATETIME; break; - case NETWORKSERVER: *out = EDG_WLL_QUERY_ATTR_NETWORK_SERVER; break; - default: return 0; - } - - return 1; -} - -int edg_wll_AttrToSoap(const edg_wll_QueryAttr in, enum lbt__queryAttr *out) -{ - assert(EDG_WLL_QUERY_ATTR_NETWORK_SERVER + 1 == EDG_WLL_QUERY_ATTR__LAST); - - switch ( in ) - { - 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; - case EDG_WLL_QUERY_ATTR_JDL_ATTR: *out = JDLATTR; break; - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: *out = STATEENTERTIME; break; - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: *out = LASTUPDATETIME; break; - case EDG_WLL_QUERY_ATTR_NETWORK_SERVER: *out = NETWORKSERVER; break; - default: return 0; - } - - return 1; -} - -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 UNEQUAL: *out = EDG_WLL_QUERY_OP_UNEQUAL; 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; - case CHANGED: *out = EDG_WLL_QUERY_OP_CHANGED; 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_UNEQUAL: *out = UNEQUAL; 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; - case EDG_WLL_QUERY_OP_CHANGED: *out = CHANGED; break; - default: assert(0); - } -} - -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 ( glite_jobid_parse(VALUEQR_GET(in, c), (glite_jobid_t *)&(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: - case EDG_WLL_QUERY_ATTR_CHKPT_TAG: - case EDG_WLL_QUERY_ATTR_JDL_ATTR: - 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: - case EDG_WLL_QUERY_ATTR_STATEENTERTIME: - case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: - 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: - case EDG_WLL_QUERY_ATTR_EXITCODE: - 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; - default: - return SOAP_FAULT; - } - - 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)); - if (!edg_wll_SoapToAttr(collection->attr, &out->attr)) return -1; - 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)); - -#ifdef GLITE_SECURITY_GSOAP_CHOICE_SETNULL - if ((qr->value2 = soap_malloc(soap, sizeof(*(qr->value2)))) == NULL) return SOAP_FAULT; - GLITE_SECURITY_GSOAP_CHOICE_SETNULL(qr->value2, queryRecValue); -#endif - switch ( in->op ) { - case EDG_WLL_QUERY_OP_WITHIN: -#ifndef GLITE_SECURITY_GSOAP_CHOICE_SETNULL - if ( !(qr->value2 = soap_malloc(soap, sizeof(*(qr->value2)))) ) return SOAP_FAULT; -#endif - 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; - - if (!edg_wll_AttrToSoap(in[0].attr, &(qc->attr))) return SOAP_FAULT; - - 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 && GLITE_SECURITY_GSOAP_LIST_GET(in, i); 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; -} - - -#define edg_wll_CommonJobsResponseToSoap do { \ - int count, i; \ -\ - assert(out); \ - out->__sizejobs = 0; \ - out->jobs = NULL; \ - out->__sizestates = 0; \ - out->states = NULL; \ -\ - count = 0; \ - if ( jobs ) { \ - for ( i = 0; jobs[i]; i++ ) ; \ - count = i; \ - out->jobs = soap_malloc(soap, sizeof(*(out->jobs))*count); \ - if ( !out->jobs ) return SOAP_FAULT; \ - out->__sizejobs = count; \ - 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 ) { \ - GLITE_SECURITY_GSOAP_LIST_CREATE(soap, out, states, struct lbt__jobStatus, count); \ - if ( !out->states ) return SOAP_FAULT; \ -\ - for ( i = 0; i < count; i++ ) \ - if ( edg_wll_StatusToSoap(soap, states+i, GLITE_SECURITY_GSOAP_LIST_GET(out->states, i)) ) \ - return SOAP_FAULT; \ - } \ -\ -} while(0) - - -int edg_wll_JobsQueryResToSoap( - struct soap *soap, - const edg_wlc_JobId *jobs, - const edg_wll_JobStat *states, - struct _lbe__QueryJobsResponse *out) -{ - edg_wll_CommonJobsResponseToSoap; - return SOAP_OK; -} - - -int edg_wll_UserJobsResToSoap( - struct soap *soap, - const edg_wlc_JobId *jobs, - const edg_wll_JobStat *states, - struct _lbe__UserJobsResponse *out) -{ - edg_wll_CommonJobsResponseToSoap; - 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" - } - if (not $e eq '_common_') { - gen "\tcase EDG_WLL_${upper_en}_UNDEFINED: assert(0);\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; - case EDG_WLL_SOURCE_NONE: - case EDG_WLL_SOURCE__LAST: - default: - assert(0); - } -} - - -/** - * 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: - return 0; - } - - 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; -} diff --git a/org.glite.lb.server/src/ws_typeref.h b/org.glite.lb.server/src/ws_typeref.h deleted file mode 100644 index 61d55f5..0000000 --- a/org.glite.lb.server/src/ws_typeref.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef GLITE_LB_WS_TYPEREF_H -#define GLITE_LB_WS_TYPEREF_H - -#ident "$Header" - -#include "glite/lb/jobstat.h" -#include "glite/lb/query_rec.h" -#include "glite/lb/events.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_UserJobsResToSoap( - struct soap *, - glite_jobid_const_t *, - const edg_wll_JobStat *, - struct _lbe__UserJobsResponse *); - -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 /* GLITE_LB_WS_TYPEREF_H */ diff --git a/org.glite.lb.server/test/oneJob.qry b/org.glite.lb.server/test/oneJob.qry deleted file mode 100644 index b46289d..0000000 --- a/org.glite.lb.server/test/oneJob.qry +++ /dev/null @@ -1,32 +0,0 @@ -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 (nil) - -select name,value from long_fields where jobid = 'WrCEKje9QTXFiSOZuPMLtw' and event = 1 - -SELECT DISTINCT j.dg_jobid,j.userid FROM jobs j WHERE (j.jobid='WrCEKje9QTXFiSOZuPMLtw') -https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw 294de3557d9d00b3d2d8a1e6aab028cf - -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 j.dg_jobid = 'https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw' AND e.jobid=j.jobid AND e.userid=u.userid AND e.code != 0 -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 - diff --git a/org.glite.lb.server/test/test_query_events.cpp b/org.glite.lb.server/test/test_query_events.cpp deleted file mode 100644 index 5224281..0000000 --- a/org.glite.lb.server/test/test_query_events.cpp +++ /dev/null @@ -1,187 +0,0 @@ -#include - -#include -#include -#include -#include - -#include -#include -#include - -#define NO_GACL -#include "lb_authz.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 > > queries; - -public: - void oneJob(); - int ExecStmt(const char *, glite_lbu_Statement *); - - void setUp() { - edg_wll_InitContext(&ctx); - ctx->dbctx = (glite_lbu_DBContext) this; /* XXX */ - ctx->dbcaps = 0; - } - - void tearDown() { - edg_wll_FreeContext(ctx); - } -}; - -void QueryEventsTest::oneJob() -{ - edg_wll_QueryRec job[2]; - const edg_wll_QueryRec *jobs[2] = { job,NULL} ; - edg_wll_Event *events; - int i; - - job[0].attr = EDG_WLL_QUERY_ATTR_JOBID; - job[0].op = EDG_WLL_QUERY_OP_EQUAL ; - glite_jobid_parse("https://lhun.ics.muni.cz:4850/WrCEKje9QTXFiSOZuPMLtw", - (glite_jobid_t *) &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 rows; - - getline(qry_file,query); - cout << "read: " << query < >(query,rows)); - } - - qry_file.close(); - - CPPUNIT_ASSERT(!edg_wll_QueryEventsServer(ctx,1,jobs,NULL,&events)); - glite_jobid_free((glite_jobid_t) job[0].value.j); - for (i = 0; events[i].type; i++) edg_wll_FreeEvent(&events[i]); - free(events); -} - -int QueryEventsTest::ExecStmt(const char *qry, glite_lbu_Statement *stmt_out) -{ - vector > >::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::iterator *rows = new vector::iterator(stmt->second.begin()); - - *stmt_out = (glite_lbu_Statement) rows; -//cerr << (*rows)->c_str() << endl; -//cerr << stmt->second.size()-1 << endl; - return stmt->second.size()-1; -} - -extern "C" { -int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx) { return 0; } -void glite_lbu_FreeDBContext(glite_lbu_DBContext ctx) { } -int glite_lbu_DBConnect(glite_lbu_DBContext ctx, const char*str) { return 0; } -void glite_lbu_DBClose(glite_lbu_DBContext ctx) { } - -int glite_lbu_ExecSQL(glite_lbu_DBContext ctx,const char *qry,glite_lbu_Statement *stmt) -{ - cout << "glite_lbu_ExecSQL: " << qry << endl; - - class QueryEventsTest *tst = (class QueryEventsTest *)ctx; - return tst->ExecStmt(qry, stmt); -} - -int glite_lbu_FetchRow(glite_lbu_Statement stmt, unsigned int n, unsigned long int *lengths, char **cols) -{ - vector::iterator *rows = (vector::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); - free(row); - - return i; -} - -void glite_lbu_FreeStmt(glite_lbu_Statement *) {} - -int debug; - -int glite_lbu_QueryColumns(glite_lbu_Statement stmt, char**cols) { return 0; } -void glite_lbu_TimeToDB(long t, char **s) { *s = NULL; } -time_t glite_lbu_DBToTime(const char *c) { return (time_t)-1; } - -int glite_lbu_Transaction(glite_lbu_DBContext ctx) { return 0; } -int glite_lbu_Commit(glite_lbu_DBContext ctx) { return 0; } -int glite_lbu_Rollback(glite_lbu_DBContext ctx) { return 0; } - -int glite_lbu_bufferedInsertInit(glite_lbu_DBContext ctx, glite_lbu_bufInsert *bi, const char *table_name, long size_limit, long record_limit, const char * columns) { return 0; } -int glite_lbu_bufferedInsert(glite_lbu_bufInsert bi, const char *row) { return 0; } -int glite_lbu_bufferedInsertClose(glite_lbu_bufInsert bi) { return 0; } -int glite_lbu_QueryIndices(glite_lbu_DBContext ctx, const char *table, char ***key_names, char ****column_names) { return 0; } -int glite_lbu_DBError(glite_lbu_DBContext ctx, char **s1, char **s2) { return 0; } - -int edg_wll_JobStatusServer( - edg_wll_Context ctx, - glite_jobid_const_t job, - int flags, - edg_wll_JobStat *stat) -{ - edg_wlc_JobIdDup(job,&stat->jobId); - return 0; -} - -int edg_wll_GetACL(edg_wll_Context ctx, glite_jobid_const_t jobid, edg_wll_Acl *acl) { return 0; } -int edg_wll_CheckACL(edg_wll_Context ctx, edg_wll_Acl acl, int requested_perm) { return 0; } -void edg_wll_FreeAcl(edg_wll_Acl acl) { return; } -} - -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; -} diff --git a/org.glite.lb.server/test/test_soap_conv.cpp b/org.glite.lb.server/test/test_soap_conv.cpp deleted file mode 100644 index c5f4337..0000000 --- a/org.glite.lb.server/test/test_soap_conv.cpp +++ /dev/null @@ -1,321 +0,0 @@ -#include -#include - -#include -#include -#include -#include - -#include - -#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; -} diff --git a/org.glite.lb.server/test/test_trans.sh b/org.glite.lb.server/test/test_trans.sh deleted file mode 100644 index 22608a8..0000000 --- a/org.glite.lb.server/test/test_trans.sh +++ /dev/null @@ -1,190 +0,0 @@ -# Simple script to test United Server Proxy behaviour -# - for internal purposes only -# - test should correspond to tests described at -# http://egee.cesnet.cz/mediawiki/index.php/LB_and_JP_cleanup#unify_lb.proxy_.2B_server - -#!/bin/bash - -QUERY_SOCK=/tmp/lb_proxy_serve.sock - - -cisti() { - echo "DB cleanup..." - - mysql -u lbserver -e "delete from users;" lbserver20trans - mysql -u lbserver -e "delete from status_tags;" lbserver20trans - mysql -u lbserver -e "delete from states;" lbserver20trans - mysql -u lbserver -e "delete from short_fields;" lbserver20trans - mysql -u lbserver -e "delete from jobs;" lbserver20trans - mysql -u lbserver -e "delete from events;" lbserver20trans - mysql -u lbserver -e "delete from server_state;" lbserver20trans - mysql -u lbserver -e "delete from notif_registrations;" lbserver20trans - mysql -u lbserver -e "delete from notif_jobs;" lbserver20trans - mysql -u lbserver -e "delete from long_fields;" lbserver20trans - mysql -u lbserver -e "delete from acls;" lbserver20trans - - echo "done." -} - -registruj() { - - echo "Registering...." - OUT=`org.glite.lb.client/build/job_reg -x -m scientific.civ.zcu.cz:7846 -s application|grep JOBID` - eval $OUT - ID1=$EDG_JOBID - OUT=`org.glite.lb.client/build/job_reg -m scientific.civ.zcu.cz:7846 -s application|grep JOBID` - eval $OUT - ID2=$EDG_JOBID - OUT=`org.glite.lb.client/build/job_reg -x -m skurut68-2.cesnet.cz:9000 -s application|grep JOBID` - eval $OUT - ID3=$EDG_JOBID - echo "done." -} - -registruj_kolekce() { - - echo "Registering...." - OUT=`org.glite.lb.client/build/job_reg -x -C -n 1 -m scientific.civ.zcu.cz:7846 -s application|grep JOBID` - eval $OUT - ID1=$EDG_WL_COLLECTION_JOBID - ID1_SUB=$EDG_WL_SUB_JOBID - OUT=`org.glite.lb.client/build/job_reg -C -n 1 -m scientific.civ.zcu.cz:7846 -s application|grep JOBID` - eval $OUT - ID2=$EDG_WL_COLLECTION_JOBID - ID2_SUB=$EDG_WL_SUB_JOBID - OUT=`org.glite.lb.client/build/job_reg -x -C -n 1 -m skurut68-2.cesnet.cz:9000 -s application|grep JOBID` - eval $OUT - ID3=$EDG_WL_COLLECTION_JOBID - ID3_SUB=$EDG_WL_SUB_JOBID - OUT=`org.glite.lb.client/build/job_reg -x -C -S -n 1 -m scientific.civ.zcu.cz:7846 -s application|grep JOBID` - eval $OUT - ID4=$EDG_WL_COLLECTION_JOBID - ID4_SUB=$EDG_WL_SUB_JOBID - OUT=`org.glite.lb.client/build/job_reg -C -S -n 1 -m scientific.civ.zcu.cz:7846 -s application|grep JOBID` - eval $OUT - ID5=$EDG_WL_COLLECTION_JOBID - ID5_SUB=$EDG_WL_SUB_JOBID - OUT=`org.glite.lb.client/build/job_reg -x -C -S -n 1 -m skurut68-2.cesnet.cz:9000 -s application|grep JOBID` - eval $OUT - ID6=$EDG_WL_COLLECTION_JOBID - ID6_SUB=$EDG_WL_SUB_JOBID - echo "done." - -} - -vypis() { - mysql -u lbserver -e "select dg_jobid,proxy,server from jobs" lbserver20trans -} - -vypis_kolekci() { - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$1'" lbserver20trans - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$2'" lbserver20trans|grep http - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$3'" lbserver20trans|grep http - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$4'" lbserver20trans|grep http - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$5'" lbserver20trans|grep http - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$6'" lbserver20trans|grep http - shift 6 - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$1'" lbserver20trans|grep http - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$2'" lbserver20trans|grep http - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$3'" lbserver20trans|grep http - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$4'" lbserver20trans|grep http - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$5'" lbserver20trans|grep http - mysql -u lbserver -e "select dg_jobid, proxy,server from jobs where dg_jobid='$6'" lbserver20trans|grep http -} - -do_stavu_cleared() { - echo "Transfering jobs to cleared state..." - stage/examples/glite-lb-cleared.sh -x -j $1 2>/dev/null - stage/examples/glite-lb-cleared.sh -j $2 2>/dev/null - stage/examples/glite-lb-cleared.sh -x -j $3 2>/dev/null - echo "done." -} - -check_states() { - echo - echo "State of job $1" - stage/examples/glite-lb-job_status -x $QUERY_SOCK $1 | grep "state : " - stage/examples/glite-lb-job_status $1 |grep "state : " - echo "State of job $2" - stage/examples/glite-lb-job_status -x $QUERY_SOCK $2 | grep "state : " - stage/examples/glite-lb-job_status $2 |grep "state : " - echo "State of job $3" - stage/examples/glite-lb-job_status -x $QUERY_SOCK $3 | grep "state : " - stage/examples/glite-lb-job_status $3 |grep "state : " -} - -test1() { - echo - echo "==================== test 1 =============================" - - cisti; - registruj; - vypis; - echo job1=$ID1 - echo job2=$ID2 - echo job3=$ID3 -} - -test2() { - echo - echo "==================== test 2 =============================" - - cisti; - registruj; - vypis; - echo job1=$ID1 - echo job2=$ID2 - echo job3=$ID3 - - do_stavu_cleared $ID1 $ID2 $ID3 - vypis; -} - -test3() { - echo - echo "==================== test 3 =============================" - - cisti; - registruj; - vypis; - echo job1=$ID1 - echo job2=$ID2 - echo job3=$ID3 - - sleep 2; - stage/bin/glite-lb-purge --cleared 1s --aborted 1s --cancelled 1s --other 1s -l -m scientific.civ.zcu.cz:7846 - vypis; -} - -test4() { - echo - echo "==================== test 4 =============================" - - cisti; - registruj; - vypis; - echo job1=$ID1 - echo job2=$ID2 - echo job3=$ID3 - - check_states $ID1 $ID2 $ID3 -} - -test5() { - echo - echo "==================== test 5 =============================" - - cisti; - registruj_kolekce; - vypis_kolekci $ID1 $ID1_SUB $ID2 $ID2_SUB $ID3 $ID3_SUB $ID4 $ID4_SUB $ID5 $ID5_SUB $ID6 $ID6_SUB -} - - - -#################################################### - -test1; -test2; -test3; -test4; -test5; diff --git a/org.glite.lb.server/test/test_xml.cpp.T b/org.glite.lb.server/test/test_xml.cpp.T deleted file mode 100644 index b4c5d00..0000000 --- a/org.glite.lb.server/test/test_xml.cpp.T +++ /dev/null @@ -1,218 +0,0 @@ -#include - -#include -#include -#include -#include - - -#include "lb_xml_parse.h" -#include - -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) -{ - char *tmp1, *tmp2; - int tmp3; - - 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) -{ - char *tmp1, *tmp2; - int tmp3; -@@@{ - 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; -} diff --git a/org.glite.lb.state-machine/LICENSE b/org.glite.lb.state-machine/LICENSE deleted file mode 100644 index 01b973b..0000000 --- a/org.glite.lb.state-machine/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.lb.state-machine/Makefile b/org.glite.lb.state-machine/Makefile deleted file mode 100644 index 4f0a0d1..0000000 --- a/org.glite.lb.state-machine/Makefile +++ /dev/null @@ -1,127 +0,0 @@ -# defaults -top_srcdir=.. -stagedir=. -distdir=. -globalprefix=glite -lbprefix=lb -package=glite-lb-state-machine -version=0.2.0 -PREFIX=/opt/glite - --include Makefile.inc - -VPATH = ../src:../interface - -default all: compile - -CC=gcc -CXX=g++ -AT3=${stagedir}/sbin/glite-lb-at3 - -SUFFIXES = .T - -DEBUG:=-g -O0 -Wall - -CFLAGS:= \ - ${DEBUG} \ - -I${classads_prefix}/include -I${classads_prefix}/include/classad \ - -I${stagedir}/include -I${top_srcdir}/src -I. \ - -I${top_srcdir}/interface - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/${libdir} ${LDFLAGS} -SOLINK:=libtool --mode=link ${CC} -module ${LDFLAGS} -rpath ${stagedir}/${libdir} -LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS} -INSTALL:=libtool --mode=install install -LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/${libdir} ${LDFLAGS} -XSLTPROC:=xsltproc --novalid - -ifneq (${classads_prefix},/usr) - classadslib := -L${classads_prefix}/${libdir} -L${classads_prefix}/lib -endif - -classadslib := ${classadslib} -lclassad - -EXT_LIBS:= -COMMON_LIBS:= -L${stagedir}/${libdir} -lglite_lb_common_${nothrflavour} -lglite_security_gss_${nothrflavour} -PLUGIN_LIBS:= -L${stagedir}/${libdir} -lglite_lb_common_${nothrflavour}\ - ${classadslib} -lstdc++ ${expatlib} -lexpat\ - -PLUGIN_LOBJS:=seqcode_aux.lo process_event.lo process_event_pbs.lo process_event_condor.lo lb_plugin.lo -MACHINE_OBJS:=seqcode_aux.o process_event.o process_event_pbs.o process_event_condor.o - -PLUGIN_LIB=glite_lb_plugin.la -MACHINE_LIB=libglite_lb_statemachine.a - -XSD=lb-job-attrs2.xsd - -default all: compile - -compile: ${MACHINE_LIB} ${PLUGIN_LIB} ${XSD} - -${PLUGIN_LIB}: ${PLUGIN_LOBJS} - ${SOLINK} -o $@ ${PLUGIN_LOBJS} ${PLUGIN_LIBS} - -${MACHINE_LIB}: ${MACHINE_OBJS} - ar crv $@ ${MACHINE_OBJS} - -ranlib $@ - - -doc: - -stage: compile - $(MAKE) install PREFIX=${stagedir} - -install: - -mkdir -p ${PREFIX}/${libdir} ${PREFIX}/interface ${PREFIX}/include/glite/lb - install -m 644 ${MACHINE_LIB} ${PREFIX}/${libdir} - ${INSTALL} -m 755 ${PLUGIN_LIB} ${PREFIX}/${libdir} - install -m 644 ${top_srcdir}/interface/lb-job-attrs.xsd ${PREFIX}/interface - install -m 644 lb-job-attrs2.xsd ${PREFIX}/interface - install -m 644 ${top_srcdir}/interface/lb-job-record.xsd ${PREFIX}/interface - install -m 644 ${top_srcdir}/interface/intjobstat.h ${PREFIX}/include/glite/lb - install -m 644 ${top_srcdir}/interface/process_event.h ${PREFIX}/include/glite/lb - install -m 644 ${top_srcdir}/interface/seqcode_aux.h ${PREFIX}/include/glite/lb - install -m 644 job_attrs.h ${PREFIX}/include/glite/lb - install -m 644 job_attrs2.h ${PREFIX}/include/glite/lb - -clean: - rm -rvf .libs *.o *.lo ${PLUGIN_LIB} ${MACHINE_LIB} - rm -rfv job_attrs.h job_attrs2.h lb-job-attrs2.xsd glite-jpis-config.xml - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - -check: - @echo No tests yet - -%.c: %.c.T - rm -f $@ - ${AT3} $< >$@ || rm -f $@ - chmod -w $@ >/dev/null - -%.cpp: %.cpp.T - rm -f $@ - ${AT3} $< >$@ || rm -f $@ - chmod -w $@ >/dev/null - -%.xsd: %.xsd.T - rm -f $@ - ${AT3} $< >$@ || rm -f $@ - chmod -w $@ >/dev/null - -%.o %.lo: %.c - ${COMPILE} -c $< - -%.lo: %.c - ${COMPILE} -o $@ -c $< - -lb_plugin.lo: lb_plugin.c job_attrs.h job_attrs2.h - ${COMPILE} -DPLUGIN_DEBUG -o $@ -c $< - -job_attrs.h: lb-job-attrs.xsd job_attrs.xsl - ${XSLTPROC} ../src/job_attrs.xsl $< >$@ - -job_attrs2.h: lb-job-attrs2.xsd job_attrs2.xsl - ${XSLTPROC} ../src/job_attrs2.xsl $< >$@ - -glite-jpis-config.xml: lb-job-attrs2.xsd jpis_config.xsl - ${XSLTPROC} ../src/jpis_config.xsl lb-job-attrs2.xsd >$@ diff --git a/org.glite.lb.state-machine/configure b/org.glite.lb.state-machine/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lb.state-machine/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lb.state-machine/interface/intjobstat.h b/org.glite.lb.state-machine/interface/intjobstat.h deleted file mode 100644 index bb18f2f..0000000 --- a/org.glite.lb.state-machine/interface/intjobstat.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef GLITE_LB_INTJOBSTAT_H -#define GLITE_LB_INTJOBSTAT_H - -#ident "$Header$" - -#include "glite/lb/jobstat.h" - -/* - * Internal representation of job state - * (includes edg_wll_JobStat API structure) - */ - -/* convention: revision Y.XX - DESCRIPTION */ -/* where Z.XX is version from indent + 1 (version after commit), Y = Z+1 */ -/* and DESCRIPTION is short hit why version changed */ - -#define INTSTAT_VERSION "revision 2.8 - undef status time" -// ".... MAX LENGTH 32 BYTES !! ...." - -// 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; - /*!! if adding new field, modify also free_branch_state() */ -} 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 - - struct timeval last_pbs_event_timestamp; - int pbs_reruning; // true if rerun event arrived - char **tag_seq_codes; - - /*!! if adding new field, modify also destroy_intJobStat_extension() * - *!! update dec/enc_intJobStat and increase INTSTAT_VERSION */ - } 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; - -typedef enum _subjobClassCodes { - SUBJOB_CLASS_UNDEF = 0, - SUBJOB_CLASS_RUNNING, - SUBJOB_CLASS_DONE, - SUBJOB_CLASS_ABORTED, - SUBJOB_CLASS_CLEARED, - SUBJOB_CLASS_REST -} subjobClassCodes; - -void destroy_intJobStat(intJobStat *); -void destroy_intJobStat_extension(intJobStat *p); - - -void init_intJobStat(intJobStat *p); - - -#endif /* GLITE_LB_INTJOBSTAT_H */ diff --git a/org.glite.lb.state-machine/interface/lb-job-attrs.xsd b/org.glite.lb.state-machine/interface/lb-job-attrs.xsd deleted file mode 100644 index b2dc3fc..0000000 --- a/org.glite.lb.state-machine/interface/lb-job-attrs.xsd +++ /dev/null @@ -1,139 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Job owner according to LB - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb.state-machine/interface/lb-job-attrs2.xsd.T b/org.glite.lb.state-machine/interface/lb-job-attrs2.xsd.T deleted file mode 100644 index db35696..0000000 --- a/org.glite.lb.state-machine/interface/lb-job-attrs2.xsd.T +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - -@@@LANG: wsdl - - - - - -@@@{ - for my $s ($status->getTypesOrdered) { - my $u = uc $s; - gen qq{ \n}; - } -@@@} - - - -@@@{ -# _code_ -> ...Type - for my $n ($status->getAllFieldsOrdered) { - my $f = selectField $status $n; - if ($f->{codes}) { - my $ln = getName $f; - @ln = split /_/,$ln; - my $un = shift @ln; $un .= ucfirst shift @ln while (@ln); - gen qq{ - - -}; - - for (@{$f->{codes}}) { - my $uc = uc $_->{name}; - gen qq{ \n}; - } - gen qq{ - - -}; - } - } - -@@@} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Job status - - -@@@{ -# elems - for my $n ($status->getAllFieldsOrdered) { - my $f = selectField $status $n; - my $type = getType $f; - my $name = getName $f; - - $type = 'jobtypeType' if $name eq 'jobtype'; - - @ln = split /_/,$name; - my $un = shift @ln; $un .= ucfirst shift @ln while (@ln); - my $c = getComment $f; - - gen qq{ - $c - - -}; - - } -@@@} - - - diff --git a/org.glite.lb.state-machine/interface/lb-job-record.xsd b/org.glite.lb.state-machine/interface/lb-job-record.xsd deleted file mode 100644 index 069a42e..0000000 --- a/org.glite.lb.state-machine/interface/lb-job-record.xsd +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb.state-machine/interface/process_event.h b/org.glite.lb.state-machine/interface/process_event.h deleted file mode 100644 index daea0c6..0000000 --- a/org.glite.lb.state-machine/interface/process_event.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef GLITE_LB_PROCESS_EVENT_H -#define GLITE_LB_PROCESS_EVENT_H - -int processEvent(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring); -int add_stringlist(char ***lptr, const char *new_item); - -#endif diff --git a/org.glite.lb.state-machine/interface/seqcode_aux.h b/org.glite.lb.state-machine/interface/seqcode_aux.h deleted file mode 100644 index d4b5979..0000000 --- a/org.glite.lb.state-machine/interface/seqcode_aux.h +++ /dev/null @@ -1,22 +0,0 @@ -#ident "$Header$" - -int component_seqcode(const char *a, edg_wll_Source index); - -char * set_component_seqcode(char *a,edg_wll_Source index,int val); - -int before_deep_resubmission(const char *a, const char *b); - -int same_branch(const char *a, const char *b) ; - -int edg_wll_compare_pbs_seq(const char *a,const char *b); -#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 *condor_seq_num) ; - -int edg_wll_compare_seq(const char *a, const char *b); - -int compare_events_by_seq(const void *a, const void *b); - -int add_taglist(const char *new_item, const char *new_item2, const char *seq_code, intJobStat *js); diff --git a/org.glite.lb.state-machine/project/ChangeLog b/org.glite.lb.state-machine/project/ChangeLog deleted file mode 100644 index aa9379f..0000000 --- a/org.glite.lb.state-machine/project/ChangeLog +++ /dev/null @@ -1,31 +0,0 @@ -1.0.0-1 -- LB 2.0 release - -1.0.0-2 -- fixed configure to work in etics - -1.0.0-3 -- Added the dummy 'check' rule to the Makefile - -1.0.0-4 -- configure script update (globus flavors added to configure call) - -1.0.0-5 -- use hostname to identify network server rather than IP (RTM compatibility) -- don't crash on null sequence codes - -1.0.0-6 -- updated configure - -1.0.0-7 -- Makefile relies on the libdir variable -- New configure script - -1.0.1-1 -- Recompute state for unknown jobs to allow purging - -1.0.2-1 -- Do not override network server endpoint with data from transfer event - -1.0.2-2 -- install libraries into $libdir diff --git a/org.glite.lb.state-machine/project/package.description b/org.glite.lb.state-machine/project/package.description deleted file mode 100644 index 168a71b..0000000 --- a/org.glite.lb.state-machine/project/package.description +++ /dev/null @@ -1 +0,0 @@ -glite-lb-state-machine is the gLite LB state machine (server core, processing LB events to produce job state presented to the user). This package contains the state machine static (linked by server) and dynamic library (LB plugin used by Job Provenance). diff --git a/org.glite.lb.state-machine/project/package.summary b/org.glite.lb.state-machine/project/package.summary deleted file mode 100644 index c9f0240..0000000 --- a/org.glite.lb.state-machine/project/package.summary +++ /dev/null @@ -1 +0,0 @@ -gLite Logging and Bookkeeping state machine diff --git a/org.glite.lb.state-machine/project/version.properties b/org.glite.lb.state-machine/project/version.properties deleted file mode 100644 index 03e254a..0000000 --- a/org.glite.lb.state-machine/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# $Header$ -module.version=1.0.2 -module.age=2 diff --git a/org.glite.lb.state-machine/src/job_attrs.xsl b/org.glite.lb.state-machine/src/job_attrs.xsl deleted file mode 100644 index 5e6fc89..0000000 --- a/org.glite.lb.state-machine/src/job_attrs.xsl +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - -#ifndef GLITE_LB_JOB_ATTRS_H -#define GLITE_LB_JOB_ATTRS_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" - - -#define GLITE_JP_LB_CLASSAD_NS "http://jdl" - -typedef enum _lb_attrs { - attr_UNDEF, -} lb_attrs; - -static const char *lb_attrNames[] = { - "UNDEFINED", -}; - -#endif /* GLITE_LB_JOB_ATTRS_H */ - - -/** */ -#define GLITE_JP_LB_ GLITE_JP_LB_NS ":" - - - attr_, /** */ - - - GLITE_JP_LB_, - - - diff --git a/org.glite.lb.state-machine/src/job_attrs2.xsl b/org.glite.lb.state-machine/src/job_attrs2.xsl deleted file mode 100644 index 6abca31..0000000 --- a/org.glite.lb.state-machine/src/job_attrs2.xsl +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - -#ifndef GLITE_LB_JOB_ATTRS2_H -#define GLITE_LB_JOB_ATTRS2_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" - - -#define GLITE_JP_LB_CLASSAD_NS "http://jdl" - -#define ATTRS2_OFFSET 100 - -typedef enum _lb_attrs2 { - attr2_UNDEF = ATTRS2_OFFSET, -} lb_attrs2; - -static const char *lb_attrNames2[] = { - "UNDEFINED", -}; - -#endif /* GLITE_LB_JOB_ATTRS2_H */ - - -/** */ -#define GLITE_JP_LB_ GLITE_JP_LB_NS ":" - - - attr2_, /** */ - - - GLITE_JP_LB_, - - - diff --git a/org.glite.lb.state-machine/src/jpis_config.xsl b/org.glite.lb.state-machine/src/jpis_config.xsl deleted file mode 100644 index a375e58..0000000 --- a/org.glite.lb.state-machine/src/jpis_config.xsl +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - -<?xml version="1.0" encoding="UTF-8"?> - -<!-- generated using org.glite.lb.state-machine module --> - -<jpelem:ServerConfiguration - xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" - xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:xsd="http://www.w3.org/2001/XMLSchema" - xmlns:jptype="http://glite.org/wsdl/types/jp" - xmlns:jpsrv="http://glite.org/wsdl/services/jp" - xmlns:jpelem="http://glite.org/wsdl/elements/jp"> - -<!-- List of attributes IS want to receive from PS's --> - <!-- Internal attributes --> - <!-- - <attrs><name>http://egee.cesnet.cz/en/Schema/JP/System:jobId</name></attrs> - <attrs><name>http://egee.cesnet.cz/en/Schema/JP/System:owner</name></attrs> - <attrs><name>http://egee.cesnet.cz/en/Schema/JP/System:regtime</name></attrs> - --> - - -<!-- List of attributes IS will index --> - <!-- default filter --> - <!--<indexedAttrs>http://egee.cesnet.cz/en/Schema/JP/System:owner</indexedAttrs>--> - <!-- internal attribute (index replacement) --> - <!--<indexedAttrs>http://egee.cesnet.cz/en/Schema/JP/System:jobId</indexedAttrs>--> - <indexedAttrs>http://egee.cesnet.cz/en/Schema/LB/Attributes:owner</indexedAttrs> - <indexedAttrs>http://egee.cesnet.cz/en/Schema/LB/Attributes:ceNode</indexedAttrs> - <indexedAttrs>http://egee.cesnet.cz/en/Schema/LB/Attributes:status</indexedAttrs> - -<!-- List of type plugins --> - <plugins></plugins> - -<!-- List of feeds IS wants to receive from PS's--> - <!-- no filter, historic batch and incremental changes --> - <feeds> - <!-- replace this by Job Provenance Primare Storage endpoint --> - <primaryServer>https://localhost:8901</primaryServer> - <!-- List of conditions triggering attrs sending --> - <condition> - <attr>http://egee.cesnet.cz/en/Schema/JP/System:regtime</attr> - <op>GREATER</op> - <value> - <string>0</string> - </value> - </condition> - <history>1</history> - <continuous>1</continuous> - </feeds> -</jpelem:ServerConfiguration> - - - <!-- --> - <attrs> - <name>http://egee.cesnet.cz/en/Schema/LB/Attributes:</name> - <multival>YES</multival> - <queryable>YES</queryable> - </attrs> - - - - diff --git a/org.glite.lb.state-machine/src/lb_plugin.c b/org.glite.lb.state-machine/src/lb_plugin.c deleted file mode 100644 index 6d980b8..0000000 --- a/org.glite.lb.state-machine/src/lb_plugin.c +++ /dev/null @@ -1,1896 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "glite/lbu/trio.h" - -#include "glite/lb/jobstat.h" -#include "glite/lb/events.h" -#include "glite/lb/events_parse.h" -#include "glite/lb/context-int.h" - -#include "intjobstat.h" -#include "seqcode_aux.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/known_attr.h" -#include "job_attrs.h" -#include "job_attrs2.h" - -#define INITIAL_NUMBER_EVENTS 100 -#define INITIAL_NUMBER_STATES EDG_WLL_NUMBER_OF_STATCODES - -typedef struct _lb_historyStatus { - edg_wll_JobStatCode state; - struct timeval timestamp; - char *reason; - char *destination; - int done_code; -} 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; - -typedef struct _rl_buffer_t { - char *buf; - size_t pos, size; - off_t offset; -} rl_buffer_t; - -#define check_strdup(s) ((s) ? strdup(s) : NULL) - -extern int processEvent(intJobStat *, edg_wll_Event *, int, int, char **); -static void edg_wll_SortPEvents(edg_wll_Event **); - -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 readline( - glite_jp_context_t ctx, - void *handle, - rl_buffer_t *buffer, - char **line -); -char* get_namespace(const char* attr); - -static int lb_StringToAttr(const char *name) { - unsigned int i; - - for (i=1; i= 0 && attr < sizeof(lb_attrNames)/sizeof(lb_attrNames[0])) return strdup(lb_attrNames[attr]); - if (attr >= ATTRS2_OFFSET && attr < ATTRS2_OFFSET + sizeof(lb_attrNames2)/sizeof(lb_attrNames2[0])) return strdup(lb_attrNames2[attr]); - return NULL; -} -*/ - -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 = 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 = 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; - - if (id0) free(id0); - if (id) free(id); - - 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]) { - free(h->fullStatusHistory[i]->reason); - free(h->fullStatusHistory[i]->destination); - free (h->fullStatusHistory[i]); - i++; - } - free(h->fullStatusHistory); - 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 = get_namespace(attr); - char *tag; - int aa = lb_StringToAttr(attr); - - 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."); - free(ns); - 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(ns, GLITE_JP_LBTAG_NS) == 0) { -/* XXX: probably obsoleted by GLITE_JP_LB_userTags below */ - 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(ns, GLITE_JP_LB_NS) == 0) { - - switch (aa) { - - case attr2_status : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = edg_wll_StatToString(h->status.state); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_jobId : - case attr_jobId : - 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; - } - break; - - case attr2_owner : - case attr_user : - 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; - } - break; - - case attr2_jobtype : - case attr_jobType : - 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; - case EDG_WLL_STAT_COLLECTION: - av[0].value = strdup("COLLECTION"); break; - case EDG_WLL_STAT_PBS: - av[0].value = strdup("PBS"); break; - case EDG_WLL_STAT_CONDOR: - av[0].value = strdup("CONDOR"); break; - default: - av[0].value = strdup("UNKNOWN"); break; - } - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_parentJob : - case attr_parent : - 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; - } - break; - - case attr2_seed : - if (h->status.seed) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.seed); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_childrenNum : - case attr_nsubjobs : - 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; - break; - - case attr2_children : - case attr_subjobs : - if ((h->status.children_num > 0) && (h->status.children)) { - char *val = NULL, *old_val; - - old_val = strdup ("\n"); - for (i=0; h->status.children[i]; i++) { - trio_asprintf(&val,"%s%|Xs\n", - old_val, 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; - } - break; - - case attr2_childrenHist : - if ((h->status.children_num > 0) && (h->status.children_hist)) { - char *val = NULL, *old_val; - - old_val = strdup ("\n"); - for (i=1; i<=h->status.children_hist[0]; i++) { - trio_asprintf(&val,"%s%d\n", - old_val, edg_wll_StatToString(i-1), h->status.children_hist[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; - } - break; - - case attr2_childrenStates : - { - 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("\n"); - t = calloc(1, sizeof(*t)); - - if (h->status.children_states) { - for (i=0; h->status.children_states[i].state; i++) { - - s_str = edg_wll_StatToString(h->status.children_states[i].state); - for (j = 0; s_str[j]; j++) s_str[j] = toupper(s_str[j]); - if (gmtime_r(&h->status.children_states[i].stateEnterTime.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->status.children_states[i].stateEnterTime.tv_usec); - } - if (h->status.children_states[i].reason) { - trio_asprintf(&r_str,"reason=\"%|Xs\" ",h->status.children_states[i].reason); - } - trio_asprintf(&val,"%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); - } - free(t); - } - break; - - case attr2_condorId : - if (h->status.condorId) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.condorId); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_globusId : - if (h->status.globusId) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.globusId); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_localId : - if (h->status.localId) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.localId); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - - case attr2_jdl : - case attr_JDL : - 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; - } - break; - - - case attr2_matchedJdl : - if (h->status.matched_jdl) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.matched_jdl); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_destination : - case attr_CE : - 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; - } - break; - - case attr2_condorJdl : - if (h->status.condor_jdl) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.condor_jdl); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_rsl : - if (h->status.rsl) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.rsl); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_reason : - 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; - } - break; - - case attr2_location : - if (h->status.location) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.location); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_ceNode : - case attr_host : - 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; - } - break; - - case attr2_networkServer : - case attr_RB : - 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; - } - break; - - case attr2_subjobFailed : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.subjob_failed); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_doneCode : - case attr_finalDoneStatus : - if (h->finalStatus && h->finalStatus->state == EDG_WLL_JOB_DONE) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - // trio_asprintf(&av[0].value,"%d",h->status.done_code); - switch (h->status.done_code) { - case EDG_WLL_STAT_OK : - av[0].value = strdup("OK"); break; - case EDG_WLL_STAT_FAILED : - av[0].value = strdup("FAILED"); break; - case EDG_WLL_STAT_CANCELLED : - av[0].value = strdup("CANCELLED"); break; - default : - break; - } - av[0].timestamp = h->finalStatus->timestamp.tv_sec; - } - else { - *attrval = NULL; - err.code = EINVAL; - err.desc = strdup("Final status is not Done"); - free(ns); - return glite_jp_stack_error(ctx,&err); - } - break; - - case attr2_exitCode : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.exit_code); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_resubmitted : - case attr_retryCount : - 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; - break; - - case attr2_cancelling : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.cancelling); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_cancelReason : - if (h->status.cancelReason) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.cancelReason); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_cpuTime : - case attr_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; - break; - - case attr2_userTags : - if (h->status.user_tags) { - char *val = NULL, *old_val; - - old_val = strdup ("\n"); - i = 0; - while (h->status.user_tags[i].tag) { - trio_asprintf(&val,"%s\n%|Xs\n%|Xs\n\n", - old_val, h->status.user_tags[i].tag, h->status.user_tags[i].value); - if (old_val) free(old_val); - old_val = val; val = NULL; - i++; - } - 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; - } - break; - - case attr2_stateEnterTime : - case attr_finalStatusDate : - { - 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; - } - } - break; - - case attr2_lastUpdateTime : - { - struct tm *t = NULL; - 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; - } - } - break; - - - case attr2_stateEnterTimes : - if (h->status.stateEnterTimes) { - char *val = NULL, *old_val; - struct tm *t = NULL; - t = calloc(1, sizeof(*t)); - - old_val = strdup ("\n"); - for (i=1; i<=h->status.stateEnterTimes[0]; i++) { - time_t st = h->status.stateEnterTimes[i]; - - if ((st != 0) && (t = gmtime_r(&st,t)) != NULL) { - /* dateTime format: yyyy-mm-ddThh:mm:ss */ - trio_asprintf(&val,"%s%04d-%02d-%02dT%02d:%02d:%02d\n", - old_val, edg_wll_StatToString(i-1), - 1900+t->tm_year, 1+t->tm_mon, t->tm_mday, - t->tm_hour, t->tm_min, t->tm_sec); - 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; - free(t); - } - break; - - case attr2_expectUpdate : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.expectUpdate); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_expectFrom : - if (h->status.expectFrom) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.expectFrom); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_acl : - if (h->status.acl) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.acl); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_payloadRunning : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.payload_running); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_possibleDestinations : - if (h->status.possible_destinations) { - char *val = NULL, *old_val; - - old_val = strdup (""); - i = 0; - while (h->status.possible_destinations[i]) { - trio_asprintf(&val,"%s%|Xs\n", - old_val, h->status.possible_destinations[i]); - if (old_val) free(old_val); - old_val = val; val = NULL; - i++; - } - 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; - } - break; - - case attr2_possibleCeNodes : - if (h->status.possible_ce_nodes) { - char *val = NULL, *old_val; - - old_val = strdup (""); - i = 0; - while (h->status.possible_ce_nodes[i]) { - trio_asprintf(&val,"%s%|Xs\n", - old_val, h->status.possible_ce_nodes[i]); - if (old_val) free(old_val); - old_val = val; val = NULL; - i++; - } - 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; - } - break; - - case attr2_suspended : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.suspended); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_suspendReason : - if (h->status.suspend_reason) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.suspend_reason); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_failureReasons : - if (h->status.failure_reasons) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.failure_reasons); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_removeFromProxy : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.remove_from_proxy); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - /* PBS: */ - - case attr2_pbsState : - if (h->status.pbs_state) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.pbs_state); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_pbsQueue : - if (h->status.pbs_queue) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.pbs_queue); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_pbsOwner : - if (h->status.pbs_owner) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.pbs_owner); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_pbsName : - if (h->status.pbs_name) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.pbs_name); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_pbsReason : - if (h->status.pbs_reason) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.pbs_reason); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_pbsScheduler : - if (h->status.pbs_scheduler) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.pbs_scheduler); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_pbsDestHost : - if (h->status.pbs_dest_host) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.pbs_dest_host); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_pbsPid : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.pbs_pid); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_pbsResourceUsage : - if (h->status.pbs_resource_usage) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.pbs_resource_usage); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_pbsExitStatus : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.pbs_exit_status); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_pbsErrorDesc : - if (h->status.pbs_error_desc) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.pbs_error_desc); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - /* Condor: */ - case attr2_condorStatus : - if (h->status.condor_status) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.condor_status); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_condorUniverse : - if (h->status.condor_universe) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.condor_universe); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_condorOwner : - if (h->status.condor_owner) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.condor_owner); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_condorPreempting : - if (h->status.condor_preempting) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.condor_preempting); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_condorShadowPid : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.condor_shadow_pid); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_condorShadowExitStatus : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.condor_shadow_exit_status); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_condorStarterPid : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.condor_starter_pid); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_condorStarterExitStatus : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.condor_starter_exit_status); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_condorJobPid : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.condor_job_pid); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - case attr2_condorJobExitStatus : - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - trio_asprintf(&av[0].value,"%d", h->status.condor_job_exit_status); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - break; - - - case attr2_condorDestHost : - if (h->status.condor_dest_host) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.condor_dest_host); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_condorReason : - if (h->status.condor_reason) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.condor_reason); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - case attr2_condorErrorDesc : - if (h->status.condor_error_desc) { - av = calloc(2, sizeof(glite_jp_attrval_t)); - av[0].name = strdup(attr); - av[0].value = strdup(h->status.condor_error_desc); - av[0].size = -1; - av[0].timestamp = h->status.lastUpdateTime.tv_sec; - } - break; - - /* Others : */ - - case attr_finalStatus : - 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; - break; - - case attr_finalStatusReason : - 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; - } - break; - - case attr_LRMSDoneStatus : - 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; - } - break; - - case attr_LRMSStatusReason : - 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; - } - break; - - case attr_lastStatusHistory : - { - 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("\n"); - 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=\"%|Xs\" ",h->fullStatusHistory[0]->reason); - } - trio_asprintf(&val,"%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=\"%|Xs\" ",h->lastStatusHistory[i]->reason); - } - trio_asprintf(&val,"%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); - } - } - break; - - case attr_fullStatusHistory : - { - 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("\n"); - t = calloc(1, sizeof(*t)); - i = 0; - while (h->fullStatusHistory[i]) { - int state; - - s_str = edg_wll_StatToString(state = 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=\"%|Xs\" ",h->fullStatusHistory[i]->reason); - } - - if (h->fullStatusHistory[i]->destination && - state >= EDG_WLL_JOB_READY && - state <= EDG_WLL_JOB_DONE - ) { - char *aux; - trio_asprintf(&aux,"%s destination=\"%|Xs\"", - r_str ? r_str : "", - h->fullStatusHistory[i]->destination); - r_str = aux; - } - - if (state == EDG_WLL_JOB_DONE) { - char *aux; - trio_asprintf(&aux,"%s doneCode=\"%d\"", - r_str ? r_str : "", - h->fullStatusHistory[i]->done_code); - r_str = aux; - } - - trio_asprintf(&val,"%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); - } - } - break; - - - case attr_VO : - if (get_classad_attr(":VirtualOrganisation", 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); - } - break; - - case attr_eNodes : - if (get_classad_attr(":max_nodes_running", 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); - } - break; - - case attr_eProc : - if (get_classad_attr(":NodeNumber", 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); - } - break; - - case attr_UIHost : - 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++; - } - break; - - case attr_aTag : /* have to be retrieved from JDL, but probably obsolete and not needed at all */ - case attr_rQType : /* have to be retrieved from JDL, but probably obsolete and not needed at all */ - case attr_eDuration : /* have to be retrieved from JDL, but probably obsolete and not needed at all */ - case attr_NProc : /* currently LB hasn't got the info */ - case attr_additionalReason : /* 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; - free(ns); - return glite_jp_stack_error(ctx,&err); - } - break; - - case attr_UNDEF : - case attr2_UNDEF : - default: - { - char et[BUFSIZ]; - *attrval = NULL; - err.code = ENOSYS; - snprintf(et,sizeof et,"Unknown attribute '%s' (in the '%s' namespace).",attr,ns); - et[BUFSIZ-1] = 0; - err.desc = et; - free(ns); - return glite_jp_stack_error(ctx,&err); - } - - break; - } /* switch */ - - } else { - char et[BUFSIZ]; - *attrval = NULL; - err.code = EINVAL; - snprintf(et,sizeof et,"No such attribute '%s' or namespace '%s'.",attr,ns); - et[BUFSIZ-1] = 0; - err.desc = et; - free(ns); - 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_tags(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]; - } - - h->fullStatusHistory[nstates]->destination = check_strdup(js->pub.destination); - h->fullStatusHistory[nstates]->done_code = js->pub.done_code; - - 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; ipub.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); - free(js); - - return 0; - -err: - destroy_intJobStat(js); - free(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; -} -*/ - - -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); -} - - -static 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); -} - -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; -} - -int readline( - glite_jp_context_t ctx, - void *handle, - rl_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; -} - -char* get_namespace(const char* attr){ - char* namespace = strdup(attr); - char* colon = strrchr(namespace, ':'); - if (colon) - namespace[strrchr(namespace, ':') - namespace] = 0; - else - namespace[0] = 0; - return namespace; -} - diff --git a/org.glite.lb.state-machine/src/process_event.c b/org.glite.lb.state-machine/src/process_event.c deleted file mode 100644 index 167830d..0000000 --- a/org.glite.lb.state-machine/src/process_event.c +++ /dev/null @@ -1,1063 +0,0 @@ -#ident "$Header$" - -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lb/context-int.h" - -#include "glite/lbu/trio.h" - -#include "intjobstat.h" -#include "seqcode_aux.h" -#include "process_event.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_PBS(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring); -int processEvent_Condor(intJobStat *js, edg_wll_Event *e, int ev_seq, int strict, char **errstring); - -int add_stringlist(char ***lptr, const char *new_item); - -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: - trio_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: - trio_asprintf(errstring,"undefined job type %d",js->pub.jobtype); - return RET_FAIL; - } -} - -#define rep(a,b) { free(a); a = (b == NULL) ? NULL : strdup(b); } -#define rep_null(a) { free(a); a = NULL; } -#define rep_cond(a,b) { if (b) { free(a); a = 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 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_null(js->branch_tag_seqcode); - rep(js->deep_resubmit_seqcode, e->any.seqcode); -} - -static char* location_string(const char *source, const char *host, const char *instance) -{ - char *ret; - trio_asprintf(&ret, "%s/%s/%s", source, host, instance); - return ret; -} - -/* is seq. number of 'es' before WMS higher then 'js' */ -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)) - || - (component_seqcode(es,EDG_WLL_SOURCE_USER_INTERFACE) > - component_seqcode(js,EDG_WLL_SOURCE_USER_INTERFACE))); -} - - -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) ((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; - edg_wll_JobStatCode new_state = EDG_WLL_JOB_UNKNOWN; - int res = RET_OK, - fine_res = RET_OK; - - int lm_favour_lrms = 0; - int ignore_seq_code = 0; - - // Aborted may not be terminal state for collection in some cases - // i.e. if some Done/failed subjob is resubmitted - if ( (old_state == EDG_WLL_JOB_ABORTED && e->any.type != EDG_WLL_EVENT_COLLECTIONSTATE) || - old_state == EDG_WLL_JOB_CANCELLED || - old_state == EDG_WLL_JOB_CLEARED) { - res = RET_LATE; - } - -/* new event coming from NS or UI => 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_null(js->branch_tag_seqcode); - rep_null(js->deep_resubmit_seqcode); - rep_null(js->last_branch_seqcode); - } - - 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: - if (!js->pub.jdl) { - 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: - rep(js->pub.ui_host, e->accepted.from_host); - 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: - if (!js->pub.jdl || e->enQueued.result == EDG_WLL_ENQUEUED_OK) { - 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; - js->pub.jw_status = EDG_WLL_STAT_WRAPPER_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.jw_status = EDG_WLL_STAT_PAYLOAD_RUNNING; - 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_SUSPEND: - if (USABLE(res, strict)) { - if (js->pub.state == EDG_WLL_JOB_RUNNING) { - js->pub.suspended = 1; - rep(js->pub.suspend_reason, e->suspend.reason); - } - } - break; - case EDG_WLL_EVENT_RESUME: - if (USABLE(res, strict)) { - if (js->pub.state == EDG_WLL_JOB_RUNNING) { - js->pub.suspended = 0; - rep(js->pub.suspend_reason, e->resume.reason); - } - } - 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 */ - if (USABLE(res, strict)) { - js->pub.jw_status = EDG_WLL_STAT_DONE; - js->pub.payload_running = 0; - } - break; - } - if (USABLE(res, strict)) { - js->pub.state = EDG_WLL_JOB_DONE; - js->pub.jw_status = EDG_WLL_STAT_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; - case EDG_WLL_DONE_FAILED: - if (js->pub.failure_reasons) { - char *glued_reasons; - - asprintf(&glued_reasons,"%s\n%s [%s]", - js->pub.failure_reasons, e->done.reason, js->pub.destination); - rep(js->pub.failure_reasons, glued_reasons) - } - else { - asprintf(&(js->pub.failure_reasons),"%s [%s]", - e->done.reason, js->pub.destination); - } - // fall through - 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: - if (!USABLE(res, strict)) { - // record reason, destination could have changed already - if (js->pub.failure_reasons) { - char *glued_reasons; - - asprintf(&glued_reasons,"%s\n%s [delayed event, destination unreliable]", - js->pub.failure_reasons, e->done.reason); - rep(js->pub.failure_reasons, glued_reasons) - } - else { - asprintf(&(js->pub.failure_reasons),"%s [delayed event, destination unreliable]", - e->done.reason); - } - } - 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; - js->pub.remove_from_proxy = 1; - 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; - js->pub.remove_from_proxy = 1; - 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; - js->pub.remove_from_proxy = 1; - 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; - - } - } - if (USABLE_DATA(res, strict)) { - switch (e->clear.reason) { - case EDG_WLL_CLEAR_USER: - js->pub.sandbox_retrieved = EDG_WLL_STAT_USER; - break; - case EDG_WLL_CLEAR_TIMEOUT: - js->pub.sandbox_retrieved = EDG_WLL_STAT_TIMEOUT; - break; - case EDG_WLL_CLEAR_NOOUTPUT: - js->pub.sandbox_retrieved = EDG_WLL_STAT_NOOUTPUT; - 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_cond(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(e->userTag.name, e->userTag.value, e->any.seqcode, js); - } else { - goto bad_event; - } - } - break; - case EDG_WLL_EVENT_LISTENER: - /* ignore, listener port is not part of job status */ - case EDG_WLL_EVENT_CURDESCR: - case EDG_WLL_EVENT_CHKPT: - /* these three event are probably dead relics */ - case EDG_WLL_EVENT_RESOURCEUSAGE: - /* ignore, not reflected in job status */ - break; - case EDG_WLL_EVENT_CHANGEACL: - /* ignore, only for event log */ - /* seq. code of this event should not influence future state computeation */ - ignore_seq_code = 1; - 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; - - /* in case of resubmit switch JW status back to unknown */ - if (js->pub.state == EDG_WLL_JOB_WAITING || - js->pub.state == EDG_WLL_JOB_READY || - js->pub.state == EDG_WLL_JOB_SCHEDULED) { - js->pub.jw_status = EDG_WLL_STAT_UNKNOWN; - } - } - 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/XX -> 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 if (!ignore_seq_code) { - rep(js->last_seqcode, e->any.seqcode); - } - } - - if (js->pub.state != EDG_WLL_JOB_RUNNING) { - js->pub.suspended = 0; - rep_null(js->pub.suspend_reason); - } - - 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; - trio_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) -{ - if (p->last_seqcode) free(p->last_seqcode); - if (p->last_cancel_seqcode) free(p->last_cancel_seqcode); - if (p->branch_tag_seqcode) free(p->branch_tag_seqcode); - if (p->last_branch_seqcode) free(p->last_branch_seqcode); - if (p->deep_resubmit_seqcode) free(p->deep_resubmit_seqcode); - free_branch_state(&p->branch_states); - if (p->tag_seq_codes) { - int i; - - for (i=0; p->tag_seq_codes[i]; i++) free(p->tag_seq_codes[i]); - free(p->tag_seq_codes); - } - - memset(p,0,sizeof(*p)); -} - -void destroy_intJobStat(intJobStat *p) -{ - edg_wll_FreeStatus(&p->pub); - destroy_intJobStat_extension(p); - memset(p, 0, sizeof(intJobStat)); -} - -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 */ -} - diff --git a/org.glite.lb.state-machine/src/process_event_condor.c b/org.glite.lb.state-machine/src/process_event_condor.c deleted file mode 100644 index bdd63f4..0000000 --- a/org.glite.lb.state-machine/src/process_event_condor.c +++ /dev/null @@ -1,207 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include - -#include "glite/lb/context-int.h" - -#include "intjobstat.h" -#include "seqcode_aux.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; -} - diff --git a/org.glite.lb.state-machine/src/process_event_pbs.c b/org.glite.lb.state-machine/src/process_event_pbs.c deleted file mode 100644 index 303a675..0000000 --- a/org.glite.lb.state-machine/src/process_event_pbs.c +++ /dev/null @@ -1,237 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include - -#include "glite/lb/context-int.h" - -#include "glite/lbu/trio.h" - -#include "intjobstat.h" -#include "seqcode_aux.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; - - trio_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; - - trio_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; - case EDG_WLL_EVENT_USERTAG: - if (USABLE_DATA(res)) { - if (e->userTag.name != NULL && e->userTag.value != NULL) { - add_taglist(e->userTag.name, e->userTag.value, e->any.seqcode, js); - } - } - 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; -} - diff --git a/org.glite.lb.state-machine/src/seqcode_aux.c b/org.glite.lb.state-machine/src/seqcode_aux.c deleted file mode 100644 index c20c627..0000000 --- a/org.glite.lb.state-machine/src/seqcode_aux.c +++ /dev/null @@ -1,334 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include - -#include "glite/lbu/trio.h" -#include "glite/lb/context-int.h" - -#include "intjobstat.h" -#include "seqcode_aux.h" - - -/* -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/cjobid.h" -#include "glite/lbu/trio.h" -#include "glite/lbu/db.h" -#include "glite/lb/context-int.h" - -#include "store.h" -#include "index.h" -#include "jobstat.h" -#include "get_events.h" -*/ - -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) { -/* FIXME: 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) { -/* FIXME: 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], src_a; - char timestamp_b[14], pos_b[10], src_b; - int ev_code_a, ev_code_b; - int res; - - res = sscanf(a,"TIMESTAMP=%14s:POS=%10s:EV.CODE=%3d:SRC=%c", timestamp_a, pos_a, &ev_code_a, &src_a); - - if (res != 4) { -/* FIXME: 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", timestamp_b, pos_b, &ev_code_b, &src_b); - - if (res != 4) { -/* FIXME: 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 - 2]) { - 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 - 2]) { - 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) { -/* FIXME: 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) { -/* FIXME: 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; -} - - -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; -} - - - -int add_taglist(const char *new_item, const char *new_item2, const char *seq_code, intJobStat *js) -{ - edg_wll_TagValue *itptr; - int i; - - if (js->pub.user_tags == NULL) { - itptr = (edg_wll_TagValue *) calloc(2,sizeof(edg_wll_TagValue)); - itptr[0].tag = strdup(new_item); - itptr[0].value = strdup(new_item2); - js->pub.user_tags = itptr; - - js->tag_seq_codes = (char **) calloc(2,sizeof(char *)); - js->tag_seq_codes[0] = strdup(seq_code); - - return 1; - } else { - for (i = 0, itptr = js->pub.user_tags; itptr[i].tag != NULL; i++) { - if ( !strcasecmp(itptr[i].tag, new_item)) { - if (edg_wll_compare_seq(seq_code,js->tag_seq_codes[i]) == 1) { - free(itptr[i].value); - itptr[i].value = strdup(new_item2); - - free(js->tag_seq_codes[i]); - js->tag_seq_codes[i] = strdup(seq_code); - - return 1; - } - else return 1; - } - } - - itptr = (edg_wll_TagValue *) realloc(js->pub.user_tags, (i+2)*sizeof(edg_wll_TagValue)); - js->tag_seq_codes = (char **) realloc(js->tag_seq_codes, (i+2) * sizeof(char *)); - - if (itptr != NULL && js->tag_seq_codes != NULL) { - itptr[i].tag = strdup(new_item); - itptr[i].value = strdup(new_item2); - itptr[i+1].tag = NULL; - itptr[i+1].value = NULL; - js->pub.user_tags = itptr; - - js->tag_seq_codes[i] = strdup(seq_code); - js->tag_seq_codes[i+1] = NULL; - - return 1; - } else { - return 0; - } - } -} - diff --git a/org.glite.lb.utils/.cvsignore b/org.glite.lb.utils/.cvsignore deleted file mode 100755 index 1df717b..0000000 --- a/org.glite.lb.utils/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -.project -.cdtproject \ No newline at end of file diff --git a/org.glite.lb.utils/LICENSE b/org.glite.lb.utils/LICENSE deleted file mode 100755 index 01b973b..0000000 --- a/org.glite.lb.utils/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.lb.utils/Makefile b/org.glite.lb.utils/Makefile deleted file mode 100644 index 63bdaa2..0000000 --- a/org.glite.lb.utils/Makefile +++ /dev/null @@ -1,123 +0,0 @@ -# defaults -top_srcdir=.. -stagedir=. -globalprefix=glite -lbprefix=lb -package=glite-lb-utils -version=0.0.0 -PREFIX=/opt/glite - -nothrflavour=gcc32 -thrflavour=gcc32pthr -expat_prefix=/opt/expat -gsoap_prefix=/opt/gsoap - --include Makefile.inc --include ../project/version.properties - -version=${module.version} - -VPATH=${top_srcdir}/src:${top_srcdir}/doc - -CC=gcc -AT3=${stagedir}/sbin/glite-lb-at3 - -SUFFIXES = .T - -DEBUG:=-g -O0 -Wall - -CFLAGS:= \ - ${WS_CFLAGS} ${DEBUG} \ - -DVERSION=\"${version}\" \ - -I${stagedir}/include -I${top_srcdir}/src -I. \ - -I${top_srcdir}/interface \ - -I${expat_prefix}/include \ - -I${gsoap_prefix}/include -I${gsoap_prefix}/ \ - ${COVERAGE_FLAGS} \ - -D_GNU_SOURCE -LDFLAGS:=-L${stagedir}/${libdir} - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/${libdir} ${LDFLAGS} -SOLINK:=libtool --mode=link ${CC} -module ${LDFLAGS} -rpath ${stagedir}/${libdir} -LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS} -INSTALL:=libtool --mode=install install -LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/${libdir} ${LDFLAGS} -XSLTPROC:=xsltproc --novalid - -ifneq (${expat_prefix},/usr) - expatlib := -L${expat_prefix}/lib -endif - -EXT_LIBS:= \ - ${expatlib} -lexpat -COMMON_LIB:=-lglite_lb_common_${nothrflavour} -CLIENT_LIB:=-lglite_lb_client_${nothrflavour} -PLUS_LIB:=-lglite_lb_clientpp_${nothrflavour} -JP_LIBS:=-lglite_jp_common_${nothrflavour} - -UTILS:=mon purge dump load dump_exporter -ALLUTILS:=${UTILS} state_history statistics -STATISTICS_OBJS:=statistics.o process_attrs.o process_attrs2.o - -MAN_GZ:=glite-lb-mon.1.gz -MAN8_GZ:=glite-lb-purge.8.gz -MAN = $(MAN_GZ:.gz=) -MAN8 = $(MAN8_GZ:.gz=) - -default: all - -compile all: ${ALLUTILS} ${MAN_GZ} ${MAN8_GZ} - -${UTILS}: %: %.o - ${LINK} -o $@ $< ${COMMON_LIB} ${CLIENT_LIB} ${EXT_LIBS} -lglite_lbu_maildir - -statistics: ${STATISTICS_OBJS} - ${LINK} -rdynamic -o $@ ${STATISTICS_OBJS} ${COMMON_LIB} ${JP_LIBS} ${EXT_LIBS} - -state_history: state_history.o - ${LINK} -o $@ state_history.o -lglite_lb_statemachine ${PLUS_LIB} - -check: compile - -doc: ${MAN_GZ} ${MAN8_GZ} - -${MAN_GZ}: ${MAN} - cp $? . - gzip -f $(notdir $?) -${MAN8_GZ}: ${MAN8} - cp $? . - gzip -f $(notdir $?) - -stage: compile - $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes - -install: - -mkdir -p ${PREFIX}/bin - -mkdir -p ${PREFIX}/${libdir} - -mkdir -p ${PREFIX}/share/doc/${package}-${version} - -mkdir -p ${PREFIX}/share/man/man1 - -mkdir -p ${PREFIX}/share/man/man8 - ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} - ( cd ${top_srcdir}/project && ${INSTALL} -m 644 ChangeLog package.description package.summary ${PREFIX}/share/doc/${package}-${version} ) - ${INSTALL} -m 644 ${top_srcdir}/doc/README* ${PREFIX}/share/doc/${package}-${version} - ${INSTALL} -m 644 ${MAN_GZ} ${PREFIX}/share/man/man1 - ${INSTALL} -m 644 ${MAN8_GZ} ${PREFIX}/share/man/man8 - ${INSTALL} -m 755 ${top_srcdir}/src/glite-lb-bkpurge-offline.sh ${PREFIX}/bin/glite-lb-bkpurge-offline - - for p in ${ALLUTILS} ; do \ - ${INSTALL} -m 755 "$$p" "${PREFIX}/bin/glite-lb-$$p"; \ - done - -clean: - rm -rfv ${ALLUTILS} statistics ${MAN_GZ} ${MAN8_GZ} *.{lo,o} .libs/ - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - -%.o: %.c - ${COMPILE} -c $< - -%.c: %.c.T - rm -f $@ - ${AT3} $< >$@ || rm -f $@ - chmod -w $@ >/dev/null - diff --git a/org.glite.lb.utils/build.xml b/org.glite.lb.utils/build.xml deleted file mode 100644 index 3e7e842..0000000 --- a/org.glite.lb.utils/build.xml +++ /dev/null @@ -1,115 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb.utils/configure b/org.glite.lb.utils/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lb.utils/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lb.utils/doc/README.LB-monitoring b/org.glite.lb.utils/doc/README.LB-monitoring deleted file mode 100644 index a1900bc..0000000 --- a/org.glite.lb.utils/doc/README.LB-monitoring +++ /dev/null @@ -1,34 +0,0 @@ -LB monitoring tools -=================== - -GLITE-LB-MON ------------- -NAME - glite-lb-mon - program for monitoring the number of jobs on the LB server and their several statistics - - -SYNOPSIS - glite-lb-mon [-t time] - -DESCRIPTION - glite-lb-mon is a low-level program for monitoring the the number of jobs on the LB server and their several statistics. - Values like minimum, average and maximum time spent in the system are calulated for jobs that entered the final state - (Aborted, Cleared, Cancelled) in specific time (default last hour). Also number of jobs that entered the system during - this time is calculated. - -OPTIONS - -t time, --time=time - querying time in seconds from now to the past [deault 3600] - -ENVIRONMENT - EDG_WL_QUERY_SERVER - set this environment variable to specify the LB server address to query - -FILES - A special bkindex configuration needed. The following time indices must be defined: - - [ type = "time"; name = "submitted" ], - [ type = "time"; name = "cleared" ], - [ type = "time"; name = "aborted" ], - [ type = "time"; name = "cancelled" ], - diff --git a/org.glite.lb.utils/doc/README.LB-statistics b/org.glite.lb.utils/doc/README.LB-statistics deleted file mode 100644 index 5025459..0000000 --- a/org.glite.lb.utils/doc/README.LB-statistics +++ /dev/null @@ -1,41 +0,0 @@ -LB statistics tools -=================== - -GLITE-LB-STATISTICS -------------------- - -General idea: - -- LB server produces dump files (during each purge on regular basis) -see LB server startup script; option -D / --dump-prefix of glite-lb-bkserverd - -- these dumps are exported for the purposes of JP also on regular basis, -see LB/JP deplyment module; option -s/ --store of glite-lb-lb_dump_exporter - -- it depends on the LB server policy if dumps in this directory are used for -the statistics purposes or all files are hardlinked for example to a different -directory - -- general idea is such that data are available for statistics server that downloads -and removes dumps after download! Dump files are then processed on the statistics -server. - - -What needs to be done on the LB server: - -- bkserver + lb_dump_exporter running - -- gridftp running (allowing statistics server to download and remove files from -a given directory - - -What needs to be done on the statistics server: - -- download and remove files from the LB server -see glite-lb-statistics-gsi.sh (shell script in the examples directory) - -- process dump files using the glite-lb-statistics tool -see glite-lb-statistics.sh (shell script in the examples directory) - -all scripts are supposed to be run from a crontab. - diff --git a/org.glite.lb.utils/doc/glite-lb-mon.1 b/org.glite.lb.utils/doc/glite-lb-mon.1 deleted file mode 100644 index 5088df0..0000000 --- a/org.glite.lb.utils/doc/glite-lb-mon.1 +++ /dev/null @@ -1,47 +0,0 @@ -.TH GLITE-LB-MON 1 "Mar 2006" "EU EGEE Project" "Logging & Bookkeeping Utils" - -.SH NAME -glite-lb-mon - program for monitoring the number of jobs on the LB server and their several statistics - -.SH SYNOPSIS -.B glite-lb-mon -.B [-t time] -.br - -.SH DESCRIPTION -.B glite-lb-mon -is a low-level program for monitoring the the number of jobs on the LB server and their several statistics. -Values like minimum, average and maximum time spent in the system are calulated for jobs that entered -the final state (Aborted, Cleared, Cancelled) in specific time (default last hour). Also number of jobs -that entered the system during this time is calculated. - -.SH OPTIONS -.TP -.B \-t time, \-\-time=time -querying time in seconds from now to the past [deault 3600] - -.SH ENVIRONMENT -.TP -.B EDG_WL_QUERY_SERVER -set this environment variable to specify the LB server address to query - -.SH FILES -A special bkindex configuration needed. The following time indices must be defined: - -.nf - [ type = "time"; name = "submitted" ], - [ type = "time"; name = "cleared" ], - [ type = "time"; name = "aborted" ], - [ type = "time"; name = "cancelled" ], -.fi - - -.SH REPORTING BUGS -Please, report all bugs to EU EGEE Bug Tracking System located at https://savannah.cern.ch/bugs/?func=additem&group=jra1mdw - -.SH SEE ALSO -.BR glite-lb-bkindex (8), -.BR glite-lb-mon (1) - -.SH AUTHOR -EU EGEE JRA1, CESNET group. diff --git a/org.glite.lb.utils/doc/glite-lb-purge.8 b/org.glite.lb.utils/doc/glite-lb-purge.8 deleted file mode 100644 index 4482ba0..0000000 --- a/org.glite.lb.utils/doc/glite-lb-purge.8 +++ /dev/null @@ -1,103 +0,0 @@ -.TH GLITE-LB-PURGE 8 "April 2008" "EGEE Project" "Logging&Bookkeeping" - - -.SH NAME -glite-lb-purge - utility for removing inactive jobs from the L&B database - - -.SH SYNOPSIS -.B glite-lb-purge -.RI [ options ] -.br - - -.SH DESCRIPTION -.B glite-lb-purge -is utility for removing inactive jobs from the L&B database. By default, it removes jobs that reached CLEARED, ABORTED and CANCELLED state and also OTHER jobs that are in another state and are inactive for specific (rather long) time. It is a command line frontend to server internal purge. It is used by administrators of bkserver and it is not supposed to be used at the user level. - -.B glite-lb-purge -may be run periodically in order to avoid database overflow, however the periodic purges are done by server itself, so check the configuration of the server first. - - -.SH OPTIONS -.IP "-m, --server \fIbkserver\fR" -L&B server machine name. If not specified, the environment variable EDG_WL_QUERY_SERVER is beeing checked. - -.IP "-a, --aborted \fiNNN[smhd]\fR" -Purge ABORTED jobs older than NNN seconds/minutes/hours/days (only one number and one letter allowed). If the time is not specified, the default timeout is determined by the server. - -.IP "-c, --cleared \fiNNN[smhd]\fR" -Purge CLEARED jobs older than given time. - -.IP "-n, --cancelled \fiNNN[smhd]\fR" -Purge CANCELLED jobs older than given time. - -.IP "-e, --done \fiNNN[smhd]\fR" -Purge DONE jobs older than given time. - -.IP "-o, --other \fiNNN[smhd]\fR" -Purge OTHER (i.e. job in other state than ABORTED, CLEARED or CANCELLED) jobs older than given time. - -.IP "-r, --dry-run" -Do not really purge. - -.IP "-j, --jobs \fIfilename\fR" -Input file with jobIds of jobs to purge. - -.IP "-l, --return-list" -Return list of jobid matching the purge/dump criteria. - -.IP "-s, --server-dump" -Dump jobs at the server into a file (see bkserverd). - -.IP "-i, --client-dump" -Receive stream of dumped jobs (NOT implemented yet!). - -.IP "-h, --help" -Display help. - -.IP "-v, --version" -Display version. - -.IP "-d, --debug" -Print diagnostics on the \fIstderr\fR. - -.IP "-x, --proxy" -Purge L&B proxy. - -.IP "-X, --sock \fIpath\fR" -Purge L&B proxy using given socket path. - -.IP "-t, --target-runtime \fiNNN[smhd]\fR" -Throttle purge to the estimated target runtime. - -.IP "-b, --background \fiN\fR" -Purge on the background. Default 1 when throttled purging. - - -.\".SH EXAMPLES -.\"To appear :o( - - -.SH FILES -No configuration files needed. - - -.SH ENVIRONMENT -.TP -.B EDG_WL_QUERY_SERVER -If -.RB $ EDG_WL_QUERY_SERVER -is set, its value is used as the bkserver address. - - -.SH REPORTING BUGS -Please, report all bugs to EGEE Bug Tracking System located at https://savannah.cern.ch - - -.SH SEE ALSO -\fBglite-lb-bkindex\fP(8), \fBglite-lb-bkserverd\fP(8), \fBglite-lb-interlogd\fP(8), \fBglite-lb-logd\fP(8), \fBglite-lb-logevent\fP(1), \fBglite-lb-dump\fP(8), \fBglite-lb-load\fP(8) - - -.SH AUTHOR -EU EGEE, JRA1. diff --git a/org.glite.lb.utils/examples/glite-lb-index.conf b/org.glite.lb.utils/examples/glite-lb-index.conf deleted file mode 100644 index 4676ee1..0000000 --- a/org.glite.lb.utils/examples/glite-lb-index.conf +++ /dev/null @@ -1,11 +0,0 @@ -[ - JobIndices = { - [ type = "system"; name = "owner" ], - [ type = "system"; name = "location" ], - [ type = "system"; name = "destination" ], - [ type = "time"; name = "submitted" ], - [ type = "time"; name = "cleared" ], - [ type = "time"; name = "aborted" ], - [ type = "time"; name = "cancelled" ], - } -] diff --git a/org.glite.lb.utils/examples/glite-lb-statistics-gsi.sh b/org.glite.lb.utils/examples/glite-lb-statistics-gsi.sh deleted file mode 100755 index 18c2a9d..0000000 --- a/org.glite.lb.utils/examples/glite-lb-statistics-gsi.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/sh - -# -# an example script for getting LB dumps by gsiftp -# and removing them at by glite-gridftp-rm -# - -GLITE_LOCATION=${GLITE_LOCATION:-/opt/glite} -GLITE_LOCATION_VAR=${GLITE_LOCATION_VAR:-${GLITE_LOCATION}/var} -GLITE_LB_DUMPDIR=${GLITE_LB_DUMPDIR:-${GLITE_LOCATION_VAR}/dump} - -GSIFTP_SERVER=scientific.civ.zcu.cz -GSIFTP_PORT=8911 -GLITE_LB_SERVER=${GSIFTP_SERVER}:${GSIFTP_PORT} -GLITE_LB_EXPORT_DUMPDIR=/home/glite/LB/export - -X509_USER_KEY=~/.cert/usercert.pem -X509_USER_CERT=~/.cert/userkey.pem - -progname=`basename $0` - -function syslog () { - if [ ! -z "$*" ]; then - echo `date +'%b %d %H:%M:%S'` `hostname` $progname: $* - fi -} - -if [ ! -d ${GLITE_LB_DUMPDIR} ]; then - syslog "Creating directory ${GLITE_LB_DUMPDIR}" - mkdir -vp ${GLITE_LB_DUMPDIR} || exit 1 -fi - -syslog "getting new dumps to ${GLITE_LB_DUMPDIR}" -globus-url-copy gsiftp://${GLITE_LB_SERVER}/${GLITE_LB_EXPORT_DUMPDIR}/ file://${GLITE_LB_DUMPDIR}/ - -syslog "NOT removing dumps on the server" -# glite-gridftp-rm ... - -syslog "done" diff --git a/org.glite.lb.utils/examples/glite-lb-statistics-rsync.sh b/org.glite.lb.utils/examples/glite-lb-statistics-rsync.sh deleted file mode 100755 index 232f828..0000000 --- a/org.glite.lb.utils/examples/glite-lb-statistics-rsync.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/sh - -# -# an example script for getting LB dumps by rsync -# (it does not remove files on the LB server!) -# - -GLITE_LOCATION=${GLITE_LOCATION:-/opt/glite} -GLITE_LOCATION_VAR=${GLITE_LOCATION_VAR:-${GLITE_LOCATION}/var} -GLITE_LB_DUMPDIR=${GLITE_LB_DUMPDIR:-${GLITE_LOCATION_VAR}/dump} - -GLITE_LB_SERVER=scientific.civ.zcu.cz -GLITE_LB_EXPORT_DUMPDIR=/home/glite/LB/export - -progname=`basename $0` - -function syslog () { - if [ ! -z "$*" ]; then - echo `date +'%b %d %H:%M:%S'` `hostname` $progname: $* - fi -} - -if [ ! -d ${GLITE_LB_DUMPDIR} ]; then - syslog "Creating directory ${GLITE_LB_DUMPDIR}" - mkdir -vp ${GLITE_LB_DUMPDIR} || exit 1 -fi - -syslog "getting new dumps to ${GLITE_LB_DUMPDIR}" -rsync -rlptoDuv ${GLITE_LB_SERVER}:${GLITE_LB_EXPORT_DUMPDIR}/ ${GLITE_LB_DUMPDIR}/ - -syslog "done" diff --git a/org.glite.lb.utils/examples/glite-lb-statistics-sftp.sh b/org.glite.lb.utils/examples/glite-lb-statistics-sftp.sh deleted file mode 100755 index 04f468c..0000000 --- a/org.glite.lb.utils/examples/glite-lb-statistics-sftp.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/sh - -# -# an example script for getting LB dumps using sftp -# (it does not remove files on the LB server!) -# - -GLITE_LOCATION=${GLITE_LOCATION:-/opt/glite} -GLITE_LOCATION_VAR=${GLITE_LOCATION_VAR:-${GLITE_LOCATION}/var} -GLITE_LB_DUMPDIR=${GLITE_LB_DUMPDIR:-${GLITE_LOCATION_VAR}/dump} - -GLITE_LB_SFTPBATCH=/tmp/glite-lb-statistics-sftp-batch - -GLITE_LB_SERVER=scientific.civ.zcu.cz -GLITE_LB_EXPORT_DUMPDIR=/home/glite/LB/export - -progname=`basename $0` - -function syslog () { - if [ ! -z "$*" ]; then - echo `date +'%b %d %H:%M:%S'` `hostname` $progname: $* - fi -} - -if [ ! -d ${GLITE_LB_DUMPDIR} ]; then - syslog "Creating directory ${GLITE_LB_DUMPDIR}" - mkdir -vp ${GLITE_LB_DUMPDIR} || exit 1 -fi - -if [ -f ${GLITE_LB_SFTPBATCH} ]; then - syslog "WARNING: File ${GLITE_LB_SFTPBATCH} already exists, will be overwritten" -fi - -syslog "writing ${GLITE_LB_SFTPBATCH}" -echo "lcd ${GLITE_LB_DUMPDIR} -cd ${GLITE_LB_EXPORT_DUMPDIR} -get -P *" > ${GLITE_LB_SFTPBATCH} || exit 1 - -syslog "getting new dumps to ${GLITE_LB_DUMPDIR}" -sftp -b ${GLITE_LB_SFTPBATCH} ${GLITE_LB_SERVER} - -syslog "done" diff --git a/org.glite.lb.utils/examples/glite-lb-statistics.sh b/org.glite.lb.utils/examples/glite-lb-statistics.sh deleted file mode 100755 index 388e9ae..0000000 --- a/org.glite.lb.utils/examples/glite-lb-statistics.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh - -# -# an example script for processing LB dumps for the statistics purposes -# suitable for running from crontab -# - -GLITE_LOCATION=${GLITE_LOCATION:-/opt/glite} -GLITE_LOCATION_VAR=${GLITE_LOCATION_VAR:-${GLITE_LOCATION}/var} -GLITE_LB_DUMPDIR=${GLITE_LB_DUMPDIR:-${GLITE_LOCATION_VAR}/dump} -GLITE_LB_STATISTICS=${GLITE_LOCATION}/bin/glite-lb-statistics - -progname=`basename $0` - -function syslog () { - if [ ! -z "$*" ]; then - echo `date +'%b %d %H:%M:%S'` `hostname` $progname: $* - fi -} - -if [ ! -d ${GLITE_LB_DUMPDIR} ]; then - syslog "Creating directory ${GLITE_LB_DUMPDIR}" - mkdir -vp ${GLITE_LB_DUMPDIR} || exit 1 -fi - -if [ ! -f ${GLITE_LB_STATISTICS} ]; then - syslog "Program ${GLITE_LB_STATISTICS} is missing" - exit 1 -fi - -syslog "processing new dumps in ${GLITE_LB_DUMPDIR}" -for file in ${GLITE_LB_DUMPDIR}/*[^xml,log] ; do - if [ ! -s $file.xml ]; then - if [ -s $file ]; then - ${GLITE_LB_STATISTICS} -v -f $file > $file.xml 2> $file.log - syslog "processed $file" - let num++ - else - syslog `rm -v -f $file*` - fi -# else -# syslog "file $file.xml already exists" - fi -done - -if [ -z $num ]; then - syslog "processed no files" -else - syslog "processed $num files" -fi diff --git a/org.glite.lb.utils/project/ChangeLog b/org.glite.lb.utils/project/ChangeLog deleted file mode 100644 index b3ea5d3..0000000 --- a/org.glite.lb.utils/project/ChangeLog +++ /dev/null @@ -1,21 +0,0 @@ -2.0.0-1 -- LB 2.0 release - -2.0.0-2 -- fixed configure to work in etics - -2.0.0-3 -- configure script update (globus flavors added to configure call) - -2.0.1-1 -- purging client - 'other' jobs selection updated. - -2.0.2-1 -- glite-lb-bkpurge-offline.sh deletes from events_flesh as well - -2.0.3-1 -- Man page update -- Support for background purge funcionality - -2.0.3-2 -- install libraries into $libdir diff --git a/org.glite.lb.utils/project/build.number b/org.glite.lb.utils/project/build.number deleted file mode 100644 index 073124b..0000000 --- a/org.glite.lb.utils/project/build.number +++ /dev/null @@ -1,2 +0,0 @@ -#Fri Aug 18 12:33:06 CEST 2006 -module.build=0090 diff --git a/org.glite.lb.utils/project/build.properties b/org.glite.lb.utils/project/build.properties deleted file mode 100755 index e69de29..0000000 diff --git a/org.glite.lb.utils/project/configure.properties.xml b/org.glite.lb.utils/project/configure.properties.xml deleted file mode 100644 index 68882d7..0000000 --- a/org.glite.lb.utils/project/configure.properties.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - -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} -mysql_prefix=${with.mysql.prefix} -mysql_version=${ext.mysql.version} -gsoap_prefix=${with.gsoap.prefix} -gsoap_version=${ext.gsoap.version} -cppunit_prefix=${with.cppunit.prefix} -thrflavour=${with.globus.thr.flavor} -nothrflavour=${with.globus.nothr.flavor} - - - diff --git a/org.glite.lb.utils/project/package.description b/org.glite.lb.utils/project/package.description deleted file mode 100644 index 44b33e2..0000000 --- a/org.glite.lb.utils/project/package.description +++ /dev/null @@ -1 +0,0 @@ -glite-lb-utils are gLite LB utilities used for dumping (glite-lb-dump) and purging (glite-lb-purge) data from LB server, for loading (glite-lb-load) data to server, for real time monitoring (glite-lb-mon) and post-mortem statistics (glite-lb-statistics). diff --git a/org.glite.lb.utils/project/package.summary b/org.glite.lb.utils/project/package.summary deleted file mode 100644 index c2476fd..0000000 --- a/org.glite.lb.utils/project/package.summary +++ /dev/null @@ -1 +0,0 @@ -gLite Logging and Bookkeeping auxiliary utilities diff --git a/org.glite.lb.utils/project/properties.xml b/org.glite.lb.utils/project/properties.xml deleted file mode 100644 index 65541d5..0000000 --- a/org.glite.lb.utils/project/properties.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb.utils/project/tar_exclude b/org.glite.lb.utils/project/tar_exclude deleted file mode 100644 index b3133e4..0000000 --- a/org.glite.lb.utils/project/tar_exclude +++ /dev/null @@ -1,10 +0,0 @@ -tar_exclude -CVS -build.xml -build -build.properties -properties.xml -configure-options.xml -.cvsignore -.project -.cdtproject diff --git a/org.glite.lb.utils/project/version.properties b/org.glite.lb.utils/project/version.properties deleted file mode 100755 index 8513689..0000000 --- a/org.glite.lb.utils/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# $Header$ -module.version=2.0.3 -module.age=2 diff --git a/org.glite.lb.utils/src/dump.c b/org.glite.lb.utils/src/dump.c deleted file mode 100644 index 1cbba21..0000000 --- a/org.glite.lb.utils/src/dump.c +++ /dev/null @@ -1,224 +0,0 @@ -#ident "$Header$" - - -#include -#include -#include -#include -#include -#include - -#define CLIENT_SBIN_PROG - -#include "glite/lb/context-int.h" -#include "glite/lb/ulm_parse.h" -#include "glite/lb/xml_parse.h" -#include "glite/lb/mini_http.h" -#include "glite/lb/consumer.h" - -#define dprintf(x) { if (debug) printf x; } - -static const char rcsid[] = "@(#)$Id$"; - -static int debug=0; - -static int edg_wll_DumpEvents( - edg_wll_Context ctx, - const edg_wll_DumpRequest *request, - edg_wll_DumpResult *result); -static void printerr(edg_wll_Context ctx); - -static struct option opts[] = { - { "from", required_argument, NULL, 'f'}, - { "to", required_argument, NULL, 't'}, - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'v' }, - { "debug", no_argument, NULL, 'd' }, - { "server", required_argument, NULL, 'm' }, - { NULL, no_argument, NULL, 0 } -}; - -static void usage(char *me) -{ - fprintf(stderr,"usage: %s [option]\n" - " -f, --from YYYYMMDDHHmmss beginning of the time interval for events to be dumped\n" - " -t, --to YYYYMMDDHHmmss end of the time interval for events to be dumped\n" - " -h, --help display this help\n" - " -v, --version display version\n" - " -d, --debug diagnostic output\n" - " -m, --server L&B server machine name\n", - me); -} - -int main(int argc,char *argv[]) -{ - edg_wll_DumpRequest *request; - edg_wll_DumpResult *result; - char *server = NULL; - char date[ULM_DATE_STRING_LENGTH+1]; - - char *me; - int opt; - edg_wll_Context ctx; - - /* initialize request to server defaults */ - request = (edg_wll_DumpRequest *) calloc(1,sizeof(edg_wll_DumpRequest)); - request->from = EDG_WLL_DUMP_LAST_END; - request->to = EDG_WLL_DUMP_NOW; - - /* initialize result */ - result = (edg_wll_DumpResult *) calloc(1,sizeof(edg_wll_DumpResult)); - - me = strrchr(argv[0],'/'); - if (me) me++; else me=argv[0]; - - /* get arguments */ - while ((opt = getopt_long(argc,argv,"f:t:m:dvh",opts,NULL)) != EOF) { - - switch (opt) { - - case 'f': request->from = (time_t) edg_wll_ULMDateToDouble(optarg); break; - case 't': request->to = (time_t) edg_wll_ULMDateToDouble(optarg); break; - case 'm': server = optarg; break; - case 'd': debug = 1; break; - case 'v': fprintf(stdout,"%s:\t%s\n",me,rcsid); exit(0); - case 'h': - case '?': usage(me); return 1; - } - } - - /* check request */ - if (debug) { - printf("Dump request:\n"); - if (request->from < 0) { - printf("- from: %ld.\n",(long) request->from); - } else { - if (edg_wll_ULMTimevalToDate(request->from,0,date) != 0) { - fprintf(stderr,"Error parsing 'from' argument.\n"); - goto main_end; - } - printf("- from: %ld (i.e. %s).\n",(long) request->from,date); - } - if (request->to < 0) { - printf("- to: %ld.\n",(long) request->to); - } else { - if (edg_wll_ULMTimevalToDate(request->to,0,date) != 0) { - fprintf(stderr,"Error parsing 'to' argument.\n"); - goto main_end; - } - printf("- to: %ld (i.e. %s).\n",(long) request->to,date); - } - } - - /* initialize context */ - edg_wll_InitContext(&ctx); - if ( server ) - { - char *p = strchr(server, ':'); - if ( p ) - { - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, atoi(p+1)); - *p = 0; - } - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server); - } - - /* that is the DumpEvents */ - dprintf(("Running the edg_wll_DumpEvents...\n")); - if (edg_wll_DumpEvents(ctx, request, result) != 0) { - fprintf(stderr,"Error running the edg_wll_DumpEvents().\n"); - printerr(ctx); - switch ( edg_wll_Error(ctx, NULL, NULL) ) - { - case ENOENT: - case EPERM: - case EINVAL: - break; - default: - goto main_end; - } - } - - /* examine the result */ - dprintf(("Examining the result of edg_wll_DumpEvents...\n")); - printf("Dump result:\n"); - if (result->server_file) { - printf("- The jobs were dumped to the file '%s' at the server.\n",result->server_file); - } else { - printf("- The jobs were not dumped.\n"); - } - if (edg_wll_ULMTimevalToDate(result->from,0,date) != 0) { - fprintf(stderr,"Error parsing 'from' argument.\n"); - goto main_end; - } - printf("- from: %ld (i.e. %s).\n",(long) result->from,date); - if (edg_wll_ULMTimevalToDate(result->to,0,date) != 0) { - fprintf(stderr,"Error parsing 'to' argument.\n"); - goto main_end; - } - printf("- to: %ld (i.e. %s).\n",(long) result->to,date); - -main_end: - dprintf(("End.\n")); - if (request) free(request); - if (result) free(result); - edg_wll_FreeContext(ctx); - return 0; -} - - -static void printerr(edg_wll_Context ctx) -{ - char *errt,*errd; - - edg_wll_Error(ctx,&errt,&errd); - fprintf(stderr,"%s (%s)\n",errt,errd); -} - - -static const char* const request_headers[] = { - "Cache-Control: no-cache", - "Accept: application/x-dglb", - "User-Agent: edg_wll_Api/" PROTO_VERSION "/" COMP_PROTO, - "Content-Type: application/x-dglb", - NULL -}; - -/** Dump events in a given time interval - */ - -static int edg_wll_DumpEvents( - edg_wll_Context ctx, - const edg_wll_DumpRequest *request, - edg_wll_DumpResult *result) -{ - int error; - char *send_mess, - *response = NULL, - *recv_mess = NULL; - - edg_wll_DumpRequestToXML(ctx, request, &send_mess); - - ctx->p_tmp_timeout = ctx->p_query_timeout; - if (ctx->p_tmp_timeout.tv_sec < 600) ctx->p_tmp_timeout.tv_sec = 600; - - if (set_server_name_and_port(ctx, NULL)) - goto edg_wll_dumpevents_end; - - error = edg_wll_http_send_recv(ctx, - "POST /dumpRequest HTTP/1.1", request_headers, send_mess, - &response, NULL, &recv_mess); - if ( error != 0 ) - goto edg_wll_dumpevents_end; - - if (http_check_status(ctx, response)) - goto edg_wll_dumpevents_end; - - edg_wll_ParseDumpResult(ctx, recv_mess, result); - -edg_wll_dumpevents_end: - if (response) free(response); - if (recv_mess) free(recv_mess); - if (send_mess) free(send_mess); - return edg_wll_Error(ctx,NULL,NULL); -} diff --git a/org.glite.lb.utils/src/dump_exporter.c b/org.glite.lb.utils/src/dump_exporter.c deleted file mode 100644 index 0bc814d..0000000 --- a/org.glite.lb.utils/src/dump_exporter.c +++ /dev/null @@ -1,390 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "glite/lbu/maildir.h" -#include "glite/lb/context.h" -#include "glite/lb/events.h" -#include "glite/lb/events_parse.h" - - -#define DUMP_FILE_STORE_PREFIX "/tmp" -#define LB_MAILDIR_PATH "/tmp/dumpinfo_lbmd" - -#define KEYNAME_JOBID "jobid " -#define KEYNAME_FILE "file " -#define KEYNAME_JPPS "jpps " -#define REALLOC_CHUNK 10000 - -typedef struct _buffer_t { - char *str; - char *eol; - int sz; - int use; -} buffer_t; - -typedef struct _dump_storage_t { - char *job; - char *fname; - int fhnd; -} dump_storage_t; - -/* hold actual number of records in dump_storage_t structure st (defined below) */ -int number_of_st = 0; - -static const char *optstr = "d:s:j:m:hx"; - -static struct option opts[] = { - { "help", 0, NULL, 'h'}, - { "dump", 0, NULL, 'd'}, - { "store", 0, NULL, 's'}, - { "jpps", 0, NULL, 'j'}, - { "lbmaildir", 0, NULL, 'm'}, - { "mixed", 0, NULL, 'x'}, - { NULL, 0, NULL, 0} -}; - -void usage(char *me) -{ - fprintf(stderr, "usage: %s [option]\n" - "\t-h, --help Shows this screen.\n" - "\t-d, --dump Dump file location.\n" - "\t-s, --store New dump files storage.\n" - "\t-j, --jpps Target JPPS.\n" - "\t-m, --lbmaildir LB maildir path.\n" - "\t-x, --mixed Suppose events in dump file unsorted by jobid (slower).\n" - , me); -} - - -static int read_line(int, buffer_t *, char **); -static dump_storage_t *dump_storage_find_sorted(dump_storage_t *, char *); -static dump_storage_t *dump_storage_find_unsorted(dump_storage_t *, char *); -static dump_storage_t *dump_storage_add(dump_storage_t **, char *, char *, int); -static void dump_storage_free(dump_storage_t *); - -typedef dump_storage_t *(*find_function)(); - -int main(int argc, char **argv) -{ - edg_wll_Context ctx; - edg_wll_Event *ev = NULL; - find_function dump_storage_find = dump_storage_find_sorted; - dump_storage_t *dstorage = NULL, - *last_st = NULL, - *st; - buffer_t buf; - char *store_pref = DUMP_FILE_STORE_PREFIX, - *lb_maildir = LB_MAILDIR_PATH, - *jpps = NULL, - *name, - *fname, - *ln; - int fhnd, - opt, ret, - msg_format_sz; - - - name = strrchr(argv[0], '/'); - if ( name ) name++; else name = argv[0]; - - fname = NULL; - while ( (opt = getopt_long(argc, argv, optstr, opts, NULL)) != EOF ) - switch ( opt ) { - case 'd': fname = optarg; break; - case 's': store_pref = optarg; break; - case 'j': jpps = optarg; break; - case 'm': lb_maildir = optarg; break; - case 'x': dump_storage_find = dump_storage_find_unsorted; break; - case 'h': usage(name); return 0; - case '?': usage(name); return 1; - } - - msg_format_sz = sizeof(KEYNAME_JOBID) + 1 + - sizeof(KEYNAME_FILE) + 1 + - (jpps? sizeof(KEYNAME_JPPS) + 1: 0); - - if ( fname ) { - if ( (fhnd = open(fname, O_RDONLY)) < 0 ) { - perror("Opening input file"); - exit(1); - } - } else fhnd = 0; - - if ( glite_lbu_MaildirInit(lb_maildir) ) { - perror(lbm_errdesc); - exit(1); - } - - -#ifndef cleanup -# define cleanup(r) { ret = (r); goto cleanup_lbl; } -#endif - - ret = 0; - memset(&buf, 0, sizeof(buf)); - edg_wll_InitContext(&ctx); - while ( 1 ) { - int rl_ret, - written, - lnsz, ct; - char *jobid, - *unique; - - if ( (rl_ret = read_line(fhnd, &buf, &ln)) < 0 ) { - perror("reading input file"); - cleanup(1); - } - if ( !ln ) break; - - if (*ln == 0) continue; - - if ( edg_wll_ParseEvent(ctx, ln, &ev) != 0 ) { - cleanup(1); - } - if ( !(jobid = edg_wlc_JobIdUnparse(ev->any.jobId)) ) { - perror("Can't unparse jobid from event"); - cleanup(1); - } - if ( !(unique = edg_wlc_JobIdGetUnique(ev->any.jobId)) ) { - perror("Can't unparse jobid from event"); - cleanup(1); - } - - if ( !(st = dump_storage_find(dstorage, jobid)) ) { - int fd, i; - char fname[PATH_MAX]; - struct timeval tv; - - i = 0; - while ( 1 ) { - if ( ++i > 10 ) { - errno = ECANCELED; - perror("Can't create dump file - max tries limit reached "); - cleanup(1); - } - gettimeofday(&tv, NULL); - snprintf(fname, PATH_MAX, "%s/%s.%ld_%ld", store_pref, unique, tv.tv_sec, tv.tv_usec); - if ( (fd = open(fname, O_CREAT|O_EXCL|O_RDWR, 00640)) < 0 ) { - if ( errno == EEXIST ) { usleep(1000); continue; } - perror(fname); - cleanup(1); - } - break; - } - if (last_st) { - close(last_st->fhnd); - last_st->fhnd = 0; - } - - if ( !(st = dump_storage_add(&dstorage, jobid, fname, fd)) ) { - perror("Can't record dump informations"); - cleanup(1); - } - } - else { - if (strcmp(last_st->fname,st->fname)) { - /* new jobid data */ - // this is only fallback code, because data in lb dump - // are clustered by jobids, hence files are created by - // open() above - close(last_st->fhnd); - last_st->fhnd = 0; - - if ( (st->fhnd = open(st->fname, O_APPEND|O_RDWR)) < 0 ) { - perror(st->fname); - cleanup(1); - } - } - } - free(jobid); - free(unique); - last_st = st; - - lnsz = strlen(ln); - ln[lnsz++] = '\n'; - written = 0; - while ( written < lnsz ) { - if ( (ct = write(st->fhnd, ln+written, lnsz-written)) < 0 ) { - if ( errno == EINTR ) { errno = 0; continue; } - perror(fname); - cleanup(1); - } - written += lnsz; - } - - - if ( !rl_ret ) break; - edg_wll_FreeEvent(ev); ev = NULL; - } - - /* store info in lb_maildir */ - for ( st = dstorage; st && st->job; st++ ) { - char *msg; - if ( !(msg = malloc(msg_format_sz + strlen(st->fname) + strlen(st->job))) ) { - perror("allocating message"); - cleanup(1); - } - if ( jpps ) - /* XXX: used to be 5x %s here, God knows why ... */ - sprintf(msg, "%s%s\n%s%s%s%s", - KEYNAME_JOBID, st->job, KEYNAME_FILE, st->fname, KEYNAME_JPPS, jpps); - else - sprintf(msg, "%s%s\n%s%s", - KEYNAME_JOBID, st->job, KEYNAME_FILE, st->fname); - if ( glite_lbu_MaildirStoreMsg(lb_maildir, "localhost", msg) < 0 ) { - perror(lbm_errdesc); - exit(1); - } - free(msg); - } - -cleanup_lbl: - if (ret) { - char *et, *ed; - - if (edg_wll_Error(ctx,&et,&ed)) { - fprintf(stderr,"\nError during dump processing! Terminating.\n%s: %s\n",et,ed); - free(et); - free(ed); - } - } - edg_wll_FreeContext(ctx); - if ( ev ) edg_wll_FreeEvent(ev); - for ( st = dstorage; st && st->job; st++ ) if ( st->fhnd > 0 ) close(st->fhnd); - dump_storage_free(dstorage); - close(fhnd); - free(buf.str); - - return (ret); -} - - -/* Suppose that dumps in purged dump file are sorted by jobid */ -static dump_storage_t *dump_storage_find_sorted(dump_storage_t *st, char *job) -{ - if (st && (st+number_of_st-1)->job) { - if ( !strcmp(job, (st+number_of_st-1)->job) ) return (st+number_of_st-1); - } - - return NULL; -} - - -/* Suppose that dumps in purged dump file are NOT sorted by jobid - * - * look thru list from the last element to the first - * last element is most likely corresponding to the job we are looking for - */ -static dump_storage_t *dump_storage_find_unsorted(dump_storage_t *st, char *job) -{ - int i; - - st = st + (number_of_st -1); // point to the last element - - for (i=number_of_st; i > 0; i--) { - if (!st || !st->job) return NULL; - if ( !strcmp(job, st->job) ) return st; - st--; - } - return NULL; -} - -static dump_storage_t *dump_storage_add(dump_storage_t **st, char *job, char *fname, int fhnd) -{ - dump_storage_t *tmp; - - if ( !(number_of_st % REALLOC_CHUNK) ) { - *st = realloc(*st, (REALLOC_CHUNK + number_of_st+2)*sizeof(*tmp)); - } - if ( !(*st) ) return NULL; - - tmp = *st + number_of_st; - - if ( !(tmp->job = strdup(job)) ) return NULL; - if ( !(tmp->fname = strdup(fname)) ) { free(tmp->job); (tmp)->job = NULL; return NULL; } - tmp->fhnd = fhnd; - number_of_st++; - (tmp+1)->job = NULL; - - return tmp; -} - -static void dump_storage_free(dump_storage_t *st) -{ - dump_storage_t *tmp; - for ( tmp = st; tmp && tmp->job; tmp++ ) { - free(tmp->job); - free(tmp->fname); - } - free(st); -} - -/* Reads line from file and returns pointer to that. - * Returned string is not mem allocated. It only points to the buffer! - * - * Buffer must be given - it is handled (allocated etc.) fully in the - * function. It has to be freed outside. - * - * returns: -1 on error - * 0 eof ('ln' could points to the last line in file) - * 1 line successfuly read - */ -static int read_line(int fhnd, buffer_t *buf, char **ln) -{ - int ct, toread; - - - if ( buf->eol ) { - int tmp = buf->eol - buf->str + 1; - - if ( tmp < buf->use ) { - char *aux; - if ( (aux = memchr(buf->eol+1, '\n', buf->use-tmp)) ) { - *ln = buf->eol+1; - *aux = 0; - buf->eol = aux; - return 1; - } - } - memmove(buf->str, buf->eol+1, buf->use - tmp); - buf->eol = NULL; - buf->use -= tmp; - } - - do { - if ( buf->use == buf->sz ) { - char *tmp = realloc(buf->str, buf->sz+BUFSIZ); - if ( !tmp ) return -1; - buf->str = tmp; - buf->sz += BUFSIZ; - } - - toread = buf->sz - buf->use; - if ( (ct = read(fhnd, buf->str+buf->use, toread)) < 0 ) { - if ( errno == EINTR ) continue; - return -1; - } - if ( ct == 0 ) break; - buf->eol = memchr(buf->str+buf->use, '\n', ct); - buf->use += ct; - } while ( ct == toread && !buf->eol ); - - *ln = buf->use? buf->str: NULL; - if ( buf->eol ) { - *buf->eol = 0; - return 1; - } - - return 0; -} diff --git a/org.glite.lb.utils/src/glite-lb-bkpurge-offline.sh b/org.glite.lb.utils/src/glite-lb-bkpurge-offline.sh deleted file mode 100644 index 9bc61af..0000000 --- a/org.glite.lb.utils/src/glite-lb-bkpurge-offline.sh +++ /dev/null @@ -1,174 +0,0 @@ -#!/bin/bash - -cat <&2 $0 probably already running! -fi - -if killall -0 glite-lb-bkserverd 2>/dev/null || killall -0 glite-lb-proxy 2>/dev/null -then -echo >&2 glite-lb-bkserverd or glite-lb-proxy running! -fi - -echo -echo -n "Continue (y/n)?"; read r -if [ "$r" = "y" ] -then echo Working... -else echo Aborting.; exit 1; -fi - - -getsecs() { - echo $(($(echo "$1" | sed -e 's/s$//' \ - -e 's/m$/*60/' \ - -e 's/h$/*3600/' \ - -e 's/d$/*86400/') )) -} - -now=$(date "+%s") - -tclause="" -add_tclause() { - case "$1" in - 6|7|8|9) spart="states.status=$1";; - o) spart="(states.status<6 OR states.status>9)";; - esac - if [ -z "$tclause" ]; then concat=""; else concat=" OR ";fi - tclause="$tclause$concat($spart AND states.jobid = es.jobid and states.seq = es.event AND es.arrived $tempfile1 - -ds="DELETE$quick FROM jobs,states,e,short_fields,long_fields,status_tags" -ds="$ds USING states" -ds="$ds LEFT JOIN events AS e ON (e.jobid = states.jobid)" -ds="$ds LEFT JOIN jobs ON (jobs.jobid = states.jobid)" -ds="$ds LEFT JOIN short_fields ON (short_fields.jobid = e.jobid AND short_fields.event=e.event)" -ds="$ds LEFT JOIN long_fields ON (long_fields.jobid = e.jobid AND long_fields.event=e.event)" -ds="$ds LEFT JOIN events_flesh ON (events_flesh.jobid = e.jobid AND events_flesh.event=e.event)" -ds="$ds LEFT JOIN status_tags ON (status_tags.jobid = states.jobid)" - -#wc -l $tempfile1 /dev/null;echo -n "???";read n -( - cnt=0 - echo "SET autocommit=0;" - echo "BEGIN;" - while read jobid - do - echo "UPDATE acls,jobs SET acls.refcnt=acls.refcnt-1 " \ - "WHERE jobs.jobid='$jobid' AND jobs.aclid=acls.aclid;" - echo "$ds WHERE states.jobid='$jobid';" - if [ $(($cnt % 10)) = 9 ] - then - echo "COMMIT;" - echo "BEGIN;" - fi - cnt=$((cnt+1)) - done - echo "DELETE FROM acls WHERE refcnt=0;" - echo "COMMIT;" -) < $tempfile1 | $mysqlcmd -rm $tempfile1 -fi - -if [ "$thorough" = 1 ] -then - ( - for table in acls jobs status_tags events \ - short_fields states long_fields events_flesh - do - echo "OPTIMIZE TABLE $table;" - done - ) | $mysqlcmd -fi - -# TODO: acls/singleshot, grey_jobs, notif_jobs, notif_registrations, users diff --git a/org.glite.lb.utils/src/load.c b/org.glite.lb.utils/src/load.c deleted file mode 100644 index a80dcd0..0000000 --- a/org.glite.lb.utils/src/load.c +++ /dev/null @@ -1,204 +0,0 @@ -#ident "$Header$" - - -#include -#include -#include -#include -#include -#include - -#define CLIENT_SBIN_PROG - -#include "glite/lb/context-int.h" -#include "glite/lb/ulm_parse.h" -#include "glite/lb/xml_parse.h" -#include "glite/lb/mini_http.h" -#include "glite/lb/consumer.h" - -#define dprintf(x) { if (debug) printf x; } - -static const char rcsid[] = "@(#)$Id$"; - -static int debug=0; - -static int edg_wll_LoadEvents( - edg_wll_Context ctx, - const edg_wll_LoadRequest *request, - edg_wll_LoadResult *result); -static void printerr(edg_wll_Context ctx); - -static struct option opts[] = { - { "file", required_argument, NULL, 'f'}, - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'v' }, - { "debug", no_argument, NULL, 'd' }, - { "server", required_argument, NULL, 'm' }, - { NULL, no_argument, NULL, 0 } -}; - -static void usage(char *me) -{ - fprintf(stderr,"usage: %s [option]\n" - " -m, --server L&B server machine name\n" - " -f, --file filename file with dumped data to be loaded\n" - " -h, --help display this help\n" - " -v, --version display version\n" - " -d, --debug diagnostic output\n", - me); -} - -int main(int argc,char *argv[]) -{ - edg_wll_LoadRequest *request; - edg_wll_LoadResult *result; - char *server = NULL; - char date[ULM_DATE_STRING_LENGTH+1]; - - char *me; - int opt; - edg_wll_Context ctx; - - /* initialize request to server defaults */ - request = (edg_wll_LoadRequest *) calloc(1,sizeof(edg_wll_LoadRequest)); - request->server_file = NULL; - - /* initialize result */ - result = (edg_wll_LoadResult *) calloc(1,sizeof(edg_wll_LoadResult)); - - me = strrchr(argv[0],'/'); - if (me) me++; else me=argv[0]; - - /* get arguments */ - while ((opt = getopt_long(argc,argv,"f:t:m:dvh",opts,NULL)) != EOF) { - - switch (opt) { - - case 'f': request->server_file = optarg; break; - case 'm': server = optarg; break; - case 'd': debug = 1; break; - case 'v': fprintf(stdout,"%s:\t%s\n",me,rcsid); exit(0); - case 'h': - case '?': usage(me); return 1; - } - } - - /* initialize context */ - edg_wll_InitContext(&ctx); - if ( server ) - { - char *p = strchr(server, ':'); - if ( p ) - { - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, atoi(p+1)); - *p = 0; - } - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server); - } - - /* check request */ - if (debug) { - printf("Load request:\n"); - if (request->server_file) { - printf("- server_file: %s.\n",request->server_file); - } else { - printf("- server_file: not specified.\n"); - } - } - - /* that is the LoadEvents */ - dprintf(("Running the edg_wll_LoadEvents...\n")); - if (edg_wll_LoadEvents(ctx, request, result) != 0) { - fprintf(stderr,"Error running the edg_wll_LoadEvents().\n"); - printerr(ctx); - if ( !result->server_file ) - goto main_end; - } - - /* examine the result */ - dprintf(("Examining the result of edg_wll_LoadEvents...\n")); - printf("Load result:\n"); - if (result->server_file) - printf("- Unloaded events were stored into the server file '%s'.\n", result->server_file); - if (edg_wll_ULMTimevalToDate(result->from,0,date) != 0) { - fprintf(stderr,"Error parsing 'from' argument.\n"); - goto main_end; - } - printf("- from: %ld (i.e. %s).\n",result->from,date); - if (edg_wll_ULMTimevalToDate(result->to,0,date) != 0) { - fprintf(stderr,"Error parsing 'to' argument.\n"); - goto main_end; - } - printf("- to: %ld (i.e. %s).\n",result->to,date); - -main_end: - dprintf(("End.\n")); - if (request) free(request); - if (result) - { - if (result->server_file) - free(result->server_file); - free(result); - } - edg_wll_FreeContext(ctx); - return 0; -} - - -static void printerr(edg_wll_Context ctx) -{ - char *errt,*errd; - - edg_wll_Error(ctx,&errt,&errd); - fprintf(stderr,"%s (%s)\n",errt,errd); -} - - -static const char* const request_headers[] = { - "Cache-Control: no-cache", - "Accept: application/x-dglb", - "User-Agent: edg_wll_Api/" PROTO_VERSION "/" COMP_PROTO, - "Content-Type: application/x-dglb", - NULL -}; - -/** Load events from a given file into the database - * \retval EPERM operation not permitted - * \retval ENOENT file not found - */ - -static int edg_wll_LoadEvents( - edg_wll_Context ctx, - const edg_wll_LoadRequest *request, - edg_wll_LoadResult *result) -{ - int error; - char *send_mess, - *response = NULL, - *recv_mess = NULL; - - edg_wll_LoadRequestToXML(ctx, request, &send_mess); - - ctx->p_tmp_timeout = ctx->p_query_timeout; - if (ctx->p_tmp_timeout.tv_sec < 600) ctx->p_tmp_timeout.tv_sec = 600; - - if (set_server_name_and_port(ctx, NULL)) - goto edg_wll_loadevents_end; - - error = edg_wll_http_send_recv(ctx, - "POST /loadRequest HTTP/1.1", request_headers, send_mess, - &response, NULL, &recv_mess); - if ( error != 0 ) - goto edg_wll_loadevents_end; - - if (http_check_status(ctx, response)) - goto edg_wll_loadevents_end; - - edg_wll_ParseLoadResult(ctx, recv_mess, result); - -edg_wll_loadevents_end: - if (response) free(response); - if (recv_mess) free(recv_mess); - if (send_mess) free(send_mess); - return edg_wll_Error(ctx,NULL,NULL); -} diff --git a/org.glite.lb.utils/src/mon.c b/org.glite.lb.utils/src/mon.c deleted file mode 100644 index afabd44..0000000 --- a/org.glite.lb.utils/src/mon.c +++ /dev/null @@ -1,171 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lb/consumer.h" - -#define DEFAULT_QUERY_TIME 3600 - -static void usage(char *); -static int query_all(edg_wll_Context, int, struct timeval, edg_wll_JobStat **); -static void dgerr(edg_wll_Context,char *); - -static char *myname = NULL; -static int debug = 0, verbose = 0, seconds = DEFAULT_QUERY_TIME, lbproxy = 0; -static const char rcsid[] = "@(#)$Id$"; - -static struct option const long_options[] = { - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'V' }, - { "verbose", no_argument, 0, 'v' }, - { "debug", no_argument, 0, 'd' }, - { "time", required_argument, 0, 't' }, - { "lbproxy", required_argument, 0, 'x' }, - { NULL, 0, NULL, 0} -}; - -int main(int argc,char *argv[]) { - edg_wll_Context ctx; - edg_wll_JobStat *statesOut = NULL; - struct timeval time_now; - int state[4] = { EDG_WLL_JOB_CLEARED, EDG_WLL_JOB_ABORTED, EDG_WLL_JOB_CANCELLED, EDG_WLL_JOB_SUBMITTED }; - - int i, j, result, opt; - result = opt = 0; - - myname = argv[0]; - fprintf(stdout,"\n"); - /* get arguments */ - while ((opt = getopt_long(argc,argv, - "h" /* help */ - "V" /* version */ - "v" /* verbose */ - "d" /* debug */ - "t:" /* time [in seconds] */ - "x", /* lbproxy */ - long_options, (int *) 0)) != EOF) { - - switch (opt) { - case 'V': fprintf(stdout,"%s:\t%s\n",argv[0],rcsid); exit(0); - case 'v': verbose = 1; break; - case 'd': debug = 1; break; - case 'x': lbproxy = 1; break; - case 't': seconds = atoi(optarg); break; - case 'h': - default: - usage(argv[0]); exit(0); - } - } - gettimeofday(&time_now,0); - - if ( edg_wll_InitContext(&ctx) ) { - fprintf(stderr,"%s: cannot initialize edg_wll_Context\n ",myname); - exit(1); - } - - for ( j = 0; j < sizeof(state)/sizeof(state[0]); j++) { - char *status = edg_wll_StatToString(state[j]); - int min,avg,max,nJobs; - - avg = max = nJobs = 0; - min = INT_MAX; - - fprintf(stdout,"Jobs that entered state %s in the last %d seconds: \n",status,seconds); - - if ( (result = query_all(ctx, state[j], time_now, &statesOut)) ) { - dgerr(ctx, "edg_wll_QueryJobs"); - } else { - if ( statesOut ) { - for (i=0; statesOut[i].state; i++) { - int val = statesOut[0].stateEnterTime.tv_sec - - statesOut[0].stateEnterTimes[1+EDG_WLL_JOB_SUBMITTED]; - - avg += val; - if (val < min) min = val; - if (val > max) max = val; - - edg_wll_FreeStatus(&statesOut[i]); - } - nJobs = i; - free(statesOut); - } - if (nJobs > 0) avg = avg / nJobs; - if (min == INT_MAX) min = 0; - - fprintf(stdout,"number of jobs: %d\n",nJobs); - if (state[j] != EDG_WLL_JOB_SUBMITTED) { - fprintf(stdout,"minimum time spent in the system: %d seconds\n",min); - fprintf(stdout,"average time spent in the system: %d seconds\n",avg); - fprintf(stdout,"maximum time spent in the system: %d seconds\n",max); - } - fprintf(stdout,"\n\n"); - } - - if (status) free(status); - - } - edg_wll_FreeContext(ctx); - - - return result; -} - -static void -usage(char *name) { - fprintf(stdout, "Usage: %s [-x] [-t time]\n" - "-h, --help display this help and exit\n" - "-t, --time querying time in seconds from now to the past [deault %d]\n", - name, DEFAULT_QUERY_TIME); -} - -static int -query_all(edg_wll_Context ctx, int query_status, struct timeval query_time, edg_wll_JobStat **statesOut) { - edg_wll_QueryRec jc[3]; - int ret; - - memset(jc, 0, sizeof jc); - - /* jobs in the state 'query_status' within last hour */ - jc[0].attr = EDG_WLL_QUERY_ATTR_STATUS; - jc[0].op = EDG_WLL_QUERY_OP_EQUAL; - jc[0].value.i = query_status; - jc[1].attr = EDG_WLL_QUERY_ATTR_TIME; - jc[1].attr_id.state = query_status; - jc[1].op = EDG_WLL_QUERY_OP_WITHIN; - jc[1].value.t.tv_sec = query_time.tv_sec - seconds; - jc[1].value.t.tv_usec = query_time.tv_usec; - jc[1].value2.t.tv_sec = query_time.tv_sec; - jc[1].value2.t.tv_usec = query_time.tv_usec; - jc[2].attr = EDG_WLL_QUERY_ATTR_UNDEF; - - if ( (ret = edg_wll_QueryJobs(ctx, jc, 0, NULL, statesOut)) ) { - if ( ret == E2BIG ) { - int r; - if ( edg_wll_GetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, &r) ) return ret; - if ( r != EDG_WLL_QUERYRES_LIMITED ) return ret; - - fprintf(stderr," edg_wll_QueryJobs() Warning: only limited result returned!\n"); - return 0; - } else return ret; - } - - return ret; -} - -static void -dgerr(edg_wll_Context ctx,char *where) { - char *etxt,*edsc; - - edg_wll_Error(ctx,&etxt,&edsc); - fprintf(stderr,"%s: %s: %s",myname,where,etxt); - if (edsc) fprintf(stderr," (%s)",edsc); - putc('\n',stderr); - if(etxt) free(etxt); - if(edsc) free(edsc); -} diff --git a/org.glite.lb.utils/src/process_attrs.c b/org.glite.lb.utils/src/process_attrs.c deleted file mode 100644 index 9b03c46..0000000 --- a/org.glite.lb.utils/src/process_attrs.c +++ /dev/null @@ -1,220 +0,0 @@ -#include -#include -#include - -#include "glite/lbu/trio.h" - -#include "glite/jp/types.h" -#include "glite/jp/context.h" -#include "glite/jp/file_plugin.h" -#include "glite/jp/attr.h" -#include "glite/lb/job_attrs.h" - -/* - * free the array of JP attr - */ -static void free_attrs(glite_jp_attrval_t *av) { - glite_jp_attrval_t *item; - - item = av; - while (item->name) { - glite_jp_attrval_free(item++, 0); - } - free(av); -} - -/* - * process attributes - */ -void process_attrs(glite_jp_context_t jpctx, glite_jpps_fplug_data_t plugin_data, void *data_handle, FILE *outfile) { - - glite_jp_attrval_t *attrval; - - /*
    */ - trio_fprintf(outfile,"\n\n"); - trio_fprintf(outfile,"value); - free_attrs(attrval); - } else { - trio_fprintf(outfile,"jobid=\"default\"\n"); - } - trio_fprintf(outfile,">\n"); - /*
    */ - - /* */ - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_user, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_parent, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_VO, &attrval); - if (attrval) { - trio_fprintf(stdout,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_aTag, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_rQType, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_eDuration, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_eNodes, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_eProc, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_RB, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_CE, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_host, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_UIHost, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_CPUTime, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_NProc, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_finalStatus, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_finalDoneStatus, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_finalStatusDate, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_finalStatusReason, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_LRMSDoneStatus, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_LRMSStatusReason, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_retryCount, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_additionalReason, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_jobType, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_nsubjobs, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_subjobs, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_lastStatusHistory, &attrval); - if (attrval) { - trio_fprintf(outfile,"%s\n",attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_fullStatusHistory, &attrval); - if (attrval) { - trio_fprintf(outfile,"%s\n",attrval->value); - free_attrs(attrval); - } - - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_JDL, &attrval); - if (attrval) { - trio_fprintf(outfile,"%|Xs\n", attrval->value); - free_attrs(attrval); - } - - /* */ - - trio_fprintf(outfile,"\n\n"); -} diff --git a/org.glite.lb.utils/src/process_attrs2.c.T b/org.glite.lb.utils/src/process_attrs2.c.T deleted file mode 100644 index 3467d29..0000000 --- a/org.glite.lb.utils/src/process_attrs2.c.T +++ /dev/null @@ -1,85 +0,0 @@ -#ident "$Header$" -/* -@@@AUTO -*/ -@@@LANG: C - -#include -#include -#include - -#include "glite/lbu/trio.h" - -#include "glite/jp/types.h" -#include "glite/jp/context.h" -#include "glite/jp/file_plugin.h" -#include "glite/jp/attr.h" -#include "glite/lb/job_attrs2.h" - -/* - * free the array of JP attr - */ -static void free_attrs(glite_jp_attrval_t *av) { - glite_jp_attrval_t *item; - - item = av; - while (item->name) { - glite_jp_attrval_free(item++, 0); - } - free(av); -} - -/* - * process attributes - */ -void process_attrs2(glite_jp_context_t jpctx, glite_jpps_fplug_data_t plugin_data, void *data_handle, FILE *outfile) { - - glite_jp_attrval_t *attrval; - - /*
    */ - fprintf(outfile,"\n\n"); - fprintf(outfile,"value); - free_attrs(attrval); - } else { - fprintf(outfile,"jobid=\"default\"\n"); - } - fprintf(outfile,">\n"); - /*
    */ - - /* */ -@@@{ -# elems - for my $n ($status->getAllFieldsOrdered) { - my $f = selectField $status $n; -# my $type = getType $f; - my $type = $f->{type}; - my $name = getName $f; - -# $type = 'jobtypeType' if $name eq 'jobtype'; - - @ln = split /_/,$name; - my $un = shift @ln; $un .= ucfirst shift @ln while (@ln); - my $c = getComment $f; - my $strformat = "%s"; - if ($type eq 'string') { $strformat = "%|Xs"; } - - gen qq{ - /** $c */ - plugin_data.ops.attr(jpctx, data_handle, GLITE_JP_LB_$un, &attrval); - if (attrval) { - trio_fprintf(outfile,"<$un>$strformat\\n", attrval->value); - free_attrs(attrval); - } -}; - - } -@@@} - fprintf(outfile,"\n\n"); - - /* */ -} diff --git a/org.glite.lb.utils/src/purge.c b/org.glite.lb.utils/src/purge.c deleted file mode 100644 index 9529e74..0000000 --- a/org.glite.lb.utils/src/purge.c +++ /dev/null @@ -1,447 +0,0 @@ -#ident "$Header$" - - -#include -#include -#include -#include -#include -#include - -#define CLIENT_SBIN_PROG - -#include "glite/lb/context-int.h" -#include "glite/lb/xml_parse.h" -#include "glite/lb/mini_http.h" -#include "glite/lb/query_rec.h" -#include "glite/lb/consumer.h" -#include "glite/lb/connection.h" - -#define dprintf(x) { if (debug) printf x; } - -#define free_jobs(jobs) { \ - if (jobs) { \ - int i; \ - for ( i = 0; jobs[i]; i++ ) \ - free(jobs[i]); \ - free(jobs); \ - } \ -} - -static const char rcsid[] = "@(#)$Id$"; - -static int debug=0; -static char *file; - -static int edg_wll_Purge( - edg_wll_Context ctx, - edg_wll_PurgeRequest *request, - edg_wll_PurgeResult *result); -static int read_jobIds(const char *file, char ***jobs_out); -static int get_timeout(const char *arg, int *timeout); -static void printerr(edg_wll_Context ctx); - -static struct option opts[] = { - { "aborted", required_argument, NULL, 'a'}, - { "cleared", required_argument, NULL, 'c'}, - { "cancelled", required_argument, NULL, 'n'}, - { "done", required_argument, NULL, 'e'}, - { "other", required_argument, NULL, 'o'}, - { "dry-run", no_argument, NULL, 'r'}, - { "jobs", required_argument, NULL, 'j'}, - { "return-list", no_argument, NULL, 'l'}, - { "server-dump", no_argument, NULL, 's'}, - { "client-dump", no_argument, NULL, 'i'}, - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'v' }, - { "debug", no_argument, NULL, 'd' }, - { "server", required_argument, NULL, 'm' }, - { "proxy", no_argument, NULL, 'x' }, - { "sock", required_argument, NULL, 'X' }, - {"target-runtime", required_argument, NULL, 't'}, - {"background", required_argument, NULL, 'b'}, - { NULL, no_argument, NULL, 0 } -}; - -static void usage(char *me) -{ - fprintf(stderr,"usage: %s [option]\n" - " -a, --aborted NNN[smhd] purge ABORTED jobs older than NNN secs/mins/hours/days\n" - " -c, --cleared NNN[smhd] purge CLEARED jobs older than given time\n" - " -n, --cancelled NNN[smhd] purge CANCELLED jobs older than given time\n" - " -e, --done NNN[smhd] purge DONE jobs older than given time\n" - " -o, --other NNN[smhd] purge OTHER jobs older than given time\n" - " -r, --dry-run do not really purge\n" - " -j, --jobs input file with jobIds of jobs to purge\n" - " -l, --return-list return list of jobid matching the purge/dump criteria\n" - " -s, --server-dump dump jobs into any server file\n" - " -i, --client-dump receive stream of dumped jobs\n" - " -h, --help display this help\n" - " -v, --version display version\n" - " -d, --debug diagnostic output\n" - " -m, --server L&B server machine name\n" - " -x, --proxy purge L&B proxy\n" - " -X, --sock purge L&B proxy using default socket path\n" - " -t, --target-runtime NNN[smhd] throttle purge to the estimated target runtime\n" - " -b, --background purge on the background\n", - me); -} - -int main(int argc,char *argv[]) -{ - edg_wll_PurgeRequest *request; - edg_wll_PurgeResult *result; - int i, timeout, background; - char *server = NULL; - - char *me; - int opt; - edg_wll_Context ctx; - - /* initialize request to server defaults */ - request = (edg_wll_PurgeRequest *) calloc(1,sizeof(edg_wll_PurgeRequest)); - request->jobs = NULL; - for (i=0; i < EDG_WLL_NUMBER_OF_STATCODES; i++) { - request->timeout[i]=-1; - } - request->flags = EDG_WLL_PURGE_REALLY_PURGE; - - /* initialize result */ - result = (edg_wll_PurgeResult *) calloc(1,sizeof(edg_wll_PurgeResult)); - - me = strrchr(argv[0],'/'); - if (me) me++; else me=argv[0]; - - /* initialize context */ - edg_wll_InitContext(&ctx); - - /* get arguments */ - while ((opt = getopt_long(argc,argv,"a:c:n:e:o:j:m:rlsidhvxX:t:b:",opts,NULL)) != EOF) { - timeout=-1; - background=-1; - - switch (opt) { - - case 'a': - if ((get_timeout(optarg,&timeout) != 0 )) { - printf("Wrong usage of timeout argument.\n"); - usage(me); - return 1; - } - if (timeout >= 0) { - request->timeout[EDG_WLL_JOB_ABORTED]=timeout; - } - break; - - case 'c': - if (get_timeout(optarg,&timeout) != 0 ) { - printf("Wrong usage of timeout argument.\n"); - usage(me); - return 1; - } - if (timeout >= 0) { - request->timeout[EDG_WLL_JOB_CLEARED]=timeout; - } - break; - - case 'n': - if (get_timeout(optarg,&timeout) != 0 ) { - printf("Wrong usage of timeout argument.\n"); - usage(me); - return 1; - } - if (timeout >= 0) { - request->timeout[EDG_WLL_JOB_CANCELLED]=timeout; - } - break; - case 'e': - if (get_timeout(optarg,&timeout) != 0 ) { - printf("Wrong usage of timeout argument.\n"); - usage(me); - return 1; - } - if (timeout >= 0) { - request->timeout[EDG_WLL_JOB_DONE]=timeout; - } - break; - - case 'o': - if (get_timeout(optarg,&timeout) != 0 ) { - printf("Wrong usage of timeout argument.\n"); - usage(me); - return 1; - } - if (timeout >= 0) - for (i = 0 ; itimeout[i]= timeout; - } - break; - - case 'm': server = optarg; break; - case 'j': file = optarg; break; - case 'r': request->flags &= (~EDG_WLL_PURGE_REALLY_PURGE); break; - case 'l': request->flags |= EDG_WLL_PURGE_LIST_JOBS; break; - case 's': request->flags |= EDG_WLL_PURGE_SERVER_DUMP; break; - case 'i': request->flags |= EDG_WLL_PURGE_CLIENT_DUMP; break; - case 'd': debug = 1; break; - case 'v': fprintf(stdout,"%s:\t%s\n",me,rcsid); exit(0); - case 'x': ctx->isProxy = 1; break; - case 'X': - ctx->isProxy = 1; - edg_wll_SetParam(ctx, EDG_WLL_PARAM_LBPROXY_SERVE_SOCK, optarg); - break; - case 't': - if ((get_timeout(optarg,&timeout) != 0 )) { - printf("Wrong usage of timeout argument.\n"); - usage(me); - return 1; - } - if (timeout >= 0) { - request->target_runtime=timeout; - } - break; - case 'b': - background = atoi(optarg); - break; - case 'h': - case '?': usage(me); return 1; - } - - if ((background == -1 && request->target_runtime) || background > 0) - request->flags |= EDG_WLL_PURGE_BACKGROUND; - } - - /* read the jobIds from file, if wanted */ - if (file) { - char **jobs=NULL; - dprintf(("Reading jobIds form file \'%s\'...",file)); - if (read_jobIds(file,&jobs) != 0) { - dprintf(("no.\n")); - fprintf(stderr,"Unable to read jobIds from file \'%s\'\n",file); - goto main_end; - } else { - dprintf(("yes.\n")); - } - request->jobs = jobs; - } - - /* check request */ - if (debug) { - printf("Purge request:\n"); - printf("- flags: %d\n",request->flags); - printf("- %d timeouts:\n",EDG_WLL_NUMBER_OF_STATCODES); - for (i=0; i < EDG_WLL_NUMBER_OF_STATCODES; i++) { - char *stat=edg_wll_StatToString(i); - printf("\t%s: %ld\n",stat,request->timeout[i]); - if (stat) free(stat); - } - printf("- list of jobs:\n"); - if (!request->jobs) { - printf("Not specified.\n"); - } else { - for ( i = 0; request->jobs[i]; i++ ) - printf("%s\n", request->jobs[i]); - } - printf("- target runtime: %ld\n", request->target_runtime); - } - - if ( server ) - { - char *p = strchr(server, ':'); - if ( p ) - { - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER_PORT, atoi(p+1)); - *p = 0; - } - edg_wll_SetParam(ctx, EDG_WLL_PARAM_QUERY_SERVER, server); - } - - /* that is the Purge */ - dprintf(("Running the edg_wll_Purge...\n")); - if (edg_wll_Purge(ctx, request, result) != 0) { - fprintf(stderr,"Error running the edg_wll_Purge().\n"); - printerr(ctx); - switch ( edg_wll_Error(ctx, NULL, NULL) ) - { - case ENOENT: - case EPERM: - case EINVAL: - break; - default: - goto main_end; - } - } - - /* examine the result */ - dprintf(("Examining the result of edg_wll_Purge...\n")); - if (result->server_file) { - printf("Server dump: %s\n",result->server_file); - } else { - printf("The jobs were not dumped.\n"); - } - if (request->flags & EDG_WLL_PURGE_LIST_JOBS) { - printf("The following jobs %s purged:\n", - request->flags & EDG_WLL_PURGE_REALLY_PURGE ? "were" : "would be"); - if (!result->jobs) printf("None.\n"); - else { - int i; - for ( i = 0; result->jobs[i]; i++ ) - printf("%s\n",result->jobs[i]); - } - } - -main_end: - dprintf(("End.\n")); - if (request) - { - free_jobs(request->jobs); - free(request); - } - if (result) free(result); - edg_wll_FreeContext(ctx); - return 0; -} - - -static void printerr(edg_wll_Context ctx) -{ - char *errt,*errd; - - edg_wll_Error(ctx,&errt,&errd); - fprintf(stderr,"%s (%s)\n",errt,errd); -} - - -static int read_jobIds(const char *file, char ***jobs_out) -{ - FILE *jobIds = fopen(file,"r"); - char buf[256]; - char **jobs; - int cnt = 0; - - jobs = NULL; - - - if (!jobIds) { - perror(file); - return 1; - } - - while ( 1 ) { - char *nl; - if ( !fgets(buf,sizeof buf,jobIds) ) - { - if (feof(jobIds)) - break; - - free_jobs(jobs); - fprintf(stderr, "Error reading file\n"); - return 1; - } - nl = strchr(buf,'\n'); - if (nl) *nl = 0; - /* TODO: check if it is really jobId, e.g. by edg_wlc_JobIdParse() */ - - if ( !(jobs = realloc(jobs, (cnt+2)*sizeof(*jobs))) ) - { - perror("cond_parse()"); - return(1); - } - jobs[cnt++] = strdup(buf); - } - jobs[cnt] = NULL; - - fclose(jobIds); - *jobs_out = jobs; - - return 0; -} - -static int get_timeout(const char *arg, int *timeout) -{ - int t = -1; - char tunit = '\0'; - - if (sscanf(arg,"%d%c",&t,&tunit) > 0) { - if (tunit) { - switch (tunit) { - case 'd': t *= 86400; break; // 24*60*60 - case 'h': t *= 3600; break; // 60*60 - case 'm': t *= 60; break; - case 's': break; - default: fprintf(stderr,"Allowed time units are s,m,h,d\n"); - return -1; - } - } - } - if (t < 0) return -1; - *timeout = t; - return 0; -} - -static const char* const request_headers[] = { - "Cache-Control: no-cache", - "Accept: application/x-dglb", - "User-Agent: edg_wll_Api/" PROTO_VERSION "/" COMP_PROTO, - "Content-Type: application/x-dglb", - NULL -}; - -/** Client side purge - * \retval EAGAIN only partial result returned, call repeatedly to get all - * output data - */ -static int edg_wll_Purge( - edg_wll_Context ctx, - edg_wll_PurgeRequest *request, - edg_wll_PurgeResult *result) -{ - char *send_mess, - *response = NULL, - *recv_mess = NULL; - - edg_wll_ResetError(ctx); - - if (request->flags & EDG_WLL_PURGE_CLIENT_DUMP) - return edg_wll_SetError(ctx,ENOSYS,"client dump"); - - if (edg_wll_PurgeRequestToXML(ctx, request, &send_mess)) - goto edg_wll_purge_end; - - ctx->p_tmp_timeout = ctx->p_query_timeout; - if (ctx->p_tmp_timeout.tv_sec < 600) ctx->p_tmp_timeout.tv_sec = 600; - - - if (ctx->isProxy){ - ctx->isProxy = 0; - if (edg_wll_http_send_recv_proxy(ctx, "POST /purgeRequest HTTP/1.1", - request_headers,send_mess,&response,NULL,&recv_mess)) - goto edg_wll_purge_end; - } - else { - if (set_server_name_and_port(ctx, NULL)) - goto edg_wll_purge_end; - - if (edg_wll_http_send_recv(ctx, - "POST /purgeRequest HTTP/1.1", request_headers, send_mess, - &response, NULL, &recv_mess)) - goto edg_wll_purge_end; - } - - if (http_check_status(ctx, response)) - goto edg_wll_purge_end; - - if (edg_wll_ParsePurgeResult(ctx, recv_mess, result)) - goto edg_wll_purge_end; - -edg_wll_purge_end: - if (response) free(response); - if (recv_mess) free(recv_mess); - if (send_mess) free(send_mess); - return edg_wll_Error(ctx,NULL,NULL); -} diff --git a/org.glite.lb.utils/src/state_history.c b/org.glite.lb.utils/src/state_history.c deleted file mode 100644 index 6c38ba1..0000000 --- a/org.glite.lb.utils/src/state_history.c +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include - -#include "glite/lb/context.h" -#include "glite/lb/consumer.h" - -#include "glite/lb/intjobstat.h" -#include "glite/lb/seqcode_aux.h" -#include "glite/lb/stat_fields.h" -#include "glite/lb/process_event.h" - -#define usage() { \ - fprintf(stderr,"usage: %s [-f fields] \n",argv[0]); \ - fprintf(stderr,"\navailable fields:\n\t"); \ - glite_lb_dump_stat_fields(); \ - putc(10,stderr); \ -} - -int main (int argc, char ** argv) -{ - edg_wll_Context ctx; - edg_wll_QueryRec jc[2]; - edg_wll_Event *events; - int i,n,opt; - intJobStat is; - char *farg = "network_server,jdl:VirtualOrganisation,destination,done_code,reason"; - void *fields; - - while ((opt = getopt(argc,argv,"f:")) != -1) switch (opt) { - case 'f': farg = optarg; break; - default: usage(); return 1; - } - - - memset(&jc,0,sizeof jc); - if (optind+1 != argc - || glite_jobid_parse(argv[optind],&jc[0].value.j) - || glite_lb_parse_stat_fields(farg,&fields)) - { - usage(); - return 1; - } - - - edg_wll_InitContext(&ctx); - jc[0].attr = EDG_WLL_QUERY_ATTR_JOBID; - jc[0].op = EDG_WLL_QUERY_OP_EQUAL; - - if (edg_wll_QueryEvents(ctx,jc,NULL,&events)) { - char *ed,*et; - edg_wll_Error(ctx,&et,&ed); - fprintf(stderr,"%s: %s (%s)\n",argv[1],et,ed); - return 1; - } - - for (n=0; events[n].type; n++); - - init_intJobStat(&is); - glite_jobid_dup(jc[0].value.j,&is.pub.jobId); - - qsort(events,n,sizeof *events,compare_events_by_seq); - - for (i=0; i -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/lb/context.h" -#include "glite/lb/jobstat.h" - -#include "glite/jp/types.h" -#include "glite/jp/context.h" -#include "glite/jp/backend.h" -#include "glite/jp/file_plugin.h" -#include "glite/jp/known_attr.h" -#include "glite/jp/attr.h" -#include "glite/lb/job_attrs.h" - - -typedef int init_f(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data); -typedef void done_f(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data); - -void process_attrs(glite_jp_context_t jpctx, glite_jpps_fplug_data_t plugin_data, void *data_handle, FILE *outfile); -void process_attrs2(glite_jp_context_t jpctx, glite_jpps_fplug_data_t plugin_data, void *data_handle, FILE *outfile); - -static const char rcsid[] = "@(#)$Id$"; -static int verbose = 0; -static char *infilename = NULL; -static char *outfilename = NULL; -static int versionone = 0; - -static struct option const long_options[] = { - { "file", required_argument, 0, 'f' }, - { "outfile", required_argument, 0, 'o' }, - { "versionone", no_argument, 0, '1' }, - { "help", no_argument, 0, 'h' }, - { "verbose", no_argument, 0, 'v' }, - { "version", no_argument, 0, 'V' }, - { NULL, 0, NULL, 0} -}; - -/* - * usage - */ -static void -usage(char *program_name) { - fprintf(stdout,"LB statistics\n" - "- reads a dump file (one job only!) \n" - "- and outputs an XML with statistics to stdout \n\n" - "Usage: %s [option]\n" - "-h, --help display this help and exit\n" - "-V, --version output version information and exit\n" - "-v, --verbose print extensive debug output to stderr\n" - "-f, --file dump file to process\n" - "-o, --outfile output filename\n" - "-1, --versionone use version 1 of the attributes (obsolete now)\n\n", - program_name); -} - -/* - * substitute implementatin of JP backend - */ - -int glite_jppsbe_pread(glite_jp_context_t ctx, void *handle, void *buf, size_t nbytes, off_t offset, ssize_t *nbytes_ret) { - FILE *f; - - f = (FILE *)handle; - if (fseek(f, offset, SEEK_SET) != 0) { - *nbytes_ret = 0; - return 0; - } - *nbytes_ret = fread(buf, 1, nbytes, f); - - return ferror(f) ? 1 : 0; -} - -/* - * main - */ -int main(int argc, char *argv[]) -{ - glite_jp_context_t jpctx; - glite_jpps_fplug_data_t plugin_data; - void *data_handle, *lib_handle; - FILE *infile,*outfile = NULL; - char *err; - init_f *plugin_init; - done_f *plugin_done; - int opt; - - /* get arguments */ - while ((opt = getopt_long(argc,argv, - "f:" /* input file */ - "o:" /* output file */ - "1" /* version one of the attributes */ - "h" /* help */ - "v" /* verbose */ - "V", /* version */ - long_options, (int *) 0)) != EOF) { - - switch (opt) { - case 'V': fprintf(stdout,"%s:\t%s\n",argv[0],rcsid); return(0); - case 'v': verbose = 1; break; - case 'f': infilename = optarg; break; - case 'o': outfilename = optarg; break; - case '1': versionone = 1; break; - case 'h': - default: - usage(argv[0]); return(0); - } - } - - /* load L&B plugin and its 'init' symbol */ - if ((lib_handle = dlopen("glite_lb_plugin.so", RTLD_LAZY)) == NULL) { - err = dlerror() ? :"unknown error"; - fprintf(stderr,"lb_statistics: can't load L&B plugin (%s)\n", err); - return 1; - } else if (verbose) fprintf(stdout,"lb_statistics: loaded L&B plugin\n"); - - if ((plugin_init = dlsym(lib_handle, "init")) == NULL || - (plugin_done = dlsym(lib_handle, "done")) == NULL) { - err = dlerror() ? : "unknown error"; - fprintf(stderr,"lb_statistics: can't find symbol 'init' or 'done' (%s)\n", err); - dlclose(lib_handle); - return 1; - } else if (verbose) fprintf(stdout,"lb_statistics: L&B plugin check o.k.\n"); - - /* dump file with events */ - if ((infile = fopen(infilename, "rt")) == NULL) { - fprintf(stderr,"lb_statistics: Error opening file %s: %s\n", infilename, strerror(errno)); - dlclose(lib_handle); - return 1; - } else if (verbose) fprintf(stdout,"lb_statistics: opened input file %s\n", infilename); - - /* output filename */ - if (outfilename) { - if ((outfile = fopen(outfilename, "wt")) == NULL) { - fprintf(stderr,"lb_statistics: Error opening file %s: %s\n", outfilename, strerror(errno)); - dlclose(lib_handle); - fclose(infile); - } else if (verbose) fprintf(stdout,"lb_statistics: opened output file %s\n", outfilename); - } else { - outfile = stdout; - if (verbose) fprintf(stdout,"lb_statistics: output will go to stdout\n"); - } - - /* use the plugin */ - jpctx = calloc(1,sizeof *jpctx); - plugin_init(jpctx, &plugin_data); - - jpctx->plugins = calloc(2,sizeof(*jpctx->plugins)); - jpctx->plugins[0] = &plugin_data; - - plugin_data.ops.open(jpctx, infile, "uri://", &data_handle); - - if (data_handle) { - - if (versionone) { - process_attrs(jpctx, plugin_data, data_handle, outfile); - } else { - process_attrs2(jpctx, plugin_data, data_handle, outfile); - } - - plugin_data.ops.close(jpctx, data_handle); - } - plugin_done(jpctx, &plugin_data); - - fclose(infile); - if (verbose) fprintf(stdout,"lb_statistics: closed input file %s\n", infilename); - - if (outfile) { - fclose(outfile); - if (verbose) fprintf(stdout,"lb_statistics: closed output file %s\n", outfilename); - } - - dlclose(lib_handle); - if (verbose) fprintf(stdout,"lb_statistics: L&B plugin closed\n"); - - return 0; -} - diff --git a/org.glite.lb/.cvsignore b/org.glite.lb/.cvsignore deleted file mode 100644 index 1df717b..0000000 --- a/org.glite.lb/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -.project -.cdtproject \ No newline at end of file diff --git a/org.glite.lb/LICENSE b/org.glite.lb/LICENSE deleted file mode 100644 index 259a91f..0000000 --- a/org.glite.lb/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.lb/build.xml b/org.glite.lb/build.xml deleted file mode 100755 index c8ef9df..0000000 --- a/org.glite.lb/build.xml +++ /dev/null @@ -1,599 +0,0 @@ - - - - - - - Ant build file to build the GLite Logging and Bookkeping Subsystem - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Preparing directories ... - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <project name="${subsystem.name}" type="post-subsystem" packageName="${global.prefix}-${subsystem.prefix}"/> - - - - diff --git a/org.glite.lb/configure b/org.glite.lb/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lb/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lb/deployment/README b/org.glite.lb/deployment/README deleted file mode 100644 index 9b104e6..0000000 --- a/org.glite.lb/deployment/README +++ /dev/null @@ -1,2 +0,0 @@ -deploy_all.diff - against RC31 -deploy_lb, deploy_jp - older patches diff --git a/org.glite.lb/deployment/deploy_all.diff b/org.glite.lb/deployment/deploy_all.diff deleted file mode 100644 index fbfb5c9..0000000 --- a/org.glite.lb/deployment/deploy_all.diff +++ /dev/null @@ -1,551 +0,0 @@ -Index: org.glite/project/global.dependencies.properties -=================================================================== -RCS file: /cvs/jra1mw/org.glite/project/global.dependencies.properties,v -retrieving revision 1.482.2.279.2.61 -diff -u -r1.482.2.279.2.61 global.dependencies.properties ---- org.glite/project/global.dependencies.properties 23 Apr 2007 09:54:21 -0000 1.482.2.279.2.61 -+++ org.glite/project/global.dependencies.properties 24 Apr 2007 08:20:35 -0000 -@@ -2100,6 +2100,24 @@ - 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 -+ - # google-perftools - ext.google-perftools.name = google-perftools - ext.google-perftools.vendor = google-perftools -@@ -3855,31 +3873,31 @@ - # System dependencies - ################################################################### - --org.glite.deployment.version = glite-deployment_branch_2_5_0 -+org.glite.deployment.version = HEAD - org.glite.testsuites.version = HEAD --org.glite.version = glite_branch_3_1_0 -+org.glite.version = HEAD - --#subsystem version tag = do not remove -+#subsystem version tag = HEAD - org.glite.slcs.version = HEAD --org.glite.amga.version = glite-amga_R_1_0_0_2 -+org.glite.amga.version = HEAD - org.glite.bdii.version = HEAD --org.glite.ce.version = glite-ce_R_1_7_13_0 --org.glite.data.version = glite-data_R_3_1_17_1 --org.glite.dgas.version = glite-dgas_R_3_1_9_1 --org.glite.gpbox.version = glite-gpbox_R_1_3_0 -+org.glite.ce.version = HEAD -+org.glite.data.version = HEAD -+org.glite.dgas.version = HEAD -+org.glite.gpbox.version = HEAD - org.glite.info.version = HEAD --org.glite.jdl.version = glite-jdl_R_3_1_11_1 --org.glite.jp.version = glite-jp_R_1_3_5_1 --org.glite.lb.version = glite-lb_R_1_4_1_1 -+org.glite.jdl.version = HEAD -+org.glite.jp.version = HEAD -+org.glite.lb.version = HEAD - org.glite.overlay.version = HEAD --org.glite.rgma.version = glite-rgma_R_5_0_66_1 --org.glite.security.version = glite-security_R_3_1_35_1 --org.glite.service-discovery.version = glite-service-discovery_R_2_0_14 --org.glite.templates-latex-style.version = glite-templates-latex-style_R_1_0_1 --org.glite.wms-ui.version = glite-wms-ui_R_3_1_17_1 --org.glite.wms-utils.version = glite-wms-utils_R_3_1_8 --org.glite.wms.version = glite-wms_R_3_1_56_1 -+org.glite.rgma.version = HEAD -+org.glite.security.version = HEAD -+org.glite.service-discovery.version = HEAD -+org.glite.templates-latex-style.version = HEAD -+org.glite.wms-ui.version = HEAD -+org.glite.wms-utils.version = HEAD -+org.glite.wms.version = HEAD - --org.gridsite.core.version = gridsite-core_R_1_1_18_1 -+org.gridsite.core.version = HEAD - org.gridsite.ws.version = HEAD - -Index: org.glite.deployment/build.xml -=================================================================== -RCS file: /cvs/jra1mw/org.glite.deployment/build.xml,v -retrieving revision 1.62 -diff -u -r1.62 build.xml ---- org.glite.deployment/build.xml 22 Aug 2005 17:00:02 -0000 1.62 -+++ org.glite.deployment/build.xml 24 Apr 2007 08:20:35 -0000 -@@ -814,6 +814,39 @@ - - - -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - - -@@ -891,6 +924,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.529 -diff -u -r1.529 dependencies.properties ---- org.glite.deployment/project/dependencies.properties 21 Jun 2006 09:29:08 -0000 1.529 -+++ org.glite.deployment/project/dependencies.properties 24 Apr 2007 08:20:35 -0000 -@@ -33,6 +33,8 @@ - org.glite.deployment.wn.version = HEAD - org.glite.deployment.wms.version = HEAD - org.glite.deployment.lb.version = HEAD -+org.glite.deployment.jpps.version = HEAD -+org.glite.deployment.jpis.version = HEAD - org.glite.deployment.io-server.version = HEAD - org.glite.deployment.io-client.version = HEAD - org.glite.deployment.ce.version = HEAD -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.46 -diff -u -r1.46 glite.deployment.csf.xml ---- org.glite.deployment/project/glite.deployment.csf.xml 31 Jul 2006 09:53:53 -0000 1.46 -+++ org.glite.deployment/project/glite.deployment.csf.xml 24 Apr 2007 08:20:35 -0000 -@@ -392,6 +392,14 @@ - - - -+ -+ -+ -+ -+ -+ -+ -+ - - - -@@ -835,6 +843,28 @@ - tag="${org.glite.deployment.lb.version}" /> - - -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - - -@@ -892,6 +922,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.66 -diff -u -r1.66 glite-lb-config.py ---- org.glite.deployment.lb/config/scripts/glite-lb-config.py 13 Mar 2006 15:22:31 -0000 1.66 -+++ org.glite.deployment.lb/config/scripts/glite-lb-config.py 24 Apr 2007 08:20:35 -0000 -@@ -121,6 +121,10 @@ - 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...' -@@ -133,7 +137,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") -@@ -142,6 +146,36 @@ - return 1 - - #------------------------------------------------------------------- -+ # start jp-importer, if enabled -+ #------------------------------------------------------------------- -+ -+ lb_import = 0 -+ if params.has_key('lb.import.enabled'): -+ if params['lb.import.enabled'] == "true": -+ lb_import = 1 -+ -+ if lb_import: -+ 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 - #------------------------------------------------------------------- - -@@ -161,6 +195,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 ', -@@ -171,6 +209,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.import.enabled'): -+ if params['lb.import.enabled'] == "true": -+ print 'The JP Importer service has been stopped ', -+ glib.printOkMessage() -+ -+ #------------------------------------------------------------------- - # MySQL - #------------------------------------------------------------------- - -@@ -195,6 +252,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 - #------------------------------------------------------------------- -@@ -325,7 +386,29 @@ - print "\n==> MySQL database %s already exist\n" % params['lb.database.name'] - - self.mysql.stop() -- -+ -+ # ------------------------------------------------------------------ -+ # export from bkserver to cron -+ # ------------------------------------------------------------------ -+ if (params['GLITE_LB_PURGE_ENABLED'] == "true") or (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 - #------------------------------------------------------------------- -@@ -411,6 +494,21 @@ - # Perl - glib.addEnvPath("PERL5LIB", "%s/lib/perl:%s/lib/perl5" % (os.environ['GPT_LOCATION'],os.environ['GLITE_LOCATION'])) - -+ # LB export -+ glib.export('GLITE_LB_PURGE_ENABLED', params['lb.purge.enabled']); -+ glib.export('GLITE_LB_EXPORT_ENABLED', params['lb.export.enabled']); -+ glib.export('GLITE_LB_IMPORT_ENABLED', params['lb.import.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 -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 24 Apr 2007 08:20:35 -0000 -@@ -17,9 +17,16 @@ - parameter. Leave it empty of comment it out to use the same as 'glite.user.name'" - value="changeme"/> - -- -+ -+ -+ -+ -+ - - - -@@ -55,6 +62,28 @@ - [Example: 17M][Type: Integer][Unit: MB]" - value="17M"/> - -+ -+ -+ -+ -+ -+ -+ -+ -+ - - - -@@ -67,7 +96,44 @@ - destination - - -- -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - - -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 -diff -u -r1.38 glite-lb.sdf.xml.template ---- org.glite.deployment.lb/project/glite-lb.sdf.xml.template 13 Mar 2006 15:19:21 -0000 1.38 -+++ org.glite.deployment.lb/project/glite-lb.sdf.xml.template 24 Apr 2007 08:20:35 -0000 -@@ -15,7 +15,7 @@ - build="@org.glite.deployment.config.info.build@" - arch="noarch"/> - -- - -+ -+ - - -+ -+ - - -- -+ - - - -+%attr(644,root,root) %{prefix}/share/doc/glite-lb/release_notes/release_notes.doc\n -+%attr(644,root,root) %{prefix}/share/doc/glite-lb/release_notes/release_notes.pdf\n -+%attr(644,root,root) %{prefix}/share/doc/glite-lb/release_notes/release_notes.html\n"/> - - - diff --git a/org.glite.lb/deployment/deploy_jp.diff b/org.glite.lb/deployment/deploy_jp.diff deleted file mode 100644 index 76a9fa7..0000000 --- a/org.glite.lb/deployment/deploy_jp.diff +++ /dev/null @@ -1,222 +0,0 @@ -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 - # - # 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 - 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 @@ - - - -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - - -@@ -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 - - 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 @@ - - - -+ -+ -+ -+ -+ -+ -+ -+ - - - -@@ -1571,6 +1579,28 @@ - tag="${org.glite.deployment.lb.version}" /> - - -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - - -@@ -1667,6 +1697,8 @@ - wn, - wms, - lb, -+ jpis, -+ jpps, - io-server, - io-client, - ce" /> diff --git a/org.glite.lb/deployment/deploy_lb.diff b/org.glite.lb/deployment/deploy_lb.diff deleted file mode 100644 index d6c74e2..0000000 --- a/org.glite.lb/deployment/deploy_lb.diff +++ /dev/null @@ -1,281 +0,0 @@ -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"/> - -- -+ -+ -+ -+ -+ - - - -@@ -55,6 +62,12 @@ - [Example: 17M][Type: Integer][Unit: MB]" - value="17M"/> - -+ -+ -+ - - - -@@ -67,7 +80,42 @@ - destination - - -- -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ -+ - - - -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"/> - -+ -+ - - -+ -+ - &1 | tee log - -:) diff --git a/org.glite.lb/doc/perf_clear_proxy b/org.glite.lb/doc/perf_clear_proxy deleted file mode 100644 index 237df95..0000000 --- a/org.glite.lb/doc/perf_clear_proxy +++ /dev/null @@ -1 +0,0 @@ -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 diff --git a/org.glite.lb/doc/perf_purge b/org.glite.lb/doc/perf_purge deleted file mode 100644 index 4bcc881..0000000 --- a/org.glite.lb/doc/perf_purge +++ /dev/null @@ -1 +0,0 @@ -./stage/sbin/glite-lb-purge -j /tmp/perftest_1000.jobids -m scientific.civ.zcu.cz:10000 -s diff --git a/org.glite.lb/doc/perf_reg_jobs b/org.glite.lb/doc/perf_reg_jobs deleted file mode 100644 index 20923a1..0000000 --- a/org.glite.lb/doc/perf_reg_jobs +++ /dev/null @@ -1 +0,0 @@ - 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 diff --git a/org.glite.lb/doc/perf_results/il_sci_09062006.txt b/org.glite.lb/doc/perf_results/il_sci_09062006.txt deleted file mode 100644 index 503966e..0000000 --- a/org.glite.lb/doc/perf_results/il_sci_09062006.txt +++ /dev/null @@ -1,63 +0,0 @@ -./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] - diff --git a/org.glite.lb/doc/perf_results/il_sci_09062006_01.txt b/org.glite.lb/doc/perf_results/il_sci_09062006_01.txt deleted file mode 100644 index 04db72b..0000000 --- a/org.glite.lb/doc/perf_results/il_sci_09062006_01.txt +++ /dev/null @@ -1,129 +0,0 @@ -[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] diff --git a/org.glite.lb/doc/perf_results/il_sci_12062006.txt b/org.glite.lb/doc/perf_results/il_sci_12062006.txt deleted file mode 100644 index f3a1a79..0000000 --- a/org.glite.lb/doc/perf_results/il_sci_12062006.txt +++ /dev/null @@ -1,65 +0,0 @@ -[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] - - diff --git a/org.glite.lb/doc/perf_results/ll_michal_21062006.txt b/org.glite.lb/doc/perf_results/ll_michal_21062006.txt deleted file mode 100644 index c13457f..0000000 --- a/org.glite.lb/doc/perf_results/ll_michal_21062006.txt +++ /dev/null @@ -1,20 +0,0 @@ -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] diff --git a/org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_22062006.txt b/org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_22062006.txt deleted file mode 100644 index d0a99c5..0000000 --- a/org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_22062006.txt +++ /dev/null @@ -1,20 +0,0 @@ -------------------- -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] - - diff --git a/org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_23062006.txt b/org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_23062006.txt deleted file mode 100644 index 8097510..0000000 --- a/org.glite.lb/doc/perf_results/proxy2serv_umbar2sci_23062006.txt +++ /dev/null @@ -1,25 +0,0 @@ -------------------- -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] diff --git a/org.glite.lb/doc/perf_results/proxy_sci_09062006.txt b/org.glite.lb/doc/perf_results/proxy_sci_09062006.txt deleted file mode 100644 index efa1a41..0000000 --- a/org.glite.lb/doc/perf_results/proxy_sci_09062006.txt +++ /dev/null @@ -1,21 +0,0 @@ ----------------------------------- -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] diff --git a/org.glite.lb/doc/perf_run_interlogd b/org.glite.lb/doc/perf_run_interlogd deleted file mode 100644 index 00d60ed..0000000 --- a/org.glite.lb/doc/perf_run_interlogd +++ /dev/null @@ -1 +0,0 @@ - ./stage/bin/glite-lb-interlogd -d -s /tmp/perftest_michal.sock --file-prefix=/tmp/perftest_michal.log --lazy diff --git a/org.glite.lb/doc/perf_run_proxy b/org.glite.lb/doc/perf_run_proxy deleted file mode 100644 index 5d88382..0000000 --- a/org.glite.lb/doc/perf_run_proxy +++ /dev/null @@ -1 +0,0 @@ -./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 diff --git a/org.glite.lb/doc/perf_run_server b/org.glite.lb/doc/perf_run_server deleted file mode 100644 index b11eb79..0000000 --- a/org.glite.lb/doc/perf_run_server +++ /dev/null @@ -1 +0,0 @@ -./stage/bin/glite-lb-bkserverd -d --perf-sink=4 -p 10000 -w 10003 -S /tmp/purge_michal -D /tmp/dump_michal --silent diff --git a/org.glite.lb/doc/perf_run_test b/org.glite.lb/doc/perf_run_test deleted file mode 100644 index 2e31b83..0000000 --- a/org.glite.lb/doc/perf_run_test +++ /dev/null @@ -1 +0,0 @@ -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 diff --git a/org.glite.lb/etics-tag-consistency.pl b/org.glite.lb/etics-tag-consistency.pl deleted file mode 100755 index 3ffbeac..0000000 --- a/org.glite.lb/etics-tag-consistency.pl +++ /dev/null @@ -1,120 +0,0 @@ -#!/usr/bin/perl - -use Getopt::Std; -use Switch; - -$TMPDIR=$ENV{'TMPDIR'}; -$GLITE_LB_LOCATION="./org.glite.lb"; - -if ($TMPDIR eq "") {$TMPDIR="/tmp";} - -getopts('ch'); - -$usage = qq{ -usage: $0 [-h] subsystem.name [subsystem.name] [...] - - This script checks the consistency of tags in CVS and version.properties - - -c also verify etics configurations - -h Display this help - -}; - - # ********************************** - # Interpret cmdline options - # ********************************** - - if (defined $opt_h) {die $usage}; - die $usage unless @ARGV[0]; - - if (defined $opt_c) { - printf ("\n\nYou have selected the -c option. Note that etics may require authetication.\n If you cannot see any progress in the script, it is probably waiting for your password. ;-)\n\n"); - } - - # ********************************** - # Iterate through subsystems - # ********************************** - - foreach $subsystem (@ARGV) { - - #Clean possible trailing '/' (even multiple occurrences :-) from subsystem name - $subsystem=~s/\/+$//; - - printf("$subsystem\n"); - - $subsystem=~/\.([^\.]+?)$/; - - @modules=split(/\s+/, `PATH=\$PATH:./:./org.glite.lb configure --listmodules $1`); - - unshift (@modules, $subsystem); - - foreach $module (@modules) { - - printf(" %-30s", $module); - - - if (open VP, "$module/project/version.properties") { - - while ($_ = ) { - chomp; - - if(/module\.version\s*=\s*(\d*)\.(\d*)\.(\d*)/) { - $current_major=$1; - $current_minor=$2; - $current_revision=$3; - } - if(/module\.age\s*=\s*(\S+)/) { - $current_age=$1; - } - } - close (VP); - - $current_prefix=$module; - $current_prefix=~s/^org\.//; - $current_prefix=~s/\./-/g; - $current_prefix="$current_prefix" . "_R_"; - $current_tag="$current_prefix" . "$current_major" . "_$current_minor" . "_$current_revision" . "_$current_age"; - - if ($module eq $subsystem) { $subsystem_tag = $current_tag; } - - printf("\t $current_major.$current_minor.$current_revision-$current_age"); - - unless (system("cvs log -h $module/project/version.properties | grep -E \"\\W$current_tag\\W\" > /dev/null")) - { printf ("\t mod. OK"); } - else { - printf(STDERR "\nERROR: Tag $current_tag does not exist in module $module!\n"); - } - - if ($module ne $subsystem ) { - unless (system("cvs log -h $module/project/version.properties | grep -E \"\\W$subsystem_tag\\W\" > /dev/null")) - { printf ("\t subsys. OK"); } - else { - printf(STDERR "\nERROR: Tag $subsystem_tag does not exist in module $module!\n"); - } - - unless (-e "$module/project/ChangeLog") { - printf(STDERR "\nERROR: The ChangeLog file for module $module does not exist!\n"); - } - } - - unless (-e "$module/configure") { - printf(STDERR "\nERROR: The configure script for module $module does not exist!\n"); - } - - if (defined $opt_c) { - unless (system("etics-list-configuration $module | grep \"$current_tag\" &> /dev/null")) - { printf ("\t etics OK"); } - else { - printf(STDERR "\nERROR: Configuration $current_tag for module $module does not exist!\n"); - } - } - - printf("\n"); - - } - else { - printf(STDERR "\nERROR: The version.properties file for module $module does not exist!\n"); - } - } - } - diff --git a/org.glite.lb/etics-tag-with-subsystems.pl b/org.glite.lb/etics-tag-with-subsystems.pl deleted file mode 100755 index bd5e113..0000000 --- a/org.glite.lb/etics-tag-with-subsystems.pl +++ /dev/null @@ -1,296 +0,0 @@ -#!/usr/bin/perl - -use Getopt::Std; -use Switch; - -$TMPDIR=$ENV{'TMPDIR'}; - -if ($TMPDIR eq "") {$TMPDIR="/tmp";} - -getopts('c:h'); - -$module = shift; - -chomp($module); - -$usage = qq{ -usage: $0 [-c ] module.name - - -c Use this configuration (\d+\.\d+\.\d+-\S+) rather than parsing version.properties - -h Display this help - -}; - if (defined $opt_h) {die $usage}; - die $usage unless $module; - - #Clean possible trailing '/' (even multiple occurrences :-) from module name - $module=~s/\/+$//; - - if (defined $opt_c) { - - # ********************************** - # Parse the tag supplied by the user - # ********************************** - - if ($opt_c=~/(\d+)\.(\d+)\.(\d+)-(\S+?)/) { - $current_major=$1; - $current_minor=$2; - $current_revision=$3; - $current_age=$4; - } - else {die ("tag not specified properly")}; - - } - else { - # ********************************** - # Determine the most recent tag and its components - # ********************************** - - open VP, "$module/project/version.properties" or die "$module/project/version.properties: $?\n"; - - while ($_ = ) { - chomp; - - if(/module\.version\s*=\s*(\d*)\.(\d*)\.(\d*)/) { - $current_major=$1; - $current_minor=$2; - $current_revision=$3; - } - if(/module\.age\s*=\s*(\S+)/) { - $current_age=$1; - } - } - close (VP); - - $current_prefix=$module; - $current_prefix=~s/^org\.//; - $current_prefix=~s/\./-/g; - $current_prefix="$current_prefix" . "_R_"; - $current_tag="$current_prefix" . "$current_major" . "_$current_minor" . "_$current_revision" . "_$current_age"; - } - - # According to the documentation, symbolic names in the 'cvs log' output are sorted by age so this should be OK - #$current_tag=`cvs log -h $module/Makefile | grep \"_R_\" | head -n 1`; - #$current_tag=~s/^\s//; - #$current_tag=~s/:.*?$//; - #chomp($current_tag); - - #$current_tag=~/(.*_R_)(\d*?)_(\d*?)_(\d*?)_(.*)/; - #$current_prefix=$1; - #$current_major=$2; - #$current_minor=$3; - #$current_revision=$4; - #$current_age=$5; - - $module=~/\.([^\.]+?)$/; - - @modules=split(/\s+/, `PATH=\$PATH:./:./org.glite.lb configure --listmodules $1`); - - my $incmajor=0; - my $incminor=0; - my $increvision=0; - my $incage=0; - - - # ********************************** - # Iterate through modules and find out what has changed - # ********************************** - - foreach $m (@modules) { - printf("\n***$m\n"); - - $old_major=-1; $old_minor=-1; $old_revision=-1; $old_age=-1; - $new_major=-1; $new_minor=-1; $new_revision=-1; $new_age=-1; - - foreach $l (`cvs diff -r $current_prefix$current_major\_$current_minor\_$current_revision\_$current_age $m/project/version.properties | grep -E "module\.age|module\.version"`) { - chomp($l); - printf("$l\n"); - - if($l=~/<\s*module\.version\s*=\s*(\d*)\.(\d*)\.(\d*)/) { - $old_major=$1; - $old_minor=$2; - $old_revision=$3; - } - elsif($l=~/<\s*module\.age\s*=\s*(\S+)/) { - $old_age=$1; - } - elsif($l=~/>\s*module\.version\s*=\s*(\d*)\.(\d*)\.(\d*)/) { - $new_major=$1; - $new_minor=$2; - $new_revision=$3; - } - elsif($l=~/>\s*module\.age\s*=\s*(\S+)/) { - $new_age=$1; - } - } - - - - if ($old_major != $new_major) { - $incmajor++; - printf("Major change ($old_major -> $new_major)"); - } - elsif ($old_minor != $new_minor) { - $incminor++; - printf("Minor change ($old_minor -> $new_minor)"); - } - elsif ($old_revision != $new_revision) { - $increvision++; - printf("Revision change ($old_revision -> $new_revision)"); - } - elsif ($old_age != $new_age) { - $incage++; - printf("Age change ($old_age -> $new_age)"); - } - printf("\n"); - - } - - printf("Current tag: $current_tag\n\tprefix: $current_prefix\n\t major: $current_major\n\t minor: $current_minor\n\t rev: $current_revision\n\t age: $current_age\n"); - - # ********************************** - # Generate the new tag name - # ********************************** - - if($incmajor > 0) { - $major=$current_major+1; - $minor=0; - $revision=0; - $age=1;} - elsif($incminor > 0) { - $major=$current_major; - $minor=$current_minor+1; - $revision=0; - $age=1;} - elsif($increvision > 0) { - $major=$current_major; - $minor=$current_minor; - $revision=$current_revision+1; - $age=1;} - elsif($incage > 0) { - $major=$current_major; - $minor=$current_minor; - $revision=$current_revision; - $age=$current_age+1;} - else { - printf("No change in either version component.\nAbort by pressing Ctrl+C or enter new age manually.\nUse a number or a word: "); - $major=$current_major; - $minor=$current_minor; - $revision=$current_revision; - $age=;} - - chomp($age); - - $tag="$current_prefix" . "$major" . "_$minor" . "_$revision" . "_$age"; - - printf("\nNew tag: $tag\n\n"); - - die "This tag already exists; reported by assertion" unless system("cvs log -h $module/Makefile | grep \"$tag\""); - - # ********************************** - # Create the execution script - # ********************************** - - open EXEC, ">", "$TMPDIR/tag-with-subsystems-$module.$major.$minor.$revision-$age.sh" or die $!; - - printf (EXEC "#This script registers tags for the $module module, version $major.$minor.$revision-$age\n#Generated automatically by $0\n\n"); - - - # ********************************** - # Update version.properties - # ********************************** - open V, "$module/project/version.properties" or die "$module/project/version.properties: $?\n"; - - printf(EXEC "#Generate new version.properties\ncat >$module/project/version.properties <) { - chomp; - - $_=~s/module\.version\s*=\s*[.0-9]+/module\.version=$major.$minor.$revision/; - $_=~s/module\.age\s*=\s*(\S+)/module\.age=$age/; - - printf(EXEC "$_\n"); - } - close V; - printf(EXEC "EOF\n\n"); - printf(EXEC "cvs commit -m \"Modified to reflect version $major.$minor.$revision-$age\" $module/project/version.properties\n\n"); - - - $cwd=`pwd`; - chomp($cwd); - - printf(EXEC "#Register the new tag\ncd $module\ncvs tag \"$tag\"\n"); - foreach $m (@modules) { - printf (EXEC "cd \"$cwd/$m\"\ncvs tag \"$tag\"\n"); - } - printf(EXEC "cd \"$cwd\"\n"); - - - - # ********************************** - # Etics configuration prepare / modify / upload - # ********************************** - -# $currentconfig="$module_$module" . "_R_$current_major" . "_$current_minor" . "_$current_revision" . "_$current_age"; -# $currentconfig=~s/^org.//; -# $currentconfig=~s/\./-/g; - $newconfig="$module_$module" . "_R_$major" . "_$minor" . "_$revision" . "_$age"; - $newconfig=~s/^org.//; - $newconfig=~s/\./-/g; - - - printf("\nNew configuration:\t$newconfig\n\nPreparing...\n"); - - open NEWCONF, ">", "$TMPDIR/$newconfig.ini.$$" or die $!; - - printf (NEWCONF "[Configuration-$newconfig]\nprofile = None\nmoduleName = $module\ndisplayName = $newconfig\ndescription = None\nprojectName = org.glite\nage = $age\ntag = $tag\nversion = $major.$minor.$revision\npath = None\n\n"); - -# printf (NEWCONF "[Platform-default:VcsCommand]\ndisplayName = None\ndescription = HEAD CVS commands\ntag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName}\nbranch = None\ncommit = None\ncheckout = cvs -d \${vcsroot} co -r \${tag} \${moduleName}\n\n"); - -# printf (NEWCONF "[Platform-default:Environment]\nHOME = \${workspaceDir}"); - - printf (NEWCONF "\n\n[Hierarchy]\n"); - - foreach $m (@modules) { - open MOD, "$m/project/version.properties" or die "$m/project/version.properties: $?\n"; - - $m_major=0; $m_minor=0; $m_revision=0; $m_age=0; - - while ($_ = ) { - chomp; - - if(/module\.version\s*=\s*(\d*)\.(\d*)\.(\d*)/) { - $m_major=$1; - $m_minor=$2; - $m_revision=$3; - } - if(/module\.age\s*=\s*(\S+)/) { - $m_age=$1; - } - } - - $modconfig="$m_$m" . "_R_$m_major" . "_$m_minor" . "_$m_revision" . "_$m_age"; - $modconfig=~s/^org.//; - $modconfig=~s/\./-/g; - -# system("echo $m = $modconfig >> $TMPDIR/$newconfig.ini.$$"); - printf(NEWCONF "$m = $modconfig\n"); - - close (MOD); - } - - close(NEWCONF); - - printf(EXEC "\n#Add new configuration\netics-configuration add -i $TMPDIR/$newconfig.ini.$$ -c $newconfig $module\n"); - printf(EXEC "etics-commit\n"); - - - # ********************************** - # Final bows - # ********************************** - - close(EXEC); - - system("chmod +x \"$TMPDIR/tag-with-subsystems-$module.$major.$minor.$revision-$age.sh\""); - - printf("\n\n---------\nFinished!\n\nExecution script written in:\t$TMPDIR/tag-with-subsystems-$module.$major.$minor.$revision-$age.sh\nNew configuration written in:\t$TMPDIR/$newconfig.ini.$$\n\n"); - diff --git a/org.glite.lb/etics-tag.pl b/org.glite.lb/etics-tag.pl deleted file mode 100755 index e5f2fe9..0000000 --- a/org.glite.lb/etics-tag.pl +++ /dev/null @@ -1,304 +0,0 @@ -#!/usr/bin/perl - -use Getopt::Std; -use Switch; - -$TMPDIR=$ENV{'TMPDIR'}; -$GLITE_LB_LOCATION="./org.glite.lb"; - -if ($TMPDIR eq "") {$TMPDIR="/tmp";} - -getopts('i:c:m:gh'); - -$module = shift; - -$usage = qq{ -usage: $0 [-i maj|min|rev|age|none|] [-g] [-c ] module.name - - -i What to increment ('maj'or version, 'min'or version, 'rev'ision, 'age') - Should you fail to specify the -i option the script will open up a cvs diff - output and ask you to specify what to increment interactively. - 'none' means no change -- this basically just generates a configuration. - -g Generate old configuration for comparison - -c Use this configuration (\d+\.\d+\.\d+-\S+) rather than parsing version.properties - -m Use this as a CVS commit message instead of the script's default. - -h Display this help - -}; - - # ********************************** - # Interpret cmdline options - # ********************************** - - if (defined $opt_h) {die $usage}; - die $usage unless $module; - - #Clean possible trailing '/' (even multiple occurrences :-) from module name - $module=~s/\/+$//; - - switch ($opt_i) { - case "maj" {$increment="j"} - case "min" {$increment="i"} - case "rev" {$increment="r"} - case "age" {$increment="a"} - case "none" {$increment="n"} - else {$increment=$opt_i}; - } - - - if (defined $opt_c) { - - # ********************************** - # Parse the tag supplied by the user - # ********************************** - - if ($opt_c=~/(\d+)\.(\d+)\.(\d+)-(\S+?)/) { - $current_major=$1; - $current_minor=$2; - $current_revision=$3; - $current_age=$4; - } - else {die ("tag not stated properly")}; - - } - else { - - # ********************************** - # Determine the most recent tag and its components from version.properties - # ********************************** - - open VP, "$module/project/version.properties" or die "$module/project/version.properties: $?\n"; - - while ($_ = ) { - chomp; - - if(/module\.version\s*=\s*(\d*)\.(\d*)\.(\d*)/) { - $current_major=$1; - $current_minor=$2; - $current_revision=$3; - } - if(/module\.age\s*=\s*(\S+)/) { - $current_age=$1; - } - } - close (VP); - - $current_prefix=$module; - $current_prefix=~s/^org\.//; - $current_prefix=~s/\./-/g; - $current_prefix="$current_prefix" . "_R_"; - $current_tag="$current_prefix" . "$current_major" . "_$current_minor" . "_$current_revision" . "_$current_age"; - } - - # According to the documentation, symbolic names in the 'cvs log' output are sorted by age so this should be OK - #$current_tag=`cvs log -h $module/Makefile | grep \"_R_\" | head -n 1`; - #$current_tag=~s/^\s//; - #$current_tag=~s/:.*?$//; - #chomp($current_tag); - - #$current_tag=~/(.*_R_)(\d*?)_(\d*?)_(\d*?)_(.*)/; - #$current_prefix=$1; - #$current_major=$2; - #$current_minor=$3; - #$current_revision=$4; - #$current_age=$5; - - printf("Current tag: $current_tag\n\tprefix: $current_prefix\n\t major: $current_major\n\t minor: $current_minor\n\t rev: $current_revision\n\t age: $current_age\n"); - - # ********************************** - # Compare the last tag with the current source - # ********************************** - - unless (defined $increment) { - printf("Diffing...\n"); - - system("cvs diff -r $current_tag $module | less"); - } - - # ********************************** - # Generate the new tag name - # ********************************** - - printf("\nWhich component do you wish to increment?\n\n\t'j'\tmaJor\n\t'i'\tmInor\n\t'r'\tRevision\n\t'a'\tAge\n\t\'n'\tNo change\n\tfree type\tUse what I have typed (single word) as a new age name (original: $current_age)\n\nType in your choice: "); - - unless (defined $increment) { - $increment=; - } - - chomp($increment); - - switch ($increment) { - case "j" { - $major=$current_major+1; - $minor=0; - $revision=0; - $age=1;} - case "i" { - $major=$current_major; - $minor=$current_minor+1; - $revision=0; - $age=1;} - case "r" { - $major=$current_major; - $minor=$current_minor; - $revision=$current_revision+1; - $age=1;} - case "a" { - $major=$current_major; - $minor=$current_minor; - $revision=$current_revision; - $age=$current_age+1;} - case "n" { - $major=$current_major; - $minor=$current_minor; - $revision=$current_revision; - $age=$current_age;} - else { - $major=$current_major; - $minor=$current_minor; - $revision=$current_revision; - $age=$increment;} - } - $tag="$current_prefix" . "$major" . "_$minor" . "_$revision" . "_$age"; - - printf("\nNew tag: $tag\n\n"); - - die "This tag already exists; reported by assertion" unless (($increment eq 'n') || system("cvs log -h $module/Makefile | grep \"$tag\"")); - - # ********************************** - # Create the execution script - # ********************************** - - open EXEC, ">", "$TMPDIR/etics-tag-$module.$major.$minor.$revision-$age.sh" or die $!; - - printf (EXEC "#This script registers tags for the $module module, version $major.$minor.$revision-$age\n#Generated automatically by $0\n\n"); - - - # ********************************** - # Update the ChangeLog - # ********************************** - - if (-r "$module/project/ChangeLog") { # ChangeLog exists (where expected). Proceed. - - $tmpChangeLog="$TMPDIR/$module.ChangeLog.$$"; - - system("cp $module/project/ChangeLog $tmpChangeLog"); - - unless ($increment eq "n") {system("echo $major.$minor.$revision-$age >> $tmpChangeLog");} - - $ChangeLogRet=system("vim $tmpChangeLog"); - - printf("Modified ChangeLog ready, ret code: $ChangeLogRet\n"); - - if (defined $opt_m) {$commit_message=$opt_m;} - else {$commit_message="Appended the description of changes regarding version $major.$minor.$revision-$age";} - - printf(EXEC "#Update and commit the ChangeLog\ncp $tmpChangeLog $module/project/ChangeLog\ncvs commit -m \"$commit_message\" $module/project/ChangeLog\n\n"); - - } - - unless ($increment eq "n") { - # ********************************** - # Update version.properties - # ********************************** - open V, "$module/project/version.properties" or die "$module/project/version.properties: $?\n"; - - printf(EXEC "#Generate new version.properties\ncat >$module/project/version.properties <) { - chomp; - - $_=~s/module\.version\s*=\s*[.0-9]+/module\.version=$major.$minor.$revision/; - $_=~s/module\.age\s*=\s*(\S+)/module\.age=$age/; - - $_=~s/\$/\\\$/g; - printf(EXEC "$_\n"); - } - close V; - printf(EXEC "EOF\n\n"); - - - if (defined $opt_m) {$commit_message=$opt_m;} - else {$commit_message="Modified to reflect version $major.$minor.$revision-$age";} - - - printf(EXEC "cvs commit -m \"$commit_message\" $module/project/version.properties\n\n"); - } - - - # ********************************** - # Update configure - # ********************************** - - printf(EXEC "#Update and commit the \"configure\" script\ncp $GLITE_LB_LOCATION/configure $module/\ncvs commit -m \"The most recent version copied. Do not modify this instance (RW in $GLITE_LB_LOCATION).\" $module/configure\n\n"); - - unless ($increment eq "n") { - # ********************************** - # Run CVS Tag - # ********************************** - - $cwd=`pwd`; - chomp($cwd); - - printf(EXEC "#Register the new tag\ncd $module\ncvs tag \"$tag\"\ncd \"$cwd\"\n"); - } - - # ********************************** - # Etics configuration prepare / modify / upload - # ********************************** - - $currentconfig="$module_$module" . "_R_$current_major" . "_$current_minor" . "_$current_revision" . "_$current_age"; - $currentconfig=~s/^org.//; - $currentconfig=~s/\./-/g; - $newconfig="$module_$module" . "_R_$major" . "_$minor" . "_$revision" . "_$age"; - $newconfig=~s/^org.//; - $newconfig=~s/\./-/g; - - $module=~/([^\.]+?)\.([^\.]+?)$/; - $subsysname=$1; - $modulename=$2; - - printf("Module=$module\nname=$modulename\nsubsys=$subsysname\n"); - system("$GLITE_LB_LOCATION/configure --mode=etics --module $subsysname.$modulename --output $TMPDIR/$newconfig.ini.$$ --version $major.$minor.$revision-$age"); - -# printf("\nCurrent configuration:\t$currentconfig\nNew configuration:\t$newconfig\n\nPreparing...\n"); -# - if (defined $opt_g) { - system("etics-configuration prepare -o $TMPDIR/$currentconfig.ini.$$ -c $currentconfig $module"); - } - -# open OLDCONF, "$TMPDIR/$currentconfig.ini.$$" or die $!; -# open NEWCONF, ">", "$TMPDIR/$newconfig.ini.$$" or die $!; - -# while ($_ = ) { -# chomp; - -## $_=~s/module\.age\s*=\s*(\S+)/module\.age=$age/; -# $_=~s/$currentconfig/$newconfig/; -# $_=~s/^\s*version\s*=\s*[.0-9]+/version = $major.$minor.$revision/; -# $_=~s/^\s*age\s*=\s*\S+/age = $age/; - -# printf(NEWCONF "$_\n"); -# } - -# close(OLDCONF); -# close(NEWCONF); - - if ($increment eq "n") { # There was no version change and the configuration should already exist - printf(EXEC "\n#Add new configuration\netics-configuration modify -i $TMPDIR/$newconfig.ini.$$ -c $newconfig $module\n"); } - else { # New configuration needs to be created - printf(EXEC "\n#Add new configuration\netics-configuration add -i $TMPDIR/$newconfig.ini.$$ -c $newconfig $module\n"); } - printf(EXEC "etics-commit\n"); - - - # ********************************** - # Final bows - # ********************************** - - close(EXEC); - - system("chmod +x \"$TMPDIR/etics-tag-$module.$major.$minor.$revision-$age.sh\""); - - printf("\n\n---------\nFinished!\n\nExecution script written in:\t$TMPDIR/etics-tag-$module.$major.$minor.$revision-$age.sh\nChangeLog candidate written in:\t$tmpChangeLog\n"); - printf("Old configuration stored in:\t$TMPDIR/$currentconfig.ini.$$\n") if (defined $opt_g); - printf("New configuration written in:\t$TMPDIR/$newconfig.ini.$$\n\n"); - diff --git a/org.glite.lb/lb4vdt/LB_install.sh b/org.glite.lb/lb4vdt/LB_install.sh deleted file mode 100755 index 93924c9..0000000 --- a/org.glite.lb/lb4vdt/LB_install.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/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 diff --git a/org.glite.lb/lb4vdt/Makefile.inc b/org.glite.lb/lb4vdt/Makefile.inc deleted file mode 100644 index c9c3072..0000000 --- a/org.glite.lb/lb4vdt/Makefile.inc +++ /dev/null @@ -1,77 +0,0 @@ -# -# 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} - diff --git a/org.glite.lb/lb4vdt/scripts/org.gridsite.core.build b/org.glite.lb/lb4vdt/scripts/org.gridsite.core.build deleted file mode 100644 index 38258c5..0000000 --- a/org.glite.lb/lb4vdt/scripts/org.gridsite.core.build +++ /dev/null @@ -1,11 +0,0 @@ -#!/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} - diff --git a/org.glite.lb/project/build.number b/org.glite.lb/project/build.number deleted file mode 100644 index cc27364..0000000 --- a/org.glite.lb/project/build.number +++ /dev/null @@ -1,2 +0,0 @@ -#Fri Aug 18 12:35:01 CEST 2006 -module.build=0242 diff --git a/org.glite.lb/project/build.properties b/org.glite.lb/project/build.properties deleted file mode 100644 index a57c085..0000000 --- a/org.glite.lb/project/build.properties +++ /dev/null @@ -1,2 +0,0 @@ -ext.gsoap.version=2.7.6b -ext.gsoap.rep.file=gSOAP-2.7.6b.tar.gz diff --git a/org.glite.lb/project/glite.lb.csf.xml b/org.glite.lb/project/glite.lb.csf.xml deleted file mode 100644 index 7d77350..0000000 --- a/org.glite.lb/project/glite.lb.csf.xml +++ /dev/null @@ -1,398 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The org.glite and org.glite.lb modules have been updated, please rerun the configuration file - - - - The org.glite and org.glite.lb modules have been updated, please rerun the configuration file - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lb/project/package.description b/org.glite.lb/project/package.description deleted file mode 100644 index 7fd54e7..0000000 --- a/org.glite.lb/project/package.description +++ /dev/null @@ -1 +0,0 @@ -gLite Logging and Bookkeeping (LB) is a Grid service that keeps a short-term trace of Grid jobs as they are processed by individual Grid components. diff --git a/org.glite.lb/project/package.summary b/org.glite.lb/project/package.summary deleted file mode 100644 index cb27971..0000000 --- a/org.glite.lb/project/package.summary +++ /dev/null @@ -1 +0,0 @@ -gLite Logging and Bookkeeping diff --git a/org.glite.lb/project/properties.xml b/org.glite.lb/project/properties.xml deleted file mode 100755 index 0d0291a..0000000 --- a/org.glite.lb/project/properties.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/org.glite.lb/project/run-workspace b/org.glite.lb/project/run-workspace deleted file mode 100644 index 03a3381..0000000 --- a/org.glite.lb/project/run-workspace +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/sh - -cd ../.. - -cvs co org.glite -cvs co org.glite.lb - -cd org.glite.lb/project -ant -f glite.lb.csf.xml - diff --git a/org.glite.lb/project/taskdefs.xml b/org.glite.lb/project/taskdefs.xml deleted file mode 100755 index 251f790..0000000 --- a/org.glite.lb/project/taskdefs.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/org.glite.lb/project/version.properties b/org.glite.lb/project/version.properties deleted file mode 100644 index 9f3167f..0000000 --- a/org.glite.lb/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# : /cvs/glite/org.glite.lb/project/version.properties,v 1.164 2008/01/09 15:35:55 mmulac Exp $ -module.version=2.0.5 -module.age=7 diff --git a/org.glite.lbjp-common.db/.cvsignore b/org.glite.lbjp-common.db/.cvsignore deleted file mode 100644 index b7d6c92..0000000 --- a/org.glite.lbjp-common.db/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -build -doc -reports diff --git a/org.glite.lbjp-common.db/LICENSE b/org.glite.lbjp-common.db/LICENSE deleted file mode 100644 index 01b973b..0000000 --- a/org.glite.lbjp-common.db/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.lbjp-common.db/Makefile b/org.glite.lbjp-common.db/Makefile deleted file mode 100644 index c2957fa..0000000 --- a/org.glite.lbjp-common.db/Makefile +++ /dev/null @@ -1,143 +0,0 @@ -# defaults -top_srcdir=.. -builddir=build -stagedir=. -distdir=. -globalprefix=glite -lbutilsprefix=lbu -package=glite-lb-utils-db -version=0.2.0 -PREFIX=/opt/glite -flavour=gcc32thr - -glite_location=/opt/glite -mysql-devel_prefix=/opt/mysql -mysql_version=4.1.11 -cppunit_prefix=/opt/cppunit -thrflavour=gcc32pthr -nothrflavour=gcc32 - --include Makefile.inc --include ../project/version.properties - -CC=gcc - -VPATH=${top_srcdir}/interface:${top_srcdir}/src:${top_srcdir}/examples - -DEBUG:=-g -O0 -W -Wall - -MYSQL_SONAME:=$(shell ../project/get_soname.sh ${mysql-devel_prefix}/${libdir} ${mysql_prefix}/${libdir} ${mysql-devel_prefix}/lib ${mysql_prefix}/lib) - -MYSQL_CPPFLAGS:=-I${mysql-devel_prefix}/include -I${mysql-devel_prefix}/include/mysql -DMYSQL_SONAME=\"${MYSQL_SONAME}\" -MYSQL_LIBS=-lz - -CFLAGS:= \ - ${DEBUG} \ - -DVERSION=\"${version}\" \ - -I${stagedir}/include -I${top_srcdir}/src -I. \ - -I${top_srcdir}/interface \ - ${COVERAGE_FLAGS} \ - ${MYSQL_CPPFLAGS} \ - -D_GNU_SOURCE - -ifdef LBS_DB_PROFILE - CFLAGS:=${CFLAGS} -DLBS_DB_PROFILE -endif - -TEST_LIBS:=-L${cppunit_prefix}/${libdir} -lcppunit -TEST_INC:=-I${cppunit_prefix}/include - -LDFLAGS:=-L${stagedir}/${libdir} ${COVERAGE_FLAGS} - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/${libdir} ${LDFLAGS} -INSTALL:=libtool --mode=install install - -EXT_LIBS:=${MYSQL_LIBS} -lglite_lbu_trio -lpthread -ldl -OBJS:=db.o -TESTOBJS:=dbtest.o -HDRS:=db.h -LOBJS:=${OBJS:.o=.lo} -LTESTOBJS:=${TESTOBJS:.o=.lo} - -default all: compile doc - -check_soname: - if [ "${MYSQL_SONAME}" = notfound ]; then \ - echo "MySQL shared library not found!"; \ - false; \ - fi - -db.lo: check_soname - -libglite_lbu_db.la: ${LOBJS} - ${LINK} -o $@ $< ${EXT_LIBS} - -libglite_lbu_dbtest.la: ${LTESTOBJS} - ${LINK} -o $@ $< ${EXT_LIBS} - -dbtest.lo dbtest.o: db.c db.h - ${COMPILE} -DGLITE_LBU_DEFAULT_RESULT_BUFFER_LENGTH=10 -c $< -o $@ - -db_test: db_test.lo libglite_lbu_dbtest.la - ${LINK} -o $@ $+ ${EXT_LIBS} - -db_expire: db_expire.lo libglite_lbu_dbtest.la - ${LINK} -o $@ $+ ${EXT_LIBS} - -compile: libglite_lbu_db.la - -check: - -echo No checks here 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 ${OBJS} | tr ' ' '\012' | sort -u`; do gcov $$i ; done - -examples: db_test db_expire - -doc: - -olddoc: - cp ${top_srcdir}/doc/*.dox . - echo "PROJECT_NUMBER = ${version}" >> C.dox - doxygen C.dox - -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: all - -mkdir -p ${PREFIX}/${libdir} - -mkdir -p ${PREFIX}/share/doc/${package}-${version} - -mkdir -p ${PREFIX}/include/${globalprefix}/${lbutilsprefix} - ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} - -cp -r C ${PREFIX}/share/doc/${package}-${version} - ${INSTALL} -m 755 "libglite_lbu_db.la" "${PREFIX}/${libdir}/libglite_lbu_db.la"; \ - ${INSTALL} -m 644 ${top_srcdir}/interface/${HDRS} ${PREFIX}/include/${globalprefix}/${lbutilsprefix} - -clean: - rm -rvf *.o *.lo .libs lib* *.c *.h *.dox C/ CPP/ - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - rm -rvf db_expire db_test - -%.o %.lo: %.c - ${COMPILE} -c $< - -db.lo: db.c db.h -db_test.lo: libglite_lbu_dbtest.la db.h db_test.c - -.PHONY: default all compile check examples doc stage dist distsrc distbin install clean test_coverage diff --git a/org.glite.lbjp-common.db/configure b/org.glite.lbjp-common.db/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lbjp-common.db/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lbjp-common.db/doc/C.dox b/org.glite.lbjp-common.db/doc/C.dox deleted file mode 100644 index e5396fa..0000000 --- a/org.glite.lbjp-common.db/doc/C.dox +++ /dev/null @@ -1,16 +0,0 @@ -PROJECT_NAME = "Glite LBJP Common: DB module" -OUTPUT_DIRECTORY = C -OPTIMIZE_OUTPUT_FOR_C = YES -INPUT = \ - ../interface/db.h -SHOW_DIRECTORIES = NO -FULL_PATH_NAMES = NO -EXTRACT_ALL = YES -PDF_HYPERLINKS = YES -USE_PDFLATEX = YES -MACRO_EXPANSION = YES -EXPAND_ONLY_PREDEF = YES -#PREDEFINED = _EDG_WLL_EVENT_COMMON -HAVE_DOT = NO -GENERATE_MAN = YES -MAN_LINKS = NO diff --git a/org.glite.lbjp-common.db/examples/db_expire.c b/org.glite.lbjp-common.db/examples/db_expire.c deleted file mode 100644 index 2eb3ba6..0000000 --- a/org.glite.lbjp-common.db/examples/db_expire.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Example (and quick test) of prepared statements expirations. - * Use 'SET GLOBAL wait_timeout=...' for experimenting. - * - * Requires existing database with appropriate access and example table: - * - * mysqladmin -u root -p create test - * mysql -u root -p -e 'GRANT ALL on test.* to testuser@localhost' - * ./db_test - * - * Then you can launch: - * - * ./db_expire - * - * Use CS environment variable for different user/pwd@machine:dbname. - */ - -#include -#include -#include - -#include "db.h" - -#define CS "testuser/@localhost:test" -#define SELECT_CMD "SELECT id, user, info FROM data WHERE user = ?" - -#define dprintf(ARGS) { printf("%s: ", name); printf ARGS; } - - -static void print_blob(unsigned long len, char *blob) { - unsigned int i; - - for (i = 0; i < len; i++) printf("%02X ", blob[i]); - printf("(='"); - for (i = 0; i < len; i++) printf("%c", blob[i]); - printf("')"); -} - - -static void print_free_result(const char *name, unsigned long *lens, char **res) { - dprintf((" id='%s'=%d\n", res[0], atoi(res[0]))); - - dprintf((" user='%s'\n", res[1])); - - dprintf((" blob=")); - if (res[2] && lens) print_blob(lens[2], res[2]); - else printf("null"); - printf("\n"); - - free(res[0]); - free(res[1]); - free(res[2]); -} - - -static void print_error(glite_lbu_DBContext ctx) { - if (ctx) { - char *t, *d; - - if (glite_lbu_DBError(ctx, &t, &d)) { - printf("Error %s: %s\n", t, d); - free(t); free(d); - } - } -} - - -int main(int argn __attribute((unused)), char *argv[]) { - char *name, *user; - const char *cs; - glite_lbu_DBContext ctx; - glite_lbu_Statement stmt; - int caps, nr, c; - unsigned long lens[3]; - char *res[3]; - - if ((name = strrchr(argv[0], '/')) != NULL) name++; - else name = argv[0]; - if ((cs = getenv("CS")) == NULL) cs = CS; - - // init - dprintf(("connecting to %s...\n", cs)); - if (glite_lbu_InitDBContext(&ctx) != 0) { - print_error(ctx); - goto failctx; - } - if (glite_lbu_DBConnect(ctx, cs) != 0) { - print_error(ctx); - goto failctx; - } - if ((caps = glite_lbu_DBQueryCaps(ctx)) == -1) { - print_error(ctx); - goto failcon; - } - if ((caps & GLITE_LBU_DB_CAP_PREPARED) == 0) { - print_error(ctx); - dprintf(("can't do prepared commands, exiting.")); - goto failcon; - } - // caps - glite_lbu_DBSetCaps(ctx, caps | GLITE_LBU_DB_CAP_ERRORS); - dprintf(("capabilities: %d\n", caps)); - - user = NULL; - dprintf(("preparing '%s'...\n", user)); - if ((glite_lbu_PrepareStmt(ctx, SELECT_CMD, &stmt)) != 0) { - print_error(ctx); - goto failcon; - } - - do { - user = "cicomexocitl.civ"; - dprintf(("executing '%s'...\n", user)); - if (glite_lbu_ExecPreparedStmt(stmt, 1, GLITE_LBU_DB_TYPE_VARCHAR, user) == -1) { - print_error(ctx); - goto failstmt; - } - dprintf(("fetching '%s'...\n", user)); - while ((nr = glite_lbu_FetchRow(stmt, 3, lens, res)) > 0) { - dprintf(("Result: n=%d, res=%p\n", nr, res)); - print_free_result(name, lens, res); - } - if (nr < 0) { - dprintf(("fetch '%s' failed\n", user)); - break; - } - dprintf(("\n")); - - c = fgetc(stdin); - } while (c != -1 && (c == '\r' || c == '\n')); - - dprintf(("closing...\n")); - glite_lbu_DBClose(ctx); - glite_lbu_FreeDBContext(ctx); - return 0; - -failstmt: - printf("closing stmt...\n"); - glite_lbu_FreeStmt(&stmt); -failcon: - dprintf(("closing...\n")); - glite_lbu_DBClose(ctx); -failctx: - glite_lbu_FreeDBContext(ctx); - dprintf(("failed\n")); - return 1; -} diff --git a/org.glite.lbjp-common.db/examples/db_test.c b/org.glite.lbjp-common.db/examples/db_test.c deleted file mode 100644 index f87aff7..0000000 --- a/org.glite.lbjp-common.db/examples/db_test.c +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Example (and quick test) of this DB module. - * - * Requires existing database with appropriate access: - * - * mysqladmin -u root -p create test - * mysql -u root -p -e 'GRANT ALL on test.* to testuser@localhost' - * - * Use CS environment variable when using different user/pwd@machine:dbname. - */ - -#include -#include -#include - -#include "glite/lbu/db.h" - -#define CS "testuser/@localhost:test" -#if defined(DB_BACKEND) && DB_BACKEND == postgresql -#define CREATE_CMD "CREATE TABLE \"data\" (\n\ - \"id\" INTEGER NOT NULL,\n\ - \"user\" VARCHAR(32) NOT NULL,\n\ - \"info\" BYTEA,\n\ - PRIMARY KEY (\"id\")\n\ -)" -#define AMP "\"" -#else -#define CREATE_CMD "CREATE TABLE data (\n\ - `id` INT NOT NULL,\n\ - `user` VARCHAR(32) NOT NULL,\n\ - `info` BLOB,\n\ - PRIMARY KEY (id),\n\ - INDEX(`user`)\n\ -) engine=innodb" -#define AMP "`" -#endif -#define DROP_CMD "DROP TABLE " AMP "data" AMP -#define INSERT_TRIO_CMD "INSERT INTO " AMP "data" AMP " (" AMP "id" AMP ", " AMP "user" AMP ", " AMP "info" AMP ") VALUES (%d, %s, %s)" -#define SELECT_TRIO_CMD "SELECT " AMP "id" AMP ", " AMP "user" AMP ", " AMP "info" AMP " FROM " AMP "data" AMP " WHERE " AMP "user" AMP " = '%s'" -#define INSERT_CMD "INSERT INTO " AMP "data" AMP " (" AMP "id" AMP ", " AMP "user" AMP ", " AMP "info" AMP ") VALUES (?, ?, ?)" -#define SELECT_CMD "SELECT " AMP "id" AMP ", " AMP "user" AMP ", " AMP "info" AMP " FROM " AMP "data" AMP " WHERE " AMP "user" AMP " = ?" - -#define dprintf(ARGS) { printf("%s: ", name); printf ARGS; } - - -static void print_blob(unsigned long len, char *blob) { - unsigned int i; - - for (i = 0; i < len; i++) printf("%02X ", blob[i]); - printf("(='"); - for (i = 0; i < len; i++) printf("%c", blob[i]); - printf("')"); -} - - -static void print_free_result(const char *name, unsigned long *lens, char **res) { - dprintf((" id='%s'=%d\n", res[0], atoi(res[0]))); - - dprintf((" user='%s'\n", res[1])); - - dprintf((" blob=")); - if (res[2] && lens) print_blob(lens[2], res[2]); - else printf("null"); - printf("\n"); - - free(res[0]); - free(res[1]); - free(res[2]); -} - - -int main(int argn __attribute((unused)), char *argv[]) { - char *name, *cmd; - const char *cs; - glite_lbu_DBContext ctx; - glite_lbu_Statement stmt; - int caps; - -#ifndef NO_PREPARED - char blob1[] = "Guess: blob or \000string?"; - char blob2[] = {0, 1, 2, 3, 4, 5}; -#endif - - int nr; - char *res[3]; - unsigned long lens[3]; - - if ((name = strrchr(argv[0], '/')) != NULL) name++; - else name = argv[0]; - if ((cs = getenv("CS")) == NULL) cs = CS; - cmd = NULL; - - // init - dprintf(("connecting to %s...\n", cs)); - if (glite_lbu_InitDBContext(&ctx) != 0) goto failctx; - if (glite_lbu_DBConnect(ctx, cs) != 0) goto failctx; - if ((caps = glite_lbu_DBQueryCaps(ctx)) == -1) goto failcon; -#ifndef NO_PREPARED - if ((caps & GLITE_LBU_DB_CAP_PREPARED) == 0) { - dprintf(("can't do prepared commands, exiting.")); - goto failcon; - } -#endif - // caps - glite_lbu_DBSetCaps(ctx, caps | GLITE_LBU_DB_CAP_ERRORS); - dprintf(("capabilities: %d\n", caps)); - // create all needed tables and data - dprintf(("creating tables...\n")); - glite_lbu_ExecSQL(ctx, DROP_CMD, NULL); - if (glite_lbu_ExecSQL(ctx, CREATE_CMD, NULL) == -1) goto failcon; - // trio-insert - dprintf(("trio-insert...\n")); - asprintf(&cmd, INSERT_TRIO_CMD, 1, "'hyperochus'", "NULL"); - if (glite_lbu_ExecSQL(ctx, cmd, NULL) != 1) goto failcon; - free(cmd); cmd = NULL; -#ifndef NO_PREPARED - // prepared-insert - dprintf(("prepare-insert...\n")); - if (glite_lbu_PrepareStmt(ctx, INSERT_CMD, &stmt) != 0) goto failcon; - dprintf(("execute 1. insert...\n")); - if (glite_lbu_ExecPreparedStmt(stmt, 3, - GLITE_LBU_DB_TYPE_INT, 2, - GLITE_LBU_DB_TYPE_VARCHAR, "cicomexocitl.civ", - GLITE_LBU_DB_TYPE_BLOB, blob1, sizeof(blob1) - 1) != 1) goto failstmt; - dprintf(("execute 2. insert...\n")); - if (glite_lbu_ExecPreparedStmt(stmt, 3, - GLITE_LBU_DB_TYPE_INT, 3, - GLITE_LBU_DB_TYPE_VARCHAR, "tartarus", - GLITE_LBU_DB_TYPE_NULL) != 1) goto failstmt; - dprintf(("execute 3. insert...\n")); - if (glite_lbu_ExecPreparedStmt(stmt, 3, - GLITE_LBU_DB_TYPE_INT, 4, - GLITE_LBU_DB_TYPE_VARCHAR, "harpia", - GLITE_LBU_DB_TYPE_BLOB, blob2, sizeof(blob2)) != 1) goto failstmt; - glite_lbu_FreeStmt(&stmt); - dprintf(("\n")); -#endif - - // trio-query -{ - const char *user; - - user = "harpia"; - dprintf(("selecting '%s'...\n", user)); - asprintf(&cmd, SELECT_TRIO_CMD, user); - if (glite_lbu_ExecSQL(ctx, cmd, &stmt) == -1) goto failcon; - free(cmd); cmd = NULL; - dprintf(("fetching '%s'...\n", user)); - while ((nr = glite_lbu_FetchRow(stmt, 3, lens, res)) > 0) { - dprintf(("Result: n=%d, res=%p\n", nr, res)); - print_free_result(name, lens, res); - } - if (nr < 0) dprintf(("fetch '%s' failed\n", user)); - dprintf(("closing stmt...\n")); - glite_lbu_FreeStmt(&stmt); - dprintf(("\n")); - - user = "hyperochus"; - dprintf(("selecting '%s'...\n", user)); - asprintf(&cmd, SELECT_TRIO_CMD, user); - if (glite_lbu_ExecSQL(ctx, cmd, &stmt) == -1) goto failcon; - free(cmd); cmd = NULL; - dprintf(("fetching '%s'...\n", user)); - while ((nr = glite_lbu_FetchRow(stmt, 3, lens, res)) > 0) { - dprintf(("Result: n=%d, res=%p\n", nr, res)); - print_free_result(name, lens, res); - } - if (nr < 0) dprintf(("fetch '%s' failed\n", user)); - dprintf(("closing stmt...\n")); - glite_lbu_FreeStmt(&stmt); - dprintf(("\n")); - - user = "nobody"; - dprintf(("selecting '%s'...\n", user)); - asprintf(&cmd, SELECT_TRIO_CMD, user); - if (glite_lbu_ExecSQL(ctx, cmd, &stmt) == -1) goto failcon; - free(cmd); cmd = NULL; - dprintf(("fetching '%s'...\n", user)); - while ((nr = glite_lbu_FetchRow(stmt, 3, lens, res)) > 0) { - dprintf(("Result: n=%d, res=%p\n", nr, res)); - print_free_result(name, lens, res); - } - if (nr < 0) dprintf(("fetch '%s' failed\n", user)); - dprintf(("closing stmt...\n")); - glite_lbu_FreeStmt(&stmt); - dprintf(("\n")); - - dprintf(("nonsese...\n")); - if (glite_lbu_ExecSQL(ctx, "nonsense", NULL) == -1) { - dprintf(("was error, OK\n")); - } else { - dprintf(("this should file\n")); - goto failcon; - } -} - -#ifndef NO_PREPARED - // "param" queries -{ - const char *user = NULL; - - dprintf(("preparing '%s'...\n", user)); - if ((glite_lbu_PrepareStmt(ctx, SELECT_CMD, &stmt)) != 0) goto failcon; - - user = "cicomexocitl.civ"; - dprintf(("executing '%s'...\n", user)); - if (glite_lbu_ExecPreparedStmt(stmt, 1, GLITE_LBU_DB_TYPE_VARCHAR, user) == -1) goto failstmt; - dprintf(("fetching '%s'...\n", user)); - while ((nr = glite_lbu_FetchRow(stmt, 3, lens, res)) > 0) { - dprintf(("Result: n=%d, res=%p\n", nr, res)); - print_free_result(name, lens, res); - } - if (nr < 0) dprintf(("fetch '%s' failed\n", user)); - dprintf(("\n")); - - dprintf(("closing stmt...\n")); - glite_lbu_FreeStmt(&stmt); - dprintf(("\n")); -} -#endif - - dprintf(("closing...\n")); - glite_lbu_DBClose(ctx); - glite_lbu_FreeDBContext(ctx); - return 0; - -#ifndef NO_PREPARED -failstmt: - dprintf(("closing stmt...\n")); - glite_lbu_FreeStmt(&stmt); -#endif -failcon: - dprintf(("closing...\n")); - glite_lbu_DBClose(ctx); -failctx: - if (ctx) { - char *t, *d; - - glite_lbu_DBError(ctx, &t, &d); - printf("Error %s: %s\n", t, d); - free(t); free(d); - } - glite_lbu_FreeDBContext(ctx); - free(cmd); - dprintf(("failed\n")); - return 1; -} diff --git a/org.glite.lbjp-common.db/interface/db.h b/org.glite.lbjp-common.db/interface/db.h deleted file mode 100644 index bd7d7e0..0000000 --- a/org.glite.lbjp-common.db/interface/db.h +++ /dev/null @@ -1,371 +0,0 @@ -#ifndef GLITE_LBU_DB_H -#define GLITE_LBU_DB_H - -#ident "$Header$" - - -#include -#include - - -#ifdef __cplusplus -extern "C" { -#endif - - -/** - * \file db.h - * \defgroup database Database module - * - * Database modul module API (LB & JP Utils). - * - * There are two ways to access DB here: - * - simple: - * - * SQL commands as single string. All values are incorporated in the SQL command strings. Proper escaping is required. - * - enhanced: - * - * Prepared SQL commands with separated parameters, functions PrepareStmt() and ExecPreparedStmt(). All values are delivered in separated buffers. Its faster for multiple using and more secure. - * @{ - */ - - -/** - * Enable transaction support if available. - * - * With disabled transaction can be used transaction functions, they are just ignored. - */ -#define GLITE_LBU_DB_CAP_TRANSACTIONS 1 - -/** - * Check prepared parameters support. - */ -#define GLITE_LBU_DB_CAP_PREPARED 2 - -/** - * Check for getting indexes support. - * - * Needed for QueryIndices call. - */ -#define GLITE_LBU_DB_CAP_INDEX 4 - - -/** - * Print all errors. - * - * Not returned from detection of capabilities. - */ -#define GLITE_LBU_DB_CAP_ERRORS 8 - - -/** - * Database connection context. - */ -typedef struct glite_lbu_DBContext_s *glite_lbu_DBContext; - - -/** - * Prepared statement, used for SQL statement with parameters. - */ -typedef struct glite_lbu_Statement_s *glite_lbu_Statement; - - -/** - * Structure holds date for multi-rows insert. - */ -typedef struct glite_lbu_bufInsert_s *glite_lbu_bufInsert; - - - -/** - * All types of parameteres, they match to the SQL types. - */ -typedef enum { - GLITE_LBU_DB_TYPE_NULL = 0, - GLITE_LBU_DB_TYPE_TINYINT = 1, - GLITE_LBU_DB_TYPE_INT = 2, - GLITE_LBU_DB_TYPE_TINYBLOB = 3, - GLITE_LBU_DB_TYPE_TINYTEXT = 4, - GLITE_LBU_DB_TYPE_BLOB = 5, - GLITE_LBU_DB_TYPE_TEXT = 6, - GLITE_LBU_DB_TYPE_MEDIUMBLOB = 7, - GLITE_LBU_DB_TYPE_MEDIUMTEXT = 8, - GLITE_LBU_DB_TYPE_LONGBLOB = 9, - GLITE_LBU_DB_TYPE_LONGTEXT = 10, - GLITE_LBU_DB_TYPE_VARCHAR = 11, - GLITE_LBU_DB_TYPE_CHAR = 12, - GLITE_LBU_DB_TYPE_DATE = 13, - GLITE_LBU_DB_TYPE_TIME = 14, - GLITE_LBU_DB_TYPE_DATETIME = 15, - GLITE_LBU_DB_TYPE_TIMESTAMP = 16, - GLITE_LBU_DB_TYPE_BOOLEAN = 17, - GLITE_LBU_DB_TYPE_LAST = 18 -} glite_lbu_DBType; - - - -/** - * Get error state from DB context. - * - * \param[in] ctx context to work with - * \param[out] text error name - * \param[out] desc error description - */ -int glite_lbu_DBError(glite_lbu_DBContext ctx, char **text, char **desc); - - -/** - * Initialize the database context. - * - * \param[out] ctx result context - */ -int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx); - - -/** - * Free database context. - */ -void glite_lbu_FreeDBContext(glite_lbu_DBContext ctx); - - -/** - * Connect to the given database. - * - * \param[out] ctx context to work with - * \param[in] cs connect string user/password\@host:database - * - * \return error code, 0 = OK - */ -int glite_lbu_DBConnect(glite_lbu_DBContext ctx, const char *cs); - - -/** - * Close the connection. - * - * \param[in,out] ctx context to work with - */ -void glite_lbu_DBClose(glite_lbu_DBContext ctx); - - -/** - * Check database version and capabilities. - * - * \param[in,out] ctx context to work with - * - * \return capabilities - * \retval -1 error occured - */ -int glite_lbu_DBQueryCaps(glite_lbu_DBContext ctx); - - -/** - * Set the database capabilities on already initialized context. - * - * It should be find out by DBQueryCaps() first. - * - * \param[in,out] ctx context to work with - * \param[in] caps capabilities to use, should be found out by QueryCaps() - */ -void glite_lbu_DBSetCaps(glite_lbu_DBContext ctx, int caps); - - -/** - * Start transaction. - */ -int glite_lbu_Transaction(glite_lbu_DBContext ctx); - - -/** - * Commit (end) transaction. - */ -int glite_lbu_Commit(glite_lbu_DBContext ctx); - - -/** - * Cancel transaction. - */ -int glite_lbu_Rollback(glite_lbu_DBContext ctx); - - -/** - * \param[in,out] stmt executed SQL statement - * \param[in] n number of items for sure there is enough space in lengths and results - * \param[out] lengths array with lengths (good for data blobs), may be NULL - * \param[out] results array with results, all items are allocated - * - * \retval >0 number of fields of the retrieved row - * \retval 0 no more rows - * \retval -1 error - */ -int glite_lbu_FetchRow(glite_lbu_Statement stmt, unsigned int n, unsigned long *lengths, char **results); - - -/** - * Free the statement structure and destroy its parameters. - * - * Statement will be set to NULL and multiple calls are allowed. - * - * \param[in,out] stmt statement - */ -void glite_lbu_FreeStmt(glite_lbu_Statement *stmt); - - -/** - * Parse and execute one simple SQL statement. - * All values are incorporated int the SQL command string. - * - * \param[in,out] ctx context to work with - * \param[in] cmd SQL command - * \param[out] stmt statement handle with results (makes sense for selects only) - * - * \return number of rows selected, created or affected by update, -1 on error - */ -int glite_lbu_ExecSQL(glite_lbu_DBContext ctx, const char *cmd, glite_lbu_Statement *stmt); - - -/** - * Query for column names of the statement. - * - * It work only for simple API, so only after ExecSQL(). - * - * \param[in,out] stmt the statement handle - * \param[out] cols result array of names - * - * \return error code - */ -int glite_lbu_QueryColumns(glite_lbu_Statement stmt, char **cols); - - -/** - * Retrieve column names of a query simple SQL statement. - * - * \param[in,out] ctx context to work with - * \param[in] table table name - * \param[out] key_names one-dimensional index names array - * \param[out] column_names two-dimensional column names array - * - * \return 0 if OK, nonzero on error - */ -int glite_lbu_QueryIndices(glite_lbu_DBContext ctx, const char *table, char ***key_names, char ****column_names); - - -/** - * Convert time_t into database-specific time string. - * - * The result string can be used directly in SQL commands. - * - * \param[in] t the converted time - * \param[out] str result allocated string - */ -void glite_lbu_TimeToDB(time_t t, char **str); - - -/** - * Convert double into database-specific time string. - * - * The result string can be used directly in SQL commands. - * - * \param[in] t the converted time - * \param[out] str result allocated string - */ -void glite_lbu_TimestampToDB(double t, char **str); - - -/** - * Convert database-specific time string to time_t. - * - * String is expected in database for (ISO format). - * - * \param[in] str the converted string - * \return result time - */ -time_t glite_lbu_DBToTime(const char *str); - - -/** - * 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 - */ -int glite_lbu_bufferedInsertInit(glite_lbu_DBContext ctx, glite_lbu_bufInsert *bi, const char *table_name, long size_limit, long record_limit, const 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 - */ -int glite_lbu_bufferedInsert(glite_lbu_bufInsert bi, const char *row); - - -/** - * Flush buffered data and free bi structure. - */ -int glite_lbu_bufferedInsertClose(glite_lbu_bufInsert bi); - - -/** - * Prepare the SQL statement. Use glite_lbu_FreeStmt() to free it. - * - * \param[in,out] ctx context to work with - * \param[in] sql SQL command - * \param[out] stmt returned SQL statement - * - * \return error code - */ -int glite_lbu_PrepareStmt(glite_lbu_DBContext ctx, const char *sql, glite_lbu_Statement *stmt); - - -/** - * Bind input parameters and execute prepared SQL statement. - * Results can be fetched via glite_lbu_FetchRow. - * - * \param[in,out] stmt SQL statement - * \param[in] n number of items - * - * Variable parameters (n-times): - * - * always: - * - * \param type DB item type - * - * then one of them: - * - * \param GLITE_LBU_DB_TYPE_TINYINT int c - * \param GLITE_LBU_DB_TYPE_INT long int i - * \param GLITE_LBU_DB_TYPE_...BLOB/TEXT void *b, unsigned long len - * \param GLITE_LBU_DB_TYPE_[VAR]CHAR char *str - * \param GLITE_LBU_DB_TYPE_DATE/TIME/DATETIME time_t t - * \param GLITE_LBU_DB_TYPE_TIMESTAMP double t - * \param GLITE_LBU_DB_TYPE_BOOLEAN int b - * \param GLITE_LBU_DB_TYPE_NULL - - * - * \return number of affected rows, -1 on error - */ -int glite_lbu_ExecPreparedStmt(glite_lbu_Statement stmt, int n, ...); - - -/** - * "va_list version" of glite_lbu_ExecPreparedStmt(). - */ -int glite_lbu_ExecPreparedStmt_v(glite_lbu_Statement stmt, int n, va_list ap); - - -/** - * Returns the last automatically generated id, if any. - */ -long int glite_lbu_Lastid(glite_lbu_Statement stmt); - - -/** - * @} database group - */ - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/org.glite.lbjp-common.db/project/ChangeLog b/org.glite.lbjp-common.db/project/ChangeLog deleted file mode 100644 index 2b5c31a..0000000 --- a/org.glite.lbjp-common.db/project/ChangeLog +++ /dev/null @@ -1,33 +0,0 @@ -1.0.0-2 -- initial version - -1.0.0-3 -- distinguish stage from prefix (etics build) - -1.0.0-4 -- configure script update (globus flavors added to configure call) - -1.0.0-5 -- configure script and Makefile update (splitting mysql dependency into separate run-time and build-time deps) - -1.0.0-6 -- configure script update (fixed 'mysql-devel' handling) - -1.0.0-7 -- Makefile fixes - streamlining the 'clean' target, fixing MySQL library detection - -1.0.0-8 -- Soname detection logic moved from the Makefille to a shell-out script - -1.0.1-1 -- Using second fractions in timestamps - -1.0.1-2 -- Makefile relies on the libdir variable -- New configure script - -1.0.1-3 -- Module repacked. - -1.0.1-4 -- install libraries into $libdir diff --git a/org.glite.lbjp-common.db/project/get_soname.sh b/org.glite.lbjp-common.db/project/get_soname.sh deleted file mode 100755 index d5f41b3..0000000 --- a/org.glite.lbjp-common.db/project/get_soname.sh +++ /dev/null @@ -1,21 +0,0 @@ -#! /bin/sh - -lib="" -for prefix in $@; do - for dir in "$prefix" "$prefix/mysql"; do - l=`find $dir -maxdepth 1 -name libmysqlclient.so* | head -n 1` - if [ -f "$l" ]; then - lib=$l - break - fi - done - if [ x"" != x"$lib" ]; then - break - fi -done - -if [ x"" != x"$lib" ]; then - readelf -d $lib | grep SONAME | sed 's/.*\(libmysqlclient.so.[0-9]\{1,\}\).*/\1/' -else - echo notfound -fi diff --git a/org.glite.lbjp-common.db/project/version.properties b/org.glite.lbjp-common.db/project/version.properties deleted file mode 100644 index 2ec18a2..0000000 --- a/org.glite.lbjp-common.db/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -: /cvs/jra1mw/org.glite.lbjp-common.db/project/version.properties,v 1.2 2009/01/21 10:44:34 zsustr Exp $ -module.version=1.0.1 -module.age=4 diff --git a/org.glite.lbjp-common.db/src/db.c b/org.glite.lbjp-common.db/src/db.c deleted file mode 100644 index 1c91526..0000000 --- a/org.glite.lbjp-common.db/src/db.c +++ /dev/null @@ -1,1239 +0,0 @@ -#ident "$Header$" - -#include -#ifdef LBS_DB_PROFILE -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "glite/lbu/trio.h" -#include "db.h" - - -#define GLITE_LBU_MYSQL_INDEX_VERSION 40001 -#define GLITE_LBU_MYSQL_PREPARED_VERSION 40102 -#define BUF_INSERT_ROW_ALLOC_BLOCK 1000 -#ifndef GLITE_LBU_DEFAULT_RESULT_BUFFER_LENGTH -#define GLITE_LBU_DEFAULT_RESULT_BUFFER_LENGTH 256 -#endif - -#define CLR_ERR(CTX) lbu_clrerr((CTX)) -#define ERR(CTX, CODE, ARGS...) lbu_err((CTX), (CODE), __FUNCTION__, __LINE__, ##ARGS) -#define STATUS(CTX) ((CTX)->err.code) -#define MY_ERR(CTX) myerr((CTX), __FUNCTION__, __LINE__) -#define MY_ERRSTMT(STMT) myerrstmt((STMT), __FUNCTION__, __LINE__) -#define MY_ISOKSTMT(STMT, RETRY) myisokstmt((STMT), __FUNCTION__, __LINE__, (RETRY)) - -#define USE_TRANS(CTX) ((CTX->caps & GLITE_LBU_DB_CAP_TRANSACTIONS) != 0) -#define LOAD(SYM, SYM2) if ((*(void **)(&db_handle.SYM) = dlsym(db_handle.lib, SYM2)) == NULL) { \ - err = ERR(*ctx, ENOENT, "can't load symbol %s from mysql library (%s)", SYM2, dlerror()); \ - break; \ -} - -#define dprintf(CTX, FMT...) if (CTX->caps & GLITE_LBU_DB_CAP_ERRORS) fprintf(stderr, ##FMT) - - -struct glite_lbu_DBContext_s { - MYSQL *mysql; - const char *cs; - int caps; - struct { - int code; - char *desc; - } err; - int in_transaction; /* this flag is set whenever we are in DB transaction */ -}; - - -struct glite_lbu_Statement_s { - glite_lbu_DBContext ctx; - - /* for simple commands */ - MYSQL_RES *result; - - /* for prepared commands */ - MYSQL_STMT *stmt; - unsigned long nrfields; - char *sql; -}; - - -struct glite_lbu_bufInsert_s { - glite_lbu_DBContext 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 */ -}; - - -/* - * mapping glite DB types to mysql types - */ -int glite_type_to_mysql[] = { - MYSQL_TYPE_NULL, - MYSQL_TYPE_TINY, - MYSQL_TYPE_LONG, - MYSQL_TYPE_TINY_BLOB, - MYSQL_TYPE_TINY_BLOB, - MYSQL_TYPE_BLOB, - MYSQL_TYPE_BLOB, - MYSQL_TYPE_MEDIUM_BLOB, - MYSQL_TYPE_MEDIUM_BLOB, - MYSQL_TYPE_LONG_BLOB, - MYSQL_TYPE_LONG_BLOB, - MYSQL_TYPE_VAR_STRING, - MYSQL_TYPE_STRING, - MYSQL_TYPE_DATE, - MYSQL_TYPE_TIME, - MYSQL_TYPE_DATETIME, - MYSQL_TYPE_TIMESTAMP, -}; - - -typedef struct { - void *lib; - pthread_mutex_t lock; - - void *(*mysql_init)(void *); - unsigned long (*mysql_get_client_version)(void); - int (*mysql_options)(MYSQL *mysql, enum mysql_option option, const char *arg); - unsigned int (*mysql_errno)(MYSQL *mysql); - const char *(*mysql_error)(MYSQL *mysql); - unsigned int (*mysql_stmt_errno)(MYSQL_STMT *stmt); - const char *(*mysql_stmt_error)(MYSQL_STMT *stmt); - MYSQL *(*mysql_real_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag); - void (*mysql_close)(MYSQL *mysql); - int (*mysql_query)(MYSQL *mysql, const char *stmt_str); - MYSQL_RES *(*mysql_store_result)(MYSQL *mysql); - void (*mysql_free_result)(MYSQL_RES *result); - my_ulonglong (*mysql_affected_rows)(MYSQL *mysql); - my_bool (*mysql_stmt_close)(MYSQL_STMT *); - unsigned int (*mysql_num_fields)(MYSQL_RES *result); - unsigned long *(*mysql_fetch_lengths)(MYSQL_RES *result); - my_bool (*mysql_stmt_bind_result)(MYSQL_STMT *stmt, MYSQL_BIND *bind); - int (*mysql_stmt_prepare)(MYSQL_STMT *stmt, const char *stmt_str, unsigned long length); - int (*mysql_stmt_store_result)(MYSQL_STMT *stmt); - MYSQL_ROW (*mysql_fetch_row)(MYSQL_RES *result); - MYSQL_FIELD *(*mysql_fetch_field)(MYSQL_RES *result); - const char *(*mysql_get_server_info)(MYSQL *mysql); - MYSQL_STMT *(*mysql_stmt_init)(MYSQL *mysql); - my_bool (*mysql_stmt_bind_param)(MYSQL_STMT *stmt, MYSQL_BIND *bind); - int (*mysql_stmt_execute)(MYSQL_STMT *stmt); - int (*mysql_stmt_fetch)(MYSQL_STMT *stmt); - my_ulonglong (*mysql_stmt_insert_id)(MYSQL_STMT *stmt); - my_ulonglong (*mysql_stmt_affected_rows)(MYSQL_STMT *stmt); - MYSQL_RES *(*mysql_stmt_result_metadata)(MYSQL_STMT *stmt); - int (*mysql_stmt_fetch_column)(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int column, unsigned long offset); -} mysql_lib_handle_t; - - -static mysql_lib_handle_t db_handle = { - lib: NULL, - lock: PTHREAD_MUTEX_INITIALIZER -}; - - -static int lbu_clrerr(glite_lbu_DBContext ctx); -static int lbu_err(glite_lbu_DBContext ctx, int code, const char *func, int line, const char *desc, ...); -static int myerr(glite_lbu_DBContext ctx, const char *source, int line); -static int myerrstmt(glite_lbu_Statement stmt, const char *source, int line); -static int myisokstmt(glite_lbu_Statement stmt, const char *source, int line, int *retry); -static int db_connect(glite_lbu_DBContext ctx, const char *cs, MYSQL **mysql); -static void db_close(MYSQL *mysql); -static int transaction_test(glite_lbu_DBContext ctx); -static int FetchRowSimple(glite_lbu_DBContext ctx, MYSQL_RES *result, unsigned long *lengths, char **results); -static int FetchRowPrepared(glite_lbu_DBContext ctx, glite_lbu_Statement stmt, unsigned int n, unsigned long *lengths, char **results); -static void set_time(MYSQL_TIME *mtime, const double time); -static void glite_lbu_DBCleanup(void); -static void glite_lbu_FreeStmt_int(glite_lbu_Statement stmt); - - -/* ---- common ---- */ - - -int glite_lbu_DBError(glite_lbu_DBContext ctx, char **text, char **desc) { - if (text) *text = strdup(strerror(ctx->err.code)); - if (desc) { - if (ctx->err.desc) *desc = strdup(ctx->err.desc); - else *desc = NULL; - } - - return ctx->err.code; -} - - -int glite_lbu_InitDBContext(glite_lbu_DBContext *ctx) { - int err = 0; - unsigned int ver_u; - - *ctx = calloc(1, sizeof **ctx); - if (!*ctx) return ENOMEM; - - /* dynamic load the mysql library */ - pthread_mutex_lock(&db_handle.lock); - if (!db_handle.lib) { - db_handle.lib = dlopen(MYSQL_SONAME, RTLD_LAZY | RTLD_LOCAL); - if (!db_handle.lib) return ERR(*ctx, ENOENT, "dlopen(): " MYSQL_SONAME ": %s", dlerror()); - do { - LOAD(mysql_init, "mysql_init"); - LOAD(mysql_get_client_version, "mysql_get_client_version"); - LOAD(mysql_options, "mysql_options"); - LOAD(mysql_errno, "mysql_errno"); - LOAD(mysql_error, "mysql_error"); - LOAD(mysql_stmt_errno, "mysql_stmt_errno"); - LOAD(mysql_stmt_error, "mysql_stmt_error"); - LOAD(mysql_real_connect, "mysql_real_connect"); - LOAD(mysql_close, "mysql_close"); - LOAD(mysql_query, "mysql_query"); - LOAD(mysql_store_result, "mysql_store_result"); - LOAD(mysql_free_result, "mysql_free_result"); - LOAD(mysql_affected_rows, "mysql_affected_rows"); - LOAD(mysql_stmt_close, "mysql_stmt_close"); - LOAD(mysql_num_fields, "mysql_num_fields"); - LOAD(mysql_fetch_lengths, "mysql_fetch_lengths"); - LOAD(mysql_stmt_bind_result, "mysql_stmt_bind_result"); - LOAD(mysql_stmt_prepare, "mysql_stmt_prepare"); - LOAD(mysql_stmt_store_result, "mysql_stmt_store_result"); - LOAD(mysql_fetch_row, "mysql_fetch_row"); - LOAD(mysql_fetch_field, "mysql_fetch_field"); - LOAD(mysql_get_server_info, "mysql_get_server_info"); - LOAD(mysql_stmt_init, "mysql_stmt_init"); - LOAD(mysql_stmt_bind_param, "mysql_stmt_bind_param"); - LOAD(mysql_stmt_execute, "mysql_stmt_execute"); - LOAD(mysql_stmt_fetch, "mysql_stmt_fetch"); - LOAD(mysql_stmt_insert_id, "mysql_stmt_insert_id"); - LOAD(mysql_stmt_affected_rows, "mysql_stmt_affected_rows"); - LOAD(mysql_stmt_result_metadata, "mysql_stmt_result_metadata"); - LOAD(mysql_stmt_fetch_column, "mysql_stmt_fetch_column"); - - // check the runtime version - ver_u = db_handle.mysql_get_client_version(); - if (ver_u != MYSQL_VERSION_ID) { - fprintf(stderr,"Warning: MySQL library version mismatch (compiled '%lu', runtime '%lu')", MYSQL_VERSION_ID, ver_u); - syslog(LOG_WARNING,"MySQL library version mismatch (compiled '%lu', runtime '%lu')", MYSQL_VERSION_ID, ver_u); - } - - pthread_mutex_unlock(&db_handle.lock); - atexit(glite_lbu_DBCleanup); - } while(0); - - if (err) { - dlclose(db_handle.lib); - db_handle.lib = NULL; - pthread_mutex_unlock(&db_handle.lock); - return err; - } - } else pthread_mutex_unlock(&db_handle.lock); - - return 0; -} - - -void glite_lbu_FreeDBContext(glite_lbu_DBContext ctx) { - if (ctx) { - assert(ctx->mysql == NULL); - free(ctx->err.desc); - free(ctx); - } -} - - -int glite_lbu_DBConnect(glite_lbu_DBContext ctx, const char *cs) { - if (db_connect(ctx, cs, &ctx->mysql) != 0 || - glite_lbu_ExecSQL(ctx, "SET AUTOCOMMIT=1", NULL) < 0 || - glite_lbu_ExecSQL(ctx, "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ", NULL) < 0) - return STATUS(ctx); - else - return 0; -} - - -void glite_lbu_DBClose(glite_lbu_DBContext ctx) { - db_close(ctx->mysql); - ctx->mysql = NULL; - CLR_ERR(ctx); -} - - -int glite_lbu_DBQueryCaps(glite_lbu_DBContext ctx) { - MYSQL *m = ctx->mysql; - int major,minor,sub,version,caps,origcaps; - const char *ver_s; - - origcaps = ctx->caps; - caps = 0; - - ver_s = db_handle.mysql_get_server_info(m); - if (!ver_s || 3 != sscanf(ver_s,"%d.%d.%d",&major,&minor,&sub)) - return ERR(ctx, EINVAL, "problem retreiving MySQL version"); - version = 10000*major + 100*minor + sub; - - if (version >= GLITE_LBU_MYSQL_INDEX_VERSION) caps |= GLITE_LBU_DB_CAP_INDEX; - if (version >= GLITE_LBU_MYSQL_PREPARED_VERSION) caps |= GLITE_LBU_DB_CAP_PREPARED; - - CLR_ERR(ctx); - transaction_test(ctx); - if ((ctx->caps & GLITE_LBU_DB_CAP_TRANSACTIONS)) caps |= GLITE_LBU_DB_CAP_TRANSACTIONS; - - ctx->caps = origcaps; - if (STATUS(ctx) == 0) return caps; - else return -1; -} - - -void glite_lbu_DBSetCaps(glite_lbu_DBContext ctx, int caps) { - ctx->caps = caps; -} - - -int glite_lbu_Transaction(glite_lbu_DBContext ctx) { - CLR_ERR(ctx); - if (USE_TRANS(ctx)) { - if (glite_lbu_ExecSQL(ctx, "SET AUTOCOMMIT=0", NULL) < 0) goto err; - if (glite_lbu_ExecSQL(ctx, "BEGIN", NULL) < 0) goto err; - ctx->in_transaction = 1; - } -err: - return STATUS(ctx); -} - - -int glite_lbu_Commit(glite_lbu_DBContext ctx) { - CLR_ERR(ctx); - if (USE_TRANS(ctx)) { - if (glite_lbu_ExecSQL(ctx, "COMMIT", NULL) < 0) goto err; - if (glite_lbu_ExecSQL(ctx, "SET AUTOCOMMIT=1", NULL) < 0) goto err; - ctx->in_transaction = 0; - } -err: - return STATUS(ctx); -} - - -int glite_lbu_Rollback(glite_lbu_DBContext ctx) { - CLR_ERR(ctx); - if (USE_TRANS(ctx)) { - if (glite_lbu_ExecSQL(ctx, "ROLLBACK", NULL) < 0) goto err; - if (glite_lbu_ExecSQL(ctx, "SET AUTOCOMMIT=1", NULL) < 0) goto err; - ctx->in_transaction = 0; - } -err: - return STATUS(ctx); -} - - -int glite_lbu_FetchRow(glite_lbu_Statement stmt, unsigned int n, unsigned long *lengths, char **results) { - memset(results, 0, n * sizeof(*results)); - if (stmt->result) return FetchRowSimple(stmt->ctx, stmt->result, lengths, results); - else return FetchRowPrepared(stmt->ctx, stmt, n, lengths, results); -} - - -static void glite_lbu_FreeStmt_int(glite_lbu_Statement stmt) { - if (stmt) { - if (stmt->result) db_handle.mysql_free_result(stmt->result); - if (stmt->stmt) db_handle.mysql_stmt_close(stmt->stmt); - free(stmt->sql); - } -} - - -void glite_lbu_FreeStmt(glite_lbu_Statement *stmt) { - glite_lbu_FreeStmt_int(*stmt); - free(*stmt); - *stmt = NULL; -} - - -int glite_lbu_QueryIndices(glite_lbu_DBContext ctx, const char *table, char ***key_names, char ****column_names) { - glite_lbu_Statement stmt = NULL; - - size_t i,j,ret; - -/* XXX: "show index from" columns. Matches at least MySQL 4.0.11 */ - char *sql, *showcol[12]; - int Key_name,Seq_in_index,Column_name,Sub_part; - - char **keys = NULL; - size_t *cols = NULL; - char **col_names = NULL; - - size_t nkeys = 0; - - char ***idx = NULL; - - Key_name = Seq_in_index = Column_name = Sub_part = -1; - - asprintf(&sql, "show index from %s", table); - if (glite_lbu_ExecSQL(ctx,sql,&stmt)<0) { - free(sql); - return STATUS(ctx); - } - free(sql); - - while ((ret = glite_lbu_FetchRow(stmt,sizeof(showcol)/sizeof(showcol[0]),NULL,showcol)) > 0) { - assert(ret <= (int)(sizeof showcol/sizeof showcol[0])); - - if (!col_names) { - col_names = malloc(ret * sizeof col_names[0]); - glite_lbu_QueryColumns(stmt,col_names); - for (i=0; i= 0 && Seq_in_index >= 0 && - Column_name >= 0 && Sub_part >= 0); - - } - - for (i=0; imysql, cmd)) { - /* error occured */ - switch (merr = db_handle.mysql_errno(ctx->mysql)) { - case 0: - break; - case ER_DUP_ENTRY: - ERR(ctx, EEXIST, db_handle.mysql_error(ctx->mysql)); - return -1; - break; - case CR_SERVER_LOST: - case CR_SERVER_GONE_ERROR: - if (ctx->in_transaction) { - ERR(ctx, ERESTART, db_handle.mysql_error(ctx->mysql)); - return -1; - } - else if (retry_nr <= 0) - do_reconnect = 1; - break; - case ER_LOCK_DEADLOCK: - ERR(ctx, EDEADLOCK, db_handle.mysql_error(ctx->mysql)); - return -1; - break; - default: - MY_ERR(ctx); - return -1; - break; - } - } - retry_nr++; - } - - if (stmt) { - *stmt = calloc(1, sizeof(**stmt)); - if (!*stmt) { - ERR(ctx, ENOMEM, NULL); - return -1; - } - (**stmt).ctx = ctx; - (**stmt).result = db_handle.mysql_store_result(ctx->mysql); - if (!(**stmt).result) { - if (db_handle.mysql_errno(ctx->mysql)) { - MY_ERR(ctx); - *stmt = NULL; - return -1; - } - } - } else { - MYSQL_RES *r = db_handle.mysql_store_result(ctx->mysql); - db_handle.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,cmd,pid,end.tv_sec,end.tv_usec,sum.tv_sec,sum.tv_usec); -#endif - - return db_handle.mysql_affected_rows(ctx->mysql); -} - - -int glite_lbu_QueryColumns(glite_lbu_Statement stmt, char **cols) -{ - int i = 0; - MYSQL_FIELD *f; - - CLR_ERR(stmt->ctx); - if (!stmt->result) return ERR(stmt->ctx, EINVAL, "QueryColumns implemented only for simple API"); - while ((f = db_handle.mysql_fetch_field(stmt->result))) cols[i++] = f->name; - return i == 0; -} - - -void glite_lbu_TimeToDB(time_t t, char **str) { - struct tm *tm = gmtime(&t); - - asprintf(str,"'%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); -} - - -void glite_lbu_TimestampToDB(double t, char **str) { - time_t tsec = t; - struct tm *tm = gmtime(&tsec); - - t = t - tsec + tm->tm_sec; - asprintf(str,"'%4d-%02d-%02d %02d:%02d:%02.09f'",tm->tm_year+1900,tm->tm_mon+1, - tm->tm_mday,tm->tm_hour,tm->tm_min,t); -} - - -time_t glite_lbu_DBToTime(const char *str) { - struct tm tm; - - memset(&tm,0,sizeof(tm)); - setenv("TZ","UTC",1); tzset(); - sscanf(str,"%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); -} - -/* ---- prepared --- */ - -int glite_lbu_PrepareStmt(glite_lbu_DBContext ctx, const char *sql, glite_lbu_Statement *stmt) { - int ret, retry; - MYSQL_RES *meta; - - // init - *stmt = calloc(1, sizeof(**stmt)); - (*stmt)->ctx = ctx; - - // create the SQL command - if (((*stmt)->stmt = db_handle.mysql_stmt_init(ctx->mysql)) == NULL) - return MY_ERRSTMT(*stmt); - - // prepare the SQL command - retry = 1; - do { - db_handle.mysql_stmt_prepare((*stmt)->stmt, sql, strlen(sql)); - ret = MY_ISOKSTMT(*stmt, &retry); - } while (ret == 0); - if (ret == -1) goto failed; - - // number of fields (0 for no results) - if ((meta = db_handle.mysql_stmt_result_metadata((*stmt)->stmt)) != NULL) { - (*stmt)->nrfields = db_handle.mysql_num_fields(meta); - db_handle.mysql_free_result(meta); - } else - (*stmt)->nrfields = 0; - - // remember the command - (*stmt)->sql = strdup(sql); - - return CLR_ERR(ctx); - -failed: - glite_lbu_FreeStmt(stmt); - return STATUS(ctx); -} - - -int glite_lbu_ExecPreparedStmt_v(glite_lbu_Statement stmt, int n, va_list ap) { - int i, prepare_retry; - glite_lbu_DBType type; - char *pchar; - int *pint; - long int *plint; - MYSQL_TIME *ptime; - glite_lbu_DBContext ctx; - int ret, retry; - MYSQL_BIND *binds = NULL; - void **data = NULL; - unsigned long *lens; - glite_lbu_Statement newstmt; - - // gather parameters - if (n) { - binds = calloc(n, sizeof(MYSQL_BIND)); - data = calloc(n, sizeof(void *)); - lens = calloc(n, sizeof(unsigned long *)); - } - for (i = 0; i < n; i++) { - type = va_arg(ap, glite_lbu_DBType); - switch (type) { - case GLITE_LBU_DB_TYPE_TINYINT: - pchar = binds[i].buffer = data[i] = malloc(sizeof(char)); - *pchar = va_arg(ap, int); - break; - - case GLITE_LBU_DB_TYPE_INT: - plint = binds[i].buffer = data[i] = malloc(sizeof(long int)); - *plint = va_arg(ap, long int); - break; - - case GLITE_LBU_DB_TYPE_BOOLEAN: - pint = binds[i].buffer = data[i] = malloc(sizeof(int)); - *pint = va_arg(ap, int) ? 1 : 0; - break; - - case GLITE_LBU_DB_TYPE_TINYBLOB: - case GLITE_LBU_DB_TYPE_TINYTEXT: - case GLITE_LBU_DB_TYPE_BLOB: - case GLITE_LBU_DB_TYPE_TEXT: - case GLITE_LBU_DB_TYPE_MEDIUMBLOB: - case GLITE_LBU_DB_TYPE_MEDIUMTEXT: - case GLITE_LBU_DB_TYPE_LONGBLOB: - case GLITE_LBU_DB_TYPE_LONGTEXT: - binds[i].buffer = va_arg(ap, void *); - binds[i].length = &lens[i]; - lens[i] = va_arg(ap, unsigned long); - break; - - case GLITE_LBU_DB_TYPE_VARCHAR: - case GLITE_LBU_DB_TYPE_CHAR: - binds[i].buffer = va_arg(ap, char *); - binds[i].length = &lens[i]; - lens[i] = binds[i].buffer ? strlen((char *)binds[i].buffer) : 0; - break; - - case GLITE_LBU_DB_TYPE_DATE: - case GLITE_LBU_DB_TYPE_TIME: - case GLITE_LBU_DB_TYPE_DATETIME: - ptime = binds[i].buffer = data[i] = malloc(sizeof(MYSQL_TIME)); - set_time(ptime, va_arg(ap, time_t)); - break; - - case GLITE_LBU_DB_TYPE_TIMESTAMP: - ptime = binds[i].buffer = data[i] = malloc(sizeof(MYSQL_TIME)); - set_time(ptime, va_arg(ap, double)); - break; - - case GLITE_LBU_DB_TYPE_NULL: - break; - - default: - assert("unimplemented parameter assign" == NULL); - break; - } - binds[i].buffer_type = glite_type_to_mysql[type]; - } - - prepare_retry = 2; - do { - // bind parameters - if (n) { - if (db_handle.mysql_stmt_bind_param(stmt->stmt, binds) != 0) { - MY_ERRSTMT(stmt); - ret = -1; - goto statement_failed; - } - } - - // run - ctx = stmt->ctx; - retry = 1; - do { - db_handle.mysql_stmt_execute(stmt->stmt); - ret = MY_ISOKSTMT(stmt, &retry); - } while (ret == 0); - statement_failed: - if (ret == -1) { - if (db_handle.mysql_stmt_errno(stmt->stmt) == ER_UNKNOWN_STMT_HANDLER) { - // expired the prepared command ==> restore it - if (glite_lbu_PrepareStmt(stmt->ctx, stmt->sql, &newstmt) == -1) goto failed; - glite_lbu_FreeStmt_int(stmt); - memcpy(stmt, newstmt, sizeof(struct glite_lbu_Statement_s)); - prepare_retry--; - ret = 0; - } else goto failed; - } - } while (ret == 0 && prepare_retry > 0); - - // result - retry = 1; - do { - db_handle.mysql_stmt_store_result(stmt->stmt); - ret = MY_ISOKSTMT(stmt, &retry); - } while (ret == 0); - if (ret == -1) goto failed; - - // free params - if (n) { - for (i = 0; i < n; i++) free(data[i]); - free(data); - free(binds); - free(lens); - } - CLR_ERR(ctx); - return db_handle.mysql_stmt_affected_rows(stmt->stmt); - -failed: - for (i = 0; i < n; i++) free(data[i]); - free(data); - free(binds); - free(lens); - return -1; -} - - -int glite_lbu_ExecPreparedStmt(glite_lbu_Statement stmt, int n, ...) { - va_list ap; - int retval; - - va_start(ap, n); - retval = glite_lbu_ExecPreparedStmt_v(stmt, n, ap); - va_end(ap); - - return retval; -} - - -int glite_lbu_bufferedInsertInit(glite_lbu_DBContext ctx, glite_lbu_bufInsert *bi, const char *table_name, long size_limit, long record_limit, const char *columns) -{ - *bi = calloc(1, sizeof(*bi)); - (*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 CLR_ERR(ctx); -} - - -static int flush_bufferd_insert(glite_lbu_bufInsert bi) -{ - char *stmt, *vals, *temp; - long i; - - - if (!bi->rec_num) - return STATUS(bi->ctx); - - 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 (glite_lbu_ExecSQL(bi->ctx,stmt,NULL) < 0) { - if (STATUS(bi->ctx) == EEXIST) - CLR_ERR(bi->ctx); - } - - /* reset bi counters */ - bi->rec_size = 0; - bi->rec_num = 0; - - free(vals); - free(stmt); - - return STATUS(bi->ctx); -} - - -int glite_lbu_bufferedInsert(glite_lbu_bufInsert bi, const 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 STATUS(bi->ctx); - } - - return CLR_ERR(bi->ctx); -} - - -static void free_buffered_insert(glite_lbu_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); -} - - -int glite_lbu_bufferedInsertClose(glite_lbu_bufInsert bi) -{ - if (flush_bufferd_insert(bi)) - return STATUS(bi->ctx); - free_buffered_insert(bi); - - return CLR_ERR(bi->ctx); -} - - -long int glite_lbu_Lastid(glite_lbu_Statement stmt) { - my_ulonglong i; - - CLR_ERR(stmt->ctx); - i = db_handle.mysql_stmt_insert_id(stmt->stmt); - assert(i < ((unsigned long int)-1) >> 1); - return (long int)i; -} - - -/* - * helping compatibility function: clear error from the context - */ -static int lbu_clrerr(glite_lbu_DBContext ctx) { - ctx->err.code = 0; - if (ctx->err.desc) { - free(ctx->err.desc); - ctx->err.desc = NULL; - } - return 0; -} - - -/* - * helping compatibility function: sets error on the context - */ -static int lbu_err(glite_lbu_DBContext ctx, int code, const char *func, int line, const char *desc, ...) { - va_list ap; - - if (code) { - ctx->err.code = code; - free(ctx->err.desc); - if (desc) { - va_start(ap, desc); - vasprintf(&ctx->err.desc, desc, ap); - va_end(ap); - } else - ctx->err.desc = NULL; - dprintf(ctx, "[db %d] %s:%d %s\n", getpid(), func, line, desc ? ctx->err.desc : ""); - return code; - } else - return ctx->err.code; -} - - -/* - * helping function: find oud mysql error and sets on the context - */ -static int myerr(glite_lbu_DBContext ctx, const char *source, int line) { - return lbu_err(ctx, EIO, source, line, db_handle.mysql_error(ctx->mysql)); -} - - -/* - * helping function: find oud mysql stmt error and sets on the context - */ -static int myerrstmt(glite_lbu_Statement stmt, const char *source, int line) { - return lbu_err(stmt->ctx, EIO, source, line, db_handle.mysql_stmt_error(stmt->stmt)); -} - - -/* - * helping function: error handle - * - * \return -1 failed - * \return 0 retry - * \return 1 OK - */ -static int myisokstmt(glite_lbu_Statement stmt, const char *source, int line, int *retry) { - switch (db_handle.mysql_stmt_errno(stmt->stmt)) { - case 0: - return 1; - break; - case ER_DUP_ENTRY: - lbu_err(stmt->ctx, EEXIST, source, line, db_handle.mysql_stmt_error(stmt->stmt)); - return -1; - break; - case CR_SERVER_LOST: - case CR_SERVER_GONE_ERROR: - if (*retry > 0) { - (*retry)--; - return 0; - } else { - myerrstmt(stmt, source, line); - return -1; - } - break; - default: - myerrstmt(stmt, source, line); - return -1; - break; - } -} - - -/* - * mysql connect - */ -static int db_connect(glite_lbu_DBContext ctx, const char *cs, MYSQL **mysql) { - char *buf = NULL; - char *host,*user,*pw,*db; - char *slash,*at,*colon; - int ret; -#if MYSQL_VERSION_ID >= 50013 - my_bool reconnect = 1; -#endif - - // needed for SQL result parameters - assert(sizeof(int) >= sizeof(my_bool)); - - if (!cs) return ERR(ctx, EINVAL, "connect string not specified"); - - if (!(*mysql = db_handle.mysql_init(NULL))) return ERR(ctx, ENOMEM, NULL); - - db_handle.mysql_options(*mysql, MYSQL_READ_DEFAULT_FILE, "my"); -#if MYSQL_VERSION_ID >= 50013 - /* XXX: may result in weird behaviour in the middle of transaction */ - db_handle.mysql_options(*mysql, MYSQL_OPT_RECONNECT, &reconnect); -#endif - - host = user = pw = db = NULL; - - buf = strdup(cs); - slash = strchr(buf,'/'); - at = strrchr(buf,'@'); - colon = strrchr(buf,':'); - - if (!slash || !at || !colon) { - free(buf); - db_close(*mysql); - *mysql = NULL; - return ERR(ctx, EINVAL, "Invalid 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 (!db_handle.mysql_real_connect(*mysql,host,user,pw,db,0,NULL,CLIENT_FOUND_ROWS)) { - char *desc; - free(buf); - ret = MY_ERR(ctx); - desc = ctx->err.desc; - ctx->err.desc = NULL; - glite_lbu_DBClose(ctx); - ctx->err.desc = desc; - return ctx->err.code = ret; - } - free(buf); - - ctx->cs = cs; - return CLR_ERR(ctx); -} - - -/* - * mysql close - */ -static void db_close(MYSQL *mysql) { - if (mysql) db_handle.mysql_close(mysql); -} - - -/* - * test transactions capability: - */ -static int transaction_test(glite_lbu_DBContext ctx) { - glite_lbu_Statement stmt; - char *table[1] = { NULL }, *res[2] = { NULL, NULL }, *cmd = NULL; - int retval; - - ctx->caps &= ~GLITE_LBU_DB_CAP_TRANSACTIONS; - - if ((retval = glite_lbu_ExecSQL(ctx, "SHOW TABLES", &stmt)) <= 0 || glite_lbu_FetchRow(stmt, 1, NULL, table) < 0) goto quit; - glite_lbu_FreeStmt(&stmt); - - trio_asprintf(&cmd, "SHOW CREATE TABLE %|Ss", table[0]); - if (glite_lbu_ExecSQL(ctx, cmd, &stmt) <= 0 || (retval = glite_lbu_FetchRow(stmt, 2, NULL, res)) < 0 ) goto quit; - if (retval != 2 || strcmp(res[0], table[0])) { - ERR(ctx, EIO, "unexpected show create result"); - goto quit; - } - - if (strstr(res[1],"ENGINE=InnoDB")) - ctx->caps |= GLITE_LBU_DB_CAP_TRANSACTIONS; - -#ifdef LBS_DB_PROFILE - fprintf(stderr, "[%d] use_transactions = %d\n", getpid(), USE_TRANS(ctx)); -#endif - -quit: - glite_lbu_FreeStmt(&stmt); - free(table[0]); - free(res[0]); - free(res[1]); - free(cmd); - return STATUS(ctx); -} - - -/* - * simple version of the fetch - */ -static int FetchRowSimple(glite_lbu_DBContext ctx, MYSQL_RES *result, unsigned long *lengths, char **results) { - MYSQL_ROW row; - unsigned int nr, i; - unsigned long *len; - - CLR_ERR(ctx); - - if (!(row = db_handle.mysql_fetch_row(result))) { - if (db_handle.mysql_errno((MYSQL *) ctx->mysql)) { - MY_ERR(ctx); - return -1; - } else return 0; - } - - nr = db_handle.mysql_num_fields(result); - len = db_handle.mysql_fetch_lengths(result); - for (i=0; inrfields) { - ERR(ctx, EINVAL, "bad number of result fields"); - return -1; - } - - // space for results - if (n) binds = calloc(n, sizeof(MYSQL_BIND)); - if (!lengths) { - lens = calloc(n, sizeof(unsigned long)); - lengths = lens; - } - for (i = 0; i < n; i++) { - binds[i].buffer_type = MYSQL_TYPE_VAR_STRING; - binds[i].buffer_length = GLITE_LBU_DEFAULT_RESULT_BUFFER_LENGTH - 1; - binds[i].length = &lengths[i]; - binds[i].buffer = results[i] = calloc(1, GLITE_LBU_DEFAULT_RESULT_BUFFER_LENGTH); - } - if (db_handle.mysql_stmt_bind_result(stmt->stmt, binds) != 0) goto failedstmt; - - // fetch data, all can be truncated - retry = 1; - do { - switch(db_handle.mysql_stmt_fetch(stmt->stmt)) { -#ifdef MYSQL_DATA_TRUNCATED - case MYSQL_DATA_TRUNCATED: -#endif - case 0: - ret = 1; break; - case 1: ret = MY_ISOKSTMT(stmt, &retry); break; - case MYSQL_NO_DATA: ret = 0; goto quit; /* it's OK */ - default: ERR(ctx, EIO, "other fetch error"); goto failed; - } - } while (ret == 0); - if (ret == -1) goto failed; - - // check if all fileds had enough buffer space - for (i = 0; i < n; i++) { - // fetch the rest if needed - if (lengths[i] > binds[i].buffer_length) { - unsigned int fetched; - - fetched = binds[i].buffer_length; - if ((results[i] = realloc(results[i], lengths[i] + 1)) == NULL) { - ERR(ctx, ENOMEM, "insufficient memory for field data"); - goto failed; - } - results[i][lengths[i]] = '\000'; - binds[i].buffer = results[i] + fetched; - binds[i].buffer_length = lengths[i] - fetched; - - retry = 1; - do { - switch (db_handle.mysql_stmt_fetch_column(stmt->stmt, binds + i, i, fetched)) { - case 0: ret = 1; break; - case 1: ret = MY_ISOKSTMT(stmt, &retry); break; - case MYSQL_NO_DATA: ret = 0; goto quit; /* it's OK */ - default: ERR(ctx, EIO, "other fetch error"); goto failed; - } - } while (ret == 0); - if (ret == -1) goto failed; - } - } - - CLR_ERR(ctx); - free(binds); - free(lens); - return n; - -failedstmt: - MY_ERRSTMT(stmt); -failed: - ret = -1; -quit: - free(binds); - free(lens); - for (i = 0; i < n; i++) { - free(results[i]); - results[i] = NULL; - } - return ret; -} - - -static void set_time(MYSQL_TIME *mtime, const double time) { - struct tm tm; - time_t itime; - - itime = time; - gmtime_r(&itime, &tm); - memset(mtime, 0, sizeof *mtime); - mtime->year = tm.tm_year + 1900; - mtime->month = tm.tm_mon + 1; - mtime->day = tm.tm_mday; - mtime->hour = tm.tm_hour; - mtime->minute = tm.tm_min; - mtime->second = tm.tm_sec; - mtime->second_part = (time - itime) * 1000; -} - - -static void glite_lbu_DBCleanup(void) { - pthread_mutex_lock(&db_handle.lock); - if (db_handle.lib) { - dlclose(db_handle.lib); - db_handle.lib = NULL; - } - pthread_mutex_unlock(&db_handle.lock); -} - - diff --git a/org.glite.lbjp-common.jp-interface/Makefile b/org.glite.lbjp-common.jp-interface/Makefile deleted file mode 100644 index 39bf384..0000000 --- a/org.glite.lbjp-common.jp-interface/Makefile +++ /dev/null @@ -1,90 +0,0 @@ -# defaults -top_srcdir=.. -builddir=build -top_builddir=${top_srcdir}/${builddir} -stagedir=. -globalprefix=glite -jpprefix=jp -package=glite-lbjp-common-jp-interface -version=0.0.0 -PREFIX=/opt/glite - -globus_prefix=/opt/globus -nothrflavour=gcc32 -thrflavour=gcc32pthr -expat_prefix=/opt/expat -gsoap_prefix=/software/gsoap-2.6 - -CC=gcc - --include Makefile.inc - - -VPATH=${top_srcdir}/src:${top_srcdir}/test:${top_srcdir}/project:${jpproject} - -DEBUG:=-g -O0 -W -Wno-sign-compare -CFLAGS:=${DEBUG} -D_GNU_SOURCE -I. -I${top_srcdir}/interface -I${stagedir}/include - -offset=0 -version_info:=-version-info ${shell \ - perl -e '$$,=":"; @F=split "\\.","${version}"; print $$F[0]+$$F[1]+${offset},$$F[2],$$F[1]' } - - -LINK:=libtool --mode=link ${CC} ${LDFLAGS} -rpath ${stagedir}/${libdir} ${version_info} -LINKXX:=libtool --mode=link ${CXX} ${LDFLAGS} -INSTALL:=libtool --mode=install install -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} - -HDRS:=types.h context.h attr.h known_attr.h backend.h builtin_plugins.h file_plugin.h indexdb.h type_plugin.h - -SRCS:=context.c attr.c utils.c indexdb.c -OBJS:=${SRCS:.c=.lo} -THROBJS:=${OBJS:.o=.thr.lo} -LIBS:=-L${stagedir}/${libdir} -lglite_jobid -lglite_lbu_db -THRLIBS:=${LIBS} - -commonlib:= libglite_jp_common_${nothrflavour}.la -commonlib_thr:= libglite_jp_common_${thrflavour}.la - -TEST_LIBS:=-L${cppunit_prefix}/${libdir} -lcppunit -ldl -TEST_INC:=-I${cppunit_prefix}/include - - -default all: compile - -compile: ${commonlib} ${commonlib_thr} - -${commonlib}: ${OBJS} - ${LINK} -o $@ ${OBJS} ${LIBS} - -${commonlib_thr}: ${THROBJS} - ${LINK} -o $@ ${THROBJS} ${THRLIBS} - -check: type_test - ./type_test type_test.xml - -type_test: %: %.cpp compile - ${CXX} -c ${CFLAGS} ${TEST_INC} $< - ${LINKXX} -o $@ $@.o ${commonlib} ${TEST_LIBS} - -doc: - -stage: compile - $(MAKE) install PREFIX=${stagedir} - -install: - -mkdir -p ${PREFIX}/include/${globalprefix}/${jpprefix} - cd ${top_srcdir}/interface && install -m 644 ${HDRS} ${PREFIX}/include/${globalprefix}/${jpprefix} - -mkdir -p ${PREFIX}/${libdir} - ${INSTALL} -m 755 ${commonlib} ${commonlib_thr} ${PREFIX}/${libdir} - -clean: - rm -rvf *.o *.lo .libs lib* - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - rm -f glite jp - -%.thr.lo: %.c - ${COMPILE} -o $@ -c $< - -%.lo: %.c - ${COMPILE} -o $@ -c $< diff --git a/org.glite.lbjp-common.jp-interface/build.xml b/org.glite.lbjp-common.jp-interface/build.xml deleted file mode 100755 index 32dd0b9..0000000 --- a/org.glite.lbjp-common.jp-interface/build.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.lbjp-common.jp-interface/configure b/org.glite.lbjp-common.jp-interface/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lbjp-common.jp-interface/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lbjp-common.jp-interface/interface/attr.h b/org.glite.lbjp-common.jp-interface/interface/attr.h deleted file mode 100644 index b8c559f..0000000 --- a/org.glite.lbjp-common.jp-interface/interface/attr.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef GLITE_JP_ATTR_H -#define GLITE_JP_ATTR_H - -#ifdef __cplusplus -extern "C" { -#endif - -void glite_jp_attrval_free(glite_jp_attrval_t *,int); -void glite_jp_attrval_copy(glite_jp_attrval_t *,const glite_jp_attrval_t *); - -/* Search through registered type plugins and call appropriate plugin method. - * See type_plugin.h for detailed description. - */ - -int glite_jp_attrval_cmp(glite_jp_context_t ctx,const glite_jp_attrval_t *a,const glite_jp_attrval_t *b,int *result); - -char *glite_jp_attrval_to_db_full(glite_jp_context_t ctx,const glite_jp_attrval_t *attr); -char *glite_jp_attrval_to_db_index(glite_jp_context_t ctx,const glite_jp_attrval_t *attr,int len); - -int glite_jp_attrval_from_db(glite_jp_context_t ctx,const char *str,glite_jp_attrval_t *attr); -const char *glite_jp_attrval_db_type_full(glite_jp_context_t ctx,const char *attr); -const char *glite_jp_attrval_db_type_index(glite_jp_context_t ctx,const char *attr,int len); - -time_t glite_jp_attr2time(const char *); -char * glite_jp_time2attr(time_t); - -#ifdef __cplusplus -}; -#endif - - -#endif /* GLITE_JP_ATTR_H */ diff --git a/org.glite.lbjp-common.jp-interface/interface/backend.h b/org.glite.lbjp-common.jp-interface/interface/backend.h deleted file mode 100644 index 3c8c1da..0000000 --- a/org.glite.lbjp-common.jp-interface/interface/backend.h +++ /dev/null @@ -1,114 +0,0 @@ -#ifndef GLITE_JP_BACKEND_H -#define GLITE_JP_BACKEND_H - -/* do we need it? -#include -#include -#include -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -int glite_jppsbe_get_names( - glite_jp_context_t ctx, - const char *job, - const char * /* class */, - char ***names_out -); - -int glite_jppsbe_destination_info( - glite_jp_context_t ctx, - const char *destination, - char **job_out, - char **class_out, - char **name_out -); - -int glite_jppsbe_get_job_url( - glite_jp_context_t ctx, - const char *job, - const char * /* class */, - const char *name, /* optional within class */ - char **url_out -); - -int glite_jppsbe_open_file( - glite_jp_context_t ctx, - const char *job, - const char * /* class */, - const char *name, /* optional within class */ - int mode, - void **handle_out -); - -int glite_jppsbe_close_file( - glite_jp_context_t ctx, - void *handle -); - -int glite_jppsbe_file_attrs( - glite_jp_context_t ctx, - void *handle, - struct stat *buf -); - -int glite_jppsbe_pread( - glite_jp_context_t ctx, - void *handle, - void *buf, - size_t nbytes, - off_t offset, - ssize_t *nbytes_ret -); - -int glite_jppsbe_pwrite( - glite_jp_context_t ctx, - void *handle, - void *buf, - size_t nbytes, - off_t offset -); - -int glite_jppsbe_append( - glite_jp_context_t ctx, - void *handle, - void *buf, - size_t nbytes -); - -int glite_jppsbe_is_metadata( - glite_jp_context_t ctx, - const char *attr -); - -int glite_jppsbe_get_job_metadata( - glite_jp_context_t ctx, - const char *job, - glite_jp_attrval_t attrs_inout[] -); - -int glite_jppsbe_query( - glite_jp_context_t ctx, - const glite_jp_query_rec_t query[], - char *attrs[], - void *arg, - int (*callback)( - glite_jp_context_t ctx, - const char *job, - const glite_jp_attrval_t metadata[], - void *arg - ) -); - -char* glite_jpps_get_namespace( - const char* attr -); - -#ifdef __cplusplus -}; -#endif - -#endif /* GLITE_JP_BACKEND_H */ - diff --git a/org.glite.lbjp-common.jp-interface/interface/builtin_plugins.h b/org.glite.lbjp-common.jp-interface/interface/builtin_plugins.h deleted file mode 100644 index 70d900b..0000000 --- a/org.glite.lbjp-common.jp-interface/interface/builtin_plugins.h +++ /dev/null @@ -1,8 +0,0 @@ - -#define GLITE_JP_FILETYPE_TAGS "urn:org.glite.jp.primary:tags" -#define GLITE_JP_FILETYPE_LB "urn:org.glite.jp.primary:lb" -#define GLITE_JP_FILETYPE_CLASSAD "urn:org.glite.jp.primary:classad" -#define GLITE_JP_FILETYPE_ISB "urn:org.glite.jp.primary:isb" -#define GLITE_JP_FILETYPE_OSB "urn:org.glite.jp.primary:osb" - -#define GLITE_JP_FPLUG_TAGS_APPEND 0 diff --git a/org.glite.lbjp-common.jp-interface/interface/context.h b/org.glite.lbjp-common.jp-interface/interface/context.h deleted file mode 100644 index 4203f56..0000000 --- a/org.glite.lbjp-common.jp-interface/interface/context.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef GLITE_JP_CONTEXT_H -#define GLITE_JP_CONTEXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -int glite_jp_init_context(glite_jp_context_t *); -void glite_jp_free_context(glite_jp_context_t); -void glite_jp_free_query_rec(glite_jp_query_rec_t *); - -char *glite_jp_peer_name(glite_jp_context_t); -char *glite_jp_error_chain(glite_jp_context_t); - -int glite_jp_stack_error(glite_jp_context_t, const glite_jp_error_t *); -int glite_jp_clear_error(glite_jp_context_t); - -int glite_jp_add_deferred(glite_jp_context_t,int (*)(glite_jp_context_t,void *),void *); -int glite_jp_run_deferred(glite_jp_context_t); - - -#ifdef __cplusplus -}; -#endif - -#endif /* GLITE_JP_CONTEXT_H */ diff --git a/org.glite.lbjp-common.jp-interface/interface/file_plugin.h b/org.glite.lbjp-common.jp-interface/interface/file_plugin.h deleted file mode 100644 index eea7d05..0000000 --- a/org.glite.lbjp-common.jp-interface/interface/file_plugin.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef GLITE_JP_FILEPLUGIN_H -#define GLITE_JP_FILEPLUGIN_H - -/** Methods of the file plugin. */ - -typedef struct _glite_jpps_fplug_op_t { - -/** Open a file. -\param[in] fpctx Context of the plugin, returned by its init. -\param[in] bhandle Handle of the file via JPPS backend. -\param[in] uri URI (type) of the opened file. -\param[out] handle Handle to the opened file structure, to be passed to other plugin functions. -*/ - int (*open)(void *fpctx,void *bhandle,const char *uri,void **handle); -/** Open from a string. -\param[in] fpctx Context of the plugin, returned by its init. -\param[in] str The string to use. -\param[in] uri URI (type) of the string -\param[in] ns namespace to handle -\param[out] handle Handle to the opened file structure, to be passed to other plugin functions. -*/ - - int (*open_str)(void *fpctx,const char *str,const char *uri,const char *ns,void **handle); - -/** Close the file. Free data associated to a handle */ - int (*close)(void *fpctx,void *handle); - -/** "Preprocess" the file -- this function is called once after the file is commited */ - int (*filecom)(void *fpctx,void *handle); - -/** Retrieve value(s) of an attribute. -\param[in] fpctx Plugin context. -\param[in] handle Handle of the opened file. -\param[in] ns Namespace of queried attribute. -\param[in] attr Queried attribute. -\param[out] attrval GLITE_JP_ATTR_UNDEF-terminated list of value(s) of the attribute. - If there are more and there is an interpretation of their order - they must be sorted, eg. current value of tag is the last one. -\retval 0 success -\retval ENOSYS this attribute is not defined by this type of file -\retval ENOENT no value is present -*/ - int (*attr)(void *fpctx,void *handle, const char *attr,glite_jp_attrval_t **attrval); - -/** File type specific operation. -\param[in] fpctx Plugin context. -\param[in] handle Handle of the opened file. -\param[in] oper Code of the operation, specific for a concrete plugin. -*/ - int (*generic)(void *fpctx,void *handle,int oper,...); - -} glite_jpps_fplug_op_t; - -/** Data describing a plugin. */ -typedef struct _glite_jpps_fplug_data_t { - void *fpctx; /**< Context passed to plugin operations. */ - char **uris; /**< NULL-terminated list of file types (URIs) - handled by the plugin. */ - char **classes; /**< The same as uris but filesystem-friendly - (can be used to construct file names).*/ - char **namespaces; /**< Which attribute namespaces this plugin handles. */ - - glite_jpps_fplug_op_t ops; /**< Plugin operations. */ -} glite_jpps_fplug_data_t; - -/** Initialisation function of the plugin. - Called after dlopen(), must be named "init". -\param[in] ctx JPPS context -\param[out] data filled-in plugin data -*/ - -typedef int (*glite_jpps_fplug_init_t)( - glite_jp_context_t ctx, - glite_jpps_fplug_data_t *plugin_data -); - - - - -/* XXX: not really public interface follows */ - -int glite_jpps_fplug_load(glite_jp_context_t ctx,int argc,char **argv); -int glite_jpps_fplug_lookup(glite_jp_context_t ctx,const char *uri, glite_jpps_fplug_data_t ***plugin_data); -int glite_jpps_fplug_lookup_byclass(glite_jp_context_t, const char *class,glite_jpps_fplug_data_t ***plugin_data); - -#endif /* GLITE_JP_FILEPLUGIN_H */ diff --git a/org.glite.lbjp-common.jp-interface/interface/indexdb.h b/org.glite.lbjp-common.jp-interface/interface/indexdb.h deleted file mode 100644 index 7130d73..0000000 --- a/org.glite.lbjp-common.jp-interface/interface/indexdb.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef GLITE_JP_INDEXDB_H -#define GLITE_JP_INDEXDB_H - -/** - * \file indexdb.h - * \brief Helper functions for accessing Job Provenance Index Server database. - */ - -#include "glite/lbu/db.h" - -#ifdef __cplusplus -extern "C" { -#endif - - -#ifdef GLITE_JP_INDEX_COMPILE - -/** - * For generating table names. - */ -#define GLITE_JP_INDEXDB_TABLE_ATTR_PREFIX "attr_" - -#endif - - -/** - * Returns internal id from attribute name. - * - * The attribute id is used in some places in the database schema. Because of the future possible changes in the schema, you should rather use other functions to get SQL commands (table names and where conditions). - * - * \param[in] name attribute name - * \return attribute id string - */ -char *glite_jp_indexdb_attr2id(const char *name); - -/** - * Get parts of the SQL SELECT command to the given attribute: - * - * SELECT column, full_value_column FROM table WHERE where; - * - * This is quick version requiring additional information about indexing of the attribute. - */ -int glite_jp_indexdb_attr2select_from_index(const char *name, int indexed, char **column, char **full_value_column, char **table, char **where); - -/** - * Get parts of the SQL SELECT command to the given attribute: - * - * SELECT column, full_value_column FROM table WHERE where; - * - * This is the most portable way - it will peep to the DB for information about indexing. - */ -int glite_jp_indexdb_attr2select_from_db(const char *name, glite_lbu_DBContext dbctx, char **column, char **full_value_column, char **table, char **where); - -#ifdef __cplusplus -}; -#endif - - -#endif /* GLITE_JP_INDEXDB_H */ diff --git a/org.glite.lbjp-common.jp-interface/interface/known_attr.h b/org.glite.lbjp-common.jp-interface/interface/known_attr.h deleted file mode 100644 index 8876831..0000000 --- a/org.glite.lbjp-common.jp-interface/interface/known_attr.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef GLITE_JP_KNOWN_ATTR_H -#define GLITE_JP_KNOWN_ATTR_H - -/** Namespace of JP system attributes */ -#define GLITE_JP_SYSTEM_NS "http://egee.cesnet.cz/en/Schema/JP/System" -#define GLITE_JP_WORKFLOW_NS "http://egee.cesnet.cz/en/Schema/JP/Workflow" - -/** Job owner, as specified with RegisterJob JPPS operation */ -#define GLITE_JP_ATTR_OWNER GLITE_JP_SYSTEM_NS ":owner" - -/** JobId */ -#define GLITE_JP_ATTR_JOBID GLITE_JP_SYSTEM_NS ":jobId" - -/** Timestamp of job registration in JP. - * Should be almost the same time as registration with LB. */ -#define GLITE_JP_ATTR_REGTIME GLITE_JP_SYSTEM_NS ":regtime" - -/** Workflow node relationships. */ -#define GLITE_JP_ATTR_WF_ANCESTOR GLITE_JP_WORKFLOW_NS ":ancestor" -#define GLITE_JP_ATTR_WF_SUCCESSOR GLITE_JP_WORKFLOW_NS ":successor" - -/** Attributes derived from LB system data - * \see jp_job_attrs.h */ - -/** Namespace for LB user tags, schemaless, all values are strings */ -#define GLITE_JP_LBTAG_NS "http://egee.cesnet.cz/en/WSDL/jp-lbtag" -#define GLITE_JP_JDL_NS "http://jdl" - -/** Namespace for Sandboxes */ -#define GLITE_JP_ISB_NS "http://egee.cesnet.cz/en/Schema/JP/ISB" -#define GLITE_JP_OSB_NS "http://egee.cesnet.cz/en/Schema/JP/OSB" - -/** Namespace for file names listed from tar */ -#define GLITE_JP_ATTR_ISB_FILENAME GLITE_JP_ISB_NS ":filename" -#define GLITE_JP_ATTR_OSB_FILENAME GLITE_JP_OSB_NS ":filename" - -/** Namespace for filenames to be unpacked from sanbox tar */ -#define GLITE_JP_ISB_CONTENT_NS GLITE_JP_ISB_NS ":content" -#define GLITE_JP_OSB_CONTENT_NS GLITE_JP_OSB_NS ":content" - -#endif /* GLITE_JP_KNOWN_ATTR_H */ diff --git a/org.glite.lbjp-common.jp-interface/interface/type_plugin.h b/org.glite.lbjp-common.jp-interface/interface/type_plugin.h deleted file mode 100644 index d3fffd2..0000000 --- a/org.glite.lbjp-common.jp-interface/interface/type_plugin.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef GLITE_JP_TYPEPLUGIN_H -#define GLITE_JP_TYPEPLUGIN_H - -typedef struct _glite_jp_tplug_data_t { - - char *namespace; - void *pctx; - -/** Compare attribute values. - * \param[in] a value to compare - * \param[in] b value to compare - * \param[out] result like strcmp() - * \param[out] err set if the values cannot be compared - * \retval 0 OK - * \retval other error - */ - int (*cmp)( - void *ctx, - const glite_jp_attrval_t *a, - const glite_jp_attrval_t *b, - int *result); - -/** Convert to database string representation. - * It is guaranteed the returned value can be converted back with - * from_db(). - * The resulting value may not be suitable for indexing with db engine. - * - * \param[in] attr the attribute value to convert - * \retval NULL can't be converted - * \retval other the string representation. - * */ - char * (*to_db_full)(void *ctx,const glite_jp_attrval_t *attr); - -/** Convert to a database string representation suitable for indexing. - * The function is non-decreasing (wrt. cmp() above and strcmp()), however it - * is not guaranteed to be one-to-one. - * - * \param[in] attr the value to convert - * \param[in] len maximum length of the converted value. - * \retval NULL can't be converted - * \retval other the string representation - */ - char * (*to_db_index)(void *ctx,const glite_jp_attrval_t *attr,int len); - -/** Convert from the database format. - * \param[in] str the string value - * \param[inout] attr name contains the name of the attribute to be converted - * the rest of attr is filled in. - */ - int (*from_db)(void *ctx,const char *str,glite_jp_attrval_t *attr); - -/** Query for database types suitable to store values returned by - * to_db_full() and to_db_index(). - * Useful for db column dynamic creation etc. - * Return pointer to internal static data, non-reentrant. - */ - const char * (*db_type_full)(void *ctx,const char *attr); - const char * (*db_type_index)(void *ctx,const char *attr,int len); - -} glite_jp_tplug_data_t; - -/** Plugin init function. - Must be called init, supposed to be called as many times as required - for different param's (e.g. xsd files). - Registers the plugin in ctx. - */ - -typedef int (*glite_jp_tplug_init_t)( - glite_jp_context_t ctx, - const char *param, - glite_jp_tplug_data_t *plugin_data -); - -#endif /* GLITE_JP_TYPEPLUGIN_H */ diff --git a/org.glite.lbjp-common.jp-interface/interface/types.h b/org.glite.lbjp-common.jp-interface/interface/types.h deleted file mode 100644 index 8aaaaae..0000000 --- a/org.glite.lbjp-common.jp-interface/interface/types.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef GLITE_JP_TYPES_H -#define GLITE_JP_TYPES_H - -#include - -typedef struct _glite_jp_error_t { - int code; - const char *desc; - const char *source; - struct _glite_jp_error_t *reason; -} glite_jp_error_t; - -typedef struct _glite_jp_context { - glite_jp_error_t *error; - int (**deferred_func)(struct _glite_jp_context *,void *); - void **deferred_arg; - void *feeds; - struct soap *other_soap; - char *peer; - void **plugins; - void **type_plugins; - void *dbhandle; - char **trusted_peers; - char *myURL; - int noauth; -} *glite_jp_context_t; - -typedef enum { - GLITE_JP_ATTR_ORIG_ANY, /**< for queries: don't care about origin */ - GLITE_JP_ATTR_ORIG_SYSTEM, /**< JP internal, e.g. job owner */ - GLITE_JP_ATTR_ORIG_USER, /**< inserted by user explicitely */ - GLITE_JP_ATTR_ORIG_FILE /**< coming from uploaded file */ -} glite_jp_attr_orig_t; - -typedef struct { - char *name; /**< including namespace */ - char *value; - int binary; /**< value is binary */ - size_t size; /**< in case of binary value */ - glite_jp_attr_orig_t origin; - char *origin_detail; /**< where it came from, i.e. file URI:name */ - time_t timestamp; -} glite_jp_attrval_t; - - -typedef enum { - GLITE_JP_QUERYOP_UNDEF, - GLITE_JP_QUERYOP_EQUAL, - GLITE_JP_QUERYOP_UNEQUAL, - GLITE_JP_QUERYOP_LESS, - GLITE_JP_QUERYOP_GREATER, - GLITE_JP_QUERYOP_WITHIN, - GLITE_JP_QUERYOP_EXISTS, - GLITE_JP_QUERYOP__LAST, -} glite_jp_queryop_t; - -typedef struct { - char *attr; - glite_jp_queryop_t op; - char *value, *value2; - int binary; - size_t size,size2; - glite_jp_attr_orig_t origin; -} glite_jp_query_rec_t; - -#endif /* GLITE_JP_TYPES_H */ diff --git a/org.glite.lbjp-common.jp-interface/project/ChangeLog b/org.glite.lbjp-common.jp-interface/project/ChangeLog deleted file mode 100644 index e9afcec..0000000 --- a/org.glite.lbjp-common.jp-interface/project/ChangeLog +++ /dev/null @@ -1,20 +0,0 @@ -1.0.0-1 -- initial release (copy of original jp.common) - -1.0.0-2 -- added required dependence on jobid.api-c - -1.0.0-3 -- fixed reference to cppunit - -1.0.0-4 -- configure script update (globus flavors added to configure call) - -1.0.0-5 -- configure script update - -1.0.0-6 -- Module repacked. - -1.0.0-7 -- install libraries into $libdir diff --git a/org.glite.lbjp-common.jp-interface/project/version.properties b/org.glite.lbjp-common.jp-interface/project/version.properties deleted file mode 100644 index 191f733..0000000 --- a/org.glite.lbjp-common.jp-interface/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -#: /cvs/jra1mw/org.glite.lbjp-common.jp-interface/project/version.properties,v 1.1.1.1 2009/01/21 14:43:52 zsustr Exp $ -module.version=1.0.0 -module.age=7 diff --git a/org.glite.lbjp-common.jp-interface/src/attr.c b/org.glite.lbjp-common.jp-interface/src/attr.c deleted file mode 100644 index 1b7285c..0000000 --- a/org.glite.lbjp-common.jp-interface/src/attr.c +++ /dev/null @@ -1,291 +0,0 @@ -#include -#include -#include -#include -#include - -#include "glite/jobid/strmd5.h" -#include "types.h" -#include "attr.h" -#include "type_plugin.h" -#include "context.h" - -void glite_jp_attrval_free(glite_jp_attrval_t *a,int f) -{ - free(a->name); - free(a->value); - free(a->origin_detail); - memset(a,0,sizeof *a); - if (f) free(a); -} - -void glite_jp_attrval_copy(glite_jp_attrval_t *dst,const glite_jp_attrval_t *src) -{ - dst->name = strdup(src->name); - dst->origin = src->origin; - dst->size = src->size; - dst->timestamp = src->timestamp; - dst->origin_detail = src->origin_detail ? - strdup(src->origin_detail) : NULL; - if ((dst->binary = src->binary)) { - dst->value = malloc(src->size); - memcpy(dst->value,src->value,src->size); - } - else dst->value = strdup(src->value); -} - - -#define min(x,y) ((x) > (y) ? (y) : (x)) - -static int fb_cmp(void *ctx,const glite_jp_attrval_t *a,const glite_jp_attrval_t *b,int *result) -{ - if (a->binary != b->binary) return EINVAL; - if (a->binary) { - *result = memcmp(a->value,b->value,min(a->size,b->size)); - if (!*result && a->size != b->size) - *result = a->size > b->size ? 1 : -1; - } - else *result = strcmp(a->value,b->value); - return 0; -} - -/* XXX: depends on specific definition of glite_jp_attr_orig_t */ -static char orig_char[] = "ASUF"; - -/* XXX: don't allocate memory, don't grow more than twice */ -static int escape_colon(const char *in, char *out) -{ - int i,o; - - for (i=o=0; in[i]; i++) switch (in[i]) { - case ':': out[o++] = '\\'; out[o++] = ':'; break; - case '\\': out[o++] = '\\'; out[o++] = '\\'; break; - default: out[o++] = in[i]; break; - } - out[o] = 0; - return o; -} - -/* XXX: read until unescaped colon is found - * allocates output */ -static char * unescape_colon(const char *in,int *rd) -{ - int i,o; - char *out; - - for (i=o=0; in[i] && in[i] != ':'; i++,o++) - if (in[i] == '\\') i++; - - out = malloc(o+1); - - for (i=o=0; in[i] && in[i] != ':'; i++) - if (in[i] == '\\') out[o++] = in[++i]; - else out[o++] = in[i]; - - out[o] = 0; - *rd = i; - return out; -} - -static char * fb_to_db_full(void *ctx,const glite_jp_attrval_t *attr) -{ - - int vsize = attr->binary ? attr->size * 4/3 + 6 : strlen(attr->value)+1, - len; - - /* 4x: + \0 + ASUF + BS + %12d */ - char *db = malloc(19 + (attr->origin_detail ? 2*strlen(attr->origin_detail) : 0) + vsize); - - if (attr->origin < 0 || attr->origin > GLITE_JP_ATTR_ORIG_FILE) { - free(db); return NULL; - } - len = sprintf(db,"%c:%d:%c:",attr->binary ? 'B' : 'S', - attr->timestamp,orig_char[attr->origin]); - - if (attr->origin_detail) len += escape_colon(attr->origin_detail,db+len); - db[len++] = ':'; - - if (attr->binary) { - vsize = base64_encode(attr->value,attr->size,db+len,vsize-1); - if (vsize < 0) { free(db); return NULL; } - db[len+vsize] = 0; - } - else strcpy(db+len,attr->value); - - return db; -} - -static char * fb_to_db_index(void *ctx,const glite_jp_attrval_t *attr,int len) -{ - char *s; - -/* XXX: binary values not really handled. Though the formal semantics is not broken */ - if (attr->binary) return strdup("XXX"); - - s = strdup(attr->value); - if (len < strlen(s)) s[len] = 0; - return s; -} - -static int fb_from_db(void *ctx,const char *str,glite_jp_attrval_t *attr) -{ - int p = 2; - char *colon,*cp; - - if (str[0] != 'B' && str[0] != 'S') return EINVAL; - attr->binary = str[0] == 'B'; - cp = attr->value = strdup(str); - - colon = strchr(cp+p,':'); - if (!colon) return EINVAL; - - *colon++ = 0; - attr->timestamp = (time_t) atol(cp+p); - p = colon-cp; - - for (attr->origin = GLITE_JP_ATTR_ORIG_ANY; orig_char[attr->origin] && orig_char[attr->origin] != cp[p]; attr->origin++); - if (!orig_char[attr->origin]) return EINVAL; - - p += 2; - if (cp[p] == ':') attr->origin_detail = NULL; - else { - int r; - attr->origin_detail = unescape_colon(cp+p,&r); - p += r; - } - if (cp[p++] != ':') return EINVAL; - - if (attr->binary) { - attr->size = base64_decode(str+p,attr->value,strlen(str)); - if (attr->size < 0) return EINVAL; - } - else strcpy(attr->value,str+p); - - return 0; -} - -static const char * fb_type_full(void *ctx,const char *attr) -{ - return "mediumblob"; -} - -static const char * fb_type_index(void *ctx,const char *attr,int len) -{ - static char tbuf[100]; - sprintf(tbuf,"varchar(%d)",len); - return tbuf; -} - - - -static glite_jp_tplug_data_t fallback_plugin = { - "", - NULL, - fb_cmp, - fb_to_db_full, - fb_to_db_index, - fb_from_db, - fb_type_full, - fb_type_index, -}; - -static glite_jp_tplug_data_t *get_plugin(glite_jp_context_t ctx,const char *aname) -{ - void **cp = ctx->type_plugins; - char *colon,*ns; - - if (!cp) return &fallback_plugin; - glite_jp_clear_error(ctx); - ns = strdup(aname); - colon = strrchr(ns,':'); - if (colon) *colon = 0; else *ns = 0; - - while (*cp) { - glite_jp_tplug_data_t *p = *cp; - if (!strcmp(ns,p->namespace)) { - free(ns); - return p; - } - cp++; - } - free(ns); - return &fallback_plugin; /* XXX: is it always desirable? */ -} - -int glite_jp_attrval_cmp(glite_jp_context_t ctx,const glite_jp_attrval_t *a,const glite_jp_attrval_t *b,int *result) -{ - glite_jp_tplug_data_t *ap = get_plugin(ctx,a->name); - glite_jp_error_t err; - - memset(&err,0,sizeof err); - err.source = __FUNCTION__; - glite_jp_clear_error(ctx); - - if (strcmp(a->name,b->name)) { - err.code = EINVAL; - err.desc = "Can't compare different attributes"; - return glite_jp_stack_error(ctx,&err); - } - - return ap->cmp ? ap->cmp(ap->pctx,a,b,result) : fb_cmp(ap->pctx,a,b,result); -} - -char *glite_jp_attrval_to_db_full(glite_jp_context_t ctx,const glite_jp_attrval_t *attr) -{ - glite_jp_tplug_data_t *ap = get_plugin(ctx,attr->name); - - glite_jp_clear_error(ctx); - return ap->to_db_full ? ap->to_db_full(ap->pctx,attr) : fb_to_db_full(ap->pctx,attr); -} - -char *glite_jp_attrval_to_db_index(glite_jp_context_t ctx,const glite_jp_attrval_t *attr,int len) -{ - glite_jp_tplug_data_t *ap = get_plugin(ctx,attr->name); - - glite_jp_clear_error(ctx); - return ap->to_db_index ? ap->to_db_index(ap->pctx,attr,len) : fb_to_db_index(ap->pctx,attr,len); -} - - -int glite_jp_attrval_from_db(glite_jp_context_t ctx,const char *str,glite_jp_attrval_t *attr) -{ - glite_jp_tplug_data_t *ap = get_plugin(ctx,attr->name); - - glite_jp_clear_error(ctx); - return ap->from_db ? ap->from_db(ap->pctx,str,attr) : fb_from_db(ap->pctx,str,attr); -} - -const char *glite_jp_attrval_db_type_full(glite_jp_context_t ctx,const char *attr) -{ - glite_jp_tplug_data_t *ap = get_plugin(ctx,attr); - - glite_jp_clear_error(ctx); - return ap->db_type_full ? ap->db_type_full(ap->pctx,attr) : fb_type_full(ap->pctx,attr); -} - -const char *glite_jp_attrval_db_type_index(glite_jp_context_t ctx,const char *attr,int len) -{ - glite_jp_tplug_data_t *ap = get_plugin(ctx,attr); - - glite_jp_clear_error(ctx); - return ap->db_type_index ? ap->db_type_index(ap->pctx,attr,len) : fb_type_index(ap->pctx,attr,len); -} - -/* XXX: UNIX time, should be ISO blahblah */ -time_t glite_jp_attr2time(const char *a) -{ - long t; - - sscanf(a,"%ld",&t); - return t; -} - -/* XXX: UNIX time, should be ISO blahblah */ -char * glite_jp_time2attr(time_t t) -{ - char *r; - - asprintf(&r,"%ld",(long) t); - return r; -} - diff --git a/org.glite.lbjp-common.jp-interface/src/context.c b/org.glite.lbjp-common.jp-interface/src/context.c deleted file mode 100644 index 62bd3c7..0000000 --- a/org.glite.lbjp-common.jp-interface/src/context.c +++ /dev/null @@ -1,145 +0,0 @@ -#include -#include -#include - -#include "types.h" -#include "context.h" - -int glite_jp_init_context(glite_jp_context_t *ctx) -{ - return (*ctx = calloc(1,sizeof **ctx)) != NULL; -} - -void glite_jp_free_context(glite_jp_context_t ctx) -{ - glite_jp_clear_error(ctx); - free(ctx); -} - -char *glite_jp_peer_name(glite_jp_context_t ctx) -{ - return strdup(ctx->peer ? ctx->peer : "unknown"); -} - -char *glite_jp_error_chain(glite_jp_context_t ctx) -{ - char *ret = NULL,indent[300] = ""; - int len = 0,add; - char buf[2000]; - - glite_jp_error_t *ep = ctx->error; - - do { - add = snprintf(buf,sizeof buf,"%s%s: %s (%s)\n", - indent, - ep->source, - strerror(ep->code), - ep->desc ? ep->desc : ""); - ret = realloc(ret,len + add + 1); - strncpy(ret + len,buf,add); ret[len += add] = 0; - strcat(indent," "); - } while ((ep = ep->reason)); - - return ret; -} - -int glite_jp_stack_error(glite_jp_context_t ctx, const glite_jp_error_t *err) -{ - glite_jp_error_t *reason = ctx->error; - - ctx->error = calloc(1,sizeof *ctx->error); - ctx->error->code = err->code; - ctx->error->desc = err->desc ? strdup(err->desc) : NULL; - ctx->error->source = err->source ? strdup(err->source) : NULL; - ctx->error->reason = reason; - - return err->code; -} - -int glite_jp_clear_error(glite_jp_context_t ctx) -{ - glite_jp_error_t *e = ctx->error, *r; - - while (e) { - r = e->reason; - free((char *) e->source); - free((char *) e->desc); - free(e); - e = r; - } - ctx->error = NULL; - return 0; -} - - -void glite_jp_free_query_rec(glite_jp_query_rec_t *q) -{ - free(q->attr); - free(q->value); - free(q->value2); - memset(q,0,sizeof *q); -} - -int glite_jp_queryrec_copy(glite_jp_query_rec_t *dst, const glite_jp_query_rec_t *src) -{ - memcpy(dst,src,sizeof *src); - if (src->attr) dst->attr = strdup(src->attr); - if (src->value) dst->value = strdup(src->value); - if (src->value2) dst->value2 = strdup(src->value2); - return 0; -} - -int glite_jp_run_deferred(glite_jp_context_t ctx) -{ - int i,cnt,ret; - - if (!ctx->deferred_func) return 0; - - glite_jp_clear_error(ctx); - for (cnt=0;ctx->deferred_func[cnt];cnt++); - for (i=0; ideferred_func)(ctx,*ctx->deferred_arg))) { - glite_jp_error_t err; - char desc[100]; - - sprintf(desc,"calling func #%d, %p",i,*ctx->deferred_func); - err.code = ret; - err.desc = desc; - err.source = "glite_jp_run_deferred()"; - - glite_jp_stack_error(ctx,&err); - return ret; - } - else { - memmove(ctx->deferred_func,ctx->deferred_func+1, - (cnt-i) * sizeof *ctx->deferred_func); - memmove(ctx->deferred_arg,ctx->deferred_arg+1, - (cnt-i) * sizeof *ctx->deferred_arg); - } - } - free(ctx->deferred_func); ctx->deferred_func = NULL; - free(ctx->deferred_arg); ctx->deferred_arg = NULL; - return 0; -} - -int glite_jp_add_deferred( - glite_jp_context_t ctx, - int (*func)(glite_jp_context_t, void *), - void *arg -) -{ - int (**v)(glite_jp_context_t, void *) = ctx->deferred_func; - int i; - - for (i=0; v && v[i]; i++); - - ctx->deferred_func = realloc(ctx->deferred_func, (i+2) * sizeof *ctx->deferred_func); - ctx->deferred_func[i] = func; - ctx->deferred_func[i+1] = NULL; - - ctx->deferred_arg = realloc(ctx->deferred_arg,(i+2) * sizeof *ctx->deferred_arg); - ctx->deferred_arg[i] = arg; - ctx->deferred_arg[i+1] = NULL; - - return 0; -} diff --git a/org.glite.lbjp-common.jp-interface/src/indexdb.c b/org.glite.lbjp-common.jp-interface/src/indexdb.c deleted file mode 100644 index cc1fc77..0000000 --- a/org.glite.lbjp-common.jp-interface/src/indexdb.c +++ /dev/null @@ -1,71 +0,0 @@ -#ident "$Header:" - -#include -#include -#include -#include -#include - -#include -#include -#include - -#define GLITE_JP_INDEX_COMPILE 1 - -#include "indexdb.h" - -char *glite_jp_indexdb_attr2id(const char *name) { - size_t i, len; - char *lname, *id; - - len = strlen(name); - lname = malloc(len + 1); - for (i = 0; i < len + 1; i++) lname[i] = tolower(name[i]); - id = str2md5(lname); - free(lname); - - return id; -} - - -int glite_jp_indexdb_attr2select_from_index(const char *name, int indexed __attribute__((unused)), char **column, char **full_value_column, char **table, char **where) { - char *id; - - if (column) *column = strdup("value"); - if (full_value_column) *full_value_column = strdup("full_value"); - if (table) { - id = glite_jp_indexdb_attr2id(name); - asprintf(table, GLITE_JP_INDEXDB_TABLE_ATTR_PREFIX "%s", id); - free(id); - } - if (where) *where = strdup(""); - - return 0; -} - - -int glite_jp_indexdb_attr2select_from_db(const char *name, glite_lbu_DBContext dbctx, char **column, char **full_value_column, char **table, char **where) { - char *sql, *id; - glite_lbu_Statement stmt; - int ret; - - if (table) { - trio_asprintf(&sql, "SELECT attrid FROM attrs WHERE name='%|Ss'", name); - ret = glite_lbu_ExecSQL(dbctx, sql, &stmt); - free(sql); - switch (ret) { - case -1: return glite_lbu_DBError(dbctx, NULL, NULL); - case 1: break; - default: return EINVAL; - } - if (glite_lbu_FetchRow(stmt, 1, NULL, &id) < 0) return glite_lbu_DBError(dbctx, NULL, NULL); - asprintf(table, GLITE_JP_INDEXDB_TABLE_ATTR_PREFIX "%s", id); - free(id); - glite_lbu_FreeStmt(&stmt); - } - if (column) *column = strdup("value"); - if (full_value_column) *full_value_column = strdup("full_value"); - if (where) *where = strdup(""); - - return 0; -} diff --git a/org.glite.lbjp-common.jp-interface/src/utils.c b/org.glite.lbjp-common.jp-interface/src/utils.c deleted file mode 100644 index 0be3e8e..0000000 --- a/org.glite.lbjp-common.jp-interface/src/utils.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite/jobid/strmd5.h" -#include "types.h" -#include "context.h" -#include "known_attr.h" -#include "attr.h" - -/* -#include "feed.h" -#include "tags.h" -*/ - -#include "backend.h" - - -typedef struct _rl_buffer_t { - char *buf; - size_t pos, size; - off_t offset; -} rl_buffer_t; - -/* - * 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; -} - - -char* glite_jpps_get_namespace(const char* attr){ - char* namespace = strdup(attr); - char* colon = strrchr(namespace, ':'); - if (colon) - namespace[strrchr(namespace, ':') - namespace] = 0; - else - namespace[0] = 0; - return namespace; -} - diff --git a/org.glite.lbjp-common.jp-interface/test/type_test.cpp b/org.glite.lbjp-common.jp-interface/test/type_test.cpp deleted file mode 100644 index 33211bb..0000000 --- a/org.glite.lbjp-common.jp-interface/test/type_test.cpp +++ /dev/null @@ -1,200 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "types.h" -#include "attr.h" -#include "context.h" -#include "backend.h" - - -class TypePluginTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(TypePluginTest); - CPPUNIT_TEST(simple); - CPPUNIT_TEST(binary); - CPPUNIT_TEST(origin); - CPPUNIT_TEST(origin2); - CPPUNIT_TEST(index); - CPPUNIT_TEST_SUITE_END(); -public: - void simple(); - void binary(); - void origin(); - void origin2(); - void index(); -}; - -void TypePluginTest::simple() -{ - glite_jp_context_t ctx; - - glite_jp_attrval_t attr = { - "myattr", - "short string", - 0,0, - GLITE_JP_ATTR_ORIG_USER, - NULL, - 0 - },attr2; - - char *db; - - glite_jp_init_context(&ctx); - attr.timestamp = time(NULL); - - db = glite_jp_attrval_to_db_full(ctx,&attr); - - CPPUNIT_ASSERT_MESSAGE(std::string("glite_jp_attrval_to_db_full()"),db); - std::cerr << db << std::endl; - - glite_jp_attrval_from_db(ctx,db,&attr2); - CPPUNIT_ASSERT_MESSAGE(std::string("value"),!strcmp(attr.value,attr2.value)); - CPPUNIT_ASSERT_MESSAGE(std::string("origin"),attr.origin == attr2.origin); - CPPUNIT_ASSERT_MESSAGE(std::string("timestamp"),attr.timestamp == attr2.timestamp); -} - -void TypePluginTest::binary() -{ - glite_jp_context_t ctx; - - glite_jp_attrval_t attr = { - "myattr", - NULL, - 1,1000, - GLITE_JP_ATTR_ORIG_USER, - NULL, - 0 - },attr2; - - char *db; - - glite_jp_init_context(&ctx); - attr.timestamp = time(NULL); - attr.value = (char *) malloc(attr.size); - - db = glite_jp_attrval_to_db_full(ctx,&attr); - - CPPUNIT_ASSERT_MESSAGE(std::string("glite_jp_attrval_to_db_full()"),db); - std::cerr << db << std::endl; - - glite_jp_attrval_from_db(ctx,db,&attr2); - CPPUNIT_ASSERT_MESSAGE(std::string("size"),attr.size == attr2.size); - CPPUNIT_ASSERT_MESSAGE(std::string("value"),!memcmp(attr.value,attr2.value,attr.size)); -} - -void TypePluginTest::origin() -{ - glite_jp_context_t ctx; - - glite_jp_attrval_t attr = { - "myattr", - NULL, - 0,0, - GLITE_JP_ATTR_ORIG_USER, - NULL, - 0 - },attr2; - - char *db; - - glite_jp_init_context(&ctx); - attr.timestamp = time(NULL); - attr.value = "origin test"; - attr.origin_detail = "simple origin"; - - db = glite_jp_attrval_to_db_full(ctx,&attr); - - CPPUNIT_ASSERT_MESSAGE(std::string("glite_jp_attrval_to_db_full()"),db); - std::cerr << db << std::endl; - - glite_jp_attrval_from_db(ctx,db,&attr2); - CPPUNIT_ASSERT_MESSAGE(std::string("origin detail"),!strcmp(attr.origin_detail,attr2.origin_detail)); -} - -void TypePluginTest::origin2() -{ - glite_jp_context_t ctx; - - glite_jp_attrval_t attr = { - "myattr", - NULL, - 0,0, - GLITE_JP_ATTR_ORIG_USER, - NULL, - 0 - },attr2; - - char *db; - - glite_jp_init_context(&ctx); - attr.timestamp = time(NULL); - attr.value = "origin:test"; - attr.origin_detail = "ftp://some.server:1234/ugly \\file"; - - db = glite_jp_attrval_to_db_full(ctx,&attr); - - CPPUNIT_ASSERT_MESSAGE(std::string("glite_jp_attrval_to_db_full()"),db); - std::cerr << db << std::endl; - - glite_jp_attrval_from_db(ctx,db,&attr2); - CPPUNIT_ASSERT_MESSAGE(std::string("origin detail"),!strcmp(attr.origin_detail,attr2.origin_detail)); - CPPUNIT_ASSERT_MESSAGE(std::string("value"),!strcmp(attr.value,attr2.value)); -} - -void TypePluginTest::index() -{ - /* TODO: check monotonity */ -} - -CPPUNIT_TEST_SUITE_REGISTRATION(TypePluginTest); - - -int main (int argc,const char *argv[]) -{ - CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - - assert(argc == 2); - std::ofstream xml(argv[1]); - - CppUnit::TestResult controller; - CppUnit::TestResultCollector result; - controller.addListener( &result ); - - CppUnit::TestRunner runner; - runner.addTest(suite); - runner.run(controller); - - CppUnit::XmlOutputter xout( &result, xml ); - CppUnit::CompilerOutputter tout( &result, std::cout); - xout.write(); - tout.write(); - - return result.wasSuccessful() ? 0 : 1 ; -} - - - - -/* fake to link */ -int glite_jppsbe_pread( - glite_jp_context_t ctx, - void *handle, - void *buf, - size_t nbytes, - off_t offset, - ssize_t *nbytes_ret -) -{ - abort(); -} - - diff --git a/org.glite.lbjp-common.maildir/.cvsignore b/org.glite.lbjp-common.maildir/.cvsignore deleted file mode 100644 index 378eac2..0000000 --- a/org.glite.lbjp-common.maildir/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/org.glite.lbjp-common.maildir/Makefile b/org.glite.lbjp-common.maildir/Makefile deleted file mode 100644 index d30e78b..0000000 --- a/org.glite.lbjp-common.maildir/Makefile +++ /dev/null @@ -1,87 +0,0 @@ -# defaults -top_srcdir=.. -builddir=build -stagedir=. -distdir=. -globalprefix=glite -lbutilsprefix=lbu -package=glite-lb-utils-maildir -version=1.0.0 -PREFIX=/opt/glite -flavour=gcc32thr - -glite_location=/opt/glite -cppunit_prefix=/opt/cppunit -thrflavour=gcc32pthr -nothrflavour=gcc32 - --include Makefile.inc --include ../project/version.properties - -CC=gcc - -VPATH=${top_srcdir}/interface:${top_srcdir}/src:${top_srcdir}/examples - -DEBUG:=-g -O0 -W -Wall - -CFLAGS:= \ - ${DEBUG} \ - -DVERSION=\"${version}\" \ - -I${stagedir}/include -I${top_srcdir}/src -I. \ - -I${top_srcdir}/interface \ - ${COVERAGE_FLAGS} \ - -D_GNU_SOURCE - -LDFLAGS:=-L${stagedir}/${libdir} ${COVERAGE_FLAGS} - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/${libdir} ${LDFLAGS} -INSTALL:=libtool --mode=install install - -EXT_LIBS:= -OBJS:=maildir.o -HDRS:=maildir.h -LOBJS:=${OBJS:.o=.lo} - -default all: compile doc - -libglite_lbu_maildir.la: ${LOBJS} - ${LINK} -o $@ $< ${EXT_LIBS} - -compile: libglite_lbu_maildir.la - -check: - -echo No checks here 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 ${OBJS} | tr ' ' '\012' | sort -u`; do gcov $$i ; done - -examples: - -#doc: -# cp ${top_srcdir}/doc/*.dox . -# echo "PROJECT_NUMBER = ${version}" >> C.dox -# doxygen C.dox - -stage: compile - $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes - -install: all - -mkdir -p ${PREFIX}/${libdir} - -mkdir -p ${PREFIX}/share/doc/${package}-${version} - -mkdir -p ${PREFIX}/include/${globalprefix}/${lbutilsprefix} - ${INSTALL} -m 755 "libglite_lbu_maildir.la" "${PREFIX}/${libdir}/libglite_lbu_maildir.la"; \ - ${INSTALL} -m 644 ${top_srcdir}/interface/${HDRS} ${PREFIX}/include/${globalprefix}/${lbutilsprefix} - -clean: - rm -rvf *.o *.lo .libs lib* *.c *.h *.dox C/ CPP/ - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - -%.o %.lo: %.c - ${COMPILE} -c $< - -maildir.lo: maildir.c maildir.h - -.PHONY: default all compile check examples doc stage dist distsrc distbin install clean test_coverage diff --git a/org.glite.lbjp-common.maildir/configure b/org.glite.lbjp-common.maildir/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lbjp-common.maildir/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lbjp-common.maildir/interface/maildir.h b/org.glite.lbjp-common.maildir/interface/maildir.h deleted file mode 100644 index fbca506..0000000 --- a/org.glite.lbjp-common.maildir/interface/maildir.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef GLITE_LBU_MAILDIR_H -#define GLITE_LBU_MAILDIR_H - -/* - * Functions for reading and writing messages via - * maildir protocol. - * Used when registering job to the JP, i.e. - */ - -enum { - LBMD_TRANS_OK, - LBMD_TRANS_FAILED, - LBMD_TRANS_FAILED_RETRY, -}; - -extern char lbm_errdesc[]; - -extern int glite_lbu_MaildirInit(const char *); -extern int glite_lbu_MaildirStoreMsg(const char *, const char *, const char *); -extern int glite_lbu_MaildirRetryTransStart(const char *, time_t, time_t, char **, char **); -extern int glite_lbu_MaildirTransStart(const char *, char **, char **); -extern int glite_lbu_MaildirTransEnd(const char *, char *, int); - -#endif /* GLITE_LBU_MAILDIR_H */ diff --git a/org.glite.lbjp-common.maildir/project/ChangeLog b/org.glite.lbjp-common.maildir/project/ChangeLog deleted file mode 100644 index 08b6ad0..0000000 --- a/org.glite.lbjp-common.maildir/project/ChangeLog +++ /dev/null @@ -1,11 +0,0 @@ -1.0.0-1 -- initial version - -1.0.0-2 -- configure script update (globus flavors added to configure call) - -1.0.0-3 -- configure script update - -1.0.0-4 -- install libraries into $libdir diff --git a/org.glite.lbjp-common.maildir/project/version.properties b/org.glite.lbjp-common.maildir/project/version.properties deleted file mode 100644 index 95b4198..0000000 --- a/org.glite.lbjp-common.maildir/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# : /cvs/jra1mw/org.glite.lbjp-common.maildir/project/version.properties,v 1.1 2007/11/01 20:17:45 valtri Exp $ -module.version=1.0.0 -module.age=4 diff --git a/org.glite.lbjp-common.maildir/src/maildir.c b/org.glite.lbjp-common.maildir/src/maildir.c deleted file mode 100644 index 78c809f..0000000 --- a/org.glite.lbjp-common.maildir/src/maildir.c +++ /dev/null @@ -1,399 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "maildir.h" - -#define DEFAULT_ROOT "/tmp/lb_maildir" - -enum { - LBMD_DIR_TMP = 0, - LBMD_DIR_NEW, - LBMD_DIR_WORK, - LBMD_DIR_POST, - LBMD_DIR_UNDELIVERABLE -}; - -static const char *dirs[] = { "tmp", "new", "work", "post", "undeliverable" }; - - -#define MAX_ERR_LEN 1024 -char lbm_errdesc[MAX_ERR_LEN]; - - -static int check_mkdir(const char *dir) -{ - struct stat sbuf; - - if ( stat(dir, &sbuf) ) { - if ( errno == ENOENT ) { - if ( mkdir(dir, S_IRWXU) ) return 1; - if ( stat(dir, &sbuf) ) return 1; - } - else return 1; - } - - if (!S_ISDIR(sbuf.st_mode)) return 1; - - if (access(dir, R_OK | W_OK)) return 1; - - return 0; -} - - -int glite_lbu_MaildirInit( - const char *dir) -{ - const char *root = dir? : DEFAULT_ROOT; - char dirname[PATH_MAX]; - size_t i; - - lbm_errdesc[0] = '\0'; - if ( check_mkdir(root) ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "%s: %s\n", root, strerror(errno)); - return 1; - } - - for ( i = 0; i < sizeof(dirs)/sizeof((dirs)[0]); i++ ) { - snprintf(dirname, PATH_MAX, "%s/%s", root, dirs[i]); - if ( check_mkdir(dirname) ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "%s: %s\n", dirname, strerror(errno)); - return 1; - } - } - - return 0; -} - - -int glite_lbu_MaildirStoreMsg( - const char *root, - const char *srvname, - const char *msg) -{ - char fname[PATH_MAX], - newfname[PATH_MAX]; - int fhnd, - written, - msgsz, - ct, i; - struct timeval tv; - - - lbm_errdesc[0] = '\0'; - if ( !root ) root = DEFAULT_ROOT; - - errno = 0; - i = 0; - while ( 1 ) { - if ( ++i > 10 ) { - errno = ECANCELED; - snprintf(lbm_errdesc, MAX_ERR_LEN, "Maximum tries limit reached with unsuccessful file creation"); - return -1; - } - gettimeofday(&tv, NULL); - snprintf(fname, PATH_MAX, "%s/%s/%ld_%ld.%s", root, dirs[LBMD_DIR_TMP], tv.tv_sec, tv.tv_usec, srvname); - if ( (fhnd = open(fname, O_CREAT|O_EXCL|O_WRONLY, 00600)) < 0 ) { - if ( errno == EEXIST ) { usleep(1000); continue; } - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't create file %s", fname); - return -1; - } - break; - } - - msgsz = strlen(msg); - written = 0; - while ( written < msgsz ) { - if ( (ct = write(fhnd, msg+written, msgsz-written)) < 0 ) { - if ( errno == EINTR ) { errno = 0; continue; } - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't write into file %s", fname); - return -1; - } - written += msgsz; - } - if ( fsync(fhnd) ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't fsync file %s", fname); - return -1; - } - if ( close(fhnd) ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't close file %s", fname); - return -1; - } - snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_NEW], strrchr(fname, '/')+1); - if ( link(fname, newfname) ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't link new file %s", newfname); - return -1; - } - - return 0; -} - - -int glite_lbu_MaildirTransEnd( - const char *root, - char *fname, - int tstate) -{ - char workfname[PATH_MAX], - newfname[PATH_MAX], - origfname[PATH_MAX]; - struct stat st; - - - lbm_errdesc[0] = '\0'; - if ( !root ) root = DEFAULT_ROOT; - - snprintf(workfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_WORK], fname); - unlink(workfname); - - snprintf(origfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_TMP], fname); - if ( tstate == LBMD_TRANS_OK ) { - unlink(origfname); - return 0; - } - - if ( tstate == LBMD_TRANS_FAILED ) return 0; - - if ( stat(origfname, &st) ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't stat file '%s'", origfname); - return -1; - } - - snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_POST], fname); - if ( link(origfname, newfname) ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't link new file %s", newfname); - return -1; - } - - return 0; -} - - -int glite_lbu_MaildirRetryTransStart( - const char *root, - time_t retry, - time_t remove, - char **msg, - char **fname) -{ - static DIR *dir = NULL; - struct dirent *ent; - time_t tlimit_retry, tlimit_remove; - struct stat st; - char newfname[PATH_MAX], - oldfname[PATH_MAX], - *buf = NULL; - int fhnd, - toread, ct, - bufsz, bufuse; - - - lbm_errdesc[0] = '\0'; - if ( !root ) root = DEFAULT_ROOT; - - if ( !dir ) { - char dirname[PATH_MAX]; - snprintf(dirname, PATH_MAX, "%s/%s", root, dirs[LBMD_DIR_POST]); - if ( !(dir = opendir(dirname)) ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open directory '%s'", root); - goto err; - } - } - - tlimit_retry = time(NULL) - retry; - tlimit_remove = time(NULL) - remove; - do { - errno = 0; - if ( !(ent = readdir(dir)) ) { - if ( errno == EBADF ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read directory '%s'", root); - dir = NULL; - goto err; - } else { - closedir(dir); - dir = NULL; - return 0; - } - } - if ( ent->d_name[0] == '.' ) continue; - - snprintf(oldfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_POST], ent->d_name); - snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_WORK], ent->d_name); - - if ( stat(oldfname, &st) < 0 ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't stat file '%s'", oldfname); - goto err; - } - - /* if we cannot deliver the file for 'remove' time limit, */ - /* it is moved to undeliverable folder and forgotten */ - if ( st.st_mtime < tlimit_remove ) { - snprintf(newfname, PATH_MAX, "%s/%s/%s", - root, dirs[LBMD_DIR_UNDELIVERABLE], ent->d_name); - } - /* try to deliver file every 'retry' seconds */ - else if ( st.st_ctime > tlimit_retry ) continue; - - - if ( rename(oldfname, newfname) ) { - if ( errno == ENOENT ) { - /* maybe some other instance moved this file away... */ - continue; - } else { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't move file '%s'", oldfname); - goto err; - } - } else { - if (st.st_mtime < tlimit_remove) { - /* we have moved undeliverable file to undeliverable folder */ - /* no other action needed */ - snprintf(oldfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_TMP], ent->d_name); - unlink(oldfname); - continue; - } else { - /* we have found and moved the file to work folder */ - /* going to process it */ - break; - } - } - } while ( 1 ); - - if ( (fhnd = open(newfname, O_RDONLY)) < 0 ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open file '%s'", newfname); - goto err; - } - - bufuse = bufsz = toread = ct = 0; - do { - errno = 0; - if ( bufuse == bufsz ) { - char *tmp = realloc(buf, bufsz+BUFSIZ); - if ( !tmp ) goto err; - buf = tmp; - bufsz += BUFSIZ; - } - toread = bufsz - bufuse; - if ( (ct = read(fhnd, buf+bufuse, toread)) < 0 ) { - if ( errno == EINTR ) continue; - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read file '%s'", newfname); - goto err; - } - if ( ct == 0 ) break; - bufuse += ct; - } while ( ct == toread ); - close(fhnd); - - if ( !(*fname = strdup(ent->d_name)) ) goto err; - buf[bufuse] = 0; - *msg = buf; - return 1; - - -err: - if ( buf ) free(buf); - - return -1; -} - - -int glite_lbu_MaildirTransStart( - const char *root, - char **msg, - char **fname) -{ - static DIR *dir = NULL; - struct dirent *ent; - char newfname[PATH_MAX], - oldfname[PATH_MAX], - *buf = NULL; - int fhnd, - toread, ct, - bufsz, bufuse; - - - lbm_errdesc[0] = '\0'; - if ( !root ) root = DEFAULT_ROOT; - - if ( !dir ) { - char dirname[PATH_MAX]; - snprintf(dirname, PATH_MAX, "%s/%s", root, dirs[LBMD_DIR_NEW]); - if ( !(dir = opendir(dirname)) ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open directory '%s'", root); - goto err; - } - } - - do { - errno = 0; - if ( !(ent = readdir(dir)) ) { - if ( errno == EBADF ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read directory '%s'", root); - dir = NULL; - goto err; - } else { - closedir(dir); - dir = NULL; - return 0; - } - } - if ( ent->d_name[0] == '.' ) continue; - snprintf(newfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_WORK], ent->d_name); - snprintf(oldfname, PATH_MAX, "%s/%s/%s", root, dirs[LBMD_DIR_NEW], ent->d_name); - if ( rename(oldfname, newfname) ) { - if ( errno == ENOENT ) { - /* maybe some other instance moved this file away... */ - continue; - } else { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't move file '%s'", oldfname); - goto err; - } - } else { - /* we have found and moved the file with which we will work now */ - break; - } - } while ( 1 ); - - if ( (fhnd = open(newfname, O_RDONLY)) < 0 ) { - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't open file '%s'", newfname); - goto err; - } - - bufuse = bufsz = toread = ct = 0; - do { - errno = 0; - if ( bufuse == bufsz ) { - char *tmp = realloc(buf, bufsz+BUFSIZ); - if ( !tmp ) goto err; - buf = tmp; - bufsz += BUFSIZ; - } - toread = bufsz - bufuse; - if ( (ct = read(fhnd, buf+bufuse, toread)) < 0 ) { - if ( errno == EINTR ) continue; - snprintf(lbm_errdesc, MAX_ERR_LEN, "Can't read file '%s'", newfname); - goto err; - } - if ( ct == 0 ) break; - bufuse += ct; - } while ( ct == toread ); - close(fhnd); - - if ( !(*fname = strdup(ent->d_name)) ) goto err; - buf[bufuse] = 0; - *msg = buf; - return 1; - - -err: - if ( buf ) free(buf); - - return -1; -} diff --git a/org.glite.lbjp-common.server-bones/.cvsignore b/org.glite.lbjp-common.server-bones/.cvsignore deleted file mode 100644 index 378eac2..0000000 --- a/org.glite.lbjp-common.server-bones/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -build diff --git a/org.glite.lbjp-common.server-bones/Makefile b/org.glite.lbjp-common.server-bones/Makefile deleted file mode 100644 index 22bf1f2..0000000 --- a/org.glite.lbjp-common.server-bones/Makefile +++ /dev/null @@ -1,77 +0,0 @@ -# defaults -top_srcdir=.. -stagedir=. -globalprefix=glite -lbutilsprefix=lbu -package=glite-lb-server-bones -version=0.0.1 -PREFIX=/opt/glite - -CC=gcc - --include Makefile.inc --include ../project/version.properties - -VPATH=${top_srcdir}/src:${top_srcdir}/examples - -DEBUG:=-g -O0 -Wall -CFLAGS:= ${DEBUG} -I${top_srcdir}/interface -D_GNU_SOURCE -LDFLAGS:= - -ifdef LB_PROF - CFLAGS:= ${CFLAGS} -pg -g - LDFLAGS:= ${LDFLAGS} -pg -endif - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/${libdir} ${LDFLAGS} -INSTALL:=libtool --mode=install install - -STATICLIB:=libglite_lbu_server_bones.a -LTLIB:=libglite_lbu_server_bones.la - -OBJS:=srvbones.o -LOBJS:=${OBJS:.o=.lo} - -HDRS:=srvbones.h - -default all: compile - -compile: ${STATICLIB} ${LTLIB} example - -${STATICLIB}: ${OBJS} - ar crv $@ ${OBJS} - ranlib $@ - -${LTLIB}: ${LOBJS} - ${LINK} -o $@ ${LOBJS} - -stage: compile - $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes - -check: - -echo "No unit tests so far." - -example: srv_example cnt_example - -srv_example: srv_example.o - ${LINK} -o $@ ${LTLIB} srv_example.o - -cnt_example: cnt_example.o - ${LINK} -o $@ cnt_example.o - -doc: - -install: - mkdir -p ${PREFIX}/include/${globalprefix}/${lbutilsprefix} - mkdir -p ${PREFIX}/${libdir} - ${INSTALL} -m 644 ${LTLIB} ${PREFIX}/${libdir} - ${INSTALL} -m 644 ${STATICLIB} ${PREFIX}/${libdir} ; \ - cd ${top_srcdir}/interface && install -m 644 ${HDRS} ${PREFIX}/include/${globalprefix}/${lbutilsprefix} - -clean: - rm -rvf *.o *.lo .libs lib* srv_example cnt_example - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - -%.o: %.c - ${COMPILE} -c $< diff --git a/org.glite.lbjp-common.server-bones/configure b/org.glite.lbjp-common.server-bones/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lbjp-common.server-bones/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lbjp-common.server-bones/examples/cnt_example.c b/org.glite.lbjp-common.server-bones/examples/cnt_example.c deleted file mode 100644 index 80b6af3..0000000 --- a/org.glite.lbjp-common.server-bones/examples/cnt_example.c +++ /dev/null @@ -1,179 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef dprintf -#define dprintf(x) { if (debug) printf x; fflush(stdout); } -#endif - -#define DEF_MSG "Test message\n" -#define DEF_PORT 9999 - -static struct option opts[] = { - { "help", no_argument, NULL, 'h'}, - { "debug", no_argument, NULL, 'd'}, - { "msg", required_argument, NULL, 'm'}, - { "port", required_argument, NULL, 'p'}, - { "repeat", required_argument, NULL, 'r'}, -}; - -int debug = 0; -int port = DEF_PORT; -char *msg = NULL; - -static int writen(int fd, char *ptr, int nbytes); -static int readln(int fd, char *out); - -static void usage(char *me) -{ - fprintf(stderr, - "usage: %s [option]\n" - " -h, --help print this screen\n" - " -d, --debug prints debug messages\n" - " -m, --msg message to send\n" - " -p, --port service port\n", me); -} - - -int main(int argc, char **argv) -{ - struct sockaddr_in addr; - char buff[512], - *me; - int opt, - sock, - n; - int repeat = 1; - - me = strrchr(argv[0], '/'); - if ( me ) me++; else me = argv[0]; - while ( (opt = getopt_long(argc, argv,"p:m:hdr:", opts, NULL)) != EOF ) - { - switch ( opt ) - { - case 'm': - msg = strdup(optarg); - break; - case 'p': - port = atoi(optarg); - break; - case 'd': debug = 1; break; - case 'r': repeat = atoi(optarg); break; - case 'h': usage(me); return 0; - case '?': usage(me); return 1; - } - } - - bzero((char *) &addr, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = inet_addr("127.0.0.1"); - addr.sin_port = htons(port); - if ( (sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) - { - perror("socket"); - exit(1); - } - if ( connect(sock, (struct sockaddr *) &addr, sizeof(addr)) < 0 ) - { - perror("connect"); - exit(1); - } - n = strlen(msg? msg: DEF_MSG); - for (;repeat; repeat--) { - if ( writen(sock, msg? msg: DEF_MSG, n) != n ) - { - dprintf(("error writing message\n")); - exit(1); - } - printf("reply: "); fflush(stdout); - n = readln(sock, buff); - if ( n < 0 ) - { - perror("read() reply error"); - return 1; - } - writen(0, buff, n); - } - close(sock); - - return 0; -} - -int writen(int fd, char *ptr, int nbytes) -{ - int nleft, nwritten; - - nleft = nbytes; - dprintf(("start writing %d bytes\n", nbytes)); - while ( nleft > 0 ) - { - nwritten = write(fd, ptr, nleft); - dprintf(("written %d bytes", nwritten)); - if ( nwritten <= 0 ) - return (nwritten); - - nleft -= nwritten; - ptr += nwritten; - dprintf((" (left %d bytes)\n", nleft)); - } - - dprintf(("written %d bytes (return: %d)\n", nwritten, nbytes - nleft)); - return (nbytes - nleft); -} - -#define BUFFER_SZ 512 - -int readln(int fd, char *out) -{ - static char buffer[BUFFER_SZ]; - static char *buffer_end = buffer; - int n; - - - dprintf(("reading line\n")); - while ( 1 ) { - if ( buffer_end - buffer ) { - /* buffer contains data - */ - char *endl; - - dprintf(("nonempty buffer\n")); - if ( (endl = memchr(buffer, '\n', buffer_end-buffer)) ) { - int linesz = endl-buffer+1; - - dprintf(("using buffer data\n")); - memcpy(out, buffer, linesz); - if ( endl+1 != buffer_end ) - memmove(buffer, endl+1, buffer_end-endl-1); - buffer_end -= linesz; - return linesz; - } - } - dprintf(("reading...\n")); - n = read(fd, buffer_end, BUFFER_SZ-(buffer_end-buffer)); - if ( n < 0 ) { - if ( errno == EAGAIN ) continue; - dprintf(("reading error\n")); - return n; - } - else if ( n == 0 ) { - int ret = buffer_end-buffer; - dprintf(("end of reading - returning %d bytes\n", ret)); - memcpy(out, buffer, ret); - buffer_end = buffer; - return ret; - } - - dprintf(("read %d bytes\n", n)); - buffer_end += n; - } - - return 0; -} diff --git a/org.glite.lbjp-common.server-bones/examples/srv_example.c b/org.glite.lbjp-common.server-bones/examples/srv_example.c deleted file mode 100644 index 0a19ab4..0000000 --- a/org.glite.lbjp-common.server-bones/examples/srv_example.c +++ /dev/null @@ -1,224 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "srvbones.h" - -#ifndef dprintf -#define dprintf(x) { if (debug) printf x; fflush(stdout); } -#endif - -#define sizofa(a) (sizeof(a)/sizeof((a)[0])) - -int debug = 1; - -static int writen(int fd, char *ptr, int nbytes); -static int readln(int fd, char *out, int nbytes); - -static int new_conn(int, struct timeval *, void *); -static int reject(int); -static int disconnect(int, struct timeval *, void *); - -static int echo(int, struct timeval *, void *); -static int upper_echo(int, struct timeval *, void *); - -#define ECHO_PORT 9999 -#define UPPER_ECHO_PORT 9998 - -#define SRV_ECHO 0 -#define SRV_UPPER_ECHO 1 - -static struct glite_srvbones_service service_table[] = { - { "Echo Service", -1, new_conn, echo, reject, disconnect }, - { "Upper Echo Service", -1, new_conn, upper_echo, reject, disconnect } -}; - -int main(void) -{ - struct sockaddr_in myaddr; - - - if ( ((service_table[SRV_ECHO].conn = socket(AF_INET, SOCK_STREAM, 0)) == -1) - || ((service_table[SRV_UPPER_ECHO].conn = socket(AF_INET, SOCK_STREAM, 0)) == -1) ) - { - perror("socket"); - exit(1); - } - - bzero((char *) &myaddr, sizeof(myaddr)); - myaddr.sin_family = AF_INET; - myaddr.sin_addr.s_addr = htonl(INADDR_ANY); - myaddr.sin_port = htons(ECHO_PORT); - if ( bind(service_table[SRV_ECHO].conn, (struct sockaddr *)&myaddr, sizeof(myaddr)) == -1 ) - { - perror("bind"); - exit(1); - } - bzero((char *) &myaddr, sizeof(myaddr)); - myaddr.sin_family = AF_INET; - myaddr.sin_addr.s_addr = htonl(INADDR_ANY); - myaddr.sin_port = htons(UPPER_ECHO_PORT); - if ( bind(service_table[SRV_UPPER_ECHO].conn, (struct sockaddr *)&myaddr, sizeof(myaddr)) == -1 ) - { - perror("bind"); - exit(1); - } - - if ( listen(service_table[SRV_ECHO].conn, 10) - || listen(service_table[SRV_UPPER_ECHO].conn, 10) ) - { - perror("listen()"); - exit(1); - } - - - glite_srvbones_set_param(GLITE_SBPARAM_SLAVES_COUNT, 1); - glite_srvbones_run(NULL, service_table, sizofa(service_table), 1); - - - return 0; -} - -int upper_echo(int fd, struct timeval *to, void *data) -{ - int n, i; - char line[80]; - - n = readln(fd, line, 80); - if ( n < 0 ) - { - perror("read() message"); - return n; - } - else if ( n == 0 ) - return ENOTCONN; - - for ( i = 0; i < n; i++ ) - line[i] = toupper(line[i]); - - if ( writen(fd, line, n) != n ) - { - perror("write() message back"); - return -1; - } - - return 0; -} - -int echo(int fd, struct timeval *to, void *data) -{ - int n; - char line[80]; - - n = readln(fd, line, 80); - dprintf(("%d bytes read\n", n)); - if ( n < 0 ) - { - perror("read() message"); - return n; - } - else if ( n == 0 ) - return ENOTCONN; - - if ( writen(fd, line, n) != n ) - { - perror("write() message back"); - return -1; - } - - return 0; -} - -int new_conn(int conn, struct timeval *to, void *cdata) -{ - dprintf(("srv-bones example: new_conn handler\n")); - return 0; -} - -int reject(int conn) -{ - dprintf(("srv-bones example: reject handler\n")); - return 0; -} - -int disconnect(int conn, struct timeval *to, void *cdata) -{ - dprintf(("srv-bones example: disconnect handler\n")); - return 0; -} - -int writen(int fd, char *ptr, int nbytes) -{ - int nleft, nwritten; - - nleft = nbytes; - dprintf(("start writing %d bytes\n", nbytes)); - while ( nleft > 0 ) { - nwritten = write(fd, ptr, nleft); - dprintf(("written %d bytes", nwritten)); - if ( nwritten <= 0 ) - return (nwritten); - - nleft -= nwritten; - ptr += nwritten; - dprintf((" (left %d bytes)\n", nleft)); - } - - dprintf(("written %d bytes (return: %d)\n", nwritten, nbytes - nleft)); - return (nbytes - nleft); -} - -#define BUFFER_SZ 512 - -int readln(int fd, char *out, int nbytes) -{ - static char buffer[BUFFER_SZ]; - static char *buffer_end = buffer; - int n; - - - dprintf(("reading line\n")); - while ( 1 ) { - if ( buffer_end - buffer ) { - /* buffer contains data - */ - char *endl; - - dprintf(("nonempty buffer\n")); - if ( (endl = memchr(buffer, '\n', buffer_end-buffer)) ) { - int linesz = endl-buffer+1; - - memcpy(out, buffer, linesz); - if ( endl+1 != buffer_end ) memmove(buffer, endl+1, buffer_end-endl-1); - buffer_end -= linesz; - return linesz; - } - } - - dprintf(("reding...\n")); - n = read(fd, buffer_end, BUFFER_SZ-(buffer_end-buffer)); - if ( n < 0 ) { - if ( errno == EAGAIN ) n = 0; - else return n; - } - if ( n == 0 ) { - int ret = buffer_end-buffer; - dprintf(("end of reading - returning %d bytes\n", ret)); - memcpy(out, buffer, ret); - buffer_end = buffer; - return ret; - } - dprintf(("read %d bytes\n", n)); - - buffer_end += n; - } - - return 0; -} diff --git a/org.glite.lbjp-common.server-bones/interface/srvbones.h b/org.glite.lbjp-common.server-bones/interface/srvbones.h deleted file mode 100644 index 31ab16f..0000000 --- a/org.glite.lbjp-common.server-bones/interface/srvbones.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef __ORG_GLITE_LB_SERVER_BONES_BONES_H__ -#define __ORG_GLITE_LB_SERVER_BONES_BONES_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum _glite_srvbones_param_t { - GLITE_SBPARAM_SLAVES_COUNT, /**< number of slaves */ - GLITE_SBPARAM_SLAVE_OVERLOAD, /**< queue items per slave */ - GLITE_SBPARAM_SLAVE_CONNS_MAX, /**< commit suicide after that many connections */ - -/* NULL for timeouts means infinity */ - GLITE_SBPARAM_IDLE_TIMEOUT, /**< keep idle connection that long (timeval) */ - GLITE_SBPARAM_CONNECT_TIMEOUT, /**< timeout for establishing a connection (timeval) */ - GLITE_SBPARAM_REQUEST_TIMEOUT, /**< timeout for a single request (timeval)*/ -} glite_srvbones_param_t; - -typedef int (*slave_data_init_hnd)(void **); - -struct glite_srvbones_service { - char *id; /**< name of the service */ - int conn; /**< listening socket */ - -/** Handler called by slave on a newly established connection, - * i.e. after accept(2). - * \param[in] conn the accepted connection - * \param[inout] timeout don't consume more, update with the remaining time - * \param[inout] user_data arbitrary user data passed among the functions - */ - int (*on_new_conn_hnd)( - int conn, - struct timeval *timeout, - void *user_data - ); - - -/** Handler called by slave to serve each request. - * \param[in] conn connection to work with - * \param[inout] timeout don't consume more, update with the remaining time - * \param[inout] user_data arbitrary user data passed among the functions - * - * \retval 0 OK, connection remains open - * \retval ENOTCON terminated gracefully, bones will clean up - * \retval >0 other POSIX errno, non-fatal error - * \retval <0 fatal error, terminate slave - */ - int (*on_request_hnd)( - int conn, - struct timeval *timeout, - void *user_data - ); - -/** Handler called by master to reject connection on server overload. - * Should kick off the client quickly, not imposing aditional load - * on server or blocking long time. - */ - int (*on_reject_hnd)(int conn); - -/** Handler called by slave before closing the connection. - * Perform server-side cleanup, and terminate the connection gracefully - * if there is a way to do so (the disconnect is server-initiated). - * close(conn) is called by bones then. - * \param[in] conn connection to work with - * \param[inout] timeout don't consume more time - * \param[inout] user_data arbitrary user data passed among the functions - */ - int (*on_disconnect_hnd)( - int conn, - struct timeval *timeout, - void *user_data - ); -}; - -extern int glite_srvbones_set_param(glite_srvbones_param_t param, ...); - - -/** Main server function. - * - * \param[in] slave_data_init_hnd callback initializing user data on every slave - */ -extern int glite_srvbones_run( - slave_data_init_hnd slave_data_init, - struct glite_srvbones_service *service_table, - size_t table_sz, - int dbg); - -/** - * helper common function to daemonize server - * - * \returns 1 OK, 0 error writtten to stderr - */ -int glite_srvbones_daemonize(const char *servername, const char *custom_pidfile, const char *custom_logfile); - -#ifdef __cplusplus -} -#endif - -#endif /* __ORG_GLITE_LB_SERVER_BONES_BONES_H__ */ diff --git a/org.glite.lbjp-common.server-bones/project/ChangeLog b/org.glite.lbjp-common.server-bones/project/ChangeLog deleted file mode 100644 index 2d9aabf..0000000 --- a/org.glite.lbjp-common.server-bones/project/ChangeLog +++ /dev/null @@ -1,11 +0,0 @@ -1.0.0-2 -- initial version - -1.0.0-3 -- configure script update (globus flavors added to configure call) - -1.0.0-4 -- configure script update - -1.0.0-5 -- install libraries into $libdir diff --git a/org.glite.lbjp-common.server-bones/project/version.properties b/org.glite.lbjp-common.server-bones/project/version.properties deleted file mode 100644 index 82c4e39..0000000 --- a/org.glite.lbjp-common.server-bones/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# : /cvs/jra1mw/org.glite.lbjp-common.server-bones/project/version.properties,v 1.2 2009/01/21 10:44:34 zsustr Exp $ -module.version=1.0.0 -module.age=5 diff --git a/org.glite.lbjp-common.server-bones/src/srvbones.c b/org.glite.lbjp-common.server-bones/src/srvbones.c deleted file mode 100644 index 047e26b..0000000 --- a/org.glite.lbjp-common.server-bones/src/srvbones.c +++ /dev/null @@ -1,753 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "srvbones.h" - -/* defaults for GLITE_SBPARAM_* */ - -#define SLAVES_COUNT 5 /* default number of slaves */ -#define SLAVE_OVERLOAD 10 /* queue items per slave */ -#define SLAVE_REQS_MAX 500 /* commit suicide after that many connections */ -#define IDLE_TIMEOUT 30 /* keep idle connection that many seconds */ -#define CONNECT_TIMEOUT 5 /* timeout for establishing a connection */ -#define REQUEST_TIMEOUT 10 /* timeout for a single request */ -#define NEW_CLIENT_DURATION 10 /* how long a client is considered new, i.e. busy - connection is not closed to serve other clients */ - -#ifndef dprintf -#define dprintf(x) { if (debug) printf x; } -#endif - -#ifdef LB_PROF -extern void _start (void), etext (void); -#endif - -static int running = 0; -static int debug = 0; -static volatile int die = 0, - child_died = 0; -static unsigned long clnt_dispatched = 0, - clnt_accepted = 0; - -static struct glite_srvbones_service *services; -static int services_ct; - -static int set_slaves_ct = SLAVES_COUNT; -static int set_slave_overload = SLAVE_OVERLOAD; -static int set_slave_reqs_max = SLAVE_REQS_MAX; -static struct timeval set_idle_to = {IDLE_TIMEOUT, 0}; -static struct timeval set_connect_to = {CONNECT_TIMEOUT, 0}; -static struct timeval set_request_to = {REQUEST_TIMEOUT, 0}; - -static int dispatchit(int, int, int); -static int do_sendmsg(int, int, unsigned long, int); -static int do_recvmsg(int, int *, unsigned long *, int *); -static int check_timeout(struct timeval, struct timeval, struct timeval); -static void catchsig(int); -static void catch_chld(int sig); -static int slave(int (*)(void **), int); - -static void glite_srvbones_set_slaves_ct(int); -static void glite_srvbones_set_slave_overload(int); -static void glite_srvbones_set_slave_conns_max(int); -static void set_timeout(struct timeval *,struct timeval *); - -int glite_srvbones_set_param(glite_srvbones_param_t param, ...) -{ - va_list ap; - - if ( running ) { - dprintf(("Attempting to set srv-bones parameter on running server")); - return -1; - } - - va_start(ap, param); - switch ( param ) { - case GLITE_SBPARAM_SLAVES_COUNT: - glite_srvbones_set_slaves_ct(va_arg(ap,int)); break; - case GLITE_SBPARAM_SLAVE_OVERLOAD: - glite_srvbones_set_slave_overload(va_arg(ap,int)); break; - case GLITE_SBPARAM_SLAVE_CONNS_MAX: - glite_srvbones_set_slave_conns_max(va_arg(ap,int)); break; - case GLITE_SBPARAM_IDLE_TIMEOUT: - set_timeout(&set_idle_to,va_arg(ap,struct timeval *)); break; - case GLITE_SBPARAM_CONNECT_TIMEOUT: - set_timeout(&set_connect_to,va_arg(ap,struct timeval *)); break; - case GLITE_SBPARAM_REQUEST_TIMEOUT: - set_timeout(&set_request_to,va_arg(ap,struct timeval *)); break; - } - va_end(ap); - - return 0; -} - -int glite_srvbones_run( - slave_data_init_hnd slave_data_init, - struct glite_srvbones_service *service_table, - size_t table_sz, - int dbg) -{ - struct sigaction sa; - sigset_t sset; - int sock_slave[2], i; - int pstat; - - - assert(service_table); - assert(table_sz > 0); - - services = service_table; - services_ct = table_sz; - debug = dbg; - - setlinebuf(stdout); - setlinebuf(stderr); - dprintf(("Master pid %d\n", getpid())); - - if ( socketpair(AF_UNIX, SOCK_STREAM, 0, sock_slave) ) - { - perror("socketpair()"); - return 1; - } - - memset(&sa, 0, sizeof(sa)); assert(sa.sa_handler == NULL); - sa.sa_handler = catchsig; - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); - - sa.sa_handler = catch_chld; - sigaction(SIGCHLD, &sa, NULL); - - sa.sa_handler = SIG_IGN; - sigaction(SIGUSR1, &sa, NULL); - sigaction(SIGXFSZ, &sa, NULL); - - sigemptyset(&sset); - sigaddset(&sset, SIGCHLD); - sigaddset(&sset, SIGTERM); - sigaddset(&sset, SIGINT); - sigprocmask(SIG_BLOCK, &sset, NULL); - - for ( i = 0; i < set_slaves_ct; i++ ) - slave(slave_data_init, sock_slave[1]); - - while ( !die ) - { - fd_set fds; - int ret, mx; - - - FD_ZERO(&fds); - FD_SET(sock_slave[0], &fds); - for ( i = 0, mx = sock_slave[0]; i < services_ct; i++ ) - { - FD_SET(services[i].conn, &fds); - if ( mx < services[i].conn ) mx = services[i].conn; - } - - sigprocmask(SIG_UNBLOCK, &sset, NULL); - ret = select(mx+1, &fds, NULL, NULL, NULL); - sigprocmask(SIG_BLOCK, &sset, NULL); - - if ( ret == -1 && errno != EINTR ) - { - if ( debug ) perror("select()"); - else syslog(LOG_CRIT,"select(): %m"); - - return 1; - } - - if ( child_died ) - { - int pid; - - while ( (pid = waitpid(-1, &pstat, WNOHANG)) > 0 ) - { - if (WIFEXITED(pstat)) { - dprintf(("[master] Slave %d exited with return code %d.\n", pid, WEXITSTATUS(pstat))); - if (WEXITSTATUS(pstat)) { - syslog(LOG_ERR, "Slave %d exited with return code %d.\n", pid, WEXITSTATUS(pstat)); - } - } - if (WIFSIGNALED(pstat)) { - dprintf(("[master] Slave %d terminated with signal %d.\n", pid, WTERMSIG(pstat))); - switch (WTERMSIG(pstat)) { - case SIGINT: - case SIGTERM: - case SIGUSR1: if (die) break; - default: - syslog(LOG_ERR, "Slave %d terminated with signal %d.\n", pid, WTERMSIG(pstat)); - break; - } - } - if ( !die ) - { - int newpid = slave(slave_data_init, sock_slave[1]); - dprintf(("[master] Servus mortuus [%d] miraculo resurrexit [%d]\n", pid, newpid)); - } - } - child_died = 0; - continue; - } - - if ( die ) continue; - - - if (FD_ISSET(sock_slave[0],&fds)) { - /* slave accepted a request - */ - unsigned long a; - - if ( (recv(sock_slave[0], &a, sizeof(a), MSG_WAITALL) == sizeof(a)) - && (a <= clnt_dispatched) - && (a > clnt_accepted || clnt_accepted > clnt_dispatched) ) - clnt_accepted = a; - } - - for ( i = 0; i < services_ct; i++ ) - if ( FD_ISSET(services[i].conn, &fds) - && dispatchit(sock_slave[0], services[i].conn ,i) ) - /* Be carefull!!! - * This must break this for cykle but start the - * while (!die) master cykle from the top also - */ - break; - } - - dprintf(("[master] Terminating on signal %d\n", die)); - if (!debug) syslog(LOG_INFO, "Terminating on signal %d\n", die); - kill(0, die); - - return 0; -} - -int glite_srvbones_daemonize(const char *servername, const char *custom_pidfile, const char *custom_logfile) { - int lfd, opid; - FILE *fpid; - pid_t master; - char *pidfile, *logfile; - - if (!custom_logfile) { - asprintf(&logfile, "%s/%s.log", geteuid() == 0 ? "/var/log" : getenv("HOME"), servername); - } else { - logfile = NULL; - } - lfd = open(logfile ? logfile : custom_logfile,O_CREAT|O_TRUNC|O_WRONLY,0600); - if (lfd < 0) { - fprintf(stderr,"%s: %s: %s\n",servername,logfile,strerror(errno)); - free(logfile); - return 0; - } -// printf("logfile: %s\n", logfile ? logfile : custom_logfile); - free(logfile); - - if (daemon(0,1) == -1) { - perror("can't daemonize"); - return 0; - } - dup2(lfd,1); - dup2(lfd,2); - - if (!custom_pidfile) { - asprintf(&pidfile, "%s/%s.pid", geteuid() == 0 ? "/var/run" : getenv("HOME"), servername); - } else { - pidfile = strdup(custom_pidfile); - } -// printf("pidfile: %s\n", pidfile ? pidfile : custom_pidfile); - setpgrp(); /* needs for signalling */ - master = getpid(); - fpid = fopen(pidfile,"r"); - if ( fpid ) - { - opid = -1; - - if ( fscanf(fpid,"%d",&opid) == 1 ) - { - if ( !kill(opid,0) ) - { - fprintf(stderr,"%s: another instance running, pid = %d\n",servername,opid); - return 0; - } - else if (errno != ESRCH) { perror("kill()"); return 0; } - } - fclose(fpid); - } else if (errno != ENOENT) { perror(pidfile); free(pidfile); return 0; } - - if (((fpid = fopen(pidfile, "w")) == NULL) || - (fprintf(fpid, "%d", getpid()) <= 0) || - (fclose(fpid) != 0)) { - perror(pidfile); - free(pidfile); - return 0; - } - - free(pidfile); - return 1; -} - -static int dispatchit(int sock_slave, int sock, int sidx) -{ - struct sockaddr_in a; - unsigned char *pom; - int conn, - alen, ret; - - - alen = sizeof(a); - if ( (conn = accept(sock, (struct sockaddr *)&a, &alen)) < 0 ) - { - if (debug) - { - perror("accept()"); - return 1; - } - else - { - syslog(LOG_ERR, "accept(): %m"); - sleep(5); - return -1; - } - } - - getpeername(conn, (struct sockaddr *)&a, &alen); - pom = (char *) &a.sin_addr.s_addr; - if (a.sin_family == PF_LOCAL) { - dprintf(("[master] %s connection from local socket\n", - services[sidx].id? services[sidx].id: "")); - } - else { - dprintf(("[master] %s connection from %d.%d.%d.%d:%d\n", - services[sidx].id? services[sidx].id: "", - (int)pom[0], (int)pom[1], (int)pom[2], (int)pom[3], - ntohs(a.sin_port))); - } - - - ret = 0; - if ( ( clnt_dispatched < clnt_accepted /* wraparound */ - || clnt_dispatched - clnt_accepted < set_slaves_ct * set_slave_overload) - && !(ret = do_sendmsg(sock_slave, conn, clnt_dispatched++, sidx)) ) - { - /* all done - */ - dprintf(("[master] Dispatched %lu, last known served %lu\n", - clnt_dispatched-1, clnt_accepted)); - } - else - { - services[sidx].on_reject_hnd(conn); - dprintf(("[master] Rejected new connection due to overload\n")); - if ( !debug ) syslog(LOG_ERR, "Rejected new connection due to overload\n"); - } - - close(conn); - if (ret) - { - perror("sendmsg()"); - if ( !debug ) syslog(LOG_ERR, "sendmsg(): %m"); - } - - - return 0; -} - - -static int slave(slave_data_init_hnd data_init_hnd, int sock) -{ - sigset_t sset; - struct sigaction sa; - struct timeval client_done, - client_start, - new_client_duration = { NEW_CLIENT_DURATION, 0 }; - - void *clnt_data = NULL; - int conn = -1, - srv = -1, - req_cnt = 0, - sockflags, - h_errno, - pid, i, - first_request = 0; /* 1 -> first request from connected client expected */ - - - - if ( (pid = fork()) ) return pid; - -#ifdef LB_PROF - monstartup((u_long)&_start, (u_long)&etext); -#endif - - srandom(getpid()+time(NULL)); - - for ( i = 0; i < services_ct; i++ ) - close(services[i].conn); - - sigemptyset(&sset); - sigaddset(&sset, SIGTERM); - sigaddset(&sset, SIGINT); - sigaddset(&sset, SIGUSR1); - - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = catchsig; - sigaction(SIGUSR1, &sa, NULL); - - if ( (sockflags = fcntl(sock, F_GETFL, 0)) < 0 - || fcntl(sock, F_SETFL, sockflags | O_NONBLOCK) < 0 ) - { - dprintf(("[%d] fcntl(master_sock): %s\n", getpid(), strerror(errno))); - if ( !debug ) syslog(LOG_CRIT, "fcntl(master_sock): %m"); - exit(1); - } - - if ( data_init_hnd && data_init_hnd(&clnt_data) ) - /* - * XXX: what if the error remains and master will start new slave - * again and again? - * - * Then we are in a deep shit. - */ - exit(1); - - while ( !die && (req_cnt < set_slave_reqs_max || (conn >= 0 && first_request))) - { - fd_set fds; - int max = sock, - connflags, - newconn = -1, - newsrv = -1; - - enum { KICK_DONT = 0, KICK_IDLE, KICK_LOAD, KICK_HANDLER, KICK_COUNT } - kick_client = KICK_DONT; - - static char * kicks[] = { - "don't kick", - "idle client", - "high load", - "no request handler", - "request count limit reached", - }; - unsigned long seq; - struct timeval now,to; - - - FD_ZERO(&fds); - if ( conn < 0 || !first_request) FD_SET(sock, &fds); - if ( conn >= 0 ) FD_SET(conn, &fds); - if ( conn > sock ) max = conn; - - to = set_idle_to; - sigprocmask(SIG_UNBLOCK, &sset, NULL); - switch (select(max+1, &fds, NULL, NULL, to.tv_sec >= 0 ? &to : NULL)) - { - case -1: - if ( errno != EINTR ) - { - dprintf(("[%d] select(): %s\n", getpid(), strerror(errno))); - if ( !debug ) syslog(LOG_CRIT, "select(): %m"); - exit(1); - } - continue; - - case 0: - if ( conn < 0 ) continue; - - default: - break; - } - sigprocmask(SIG_BLOCK, &sset, NULL); - - gettimeofday(&now,NULL); - - if ( conn >= 0 && FD_ISSET(conn, &fds) ) - { - /* - * serve the request - */ - int rv; - - dprintf(("[%d] incoming request\n", getpid())); - - if ( !services[srv].on_request_hnd ) - { - kick_client = KICK_HANDLER; - } else { - req_cnt++; - first_request = 0; - to = set_request_to; - rv = services[srv].on_request_hnd(conn,to.tv_sec>=0 ? &to : NULL,clnt_data); - if ( (rv == ENOTCONN) || (rv == ECONNREFUSED) ) { - if (services[srv].on_disconnect_hnd - && (rv = services[srv].on_disconnect_hnd(conn,NULL,clnt_data))) - { - dprintf(("[%d] disconnect handler: %s, terminating\n",getpid(),strerror(rv))); - exit(1); - } - close(conn); - conn = -1; - srv = -1; - dprintf(("[%d] Connection closed\n", getpid())); - } - else if (rv > 0) { - /* non-fatal error -> close connection and contiue - * XXX: likely to leak resources but can we call on_disconnect_hnd() on error? - */ - close(conn); - conn = -1; - srv = -1; - dprintf(("[%d] %s, connection closed\n",getpid(),strerror(rv))); - continue; - } - else if ( rv < 0 ) { - /* unknown error -> clasified as FATAL -> kill slave - */ - dprintf(("[%d] %s, terminating\n",getpid(),strerror(-rv))); - exit(1); - } - else { - dprintf(("[%d] request done\n", getpid())); - gettimeofday(&client_done, NULL); - } - - if (!check_timeout(new_client_duration,client_start,now)) continue; - - } - } else { - if (conn >= 0 && check_timeout(set_idle_to, client_done, now)) - kick_client = KICK_IDLE; - } - - if ( !die && (conn < 0 || !first_request) && FD_ISSET(sock, &fds) && req_cnt < set_slave_reqs_max ) - { - /* Prefer slaves with no connection, then kick idle clients, - * active ones last. Wait less if we have serviced a request in the meantime. - * Tuned for HZ=100 timer. */ - if ( conn >= 0 ) usleep( kick_client || FD_ISSET(conn, &fds) ? 11000 : 21000); - if ( do_recvmsg(sock, &newconn, &seq, &newsrv) ) switch ( errno ) - { - case EINTR: /* XXX: signals are blocked */ - case EAGAIN: - continue; - default: dprintf(("[%d] recvmsg(): %s\n", getpid(), strerror(errno))); - if (!debug) syslog(LOG_CRIT,"recvmsg(): %m\n"); - exit(1); - } - kick_client = KICK_LOAD; - } - - if (req_cnt >= set_slave_reqs_max && !first_request) kick_client = KICK_COUNT; - - if ( kick_client && conn >= 0 ) - { - if ( services[srv].on_disconnect_hnd ) - services[srv].on_disconnect_hnd(conn, NULL, clnt_data); - close(conn); - conn = -1; - srv = -1; - dprintf(("[%d] Connection closed, %s\n", getpid(), kicks[kick_client])); - } - - if ( newconn >= 0 ) - { - int ret; - - conn = newconn; - srv = newsrv; - gettimeofday(&client_start, NULL); - - switch ( send(sock, &seq, sizeof(seq), 0) ) - { - case -1: - if (debug) perror("send()"); - else syslog(LOG_CRIT, "send(): %m\n"); - exit(1); - - case sizeof(seq): - break; - - default: dprintf(("[%d] send(): incomplete message\n", getpid())); - exit(1); - } - - req_cnt++; - dprintf(("[%d] serving %s connection %lu\n", getpid(), - services[srv].id? services[srv].id: "", seq)); - - connflags = fcntl(conn, F_GETFL, 0); - if ( fcntl(conn, F_SETFL, connflags | O_NONBLOCK) < 0 ) - { - dprintf(("[%d] can't set O_NONBLOCK mode (%s), closing.\n", getpid(), strerror(errno))); - if ( !debug ) syslog(LOG_ERR, "can't set O_NONBLOCK mode (%s), closing.\n", strerror(errno)); - close(conn); - conn = srv = -1; - continue; - } - - to = set_connect_to; - if ( services[srv].on_new_conn_hnd - && (ret = services[srv].on_new_conn_hnd(conn, to.tv_sec >= 0 ? &to : NULL, clnt_data)) ) - { - dprintf(("[%d] Connection not established, err = %d.\n", getpid(),ret)); - if ( !debug ) syslog(LOG_ERR, "Connection not established, err = %d.\n",ret); - close(conn); - conn = srv = -1; - if (ret < 0) exit(1); - continue; - } - gettimeofday(&client_done, NULL); - first_request = 1; - } - } - - if ( die ) - { - dprintf(("[%d] Terminating on signal %d\n", getpid(), die)); - if ( !debug ) syslog(LOG_INFO, "Terminating on signal %d", die); - } - - if (conn >= 0 && services[srv].on_disconnect_hnd ) - services[srv].on_disconnect_hnd(conn, NULL, clnt_data); - - dprintf(("[%d] Terminating after %d requests\n", getpid(), req_cnt)); - if ( !debug ) syslog(LOG_INFO, "Terminating after %d requests", req_cnt); - - - exit(0); -} - -static void catchsig(int sig) -{ - die = sig; -} - -static void catch_chld(int sig) -{ - child_died = 1; -} - -static int check_timeout(struct timeval timeout, struct timeval before, struct timeval after) -{ - return (timeout.tv_usec <= after.tv_usec - before.tv_usec) ? - (timeout.tv_sec <= after.tv_sec - before.tv_sec) : - (timeout.tv_sec < after.tv_sec - before.tv_sec); -} - -#define MSG_BUFSIZ 30 - -/* - * send socket sock through socket to_sock - */ -static int do_sendmsg(int to_sock, int sock, unsigned long clnt_dispatched, int srv) -{ - struct msghdr msg = {0}; - struct cmsghdr *cmsg; - struct iovec sendiov; - int myfds, /* file descriptors to pass. */ - *fdptr; - char buf[CMSG_SPACE(sizeof myfds)]; /* ancillary data buffer */ - char sendbuf[MSG_BUFSIZ]; /* to store unsigned int + \0 */ - - - memset(sendbuf, 0, sizeof(sendbuf)); - snprintf(sendbuf, sizeof(sendbuf), "%u %lu", srv, clnt_dispatched); - - msg.msg_name = NULL; - msg.msg_namelen = 0; - msg.msg_iov = &sendiov; - msg.msg_iovlen = 1; - sendiov.iov_base = sendbuf; - sendiov.iov_len = sizeof(sendbuf); - - msg.msg_control = buf; - msg.msg_controllen = sizeof buf; - - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(sizeof(int)); - fdptr = (int *)CMSG_DATA(cmsg); - *fdptr = sock; - - msg.msg_controllen = cmsg->cmsg_len; - /* send fd to server-slave to do rest of communication */ - if (sendmsg(to_sock, &msg, 0) < 0) - return 1; - - return 0; -} - - -/* receive socket sock through socket from_sock */ -static int do_recvmsg(int from_sock, int *sock, unsigned long *clnt_accepted,int *srv) -{ - struct msghdr msg = {0}; - struct cmsghdr *cmsg; - struct iovec recviov; - int myfds; /* file descriptors to pass. */ - char buf[CMSG_SPACE(sizeof(myfds))]; /* ancillary data buffer */ - char recvbuf[MSG_BUFSIZ]; - - - msg.msg_name = NULL; - msg.msg_namelen = 0; - msg.msg_iov = &recviov; - msg.msg_iovlen = 1; - recviov.iov_base = recvbuf; - recviov.iov_len = sizeof(recvbuf); - - msg.msg_control = buf; - msg.msg_controllen = sizeof buf; - - cmsg = CMSG_FIRSTHDR(&msg); - cmsg->cmsg_level = SOL_SOCKET; - cmsg->cmsg_type = SCM_RIGHTS; - cmsg->cmsg_len = CMSG_LEN(sizeof(int)); - msg.msg_controllen = cmsg->cmsg_len; - - if (recvmsg(from_sock, &msg, 0) < 0) - return 1; - - *sock = *((int *)CMSG_DATA(cmsg)); - sscanf(recvbuf, "%u %lu", srv, clnt_accepted); - - return 0; -} - -static void glite_srvbones_set_slaves_ct(int n) -{ - set_slaves_ct = (n == -1)? SLAVES_COUNT: n; -} - -static void glite_srvbones_set_slave_overload(int n) -{ - set_slave_overload = (n == -1)? SLAVE_OVERLOAD: n; -} - -static void glite_srvbones_set_slave_conns_max(int n) -{ - set_slave_reqs_max = (n == -1)? SLAVE_REQS_MAX: n; -} - -static void set_timeout(struct timeval *to, struct timeval *val) -{ - if (val) { - /* XXX: why not, negative timeouts don't make any sense, IMHO */ - assert(val->tv_sec >= 0); - *to = *val; - } - else to->tv_sec = -1; -} diff --git a/org.glite.lbjp-common.trio/.cvsignore b/org.glite.lbjp-common.trio/.cvsignore deleted file mode 100644 index c795b05..0000000 --- a/org.glite.lbjp-common.trio/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -build \ No newline at end of file diff --git a/org.glite.lbjp-common.trio/LICENSE b/org.glite.lbjp-common.trio/LICENSE deleted file mode 100644 index 01b973b..0000000 --- a/org.glite.lbjp-common.trio/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.lbjp-common.trio/Makefile b/org.glite.lbjp-common.trio/Makefile deleted file mode 100644 index af7b157..0000000 --- a/org.glite.lbjp-common.trio/Makefile +++ /dev/null @@ -1,112 +0,0 @@ -# Default values -top_srcdir=.. -builddir=build -top_builddir=${top_srcdir}/${builddir} -stagedir=. -distdir=. -globalprefix=glite -package=glite-lb-utils-trio -version=0.0.0 -PREFIX=/opt/glite -lbuprefix=lbu - --include Makefile.inc --include ../project/version.properties - -VPATH=${top_srcdir}/src:${top_srcdir}/test::${top_srcdir}/doc - -CC=gcc - -DEBUG:=-g -O0 -Wall - -CFLAGS:=${DEBUG} -I${top_srcdir}/src -I${top_srcdir}/interface -I. -DDATAGRID_EXTENSION - -COMPILE:=libtool --mode=compile ${CC} -LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/${libdir} ${LDFLAGS} -LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/${libdir} ${LDFLAGS} -INSTALL:=libtool --mode=install install - -REPORTS:=${top_srcdir}/reports -TEST_LIBS:=-L${cppunit_prefix}/lib -lcppunit -ldl -TEST_INC:=-I${cppunit_prefix}/include - - -OBJS:=trio.o strio.o escape.o -LOBJS:=${OBJS:.o=.lo} - -HDRS:=trio.h escape.h - -STATICLIB:=libglite_lbu_trio.a -LTLIB:=libglite_lbu_trio.la - -default: all - -all compile: ${STATICLIB} ${LTLIB} - -# to use libtool versioning correcty, we should have: -# -# current = major + minor + offset -# revision = patch -# age = minor -# -# where offset is a sum of maximal released minor's of all previous major's -# -# version_info=-version-info `echo ${version} | cut -d. -f1,2 | tr . :` - -# counted minors: n/a -offset=0 - -version_info:=-version-info ${shell \ - perl -e '$$,=":"; @F=split "\\.","${version}"; print $$F[0]+$$F[1]+${offset},$$F[2],$$F[1]' } - -${STATICLIB}: ${OBJS} - ar crv $@ ${OBJS} - ranlib $@ - -${LTLIB}: ${OBJS} - ${LINK} ${version_info} -o $@ ${LOBJS} -lm - -stage: compile - $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes - -check: compile mkreports runtest - -mkreports: - -mkdir ${REPORTS} - -runtest: trio_test - ./trio_test ${REPORTS}/trio.xml - -trio_test: trio_test.cpp - ${CXX} -c ${CFLAGS} ${TEST_INC} $< - ${LINKXX} -o $@ trio_test.o ${LTLIB} ${TEST_LIBS} - - -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: all - -mkdir -p ${PREFIX}/${libdir} - -mkdir -p ${PREFIX}/share/doc/${package}-${version} - -mkdir -p ${PREFIX}/include/${globalprefix}/${lbutilsprefix} - -mkdir -p ${PREFIX}/include/${globalprefix}/${lbuprefix} - ${INSTALL} -m 644 ${LTLIB} ${STATICLIB} ${PREFIX}/${libdir} - ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} - (cd ${top_srcdir}/interface && ${INSTALL} -m 644 ${HDRS} ${PREFIX}/include/${globalprefix}/${lbuprefix}) - -clean: - rm -rvf *.o *.lo .libs lib* *.c *.h *.dox C/ CPP/ - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - -%.o: %.c - ${COMPILE} ${CFLAGS} -c $< diff --git a/org.glite.lbjp-common.trio/configure b/org.glite.lbjp-common.trio/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.lbjp-common.trio/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.lbjp-common.trio/interface/escape.h b/org.glite.lbjp-common.trio/interface/escape.h deleted file mode 100644 index 4795f68..0000000 --- a/org.glite.lbjp-common.trio/interface/escape.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef __EDG_WORKLOAD_LOGGING_COMMON_ESCAPE_H__ -#define __EDG_WORKLOAD_LOGGING_COMMON_ESCAPE_H__ -/*! - * \file escape.h - */ - -#ident "$Header$" - - -/*! - * \fn char *glite_lbu_EscapeULM(const char *str) - * \param str a string to escape - * \return new (allocated) escaped string - * \brief in given string (ULM) escape all ULM_QM, ULM_BS and ULM_LF by ULM_BS - */ - -char *glite_lbu_EscapeULM(const char *); - - -/*! - * \fn char *glite_lbu_UnescapeULM(const char *str) - * \param str a string to unescape - * \return new (allocated) unescaped string - * \brief in given string (ULM) unescape all escaped ULM_QM, ULM_BS and ULM_LF - */ - -char *glite_lbu_UnescapeULM(const char *); - - -/*! - * \fn char *glite_lbu_EscapeXML(const char *str); - * \param str a string to escape - * \return new (allocated) escaped string - * \brief in given string (XML) escape all unwanted characters - */ - -char *glite_lbu_EscapeXML(const char *); - - -/*! - * \fn char *glite_lbu_UnescapeXML(const char *str) - * \param str a string to unescape - * \return new (allocated) unescaped string - * \brief in given string (XML) unescape all escaped characters - */ - -char *glite_lbu_UnescapeXML(const char *); - - -/*! - * \fn char *glite_lbu_EscapeSQL(const char *str) - * \param str a string to escape - * \return new (allocated) escaped string - * \briefin given string (SQL) escape all unwanted characters - */ - -char *glite_lbu_EscapeSQL(const char *); - -#endif /* __EDG_WORKLOAD_LOGGING_COMMON_ESCAPE_H__ */ diff --git a/org.glite.lbjp-common.trio/interface/trio.h b/org.glite.lbjp-common.trio/interface/trio.h deleted file mode 100644 index 04f133c..0000000 --- a/org.glite.lbjp-common.trio/interface/trio.h +++ /dev/null @@ -1,187 +0,0 @@ -/************************************************************************* - * - * $Id$ - * - * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND - * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. - * - ************************************************************************/ - -#ifndef TRIO_TRIO_H -#define TRIO_TRIO_H - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* make utility and C++ compiler in Windows NT fails to find this symbol */ -#if defined(WIN32) && !defined(isascii) -# define isascii ((unsigned)(x) < 0x80) -#endif - -/* - * Error codes. - * - * Remember to add a textual description to trio_strerror. - */ -enum { - TRIO_EOF = 1, - TRIO_EINVAL = 2, - TRIO_ETOOMANY = 3, - TRIO_EDBLREF = 4, - TRIO_EGAP = 5, - TRIO_ENOMEM = 6, - TRIO_ERANGE = 7 -}; - -/* Error macros */ -#define TRIO_ERROR_CODE(x) ((-(x)) & 0x00FF) -#define TRIO_ERROR_POSITION(x) ((-(x)) >> 8) -#define TRIO_ERROR_NAME(x) trio_strerror(x) - -const char *trio_strerror(int); - -/************************************************************************* - * Print Functions - */ - -int trio_printf(const char *format, ...); -int trio_vprintf(const char *format, va_list args); -int trio_printfv(const char *format, void **args); - -int trio_fprintf(FILE *file, const char *format, ...); -int trio_vfprintf(FILE *file, const char *format, va_list args); -int trio_fprintfv(FILE *file, const char *format, void **args); - -int trio_dprintf(int fd, const char *format, ...); -int trio_vdprintf(int fd, const char *format, va_list args); -int trio_dprintfv(int fd, const char *format, void **args); - -/* trio_sprintf(target, format, ...) - * trio_snprintf(target, maxsize, format, ...) - * - * Build 'target' according to 'format' and succesive - * arguments. This is equal to the sprintf() and - * snprintf() functions. - */ -int trio_sprintf(char *buffer, const char *format, ...); -int trio_vsprintf(char *buffer, const char *format, va_list args); -int trio_sprintfv(char *buffer, const char *format, void **args); - -int trio_snprintf(char *buffer, size_t max, const char *format, ...); -int trio_vsnprintf(char *buffer, size_t bufferSize, const char *format, - va_list args); -int trio_snprintfv(char *buffer, size_t bufferSize, const char *format, - void **args); - -int trio_snprintfcat(char *buffer, size_t max, const char *format, ...); -int trio_vsnprintfcat(char *buffer, size_t bufferSize, const char *format, - va_list args); - -char *trio_aprintf(const char *format, ...); -char *trio_vaprintf(const char *format, va_list args); - -int trio_asprintf(char **ret, const char *format, ...); -int trio_vasprintf(char **ret, const char *format, va_list args); - -/************************************************************************* - * Scan Functions - */ -int trio_scanf(const char *format, ...); -int trio_vscanf(const char *format, va_list args); -int trio_scanfv(const char *format, void **args); - -int trio_fscanf(FILE *file, const char *format, ...); -int trio_vfscanf(FILE *file, const char *format, va_list args); -int trio_fscanfv(FILE *file, const char *format, void **args); - -int trio_dscanf(int fd, const char *format, ...); -int trio_vdscanf(int fd, const char *format, va_list args); -int trio_dscanfv(int fd, const char *format, void **args); - -int trio_sscanf(const char *buffer, const char *format, ...); -int trio_vsscanf(const char *buffer, const char *format, va_list args); -int trio_sscanfv(const char *buffer, const char *format, void **args); - -/************************************************************************* - * Renaming - */ -#ifdef TRIO_REPLACE_STDIO -/* Replace the functions */ -#ifndef HAVE_PRINTF -# define printf trio_printf -#endif -#ifndef HAVE_VPRINTF -# define vprintf trio_vprintf -#endif -#ifndef HAVE_FPRINTF -# define fprintf trio_fprintf -#endif -#ifndef HAVE_VFPRINTF -# define vfprintf trio_vfprintf -#endif -#ifndef HAVE_SPRINTF -# define sprintf trio_sprintf -#endif -#ifndef HAVE_VSPRINTF -# define vsprintf trio_vsprintf -#endif -#ifndef HAVE_SNPRINTF -# define snprintf trio_snprintf -#endif -#ifndef HAVE_VSNPRINTF -# define vsnprintf trio_vsnprintf -#endif -#ifndef HAVE_SCANF -# define scanf trio_scanf -#endif -#ifndef HAVE_VSCANF -# define vscanf trio_vscanf -#endif -#ifndef HAVE_FSCANF -# define fscanf trio_fscanf -#endif -#ifndef HAVE_VFSCANF -# define vfscanf trio_vfscanf -#endif -#ifndef HAVE_SSCANF -# define sscanf trio_sscanf -#endif -#ifndef HAVE_VSSCANF -# define vsscanf trio_vsscanf -#endif -/* These aren't stdio functions, but we make them look similar */ -#define dprintf trio_dprintf -#define vdprintf trio_vdprintf -#define aprintf trio_aprintf -#define vaprintf trio_vaprintf -#define asprintf trio_asprintf -#define vasprintf trio_vasprintf -#define dscanf trio_dscanf -#define vdscanf trio_vdscanf -#endif - -/* strio compatible names */ -#define StrScan trio_sscanf -#define StrFormat trio_sprintf -#define StrFormatMax trio_snprintf -#define StrFormatAlloc trio_aprintf -#define StrFormatAppendMax trio_snprintfcat - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* TRIO_TRIO_H */ diff --git a/org.glite.lbjp-common.trio/project/ChangeLog b/org.glite.lbjp-common.trio/project/ChangeLog deleted file mode 100644 index dafb776..0000000 --- a/org.glite.lbjp-common.trio/project/ChangeLog +++ /dev/null @@ -1,14 +0,0 @@ -1.0.0-2 -- initial version - -1.0.0-3 -- depends on cppunit - -1.0.0-4 -- configure script update (globus flavors added to configure call) - -1.0.0-5 -- configure script update - -1.0.0-6 -- install libraries into $libdir diff --git a/org.glite.lbjp-common.trio/project/version.properties b/org.glite.lbjp-common.trio/project/version.properties deleted file mode 100644 index 49f3397..0000000 --- a/org.glite.lbjp-common.trio/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# : /cvs/jra1mw/org.glite.lbjp-common.trio/project/version.properties,v 1.2 2009/01/21 10:44:34 zsustr Exp $ -module.version=1.0.0 -module.age=6 diff --git a/org.glite.lbjp-common.trio/src/escape.c b/org.glite.lbjp-common.trio/src/escape.c deleted file mode 100644 index 493dac4..0000000 --- a/org.glite.lbjp-common.trio/src/escape.c +++ /dev/null @@ -1,226 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include - -#include "escape.h" - -#define ULM_QM '"' -#define ULM_BS '\\' -#define ULM_LF '\n' - -/* - *---------------------------------------------------------------------- - * - * \fn char *glite_lbu_EscapeULM(const char *str) - * \param str a string to escape - * \return new (allocated) escaped string (is is empty "" if str is NULL) - * \brief in given string escape all ULM_QM, ULM_BS and ULM_LF by ULM_BS - * - * Calls: malloc, strlen - * - * Algorithm: array lookup - * - the new string will be allocated - * - *---------------------------------------------------------------------- - */ - -char *glite_lbu_EscapeULM(const char *str) -{ -unsigned int i,j; -size_t size; -char *ret; - -if (str == NULL) return strdup(""); -if ((size = strlen(str)) == 0) return strdup(""); - -ret = (char*) malloc(1+2*size*sizeof(char)); - -j = 0; -for (i=0; i',"gt" }, - { '&',"amp" }, - { '"',"quot" }, - { '\'',"apos" }, - { 0, NULL } -}; - -#define XML_ESCAPE_SET "<>&\"'" - -char *glite_lbu_EscapeXML(const char *in) -{ - const char* tmp_in; - char *out; - int cnt,i,j,k; - - if (!in) return NULL; - - for (cnt = 0, tmp_in = in; *tmp_in != '\0'; ++tmp_in) { - if (strchr(XML_ESCAPE_SET, *tmp_in) || - (*tmp_in & 0x7f) < 0x20 /* control character */ || - (*tmp_in == '%')) cnt++; - } - - out = malloc(strlen(in)+1+cnt*5); - - for (i=j=0; in[i]; i++) { - for (k=0; xml_etab[k].c && xml_etab[k].c != in[i]; k++); - if (xml_etab[k].c) { - int l; - - out[j++] = '&'; - memcpy(out+j,xml_etab[k].e,l=strlen(xml_etab[k].e)); - j += l; - out[j++] = ';'; - } else if ((in[i] & 0x7f) < 0x20 || in[i] == '%') { - sprintf(out+j, "%%%02x", (unsigned char)in[i]); - j+=3; - } else { - out[j++] = in[i]; - } - } - out[j] = 0; - return out; -} - -char *glite_lbu_UnescapeXML(const char *in) -{ - char *out; - int i,j,k; - char xtmp[3]; - unsigned char origchar; - - if (!in) return NULL; - out = malloc(strlen(in)+1); - - for (i=j=0; in[i]; j++) if (in[i] == '&') { - char *s = strchr(in+i,';'); - if (s) { - int l = s-in-i+1; - for (k=0; xml_etab[k].c && strncasecmp(in+i+1,xml_etab[k].e,l-2); k++); - if (xml_etab[k].c) { - out[j] = xml_etab[k].c; - i += l; - } else out[j] = in[i++]; - } else out[j] = in[i++]; - } else if (in[i] == '%') { - if (isxdigit(xtmp[0]=in[i+1]) && isxdigit(xtmp[1]=in[i+2])) { - xtmp[2] = '\0'; - origchar = (unsigned char) strtol(xtmp, NULL, 16); - if ((origchar & 0x7f) < 0x20 || origchar == '%') { - out[j] = origchar; - i += 3; - } else out[j] = in[i++]; - } else out[j] = in[i++]; - } else { - out[j] = in[i++]; - } - out[j] = 0; - return out; -} - -char *glite_lbu_EscapeSQL(const char *in) -{ - const char* tmp_in; - char *out = NULL; - int i,j,cnt; - - if (!in) return NULL; - - for (cnt = 0, tmp_in = in; (tmp_in = strchr(tmp_in,'\'')) != NULL; ++tmp_in) { - ++cnt; - } - for (tmp_in = in; (tmp_in = strchr(tmp_in,'\\')) != NULL; ++tmp_in) { - ++cnt; - } - - out = malloc(strlen(in)+1+cnt); - - for (i=j=0; in[i]; i++) { - if (in[i] == '\\') out[j++] = '\\'; - if (in[i] == '\'') out[j++] = '\''; - out[j++] = in[i]; - } - out[j] = 0; - - return out; -} diff --git a/org.glite.lbjp-common.trio/src/strio.c b/org.glite.lbjp-common.trio/src/strio.c deleted file mode 100644 index f1ab5b8..0000000 --- a/org.glite.lbjp-common.trio/src/strio.c +++ /dev/null @@ -1,581 +0,0 @@ -/************************************************************************* - * - * $Id$ - * - * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND - * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. - * - ************************************************************************/ - -/* - * TODO - * - StrToLongDouble - */ - -static const char rcsid[] = "@(#)$Id$"; - -#if defined(unix) || defined(__xlC__) || defined(__QNX__) -# define PLATFORM_UNIX -#elif defined(WIN32) || defined(_WIN32) -# define PLATFORM_WIN32 -#elif defined(AMIGA) && defined(__GNUC__) -# define PLATFORM_UNIX -#endif - -#if defined(__STDC__) && (__STDC_VERSION__ >= 199901L) -# define TRIO_C99 -#endif - -#include "strio.h" -#include -#include -#include -#include -#include -#include -#ifndef DEBUG -# define NDEBUG -#endif -#include - -#ifndef NULL -# define NULL 0 -#endif -#define NIL ((char)0) -#ifndef FALSE -# define FALSE (1 == 0) -# define TRUE (! FALSE) -#endif - -#define VALID(x) (NULL != (x)) -#define INVALID(x) (NULL == (x)) - -#if defined(PLATFORM_UNIX) -# define USE_STRCASECMP -# define USE_STRNCASECMP -# define USE_STRERROR -# if defined(__QNX__) -# define strcasecmp(x,y) stricmp(x,y) -# define strncasecmp(x,y,n) strnicmp(x,y,n) -# endif -#elif defined(PLATFORM_WIN32) -# define USE_STRCASECMP -# define strcasecmp(x,y) strcmpi(x,y) -#endif - -/************************************************************************* - * StrAppendMax - */ -char *StrAppendMax(char *target, size_t max, const char *source) -{ - assert(VALID(target)); - assert(VALID(source)); - assert(max > 0); - - max -= StrLength(target) + 1; - return (max > 0) ? strncat(target, source, max) : target; -} - -/************************************************************************* - * StrCopyMax - */ -char *StrCopyMax(char *target, size_t max, const char *source) -{ - assert(VALID(target)); - assert(VALID(source)); - assert(max > 0); /* Includes != 0 */ - - target = strncpy(target, source, max - 1); - target[max - 1] = (char)0; - return target; -} - -/************************************************************************* - * StrDuplicate - */ -char *StrDuplicate(const char *source) -{ - char *target; - - assert(VALID(source)); - - target = StrAlloc(StrLength(source) + 1); - if (target) - { - StrCopy(target, source); - } - return target; -} - -/************************************************************************* - * StrDuplicateMax - */ -char *StrDuplicateMax(const char *source, size_t max) -{ - char *target; - size_t len; - - assert(VALID(source)); - assert(max > 0); - - /* Make room for string plus a terminating zero */ - len = StrLength(source) + 1; - if (len > max) - { - len = max; - } - target = StrAlloc(len); - if (target) - { - StrCopyMax(target, len, source); - } - return target; -} - -/************************************************************************* - * StrEqual - */ -int StrEqual(const char *first, const char *second) -{ - assert(VALID(first)); - assert(VALID(second)); - - if (VALID(first) && VALID(second)) - { -#if defined(USE_STRCASECMP) - return (0 == strcasecmp(first, second)); -#else - while ((*first != NIL) && (*second != NIL)) - { - if (toupper(*first) != toupper(*second)) - { - break; - } - first++; - second++; - } - return ((*first == NIL) && (*second == NIL)); -#endif - } - return FALSE; -} - -/************************************************************************* - * StrEqualCase - */ -int StrEqualCase(const char *first, const char *second) -{ - assert(VALID(first)); - assert(VALID(second)); - - if (VALID(first) && VALID(second)) - { - return (0 == strcmp(first, second)); - } - return FALSE; -} - -/************************************************************************* - * StrEqualCaseMax - */ -int StrEqualCaseMax(const char *first, size_t max, const char *second) -{ - assert(VALID(first)); - assert(VALID(second)); - - if (VALID(first) && VALID(second)) - { - return (0 == strncmp(first, second, max)); - } - return FALSE; -} - -/************************************************************************* - * StrEqualLocale - */ -int StrEqualLocale(const char *first, const char *second) -{ - assert(VALID(first)); - assert(VALID(second)); - -#if defined(LC_COLLATE) - return (strcoll(first, second) == 0); -#else - return StrEqual(first, second); -#endif -} - -/************************************************************************* - * StrEqualMax - */ -int StrEqualMax(const char *first, size_t max, const char *second) -{ - assert(VALID(first)); - assert(VALID(second)); - - if (VALID(first) && VALID(second)) - { -#if defined(USE_STRNCASECMP) - return (0 == strncasecmp(first, second, max)); -#else - /* Not adequately tested yet */ - size_t cnt = 0; - while ((*first != NIL) && (*second != NIL) && (cnt <= max)) - { - if (toupper(*first) != toupper(*second)) - { - break; - } - first++; - second++; - cnt++; - } - return ((cnt == max) || ((*first == NIL) && (*second == NIL))); -#endif - } - return FALSE; -} - -/************************************************************************* - * StrError - */ -const char *StrError(int errorNumber) -{ -#if defined(USE_STRERROR) - return strerror(errorNumber); -#else - return "unknown"; -#endif -} - -/************************************************************************* - * StrFormatDate - */ -size_t StrFormatDateMax(char *target, - size_t max, - const char *format, - const struct tm *datetime) -{ - assert(VALID(target)); - assert(VALID(format)); - assert(VALID(datetime)); - assert(max > 0); - - return strftime(target, max, format, datetime); -} - -/************************************************************************* - * StrHash - */ -unsigned long StrHash(const char *string, int type) -{ - unsigned long value = 0L; - char ch; - - assert(VALID(string)); - - switch (type) - { - case STRIO_HASH_PLAIN: - while ( (ch = *string++) != NIL ) - { - value *= 31; - value += (unsigned long)ch; - } - break; - default: - assert(FALSE); - break; - } - return value; -} - -/************************************************************************* - * StrMatch - */ -int StrMatch(char *string, char *pattern) -{ - assert(VALID(string)); - assert(VALID(pattern)); - - for (; ('*' != *pattern); ++pattern, ++string) - { - if (NIL == *string) - { - return (NIL == *pattern); - } - if ((toupper((int)*string) != toupper((int)*pattern)) - && ('?' != *pattern)) - { - return FALSE; - } - } - /* two-line patch to prevent *too* much recursiveness: */ - while ('*' == pattern[1]) - pattern++; - - do - { - if ( StrMatch(string, &pattern[1]) ) - { - return TRUE; - } - } - while (*string++); - - return FALSE; -} - -/************************************************************************* - * StrMatchCase - */ -int StrMatchCase(char *string, char *pattern) -{ - assert(VALID(string)); - assert(VALID(pattern)); - - for (; ('*' != *pattern); ++pattern, ++string) - { - if (NIL == *string) - { - return (NIL == *pattern); - } - if ((*string != *pattern) - && ('?' != *pattern)) - { - return FALSE; - } - } - /* two-line patch to prevent *too* much recursiveness: */ - while ('*' == pattern[1]) - pattern++; - - do - { - if ( StrMatchCase(string, &pattern[1]) ) - { - return TRUE; - } - } - while (*string++); - - return FALSE; -} - -/************************************************************************* - * StrSpanFunction - * - * Untested - */ -size_t StrSpanFunction(char *source, int (*Function)(int)) -{ - size_t count = 0; - - assert(VALID(source)); - assert(VALID(Function)); - - while (*source != NIL) - { - if (Function(*source)) - break; /* while */ - source++; - count++; - } - return count; -} - -/************************************************************************* - * StrSubstringMax - */ -char *StrSubstringMax(const char *string, size_t max, const char *find) -{ - size_t count; - size_t size; - char *result = NULL; - - assert(VALID(string)); - assert(VALID(find)); - - size = StrLength(find); - if (size <= max) - { - for (count = 0; count <= max - size; count++) - { - if (StrEqualMax(find, size, &string[count])) - { - result = (char *)&string[count]; - break; - } - } - } - return result; -} - -/************************************************************************* - * StrToDouble - * - * double ::= [ ] - * ( | - * | - * ) - * [ [ ] ] - * number ::= 1*( ) - * digit ::= ( '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ) - * exponential ::= ( 'e' | 'E' ) - * sign ::= ( '-' | '+' ) - * decimal_point ::= '.' - */ -double StrToDouble(const char *source, const char **endp) -{ -#if defined(TRIO_C99) - return strtod(source, endp); -#else - /* Preliminary code */ - int isNegative = FALSE; - int isExponentNegative = FALSE; - unsigned long integer = 0; - unsigned long fraction = 0; - unsigned long fracdiv = 1; - unsigned long exponent = 0; - double value = 0.0; - - /* First try hex-floats */ - if ((source[0] == '0') && ((source[1] == 'x') || (source[1] == 'X'))) - { - source += 2; - while (isxdigit((int)*source)) - { - integer *= 16; - integer += (isdigit((int)*source) - ? (*source - '0') - : 10 + (toupper((int)*source) - 'A')); - source++; - } - if (*source == '.') - { - source++; - while (isxdigit((int)*source)) - { - fraction *= 16; - fraction += (isdigit((int)*source) - ? (*source - '0') - : 10 + (toupper((int)*source) - 'A')); - fracdiv *= 16; - source++; - } - if ((*source == 'p') || (*source == 'P')) - { - source++; - if ((*source == '+') || (*source == '-')) - { - isExponentNegative = (*source == '-'); - source++; - } - while (isdigit((int)*source)) - { - exponent *= 10; - exponent += (*source - '0'); - source++; - } - } - } - } - else /* Then try normal decimal floats */ - { - isNegative = (*source == '-'); - /* Skip sign */ - if ((*source == '+') || (*source == '-')) - source++; - - /* Integer part */ - while (isdigit((int)*source)) - { - integer *= 10; - integer += (*source - '0'); - source++; - } - - if (*source == '.') - { - source++; /* skip decimal point */ - while (isdigit((int)*source)) - { - fraction *= 10; - fraction += (*source - '0'); - fracdiv *= 10; - source++; - } - } - if ((*source == 'e') || (*source == 'E')) - { - source++; /* Skip exponential indicator */ - isExponentNegative = (*source == '-'); - if ((*source == '+') || (*source == '-')) - source++; - while (isdigit((int)*source)) - { - exponent *= 10; - exponent += (*source - '0'); - source++; - } - } - } - - value = (double)integer; - if (fraction != 0) - { - value += (double)fraction / (double)fracdiv; - } - if (exponent != 0) - { - if (isExponentNegative) - value /= pow((double)10, (double)exponent); - else - value *= pow((double)10, (double)exponent); - } - if (isNegative) - value = -value; - - if (endp) - *endp = source; - return value; -#endif -} - -/************************************************************************* - * StrToFloat - */ -float StrToFloat(const char *source, const char **endp) -{ -#if defined(TRIO_C99) - return strtof(source, endp); -#else - return (float)StrToDouble(source, endp); -#endif -} - -/************************************************************************* - * StrToUpper - */ -int StrToUpper(char *target) -{ - int i = 0; - - assert(VALID(target)); - - while (NIL != *target) - { - *target = toupper((int)*target); - target++; - i++; - } - return i; -} diff --git a/org.glite.lbjp-common.trio/src/strio.h b/org.glite.lbjp-common.trio/src/strio.h deleted file mode 100644 index 68845a3..0000000 --- a/org.glite.lbjp-common.trio/src/strio.h +++ /dev/null @@ -1,227 +0,0 @@ -/************************************************************************* - * - * $Id$ - * - * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND - * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. - * - ************************************************************************/ - -#ifndef TRIO_STRIO_H -#define TRIO_STRIO_H - -#if !(defined(DEBUG) || defined(NDEBUG)) -# define NDEBUG -#endif -#include -#include -#include -#include - -#ifndef STRIO_MALLOC -# define STRIO_MALLOC(n) malloc(n) -#endif -#ifndef STRIO_FREE -# define STRIO_FREE(x) free(x) -#endif - -/* - * StrAppend(target, source) - * StrAppendMax(target, maxsize, source) - * - * Append 'source' to 'target' - * - * target = StrAlloc(size) - * - * Allocate a new string - * - * StrContains(target, substring) - * - * Find out if the string 'substring' is - * contained in the string 'target' - * - * StrCopy(target, source) - * StrCopyMax(target, maxsize, source) - * - * Copy 'source' to 'target' - * - * target = StrDuplicate(source) - * target = StrDuplicateMax(source, maxsize) - * - * Allocate and copy 'source' to 'target' - * - * StrEqual(first, second) - * StrEqualMax(first, maxsize, second) - * - * Compare if 'first' is equal to 'second'. - * Case-independent. - * - * StrEqualCase(first, second) - * StrEqualCaseMax(first, maxsize, second) - * - * Compare if 'first' is equal to 'second' - * Case-dependent. Please note that the use of the - * word 'case' has the opposite meaning as that of - * strcasecmp(). - * - * StrFormat(target, format, ...) - * StrFormatMax(target, maxsize, format, ...) - * - * Build 'target' according to 'format' and succesive - * arguments. This is equal to the sprintf() and - * snprintf() functions. - * - * StrFormatDate(target, format, ...) - * - * StrFree(target) - * - * De-allocates a string - * - * StrHash(string, type) - * - * Calculates the hash value of 'string' based on the - * 'type'. - * - * StrIndex(target, character) - * StrIndexLast(target, character) - * - * Find the first/last occurrence of 'character' in - * 'target' - * - * StrLength(target) - * - * Return the length of 'target' - * - * StrMatch(string, pattern) - * StrMatchCase(string, pattern) - * - * Find 'pattern' within 'string'. 'pattern' may contain - * wildcards such as * (asterics) and ? (question mark) - * which matches zero or more characters and exactly - * on character respectively - * - * StrScan(source, format, ...) - * - * Equal to sscanf() - * - * StrSubstring(target, substring) - * - * Find the first occurrence of the string 'substring' - * within the string 'target' - * - * StrTokenize(target, list) - * - * Split 'target' into the first token delimited by - * one of the characters in 'list'. If 'target' is - * NULL then next token will be returned. - * - * StrToUpper(target) - * - * Convert all lower case characters in 'target' into - * upper case characters. - */ - -enum { - STRIO_HASH_NONE = 0, - STRIO_HASH_PLAIN, - STRIO_HASH_TWOSIGNED -}; - -#if !defined(DEBUG) || defined(__DECC) -#define StrAlloc(n) (char *)STRIO_MALLOC(n) -#define StrAppend(x,y) strcat((x), (y)) -#define StrContains(x,y) (0 != strstr((x), (y))) -#define StrCopy(x,y) strcpy((x), (y)) -#define StrIndex(x,y) strchr((x), (y)) -#define StrIndexLast(x,y) strrchr((x), (y)) -#define StrFree(x) STRIO_FREE(x) -#define StrLength(x) strlen((x)) -#define StrSubstring(x,y) strstr((x), (y)) -#define StrTokenize(x,y) strtok((x), (y)) -#define StrToLong(x,y,n) strtol((x), (y), (n)) -#define StrToUnsignedLong(x,y,n) strtoul((x), (y), (n)) -#else /* DEBUG */ - /* - * To be able to use these macros everywhere, including in - * if() sentences, the assertions are put first in a comma - * seperated list. - * - * Unfortunately the DECC compiler does not seem to like this - * so it will use the un-asserted functions above for the - * debugging case too. - */ -#define StrAlloc(n) \ - (assert((n) > 0),\ - (char *)STRIO_MALLOC(n)) -#define StrAppend(x,y) \ - (assert((x) != NULL),\ - assert((y) != NULL),\ - strcat((x), (y))) -#define StrContains(x,y) \ - (assert((x) != NULL),\ - assert((y) != NULL),\ - (0 != strstr((x), (y)))) -#define StrCopy(x,y) \ - (assert((x) != NULL),\ - assert((y) != NULL),\ - strcpy((x), (y))) -#define StrIndex(x,c) \ - (assert((x) != NULL),\ - strchr((x), (c))) -#define StrIndexLast(x,c) \ - (assert((x) != NULL),\ - strrchr((x), (c))) -#define StrFree(x) \ - (assert((x) != NULL),\ - STRIO_FREE(x)) -#define StrLength(x) \ - (assert((x) != NULL),\ - strlen((x))) -#define StrSubstring(x,y) \ - (assert((x) != NULL),\ - assert((y) != NULL),\ - strstr((x), (y))) -#define StrTokenize(x,y) \ - (assert((y) != NULL),\ - strtok((x), (y))) -#define StrToLong(x,y,n) \ - (assert((x) != NULL),\ - assert((y) != NULL),\ - assert((n) >= 2 && (n) <= 36),\ - strtol((x), (y), (n))) -#define StrToUnsignedLong(x,y,n) \ - (assert((x) != NULL),\ - assert((y) != NULL),\ - assert((n) >= 2 && (n) <= 36),\ - strtoul((x), (y), (n))) -#endif /* DEBUG */ - -char *StrAppendMax(char *target, size_t max, const char *source); -char *StrCopyMax(char *target, size_t max, const char *source); -char *StrDuplicate(const char *source); -char *StrDuplicateMax(const char *source, size_t max); -int StrEqual(const char *first, const char *second); -int StrEqualCase(const char *first, const char *second); -int StrEqualCaseMax(const char *first, size_t max, const char *second); -int StrEqualLocale(const char *first, const char *second); -int StrEqualMax(const char *first, size_t max, const char *second); -const char *StrError(int); -size_t StrFormatDateMax(char *target, size_t max, const char *format, const struct tm *datetime); -unsigned long StrHash(const char *string, int type); -int StrMatch(char *string, char *pattern); -int StrMatchCase(char *string, char *pattern); -size_t StrSpanFunction(char *source, int (*Function)(int)); -char *StrSubstringMax(const char *string, size_t max, const char *find); -float StrToFloat(const char *source, const char **target); -double StrToDouble(const char *source, const char **target); -int StrToUpper(char *target); - -#endif /* TRIO_STRIO_H */ diff --git a/org.glite.lbjp-common.trio/src/trio.c b/org.glite.lbjp-common.trio/src/trio.c deleted file mode 100644 index 6e4211e..0000000 --- a/org.glite.lbjp-common.trio/src/trio.c +++ /dev/null @@ -1,5706 +0,0 @@ - -/************************************************************************* - * - * $Id$ - * - * Copyright (C) 1998 Bjorn Reese and Daniel Stenberg. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND - * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. - * - ************************************************************************* - * - * A note to trio contributors: - * - * Avoid heap allocation at all costs to ensure that the trio functions - * are async-safe. The exceptions are the printf/fprintf functions, which - * uses fputc, and the asprintf functions and the modifier, which - * by design are required to allocate form the heap. - * - ************************************************************************/ - -/* - * TODO: - * - Scan is probably too permissive about its modifiers. - * - C escapes in %#[] ? - * - C99 support has not been properly tested. - * - Multibyte characters (done for format parsing, except scan groups) - * - Complex numbers? (C99 _Complex) - * - Boolean values? (C99 _Bool) - * - C99 NaN(n-char-sequence) missing - * - Should we support the GNU %a alloc modifier? GNU has an ugly hack - * for %a, because C99 used %a for other purposes. If specified as - * %as or %a[ it is interpreted as the alloc modifier, otherwise as - * the C99 hex-float. This means that you cannot scan %as as a hex-float - * immediately followed by an 's'. - * - Scanning of collating symbols. - */ - -static const char rcsid[] = "@(#)$Id$"; - -/************************************************************************* - * Trio include files - */ -#include "trio.h" -#include "triop.h" -#include "strio.h" - -#ifdef DATAGRID_EXTENSION -#include "escape.h" -#endif - -/* - * Encode the error code and the position. This is decoded - * with TRIO_ERROR_CODE and TRIO_ERROR_POSITION. - */ -#if TRIO_ERRORS -# define TRIO_ERROR_RETURN(x,y) (- ((x) + ((y) << 8))) -#else -# define TRIO_ERROR_RETURN(x,y) (-1) -#endif - - -/************************************************************************* - * Platform and compiler support detection - */ -#if defined(unix) || defined(__xlC__) || defined(_AIX) || defined(__QNX__) -# define PLATFORM_UNIX -#elif defined(AMIGA) && defined(__GNUC__) -# define PLATFORM_UNIX -#elif defined(WIN32) || defined(_WIN32) || defined(_MSC_VER) -# define PLATFORM_WIN32 -# define TRIO_MSVC_5 1100 -#endif - -#if defined(__STDC__) && defined(__STDC_VERSION__) -# if (__STDC_VERSION__ >= 199409L) -# define TRIO_COMPILER_SUPPORTS_ISO94 -# endif -# if (__STDC_VERSION__ >= 199901L) -# define TRIO_COMPILER_SUPPORTS_C99 -# endif -#endif - -#if defined(_XOPEN_SOURCE) && defined(_XOPEN_SOURCE_EXTENDED) -# define TRIO_COMPILER_SUPPORTS_UNIX98 -#endif - -#if defined(__STDC_ISO_10646__) || defined(MB_LEN_MAX) || defined(USE_MULTIBYTE) || TRIO_WIDECHAR -# define TRIO_COMPILER_SUPPORTS_MULTIBYTE -# if !defined(MB_LEN_MAX) -# define MB_LEN_MAX 6 -# endif -#endif - - -/************************************************************************* - * Generic definitions - */ - -#if !(defined(DEBUG) || defined(NDEBUG)) -# define NDEBUG -#endif -#include -#include -#if !defined(TRIO_COMPILER_SUPPORTS_C99) && !defined(isblank) -# define isblank(x) (((x)==32) || ((x)==9)) -#endif -#include -#include -#include -#include -#include -#include - -#ifndef NULL -# define NULL 0 -#endif -#define NIL ((char)0) -#ifndef FALSE -# define FALSE (1 == 0) -# define TRUE (! FALSE) -#endif -#define BOOLEAN_T int - -/* mincore() can be used for debugging purposes */ -#define VALID(x) (NULL != (x)) - -/* xlC crashes on log10(0) */ -#define guarded_log10(x) (((x) == 0.0) ? -HUGE_VAL : log10(x)) -#define guarded_log16(x) (guarded_log10(x) / log10(16.0)) - - -/************************************************************************* - * Platform specific definitions - */ -#if defined(PLATFORM_UNIX) -# include -# include -# include -# define USE_LOCALE -#endif /* PLATFORM_UNIX */ -#if defined(PLATFORM_WIN32) -# include -# define read _read -# define write _write -#endif /* PLATFORM_WIN32 */ - -#if TRIO_WIDECHAR -# if defined(TRIO_COMPILER_SUPPORTS_ISO94) -# include -# include -# else -typedef char wchar_t; -typedef int wint_t; -# define WEOF EOF -# define iswalnum(x) isalnum(x) -# define iswalpha(x) isalpha(x) -# define iswblank(x) isblank(x) -# define iswcntrl(x) iscntrl(x) -# define iswdigit(x) isdigit(x) -# define iswgraph(x) isgraph(x) -# define iswlower(x) islower(x) -# define iswprint(x) isprint(x) -# define iswpunct(x) ispunct(x) -# define iswspace(x) isspace(x) -# define iswupper(x) isupper(x) -# define iswxdigit(x) isxdigit(x) -# endif -#endif - - -/************************************************************************* - * Compiler dependent definitions - */ - -/* Support for long long */ -#ifndef __cplusplus -# if !defined(USE_LONGLONG) -# if defined(__GNUC__) && !defined(__STRICT_ANSI__) -# define USE_LONGLONG -# elif defined(__SUNPRO_C) -# define USE_LONGLONG -# elif defined(_LONG_LONG) || defined(_LONGLONG) -# define USE_LONGLONG -# endif -# endif -#endif - -/* The extra long numbers */ -#if defined(USE_LONGLONG) -typedef signed long long int trio_longlong_t; -typedef unsigned long long int trio_ulonglong_t; -#elif defined(_MSC_VER) -# if (_MSC_VER >= TRIO_MSVC_5) -typedef signed __int64 trio_longlong_t; -typedef unsigned __int64 trio_ulonglong_t; -# else -typedef signed long int trio_longlong_t; -typedef unsigned long int trio_ulonglong_t; -# endif -#else -typedef signed long int trio_longlong_t; -typedef unsigned long int trio_ulonglong_t; -#endif - -/* Maximal and fixed integer types */ -#if defined(TRIO_COMPILER_SUPPORTS_C99) -# include -typedef intmax_t trio_intmax_t; -typedef uintmax_t trio_uintmax_t; -typedef int8_t trio_int8_t; -typedef int16_t trio_int16_t; -typedef int32_t trio_int32_t; -typedef int64_t trio_int64_t; -#elif defined(TRIO_COMPILER_SUPPORTS_UNIX98) -# include -typedef intmax_t trio_intmax_t; -typedef uintmax_t trio_uintmax_t; -typedef int8_t trio_int8_t; -typedef int16_t trio_int16_t; -typedef int32_t trio_int32_t; -typedef int64_t trio_int64_t; -#elif defined(_MSC_VER) && (_MSC_VER >= TRIO_MSVC_5) -typedef trio_longlong_t trio_intmax_t; -typedef trio_ulonglong_t trio_uintmax_t; -typedef __int8 trio_int8_t; -typedef __int16 trio_int16_t; -typedef __int32 trio_int32_t; -typedef __int64 trio_int64_t; -#else -typedef trio_longlong_t trio_intmax_t; -typedef trio_ulonglong_t trio_uintmax_t; -# if defined(TRIO_INT8_T) -typedef TRIO_INT8_T trio_int8_t; -# else -typedef signed char trio_int8_t; -# endif -# if defined(TRIO_INT16_T) -typedef TRIO_INT16_T trio_int16_t; -# else -typedef signed short trio_int16_t; -# endif -# if defined(TRIO_INT32_T) -typedef TRIO_INT32_T trio_int32_t; -# else -typedef signed int trio_int32_t; -# endif -# if defined(TRIO_INT64_T) -typedef TRIO_INT64_T trio_int64_t; -# else -typedef trio_longlong_t trio_int64_t; -# endif -#endif - - -/************************************************************************* - * Internal definitions - */ - -/* Long double sizes */ -#ifdef LDBL_DIG -# define MAX_MANTISSA_DIGITS LDBL_DIG -# define MAX_EXPONENT_DIGITS 4 -#else -# define MAX_MANTISSA_DIGITS DBL_DIG -# define MAX_EXPONENT_DIGITS 3 -#endif - -/* The maximal number of digits is for base 2 */ -#define MAX_CHARS_IN(x) (sizeof(x) * CHAR_BIT) -/* The width of a pointer. The number of bits in a hex digit is 4 */ -#define POINTER_WIDTH ((sizeof("0x") - 1) + sizeof(void *) * CHAR_BIT / 4) - -/* Infinite and Not-A-Number for floating-point */ -#define INFINITE_LOWER "inf" -#define INFINITE_UPPER "INF" -#define LONG_INFINITE_LOWER "infinite" -#define LONG_INFINITE_UPPER "INFINITE" -#define NAN_LOWER "nan" -#define NAN_UPPER "NAN" - -/* Various constants */ -enum { - TYPE_PRINT = 1, - TYPE_SCAN = 2, - - /* Flags. Use maximum 32 */ - FLAGS_NEW = 0, - FLAGS_STICKY = 1, - FLAGS_SPACE = 2 * FLAGS_STICKY, - FLAGS_SHOWSIGN = 2 * FLAGS_SPACE, - FLAGS_LEFTADJUST = 2 * FLAGS_SHOWSIGN, - FLAGS_ALTERNATIVE = 2 * FLAGS_LEFTADJUST, - FLAGS_SHORT = 2 * FLAGS_ALTERNATIVE, - FLAGS_SHORTSHORT = 2 * FLAGS_SHORT, - FLAGS_LONG = 2 * FLAGS_SHORTSHORT, - FLAGS_QUAD = 2 * FLAGS_LONG, - FLAGS_LONGDOUBLE = 2 * FLAGS_QUAD, - FLAGS_SIZE_T = 2 * FLAGS_LONGDOUBLE, - FLAGS_PTRDIFF_T = 2 * FLAGS_SIZE_T, - FLAGS_INTMAX_T = 2 * FLAGS_PTRDIFF_T, - FLAGS_NILPADDING = 2 * FLAGS_INTMAX_T, - FLAGS_UNSIGNED = 2 * FLAGS_NILPADDING, - FLAGS_UPPER = 2 * FLAGS_UNSIGNED, - FLAGS_WIDTH = 2 * FLAGS_UPPER, - FLAGS_WIDTH_PARAMETER = 2 * FLAGS_WIDTH, - FLAGS_PRECISION = 2 * FLAGS_WIDTH_PARAMETER, - FLAGS_PRECISION_PARAMETER = 2 * FLAGS_PRECISION, - FLAGS_BASE = 2 * FLAGS_PRECISION_PARAMETER, - FLAGS_BASE_PARAMETER = 2 * FLAGS_BASE, - FLAGS_FLOAT_E = 2 * FLAGS_BASE_PARAMETER, - FLAGS_FLOAT_G = 2 * FLAGS_FLOAT_E, - FLAGS_QUOTE = 2 * FLAGS_FLOAT_G, - FLAGS_WIDECHAR = 2 * FLAGS_QUOTE, - FLAGS_ALLOC = 2 * FLAGS_WIDECHAR, - FLAGS_IGNORE = 2 * FLAGS_ALLOC, - FLAGS_IGNORE_PARAMETER = 2 * FLAGS_IGNORE, - FLAGS_VARSIZE_PARAMETER = 2 * FLAGS_IGNORE_PARAMETER, - FLAGS_FIXED_SIZE = 2 * FLAGS_VARSIZE_PARAMETER, - /* Reused flags */ - FLAGS_EXCLUDE = FLAGS_SHORT, - FLAGS_USER_DEFINED = FLAGS_IGNORE, - /* Compounded flags */ - FLAGS_ALL_VARSIZES = FLAGS_LONG | FLAGS_QUAD | FLAGS_INTMAX_T | FLAGS_PTRDIFF_T | FLAGS_SIZE_T, - FLAGS_ALL_SIZES = FLAGS_ALL_VARSIZES | FLAGS_SHORTSHORT | FLAGS_SHORT, - - NO_POSITION = -1, - NO_WIDTH = 0, - NO_PRECISION = -1, - NO_SIZE = -1, - - NO_BASE = -1, - MIN_BASE = 2, - MAX_BASE = 36, - BASE_BINARY = 2, - BASE_OCTAL = 8, - BASE_DECIMAL = 10, - BASE_HEX = 16, - - /* Maximal number of allowed parameters */ - MAX_PARAMETERS = 64, - /* Maximal number of characters in class */ - MAX_CHARACTER_CLASS = UCHAR_MAX, - - /* Maximal string lengths for user-defined specifiers */ - MAX_USER_NAME = 64, - MAX_USER_DATA = 256, - - /* Maximal length of locale separator strings */ - MAX_LOCALE_SEPARATOR_LENGTH = MB_LEN_MAX, - /* Maximal number of integers in grouping */ - MAX_LOCALE_GROUPS = 64 -}; - -#define NO_GROUPING ((int)CHAR_MAX) - -/* Fundamental formatting parameter types */ -#define FORMAT_UNKNOWN 0 -#define FORMAT_INT 1 -#define FORMAT_DOUBLE 2 -#define FORMAT_CHAR 3 -#define FORMAT_STRING 4 -#define FORMAT_POINTER 5 -#define FORMAT_COUNT 6 -#define FORMAT_PARAMETER 7 -#define FORMAT_GROUP 8 -#if TRIO_GNU -# define FORMAT_ERRNO 9 -#endif -#if TRIO_EXTENSION -# define FORMAT_USER_DEFINED 10 -#endif - -/* Character constants */ -#define CHAR_IDENTIFIER '%' -#define CHAR_BACKSLASH '\\' -#define CHAR_QUOTE '\"' -#define CHAR_ADJUST ' ' - -/* Character class expressions */ -#define CLASS_ALNUM ":alnum:" -#define CLASS_ALPHA ":alpha:" -#define CLASS_CNTRL ":cntrl:" -#define CLASS_DIGIT ":digit:" -#define CLASS_GRAPH ":graph:" -#define CLASS_LOWER ":lower:" -#define CLASS_PRINT ":print:" -#define CLASS_PUNCT ":punct:" -#define CLASS_SPACE ":space:" -#define CLASS_UPPER ":upper:" -#define CLASS_XDIGIT ":xdigit:" - -/* - * SPECIFIERS: - * - * - * a Hex-float - * A Hex-float - * c Character - * C Widechar character (wint_t) - * d Decimal - * e Float - * E Float - * F Float - * F Float - * g Float - * G Float - * i Integer - * m Error message - * n Count - * o Octal - * p Pointer - * s String - * S Widechar string (wchar_t *) - * u Unsigned - * x Hex - * X Hex - * [] Group - * <> User-defined - * - * Reserved: - * - * D Binary Coded Decimal %D(length,precision) (OS/390) - */ -#define SPECIFIER_CHAR 'c' -#define SPECIFIER_STRING 's' -#define SPECIFIER_DECIMAL 'd' -#define SPECIFIER_INTEGER 'i' -#define SPECIFIER_UNSIGNED 'u' -#define SPECIFIER_OCTAL 'o' -#define SPECIFIER_HEX 'x' -#define SPECIFIER_HEX_UPPER 'X' -#define SPECIFIER_FLOAT_E 'e' -#define SPECIFIER_FLOAT_E_UPPER 'E' -#define SPECIFIER_FLOAT_F 'f' -#define SPECIFIER_FLOAT_F_UPPER 'F' -#define SPECIFIER_FLOAT_G 'g' -#define SPECIFIER_FLOAT_G_UPPER 'G' -#define SPECIFIER_POINTER 'p' -#define SPECIFIER_GROUP '[' -#define SPECIFIER_UNGROUP ']' -#define SPECIFIER_COUNT 'n' -#if TRIO_UNIX98 -# define SPECIFIER_CHAR_UPPER 'C' -# define SPECIFIER_STRING_UPPER 'S' -#endif -#if TRIO_C99 -# define SPECIFIER_HEXFLOAT 'a' -# define SPECIFIER_HEXFLOAT_UPPER 'A' -#endif -#if TRIO_GNU -# define SPECIFIER_ERRNO 'm' -#endif -#if TRIO_EXTENSION -# define SPECIFIER_BINARY 'b' -# define SPECIFIER_BINARY_UPPER 'B' -# define SPECIFIER_USER_DEFINED_BEGIN '<' -# define SPECIFIER_USER_DEFINED_END '>' -# define SPECIFIER_USER_DEFINED_SEPARATOR ':' -#endif - -/* - * QUALIFIERS: - * - * - * Numbers = d,i,o,u,x,X - * Float = a,A,e,E,f,F,g,G - * String = s - * Char = c - * - * - * 9$ Position - * Use the 9th parameter. 9 can be any number between 1 and - * the maximal argument - * - * 9 Width - * Set width to 9. 9 can be any number, but must not be postfixed - * by '$' - * - * h Short - * Numbers: - * (unsigned) short int - * - * hh Short short - * Numbers: - * (unsigned) char - * - * l Long - * Numbers: - * (unsigned) long int - * String: - * as the S specifier - * Char: - * as the C specifier - * - * ll Long Long - * Numbers: - * (unsigned) long long int - * - * L Long Double - * Float - * long double - * - * # Alternative - * Float: - * Decimal-point is always present - * String: - * non-printable characters are handled as \number - * - * Spacing - * - * + Sign - * - * - Alignment - * - * . Precision - * - * * Parameter - * print: use parameter - * scan: no parameter (ignore) - * - * q Quad - * - * Z size_t - * - * w Widechar - * - * ' Thousands/quote - * Numbers: - * Integer part grouped in thousands - * Binary numbers: - * Number grouped in nibbles (4 bits) - * String: - * Quoted string - * - * j intmax_t - * t prtdiff_t - * z size_t - * - * ! Sticky - * @ Parameter (for both print and scan) - * - * I n-bit Integer - * Numbers: - * The following options exists - * I8 = 8-bit integer - * I16 = 16-bit integer - * I32 = 32-bit integer - * I64 = 64-bit integer - */ -#define QUALIFIER_POSITION '$' -#define QUALIFIER_SHORT 'h' -#define QUALIFIER_LONG 'l' -#define QUALIFIER_LONG_UPPER 'L' -#define QUALIFIER_ALTERNATIVE '#' -#define QUALIFIER_SPACE ' ' -#define QUALIFIER_PLUS '+' -#define QUALIFIER_MINUS '-' -#define QUALIFIER_DOT '.' -#define QUALIFIER_STAR '*' -#define QUALIFIER_CIRCUMFLEX '^' -#if TRIO_C99 -# define QUALIFIER_SIZE_T 'z' -# define QUALIFIER_PTRDIFF_T 't' -# define QUALIFIER_INTMAX_T 'j' -#endif -#if TRIO_BSD || TRIO_GNU -# define QUALIFIER_QUAD 'q' -#endif -#if TRIO_GNU -# define QUALIFIER_SIZE_T_UPPER 'Z' -#endif -#if TRIO_MISC -# define QUALIFIER_WIDECHAR 'w' -#endif -#if TRIO_MICROSOFT -# define QUALIFIER_FIXED_SIZE 'I' -#endif -#if TRIO_EXTENSION -# define QUALIFIER_QUOTE '\'' -# define QUALIFIER_STICKY '!' -# define QUALIFIER_VARSIZE '&' /* This should remain undocumented */ -# define QUALIFIER_PARAM '@' /* Experimental */ -# define QUALIFIER_COLON ':' /* For scanlists */ -# define QUALIFIER_EQUAL '=' /* For scanlists */ -#endif -#if DATAGRID_EXTENSION -# define QUALIFIER_ESCAPE '|' -#endif - - -/************************************************************************* - * Internal structures - */ - -/* Parameters */ -typedef struct { - int type; - unsigned long flags; - int width; - int precision; - int base; - int varsize; -#ifdef QUALIFIER_ESCAPE - enum dg_escape { ESCAPE_NONE, ESCAPE_ULM, ESCAPE_XML, ESCAPE_SQL } escape; -#endif - int indexAfterSpecifier; - union { - char *string; -#if TRIO_WIDECHAR - wchar_t *wstring; -#endif - void *pointer; - union { - trio_uintmax_t as_signed; - trio_intmax_t as_unsigned; - } number; - double doubleNumber; - double *doublePointer; - long double longdoubleNumber; - long double *longdoublePointer; - int errorNumber; - } data; - /* For the user-defined specifier */ - char user_name[MAX_USER_NAME]; - char user_data[MAX_USER_DATA]; -} parameter_T; - -/* General trio "class" */ -typedef struct _trio_T { - void *location; - void (*OutStream)(struct _trio_T *, int); - void (*InStream)(struct _trio_T *, int *); - /* - * The number of characters that would have been written/read if - * there had been sufficient space. - */ - int processed; - /* - * The number of characters that are actually written/read. - * Processed and committed with only differ for the *nprintf - * and *nscanf functions. - */ - int committed; - int max; - int current; -} trio_T; - -/* References (for user-defined callbacks) */ -typedef struct _reference_T { - trio_T *data; - parameter_T *parameter; -} reference_T; - -/* Registered entries (for user-defined callbacks) */ -typedef struct _userdef_T { - struct _userdef_T *next; - trio_callback_t callback; - char *name; -} userdef_T; - - -/************************************************************************* - * Internal variables - */ - -static const char null[] = "(nil)"; - -#if defined(USE_LOCALE) -static struct lconv *internalLocaleValues = NULL; -#endif - -/* - * UNIX98 says "in a locale where the radix character is not defined, - * the radix character defaults to a period (.)" - */ -static char internalDecimalPoint[MAX_LOCALE_SEPARATOR_LENGTH + 1] = "."; -static char internalThousandSeparator[MAX_LOCALE_SEPARATOR_LENGTH + 1] = ","; -static char internalGrouping[MAX_LOCALE_GROUPS] = { (char)NO_GROUPING }; - -static const char internalDigitsLower[] = "0123456789abcdefghijklmnopqrstuvwxyz"; -static const char internalDigitsUpper[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -static BOOLEAN_T internalDigitsUnconverted = TRUE; -static int internalDigitArray[128]; -#if TRIO_EXTENSION -static BOOLEAN_T internalCollationUnconverted = TRUE; -static char internalCollationArray[MAX_CHARACTER_CLASS][MAX_CHARACTER_CLASS]; -#endif - -static volatile trio_callback_t internalEnterCriticalRegion = NULL; -static volatile trio_callback_t internalLeaveCriticalRegion = NULL; -static userdef_T *internalUserDef = NULL; - - -/************************************************************************* - * trio_strerror [public] - */ -const char *trio_strerror(int errorcode) -{ - /* Textual versions of the error codes */ - switch (TRIO_ERROR_CODE(errorcode)) - { - case TRIO_EOF: - return "End of file"; - case TRIO_EINVAL: - return "Invalid argument"; - case TRIO_ETOOMANY: - return "Too many arguments"; - case TRIO_EDBLREF: - return "Double reference"; - case TRIO_EGAP: - return "Reference gap"; - case TRIO_ENOMEM: - return "Out of memory"; - case TRIO_ERANGE: - return "Invalid range"; - default: - return "Unknown"; - } -} - -/************************************************************************* - * TrioIsQualifier [private] - * - * Description: - * Remember to add all new qualifiers to this function. - * QUALIFIER_POSITION must not be added. - */ -static BOOLEAN_T -TrioIsQualifier(const char ch) -{ - /* QUALIFIER_POSITION is not included */ - switch (ch) - { - case '0': case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - case QUALIFIER_PLUS: - case QUALIFIER_MINUS: - case QUALIFIER_SPACE: - case QUALIFIER_DOT: - case QUALIFIER_STAR: - case QUALIFIER_ALTERNATIVE: - case QUALIFIER_SHORT: - case QUALIFIER_LONG: - case QUALIFIER_LONG_UPPER: - case QUALIFIER_CIRCUMFLEX: -#if defined(QUALIFIER_SIZE_T) - case QUALIFIER_SIZE_T: -#endif -#if defined(QUALIFIER_PTRDIFF_T) - case QUALIFIER_PTRDIFF_T: -#endif -#if defined(QUALIFIER_INTMAX_T) - case QUALIFIER_INTMAX_T: -#endif -#if defined(QUALIFIER_QUAD) - case QUALIFIER_QUAD: -#endif -#if defined(QUALIFIER_SIZE_T_UPPER) - case QUALIFIER_SIZE_T_UPPER: -#endif -#if defined(QUALIFIER_WIDECHAR) - case QUALIFIER_WIDECHAR: -#endif -#if defined(QUALIFIER_QUOTE) - case QUALIFIER_QUOTE: -#endif -#if defined(QUALIFIER_STICKY) - case QUALIFIER_STICKY: -#endif -#if defined(QUALIFIER_VARSIZE) - case QUALIFIER_VARSIZE: -#endif -#if defined(QUALIFIER_PARAM) - case QUALIFIER_PARAM: -#endif -#if defined(QUALIFIER_FIXED_SIZE) - case QUALIFIER_FIXED_SIZE: -#endif -#ifdef QUALIFIER_ESCAPE - case QUALIFIER_ESCAPE: -#endif - return TRUE; - default: - return FALSE; - } -} - -/************************************************************************* - * TrioGenerateNan [private] - * - * Calculating NaN portably is difficult. Some compilers will emit - * warnings about divide by zero, and others will simply fail to - * generate a NaN. - */ -static double -TrioGenerateNaN(void) -{ -#if defined(TRIO_COMPILER_SUPPORTS_C99) - return nan(NULL); -#elif defined(DBL_QNAN) - return DBL_QNAN; -#elif defined(PLATFORM_UNIX) - double value; - void (*signal_handler)(int); - - signal_handler = signal(SIGFPE, SIG_IGN); - value = 0.0 / 0.0; - signal(SIGFPE, signal_handler); - return value; -#else - return 0.0 / 0.0; -#endif -} - -/************************************************************************* - * TrioIsNan [private] - */ -static int -TrioIsNan(double number) -{ -#ifdef isnan - /* C99 defines isnan() as a macro */ - return isnan(number); -#else - double integral, fraction; - - return (/* NaN is the only number which does not compare to itself */ - (number != number) || - /* Fallback solution if NaN compares to NaN */ - ((number != 0.0) && - (fraction = modf(number, &integral), - integral == fraction))); -#endif -} - -/************************************************************************* - * TrioIsInfinite [private] - */ -static int -TrioIsInfinite(double number) -{ -#ifdef isinf - /* C99 defines isinf() as a macro */ - return isinf(number); -#else - return ((number == HUGE_VAL) ? 1 : ((number == -HUGE_VAL) ? -1 : 0)); -#endif -} - -/************************************************************************* - * TrioSetLocale [private] - */ -#if defined(USE_LOCALE) -static void -TrioSetLocale(void) -{ - internalLocaleValues = (struct lconv *)localeconv(); - if (internalLocaleValues) - { - if ((internalLocaleValues->decimal_point) && - (internalLocaleValues->decimal_point[0] != NIL)) - { - StrCopyMax(internalDecimalPoint, - sizeof(internalDecimalPoint), - internalLocaleValues->decimal_point); - } - if ((internalLocaleValues->thousands_sep) && - (internalLocaleValues->thousands_sep[0] != NIL)) - { - StrCopyMax(internalThousandSeparator, - sizeof(internalThousandSeparator), - internalLocaleValues->thousands_sep); - } - if ((internalLocaleValues->grouping) && - (internalLocaleValues->grouping[0] != NIL)) - { - StrCopyMax(internalGrouping, - sizeof(internalGrouping), - internalLocaleValues->grouping); - } - } -} -#endif /* defined(USE_LOCALE) */ - -/************************************************************************* - * TrioGetPosition [private] - * - * Get the %n$ position. - */ -static int -TrioGetPosition(const char *format, - int *indexPointer) -{ - char *tmpformat; - int number = 0; - int index = *indexPointer; - - number = (int)StrToLong(&format[index], &tmpformat, BASE_DECIMAL); - index = (int)(tmpformat - format); - if ((number != 0) && (QUALIFIER_POSITION == format[index++])) - { - *indexPointer = index; - /* - * number is decreased by 1, because n$ starts from 1, whereas - * the array it is indexing starts from 0. - */ - return number - 1; - } - return NO_POSITION; -} - -/************************************************************************* - * TrioFindNamespace [private] - * - * Find registered user-defined specifier. - * The prev argument is used for optimisation only. - */ -static userdef_T * -TrioFindNamespace(const char *name, userdef_T **prev) -{ - userdef_T *def; - - if (internalEnterCriticalRegion) - (void)internalEnterCriticalRegion(NULL); - - for (def = internalUserDef; def; def = def->next) - { - /* Case-sensitive string comparison */ - if (StrEqualCase(def->name, name)) - break; - - if (prev) - *prev = def; - } - - if (internalLeaveCriticalRegion) - (void)internalLeaveCriticalRegion(NULL); - - return def; -} - -/************************************************************************* - * TrioPreprocess [private] - * - * Description: - * Parse the format string - */ -static int -TrioPreprocess(int type, - const char *format, - parameter_T *parameters, - va_list arglist, - void **argarray) -{ -#if TRIO_ERRORS - /* Count the number of times a parameter is referenced */ - unsigned short usedEntries[MAX_PARAMETERS]; -#endif - /* Parameter counters */ - int parameterPosition; - int currentParam; - int maxParam = -1; - /* Utility variables */ - unsigned long flags; - int width; - int precision; - int varsize; -#ifdef QUALIFIER_ESCAPE - enum dg_escape escape; -#endif - int base; - int index; /* Index into formatting string */ - int dots; /* Count number of dots in modifier part */ - BOOLEAN_T positional; /* Does the specifier have a positional? */ - BOOLEAN_T got_sticky = FALSE; /* Are there any sticky modifiers at all? */ - /* - * indices specifies the order in which the parameters must be - * read from the va_args (this is necessary to handle positionals) - */ - int indices[MAX_PARAMETERS]; - int pos = 0; - /* Various variables */ - char ch; -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - int charlen; -#endif - int i = -1; - int num; - char *tmpformat; - - -#if TRIO_ERRORS - /* - * The 'parameters' array is not initialized, but we need to - * know which entries we have used. - */ - memset(usedEntries, 0, sizeof(usedEntries)); -#endif - - index = 0; - parameterPosition = 0; -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - mblen(NULL, 0); -#endif - - while (format[index]) - { -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - if (! isascii(format[index])) - { - /* - * Multibyte characters cannot be legal specifiers or - * modifiers, so we skip over them. - */ - charlen = mblen(&format[index], MB_LEN_MAX); - index += (charlen > 0) ? charlen : 1; - continue; /* while */ - } -#endif /* TRIO_COMPILER_SUPPORTS_MULTIBYTE */ - if (CHAR_IDENTIFIER == format[index++]) - { - if (CHAR_IDENTIFIER == format[index]) - { - index++; - continue; /* while */ - } - - flags = FLAGS_NEW; - dots = 0; - currentParam = TrioGetPosition(format, &index); - positional = (NO_POSITION != currentParam); - if (!positional) - { - /* We have no positional, get the next counter */ - currentParam = parameterPosition; - } - if(currentParam >= MAX_PARAMETERS) - { - /* Bail out completely to make the error more obvious */ - return TRIO_ERROR_RETURN(TRIO_ETOOMANY, index); - } - - if (currentParam > maxParam) - maxParam = currentParam; - - /* Default values */ - width = NO_WIDTH; - precision = NO_PRECISION; - base = NO_BASE; - varsize = NO_SIZE; -#ifdef QUALIFIER_ESCAPE - escape = ESCAPE_NONE; -#endif - - while (TrioIsQualifier(format[index])) - { - ch = format[index++]; - - switch (ch) - { - case QUALIFIER_SPACE: - flags |= FLAGS_SPACE; - break; - - case QUALIFIER_PLUS: - flags |= FLAGS_SHOWSIGN; - break; - - case QUALIFIER_MINUS: - flags |= FLAGS_LEFTADJUST; - flags &= ~FLAGS_NILPADDING; - break; - - case QUALIFIER_ALTERNATIVE: - flags |= FLAGS_ALTERNATIVE; - break; - - case QUALIFIER_DOT: - if (dots == 0) /* Precision */ - { - dots++; - - /* Skip if no precision */ - if (QUALIFIER_DOT == format[index]) - break; - - /* After the first dot we have the precision */ - flags |= FLAGS_PRECISION; - if ((QUALIFIER_STAR == format[index]) || - (QUALIFIER_PARAM == format[index])) - { - index++; - flags |= FLAGS_PRECISION_PARAMETER; - - precision = TrioGetPosition(format, &index); - if (precision == NO_POSITION) - { - parameterPosition++; - if (positional) - precision = parameterPosition; - else - { - precision = currentParam; - currentParam = precision + 1; - } - } - else - { - if (! positional) - currentParam = precision + 1; - if (width > maxParam) - maxParam = precision; - } - if (currentParam > maxParam) - maxParam = currentParam; - } - else - { - precision = StrToLong(&format[index], &tmpformat, BASE_DECIMAL); - index = (int)(tmpformat - format); - } - } - else if (dots == 1) /* Base */ - { - dots++; - - /* After the second dot we have the base */ - flags |= FLAGS_BASE; - if ((QUALIFIER_STAR == format[index]) || - (QUALIFIER_PARAM == format[index])) - { - index++; - flags |= FLAGS_BASE_PARAMETER; - base = TrioGetPosition(format, &index); - if (base == NO_POSITION) - { - parameterPosition++; - if (positional) - base = parameterPosition; - else - { - base = currentParam; - currentParam = base + 1; - } - } - else - { - if (! positional) - currentParam = base + 1; - if (base > maxParam) - maxParam = base; - } - if (currentParam > maxParam) - maxParam = currentParam; - } - else - { - base = StrToLong(&format[index], &tmpformat, BASE_DECIMAL); - if (base > MAX_BASE) - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - index = (int)(tmpformat - format); - } - } - else - { - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - } - break; /* QUALIFIER_DOT */ - - case QUALIFIER_PARAM: - type = TYPE_PRINT; - /* FALLTHROUGH */ - case QUALIFIER_STAR: - /* This has different meanings for print and scan */ - if (TYPE_PRINT == type) - { - /* Read with from parameter */ - flags |= (FLAGS_WIDTH | FLAGS_WIDTH_PARAMETER); - width = TrioGetPosition(format, &index); - if (width == NO_POSITION) - { - parameterPosition++; - if (positional) - width = parameterPosition; - else - { - width = currentParam; - currentParam = width + 1; - } - } - else - { - if (! positional) - currentParam = width + 1; - if (width > maxParam) - maxParam = width; - } - if (currentParam > maxParam) - maxParam = currentParam; - } - else - { - /* Scan, but do not store result */ - flags |= FLAGS_IGNORE; - } - - break; /* QUALIFIER_STAR */ - - case '0': - if (! (flags & FLAGS_LEFTADJUST)) - flags |= FLAGS_NILPADDING; - /* FALLTHROUGH */ - case '1': case '2': case '3': case '4': - case '5': case '6': case '7': case '8': case '9': - flags |= FLAGS_WIDTH; - /* &format[index - 1] is used to "rewind" the read - * character from format - */ - width = StrToLong(&format[index - 1], &tmpformat, BASE_DECIMAL); - index = (int)(tmpformat - format); - break; - - case QUALIFIER_SHORT: - if (flags & FLAGS_SHORTSHORT) - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - else if (flags & FLAGS_SHORT) - flags |= FLAGS_SHORTSHORT; - else - flags |= FLAGS_SHORT; - break; - - case QUALIFIER_LONG: - if (flags & FLAGS_QUAD) - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - else if (flags & FLAGS_LONG) - flags |= FLAGS_QUAD; - else - flags |= FLAGS_LONG; - break; - - case QUALIFIER_LONG_UPPER: - flags |= FLAGS_LONGDOUBLE; - break; - -#if defined(QUALIFIER_SIZE_T) - case QUALIFIER_SIZE_T: - flags |= FLAGS_SIZE_T; - /* Modify flags for later truncation of number */ - if (sizeof(size_t) == sizeof(trio_ulonglong_t)) - flags |= FLAGS_QUAD; - else if (sizeof(size_t) == sizeof(long)) - flags |= FLAGS_LONG; - break; -#endif - -#if defined(QUALIFIER_PTRDIFF_T) - case QUALIFIER_PTRDIFF_T: - flags |= FLAGS_PTRDIFF_T; - if (sizeof(ptrdiff_t) == sizeof(trio_ulonglong_t)) - flags |= FLAGS_QUAD; - else if (sizeof(ptrdiff_t) == sizeof(long)) - flags |= FLAGS_LONG; - break; -#endif - -#if defined(QUALIFIER_INTMAX_T) - case QUALIFIER_INTMAX_T: - flags |= FLAGS_INTMAX_T; - if (sizeof(trio_intmax_t) == sizeof(trio_ulonglong_t)) - flags |= FLAGS_QUAD; - else if (sizeof(trio_intmax_t) == sizeof(long)) - flags |= FLAGS_LONG; - break; -#endif - -#if defined(QUALIFIER_QUAD) - case QUALIFIER_QUAD: - flags |= FLAGS_QUAD; - break; -#endif - -#if defined(QUALIFIER_FIXED_SIZE) - case QUALIFIER_FIXED_SIZE: - if (flags & FLAGS_FIXED_SIZE) - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - - if (flags & (FLAGS_ALL_SIZES | FLAGS_LONGDOUBLE | - FLAGS_WIDECHAR | FLAGS_VARSIZE_PARAMETER)) - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - - if ((format[index] == '6') && - (format[index + 1] == '4')) - { - varsize = sizeof(trio_int64_t); - index += 2; - } - else if ((format[index] == '3') && - (format[index + 1] == '2')) - { - varsize = sizeof(trio_int32_t); - index += 2; - } - else if ((format[index] == '1') && - (format[index + 1] == '6')) - { - varsize = sizeof(trio_int16_t); - index += 2; - } - else if (format[index] == '8') - { - varsize = sizeof(trio_int8_t); - index++; - } - else - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - - flags |= FLAGS_FIXED_SIZE; - break; -#endif - -#ifdef QUALIFIER_ESCAPE - case QUALIFIER_ESCAPE: - switch (format[index++]) { - case 'U': escape = ESCAPE_ULM; break; - case 'X': escape = ESCAPE_XML; break; - case 'S': escape = ESCAPE_SQL; break; - default: return TRIO_ERROR_RETURN(TRIO_EINVAL,index); - } - break; -#endif - - -#if defined(QUALIFIER_WIDECHAR) - case QUALIFIER_WIDECHAR: - flags |= FLAGS_WIDECHAR; - break; -#endif - -#if defined(QUALIFIER_SIZE_T_UPPER) - case QUALIFIER_SIZE_T_UPPER: - break; -#endif - -#if defined(QUALIFIER_QUOTE) - case QUALIFIER_QUOTE: - flags |= FLAGS_QUOTE; - break; -#endif - -#if defined(QUALIFIER_STICKY) - case QUALIFIER_STICKY: - flags |= FLAGS_STICKY; - got_sticky = TRUE; - break; -#endif - -#if defined(QUALIFIER_VARSIZE) - case QUALIFIER_VARSIZE: - flags |= FLAGS_VARSIZE_PARAMETER; - parameterPosition++; - if (positional) - varsize = parameterPosition; - else - { - varsize = currentParam; - currentParam = varsize + 1; - } - if (currentParam > maxParam) - maxParam = currentParam; - break; -#endif - - default: - /* Bail out completely to make the error more obvious */ - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - } - } /* while qualifier */ - - /* - * Parameters only need the type and value. The value is - * read later. - */ - if (flags & FLAGS_WIDTH_PARAMETER) - { -#if TRIO_ERRORS - usedEntries[width] += 1; -#endif - parameters[pos].type = FORMAT_PARAMETER; - indices[width] = pos; - width = pos++; - } - if (flags & FLAGS_PRECISION_PARAMETER) - { -#if TRIO_ERRORS - usedEntries[precision] += 1; -#endif - parameters[pos].type = FORMAT_PARAMETER; - indices[precision] = pos; - precision = pos++; - } - if (flags & FLAGS_BASE_PARAMETER) - { -#if TRIO_ERRORS - usedEntries[base] += 1; -#endif - parameters[pos].type = FORMAT_PARAMETER; - indices[base] = pos; - base = pos++; - } - if (flags & FLAGS_VARSIZE_PARAMETER) - { -#if TRIO_ERRORS - usedEntries[varsize] += 1; -#endif - parameters[pos].type = FORMAT_PARAMETER; - indices[varsize] = pos; - varsize = pos++; - } - - indices[currentParam] = pos; - - switch (format[index++]) - { -#if defined(SPECIFIER_CHAR_UPPER) - case SPECIFIER_CHAR_UPPER: - flags |= FLAGS_WIDECHAR; - /* FALLTHROUGH */ -#endif - case SPECIFIER_CHAR: - if (flags & FLAGS_LONG) - flags |= FLAGS_WIDECHAR; - else if (flags & FLAGS_SHORT) - flags &= ~FLAGS_WIDECHAR; - parameters[pos].type = FORMAT_CHAR; - break; - -#if defined(SPECIFIER_STRING_UPPER) - case SPECIFIER_STRING_UPPER: - flags |= FLAGS_WIDECHAR; - /* FALLTHROUGH */ -#endif - case SPECIFIER_STRING: - if (flags & FLAGS_LONG) - flags |= FLAGS_WIDECHAR; - else if (flags & FLAGS_SHORT) - flags &= ~FLAGS_WIDECHAR; - parameters[pos].type = FORMAT_STRING; - break; - - - case SPECIFIER_GROUP: - if (TYPE_SCAN == type) - { - int depth = 1; - parameters[pos].type = FORMAT_GROUP; - if (format[index] == QUALIFIER_CIRCUMFLEX) - index++; - if (format[index] == SPECIFIER_UNGROUP) - index++; - if (format[index] == QUALIFIER_MINUS) - index++; - /* Skip nested brackets */ - while (format[index] != NIL) - { - if (format[index] == SPECIFIER_GROUP) - { - depth++; - } - else if (format[index] == SPECIFIER_UNGROUP) - { - if (--depth <= 0) - { - index++; - break; - } - } - index++; - } - } - break; - - case SPECIFIER_INTEGER: - parameters[pos].type = FORMAT_INT; - break; - - case SPECIFIER_UNSIGNED: - flags |= FLAGS_UNSIGNED; - parameters[pos].type = FORMAT_INT; - break; - - case SPECIFIER_DECIMAL: - /* Disable base modifier */ - flags &= ~FLAGS_BASE_PARAMETER; - base = BASE_DECIMAL; - parameters[pos].type = FORMAT_INT; - break; - - case SPECIFIER_OCTAL: - flags &= ~FLAGS_BASE_PARAMETER; - base = BASE_OCTAL; - parameters[pos].type = FORMAT_INT; - break; - -#if defined(SPECIFIER_BINARY) - case SPECIFIER_BINARY_UPPER: - flags |= FLAGS_UPPER; - /* FALLTHROUGH */ - case SPECIFIER_BINARY: - flags |= FLAGS_NILPADDING; - flags &= ~FLAGS_BASE_PARAMETER; - base = BASE_BINARY; - parameters[pos].type = FORMAT_INT; - break; -#endif - - case SPECIFIER_HEX_UPPER: - flags |= FLAGS_UPPER; - /* FALLTHROUGH */ - case SPECIFIER_HEX: - flags |= FLAGS_UNSIGNED; - flags &= ~FLAGS_BASE_PARAMETER; - base = BASE_HEX; - parameters[pos].type = FORMAT_INT; - break; - - case SPECIFIER_FLOAT_E_UPPER: - flags |= FLAGS_UPPER; - /* FALLTHROUGH */ - case SPECIFIER_FLOAT_E: - flags |= FLAGS_FLOAT_E; - parameters[pos].type = FORMAT_DOUBLE; - break; - - case SPECIFIER_FLOAT_G_UPPER: - flags |= FLAGS_UPPER; - /* FALLTHROUGH */ - case SPECIFIER_FLOAT_G: - flags |= FLAGS_FLOAT_G; - parameters[pos].type = FORMAT_DOUBLE; - break; - - case SPECIFIER_FLOAT_F_UPPER: - flags |= FLAGS_UPPER; - /* FALLTHROUGH */ - case SPECIFIER_FLOAT_F: - parameters[pos].type = FORMAT_DOUBLE; - break; - - case SPECIFIER_POINTER: - parameters[pos].type = FORMAT_POINTER; - break; - - case SPECIFIER_COUNT: - parameters[pos].type = FORMAT_COUNT; - break; - -#if defined(SPECIFIER_HEXFLOAT) -# if defined(SPECIFIER_HEXFLOAT_UPPER) - case SPECIFIER_HEXFLOAT_UPPER: - flags |= FLAGS_UPPER; - /* FALLTHROUGH */ -# endif - case SPECIFIER_HEXFLOAT: - base = BASE_HEX; - parameters[pos].type = FORMAT_DOUBLE; - break; -#endif - -#if defined(FORMAT_ERRNO) - case SPECIFIER_ERRNO: - parameters[pos].type = FORMAT_ERRNO; - break; -#endif - -#if defined(SPECIFIER_USER_DEFINED_BEGIN) - case SPECIFIER_USER_DEFINED_BEGIN: - { - unsigned int max; - int without_namespace = TRUE; - - parameters[pos].type = FORMAT_USER_DEFINED; - parameters[pos].user_name[0] = NIL; - tmpformat = (char *)&format[index]; - - while ((ch = format[index])) - { - index++; - if (ch == SPECIFIER_USER_DEFINED_END) - { - if (without_namespace) - { - /* We must get the handle first */ - parameters[pos].type = FORMAT_PARAMETER; - parameters[pos].indexAfterSpecifier = index; - parameters[pos].flags = FLAGS_USER_DEFINED; - /* Adjust parameters for insertion of new one */ - pos++; -# if TRIO_ERRORS - usedEntries[currentParam] += 1; -# endif - parameters[pos].type = FORMAT_USER_DEFINED; - currentParam++; - indices[currentParam] = pos; - if (currentParam > maxParam) - maxParam = currentParam; - } - /* Copy the user data */ - max = (unsigned int)(&format[index] - tmpformat); - if (max > MAX_USER_DATA) - max = MAX_USER_DATA; - StrCopyMax(parameters[pos].user_data, - max, - tmpformat); - break; /* while */ - } - if (ch == SPECIFIER_USER_DEFINED_SEPARATOR) - { - without_namespace = FALSE; - /* Copy the namespace for later looking-up */ - max = (int)(&format[index] - tmpformat); - if (max > MAX_USER_NAME) - max = MAX_USER_NAME; - StrCopyMax(parameters[pos].user_name, - max, - tmpformat); - tmpformat = (char *)&format[index]; - } - } - if (ch != SPECIFIER_USER_DEFINED_END) - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - } - break; -#endif /* defined(SPECIFIER_USER_DEFINED_BEGIN) */ - - default: - /* Bail out completely to make the error more obvious */ - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - } - -#if TRIO_ERRORS - /* Count the number of times this entry has been used */ - usedEntries[currentParam] += 1; -#endif - - /* Find last sticky parameters */ - if (got_sticky && !(flags & FLAGS_STICKY)) - { - for (i = pos - 1; i >= 0; i--) - { - if (parameters[i].type == FORMAT_PARAMETER) - continue; - if ((parameters[i].flags & FLAGS_STICKY) && - (parameters[i].type == parameters[pos].type)) - { - /* Do not overwrite current qualifiers */ - flags |= (parameters[i].flags & (unsigned long)~FLAGS_STICKY); - if (width == NO_WIDTH) - width = parameters[i].width; - if (precision == NO_PRECISION) - precision = parameters[i].precision; - if (base == NO_BASE) - base = parameters[i].base; - break; - } - } - } - - parameters[pos].indexAfterSpecifier = index; - parameters[pos].flags = flags; - parameters[pos].width = width; - parameters[pos].precision = precision; - parameters[pos].base = (base == NO_BASE) ? BASE_DECIMAL : base; - parameters[pos].varsize = varsize; -#ifdef QUALIFIER_ESCAPE - parameters[pos].escape = escape; -#endif - pos++; - - if (! positional) - parameterPosition++; - - } /* if identifier */ - - } /* while format characters left */ - - for (num = 0; num <= maxParam; num++) - { -#if TRIO_ERRORS - if (usedEntries[num] != 1) - { - if (usedEntries[num] == 0) /* gap detected */ - return TRIO_ERROR_RETURN(TRIO_EGAP, num); - else /* double references detected */ - return TRIO_ERROR_RETURN(TRIO_EDBLREF, num); - } -#endif - - i = indices[num]; - - /* - * FORMAT_PARAMETERS are only present if they must be read, - * so it makes no sense to check the ignore flag (besides, - * the flags variable is not set for that particular type) - */ - if ((parameters[i].type != FORMAT_PARAMETER) && - (parameters[i].flags & FLAGS_IGNORE)) - continue; /* for all arguments */ - - /* - * The stack arguments are read according to ANSI C89 - * default argument promotions: - * - * char = int - * short = int - * unsigned char = unsigned int - * unsigned short = unsigned int - * float = double - * - * In addition to the ANSI C89 these types are read (the - * default argument promotions of C99 has not been - * considered yet) - * - * long long - * long double - * size_t - * ptrdiff_t - * intmax_t - */ - switch (parameters[i].type) - { - case FORMAT_GROUP: - case FORMAT_STRING: -#if TRIO_WIDECHAR - if (flags & FLAGS_WIDECHAR) - { - parameters[i].data.wstring = (argarray == NULL) - ? va_arg(arglist, wchar_t *) - : (wchar_t *)(argarray[num]); - } - else -#endif - { - parameters[i].data.string = (argarray == NULL) - ? va_arg(arglist, char *) - : (char *)(argarray[num]); - } - break; - - case FORMAT_POINTER: - case FORMAT_COUNT: - case FORMAT_USER_DEFINED: - case FORMAT_UNKNOWN: - parameters[i].data.pointer = (argarray == NULL) - ? va_arg(arglist, void *) - : argarray[num]; - break; - - case FORMAT_CHAR: - case FORMAT_INT: - if (TYPE_SCAN == type) - { - if (argarray == NULL) - parameters[i].data.pointer = - (trio_uintmax_t *)va_arg(arglist, void *); - else - { - if (parameters[i].type == FORMAT_CHAR) - parameters[i].data.pointer = - (trio_uintmax_t *)((char *)argarray[num]); - else if (parameters[i].flags & FLAGS_SHORT) - parameters[i].data.pointer = - (trio_uintmax_t *)((short *)argarray[num]); - else - parameters[i].data.pointer = - (trio_uintmax_t *)((int *)argarray[num]); - } - } - else - { -#if defined(QUALIFIER_VARSIZE) || defined(QUALIFIER_FIXED_SIZE) - if ((parameters[i].flags & FLAGS_VARSIZE_PARAMETER) || - (parameters[i].flags & FLAGS_FIXED_SIZE)) - { - if (parameters[i].flags & FLAGS_VARSIZE_PARAMETER) - { - /* - * Variable sizes are mapped onto the fixed sizes, in - * accordance with integer promotion. - * - * Please note that this may not be portable, as we - * only guess the size, not the layout of the numbers. - * For example, if int is little-endian, and long is - * big-endian, then this will fail. - */ - varsize = (int)parameters[parameters[i].varsize].data.number.as_unsigned; - } - else - { - /* Used for the I modifiers */ - varsize = parameters[i].varsize; - } - parameters[i].flags &= ~FLAGS_ALL_VARSIZES; - - if (varsize <= (int)sizeof(int)) - ; - else if (varsize <= (int)sizeof(long)) - parameters[i].flags |= FLAGS_LONG; -#if defined(QUALIFIER_INTMAX_T) - else if (varsize <= (int)sizeof(trio_longlong_t)) - parameters[i].flags |= FLAGS_QUAD; - else - parameters[i].flags |= FLAGS_INTMAX_T; -#else - else - parameters[i].flags |= FLAGS_QUAD; -#endif - } -#endif /* defined(QUALIFIER_VARSIZE) */ -#if defined(QUALIFIER_SIZE_T) || defined(QUALIFIER_SIZE_T_UPPER) - if (parameters[i].flags & FLAGS_SIZE_T) - parameters[i].data.number.as_unsigned = (argarray == NULL) - ? (trio_uintmax_t)va_arg(arglist, size_t) - : (trio_uintmax_t)(*((size_t *)argarray[num])); - else -#endif -#if defined(QUALIFIER_PTRDIFF_T) - if (parameters[i].flags & FLAGS_PTRDIFF_T) - parameters[i].data.number.as_unsigned = (argarray == NULL) - ? (trio_uintmax_t)va_arg(arglist, ptrdiff_t) - : (trio_uintmax_t)(*((ptrdiff_t *)argarray[num])); - else -#endif -#if defined(QUALIFIER_INTMAX_T) - if (parameters[i].flags & FLAGS_INTMAX_T) - parameters[i].data.number.as_unsigned = (argarray == NULL) - ? (trio_uintmax_t)va_arg(arglist, trio_intmax_t) - : (trio_uintmax_t)(*((trio_intmax_t *)argarray[num])); - else -#endif - if (parameters[i].flags & FLAGS_QUAD) - parameters[i].data.number.as_unsigned = (argarray == NULL) - ? (trio_uintmax_t)va_arg(arglist, trio_ulonglong_t) - : (trio_uintmax_t)(*((trio_ulonglong_t *)argarray[num])); - else if (parameters[i].flags & FLAGS_LONG) - parameters[i].data.number.as_unsigned = (argarray == NULL) - ? (trio_uintmax_t)va_arg(arglist, long) - : (trio_uintmax_t)(*((long *)argarray[num])); - else - { - if (argarray == NULL) - parameters[i].data.number.as_unsigned = (trio_uintmax_t)va_arg(arglist, int); - else - { - if (parameters[i].type == FORMAT_CHAR) - parameters[i].data.number.as_unsigned = (trio_uintmax_t)(*((char *)argarray[num])); - else if (parameters[i].flags & FLAGS_SHORT) - parameters[i].data.number.as_unsigned = (trio_uintmax_t)(*((short *)argarray[num])); - else - parameters[i].data.number.as_unsigned = (trio_uintmax_t)(*((int *)argarray[num])); - } - } - } - break; - - case FORMAT_PARAMETER: - /* - * The parameter for the user-defined specifier is a pointer, - * whereas the rest (width, precision, base) uses an integer. - */ - if (parameters[i].flags & FLAGS_USER_DEFINED) - parameters[i].data.pointer = (argarray == NULL) - ? va_arg(arglist, void *) - : argarray[num]; - else - parameters[i].data.number.as_unsigned = (argarray == NULL) - ? (trio_uintmax_t)va_arg(arglist, int) - : (trio_uintmax_t)(*((int *)argarray[num])); - break; - - case FORMAT_DOUBLE: - if (TYPE_SCAN == type) - { - if (parameters[i].flags & FLAGS_LONG) - parameters[i].data.longdoublePointer = (argarray == NULL) - ? va_arg(arglist, long double *) - : (long double *)((long double *)argarray[num]); - else - { - if (argarray == NULL) - parameters[i].data.doublePointer = - va_arg(arglist, double *); - else - { - if (parameters[i].flags & FLAGS_SHORT) - parameters[i].data.doublePointer = - (double *)((float *)argarray[num]); - else - parameters[i].data.doublePointer = - (double *)((double *)argarray[num]); - } - } - } - else - { - if (parameters[i].flags & FLAGS_LONG) - parameters[i].data.longdoubleNumber = (argarray == NULL) - ? va_arg(arglist, long double) - : (long double)(*((long double *)argarray[num])); - else - { - if (argarray == NULL) - parameters[i].data.longdoubleNumber = (long double)va_arg(arglist, double); - else - { - if (parameters[i].flags & FLAGS_SHORT) - parameters[i].data.longdoubleNumber = (long double)(*((float *)argarray[num])); - else - parameters[i].data.longdoubleNumber = (long double)(long double)(*((double *)argarray[num])); - } - } - } - break; - -#if defined(FORMAT_ERRNO) - case FORMAT_ERRNO: - parameters[i].data.errorNumber = errno; - break; -#endif - - default: - break; - } - } /* for all specifiers */ - return num; -} - - -/************************************************************************* - * - * @FORMATTING - * - ************************************************************************/ - - -/************************************************************************* - * TrioWriteNumber [private] - * - * Description: - * Output a number. - * The complexity of this function is a result of the complexity - * of the dependencies of the flags. - */ -static void -TrioWriteNumber(trio_T *self, - trio_uintmax_t number, - unsigned long flags, - int width, - int precision, - int base) -{ - BOOLEAN_T isNegative; - char buffer[MAX_CHARS_IN(trio_uintmax_t) * (1 + MAX_LOCALE_SEPARATOR_LENGTH) + 1]; - char *bufferend; - char *pointer; - const char *digits; - int i; - int length; - char *p; - int charsPerThousand; - int groupingIndex; - int count; - - assert(VALID(self)); - assert(VALID(self->OutStream)); - assert((base >= MIN_BASE && base <= MAX_BASE) || (base == NO_BASE)); - - digits = (flags & FLAGS_UPPER) ? internalDigitsUpper : internalDigitsLower; - - isNegative = (flags & FLAGS_UNSIGNED) - ? FALSE - : ((trio_intmax_t)number < 0); - if (isNegative) - number = -number; - - if (flags & FLAGS_QUAD) - number &= (trio_ulonglong_t)-1; - else if (flags & FLAGS_LONG) - number &= (unsigned long)-1; - else - number &= (unsigned int)-1; - - /* Build number */ - pointer = bufferend = &buffer[sizeof(buffer) - 1]; - *pointer-- = NIL; - charsPerThousand = (int)internalGrouping[0]; - groupingIndex = 1; - for (i = 1; i < (int)sizeof(buffer); i++) - { - *pointer-- = digits[number % base]; - number /= base; - if (number == 0) - break; - - if ((flags & FLAGS_QUOTE) - && (charsPerThousand != NO_GROUPING) - && (i % charsPerThousand == 0)) - { - /* - * We are building the number from the least significant - * to the most significant digit, so we have to copy the - * thousand separator backwards - */ - length = StrLength(internalThousandSeparator); - if (((int)(pointer - buffer) - length) > 0) - { - p = &internalThousandSeparator[length - 1]; - while (length-- > 0) - *pointer-- = *p--; - } - - /* Advance to next grouping number */ - switch (internalGrouping[groupingIndex]) - { - case CHAR_MAX: /* Disable grouping */ - charsPerThousand = NO_GROUPING; - break; - case 0: /* Repeat last group */ - break; - default: - charsPerThousand = (int)internalGrouping[groupingIndex++]; - break; - } - } - } - - /* Adjust width */ - width -= (bufferend - pointer) - 1; - - /* Adjust precision */ - if (NO_PRECISION != precision) - { - precision -= (bufferend - pointer) - 1; - if (precision < 0) - precision = 0; - flags |= FLAGS_NILPADDING; - } - - /* Adjust width further */ - if (isNegative || (flags & FLAGS_SHOWSIGN) || (flags & FLAGS_SPACE)) - width--; - if (flags & FLAGS_ALTERNATIVE) - { - switch (base) - { - case BASE_BINARY: - case BASE_HEX: - width -= 2; - break; - case BASE_OCTAL: - width--; - break; - default: - break; - } - } - - /* Output prefixes spaces if needed */ - if (! ((flags & FLAGS_LEFTADJUST) || - ((flags & FLAGS_NILPADDING) && (precision == NO_PRECISION)))) - { - count = (precision == NO_PRECISION) ? 0 : precision; - while (width-- > count) - self->OutStream(self, CHAR_ADJUST); - } - - /* width has been adjusted for signs and alternatives */ - if (isNegative) - self->OutStream(self, '-'); - else if (flags & FLAGS_SHOWSIGN) - self->OutStream(self, '+'); - else if (flags & FLAGS_SPACE) - self->OutStream(self, ' '); - - if (flags & FLAGS_ALTERNATIVE) - { - switch (base) - { - case BASE_BINARY: - self->OutStream(self, '0'); - self->OutStream(self, (flags & FLAGS_UPPER) ? 'B' : 'b'); - break; - - case BASE_OCTAL: - self->OutStream(self, '0'); - break; - - case BASE_HEX: - self->OutStream(self, '0'); - self->OutStream(self, (flags & FLAGS_UPPER) ? 'X' : 'x'); - break; - - default: - break; - } /* switch base */ - } - - /* Output prefixed zero padding if needed */ - if (flags & FLAGS_NILPADDING) - { - if (precision == NO_PRECISION) - precision = width; - while (precision-- > 0) - { - self->OutStream(self, '0'); - width--; - } - } - - /* Output the number itself */ - while (*(++pointer)) - { - self->OutStream(self, *pointer); - } - - /* Output trailing spaces if needed */ - if (flags & FLAGS_LEFTADJUST) - { - while (width-- > 0) - self->OutStream(self, CHAR_ADJUST); - } -} - -/************************************************************************* - * TrioWriteStringCharacter [private] - * - * Description: - * Output a single character of a string - */ -static void -TrioWriteStringCharacter(trio_T *self, - int ch, - unsigned long flags) -{ - if (flags & FLAGS_ALTERNATIVE) - { - if (! (isprint(ch) || isspace(ch))) - { - /* - * Non-printable characters are converted to C escapes or - * \number, if no C escape exists. - */ - self->OutStream(self, CHAR_BACKSLASH); - switch (ch) - { - case '\007': self->OutStream(self, 'a'); break; - case '\b': self->OutStream(self, 'b'); break; - case '\f': self->OutStream(self, 'f'); break; - case '\n': self->OutStream(self, 'n'); break; - case '\r': self->OutStream(self, 'r'); break; - case '\t': self->OutStream(self, 't'); break; - case '\v': self->OutStream(self, 'v'); break; - case '\\': self->OutStream(self, '\\'); break; - default: - self->OutStream(self, 'x'); - TrioWriteNumber(self, (trio_intmax_t)ch, - FLAGS_UNSIGNED | FLAGS_NILPADDING, - 2, 2, BASE_HEX); - break; - } - } - else if (ch == CHAR_BACKSLASH) - { - self->OutStream(self, CHAR_BACKSLASH); - self->OutStream(self, CHAR_BACKSLASH); - } - else - { - self->OutStream(self, ch); - } - } - else - { - self->OutStream(self, ch); - } -} - -/************************************************************************* - * TrioWriteString [private] - * - * Description: - * Output a string - */ -static void -TrioWriteString(trio_T *self, - const char *string, - unsigned long flags, - int width, - int precision) -{ - int length; - int ch; - - assert(VALID(self)); - assert(VALID(self->OutStream)); - - if (string == NULL) - { - string = null; - length = sizeof(null) - 1; - /* Disable quoting for the null pointer */ - flags &= (~FLAGS_QUOTE); - width = 0; - } - else - { - length = StrLength(string); - } - if ((NO_PRECISION != precision) && - (precision < length)) - { - length = precision; - } - width -= length; - - if (flags & FLAGS_QUOTE) - self->OutStream(self, CHAR_QUOTE); - - if (! (flags & FLAGS_LEFTADJUST)) - { - while (width-- > 0) - self->OutStream(self, CHAR_ADJUST); - } - - while (length-- > 0) - { - /* The ctype parameters must be an unsigned char (or EOF) */ - ch = (int)((unsigned char)(*string++)); - TrioWriteStringCharacter(self, ch, flags); - } - - if (flags & FLAGS_LEFTADJUST) - { - while (width-- > 0) - self->OutStream(self, CHAR_ADJUST); - } - if (flags & FLAGS_QUOTE) - self->OutStream(self, CHAR_QUOTE); -} - -/************************************************************************* - * TrioWriteWideStringCharacter [private] - * - * Description: - * Output a wide string as a multi-byte sequence - */ -#if TRIO_WIDECHAR -static int -TrioWriteWideStringCharacter(trio_T *self, - wchar_t wch, - unsigned long flags, - int width) -{ - int size; - int i; - int ch; - char *string; - char buffer[MB_LEN_MAX + 1]; - - if (width == NO_WIDTH) - width = sizeof(buffer); - - size = wctomb(buffer, wch); - if ((size <= 0) || (size > width) || (buffer[0] == NIL)) - return 0; - - string = buffer; - i = size; - while ((width >= i) && (width-- > 0) && (i-- > 0)) - { - /* The ctype parameters must be an unsigned char (or EOF) */ - ch = (int)((unsigned char)(*string++)); - TrioWriteStringCharacter(self, ch, flags); - } - return size; -} -#endif /* TRIO_WIDECHAR */ - -/************************************************************************* - * TrioWriteString [private] - * - * Description: - * Output a wide character string as a multi-byte string - */ -#if TRIO_WIDECHAR -static void -TrioWriteWideString(trio_T *self, - const wchar_t *wstring, - unsigned long flags, - int width, - int precision) -{ - int length; - int size; - - assert(VALID(self)); - assert(VALID(self->OutStream)); - -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - mblen(NULL, 0); -#endif - - if (wstring == NULL) - { - TrioWriteString(self, NULL, flags, width, precision); - return; - } - - if (NO_PRECISION == precision) - { - length = INT_MAX; - } - else - { - length = precision; - width -= length; - } - - if (flags & FLAGS_QUOTE) - self->OutStream(self, CHAR_QUOTE); - - if (! (flags & FLAGS_LEFTADJUST)) - { - while (width-- > 0) - self->OutStream(self, CHAR_ADJUST); - } - - while (length > 0) - { - size = TrioWriteWideStringCharacter(self, *wstring++, flags, length); - if (size == 0) - break; /* while */ - length -= size; - } - - if (flags & FLAGS_LEFTADJUST) - { - while (width-- > 0) - self->OutStream(self, CHAR_ADJUST); - } - if (flags & FLAGS_QUOTE) - self->OutStream(self, CHAR_QUOTE); -} -#endif /* TRIO_WIDECHAR */ - -/************************************************************************* - * TrioWriteDouble [private] - */ -static void -TrioWriteDouble(trio_T *self, - long double longdoubleNumber, - unsigned long flags, - int width, - int precision, - int base) -{ - int charsPerThousand; - int length; - double number; - double workNumber; - int integerDigits; - int fractionDigits; - int exponentDigits; - int expectedWidth; - int exponent; - unsigned int uExponent = 0; - double dblBase; - BOOLEAN_T isNegative; - BOOLEAN_T isExponentNegative = FALSE; - BOOLEAN_T isHex; - const char *digits; - char numberBuffer[MAX_MANTISSA_DIGITS - * (1 + MAX_LOCALE_SEPARATOR_LENGTH) + 1]; - char *numberPointer; - char exponentBuffer[MAX_EXPONENT_DIGITS + 1]; - char *exponentPointer = NULL; - int groupingIndex; - char *work; - int i; - BOOLEAN_T onlyzero; - int zeroes = 0; - - assert(VALID(self)); - assert(VALID(self->OutStream)); - assert(base == BASE_DECIMAL || base == BASE_HEX); - - number = (double)longdoubleNumber; - - /* Look for infinite numbers and non-a-number first */ - switch (TrioIsInfinite(number)) - { - case 1: - /* Positive infinity */ - TrioWriteString(self, - (flags & FLAGS_UPPER) - ? INFINITE_UPPER - : INFINITE_LOWER, - flags, width, precision); - return; - - case -1: - /* Negative infinity */ - TrioWriteString(self, - (flags & FLAGS_UPPER) - ? "-" INFINITE_UPPER - : "-" INFINITE_LOWER, - flags, width, precision); - return; - - default: - /* Finitude */ - break; - } - if (TrioIsNan(number)) - { - TrioWriteString(self, - (flags & FLAGS_UPPER) - ? NAN_UPPER - : NAN_LOWER, - flags, width, precision); - return; - } - - /* Normal numbers */ - digits = (flags & FLAGS_UPPER) ? internalDigitsUpper : internalDigitsLower; - isHex = (base == BASE_HEX); - dblBase = (double)base; - - if (precision == NO_PRECISION) - precision = FLT_DIG; - - isNegative = (number < 0.0); - if (isNegative) - number = -number; - - if ((flags & FLAGS_FLOAT_G) || isHex) - { - if (precision == 0) - precision = 1; - - if ((number < 1.0e-4) || (number > pow(10.0, (double)precision))) - { - /* Use scientific notation */ - flags |= FLAGS_FLOAT_E; - } - else if (number < 1.0) - { - /* - * Use normal notation. If the integer part of the number is - * zero, then adjust the precision to include leading fractional - * zeros. - */ - workNumber = fabs(guarded_log10(number)); - if (workNumber - floor(workNumber) < 0.001) - workNumber--; - zeroes = (int)floor(workNumber); - } - } - - if (flags & FLAGS_FLOAT_E) - { - /* Scale the number */ - workNumber = guarded_log10(number); - if (workNumber == -HUGE_VAL) - { - exponent = 0; - /* Undo setting */ - if (flags & FLAGS_FLOAT_G) - flags &= ~FLAGS_FLOAT_E; - } - else - { - exponent = (int)floor(workNumber); - number /= pow(10.0, (double)exponent); - isExponentNegative = (exponent < 0); - uExponent = (isExponentNegative) ? -exponent : exponent; - /* No thousand separators */ - flags &= ~FLAGS_QUOTE; - } - } - - /* - * Truncated number. - * - * precision is number of significant digits for FLOAT_G - * and number of fractional digits for others - */ - integerDigits = (floor(number) > DBL_EPSILON) - ? 1 + (int)guarded_log10(floor(number)) - : 1; - fractionDigits = ((flags & FLAGS_FLOAT_G) && (zeroes == 0)) - ? precision - integerDigits - : zeroes + precision; - - number = floor(0.5 + number * pow(dblBase, (double)fractionDigits)); - workNumber = (isHex - ? guarded_log16(0.5 + number) - : guarded_log10(0.5 + number)); - if ((int)workNumber + 1 > integerDigits + fractionDigits) - { - if (flags & FLAGS_FLOAT_E) - { - /* Adjust if number was rounded up one digit (ie. 0.99 to 1.00) */ - exponent--; - uExponent -= (isExponentNegative) ? 1 : -1; - number /= dblBase; - } - else - { - /* Adjust if number was rounded up one digit (ie. 99 to 100) */ - integerDigits++; - } - } - - /* Build the fraction part */ - numberPointer = &numberBuffer[sizeof(numberBuffer) - 1]; - *numberPointer = NIL; - onlyzero = TRUE; - for (i = 0; i < fractionDigits; i++) - { - *(--numberPointer) = digits[(int)fmod(number, dblBase)]; - number = floor(number / dblBase); - - if ((flags & FLAGS_FLOAT_G) && !(flags & FLAGS_ALTERNATIVE)) - { - /* Prune trailing zeroes */ - if (numberPointer[0] != digits[0]) - onlyzero = FALSE; - else if (onlyzero && (numberPointer[0] == digits[0])) - numberPointer++; - } - else - onlyzero = FALSE; - } - - /* Insert decimal point */ - if ((flags & FLAGS_ALTERNATIVE) || ((fractionDigits > 0) && !onlyzero)) - { - i = StrLength(internalDecimalPoint); - while (i> 0) - { - *(--numberPointer) = internalDecimalPoint[--i]; - } - } - /* Insert the integer part and thousand separators */ - charsPerThousand = (int)internalGrouping[0]; - groupingIndex = 1; - for (i = 1; i < integerDigits + 1; i++) - { - *(--numberPointer) = digits[(int)fmod(number, dblBase)]; - number = floor(number / dblBase); - if (number < DBL_EPSILON) - break; - - if ((i > 0) - && ((flags & (FLAGS_FLOAT_E | FLAGS_QUOTE)) == FLAGS_QUOTE) - && (charsPerThousand != NO_GROUPING) - && (i % charsPerThousand == 0)) - { - /* - * We are building the number from the least significant - * to the most significant digit, so we have to copy the - * thousand separator backwards - */ - length = StrLength(internalThousandSeparator); - integerDigits += length; - if (((int)(numberPointer - numberBuffer) - length) > 0) - { - work = &internalThousandSeparator[length - 1]; - while (length-- > 0) - *(--numberPointer) = *work--; - } - - /* Advance to next grouping number */ - if (charsPerThousand != NO_GROUPING) - { - switch (internalGrouping[groupingIndex]) - { - case CHAR_MAX: /* Disable grouping */ - charsPerThousand = NO_GROUPING; - break; - case 0: /* Repeat last group */ - break; - default: - charsPerThousand = (int)internalGrouping[groupingIndex++]; - break; - } - } - } - } - - /* Build the exponent */ - exponentDigits = 0; - if (flags & FLAGS_FLOAT_E) - { - exponentPointer = &exponentBuffer[sizeof(exponentBuffer) - 1]; - *exponentPointer-- = NIL; - do { - *exponentPointer-- = digits[uExponent % base]; - uExponent /= base; - exponentDigits++; - } while (uExponent); - } - - /* - * Calculate expected width. - * sign + integer part + thousands separators + decimal point - * + fraction + exponent - */ - expectedWidth = StrLength(numberPointer); - if (isNegative || (flags & FLAGS_SHOWSIGN)) - expectedWidth += sizeof("-") - 1; - if (exponentDigits > 0) - expectedWidth += exponentDigits + - ((exponentDigits > 1) ? sizeof("E+") : sizeof("E+0")) - 1; - if (isHex) - expectedWidth += sizeof("0X") - 1; - - /* Output prefixing */ - if (flags & FLAGS_NILPADDING) - { - /* Leading zeros must be after sign */ - if (isNegative) - self->OutStream(self, '-'); - else if (flags & FLAGS_SHOWSIGN) - self->OutStream(self, '+'); - if (isHex) - { - self->OutStream(self, '0'); - self->OutStream(self, (flags & FLAGS_UPPER) ? 'X' : 'x'); - } - if (!(flags & FLAGS_LEFTADJUST)) - { - for (i = expectedWidth; i < width; i++) - { - self->OutStream(self, '0'); - } - } - } - else - { - /* Leading spaces must be before sign */ - if (!(flags & FLAGS_LEFTADJUST)) - { - for (i = expectedWidth; i < width; i++) - { - self->OutStream(self, CHAR_ADJUST); - } - } - if (isNegative) - self->OutStream(self, '-'); - else if (flags & FLAGS_SHOWSIGN) - self->OutStream(self, '+'); - if (isHex) - { - self->OutStream(self, '0'); - self->OutStream(self, (flags & FLAGS_UPPER) ? 'X' : 'x'); - } - } - /* Output number */ - for (i = 0; numberPointer[i]; i++) - { - self->OutStream(self, numberPointer[i]); - } - /* Output exponent */ - if (exponentDigits > 0) - { - self->OutStream(self, - isHex - ? ((flags & FLAGS_UPPER) ? 'P' : 'p') - : ((flags & FLAGS_UPPER) ? 'E' : 'e')); - self->OutStream(self, (isExponentNegative) ? '-' : '+'); - - /* The exponent must contain at least two digits */ - if (exponentDigits == 1) - self->OutStream(self, '0'); - - for (i = 0; i < exponentDigits; i++) - { - self->OutStream(self, exponentPointer[i + 1]); - } - } - /* Output trailing spaces */ - if (flags & FLAGS_LEFTADJUST) - { - for (i = expectedWidth; i < width; i++) - { - self->OutStream(self, CHAR_ADJUST); - } - } -} - -/************************************************************************* - * TrioFormatProcess [private] - */ -static int -TrioFormatProcess(trio_T *data, - const char *format, - parameter_T *parameters) - -{ -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - int charlen; -#endif - int i; - const char *string; - void *pointer; - unsigned long flags; - int width; - int precision; - int base; - int index; - - index = 0; - i = 0; -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - mblen(NULL, 0); -#endif - - while (format[index]) - { -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - if (! isascii(format[index])) - { - charlen = mblen(&format[index], MB_LEN_MAX); - while (charlen-- > 0) - { - data->OutStream(data, format[index++]); - } - continue; /* while */ - } -#endif /* TRIO_COMPILER_SUPPORTS_MULTIBYTE */ - if (CHAR_IDENTIFIER == format[index]) - { - if (CHAR_IDENTIFIER == format[index + 1]) - { - data->OutStream(data, CHAR_IDENTIFIER); - index += 2; - } - else - { - /* Skip the parameter entries */ - while (parameters[i].type == FORMAT_PARAMETER) - i++; - - flags = parameters[i].flags; - - /* Find width */ - width = parameters[i].width; - if (flags & FLAGS_WIDTH_PARAMETER) - { - /* Get width from parameter list */ - width = (int)parameters[width].data.number.as_signed; - } - - /* Find precision */ - if (flags & FLAGS_PRECISION) - { - precision = parameters[i].precision; - if (flags & FLAGS_PRECISION_PARAMETER) - { - /* Get precision from parameter list */ - precision = (int)parameters[precision].data.number.as_signed; - } - } - else - { - precision = NO_PRECISION; - } - - /* Find base */ - base = parameters[i].base; - if (flags & FLAGS_BASE_PARAMETER) - { - /* Get base from parameter list */ - base = (int)parameters[base].data.number.as_signed; - } - - switch (parameters[i].type) - { - case FORMAT_CHAR: - if (flags & FLAGS_QUOTE) - data->OutStream(data, CHAR_QUOTE); - if (! (flags & FLAGS_LEFTADJUST)) - { - while (--width > 0) - data->OutStream(data, CHAR_ADJUST); - } -#if TRIO_WIDECHAR - if (flags & FLAGS_WIDECHAR) - { - TrioWriteWideStringCharacter(data, - (wchar_t)parameters[i].data.number.as_signed, - flags, - NO_WIDTH); - } - else -#endif - TrioWriteStringCharacter(data, - (int)parameters[i].data.number.as_signed, - flags); - - if (flags & FLAGS_LEFTADJUST) - { - while(--width > 0) - data->OutStream(data, CHAR_ADJUST); - } - if (flags & FLAGS_QUOTE) - data->OutStream(data, CHAR_QUOTE); - - break; /* FORMAT_CHAR */ - - case FORMAT_INT: - if (base == NO_BASE) - base = BASE_DECIMAL; - - TrioWriteNumber(data, - parameters[i].data.number.as_signed, - flags, - width, - precision, - base); - - break; /* FORMAT_INT */ - - case FORMAT_DOUBLE: - TrioWriteDouble(data, - parameters[i].data.longdoubleNumber, - flags, - width, - precision, - base); - break; /* FORMAT_DOUBLE */ - - case FORMAT_STRING: -#if TRIO_WIDECHAR - if (flags & FLAGS_WIDECHAR) - { - TrioWriteWideString(data, - parameters[i].data.wstring, - flags, - width, - precision); - } - else -#endif -#ifdef QUALIFIER_ESCAPE - { - char *s = NULL; - static const char* empty = "(null)"; - switch (parameters[i].escape) - { - case ESCAPE_ULM: - s = glite_lbu_EscapeULM(parameters[i].data.string); - break; - case ESCAPE_XML: - s = glite_lbu_EscapeXML(parameters[i].data.string); - break; - case ESCAPE_SQL: - s = glite_lbu_EscapeSQL(parameters[i].data.string); - break; - case ESCAPE_NONE: - s = strdup(parameters[i].data.string ? parameters[i].data.string : empty); - break; - } - TrioWriteString(data,s,flags,width,precision); - free(s); - } -#else - { - TrioWriteString(data, - parameters[i].data.string, - flags, - width, - precision); - } -#endif - break; /* FORMAT_STRING */ - - case FORMAT_POINTER: - { - reference_T reference; - - reference.data = data; - reference.parameter = ¶meters[i]; - trio_print_pointer(&reference, parameters[i].data.pointer); - } - break; /* FORMAT_POINTER */ - - case FORMAT_COUNT: - pointer = parameters[i].data.pointer; - if (NULL != pointer) - { - /* - * C99 paragraph 7.19.6.1.8 says "the number of - * characters written to the output stream so far by - * this call", which is data->committed - */ -#if defined(QUALIFIER_SIZE_T) || defined(QUALIFIER_SIZE_T_UPPER) - if (flags & FLAGS_SIZE_T) - *(size_t *)pointer = (size_t)data->committed; - else -#endif -#if defined(QUALIFIER_PTRDIFF_T) - if (flags & FLAGS_PTRDIFF_T) - *(ptrdiff_t *)pointer = (ptrdiff_t)data->committed; - else -#endif -#if defined(QUALIFIER_INTMAX_T) - if (flags & FLAGS_INTMAX_T) - *(trio_intmax_t *)pointer = (trio_intmax_t)data->committed; - else -#endif - if (flags & FLAGS_QUAD) - { - *(trio_ulonglong_t *)pointer = (trio_ulonglong_t)data->committed; - } - else if (flags & FLAGS_LONG) - { - *(long int *)pointer = (long int)data->committed; - } - else if (flags & FLAGS_SHORT) - { - *(short int *)pointer = (short int)data->committed; - } - else - { - *(int *)pointer = (int)data->committed; - } - } - break; /* FORMAT_COUNT */ - - case FORMAT_PARAMETER: - break; /* FORMAT_PARAMETER */ - -#if defined(FORMAT_ERRNO) - case FORMAT_ERRNO: - string = StrError(parameters[i].data.errorNumber); - if (string) - { - TrioWriteString(data, - string, - flags, - width, - precision); - } - else - { - data->OutStream(data, '#'); - TrioWriteNumber(data, - (trio_intmax_t)parameters[i].data.errorNumber, - flags, - width, - precision, - BASE_DECIMAL); - } - break; /* FORMAT_ERRNO */ -#endif /* defined(FORMAT_ERRNO) */ - -#if defined(FORMAT_USER_DEFINED) - case FORMAT_USER_DEFINED: - { - reference_T reference; - userdef_T *def = NULL; - - if (parameters[i].user_name[0] == NIL) - { - /* Use handle */ - if ((i > 0) || - (parameters[i - 1].type == FORMAT_PARAMETER)) - def = (userdef_T *)parameters[i - 1].data.pointer; - } - else - { - /* Look up namespace */ - def = TrioFindNamespace(parameters[i].user_name, NULL); - } - if (def) { - reference.data = data; - reference.parameter = ¶meters[i]; - def->callback(&reference); - } - } - break; -#endif /* defined(FORMAT_USER_DEFINED) */ - - default: - break; - } /* switch parameter type */ - - /* Prepare for next */ - index = parameters[i].indexAfterSpecifier; - i++; - } - } - else /* not identifier */ - { - data->OutStream(data, format[index++]); - } - } - return data->processed; -} - -/************************************************************************* - * TrioFormatRef [private] - */ -static int -TrioFormatRef(reference_T *reference, - const char *format, - va_list arglist, - void **argarray) -{ - int status; - parameter_T parameters[MAX_PARAMETERS]; - - status = TrioPreprocess(TYPE_PRINT, format, parameters, arglist, argarray); - if (status < 0) - return status; - - return TrioFormatProcess(reference->data, format, parameters); -} - -/************************************************************************* - * TrioFormat [private] - * - * Description: - * This is the main engine for formatting output - */ -static int -TrioFormat(void *destination, - size_t destinationSize, - void (*OutStream)(trio_T *, int), - const char *format, - va_list arglist, - void **argarray) -{ - int status; - trio_T data; - parameter_T parameters[MAX_PARAMETERS]; - - assert(VALID(OutStream)); - assert(VALID(format)); - - memset(&data, 0, sizeof(data)); - data.OutStream = OutStream; - data.location = destination; - data.max = destinationSize; - -#if defined(USE_LOCALE) - if (NULL == internalLocaleValues) - { - TrioSetLocale(); - } -#endif - - status = TrioPreprocess(TYPE_PRINT, format, parameters, arglist, argarray); - if (status < 0) - return status; - - return TrioFormatProcess(&data, format, parameters); -} - -/************************************************************************* - * TrioOutStreamFile [private] - */ -static void -TrioOutStreamFile(trio_T *self, - int output) -{ - FILE *file = (FILE *)self->location; - - assert(VALID(self)); - assert(VALID(file)); - - self->processed++; - self->committed++; - (void)fputc(output, file); -} - -/************************************************************************* - * TrioOutStreamFileDescriptor [private] - */ -static void -TrioOutStreamFileDescriptor(trio_T *self, - int output) -{ - int fd = *((int *)self->location); - char ch; - - assert(VALID(self)); - - ch = (char)output; - (void)write(fd, &ch, sizeof(char)); - self->processed++; - self->committed++; -} - -/************************************************************************* - * TrioOutStreamString [private] - */ -static void -TrioOutStreamString(trio_T *self, - int output) -{ - char **buffer = (char **)self->location; - - assert(VALID(self)); - assert(VALID(buffer)); - - **buffer = (char)output; - (*buffer)++; - self->processed++; - self->committed++; -} - -/************************************************************************* - * TrioOutStreamStringMax [private] - */ -static void -TrioOutStreamStringMax(trio_T *self, - int output) -{ - char **buffer; - - assert(VALID(self)); - buffer = (char **)self->location; - assert(VALID(buffer)); - - if (self->processed < self->max) - { - **buffer = (char)output; - (*buffer)++; - self->committed++; - } - self->processed++; -} - -/************************************************************************* - * TrioOutStreamStringDynamic [private] - */ -#define DYNAMIC_START_SIZE 32 -struct dynamicBuffer { - char *buffer; - size_t length; - size_t allocated; -}; - -static void -TrioOutStreamStringDynamic(trio_T *self, - int output) -{ - struct dynamicBuffer *infop; - - assert(VALID(self)); - assert(VALID(self->location)); - - infop = (struct dynamicBuffer *)self->location; - - if (infop->buffer == NULL) - { - /* Start with a reasonable size */ - infop->buffer = (char *)TRIO_MALLOC(DYNAMIC_START_SIZE); - if (infop->buffer == NULL) - return; /* fail */ - - infop->allocated = DYNAMIC_START_SIZE; - self->processed = 0; - self->committed = 0; - } - else if (self->committed + sizeof(NIL) >= infop->allocated) - { - char *newptr; - - /* Allocate increasing chunks */ - newptr = (char *)TRIO_REALLOC(infop->buffer, infop->allocated * 2); - - if (newptr == NULL) - return; - - infop->buffer = newptr; - infop->allocated *= 2; - } - - infop->buffer[self->committed] = (char)output; - self->committed++; - self->processed++; - - infop->length = self->committed; -} - -/************************************************************************* - * printf - */ -int -trio_printf(const char *format, - ...) -{ - int status; - va_list args; - - assert(VALID(format)); - - va_start(args, format); - status = TrioFormat(stdout, 0, TrioOutStreamFile, format, args, NULL); - va_end(args); - return status; -} - -int -trio_vprintf(const char *format, - va_list args) -{ - assert(VALID(format)); - - return TrioFormat(stdout, 0, TrioOutStreamFile, format, args, NULL); -} - -#ifdef __GNUC__ -#define UNUSED_VAR __attribute__((unused)) -#else -#define UNUSED_VAR -#endif - -static void shutup_unitialized(va_list *dummy UNUSED_VAR) { -} - -int -trio_printfv(const char *format, - void ** args) -{ - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(format)); - - return TrioFormat(stdout, 0, TrioOutStreamFile, format, dummy, args); -} - -/************************************************************************* - * fprintf - */ -int -trio_fprintf(FILE *file, - const char *format, - ...) -{ - int status; - va_list args; - - assert(VALID(file)); - assert(VALID(format)); - - va_start(args, format); - status = TrioFormat(file, 0, TrioOutStreamFile, format, args, NULL); - va_end(args); - return status; -} - -int -trio_vfprintf(FILE *file, - const char *format, - va_list args) -{ - assert(VALID(file)); - assert(VALID(format)); - - return TrioFormat(file, 0, TrioOutStreamFile, format, args, NULL); -} - -int -trio_fprintfv(FILE *file, - const char *format, - void ** args) -{ - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(file)); - assert(VALID(format)); - - return TrioFormat(file, 0, TrioOutStreamFile, format, dummy, args); -} - -/************************************************************************* - * dprintf - */ -int -trio_dprintf(int fd, - const char *format, - ...) -{ - int status; - va_list args; - - assert(VALID(format)); - - va_start(args, format); - status = TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, args, NULL); - va_end(args); - return status; -} - -int -trio_vdprintf(int fd, - const char *format, - va_list args) -{ - assert(VALID(format)); - - return TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, args, NULL); -} - -int -trio_dprintfv(int fd, - const char *format, - void **args) -{ - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(format)); - - return TrioFormat(&fd, 0, TrioOutStreamFileDescriptor, format, dummy, args); -} - -/************************************************************************* - * sprintf - */ -int -trio_sprintf(char *buffer, - const char *format, - ...) -{ - int status; - va_list args; - - assert(VALID(buffer)); - assert(VALID(format)); - - va_start(args, format); - status = TrioFormat(&buffer, 0, TrioOutStreamString, format, args, NULL); - *buffer = NIL; /* Terminate with NIL character */ - va_end(args); - return status; -} - -int -trio_vsprintf(char *buffer, - const char *format, - va_list args) -{ - int status; - - assert(VALID(buffer)); - assert(VALID(format)); - - status = TrioFormat(&buffer, 0, TrioOutStreamString, format, args, NULL); - *buffer = NIL; - return status; -} - -int -trio_sprintfv(char *buffer, - const char *format, - void **args) -{ - int status; - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(buffer)); - assert(VALID(format)); - - status = TrioFormat(&buffer, 0, TrioOutStreamString, format, dummy, args); - *buffer = NIL; - return status; -} - -/************************************************************************* - * snprintf - */ -int -trio_snprintf(char *buffer, - size_t bufferSize, - const char *format, - ...) -{ - int status; - va_list args; - - assert(VALID(buffer)); - assert(VALID(format)); - - va_start(args, format); - status = TrioFormat(&buffer, bufferSize > 0 ? bufferSize - 1 : 0, - TrioOutStreamStringMax, format, args, NULL); - if (bufferSize > 0) - *buffer = NIL; - va_end(args); - return status; -} - -int -trio_vsnprintf(char *buffer, - size_t bufferSize, - const char *format, - va_list args) -{ - int status; - - assert(VALID(buffer)); - assert(VALID(format)); - - status = TrioFormat(&buffer, bufferSize > 0 ? bufferSize - 1 : 0, - TrioOutStreamStringMax, format, args, NULL); - if (bufferSize > 0) - *buffer = NIL; - return status; -} - -int -trio_snprintfv(char *buffer, - size_t bufferSize, - const char *format, - void **args) -{ - int status; - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(buffer)); - assert(VALID(format)); - - status = TrioFormat(&buffer, bufferSize > 0 ? bufferSize - 1 : 0, - TrioOutStreamStringMax, format, dummy, args); - if (bufferSize > 0) - *buffer = NIL; - return status; -} - -/************************************************************************* - * snprintfcat - * Appends the new string to the buffer string overwriting the '\0' - * character at the end of buffer. - */ -int -trio_snprintfcat(char *buffer, - size_t bufferSize, - const char *format, - ...) -{ - int status; - va_list args; - size_t buf_len; - - va_start(args, format); - - assert(VALID(buffer)); - assert(VALID(format)); - - buf_len = strlen(buffer); - buffer = &buffer[buf_len]; - - status = TrioFormat(&buffer, bufferSize - 1 - buf_len, - TrioOutStreamStringMax, format, args, NULL); - va_end(args); - *buffer = NIL; - return status; -} - -int -trio_vsnprintfcat(char *buffer, - size_t bufferSize, - const char *format, - va_list args) -{ - int status; - size_t buf_len; - assert(VALID(buffer)); - assert(VALID(format)); - - buf_len = strlen(buffer); - buffer = &buffer[buf_len]; - status = TrioFormat(&buffer, bufferSize - 1 - buf_len, - TrioOutStreamStringMax, format, args, NULL); - *buffer = NIL; - return status; -} - -/************************************************************************* - * trio_aprintf - */ - -/* Deprecated */ -char * -trio_aprintf(const char *format, - ...) -{ - va_list args; - struct dynamicBuffer info; - - assert(VALID(format)); - - info.buffer = NULL; - info.length = 0; - info.allocated = 0; - - va_start(args, format); - (void)TrioFormat(&info, 0, TrioOutStreamStringDynamic, format, args, NULL); - va_end(args); - if (info.length) { - info.buffer[info.length] = NIL; /* we terminate this with a zero byte */ - return info.buffer; - } - else - return NULL; -} - -/* Deprecated */ -char * -trio_vaprintf(const char *format, - va_list args) -{ - struct dynamicBuffer info; - - assert(VALID(format)); - - info.buffer = NULL; - info.length = 0; - info.allocated = 0; - - (void)TrioFormat(&info, 0, TrioOutStreamStringDynamic, format, args, NULL); - if (info.length) { - info.buffer[info.length] = NIL; /* we terminate this with a zero byte */ - return info.buffer; - } - else - return NULL; -} - -int -trio_asprintf(char **result, - const char *format, - ...) -{ - va_list args; - int status; - struct dynamicBuffer info; - - assert(VALID(format)); - - info.buffer = NULL; - info.length = 0; - info.allocated = 0; - - va_start(args, format); - status = TrioFormat(&info, 0, TrioOutStreamStringDynamic, format, args, NULL); - va_end(args); - if (status < 0) { - *result = NULL; - return status; - } - if (info.length == 0) { - /* - * If the length is zero, no characters have been written and therefore - * no memory has been allocated, but we must to allocate and return an - * empty string. - */ - info.buffer = (char *)TRIO_MALLOC(sizeof(char)); - if (info.buffer == NULL) { - *result = NULL; - return TRIO_ERROR_RETURN(TRIO_ENOMEM, 0); - } - } - info.buffer[info.length] = NIL; /* we terminate this with a zero byte */ - *result = info.buffer; - - return status; -} - -int -trio_vasprintf(char **result, - const char *format, - va_list args) -{ - int status; - struct dynamicBuffer info; - - assert(VALID(format)); - - info.buffer = NULL; - info.length = 0; - info.allocated = 0; - - status = TrioFormat(&info, 0, TrioOutStreamStringDynamic, format, args, NULL); - if (status < 0) { - *result = NULL; - return status; - } - if (info.length == 0) { - info.buffer = (char *)TRIO_MALLOC(sizeof(char)); - if (info.buffer == NULL) { - *result = NULL; - return TRIO_ERROR_RETURN(TRIO_ENOMEM, 0); - } - } - info.buffer[info.length] = NIL; /* we terminate this with a zero byte */ - *result = info.buffer; - - return status; -} - - -/************************************************************************* - * - * @CALLBACK - * - ************************************************************************/ - - -/************************************************************************* - * trio_register [public] - */ -void * -trio_register(trio_callback_t callback, - const char *name) -{ - userdef_T *def; - userdef_T *prev = NULL; - - if (callback == NULL) - return NULL; - - if (name) - { - /* Handle built-in namespaces */ - if (name[0] == ':') - { - if (StrEqual(name, ":enter")) - { - internalEnterCriticalRegion = callback; - } - else if (StrEqual(name, ":leave")) - { - internalLeaveCriticalRegion = callback; - } - return NULL; - } - - /* Bail out if namespace is too long */ - if (StrLength(name) >= MAX_USER_NAME) - return NULL; - - /* Bail out if namespace already is registered */ - def = TrioFindNamespace(name, &prev); - if (def) - return NULL; - } - - def = (userdef_T *)TRIO_MALLOC(sizeof(userdef_T)); - if (def) - { - if (internalEnterCriticalRegion) - (void)internalEnterCriticalRegion(NULL); - - if (name) - { - /* Link into internal list */ - if (prev == NULL) - internalUserDef = def; - else - prev->next = def; - } - /* Initialize */ - def->callback = callback; - def->name = (name == NULL) - ? NULL - : StrDuplicate(name); - def->next = NULL; - - if (internalLeaveCriticalRegion) - (void)internalLeaveCriticalRegion(NULL); - } - return def; -} - -/************************************************************************* - * trio_unregister [public] - */ -void -trio_unregister(void *handle) -{ - userdef_T *self = (userdef_T *)handle; - userdef_T *def; - userdef_T *prev = NULL; - - assert(VALID(self)); - - if (self->name) - { - def = TrioFindNamespace(self->name, &prev); - if (def) - { - if (internalEnterCriticalRegion) - (void)internalEnterCriticalRegion(NULL); - - if (prev == NULL) - internalUserDef = NULL; - else - prev->next = def->next; - - if (internalLeaveCriticalRegion) - (void)internalLeaveCriticalRegion(NULL); - } - StrFree(self->name); - } - TRIO_FREE(self); -} - -/************************************************************************* - * trio_get_format [public] - */ -const char * -trio_get_format(void *ref) -{ - assert(((reference_T *)ref)->parameter->type == FORMAT_USER_DEFINED); - - return (((reference_T *)ref)->parameter->user_data); -} - -/************************************************************************* - * trio_get_argument [public] - */ -void * -trio_get_argument(void *ref) -{ - assert(((reference_T *)ref)->parameter->type == FORMAT_USER_DEFINED); - - return ((reference_T *)ref)->parameter->data.pointer; -} - -/************************************************************************* - * trio_get_width / trio_set_width [public] - */ -int -trio_get_width(void *ref) -{ - return ((reference_T *)ref)->parameter->width; -} - -void -trio_set_width(void *ref, - int width) -{ - ((reference_T *)ref)->parameter->width = width; -} - -/************************************************************************* - * trio_get_precision / trio_set_precision [public] - */ -int -trio_get_precision(void *ref) -{ - return (((reference_T *)ref)->parameter->precision); -} - -void -trio_set_precision(void *ref, - int precision) -{ - ((reference_T *)ref)->parameter->precision = precision; -} - -/************************************************************************* - * trio_get_base / trio_set_base [public] - */ -int -trio_get_base(void *ref) -{ - return (((reference_T *)ref)->parameter->base); -} - -void -trio_set_base(void *ref, - int base) -{ - ((reference_T *)ref)->parameter->base = base; -} - -/************************************************************************* - * trio_get_long / trio_set_long [public] - */ -int -trio_get_long(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_LONG); -} - -void -trio_set_long(void *ref, - int is_long) -{ - if (is_long) - ((reference_T *)ref)->parameter->flags |= FLAGS_LONG; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_LONG; -} - -/************************************************************************* - * trio_get_longlong / trio_set_longlong [public] - */ -int -trio_get_longlong(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_QUAD); -} - -void -trio_set_longlong(void *ref, - int is_longlong) -{ - if (is_longlong) - ((reference_T *)ref)->parameter->flags |= FLAGS_QUAD; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_QUAD; -} - -/************************************************************************* - * trio_get_longdouble / trio_set_longdouble [public] - */ -int -trio_get_longdouble(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_LONGDOUBLE); -} - -void -trio_set_longdouble(void *ref, - int is_longdouble) -{ - if (is_longdouble) - ((reference_T *)ref)->parameter->flags |= FLAGS_LONGDOUBLE; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_LONGDOUBLE; -} - -/************************************************************************* - * trio_get_short / trio_set_short [public] - */ -int -trio_get_short(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_SHORT); -} - -void -trio_set_short(void *ref, - int is_short) -{ - if (is_short) - ((reference_T *)ref)->parameter->flags |= FLAGS_SHORT; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_SHORT; -} - -/************************************************************************* - * trio_get_shortshort / trio_set_shortshort [public] - */ -int -trio_get_shortshort(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_SHORTSHORT); -} - -void -trio_set_shortshort(void *ref, - int is_shortshort) -{ - if (is_shortshort) - ((reference_T *)ref)->parameter->flags |= FLAGS_SHORTSHORT; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_SHORTSHORT; -} - -/************************************************************************* - * trio_get_alternative / trio_set_alternative [public] - */ -int -trio_get_alternative(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_ALTERNATIVE); -} - -void -trio_set_alternative(void *ref, - int is_alternative) -{ - if (is_alternative) - ((reference_T *)ref)->parameter->flags |= FLAGS_ALTERNATIVE; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_ALTERNATIVE; -} - -/************************************************************************* - * trio_get_alignment / trio_set_alignment [public] - */ -int -trio_get_alignment(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_LEFTADJUST); -} - -void -trio_set_alignment(void *ref, - int is_leftaligned) -{ - if (is_leftaligned) - ((reference_T *)ref)->parameter->flags |= FLAGS_LEFTADJUST; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_LEFTADJUST; -} - -/************************************************************************* - * trio_get_spacing /trio_set_spacing [public] - */ -int -trio_get_spacing(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_SPACE); -} - -void -trio_set_spacing(void *ref, - int is_space) -{ - if (is_space) - ((reference_T *)ref)->parameter->flags |= FLAGS_SPACE; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_SPACE; -} - -/************************************************************************* - * trio_get_sign / trio_set_sign [public] - */ -int -trio_get_sign(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_SHOWSIGN); -} - -void -trio_set_sign(void *ref, - int is_sign) -{ - if (is_sign) - ((reference_T *)ref)->parameter->flags |= FLAGS_SHOWSIGN; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_SHOWSIGN; -} - -/************************************************************************* - * trio_get_padding / trio_set_padding [public] - */ -int -trio_get_padding(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_NILPADDING); -} - -void -trio_set_padding(void *ref, - int is_padding) -{ - if (is_padding) - ((reference_T *)ref)->parameter->flags |= FLAGS_NILPADDING; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_NILPADDING; -} - -/************************************************************************* - * trio_get_quote / trio_set_quote [public] - */ -int -trio_get_quote(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_QUOTE); -} - -void -trio_set_quote(void *ref, - int is_quote) -{ - if (is_quote) - ((reference_T *)ref)->parameter->flags |= FLAGS_QUOTE; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_QUOTE; -} - -/************************************************************************* - * trio_get_upper / trio_set_upper [public] - */ -int -trio_get_upper(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_UPPER); -} - -void -trio_set_upper(void *ref, - int is_upper) -{ - if (is_upper) - ((reference_T *)ref)->parameter->flags |= FLAGS_UPPER; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_UPPER; -} - -/************************************************************************* - * trio_get_largest / trio_set_largest [public] - */ -#if TRIO_C99 -int -trio_get_largest(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_INTMAX_T); -} - -void -trio_set_largest(void *ref, - int is_largest) -{ - if (is_largest) - ((reference_T *)ref)->parameter->flags |= FLAGS_INTMAX_T; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_INTMAX_T; -} -#endif - -/************************************************************************* - * trio_get_ptrdiff / trio_set_ptrdiff [public] - */ -int -trio_get_ptrdiff(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_PTRDIFF_T); -} - -void -trio_set_ptrdiff(void *ref, - int is_ptrdiff) -{ - if (is_ptrdiff) - ((reference_T *)ref)->parameter->flags |= FLAGS_PTRDIFF_T; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_PTRDIFF_T; -} - -/************************************************************************* - * trio_get_size / trio_set_size [public] - */ -#if TRIO_C99 -int -trio_get_size(void *ref) -{ - return (((reference_T *)ref)->parameter->flags & FLAGS_SIZE_T); -} - -void -trio_set_size(void *ref, - int is_size) -{ - if (is_size) - ((reference_T *)ref)->parameter->flags |= FLAGS_SIZE_T; - else - ((reference_T *)ref)->parameter->flags &= ~FLAGS_SIZE_T; -} -#endif - -/************************************************************************* - * trio_print_int [public] - */ -void -trio_print_int(void *ref, - int number) -{ - reference_T *self = (reference_T *)ref; - - TrioWriteNumber(self->data, - (trio_intmax_t)number, - self->parameter->flags, - self->parameter->width, - self->parameter->precision, - self->parameter->base); -} - -/************************************************************************* - * trio_print_uint [public] - */ -void -trio_print_uint(void *ref, - unsigned int number) -{ - reference_T *self = (reference_T *)ref; - - TrioWriteNumber(self->data, - (trio_intmax_t)number, - self->parameter->flags | FLAGS_UNSIGNED, - self->parameter->width, - self->parameter->precision, - self->parameter->base); -} - -/************************************************************************* - * trio_print_double [public] - */ -void -trio_print_double(void *ref, - double number) -{ - reference_T *self = (reference_T *)ref; - - TrioWriteDouble(self->data, - number, - self->parameter->flags, - self->parameter->width, - self->parameter->precision, - self->parameter->base); -} - -/************************************************************************* - * trio_print_string [public] - */ -void -trio_print_string(void *ref, - char *string) -{ - reference_T *self = (reference_T *)ref; - - TrioWriteString(self->data, - string, - self->parameter->flags, - self->parameter->width, - self->parameter->precision); -} - -/************************************************************************* - * trio_print_pointer [public] - */ -void -trio_print_pointer(void *ref, - void *pointer) -{ - reference_T *self = (reference_T *)ref; - unsigned long flags; - trio_uintmax_t number; - - if (NULL == pointer) - { - const char *string = null; - while (*string) - self->data->OutStream(self->data, *string++); - } - else - { - /* - * The subtraction of the null pointer is a workaround - * to avoid a compiler warning. The performance overhead - * is negligible (and likely to be removed by an - * optimising compiler). The (char *) casting is done - * to please ANSI C++. - */ - number = (trio_uintmax_t)((char *)pointer - (char *)0); - /* Shrink to size of pointer */ - number &= (trio_uintmax_t)-1; - flags = self->parameter->flags; - flags |= (FLAGS_UNSIGNED | FLAGS_ALTERNATIVE | - FLAGS_NILPADDING); - TrioWriteNumber(self->data, - (trio_intmax_t)number, - flags, - POINTER_WIDTH, - NO_PRECISION, - BASE_HEX); - } -} - -/************************************************************************* - * trio_print_ref [public] - */ -int -trio_print_ref(void *ref, - const char *format, - ...) -{ - int status; - va_list arglist; - - assert(VALID(format)); - - va_start(arglist, format); - status = TrioFormatRef((reference_T *)ref, format, arglist, NULL); - va_end(arglist); - return status; -} - -/************************************************************************* - * trio_vprint_ref [public] - */ -int -trio_vprint_ref(void *ref, - const char *format, - va_list arglist) -{ - assert(VALID(format)); - - return TrioFormatRef((reference_T *)ref, format, arglist, NULL); -} - -/************************************************************************* - * trio_printv_ref [public] - */ -int -trio_printv_ref(void *ref, - const char *format, - void **argarray) -{ - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(format)); - - return TrioFormatRef((reference_T *)ref, format, dummy, argarray); -} - - -/************************************************************************* - * - * @SCANNING - * - ************************************************************************/ - - -/************************************************************************* - * TrioSkipWhitespaces [private] - */ -static int -TrioSkipWhitespaces(trio_T *self) -{ - int ch; - - ch = self->current; - while (isspace(ch)) - { - self->InStream(self, &ch); - } - return ch; -} - -/************************************************************************* - * TrioGetCollation [private] - */ -#if TRIO_EXTENSION -static void -TrioGetCollation() -{ - int i; - int j; - int k; - char first[2]; - char second[2]; - - /* This is computational expensive */ - first[1] = NIL; - second[1] = NIL; - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - { - k = 0; - first[0] = (char)i; - for (j = 0; j < MAX_CHARACTER_CLASS; j++) - { - second[0] = (char)j; - if (StrEqualLocale(first, second)) - internalCollationArray[i][k++] = (char)j; - } - internalCollationArray[i][k] = NIL; - } -} -#endif - -/************************************************************************* - * TrioGetCharacterClass [private] - * - * FIXME: - * multibyte - */ -static int -TrioGetCharacterClass(const char *format, - int *indexPointer, - unsigned long *flagsPointer, - int *characterclass) -{ - int index = *indexPointer; - int i; - char ch; - char range_begin; - char range_end; - - *flagsPointer &= ~FLAGS_EXCLUDE; - - if (format[index] == QUALIFIER_CIRCUMFLEX) - { - *flagsPointer |= FLAGS_EXCLUDE; - index++; - } - /* - * If the ungroup character is at the beginning of the scanlist, - * it will be part of the class, and a second ungroup character - * must follow to end the group. - */ - if (format[index] == SPECIFIER_UNGROUP) - { - characterclass[(int)SPECIFIER_UNGROUP]++; - index++; - } - /* - * Minus is used to specify ranges. To include minus in the class, - * it must be at the beginning of the list - */ - if (format[index] == QUALIFIER_MINUS) - { - characterclass[(int)QUALIFIER_MINUS]++; - index++; - } - /* Collect characters */ - for (ch = format[index]; - (ch != SPECIFIER_UNGROUP) && (ch != NIL); - ch = format[++index]) - { - switch (ch) - { - case QUALIFIER_MINUS: /* Scanlist ranges */ - - /* - * Both C99 and UNIX98 describes ranges as implementation- - * defined. - * - * We support the following behaviour (although this may - * change as we become wiser) - * - only increasing ranges, ie. [a-b] but not [b-a] - * - transitive ranges, ie. [a-b-c] == [a-c] - * - trailing minus, ie. [a-] is interpreted as an 'a' - * and a '-' - * - duplicates (although we can easily convert these - * into errors) - */ - range_begin = format[index - 1]; - range_end = format[++index]; - if (range_end == SPECIFIER_UNGROUP) - { - /* Trailing minus is included */ - characterclass[(int)ch]++; - ch = range_end; - break; /* for */ - } - if (range_end == NIL) - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - if (range_begin > range_end) - return TRIO_ERROR_RETURN(TRIO_ERANGE, index); - - for (i = (int)range_begin; i <= (int)range_end; i++) - characterclass[i]++; - - ch = range_end; - break; - -#if TRIO_EXTENSION - - case SPECIFIER_GROUP: - - switch (format[index + 1]) - { - case QUALIFIER_DOT: /* Collating symbol */ - /* - * FIXME: This will be easier to implement when multibyte - * characters have been implemented. Until now, we ignore - * this feature. - */ - for (i = index + 2; ; i++) - { - if (format[i] == NIL) - /* Error in syntax */ - return -1; - else if (format[i] == QUALIFIER_DOT) - break; /* for */ - } - if (format[++i] != SPECIFIER_UNGROUP) - return -1; - - index = i; - break; - - case QUALIFIER_EQUAL: /* Equivalence class expressions */ - { - unsigned int j; - unsigned int k; - - if (internalCollationUnconverted) - { - /* Lazy evalutation of collation array */ - TrioGetCollation(); - internalCollationUnconverted = FALSE; - } - for (i = index + 2; ; i++) - { - if (format[i] == NIL) - /* Error in syntax */ - return -1; - else if (format[i] == QUALIFIER_EQUAL) - break; /* for */ - else - { - /* Mark any equivalent character */ - k = (unsigned int)format[i]; - for (j = 0; internalCollationArray[k][j] != NIL; j++) - characterclass[(int)internalCollationArray[k][j]]++; - } - } - if (format[++i] != SPECIFIER_UNGROUP) - return -1; - - index = i; - } - break; - - case QUALIFIER_COLON: /* Character class expressions */ - - if (StrEqualMax(CLASS_ALNUM, sizeof(CLASS_ALNUM) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (isalnum(i)) - characterclass[i]++; - index += sizeof(CLASS_ALNUM) - 1; - } - else if (StrEqualMax(CLASS_ALPHA, sizeof(CLASS_ALPHA) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (isalpha(i)) - characterclass[i]++; - index += sizeof(CLASS_ALPHA) - 1; - } - else if (StrEqualMax(CLASS_CNTRL, sizeof(CLASS_CNTRL) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (iscntrl(i)) - characterclass[i]++; - index += sizeof(CLASS_CNTRL) - 1; - } - else if (StrEqualMax(CLASS_DIGIT, sizeof(CLASS_DIGIT) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (isdigit(i)) - characterclass[i]++; - index += sizeof(CLASS_DIGIT) - 1; - } - else if (StrEqualMax(CLASS_GRAPH, sizeof(CLASS_GRAPH) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (isgraph(i)) - characterclass[i]++; - index += sizeof(CLASS_GRAPH) - 1; - } - else if (StrEqualMax(CLASS_LOWER, sizeof(CLASS_LOWER) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (islower(i)) - characterclass[i]++; - index += sizeof(CLASS_LOWER) - 1; - } - else if (StrEqualMax(CLASS_PRINT, sizeof(CLASS_PRINT) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (isprint(i)) - characterclass[i]++; - index += sizeof(CLASS_PRINT) - 1; - } - else if (StrEqualMax(CLASS_PUNCT, sizeof(CLASS_PUNCT) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (ispunct(i)) - characterclass[i]++; - index += sizeof(CLASS_PUNCT) - 1; - } - else if (StrEqualMax(CLASS_SPACE, sizeof(CLASS_SPACE) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (isspace(i)) - characterclass[i]++; - index += sizeof(CLASS_SPACE) - 1; - } - else if (StrEqualMax(CLASS_UPPER, sizeof(CLASS_UPPER) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (isupper(i)) - characterclass[i]++; - index += sizeof(CLASS_UPPER) - 1; - } - else if (StrEqualMax(CLASS_XDIGIT, sizeof(CLASS_XDIGIT) - 1, - &format[index])) - { - for (i = 0; i < MAX_CHARACTER_CLASS; i++) - if (isxdigit(i)) - characterclass[i]++; - index += sizeof(CLASS_XDIGIT) - 1; - } - else - { - characterclass[(int)ch]++; - } - break; - - default: - characterclass[(int)ch]++; - break; - } - break; - -#endif /* TRIO_EXTENSION */ - - default: - characterclass[(int)ch]++; - break; - } - } - return 0; -} - -/************************************************************************* - * TrioReadNumber [private] - * - * We implement our own number conversion in preference of strtol and - * strtoul, because we must handle 'long long' and thousand separators. - */ -static BOOLEAN_T -TrioReadNumber(trio_T *self, - trio_uintmax_t *target, - unsigned long flags, - int width, - int base) -{ - trio_uintmax_t number = 0; - int digit; - int count; - BOOLEAN_T isNegative = FALSE; - int j; - - assert(VALID(self)); - assert(VALID(self->InStream)); - assert((base >= MIN_BASE && base <= MAX_BASE) || (base == NO_BASE)); - - if (internalDigitsUnconverted) - { - /* Lazy evaluation of digits array */ - memset(internalDigitArray, -1, sizeof(internalDigitArray)); - for (j = 0; j < (int)sizeof(internalDigitsLower) - 1; j++) - { - internalDigitArray[(int)internalDigitsLower[j]] = j; - internalDigitArray[(int)internalDigitsUpper[j]] = j; - } - internalDigitsUnconverted = FALSE; - } - - TrioSkipWhitespaces(self); - - if (!(flags & FLAGS_UNSIGNED)) - { - /* Leading sign */ - if (self->current == '+') - { - self->InStream(self, NULL); - } - else if (self->current == '-') - { - self->InStream(self, NULL); - isNegative = TRUE; - } - } - - count = self->processed; - - if (flags & FLAGS_ALTERNATIVE) - { - switch (base) - { - case NO_BASE: - case BASE_OCTAL: - case BASE_HEX: - case BASE_BINARY: - if (self->current == '0') - { - self->InStream(self, NULL); - if (self->current) - { - if ((base == BASE_HEX) && - (toupper(self->current) == 'X')) - { - self->InStream(self, NULL); - } - else if ((base == BASE_BINARY) && - (toupper(self->current) == 'B')) - { - self->InStream(self, NULL); - } - } - } - else - return FALSE; - break; - default: - break; - } - } - - while (((width == NO_WIDTH) || (self->processed - count < width)) && - (! ((self->current == EOF) || isspace(self->current)))) - { - if (isascii(self->current)) - { - digit = internalDigitArray[self->current]; - /* Abort if digit is not allowed in the specified base */ - if ((digit == -1) || (digit >= base)) - break; - } - else if (flags & FLAGS_QUOTE) - { - /* Compare with thousands separator */ - for (j = 0; internalThousandSeparator[j] && self->current; j++) - { - if (internalThousandSeparator[j] != self->current) - break; - - self->InStream(self, NULL); - } - if (internalThousandSeparator[j]) - break; /* Mismatch */ - else - continue; /* Match */ - } - else - break; - - number *= base; - number += digit; - - self->InStream(self, NULL); - } - - /* Was anything read at all? */ - if (self->processed == count) - return FALSE; - - if (target) - *target = (isNegative) ? -number : number; - return TRUE; -} - -/************************************************************************* - * TrioReadChar [private] - */ -static int -TrioReadChar(trio_T *self, - char *target, - unsigned long flags, - int width) -{ - int i; - char ch; - trio_uintmax_t number; - - assert(VALID(self)); - assert(VALID(self->InStream)); - - for (i = 0; - (self->current != EOF) && (i < width); - i++) - { - ch = (char)self->current; - self->InStream(self, NULL); - if ((flags & FLAGS_ALTERNATIVE) && (ch == CHAR_BACKSLASH)) - { - switch (self->current) - { - case '\\': ch = '\\'; break; - case 'a': ch = '\007'; break; - case 'b': ch = '\b'; break; - case 'f': ch = '\f'; break; - case 'n': ch = '\n'; break; - case 'r': ch = '\r'; break; - case 't': ch = '\t'; break; - case 'v': ch = '\v'; break; - default: - if (isdigit(self->current)) - { - /* Read octal number */ - if (!TrioReadNumber(self, &number, 0, 3, BASE_OCTAL)) - return 0; - ch = (char)number; - } - else if (toupper(self->current) == 'X') - { - /* Read hexadecimal number */ - self->InStream(self, NULL); - if (!TrioReadNumber(self, &number, 0, 2, BASE_HEX)) - return 0; - ch = (char)number; - } - else - { - ch = (char)self->current; - } - break; - } - } - - if (target) - target[i] = ch; - } - return i + 1; -} - -/************************************************************************* - * TrioReadString [private] - */ -static BOOLEAN_T -TrioReadString(trio_T *self, - char *target, - unsigned long flags, - int width) -{ - int i; - - assert(VALID(self)); - assert(VALID(self->InStream)); - - TrioSkipWhitespaces(self); - - /* - * Continue until end of string is reached, a whitespace is encountered, - * or width is exceeded - */ - for (i = 0; - ((width == NO_WIDTH) || (i < width)) && - (! ((self->current == EOF) || isspace(self->current))); - i++) - { - if (TrioReadChar(self, &target[i], flags, 1) == 0) - break; /* for */ - } - if (target) - target[i] = NIL; - return TRUE; -} - -/************************************************************************* - * TrioReadWideChar [private] - */ -#if TRIO_WIDECHAR -static int -TrioReadWideChar(trio_T *self, - wchar_t *target, - unsigned long flags, - int width) -{ - int i; - int j; - int size; - int amount = 0; - wchar_t wch; - char buffer[MB_LEN_MAX + 1]; - - assert(VALID(self)); - assert(VALID(self->InStream)); - - for (i = 0; - (self->current != EOF) && (i < width); - i++) - { - if (isascii(self->current)) - { - if (TrioReadChar(self, buffer, flags, 1) == 0) - return 0; - buffer[1] = NIL; - } - else - { - /* - * Collect a multibyte character, by enlarging buffer until - * it contains a fully legal multibyte character, or the - * buffer is full. - */ - j = 0; - do - { - buffer[j++] = (char)self->current; - buffer[j] = NIL; - self->InStream(self, NULL); - } - while ((j < (int)sizeof(buffer)) && (mblen(buffer, (size_t)j) != j)); - } - if (target) - { - size = mbtowc(&wch, buffer, sizeof(buffer)); - if (size > 0) - target[i] = wch; - } - amount += size; - self->InStream(self, NULL); - } - return amount; -} -#endif /* TRIO_WIDECHAR */ - -/************************************************************************* - * TrioReadWideString [private] - */ -#if TRIO_WIDECHAR -static BOOLEAN_T -TrioReadWideString(trio_T *self, - wchar_t *target, - unsigned long flags, - int width) -{ - int i; - int size; - - assert(VALID(self)); - assert(VALID(self->InStream)); - - TrioSkipWhitespaces(self); - -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - mblen(NULL, 0); -#endif - - /* - * Continue until end of string is reached, a whitespace is encountered, - * or width is exceeded - */ - for (i = 0; - ((width == NO_WIDTH) || (i < width)) && - (! ((self->current == EOF) || isspace(self->current))); - ) - { - size = TrioReadWideChar(self, &target[i], flags, 1); - if (size == 0) - break; /* for */ - - i += size; - } - if (target) - target[i] = L'\0'; - return TRUE; -} -#endif /* TRIO_WIDECHAR */ - -/************************************************************************* - * TrioReadGroup [private] - * - * FIXME: characterclass does not work with multibyte characters - */ -static BOOLEAN_T -TrioReadGroup(trio_T *self, - char *target, - int *characterclass, - unsigned long flags, - int width) -{ - int ch; - int i; - - assert(VALID(self)); - assert(VALID(self->InStream)); - - ch = self->current; - for (i = 0; - ((width == NO_WIDTH) || (i < width)) && - (! ((ch == EOF) || - (((flags & FLAGS_EXCLUDE) != 0) ^ (characterclass[ch] == 0)))); - i++) - { - if (target) - target[i] = (char)ch; - self->InStream(self, &ch); - } - - if (target) - target[i] = NIL; - return TRUE; -} - -/************************************************************************* - * TrioReadDouble [private] - * - * FIXME: - * add long double - */ -static BOOLEAN_T -TrioReadDouble(trio_T *self, - double *target, - unsigned long flags, - int width) -{ - int ch; - char doubleString[512] = ""; - int index = 0; - int start; - int j; - BOOLEAN_T isHex = FALSE; - - if ((width == NO_WIDTH) || (width > (int)sizeof(doubleString) - 1)) - width = sizeof(doubleString) - 1; - - TrioSkipWhitespaces(self); - - /* - * Read entire double number from stream. StrToDouble requires a - * string as input, but InStream can be anything, so we have to - * collect all characters. - */ - ch = self->current; - if ((ch == '+') || (ch == '-')) - { - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - width--; - } - - start = index; - switch (ch) - { - case 'n': - case 'N': - /* Not-a-number */ - if (index != 0) - break; - /* FALLTHROUGH */ - case 'i': - case 'I': - /* Infinity */ - while (isalpha(ch) && (index - start < width)) - { - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - } - doubleString[index] = NIL; - - /* Case insensitive string comparison */ - if (StrEqual(&doubleString[start], INFINITE_UPPER) || - StrEqual(&doubleString[start], LONG_INFINITE_UPPER)) - { - *target = ((start == 1 && doubleString[0] == '-')) - ? -HUGE_VAL - : HUGE_VAL; - return TRUE; - } - if (StrEqual(doubleString, NAN_LOWER)) - { - /* NaN must not have a preceeding + nor - */ - *target = TrioGenerateNaN(); - return TRUE; - } - return FALSE; - - default: - break; - } - - if (ch == '0') - { - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - if (toupper(ch) == 'X') - { - isHex = TRUE; - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - } - } - while ((ch != EOF) && (index - start < width)) - { - /* Integer part */ - if (isHex ? isxdigit(ch) : isdigit(ch)) - { - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - } - else if (flags & FLAGS_QUOTE) - { - /* Compare with thousands separator */ - for (j = 0; internalThousandSeparator[j] && self->current; j++) - { - if (internalThousandSeparator[j] != self->current) - break; - - self->InStream(self, &ch); - } - if (internalThousandSeparator[j]) - break; /* Mismatch */ - else - continue; /* Match */ - } - else - break; /* while */ - } - if (ch == '.') - { - /* Decimal part */ - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - while ((isHex ? isxdigit(ch) : isdigit(ch)) && - (index - start < width)) - { - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - } - if (isHex ? (toupper(ch) == 'P') : (toupper(ch) == 'E')) - { - /* Exponent */ - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - if ((ch == '+') || (ch == '-')) - { - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - } - while ((isHex ? isxdigit(ch) : isdigit(ch)) && - (index - start < width)) - { - doubleString[index++] = (char)ch; - self->InStream(self, &ch); - } - } - } - - if ((index == start) || (*doubleString == NIL)) - return FALSE; - - if (flags & FLAGS_LONGDOUBLE) -/* *longdoublePointer = StrToLongDouble()*/ - return FALSE; /* FIXME: Remove when long double is implemented */ - else - { - *target = StrToDouble(doubleString, NULL); - } - return TRUE; -} - -/************************************************************************* - * TrioReadPointer [private] - */ -static BOOLEAN_T -TrioReadPointer(trio_T *self, - void **target, - unsigned long flags) -{ - trio_uintmax_t number; - char buffer[sizeof(null)]; - - flags |= (FLAGS_UNSIGNED | FLAGS_ALTERNATIVE | FLAGS_NILPADDING); - - if (TrioReadNumber(self, - &number, - flags, - POINTER_WIDTH, - BASE_HEX)) - { - /* - * The strange assignment of number is a workaround for a compiler - * warning - */ - if (target) - *target = (char *)0 + number; - return TRUE; - } - else if (TrioReadString(self, - (flags & FLAGS_IGNORE) - ? NULL - : buffer, - 0, - sizeof(null) - 1)) - { - if (StrEqualCase(buffer, null)) - { - if (target) - *target = NULL; - return TRUE; - } - } - return FALSE; -} - -/************************************************************************* - * TrioScan [private] - */ -static int -TrioScan(const void *source, - size_t sourceSize, - void (*InStream)(trio_T *, int *), - const char *format, - va_list arglist, - void **argarray) -{ -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - int charlen; -#endif - int status; - int assignment; - parameter_T parameters[MAX_PARAMETERS]; - trio_T internalData; - trio_T *data; - int ch; -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - int cnt; -#endif - int index; /* Index of format string */ - int i; /* Index of current parameter */ - unsigned long flags; - int width; - int base; - void *pointer; - - assert(VALID(InStream)); - assert(VALID(format)); - - memset(&internalData, 0, sizeof(internalData)); - data = &internalData; - data->InStream = InStream; - data->location = (void *)source; - data->max = sourceSize; - -#if defined(USE_LOCALE) - if (NULL == internalLocaleValues) - { - TrioSetLocale(); - } -#endif - - status = TrioPreprocess(TYPE_SCAN, format, parameters, arglist, argarray); - if (status < 0) - return status; - - assignment = 0; - i = 0; - index = 0; - data->InStream(data, &ch); - -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - mblen(NULL, 0); -#endif - - while (format[index]) - { -#if defined(TRIO_COMPILER_SUPPORTS_MULTIBYTE) - if (! isascii(format[index])) - { - charlen = mblen(&format[index], MB_LEN_MAX); - /* Compare multibyte characters in format string */ - for (cnt = 0; cnt < charlen - 1; cnt++) - { - if (ch != format[index + cnt]) - { - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - } - data->InStream(data, &ch); - } - continue; /* while */ - } -#endif /* TRIO_COMPILER_SUPPORTS_MULTIBYTE */ - if (EOF == ch) - return EOF; - - if (CHAR_IDENTIFIER == format[index]) - { - if (CHAR_IDENTIFIER == format[index + 1]) - { - /* Two % in format matches one % in input stream */ - if (CHAR_IDENTIFIER == ch) - { - data->InStream(data, &ch); - index += 2; - continue; /* while format chars left */ - } - else - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - } - - /* Skip the parameter entries */ - while (parameters[i].type == FORMAT_PARAMETER) - i++; - - flags = parameters[i].flags; - /* Find width */ - width = parameters[i].width; - if (flags & FLAGS_WIDTH_PARAMETER) - { - /* Get width from parameter list */ - width = (int)parameters[width].data.number.as_signed; - } - /* Find base */ - base = parameters[i].base; - if (flags & FLAGS_BASE_PARAMETER) - { - /* Get base from parameter list */ - base = (int)parameters[base].data.number.as_signed; - } - - switch (parameters[i].type) - { - case FORMAT_INT: - { - trio_uintmax_t number; - - if (0 == base) - base = BASE_DECIMAL; - - if (!TrioReadNumber(data, - &number, - flags, - width, - base)) - return assignment; - assignment++; - - if (!(flags & FLAGS_IGNORE)) - { - pointer = parameters[i].data.pointer; -#if defined(QUALIFIER_SIZE_T) || defined(QUALIFIER_SIZE_T_UPPER) - if (flags & FLAGS_SIZE_T) - *(size_t *)pointer = (size_t)number; - else -#endif -#if defined(QUALIFIER_PTRDIFF_T) - if (flags & FLAGS_PTRDIFF_T) - *(ptrdiff_t *)pointer = (ptrdiff_t)number; - else -#endif -#if defined(QUALIFIER_INTMAX_T) - if (flags & FLAGS_INTMAX_T) - *(trio_intmax_t *)pointer = (trio_intmax_t)number; - else -#endif - if (flags & FLAGS_QUAD) - *(trio_ulonglong_t *)pointer = (trio_ulonglong_t)number; - else if (flags & FLAGS_LONG) - *(long int *)pointer = (long int)number; - else if (flags & FLAGS_SHORT) - *(short int *)pointer = (short int)number; - else - *(int *)pointer = (int)number; - } - } - break; /* FORMAT_INT */ - - case FORMAT_STRING: -#if TRIO_WIDECHAR - if (flags & FLAGS_WIDECHAR) - { - if (!TrioReadWideString(data, - (flags & FLAGS_IGNORE) - ? NULL - : parameters[i].data.wstring, - flags, - width)) - return assignment; - } - else -#endif - { - if (!TrioReadString(data, - (flags & FLAGS_IGNORE) - ? NULL - : parameters[i].data.string, - flags, - width)) - return assignment; - } - assignment++; - break; /* FORMAT_STRING */ - - case FORMAT_DOUBLE: - if (!TrioReadDouble(data, - (flags & FLAGS_IGNORE) - ? NULL - : parameters[i].data.doublePointer, - flags, - width)) - return assignment; - assignment++; - break; /* FORMAT_DOUBLE */ - - case FORMAT_GROUP: - { - int characterclass[MAX_CHARACTER_CLASS + 1]; - int rc; - - /* Skip over modifiers */ - while (format[index] != SPECIFIER_GROUP) - { - index++; - } - /* Skip over group specifier */ - index++; - - memset(characterclass, 0, sizeof(characterclass)); - rc = TrioGetCharacterClass(format, - &index, - &flags, - characterclass); - if (rc < 0) - return rc; - - if (!TrioReadGroup(data, - (flags & FLAGS_IGNORE) - ? NULL - : parameters[i].data.string, - characterclass, - flags, - parameters[i].width)) - return assignment; - assignment++; - } - break; /* FORMAT_GROUP */ - - case FORMAT_COUNT: - pointer = parameters[i].data.pointer; - if (NULL != pointer) - { -#if defined(QUALIFIER_SIZE_T) || defined(QUALIFIER_SIZE_T_UPPER) - if (flags & FLAGS_SIZE_T) - *(size_t *)pointer = (size_t)data->committed; - else -#endif -#if defined(QUALIFIER_PTRDIFF_T) - if (flags & FLAGS_PTRDIFF_T) - *(ptrdiff_t *)pointer = (ptrdiff_t)data->committed; - else -#endif -#if defined(QUALIFIER_INTMAX_T) - if (flags & FLAGS_INTMAX_T) - *(trio_intmax_t *)pointer = (trio_intmax_t)data->committed; - else -#endif - if (flags & FLAGS_QUAD) - { - *(trio_ulonglong_t *)pointer = (trio_ulonglong_t)data->committed; - } - else if (flags & FLAGS_LONG) - { - *(long int *)pointer = (long int)data->committed; - } - else if (flags & FLAGS_SHORT) - { - *(short int *)pointer = (short int)data->committed; - } - else - { - *(int *)pointer = (int)data->committed; - } - } - break; /* FORMAT_COUNT */ - - case FORMAT_CHAR: -#if TRIO_WIDECHAR - if (flags & FLAGS_WIDECHAR) - { - if (TrioReadWideChar(data, - (flags & FLAGS_IGNORE) - ? NULL - : parameters[i].data.wstring, - flags, - (width == NO_WIDTH) ? 1 : width) > 0) - return assignment; - } - else -#endif - { - if (TrioReadChar(data, - (flags & FLAGS_IGNORE) - ? NULL - : parameters[i].data.string, - flags, - (width == NO_WIDTH) ? 1 : width) > 0) - return assignment; - } - assignment++; - break; /* FORMAT_CHAR */ - - case FORMAT_POINTER: - if (!TrioReadPointer(data, - (flags & FLAGS_IGNORE) - ? NULL - : (void **)parameters[i].data.pointer, - flags)) - return assignment; - assignment++; - break; /* FORMAT_POINTER */ - - case FORMAT_PARAMETER: - break; /* FORMAT_PARAMETER */ - - default: - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - } - ch = data->current; - index = parameters[i].indexAfterSpecifier; - i++; - } - else /* Not an % identifier */ - { - if (isspace((int)format[index])) - { - /* Whitespaces may match any amount of whitespaces */ - ch = TrioSkipWhitespaces(data); - } - else if (ch == format[index]) - { - data->InStream(data, &ch); - } - else - return TRIO_ERROR_RETURN(TRIO_EINVAL, index); - - index++; - } - } - return assignment; -} - -/************************************************************************* - * TrioInStreamFile [private] - */ -static void -TrioInStreamFile(trio_T *self, - int *intPointer) -{ - FILE *file = (FILE *)self->location; - - assert(VALID(self)); - assert(VALID(file)); - - self->current = fgetc(file); - self->processed++; - self->committed++; - - if (VALID(intPointer)) - { - *intPointer = self->current; - } -} - -/************************************************************************* - * TrioInStreamFileDescriptor [private] - */ -static void -TrioInStreamFileDescriptor(trio_T *self, - int *intPointer) -{ - int fd = *((int *)self->location); - int size; - unsigned char input; - - assert(VALID(self)); - - size = read(fd, &input, sizeof(char)); - self->current = (size == 0) ? EOF : input; - self->processed++; - self->committed++; - - if (VALID(intPointer)) - { - *intPointer = self->current; - } -} - -/************************************************************************* - * TrioInStreamString [private] - */ -static void -TrioInStreamString(trio_T *self, - int *intPointer) -{ - unsigned char **buffer; - - assert(VALID(self)); - assert(VALID(self->InStream)); - assert(VALID(self->location)); - - buffer = (unsigned char **)self->location; - self->current = (*buffer)[0]; - if (self->current == NIL) - self->current = EOF; - (*buffer)++; - self->processed++; - self->committed++; - - if (VALID(intPointer)) - { - *intPointer = self->current; - } -} - -/************************************************************************* - * scanf - */ -int -trio_scanf(const char *format, - ...) -{ - int status; - va_list args; - - assert(VALID(format)); - - va_start(args, format); - status = TrioScan(stdin, 0, TrioInStreamFile, format, args, NULL); - va_end(args); - return status; -} - -int -trio_vscanf(const char *format, - va_list args) -{ - assert(VALID(format)); - - return TrioScan(stdin, 0, TrioInStreamFile, format, args, NULL); -} - -int -trio_scanfv(const char *format, - void **args) -{ - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(format)); - - return TrioScan(stdin, 0, TrioInStreamFile, format, dummy, args); -} - -/************************************************************************* - * fscanf - */ -int -trio_fscanf(FILE *file, - const char *format, - ...) -{ - int status; - va_list args; - - assert(VALID(file)); - assert(VALID(format)); - - va_start(args, format); - status = TrioScan(file, 0, TrioInStreamFile, format, args, NULL); - va_end(args); - return status; -} - -int -trio_vfscanf(FILE *file, - const char *format, - va_list args) -{ - assert(VALID(file)); - assert(VALID(format)); - - return TrioScan(file, 0, TrioInStreamFile, format, args, NULL); -} - -int -trio_fscanfv(FILE *file, - const char *format, - void **args) -{ - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(file)); - assert(VALID(format)); - - return TrioScan(file, 0, TrioInStreamFile, format, dummy, args); -} - -/************************************************************************* - * dscanf - */ -int -trio_dscanf(int fd, - const char *format, - ...) -{ - int status; - va_list args; - - assert(VALID(format)); - - va_start(args, format); - status = TrioScan(&fd, 0, TrioInStreamFileDescriptor, format, args, NULL); - va_end(args); - return status; -} - -int -trio_vdscanf(int fd, - const char *format, - va_list args) -{ - assert(VALID(format)); - - return TrioScan(&fd, 0, TrioInStreamFileDescriptor, format, args, NULL); -} - -int -trio_dscanfv(int fd, - const char *format, - void **args) -{ - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(format)); - - return TrioScan(&fd, 0, TrioInStreamFileDescriptor, format, dummy, args); -} - -/************************************************************************* - * sscanf - */ -int -trio_sscanf(const char *buffer, - const char *format, - ...) -{ - int status; - va_list args; - - assert(VALID(buffer)); - assert(VALID(format)); - - va_start(args, format); - status = TrioScan(&buffer, 0, TrioInStreamString, format, args, NULL); - va_end(args); - return status; -} - -int -trio_vsscanf(const char *buffer, - const char *format, - va_list args) -{ - assert(VALID(buffer)); - assert(VALID(format)); - - return TrioScan(&buffer, 0, TrioInStreamString, format, args, NULL); -} - -int -trio_sscanfv(const char *buffer, - const char *format, - void **args) -{ - va_list dummy; - shutup_unitialized(&dummy); - - assert(VALID(buffer)); - assert(VALID(format)); - - return TrioScan(&buffer, 0, TrioInStreamString, format, dummy, args); -} - diff --git a/org.glite.lbjp-common.trio/src/triop.h b/org.glite.lbjp-common.trio/src/triop.h deleted file mode 100644 index ca49fab..0000000 --- a/org.glite.lbjp-common.trio/src/triop.h +++ /dev/null @@ -1,138 +0,0 @@ -/************************************************************************* - * - * $Id$ - * - * Copyright (C) 2000 Bjorn Reese and Daniel Stenberg. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF - * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS AND - * CONTRIBUTORS ACCEPT NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER. - * - ************************************************************************ - * - * Private functions, types, etc. used for callback functions. - * - * The ref pointer is an opaque type and should remain as such. - * Private data must only be accessible through the getter and - * setter functions. - * - ************************************************************************/ - -#ifndef TRIO_TRIOP_H -#define TRIO_TRIOP_H - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef TRIO_C99 -# define TRIO_C99 1 -#endif -#ifndef TRIO_BSD -# define TRIO_BSD 1 -#endif -#ifndef TRIO_GNU -# define TRIO_GNU 1 -#endif -#ifndef TRIO_MISC -# define TRIO_MISC 1 -#endif -#ifndef TRIO_UNIX98 -# define TRIO_UNIX98 1 -#endif -#ifndef TRIO_MICROSOFT -# define TRIO_MICROSOFT 1 -#endif -#ifndef TRIO_EXTENSION -# define TRIO_EXTENSION 1 -#endif -#ifndef TRIO_WIDECHAR -# define TRIO_WIDECHAR 0 -#endif -#ifndef TRIO_ERRORS -# define TRIO_ERRORS 1 -#endif - -#ifndef TRIO_MALLOC -# define TRIO_MALLOC(n) malloc(n) -#endif -#ifndef TRIO_REALLOC -# define TRIO_REALLOC(x,n) realloc((x),(n)) -#endif -#ifndef TRIO_FREE -# define TRIO_FREE(x) free(x) -#endif - -typedef int (*trio_callback_t)(void *ref); - -void *trio_register(trio_callback_t callback, const char *name); -void trio_unregister(void *handle); - -const char *trio_get_format(void *ref); -void *trio_get_argument(void *ref); - -/* Modifiers */ -int trio_get_width(void *ref); -void trio_set_width(void *ref, int width); -int trio_get_precision(void *ref); -void trio_set_precision(void *ref, int precision); -int trio_get_base(void *ref); -void trio_set_base(void *ref, int base); -int trio_get_padding(void *ref); -void trio_set_padding(void *ref, int is_padding); -int trio_get_short(void *ref); /* h */ -void trio_set_shortshort(void *ref, int is_shortshort); -int trio_get_shortshort(void *ref); /* hh */ -void trio_set_short(void *ref, int is_short); -int trio_get_long(void *ref); /* l */ -void trio_set_long(void *ref, int is_long); -int trio_get_longlong(void *ref); /* ll */ -void trio_set_longlong(void *ref, int is_longlong); -int trio_get_longdouble(void *ref); /* L */ -void trio_set_longdouble(void *ref, int is_longdouble); -int trio_get_alternative(void *ref); /* # */ -void trio_set_alternative(void *ref, int is_alternative); -int trio_get_alignment(void *ref); /* - */ -void trio_set_alignment(void *ref, int is_leftaligned); -int trio_get_spacing(void *ref); /* (space) */ -void trio_set_spacing(void *ref, int is_space); -int trio_get_sign(void *ref); /* + */ -void trio_set_sign(void *ref, int is_showsign); -int trio_get_quote(void *ref); /* ' */ -void trio_set_quote(void *ref, int is_quote); -int trio_get_upper(void *ref); -void trio_set_upper(void *ref, int is_upper); -#if TRIO_C99 -int trio_get_largest(void *ref); /* j */ -void trio_set_largest(void *ref, int is_largest); -int trio_get_ptrdiff(void *ref); /* t */ -void trio_set_ptrdiff(void *ref, int is_ptrdiff); -int trio_get_size(void *ref); /* z / Z */ -void trio_set_size(void *ref, int is_size); -#endif - -/* Printing */ -int trio_print_ref(void *ref, const char *format, ...); -int trio_vprint_ref(void *ref, const char *format, va_list args); -int trio_printv_ref(void *ref, const char *format, void **args); - -void trio_print_int(void *ref, int number); -void trio_print_uint(void *ref, unsigned int number); -/* void trio_print_long(void *ref, long number); */ -/* void trio_print_ulong(void *ref, unsigned long number); */ -void trio_print_double(void *ref, double number); -void trio_print_string(void *ref, char *string); -void trio_print_pointer(void *ref, void *pointer); - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /* TRIO_TRIOP_H */ diff --git a/org.glite.lbjp-common.trio/test/trio_test.cpp b/org.glite.lbjp-common.trio/test/trio_test.cpp deleted file mode 100644 index 3ba4b9c..0000000 --- a/org.glite.lbjp-common.trio/test/trio_test.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include - -#include -#include - -#include "trio.h" - -class TrioTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(TrioTest); - CPPUNIT_TEST(escapeULM); - CPPUNIT_TEST(escapeXML); - CPPUNIT_TEST(escapeSQL); - CPPUNIT_TEST_SUITE_END(); - -public: - void escapeULM(); - void escapeXML(); - void escapeSQL(); -}; - -void TrioTest::escapeULM() -{ - char *e, *r = "START we have =, \\\", and \\n in the string END"; - - trio_asprintf(&e,"START %|Us END", "we have =, \", and \n in the string"), - std::cerr << e << std::endl; - - CPPUNIT_ASSERT_MESSAGE("escape ULM failed",!strcmp(e,r)); -} - -void TrioTest::escapeXML() -{ - char *e, *r = "START there is a <tag> containing &something; </tag> END"; - - trio_asprintf(&e,"START %|Xs END", "there is a containing &something; "), - std::cerr << e << std::endl; - - CPPUNIT_ASSERT_MESSAGE("escape XML failed",!strcmp(e,r)); -} - -void TrioTest::escapeSQL() -{ - char *e, *r = "START SQL doesn''t like '' END"; - - trio_asprintf(&e,"START %|Ss END", "SQL doesn't like '"), - std::cerr << e << std::endl; - - CPPUNIT_ASSERT_MESSAGE("escape SQL failed",!strcmp(e,r)); -} - -CPPUNIT_TEST_SUITE_REGISTRATION( TrioTest ); - -#include -#include - -#include -#include -#include -#include -#include -#include - -int main (int argc,const char *argv[]) -{ - CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - - assert(argc == 2); - std::ofstream xml(argv[1]); - - CppUnit::TestResult controller; - CppUnit::TestResultCollector result; - controller.addListener( &result ); - - CppUnit::TestRunner runner; - runner.addTest(suite); - runner.run(controller); - - CppUnit::XmlOutputter xout( &result, xml ); - CppUnit::CompilerOutputter tout( &result, std::cout); - xout.write(); - tout.write(); - - return result.wasSuccessful() ? 0 : 1 ; -} diff --git a/org.glite.lbjp-common/project/version.properties b/org.glite.lbjp-common/project/version.properties deleted file mode 100644 index 11900b7..0000000 --- a/org.glite.lbjp-common/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# : /cvs/glite/org.glite.lbjp-common/project/version.properties,v 1.1 2009/01/21 12:57:26 akrenek Exp $ -module.version=1.0.1 -module.age=4 diff --git a/org.glite.security.gsoap-plugin/LICENSE b/org.glite.security.gsoap-plugin/LICENSE deleted file mode 100644 index 259a91f..0000000 --- a/org.glite.security.gsoap-plugin/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.security.gsoap-plugin/Makefile b/org.glite.security.gsoap-plugin/Makefile deleted file mode 100644 index 587fc94..0000000 --- a/org.glite.security.gsoap-plugin/Makefile +++ /dev/null @@ -1,284 +0,0 @@ -# defaults -top_srcdir=.. -builddir=build -top_builddir=${top_srcdir}/${builddir} -stagedir=. -globalprefix=glite -package=gsoap-plugin -version=1.0.0 -PREFIX=/opt/glite - -glite_location=/opt/glite -nothrflavour=gcc32 -thrflavour=gcc32pthr -gsoap_prefix=/opt/gsoap - -CC=gcc - -gsoap_versions_noflavours?=2.6.2 2.7.0f 2.7.6b 2.7.6d 2.7.9d 2.7.9b -gsoap_versions_flavours?=2.7.10 -gsoap_versions_flavours:=${shell if ! echo $gsoap_versions_flavours | grep "\<${gsoap_default_version}\>" >/dev/null; then echo "${gsoap_default_version} "; else echo ne; fi} ${gsoap_versions_flavours} - --include Makefile.inc --include ../Makefile.inc - -GSPLUGIN_DEBUG?=no -GSPLUGIN_VERSION_CHECKING?=yes -CC=gcc - -offset=0 -version_info:=-version-info ${shell \ - perl -e '$$,=":"; @F=split "\\.","${version}"; print $$F[0]+$$F[1]+${offset},$$F[2],$$F[1]' } - -# version_info=-version-info `echo ${version} | cut -d. -f1,2 | tr . :` - -ext_repository:=${shell if [ -d "${repository}/externals" ]; then \ - echo "${repository}/externals"; \ - else echo "${repository}"; \ - fi} - -gsoap_version=${gsoap_default_version} -gsoap_prefix?=${ext_repository}/${gsoap_name}/${gsoap_version}/${gsoap_platform} -ifdef lang -langflavour:=_${lang} -langsuffix:=.${lang} -endif - -VPATH=${top_srcdir}/src:${top_srcdir}/test:${top_srcdir}/examples - -default: all - -DEBUG:=-g -O0 -W -Wall -Wno-unused-parameter -# not for globus and gsoap: -Werror -ifeq ($(GSPLUGIN_DEBUG),yes) - DEBUG:=${DEBUG} -DGSPLUGIN_DEBUG=1 -endif -# gsoap logs: -DDEBUG -ifeq ($(GSOAP_DEBUG),yes) - DEBUG:=${DEBUG} -DDEBUG=1 -endif - -#ifeq ($(GSPLUGIN_VERSION_CHECKING),yes) -# DEBUG:=${DEBUG} -DCHECK_GSOAP_VERSION -#endif - -CFLAGS:= ${DEBUG} \ - -DVERSION=\"${version}\" \ - -DWITH_NONAMESPACES \ - -I. -I${top_srcdir}/interface \ - -I${stagedir}/include \ - ${COVERAGE_FLAGS} -D_GNU_SOURCE -DDATAGRID_EXTENSION - -LDFLAGS:=${COVERAGE_FLAGS} - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -COMPILEXX:=libtool --mode=compile ${CXX} ${CFLAGS} -LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/${libdir} ${LDFLAGS} -LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/${libdir} ${LDFLAGS} -INSTALL:=libtool --mode=install install -LINK_lang:=PATH=${top_srcdir}/project/libtoolhack:${PATH} libtool --mode=link ${CXX} -rpath ${stagedir}/${libdir} ${LDFLAGS} -ifeq (${lang},c) -LINK_lang:=${LINK} -endif -ifeq (${lang},cxx) -LINK_lang:=${LINKXX} -endif - -EX_LIBS:=-L${stagedir}/${libdir} -lglite_security_gss_${nothrflavour} -EX_THRLIBS:=-L${stagedir}/${libdir} -lglite_security_gss_${thrflavour} -HDRS:=glite_gsplugin.h glite_gscompat.h glite_gsplugin-int.h -EXAMPLES:=wscalc_clt_ex wscalc_srv_ex wscalc_srv_ex2 -TESTS:=test_cxx - -STATICLIB:=libglite_security_gsoap_plugin_${nothrflavour}${langflavour}.a -THRSTATICLIB:=libglite_security_gsoap_plugin_${thrflavour}${langflavour}.a -LTLIB:=libglite_security_gsoap_plugin_${nothrflavour}${langflavour}.la -THRLTLIB:=libglite_security_gsoap_plugin_${thrflavour}${langflavour}.la - -OBJS:=${GSS_OBJS} glite_gsplugin${langsuffix}.o -LOBJS:=${OBJS:.o=.lo} -THROBJS:=${OBJS:.o=.thr.o} -THRLOBJS:=${OBJS:.o=.thr.lo} - -dotless_ver:=${shell echo ${gsoap_version} | tr -d '.'} -STATICLIB_S:=libglite_security_gsoap_plugin_${dotless_ver}_${nothrflavour}${langflavour}.a -THRSTATICLIB_S:=libglite_security_gsoap_plugin_${dotless_ver}_${thrflavour}${langflavour}.a -LTLIB_S:=libglite_security_gsoap_plugin_${dotless_ver}_${nothrflavour}${langflavour}.la -THRLTLIB_S:=libglite_security_gsoap_plugin_${dotless_ver}_${thrflavour}${langflavour}.la -LTLIB_TEST_S:=libglite_security_gsoap_plugin_${dotless_ver}_${nothrflavour}_cxx.la - -OBJS_S:=glite_gsplugin${langsuffix}.o stdsoap2${langsuffix}.o -LOBJS_S:=${OBJS_S:.o=.lo} -THROBJS_S:=${OBJS_S:.o=.thr.o} -THRLOBJS_S:=${OBJS_S:.o=.thr.lo} - -${STATICLIB}: ${OBJS} - ar crv $@ ${OBJS} - ranlib $@ - -${THRSTATICLIB}: ${THROBJS} - ar crv $@ ${THROBJS} - ranlib $@ - -${LTLIB}: ${OBJS} - ${LINK_lang} ${version_info} -o $@ ${LOBJS} ${EX_LIBS} - -${THRLTLIB}: ${THROBJS} - ${LINK_lang} ${version_info} -o $@ ${THRLOBJS} ${EX_THRLIBS} - -${STATICLIB_S}: ${OBJS_S} - ar crv $@ ${OBJS_S} - ranlib $@ - -${THRSTATICLIB_S}: ${THROBJS_S} - ar crv $@ ${THROBJS_S} - ranlib $@ - -${LTLIB_S}: ${OBJS_S} - ${LINK_lang} ${version_info} -o $@ ${LOBJS_S} ${EX_LIBS} - -${THRLTLIB_S}: ${THROBJS_S} - ${LINK_lang} ${version_info} -o $@ ${THRLOBJS_S} ${EX_THRLIBS} - -all compile: \ - ${STATICLIB} ${LTLIB} ${THRSTATICLIB} ${THRLTLIB} \ - all-libs-with-soap examples - -check: check.cxx - -# C/C++ compatibility test -# (C flavour, gsoap 2.7.10 ==> C++ test fails) -check.cxx: - ${MAKE} lang=cxx -f ${top_srcdir}/Makefile ${LTLIB_TEST_S} test_cxx - ./test_cxx - -examples: ${EXAMPLES} - -all-libs-with-soap: - for v in ${gsoap_versions_noflavours}; do \ - dir=`echo $$v | tr -d .`; \ - mkdir $$dir; \ - ${MAKE} -C $$dir -f ../Makefile gsoap_version=$$v top_srcdir=../.. lang= libs-with-soap || exit $?; \ - done - for v in ${gsoap_versions_flavours}; do \ - dir=`echo $$v | tr -d .`; \ - mkdir $$dir; \ - ${MAKE} -C $$dir -f ../Makefile gsoap_version=$$v top_srcdir=../.. lang=c libs-with-soap || exit $?; \ - ${MAKE} -C $$dir -f ../Makefile gsoap_version=$$v top_srcdir=../.. lang=cxx libs-with-soap || exit $?; \ - done - -libs-with-soap: ${LTLIB_S} ${THRLTLIB_S} ${STATICLIB_S} ${THRSTATICLIB_S} - -gsoap_srcname=gsoap-`echo ${gsoap_version} | cut -d. -f1,2` - -link-gsoap: - if [ -f ${top_srcdir}/src/stdsoap2_${gsoap_version}.c ]; then \ - ln -sf ${top_srcdir}/src/stdsoap2_${gsoap_version}.c stdsoap2.c; \ - ln -sf ${top_srcdir}/src/stdsoap2_${gsoap_version}.h stdsoap2.h; \ - elif [ -f ${ext_repository}/${gsoap_name}/${gsoap_version}/src/stdsoap2.c ]; then \ - ln -sf ${ext_repository}/${gsoap_name}/${gsoap_version}/src/stdsoap2.[ch] .; \ - elif [ -f ${ext_repository}/${gsoap_name}/${gsoap_version}/${gsoap_platform}/stdsoap2.c ]; then \ - ln -sf ${ext_repository}/${gsoap_name}/${gsoap_version}/${gsoap_platform}/stdsoap2.[ch] .; \ - elif [ -f ${ext_repository}/${gsoap_name}/${gsoap_version}/${gsoap_platform}/src/stdsoap2.c ]; then \ - ln -sf ${ext_repository}/${gsoap_name}/${gsoap_version}/${gsoap_platform}/src/stdsoap2.c .; \ - ln -sf ${ext_repository}/${gsoap_name}/${gsoap_version}/${gsoap_platform}/include/stdsoap2.h .; \ - elif [ -f ${ext_repository}/${gsoap_name}/${gsoap_version}/src/stdsoap2.c ]; then \ - ln -sf ${ext_repository}/${gsoap_name}/${gsoap_version}/src/stdsoap2.[ch] .; \ - elif [ -f ${ext_repository}/${gsoap_name}/${gsoap_version}/src/${gsoap_srcname}/soapcpp2/stdsoap2.c ]; then \ - ln -sf ${ext_repository}/${gsoap_name}/${gsoap_version}/src/${gsoap_srcname}/soapcpp2/stdsoap2.[ch] .; \ - else false ; \ - fi - -stdsoap2.c stdsoap2.h: link-gsoap - -GSOAP_FPREFIX:= GSOAP_ - -WSCALC_CLT_OBJS = wscalc_clt_ex.o ${GSOAP_FPREFIX}C.o ${GSOAP_FPREFIX}Client.o -WSCALC_SRV_OBJS = wscalc_srv_ex.o ${GSOAP_FPREFIX}C.o ${GSOAP_FPREFIX}Server.o -WSCALC_SRV2_OBJS = wscalc_srv_ex2.o ${GSOAP_FPREFIX}C.o ${GSOAP_FPREFIX}Server.o - -wscalc_clt_ex.o wscalc_srv_ex.o wscalc_srv_ex2.o: ${GSOAP_FPREFIX}H.h - -wscalc_clt_ex: ${WSCALC_CLT_OBJS} ${LTLIB_S} - ${LINK_lang} -o $@ ${WSCALC_CLT_OBJS} ${LTLIB_S} - -wscalc_srv_ex: ${WSCALC_SRV_OBJS} ${LTLIB_S} - ${LINK_lang} -o $@ ${WSCALC_SRV_OBJS} ${LTLIB_S} - -wscalc_srv_ex2: ${WSCALC_SRV2_OBJS} ${LTLIB_S} - ${LINK_lang} -o $@ ${WSCALC_SRV2_OBJS} ${LTLIB_S} - -test_cxx: test_gsplugin_cxx.o ${GSOAP_FPREFIX}C.cxx.o - ${LINKXX} -o $@ $+ ${LTLIB_TEST_S} - -soapcpp:=${shell if [ -x ${gsoap_prefix}/bin/soapcpp2 ]; then \ - echo ${gsoap_prefix}/bin/soapcpp2; \ - else echo ${gsoap_prefix}/soapcpp2; \ - fi} - -${GSOAP_FPREFIX}H.h ${GSOAP_FPREFIX}C.c ${GSOAP_FPREFIX}Server.c ${GSOAP_FPREFIX}Client.c ${GSOAP_FPREFIX}ServerLib.c ${GSOAP_FPREFIX}ClientLib.c: calc.h.S - ${soapcpp} -c -p ${GSOAP_FPREFIX} ${top_srcdir}/examples/calc.h.S - -wscalc_clt_ex.o: wscalc_clt_ex.c - ${CC} -c ${CFLAGS} -o $@ $< - -doc: - -stage: - $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes - -install: - -mkdir -p ${PREFIX}/${libdir} - -mkdir -p ${PREFIX}/include/glite/security - -mkdir -p ${PREFIX}/share/doc/${package}-${version} - -mkdir -p ${PREFIX}/include/glite/security/ - ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} - cd ${top_srcdir}/interface && ${INSTALL} -m 644 ${HDRS} ${PREFIX}/include/glite/security/ - for v in ${gsoap_versions_noflavours}; do \ - ${MAKE} -C `echo $$v | tr -d .` -f ../Makefile install-soaplib gsoap_version=$$v lang= PREFIX=${PREFIX} top_srcdir=${top_srcdir}/.. || exit $?; \ - done - for v in ${gsoap_versions_flavours}; do \ - ${MAKE} -C `echo $$v | tr -d .` -f ../Makefile install-soaplib gsoap_version=$$v lang=c PREFIX=${PREFIX} top_srcdir=${top_srcdir}/.. || exit $?; \ - ${MAKE} -C `echo $$v | tr -d .` -f ../Makefile install-soaplib gsoap_version=$$v lang=cxx PREFIX=${PREFIX} top_srcdir=${top_srcdir}/.. || exit $?; \ - done - -install-soaplib: - ${INSTALL} -m 755 ${LTLIB_S} ${THRLTLIB_S} ${PREFIX}/${libdir} - -clean: - rm -rvf ${STATICLIB} ${LTLIB} ${THRSTATICLIB} ${THRLTLIB} - rm -rvf ${LTLIB_S} ${THRLTLIB_S} ${STATICLIB_S} ${THRSTATICLIB_S} - rm -rvf ${LTLIB_TEST_S} - rm -rvf *.c *.h *.xml *.nsmap *.o *.lo .libs ${EXAMPLES} ${TESTS} - rm -rvf CalcService.wsdl wscalc.xsd - rm -rvf log.xml project/ rpmbuild/ RPMS/ tgz/ - for v in ${gsoap_versions_noflavours} ${gsoap_versions_flavours}; do \ - rm -rvf `echo $$v | tr -d .`; \ - done - -%.c.o: %.c - ${COMPILE} -o $@ -c $< - -%.cxx.o: %.c - ${COMPILEXX} -o $@ -c $< - -%.o: %.c - ${COMPILE} -o $@ -c $< - -%.c.thr.o: %.c - ${COMPILE} -o $@ -c $< - -%.cxx.thr.o: %.c - ${COMPILEXX} -o $@ -c $< - -%.thr.o: %.c - ${COMPILE} -o $@ -c $< - -test_gsplugin_cxx.o: %.o: %.cpp stdsoap2.h - ${COMPILEXX} -c ${GLOBUS_INC} $< - -glite_gsplugin${langsuffix}.o glite_gsplugin${langsuffix}.thr.o: soap_version.h - -soap_version.h: stdsoap2.h - head stdsoap2.h | \ - perl -ne '/^\s*stdsoap2.h\s+([0-9])\.([0-9])\.(\S+)\s.*/ && printf "#define GSOAP_VERSION %d%02d%02d\n#define GSOAP_MIN_VERSION \"$$3\"\n#ident \"soap_version.h $$1.$$2.$$3\"\n",$$1,$$2,$$3' >$@ diff --git a/org.glite.security.gsoap-plugin/build.xml b/org.glite.security.gsoap-plugin/build.xml deleted file mode 100755 index 2bae60a..0000000 --- a/org.glite.security.gsoap-plugin/build.xml +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.security.gsoap-plugin/configure b/org.glite.security.gsoap-plugin/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.security.gsoap-plugin/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.security.gsoap-plugin/examples/calc.h.S b/org.glite.security.gsoap-plugin/examples/calc.h.S deleted file mode 100644 index da6ea9f..0000000 --- a/org.glite.security.gsoap-plugin/examples/calc.h.S +++ /dev/null @@ -1,13 +0,0 @@ -//gsoap wscalc service name: CalcService -//gsoap wscalc service type: Calc -//gsoap wscalc service port: https://localhost:19999/ -//gsoap wscalc service namespace: urn:calc:wscalc -//gsoap wscalc service documentation: Calculator service - -//gsoap wscalc service method-documentation: add Adds two numbers -int wscalc__add(double a, double b, struct wscalc__addResponse { -double result; } * ); - -//gsoap wscalc service method-documentation: sub Subtracts two numbers -int wscalc__sub(double a, double b, struct wscalc__subResponse { -double result; } * ); diff --git a/org.glite.security.gsoap-plugin/examples/wscalc_clt_ex.c b/org.glite.security.gsoap-plugin/examples/wscalc_clt_ex.c deleted file mode 100644 index 41f36d4..0000000 --- a/org.glite.security.gsoap-plugin/examples/wscalc_clt_ex.c +++ /dev/null @@ -1,52 +0,0 @@ -#include - -#include "GSOAP_H.h" -#include "CalcService.nsmap" - -static const char *server = "http://localhost:19999/"; - -int -main(int argc, char **argv) -{ - struct soap soap; - double a, b, result; - int ret; - struct wscalc__addResponse addresult; - struct wscalc__subResponse subresult; - - - if (argc < 4) { - fprintf(stderr, "Usage: [add|sub] num num\n"); - exit(1); - } - - soap_init(&soap); - soap_set_namespaces(&soap, namespaces); - soap_register_plugin(&soap, glite_gsplugin); - - a = strtod(argv[2], NULL); - b = strtod(argv[3], NULL); - switch ( *argv[1] ) { - case 'a': - ret = soap_call_wscalc__add(&soap, server, "", a, b, &addresult); - result = addresult.result; - break; - case 's': - ret = soap_call_wscalc__sub(&soap, server, "", a, b, &subresult); - result = subresult.result; - break; - default: - fprintf(stderr, "Unknown command\n"); - exit(2); - } - - if ( ret ) { - fprintf(stderr, "NECO JE V ****\n\n"); - fprintf(stderr, "plugin err: %s", glite_gsplugin_errdesc(&soap)); - soap_print_fault(&soap, stderr); - } - else printf("result = %g\n", result); - - - return 0; -} diff --git a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex.c b/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex.c deleted file mode 100644 index d711b9f..0000000 --- a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex.c +++ /dev/null @@ -1,111 +0,0 @@ -#include -#include -#include -#include - -#include "GSOAP_H.h" -#include "CalcService.nsmap" - - -static struct option long_options[] = { - { "cert", required_argument, NULL, 'c' }, - { "key", required_argument, NULL, 'k' }, - { NULL, 0, NULL, 0 } -}; - -void -usage(const char *me) -{ - fprintf(stderr, - "usage: %s [option]\n" - "\t-c, --cred\t certificate file\n" - "\t-k, --key\t private key file\n", me); -} - - -int -main(int argc, char **argv) -{ - struct soap soap; - glite_gsplugin_Context ctx = NULL; - char *name; - char *cert, *key; - int opt; - edg_wll_GssCred cred; - - cert = key = NULL; - name = strrchr(argv[0],'/'); - if ( name ) name++; else name = argv[0]; - - while ((opt = getopt_long(argc, argv, "c:k:", long_options, NULL)) != EOF) { - switch (opt) { - case 'c': cert = optarg; break; - case 'k': key = optarg; break; - case '?': - default : usage(name); exit(1); - } - } - - soap_init(&soap); - soap_set_namespaces(&soap, namespaces); - - if ( soap_register_plugin_arg(&soap, glite_gsplugin, NULL) ) { - fprintf(stderr, "Can't register plugin\n"); - exit(1); - } - - if ( cert || key ) { - ctx = glite_gsplugin_get_context(&soap); - if (ctx == NULL) { - fprintf(stderr, "Can't get context\n"); - exit(1); - } - - if (glite_gsplugin_set_credential(ctx, cert, key) != 0) { - fprintf(stderr, "Can't set credentials: %s\n", - glite_gsplugin_errdesc(&soap)); - exit(1); - } - } - - if ( soap_bind(&soap, NULL, 19999, 100) < 0 ) { - soap_print_fault(&soap, stderr); - exit(1); - } - - while ( 1 ) { - printf("accepting connection\n"); - if ( soap_accept(&soap) < 0 ) { - fprintf(stderr, "soap_accept() failed!!!\n"); - soap_print_fault(&soap, stderr); - fprintf(stderr, "plugin err: %s\n", glite_gsplugin_errdesc(&soap)); - continue; - } - - printf("serving connection\n"); - if ( soap_serve(&soap) ) { - soap_print_fault(&soap, stderr); - fprintf(stderr, "plugin err: %s", glite_gsplugin_errdesc(&soap)); - } - - soap_destroy(&soap); /* clean up class instances */ - soap_end(&soap); /* clean up everything and close socket */ - } - soap_done(&soap); /* close master socket */ - - if ( ctx ) glite_gsplugin_free_context(ctx); - - return 0; -} - -int wscalc__add(struct soap *soap, double a, double b, struct wscalc__addResponse *result) -{ - result->result = a + b; - return SOAP_OK; -} - -int wscalc__sub(struct soap *soap, double a, double b, struct wscalc__subResponse *result) -{ - result->result = a - b; - return SOAP_OK; -} diff --git a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c b/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c deleted file mode 100644 index d65e625..0000000 --- a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c +++ /dev/null @@ -1,138 +0,0 @@ -#include -#include -#include -#include -#include - -#include "GSOAP_H.h" -#include "CalcService.nsmap" - - -static struct option long_options[] = { - { "cert", required_argument, NULL, 'c' }, - { "key", required_argument, NULL, 'k' }, - { "port", required_argument, NULL, 'p' }, - { NULL, 0, NULL, 0 } -}; - -void -usage(const char *me) -{ - fprintf(stderr, - "usage: %s [option]\n" - "\t-p, --port\t listening port\n" - "\t-c, --cred\t certificate file\n" - "\t-k, --key\t private key file\n", me); -} - - -int -main(int argc, char **argv) -{ - struct soap soap; - edg_wll_GssStatus gss_code; - edg_wll_GssCred cred = NULL; - edg_wll_GssConnection connection; - glite_gsplugin_Context ctx; - struct sockaddr_in a; - int alen; - char *name, *msg; - int opt, - port = 19999; - char *cert_filename = NULL, *key_filename = NULL; - int sock; - - - name = strrchr(argv[0],'/'); - if ( name ) name++; else name = argv[0]; - - if ( glite_gsplugin_init_context(&ctx) ) { perror("init context"); exit(1); } - - while ((opt = getopt_long(argc, argv, "c:k:p:", long_options, NULL)) != EOF) { - switch (opt) { - case 'p': port = atoi(optarg); break; - case 'c': cert_filename = strdup(optarg); break; - case 'k': key_filename = strdup(optarg); break; - case '?': - default : usage(name); exit(1); - } - } - - if ( edg_wll_gss_acquire_cred_gsi(cert_filename, key_filename, &cred, &gss_code) ) { - edg_wll_gss_get_error(&gss_code, "Failed to read credential", &msg); - fprintf(stderr, "%s\n", msg); - free(msg); - exit(1); - } - if (cred->name) { - printf("server running with certificate: %s\n", cred->name); - } - - glite_gsplugin_use_credential(ctx, cred); - - soap_init(&soap); - soap_set_namespaces(&soap, namespaces); - - if ( soap_register_plugin_arg(&soap, glite_gsplugin, ctx) ) { - fprintf(stderr, "Can't register plugin\n"); - exit(1); - } - - alen = sizeof(a); - if ( (sock = socket(PF_INET,SOCK_STREAM,0)) < 0 ) { perror("socket()"); exit(1); } - a.sin_family = AF_INET; - a.sin_port = htons(port); - a.sin_addr.s_addr = INADDR_ANY; - if ( bind(sock, (struct sockaddr *)&a, sizeof(a)) ) { perror("bind()"); exit(1); } - if ( listen(sock, 100) ) { perror("listen()"); exit(1); } - - bzero((char *) &a, alen); - - while ( 1 ) { - int conn; - - printf("accepting connection\n"); - if ( (conn = accept(sock, (struct sockaddr *) &a, &alen)) < 0 ) { - close(sock); - perror("accept"); - exit(1); - } - if ( edg_wll_gss_accept(cred,conn,ctx->timeout,&connection,&gss_code) ){ - edg_wll_gss_get_error(&gss_code, "Failed to read credential", &msg); - fprintf(stderr, "%s\n", msg); - free(msg); - exit(1); - } - - glite_gsplugin_set_connection(ctx, &connection); - - printf("serving connection\n"); - if ( soap_serve(&soap) ) { - soap_print_fault(&soap, stderr); - fprintf(stderr, "plugin err: %s", glite_gsplugin_errdesc(&soap)); - } - - soap_destroy(&soap); /* clean up class instances */ - soap_end(&soap); /* clean up everything and close socket */ - edg_wll_gss_close(&connection, NULL); - } - - soap_done(&soap); /* close master socket */ - - glite_gsplugin_free_context(ctx); - edg_wll_gss_release_cred(&cred, NULL); - - return 0; -} - -int wscalc__add(struct soap *soap, double a, double b, struct wscalc__addResponse *result) -{ - result->result = a + b; - return SOAP_OK; -} - -int wscalc__sub(struct soap *soap, double a, double b, struct wscalc__subResponse *result) -{ - result->result = a - b; - return SOAP_OK; -} diff --git a/org.glite.security.gsoap-plugin/interface/glite_gscompat.h b/org.glite.security.gsoap-plugin/interface/glite_gscompat.h deleted file mode 100644 index 35da223..0000000 --- a/org.glite.security.gsoap-plugin/interface/glite_gscompat.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef GLITE_SECURITY_GSCOMPAT_H -#define GLITE_SECURITY_GSCOMPAT_H - -#ident "$Header: " - -#ifndef GSOAP_VERSION - #error GSOAP_VERSION required -#endif - -#ifndef GSOAP_VERSION_LETTER -#define GSOAP_VERSION_LETTER '\0' -#endif - -#if GSOAP_VERSION >= 20709 || GSOAP_VERSION == 20706 && GSOAP_VERSION_LETTER >= 'd' - #define GLITE_SECURITY_GSOAP_CHOICE_GET(CHOICE, ITEM, TYPENAME, TYPENO) ((CHOICE)->union_##TYPENAME.ITEM) - #define GLITE_SECURITY_GSOAP_CHOICE_SETTYPE(CHOICE, ITEM, NS, TYPENAME, TYPENO) ((CHOICE)->__union_##TYPENAME) = SOAP_UNION__##NS##__union_##TYPENAME##_##ITEM - #define GLITE_SECURITY_GSOAP_CHOICE_ISTYPE(CHOICE, ITEM, NS, TYPENAME, TYPENO) (((CHOICE)->__union_##TYPENAME) == SOAP_UNION__##NS##__union_##TYPENAME##_##ITEM) - /** 2.7.10 requires created dummy choice with type == 0 for empty optional choice */ - #if GSOAP_VERSION >= 20710 - #define GLITE_SECURITY_GSOAP_CHOICE_SETNULL(CHOICE, TYPENAME) ((CHOICE)->__union_##TYPENAME) = 0 - #endif -#elif GSOAP_VERSION >= 20706 - #define GLITE_SECURITY_GSOAP_CHOICE_GET(CHOICE, ITEM, TYPENAME, TYPENO) ((CHOICE)->union_##TYPENO.ITEM) - #define GLITE_SECURITY_GSOAP_CHOICE_SETTYPE(CHOICE, ITEM, NS, TYPENAME, TYPENO) ((CHOICE)->__union_##TYPENO) = SOAP_UNION_##NS##__union_##TYPENO##_##ITEM - #define GLITE_SECURITY_GSOAP_CHOICE_ISTYPE(CHOICE, ITEM, NS, TYPENAME, TYPENO) (((CHOICE)->__union_##TYPENO) == SOAP_UNION_##NS##__union_##TYPENO##_##ITEM) -#else - #define GLITE_SECURITY_GSOAP_CHOICE_GET(CHOICE, ITEM, TYPENAME, TYPENO) ((CHOICE)->ITEM) - #define GLITE_SECURITY_GSOAP_CHOICE_SETTYPE(CHOICE, ITEM, NS, TYPENAME, TYPENO) - #define GLITE_SECURITY_GSOAP_CHOICE_ISTYPE(CHOICE, ITEM, NS, TYPENAME, TYPENO) (((CHOICE)->ITEM) != NULL) -#endif -#define GLITE_SECURITY_GSOAP_CHOICE_SET(CHOICE, ITEM, NS, TYPENAME, TYPENO, VALUE) do { \ - memset((CHOICE), 0, sizeof(*(CHOICE))); \ - GLITE_SECURITY_GSOAP_CHOICE_SETTYPE(CHOICE, ITEM, NS, TYPENAME, TYPENO); \ - GLITE_SECURITY_GSOAP_CHOICE_GET(CHOICE, ITEM, TYPENAME, TYPENO) = (VALUE); \ -} while(0) - -#if GSOAP_VERSION >= 20706 - #define GLITE_SECURITY_GSOAP_REASON2(SOAP) ((SOAP)->fault->SOAP_ENV__Reason ? (SOAP)->fault->SOAP_ENV__Reason->SOAP_ENV__Text : "(no reason)") - #define GLITE_SECURITY_GSOAP_TRUE xsd__boolean__true_ - #define GLITE_SECURITY_GSOAP_FALSE xsd__boolean__false_ -#else - #define GLITE_SECURITY_GSOAP_REASON2(SOAP) ((SOAP)->fault->SOAP_ENV__Reason) - #define GLITE_SECURITY_GSOAP_TRUE true_ - #define GLITE_SECURITY_GSOAP_FALSE false_ -#endif - -#define GLITE_SECURITY_GSOAP_DETAIL(SOAP) ((SOAP)->version == 2 ? (SOAP)->fault->SOAP_ENV__Detail : (SOAP)->fault->detail) -#define GLITE_SECURITY_GSOAP_REASON(SOAP) ((SOAP)->version == 2 ? GLITE_SECURITY_GSOAP_REASON2((SOAP)) : (SOAP)->fault->faultstring) - -#if GSOAP_VERSION >= 20709 - #define GLITE_SECURITY_GSOAP_LIST_CREATE0(SOAP, LIST, SIZE, TYPE, N) do { \ - if ((N) != 0) (LIST) = soap_malloc((SOAP), (N) * sizeof(TYPE)); \ - else (LIST) = NULL; \ - (SIZE) = (N); \ -} while (0) - #define GLITE_SECURITY_GSOAP_LIST_DESTROY0(SOAP, LIST, SIZE) do { \ - if ((LIST) && (SIZE) != 0) soap_dealloc((SOAP), (LIST)); \ - (LIST) = NULL; \ -} while (0) - #define GLITE_SECURITY_GSOAP_LIST_GET(LIST, INDEX) (&(LIST)[INDEX]) - #define GLITE_SECURITY_GSOAP_LIST_TYPE(NS, LIST) struct NS##__##LIST * -#else - #define GLITE_SECURITY_GSOAP_LIST_CREATE0(SOAP, LIST, SIZE, TYPE, N) do { \ - int ilist; \ - \ - if ((N) != 0) (LIST) = soap_malloc((SOAP), (N) * sizeof(void *)); \ - else (LIST) = NULL; \ - (SIZE) = (N); \ - for (ilist = 0; ilist < (N); ilist++) { \ - (LIST)[ilist] = soap_malloc((SOAP), sizeof(TYPE)); \ - } \ -} while (0) - #define GLITE_SECURITY_GSOAP_LIST_DESTROY0(SOAP, LIST, SIZE) do { \ - int ilist; \ - \ - for (ilist = 0; ilist < (SIZE); ilist++) soap_dealloc((SOAP), (LIST)[ilist]); \ - if ((LIST) && (SIZE) != 0) soap_dealloc((SOAP), (LIST)); \ - (LIST) = NULL; \ -} while (0) - #define GLITE_SECURITY_GSOAP_LIST_GET(LIST, INDEX) ((LIST)[INDEX]) - #define GLITE_SECURITY_GSOAP_LIST_TYPE(NS, LIST) struct NS##__##LIST ** -#endif -#define GLITE_SECURITY_GSOAP_LIST_CREATE(SOAP, CONTAINER, LIST, TYPE, N) GLITE_SECURITY_GSOAP_LIST_CREATE0(SOAP, (CONTAINER)->LIST, (CONTAINER)->__size##LIST, TYPE, N) -#define GLITE_SECURITY_GSOAP_LIST_DESTROY(SOAP, CONTAINER, LIST) GLITE_SECURITY_GSOAP_LIST_DESTROY0(SOAP, (CONTAINER)->LIST, (CONTAINER)->__size##LIST) - -#endif diff --git a/org.glite.security.gsoap-plugin/interface/glite_gsplugin-int.h b/org.glite.security.gsoap-plugin/interface/glite_gsplugin-int.h deleted file mode 100644 index 4fa7234..0000000 --- a/org.glite.security.gsoap-plugin/interface/glite_gsplugin-int.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef GLITE_SECURITY_GSOAP_PLUGIN_INTERNAL_H -#define GLITE_SECURITY_GSOAP_PLUGIN_INTERNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "glite/security/glite_gss.h" - -struct _glite_gsplugin_ctx { - struct timeval _timeout, *timeout; - - char *error_msg; - - edg_wll_GssConnection *connection; - edg_wll_GssCred cred; - int internal_connection; - int internal_credentials; - - void *user_data; -}; - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/org.glite.security.gsoap-plugin/interface/glite_gsplugin.h b/org.glite.security.gsoap-plugin/interface/glite_gsplugin.h deleted file mode 100644 index e1e7a91..0000000 --- a/org.glite.security.gsoap-plugin/interface/glite_gsplugin.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef GLITE_SECURITY_GSOAP_PLUGIN_H -#define GLITE_SECURITY_GSOAP_PLUGIN_H - -#include - -#include "glite/security/glite_gss.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PLUGIN_ID "GLITE_GSOAP_PLUGIN" - -typedef struct _glite_gsplugin_ctx *glite_gsplugin_Context; - -extern int glite_gsplugin_init_context(glite_gsplugin_Context *); -extern int glite_gsplugin_free_context(glite_gsplugin_Context); -extern glite_gsplugin_Context glite_gsplugin_get_context(struct soap *); -extern void *glite_gsplugin_get_udata(struct soap *); -extern void glite_gsplugin_set_udata(struct soap *, void *); - -extern void glite_gsplugin_set_timeout(glite_gsplugin_Context, struct timeval const *); -extern int glite_gsplugin_set_credential(glite_gsplugin_Context, const char *, const char *); -extern void glite_gsplugin_use_credential(glite_gsplugin_Context, edg_wll_GssCred); -extern int glite_gsplugin_set_connection(glite_gsplugin_Context, edg_wll_GssConnection *); - -extern int glite_gsplugin(struct soap *, struct soap_plugin *, void *); -extern char *glite_gsplugin_errdesc(struct soap *); - -#ifdef __cplusplus -} -#endif - -#endif /* GLITE_SECURITY_GSOAP_PLUGIN_H */ diff --git a/org.glite.security.gsoap-plugin/project/ChangeLog b/org.glite.security.gsoap-plugin/project/ChangeLog deleted file mode 100644 index e3fcd8a..0000000 --- a/org.glite.security.gsoap-plugin/project/ChangeLog +++ /dev/null @@ -1,26 +0,0 @@ -1.5.3-1 -- avoid memleak in gsoap -- fix #32059 -- support gsoap 2.7.10 - -1.5.4-1 -- handle client connection errors in gsoap (generate faults) -- don't define gsoap.platformName in configuration confusingly - -1.5.4-2 -- disctinct c and c++ builds (concerns gsoap 2.7.10 only) - -2.0.0-1 -- LB 2.0 release - -2.0.0-2 -- configure script update (globus flavors added to configure call) - -2.0.1-1 -- API reverted towards backward compatibility - -2.0.1-2 -- Module repacked - -2.0.1-3 -- install libraries into $libdir diff --git a/org.glite.security.gsoap-plugin/project/build.number b/org.glite.security.gsoap-plugin/project/build.number deleted file mode 100644 index d794048..0000000 --- a/org.glite.security.gsoap-plugin/project/build.number +++ /dev/null @@ -1 +0,0 @@ -module.build=0 diff --git a/org.glite.security.gsoap-plugin/project/build.properties b/org.glite.security.gsoap-plugin/project/build.properties deleted file mode 100644 index e69de29..0000000 diff --git a/org.glite.security.gsoap-plugin/project/configure.properties.xml b/org.glite.security.gsoap-plugin/project/configure.properties.xml deleted file mode 100644 index 3977f05..0000000 --- a/org.glite.security.gsoap-plugin/project/configure.properties.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - -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} -cares_prefix=${with.c-ares.prefix} -globus_prefix=${with.globus.prefix} -thrflavour=${with.globus.thr.flavor} -nothrflavour=${with.globus.nothr.flavor} -cppunit=${with.cppunit.prefix} -gsoap_prefix=${with.gsoap.prefix} -gsoap_default_version=${ext.gsoap.version} -gsoap_name=${ext.gsoap.name} -gsoap_platform=${ext.gsoap.platform} -repository=${repository} - - - diff --git a/org.glite.security.gsoap-plugin/project/libtoolhack/gcc b/org.glite.security.gsoap-plugin/project/libtoolhack/gcc deleted file mode 100644 index 32933cd..0000000 --- a/org.glite.security.gsoap-plugin/project/libtoolhack/gcc +++ /dev/null @@ -1 +0,0 @@ -g++ "$@" diff --git a/org.glite.security.gsoap-plugin/project/package.description b/org.glite.security.gsoap-plugin/project/package.description deleted file mode 100644 index ebfb912..0000000 --- a/org.glite.security.gsoap-plugin/project/package.description +++ /dev/null @@ -1 +0,0 @@ -glite-security-gsoap-plugin is plugin for gSoap providing secured communication via GSS, as well as strict timing control of all operations via glite-security-gss. diff --git a/org.glite.security.gsoap-plugin/project/package.summary b/org.glite.security.gsoap-plugin/project/package.summary deleted file mode 100644 index 2f80d4f..0000000 --- a/org.glite.security.gsoap-plugin/project/package.summary +++ /dev/null @@ -1 +0,0 @@ -Plugin for gSoap to use glite-security-gss as the communication layer. diff --git a/org.glite.security.gsoap-plugin/project/properties.xml b/org.glite.security.gsoap-plugin/project/properties.xml deleted file mode 100755 index f63ddbd..0000000 --- a/org.glite.security.gsoap-plugin/project/properties.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/org.glite.security.gsoap-plugin/project/tar_exclude b/org.glite.security.gsoap-plugin/project/tar_exclude deleted file mode 100644 index b3133e4..0000000 --- a/org.glite.security.gsoap-plugin/project/tar_exclude +++ /dev/null @@ -1,10 +0,0 @@ -tar_exclude -CVS -build.xml -build -build.properties -properties.xml -configure-options.xml -.cvsignore -.project -.cdtproject diff --git a/org.glite.security.gsoap-plugin/project/version.properties b/org.glite.security.gsoap-plugin/project/version.properties deleted file mode 100644 index 1caec29..0000000 --- a/org.glite.security.gsoap-plugin/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# $Header$ -module.version=2.0.1 -module.age=3 diff --git a/org.glite.security.gsoap-plugin/src/glite_gsplugin.c b/org.glite.security.gsoap-plugin/src/glite_gsplugin.c deleted file mode 100644 index 444bf36..0000000 --- a/org.glite.security.gsoap-plugin/src/glite_gsplugin.c +++ /dev/null @@ -1,567 +0,0 @@ -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "soap_version.h" -#include "glite_gsplugin-int.h" -#include "glite_gsplugin.h" - -#ifdef GSPLUGIN_DEBUG -# define pdprintf(s) printf s -#else -# define pdprintf(s) -#endif - -typedef struct _int_plugin_data_t { - glite_gsplugin_Context ctx; /**< data used for connection etc. */ - int def; /**< is the context created by plugin? */ -} int_plugin_data_t; - -static const char plugin_id[] = PLUGIN_ID; - -static void glite_gsplugin_delete(struct soap *, struct soap_plugin *); -static int glite_gsplugin_copy(struct soap *, struct soap_plugin *, struct soap_plugin *); - -static size_t glite_gsplugin_recv(struct soap *, char *, size_t); -static int glite_gsplugin_send(struct soap *, const char *, size_t); -static int glite_gsplugin_connect(struct soap *, const char *, const char *, int); -static int glite_gsplugin_close(struct soap *); -#if GSOAP_VERSION >= 20700 -static int glite_gsplugin_poll(struct soap *); -#endif -static int glite_gsplugin_accept(struct soap *, int, struct sockaddr *, int *); -static int glite_gsplugin_posthdr(struct soap *soap, const char *key, const char *val); - - -int -glite_gsplugin_init_context(glite_gsplugin_Context *ctx) -{ - glite_gsplugin_Context out = (glite_gsplugin_Context) malloc(sizeof(*out)); - if (!out) return ENOMEM; - - memset(out, 0, sizeof(*out)); - out->cred = NULL; - - /* XXX: some troubles with glite_gss and blocking calls! - out->timeout.tv_sec = 10000; - */ - - out->timeout = NULL; - *ctx = out; - - return 0; -} - -int -glite_gsplugin_free_context(glite_gsplugin_Context ctx) -{ - if (ctx == NULL) - return 0; - - if ( ctx->internal_credentials && ctx->cred != NULL ) - edg_wll_gss_release_cred(&ctx->cred, NULL); - if ( ctx->connection ) { - if ( ctx->connection->context != NULL ) - edg_wll_gss_close(ctx->connection, NULL); - free(ctx->connection); - } - if (ctx->error_msg) - free(ctx->error_msg); - free(ctx); - - return 0; -} - -glite_gsplugin_Context -glite_gsplugin_get_context(struct soap *soap) -{ - return ((int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id))->ctx; -} - -void * -glite_gsplugin_get_udata(struct soap *soap) -{ - int_plugin_data_t *pdata; - - pdata = (int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id); - assert(pdata); - return pdata->ctx->user_data; -} - -void -glite_gsplugin_set_udata(struct soap *soap, void *d) -{ - int_plugin_data_t *pdata; - - pdata = (int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id); - assert(pdata); - pdata->ctx->user_data = d; -} - -void glite_gsplugin_set_timeout(glite_gsplugin_Context ctx, struct timeval const *to) -{ - if (to) { - ctx->_timeout = *to; - ctx->timeout = &ctx->_timeout; - } - else ctx->timeout = NULL; -} - -int -glite_gsplugin_set_credential(glite_gsplugin_Context ctx, - const char *cert, - const char *key) -{ - edg_wll_GssStatus gss_code; - edg_wll_GssCred cred = NULL; - - int ret; - - ret = edg_wll_gss_acquire_cred_gsi((char *)cert, (char *)key, &cred, &gss_code); - if (ret) { - edg_wll_gss_get_error(&gss_code, "failed to load GSI credentials", - &ctx->error_msg); - return EINVAL; - } - - if (ctx->internal_credentials && ctx->cred != NULL) - edg_wll_gss_release_cred(&ctx->cred, NULL); - - ctx->cred = cred; - ctx->internal_credentials = 1; - - return 0; -} - -void -glite_gsplugin_use_credential(glite_gsplugin_Context ctx, - edg_wll_GssCred cred) -{ - ctx->cred = cred; - ctx->internal_credentials = 0; -} - -int -glite_gsplugin_set_connection(glite_gsplugin_Context ctx, edg_wll_GssConnection *conn) -{ - int ret = SOAP_OK; - - if ( ctx->connection ) { - if ( ctx->internal_connection && ctx->connection->context != NULL) { - pdprintf(("GSLITE_GSPLUGIN: closing gss connection\n")); - ret = edg_wll_gss_close(ctx->connection, ctx->timeout); - } - free(ctx->connection); - } - if (conn) { - ctx->connection = (edg_wll_GssConnection *)malloc(sizeof(edg_wll_GssConnection)); - memcpy(ctx->connection, conn, sizeof(edg_wll_GssConnection)); - } else ctx->connection = NULL; - ctx->internal_connection = 0; - - return ret; -} - -int -glite_gsplugin(struct soap *soap, struct soap_plugin *p, void *arg) -{ - int_plugin_data_t *pdata = (int_plugin_data_t *)malloc(sizeof(int_plugin_data_t)); - - pdprintf(("GSLITE_GSPLUGIN: initializing gSOAP plugin\n")); - if ( !pdata ) return ENOMEM; - if ( arg ) { - pdprintf(("GSLITE_GSPLUGIN: Context is given\n")); - pdata->ctx = (glite_gsplugin_Context)arg; - pdata->def = 0; - } - else { - edg_wll_GssStatus gss_code; - - pdprintf(("GSLITE_GSPLUGIN: Creating default context\n")); - if ( glite_gsplugin_init_context((glite_gsplugin_Context*)&(pdata->ctx)) ) { - free(pdata); - return ENOMEM; - } - if ( edg_wll_gss_acquire_cred_gsi(NULL, NULL, &pdata->ctx->cred, &gss_code) ) { - /* XXX: Let user know, that cred. load failed. Somehow... - */ - glite_gsplugin_free_context(pdata->ctx); - return EINVAL; - } - pdata->ctx->internal_credentials = 1; - pdprintf(("GSLITE_GSPLUGIN: server running with certificate: %s\n", - pdata->ctx->cred->name)); - pdata->def = 1; - } - - p->id = plugin_id; - p->data = pdata; - p->fdelete = glite_gsplugin_delete; - p->fcopy = glite_gsplugin_copy; - - soap->fopen = glite_gsplugin_connect; - soap->fconnect = NULL; - soap->fclose = glite_gsplugin_close; -#if GSOAP_VERSION >= 20700 - soap->fclosesocket = NULL; - soap->fpoll = glite_gsplugin_poll; -#endif - soap->faccept = glite_gsplugin_accept; - soap->fsend = glite_gsplugin_send; - soap->frecv = glite_gsplugin_recv; - soap->fposthdr = glite_gsplugin_posthdr; - - return SOAP_OK; -} - - -char *glite_gsplugin_errdesc(struct soap *soap) -{ - glite_gsplugin_Context ctx; - - ctx = ((int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id))->ctx; - if ( ctx ) return ctx->error_msg; - - return NULL; -} - - - -static int -glite_gsplugin_copy(struct soap *soap, struct soap_plugin *dst, struct soap_plugin *src) -{ - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_copy()\n")); - /* Should be the copy code here? - */ - return ENOSYS; -} - -static void -glite_gsplugin_delete(struct soap *soap, struct soap_plugin *p) -{ - int_plugin_data_t *d = (int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id); - - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_delete()\n")); - if ( d->def ) { - glite_gsplugin_close(soap); - glite_gsplugin_free_context(d->ctx); - } - free(d); -} - - -static int -glite_gsplugin_connect( - struct soap *soap, - const char *endpoint, - const char *host, - int port) -{ - glite_gsplugin_Context ctx; - edg_wll_GssStatus gss_stat; - int ret; - - - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_connect()\n")); -#if defined(CHECK_GSOAP_VERSION) && GSOAP_VERSION <= 20700 - if ( GSOAP_VERSION < 20700 - || (GSOAP_VERSION == 20700 - && (strlen(GSOAP_MIN_VERSION) < 1 || GSOAP_MIN_VERSION[1] < 'e')) ) { - fprintf(stderr, "Client connect will work only with gSOAP v2.7.0e and later"); - soap->errnum = ENOSYS; - return ENOSYS; - } -#endif - - ctx = ((int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id))->ctx; - if (ctx->connection) { - pdprintf(("GSLITE_GSPLUGIN: Warning: connection dropped, new to %s:%d\n", host, port)); - } - pdprintf(("GSLITE_GSPLUGIN: connection to %s:%d will be established\n", host, port)); - - if ( ctx->cred == NULL ) { - pdprintf(("GSLITE_GSPLUGIN: loading default credentials\n")); - ret = edg_wll_gss_acquire_cred_gsi(NULL, NULL, - &ctx->cred, &gss_stat); - if ( ret ) { - edg_wll_gss_get_error(&gss_stat, "failed to load GSI credentials", - &ctx->error_msg); - goto err; - } - ctx->internal_credentials = 1; - } - - if ( !(ctx->connection = (edg_wll_GssConnection *)malloc(sizeof(*ctx->connection))) ) return errno; - ret = edg_wll_gss_connect(ctx->cred, - host, port, - ctx->timeout, - ctx->connection, &gss_stat); - if ( ret ) { - free(ctx->connection); - ctx->connection = NULL; - edg_wll_gss_get_error(&gss_stat, "edg_wll_gss_connect()", &ctx->error_msg); - goto err; - } - ctx->internal_connection = 1; - - soap->errnum = 0; - return ctx->connection->sock; - -err: - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_connect() error!\n")); - switch ( ret ) { - case EDG_WLL_GSS_ERROR_GSS: - ret = SOAP_INVALID_SOCKET; - soap_set_sender_error(soap, "SSL error", "SSL authentication failed in tcp_connect(): check password, key file, and ca file.", SOAP_SSL_ERROR); - break; - case EDG_WLL_GSS_ERROR_HERRNO: - ret = h_errno; - soap_set_sender_error(soap, "connection error", hstrerror(ret), SOAP_CLI_FAULT); - break; - case EDG_WLL_GSS_ERROR_ERRNO: - ret = errno; - soap_set_sender_error(soap, "connection error", strerror(ret), SOAP_CLI_FAULT); - break; - case EDG_WLL_GSS_ERROR_EOF: ret = ECONNREFUSED; - soap_set_sender_error(soap, "connection error", strerror(ret), SOAP_CLI_FAULT); - break; - case EDG_WLL_GSS_ERROR_TIMEOUT: ret = ETIMEDOUT; - soap_set_sender_error(soap, "connection error", strerror(ret), SOAP_CLI_FAULT); - break; - default: - soap_set_sender_error(soap, "unknown error", "", SOAP_CLI_FAULT); - break; - } - - soap->errnum = ret; - return SOAP_INVALID_SOCKET; -} - -/** It is called in soap_closesocket() - * - * return like errno value - */ -static int -glite_gsplugin_close(struct soap *soap) -{ - glite_gsplugin_Context ctx; - - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_close()\n")); - ctx = ((int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id))->ctx; - return glite_gsplugin_set_connection(ctx, NULL); -} - - -static int -glite_gsplugin_accept(struct soap *soap, int s, struct sockaddr *a, int *n) -{ - glite_gsplugin_Context ctx; - edg_wll_GssStatus gss_code; - int conn; - - soap->errnum = 0; - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_accept()\n")); - ctx = ((int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id))->ctx; - if ( (conn = accept(s, (struct sockaddr *)&a, (socklen_t *)n)) < 0 ) return conn; - if ( !ctx->connection ) { - if ( !(ctx->connection = (edg_wll_GssConnection *)malloc(sizeof(*ctx->connection))) ) { - soap_set_receiver_error(soap, "malloc error", strerror(ENOMEM), ENOMEM); - return SOAP_INVALID_SOCKET; - } - ctx->internal_connection = 1; - } - if ( edg_wll_gss_accept(ctx->cred, conn, ctx->timeout, ctx->connection, &gss_code)) { - pdprintf(("GSLITE_GSPLUGIN: Client authentication failed, closing.\n")); - edg_wll_gss_get_error(&gss_code, "Client authentication failed", &ctx->error_msg); - soap->errnum = SOAP_SVR_FAULT; - soap_set_receiver_error(soap, "SSL error", "SSL authentication failed in tcp_connect(): check password, key file, and ca file.", SOAP_SSL_ERROR); - return SOAP_INVALID_SOCKET; - } - - return conn; -} - -static size_t -glite_gsplugin_recv(struct soap *soap, char *buf, size_t bufsz) -{ - glite_gsplugin_Context ctx; - edg_wll_GssStatus gss_code; - int len; - - - ctx = ((int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id))->ctx; - if ( ctx->error_msg ) { free(ctx->error_msg); ctx->error_msg = NULL; } - - if ( ctx->connection->context == NULL ) { - soap->errnum = ENOTCONN; - /* XXX: glite_gsplugin_send() returns SOAP_EOF on errors - */ - return 0; - } - - len = edg_wll_gss_read(ctx->connection, buf, bufsz, - ctx->timeout, - &gss_code); - - switch ( len ) { - case EDG_WLL_GSS_OK: - break; - - case EDG_WLL_GSS_ERROR_GSS: - edg_wll_gss_get_error(&gss_code, "receving WS request", - &ctx->error_msg); - soap->errnum = ENOTCONN; - return 0; - - case EDG_WLL_GSS_ERROR_ERRNO: - ctx->error_msg = strdup("edg_wll_gss_read()"); - soap->errnum = errno; - return 0; - - case EDG_WLL_GSS_ERROR_TIMEOUT: - soap->errnum = ETIMEDOUT; - return 0; - - case EDG_WLL_GSS_ERROR_EOF: - soap->errnum = ENOTCONN; - return 0; - - /* default: fallthrough */ - } - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_recv() = %d\n",len)); - - return len; -} - -static int -glite_gsplugin_send(struct soap *soap, const char *buf, size_t bufsz) -{ - glite_gsplugin_Context ctx; - edg_wll_GssStatus gss_code; - struct sigaction sa, osa; - size_t total = 0; - int ret; - - - ctx = ((int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id))->ctx; - /* XXX: check whether ctx is initialized - * i.e. ctx->connection != NULL - */ - if ( ctx->error_msg ) { free(ctx->error_msg); ctx->error_msg = NULL; } - if ( ctx->connection == NULL || ctx->connection->context == NULL ) { - soap->errnum = ENOTCONN; - return SOAP_EOF; - } - - memset(&sa, 0, sizeof(sa)); - assert(sa.sa_handler == NULL); - sa.sa_handler = SIG_IGN; - sigaction(SIGPIPE, &sa, &osa); - - ret = edg_wll_gss_write_full(ctx->connection, - (void*)buf, bufsz, ctx->timeout, &total, &gss_code); - - sigaction(SIGPIPE, &osa, NULL); - - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_send(%d) = %d\n",bufsz,ret)); - - switch ( ret ) { - case EDG_WLL_GSS_OK: - break; - - case EDG_WLL_GSS_ERROR_TIMEOUT: - ctx->error_msg = strdup("glite_gsplugin_send()"); - soap->errnum = ETIMEDOUT; - return SOAP_EOF; - - case EDG_WLL_GSS_ERROR_ERRNO: - if ( errno == EPIPE ) { - ctx->error_msg = strdup("glite_gsplugin_send()"); - soap->errnum = ENOTCONN; - } - else { - ctx->error_msg = strdup("glite_gsplugin_send()"); - soap->errnum = errno; - } - return SOAP_EOF; - - case EDG_WLL_GSS_ERROR_GSS: - case EDG_WLL_GSS_ERROR_EOF: - default: - ctx->error_msg = strdup("glite_gsplugin_send()"); - soap->errnum = ENOTCONN; - return SOAP_EOF; - } - - return SOAP_OK; -} - - -#if GSOAP_VERSION >= 20700 -static int -glite_gsplugin_poll(struct soap *soap) -{ - glite_gsplugin_Context ctx; - fd_set readfds; - struct timeval timeout = {tv_sec: 0, tv_usec: 0}; - int ret; - - ctx = ((int_plugin_data_t *)soap_lookup_plugin(soap, plugin_id))->ctx; - if (!ctx->connection || !ctx->connection->context) { - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_poll, no connection\n")); - return SOAP_EOF; - } - - FD_ZERO(&readfds); - FD_SET(ctx->connection->sock, &readfds); - ret = select(ctx->connection->sock + 1, &readfds, NULL, NULL, &timeout); - if (ret < 0) { - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_poll, select(%d) failed\n", ctx->connection->sock)); - return SOAP_TCP_ERROR; - } else if (ret == 0) { - /* has been OK but server can disconnect anytime */ - return SOAP_OK; - } else { - pdprintf(("GSLITE_GSPLUGIN: glite_gsplugin_poll, select(%d) = %d\n", ctx->connection->sock, ret)); - return SOAP_EOF; - } -} -#endif - - -static int http_send_header(struct soap *soap, const char *s) { - 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; -} - - -static int glite_gsplugin_posthdr(struct soap *soap, const char *key, const char *val) { - if (key) { - if (strcmp(key, "Status") == 0) { - snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "HTTP/%s", soap->http_version); - if (http_send_header(soap, soap->tmpbuf)) return soap->error; - if (val && (soap_send_raw(soap, " ", 1) || http_send_header(soap, val))) - return soap->error; - } else { - 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); -} diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.c b/org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.c deleted file mode 100644 index 78c4872..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.c +++ /dev/null @@ -1,11020 +0,0 @@ -/* - -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 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, "")) - 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, "", 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, "", 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, "", 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 - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.h b/org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.h deleted file mode 100644 index 15a47fa..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.6.2.h +++ /dev/null @@ -1,1647 +0,0 @@ -/* - -stdsoap2.h 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 --------------------------------------------------------------------------------- -*/ - -#ifdef WITH_SOAPDEFS_H -# include "soapdefs.h" /* include user-defined stuff */ -#endif - -#ifndef _THREAD_SAFE -# define _THREAD_SAFE -#endif - -#ifndef OPENSERVER -# ifndef _REENTRANT -# define _REENTRANT -# endif -#endif - -#ifndef SOAP_BEGIN_NAMESPACE -# define SOAP_BEGIN_NAMESPACE(name) -#endif - -#ifndef SOAP_END_NAMESPACE -# define SOAP_END_NAMESPACE(name) -#endif - -#ifndef SOAP_FMAC1 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC1 -#endif - -#ifndef SOAP_FMAC2 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC2 -#endif - -#ifndef SOAP_FMAC3 /* (de)serializer declaration macro */ -# define SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC4 /* (de)serializer declaration macro */ -# define SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC5 /* stub/skeleton declaration macro */ -# define SOAP_FMAC5 -#endif - -#ifndef SOAP_FMAC6 /* stub/skeleton declaration macro */ -# define SOAP_FMAC6 -#endif - -#ifndef SOAP_CMAC /* class declaration macro */ -# define SOAP_CMAC -#endif - -#ifndef SOAP_NMAC /* namespace table declaration macro */ -# define SOAP_NMAC -#endif - -#ifndef SOAP_SOURCE_STAMP -# define SOAP_SOURCE_STAMP(str) -#endif - -#ifdef WITH_LEANER -# ifndef WITH_LEAN -# define WITH_LEAN -# endif -#endif - -#ifdef WITH_LEAN -# ifdef WITH_COOKIES -# error "Cannot build WITH_LEAN code WITH_COOKIES enabled" -# endif -#endif - -#ifndef STDSOAP_H -#define STDSOAP_H - -/* WR[ */ -#if (defined(__vxworks) || defined(__VXWORKS__)) -# define VXWORKS -#endif -/* ]WR */ - -#ifdef _WIN32 -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef UNDER_CE -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef __BORLANDC__ -# ifdef __WIN32__ -# ifndef WIN32 -# define WIN32 -# endif -# endif -#endif - -#ifdef __CYGWIN__ -# ifndef CYGWIN -# define CYGWIN -# endif -#endif - -#ifdef __SYMBIAN32__ -# define SYMBIAN -#endif - -#ifdef __palmos__ -# define PALM -#endif - -#ifdef PALM_GCC -# define PALM -#endif - -#ifdef HAVE_CONFIG_H -# include "config.h" -#else -# if defined(UNDER_CE) -# define WITH_LEAN -# elif defined(WIN32) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(CYGWIN) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__APPLE__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(_AIXVERSION_431) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(HP_UX) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(FREEBSD) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GETTIMEOFDAY -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__VMS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__GLIBC__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(TRU64) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GETTIMEOFDAY -# define HAVE_SYS_TIMEB_H -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(MAC_CARBON) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(PALM) -# define HAVE_STRTOD /* strtod() is defined in palmmissing.h */ -# ifndef CONST2 -# define CONST2 -# endif -# define WITH_LEAN -# define WITH_NONAMESPACES -# define _LINUX_CTYPE_H -# include - typedef WChar wchar_t; -# define IGNORE_STDIO_STUBS - typedef Int32 time_t; -# define tm HostTmType -# define strftime HostStrFTime -# define mktime HostMkTime -# define localtime HostLocalTime -# define tm_year tm_year_ -# define tm_hour tm_hour_ -# define tm_mon tm_mon_ -# define tm_min tm_min_ -# define tm_sec tm_sec_ -# define tm_mday tm_mday_ -# define tm_isdst tm_isdst_ -# include -# define O_NONBLOCK FNONBIO -# include -# if 1 - void displayText(char *text); -# define pdebug(s) displayText(s) -# define pdebugV(s,p) sprintf(buff,s,p); displayText(buff) -# else -# define pdebug(s) WinDrawChars(s,strlen(s),10,10) -# define pdebugV(s,p) sprintf(buff,s,p); WinDrawChars(buff,strlen(buff),10,10) -# endif -# include "palmmissing.h" -# include "slib_socket.h" -# elif defined(SYMBIAN) -# define WITH_LEAN -# define WITH_NONAMESPACES -# define CONST2 const -# undef SOAP_FMAC1 -# define SOAP_FMAC1 EXPORT_C -# ifdef __cplusplus -# include -# else -# define TInt64 long -# endif -/* WR[ */ -# elif defined(VXWORKS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_PGMTIME_R -# define HAVE_PLOCALTIME_R -# define HAVE_MKTIME -/* ]WR */ -# else -/* Default asumptions on supported functions */ -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# endif -#endif - -#if defined(TRU64) -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -#elif defined(WIN32) -# define SOAP_LONG_FORMAT "%I64d" -# define SOAP_ULONG_FORMAT "%I64u" -#endif - -#ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%lld" /* printf format for 64 bit ints */ -#endif - -#ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%llu" /* printf format for unsigned 64 bit ints */ -#endif - -#ifndef SOAP_MALLOC /* use libc malloc */ -# define SOAP_MALLOC(n) malloc(n) -#endif - -#ifndef SOAP_FREE /* use libc free */ -# define SOAP_FREE(p) free(p) -#endif - -#include - -#ifndef PALM -# include -#endif - -#ifndef PALM_GCC -# include -#endif - -#include /* for tolower() */ -#include - -#if defined(__cplusplus) && !defined(UNDER_CE) -# include -# include - using namespace std; -#endif - -#ifndef UNDER_CE -# ifndef PALM -# include -# ifndef MAC_CARBON -# include -# endif -# ifndef WITH_LEAN -# ifdef HAVE_SYS_TIMEB_H -# include /* for ftime() */ -# endif -# include -# endif -# endif -#endif - -#ifdef OPENSERVER -# include -# include -# include - extern int h_errno; -#endif - -#ifndef MAC_CARBON -# ifndef WIN32 -# ifndef PALM -# include -/* WR[ */ -# ifdef VXWORKS -# include -# endif -# ifndef VXWORKS -/* ]WR */ -# ifndef SYMBIAN -# include -# endif -/* WR[ */ -# endif -/* ]WR */ -# ifdef SUN_OS -# include /* SUN */ -# include /* SUN < 2.8 (?) */ -# endif -/* WR[ */ -# ifdef VXWORKS -# include -# else -/* ]WR */ -# include -/* WR[ */ -# endif -/* ]WR */ -# include -# include /* TCP_NODELAY */ -# include -# endif -# endif -#endif - -#ifdef WITH_FASTCGI -# include -#endif - -#ifdef WITH_OPENSSL -# define OPENSSL_NO_KRB5 -# include -# include -# include -# ifndef ALLOW_OLD_VERSIONS -# if (OPENSSL_VERSION_NUMBER < 0x00905100L) -# error "Must use OpenSSL 0.9.6 or later" -# endif -# endif -#endif - -#ifdef WITH_GZIP -# ifndef WITH_ZLIB -# define WITH_ZLIB -# endif -#endif - -#ifdef WITH_CASEINSENSITIVETAGS -# define SOAP_STRCMP soap_tag_cmp /* case insensitve XML element/attribute names */ -#else -# define SOAP_STRCMP strcmp /* case sensitive XML element/attribute names */ -#endif - -#ifdef WITH_ZLIB -# include -#endif - -#ifndef PALM_GCC -# include /* for isnan() */ -#endif - -/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define soap_get0(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx]) -#define soap_get1(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx++]) -#define soap_revget1(soap) ((soap)->bufidx--) -#define soap_unget(soap, c) ((soap)->ahead = c) -#define soap_register_plugin(soap, plugin) soap_register_plugin_arg(soap, plugin, NULL) -#define soap_imode(soap, n) ((soap)->mode = (soap)->imode = (n)) -#define soap_set_imode(soap, n) ((soap)->mode = (soap)->imode |= (n)) -#define soap_clr_imode(soap, n) ((soap)->mode = (soap)->imode &= ~(n)) -#define soap_omode(soap, n) ((soap)->mode = (soap)->omode = (n)) -#define soap_set_omode(soap, n) ((soap)->mode = (soap)->omode |= (n)) -#define soap_clr_omode(soap, n) ((soap)->mode = (soap)->omode &= ~(n)) -#define soap_destroy(soap) soap_delete((soap), NULL) - -#ifdef WIN32 -# ifndef UNDER_CE -# include -# include -# endif -# include -/* # include */ /* Alternative: use winsock2 (not available with eVC) */ -/* WR[ */ -# ifdef WITH_IPV6 -# include -# include -# endif -#else -# ifdef VXWORKS -# include -# include -# include -# endif -/* ]WR */ -# ifndef MAC_CARBON -# ifndef PALM -# include -# include -# endif -# include -# include -# endif -#endif - -#ifdef WIN32 -# define SOAP_SOCKET SOCKET -#else -# define SOAP_SOCKET int -# define closesocket(n) close(n) -#endif - -#define soap_valid_socket(n) ((n) >= 0) -#define SOAP_INVALID_SOCKET (-1) - -/* WR[ */ -#ifdef VXWORKS -# ifdef __INCmathh -# define _MATH_H -# include -# define isnan(num) isNan(num) -# endif -#endif - -#ifdef WIN32 -# define _MATH_H -# include -# define isnan(num) _isnan(num) -#endif -/* ]WR */ - -#if (!defined(_MATH_H) && !defined(_MATH_INCLUDED)) -# ifndef isnan -# define isnan(_) (0) -# endif -#endif - -extern const struct soap_double_nan { unsigned int n1, n2; } soap_double_nan; - -#if defined(SYMBIAN) -# define LONG64 TInt64 -# define ULONG64 TInt64 -#elif !defined(WIN32) -# define LONG64 long long -# define ULONG64 unsigned LONG64 -#elif defined(UNDER_CE) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#elif defined(__BORLANDC__) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#endif - -#ifdef WIN32 -# define SOAP_EINTR WSAEINTR -# define SOAP_EAGAIN WSAEWOULDBLOCK -# define SOAP_EWOULDBLOCK WSAEWOULDBLOCK -# define SOAP_EINPROGRESS WSAEINPROGRESS -#else -# define SOAP_EINTR EINTR -# define SOAP_EAGAIN EAGAIN -# ifdef SYMBIAN -# define SOAP_EWOULDBLOCK 9898 -# define SOAP_EINPROGRESS 9899 -# else -# define SOAP_EWOULDBLOCK EWOULDBLOCK -# define SOAP_EINPROGRESS EINPROGRESS -# endif -#endif - -#ifdef WIN32 -# ifdef UNDER_CE -# define soap_errno GetLastError() -# define soap_socket_errno GetLastError() -# else -# define soap_errno GetLastError() -# define soap_socket_errno WSAGetLastError() -# endif -#else -# define soap_errno errno -# define soap_socket_errno errno -#endif - -#ifndef SOAP_BUFLEN -# ifndef WITH_LEAN -# define SOAP_BUFLEN (32768) /* buffer length for socket packets, also used by gethostbyname_r so don't make this too small */ -# else -# define SOAP_BUFLEN (2048) -# endif -#endif -#ifndef SOAP_LABLEN -# ifndef WITH_LEAN -# define SOAP_LABLEN (256) /* initial look-aside buffer length */ -# else -# define SOAP_LABLEN (64) -# endif -#endif -#ifndef SOAP_PTRHASH -# ifndef WITH_LEAN -# define SOAP_PTRHASH (1024) /* size of pointer analysis hash table (must be power of 2) */ -# else -# define SOAP_PTRHASH (16) -# endif -#endif -#ifndef SOAP_IDHASH -# ifndef WITH_LEAN -# define SOAP_IDHASH (256) /* size of hash table for receiving id/href's */ -# else -# define SOAP_IDHASH (16) -# endif -#endif -#ifndef SOAP_BLKLEN -# define SOAP_BLKLEN (256) /* size of blocks to collect long strings and XML attributes */ -#endif -#ifndef SOAP_TAGLEN -# define SOAP_TAGLEN (256) /* maximum length of XML element tag/attribute name + 1 */ -#endif -#ifndef SOAP_HDRLEN -# ifndef WITH_LEAN -# define SOAP_HDRLEN (8192) /* maximum length of HTTP header line (must be >4096 to read cookies) */ -# else -# define SOAP_HDRLEN (1024) -# endif -#endif -#ifndef SOAP_MAXDIMS -# define SOAP_MAXDIMS (16) /* maximum array dimensions (array nestings) must be less than 64 to protect soap->tmpbuf */ -#endif - -#ifndef SOAP_MAXLOGS -# define SOAP_MAXLOGS (3) /* max number of debug logs per struct soap environment */ -# define SOAP_INDEX_RECV (0) -# define SOAP_INDEX_SENT (1) -# define SOAP_INDEX_TEST (2) -#endif - -#ifndef SOAP_MAXKEEPALIVE -# define SOAP_MAXKEEPALIVE (100) /* max iterations to keep server connection alive */ -#endif - -#ifndef SOAP_MAXARRAYSIZE -# define SOAP_MAXARRAYSIZE (100000) /* "trusted" max size of inbound SOAP array for compound array allocation */ -#endif - -/* WR[ */ -#ifdef VXWORKS -# ifndef FLT_MAX -# define FLT_MAX _ARCH_FLT_MAX -# endif -# ifndef DBL_MAX -# define DBL_MAX _ARCH_DBL_MAX -# endif -#endif -/* ]WR */ - -#ifndef FLT_NAN -# if (defined(_MATH_H) || defined(_MATH_INCLUDED)) -# define FLT_NAN (*(float*)&soap_double_nan) -# else -# define FLT_NAN (0.0) -# endif -#endif - -#ifndef FLT_PINFTY -# ifdef FLT_MAX -# define FLT_PINFTY FLT_MAX -# else -# ifdef HUGE_VAL -# define FLT_PINFTY (float)HUGE_VAL -# else -# ifdef FLOAT_MAX -# define FLT_PINFTY FLOAT_MAX -# else -# define FLT_PINFTY (3.40282347e+38) -# endif -# endif -# endif -#endif - -#ifndef FLT_NINFTY -# define FLT_NINFTY (-FLT_PINFTY) -#endif - -#ifndef DBL_NAN -# if (defined(_MATH_H) || defined(_MATH_INCLUDED)) -# define DBL_NAN (*(double*)&soap_double_nan) -# else -# define DBL_NAN (0.0) -# endif -#endif -#ifndef DBL_PINFTY -# ifdef DBL_MAX -# define DBL_PINFTY DBL_MAX -# else -# ifdef HUGE_VAL -# define DBL_PINFTY (double)HUGE_VAL -# else -# ifdef DOUBLE_MAX -# define DBL_PINFTY DOUBLE_MAX -# else -# define DBL_PINFTY (1.7976931348623157e+308) -# endif -# endif -# endif -#endif - -#ifndef DBL_NINFTY -# define DBL_NINFTY (-DBL_PINFTY) -#endif - -/* gSOAP error codes */ - -#define SOAP_EOF EOF -#define SOAP_ERR EOF -#define SOAP_OK 0 -#define SOAP_CLI_FAULT 1 -#define SOAP_SVR_FAULT 2 -#define SOAP_TAG_MISMATCH 3 -#define SOAP_TYPE 4 -#define SOAP_SYNTAX_ERROR 5 -#define SOAP_NO_TAG 6 -#define SOAP_IOB 7 -#define SOAP_MUSTUNDERSTAND 8 -#define SOAP_NAMESPACE 9 -#define SOAP_OBJ_MISMATCH 10 -#define SOAP_FATAL_ERROR 11 -#define SOAP_FAULT 12 -#define SOAP_NO_METHOD 13 -#define SOAP_GET_METHOD 14 -#define SOAP_EOM 15 -#define SOAP_NULL 16 -#define SOAP_MULTI_ID 17 -#define SOAP_MISSING_ID 18 -#define SOAP_HREF 19 -#define SOAP_TCP_ERROR 20 -#define SOAP_HTTP_ERROR 21 -#define SOAP_SSL_ERROR 22 -#define SOAP_ZLIB_ERROR 23 -#define SOAP_DIME_ERROR 24 -#define SOAP_EOD 25 -#define SOAP_VERSIONMISMATCH 26 -#define SOAP_DIME_MISMATCH 27 -#define SOAP_PLUGIN_ERROR 28 -#define SOAP_DATAENCODINGUNKNOWN 29 -#define SOAP_REQUIRED 30 -#define SOAP_OCCURS 31 - -#define soap_xml_error_check(e) ((e) == SOAP_TAG_MISMATCH || (e) == SOAP_SYNTAX_ERROR || (e) == SOAP_NAMESPACE || (e) == SOAP_MULTI_ID || (e) == SOAP_MISSING_ID || (e) == SOAP_REQUIRED || (e) == SOAP_OCCURS) -#define soap_soap_error_check(e) ((e) == SOAP_CLI_FAULT || (e) == SOAP_SVR_FAULT || (e) == SOAP_VERSIONMISMATCH || (e) == SOAP_MUSTUNDERSTAND || (e) == SOAP_FAULT || (e) == SOAP_NO_METHOD || (e) == SOAP_OBJ_MISMATCH || (e) == SOAP_NULL) -#define soap_tcp_error_check(e) ((e) == SOAP_EOF || (e) == SOAP_TCP_ERROR) -#define soap_ssl_error_check(e) ((e) == SOAP_SSL_ERROR) -#define soap_zlib_error_check(e) ((e) == SOAP_ZLIB_ERROR) -#define soap_dime_error_check(e) ((e) == SOAP_DIME_ERROR || (e) == SOAP_DIME_MISMATCH) -#define soap_http_error_check(e) ((e) == SOAP_HTTP_ERROR || (e) == SOAP_GET_METHOD || ((e) >= 100 && (e) < 600)) - -/* gSOAP HTTP response status codes 100 to 600 are reserved */ - -/* Special gSOAP HTTP response status codes */ - -#define SOAP_STOP 1000 /* No HTTP response */ -#define SOAP_HTML 1001 /* Custom HTML response */ -#define SOAP_FILE 1002 /* Custom file-based response */ - -/* gSOAP HTTP request status codes */ - -#define SOAP_POST 1003 -#define SOAP_GET 1104 - -/* gSOAP DIME */ - -#define SOAP_DIME_CF 0x01 -#define SOAP_DIME_ME 0x02 -#define SOAP_DIME_MB 0x04 -#define SOAP_DIME_VERSION 0x08 /* DIME version 1 */ -#define SOAP_DIME_MEDIA 0x10 -#define SOAP_DIME_ABSURI 0x20 - -/* gSOAP ZLIB */ - -#define SOAP_ZLIB_NONE 0x00 -#define SOAP_ZLIB_DEFLATE 0x01 -#define SOAP_ZLIB_INFLATE 0x02 -#define SOAP_ZLIB_GZIP 0x02 - -/* gSOAP transport, connection, and content encoding modes */ - -#define SOAP_IO 0x000003 -#define SOAP_IO_FLUSH 0x000000 /* flush output immediately, no buffering */ -#define SOAP_IO_BUFFER 0x000001 /* buffer output in packets of size SOAP_BUFLEN */ -#define SOAP_IO_STORE 0x000002 /* store entire output to determine length for transport */ -#define SOAP_IO_CHUNK 0x000003 /* use HTTP chunked transfer AND buffer packets */ - -#define SOAP_IO_LENGTH 0x000004 -#define SOAP_IO_KEEPALIVE 0x000008 - -#define SOAP_ENC_XML 0x000010 /* plain XML encoding, no HTTP header */ -#define SOAP_ENC_DIME 0x000020 -#define SOAP_ENC_ZLIB 0x000040 -#define SOAP_ENC_SSL 0x000080 - -#define SOAP_XML_STRICT 0x000100 /* input mode flag */ -#define SOAP_XML_CANONICAL 0x000200 /* output mode flag */ -#define SOAP_XML_TREE 0x000400 -#define SOAP_XML_GRAPH 0x000800 -#define SOAP_XML_NIL 0x001000 -#define SOAP_XML_DOM 0x002000 - -#define SOAP_C_NOIOB 0x010000 -#define SOAP_C_UTFSTRING 0x020000 -#define SOAP_C_MBSTRING 0x040000 -#define SOAP_C_LATIN 0x080000 - -#define SOAP_DOM_TREE 0x100000 -#define SOAP_DOM_NODE 0x200000 - -#define SOAP_IO_DEFAULT SOAP_IO_FLUSH - -/* SSL client/server authentication settings */ - -#define SOAP_SSL_NO_AUTHENTICATION 0x00 /* for testing purposes */ -#define SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION 0x01 /* client requires server to authenticate */ -#define SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION 0x02 /* server requires client to authenticate */ - -#define SOAP_SSL_DEFAULT SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION - -/* */ - -#define SOAP_BEGIN 0 -#define SOAP_IN_ENVELOPE 2 -#define SOAP_IN_HEADER 3 -#define SOAP_END_HEADER 4 -#define SOAP_IN_BODY 5 -#define SOAP_END_BODY 6 -#define SOAP_END_ENVELOPE 7 -#define SOAP_END 8 - -/* DEBUG macros */ - -#ifndef WITH_LEAN -# ifdef DEBUG -# ifndef SOAP_DEBUG -# define SOAP_DEBUG -# endif -# endif -#endif - -#ifdef SOAP_DEBUG -# ifndef SOAP_MESSAGE -# define SOAP_MESSAGE fprintf -# endif -# ifndef DBGLOG -# define DBGLOG(DBGFILE, CMD) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ - CMD;\ - fflush(fdebug);\ - }\ - }\ -} -# endif -# ifndef DBGMSG -# define DBGMSG(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { fwrite((MSG), 1, (LEN), soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -#else -# define DBGLOG(DBGFILE, CMD) -# define DBGMSG(DBGFILE, MSG, LEN) -#endif - -typedef long wchar; /* 32 bit, for compatibility */ - -struct Namespace -{ const char *id; - const char *ns; - const char *in; - char *out; -}; - -struct soap_nlist -{ struct soap_nlist *next; - unsigned int level; - short index; /* corresponding entry in ns mapping table */ - char *ns; /* only set when parsed ns URI is not in the ns mapping table */ - char id[1]; /* the actual string value overflows into allocated region below this struct */ -}; - -struct soap_blist -{ struct soap_blist *next; - char *ptr; - size_t size; -}; - -struct soap_array -{ void *__ptr; - int __size; -}; - -/* pointer serialization management */ -struct soap_plist -{ struct soap_plist *next; - const void *ptr; - const struct soap_array *array; - int type; - int id; - char mark1; - char mark2; -}; - -/* class allocation list */ -struct soap_clist -{ struct soap_clist *next; - void *ptr; - int type; - int size; - void (*fdelete)(struct soap_clist*); -}; - -/* id-ref forwarding list */ -struct soap_ilist -{ struct soap_ilist *next; - int type; - size_t size; - void *link; - void *copy; - struct soap_flist *flist; - void *ptr; - unsigned int level; - char id[1]; /* the actual id string value overflows into allocated region below this struct */ -}; - -struct soap_attribute -{ struct soap_attribute *next; - short visible; - char *value; - size_t size; - char *ns; - char name[1]; /* the actual name string overflows into allocated region below this struct */ -}; - -struct soap_cookie -{ struct soap_cookie *next; - char *name; - char *value; - char *domain; - char *path; - long expire; /* client-side: local time to expire; server-side: seconds to expire */ - unsigned int version; - short secure; - short session; /* server-side */ - short env; /* server-side: got cookie from client */ - short modified; /* server-side: client cookie was modified */ -}; - -struct soap_dom_attribute -{ struct soap_dom_attribute *next; - const char *nstr; - char *name; - char *data; - wchar_t *wide; - struct soap *soap; -#ifdef __cplusplus - struct soap_dom_attribute &set(const char *nstr, const char *name); // set namespace and name - struct soap_dom_attribute &set(const char *data); // set data - void unlink(); - soap_dom_attribute(); - soap_dom_attribute(struct soap *soap); - soap_dom_attribute(struct soap *soap, const char *nstr, const char *name, const char *data); - ~soap_dom_attribute(); -#endif -}; - -#ifdef __cplusplus -class soap_dom_iterator -{ public: - struct soap_dom_element *elt; - const char *nstr; - const char *name; - int type; - bool operator==(const soap_dom_iterator&) const; - bool operator!=(const soap_dom_iterator&) const; - struct soap_dom_element &operator*() const; - soap_dom_iterator &operator++(); - soap_dom_iterator(); - soap_dom_iterator(struct soap_dom_element*); - ~soap_dom_iterator(); -}; -#endif - -struct soap_dom_element -{ struct soap_dom_element *next; /* next sibling */ - struct soap_dom_element *prnt; /* parent */ - struct soap_dom_element *elts; /* first child element */ - struct soap_dom_attribute *atts; /* first child attribute */ - const char *nstr; /* namespace string */ - char *name; /* element tag name */ - char *data; /* element content data (with SOAP_C_UTFSTRING flag set) */ - wchar_t *wide; /* element content data */ - int type; /* optional: serialized C/C++ data type */ - void *node; /* optional: pointer to serialized C/C++ data */ - struct soap *soap; -#ifdef __cplusplus - typedef soap_dom_iterator iterator; - struct soap_dom_element &set(const char *nstr, const char *name); - struct soap_dom_element &set(const char *data); - struct soap_dom_element &set(void *node, int type); - struct soap_dom_element &add(struct soap_dom_element*); - struct soap_dom_element &add(struct soap_dom_element&); - struct soap_dom_element &add(struct soap_dom_attribute*); - struct soap_dom_element &add(struct soap_dom_attribute&); - soap_dom_iterator begin(); - soap_dom_iterator end(); - soap_dom_iterator find(const char *nstr, const char *name); - soap_dom_iterator find(int type); - void unlink(); - soap_dom_element(); - soap_dom_element(struct soap *soap); - soap_dom_element(struct soap *soap, const char *nstr, const char *name); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type); - ~soap_dom_element(); -#endif -}; - -#if defined(__cplusplus) && !defined(UNDER_CE) -} -extern ostream &operator<<(ostream&, const struct soap_dom_element&); -extern istream &operator>>(istream&, struct soap_dom_element&); -extern "C" { -#endif - -struct soap -{ short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table) */ - unsigned int mode; - unsigned int imode; - unsigned int omode; - short copy; /* 1 = copy of another soap struct */ - const char *float_format; /* points to user-definable format string for floats (<1024 chars) */ - const char *double_format; /* points to user-definable format string for doubles (<1024 chars) */ - const char *dime_id_format; /* points to user-definable format string for integer DIME id ( 0, gives socket recv timeout in seconds, < 0 in usec */ - int send_timeout; /* when > 0, gives socket send timeout in seconds, < 0 in usec */ - int connect_timeout; /* when > 0, gives socket connect() timeout in seconds, < 0 in usec */ - int accept_timeout; /* when > 0, gives socket accept() timeout in seconds, < 0 in usec */ - int socket_flags; /* socket recv() and send() flags, e.g. set to MSG_NOSIGNAL to disable sigpipe */ - int connect_flags; /* connect() SOL_SOCKET sockopt flags, e.g. set to SO_DEBUG to debug socket */ - int bind_flags; /* bind() SOL_SOCKET sockopt flags, e.g. set to SO_REUSEADDR to enable reuse */ - int accept_flags; /* accept() SOL_SOCKET sockopt flags */ - struct Namespace *namespaces; /* Pointer to global namespace mapping table */ - struct Namespace *local_namespaces; /* Local namespace mapping table */ - struct soap_nlist *nlist; /* namespace stack */ - struct soap_blist *blist; /* block allocation stack */ - struct soap_clist *clist; /* class instance allocation list */ - void *alist; /* memory allocation list */ - struct soap_ilist *iht[SOAP_IDHASH]; - struct soap_plist *pht[SOAP_PTRHASH]; - struct SOAP_ENV__Header *header; - struct SOAP_ENV__Fault *fault; - void *user; /* to pass user-defined data */ - struct soap_plugin *plugins; /* linked list of plug-in data */ - char *userid; /* HTTP Basic authorization userid */ - char *passwd; /* HTTP Basic authorization passwd */ - int (*fpost)(struct soap*, const char*, const char*, int, const char*, const char*, size_t); - int (*fget)(struct soap*); - int (*fposthdr)(struct soap*, const char*, const char*); - int (*fresponse)(struct soap*, int, size_t); - int (*fparse)(struct soap*); - int (*fparsehdr)(struct soap*, const char*, const char*); - int (*fconnect)(struct soap*, const char*, const char*, int); - int (*fdisconnect)(struct soap*); - int (*fopen)(struct soap*, const char*, const char*, int); - int (*faccept)(struct soap*, int, struct sockaddr*, int *n); - int (*fclose)(struct soap*); - int (*fsend)(struct soap*, const char*, size_t); - size_t (*frecv)(struct soap*, char*, size_t); - int (*fprepare)(struct soap*, const char*, size_t); - int (*fignore)(struct soap*, const char*); - void *(*fplugin)(struct soap*, const char*); - void *(*fdimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fdimewriteopen)(struct soap*, const char*, const char*, const char*); - void (*fdimereadclose)(struct soap*, void*); - void (*fdimewriteclose)(struct soap*, void*); - size_t (*fdimeread)(struct soap*, void*, char*, size_t); - int (*fdimewrite)(struct soap*, void*, const char*, size_t); - int master; - int socket; -#if defined(__cplusplus) && !defined(UNDER_CE) - ostream *os; - istream *is; -#else - void *os; /* preserve alignment */ - void *is; /* preserve alignment */ -#endif -#ifndef UNDER_CE - int sendfd; - int recvfd; -#else - FILE *sendfd; - FILE *recvfd; - char errorstr[256]; - wchar_t werrorstr[256]; -#endif - size_t bufidx; - size_t buflen; - wchar ahead; - short cdata; - short body; - unsigned int level; - size_t count; /* message length counter */ - size_t length; /* message length as set by HTTP header */ - char *labbuf; /* look-aside buffer */ - size_t lablen; /* look-aside buffer allocated length */ - size_t labidx; /* look-aside buffer index to available part */ - char buf[SOAP_BUFLEN];/* send and receive buffer */ - char msgbuf[1024]; /* output buffer for (error) messages <=1024 bytes */ - char tmpbuf[1024]; /* output buffer for HTTP headers, simpleType values, attribute names, and DIME >=1024 bytes */ - char tag[SOAP_TAGLEN]; - char id[SOAP_TAGLEN]; - char href[SOAP_TAGLEN]; - char type[SOAP_TAGLEN]; - char arrayType[SOAP_TAGLEN]; - char arraySize[SOAP_TAGLEN]; - char arrayOffset[SOAP_TAGLEN]; - short other; - short root; - short position; - int positions[SOAP_MAXDIMS]; - struct soap_attribute *attributes; /* attribute list */ - short encoding; - short mustUnderstand; - short null; - short ns; - short part; - short alloced; - short peeked; - short dot_net_bug; - short keep_alive; - size_t chunksize; - size_t chunkbuflen; - char endpoint[SOAP_TAGLEN]; - char path[SOAP_TAGLEN]; - char host[SOAP_TAGLEN]; - char *action; - int port; - unsigned int max_keep_alive; - const char *proxy_host; /* Proxy Server host name */ - int proxy_port; /* Proxy Server port (default = 8080) */ - const char *proxy_userid; /* Proxy Authorization user name */ - const char *proxy_passwd; /* Proxy Authorization password */ - int status; /* -1 when request, else error code to be returned by server */ - int error; - int errmode; - int errnum; - unsigned long idnum; - unsigned long ip; - size_t dime_count; - int dime_flags; - size_t dime_size; - size_t dime_chunksize; - size_t dime_buflen; - char *dime_ptr; - char *dime_id; - char *dime_type; - char *dime_options; - struct soap_dom_element *dom; -#ifndef WITH_LEAN - const char *logfile[SOAP_MAXLOGS]; - FILE *fdebug[SOAP_MAXLOGS]; - struct soap_cookie *cookies; - const char *cookie_domain; - const char *cookie_path; - int cookie_max; -#endif -#ifdef WITH_OPENSSL - int (*fsslauth)(struct soap*); - int (*fsslverify)(int, X509_STORE_CTX*); - BIO *bio; - SSL *ssl; - SSL_CTX *ctx; - short require_server_auth; - short require_client_auth; - short rsa; /* when set, use RSA instead of DH */ - const char *keyfile; - const char *password; - const char *dhfile; - const char *cafile; - const char *capath; - const char *randfile; - SSL_SESSION *session; - char session_host[SOAP_TAGLEN]; - int session_port; -#endif -#ifdef WITH_ZLIB - short zlib_state; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_INFLATE */ - short zlib_in; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - short zlib_out; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - z_stream d_stream; /* decompression stream */ - char z_buf[SOAP_BUFLEN]; /* buffer */ - size_t z_buflen; - unsigned short z_level; /* compression level to be used (0=none, 1=fast to 9=best) */ - unsigned long z_crc; /* internal gzip crc */ - float z_ratio_in; /* detected compression ratio compressed_length/length of inbound message */ - float z_ratio_out; /* detected compression ratio compressed_length/length of outbound message */ -#endif -#ifdef PALM - UInt16 stdLibNum; - UInt16 stdLib2Num; - UInt16 stdLib3Num; - UInt16 genLibNum; - Err fH_errno; - Err fErrno; - Int32 timeout; - NetHostInfoBufType hostInfo; - UInt16 socketLibNum; -#endif -/* WR[ */ -#ifdef WMW_RPM_IO - void *rpmreqid; -#endif /* WMW_RPM_IO */ -/* ]WR */ -}; - -struct soap_code_map -{ long code; - const char *string; -}; - -/* forwarding list for container elements */ -struct soap_flist -{ struct soap_flist *next; - int type; - void *ptr; - unsigned int level; - void (*finsert)(struct soap*, int, void*, void*); -}; - -struct soap_plugin -{ struct soap_plugin *next; - const char *id; - void *data; - int (*fcopy)(struct soap *soap, struct soap_plugin *dst, struct soap_plugin *src); - void (*fdelete)(struct soap *soap, struct soap_plugin *p); /* should delete fields of plugin only and not free(p) */ -}; - -#ifndef WITH_NONAMESPACES -extern SOAP_NMAC struct Namespace namespaces[]; -#endif - -#ifdef HAVE_STRRCHR - #define soap_strrchr(s, t) strrchr(s, t) -#else - SOAP_FMAC1 char* SOAP_FMAC2 soap_strrchr(const char *s, int t); -#endif - -#ifdef HAVE_STRTOL - #define soap_strtol(s, t, b) strtol(s, t, b) -#else - SOAP_FMAC1 long SOAP_FMAC2 soap_strtol(const char *s, char **t, int b); -#endif - -#ifdef HAVE_STRTOUL - #define soap_strtoul(s, t, b) strtoul(s, t, b) -#else - SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b); -#endif - -SOAP_FMAC1 void SOAP_FMAC2 soap_fault(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultstring(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultdetail(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializefault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getfault(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_poll(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect_command(struct soap*, int, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_bind(struct soap*, const char*, int, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_accept(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_accept(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_puthttphdr(struct soap*, int status, size_t count); - -SOAP_FMAC1 int SOAP_FMAC2 soap_hash(const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_endpoint(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush(struct soap*); -SOAP_FMAC1 wchar SOAP_FMAC2 soap_get(struct soap*); -SOAP_FMAC1 wchar SOAP_FMAC2 soap_getchar(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_tag_cmp(const char*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_sender_error(struct soap*, const char*, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_receiver_error(struct soap*, const char*, const char*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_raw(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pututf8(struct soap*, unsigned long); -SOAP_FMAC1 wchar SOAP_FMAC2 soap_getutf8(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_putbase64(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_getbase64(struct soap*, int*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_puthex(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_gethex(struct soap*, int*); - - -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_lookup(struct soap*, const char*); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_enter(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_resolve_ptr(struct soap_ilist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_resolve(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup(struct soap*, const void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_pointer_lookup(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup_id(struct soap*, void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_enter(struct soap*, const void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_pointer_enter(struct soap*, const void *p, const struct soap_array *a, int t, struct soap_plist**); - -SOAP_FMAC1 int SOAP_FMAC2 soap_embed_element(struct soap *soap, const void *p, const char *tag, int type); -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); - -SOAP_FMAC1 void SOAP_FMAC2 soap_begin_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_send(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_embedded(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_reference(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_reference(struct soap*, const void *p, const struct soap_array *a, int n, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_embedded_id(struct soap*, int id, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_embedded(struct soap*, struct soap_plist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_single(struct soap*, struct soap_plist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_multi(struct soap*, struct soap_plist*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_embedded(struct soap*, struct soap_plist*); - -SOAP_FMAC1 const struct soap_code_map* SOAP_FMAC2 soap_code(const struct soap_code_map*, const char *str); -SOAP_FMAC1 long SOAP_FMAC2 soap_int_code(const struct soap_code_map*, const char *str, long other); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_str_code(const struct soap_code_map*, long code); - -SOAP_FMAC1 int SOAP_FMAC2 soap_getline(struct soap*, char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_recv(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_malloc(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_dealloc(struct soap*, void*); -SOAP_FMAC1 struct soap_clist * SOAP_FMAC2 soap_link(struct soap*, void*, int, int, void (*fdelete)(struct soap_clist*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_unlink(struct soap*, const void*); -SOAP_FMAC1 void SOAP_FMAC2 soap_free(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_lookup_type(struct soap*, const char *id); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_lookup(struct soap*, const char *id, void **p, int t, size_t n, unsigned int k); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_forward(struct soap*, const char *id, void *p, int t, size_t n); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_enter(struct soap*, const char *id, void *p, int t, size_t n, int k); - -SOAP_FMAC1 int SOAP_FMAC2 soap_size(const int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getoffsets(const char *, const int *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsize(const char *, const char *, int *); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsizes(const char *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getposition(const char *, int *); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsize(struct soap*, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizesoffsets(struct soap*, const char *, const int *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizes(struct soap*, const char *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffset(struct soap*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffsets(struct soap*, const int *, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_closesock(struct soap*); - -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new(void); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new1(int); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new2(int, int); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*,struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init1(struct soap*, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_init2(struct soap*, int, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_end(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_delete(struct soap*, void*); - -#ifndef WITH_LEAN -SOAP_FMAC1 void SOAP_FMAC2 soap_set_recv_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_sent_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_test_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_close_logfiles(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_open_logfile(struct soap*, int); -#endif - -SOAP_FMAC1 char* SOAP_FMAC2 soap_value(struct soap*); - -SOAP_FMAC1 wchar SOAP_FMAC2 soap_advance(struct soap*); -SOAP_FMAC1 wchar SOAP_FMAC2 soap_skip(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_tag(struct soap*, const char*, const char *); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_array(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element(struct soap*, const char*, int, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_out(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_begin_out(struct soap*, const char *tag, int id, const char *type, const char *offset); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_ref(struct soap*, const char *tag, int id, int href); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_href(struct soap*, const char *tag, int id, const char *href); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_null(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_result(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_out(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_start_end_out(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_attribute(struct soap*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_in(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_in(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_peek_element(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_retry(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_revert(struct soap*); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_strdup(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_string_out(struct soap*, const char *s, int flag); -SOAP_FMAC1 char* SOAP_FMAC2 soap_string_in(struct soap*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_wstring_out(struct soap*, const wchar_t *s, int flag); -SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstring_in(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_namespace(struct soap*, const char *, const char*, int n1, int n2); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_default_namespace(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap*, struct Namespace*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_namespace(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_push_namespace(struct soap*, const char *,const char *); -SOAP_FMAC1 int SOAP_FMAC2 soap_push_default_namespace(struct soap*, const char *, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_new_block(struct soap*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_push_block(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_size_block(struct soap*, size_t); -SOAP_FMAC1 char* SOAP_FMAC2 soap_first_block(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_next_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_block_size(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_save_block(struct soap*, char*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_store_block(struct soap*, char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*); -SOAP_FMAC1 int soap_envelope_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_out(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_header(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_response(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_fault(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_fault(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap*, FILE*); -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault_location(struct soap*, FILE*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_s2byte(struct soap*, const char*, char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2short(struct soap*, const char*, short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2int(struct soap*, const char*, int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2long(struct soap*, const char*, long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2LONG64(struct soap*, const char*, LONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2float(struct soap*, const char*, float*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2double(struct soap*, const char*, double*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedByte(struct soap*, const char*, unsigned char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedShort(struct soap*, const char*, unsigned short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedInt(struct soap*, const char*, unsigned int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedLong(struct soap*, const char*, unsigned long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2ULONG64(struct soap*, const char*, ULONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2dateTime(struct soap*, const char*, time_t*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2string(struct soap*, const char*, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2QName(struct soap*, const char*, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2base64(struct soap*, const unsigned char*, char*, size_t); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_byte2s(struct soap*, char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_short2s(struct soap*, short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_int2s(struct soap*, int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_long2s(struct soap*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_LONG642s(struct soap*, LONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_float2s(struct soap*, float); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_double2s(struct soap*, double); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedByte2s(struct soap*, unsigned char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedShort2s(struct soap*, unsigned short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedInt2s(struct soap*, unsigned int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedLong2s(struct soap*, unsigned long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_ULONG642s(struct soap*, ULONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_dateTime2s(struct soap*, time_t); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_QName2s(struct soap*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_base642s(struct soap*, const char*, char*, size_t, size_t*); - -SOAP_FMAC1 int* SOAP_FMAC2 soap_inint(struct soap*, const char *tag, int *p, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_inbyte(struct soap*, const char *tag, char *p, const char *, int); -SOAP_FMAC1 long* SOAP_FMAC2 soap_inlong(struct soap*, const char *tag, long *p, const char *, int); -SOAP_FMAC1 LONG64* SOAP_FMAC2 soap_inLONG64(struct soap*, const char *tag, LONG64 *p, const char *, int); -SOAP_FMAC1 short* SOAP_FMAC2 soap_inshort(struct soap*, const char *tag, short *p, const char *, int); -SOAP_FMAC1 float* SOAP_FMAC2 soap_infloat(struct soap*, const char *tag, float *p, const char *, int); -SOAP_FMAC1 double* SOAP_FMAC2 soap_indouble(struct soap*, const char *tag, double *p, const char *, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_inunsignedByte(struct soap*, const char *tag, unsigned char *p, const char *, int); -SOAP_FMAC1 unsigned short* SOAP_FMAC2 soap_inunsignedShort(struct soap*, const char *tag, unsigned short *p, const char *, int); -SOAP_FMAC1 unsigned int* SOAP_FMAC2 soap_inunsignedInt(struct soap*, const char *tag, unsigned int *p, const char *, int); -SOAP_FMAC1 unsigned long* SOAP_FMAC2 soap_inunsignedLong(struct soap*, const char *tag, unsigned long *p, const char *, int); -SOAP_FMAC1 ULONG64* SOAP_FMAC2 soap_inULONG64(struct soap*, const char *tag, ULONG64 *p, const char *, int); -SOAP_FMAC1 time_t* SOAP_FMAC2 soap_indateTime(struct soap*, const char *tag, time_t *p, const char *, int); -SOAP_FMAC1 char** SOAP_FMAC2 soap_instring(struct soap*, const char *tag, char **p, const char *, int, int); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwstring(struct soap*, const char *tag, wchar_t **p, const char *, int); -SOAP_FMAC1 char** SOAP_FMAC2 soap_inliteral(struct soap*, const char *tag, char **p); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwliteral(struct soap*, const char *tag, wchar_t **p); - -SOAP_FMAC1 int SOAP_FMAC2 soap_outbyte(struct soap*, const char *tag, int id, const char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outshort(struct soap*, const char *tag, int id, const short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outint(struct soap*, const char *tag, int id, const int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outlong(struct soap*, const char *tag, int id, const long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outLONG64(struct soap*, const char *tag, int id, const LONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outfloat(struct soap*, const char *tag, int id, const float *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdouble(struct soap*, const char *tag, int id, const double *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedByte(struct soap*, const char *tag, int id, const unsigned char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedShort(struct soap*, const char *tag, int id, const unsigned short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedInt(struct soap*, const char *tag, int id, const unsigned int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedLong(struct soap*, const char *tag, int id, const unsigned long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outULONG64(struct soap*, const char *tag, int id, const ULONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdateTime(struct soap*, const char *tag, int id, const time_t *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outstring(struct soap*, const char *tag, int id, char *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwstring(struct soap*, const char *tag, int id, wchar_t *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outliteral(struct soap*, const char *tag, char *const*p); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwliteral(struct soap*, const char *tag, wchar_t *const*p); - -#ifndef WITH_LEANER -SOAP_FMAC1 void SOAP_FMAC2 soap_set_attached(struct soap*, struct soap_plist*, const char*, const char*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, long); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_tell(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_dime_option(struct soap*, unsigned short, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdime(struct soap*, int, char*, char*, char*, void*, size_t); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_register_plugin_arg(struct soap*, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_lookup_plugin(struct soap*, const char*); - -SOAP_FMAC1 struct soap_attribute * SOAP_FMAC2 soap_attr(struct soap *soap, const char *name); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_attr_value(struct soap *soap, const char *name); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_attr(struct soap *soap, const char *name, const char *value); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_attr(struct soap *soap); - -#ifdef WITH_COOKIES -SOAP_FMAC1 int SOAP_FMAC2 soap_encode_cookie(const char*, char*, int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_cookie(char*, int, const char*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_set_cookie(struct soap*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern long SOAP_FMAC2 soap_cookie_expire(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_expire(struct soap*, const char*, long, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_clr_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_clr_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_getenv_cookies(struct soap*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_copy_cookies(struct soap*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_free_cookies(struct soap*); -#endif - -#if defined(PALM) && !defined(NOSHAREDLIB) && !(defined(BUILDING_STDSOAP) || defined(BUILDING_STDSOAP2) || defined(BUILDING_STDLIB) || defined(BUILDING_STDLIB2) || defined(PALM_1) || defined(PALM_2)) -# include "palmSharedLib.h" -#endif - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.c b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.c deleted file mode 100644 index fab9eee..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.c +++ /dev/null @@ -1,11692 +0,0 @@ -/* - -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_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 : "")) - 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, "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, "", 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, "", 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 = ""; -} -#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 - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.h b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.h deleted file mode 100644 index ff1d52d..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0.h +++ /dev/null @@ -1,1764 +0,0 @@ -/* - -stdsoap2.h 2.7.0d - -gSOAP 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 --------------------------------------------------------------------------------- -*/ - -#ifdef WITH_SOAPDEFS_H -# include "soapdefs.h" /* include user-defined stuff */ -#endif - -#ifndef _THREAD_SAFE -# define _THREAD_SAFE -#endif - -#ifndef OPENSERVER -# ifndef _REENTRANT -# define _REENTRANT -# endif -#endif - -#ifndef SOAP_BEGIN_NAMESPACE -# define SOAP_BEGIN_NAMESPACE(name) -#endif - -#ifndef SOAP_END_NAMESPACE -# define SOAP_END_NAMESPACE(name) -#endif - -#ifndef SOAP_FMAC1 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC1 -#endif - -#ifndef SOAP_FMAC2 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC2 -#endif - -#ifndef SOAP_FMAC3 /* (de)serializer declaration macro */ -# define SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC4 /* (de)serializer declaration macro */ -# define SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC5 /* stub/skeleton declaration macro */ -# define SOAP_FMAC5 -#endif - -#ifndef SOAP_FMAC6 /* stub/skeleton declaration macro */ -# define SOAP_FMAC6 -#endif - -#ifndef SOAP_CMAC /* class declaration macro */ -# define SOAP_CMAC -#endif - -#ifndef SOAP_NMAC /* namespace table declaration macro */ -# define SOAP_NMAC -#endif - -#ifndef SOAP_SOURCE_STAMP -# define SOAP_SOURCE_STAMP(str) -#endif - -#ifdef WITH_LEANER -# ifndef WITH_LEAN -# define WITH_LEAN -# endif -#endif - -#ifdef WITH_LEAN -# ifdef WITH_COOKIES -# error "Cannot build WITH_LEAN code WITH_COOKIES enabled" -# endif -#endif - -#ifndef STDSOAP_H -#define STDSOAP_H - -#if defined(__vxworks) || defined(__VXWORKS__) -# define VXWORKS -#endif - -#ifdef _WIN32 -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef UNDER_CE -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef __BORLANDC__ -# ifdef __WIN32__ -# ifndef WIN32 -# define WIN32 -# endif -# endif -#endif - -#ifdef __CYGWIN__ -# ifndef CYGWIN -# define CYGWIN -# endif -#endif - -#ifdef __SYMBIAN32__ -# define SYMBIAN -# undef WIN32 -#endif - -#if defined(__palmos__) || defined(PALM_GCC) || defined(__PALMOS_TRAPS__) -# define PALM -#endif - -#ifdef __hpux -# define HP_UX -#endif - -#ifdef __alpha -# define TRU64 -#endif - -#ifdef __MVS__ -# define OS390 -#endif - -#ifdef _AIX -# define __socklen_t_defined -#endif - -#ifdef HAVE_CONFIG_H -# include "config.h" -#else -# if defined(UNDER_CE) -# define WITH_LEAN -# define HAVE_SSCANF -# elif defined(WIN32) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(CYGWIN) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__APPLE__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(_AIXVERSION_431) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(HP_UX) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(FREEBSD) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GETTIMEOFDAY -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__VMS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__GLIBC__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define HAVE_ISNAN -# elif defined(TRU64) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GETTIMEOFDAY -# define HAVE_SYS_TIMEB_H -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define __USE_STD_IOSTREAM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(MAC_CARBON) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(PALM) -# define WITH_LEAN -# define HAVE_STRTOD /* strtod() is defined in palmFunctions.h */ -# include /* Needs to be included before unix headers */ -# include -# define IGNORE_STDIO_STUBS -# include -# define O_NONBLOCK FNONBIO -# include -# include -# include "palmFunctions.h" -# elif defined(SYMBIAN) -# define WITH_LEAN -# define WITH_NONAMESPACES -# define HAVE_STRTOD /* use STRTOD since sscanf doesn't seem to work */ -# include -# elif defined(VXWORKS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_PGMTIME_R -# define HAVE_PLOCALTIME_R -# define HAVE_MKTIME -# elif defined(OS390) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MB -# else -/* Default asumptions on supported functions */ -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# endif -#endif - -#if defined(TRU64) -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -#elif defined(WIN32) -# define SOAP_LONG_FORMAT "%I64d" -# define SOAP_ULONG_FORMAT "%I64u" -#endif - -#ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%lld" /* printf format for 64 bit ints */ -#endif - -#ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%llu" /* printf format for unsigned 64 bit ints */ -#endif - -#ifndef SOAP_MALLOC /* use libc malloc */ -# define SOAP_MALLOC(n) malloc(n) -#endif - -#ifndef SOAP_FREE /* use libc free */ -# define SOAP_FREE(p) free(p) -#endif - -#include - -#ifndef PALM -# include -# include -#endif - -#include -#include - -#if defined(__cplusplus) && !defined(WITH_LEAN) -# include -# include - using namespace std; -#endif - -#ifndef UNDER_CE -# ifndef PALM -# include -# ifndef MAC_CARBON -# include -# endif -# ifndef WITH_LEAN -# ifdef HAVE_SYS_TIMEB_H -# include /* for ftime() */ -# endif -# include -# endif -# endif -#endif - -#ifdef OPENSERVER -# include -# include -# include - extern int h_errno; -#endif - -#ifndef MAC_CARBON -# ifndef WIN32 -# ifndef PALM -# include -# ifdef VXWORKS -# include -# endif -# ifndef VXWORKS -# ifndef SYMBIAN -# include -# endif -# endif -# ifdef SUN_OS -# include /* SUN */ -# include /* SUN < 2.8 (?) */ -# endif -# ifdef VXWORKS -# include -# else -# include -# endif -# include -# ifdef OS390 -# include -# else -# include /* TCP_NODELAY */ -# endif -# include -# endif -# endif -#endif - -#ifdef WITH_FASTCGI -# include -#endif - -#ifdef WITH_OPENSSL -# define OPENSSL_NO_KRB5 -# include -# include -# include -# ifndef ALLOW_OLD_VERSIONS -# if (OPENSSL_VERSION_NUMBER < 0x00905100L) -# error "Must use OpenSSL 0.9.6 or later" -# endif -# endif -#endif - -#ifdef WITH_GZIP -# ifndef WITH_ZLIB -# define WITH_ZLIB -# endif -#endif - -#ifdef WITH_CASEINSENSITIVETAGS -# define SOAP_STRCMP soap_tag_cmp /* case insensitve XML element/attribute names */ -#else -# define SOAP_STRCMP strcmp /* case sensitive XML element/attribute names */ -#endif - -#ifdef WITH_ZLIB -# include -#endif - -#ifndef PALM -# include /* for isnan() */ -#endif - -/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define soap_get0(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx]) -#define soap_get1(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx++]) -#define soap_revget1(soap) ((soap)->bufidx--) -#define soap_unget(soap, c) ((soap)->ahead = c) -#define soap_register_plugin(soap, plugin) soap_register_plugin_arg(soap, plugin, NULL) -#define soap_imode(soap, n) ((soap)->mode = (soap)->imode = (n)) -#define soap_set_imode(soap, n) ((soap)->mode = (soap)->imode |= (n)) -#define soap_clr_imode(soap, n) ((soap)->mode = (soap)->imode &= ~(n)) -#define soap_omode(soap, n) ((soap)->mode = (soap)->omode = (n)) -#define soap_set_omode(soap, n) ((soap)->mode = (soap)->omode |= (n)) -#define soap_clr_omode(soap, n) ((soap)->mode = (soap)->omode &= ~(n)) -#define soap_destroy(soap) soap_delete((soap), NULL) - -#ifdef WIN32 -# ifndef UNDER_CE -# include -# include -# endif -# include -/* # include */ /* Alternative: use winsock2 (not available with eVC) */ -/* WR[ */ -# ifdef WITH_IPV6 -# include -# include -# endif -#else -# ifdef VXWORKS -# include -# include -# include -# endif -/* ]WR */ -# ifndef MAC_CARBON -# ifndef PALM -# include -# include -# include -# include -# endif -# endif -#endif - -#ifdef WIN32 -# define SOAP_SOCKET SOCKET -#else -# define SOAP_SOCKET int -# define closesocket(n) close(n) -#endif - -#define soap_valid_socket(n) ((n) >= 0) -#define SOAP_INVALID_SOCKET (-1) - -#if defined(SYMBIAN) -# define LONG64 long -# define ULONG64 unsigned LONG64 -#elif !defined(WIN32) -# define LONG64 long long -# define ULONG64 unsigned LONG64 -#elif defined(UNDER_CE) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#elif defined(__BORLANDC__) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#endif - -#if defined(WIN32) -# define soap_int32 __int32 -#elif defined(SYMBIAN) -# define soap_int32 long -#elif defined(PALM) -# define soap_int32 Int32 -#else -# define soap_int32 int32_t -#endif - -/* UCS-4 requires 32 bits (0-7FFFFFFF, the sign bit is used by gSOAP to distinguish XML entities) */ -typedef soap_int32 soap_wchar; - -#ifdef WIN32 -# define SOAP_EINTR WSAEINTR -# define SOAP_EAGAIN WSAEWOULDBLOCK -# define SOAP_EWOULDBLOCK WSAEWOULDBLOCK -# define SOAP_EINPROGRESS WSAEINPROGRESS -#else -# define SOAP_EINTR EINTR -# define SOAP_EAGAIN EAGAIN -# ifdef SYMBIAN -# define SOAP_EWOULDBLOCK 9898 -# define SOAP_EINPROGRESS 9899 -# else -# define SOAP_EWOULDBLOCK EWOULDBLOCK -# define SOAP_EINPROGRESS EINPROGRESS -# endif -#endif - -#ifdef WIN32 -# ifdef UNDER_CE -# define soap_errno GetLastError() -# define soap_socket_errno GetLastError() -# else -# define soap_errno GetLastError() -# define soap_socket_errno WSAGetLastError() -# endif -#else -# define soap_errno errno -# define soap_socket_errno errno -#endif - -#ifndef SOAP_BUFLEN -# ifndef WITH_LEAN -# define SOAP_BUFLEN (32768) /* buffer length for socket packets, also used by gethostbyname_r so don't make this too small */ -# else -# define SOAP_BUFLEN (2048) -# endif -#endif -#ifndef SOAP_LABLEN -# ifndef WITH_LEAN -# define SOAP_LABLEN (256) /* initial look-aside buffer length */ -# else -# define SOAP_LABLEN (64) -# endif -#endif -#ifndef SOAP_PTRHASH -# ifndef WITH_LEAN -# define SOAP_PTRHASH (1024) /* size of pointer analysis hash table (must be power of 2) */ -# else -# define SOAP_PTRHASH (16) -# endif -#endif -#ifndef SOAP_IDHASH -# ifndef WITH_LEAN -# define SOAP_IDHASH (1999) /* prime size of hash table for parsed id/ref */ -# else -# define SOAP_IDHASH (199) -# endif -#endif -#ifndef SOAP_BLKLEN -# define SOAP_BLKLEN (256) /* size of blocks to collect long strings and XML attributes */ -#endif -#ifndef SOAP_TAGLEN -# define SOAP_TAGLEN (256) /* maximum length of XML element tag/attribute name + 1 */ -#endif -#ifndef SOAP_HDRLEN -# ifndef WITH_LEAN -# define SOAP_HDRLEN (8192) /* maximum length of HTTP header line (must be >4096 to read cookies) */ -# else -# define SOAP_HDRLEN (1024) -# endif -#endif -#ifndef SOAP_MAXDIMS -# define SOAP_MAXDIMS (16) /* maximum array dimensions (array nestings) must be less than 64 to protect soap->tmpbuf */ -#endif - -#ifndef SOAP_MAXLOGS -# define SOAP_MAXLOGS (3) /* max number of debug logs per struct soap environment */ -# define SOAP_INDEX_RECV (0) -# define SOAP_INDEX_SENT (1) -# define SOAP_INDEX_TEST (2) -#endif - -#ifndef SOAP_MAXKEEPALIVE -# define SOAP_MAXKEEPALIVE (100) /* max iterations to keep server connection alive */ -#endif - -#ifndef SOAP_MAXARRAYSIZE -# define SOAP_MAXARRAYSIZE (100000) /* "trusted" max size of inbound SOAP array for compound array allocation */ -#endif - -#ifdef VXWORKS -# ifdef __INCmathh -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) isNan(num) -# endif -#endif - -#ifdef WIN32 -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) _isnan(num) -#endif - -#ifdef SUN_OS -# define soap_isnan(n) isnan(n) -#endif - -#if !defined(HAVE_ISNAN) && (defined(_MATH_H) || defined(_MATH_INCLUDED)) -# define HAVE_ISNAN -#endif - -#ifndef soap_isnan -# ifdef HAVE_ISNAN -# define soap_isnan(n) isnan(n) -# else -# define soap_isnan(_) (0) -# endif -#endif - -extern const struct soap_double_nan { unsigned int n1, n2; } soap_double_nan; - -#ifdef VXWORKS -# ifndef FLT_MAX -# define FLT_MAX _ARCH_FLT_MAX -# endif -# ifndef DBL_MAX -# define DBL_MAX _ARCH_DBL_MAX -# endif -#endif - -#ifndef FLT_NAN -# ifdef HAVE_ISNAN -# define FLT_NAN (*(float*)&soap_double_nan) -# else -# define FLT_NAN (0.0) -# endif -#endif - -#ifndef FLT_PINFTY -# ifdef FLT_MAX -# define FLT_PINFTY FLT_MAX -# else -# ifdef HUGE_VAL -# define FLT_PINFTY (float)HUGE_VAL -# else -# ifdef FLOAT_MAX -# define FLT_PINFTY FLOAT_MAX -# else -# define FLT_PINFTY (3.40282347e+38) -# endif -# endif -# endif -#endif - -#ifndef FLT_NINFTY -# define FLT_NINFTY (-FLT_PINFTY) -#endif - -#ifndef DBL_NAN -# ifdef HAVE_ISNAN -# define DBL_NAN (*(double*)&soap_double_nan) -# else -# define DBL_NAN (0.0) -# endif -#endif - -#ifndef DBL_PINFTY -# ifdef DBL_MAX -# define DBL_PINFTY DBL_MAX -# else -# ifdef HUGE_VAL -# define DBL_PINFTY (double)HUGE_VAL -# else -# ifdef DOUBLE_MAX -# define DBL_PINFTY DOUBLE_MAX -# else -# define DBL_PINFTY (1.7976931348623157e+308) -# endif -# endif -# endif -#endif - -#ifndef DBL_NINFTY -# define DBL_NINFTY (-DBL_PINFTY) -#endif - -#define soap_ispinfd(n) ((n) >= DBL_PINFTY) -#define soap_ispinff(n) ((n) >= FLT_PINFTY) -#define soap_isninfd(n) ((n) <= DBL_NINFTY) -#define soap_isninff(n) ((n) <= FLT_NINFTY) - -/* gSOAP error codes */ - -#define SOAP_EOF EOF -#define SOAP_ERR EOF -#define SOAP_OK 0 -#define SOAP_CLI_FAULT 1 -#define SOAP_SVR_FAULT 2 -#define SOAP_TAG_MISMATCH 3 -#define SOAP_TYPE 4 -#define SOAP_SYNTAX_ERROR 5 -#define SOAP_NO_TAG 6 -#define SOAP_IOB 7 -#define SOAP_MUSTUNDERSTAND 8 -#define SOAP_NAMESPACE 9 -/* #define SOAP_OBJ_MISMATCH 10 obsolete */ -#define SOAP_TAG_END 10 -#define SOAP_FATAL_ERROR 11 -#define SOAP_FAULT 12 -#define SOAP_NO_METHOD 13 -#define SOAP_GET_METHOD 14 -#define SOAP_EOM 15 -#define SOAP_NULL 16 -#define SOAP_MULTI_ID 17 -#define SOAP_MISSING_ID 18 -#define SOAP_HREF 19 -#define SOAP_TCP_ERROR 20 -#define SOAP_HTTP_ERROR 21 -#define SOAP_SSL_ERROR 22 -#define SOAP_ZLIB_ERROR 23 -#define SOAP_DIME_ERROR 24 -#define SOAP_DIME_HREF 25 -#define SOAP_DIME_MISMATCH 26 -#define SOAP_DIME_END 27 -#define SOAP_MIME_ERROR 28 -#define SOAP_VERSIONMISMATCH 29 -#define SOAP_PLUGIN_ERROR 30 -#define SOAP_DATAENCODINGUNKNOWN 31 -#define SOAP_REQUIRED 32 -#define SOAP_PROHIBITED 33 -#define SOAP_OCCURS 34 -#define SOAP_LENGTH 35 - -#define soap_xml_error_check(e) ((e) == SOAP_TAG_MISMATCH || (e) == SOAP_TAG_END || (e) == SOAP_SYNTAX_ERROR || (e) == SOAP_NAMESPACE || (e) == SOAP_MULTI_ID || (e) == SOAP_MISSING_ID || (e) == SOAP_REQUIRED || (e) == SOAP_PROHIBITED || (e) == SOAP_OCCURS || (e) == SOAP_LENGTH || (e) == SOAP_NULL || (e) == SOAP_HREF) -#define soap_soap_error_check(e) ((e) == SOAP_CLI_FAULT || (e) == SOAP_SVR_FAULT || (e) == SOAP_VERSIONMISMATCH || (e) == SOAP_MUSTUNDERSTAND || (e) == SOAP_FAULT || (e) == SOAP_NO_METHOD) -#define soap_tcp_error_check(e) ((e) == SOAP_EOF || (e) == SOAP_TCP_ERROR) -#define soap_ssl_error_check(e) ((e) == SOAP_SSL_ERROR) -#define soap_zlib_error_check(e) ((e) == SOAP_ZLIB_ERROR) -#define soap_mime_error_check(e) ((e) == SOAP_MIME_ERROR) -#define soap_dime_error_check(e) ((e) == SOAP_DIME_ERROR || (e) == SOAP_DIME_MISMATCH) -#define soap_http_error_check(e) ((e) == SOAP_HTTP_ERROR || (e) == SOAP_GET_METHOD || ((e) >= 100 && (e) < 600)) - -/* gSOAP HTTP response status codes 100 to 600 are reserved */ - -/* Special gSOAP HTTP response status codes */ - -#define SOAP_STOP 1000 /* No HTTP response */ -#define SOAP_HTML 1001 /* Custom HTML response */ -#define SOAP_FILE 1002 /* Custom file-based response */ - -/* gSOAP HTTP request status codes */ - -#define SOAP_POST 1003 -#define SOAP_GET 1104 - -/* gSOAP DIME */ - -#define SOAP_DIME_CF 0x01 -#define SOAP_DIME_ME 0x02 -#define SOAP_DIME_MB 0x04 -#define SOAP_DIME_VERSION 0x08 /* DIME version 1 */ -#define SOAP_DIME_MEDIA 0x10 -#define SOAP_DIME_ABSURI 0x20 - -/* gSOAP ZLIB */ - -#define SOAP_ZLIB_NONE 0x00 -#define SOAP_ZLIB_DEFLATE 0x01 -#define SOAP_ZLIB_INFLATE 0x02 -#define SOAP_ZLIB_GZIP 0x02 - -/* gSOAP transport, connection, and content encoding modes */ - -typedef soap_int32 soap_mode; - -#define SOAP_IO 0x00000003 /* IO mask */ -#define SOAP_IO_FLUSH 0x00000000 /* flush output immediately, no buffering */ -#define SOAP_IO_BUFFER 0x00000001 /* buffer output in packets of size SOAP_BUFLEN */ -#define SOAP_IO_STORE 0x00000002 /* store entire output to determine length for transport */ -#define SOAP_IO_CHUNK 0x00000003 /* use HTTP chunked transfer AND buffer packets */ - -#define SOAP_IO_LENGTH 0x00000004 -#define SOAP_IO_KEEPALIVE 0x00000008 - -#define SOAP_ENC_LATIN 0x00800010 /* iso-8859-1 encoding */ -#define SOAP_ENC_XML 0x00000020 /* plain XML encoding, no HTTP header */ -#define SOAP_ENC_DIME 0x00000040 -#define SOAP_ENC_MIME 0x00000080 -#define SOAP_ENC_ZLIB 0x00000100 -#define SOAP_ENC_SSL 0x00000200 - -#define SOAP_XML_STRICT 0x00001000 /* strict validation */ -#define SOAP_XML_CANONICAL 0x00002000 /* C14N canonical XML */ -#define SOAP_XML_TREE 0x00004000 -#define SOAP_XML_GRAPH 0x00008000 -#define SOAP_XML_NIL 0x00010000 -#define SOAP_XML_DOM 0x00020000 -#define SOAP_XML_SEC 0x00040000 /* reserved for WS security */ - -#define SOAP_C_NOIOB 0x00100000 -#define SOAP_C_UTFSTRING 0x00200000 -#define SOAP_C_MBSTRING 0x00400000 - -#define SOAP_DOM_TREE 0x01000000 -#define SOAP_DOM_NODE 0x02000000 - -#define SOAP_IO_DEFAULT SOAP_IO_FLUSH - -/* SSL client/server authentication settings */ - -#define SOAP_SSL_NO_AUTHENTICATION 0x00 /* for testing purposes */ -#define SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION 0x01 /* client requires server to authenticate */ -#define SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION 0x02 /* server requires client to authenticate */ - -#define SOAP_SSL_DEFAULT SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION - -/* */ - -#define SOAP_BEGIN 0 -#define SOAP_IN_ENVELOPE 2 -#define SOAP_IN_HEADER 3 -#define SOAP_END_HEADER 4 -#define SOAP_IN_BODY 5 -#define SOAP_END_BODY 6 -#define SOAP_END_ENVELOPE 7 -#define SOAP_END 8 - -/* DEBUG macros */ - -#ifndef WITH_LEAN -# ifdef DEBUG -# ifndef SOAP_DEBUG -# define SOAP_DEBUG -# endif -# endif -#endif - -#ifdef SOAP_DEBUG -# ifndef SOAP_MESSAGE -# define SOAP_MESSAGE fprintf -# endif -# ifndef DBGLOG -# define DBGLOG(DBGFILE, CMD) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ - CMD;\ - fflush(fdebug);\ - }\ - }\ -} -# endif -# ifndef DBGMSG -# define DBGMSG(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { fwrite((MSG), 1, (LEN), soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -#else -# define DBGLOG(DBGFILE, CMD) -# define DBGMSG(DBGFILE, MSG, LEN) -#endif - -struct Namespace -{ const char *id; - const char *ns; - const char *in; - char *out; -}; - -struct soap_nlist -{ struct soap_nlist *next; - unsigned int level; - short index; /* corresponding entry in ns mapping table */ - char *ns; /* only set when parsed ns URI is not in the ns mapping table */ - char id[1]; /* the actual string value flows into the allocated region below this struct */ -}; - -struct soap_blist -{ struct soap_blist *next; - char *ptr; - size_t size; -}; - -struct soap_array -{ void *__ptr; - int __size; -}; - -/* pointer serialization management */ -struct soap_plist -{ struct soap_plist *next; - const void *ptr; - const struct soap_array *array; - int type; - int id; - char mark1; - char mark2; -}; - -/* class allocation list */ -struct soap_clist -{ struct soap_clist *next; - void *ptr; - int type; - int size; - void (*fdelete)(struct soap_clist*); -}; - -struct soap_attribute -{ struct soap_attribute *next; - char *value; - size_t size; - char *ns; - short visible; - char name[1]; /* the actual name string flows into the allocated region below this struct */ -}; - -struct soap_cookie -{ struct soap_cookie *next; - char *name; - char *value; - char *domain; - char *path; - long expire; /* client-side: local time to expire; server-side: seconds to expire */ - unsigned int version; - short secure; - short session; /* server-side */ - short env; /* server-side: got cookie from client */ - short modified; /* server-side: client cookie was modified */ -}; - -#ifdef __cplusplus -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); -class soap_multipart_iterator -{ public: - struct soap_multipart *content; - bool operator==(const soap_multipart_iterator& iter) const - { return content == iter.content; } - bool operator!=(const soap_multipart_iterator& iter) const - { return content != iter.content; } - struct soap_multipart &operator*() const - { return *content; } - soap_multipart_iterator &operator++() - { content = soap_next_multipart(content); return *this; } - soap_multipart_iterator() : content(NULL) - { } - soap_multipart_iterator(struct soap_multipart *p) : content(p) - { } -}; -#endif - -struct soap_dime -{ size_t count; - size_t size; - size_t chunksize; - size_t buflen; - char flags; - char *ptr; - const char *id; - const char *type; - const char *options; - struct soap_multipart *list; /* list of DIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; - -struct soap_mime -{ char *boundary; /* MIME boundary */ - const char *start; /* MIME start ID */ - struct soap_multipart *list; /* list of DIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; - -/* RFC2045 MIME content transfer encodings */ -enum soap_mime_encoding -{ SOAP_MIME_NONE, - SOAP_MIME_7BIT, - SOAP_MIME_8BIT, - SOAP_MIME_BINARY, - SOAP_MIME_QUOTED_PRINTABLE, - SOAP_MIME_BASE64, - SOAP_MIME_IETF_TOKEN, - SOAP_MIME_X_TOKEN -}; - -/* DIME/MIME multipart list */ -struct soap_multipart -{ struct soap_multipart *next; - char *ptr; /* points to raw data content */ - size_t size; /* size of data content */ - const char *id; /* DIME/MIME content ID */ - const char *type; /* DIME/MIME type (MIME type format) */ - const char *options; /* DIME options */ - enum soap_mime_encoding encoding; /* MIME Content-Transfer-Encoding */ - const char *location; /* MIME Content-Location (optional) */ - const char *description; /* MIME Content-Description (optional) */ -#ifdef __cplusplus - typedef soap_multipart_iterator iterator; -#endif -}; - -struct soap_dom_attribute -{ struct soap_dom_attribute *next; - const char *nstr; - char *name; - char *data; - wchar_t *wide; - struct soap *soap; -#ifdef __cplusplus - struct soap_dom_attribute &set(const char *nstr, const char *name); // set namespace and name - struct soap_dom_attribute &set(const char *data); // set data - void unlink(); - soap_dom_attribute(); - soap_dom_attribute(struct soap *soap); - soap_dom_attribute(struct soap *soap, const char *nstr, const char *name, const char *data); - ~soap_dom_attribute(); -#endif -}; - -#ifdef __cplusplus -class soap_dom_iterator -{ public: - struct soap_dom_element *elt; - const char *nstr; - const char *name; - int type; - bool operator==(const soap_dom_iterator&) const; - bool operator!=(const soap_dom_iterator&) const; - struct soap_dom_element &operator*() const; - soap_dom_iterator &operator++(); - soap_dom_iterator(); - soap_dom_iterator(struct soap_dom_element*); - ~soap_dom_iterator(); -}; -#endif - -struct soap_dom_element -{ struct soap_dom_element *next; /* next sibling */ - struct soap_dom_element *prnt; /* parent */ - struct soap_dom_element *elts; /* first child element */ - struct soap_dom_attribute *atts; /* first child attribute */ - const char *nstr; /* namespace string */ - char *name; /* element tag name */ - char *data; /* element content data (with SOAP_C_UTFSTRING flag set) */ - wchar_t *wide; /* element content data */ - int type; /* optional: serialized C/C++ data type */ - void *node; /* optional: pointer to serialized C/C++ data */ - struct soap *soap; -#ifdef __cplusplus - typedef soap_dom_iterator iterator; - struct soap_dom_element &set(const char *nstr, const char *name); - struct soap_dom_element &set(const char *data); - struct soap_dom_element &set(void *node, int type); - struct soap_dom_element &add(struct soap_dom_element*); - struct soap_dom_element &add(struct soap_dom_element&); - struct soap_dom_element &add(struct soap_dom_attribute*); - struct soap_dom_element &add(struct soap_dom_attribute&); - soap_dom_iterator begin(); - soap_dom_iterator end(); - soap_dom_iterator find(const char *nstr, const char *name); - soap_dom_iterator find(int type); - void unlink(); - soap_dom_element(); - soap_dom_element(struct soap *soap); - soap_dom_element(struct soap *soap, const char *nstr, const char *name); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type); - ~soap_dom_element(); -#endif -}; - -#if defined(__cplusplus) && !defined(WITH_LEAN) -} -extern ostream &operator<<(ostream&, const struct soap_dom_element&); -extern istream &operator>>(istream&, struct soap_dom_element&); -extern "C" { -#endif - -struct soap -{ short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table) */ - short copy; /* 1 = copy of another soap struct */ - soap_mode mode; - soap_mode imode; - soap_mode omode; - const char *float_format; /* points to user-definable format string for floats (<1024 chars) */ - const char *double_format; /* points to user-definable format string for doubles (<1024 chars) */ - const char *dime_id_format; /* points to user-definable format string for integer DIME id ( 0, gives socket recv timeout in seconds, < 0 in usec */ - int send_timeout; /* when > 0, gives socket send timeout in seconds, < 0 in usec */ - int connect_timeout; /* when > 0, gives socket connect() timeout in seconds, < 0 in usec */ - int accept_timeout; /* when > 0, gives socket accept() timeout in seconds, < 0 in usec */ - int socket_flags; /* socket recv() and send() flags, e.g. set to MSG_NOSIGNAL to disable sigpipe */ - int connect_flags; /* connect() SOL_SOCKET sockopt flags, e.g. set to SO_DEBUG to debug socket */ - int bind_flags; /* bind() SOL_SOCKET sockopt flags, e.g. set to SO_REUSEADDR to enable reuse */ - int accept_flags; /* accept() SOL_SOCKET sockopt flags */ - const struct Namespace *namespaces; /* Pointer to global namespace mapping table */ - struct Namespace *local_namespaces; /* Local namespace mapping table */ - struct soap_nlist *nlist; /* namespace stack */ - struct soap_blist *blist; /* block allocation stack */ - struct soap_clist *clist; /* class instance allocation list */ - void *alist; /* memory allocation list */ - struct soap_ilist *iht[SOAP_IDHASH]; - struct soap_plist *pht[SOAP_PTRHASH]; - struct SOAP_ENV__Header *header; - struct SOAP_ENV__Fault *fault; - void *user; /* to pass user-defined data */ - struct soap_plugin *plugins; /* linked list of plug-in data */ - char *userid; /* HTTP Basic authorization userid */ - char *passwd; /* HTTP Basic authorization passwd */ - int (*fpost)(struct soap*, const char*, const char*, int, const char*, const char*, size_t); - int (*fget)(struct soap*); - int (*fposthdr)(struct soap*, const char*, const char*); - int (*fresponse)(struct soap*, int, size_t); - int (*fparse)(struct soap*); - int (*fparsehdr)(struct soap*, const char*, const char*); - int (*fresolve)(struct soap*, const char*, struct in_addr* inaddr); - int (*fconnect)(struct soap*, const char*, const char*, int); - int (*fdisconnect)(struct soap*); - int (*fclosesocket)(struct soap*, SOAP_SOCKET); - int (*fshutdownsocket)(struct soap*, SOAP_SOCKET, int); - int (*fopen)(struct soap*, const char*, const char*, int); - int (*faccept)(struct soap*, int, struct sockaddr*, int *n); - int (*fclose)(struct soap*); - int (*fsend)(struct soap*, const char*, size_t); - size_t (*frecv)(struct soap*, char*, size_t); - int (*fpoll)(struct soap*); - int (*fprepareinit)(struct soap*); - int (*fpreparesend)(struct soap*, const char*, size_t); - int (*fpreparerecv)(struct soap*, const char*, size_t); - int (*fignore)(struct soap*, const char*); - int (*fserveloop)(struct soap*); - void *(*fplugin)(struct soap*, const char*); - void *(*fdimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fdimewriteopen)(struct soap*, const char*, const char*, const char*); - void (*fdimereadclose)(struct soap*, void*); - void (*fdimewriteclose)(struct soap*, void*); - size_t (*fdimeread)(struct soap*, void*, char*, size_t); - int (*fdimewrite)(struct soap*, void*, const char*, size_t); - int master; - int socket; -#if defined(__cplusplus) && !defined(WITH_LEAN) - ostream *os; - istream *is; -#else - void *os; /* preserve alignment */ - void *is; /* preserve alignment */ -#endif -#ifndef UNDER_CE - int sendfd; - int recvfd; -#else - FILE *sendfd; - FILE *recvfd; - char errorstr[256]; - wchar_t werrorstr[256]; -#endif - size_t bufidx; - size_t buflen; - soap_wchar ahead; - short cdata; - short body; - unsigned int level; - size_t count; /* message length counter */ - size_t length; /* message length as set by HTTP header */ - char *labbuf; /* look-aside buffer */ - size_t lablen; /* look-aside buffer allocated length */ - size_t labidx; /* look-aside buffer index to available part */ - char buf[SOAP_BUFLEN];/* send and receive buffer */ - char tmpbuf[1024]; /* output buffer for HTTP headers, simpleType values, attribute names, and DIME >=1024 bytes */ - char msgbuf[1024]; /* output buffer for (error) messages <=1024 bytes */ - char tag[SOAP_TAGLEN]; - char id[SOAP_TAGLEN]; - char href[SOAP_TAGLEN]; - char type[SOAP_TAGLEN]; - char arrayType[SOAP_TAGLEN]; - char arraySize[SOAP_TAGLEN]; - char arrayOffset[SOAP_TAGLEN]; - short other; - short root; - short position; - int positions[SOAP_MAXDIMS]; - struct soap_attribute *attributes; /* attribute list */ - short encoding; - short mustUnderstand; - short null; - short ns; - short part; - short alloced; - short peeked; - short keep_alive; - size_t chunksize; - size_t chunkbuflen; - char endpoint[SOAP_TAGLEN]; - char path[SOAP_TAGLEN]; - char host[SOAP_TAGLEN]; - char *action; - char *authrealm; /* HTTP authentication realm */ - char *prolog; /* XML declaration prolog */ - int port; - unsigned int max_keep_alive; - const char *proxy_host; /* Proxy Server host name */ - int proxy_port; /* Proxy Server port (default = 8080) */ - const char *proxy_userid; /* Proxy Authorization user name */ - const char *proxy_passwd; /* Proxy Authorization password */ - int status; /* -1 when request, else error code to be returned by server */ - int error; - int errmode; - int errnum; - unsigned long idnum; - unsigned long ip; - struct soap_dime dime; - struct soap_mime mime; - struct soap_dom_element *dom; -#if !defined(WITH_LEAN) || defined(SOAP_DEBUG) - const char *logfile[SOAP_MAXLOGS]; - FILE *fdebug[SOAP_MAXLOGS]; -#endif -#ifndef WITH_LEAN - struct soap_cookie *cookies; - const char *cookie_domain; - const char *cookie_path; - int cookie_max; -#endif -#ifdef WITH_OPENSSL - int (*fsslauth)(struct soap*); - int (*fsslverify)(int, X509_STORE_CTX*); - BIO *bio; - SSL *ssl; - SSL_CTX *ctx; - short require_server_auth; - short require_client_auth; - short rsa; /* when set, use RSA instead of DH */ - const char *keyfile; - const char *password; - const char *dhfile; - const char *cafile; - const char *capath; - const char *randfile; - SSL_SESSION *session; - char session_host[SOAP_TAGLEN]; - int session_port; -#endif -#ifdef WITH_ZLIB - short zlib_state; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_INFLATE */ - short zlib_in; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - short zlib_out; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - z_stream d_stream; /* decompression stream */ - char z_buf[SOAP_BUFLEN]; /* buffer */ - size_t z_buflen; - unsigned short z_level; /* compression level to be used (0=none, 1=fast to 9=best) */ - uLong z_crc; /* internal gzip crc */ - float z_ratio_in; /* detected compression ratio compressed_length/length of inbound message */ - float z_ratio_out; /* detected compression ratio compressed_length/length of outbound message */ -#endif -/* WR[ */ -#ifdef WMW_RPM_IO - void *rpmreqid; -#endif /* WMW_RPM_IO */ -/* ]WR */ -}; - -struct soap_code_map -{ long code; - const char *string; -}; - -/* forwarding list */ -struct soap_flist -{ struct soap_flist *next; - int type; - void *ptr; - unsigned int level; - void (*fcopy)(struct soap*, int, int, void*, const void*, size_t); -}; - -/* id-ref forwarding list */ -struct soap_ilist -{ struct soap_ilist *next; - int type; - size_t size; - void *link; - void *copy; - struct soap_flist *flist; - void *ptr; - unsigned int level; - char id[1]; /* the actual id string value flows into the allocated region below this struct */ -}; - -struct soap_plugin -{ struct soap_plugin *next; - const char *id; - void *data; - int (*fcopy)(struct soap *soap, struct soap_plugin *dst, struct soap_plugin *src); - void (*fdelete)(struct soap *soap, struct soap_plugin *p); /* should delete fields of plugin only and not free(p) */ -}; - -#ifndef WITH_NONAMESPACES -extern SOAP_NMAC struct Namespace namespaces[]; -#endif - -#ifdef HAVE_STRRCHR -# define soap_strrchr(s, t) strrchr(s, t) -#else - SOAP_FMAC1 char* SOAP_FMAC2 soap_strrchr(const char *s, int t); -#endif - -#ifdef HAVE_STRTOL -# define soap_strtol(s, t, b) strtol(s, t, b) -#else - SOAP_FMAC1 long SOAP_FMAC2 soap_strtol(const char *s, char **t, int b); -#endif - -#ifdef HAVE_STRTOUL -# define soap_strtoul(s, t, b) strtoul(s, t, b) -#else - SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b); -#endif - -SOAP_FMAC1 void SOAP_FMAC2 soap_fault(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultstring(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultdetail(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializefault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getfault(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_poll(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect_command(struct soap*, int, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_bind(struct soap*, const char*, int, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_accept(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_accept(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_puthttphdr(struct soap*, int status, size_t count); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_get_header_attribute(struct soap*, const char*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_key(char*, size_t, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_val(char*, size_t, const char*); - -SOAP_FMAC1 size_t SOAP_FMAC2 soap_hash(const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_endpoint(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_get(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getchar(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_tag_cmp(const char*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_sender_error(struct soap*, const char*, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_receiver_error(struct soap*, const char*, const char*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_raw(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send2(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send3(struct soap*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pututf8(struct soap*, unsigned long); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getutf8(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_putbase64(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_getbase64(struct soap*, int*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_puthex(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_gethex(struct soap*, int*); - - -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_lookup(struct soap*, const char*); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_enter(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_resolve(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup_id(struct soap*, void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup(struct soap*, const void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_enter(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_pointer_lookup(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); - -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); - -SOAP_FMAC1 void SOAP_FMAC2 soap_begin_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_send(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_embedded(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_reference(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_reference(struct soap*, const void *p, const struct soap_array *a, int n, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_embedded_id(struct soap*, int id, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_embedded(struct soap*, struct soap_plist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_single(struct soap*, struct soap_plist*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_embedded(struct soap*, struct soap_plist*); - -SOAP_FMAC1 const struct soap_code_map* SOAP_FMAC2 soap_code(const struct soap_code_map*, const char *str); -SOAP_FMAC1 long SOAP_FMAC2 soap_int_code(const struct soap_code_map*, const char *str, long other); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_str_code(const struct soap_code_map*, long code); - -SOAP_FMAC1 int SOAP_FMAC2 soap_getline(struct soap*, char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_recv(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_malloc(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_dealloc(struct soap*, void*); -SOAP_FMAC1 struct soap_clist * SOAP_FMAC2 soap_link(struct soap*, void*, int, int, void (*fdelete)(struct soap_clist*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_unlink(struct soap*, const void*); -SOAP_FMAC1 void SOAP_FMAC2 soap_free(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_lookup_type(struct soap*, const char *id); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_lookup(struct soap*, const char *id, void **p, int t, size_t n, unsigned int k); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_forward(struct soap*, const char *id, void *p, int st, int tt, size_t n, unsigned int k, void(*fcopy)(struct soap*, int, int, void*, const void*, size_t)); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_enter(struct 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*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_fcopy(struct soap *soap, int st, int tt, void *p, const void *q, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_size(const int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getoffsets(const char *, const int *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsize(const char *, const char *, int *); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsizes(const char *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getposition(const char *, int *); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsize(struct soap*, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizesoffsets(struct soap*, const char *, const int *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizes(struct soap*, const char *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffset(struct soap*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffsets(struct soap*, const int *, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_closesock(struct soap*); - -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new(void); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new1(int); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new2(int, int); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*,struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init1(struct soap*, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_init2(struct soap*, int, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_end(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_delete(struct soap*, void*); - -#ifdef SOAP_DEBUG -SOAP_FMAC1 void SOAP_FMAC2 soap_set_recv_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_sent_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_test_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_close_logfiles(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_open_logfile(struct soap*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_value(struct soap*); - -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_advance(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_skip(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_tag(struct soap*, const char*, const char *); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_array(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element(struct soap*, const char*, int, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_out(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_begin_out(struct soap*, const char *tag, int id, const char *type, const char *offset); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_ref(struct soap*, const char *tag, int id, int href); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_href(struct soap*, const char *tag, int id, const char *ref, const char *val); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_null(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_id(struct soap*, const char *tag, int id, const void *p, const struct soap_array *a, int d, const char *type, int n); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_result(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_out(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_start_end_out(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_attribute(struct soap*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_in(struct soap*, const char *tag, int nillable); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_in(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_peek_element(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_retry(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_revert(struct soap*); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_strdup(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_string_out(struct soap*, const char *s, int flag); -SOAP_FMAC1 char* SOAP_FMAC2 soap_string_in(struct soap*, int, long, long); -SOAP_FMAC1 int SOAP_FMAC2 soap_wstring_out(struct soap*, const wchar_t *s, int flag); -SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstring_in(struct soap*, int, long, long); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_namespace(struct soap*, const char *, const char*, int n1, int n2); - -SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap*, struct Namespace*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_namespace(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_push_namespace(struct soap*, const char *,const char *); - -SOAP_FMAC1 int SOAP_FMAC2 soap_new_block(struct soap*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_push_block(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_size_block(struct soap*, size_t); -SOAP_FMAC1 char* SOAP_FMAC2 soap_first_block(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_next_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_block_size(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_save_block(struct soap*, char*, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*); -SOAP_FMAC1 int soap_envelope_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_out(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_header(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_response(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_fault(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_fault(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap*, FILE*); -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault_location(struct soap*, FILE*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_s2byte(struct soap*, const char*, char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2short(struct soap*, const char*, short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2int(struct soap*, const char*, int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2long(struct soap*, const char*, long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2LONG64(struct soap*, const char*, LONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2float(struct soap*, const char*, float*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2double(struct soap*, const char*, double*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedByte(struct soap*, const char*, unsigned char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedShort(struct soap*, const char*, unsigned short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedInt(struct soap*, const char*, unsigned int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedLong(struct soap*, const char*, unsigned long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2ULONG64(struct soap*, const char*, ULONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2dateTime(struct soap*, const char*, time_t*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2string(struct soap*, const char*, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2QName(struct soap*, const char*, char**); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2base64(struct soap*, const unsigned char*, char*, size_t); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_byte2s(struct soap*, char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_short2s(struct soap*, short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_int2s(struct soap*, int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_long2s(struct soap*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_LONG642s(struct soap*, LONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_float2s(struct soap*, float); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_double2s(struct soap*, double); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedByte2s(struct soap*, unsigned char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedShort2s(struct soap*, unsigned short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedInt2s(struct soap*, unsigned int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedLong2s(struct soap*, unsigned long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_ULONG642s(struct soap*, ULONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_dateTime2s(struct soap*, time_t); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_QName2s(struct soap*, const char*); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_base642s(struct soap*, const char*, char*, size_t, size_t*); - -SOAP_FMAC1 int* SOAP_FMAC2 soap_inint(struct soap*, const char *tag, int *p, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_inbyte(struct soap*, const char *tag, char *p, const char *, int); -SOAP_FMAC1 long* SOAP_FMAC2 soap_inlong(struct soap*, const char *tag, long *p, const char *, int); -SOAP_FMAC1 LONG64* SOAP_FMAC2 soap_inLONG64(struct soap*, const char *tag, LONG64 *p, const char *, int); -SOAP_FMAC1 short* SOAP_FMAC2 soap_inshort(struct soap*, const char *tag, short *p, const char *, int); -SOAP_FMAC1 float* SOAP_FMAC2 soap_infloat(struct soap*, const char *tag, float *p, const char *, int); -SOAP_FMAC1 double* SOAP_FMAC2 soap_indouble(struct soap*, const char *tag, double *p, const char *, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_inunsignedByte(struct soap*, const char *tag, unsigned char *p, const char *, int); -SOAP_FMAC1 unsigned short* SOAP_FMAC2 soap_inunsignedShort(struct soap*, const char *tag, unsigned short *p, const char *, int); -SOAP_FMAC1 unsigned int* SOAP_FMAC2 soap_inunsignedInt(struct soap*, const char *tag, unsigned int *p, const char *, int); -SOAP_FMAC1 unsigned long* SOAP_FMAC2 soap_inunsignedLong(struct soap*, const char *tag, unsigned long *p, const char *, int); -SOAP_FMAC1 ULONG64* SOAP_FMAC2 soap_inULONG64(struct soap*, const char *tag, ULONG64 *p, const char *, int); -SOAP_FMAC1 time_t* SOAP_FMAC2 soap_indateTime(struct soap*, const char *tag, time_t *p, const char *, int); -SOAP_FMAC1 char** SOAP_FMAC2 soap_instring(struct soap*, const char *tag, char **p, const char *, int, int, long, long); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwstring(struct soap*, const char *tag, wchar_t **p, const char *, int, long, long); -SOAP_FMAC1 char** SOAP_FMAC2 soap_inliteral(struct soap*, const char *tag, char **p); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwliteral(struct soap*, const char *tag, wchar_t **p); - -SOAP_FMAC1 int SOAP_FMAC2 soap_outbyte(struct soap*, const char *tag, int id, const char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outshort(struct soap*, const char *tag, int id, const short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outint(struct soap*, const char *tag, int id, const int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outlong(struct soap*, const char *tag, int id, const long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outLONG64(struct soap*, const char *tag, int id, const LONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outfloat(struct soap*, const char *tag, int id, const float *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdouble(struct soap*, const char *tag, int id, const double *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedByte(struct soap*, const char *tag, int id, const unsigned char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedShort(struct soap*, const char *tag, int id, const unsigned short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedInt(struct soap*, const char *tag, int id, const unsigned int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedLong(struct soap*, const char *tag, int id, const unsigned long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outULONG64(struct soap*, const char *tag, int id, const ULONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdateTime(struct soap*, const char *tag, int id, const time_t *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outstring(struct soap*, const char *tag, int id, char *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwstring(struct soap*, const char *tag, int id, wchar_t *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outliteral(struct soap*, const char *tag, char *const*p); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwliteral(struct soap*, const char *tag, wchar_t *const*p); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_element_dime(struct soap *, const char*, int, const void*, const struct soap_array*, const char*, const char*, const char*, int, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, long); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_tell(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_dime_option(struct soap*, unsigned short, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmimehdr(struct soap*, struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_mime(struct soap*, const char *boundary, const char *start); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_mime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_dime_attachment(struct soap*, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_mime_attachment(struct soap*, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_register_plugin_arg(struct soap*, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_lookup_plugin(struct soap*, const char*); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_attr_value(struct soap *soap, const char *name, int flag); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_attr(struct soap *soap, const char *name, const char *value); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_attr(struct soap *soap); - -#ifdef WITH_COOKIES -SOAP_FMAC1 size_t SOAP_FMAC2 soap_encode_cookie(const char*, char*, size_t); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_set_cookie(struct soap*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern long SOAP_FMAC2 soap_cookie_expire(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_expire(struct soap*, const char*, long, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_clr_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_clr_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_getenv_cookies(struct soap*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_copy_cookies(struct soap*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_free_cookies(struct soap*); -#endif - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.c b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.c deleted file mode 100644 index b4750a4..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.c +++ /dev/null @@ -1,12026 +0,0 @@ -/* - -stdsoap2.c[pp] 2.7.0f - -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. - --------------------------------------------------------------------------------- - - This software is released under one of the following three licenses: - GPL, the gSOAP public license, or Genivia's license for commercial use. - --------------------------------------------------------------------------------- -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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- - -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.0f 2005-02-28 12:00:00 GMT") -extern "C" { -#else -SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.7.0f 2005-02-28 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_QT (soap_wchar)(-5) /* XML character '"' */ -#define SOAP_AP (soap_wchar)(-6) /* XML character ''' */ - -#define SOAP_BOM (soap_wchar)(0xFEFF) /* UTF BOM is Unicode FEFF */ - -#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*); - -#ifndef WITH_NOIDREF -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*); -#endif - -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, soap_wchar); -static void soap_set_local_namespaces(struct soap*); -static void *fplugin(struct soap*, const char*); - -#ifndef WITH_LEAN -static const char *soap_set_validation_fault(struct soap*, const char*, const char*); -static int soap_isnumeric(struct soap*, const char*); -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 - -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -static const char *soap_decode(char*, size_t, const char*, const char*); -#endif - -#ifndef WITH_NOHTTP -static soap_wchar soap_getchunkchar(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*); -#endif - -#ifndef WITH_NOIO -static int fsend(struct soap*, const char*, size_t); -static size_t frecv(struct soap*, char*, size_t); -static int tcp_init(struct soap*); -static const char *tcp_error(struct soap*); -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 const char *soap_strerror(struct soap*); -#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_NOIO -#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 -#endif - -#ifndef WITH_NOHTTP -#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 -#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 WITH_NOIO -#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); -#ifndef WITH_LEANER - if (soap->fpreparesend) - return soap->fpreparesend(soap, s, n); -#endif - return SOAP_OK; - } -#ifndef WITH_LEANER - 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); -#endif - 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; -#ifndef WITH_LEANER - if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->fpreparesend(soap, s, n); -#endif - 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 WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 - if (soap->recv_timeout) - { struct timeval timeout; - fd_set fd; - 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 || 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_socket_errno != SOAP_EWOULDBLOCK) - { 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); -#ifdef WITH_OPENSSL - if (soap->ssl && SSL_get_error(soap->ssl, r) == SSL_ERROR_WANT_WRITE) - r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); - else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#endif - 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 WITH_NOHTTP -#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 from socket %d\n", (unsigned int)soap->buflen, soap->socket)); - DBGMSG(RECV, soap->buf, soap->buflen); - if (soap->buflen) - return soap->buf[soap->bufidx++]; - return EOF; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -static int -soap_isxdigit(int c) -{ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); -} -#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 -#ifndef WITH_NOHTTP - 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 from socket %d\n", (unsigned int)ret, soap->socket)); - 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 -#endif - { soap->bufidx = 0; - soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - } -#ifndef WITH_LEANER - if (soap->fpreparerecv && (soap->error = soap->fpreparerecv(soap, soap->buf, ret))) - return soap->error; -#endif -#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 - -/******************************************************************************/ -#ifdef WITH_LEAN -soap_wchar -soap_get0(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx]; -} -#endif - -/******************************************************************************/ -#ifdef WITH_LEAN -soap_wchar -soap_get1(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx++]; -} -#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 WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#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); -#ifndef WITH_NOIDREF - if (flag) - soap_update_ptrs(soap, q, q + n, (long)s - (long)q); /* pointers s and q may or may not be related */ -#endif - 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 WITH_NOIO -#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 -#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; -#ifndef WITH_NOHTTP - 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; -#endif -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; -#endif - 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 WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static const char* -http_error(struct soap *soap, int status) -{ register const char *msg = SOAP_STR_EOS; -#ifndef WITH_LEAN - msg = soap_str_code(h_http_error_codes, status); - if (!msg) - msg = SOAP_STR_EOS; -#endif - return msg; -} -#endif -#endif - -/******************************************************************************/ -/* WR[ */ -#ifndef WITH_IPV6 -/* ]WR */ -#ifndef WITH_NOIO -#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 WITH_NOIO -#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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } -#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 SOAP_INVALID_SOCKET; - } - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } -#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 SOAP_INVALID_SOCKET; - } -#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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - } - 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 &= ~SOAP_ENC; /* 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 SOAP_INVALID_SOCKET; -#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 SOAP_INVALID_SOCKET; - soap->omode = k; - k = soap->imode; - soap->imode &= ~SOAP_ENC; /* mask IO and ENC */ - if (soap_begin_recv(soap)) - return SOAP_INVALID_SOCKET; - 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 SOAP_INVALID_SOCKET; - } - soap->ssl = SSL_new(soap->ctx); - if (!soap->ssl) - { soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - } - } -#endif - return fd; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 SOAP_INVALID_SOCKET; - } -/* 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } -#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 SOAP_INVALID_SOCKET; - } -/* 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } -#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 SOAP_INVALID_SOCKET; - } -#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 SOAP_INVALID_SOCKET; - } -#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 SOAP_INVALID_SOCKET; - } - } - 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 SOAP_INVALID_SOCKET; - } -/* WR[ */ -#endif /* WITH_IPV6 */ -/* ]WR */ -#ifdef WITH_OPENSSL - if (!soap->ctx && (soap->error = soap->fsslauth(soap))) - return SOAP_INVALID_SOCKET; -#endif - return soap->master; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_poll(struct soap *soap) -{ -#ifndef WITH_LEAN - struct timeval timeout; - fd_set sfd, rfd, xfd; - int r; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_ZERO(&xfd); - if (soap_valid_socket(soap->socket)) - { FD_SET(soap->socket, &rfd); - FD_SET(soap->socket, &sfd); - FD_SET(soap->socket, &xfd); - r = select(soap->socket + 1, &rfd, &sfd, &xfd, &timeout); - if (r > 0 && FD_ISSET(soap->socket, &xfd)) - r = -1; - } - else if (soap_valid_socket(soap->master)) - { FD_SET(soap->master, &rfd); - r = select(soap->master + 1, &rfd, &sfd, NULL, &timeout); - } - else - return SOAP_OK; - if (r > 0) - { -#ifdef WITH_OPENSSL - if (soap->ssl) - { if (soap_valid_socket(soap->socket) && FD_ISSET(soap->socket, &rfd)) - { char buf = '\0'; - if (SSL_peek(soap->ssl, &buf, 1) <= 0) - return SOAP_EOF; - } - } -#endif - if (soap_valid_socket(soap->socket) && FD_ISSET(soap->socket, &rfd)) - return SOAP_EOF; - 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 WITH_NOIO -#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 WITH_NOIO -#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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - } -#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 - soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&sockaddr, &n); - if (soap_valid_socket(soap->socket)) - { -/* 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 SOAP_INVALID_SOCKET; - } - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } -#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 SOAP_INVALID_SOCKET; - } -#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) - { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host)); - soap->errnum = soap_socket_errno; - soap_set_receiver_error(soap, tcp_error(soap), "TCP accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } - } - else - { soap_set_receiver_error(soap, tcp_error(soap), "TCP no master socket in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 WITH_NOIO -#ifndef PALM_1 -static int -tcp_closesocket(struct soap *soap, SOAP_SOCKET fd) -{ return closesocket(fd); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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; - if (status == SOAP_EOF || status == SOAP_TCP_ERROR || status == SOAP_SSL_ERROR || !soap->keep_alive) - { if (soap->fclose && (soap->error = soap->fclose(soap))) - return soap->error; - soap->socket = SOAP_INVALID_SOCKET; - soap->keep_alive = 0; - } -#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 WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new1(soap_mode mode) -{ return soap_new2(mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new() -{ return soap_new2(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new2(soap_mode imode, soap_mode omode) -{ struct soap *soap = (struct soap*)SOAP_MALLOC(sizeof(struct soap)); - if (soap) - soap_init2(soap, imode, omode); - return soap; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#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)) -#ifndef WITH_LEANER - && !soap->fpreparesend -#endif - )) - soap->mode &= ~SOAP_IO_LENGTH; - else - soap->mode |= SOAP_IO_LENGTH; - } -#ifdef WITH_ZLIB - 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; - } - -#endif - 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; -#ifndef WITH_LEANER - soap->dime.count = 0; /* count # of attachments */ - soap->dime.size = 0; /* accumulate total size of attachments */ - if (soap->fprepareinit && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - soap->fprepareinit(soap); -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); -} -#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->mode & (SOAP_IO_LENGTH | SOAP_ENC_DIME)); -#ifdef WITH_ZLIB - 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; - } -#endif - if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket)) - { if (soap->count || (soap->mode & SOAP_IO_LENGTH) || (soap->mode & SOAP_ENC_XML)) - soap->mode |= SOAP_IO_BUFFER; - else - soap->mode |= SOAP_IO_STORE; - } - soap->mode &= ~SOAP_IO_LENGTH; - 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); -#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 -#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)); -#ifndef WITH_LEANER - if (soap->fprepareinit && (soap->mode & SOAP_IO) == SOAP_IO_STORE) - soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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; - int i; - 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:"")); - i = soap_array_pointer_lookup(soap, p, a, n, t, &pp); - if (!i) - { i = soap_pointer_enter(soap, p, a, n, t, &pp); - if (!i) - { soap->error = SOAP_EOM; - return -1; - } - } - if (id < 0) - id = i; - 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) - { soap->error = SOAP_EOM; - return -1; - } - content->id = aid; - content->type = atype; - content->options = aoptions; - pp->mark1 = 3; - } - } - else - pp->mark2 = 3; - return -1; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#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 WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 (!p || !id || !*id) - return p; - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#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; - } -#ifndef WITH_NOIDREF - if (!id || !*id) -#endif - return p; -#ifndef WITH_NOIDREF - 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 -} -#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; -#ifndef WITH_NOHTTP - 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++; - } -#endif - 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); - } -#ifndef WITH_LEANER - 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) - 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; -#ifndef WITH_NOIDREF - return soap_resolve(soap); -#else - return SOAP_OK; -#endif -} -#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 -#ifndef WITH_NOIDREF - soap_free_pht(soap); - soap_free_iht(soap); -#endif - 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); -#ifndef WITH_NOIDREF - soap_init_iht(copy); - soap_init_pht(copy); -#endif - 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; -#ifndef WITH_NOHTTP - 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; -#endif - soap->fconnect = NULL; - soap->fdisconnect = NULL; -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; -#endif - soap->fignore = NULL; - soap->fserveloop = NULL; - soap->fplugin = fplugin; -#ifndef WITH_LEANER - soap->fdimereadopen = NULL; - soap->fdimewriteopen = NULL; - soap->fdimereadclose = NULL; - soap->fdimewriteclose = NULL; - soap->fdimeread = NULL; - soap->fdimewrite = NULL; -#endif - 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; -#ifdef WITH_FAST - soap->labbuf = NULL; - soap->lablen = 0; - soap->labidx = 0; -#endif - 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; -#ifndef WITH_LEANER - 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; -#endif -#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 -#ifndef WITH_NOIDREF - soap_init_iht(soap); - soap_init_pht(soap); -#endif - 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, soap_mode mode) -{ soap_init2(soap, mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init2(struct soap *soap, soap_mode imode, soap_mode 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'; -#ifndef WITH_LEANER - soap->dime.chunksize = 0; - soap->dime.buflen = 0; -#endif - 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++; - n *= sizeof(struct Namespace); - ns2 = (struct Namespace*)SOAP_MALLOC(n); - if (ns2) - { memcpy(ns2, soap->namespaces, n); - 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 : "")) - 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_send(soap, " ") || 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_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, "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) -{ if (!p || (a && !a->__ptr)) - { soap_element_null(soap, tag, id, type); - return -1; - } -#ifndef WITH_NOIDREF - if (soap->mode & SOAP_XML_TREE) - return 0; - if (id < 0) - { struct soap_plist *pp; - 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; -#else - return 0; -#endif -} -#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_send(soap, " ") || 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, 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; - register int n = 0; - if (tag && *tag == '-') - return SOAP_OK; - soap->level--; - soap_pop_namespace(soap); - if (soap->error == SOAP_NO_TAG) - soap->error = SOAP_OK; - if (soap->peeked && *soap->tag) - n++; - soap->peeked = 0; - do - { while (((c = soap_get(soap)) != SOAP_TT)) - { if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (c == SOAP_LT) - n++; - } - } while (n--); - 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->peeked) - { if (!*soap->tag) - return soap->error = SOAP_NO_TAG; - return SOAP_OK; - } - soap->peeked = 1; - for (;;) - { c = soap_getutf8(soap); - if (c == SOAP_BOM) - c = soap_getutf8(soap); - while (soap_blank(c)) - c = soap_getutf8(soap); - if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (c != SOAP_LT) - { *soap->tag = '\0'; - soap_unget(soap, c); - return soap->error = SOAP_NO_TAG; - } - 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->error = 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 = 0xFFFFFF80UL; -#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: -#ifndef WITH_LEANER -#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 -#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 size_t m = 0; - register soap_wchar c; -#if !defined(WITH_LEANER) && defined(HAVE_WCTOMB) - char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8]; -#else - char buf[8]; -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading string content\n")); -#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: -#ifndef WITH_LEANER -#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 -#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*)"amp;"; - m = 4; - } - 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; -#ifndef WITH_LEANER -#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 -#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; - if (soap->peeked && *soap->tag) - { soap->peeked = 0; - if (soap_element_end_in(soap, NULL)) - return NULL; - } - return t; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading wide string content\n")); - if (soap->peeked && *soap->tag) - { n = 1; - soap->peeked = 0; - } - 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; - } - if (soap->peeked && *soap->tag) - { soap->peeked = 0; - if (soap_element_end_in(soap, NULL)) - return NULL; - } - return (wchar_t*)soap_save_block(soap, NULL, 0); -} -#endif -#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 - { -#if defined(HAVE_STRTOF) - char *r; - *p = strtof(s, &r); - if (*r) -#elif defined(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 PALM_2 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_unsignedShort2s(struct soap *soap, unsigned short n) -{ return soap_unsignedLong2s(soap, (unsigned long)n); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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 PALM_2 -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 PALM_2 -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)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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 WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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 -#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, "", 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)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - if (!(p = (char**)soap_malloc(soap, sizeof(char*)))) - return NULL; - if (soap->null) - *p = NULL; - else - *p = soap_string_in(soap, 0, -1, -1); - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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, "", t); - return soap_send(soap, soap->tmpbuf); - } - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*)))) - return NULL; - if (soap->null) - *p = NULL; - else - *p = soap_wstring_in(soap, 0, -1, -1); - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif -#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 - -/******************************************************************************/ -#if !defined(WITH_LEANER) || !defined(WITH_NOHTTP) -#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' || c == '\n') - break; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - *s++ = (char)c; - } - if (c != '\n') - c = soap_getchar(soap); /* got \r, now get \n */ - if (c == '\n') - { *s = '\0'; - if (i+1 == len) /* empty line: end of HTTP/MIME 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 -#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, *t = NULL; - 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 (;;) - { 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; - memset(t, 0, sizeof(soap->tmpbuf)); - strcpy(t, "\n--"); - strncat(t, soap->mime.boundary, sizeof(soap->tmpbuf)-4); - 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 + 1); - if (!s) - return; - } - strcpy(s, "<>"); - s += 2; - n -= 4; - while (n) - { *s++ = soap_base64o[rand()&0x3F]; - n--; - } - strcpy(s, "<>"); - } - if (!soap->mime.start) - soap->mime.start = ""; -} -#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 && !strchr("()<>@,;:\\\"/[]?={}", 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); - *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 */ -#ifndef WITH_NOIDREF - soap_free_iht(soap); -#endif - 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; -#ifndef WITH_LEANER - 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; -#endif -#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 -#ifndef WITH_LEANER - 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 -#ifndef WITH_LEANER - 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 -#endif - { while (soap_blank(c)) - c = soap_getchar(soap); - } - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifndef WITH_NOHTTP - 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; - } -#ifndef WITH_LEANER - else if (soap->fpreparerecv && soap->buflen != soap->bufidx) - soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx); -#endif -#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 - } -#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 WITH_NOHTTP -#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)) - { if (soap->error == SOAP_EOF) - { soap->error = SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "EOF in HTTP header, continue anyway\n")); - break; - } - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#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); -#ifndef WITH_LEANER - if (soap->fconnect) - { if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port))) - return soap->error; - } - else -#endif - if (soap->fopen && *soap->host) - { soap->status = http_command; - if (!soap->keep_alive || !soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port || !soap->fpoll || soap->fpoll(soap)) - { soap->keep_alive = 0; /* force close */ - soap_closesock(soap); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect/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; - soap->keep_alive = ((soap->omode & SOAP_IO_KEEPALIVE) != 0); - } - } - if (soap_begin_send(soap)) - return soap->error; - count = soap_count_attachments(soap); -#ifndef WITH_NOHTTP - 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; -#ifndef WITH_LEANER - if ((k & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = k; - } - if (http_command != SOAP_POST) - return soap_end_send(soap); -#endif - 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 WITH_NOHTTP -#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 && soap->http_content) - 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->status != SOAP_GET) - { register const char *t = strchr(s, ';'); - sprintf(soap->tmpbuf, "multipart/related; boundary=\"%s\"; type=\"", soap->mime.boundary); - if (t) - strncat(soap->tmpbuf, s, t - s); - else - strcat(soap->tmpbuf, s); - if (soap->mime.start) - { strcat(soap->tmpbuf, "\"; start=\""); - strcat(soap->tmpbuf, soap->mime.start); - } - strcat(soap->tmpbuf, "\""); - 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 -#ifndef WITH_LEANER - if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK) - err = soap->fposthdr(soap, "Transfer-Encoding", "chunked"); - else -#endif - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_get(struct soap *soap) -{ return SOAP_GET_METHOD; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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; -#ifndef WITH_LEAN - 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; - } -#endif - } - 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 -#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; -#ifndef WITH_NOHTTP - 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; -#ifndef WITH_LEANER - if ((n & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = n; - } -#endif - 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_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; -#ifndef WITH_NOIO - case SOAP_TCP_ERROR: - *s = tcp_error(soap); - break; -#endif - 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: -#ifndef WITH_NOIO - sprintf(soap->msgbuf, "End of file or no input: '%s'", soap_strerror(soap)); - *s = soap->msgbuf; - break; -#else - *s = "End of file or no input"; - break; -#endif - default: -#ifndef WITH_NOHTTP -#ifndef WITH_LEAN - if (soap->error > 200 && soap->error < 600) - { sprintf(soap->msgbuf, "HTTP Error: %d %s", soap->error, http_error(soap, soap->error)); - *s = soap->msgbuf; - } - else -#endif -#endif - { 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 WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_send_empty_response(struct soap *soap) -{ soap->count = 0; - if (soap_response(soap, SOAP_OK) || soap_end_send(soap)) - return soap_closesock(soap); - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_recv_empty_response(struct soap *soap) -{ if (soap_begin_recv(soap) || soap_end_recv(soap)) - return soap_closesock(soap); - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static const char* -soap_strerror(struct soap *soap) -{ - int err = soap->errnum; - if (!err) - err = soap_errno; - if (err) - { -#ifndef WIN32 - return strerror(err); -#else - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)&soap->errorstr, sizeof(soap->errorstr), NULL); - return soap->errorstr; -#endif - } - return "Operation interrupted or timed out"; -} -#endif -#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 -#ifndef WITH_NOIO -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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -#ifndef WITH_NOIO -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 -#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 - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.h b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.h deleted file mode 100644 index 097b551..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.0f.h +++ /dev/null @@ -1,1885 +0,0 @@ -/* - -stdsoap2.h 2.7.0f - -gSOAP runtime environment. - -gSOAP XML Web services tools -Copyright (C) 2000-2005, Robert van Engelen, Genivia, Inc., All Rights Reserved. - -Contributors: - -Wind River Systems, Inc., for the following additions (marked WR[...]) : - - vxWorks compatible - - Support for IPv6. - --------------------------------------------------------------------------------- - - This software is released under one of the following three licenses: - GPL, the gSOAP public license, or Genivia's license for commercial use. - --------------------------------------------------------------------------------- -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-2005, 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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- -*/ - -#ifdef WITH_SOAPDEFS_H -# include "soapdefs.h" /* include user-defined stuff */ -#endif - -#ifndef _THREAD_SAFE -# define _THREAD_SAFE -#endif - -#ifndef OPENSERVER -# ifndef _REENTRANT -# define _REENTRANT -# endif -#endif - -#ifndef SOAP_BEGIN_NAMESPACE -# define SOAP_BEGIN_NAMESPACE(name) -#endif - -#ifndef SOAP_END_NAMESPACE -# define SOAP_END_NAMESPACE(name) -#endif - -#ifndef SOAP_FMAC1 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC1 -#endif - -#ifndef SOAP_FMAC2 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC2 -#endif - -#ifndef SOAP_FMAC3 /* (de)serializer declaration macro */ -# define SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC3S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC3S SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC4 /* (de)serializer declaration macro */ -# define SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC4S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC4S SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC5 /* stub/skeleton declaration macro */ -# define SOAP_FMAC5 -#endif - -#ifndef SOAP_FMAC6 /* stub/skeleton declaration macro */ -# define SOAP_FMAC6 -#endif - -#ifndef SOAP_CMAC /* class declaration macro */ -# define SOAP_CMAC -#endif - -#ifndef SOAP_NMAC /* namespace table declaration macro */ -# define SOAP_NMAC -#endif - -#ifndef SOAP_SOURCE_STAMP -# define SOAP_SOURCE_STAMP(str) -#endif - -#ifdef WITH_LEANER -# ifndef WITH_LEAN -# define WITH_LEAN -# endif -#endif - -#ifdef WITH_LEAN -# ifdef WITH_COOKIES -# error "Cannot build WITH_LEAN code WITH_COOKIES enabled" -# endif -#endif - -#ifndef STDSOAP_H -#define STDSOAP_H - -#if defined(__vxworks) || defined(__VXWORKS__) -# define VXWORKS -#endif - -#ifdef _WIN32 -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef UNDER_CE -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef __BORLANDC__ -# ifdef __WIN32__ -# ifndef WIN32 -# define WIN32 -# endif -# endif -#endif - -#ifdef __CYGWIN__ -# ifndef CYGWIN -# define CYGWIN -# endif -#endif - -#ifdef __SYMBIAN32__ -# define SYMBIAN -# undef WIN32 -#endif - -#if defined(__palmos__) || defined(PALM_GCC) || defined(__PALMOS_TRAPS__) -# ifndef PALM -# define PALM -# endif -#endif - -#if defined(__hpux) -# ifndef HP_UX -# define HP_UX -# endif -#endif - -#ifdef __alpha -# ifndef TRU64 -# define TRU64 -# endif -#endif - -#ifdef __MVS__ -# ifndef OS390 -# define OS390 -# endif -#endif - -#ifdef _AIX -# define __socklen_t_defined -#endif - -#ifdef HAVE_CONFIG_H -# include "config.h" -#else -# if defined(UNDER_CE) -# define WITH_LEAN -# define HAVE_SSCANF -# elif defined(WIN32) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(CYGWIN) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__APPLE__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(_AIXVERSION_431) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(HP_UX) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(FREEBSD) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GETTIMEOFDAY -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__VMS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__GLIBC__) || defined(__GNU__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define HAVE_ISNAN -# elif defined(TRU64) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GETTIMEOFDAY -# define HAVE_SYS_TIMEB_H -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define __USE_STD_IOSTREAM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(MAC_CARBON) -# define WITH_NOIO -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(PALM) -# define WITH_LEAN -# define HAVE_STRTOD /* strtod() is defined in palmFunctions.h */ -# include /* Needs to be included before unix headers */ -# include -# define IGNORE_STDIO_STUBS -# include -# define O_NONBLOCK FNONBIO -# include -# include -# include "palmFunctions.h" -# elif defined(SYMBIAN) -# define WITH_LEAN -# define WITH_NONAMESPACES -# define HAVE_STRTOD /* use STRTOD since sscanf doesn't seem to work */ -# include -# include -# elif defined(VXWORKS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_PGMTIME_R -# define HAVE_PLOCALTIME_R -# define HAVE_MKTIME -# elif defined(OS390) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MB -# else -/* Default asumptions on supported functions */ -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# endif -#endif - -#if defined(TRU64) -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -#elif defined(WIN32) -# define SOAP_LONG_FORMAT "%I64d" -# define SOAP_ULONG_FORMAT "%I64u" -#endif - -#ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%lld" /* printf format for 64 bit ints */ -#endif - -#ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%llu" /* printf format for unsigned 64 bit ints */ -#endif - -#ifndef SOAP_MALLOC /* use libc malloc */ -# define SOAP_MALLOC(n) malloc(n) -#endif - -#ifndef SOAP_FREE /* use libc free */ -# define SOAP_FREE(p) free(p) -#endif - -#include - -#ifndef PALM -# include -# include -#endif - -#include -#include - -#if defined(__cplusplus) && !defined(WITH_LEAN) -# include -# include - using namespace std; -#endif - -#ifdef WITH_NOHTTP -# ifndef WITH_NOIO -# define WITH_NOIO -# undef WITH_COOKIES -# endif -#endif - -#ifndef UNDER_CE -# ifndef PALM -# ifndef WITH_NOIO -# include -# include -# endif -# ifndef WITH_LEAN -# ifdef HAVE_SYS_TIMEB_H -# include /* for ftime() */ -# endif -# include -# endif -# endif -#endif - -#ifdef OPENSERVER -# include -# include -# include - extern int h_errno; -#endif - -#ifndef WITH_NOIO -# ifndef WIN32 -# ifndef PALM -# include -# ifdef VXWORKS -# include -# endif -# ifndef VXWORKS -# ifndef SYMBIAN -# include -# endif -# endif -# ifdef SUN_OS -# include /* SUN */ -# include /* SUN < 2.8 (?) */ -# endif -# ifdef VXWORKS -# include -# else -# include -# endif -# include -# ifdef OS390 -# include -# else -# include /* TCP_NODELAY */ -# endif -# include -# endif -# endif -#endif - -#ifdef WITH_FASTCGI -# include -#endif - -#ifdef WITH_OPENSSL -# define OPENSSL_NO_KRB5 -# include -# include -# include -# ifndef ALLOW_OLD_VERSIONS -# if (OPENSSL_VERSION_NUMBER < 0x00905100L) -# error "Must use OpenSSL 0.9.6 or later" -# endif -# endif -#endif - -#ifdef WITH_GZIP -# ifndef WITH_ZLIB -# define WITH_ZLIB -# endif -#endif - -#ifdef WITH_CASEINSENSITIVETAGS -# define SOAP_STRCMP soap_tag_cmp /* case insensitve XML element/attribute names */ -#else -# define SOAP_STRCMP strcmp /* case sensitive XML element/attribute names */ -#endif - -#ifdef WITH_ZLIB -# include -#endif - -#ifndef PALM -# include /* for isnan() */ -#endif - -/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef WIN32 -# ifndef UNDER_CE -# include -# include -# endif -# include -/* # include */ /* Alternative: use winsock2 (not available with eVC) */ -/* WR[ */ -# ifdef WITH_IPV6 -# include -# include -# endif -#else -# ifdef VXWORKS -# include -# include -# include -# endif -/* ]WR */ -# ifndef WITH_NOIO -# ifndef PALM -# include -# include -# include -# include -# endif -# endif -#endif - -#ifdef WIN32 -# define SOAP_SOCKET SOCKET -#else -# define SOAP_SOCKET int -# define closesocket(n) close(n) -#endif - -#define SOAP_INVALID_SOCKET (-1) -#define soap_valid_socket(n) ((n) != SOAP_INVALID_SOCKET) - -#if defined(SYMBIAN) -# define LONG64 long -# define ULONG64 unsigned LONG64 -#elif !defined(WIN32) || defined(__GLIBC__) || defined(__GNU__) -# ifndef LONG64 -# define LONG64 long long -# define ULONG64 unsigned LONG64 -# endif -#elif defined(UNDER_CE) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#elif defined(__BORLANDC__) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#endif - -#if defined(WIN32) -# define soap_int32 __int32 -#elif defined(SYMBIAN) -# define soap_int32 long -#elif defined(PALM) -# define soap_int32 Int32 -#else -# define soap_int32 int32_t -#endif - -#ifdef WIN32 -# define SOAP_EINTR WSAEINTR -# define SOAP_EAGAIN WSAEWOULDBLOCK -# define SOAP_EWOULDBLOCK WSAEWOULDBLOCK -# define SOAP_EINPROGRESS WSAEINPROGRESS -#else -# define SOAP_EINTR EINTR -# define SOAP_EAGAIN EAGAIN -# ifdef SYMBIAN -# define SOAP_EWOULDBLOCK 9898 -# define SOAP_EINPROGRESS 9899 -# else -# define SOAP_EWOULDBLOCK EWOULDBLOCK -# define SOAP_EINPROGRESS EINPROGRESS -# endif -#endif - -#ifdef WIN32 -# ifdef UNDER_CE -# define soap_errno GetLastError() -# define soap_socket_errno GetLastError() -# else -# define soap_errno GetLastError() -# define soap_socket_errno WSAGetLastError() -# endif -#else -# ifndef WITH_NOIO -# define soap_errno errno -# define soap_socket_errno errno -# else -# define soap_errno 0 -# define soap_socket_errno 0 -# endif -#endif - -#ifndef SOAP_BUFLEN -# ifndef WITH_LEAN -# define SOAP_BUFLEN (32768) /* buffer length for socket packets, also used by gethostbyname_r so don't make this too small */ -# else -# define SOAP_BUFLEN (2048) -# endif -#endif -#ifndef SOAP_LABLEN -# ifndef WITH_LEAN -# define SOAP_LABLEN (256) /* initial look-aside buffer length */ -# else -# define SOAP_LABLEN (32) -# endif -#endif -#ifndef SOAP_PTRHASH -# ifndef WITH_LEAN -# define SOAP_PTRHASH (1024) /* size of pointer analysis hash table (must be power of 2) */ -# else -# define SOAP_PTRHASH (16) -# endif -#endif -#ifndef SOAP_IDHASH -# ifndef WITH_LEAN -# define SOAP_IDHASH (1999) /* prime size of hash table for parsed id/ref */ -# else -# define SOAP_IDHASH (19) /* 19, 199 */ -# endif -#endif -#ifndef SOAP_BLKLEN -# ifndef WITH_LEAN -# define SOAP_BLKLEN (256) /* size of blocks to collect long strings and XML attributes */ -# else -# define SOAP_BLKLEN (32) -# endif -#endif -#ifndef SOAP_TAGLEN -# ifndef WITH_LEAN -# define SOAP_TAGLEN (256) /* maximum length of XML element tag/attribute name or host/path name + 1 */ -# else -# define SOAP_TAGLEN (64) -# endif -#endif -#ifndef SOAP_HDRLEN -# ifndef WITH_LEAN -# define SOAP_HDRLEN (8192) /* maximum length of HTTP header line (must be >4096 to read cookies) */ -# else -# define SOAP_HDRLEN (1024) -# endif -#endif -#ifndef SOAP_MAXDIMS -# ifndef WITH_LEAN -# define SOAP_MAXDIMS (16) /* maximum array dimensions (array nestings) must be less than 64 to protect soap->tmpbuf */ -# else -# define SOAP_MAXDIMS (4) -# endif -#endif - -#ifndef SOAP_MAXLOGS -# define SOAP_MAXLOGS (3) /* max number of debug logs per struct soap environment */ -# define SOAP_INDEX_RECV (0) -# define SOAP_INDEX_SENT (1) -# define SOAP_INDEX_TEST (2) -#endif - -#ifndef SOAP_MAXKEEPALIVE -# define SOAP_MAXKEEPALIVE (100) /* max iterations to keep server connection alive */ -#endif - -#ifndef SOAP_MAXARRAYSIZE -# define SOAP_MAXARRAYSIZE (100000) /* "trusted" max size of inbound SOAP array for compound array allocation */ -#endif - -#ifdef VXWORKS -# ifdef __INCmathh -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) isNan(num) -# endif -#endif - -#ifdef WIN32 -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) _isnan(num) -#endif - -#ifdef SUN_OS -# define soap_isnan(n) isnan(n) -#endif - -#if !defined(HAVE_ISNAN) && (defined(_MATH_H) || defined(_MATH_INCLUDED)) -# define HAVE_ISNAN -#endif - -#ifndef soap_isnan -# ifdef HAVE_ISNAN -# define soap_isnan(n) isnan(n) -# else -# define soap_isnan(_) (0) -# endif -#endif - -extern const struct soap_double_nan { unsigned int n1, n2; } soap_double_nan; - -#ifdef VXWORKS -# ifndef FLT_MAX -# define FLT_MAX _ARCH_FLT_MAX -# endif -# ifndef DBL_MAX -# define DBL_MAX _ARCH_DBL_MAX -# endif -#endif - -#ifndef FLT_NAN -# ifdef HAVE_ISNAN -# define FLT_NAN (*(float*)&soap_double_nan) -# else -# define FLT_NAN (0.0) -# endif -#endif - -#ifndef FLT_PINFTY -# ifdef FLT_MAX -# define FLT_PINFTY FLT_MAX -# else -# ifdef HUGE_VAL -# define FLT_PINFTY (float)HUGE_VAL -# else -# ifdef FLOAT_MAX -# define FLT_PINFTY FLOAT_MAX -# else -# define FLT_PINFTY (3.40282347e+38F) -# endif -# endif -# endif -#endif - -#ifndef FLT_NINFTY -# define FLT_NINFTY (-FLT_PINFTY) -#endif - -#ifndef DBL_NAN -# ifdef HAVE_ISNAN -# define DBL_NAN (*(double*)&soap_double_nan) -# else -# define DBL_NAN (0.0) -# endif -#endif - -#ifndef DBL_PINFTY -# ifdef DBL_MAX -# define DBL_PINFTY DBL_MAX -# else -# ifdef HUGE_VAL -# define DBL_PINFTY (double)HUGE_VAL -# else -# ifdef DOUBLE_MAX -# define DBL_PINFTY DOUBLE_MAX -# else -# define DBL_PINFTY (1.7976931348623157e+308) -# endif -# endif -# endif -#endif - -#ifndef DBL_NINFTY -# define DBL_NINFTY (-DBL_PINFTY) -#endif - -#define soap_ispinfd(n) ((n) >= DBL_PINFTY) -#define soap_ispinff(n) ((n) >= FLT_PINFTY) -#define soap_isninfd(n) ((n) <= DBL_NINFTY) -#define soap_isninff(n) ((n) <= FLT_NINFTY) - -/* gSOAP error codes */ - -#define SOAP_EOF EOF -#define SOAP_ERR EOF -#define SOAP_OK 0 -#define SOAP_CLI_FAULT 1 -#define SOAP_SVR_FAULT 2 -#define SOAP_TAG_MISMATCH 3 -#define SOAP_TYPE 4 -#define SOAP_SYNTAX_ERROR 5 -#define SOAP_NO_TAG 6 -#define SOAP_IOB 7 -#define SOAP_MUSTUNDERSTAND 8 -#define SOAP_NAMESPACE 9 -/* #define SOAP_OBJ_MISMATCH 10 obsolete */ -#define SOAP_FATAL_ERROR 11 -#define SOAP_FAULT 12 -#define SOAP_NO_METHOD 13 -#define SOAP_GET_METHOD 14 -#define SOAP_EOM 15 -#define SOAP_NULL 16 -#define SOAP_MULTI_ID 17 -#define SOAP_MISSING_ID 18 -#define SOAP_HREF 19 -#define SOAP_TCP_ERROR 20 -#define SOAP_HTTP_ERROR 21 -#define SOAP_SSL_ERROR 22 -#define SOAP_ZLIB_ERROR 23 -#define SOAP_DIME_ERROR 24 -#define SOAP_DIME_HREF 25 -#define SOAP_DIME_MISMATCH 26 -#define SOAP_DIME_END 27 -#define SOAP_MIME_ERROR 28 -#define SOAP_VERSIONMISMATCH 29 -#define SOAP_PLUGIN_ERROR 30 -#define SOAP_DATAENCODINGUNKNOWN 31 -#define SOAP_REQUIRED 32 -#define SOAP_PROHIBITED 33 -#define SOAP_OCCURS 34 -#define SOAP_LENGTH 35 - -#define soap_xml_error_check(e) ((e) == SOAP_TAG_MISMATCH || (e) == SOAP_TAG_END || (e) == SOAP_SYNTAX_ERROR || (e) == SOAP_NAMESPACE || (e) == SOAP_MULTI_ID || (e) == SOAP_MISSING_ID || (e) == SOAP_REQUIRED || (e) == SOAP_PROHIBITED || (e) == SOAP_OCCURS || (e) == SOAP_LENGTH || (e) == SOAP_NULL || (e) == SOAP_HREF) -#define soap_soap_error_check(e) ((e) == SOAP_CLI_FAULT || (e) == SOAP_SVR_FAULT || (e) == SOAP_VERSIONMISMATCH || (e) == SOAP_MUSTUNDERSTAND || (e) == SOAP_FAULT || (e) == SOAP_NO_METHOD) -#define soap_tcp_error_check(e) ((e) == SOAP_EOF || (e) == SOAP_TCP_ERROR) -#define soap_ssl_error_check(e) ((e) == SOAP_SSL_ERROR) -#define soap_zlib_error_check(e) ((e) == SOAP_ZLIB_ERROR) -#define soap_mime_error_check(e) ((e) == SOAP_MIME_ERROR) -#define soap_dime_error_check(e) ((e) == SOAP_DIME_ERROR || (e) == SOAP_DIME_MISMATCH) -#define soap_http_error_check(e) ((e) == SOAP_HTTP_ERROR || (e) == SOAP_GET_METHOD || ((e) >= 100 && (e) < 600)) - -/* gSOAP HTTP response status codes 100 to 600 are reserved */ - -/* Special gSOAP HTTP response status codes */ - -#define SOAP_STOP 1000 /* No HTTP response */ -#define SOAP_HTML 1001 /* Custom HTML response */ -#define SOAP_FILE 1002 /* Custom file-based response */ - -/* gSOAP HTTP request status codes */ - -#define SOAP_POST 1003 -#define SOAP_GET 1104 - -/* gSOAP DIME */ - -#define SOAP_DIME_CF 0x01 -#define SOAP_DIME_ME 0x02 -#define SOAP_DIME_MB 0x04 -#define SOAP_DIME_VERSION 0x08 /* DIME version 1 */ -#define SOAP_DIME_MEDIA 0x10 -#define SOAP_DIME_ABSURI 0x20 - -/* gSOAP ZLIB */ - -#define SOAP_ZLIB_NONE 0x00 -#define SOAP_ZLIB_DEFLATE 0x01 -#define SOAP_ZLIB_INFLATE 0x02 -#define SOAP_ZLIB_GZIP 0x02 - -/* gSOAP transport, connection, and content encoding modes */ - -typedef soap_int32 soap_mode; - -#define SOAP_IO 0x00000003 /* IO mask */ -#define SOAP_IO_FLUSH 0x00000000 /* flush output immediately, no buffering */ -#define SOAP_IO_BUFFER 0x00000001 /* buffer output in packets of size SOAP_BUFLEN */ -#define SOAP_IO_STORE 0x00000002 /* store entire output to determine length for transport */ -#define SOAP_IO_CHUNK 0x00000003 /* use HTTP chunked transfer AND buffer packets */ - -#define SOAP_IO_LENGTH 0x00000004 -#define SOAP_IO_KEEPALIVE 0x00000008 - -#define SOAP_ENC_LATIN 0x00800010 /* iso-8859-1 encoding */ -#define SOAP_ENC_XML 0x00000020 /* plain XML encoding, no HTTP header */ -#define SOAP_ENC_DIME 0x00000040 -#define SOAP_ENC_MIME 0x00000080 -#define SOAP_ENC_ZLIB 0x00000100 -#define SOAP_ENC_SSL 0x00000200 - -#define SOAP_ENC 0x00000FFF /* IO and ENC mask */ - -#define SOAP_XML_STRICT 0x00001000 /* strict validation */ -#define SOAP_XML_CANONICAL 0x00002000 /* C14N canonical XML */ -#define SOAP_XML_TREE 0x00004000 -#define SOAP_XML_GRAPH 0x00008000 -#define SOAP_XML_NIL 0x00010000 -#define SOAP_XML_DOM 0x00020000 -#define SOAP_XML_SEC 0x00040000 /* reserved for WS security */ - -#define SOAP_C_NOIOB 0x00100000 -#define SOAP_C_UTFSTRING 0x00200000 -#define SOAP_C_MBSTRING 0x00400000 - -#define SOAP_DOM_TREE 0x01000000 -#define SOAP_DOM_NODE 0x02000000 - -#define SOAP_IO_DEFAULT SOAP_IO_FLUSH - -/* SSL client/server authentication settings */ - -#define SOAP_SSL_NO_AUTHENTICATION 0x00 /* for testing purposes */ -#define SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION 0x01 /* client requires server to authenticate */ -#define SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION 0x02 /* server requires client to authenticate */ - -#define SOAP_SSL_DEFAULT SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION - -/* */ - -#define SOAP_BEGIN 0 -#define SOAP_IN_ENVELOPE 2 -#define SOAP_IN_HEADER 3 -#define SOAP_END_HEADER 4 -#define SOAP_IN_BODY 5 -#define SOAP_END_BODY 6 -#define SOAP_END_ENVELOPE 7 -#define SOAP_END 8 - -/* DEBUG macros */ - -#ifndef WITH_LEAN -# ifdef DEBUG -# ifndef SOAP_DEBUG -# define SOAP_DEBUG -# endif -# endif -#endif - -#ifdef SOAP_DEBUG -# ifndef SOAP_MESSAGE -# define SOAP_MESSAGE fprintf -# endif -# ifndef DBGLOG -# define DBGLOG(DBGFILE, CMD) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ - CMD;\ - fflush(fdebug);\ - }\ - }\ -} -# endif -# ifndef DBGMSG -# define DBGMSG(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { fwrite((MSG), 1, (LEN), soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -#else -# define DBGLOG(DBGFILE, CMD) -# define DBGMSG(DBGFILE, MSG, LEN) -#endif - -/* UCS-4 requires 32 bits (0-7FFFFFFF, the sign bit is used by gSOAP to distinguish XML entities) */ -typedef soap_int32 soap_wchar; - -struct Namespace -{ const char *id; - const char *ns; - const char *in; - char *out; -}; - -struct soap_nlist -{ struct soap_nlist *next; - unsigned int level; - short index; /* corresponding entry in ns mapping table */ - char *ns; /* only set when parsed ns URI is not in the ns mapping table */ - char id[1]; /* the actual string value flows into the allocated region below this struct */ -}; - -struct soap_blist -{ struct soap_blist *next; - char *ptr; - size_t size; -}; - -struct soap_array -{ void *__ptr; - int __size; -}; - -/* pointer serialization management */ -struct soap_plist -{ struct soap_plist *next; - const void *ptr; - const struct soap_array *array; - int type; - int id; - char mark1; - char mark2; -}; - -/* class allocation list */ -struct soap_clist -{ struct soap_clist *next; - void *ptr; - int type; - int size; - void (*fdelete)(struct soap_clist*); -}; - -struct soap_attribute -{ struct soap_attribute *next; - char *value; - size_t size; - char *ns; - short visible; - char name[1]; /* the actual name string flows into the allocated region below this struct */ -}; - -struct soap_cookie -{ struct soap_cookie *next; - char *name; - char *value; - char *domain; - char *path; - long expire; /* client-side: local time to expire; server-side: seconds to expire */ - unsigned int version; - short secure; - short session; /* server-side */ - short env; /* server-side: got cookie from client */ - short modified; /* server-side: client cookie was modified */ -}; - -#ifdef __cplusplus -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); - -class soap_multipart_iterator -{ public: - struct soap_multipart *content; - bool operator==(const soap_multipart_iterator& iter) const - { return content == iter.content; } - bool operator!=(const soap_multipart_iterator& iter) const - { return content != iter.content; } - struct soap_multipart &operator*() const - { return *content; } - soap_multipart_iterator &operator++() - { content = soap_next_multipart(content); return *this; } - soap_multipart_iterator() : content(NULL) - { } - soap_multipart_iterator(struct soap_multipart *p) : content(p) - { } -}; -#endif - -#ifndef WITH_LEANER -struct soap_dime -{ size_t count; - size_t size; - size_t chunksize; - size_t buflen; - char flags; - char *ptr; - const char *id; - const char *type; - const char *options; - struct soap_multipart *list; /* list of DIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -struct soap_mime -{ char *boundary; /* MIME boundary */ - const char *start; /* MIME start ID */ - struct soap_multipart *list; /* list of DIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* RFC2045 MIME content transfer encodings */ -enum soap_mime_encoding -{ SOAP_MIME_NONE, - SOAP_MIME_7BIT, - SOAP_MIME_8BIT, - SOAP_MIME_BINARY, - SOAP_MIME_QUOTED_PRINTABLE, - SOAP_MIME_BASE64, - SOAP_MIME_IETF_TOKEN, - SOAP_MIME_X_TOKEN -}; -#endif - -#ifndef WITH_LEANER -/* DIME/MIME multipart list */ -struct soap_multipart -{ struct soap_multipart *next; - char *ptr; /* points to raw data content */ - size_t size; /* size of data content */ - const char *id; /* DIME/MIME content ID */ - const char *type; /* DIME/MIME type (MIME type format) */ - const char *options; /* DIME options */ - enum soap_mime_encoding encoding; /* MIME Content-Transfer-Encoding */ - const char *location; /* MIME Content-Location (optional) */ - const char *description; /* MIME Content-Description (optional) */ -#ifdef __cplusplus - typedef soap_multipart_iterator iterator; -#endif -}; -#endif - -#ifndef WITH_LEANER -struct soap_dom_attribute -{ struct soap_dom_attribute *next; - const char *nstr; - char *name; - char *data; - wchar_t *wide; - struct soap *soap; -#ifdef __cplusplus - struct soap_dom_attribute &set(const char *nstr, const char *name); /* set namespace and name */ - struct soap_dom_attribute &set(const char *data); /* set data */ - void unlink(); - soap_dom_attribute(); - soap_dom_attribute(struct soap *soap); - soap_dom_attribute(struct soap *soap, const char *nstr, const char *name, const char *data); - ~soap_dom_attribute(); -#endif -}; -#endif - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_iterator -{ public: - struct soap_dom_element *elt; - const char *nstr; - const char *name; - int type; - bool operator==(const soap_dom_iterator&) const; - bool operator!=(const soap_dom_iterator&) const; - struct soap_dom_element &operator*() const; - soap_dom_iterator &operator++(); - soap_dom_iterator(); - soap_dom_iterator(struct soap_dom_element*); - ~soap_dom_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_element -{ struct soap_dom_element *next; /* next sibling */ - struct soap_dom_element *prnt; /* parent */ - struct soap_dom_element *elts; /* first child element */ - struct soap_dom_attribute *atts; /* first child attribute */ - const char *nstr; /* namespace string */ - char *name; /* element tag name */ - char *data; /* element content data (with SOAP_C_UTFSTRING flag set) */ - wchar_t *wide; /* element content data */ - int type; /* optional: serialized C/C++ data type */ - void *node; /* optional: pointer to serialized C/C++ data */ - struct soap *soap; -#ifdef __cplusplus - typedef soap_dom_iterator iterator; - struct soap_dom_element &set(const char *nstr, const char *name); - struct soap_dom_element &set(const char *data); - struct soap_dom_element &set(void *node, int type); - struct soap_dom_element &add(struct soap_dom_element*); - struct soap_dom_element &add(struct soap_dom_element&); - struct soap_dom_element &add(struct soap_dom_attribute*); - struct soap_dom_element &add(struct soap_dom_attribute&); - soap_dom_iterator begin(); - soap_dom_iterator end(); - soap_dom_iterator find(const char *nstr, const char *name); - soap_dom_iterator find(int type); - void unlink(); - soap_dom_element(); - soap_dom_element(struct soap *soap); - soap_dom_element(struct soap *soap, const char *nstr, const char *name); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type); - ~soap_dom_element(); -#endif -}; -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -} -extern ostream &operator<<(ostream&, const struct soap_dom_element&); -extern istream &operator>>(istream&, struct soap_dom_element&); -extern "C" { -#endif - -struct soap -{ short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table) */ - short copy; /* 1 = copy of another soap struct */ - soap_mode mode; - soap_mode imode; - soap_mode omode; - const char *float_format; /* points to user-definable format string for floats (<1024 chars) */ - const char *double_format; /* points to user-definable format string for doubles (<1024 chars) */ - const char *dime_id_format; /* points to user-definable format string for integer DIME id ( 0, gives socket recv timeout in seconds, < 0 in usec */ - int send_timeout; /* when > 0, gives socket send timeout in seconds, < 0 in usec */ - int connect_timeout; /* when > 0, gives socket connect() timeout in seconds, < 0 in usec */ - int accept_timeout; /* when > 0, gives socket accept() timeout in seconds, < 0 in usec */ - int socket_flags; /* socket recv() and send() flags, e.g. set to MSG_NOSIGNAL to disable sigpipe */ - int connect_flags; /* connect() SOL_SOCKET sockopt flags, e.g. set to SO_DEBUG to debug socket */ - int bind_flags; /* bind() SOL_SOCKET sockopt flags, e.g. set to SO_REUSEADDR to enable reuse */ - int accept_flags; /* accept() SOL_SOCKET sockopt flags */ - const struct Namespace *namespaces; /* Pointer to global namespace mapping table */ - struct Namespace *local_namespaces; /* Local namespace mapping table */ - struct soap_nlist *nlist; /* namespace stack */ - struct soap_blist *blist; /* block allocation stack */ - struct soap_clist *clist; /* class instance allocation list */ - void *alist; /* memory allocation list */ - struct soap_ilist *iht[SOAP_IDHASH]; - struct soap_plist *pht[SOAP_PTRHASH]; - struct SOAP_ENV__Header *header; - struct SOAP_ENV__Fault *fault; - void *user; /* to pass user-defined data */ - struct soap_plugin *plugins; /* linked list of plug-in data */ - char *userid; /* HTTP Basic authorization userid */ - char *passwd; /* HTTP Basic authorization passwd */ - int (*fpost)(struct soap*, const char*, const char*, int, const char*, const char*, size_t); - int (*fget)(struct soap*); - int (*fposthdr)(struct soap*, const char*, const char*); - int (*fresponse)(struct soap*, int, size_t); - int (*fparse)(struct soap*); - int (*fparsehdr)(struct soap*, const char*, const char*); - int (*fresolve)(struct soap*, const char*, struct in_addr* inaddr); - int (*fconnect)(struct soap*, const char*, const char*, int); - int (*fdisconnect)(struct soap*); - int (*fclosesocket)(struct soap*, SOAP_SOCKET); - int (*fshutdownsocket)(struct soap*, SOAP_SOCKET, int); - int (*fopen)(struct soap*, const char*, const char*, int); - int (*faccept)(struct soap*, int, struct sockaddr*, int *n); - int (*fclose)(struct soap*); - int (*fsend)(struct soap*, const char*, size_t); - size_t (*frecv)(struct soap*, char*, size_t); - int (*fpoll)(struct soap*); - int (*fignore)(struct soap*, const char*); - int (*fserveloop)(struct soap*); - void *(*fplugin)(struct soap*, const char*); -#ifndef WITH_LEANER - int (*fprepareinit)(struct soap*); - int (*fpreparesend)(struct soap*, const char*, size_t); - int (*fpreparerecv)(struct soap*, const char*, size_t); - void *(*fdimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fdimewriteopen)(struct soap*, const char*, const char*, const char*); - void (*fdimereadclose)(struct soap*, void*); - void (*fdimewriteclose)(struct soap*, void*); - size_t (*fdimeread)(struct soap*, void*, char*, size_t); - int (*fdimewrite)(struct soap*, void*, const char*, size_t); -#endif - int master; - int socket; -#if defined(__cplusplus) && !defined(WITH_LEAN) - ostream *os; - istream *is; -#else - void *os; /* preserve alignment */ - void *is; /* preserve alignment */ -#endif -#ifndef UNDER_CE - int sendfd; - int recvfd; -#else - FILE *sendfd; - FILE *recvfd; -#endif -#ifdef WIN32 - char errorstr[256]; /* buf for FormatMessage() */ -#endif - size_t bufidx; /* index in soap.buf[] */ - size_t buflen; /* length of soap.buf[] content */ - soap_wchar ahead; /* parser lookahead */ - short cdata; /* CDATA parser state */ - short body; - unsigned int level; /* XML nesting level */ - size_t count; /* message length counter */ - size_t length; /* message length as set by HTTP header */ -#ifdef WITH_FAST - char *labbuf; /* look-aside buffer */ - size_t lablen; /* look-aside buffer allocated length */ - size_t labidx; /* look-aside buffer index to available part */ -#endif - char buf[SOAP_BUFLEN];/* send and receive buffer */ - char tmpbuf[1024]; /* in/output buffer for HTTP headers, simpleType values, attribute names, and DIME >=1024 bytes */ - char msgbuf[1024]; /* output buffer for (error) messages <=1024 bytes */ - char tag[SOAP_TAGLEN]; - char id[SOAP_TAGLEN]; - char href[SOAP_TAGLEN]; - char type[SOAP_TAGLEN]; - char arrayType[SOAP_TAGLEN]; - char arraySize[SOAP_TAGLEN]; - char arrayOffset[SOAP_TAGLEN]; - short other; - short root; - short position; - int positions[SOAP_MAXDIMS]; - struct soap_attribute *attributes; /* attribute list */ - short encoding; - short mustUnderstand; - short null; - short ns; - short part; - short alloced; - short peeked; - short keep_alive; - size_t chunksize; - size_t chunkbuflen; - char endpoint[SOAP_TAGLEN]; - char path[SOAP_TAGLEN]; - char host[SOAP_TAGLEN]; - char *action; - char *authrealm; /* HTTP authentication realm */ - char *prolog; /* XML declaration prolog */ - int port; - unsigned int max_keep_alive; - const char *proxy_host; /* Proxy Server host name */ - int proxy_port; /* Proxy Server port (default = 8080) */ - const char *proxy_userid; /* Proxy Authorization user name */ - const char *proxy_passwd; /* Proxy Authorization password */ - int status; /* -1 when request, else error code to be returned by server */ - int error; - int errmode; - int errnum; - unsigned long idnum; - unsigned long ip; -#ifndef WITH_LEANER - struct soap_dom_element *dom; - struct soap_dime dime; - struct soap_mime mime; -#endif -#if !defined(WITH_LEAN) || defined(SOAP_DEBUG) - const char *logfile[SOAP_MAXLOGS]; - FILE *fdebug[SOAP_MAXLOGS]; -#endif -#ifndef WITH_LEAN - struct soap_cookie *cookies; - const char *cookie_domain; - const char *cookie_path; - int cookie_max; -#endif -#ifdef WITH_OPENSSL - int (*fsslauth)(struct soap*); - int (*fsslverify)(int, X509_STORE_CTX*); - BIO *bio; - SSL *ssl; - SSL_CTX *ctx; - short require_server_auth; - short require_client_auth; - short rsa; /* when set, use RSA instead of DH */ - const char *keyfile; - const char *password; - const char *dhfile; - const char *cafile; - const char *capath; - const char *randfile; - SSL_SESSION *session; - char session_host[SOAP_TAGLEN]; - int session_port; -#endif -#ifdef WITH_ZLIB - short zlib_state; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_INFLATE */ - short zlib_in; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - short zlib_out; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - z_stream d_stream; /* decompression stream */ - char z_buf[SOAP_BUFLEN]; /* buffer */ - size_t z_buflen; - unsigned short z_level; /* compression level to be used (0=none, 1=fast to 9=best) */ - uLong z_crc; /* internal gzip crc */ - float z_ratio_in; /* detected compression ratio compressed_length/length of inbound message */ - float z_ratio_out; /* detected compression ratio compressed_length/length of outbound message */ -#endif -/* WR[ */ -#ifdef WMW_RPM_IO - void *rpmreqid; -#endif /* WMW_RPM_IO */ -/* ]WR */ -}; - -struct soap_code_map -{ long code; - const char *string; -}; - -/* forwarding list */ -struct soap_flist -{ struct soap_flist *next; - int type; - void *ptr; - unsigned int level; - void (*fcopy)(struct soap*, int, int, void*, const void*, size_t); -}; - -/* id-ref forwarding list */ -struct soap_ilist -{ struct soap_ilist *next; - int type; - size_t size; - void *link; - void *copy; - struct soap_flist *flist; - void *ptr; - unsigned int level; - char id[1]; /* the actual id string value flows into the allocated region below this struct */ -}; - -struct soap_plugin -{ struct soap_plugin *next; - const char *id; - void *data; - int (*fcopy)(struct soap *soap, struct soap_plugin *dst, struct soap_plugin *src); - void (*fdelete)(struct soap *soap, struct soap_plugin *p); /* should delete fields of plugin only and not free(p) */ -}; - -#ifndef WITH_NONAMESPACES -extern SOAP_NMAC struct Namespace namespaces[]; -#endif - -#ifndef WITH_LEAN -# define soap_get0(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx]) -# define soap_get1(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx++]) -#else -soap_wchar soap_get0(struct soap*); -soap_wchar soap_get1(struct soap*); -#endif - -#define soap_revget1(soap) ((soap)->bufidx--) -#define soap_unget(soap, c) ((soap)->ahead = c) -#define soap_register_plugin(soap, plugin) soap_register_plugin_arg(soap, plugin, NULL) -#define soap_imode(soap, n) ((soap)->mode = (soap)->imode = (n)) -#define soap_set_imode(soap, n) ((soap)->mode = (soap)->imode |= (n)) -#define soap_clr_imode(soap, n) ((soap)->mode = (soap)->imode &= ~(n)) -#define soap_omode(soap, n) ((soap)->mode = (soap)->omode = (n)) -#define soap_set_omode(soap, n) ((soap)->mode = (soap)->omode |= (n)) -#define soap_clr_omode(soap, n) ((soap)->mode = (soap)->omode &= ~(n)) -#define soap_destroy(soap) soap_delete((soap), NULL) - -#ifdef HAVE_STRRCHR -# define soap_strrchr(s, t) strrchr(s, t) -#else - SOAP_FMAC1 char* SOAP_FMAC2 soap_strrchr(const char *s, int t); -#endif - -#ifdef HAVE_STRTOL -# define soap_strtol(s, t, b) strtol(s, t, b) -#else - SOAP_FMAC1 long SOAP_FMAC2 soap_strtol(const char *s, char **t, int b); -#endif - -#ifdef HAVE_STRTOUL -# define soap_strtoul(s, t, b) strtoul(s, t, b) -#else - SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b); -#endif - -#ifdef WITH_NOIDREF -# define soap_embedded(s, p, t) (0) -# define soap_id_lookup(s, i, p, t, n, k) (p) -# define soap_id_forward(s, h, p, st, tt, n, k, fc) (p) -# define soap_reference(s, a, t) (1) -# define soap_array_reference(s, p, a, n, t) (1) -# define soap_embed(s, p, a, n, t, pp) (0) -# define soap_embedded_id(s, i, p, t) (i) -# define soap_is_embedded(s, p) (0) -# define soap_is_single(s, p) (1) -# define soap_lookup_type(s, i) (0) -# define soap_getindependent(s) (0) -# define soap_putindependent(s) (0) -# define soap_getelement(s, n) (0) -# define soap_putelement(s, p, t, i, n) (0) -# define soap_markelement(s, p, n) (0) -#endif - -SOAP_FMAC1 void SOAP_FMAC2 soap_fault(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultstring(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultdetail(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializefault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getfault(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_poll(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect_command(struct soap*, int, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_bind(struct soap*, const char*, int, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_accept(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_accept(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_puthttphdr(struct soap*, int status, size_t count); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_get_header_attribute(struct soap*, const char*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_key(char*, size_t, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_val(char*, size_t, const char*); - -SOAP_FMAC1 size_t SOAP_FMAC2 soap_hash(const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_endpoint(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_get(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getchar(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_tag_cmp(const char*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_sender_error(struct soap*, const char*, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_receiver_error(struct soap*, const char*, const char*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_raw(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send2(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send3(struct soap*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pututf8(struct soap*, unsigned long); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getutf8(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_putbase64(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_getbase64(struct soap*, int*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_puthex(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_gethex(struct soap*, int*); - - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup_id(struct soap*, void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup(struct soap*, const void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_enter(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_pointer_lookup(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -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); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_lookup(struct soap*, const char*); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_enter(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_resolve(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_embedded(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_reference(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_reference(struct soap*, const void *p, const struct soap_array *a, int n, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_embedded_id(struct soap*, int id, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_embedded(struct soap*, struct soap_plist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_single(struct soap*, struct soap_plist*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_embedded(struct soap*, struct soap_plist*); -#endif - -SOAP_FMAC1 void SOAP_FMAC2 soap_begin_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_send(struct soap*); - -SOAP_FMAC1 const struct soap_code_map* SOAP_FMAC2 soap_code(const struct soap_code_map*, const char *str); -SOAP_FMAC1 long SOAP_FMAC2 soap_int_code(const struct soap_code_map*, const char *str, long other); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_str_code(const struct soap_code_map*, long code); - -SOAP_FMAC1 int SOAP_FMAC2 soap_getline(struct soap*, char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_recv(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_malloc(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_dealloc(struct soap*, void*); -SOAP_FMAC1 struct soap_clist * SOAP_FMAC2 soap_link(struct soap*, void*, int, int, void (*fdelete)(struct soap_clist*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_unlink(struct soap*, const void*); -SOAP_FMAC1 void SOAP_FMAC2 soap_free(struct soap*); - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_lookup_type(struct soap*, const char *id); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_lookup(struct soap*, const char *id, void **p, int t, size_t n, unsigned int k); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_forward(struct soap*, const char *id, void *p, int st, int tt, size_t n, unsigned int k, void(*fcopy)(struct soap*, int, int, void*, const void*, size_t)); -#endif -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_enter(struct 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*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_fcopy(struct soap *soap, int st, int tt, void *p, const void *q, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_size(const int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getoffsets(const char *, const int *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsize(const char *, const char *, int *); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsizes(const char *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getposition(const char *, int *); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsize(struct soap*, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizesoffsets(struct soap*, const char *, const int *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizes(struct soap*, const char *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffset(struct soap*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffsets(struct soap*, const int *, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_closesock(struct soap*); - -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new(void); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new1(soap_mode); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new2(soap_mode, soap_mode); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*,struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init1(struct soap*, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_init2(struct soap*, soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_end(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_delete(struct soap*, void*); - -#ifdef SOAP_DEBUG -SOAP_FMAC1 void SOAP_FMAC2 soap_set_recv_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_sent_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_test_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_close_logfiles(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_open_logfile(struct soap*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_value(struct soap*); - -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_advance(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_skip(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_tag(struct soap*, const char*, const char *); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_array(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element(struct soap*, const char*, int, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_out(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_begin_out(struct soap*, const char *tag, int id, const char *type, const char *offset); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_ref(struct soap*, const char *tag, int id, int href); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_href(struct soap*, const char *tag, int id, const char *ref, const char *val); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_null(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_id(struct soap*, const char *tag, int id, const void *p, const struct soap_array *a, int d, const char *type, int n); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_result(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_out(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_start_end_out(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_attribute(struct soap*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_in(struct soap*, const char *tag, int nillable); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_in(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_peek_element(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_retry(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_revert(struct soap*); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_strdup(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_string_out(struct soap*, const char *s, int flag); -SOAP_FMAC1 char* SOAP_FMAC2 soap_string_in(struct soap*, int, long, long); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_wstring_out(struct soap*, const wchar_t *s, int flag); -SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstring_in(struct soap*, int, long, long); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_namespace(struct soap*, const char *, const char*, int n1, int n2); - -SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap*, struct Namespace*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_namespace(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_push_namespace(struct soap*, const char *,const char *); - -SOAP_FMAC1 int SOAP_FMAC2 soap_new_block(struct soap*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_push_block(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_size_block(struct soap*, size_t); -SOAP_FMAC1 char* SOAP_FMAC2 soap_first_block(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_next_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_block_size(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_save_block(struct soap*, char*, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*); -SOAP_FMAC1 int soap_envelope_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_out(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_header(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_response(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_empty_response(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_empty_response(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_fault(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap*, FILE*); -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault_location(struct soap*, FILE*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_s2byte(struct soap*, const char*, char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2short(struct soap*, const char*, short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2int(struct soap*, const char*, int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2long(struct soap*, const char*, long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2LONG64(struct soap*, const char*, LONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2float(struct soap*, const char*, float*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2double(struct soap*, const char*, double*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedByte(struct soap*, const char*, unsigned char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedShort(struct soap*, const char*, unsigned short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedInt(struct soap*, const char*, unsigned int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedLong(struct soap*, const char*, unsigned long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2ULONG64(struct soap*, const char*, ULONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2string(struct soap*, const char*, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2QName(struct soap*, const char*, char**); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_s2dateTime(struct soap*, const char*, time_t*); -#endif - -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2base64(struct soap*, const unsigned char*, char*, size_t); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_byte2s(struct soap*, char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_short2s(struct soap*, short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_int2s(struct soap*, int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_long2s(struct soap*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_LONG642s(struct soap*, LONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_float2s(struct soap*, float); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_double2s(struct soap*, double); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedByte2s(struct soap*, unsigned char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedShort2s(struct soap*, unsigned short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedInt2s(struct soap*, unsigned int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedLong2s(struct soap*, unsigned long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_ULONG642s(struct soap*, ULONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_QName2s(struct soap*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_base642s(struct soap*, const char*, char*, size_t, size_t*); - -#ifndef WITH_LEAN -SOAP_FMAC1 const char* SOAP_FMAC2 soap_dateTime2s(struct soap*, time_t); -#endif - - -SOAP_FMAC1 int* SOAP_FMAC2 soap_inint(struct soap*, const char *tag, int *p, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_inbyte(struct soap*, const char *tag, char *p, const char *, int); -SOAP_FMAC1 long* SOAP_FMAC2 soap_inlong(struct soap*, const char *tag, long *p, const char *, int); -SOAP_FMAC1 LONG64* SOAP_FMAC2 soap_inLONG64(struct soap*, const char *tag, LONG64 *p, const char *, int); -SOAP_FMAC1 short* SOAP_FMAC2 soap_inshort(struct soap*, const char *tag, short *p, const char *, int); -SOAP_FMAC1 float* SOAP_FMAC2 soap_infloat(struct soap*, const char *tag, float *p, const char *, int); -SOAP_FMAC1 double* SOAP_FMAC2 soap_indouble(struct soap*, const char *tag, double *p, const char *, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_inunsignedByte(struct soap*, const char *tag, unsigned char *p, const char *, int); -SOAP_FMAC1 unsigned short* SOAP_FMAC2 soap_inunsignedShort(struct soap*, const char *tag, unsigned short *p, const char *, int); -SOAP_FMAC1 unsigned int* SOAP_FMAC2 soap_inunsignedInt(struct soap*, const char *tag, unsigned int *p, const char *, int); -SOAP_FMAC1 unsigned long* SOAP_FMAC2 soap_inunsignedLong(struct soap*, const char *tag, unsigned long *p, const char *, int); -SOAP_FMAC1 ULONG64* SOAP_FMAC2 soap_inULONG64(struct soap*, const char *tag, ULONG64 *p, const char *, int); -SOAP_FMAC1 char** SOAP_FMAC2 soap_instring(struct soap*, const char *tag, char **p, const char *, int, int, long, long); -SOAP_FMAC1 char** SOAP_FMAC2 soap_inliteral(struct soap*, const char *tag, char **p); - -#ifndef WITH_LEAN -SOAP_FMAC1 time_t* SOAP_FMAC2 soap_indateTime(struct soap*, const char *tag, time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwstring(struct soap*, const char *tag, wchar_t **p, const char *, int, long, long); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwliteral(struct soap*, const char *tag, wchar_t **p); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_outbyte(struct soap*, const char *tag, int id, const char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outshort(struct soap*, const char *tag, int id, const short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outint(struct soap*, const char *tag, int id, const int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outlong(struct soap*, const char *tag, int id, const long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outLONG64(struct soap*, const char *tag, int id, const LONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outfloat(struct soap*, const char *tag, int id, const float *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdouble(struct soap*, const char *tag, int id, const double *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedByte(struct soap*, const char *tag, int id, const unsigned char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedShort(struct soap*, const char *tag, int id, const unsigned short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedInt(struct soap*, const char *tag, int id, const unsigned int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedLong(struct soap*, const char *tag, int id, const unsigned long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outULONG64(struct soap*, const char *tag, int id, const ULONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outstring(struct soap*, const char *tag, int id, char *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outliteral(struct soap*, const char *tag, char *const*p); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_outdateTime(struct soap*, const char *tag, int id, const time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_outwstring(struct soap*, const char *tag, int id, wchar_t *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwliteral(struct soap*, const char *tag, wchar_t *const*p); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_element_dime(struct soap *, const char*, int, const void*, const struct soap_array*, const char*, const char*, const char*, int, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, long); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_tell(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_dime_option(struct soap*, unsigned short, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmimehdr(struct soap*, struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_mime(struct soap*, const char *boundary, const char *start); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_mime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_dime_attachment(struct soap*, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_mime_attachment(struct soap*, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_register_plugin_arg(struct soap*, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_lookup_plugin(struct soap*, const char*); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_attr_value(struct soap *soap, const char *name, int flag); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_attr(struct soap *soap, const char *name, const char *value); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_attr(struct soap *soap); - -#ifdef WITH_COOKIES -SOAP_FMAC1 size_t SOAP_FMAC2 soap_encode_cookie(const char*, char*, size_t); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_set_cookie(struct soap*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern long SOAP_FMAC2 soap_cookie_expire(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_expire(struct soap*, const char*, long, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_clr_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_clr_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_getenv_cookies(struct soap*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_copy_cookies(struct soap*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_free_cookies(struct soap*); -#endif - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.c b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.c deleted file mode 100644 index ce46e28..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.c +++ /dev/null @@ -1,14890 +0,0 @@ -/* - stdsoap2.c[pp] 2.7.10 - - gSOAP runtime engine - -gSOAP XML Web services tools -Copyright (C) 2000-2008, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under ONE of the following licenses: -GPL, the gSOAP public license, OR Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems Inc., for the following additions under gSOAP public license: - - vxWorks compatible --------------------------------------------------------------------------------- -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-2008, 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 - -This program is released under the GPL with the additional exemption that -compiling, linking, and/or using OpenSSL is allowed. --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- - -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. - -*/ - -#ifdef AS400 -# pragma convert(819) /* EBCDIC to ASCII */ -#endif - -#include "stdsoap2.h" - -#ifdef __BORLANDC__ -# pragma warn -8060 -#else -# ifdef WIN32 -# ifdef UNDER_CE -# pragma comment(lib, "winsock.lib") -# else -# pragma comment(lib, "wsock32.lib") -# endif -# pragma warning(disable : 4996) // disable deprecation warnings -# endif -#endif - -#ifdef __cplusplus -SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.7.10 2008-01-27 00:00:00 GMT") -extern "C" { -#else -SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.7.10 2008-01-27 00:00:00 GMT") -#endif - -/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale with multibyte support enabled) */ -#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_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) - -#if defined(WIN32) && !defined(UNDER_CE) -#define soap_hash_ptr(p) ((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1)) -#else -#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1))) -#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 SOAP_MEM_DEBUG -static void soap_init_mht(struct soap*); -static void soap_free_mht(struct soap*); -static void soap_track_unlink(struct soap*, const void*); -#endif - -#ifndef PALM_2 -static int soap_set_error(struct soap*, const char*, const char*, const char*, const char*, int); -static int soap_copy_fault(struct soap*, const char*, const char*, const char*, const char*); -static int soap_getattrval(struct soap*, char*, size_t, soap_wchar); -#endif - -#ifndef PALM_1 -static soap_wchar soap_char(struct soap*); -static soap_wchar soap_get_pi(struct soap*); -static int soap_isxdigit(int); -static void *fplugin(struct soap*, const char*); -#ifndef WITH_NOIDREF -static void soap_update_ptrs(struct soap*, char*, char*, char*, char*); -static int soap_has_copies(struct soap*, const char*, 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*); -#endif -#endif - -#ifndef WITH_LEAN -static const char *soap_set_validation_fault(struct soap*, const char*, const char*); -static int soap_isnumeric(struct soap*, const char*); -static struct soap_nlist *soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized); -static void soap_pop_ns(struct soap *soap); -static void soap_utilize_ns(struct soap *soap, const char *tag, size_t n); -#endif - -#ifndef WITH_LEANER -#ifndef PALM_1 -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*); -static void soap_resolve_attachment(struct soap*, struct soap_multipart*); -#endif -#endif - -#ifdef WITH_GZIP -static int soap_getgziphdr(struct soap*); -#endif - -#ifdef WITH_OPENSSL -int soap_ssl_init_done = 0; - -static int ssl_auth_init(struct soap*); -static int ssl_verify_callback(int, X509_STORE_CTX*); -static int ssl_password(char*, int, int, void *); -/* The callback below is included for future references: -static DH *ssl_tmp_dh(SSL*, int, int); -*/ -#endif - -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#ifndef PALM_1 -static const char *soap_decode(char*, size_t, const char*, const char*); -#endif -#endif - -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static soap_wchar soap_getchunkchar(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_put(struct soap*); -static int http_del(struct soap*); -static int http_head(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*); -#endif -#endif - -#ifndef WITH_NOIO - -#ifndef PALM_1 -static int fsend(struct soap*, const char*, size_t); -static size_t frecv(struct soap*, char*, size_t); -static int tcp_init(struct soap*); -static const char *tcp_error(struct soap*); -#ifndef WITH_LEAN -static size_t frecv_stop(struct soap*, char*, size_t); -#endif -#ifndef WITH_IPV6 -static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr); -#endif -static SOAP_SOCKET tcp_connect(struct soap*, const char *endpoint, const char *host, int port); -static SOAP_SOCKET tcp_accept(struct soap*, SOAP_SOCKET, 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 const char *soap_strerror(struct soap*); -#endif - -#if defined(WIN32) - #define SOAP_SOCKBLOCK(fd) \ - { u_long blocking = 0; \ - ioctlsocket(fd, FIONBIO, &blocking); \ - } - #define SOAP_SOCKNONBLOCK(fd) \ - { u_long nonblocking = 1; \ - ioctlsocket(fd, FIONBIO, &nonblocking); \ - } -#elif defined(VXWORKS) - #define SOAP_SOCKBLOCK(fd) \ - { u_long blocking = 0; \ - ioctl(fd, FIONBIO, (int)(&blocking)); \ - } - #define SOAP_SOCKNONBLOCK(fd) \ - { u_long nonblocking = 1; \ - ioctl(fd, FIONBIO, (int)(&nonblocking)); \ - } -#elif defined(PALM) - #define SOAP_SOCKBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0)&~O_NONBLOCK); - #define SOAP_SOCKNONBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0)|O_NONBLOCK); -#elif defined(SYMBIAN) - #define SOAP_SOCKBLOCK(fd) \ - { long blocking = 0; \ - ioctl(fd, 0/*FIONBIO*/, &blocking); \ - } - #define SOAP_SOCKNONBLOCK(fd) \ - { long nonblocking = 1; \ - ioctl(fd, 0/*FIONBIO*/, &nonblocking); \ - } -#else - #define SOAP_SOCKBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)&~O_NONBLOCK); - #define SOAP_SOCKNONBLOCK(fd) fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK); -#endif - -#endif - -#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 - -#ifndef WITH_LEAN -static const char soap_indent[11] = "\n\t\t\t\t\t\t\t\t\t"; -/* Alternative indentation form for SOAP_XML_INDENT: -static const char soap_indent[21] = "\n "; -*/ -#endif - -#ifndef SOAP_CANARY -# define SOAP_CANARY (0xC0DE) -#endif - -static const char soap_padding[4] = "\0\0\0"; -#define SOAP_STR_PADDING (soap_padding) -#define SOAP_STR_EOS (soap_padding) -#define SOAP_NON_NULL (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_NOIO -#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 -#endif - -#ifndef WITH_NOHTTP -#ifndef WITH_LEAN -static const struct soap_code_map h_http_error_codes[] = -{ { 200, "OK" }, - { 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 -#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 WITH_NOIO -#ifndef PALM_1 -static int -fsend(struct soap *soap, const char *s, size_t n) -{ register int nwritten, err; -#if defined(__cplusplus) && !defined(WITH_LEAN) - if (soap->os) - { soap->os->write(s, (std::streamsize)n); - if (soap->os->good()) - return SOAP_OK; - soap->errnum = 0; - return SOAP_EOF; - } -#endif - while (n) - { if (soap_valid_socket(soap->socket)) - { -#ifndef WITH_LEAN - if (soap->send_timeout) - { -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - for (;;) - { struct timeval timeout; - fd_set fd; - register int r; - 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, &fd); -#ifdef WITH_OPENSSL - if (soap->ssl) - r = select((int)soap->socket + 1, &fd, &fd, &fd, &timeout); - else -#endif - r = select((int)soap->socket + 1, NULL, &fd, &fd, &timeout); - if (r > 0) - break; - if (!r) - { soap->errnum = 0; - return SOAP_EOF; - } - err = soap_socket_errno(soap->socket); - if (err != SOAP_EINTR && err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK) - { soap->errnum = err; - return SOAP_EOF; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - nwritten = SSL_write(soap->ssl, s, (int)n); - else if (soap->bio) - nwritten = BIO_write(soap->bio, s, (int)n); - else -#endif -#ifndef WITH_LEAN - if ((soap->omode & SOAP_IO_UDP)) - { if (soap->peerlen) - nwritten = sendto(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen); - else - nwritten = send(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags); - /* retry and back-off algorithm */ - /* TODO: this is not very clear from specs so verify and limit conditions under which we should loop (e.g. ENOBUFS) */ - if (nwritten < 0) - { struct timeval timeout; - fd_set fd; - int udp_repeat; - int udp_delay; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - if ((soap->connect_flags & SO_BROADCAST)) - udp_repeat = 3; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */ - else - udp_repeat = 1; /* SOAP-over-UDP UNICAST_UDP_REPEAT - 1 */ - udp_delay = (soap_random % 201) + 50; /* UDP_MIN_DELAY .. UDP_MAX_DELAY */ - do - { timeout.tv_sec = 0; - timeout.tv_usec = 1000 * udp_delay; /* ms */ - FD_ZERO(&fd); - FD_SET(soap->socket, &fd); - select((int)soap->socket + 1, NULL, NULL, &fd, &timeout); - if (soap->peerlen) - nwritten = sendto(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen); - else - nwritten = send(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags); - udp_delay <<= 1; - if (udp_delay > 500) /* UDP_UPPER_DELAY */ - udp_delay = 500; - } - while (nwritten < 0 && --udp_repeat > 0); - } - } - else -#endif -#if !defined(PALM) && !defined(AS400) - nwritten = send(soap->socket, s, (int)n, soap->socket_flags); -#else - nwritten = send(soap->socket, (void*)s, n, soap->socket_flags); -#endif - if (nwritten <= 0) - { -#if defined(WITH_OPENSSL) || !defined(WITH_LEAN) - register int r = 0; -#endif - err = soap_socket_errno(soap->socket); -#ifdef WITH_OPENSSL - if (soap->ssl && (r = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && r != SSL_ERROR_WANT_READ && r != SSL_ERROR_WANT_WRITE) - { soap->errnum = err; - return SOAP_EOF; - } -#endif - if (err == SOAP_EWOULDBLOCK || err == SOAP_EAGAIN) - { -#ifndef WITH_LEAN - struct timeval timeout; - fd_set fd; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - if (soap->send_timeout > 0) - { timeout.tv_sec = soap->send_timeout; - timeout.tv_usec = 0; - } - else if (soap->send_timeout < 0) - { timeout.tv_sec = -soap->send_timeout/1000000; - timeout.tv_usec = -soap->send_timeout%1000000; - } - else - { timeout.tv_sec = 0; - timeout.tv_usec = 10000; - } - FD_ZERO(&fd); - FD_SET(soap->socket, &fd); -#ifdef WITH_OPENSSL - if (soap->ssl && r == SSL_ERROR_WANT_READ) - r = select((int)soap->socket + 1, &fd, NULL, &fd, &timeout); - else - r = select((int)soap->socket + 1, NULL, &fd, &fd, &timeout); -#else - r = select((int)soap->socket + 1, NULL, &fd, &fd, &timeout); -#endif - if (r < 0 && (r = soap_socket_errno(soap->socket)) != SOAP_EINTR) - { soap->errnum = r; - return SOAP_EOF; - } -#endif - } - else if (err && err != SOAP_EINTR) - { soap->errnum = err; - 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 -#ifdef VXWORKS -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - nwritten = (httpBlockPut(soap->rpmreqid, s, n) == 0) ? n : -1; - else -#endif - nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w")); -#else - nwritten = write(soap->sendfd, s, (unsigned int)n); -#endif -#endif -#endif - if (nwritten <= 0) - { err = soap_errno; - if (err && err != SOAP_EINTR && err != SOAP_EWOULDBLOCK && err != SOAP_EAGAIN) - { soap->errnum = err; - 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_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; -#ifndef WITH_LEANER - if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - 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_flush(struct soap *soap) -{ register size_t n = soap->bufidx; - if (n) - { soap->bufidx = 0; -#ifdef WITH_ZLIB - if (soap->mode & SOAP_ENC_ZLIB) - { soap->d_stream->next_in = (Byte*)soap->buf; - soap->d_stream->avail_in = (unsigned int)n; -#ifdef WITH_GZIP - soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)n); -#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 - return soap_flush_raw(soap, soap->buf, n); - } - return SOAP_OK; -} -#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); -#ifndef WITH_LEANER - if (soap->fpreparesend) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - return SOAP_OK; - } -#ifndef WITH_LEANER - 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); -#endif - return soap->error = soap->fsend(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 WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static size_t -frecv(struct soap *soap, char *s, size_t n) -{ register int r; -#ifndef WITH_LEAN - register int retries = 100; /* max 100 retries with non-blocking sockets */ -#endif - soap->errnum = 0; -#if defined(__cplusplus) && !defined(WITH_LEAN) - if (soap->is) - { if (soap->is->good()) - return soap->is->read(s, (std::streamsize)n).gcount(); - return 0; - } -#endif - if (soap_valid_socket(soap->socket)) - { for (;;) - { -#ifdef WITH_OPENSSL - register int err = 0; -#endif -#ifndef WITH_LEAN -#ifdef WITH_OPENSSL - if (soap->recv_timeout && !soap->ssl) /* SSL: sockets are nonblocking */ -#else - if (soap->recv_timeout) -#endif - { -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return 0; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - for (;;) - { struct timeval timeout; - fd_set fd; - 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, &fd); - r = select((int)soap->socket + 1, &fd, NULL, &fd, &timeout); - if (r > 0) - break; - if (!r) - { soap->errnum = 0; - return 0; - } - r = soap_socket_errno(soap->socket); - if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) - { soap->errnum = r; - return 0; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - { r = SSL_read(soap->ssl, s, (int)n); - if (r > 0) - return (size_t)r; - err = SSL_get_error(soap->ssl, r); - if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE) - return 0; - } - else if (soap->bio) - { r = BIO_read(soap->bio, s, (int)n); - if (r > 0) - return (size_t)r; - return 0; - } - else -#endif - { -#ifndef WITH_LEAN - if ((soap->omode & SOAP_IO_UDP)) - { SOAP_SOCKLEN_T k = (SOAP_SOCKLEN_T)sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - r = recvfrom(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, &k); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - soap->peerlen = (size_t)k; -#ifndef WITH_IPV6 - soap->ip = ntohl(soap->peer.sin_addr.s_addr); -#endif - } - else -#endif - r = recv(soap->socket, s, (int)n, soap->socket_flags); -#ifdef PALM - /* CycleSyncDisplay(curStatusMsg); */ -#endif - if (r >= 0) - return (size_t)r; - r = soap_socket_errno(soap->socket); - if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) - { soap->errnum = r; - return 0; - } - } -#ifndef WITH_LEAN - { struct timeval timeout; - fd_set fd; - if (soap->recv_timeout > 0) - { timeout.tv_sec = soap->recv_timeout; - timeout.tv_usec = 0; - } - else if (soap->recv_timeout < 0) - { timeout.tv_sec = -soap->recv_timeout/1000000; - timeout.tv_usec = -soap->recv_timeout%1000000; - } - else - { timeout.tv_sec = 5; - timeout.tv_usec = 0; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return 0; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fd); - FD_SET(soap->socket, &fd); -#ifdef WITH_OPENSSL - if (soap->ssl && err == SSL_ERROR_WANT_WRITE) - r = select((int)soap->socket + 1, NULL, &fd, &fd, &timeout); - else - r = select((int)soap->socket + 1, &fd, NULL, &fd, &timeout); -#else - r = select((int)soap->socket + 1, &fd, NULL, &fd, &timeout); -#endif - if (!r && soap->recv_timeout) - { soap->errnum = 0; - return 0; - } - if (r < 0) - { r = soap_socket_errno(soap->socket); - if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) - { soap->errnum = r; - return 0; - } - } - if (retries-- <= 0) - { soap->errnum = soap_socket_errno(soap->socket); - return 0; - } - } -#endif -#ifdef PALM - r = soap_socket_errno(soap->socket); - if (r != SOAP_EINTR && retries-- <= 0) - { soap->errnum = r; - return 0; - } -#endif - } - } -#ifdef WITH_FASTCGI - return fread(s, 1, n, stdin); -#else -#ifdef UNDER_CE - return fread(s, 1, n, soap->recvfd); -#else -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - r = httpBlockRead(soap->rpmreqid, s, n); - else -#endif - r = read(soap->recvfd, s, (unsigned int)n); - if (r >= 0) - return (size_t)r; - soap->errnum = soap_errno; - return 0; -#endif -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef WITH_NOIO -#ifndef PALM_1 -static size_t -frecv_stop(struct soap *soap, char *s, size_t n) -{ return 0; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 from socket %d\n", (unsigned int)soap->buflen, soap->socket)); - DBGMSG(RECV, soap->buf, soap->buflen); - if (soap->buflen) - return soap->buf[soap->bufidx++]; - return EOF; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -static int -soap_isxdigit(int c) -{ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); -} -#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; - ret = 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)ret); - 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 (ret) - { soap->count += ret; - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n")); - DBGMSG(RECV, soap->buf, ret); - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n----\n")); - 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; - soap->error = SOAP_ZLIB_ERROR; - 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; - } - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- compressed ----\n")); - } -#endif -#ifndef WITH_NOHTTP - if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) /* read HTTP chunked transfer */ - { for (;;) - { register soap_wchar c; - char *t, tmp[8]; - 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; - break; - } - t = tmp; - if (!soap->chunkbuflen) - { soap->chunkbuflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes (chunked) from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - soap->bufidx = 0; - if (!ret) - return soap->ahead = EOF; - } - else - soap->bufidx = soap->buflen; - soap->buflen = soap->chunkbuflen; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (idx=%u len=%u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen)); - while (!soap_isxdigit((int)(c = soap_getchunkchar(soap)))) - { if ((int)c == EOF) - return soap->ahead = 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 soap->ahead = EOF; - *t = '\0'; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Chunk size = %s (hex)\n", tmp)); - 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); - ret = 0; - soap->ahead = EOF; - break; - } - soap->buflen = soap->bufidx + soap->chunksize; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to idx=%u len=%u (%s)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen, 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 (%u bytes left)\n", (unsigned int)(soap->buflen - soap->bufidx))); - } - else if (soap->chunkbuflen) - soap->chunksize = 0; - ret = soap->buflen - soap->bufidx; - if (ret) - break; - } - } - else -#endif - { soap->bufidx = 0; - soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - } -#ifndef WITH_LEANER - if (soap->fpreparerecv && (soap->error = soap->fpreparerecv(soap, soap->buf, ret))) - return soap->error; -#endif -#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 = 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)soap->buflen)); - if (ret && !soap->buflen) - goto zlib_again; - ret = soap->buflen; - if (r == Z_STREAM_END) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inflated total %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; - } - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n")); - DBGMSG(RECV, soap->buf, ret); - } - 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; - soap->error = SOAP_ZLIB_ERROR; - 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; - c = soap->ahead; - if (c) - { if (c != EOF) - 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 *code_map, const char *str) -{ if (code_map && str) - { while (code_map->string) - { if (!strcmp(str, code_map->string)) /* case sensitive */ - return code_map; - code_map++; - } - } - return NULL; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -long -SOAP_FMAC2 -soap_code_int(const struct soap_code_map *code_map, const char *str, long other) -{ if (code_map) - { while (code_map->string) - { if (!soap_tag_cmp(str, code_map->string)) /* case insensitive */ - return code_map->code; - code_map++; - } - } - return other; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_code_str(const struct soap_code_map *code_map, long code) -{ if (!code_map) - return NULL; - while (code_map->code != code && code_map->string) - code_map++; - return code_map->string; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -long -SOAP_FMAC2 -soap_code_bits(const struct soap_code_map *code_map, const char *str) -{ register long bits = 0; - if (code_map) - { while (str && *str) - { const struct soap_code_map *p; - for (p = code_map; p->string; p++) - { register size_t n = strlen(p->string); - if (!strncmp(p->string, str, n) && soap_blank(str[n])) - { bits |= p->code; - str += n; - while (*str > 0 && *str <= 32) - str++; - break; - } - } - if (!p->string) - return 0; - } - } - return bits; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_code_list(struct soap *soap, const struct soap_code_map *code_map, long code) -{ register char *t = soap->tmpbuf; - if (code_map) - { while (code_map->string) - { if (code_map->code & code) - { register const char *s = code_map->string; - if (t != soap->tmpbuf) - *t++ = ' '; - while (*s && t < soap->tmpbuf + sizeof(soap->tmpbuf) - 1) - *t++ = *s++; - if (t == soap->tmpbuf + sizeof(soap->tmpbuf) - 1) - break; - } - code_map++; - } - } - *t = '\0'; - return soap->tmpbuf; -} -#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_code_int(html_entity_codes, tmp, SOAP_UNKNOWN_CHAR); -#else - return SOAP_UNKNOWN_CHAR; /* use this to represent unknown code */ -#endif -} -#endif - -/******************************************************************************/ -#ifdef WITH_LEAN -#ifndef PALM_1 -soap_wchar -soap_get0(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx]; -} -#endif -#endif - -/******************************************************************************/ -#ifdef WITH_LEAN -#ifndef PALM_1 -soap_wchar -soap_get1(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx++]; -} -#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) - { if ((int)c != EOF) - soap->ahead = 0; - } - else - c = soap_get1(soap); - while ((int)c != EOF) - { if (soap->cdata) - { if (c == ']') - { c = soap_get1(soap); - if (c == ']') - { c = soap_get0(soap); - if (c == '>') - { soap->cdata = 0; - soap_get1(soap); - c = soap_get1(soap); - } - else - { soap_unget(soap, ']'); - return ']'; - } - } - else - { soap_revget1(soap); - return ']'; - } - } - else - return c; - } - switch (c) - { case '<': - do c = soap_get1(soap); - while (soap_blank(c)); - if (c == '!' || c == '?' || c == '%') - { register int k = 1; - 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); - } - } - else if (c == '?') - c = soap_get_pi(soap); - while ((int)c != EOF) - { if (c == '<') - k++; - else if (c == '>') - { if (--k <= 0) - break; - } - 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 -static soap_wchar -soap_get_pi(struct soap *soap) -{ char buf[64]; - register char *s = buf; - register int i = sizeof(buf); - register soap_wchar c = soap_getchar(soap); - /* This is a quick way to parse XML PI and we could use a callback instead to - * enable applications to intercept processing instructions */ - while ((int)c != EOF && c != '?') - { if (--i > 0) - { if (soap_blank(c)) - c = ' '; - *s++ = (char)c; - } - c = soap_getchar(soap); - } - *s = '\0'; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI \n", buf)); - if (!strncmp(buf, "xml ", 4)) - { s = strstr(buf, " encoding="); - if (s && s[10]) - { if (!soap_tag_cmp(s + 11, "iso-8859-1*") - || !soap_tag_cmp(s + 11, "latin1*")) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to latin1 encoding\n")); - soap->mode |= SOAP_ENC_LATIN; - } - else if (!soap_tag_cmp(s + 11, "utf-8*")) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to utf-8 encoding\n")); - soap->mode &= ~SOAP_ENC_LATIN; - } - } - } - if ((int)c != EOF) - c = soap_getchar(soap); - 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 < 0x80 && c > 0) - { *tmp = (char)c; - return soap_send_raw(soap, tmp, 1); - } -#ifndef WITH_LEAN - if (c >= 0x80) - { 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 - sprintf(tmp, "&#%lu;", c); -#endif - 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->ahead; - if (c > 0xFF) - { soap->ahead = 0; - return c; - } -again: - c = soap_get(soap); - if (c < 0x80 || (soap->mode & SOAP_ENC_LATIN)) - return c; - c1 = soap_get1(soap); - if (c1 < 0x80) - { soap_revget1(soap); /* doesn't look like this is UTF8 */ - return c; - } - c1 &= 0x3F; - if (c < 0xE0) - return ((soap_wchar)(c & 0x1F) << 6) | c1; - c2 = (soap_wchar)soap_get1(soap) & 0x3F; - if (c == 0xEF && c1 == 0x3B && c2 == 0x3F) /* ignore UTF-8 BOM */ - goto again; - 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) -{ char d[2]; - register int i; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!(soap->dom->data = soap_s2hex(soap, s, NULL, n))) - return soap->error; - return SOAP_OK; - } -#endif - 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_hex2s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#ifdef WITH_FAST - soap->labidx = 0; - for (;;) - { register char *s; - register size_t 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 + i - k); - p = (unsigned char*)soap_malloc(soap, soap->lablen + i - k); - if (p) - memcpy(p, soap->labbuf, soap->lablen + i - k); - 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 = (int)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, NULL, 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_base642s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#ifdef WITH_FAST - soap->labidx = 0; - for (;;) - { register size_t i, k; - register char *s; - if (soap_append_lab(soap, NULL, 2)) - return NULL; - s = soap->labbuf + soap->labidx; - k = soap->lablen - soap->labidx; - soap->labidx = 3 * (soap->lablen / 3); - if (!s) - return NULL; - if (k > 2) - { for (i = 0; i < k - 2; 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 + i - k); - p = (unsigned char*)soap_malloc(soap, soap->lablen + i - k); - if (p) - memcpy(p, soap->labbuf, soap->lablen + i - k); - 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) - { register int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; - } - else if (!soap_blank(c + '+')) - { soap->error = SOAP_TYPE; - return NULL; - } - } 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) - { int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; - } - else if (!soap_blank(c)) - { soap->error = SOAP_TYPE; - return NULL; - } - } while (j < 4); - *s++ = (char)((m >> 16) & 0xFF); - *s++ = (char)((m >> 8) & 0xFF); - *s++ = (char)(m & 0xFF); - } - } -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_xop_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ /* Check MTOM xop:Include element (within hex/base64Binary) */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - int body = soap->body; /* should save type too? */ - if (!soap_peek_element(soap)) - { if (!soap_element_begin_in(soap, "xop:Include", 0, NULL) && *soap->href) - { if (soap_dime_forward(soap, ptr, size, id, type, options)) - return soap->error; - } - if (soap->body && soap_element_end_in(soap, NULL)) - return soap->error; - } - soap->body = body; - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_dime_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ struct soap_xlist *xp; - *ptr = NULL; - *size = 0; - *id = NULL; - *type = NULL; - *options = NULL; - if (!*soap->href) - return SOAP_OK; - *id = soap_strdup(soap, soap->href); - xp = (struct soap_xlist*)SOAP_MALLOC(soap, sizeof(struct soap_xlist)); - if (!xp) - return soap->error = SOAP_EOM; - xp->next = soap->xlist; - xp->ptr = ptr; - xp->size = size; - xp->id = *id; - xp->type = type; - xp->options = options; - soap->xlist = xp; - return SOAP_OK; -} -#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 -wchar_t * -SOAP_FMAC2 -soap_wstrdup(struct soap *soap, const wchar_t *s) -{ wchar_t *t = NULL; - if (s) - { size_t n = 0; - while (s[n]) - n++; - if ((t = (wchar_t*)soap_malloc(soap, sizeof(wchar_t)*(n+1)))) - memcpy(t, s, sizeof(wchar_t)*(n+1)); - } - 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(soap, 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(soap, 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(soap, p); -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_update_ptrs(struct soap *soap, char *start, char *end, char *p1, char *p2) -{ int i; - register struct soap_ilist *ip = NULL; - register struct soap_flist *fp = NULL; -#ifndef WITH_LEANER - register struct soap_xlist *xp = NULL; -#endif - 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 + (p1-p2))); - ip->ptr = (char*)ip->ptr + (p1-p2); - } - 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 + (p1-p2); - } - } - 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 + (p1-p2); - } - } - 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 + (p1-p2); - } - } - } - } -#ifndef WITH_LEANER - for (xp = soap->xlist; xp; xp = xp->next) - { if (xp->ptr && (char*)xp->ptr >= start && (char*)xp->ptr < end) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", xp->id?xp->id:"", xp->ptr, (char*)xp->ptr + (p1-p2))); - xp->ptr = (unsigned char**)((char*)xp->ptr + (p1-p2)); - xp->size = (int*)((char*)xp->size + (p1-p2)); - xp->type = (char**)((char*)xp->type + (p1-p2)); - xp->options = (char**)((char*)xp->options + (p1-p2)); - } - } -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 = NULL; - register struct soap_flist *fp = NULL; - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_resolve(struct soap *soap) -{ register int i; - register struct soap_ilist *ip = NULL; - register struct soap_flist *fp = NULL; - 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, fp->len, p, ip->size); - else - soap_fcopy(soap, ip->type, fp->type, fp->ptr, fp->len, p, ip->size); - ip->flist = fp->next; - SOAP_FREE(soap, 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 -#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(soap, 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(soap, p); - } - soap->blist = bp->next; - SOAP_FREE(soap, 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); -#ifndef WITH_NOIDREF - if (flag) - soap_update_ptrs(soap, q, q + n, s, q); -#endif - 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; - if (*attr1 == '[') - attr1++; - n = 1; - for (;;) - { 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; - } - if (!attr1) - break; - 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 = (int)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; - register short i = -1; - register size_t n, k; - n = strlen(id); - k = strlen(ns) + 1; - p = soap->local_namespaces; - if (p) - { for (i = 0; p->id; p++, i++) - { if (p->ns && !strcmp(ns, p->ns)) - { if (p->out) - { SOAP_FREE(soap, p->out); - p->out = NULL; - } - break; - } - if (p->out) - { if (!strcmp(ns, p->out)) - break; - } - else if (p->in) - { if (!soap_tag_cmp(ns, p->in)) - { if ((p->out = (char*)SOAP_MALLOC(soap, k))) - strcpy(p->out, ns); - break; - } - } - } - if (!p || !p->id) - i = -1; - } - if (i >= 0) - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k); - if (!np) - return soap->error = SOAP_EOM; - np->next = soap->nlist; - soap->nlist = np; - np->level = soap->level; - np->index = i; - strcpy(np->id, id); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns)); - if (i < 0) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns)); - } - else - { np->ns = NULL; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id)); - } - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_pop_namespace(struct soap *soap) -{ register struct soap_nlist *np, *nq; - for (np = soap->nlist; np && np->level >= soap->level; np = nq) - { nq = np->next; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Pop namespace binding (level=%u) '%s'\n", soap->level, np->id)); - SOAP_FREE(soap, np); - } - soap->nlist = np; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_match_namespace(struct soap *soap, const char *id1, const char *id2, size_t n1, size_t 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 - || (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 && !strncmp(id1, "xml", 3) && !strncmp(id1, id2, 3)) - return SOAP_OK; - return soap->error = SOAP_SYNTAX_ERROR; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_current_namespace(struct soap *soap, const char *tag) -{ register struct soap_nlist *np; - register const char *s; - if (!tag || !strncmp(tag, "xml", 3)) - return NULL; - np = soap->nlist; - if (!(s = strchr(tag, ':'))) - { while (np && *np->id) /* find default namespace, if present */ - np = np->next; - } - else - { while (np && (strncmp(np->id, tag, s - tag) || np->id[s - tag])) - np = np->next; - if (!np) - soap->error = SOAP_NAMESPACE; - } - if (np) - { if (np->index >= 0) - return soap->namespaces[np->index].ns; - if (np->ns) - return soap_strdup(soap, np->ns); - } - return NULL; -} -#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 && !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; - register int err; - 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 && (err = 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)); - if (err == SOAP_NAMESPACE) - return SOAP_TAG_MISMATCH; - return err; - } - } - else if (SOAP_STRCMP(tag1, t + 1)) - { return SOAP_TAG_MISMATCH; - } - else if (t != tag2 && (err = 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)); - if (err == SOAP_NAMESPACE) - return SOAP_TAG_MISMATCH; - return err; - } - 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 - -/******************************************************************************\ - * - * SSL - * -\******************************************************************************/ - -#ifdef WITH_OPENSSL -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_rand() -{ unsigned char buf[4]; - if (!soap_ssl_init_done) - soap_ssl_init(); - RAND_pseudo_bytes(buf, 4); - return *(int*)buf; -} -#endif - -/******************************************************************************/ -#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; - soap->dhfile = dhfile; - soap->randfile = randfile; - soap->ssl_flags = flags | (dhfile == NULL ? SOAP_SSL_RSA : 0); - if (!(err = soap->fsslauth(soap))) - { if (sid) - SSL_CTX_set_session_id_context(soap->ctx, (unsigned char*)sid, (unsigned int)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->ssl_flags = flags; - soap->randfile = randfile; - return soap->fsslauth(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_ssl_init() -{ /* Note: for MT systems, the main program MUST call soap_ssl_init() before any threads are started */ - if (!soap_ssl_init_done) - { soap_ssl_init_done = 1; - SSL_library_init(); -#ifndef WITH_LEAN - SSL_load_error_strings(); -#endif - if (!RAND_load_file("/dev/urandom", 1024)) - { char buf[1024]; - RAND_seed(buf, sizeof(buf)); - while (!RAND_status()) - { int r = rand(); - RAND_seed(&r, sizeof(int)); - } - } - } -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_ssl_error(struct soap *soap, int ret) -{ int err = SSL_get_error(soap->ssl, ret); - const char *msg = soap_code_str(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 (int)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) -{ long flags; - int mode; - if (!soap_ssl_init_done) - 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); - /* Alters the behavior of SSL read/write: - SSL_CTX_set_mode(soap->ctx, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_AUTO_RETRY); - */ - } - 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 directory", SOAP_SSL_ERROR); - if (soap->cafile && (soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION)) - SSL_CTX_set_client_CA_list(soap->ctx, SSL_load_client_CA_file(soap->cafile)); - } - 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); -/* This code assumes a typical scenario, see alternative code below */ - 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); - } -/* Suggested alternative approach to check the key file for certs (cafile=NULL): - 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 (!soap->cafile || !SSL_CTX_use_certificate_chain_file(soap->ctx, soap->cafile)) - { 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 or key file", SOAP_SSL_ERROR); - 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->ssl_flags & SOAP_SSL_RSA)) - { RSA *rsa = RSA_generate_key(1024, 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); - } - flags = (SSL_OP_ALL | SSL_OP_NO_SSLv2); - if ((soap->ssl_flags & SOAP_SSLv3)) - flags |= SSL_OP_NO_TLSv1; - if ((soap->ssl_flags & SOAP_TLSv1)) - flags |= SSL_OP_NO_SSLv3; - SSL_CTX_set_options(soap->ctx, flags); - if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION)) - mode = (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT); - else if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION)) - mode = SSL_VERIFY_PEER; - else - mode = SSL_VERIFY_NONE; - SSL_CTX_set_verify(soap->ctx, mode, 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 or warning 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 - /* Note: return 1 to 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) -{ BIO *bio; - int retries, r, s; - 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->ctx && (soap->error = soap->fsslauth(soap))) - return SOAP_INVALID_SOCKET; - 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; - /* Set SSL sockets to non-blocking */ - SOAP_SOCKNONBLOCK(soap->socket) - bio = BIO_new_socket(soap->socket, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, bio); - retries = 100; /* 10 sec retries, 100 times 0.1 sec */ - 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; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - timeout.tv_sec = 0; - timeout.tv_usec = 100000; - FD_ZERO(&fd); - FD_SET(soap->socket, &fd); - if (err == SSL_ERROR_WANT_READ) - s = select((int)soap->socket + 1, &fd, NULL, &fd, &timeout); - else - s = select((int)soap->socket + 1, NULL, &fd, &fd, &timeout); - if (s < 0 && (s = soap_socket_errno(soap->socket)) != SOAP_EINTR) - { soap->errnum = s; - break; - } - } - else - { soap->errnum = err; - break; - } - if (retries-- <= 0) - break; - } - if (r <= 0) - { soap_set_receiver_error(soap, soap_ssl_error(soap, r), "SSL_accept() failed in soap_ssl_accept()", SOAP_SSL_ERROR); - soap_closesock(soap); - return SOAP_SSL_ERROR; - } - if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION)) - { 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 WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_done(struct soap *soap) -{ -#ifdef SOAP_DEBUG - int i; -#endif - if (soap_check_state(soap)) - return; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Done with context\n")); - soap_free_temp(soap); - while (soap->clist) - { struct soap_clist *p = soap->clist->next; - SOAP_FREE(soap, 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->state == SOAP_INIT) - soap->plugins->fdelete(soap, soap->plugins); - SOAP_FREE(soap, soap->plugins); - soap->plugins = p; - } - soap->fplugin = fplugin; - soap->fmalloc = NULL; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fput = http_put; - soap->fdel = http_del; - soap->fhead = http_head; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif - soap->fheader = NULL; -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; -#endif - soap->fseterror = NULL; - soap->fignore = NULL; - soap->fserveloop = NULL; -#ifdef WITH_OPENSSL - if (soap->session) - { SSL_SESSION_free(soap->session); - soap->session = NULL; - } -#endif - if (soap->state == SOAP_INIT) - { if (soap_valid_socket(soap->master)) - { soap->fclosesocket(soap, soap->master); - soap->master = SOAP_INVALID_SOCKET; - } -#ifdef WITH_OPENSSL - if (soap->ctx) - { SSL_CTX_free(soap->ctx); - soap->ctx = NULL; - } -#endif - } -#ifdef WITH_ZLIB - if (soap->d_stream) - { SOAP_FREE(soap, (void*)soap->d_stream); - soap->d_stream = NULL; - } - if (soap->z_buf) - { SOAP_FREE(soap, (void*)soap->z_buf); - soap->z_buf = NULL; - } -#endif -#ifdef SOAP_DEBUG - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free logfiles\n")); - for (i = 0; i < SOAP_MAXLOGS; i++) - { if (soap->logfile[i]) - { SOAP_FREE(soap, (void*)soap->logfile[i]); - soap->logfile[i] = NULL; - } - soap_close_logfile(soap, i); - } - soap->state = 0; -#endif -#ifdef SOAP_MEM_DEBUG - soap_free_mht(soap); -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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_code_str(h_error_codes, soap->errnum); - if (!msg) -#endif - { sprintf(soap->msgbuf, "TCP/UDP IP error %d", soap->errnum); - msg = soap->msgbuf; - } - } - } - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static const char* -http_error(struct soap *soap, int status) -{ register const char *msg = SOAP_STR_EOS; -#ifndef WITH_LEAN - msg = soap_code_str(h_http_error_codes, status); - if (!msg) - msg = SOAP_STR_EOS; -#endif - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_IPV6 -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr) -{ soap_int32 iadd = -1; - struct hostent hostent, *host = &hostent; -#ifdef VXWORKS - int hostint; - /* inet_addr(), and hostGetByName() expect "char *"; addr is a "const char *". */ - iadd = inet_addr((char*)addr); -#else -#if defined(_AIX43) || defined(TRU64) - struct hostent_data ht_data; -#endif -#ifdef AS400 - iadd = inet_addr((void*)addr); -#else - iadd = inet_addr(addr); -#endif -#endif - if (iadd != -1) - { memcpy(inaddr, &iadd, sizeof(iadd)); - return SOAP_OK; - } -#if defined(__GLIBC__) || (defined(HAVE_GETHOSTBYNAME_R) && (defined(FREEBSD) || defined(__FreeBSD__))) - if (gethostbyname_r(addr, &hostent, soap->buf, SOAP_BUFLEN, &host, &soap->errnum) < 0) - host = NULL; -#elif defined(_AIX43) || 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); -#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((char*)addr); - if (hostint == ERROR) - { host = NULL; - soap->errnum = soap_errno; - } -#else -#ifdef AS400 - if (!(host = gethostbyname((void*)addr))) - soap->errnum = h_errno; -#else - if (!(host = gethostbyname(addr))) - soap->errnum = h_errno; -#endif -#endif - if (!host) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Host name not found\n")); - return SOAP_ERR; - } -#ifdef VXWORKS - inaddr->s_addr = hostint; -#else - memcpy(inaddr, host->h_addr, host->h_length); -#endif - return SOAP_OK; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static SOAP_SOCKET -tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port) -{ -#ifdef WITH_IPV6 - struct addrinfo hints, *res, *ressave; -#endif - SOAP_SOCKET fd; - int err = 0; -#ifndef WITH_LEAN - int retry = 10; - int len = SOAP_BUFLEN; - int set = 1; -#endif - if (soap_valid_socket(soap->socket)) - soap->fclosesocket(soap, soap->socket); - soap->socket = SOAP_INVALID_SOCKET; - if (tcp_init(soap)) - { soap->errnum = 0; - soap_set_sender_error(soap, tcp_error(soap), "TCP init failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->errmode = 0; -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifndef WITH_LEAN - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - soap->errmode = 2; - if (soap->proxy_host) - err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &res); - else - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &res); - if (err) - { soap_set_sender_error(soap, SOAP_GAI_STRERROR(err), "getaddrinfo failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - ressave = res; -again: - fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); - soap->errmode = 0; -#else -#ifndef WITH_LEAN -again: -#endif -#ifndef WITH_LEAN - if ((soap->omode & SOAP_IO_UDP)) - fd = socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - fd = socket(AF_INET, SOCK_STREAM, 0); -#endif - if (!soap_valid_socket(fd)) - { -#ifdef WITH_IPV6 - if (res->ai_next) - { res = res->ai_next; - goto again; - } -#endif - soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "socket failed in tcp_connect()", SOAP_TCP_ERROR); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#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(fd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - } - else if (soap->connect_flags && setsockopt(fd, SOL_SOCKET, soap->connect_flags, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - if ((soap->keep_alive || soap->tcp_keep_alive) && setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_KEEPIDLE - if (soap->tcp_keep_idle && setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_KEEPIDLE, (unsigned int*)&(soap->tcp_keep_idle), sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_KEEPIDLE failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#endif -#ifdef TCP_KEEPINTVL - if (soap->tcp_keep_intvl && setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_KEEPINTVL, (unsigned int*)&(soap->tcp_keep_intvl), sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_KEEPINTVL failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#endif -#ifdef TCP_KEEPCNT - if (soap->tcp_keep_cnt && setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_KEEPCNT, (unsigned int*)&(soap->tcp_keep_cnt), sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_KEEPCNT failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#endif -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#endif -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket %d to host='%s' port=%d\n", fd, host, port)); -#ifndef WITH_IPV6 - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (soap->proxy_host) - { if (soap->fresolve(soap, soap->proxy_host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)soap->proxy_port); - } - else - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)port); - } - soap->errmode = 0; -#ifndef WITH_LEAN - if ((soap->omode & SOAP_IO_UDP)) - { -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return fd; - } -#endif -#endif -#ifndef WITH_LEAN - if (soap->connect_timeout) - SOAP_SOCKNONBLOCK(fd) - else - SOAP_SOCKBLOCK(fd) -#endif - for (;;) - { -#ifdef WITH_IPV6 - if (connect(fd, res->ai_addr, (int)res->ai_addrlen)) -#else - if (connect(fd, (struct sockaddr*)&soap->peer, sizeof(soap->peer))) -#endif - { err = soap_socket_errno(fd); -#ifndef WITH_LEAN - if (err == SOAP_EADDRINUSE) - { soap->fclosesocket(soap, fd); - if (retry-- > 0) - goto again; - } - else if (soap->connect_timeout && (err == SOAP_EINPROGRESS || err == SOAP_EAGAIN || err == SOAP_EWOULDBLOCK)) - { - SOAP_SOCKLEN_T k; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - for (;;) - { struct timeval timeout; - fd_set fds; - register int r; - 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(fd, &fds); - r = select((int)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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - r = soap_socket_errno(fd); - if (r != SOAP_EINTR) - { soap->errnum = r; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - } - k = (SOAP_SOCKLEN_T)sizeof(soap->errnum); - if (!getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &k) && !soap->errnum) /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - break; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - if (!soap->errnum) - soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#endif -#ifdef WITH_IPV6 - if (res->ai_next) - { res = res->ai_next; - soap->fclosesocket(soap, fd); - goto again; - } -#endif - if (err && err != SOAP_EINTR) - { soap->errnum = err; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - } - else - break; - } -#ifdef WITH_IPV6 - soap->peerlen = 0; /* IPv6: already connected so use send() */ - freeaddrinfo(ressave); -#endif -#ifndef WITH_LEAN - if (soap->recv_timeout || soap->send_timeout) - SOAP_SOCKNONBLOCK(fd) - else - SOAP_SOCKBLOCK(fd) -#endif - soap->socket = fd; - soap->imode &= ~SOAP_ENC_SSL; - soap->omode &= ~SOAP_ENC_SSL; - if (!soap_tag_cmp(endpoint, "https:*")) - { -#ifdef WITH_OPENSSL - BIO *bio; - 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 */ - char *userid, *passwd; - soap->omode &= ~SOAP_ENC; /* mask IO and ENC */ - soap->omode |= SOAP_IO_BUFFER; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to %s proxy server\n", soap->proxy_http_version)); - sprintf(soap->tmpbuf, "CONNECT %s:%d HTTP/%s", host, port, soap->proxy_http_version); - if (soap_begin_send(soap) - || (soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL))) - { soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } -#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, (int)strlen(soap->tmpbuf + 262)); - if ((soap->error = soap->fposthdr(soap, "Proxy-Authorization", soap->tmpbuf))) - { soap->fclosesocket(soap, fd); - return soap->error; - } - } -#endif - if ((soap->error = soap->fposthdr(soap, NULL, NULL)) - || soap_flush(soap)) - { soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } - soap->omode = k; - k = soap->imode; - soap->imode &= ~SOAP_ENC; /* mask IO and ENC */ - userid = soap->userid; /* preserve */ - passwd = soap->passwd; /* preserve */ - if ((soap->error = soap->fparse(soap))) - { soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } - soap->userid = userid; /* restore */ - soap->passwd = passwd; /* restore */ - soap->imode = k; /* restore */ - soap->count = n; /* restore */ - if (soap_begin_send(soap)) - { soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } - if (endpoint) - strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint)-1); /* restore */ - } - 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); - soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } - soap->ssl = SSL_new(soap->ctx); - if (!soap->ssl) - { soap->fclosesocket(soap, fd); - soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; - } - 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; - bio = BIO_new_socket(fd, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, bio); -#ifndef WITH_LEAN - /* Connect timeout: set SSL sockets to non-blocking */ - if (soap->connect_timeout) - SOAP_SOCKNONBLOCK(fd) - else - SOAP_SOCKBLOCK(fd) - /* Try connecting until success or timeout */ - 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, soap_ssl_error(soap, r), "SSL connect failed in tcp_connect()", SOAP_SSL_ERROR); - soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } - if (soap->connect_timeout) - { -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return SOAP_INVALID_SOCKET; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - for (;;) - { struct timeval timeout; - fd_set fds; - register int r; - 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(fd, &fds); - r = select((int)fd + 1, &fds, &fds, &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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } - } - continue; - } - } - break; - } - /* Set SSL sockets to nonblocking */ - SOAP_SOCKNONBLOCK(fd) -#endif - /* Check server credentials when required */ - if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION)) - { 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); - soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } - if (!(soap->ssl_flags & SOAP_SSL_SKIP_HOST_CHECK)) - { X509_NAME *subj; - int ext_count; - int ok = 0; - X509 *peer; - 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); - soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } - ext_count = X509_get_ext_count(peer); - if (ext_count > 0) - { int i; - for (i = 0; i < ext_count; i++) - { X509_EXTENSION *ext = X509_get_ext(peer, i); - const char *ext_str = OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(ext))); - if (ext_str && !strcmp(ext_str, "subjectAltName")) - { X509V3_EXT_METHOD *meth = X509V3_EXT_get(ext); - void *ext_data; -#if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) - const unsigned char *data; -#else - unsigned char *data; -#endif - STACK_OF(CONF_VALUE) *val; - int j; - if (!meth) - break; - data = ext->value->data; -#if (OPENSSL_VERSION_NUMBER > 0x00907000L) - if (meth->it) - ext_data = ASN1_item_d2i(NULL, &data, ext->value->length, ASN1_ITEM_ptr(meth->it)); - else - { /* OpenSSL not perfectly portable at this point (?): - Some compilers appear to prefer - meth->d2i(NULL, (const unsigned char**)&data, ... - or - meth->d2i(NULL, &data, ext->value->length); - */ - ext_data = meth->d2i(NULL, &data, ext->value->length); - } -#else - ext_data = meth->d2i(NULL, &data, ext->value->length); -#endif - val = meth->i2v(meth, ext_data, NULL); - for (j = 0; j < sk_CONF_VALUE_num(val); j++) - { CONF_VALUE *nval = sk_CONF_VALUE_value(val, j); - if (nval && !strcmp(nval->name, "DNS") && !strcmp(nval->value, host)) - { ok = 1; - break; - } - } - } - if (ok) - break; - } - } - if (!ok && (subj = X509_get_subject_name(peer))) - { int i = -1; - do - { ASN1_STRING *name; - i = X509_NAME_get_index_by_NID(subj, NID_commonName, i); - if (i == -1) - break; - name = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(subj, i)); - if (name) - { if (!soap_tag_cmp(host, (const char*)name)) - ok = 1; - else - { unsigned char *tmp = NULL; - ASN1_STRING_to_UTF8(&tmp, name); - if (tmp) - { if (!soap_tag_cmp(host, (const char*)tmp)) - ok = 1; - OPENSSL_free(tmp); - } - } - } - } while (!ok); - } - X509_free(peer); - if (!ok) - { soap_set_sender_error(soap, "SSL error", "SSL certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR); - soap->fclosesocket(soap, fd); - return SOAP_INVALID_SOCKET; - } - } - } -#else - soap->fclosesocket(soap, fd); - soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; -#endif - } - return fd; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -SOAP_SOCKET -SOAP_FMAC2 -soap_bind(struct soap *soap, const char *host, int port, int backlog) -{ -#ifdef WITH_IPV6 - struct addrinfo *addrinfo = NULL; - struct addrinfo hints; - struct addrinfo res; - int err; -#endif -#ifndef WITH_LEAN - int len = SOAP_BUFLEN; - int set = 1; -#endif - if (soap_valid_socket(soap->master)) - { soap->fclosesocket(soap, 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 SOAP_INVALID_SOCKET; - } -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifndef WITH_LEAN - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - soap->errmode = 2; - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo); - if (addrinfo) - { res = *addrinfo; - memcpy(&soap->peer, addrinfo->ai_addr, addrinfo->ai_addrlen); - soap->peerlen = addrinfo->ai_addrlen; - res.ai_addr = (struct sockaddr*)&soap->peer; - res.ai_addrlen = soap->peerlen; - freeaddrinfo(addrinfo); - } - if (err || !addrinfo) - { soap_set_receiver_error(soap, SOAP_GAI_STRERROR(err), "getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->master = (int)socket(res.ai_family, res.ai_socktype, res.ai_protocol); -#else -#ifndef WITH_LEAN - if ((soap->omode & SOAP_IO_UDP)) - soap->master = (int)socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - soap->master = (int)socket(AF_INET, SOCK_STREAM, 0); -#endif - soap->errmode = 0; - if (!soap_valid_socket(soap->master)) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "socket failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifndef WITH_LEAN - if ((soap->omode & SOAP_IO_UDP)) - soap->socket = soap->master; -#endif -#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->master, SOL_SOCKET, soap->bind_flags, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt(soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (setsockopt(soap->master, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (setsockopt(soap->master, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && setsockopt(soap->master, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif -#endif -#ifdef WITH_IPV6 - soap->errmode = 0; - if (bind(soap->master, res.ai_addr, (int)res.ai_addrlen)) - { soap->errnum = soap_socket_errno(soap->master); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n")); - soap_closesock(soap); - soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#else - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (host) - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_receiver_error(soap, tcp_error(soap), "get host by name failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } - else - soap->peer.sin_addr.s_addr = htonl(INADDR_ANY); - soap->peer.sin_port = htons((short)port); - soap->errmode = 0; - if (bind(soap->master, (struct sockaddr*)&soap->peer, (int)soap->peerlen)) - { soap->errnum = soap_socket_errno(soap->master); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n")); - soap_closesock(soap); - soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif - if (!(soap->omode & SOAP_IO_UDP) && listen(soap->master, backlog)) - { soap->errnum = soap_socket_errno(soap->master); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n")); - soap_closesock(soap); - soap_set_receiver_error(soap, tcp_error(soap), "listen failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - return soap->master; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_poll(struct soap *soap) -{ -#ifndef WITH_LEAN - struct timeval timeout; - fd_set rfd, sfd, xfd; - register int r; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_ZERO(&xfd); - if (soap_valid_socket(soap->socket)) - { FD_SET(soap->socket, &rfd); - FD_SET(soap->socket, &sfd); - FD_SET(soap->socket, &xfd); - r = select((int)soap->socket + 1, &rfd, &sfd, &xfd, &timeout); - if (r > 0 && FD_ISSET(soap->socket, &xfd)) - r = -1; - } - else if (soap_valid_socket(soap->master)) - { FD_SET(soap->master, &sfd); - r = select((int)soap->master + 1, NULL, &sfd, NULL, &timeout); - } - else - return SOAP_OK; - if (r > 0) - { -#ifdef WITH_OPENSSL - if (soap->imode & SOAP_ENC_SSL) - { - if (soap_valid_socket(soap->socket) - && FD_ISSET(soap->socket, &sfd) - && (!FD_ISSET(soap->socket, &rfd) - || SSL_peek(soap->ssl, soap->tmpbuf, 1) > 0)) - return SOAP_OK; - } - else -#endif - if (soap_valid_socket(soap->socket) - && FD_ISSET(soap->socket, &sfd) - && (!FD_ISSET(soap->socket, &rfd) - || recv(soap->socket, soap->tmpbuf, 1, MSG_PEEK) > 0)) - return SOAP_OK; - } - else if (r < 0) - { soap->errnum = soap_socket_errno(soap->master); - if ((soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno(soap->master) != SOAP_EINTR) - { 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 = 0; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Polling: other end down on socket=%d select=%d\n", soap->socket, r)); - return SOAP_EOF; -#else - return SOAP_OK; -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static SOAP_SOCKET -tcp_accept(struct soap *soap, SOAP_SOCKET s, struct sockaddr *a, int *n) -{ SOAP_SOCKET fd; - fd = accept(s, a, (SOAP_SOCKLEN_T*)n); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ -#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 WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -SOAP_SOCKET -SOAP_FMAC2 -soap_accept(struct soap *soap) -{ int n = (int)sizeof(soap->peer); -#ifndef WITH_LEAN - int len = SOAP_BUFLEN; - int set = 1; -#endif - soap->error = SOAP_OK; -#ifndef WITH_LEAN - if ((soap->omode & SOAP_IO_UDP)) - return soap->socket = soap->master; -#endif - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->socket = SOAP_INVALID_SOCKET; - soap->errmode = 0; - soap->keep_alive = 0; - if (soap_valid_socket(soap->master)) - { register int err; - for (;;) - { -#ifndef WITH_LEAN - if (soap->accept_timeout || soap->send_timeout || soap->recv_timeout) - { -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return SOAP_INVALID_SOCKET; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - for (;;) - { struct timeval timeout; - fd_set fd; - register int r; - if (soap->accept_timeout > 0) - { timeout.tv_sec = soap->accept_timeout; - timeout.tv_usec = 0; - } - else if (soap->accept_timeout < 0) - { timeout.tv_sec = -soap->accept_timeout/1000000; - timeout.tv_usec = -soap->accept_timeout%1000000; - } - else - { timeout.tv_sec = 60; - timeout.tv_usec = 0; - } - FD_ZERO(&fd); - FD_SET(soap->master, &fd); - r = select((int)soap->master + 1, &fd, &fd, &fd, &timeout); - if (r > 0) - break; - if (!r && soap->accept_timeout) - { soap->errnum = 0; - soap_set_receiver_error(soap, "Timeout", "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (r < 0) - { r = soap_socket_errno(soap->master); - if (r != SOAP_EINTR) - { soap->errnum = r; - soap_closesock(soap); - soap_set_sender_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } - } - } - if (soap->accept_timeout || soap->send_timeout || soap->recv_timeout) - SOAP_SOCKNONBLOCK(soap->master) - else - SOAP_SOCKBLOCK(soap->master) -#endif - soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&soap->peer, &n); - soap->peerlen = (size_t)n; - if (soap_valid_socket(soap->socket)) - { -#ifdef WITH_IPV6 -/* Use soap->host to store the numeric form of the remote host */ - getnameinfo((struct sockaddr*)&soap->peer, 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->peer and soap->host */ - soap->port = 0; /* info stored in soap->peer and soap->host */ -#else - soap->ip = ntohl(soap->peer.sin_addr.s_addr); - soap->port = (int)ntohs(soap->peer.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)); -#endif -#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, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(struct linger))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - else if (soap->accept_flags && setsockopt(soap->socket, SOL_SOCKET, soap->accept_flags, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt(soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (setsockopt(soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (setsockopt(soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && setsockopt(soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#endif -#endif - soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0); - return soap->socket; - } - err = soap_socket_errno(soap->socket); - if (err != 0 && err != SOAP_EINTR && err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK) - { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host)); - soap->errnum = err; - soap_set_receiver_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - } - else - { soap->errnum = 0; - soap_set_receiver_error(soap, tcp_error(soap), "no master socket in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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); - soap->session = NULL; - } - 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 == 0) - { if (soap_valid_socket(soap->socket)) - { struct timeval timeout; - fd_set fd; - if (soap->fshutdownsocket(soap, soap->socket, 1)) - { /* - wait up to 10 seconds for close_notify to be sent by peer (if peer not - present, this avoids calling SSL_shutdown() which has a lengthy return - timeout) - */ -#ifndef WIN32 - if ((int)soap->socket < (int)FD_SETSIZE) - { -#endif - timeout.tv_sec = 10; - timeout.tv_usec = 0; - FD_ZERO(&fd); - FD_SET(soap->socket, &fd); - r = select((int)soap->socket + 1, &fd, NULL, &fd, &timeout); - if (r <= 0 && soap_socket_errno(soap->socket) != SOAP_EINTR) - { soap->errnum = 0; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connection lost...\n")); - soap->fclosesocket(soap, soap->socket); - soap->socket = SOAP_INVALID_SOCKET; - SSL_free(soap->ssl); - soap->ssl = NULL; - ERR_remove_state(0); - return SOAP_OK; - } -#ifndef WIN32 - } -#endif - } - } - r = SSL_shutdown(soap->ssl); - } - if (r != 1) - { s = ERR_get_error(); - if (s) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown failed: %d\n", SSL_get_error(soap->ssl, r))); - if (soap_valid_socket(soap->socket) && !(soap->omode & SOAP_IO_UDP)) - { soap->fclosesocket(soap, soap->socket); - soap->socket = SOAP_INVALID_SOCKET; - } - SSL_free(soap->ssl); - soap->ssl = NULL; - ERR_remove_state(0); - return SOAP_SSL_ERROR; - } - } - SSL_free(soap->ssl); - soap->ssl = NULL; - ERR_remove_state(0); - } -#endif - if (soap_valid_socket(soap->socket) && !(soap->omode & SOAP_IO_UDP)) - { soap->fshutdownsocket(soap, soap->socket, 2); - soap->fclosesocket(soap, soap->socket); - soap->socket = SOAP_INVALID_SOCKET; - } - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_closesocket(struct soap *soap, SOAP_SOCKET fd) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket %d\n", (int)fd)); - return soap_closesocket(fd); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET fd, int how) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket %d how=%d\n", (int)fd, 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; - if (status == SOAP_EOF || status == SOAP_TCP_ERROR || status == SOAP_SSL_ERROR || !soap->keep_alive) - { if (soap->fclose && (soap->error = soap->fclose(soap))) - return soap->error; - soap->keep_alive = 0; - } -#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 WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_init_pht(struct soap *soap) -{ register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing pointer hashtable\n")); - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new1(soap_mode mode) -{ return soap_new2(mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new() -{ return soap_new2(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new2(soap_mode imode, soap_mode omode) -{ struct soap *soap = (struct soap*)malloc(sizeof(struct soap)); - if (soap) - soap_init2(soap, imode, omode); - return soap; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_free(struct soap *soap) -{ soap_done(soap); - free(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_del(struct soap *soap) -{ free(soap); -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_free_pht(struct soap *soap) -{ register struct soap_pblk *pb, *next; - register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n")); - for (pb = soap->pblk; pb; pb = next) - { next = pb->next; - SOAP_FREE(soap, pb); - } - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 size_t h; - register struct soap_plist *pp; - if (!soap->pblk || soap->pidx >= SOAP_PTRBLK) - { register struct soap_pblk *pb = (struct soap_pblk*)SOAP_MALLOC(soap, sizeof(struct soap_pblk)); - if (!pb) - { soap->error = SOAP_EOM; - return 0; - } - pb->next = soap->pblk; - soap->pblk = pb; - soap->pidx = 0; - } - *ppp = pp = &soap->pblk->plist[soap->pidx++]; - 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=%d\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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_begin_count(struct soap *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)) -#ifndef WITH_LEANER - && !soap->fpreparesend -#endif - )) - soap->mode &= ~SOAP_IO_LENGTH; - else - soap->mode |= SOAP_IO_LENGTH; - } -#ifdef WITH_ZLIB - 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; - } -#endif - if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH)) - soap->mode |= SOAP_XML_TREE; -#ifndef WITH_LEANER - if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME)) - soap->mode |= SOAP_ENC_MIME; - else - soap->mode &= ~SOAP_ENC_MTOM; - 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_clr_attr(soap); - soap_set_local_namespaces(soap); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); -#ifndef WITH_LEANER - soap->dime.count = 0; /* count # of attachments */ - soap->dime.size = 0; /* accumulate total size of attachments */ - if (soap->fprepareinit && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_end_count(struct soap *soap) -{ -#ifndef WITH_LEANER - if (soap->fpreparefinal) - return soap->error = soap->fpreparefinal(soap); -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of count phase\n")); - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_begin_send(struct soap *soap) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for output\n")); - soap->error = SOAP_OK; - soap->mode = soap->omode | (soap->mode & (SOAP_IO_LENGTH | SOAP_ENC_DIME)); -#ifdef WITH_ZLIB - 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; - } -#endif -#ifndef WITH_LEAN - if ((soap->mode & SOAP_IO_UDP)) - { soap->mode |= SOAP_ENC_XML; - if (soap->count > SOAP_BUFLEN) - return soap->error = SOAP_UDP_ERROR; - } -#endif - if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket)) - { if (soap->count || (soap->mode & SOAP_IO_LENGTH) || (soap->mode & SOAP_ENC_XML)) - soap->mode |= SOAP_IO_BUFFER; - else - soap->mode |= SOAP_IO_STORE; - } - soap->mode &= ~SOAP_IO_LENGTH; - 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_MTOM) && (soap->mode & SOAP_ENC_DIME)) - { soap->mode |= SOAP_ENC_MIME; - soap->mode &= ~SOAP_ENC_DIME; - } - else - soap->mode &= ~SOAP_ENC_MTOM; - if (soap->mode & SOAP_ENC_MIME) - soap_select_mime_boundary(soap); -#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->sendfd, O_BINARY); -#else - _setmode(soap->sendfd, _O_BINARY); -#endif -#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->idnum = 0; - soap->level = 0; - soap_clr_attr(soap); - soap_set_local_namespaces(soap); -#ifdef WITH_ZLIB - soap->z_ratio_out = 1.0; - if ((soap->mode & SOAP_ENC_ZLIB) && soap->zlib_state != SOAP_ZLIB_DEFLATE) - { if (!soap->z_buf) - soap->z_buf = (char*)SOAP_MALLOC(soap, SOAP_BUFLEN); - soap->d_stream->next_out = (Byte*)soap->z_buf; - soap->d_stream->avail_out = SOAP_BUFLEN; -#ifdef WITH_GZIP - if (soap->zlib_out != SOAP_ZLIB_DEFLATE) - { 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); - soap->zlib_out = SOAP_ZLIB_GZIP; - if (deflateInit2(soap->d_stream, soap->z_level, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK) - return soap->error = SOAP_ZLIB_ERROR; - } - else -#endif - if (deflateInit(soap->d_stream, soap->z_level) != Z_OK) - 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=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); - soap->part = SOAP_BEGIN; -#ifndef WITH_LEANER - if (soap->fprepareinit && (soap->mode & SOAP_IO) == SOAP_IO_STORE) - soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 || !a->__ptr) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 = NULL; - if (soap->mode & SOAP_XML_TREE) - return id; - 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_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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_attachment(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) -{ -#ifndef WITH_NOIDREF - struct soap_plist *pp; - int i; - 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:"")); - i = soap_array_pointer_lookup(soap, p, a, n, t, &pp); - if (!i) - { i = soap_pointer_enter(soap, p, a, n, t, &pp); - if (!i) - { soap->error = SOAP_EOM; - return -1; - } - } - if (id <= 0) - id = i; - if (!aid) - { sprintf(soap->tmpbuf, soap->dime_id_format, id); - aid = soap_strdup(soap, soap->tmpbuf); - } - /* Add MTOM xop:Include element when necessary */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - if ((soap->mode & SOAP_ENC_MTOM) && strcmp(tag, "xop:Include")) - { if (soap_element_begin_out(soap, tag, 0, type) - || soap_element_href(soap, "xop:Include", 0, "href", aid) - || soap_element_end_out(soap, tag)) - return soap->error; - } - else 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; - if (soap->mode & SOAP_ENC_MTOM) - content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, (char*)a->__ptr, a->__size); - else - content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, (char*)a->__ptr, a->__size); - if (!content) - { soap->error = SOAP_EOM; - return -1; - } - if (!strncmp(aid, "cid:", 4)) /* RFC 2111 */ - { if (soap->mode & SOAP_ENC_MTOM) - { char *s = (char*)soap_malloc(soap, strlen(aid) - 1); - if (s) - { *s = '<'; - strcpy(s + 1, aid + 4); - strcat(s, ">"); - content->id = s; - } - } - else - content->id = aid + 4; - } - else - content->id = aid; - content->type = atype; - content->options = aoptions; - content->encoding = SOAP_MIME_BINARY; - pp->mark1 = 3; - } - } - else - pp->mark2 = 3; -#endif - return -1; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_free_iht(struct soap *soap) -{ register int i; - register struct soap_ilist *ip = NULL, *p = NULL; - register struct soap_flist *fp = NULL, *fq = NULL; - 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(soap, fp); - } - p = ip->next; - SOAP_FREE(soap, ip); - } - soap->iht[i] = NULL; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_2 -SOAP_FMAC1 -struct soap_ilist * -SOAP_FMAC2 -soap_lookup(struct soap *soap, const char *id) -{ register struct soap_ilist *ip = NULL; - for (ip = soap->iht[soap_hash(id)]; ip; ip = ip->next) - if (!strcmp(ip->id, id)) - return ip; - return NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, 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 -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_malloc(struct soap *soap, size_t n) -{ register char *p; - if (!n) - return (void*)SOAP_NON_NULL; - if (!soap) - return SOAP_MALLOC(soap, n); - if (soap->fmalloc) - p = (char*)soap->fmalloc(soap, n); - else - { n += sizeof(short); - n += (-(long)n) & (sizeof(void*)-1); /* align at 4-, 8- or 16-byte boundary */ - if (!(p = (char*)SOAP_MALLOC(soap, n + sizeof(void*) + sizeof(size_t)))) - { soap->error = SOAP_EOM; - return NULL; - } - /* set the canary to detect corruption */ - *(short*)(p + n - sizeof(short)) = (short)SOAP_CANARY; - /* keep chain of alloced cells for destruction */ - *(void**)(p + n) = soap->alist; - *(size_t*)(p + n + sizeof(void*)) = n; - soap->alist = p + n; - } - soap->alloced = 1; - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -static void -soap_init_mht(struct soap *soap) -{ register int i; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->mht[i] = NULL; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -static void -soap_free_mht(struct soap *soap) -{ register int i; - register struct soap_mlist *mp, *mq; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - { for (mp = soap->mht[i]; mp; mp = mq) - { mq = mp->next; - if (mp->live) - fprintf(stderr, "%s(%d): malloc() = %p not freed (memory leak or forgot to call soap_end()?)\n", mp->file, mp->line, mp->ptr); - free(mp); - } - soap->mht[i] = NULL; - } -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_track_malloc(struct soap *soap, const char *file, int line, size_t size) -{ register void *p = malloc(size); - if (soap) - { register size_t h = soap_hash_ptr(p); - register struct soap_mlist *mp = (struct soap_mlist*)malloc(sizeof(struct soap_mlist)); - if (soap->fdebug[SOAP_INDEX_TEST]) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): malloc(%lu) = %p\n", file, line, (unsigned long)size, p)); - } - mp->next = soap->mht[h]; - mp->ptr = p; - mp->file = file; - mp->line = line; - mp->live = 1; - soap->mht[h] = mp; - } - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_track_free(struct soap *soap, const char *file, int line, void *p) -{ register size_t h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - { if (mp->live) - { free(p); - if (soap->fdebug[SOAP_INDEX_TEST]) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): free(%p)\n", file, line, p)); - } - mp->live = 0; - } - else - fprintf(stderr, "%s(%d): free(%p) double free of pointer malloced at %s(%d)\n", file, line, p, mp->file, mp->line); - } - else - fprintf(stderr, "%s(%d): free(%p) pointer not malloced\n", file, line, p); -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -static void -soap_track_unlink(struct soap *soap, const void *p) -{ register size_t h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - mp->live = 0; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_dealloc(struct soap *soap, void *p) -{ if (soap_check_state(soap)) - return; - if (p) - { register char **q; - for (q = (char**)&soap->alist; *q; q = *(char***)q) - { - if (*(short*)(char*)(*q - sizeof(short)) != (short)SOAP_CANARY) - { -#ifdef SOAP_MEM_DEBUG - fprintf(stderr, "Data corruption in dynamic allocation (see logs)\n"); -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Data corruption:\n")); - DBGHEX(TEST, *q - 200, 200); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n")); - soap->error = SOAP_MOE; - return; - } - 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(soap, p); - return; - } - } - soap_delete(soap, p); - } - else - { register char *q; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free all soap_malloc() data\n")); - while (soap->alist) - { q = (char*)soap->alist; - if (*(short*)(char*)(q - sizeof(short)) != (short)SOAP_CANARY) - { -#ifdef SOAP_MEM_DEBUG - fprintf(stderr, "Data corruption in dynamic allocation (see logs)\n"); -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Data corruption:\n")); - DBGHEX(TEST, q - 200, 200); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n")); - soap->error = SOAP_MOE; - return; - } - soap->alist = *(void**)q; - q -= *(size_t*)(q + sizeof(void*)); - SOAP_FREE(soap, q); - } - /* we must assume these were deallocated: */ - soap->action = NULL; - soap->fault = NULL; - soap->header = NULL; - soap->userid = NULL; - soap->passwd = NULL; - soap->authrealm = NULL; - soap->http_content = 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; - if (soap_check_state(soap)) - return; - cp = &soap->clist; - if (p) - { while (*cp) - { if (p == (*cp)->ptr) - { register struct soap_clist *q = *cp; - *cp = q->next; - if (q->fdelete(q)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: deletion callback failed for object type %d\n", q->ptr, q->type)); -#ifdef SOAP_MEM_DEBUG - fprintf(stderr, "new(object type = %d) = %p not freed: deletion callback failed\n", q->type, q->ptr); -#endif - } - SOAP_FREE(soap, 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->fdelete(q)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: deletion callback failed for object type %d\n", q->ptr, q->type)); -#ifdef SOAP_MEM_DEBUG - fprintf(stderr, "new(object type = %d) = %p not freed: deletion callback failed\n", q->type, q->ptr); -#endif - } - SOAP_FREE(soap, q); - } - } - soap->fault = NULL; /* this was possibly deallocated */ - soap->header = NULL; /* this was possibly deallocated */ -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -struct soap_clist * -SOAP_FMAC2 -soap_link(struct soap *soap, void *p, int t, int n, int (*fdelete)(struct soap_clist*)) -{ register struct soap_clist *cp; - if ((cp = (struct soap_clist*)SOAP_MALLOC(soap, 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)); -#ifdef SOAP_MEM_DEBUG - soap_track_unlink(soap, p); -#endif - 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(soap, q); - return; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 (!p || !id || !*id) - return p; - 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: href='%s' id-type=%d href-type=%d\n", id, 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_2 -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_id_forward(struct soap *soap, const char *href, void *p, size_t len, int st, int tt, size_t n, unsigned int k, void (*fcopy)(struct soap*, int, int, void*, size_t, 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(soap, 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; - fp->len = len; - 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 len=%lu href='%s'\n", st, tt, (unsigned long)n, p, k, (unsigned long)len, 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 -#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*)) -{ -#ifndef WITH_NOIDREF - struct soap_ilist *ip; -#endif - 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; - } -#ifndef WITH_NOIDREF - if (!id || !*id) -#endif - return p; -#ifndef WITH_NOIDREF - 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_DUPLICATE_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 -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_fcopy(struct soap *soap, int st, int tt, void *p, size_t len, 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 total %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 - if (soap->zlib_out != SOAP_ZLIB_DEFLATE) - { 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; -#ifndef WITH_NOHTTP - 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++; - } -#endif - 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); - } -#ifndef WITH_LEANER - 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_TCPFIN -#ifdef WITH_OPENSSL - if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, soap->socket, 1); /* Send TCP FIN */ -#else - if (soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, soap->socket, 1); /* Send TCP FIN */ -#endif -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send phase\n")); - soap->omode &= ~SOAP_XML_SEC; - soap->count = 0; - soap->part = SOAP_END; - 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_DIME) && soap_getdime(soap)) - { soap->dime.first = NULL; - soap->dime.last = NULL; - return soap->error; - } - soap->dime.list = soap->dime.first; - soap->dime.first = NULL; - soap->dime.last = NULL; - /* Check if MIME attachments and mime-post-check flag is set, if set call soap_resolve() and return */ - if (soap->mode & SOAP_ENC_MIME) - { -#ifndef WITH_NOIDREF - if (soap->mode & SOAP_MIME_POSTCHECK) - { soap_resolve(soap); - return SOAP_OK; - } -#endif - if (soap_getmime(soap)) - return soap->error; - } - soap->mime.list = soap->mime.first; - soap->mime.first = NULL; - soap->mime.last = NULL; - soap->mime.boundary = NULL; - if (soap->xlist) - { struct soap_multipart *content; - for (content = soap->mime.list; content; content = content->next) - soap_resolve_attachment(soap, content); - } -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "End of receive message ok\n")); -#ifdef WITH_ZLIB - if (soap->mode & SOAP_ENC_ZLIB) - { /* Make sure end of compressed content is reached */ - while (soap->d_stream->next_out != Z_NULL) - if ((int)soap_get1(soap) == EOF) - break; - 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; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Inflate end ok\n")); -#ifdef WITH_GZIP - if (soap->zlib_in == SOAP_ZLIB_GZIP) - { soap_wchar c; - short i; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Inflate gzip crc check\n")); - for (i = 0; i < 8; i++) - { if ((int)(c = soap_get1(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; - } - } - soap->zlib_in = SOAP_ZLIB_NONE; -#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; -#ifndef WITH_NOIDREF - if (soap_resolve(soap)) - return soap->error; -#endif -#ifndef WITH_LEANER - if (soap->xlist) - { if (soap->mode & SOAP_ENC_MTOM) - return soap->error = SOAP_MIME_HREF; - return soap->error = SOAP_DIME_HREF; - } -#endif - soap_free_temp(soap); - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_free_temp(struct soap *soap) -{ register struct soap_nlist *np, *nq; - register struct soap_attribute *tp, *tq; - register struct Namespace *ns; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n")); - for (np = soap->nlist; np; np = nq) - { nq = np->next; - SOAP_FREE(soap, np); - } - soap->nlist = NULL; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free any remaining temp blocks\n")); - while (soap->blist) - soap_end_block(soap); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free attribute storage\n")); - for (tp = soap->attributes; tp; tp = tq) - { tq = tp->next; - if (tp->value) - SOAP_FREE(soap, tp->value); - SOAP_FREE(soap, tp); - } - soap->attributes = NULL; -#ifdef WITH_FAST - if (soap->labbuf) - SOAP_FREE(soap, soap->labbuf); - soap->labbuf = NULL; - soap->lablen = 0; - soap->labidx = 0; -#endif - ns = soap->local_namespaces; - if (ns) - { for (; ns->id; ns++) - { if (ns->out) - { if (soap->encodingStyle == ns->out) - soap->encodingStyle = SOAP_STR_EOS; - SOAP_FREE(soap, ns->out); - ns->out = NULL; - } - if (soap->encodingStyle == ns->ns) - soap->encodingStyle = SOAP_STR_EOS; - } - SOAP_FREE(soap, soap->local_namespaces); - soap->local_namespaces = NULL; - } -#ifndef WITH_LEANER - while (soap->xlist) - { struct soap_xlist *xp = soap->xlist->next; - SOAP_FREE(soap, soap->xlist); - soap->xlist = xp; - } -#endif -#ifndef WITH_NOIDREF - soap_free_pht(soap); - soap_free_iht(soap); -#endif -} -#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) -{ const char *s; - char *t = NULL; - soap_close_logfile(soap, i); - s = soap->logfile[i]; - soap->logfile[i] = logfile; - if (s) - SOAP_FREE(soap, (void*)s); - if (logfile) - if ((t = (char*)SOAP_MALLOC(soap, strlen(logfile) + 1))) - strcpy(t, logfile); - soap->logfile[i] = t; -} -#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(const struct soap *soap) -{ return soap_copy_context((struct soap*)malloc(sizeof(struct soap)), soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_copy_context(struct soap *copy, const struct soap *soap) -{ if (soap_check_state(soap)) - return NULL; - if (copy) - { register struct soap_plugin *p = NULL; - memcpy(copy, soap, sizeof(struct soap)); - copy->state = SOAP_COPY; - copy->error = SOAP_OK; - copy->userid = NULL; - copy->passwd = NULL; - copy->nlist = NULL; - copy->blist = NULL; - copy->clist = NULL; - copy->alist = NULL; - copy->attributes = NULL; - copy->labbuf = NULL; - copy->lablen = 0; - copy->labidx = 0; -#ifdef SOAP_MEM_DEBUG - soap_init_mht(copy); -#endif -#ifdef SOAP_DEBUG - soap_init_logs(copy); - soap_set_recv_logfile(copy, soap->logfile[SOAP_INDEX_RECV]); - soap_set_sent_logfile(copy, soap->logfile[SOAP_INDEX_SENT]); - soap_set_test_logfile(copy, soap->logfile[SOAP_INDEX_TEST]); -#endif -#ifdef WITH_ZLIB - copy->d_stream = (z_stream*)SOAP_MALLOC(copy, sizeof(z_stream)); - copy->d_stream->zalloc = Z_NULL; - copy->d_stream->zfree = Z_NULL; - copy->d_stream->opaque = Z_NULL; - copy->z_buf = NULL; -#endif - copy->local_namespaces = NULL; -#ifndef WITH_NOIDREF - soap_init_iht(copy); - soap_init_pht(copy); -#endif - copy->header = NULL; - copy->fault = NULL; - copy->action = NULL; -#ifndef WITH_LEAN -#ifdef WITH_COOKIES - copy->cookies = soap_copy_cookies(copy, soap); -#else - copy->cookies = NULL; -#endif -#endif - copy->plugins = NULL; - for (p = soap->plugins; p; p = p->next) - { register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(copy, sizeof(struct soap_plugin)); - if (!q) - return NULL; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Copying plugin '%s'\n", p->id)); - *q = *p; - if (p->fcopy && p->fcopy(copy, q, p)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not copy plugin '%s'\n", p->id)); - SOAP_FREE(copy, q); - return NULL; - } - q->next = copy->plugins; - copy->plugins = q; - } - } - return copy; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_copy_stream(struct soap *copy, struct soap *soap) -{ copy->mode = soap->mode; - copy->imode = soap->imode; - copy->omode = soap->omode; - copy->socket = soap->socket; - copy->recv_timeout = soap->recv_timeout; - copy->send_timeout = soap->send_timeout; -#if defined(__cplusplus) && !defined(WITH_LEAN) - copy->os = soap->os; - copy->is = soap->is; -#endif - copy->sendfd = soap->sendfd; - copy->recvfd = soap->recvfd; - copy->bufidx = soap->bufidx; - copy->buflen = soap->buflen; - copy->ahead = soap->ahead; - copy->cdata = soap->cdata; - copy->chunksize = soap->chunksize; - copy->chunkbuflen = soap->chunkbuflen; - copy->keep_alive = soap->keep_alive; - copy->tcp_keep_alive = soap->tcp_keep_alive; - copy->tcp_keep_idle = soap->tcp_keep_idle; - copy->tcp_keep_intvl = soap->tcp_keep_intvl; - copy->tcp_keep_cnt = soap->tcp_keep_cnt; - copy->max_keep_alive = soap->max_keep_alive; -#ifndef WITH_NOIO - copy->peer = soap->peer; - copy->peerlen = soap->peerlen; -#endif -#ifdef WITH_OPENSSL - copy->bio = soap->bio; - copy->ssl = soap->ssl; - copy->ctx = soap->ctx; -#endif -#ifdef WITH_ZLIB - copy->zlib_state = soap->zlib_state; - copy->zlib_in = soap->zlib_in; - copy->zlib_out = soap->zlib_out; - copy->d_stream = (z_stream*)SOAP_MALLOC(copy, sizeof(z_stream)); - memcpy(copy->d_stream, soap->d_stream, sizeof(z_stream)); - copy->z_crc = soap->z_crc; - copy->z_ratio_in = soap->z_ratio_in; - copy->z_ratio_out = soap->z_ratio_out; - copy->z_buf = NULL; - copy->z_buflen = soap->z_buflen; - copy->z_level = soap->z_level; - if (soap->z_buf && soap->zlib_state != SOAP_ZLIB_NONE) - { copy->z_buf = (char*)SOAP_MALLOC(copy, SOAP_BUFLEN); - memcpy(copy->z_buf, soap->z_buf, sizeof(soap->z_buf)); - } -#endif - memcpy(copy->buf, soap->buf, sizeof(soap->buf)); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init(struct soap *soap) -{ soap->state = SOAP_INIT; -#ifdef SOAP_MEM_DEBUG - soap_init_mht(soap); -#endif - soap->version = 0; - soap_imode(soap, SOAP_IO_DEFAULT); - soap_omode(soap, SOAP_IO_DEFAULT); - soap->plugins = NULL; - soap->user = NULL; - soap->userid = NULL; - soap->passwd = NULL; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fput = http_put; - soap->fdel = http_del; - soap->fhead = http_head; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif - soap->fheader = NULL; - soap->fconnect = NULL; - soap->fdisconnect = NULL; -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif - soap->fseterror = NULL; - soap->fignore = NULL; - soap->fserveloop = NULL; - soap->fplugin = fplugin; - soap->fmalloc = NULL; -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; - soap->fdimereadopen = NULL; - soap->fdimewriteopen = NULL; - soap->fdimereadclose = NULL; - soap->fdimewriteclose = NULL; - soap->fdimeread = NULL; - soap->fdimewrite = NULL; - soap->fmimereadopen = NULL; - soap->fmimewriteopen = NULL; - soap->fmimereadclose = NULL; - soap->fmimewriteclose = NULL; - soap->fmimeread = NULL; - soap->fmimewrite = NULL; -#endif - soap->float_format = "%.9G"; /* Alternative: use "%G" */ - soap->double_format = "%.17lG"; /* Alternative: use "%lG" */ - soap->dime_id_format = "cid:id%d"; /* default DIME id format */ - soap->http_version = "1.1"; - soap->proxy_http_version = "1.0"; - soap->http_content = NULL; - soap->actor = NULL; - soap->keep_alive = 0; - soap->tcp_keep_alive = 0; - soap->tcp_keep_idle = 0; - soap->tcp_keep_intvl = 0; - soap->tcp_keep_cnt = 0; - soap->max_keep_alive = SOAP_MAXKEEPALIVE; - 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; -#ifndef WITH_LEANER - 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; - soap->xlist = NULL; -#endif -#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_ZLIB - soap->zlib_state = SOAP_ZLIB_NONE; - soap->zlib_in = SOAP_ZLIB_NONE; - soap->zlib_out = SOAP_ZLIB_NONE; - soap->d_stream = (z_stream*)SOAP_MALLOC(soap, sizeof(z_stream)); - soap->d_stream->zalloc = Z_NULL; - soap->d_stream->zfree = Z_NULL; - soap->d_stream->opaque = Z_NULL; - soap->z_buf = NULL; - soap->z_level = 6; -#endif -#ifndef WITH_LEAN - soap->c14ninclude = NULL; - soap->c14nexclude = NULL; - soap->cookies = NULL; - soap->cookie_domain = NULL; - soap->cookie_path = NULL; - soap->cookie_max = 32; -#endif -#ifdef SOAP_DEBUG - soap_init_logs(soap); -#endif -#ifdef WMW_RPM_IO - soap->rpmreqid = NULL; -#endif -#ifdef PALM - palmNetLibOpen(); -#endif -#ifndef WITH_NOIDREF - soap_init_iht(soap); - soap_init_pht(soap); -#endif -#ifdef SOAP_DEBUG - soap_set_recv_logfile(soap, "RECV.log"); - soap_set_sent_logfile(soap, "SENT.log"); - soap_set_test_logfile(soap, "TEST.log"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing context\n")); -#endif -#ifdef WITH_OPENSSL - if (!soap_ssl_init_done) - { soap_ssl_init(); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing OpenSSL, version=%ld\n", (long)OPENSSL_VERSION_NUMBER)); - } - soap->fsslauth = ssl_auth_init; - soap->fsslverify = ssl_verify_callback; - soap->bio = NULL; - soap->ssl = NULL; - soap->ctx = NULL; - soap->ssl_flags = SOAP_SSL_DEFAULT; - soap->keyfile = NULL; - soap->password = NULL; - soap->dhfile = NULL; - soap->cafile = NULL; - soap->capath = NULL; - soap->crlfile = NULL; - soap->randfile = NULL; - soap->session = NULL; -#endif - soap_begin(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init1(struct soap *soap, soap_mode mode) -{ soap_init2(soap, mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init2(struct soap *soap, soap_mode imode, soap_mode 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, "Reinitializing context\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_END; - 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'; -#ifndef WITH_LEANER - soap->dime.chunksize = 0; - soap->dime.buflen = 0; -#endif - soap_free_temp(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_end(struct soap *soap) -{ if (soap_check_state(soap)) - return; - soap_free_temp(soap); - soap_dealloc(soap, NULL); - while (soap->clist) - { register struct soap_clist *cp = soap->clist->next; - SOAP_FREE(soap, 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, const struct Namespace *p) -{ register struct Namespace *ns = soap->local_namespaces; - register struct soap_nlist *np, *nq, *nr; - register unsigned int level = soap->level; - soap->namespaces = p; - soap->local_namespaces = NULL; - soap_set_local_namespaces(soap); - /* reverse the namespace 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; - } - } - /* then push on new stack */ - while (np) - { register const char *s; - soap->level = np->level; /* preserve element nesting level */ - s = np->ns; - if (!s && np->index >= 0 && ns) - { s = ns[np->index].out; - if (!s) - s = ns[np->index].ns; - } - if (s && soap_push_namespace(soap, np->id, s)) - return soap->error; - nq = np; - np = np->next; - SOAP_FREE(soap, nq); - } - if (ns) - { register int i; - for (i = 0; ns[i].id; i++) - { if (ns[i].out) - { SOAP_FREE(soap, ns[i].out); - ns[i].out = NULL; - } - } - SOAP_FREE(soap, ns); - } - soap->level = level; /* restore level */ - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -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++; - n *= sizeof(struct Namespace); - ns2 = (struct Namespace*)SOAP_MALLOC(soap, n); - if (ns2) - { memcpy(ns2, soap->namespaces, n); - if (ns2[0].ns) - { if (!strcmp(ns2[0].ns, soap_env1)) - soap->version = 1; - else - soap->version = 2; - } - soap->local_namespaces = ns2; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef PALM_1 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_strsearch(const char *big, const char *little) -{ size_t n = strlen(little); - const char *s = big; - while (s) - { if (!strncmp(s, little, n) && (s[n] == '\0' || s[n] == ' ')) - return s; - s = strchr(s, ' '); - if (s) - s++; - } - return NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef PALM_1 -SOAP_FMAC1 -struct soap_nlist * -SOAP_FMAC2 -soap_lookup_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np; - for (np = soap->nlist; np; np = np->next) - { if (!strncmp(np->id, tag, n) && !np->id[n]) - return np; - } - return NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static struct soap_nlist * -soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized) -{ register struct soap_nlist *np; - size_t n, k; - if (soap_strsearch(soap->c14nexclude, id)) - return NULL; - if (!utilized) - { for (np = soap->nlist; np; np = np->next) - { if (!strcmp(np->id, id) && (!np->ns || !strcmp(np->ns, ns))) - break; - } - if (np) - { if ((np->level < soap->level || !np->ns) && np->index == 1) - utilized = 1; - else - return NULL; - } - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Adding namespace binding (level=%u) '%s' '%s' utilized=%d\n", soap->level, id, ns?ns:"(null)", utilized)); - n = strlen(id); - if (ns) - k = strlen(ns); - else - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k + 1); - if (!np) - { soap->error = SOAP_EOM; - return NULL; - } - np->next = soap->nlist; - soap->nlist = np; - strcpy(np->id, id); - if (ns) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - } - else - np->ns = NULL; - np->level = soap->level; - np->index = utilized; - return np; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_utilize_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np = soap_lookup_ns(soap, tag, n); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Utilizing namespace of '%s'\n", tag)); - if (np) - { if (np->index == 0) - soap_push_ns(soap, np->id, np->ns, 1); - } - else if (strncmp(tag, "xml", 3)) - { strncpy(soap->tmpbuf, tag, n); - soap->tmpbuf[n] = '\0'; - soap_push_ns(soap, soap->tmpbuf, NULL, 1); - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_pop_ns(struct soap *soap) -{ soap_pop_namespace(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_element(struct soap *soap, const char *tag, int id, const char *type) -{ -#ifdef WITH_XMLNS - register const char *s; -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' id='%d' type='%s'\n", tag, id, type?type:"")); -#ifdef WITH_DOM - if (soap->part == SOAP_BEGIN_SECURITY && (soap->mode & SOAP_XML_CANONICAL) && !(soap->mode & SOAP_DOM_ASIS)) - { register struct soap_nlist *np; - /* wsu:Id found: clear xmlns renderings, so re-emit them for exc-c14n */ - for (np = soap->nlist; np; np = np->next) - { if (np->index == 2) - np->index = 0; - } - } - if (soap->mode & SOAP_XML_DOM) - { register struct soap_dom_element *elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->soap = soap; - elt->next = NULL; - elt->prnt = soap->dom; - elt->name = soap_strdup(soap, tag); - elt->elts = NULL; - elt->atts = NULL; - elt->nstr = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->node = NULL; - elt->type = 0; - elt->head = NULL; - elt->tail = NULL; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - } - else - { -#endif - soap->level++; -#ifndef WITH_LEAN - if (!soap->ns) - { if (!(soap->mode & SOAP_XML_CANONICAL) - && soap_send(soap, soap->prolog ? soap->prolog : "\n")) - return soap->error; - } - else if (soap->mode & SOAP_XML_INDENT) - { if (soap->ns == 1 && soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - soap->body = 1; - } -#endif -#ifdef WITH_XMLNS - s = strchr(tag, ':'); - if (s && strncmp(tag, "SOAP-ENV", s - tag)) - { struct Namespace *ns = soap->local_namespaces; - size_t n = s - tag; - if (soap_send_raw(soap, "<", 1) - || soap_send(soap, s + 1)) - return soap->error; - if (soap->nlist && !strncmp(soap->nlist->id, tag, n) && !soap->nlist->id[n]) - ns = NULL; - for (; ns && ns->id; ns++) - { if (*ns->id && (ns->out || ns->ns) && !strncmp(ns->id, tag, n) && !ns->id[n]) - { soap_push_ns(soap, ns->id, ns->out ? ns->out : ns->ns, 0); - if (soap_attribute(soap, "xmlns", ns->out ? ns->out : ns->ns)) - return soap->error; - break; - } - } - } - else -#endif - if (soap_send_raw(soap, "<", 1) - || soap_send(soap, tag)) - return soap->error; -#ifdef WITH_DOM - } -#endif - if (!soap->ns) - { struct Namespace *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; /* start with 0 or 2, but should be one to continue */ -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *t = strchr(tag, ':'); - if (t) - soap_utilize_ns(soap, tag, t - tag); - } -#endif - if (id > 0) - { sprintf(soap->tmpbuf, "_%d", id); - if (soap_attribute(soap, "id", soap->tmpbuf)) - return soap->error; - } - if (type && *type && (!(soap->mode & SOAP_XML_SEC) || soap->part == SOAP_IN_BODY)) - { if (soap_attribute(soap, "xsi:type", type)) - return soap->error; -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *t = strchr(type, ':'); - if (t) - soap_utilize_ns(soap, type, t - type); - } -#endif - } - if (soap->null && soap->position > 0) - { register 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; - if (soap->part == SOAP_BEGIN_SECURITY && (soap->mode & SOAP_XML_CANONICAL)) - soap->part = SOAP_IN_SECURITY; - 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 && (n > 214748364 || c >= '8')) - 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 && (n > 429496729 || c >= '6')) - 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; - } -#ifndef WITH_LEAN - if (type && *type && (soap->mode & SOAP_XML_CANONICAL)) - { const char *s = strchr(type, ':'); - if (s) - soap_utilize_ns(soap, type, s - type); - } -#endif - 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; -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { struct soap_nlist *np; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible && tp->name) - { const char *s = strchr(tp->name, ':'); - if (s) - soap_utilize_ns(soap, tp->name, s - tp->name); - } - } - for (np = soap->nlist; np; np = np->next) - { if (np->index == 1 && np->ns) - { sprintf(soap->tmpbuf, "xmlns:%s", np->id); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enabling utilized binding (level=%u) %s='%s'\n", np->level, soap->tmpbuf, np->ns)); - soap_set_attr(soap, soap->tmpbuf, np->ns); - np->index = 2; - } - } - } -#endif -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { register struct soap_dom_attribute **att; - att = &soap->dom->atts; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, tp->name); - (*att)->data = soap_strdup(soap, tp->value); - (*att)->wide = NULL; - (*att)->soap = soap; - att = &(*att)->next; - tp->visible = 0; - } - } - return SOAP_OK; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { -#ifdef WITH_XMLNS - const char *s = strchr(tp->name, ':'); - if (s) - { size_t n = s - tp->name; - if (soap->nlist && !strncmp(soap->nlist->id, tp->name, n) && !soap->nlist->id[n]) - s++; - else - s = tp->name; - if (soap_send(soap, " ") || soap_send(soap, s)) - return soap->error; - } - else -#endif - if (soap_send(soap, " ") || 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) - { -#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 - soap->level--; /* decrement level just before /> */ - if (soap_send_raw(soap, "/>", 2)) - return soap->error; - return SOAP_OK; - } - 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 -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - soap_pop_ns(soap); - if (soap->mode & SOAP_XML_INDENT) - { if (!soap->body) - { if (soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - } - soap->body = 0; - } -#endif -#ifdef WITH_XMLNS - { const char *s = strchr(tag, ':'); - if (s && strncmp(tag, "SOAP-ENV", s - tag)) - { soap_pop_ns(soap); - tag = s + 1; - } - } -#endif - if (soap_send_raw(soap, "error; - soap->level--; /* decrement level just before > */ - 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; - const char *s = "href"; - if (soap->version == 2) - { s = "SOAP-ENC:ref"; - n = 1; - } - sprintf(soap->href, "#_%d", href); - return soap_element_href(soap, tag, id, s, 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 (!tp && 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) -{ if (!p || (a && !a->__ptr)) - { soap_element_null(soap, tag, id, type); - return -1; - } -#ifndef WITH_NOIDREF - if (soap->mode & SOAP_XML_TREE) - return 0; - if (id < 0) - { struct soap_plist *pp; - 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; -#else - return 0; -#endif -} -#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_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_check_result(struct soap *soap, const char *tag) -{ if (soap->version == 2 && soap->encodingStyle) - { soap_instring(soap, ":result", NULL, NULL, 0, 2, -1, -1); - /* just ignore content for compliance reasons, but should compare tag to element's QName value? */ - } -} -#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->mode & SOAP_XML_CANONICAL) && 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); - a->data = soap_strdup(soap, value); - a->wide = NULL; - a->soap = soap; - soap->dom->atts = a; - return SOAP_OK; - } -#endif -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { /* TODO: consider using this code to handle default namespace bindings - if (!strncmp(name, "xmlns", 5) && (name[5] == ':' || name[5] == '\0')) - { if (name[5] == ':') - soap_push_ns(soap, name + 6, value, 0); - else - soap_push_ns(soap, "", value, 0); - } - */ - if (!strncmp(name, "xmlns:", 6)) - soap_push_ns(soap, name + 6, value, 0); - else if (soap_set_attr(soap, name, value)) - return soap->error; - } - else -#endif - { if (soap_send(soap, " ") || 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, int nillable, const char *type) -{ 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 (type && *soap->type && soap_match_tag(soap, soap->type, type)) - return soap->error = SOAP_TYPE; - if (!nillable && soap->null && (soap->mode & SOAP_XML_STRICT)) - return soap->error = SOAP_NULL; - if (soap->body) - soap->level++; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin element found (level=%u) '%s'='%s'\n", soap->level, soap->tag, tag?tag:"" )); - } - } - else if (soap->error == SOAP_NO_TAG && tag && *tag == '-') - soap->error = SOAP_OK; - 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 int n = 0; - if (tag && *tag == '-') - return SOAP_OK; - if (soap->error == SOAP_NO_TAG) - soap->error = SOAP_OK; -#ifdef WITH_DOM - /* this whitespace or mixed content is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!soap->peeked && !soap_string_in(soap, 3, -1, -1)) - return soap->error; - if (soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - if (soap->peeked) - { if (*soap->tag) - n++; - soap->peeked = 0; - } - do - { while (((c = soap_get(soap)) != SOAP_TT)) - { if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (c == SOAP_LT) - n++; - else if (c == '/') - { c = soap_get(soap); - if (c == SOAP_GT) - n--; - else - soap_unget(soap, c); - } - } - } while (n--); - s = soap->tag; - n = sizeof(soap->tag); - while (soap_notblank(c = soap_get(soap))) - { if (--n > 0) - *s++ = (char)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:"")); -#ifndef WITH_LEAN - if (tag && (soap->mode & SOAP_XML_STRICT)) - { soap_pop_namespace(soap); - if (soap_match_tag(soap, soap->tag, tag)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End element tag name does not match\n")); - return soap->error = SOAP_SYNTAX_ERROR; - } - } -#endif - soap->level--; - return SOAP_OK; -} -#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; - if (*name == '-') - return SOAP_STR_EOS; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible && !soap_match_tag(soap, tp->name, name)) - break; - } - if (tp) - { 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; - if (*name == '-') - return SOAP_OK; - 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(soap, 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, ':'); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inserting attribute %s for c14n\n", 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 (tp->visible) - { return SOAP_OK; - } - 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(soap, tp->value); - tp->value = NULL; - tp->ns = NULL; - } - if (value) - { if (!tp->value) - { tp->size = strlen(value) + 1; - if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size))) - return soap->error = SOAP_EOM; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute value for %s (%p)\n", tp->name, tp->value)); - } - strcpy(tp->value, value); - if (!strncmp(tp->name, "xmlns:", 6)) - tp->ns = tp->value; - tp->visible = 2; -#ifndef WITH_LEAN - if (!strcmp(name, "wsu:Id")) - { soap->part = SOAP_BEGIN_SECURITY; - strncpy(soap->id, value, sizeof(soap->id)); - soap->id[sizeof(soap->id)-1] = '\0'; - } -#endif - } - 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; - if (soap->attributes->value) - SOAP_FREE(soap, soap->attributes->value); - SOAP_FREE(soap, 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) -{ register size_t i; - for (i = 0; i < n; i++) - { register soap_wchar c = soap_get(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 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_store_lab(struct soap *soap, const char *s, size_t n) -{ soap->labidx = 0; - return soap_append_lab(soap, s, n); -} -#endif -#endif - -/******************************************************************************/ -#ifdef WITH_FAST -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -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, soap->lablen); - if (!soap->labbuf) - { if (t) - SOAP_FREE(soap, t); - return soap->error = SOAP_EOM; - } - if (t) - { memcpy(soap->labbuf, t, soap->labidx); - SOAP_FREE(soap, 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) -{ -#ifdef WITH_DOM - register struct soap_dom_attribute **att = NULL; - register char *lead = NULL; -#endif - register struct soap_attribute *tp, *tq = NULL; - const char *t; - register char *s; - register soap_wchar c; - register int i; - if (soap->peeked) - { if (!*soap->tag) - return soap->error = SOAP_NO_TAG; - return SOAP_OK; - } - soap->peeked = 1; - 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; - c = soap_getutf8(soap); -#ifdef WITH_DOM - /* whitespace leading to start tag is not insignificant for DOM */ - if (soap_blank(c)) - { soap->labidx = 0; - do - { if (soap_append_lab(soap, NULL, 0)) - return SOAP_EOM; - s = soap->labbuf + soap->labidx; - i = soap->lablen - soap->labidx; - soap->labidx = soap->lablen; - while (soap_blank(c) && i--) - { *s++ = c; - c = soap_getutf8(soap); - } - } - while (soap_blank(c)); - *s = '\0'; - lead = soap_strdup(soap, soap->labbuf); - } -#else - while (soap_blank(c)) - c = soap_getutf8(soap); -#endif - if (c != SOAP_LT) - { *soap->tag = '\0'; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifdef WITH_DOM - /* whitespace leading to end tag is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->tail = soap_strdup(soap, lead); -#endif - return soap->error = SOAP_NO_TAG; - } - s = soap->tag; - do c = soap_get1(soap); - while (soap_blank(c)); - i = sizeof(soap->tag); - while (c != '>' && c != '/' && soap_notblank(c) && (int)c != EOF) - { if (--i > 0) - *s++ = (char)c; - c = soap_get1(soap); - } - while (soap_blank(c)) - c = soap_get1(soap); - *s = '\0'; -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { register struct soap_dom_element *elt; - elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->next = NULL; - elt->nstr = NULL; - elt->name = soap_strdup(soap, soap->tag); - elt->prnt = soap->dom; - elt->elts = NULL; - elt->atts = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->type = 0; - elt->node = NULL; - elt->head = lead; - elt->tail = NULL; - elt->soap = soap; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - att = &elt->atts; - } -#endif - soap_pop_namespace(soap); - for (tp = soap->attributes; tp; tp = tp->next) - tp->visible = 0; - while ((int)c != EOF && c != '>' && c != '/') - { s = soap->tmpbuf; - i = sizeof(soap->tmpbuf); - while (c != '=' && c != '>' && c != '/' && soap_notblank(c) && (int)c != EOF) - { if (--i > 0) - *s++ = (char)c; - c = soap_get1(soap); - } - *s = '\0'; - if (i == sizeof(soap->tmpbuf)) - return soap->error = SOAP_SYNTAX_ERROR; -#ifdef WITH_DOM - /* add attribute name to dom */ - if (att) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, soap->tmpbuf); - (*att)->data = NULL; - (*att)->wide = NULL; - (*att)->soap = soap; - } -#endif - if (!strncmp(soap->tmpbuf, "xmlns", 5)) - { if (soap->tmpbuf[5] == ':') - t = soap->tmpbuf + 6; - else if (soap->tmpbuf[5]) - t = NULL; - else - t = SOAP_STR_EOS; - } - else - t = NULL; - tq = NULL; - for (tp = soap->attributes; tp; tq = tp, tp = tp->next) - { if (!SOAP_STRCMP(tp->name, soap->tmpbuf)) - break; - } - if (!tp) - { tp = (struct soap_attribute*)SOAP_MALLOC(soap, 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; - /* if attribute name is qualified, append it to the end of the list */ - if (tq && strchr(soap->tmpbuf, ':')) - { tq->next = tp; - tp->next = NULL; - } - else - { tp->next = soap->attributes; - soap->attributes = tp; - } - } - while (soap_blank(c)) - c = soap_get1(soap); - if (c == '=') - { do c = soap_getutf8(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; - if (soap_store_lab(soap, tp->value, tp->size)) - return soap->error; - if (tp->value) - SOAP_FREE(soap, 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; - } - if (soap->labidx) - tp->size = soap->lablen; - else - { tp->size = strlen(soap->labbuf) + 1; - if (tp->size < SOAP_LABLEN) - tp->size = SOAP_LABLEN; - } - if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size))) - return soap->error = SOAP_EOM; - strcpy(tp->value, soap->labbuf); -#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(soap, n))) - return soap->error = SOAP_EOM; - if (tp->value) - { memcpy(s, tp->value, tp->size); - SOAP_FREE(soap, tp->value); - } - soap_save_block(soap, s + tp->size, 0); - tp->value = s; - tp->size = n; -#endif - } - do c = soap_get1(soap); - while (soap_blank(c)); - tp->visible = 2; /* seen this attribute w/ value */ -#ifdef WITH_DOM - if (att) - (*att)->data = soap_strdup(soap, tp->value); -#endif - } - else - tp->visible = 1; /* seen this attribute w/o value */ -#ifdef WITH_DOM - if (att) - att = &(*att)->next; -#endif - if (t && tp->value) - { if (soap_push_namespace(soap, t, tp->value)) - return soap->error; - } - } -#ifdef WITH_DOM - if (att) - { soap->dom->nstr = soap_current_namespace(soap, soap->tag); - for (att = &soap->dom->atts; *att; att = &(*att)->next) - (*att)->nstr = soap_current_namespace(soap, (*att)->name); - } -#endif - if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (!(soap->body = (c != '/'))) - do c = soap_get1(soap); - while (soap_blank(c)); -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { if (!soap->body && soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible && tp->value) - { -#ifndef WITH_NOIDREF - if (!strcmp(tp->name, "id")) - { if ((soap->version > 0 && !(soap->mode & SOAP_XML_TREE)) - || (soap->mode & SOAP_XML_GRAPH)) - { *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")) - { if (soap->version == 1 - || (soap->mode & SOAP_XML_GRAPH) - || (soap->mode & SOAP_ENC_MTOM)) - { strncpy(soap->href, tp->value, sizeof(soap->href) - 1); - soap->href[sizeof(soap->href)-1] = '\0'; - } - } - else -#endif - 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_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; - } - else if (soap->version == 1) - { if (!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_match_tag(soap, tp->name, "SOAP-ENC:offset")) - strncpy(soap->arrayOffset, tp->value, sizeof(soap->arrayOffset)); - else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:position")) - soap->position = soap_getposition(tp->value, soap->positions); - else if (!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:mustUnderstand") - && (!strcmp(tp->value, "1") || !strcmp(tp->value, "true"))) - soap->mustUnderstand = 1; - else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:actor")) - { if ((!soap->actor || strcmp(soap->actor, tp->value)) - && strcmp(tp->value, "http://schemas.xmlsoap.org/soap/actor/next")) - soap->other = 1; - } - } - else if (soap->version == 2) - { -#ifndef WITH_NOIDREF - if (!strcmp(tp->name, "ref") - || !soap_match_tag(soap, tp->name, "SOAP-ENC:ref")) - { *soap->href = '#'; - strncpy(soap->href + 1, tp->value, sizeof(soap->href) - 2); - soap->href[sizeof(soap->href)-1] = '\0'; - } - else -#endif - if (!soap_match_tag(soap, tp->name, "SOAP-ENC:itemType")) - strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1); - else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:arraySize")) - strncpy(soap->arraySize, tp->value, sizeof(soap->arraySize) - 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, "SOAP-ENV:role")) - { if ((!soap->actor || strcmp(soap->actor, tp->value)) - && strcmp(tp->value, "http://www.w3.org/2003/05/soap-envelope/role/next")) - soap->other = 1; - } - } - } - } - return soap->error = SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_retry(struct soap *soap) -{ soap->error = SOAP_OK; - soap_revert(soap); -} -#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 = 0xFFFFFF80UL; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_strdup(soap, s); - return SOAP_OK; - } -#endif - if (soap->mode & SOAP_C_UTFSTRING) - mask = 0; - t = s; - while ((c = *t++)) - { switch (c) - { - case 0x09: - if (flag) - { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, " ", 5)) - return soap->error; - s = t; - } - break; - case 0x0A: - 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 0x0D: - 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: -#ifndef WITH_LEANER -#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 -#endif -#ifndef WITH_NOSTRINGTOUTF8 - if ((c & mask) || !(c & 0xFFFFFFE0UL)) - { if (soap_send_raw(soap, s, t - s - 1) || soap_pututf8(soap, (unsigned char)c)) - return soap->error; - s = t; - } -#endif - } - } - 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; -#if !defined(WITH_LEANER) && defined(HAVE_WCTOMB) - char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8]; -#else - char buf[8]; -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { -#ifndef WITH_LEAN - struct soap_attribute *tp; - t = soap->tmpbuf; - *t = '<'; - t[sizeof(soap->tmpbuf)-1] = '\0'; - strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 2); - t += strlen(t); - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { if (t >= soap->tmpbuf + sizeof(soap->tmpbuf) - 2) - break; - *t++ = ' '; - strcpy(t, tp->name); - t += strlen(t); - if (t >= soap->tmpbuf + sizeof(soap->tmpbuf) - 2) - break; - if (tp->value) - { *t++ = '='; - *t++ = '"'; - strcpy(t, tp->value); - t += strlen(t); - *t++ = '"'; - } - } - } - *t++ = '>'; - *t = '\0'; - t = soap->tmpbuf; - m = (int)strlen(soap->tmpbuf); -#endif - n = 1; - soap->peeked = 0; - } - } -#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 && state != 1 && !(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: -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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 (soap_wchar)('<' | 0x80000000): - if (flag) - *s++ = '<'; - else - { *s++ = '&'; - t = (char*)"lt;"; - m = 3; - } - break; - case (soap_wchar)('>' | 0x80000000): - if (flag) - *s++ = '>'; - else - { *s++ = '&'; - t = (char*)"gt;"; - m = 3; - } - break; - case (soap_wchar)('&' | 0x80000000): - if (flag) - *s++ = '&'; - else - { *s++ = '&'; - t = (char*)"amp;"; - m = 4; - } - break; - case (soap_wchar)('"' | 0x80000000): - if (flag) - *s++ = '"'; - else - { *s++ = '&'; - t = (char*)"quot;"; - m = 5; - } - break; - case (soap_wchar)('\'' | 0x80000000): - if (flag) - *s++ = '\''; - else - { *s++ = '&'; - t = (char*)"apos;"; - m = 5; - } - break; - default: - if ((int)c == EOF) - goto end; -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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; - } -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (flag == 3) - soap->dom->tail = t; - else - soap->dom->data = t; - } -#endif - if (flag == 2) - if (soap_s2QName(soap, t, &t)) - return NULL; - return t; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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) - { wchar_t *r = (wchar_t*)s; - int n = 1; - while (*r++) - n++; - soap->dom->wide = r = (wchar_t*)soap_malloc(soap, n * sizeof(wchar_t)); - while (n--) - *r++ = *s++; - return SOAP_OK; - } -#endif - while ((c = *s++)) - { switch (c) - { - case 0x09: - if (flag) - t = " "; - else - t = "\t"; - break; - case 0x0A: - if (flag || !(soap->mode & SOAP_XML_CANONICAL)) - t = " "; - else - t = "\n"; - break; - case 0x0D: - 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 >= 0x20 && 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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; - char *t = NULL; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading wide string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { -#ifndef WITH_LEAN - struct soap_attribute *tp; - t = soap->tmpbuf; - *t = '<'; - t[sizeof(soap->tmpbuf)-1] = '\0'; - strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 2); - t += strlen(t); - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { if (t >= soap->tmpbuf + sizeof(soap->tmpbuf) - 2) - break; - *t++ = ' '; - strcpy(t, tp->name); - t += strlen(t); - if (t >= soap->tmpbuf + sizeof(soap->tmpbuf) - 2) - break; - if (tp->value) - { *t++ = '='; - *t++ = '"'; - strcpy(t, tp->value); - t += strlen(t); - *t++ = '"'; - } - } - } - *t++ = '>'; - *t = '\0'; - t = soap->tmpbuf; -#endif - n = 1; - soap->peeked = 0; - } - } - 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; - } - s = (wchar_t*)soap_save_block(soap, NULL, 0); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->wide = s; -#endif - return s; -} -#endif -#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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = (int)soap_strtol(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (int*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(int), 0, NULL); - else if (p) - { if (soap_s2int(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = soap_strtol(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (long*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(long), 0, NULL); - else if (p) - { if (soap_s2long(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOLL - char *r; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = strtoll(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -# ifdef HAVE_SSCANF - if (sscanf(s, SOAP_LONG_FORMAT, p) != 1) -# endif -#endif - 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, NULL)) - 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 (*soap->href) - p = (LONG64*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(LONG64), 0, NULL); - else if (p) - { if (soap_s2LONG64(soap, soap_value(soap), p)) - return 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 (s == r || *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, NULL)) - 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 (*soap->href) - p = (char*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(char), 0, NULL); - else if (p) - { if (soap_s2byte(soap, soap_value(soap), p)) - return 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 (s == r || *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, NULL)) - 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 (*soap->href) - p = (short*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(short), 0, NULL); - else if (p) - { if (soap_s2short(soap, soap_value(soap), p)) - return 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) -{ char *s; - if (soap_isnan((double)n)) - return "NaN"; - if (soap_ispinff(n)) - return "INF"; - if (soap_isninff(n)) - return "-INF"; - s = soap->tmpbuf; -#if defined(HAVE_SPRINTF_L) - sprintf_l(s, NULL, soap->float_format, n); -#else - sprintf(s, soap->float_format, n); - s = strchr(s, ','); /* convert decimal comma to DP */ - if (s) - *s = '.'; -#endif - return soap->tmpbuf; -} -#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 (!*s) - return soap->error = SOAP_TYPE; - 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 - { -/* On some systems, strtof appears to be broken or doesn't link: use with caution */ -#if defined(HAVE_STRTOF_L) - char *r; - *p = strtof_l((char*)s, &r, NULL); - if (*r) -#elif defined(HAVE_STRTOD_L) - char *r; - *p = (float)strtod_l(s, &r, NULL); - if (*r) -#elif defined(HAVE_STRTOF) - char *r; - *p = strtof((char*)s, &r); - if (*r) -#elif defined(HAVE_STRTOD) - char *r; - *p = (float)strtod(s, &r); - if (*r) -#endif -#if defined(HAVE_SSCANF_L) - if (sscanf_l(s, NULL, "%g", p) != 1) - soap->error = SOAP_TYPE; -#elif defined(HAVE_SSCANF) - if (sscanf(s, "%g", 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, NULL)) - 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 (*soap->href) - p = (float*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(float), 0, NULL); - else if (p) - { if (soap_s2float(soap, soap_value(soap), p)) - return 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) -{ char *s; - if (soap_isnan(n)) - return "NaN"; - if (soap_ispinfd(n)) - return "INF"; - if (soap_isninfd(n)) - return "-INF"; - s = soap->tmpbuf; -#if defined(HAVE_SPRINTF_L) - sprintf_l(s, NULL, soap->double_format, n); -#else - sprintf(s, soap->double_format, n); - s = strchr(s, ','); /* convert decimal comma to DP */ - if (s) - *s = '.'; -#endif - return soap->tmpbuf; -} -#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 (!*s) - return soap->error = SOAP_TYPE; - 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 - { -#if defined(HAVE_STRTOD_L) - char *r; - *p = strtod_l(s, &r, NULL); - if (*r) -#elif defined(HAVE_STRTOD) - char *r; - *p = strtod(s, &r); - if (*r) -#endif -#if defined(HAVE_SSCANF_L) - if (sscanf_l(s, NULL, "%lg", p) != 1) - soap->error = SOAP_TYPE; -#elif defined(HAVE_SSCANF) - if (sscanf(s, "%lg", 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, NULL)) - 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 (*soap->href) - p = (double*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(double), 0, NULL); - else if (p) - { if (soap_s2double(soap, soap_value(soap), p)) - return 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 (s == r || *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, NULL)) - 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 (*soap->href) - p = (unsigned char*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned char), 0, NULL); - else if (p) - { if (soap_s2unsignedByte(soap, soap_value(soap), p)) - return 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_unsignedShort2s(struct soap *soap, unsigned short n) -{ return soap_unsignedLong2s(soap, (unsigned long)n); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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 PALM_2 -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 (s == r || *r || n > 65535) - soap->error = SOAP_TYPE; - *p = (unsigned short)n; - } - return soap->error; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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, NULL)) - 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 (*soap->href) - p = (unsigned short*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned short), 0, NULL); - else if (p) - { if (soap_s2unsignedShort(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = (unsigned int)soap_strtoul(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (unsigned int*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned int), 0, NULL); - else if (p) - { if (soap_s2unsignedInt(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = soap_strtoul(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (unsigned long*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned long), 0, NULL); - else if (p) - { if (soap_s2unsignedLong(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOULL - char *r; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = strtoull(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -#ifdef HAVE_SSCANF - if (sscanf(s, SOAP_ULONG_FORMAT, p) != 1) -#endif -#endif - 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, NULL)) - 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 (*soap->href) - p = (ULONG64*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(ULONG64), 0, NULL); - else if (p) - { if (soap_s2ULONG64(soap, soap_value(soap), p)) - return 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) -{ if (s) - { if (!(*t = soap_strdup(soap, s))) - return soap->error = SOAP_EOM; - if (!(soap->mode & (SOAP_ENC_LATIN | SOAP_C_UTFSTRING))) - { /* TODO: consider truncating UTF8 to ASCII for regular XML attribute strings? */ - } - } - return soap->error; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_s2QName(struct soap *soap, const char *s, char **t) -{ if (s) - { soap->labidx = 0; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Normalized namespace(s) of QNames '%s'", s)); - /* convert (by prefix normalize prefix) all QNames in s */ - for (;;) - { size_t n; - struct soap_nlist *np; - register const char *p; - /* skip blanks */ - while (*s && soap_blank(*s)) - s++; - if (!*s) - break; - /* find next QName */ - n = 1; - while (s[n] && !soap_blank(s[n])) - n++; - np = soap->nlist; - /* if there is no namespace stack, or prefix is "xml" then copy string */ - if (!np || !strncmp(s, "xml:", 4)) - { soap_append_lab(soap, s, n); - } - else /* we normalize the QName by replacing its prefix */ - { p = strchr(s, ':'); - if (p) - { size_t k = p - s; - while (np && (strncmp(np->id, s, k) || np->id[k])) - np = np->next; - p++; - } - else - { while (np && *np->id) - np = np->next; - p = s; - } - /* replace prefix */ - if (np) - { if (np->index >= 0 && soap->local_namespaces) - { const char *q = soap->local_namespaces[np->index].id; - if (q) - soap_append_lab(soap, q, strlen(q)); - } - else if (np->ns) - { soap_append_lab(soap, "\"", 1); - soap_append_lab(soap, np->ns, strlen(np->ns)); - soap_append_lab(soap, "\"", 1); - } - else - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\nNamespace prefix of '%s' not defined (index=%d, URI=%s)\n", s, np->index, np->ns?np->ns:"")); - return soap->error = SOAP_NAMESPACE; - } - } - else /* no namespace: assume default "" namespace */ - { soap_append_lab(soap, "\"\"", 2); - } - soap_append_lab(soap, ":", 1); - soap_append_lab(soap, p, n - (p-s)); - } - /* advance to next and add spacing */ - s += n; - if (*s) - soap_append_lab(soap, " ", 1); - } - soap_append_lab(soap, SOAP_STR_EOS, 1); - *t = soap_strdup(soap, soap->labbuf); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, " into '%s'\n", *t)); - } - return soap->error; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_QName2s(struct soap *soap, const char *s) -{ const char *t = NULL; - if (s) - { soap->labidx = 0; - for (;;) - { size_t n; - /* skip blanks */ - while (*s && soap_blank(*s)) - s++; - if (!*s) - break; - /* find next QName */ - n = 1; - while (s[n] && !soap_blank(s[n])) - n++; - /* normal prefix: pass string as is */ - if (*s != '"') - { soap_append_lab(soap, s, n); -#ifndef WITH_LEAN - if ((soap->mode & SOAP_XML_CANONICAL)) - { const char *r = strchr(s, ':'); - if (r) - soap_utilize_ns(soap, s, r - s); - } -#endif - } - else /* URL-based string prefix */ - { const char *q; - s++; - q = strchr(s, '"'); - if (q) - { struct Namespace *p = soap->local_namespaces; - if (p) - { 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; - } - } - /* URL is in the namespace table? */ - if (p && p->id) - { soap_append_lab(soap, p->id, strlen(p->id)); - } - else /* not in namespace table: create xmlns binding */ - { char *r = soap_strdup(soap, s); - r[q-s] = '\0'; - sprintf(soap->tmpbuf, "xmlns:_%d", soap->idnum++); - soap_set_attr(soap, soap->tmpbuf, r); - soap_append_lab(soap, soap->tmpbuf + 6, strlen(soap->tmpbuf + 6)); - } - soap_append_lab(soap, q + 1, n - (q-s) - 1); - } - } - /* advance to next and add spacing */ - s += n; - if (*s) - soap_append_lab(soap, " ", 1); - } - soap_append_lab(soap, SOAP_STR_EOS, 1); - t = soap_strdup(soap, soap->labbuf); - } - return t; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_s2wchar(struct soap *soap, const char *s, wchar_t **t) -{ if (s) - { wchar_t *r; - *t = r = (wchar_t*)soap_malloc(soap, sizeof(wchar_t) * (strlen(s) + 1)); - if (!r) - return soap->error; - if (soap->mode & SOAP_ENC_LATIN) - { while (*s) - *r++ = (wchar_t)*s++; - } - else - { /* Convert UTF8 to wchar */ - while (*s) - { register soap_wchar c, c1, c2, c3, c4; - c = *s++; - if (c < 0x80) - *r++ = (wchar_t)c; - else - { c1 = (soap_wchar)*s++ & 0x3F; - if (c < 0xE0) - *r++ = (wchar_t)(((soap_wchar)(c & 0x1F) << 6) | c1); - else - { c2 = (soap_wchar)*s++ & 0x3F; - if (c < 0xF0) - *r++ = (wchar_t)(((soap_wchar)(c & 0x0F) << 12) | (c1 << 6) | c2); - else - { c3 = (soap_wchar)*s++ & 0x3F; - if (c < 0xF8) - *r++ = (wchar_t)(((soap_wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3); - else - { c4 = (soap_wchar)*s++ & 0x3F; - if (c < 0xFC) - *r++ = (wchar_t)(((soap_wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4); - else - *r++ = (wchar_t)(((soap_wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (soap_wchar)(*s++ & 0x3F)); - } - } - } - } - } - } - *r = L'\0'; - } - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_wchar2s(struct soap *soap, const wchar_t *s) -{ register soap_wchar c; - register char *r, *t; - const wchar_t *q = s; - size_t n = 0; - while ((c = *q++)) - { if (c > 0 && c < 0x80) - n++; - else - n += 6; - } - r = t = (char*)soap_malloc(soap, n + 1); - if (r) - { /* Convert wchar to UTF8 */ - while ((c = *s++)) - { if (c > 0 && c < 0x80) - *t++ = (char)c; - else - { 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'; - } - return r; -} -#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) - return soap->error; - if (!**p && (soap->mode & SOAP_C_NILSTRING)) - return soap_element_null(soap, tag, id, type); - if (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, NULL)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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; - if (!**p && tag && *tag == '-') - { soap->error = SOAP_NO_TAG; - return NULL; - } - } - else if (tag && *tag == '-') - { soap->error = SOAP_NO_TAG; - return NULL; - } - else if (soap->null) - *p = NULL; - else - *p = soap_strdup(soap, SOAP_STR_EOS); - if (*soap->href) - 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 WITH_LEANER -#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) - return soap->error; - if (!**p && (soap->mode & SOAP_C_NILSTRING)) - return soap_element_null(soap, tag, id, type); - if (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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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, NULL)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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; - if (!**p && tag && *tag == '-') - { soap->error = SOAP_NO_TAG; - return NULL; - } - } - else if (tag && *tag == '-') - { soap->error = SOAP_NO_TAG; - return NULL; - } - else if (soap->null) - *p = NULL; - else - *p = soap_wstrdup(soap, (wchar_t*)SOAP_STR_EOS); - if (*soap->href) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -time_t -SOAP_FMAC2 -soap_timegm(struct tm *T) -{ -#if defined(HAVE_TIMEGM) - return timegm(T); -#else - time_t t, g, z; - struct tm tm; - t = mktime(T); - if (t == (time_t)-1) - return (time_t)-1; -#ifdef HAVE_GMTIME_R - gmtime_r(&t, &tm); -#else - tm = *gmtime(&t); -#endif - tm.tm_isdst = 0; - g = mktime(&tm); - if (g == (time_t)-1) - return (time_t)-1; - z = g - t; - return t - z; -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_dateTime2s(struct soap *soap, time_t n) -{ struct tm T, *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); -#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+(pT->tm_isdst!=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+(pT->tm_isdst!=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)) - { -#ifdef __BORLANDC__ - ::ftime(&t); -#else - ftime(&t); -#endif - strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); - sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60); - } -#else - if ((pT = localtime(&n))) - { -#ifdef __BORLANDC__ - ::ftime(&t); -#else - ftime(&t); -#endif - strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); - sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=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); -#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[32]; - const char *t; - memset((void*)&T, 0, sizeof(T)); - zone[sizeof(zone)-1] = '\0'; - if (strchr(s, '-')) - t = "%d-%d-%dT%d:%d:%d%31s"; - else if (strchr(s, ':')) - t = "%4d%2d%2dT%d:%d:%d%31s"; - else /* parse non-XSD-standard alternative ISO 8601 format */ - t = "%4d%2d%2dT%2d%2d%2d%31s"; - sscanf(s, t, &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 == '+' || *s == '-') - { int h = 0, m = 0; - if (s[3] == ':') - { sscanf(s, "%d:%d", &h, &m); - if (h < 0) - m = -m; - } - else - { m = (int)atol(s); - h = m / 100; - m = m % 100; - } - T.tm_hour -= h; - T.tm_min -= m; - } - T.tm_isdst = 0; - *p = soap_timegm(&T); - } - else - { T.tm_isdst = -1; - *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, NULL)) - 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 (*soap->href) - p = (time_t*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(time_t), 0, NULL); - else if (p) - { if (soap_s2dateTime(soap, soap_value(soap), p)) - return 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, const char *type) -{ int i; - const char *t = NULL; - if (tag && *tag != '-') - { if (soap->local_namespaces && (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++; - if (soap_element(soap, t, 0, type) - || soap_attribute(soap, "xmlns", soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS) - || soap_element_start_end_out(soap, NULL)) - return soap->error; - } - else - { t = tag; - if (soap_element_begin_out(soap, t, 0, type)) - return soap->error; - } - } - if (p && *p) - { if (soap_send(soap, *p)) - return soap->error; - } - if (t) - return soap_element_end_out(soap, t); - 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, NULL)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - { if (!(p = (char**)soap_malloc(soap, sizeof(char*)))) - return NULL; - } - if (soap->body) - { *p = soap_string_in(soap, 0, -1, -1); - if (!*p) - return NULL; - if (!**p && tag && *tag == '-') - { soap->error = SOAP_NO_TAG; - return NULL; - } - } - else if (tag && *tag == '-') - { soap->error = SOAP_NO_TAG; - return NULL; - } - else if (soap->null) - *p = NULL; - else - *p = soap_strdup(soap, SOAP_STR_EOS); - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p, const char *type) -{ int i; - const char *t = NULL; - if (tag && *tag != '-') - { if (soap->local_namespaces && (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++; - if (soap_element(soap, t, 0, type) - || soap_attribute(soap, "xmlns", soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS) - || soap_element_start_end_out(soap, NULL)) - return soap->error; - } - else - { t = tag; - if (soap_element_begin_out(soap, t, 0, type)) - return soap->error; - } - if (soap_send(soap, soap->tmpbuf)) - return soap->error; - } - if (p) - { wchar_t c; - const wchar_t *s = *p; - while ((c = *s++)) - { if (soap_pututf8(soap, (unsigned long)c)) - return soap->error; - } - } - if (t) - return soap_element_end_out(soap, t); - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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, NULL)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - { if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*)))) - return NULL; - } - if (soap->body) - { *p = soap_wstring_in(soap, 0, -1, -1); - if (!*p) - return NULL; - if (!**p && tag && *tag == '-') - { soap->error = SOAP_NO_TAG; - return NULL; - } - } - else if (tag && *tag == '-') - { soap->error = SOAP_NO_TAG; - return NULL; - } - else if (soap->null) - *p = NULL; - else - *p = soap_wstrdup(soap, (wchar_t*)SOAP_STR_EOS); - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_value(struct soap *soap) -{ register size_t i; - register soap_wchar c = 0; - register char *s = soap->tmpbuf; - if (!soap->body) - return SOAP_STR_EOS; - do c = soap_get(soap); - while (soap_blank(c)); - for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++) - { if (c == SOAP_TT || (int)c == EOF) - break; - *s++ = (char)c; - c = soap_get(soap); - } - for (s--; i > 0; i--, s--) - { if (!soap_blank(*s)) - break; - } - s[1] = '\0'; - if ((int)c == EOF || c == SOAP_TT) - soap_unget(soap, c); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element content value='%s'\n", soap->tmpbuf)); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->data = soap_strdup(soap, soap->tmpbuf); -#endif - return soap->tmpbuf; /* return non-null pointer */ -} -#endif - -/******************************************************************************/ -#if !defined(WITH_LEANER) || !defined(WITH_NOHTTP) -#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' || c == '\n') - break; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - *s++ = (char)c; - } - if (c != '\n') - c = soap_getchar(soap); /* got \r or something else, now get \n */ - if (c == '\n') - { *s = '\0'; - if (i+1 == len) /* empty line: end of HTTP/MIME header */ - break; - c = soap_get0(soap); - if (c != ' ' && c != '\t') /* HTTP line continuation? */ - break; - } - else if ((int)c == EOF) - return soap->error = SOAP_EOF; - } - if (i < 0) - return soap->error = SOAP_HDR; - return SOAP_OK; -} -#endif -#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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the message size with attachments, current count=%lu\n", (unsigned long)count)); - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - { 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 content is %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); - /* count Content-Transfer-Encoding: ...\r\n */ - s = soap_code_str(mime_codes, content->encoding); - 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->description); - /* count \r\n...content */ - count += 2 + content->size; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Size of MIME attachment content is %lu bytes\n", (unsigned long)content->size)); - } - /* count \r\n--boundary-- */ - count += 6 + n; - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New count is %lu bytes\n", (unsigned long)count)); - 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] = (char)(optype >> 8); - s[1] = (char)(optype & 0xFF); - s[2] = (char)(n >> 8); - s[3] = (char)(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 (idlen > 0x0000FFFF) - idlen = 0x0000FFFF; - } - if (soap->dime.type) - { typelen = strlen(soap->dime.type); - if (typelen > 0x0000FFFF) - typelen = 0x0000FFFF; - } - tmp[0] = SOAP_DIME_VERSION | (soap->dime.flags & 0x7); - tmp[1] = soap->dime.flags & 0xF0; - tmp[2] = (char)(optlen >> 8); - tmp[3] = (char)(optlen & 0xFF); - tmp[4] = (char)(idlen >> 8); - tmp[5] = (char)(idlen & 0xFF); - tmp[6] = (char)(typelen >> 8); - tmp[7] = (char)(typelen & 0xFF); - tmp[8] = (char)(soap->dime.size >> 24); - tmp[9] = (char)((soap->dime.size >> 16) & 0xFF); - tmp[10] = (char)((soap->dime.size >> 8) & 0xFF); - tmp[11] = (char)(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 (!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)content->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 size_t i; - register char *s; - register 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) -{ while (soap->dime.flags & SOAP_DIME_CF) - { if (soap_getdimehdr(soap)) - return soap->error; - if (soap_move(soap, (long)soap->dime.size)) - return soap->error = SOAP_EOF; - } - if (soap_move(soap, (long)(((soap->dime.size+3)&(~3))-soap_tell(soap)))) - return soap->error = SOAP_EOF; - for (;;) - { register struct soap_multipart *content; - if (soap_getdimehdr(soap)) - break; - 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; - id = soap->dime.id; - type = soap->dime.type; - options = soap->dime.options; - if (soap_new_block(soap)) - return SOAP_EOM; - for (;;) - { register soap_wchar c; - register size_t i; - register char *s; - 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; - if (soap->error) - return soap->error; - soap_resolve_attachment(soap, content); - } - if (soap->error != SOAP_DIME_END) - return soap->error; - return soap->error = SOAP_OK; -} -#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-Disposition")) - content->id = soap_strdup(soap, soap_get_header_attribute(soap, val, "name")); - 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_code_int(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) -{ while (soap_get_mime_attachment(soap, NULL)) - ; - return soap->error; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_post_check_mime_attachments(struct soap *soap) -{ soap->imode |= SOAP_MIME_POSTCHECK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_check_mime_attachments(struct soap *soap) -{ if (soap->mode & SOAP_MIME_POSTCHECK) - return soap_get_mime_attachment(soap, NULL) != NULL; - return 0; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -struct soap_multipart * -SOAP_FMAC2 -soap_get_mime_attachment(struct soap *soap, void *handle) -{ register soap_wchar c = 0; - register size_t i, m = 0; - register char *s, *t = NULL; - register struct soap_multipart *content; - register short flag = 0; - if (!(soap->mode & SOAP_ENC_MIME)) - return NULL; - content = soap->mime.last; - if (!content) - { if (soap_getmimehdr(soap)) - return NULL; - content = soap->mime.last; - } - else if (content != soap->mime.first) - { if (soap->fmimewriteopen && ((content->ptr = (char*)soap->fmimewriteopen(soap, (void*)handle, content->id, content->type, content->description, content->encoding)) || soap->error)) - { if (!content->ptr) - return NULL; - } - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id=%s type=%s\n", content->id?content->id:"", content->type?content->type:"")); - if (!content->ptr && soap_new_block(soap)) - { soap->error = SOAP_EOM; - return NULL; - } - for (;;) - { if (content->ptr) - s = soap->tmpbuf; - else if (!(s = (char*)soap_push_block(soap, sizeof(soap->tmpbuf)))) - { soap->error = SOAP_EOM; - return NULL; - } - for (i = 0; i < sizeof(soap->tmpbuf); i++) - { if (m > 0) - { *s++ = *t++; - m--; - } - else - { if (!flag) - { c = soap_get1(soap); - if ((int)c == EOF) - { soap->error = SOAP_EOF; - return NULL; - } - } - if (flag || c == '\r') - { t = soap->msgbuf; - memset(t, 0, sizeof(soap->msgbuf)); - strcpy(t, "\n--"); - if (soap->mime.boundary) - strncat(t, soap->mime.boundary, sizeof(soap->msgbuf)-4); - do c = soap_getchar(soap); - while (c == *t++); - if ((int)c == EOF) - { soap->error = SOAP_EOF; - return NULL; - } - if (!*--t) - goto end; - *t = (char)c; - flag = (c == '\r'); - m = t - soap->msgbuf + 1 - flag; - t = soap->msgbuf; - c = '\r'; - } - *s++ = (char)c; - } - } - if (content->ptr && soap->fmimewrite) - { if ((soap->error = soap->fmimewrite(soap, (void*)content->ptr, soap->tmpbuf, i))) - break; - } - } -end: - *s = '\0'; /* force 0-terminated */ - if (content->ptr) - { if (!soap->error && soap->fmimewrite) - soap->error = soap->fmimewrite(soap, (void*)content->ptr, soap->tmpbuf, i); - if (soap->fmimewriteclose) - soap->fmimewriteclose(soap, (void*)content->ptr); - if (soap->error) - return NULL; - } - else - { content->size = soap_size_block(soap, i+1)-1; - content->ptr = soap_save_block(soap, NULL, 0); - } - soap_resolve_attachment(soap, content); - if (c == '-' && soap_getchar(soap) == '-') - { soap->mode &= ~SOAP_ENC_MIME; - if ((soap->mode & SOAP_MIME_POSTCHECK) && soap_end_recv(soap)) - return NULL; - } - else - { while (c != '\r' && (int)c != EOF && soap_blank(c)) - c = soap_getchar(soap); - if (c != '\r' || soap_getchar(soap) != '\n') - { soap->error = SOAP_MIME_ERROR; - return NULL; - } - if (soap_getmimehdr(soap)) - return NULL; - } - return content; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_match_cid(struct soap *soap, const char *s, const char *t) -{ register size_t n; - if (!s) - return 1; - if (!strcmp(s, t)) - return 0; - if (!strncmp(s, "cid:", 4)) - s += 4; - n = strlen(t); - if (*t == '<') - { t++; - n -= 2; - } - if (!strncmp(s, t, n) && !s[n]) - return 0; - soap_decode(soap->tmpbuf, sizeof(soap->tmpbuf), s, SOAP_STR_EOS); - if (!strncmp(soap->tmpbuf, t, n) && !soap->tmpbuf[n]) - return 0; - return 1; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -static void -soap_resolve_attachment(struct soap *soap, struct soap_multipart *content) -{ if (content->id) - { register struct soap_xlist **xp = &soap->xlist; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving attachment data for id=%s\n", content->id)); - while (*xp) - { register struct soap_xlist *xq = *xp; - if (!soap_match_cid(soap, xq->id, content->id)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Found matching attachment %s for content id=%s\n", xq->id, content->id)); - *xp = xq->next; - *xq->ptr = (unsigned char*)content->ptr; - *xq->size = (int)content->size; - *xq->type = (char*)content->type; - if (content->options) - *xq->options = (char*)content->options; - else - *xq->options = (char*)content->description; - SOAP_FREE(soap, xq); - } - else - xp = &(*xp)->next; - } - } -} -#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_code_str(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) - { void *handle; - if (soap->fmimereadopen && ((handle = soap->fmimereadopen(soap, (void*)content->ptr, content->id, content->type, content->description)) || soap->error)) - { size_t size = content->size; - if (!handle) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimereadopen failed\n")); - return soap->error; - } - if (soap_putmimehdr(soap, content)) - return soap->error; - if (!size) - { if ((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 MIME\n")); - do - { size = soap->fmimeread(soap, handle, soap->tmpbuf, sizeof(soap->tmpbuf)); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimeread returned %lu bytes\n", (unsigned long)size)); - if (soap_send_raw(soap, soap->tmpbuf, size)) - break; - } while (size); - } - else - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error: cannot chunk streaming MIME (no HTTP chunking)\n")); - } - } - else - { do - { size_t bufsize; - if (size < sizeof(soap->tmpbuf)) - bufsize = size; - else - bufsize = sizeof(soap->tmpbuf); - if (!(bufsize = soap->fmimeread(soap, handle, soap->tmpbuf, bufsize))) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)content->size)); - soap->error = SOAP_EOF; - break; - } - if (soap_send_raw(soap, soap->tmpbuf, bufsize)) - break; - size -= bufsize; - } while (size); - } - if (soap->fmimereadclose) - soap->fmimereadclose(soap, handle); - } - else - { 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, "--"); -} -#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 = 64; - s = soap->mime.boundary = (char*)soap_malloc(soap, n + 1); - if (!s) - return; - } - strcpy(s, "=="); - s += 2; - n -= 4; - while (n) - { *s++ = soap_base64o[soap_random & 0x3F]; - n--; - } - strcpy(s, "=="); - } - if (!soap->mime.start) - soap->mime.start = ""; -} -#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; - if (soap->fmimeread) - return SOAP_OK; - 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 - -/******************************************************************************\ - * - * HTTP cookie handling - * -\******************************************************************************/ - -#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 && !strchr("()<>@,;:\\\"/[]?={}", 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 = SOAP_STR_EOS; - else if (*path == '/') - path++; - n = strlen(path); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Search cookie %s domain=%s path=%s\n", name, domain?domain:"(null)", path?path:"(null)")); - for (p = soap->cookies; p; p = p->next) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie in database: %s=%s domain=%s path=%s env=%hd\n", p->name, p->value?p->value:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", p->env)); - if (!strcmp(p->name, name) - && p->domain - && p->path - && !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; - if (!domain) - domain = soap->cookie_domain; - if (!path) - path = soap->cookie_path; - if (!path) - path = SOAP_STR_EOS; - else if (*path == '/') - path++; - q = soap_cookie(soap, name, domain, path); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set %scookie: %s=%s domain=%s path=%s\n", q ? "" : "new ", name, value?value:"(null)", domain?domain:"(null)", path?path:"(null)")); - if (!q) - { if ((q = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie)))) - { if ((q->name = (char*)SOAP_MALLOC(soap, strlen(name)+1))) - strcpy(q->name, name); - q->value = NULL; - q->domain = NULL; - q->path = NULL; - q->expire = 0; - q->maxage = -1; - q->version = 1; - q->secure = 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 && path && strcmp((*p)->path, path) < 0) - break; - if (n) - { q->next = *p; - *p = q; - } - else - { SOAP_FREE(soap, q->name); - SOAP_FREE(soap, q); - q = NULL; - } - } - } - else - q->modified = 1; - if (q) - { if (q->value) - { SOAP_FREE(soap, q->value); - q->value = NULL; - } - if (q->domain) - { SOAP_FREE(soap, q->domain); - q->domain = NULL; - } - if (q->path) - { SOAP_FREE(soap, q->path); - q->path = NULL; - } - if (value && *value && (q->value = (char*)SOAP_MALLOC(soap, strlen(value)+1))) - strcpy(q->value, value); - if (domain && (q->domain = (char*)SOAP_MALLOC(soap, strlen(domain)+1))) - strcpy(q->domain, domain); - if (path && (q->path = (char*)SOAP_MALLOC(soap, strlen(path)+1))) - strcpy(q->path, path); - q->session = 1; - q->env = 0; - } - 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) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie domain not set\n", name?name:"(null)")); - return; - } - if (!path) - path = soap->cookie_path; - if (!path) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie path not set\n", name?name:"(null)")); - 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(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, 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 -char * -SOAP_FMAC2 -soap_env_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)) && p->env) - return p->value; - return NULL; -} - -/******************************************************************************/ -SOAP_FMAC1 -time_t -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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie expiration max-age %ld: %s domain=%s path=%s\n", expire, name, domain?domain:"(null)", path?path:"(null)")); - if ((p = soap_cookie(soap, name, domain, path))) - { p->maxage = 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 -#ifdef WITH_OPENSSL - || (!p->env && !soap->ssl == !p->secure) -#endif - ) - { 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) - { strcpy(s, ";Domain="); - strcat(s, p->domain); - } - else if (soap->cookie_domain && (int)strlen(soap->cookie_domain) < tmp-s+4064) - { strcpy(s, ";Domain="); - strcat(s, soap->cookie_domain); - } - strcat(s, ";Path=/"); - s += strlen(s); - if (p->path) - t = p->path; - else - t = soap->cookie_path; - if (t) - { if (*t == '/') - t++; - if ((int)strlen(t) < tmp-s+4064) - { if (strchr(t, '%')) /* already URL encoded? */ - { strcpy(s, t); - s += strlen(s); - } - else - s += soap_encode_cookie(t, s, tmp-s+4064); - } - } - if (p->version > 0 && s-tmp < 4060) - { sprintf(s, ";Version=%u", p->version); - s += strlen(s); - } - if (p->maxage >= 0 && s-tmp < 4060) - { sprintf(s, ";Max-Age=%ld", p->maxage); - s += strlen(s); - } - if (s-tmp < 4073 - && (p->secure -#ifdef WITH_OPENSSL - || soap->ssl -#endif - )) - strcpy(s, ";Secure"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set-Cookie: %s\n", tmp)); - if ((soap->error = 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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending cookies for domain=%s path=%s\n", domain, path)); - if (*path == '/') - path++; - while ((q = *p)) - { if (q->expire && now > q->expire) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name)); - SOAP_FREE(soap, q->name); - if (q->value) - SOAP_FREE(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, q); - } - else - { int flag; - char *t = q->domain; - size_t n = 0; - if (!t) - flag = 1; - else - { const char *r = strchr(t, ':'); - if (r) - n = r - t; - else - n = strlen(t); - flag = !strncmp(t, domain, n); - } - /* domain-level cookies */ - if (!flag) - { struct hostent *hostent = gethostbyname((char*)domain); - if (hostent) - { const char *r = strchr(hostent->h_name, '.'); - if (!r) - r = hostent->h_name; - flag = !strncmp(t, r, n); - } - } - if (flag - && (!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 && *q->path && (int)strlen(q->path) < tmp-s+4080) - { sprintf(s, ";$Path=\"/%s\"", (*q->path == '/' ? q->path + 1 : 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->error = soap->fposthdr(soap, "Cookie", tmp))) - return soap->error; - } - 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->path) - SOAP_FREE(soap, p->path); - p->path = t; - } - else - { if (path) - SOAP_FREE(soap, 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->domain) - SOAP_FREE(soap, p->domain); - p->domain = t; - } - else - { if (domain) - SOAP_FREE(soap, domain); - domain = t; - } - } - else if (p && !soap_tag_cmp(tmp, "Path")) - { if (p->path) - SOAP_FREE(soap, p->path); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->path = (char*)SOAP_MALLOC(soap, strlen(tmp)+1))) - strcpy(p->path, tmp); - } - else - p->path = NULL; - } - else if (p && !soap_tag_cmp(tmp, "Domain")) - { if (p->domain) - SOAP_FREE(soap, p->domain); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->domain = (char*)SOAP_MALLOC(soap, 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 = (int)(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:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if ((p = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie)))) - { p->name = (char*)SOAP_MALLOC(soap, strlen(tmp)+1); - strcpy(p->name, tmp); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { p->value = (char*)SOAP_MALLOC(soap, strlen(tmp)+1); - strcpy(p->value, tmp); - } - else - p->value = NULL; - if (domain) - p->domain = domain; - else if (*soap->host) - { p->domain = (char*)SOAP_MALLOC(soap, strlen(soap->host)+1); - strcpy(p->domain, soap->host); - } - else - p->domain = NULL; - if (path) - p->path = path; - else if (soap->path && *soap->path) - { p->path = (char*)SOAP_MALLOC(soap, strlen(soap->path)+1); - strcpy(p->path, soap->path); - } - else - { p->path = (char*)SOAP_MALLOC(soap, 2); - strcpy(p->path, "/"); - } - p->expire = 0; - p->secure = 0; - p->version = version; - } - } - } - 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:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if (domain) - SOAP_FREE(soap, domain); - if (path) - SOAP_FREE(soap, 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 *copy, const 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(copy, sizeof(struct soap_cookie)))) - return r; - **q = *p; - if (p->name) - { if (((*q)->name = (char*)SOAP_MALLOC(copy, strlen(p->name)+1))) - strcpy((*q)->name, p->name); - } - if (p->value) - { if (((*q)->value = (char*)SOAP_MALLOC(copy, strlen(p->value)+1))) - strcpy((*q)->value, p->value); - } - if (p->domain) - { if (((*q)->domain = (char*)SOAP_MALLOC(copy, strlen(p->domain)+1))) - strcpy((*q)->domain, p->domain); - } - if (p->path) - { if (((*q)->path = (char*)SOAP_MALLOC(copy, 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } -} - -/******************************************************************************/ -#endif /* WITH_COOKIES */ - -/******************************************************************************/ -#ifdef WITH_GZIP -#ifndef PALM_1 -static int -soap_getgziphdr(struct soap *soap) -{ int i; - soap_wchar c = 0, 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)c != 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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for input\n")); - soap->error = SOAP_OK; - soap_free_temp(soap); - soap_set_local_namespaces(soap); - soap->version = 0; /* don't assume we're parsing SOAP content by default */ -#ifndef WITH_NOIDREF - soap_free_iht(soap); -#endif - 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->action = NULL; - soap->header = NULL; - soap->fault = NULL; - soap->status = 0; -#ifndef WITH_LEANER - soap->dom = 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; - soap->xlist = NULL; -#endif -#ifdef WIN32 -#ifndef UNDER_CE -#ifndef WITH_FASTCGI - if (!soap_valid_socket(soap->socket)) -#ifdef __BORLANDC__ - setmode(soap->recvfd, O_BINARY); -#else - _setmode(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 -#ifndef WITH_LEANER - 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")); - if (!soap->z_buf) - soap->z_buf = (char*)SOAP_MALLOC(soap, SOAP_BUFLEN); - 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 -#ifndef WITH_LEANER - 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 -#endif - { while (soap_blank(c)) - c = soap_getchar(soap); - } - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifndef WITH_NOHTTP - /* if not XML or (start of)BOM or MIME/DIME/ZLIB, assume HTTP header */ - if (c != '<' && c != 0xEF && !(soap->mode & (SOAP_ENC_MIME | SOAP_ENC_DIME | SOAP_ENC_ZLIB))) - { soap->mode &= ~SOAP_IO; - soap->error = soap->fparse(soap); - if (soap->error && soap->error < SOAP_STOP) - { soap->keep_alive = 0; /* force close later */ - return soap->error; - } - if (soap->error == SOAP_STOP) - return soap->error; - if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) - { soap->chunkbuflen = soap->buflen; - soap->buflen = soap->bufidx; - soap->chunksize = 0; - } -#ifndef WITH_LEANER - else if (soap->fpreparerecv && soap->buflen != soap->bufidx) - soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx); -#endif - /* Note: fparse should not use soap_unget to push back last char */ - if (soap_get0(soap) == (int)EOF) - { if (soap->status == 200) - return soap->error = SOAP_NO_DATA; - return soap->error = soap->status; - } -#ifdef WITH_ZLIB - if (soap->zlib_in != SOAP_ZLIB_NONE) - { -#ifdef WITH_GZIP - if (soap->zlib_in != SOAP_ZLIB_DEFLATE) - { 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->z_crc = crc32(0L, NULL, 0); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip initialized\n")); - } - else - { soap_revget1(soap); - if (inflateInit(soap->d_stream) != Z_OK) - return soap->error = SOAP_ZLIB_ERROR; - soap->zlib_in = SOAP_ZLIB_DEFLATE; - } - } - 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; - if (!soap->z_buf) - soap->z_buf = (char*)SOAP_MALLOC(soap, SOAP_BUFLEN); - 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 - if (soap->error) - { if (soap->error == SOAP_FORM && soap->fform) - { soap->error = soap->fform(soap); - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - } - return soap->error; - } - } -#endif -#ifndef WITH_LEANER - if (soap->mode & SOAP_ENC_MIME) - { if (soap_getmimehdr(soap)) - return soap->error; - if (soap->mime.start) - { do - { if (!soap->mime.last->id) - break; - if (!soap_match_cid(soap, soap->mime.start, soap->mime.last->id)) - break; - } while (soap_get_mime_attachment(soap, NULL)); - } - 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 WITH_NOHTTP -#ifndef PALM_1 -static int -http_parse(struct soap *soap) -{ char header[SOAP_HDRLEN], *s; - unsigned short httpcmd = 0, status = 0, k = 0; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for HTTP request/response...\n")); - *soap->endpoint = '\0'; - soap->length = 0; - soap->userid = NULL; - soap->passwd = NULL; - soap->action = NULL; - soap->authrealm = NULL; - soap->proxy_from = NULL; - soap->http_content = NULL; - soap->status = 0; - do - { if (soap_getline(soap, soap->msgbuf, sizeof(soap->msgbuf))) - { if (soap->error == SOAP_EOF) - return SOAP_EOF; - return soap->error = 414; - } - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP status: %s\n", soap->msgbuf)); - for (;;) - { if (soap_getline(soap, header, SOAP_HDRLEN)) - { if (soap->error == SOAP_EOF) - { soap->error = SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "EOF in HTTP header, continue anyway\n")); - break; - } - return soap->error; - } - if (!*header) - break; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP header: %s\n", header)); - s = strchr(header, ':'); - if (s) - { char *t; - *s = '\0'; - do s++; - while (*s && *s <= 32); - if (*s == '"') - s++; - t = s + strlen(s) - 1; - while (t > s && *t <= 32) - t--; - if (t >= s && *t == '"') - t--; - t[1] = '\0'; - if ((soap->error = soap->fparsehdr(soap, header, s))) - { if (soap->error < SOAP_STOP) - return soap->error; - status = soap->error; - soap->error = SOAP_OK; - } - } - } - if ((s = strchr(soap->msgbuf, ' '))) - { k = (unsigned short)soap_strtoul(s, &s, 10); - if (!soap_blank(*s)) - k = 0; - } - else - k = 0; - } while (k == 100); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Finished HTTP header parsing, status = %d\n", k)); - 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 (k == 0) - { size_t l = 0; - if (s) - { if (!strncmp(soap->msgbuf, "POST ", l = 5)) - httpcmd = 1; - else if (!strncmp(soap->msgbuf, "GET ", l = 4)) - httpcmd = 2; - else if (!strncmp(soap->msgbuf, "PUT ", l = 4)) - httpcmd = 3; - else if (!strncmp(soap->msgbuf, "DELETE ", l = 7)) - httpcmd = 4; - else if (!strncmp(soap->msgbuf, "HEAD ", l = 5)) - httpcmd = 5; - } - if (s && httpcmd) - { size_t m = strlen(soap->endpoint); - size_t n = m + (s - soap->msgbuf) - l - 1; - if (m > n) - m = n; - if (n >= sizeof(soap->endpoint)) - n = sizeof(soap->endpoint) - 1; - strncpy(soap->path, soap->msgbuf + l, n - m); - soap->path[n - m] = '\0'; - strcat(soap->endpoint, soap->path); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint)); - if (httpcmd > 1) - { switch (httpcmd) - { case 2: soap->error = soap->fget(soap); break; - case 3: soap->error = soap->fput(soap); break; - case 4: soap->error = soap->fdel(soap); break; - case 5: soap->error = soap->fhead(soap); break; - default: soap->error = SOAP_HTTP_METHOD; break; - } - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - return soap->error; - } - if (status) - return soap->error = status; - } - else if (status) - return soap->error = status; - else if (s) - return soap->error = 405; - } - soap->status = k; - /* Status OK (HTTP 200) */ - if (k == 0 || k == 200) - return SOAP_OK; - /* Status 201 (Created), 202 (Accepted), ... and HTTP 400 and 500 errors. - Only keep parsing HTTP body when content-length>0 or chunked is set. - */ - if (((k > 200 && k <= 299) || k == 400 || k == 500) && (soap->length > 0 || (soap->imode & SOAP_IO) == SOAP_IO_CHUNK)) - return SOAP_OK; - /* HTTP 400 and 500 headers are supposed to set content-length or chunked. - For those that don't we keep parsing the body only if content type is - given and connection closes. - */ - if ((k == 400 || k == 500) && (soap->http_content || soap->keep_alive == 0)) - return SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP error %d\n", k)); - return soap_set_receiver_error(soap, "HTTP Error", soap->msgbuf, k); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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")) - { const char *action; - soap->http_content = soap_strdup(soap, val); - 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_get_header_attribute(soap, val, "multipart/form-data")) - { 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; - } - action = soap_get_header_attribute(soap, val, "action"); - if (action) - { if (*action == '"') - { soap->action = soap_strdup(soap, action + 1); - soap->action[strlen(soap->action) - 1] = '\0'; - } - else - soap->action = soap_strdup(soap, action); - } - } -#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 *")) - { int 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 == '"') - { soap->action = soap_strdup(soap, val + 1); - soap->action[strlen(soap->action) - 1] = '\0'; - } - else - soap->action = soap_strdup(soap, val); - } - 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, "X-Forwarded-For")) - { soap->proxy_from = soap_strdup(soap, val); - } -#ifdef WITH_COOKIES - else if (!soap_tag_cmp(key, "Cookie") - || !soap_tag_cmp(key, "Cookie2") - || !soap_tag_cmp(key, "Set-Cookie") - || !soap_tag_cmp(key, "Set-Cookie2")) - { soap_getcookies(soap, val); - } -#endif - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 (*s && !soap_blank(*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 -#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 && strlen(soap->mime.boundary) + strlen(soap->mime.start) < sizeof(soap->tmpbuf) - 80 ) - { const char *s; - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - s = "application/dime"; - else if (soap->version == 2) - { if (soap->mode & SOAP_ENC_MTOM) - s = "application/xop+xml; charset=utf-8; type=\"application/soap+xml\""; - else - 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->mode & SOAP_ENC_MTOM)) - { 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)) + (soap->dime.type ? ((strlen(soap->dime.type)+3)&(~3)) : 0); - } - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - 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, NULL)) - { -#ifndef WITH_LEAN - if (soap->error == SOAP_TAG_MISMATCH && !soap_element_begin_in(soap, "html", 0, NULL)) - { /* get HTML from buffer, stop receiving to avoid HTML parsing issues */ - char *s; -#ifndef WITH_NOIO - size_t (*f)(struct soap*, char*, size_t) = soap->frecv; - soap->frecv = frecv_stop; -#endif - soap_revert(soap); - s = soap_string_in(soap, 1, -1, -1); -#ifndef WITH_NOIO - soap->frecv = f; -#endif - return soap_set_receiver_error(soap, "HTTP Error", s, SOAP_HTTP_ERROR); - } -#endif - if (soap->error == SOAP_TAG_MISMATCH) - return soap->error = SOAP_VERSIONMISMATCH; - return soap->error; - } - 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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) -{ soap->part = SOAP_END_ENVELOPE; - return soap_element_end_in(soap, "SOAP-ENV:Envelope"); -} -#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; -#ifndef WITH_LEAN - if ((soap->mode & SOAP_XML_SEC) && soap_set_attr(soap, "wsu:Id", "Body")) - return soap->error; -#endif - if (soap_element(soap, "SOAP-ENV:Body", 0, NULL)) - 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_END_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; - if (soap_element_begin_in(soap, "SOAP-ENV:Body", 0, NULL)) - return soap->error; - if (!soap->body) - soap->part = SOAP_NO_BODY; - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_body_end_in(struct soap *soap) -{ if (soap->part == SOAP_NO_BODY) - return SOAP_OK; - soap->part = SOAP_END_BODY; - return soap_element_end_in(soap, "SOAP-ENV:Body"); -} -#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; - else if (soap->error == SOAP_OK && soap->fheader) - soap->error = soap->fheader(soap); - 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] = '\0'; - soap->host[0] = '\0'; - soap->path[0] = '/'; - soap->path[1] = '\0'; - soap->port = 80; - if (!endpoint || !*endpoint) - return; -#ifdef WITH_OPENSSL - if (!soap_tag_cmp(endpoint, "https:*")) - soap->port = 443; -#endif - strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint) - 1); - soap->endpoint[sizeof(soap->endpoint) - 1] = '\0'; - 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; -#ifdef WITH_IPV6 - if (s[0] == '[') - { s++; - for (i = 0; i < n; i++) - { if (s[i] == ']') - { s++; - --n; - break; - } - soap->host[i] = s[i]; - } - } - else - { for (i = 0; i < n; i++) - { soap->host[i] = s[i]; - if (s[i] == '/' || s[i] == ':') - break; - } - } -#else - for (i = 0; i < n; i++) - { soap->host[i] = s[i]; - if (s[i] == '/' || s[i] == ':') - break; - } -#endif - soap->host[i] = '\0'; - if (s[i] == ':') - { soap->port = (int)atol(s + i + 1); - for (i++; i < n; i++) - if (s[i] == '/') - break; - } - if (i < n && s[i]) - { strncpy(soap->path, s + i, 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 previous host name to compare */ - port = soap->port; /* save previous port to compare */ - soap->status = http_command; - soap_set_endpoint(soap, endpoint); -#ifndef WITH_LEANER - if (soap->fconnect) - { if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port))) - return soap->error; - } - else -#endif - if (soap->fopen && *soap->host) - { if (!soap->keep_alive || !soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port || !soap->fpoll || soap->fpoll(soap)) - { soap->keep_alive = 0; /* to force close */ - soap->omode &= ~SOAP_IO_UDP; /* to force close */ - soap_closesock(soap); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect/reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port)); -#ifndef WITH_LEAN - if (!strncmp(endpoint, "soap.udp:", 9)) - soap->omode |= SOAP_IO_UDP; -#endif - 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); - } - } - count = soap_count_attachments(soap); - if (soap_begin_send(soap)) - return soap->error; - if (http_command != SOAP_POST) - { soap->mode &= ~SOAP_IO; - soap->mode |= SOAP_IO_BUFFER; - } -#ifndef WITH_NOHTTP - soap->action = soap_strdup(soap, action); - 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; -#ifndef WITH_LEANER - if ((k & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = k; - } - if (http_command != SOAP_POST) - return soap_end_send(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2base64(struct soap *soap, const unsigned char *s, char *t, int n) -{ register int 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, int *n) -{ register int i, j, c; - register unsigned long m; - register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = (strlen(s) + 3) / 4 * 3; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - 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) - { int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; - } - else if (!soap_blank(c + '+')) - { soap->error = SOAP_TYPE; - return NULL; - } - } - *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 WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2hex(struct soap *soap, const unsigned char *s, char *t, int n) -{ register char *p; - if (!t) - t = (char*)soap_malloc(soap, 2 * n + 1); - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - t[0] = '\0'; - if (s) - { for (; n > 0; n--) - { register int m = *s++; - *t++ = (char)((m >> 4) + (m > 159 ? 'a' - 10 : '0')); - m &= 0x0F; - *t++ = (char)(m + (m > 9 ? 'a' - 10 : '0')); - } - } - *t++ = '\0'; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_hex2s(struct soap *soap, const char *s, char *t, size_t l, int *n) -{ register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = strlen(s) / 2; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - while (l) - { register int d1, d2; - d1 = *s++; - if (!d1) - break; - d2 = *s++; - if (!d2) - break; - *t++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0'); - l--; - } - if (n) - *n = (int)(t - p); - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_puthttphdr(struct soap *soap, int status, size_t count) -{ if (soap->status != SOAP_GET) - { register const char *s = "text/xml; charset=utf-8"; - register int err = SOAP_OK; -#ifndef WITH_LEANER - register const char *r = NULL; -#endif - if (status == SOAP_FILE && soap->http_content) - s = soap->http_content; - else if (status == SOAP_HTML) - s = "text/html; charset=utf-8"; - else if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)) - { if (soap->version == 2) - s = "application/soap+xml; charset=utf-8"; - } -#ifndef WITH_LEANER - if (soap->mode & (SOAP_ENC_DIME | SOAP_ENC_MTOM)) - { if (soap->mode & SOAP_ENC_MTOM) - { r = s; - s = "application/xop+xml; charset=utf-8"; - } - else - s = "application/dime"; - } - if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && strlen(soap->mime.boundary) + strlen(soap->mime.start ? soap->mime.start : SOAP_STR_EOS) < sizeof(soap->tmpbuf) - 80) - { register const char *t = strchr(s, ';'); - sprintf(soap->tmpbuf, "multipart/related; boundary=\"%s\"; type=\"", soap->mime.boundary); - if (t) - strncat(soap->tmpbuf, s, t - s); - else - strcat(soap->tmpbuf, s); - if (soap->mime.start) - { strcat(soap->tmpbuf, "\"; start=\""); - strcat(soap->tmpbuf, soap->mime.start); - } - strcat(soap->tmpbuf, "\""); - if (r) - { strcat(soap->tmpbuf, "; start-info=\""); - strcat(soap->tmpbuf, r); - strcat(soap->tmpbuf, "\""); - } - s = soap->tmpbuf; - } -#endif - if (s && (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", soap->zlib_out == SOAP_ZLIB_DEFLATE ? "deflate" : "gzip"); -#else - err = soap->fposthdr(soap, "Content-Encoding", "deflate"); -#endif - if (err) - return err; - } -#endif -#ifndef WITH_LEANER - if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK) - err = soap->fposthdr(soap, "Transfer-Encoding", "chunked"); - else -#endif - if (s) - { 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_get(struct soap *soap) -{ return SOAP_GET_METHOD; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_put(struct soap *soap) -{ return SOAP_PUT_METHOD; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_del(struct soap *soap) -{ return SOAP_DEL_METHOD; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_head(struct soap *soap) -{ return SOAP_HEAD_METHOD; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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"; - else - s = "POST"; -#ifdef PALM - if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6)) && strncmp(endpoint, "_beam:", 6) && strncmp(endpoint, "_local:", 7) && strncmp(endpoint, "_btobex:", 8)) -#else - if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6))) -#endif - return SOAP_OK; - if (strlen(endpoint) + strlen(soap->http_version) > sizeof(soap->tmpbuf) - 80) - return soap->error = SOAP_EOM; - if (soap->proxy_host && soap_tag_cmp(endpoint, "https:*")) - sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version); - else - sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, (*path == '/' ? path + 1 : path), soap->http_version); - if ((err = soap->fposthdr(soap, soap->tmpbuf, NULL))) - return err; -#ifdef WITH_OPENSSL - if ((soap->ssl && soap->port != 443) || (!soap->ssl && soap->port != 80)) - sprintf(soap->tmpbuf, "%s:%d", host, port); - else - strcpy(soap->tmpbuf, host); -#else - if (port != 80) - sprintf(soap->tmpbuf, "%s:%d", host, port); - else - strcpy(soap->tmpbuf, host); -#endif - 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, (int)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, (int)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 (soap->status != SOAP_GET && (soap->version == 1 || (action && *action && strlen(action) < sizeof(soap->tmpbuf) - 2))) - { sprintf(soap->tmpbuf, "\"%s\"", action?action:""); - if ((err = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf))) - return err; - } - return soap->fposthdr(soap, NULL, NULL); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_response(struct soap *soap, int status, size_t count) -{ register int err; -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - httpOutputEnable(soap->rpmreqid); -#endif - if (strlen(soap->http_version) > 4) - return soap->error = SOAP_EOM; - if (!status || status == SOAP_HTML || status == SOAP_FILE) - { const char *s; - if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)) - s = "200 OK"; - else - s = "202 ACCEPTED"; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Status = %s\n", s)); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif - { 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; - } - 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; -#ifndef WITH_LEAN - if (status == 401) - { sprintf(soap->tmpbuf, "Basic realm=\"%s\"", (soap->authrealm ? strlen(soap->authrealm) : 18) < sizeof(soap->tmpbuf) - 14 ? 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; - } -#endif - } - else - { const char *s = *soap_faultcode(soap); - if (soap->version == 2 && (!s || !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)); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif - { 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))) /* CGI */ - 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 -#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; -#ifndef WITH_NOHTTP - 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; -#ifndef WITH_LEANER - if ((n & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = n; - } -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static const char* -soap_set_validation_fault(struct soap *soap, const char *s, const char *t) -{ if (*soap->tag) - sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element <%s>", s, t?t:SOAP_STR_EOS, soap->tag); - else - sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t?t:SOAP_STR_EOS); - 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 (soap->fseterror) - soap->fseterror(soap, c, s); - 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_TYPE: - *s = soap_set_validation_fault(soap, "data type mismatch ", soap->type); - break; - case SOAP_SYNTAX_ERROR: - *s = "Well-formedness violation"; - break; - case SOAP_NO_TAG: - *s = "No XML element tag"; - 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 = "Invalid SOAP message or SOAP version mismatch"; - break; - case SOAP_DATAENCODINGUNKNOWN: - *c = "SOAP-ENV:DataEncodingUnknown"; - *s = "Unsupported SOAP data encoding"; - break; - case SOAP_NAMESPACE: - *s = soap_set_validation_fault(soap, "namespace error", NULL); - break; - case SOAP_USER_ERROR: - *s = "User error"; - 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_NO_DATA: - *s = "Data required for operation"; - break; - case SOAP_GET_METHOD: - *s = "HTTP GET method not implemented"; - break; - case SOAP_PUT_METHOD: - *s = "HTTP PUT method not implemented"; - break; - case SOAP_HEAD_METHOD: - *s = "HTTP HEAD method not implemented"; - break; - case SOAP_HTTP_METHOD: - *s = "HTTP method not implemented"; - break; - case SOAP_EOM: - *s = "Out of memory"; - break; - case SOAP_MOE: - *s = "Memory overflow or memory corruption error"; - break; - case SOAP_HDR: - *s = "Header line too long"; - 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_DUPLICATE_ID: - *s = soap_set_validation_fault(soap, "multiple definitions of id ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:DuplicateID"; - break; - case SOAP_MISSING_ID: - *s = soap_set_validation_fault(soap, "missing id for ref ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:MissingID"; - break; - case SOAP_HREF: - *s = soap_set_validation_fault(soap, "incompatible object type ref/id pair ", soap->id); - break; - case SOAP_FAULT: - break; -#ifndef WITH_NOIO - case SOAP_UDP_ERROR: - *s = "Message too large for UDP packet"; - break; - case SOAP_TCP_ERROR: - *s = tcp_error(soap); - break; -#endif - case SOAP_HTTP_ERROR: - *s = "An HTTP processing error occurred"; - break; - case SOAP_SSL_ERROR: -#ifdef WITH_OPENSSL - *s = "SSL error"; -#else - *s = "OpenSSL not installed: recompile with -DWITH_OPENSSL"; -#endif - break; - case SOAP_PLUGIN_ERROR: - *s = "Plugin registry error"; - break; - case SOAP_DIME_ERROR: - *s = "DIME format error"; - break; - case SOAP_DIME_HREF: - *s = "DIME href to missing attachment"; - break; - case SOAP_DIME_MISMATCH: - *s = "DIME version/transmission error"; - break; - case SOAP_DIME_END: - *s = "End of DIME error"; - break; - case SOAP_MIME_ERROR: - *s = "MIME format error"; - break; - case SOAP_MIME_HREF: - *s = "MIME href to missing attachment"; - break; - case SOAP_MIME_END: - *s = "End of MIME 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/gzip not installed for (de)compression: recompile with -DWITH_GZIP"; -#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, "occurrence violation", NULL); - break; - case SOAP_LENGTH: - *s = soap_set_validation_fault(soap, "content length violation", NULL); - break; - case SOAP_FD_EXCEEDED: - *s = "Maximum number of open connections was reached"; - break; - case SOAP_STOP: - *s = "Stopped: no response sent"; - break; -#endif - case SOAP_EOF: -#ifndef WITH_NOIO - strcpy(soap->msgbuf, soap_strerror(soap)); -#ifndef WITH_LEAN - if (strlen(soap->msgbuf) + 25 < sizeof(soap->msgbuf)) - { memmove(soap->msgbuf + 25, soap->msgbuf, strlen(soap->msgbuf) + 1); - memcpy(soap->msgbuf, "End of file or no input: ", 25); - } -#endif - *s = soap->msgbuf; - break; -#else - *s = "End of file or no input"; - break; -#endif - default: -#ifndef WITH_NOHTTP -#ifndef WITH_LEAN - if (soap->error > 200 && soap->error < 600) - { sprintf(soap->msgbuf, "HTTP Error: %d %s", soap->error, http_error(soap, soap->error)); - *s = soap->msgbuf; - } - else -#endif -#endif - { sprintf(soap->msgbuf, "Error %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; - int r = 1; - 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); -#ifndef WITH_NOIO -#ifndef WITH_LEAN - if (soap_valid_socket(soap->socket)) - { struct timeval timeout; - fd_set rfd, sfd; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_SET(soap->socket, &rfd); - FD_SET(soap->socket, &sfd); - r = select((int)soap->socket + 1, &rfd, &sfd, NULL, &timeout); - if (r > 0) - { if (!FD_ISSET(soap->socket, &sfd) - || (FD_ISSET(soap->socket, &rfd) - && recv(soap->socket, soap->tmpbuf, 1, MSG_PEEK) < 0)) - r = 0; - } - } -#endif -#endif - if ((status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) && r > 0) - { 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); - } - soap_end_count(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 WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_send_empty_response(struct soap *soap, int httpstatuscode) -{ register soap_mode m = soap->omode; - soap->count = 0; - if ((m & SOAP_IO) == SOAP_IO_CHUNK) - { soap->omode &= ~SOAP_IO_CHUNK; - soap->omode |= SOAP_IO_BUFFER; - } - if (soap_response(soap, httpstatuscode) || soap_end_send(soap)) - { soap->omode = m; - return soap_closesock(soap); - } - soap->omode = m; - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_recv_empty_response(struct soap *soap) -{ if (soap_begin_recv(soap) || soap_end_recv(soap)) - { if (soap->error != 202) - return soap_closesock(soap); - soap->error = SOAP_OK; - } - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static const char* -soap_strerror(struct soap *soap) -{ register int err = soap->errnum; - if (err) - { -#ifndef WIN32 - return strerror(err); -#else -#ifndef UNDER_CE - DWORD len; - *soap->msgbuf = '\0'; - len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)soap->msgbuf, (DWORD)sizeof(soap->msgbuf), NULL); -#else - DWORD i, len; - *soap->msgbuf = '\0'; - len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)soap->msgbuf, (DWORD)(sizeof(soap->msgbuf)/sizeof(TCHAR)), NULL); - for (i = 0; i <= len; i++) - { if (((TCHAR*)soap->msgbuf)[i] < 0x80) - soap->msgbuf[i] = (char)((TCHAR*)soap->msgbuf)[i]; - else - soap->msgbuf[i] = '?'; - } -#endif - return soap->msgbuf; -#endif - } -#ifndef WITH_LEAN - if (soap->recv_timeout > 0) - { if (soap->send_timeout > 0) - sprintf(soap->msgbuf, "Operation interrupted or timed out after %ds send or %ds receive delay", soap->send_timeout, soap->recv_timeout); - else - sprintf(soap->msgbuf, "Operation interrupted or timed out after %ds receive delay", soap->recv_timeout); - return soap->msgbuf; - } -#endif - return "Operation interrupted or timed out"; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_set_error(struct soap *soap, const char *faultcode, const char *faultsubcodeQName, const char *faultstring, const char *faultdetailXML, int soaperror) -{ *soap_faultcode(soap) = faultcode; - if (faultsubcodeQName) - *soap_faultsubcode(soap) = faultsubcodeQName; - *soap_faultstring(soap) = faultstring; - if (faultdetailXML && *faultdetailXML) - { register const char **s = soap_faultdetail(soap); - if (s) - *s = faultdetailXML; - } - 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 *faultdetailXML, int soaperror) -{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", NULL, faultstring, faultdetailXML, soaperror); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_set_receiver_error(struct soap *soap, const char *faultstring, const char *faultdetailXML, int soaperror) -{ return soap_set_error(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", NULL, faultstring, faultdetailXML, soaperror); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultsubcodeQName, const char *faultstring, const char *faultdetailXML) -{ char *r = NULL, *s = NULL, *t = NULL; - if (faultsubcodeQName) - r = soap_strdup(soap, faultsubcodeQName); - if (faultstring) - s = soap_strdup(soap, faultstring); - if (faultdetailXML) - t = soap_strdup(soap, faultdetailXML); - return soap_set_error(soap, faultcode, r, s, t, SOAP_FAULT); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_sender_fault(struct soap *soap, const char *faultstring, const char *faultdetailXML) -{ return soap_sender_fault_subcode(soap, NULL, faultstring, faultdetailXML); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_sender_fault_subcode(struct soap *soap, const char *faultsubcodeQName, const char *faultstring, const char *faultdetailXML) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultsubcodeQName, faultstring, faultdetailXML); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_receiver_fault(struct soap *soap, const char *faultstring, const char *faultdetailXML) -{ return soap_receiver_fault_subcode(soap, NULL, faultstring, faultdetailXML); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_receiver_fault_subcode(struct soap *soap, const char *faultsubcodeQName, const char *faultstring, const char *faultdetailXML) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultsubcodeQName, faultstring, faultdetailXML); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault(struct soap *soap, FILE *fd) -{ if (soap_check_state(soap)) - fprintf(fd, "Error: soap struct state not initialized\n"); - else if (soap->error) - { const char *c, *v = NULL, *s, **d; - d = soap_faultcode(soap); - if (!*d) - soap_set_fault(soap); - c = *d; - if (soap->version == 2) - v = *soap_faultsubcode(soap); - s = *soap_faultstring(soap); - d = soap_faultdetail(soap); - fprintf(fd, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]"); - } -} -#endif -#endif - -/******************************************************************************/ -#ifdef __cplusplus -#ifndef WITH_LEAN -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_stream_fault(struct soap *soap, std::ostream& os) -{ if (soap_check_state(soap)) - os << "Error: soap struct state not initialized\n"; - else if (soap->error) - { const char *c, *v = NULL, *s, **d; - d = soap_faultcode(soap); - if (!*d) - soap_set_fault(soap); - c = *d; - if (soap->version == 2) - v = *soap_faultsubcode(soap); - s = *soap_faultstring(soap); - d = soap_faultdetail(soap); - os << (soap->version ? "SOAP 1." : "Error ") - << (soap->version ? (int)soap->version : soap->error) - << " fault: " << c - << "[" << (v ? v : "no subcode") << "]" - << std::endl - << "\"" << (s ? s : "[no reason]") << "\"" - << std::endl - << "Detail: " << (d && *d ? *d : "[no detail]") - << std::endl; - } -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_sprint_fault(struct soap *soap, char *buf, size_t len) -{ if (soap_check_state(soap)) - strncpy(buf, "Error: soap struct not initialized", len); - else if (soap->error) - { const char *c, *v = NULL, *s, **d; - d = soap_faultcode(soap); - if (!*d) - soap_set_fault(soap); - c = *d; - if (soap->version == 2) - v = *soap_faultsubcode(soap); - s = *soap_faultstring(soap); - d = soap_faultdetail(soap); -#ifdef WIN32 - _snprintf -#else - snprintf -#endif - (buf, len, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]"); - } - return buf; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault_location(struct soap *soap, FILE *fd) -{ -#ifndef WITH_LEAN - int i, j, c1, c2; - if (soap->error && soap->bufidx <= soap->buflen && soap->buflen > 0 && soap->buflen <= SOAP_BUFLEN) - { i = (int)soap->bufidx - 1; - if (i <= 0) - i = 0; - c1 = soap->buf[i]; - soap->buf[i] = '\0'; - if ((int)soap->buflen >= i + 1024) - j = i + 1023; - else - j = (int)soap->buflen - 1; - c2 = soap->buf[j]; - soap->buf[j] = '\0'; - fprintf(fd, "%s%c\n\n", soap->buf, c1); - if (soap->bufidx < soap->buflen) - fprintf(fd, "%s\n", soap->buf + soap->bufidx); - soap->buf[i] = c1; - soap->buf[j] = c2; - } -#endif -} -#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(soap, 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(soap, 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 - -/******************************************************************************\ - * - * C++ soap struct methods - * -\******************************************************************************/ - -#ifdef __cplusplus -soap::soap() -{ soap_init(this); -} -#endif - -/******************************************************************************/ -#ifdef __cplusplus -soap::soap(soap_mode m) -{ soap_init1(this, m); -} -#endif - -/******************************************************************************/ -#ifdef __cplusplus -soap::soap(soap_mode im, soap_mode om) -{ soap_init2(this, im, om); -} -#endif - -/******************************************************************************/ -#ifdef __cplusplus -soap::soap(struct soap& soap) -{ soap_copy_context(this, &soap); -} -#endif - -/******************************************************************************/ -#ifdef __cplusplus -soap::~soap() -{ soap_destroy(this); - soap_end(this); - soap_done(this); -} -#endif - -/******************************************************************************/ diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.h b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.h deleted file mode 100644 index ff11248..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.10.h +++ /dev/null @@ -1,2281 +0,0 @@ -/* - stdsoap2.h 2.7.10 - - gSOAP runtime engine - -gSOAP XML Web services tools -Copyright (C) 2000-2008, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under ONE of the following licenses: -GPL, the gSOAP public license, OR Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems, Inc., for the following additions - - vxWorks compatible --------------------------------------------------------------------------------- -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-2008, 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 - -This program is released under the GPL with the additional exemption that -compiling, linking, and/or using OpenSSL is allowed. --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- -*/ - -#ifdef WITH_SOAPDEFS_H -# include "soapdefs.h" /* include user-defined stuff */ -#endif - -#ifndef _THREAD_SAFE -# define _THREAD_SAFE -#endif - -#ifndef OPENSERVER -# ifndef _REENTRANT -# define _REENTRANT -# endif -#endif - -#ifndef SOAP_FMAC1 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC1 -#endif - -#ifndef SOAP_FMAC2 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC2 -#endif - -#ifndef SOAP_FMAC3 /* (de)serializer declaration macro */ -# define SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC3S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC3S SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC4 /* (de)serializer declaration macro */ -# define SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC4S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC4S SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC5 /* stub/skeleton declaration macro */ -# define SOAP_FMAC5 -#endif - -#ifndef SOAP_FMAC6 /* stub/skeleton declaration macro */ -# define SOAP_FMAC6 -#endif - -#ifndef SOAP_CMAC /* class declaration macro */ -# define SOAP_CMAC -#endif - -#ifndef SOAP_NMAC /* namespace table declaration macro */ -# define SOAP_NMAC -#endif - -#ifndef SOAP_SOURCE_STAMP -# define SOAP_SOURCE_STAMP(str) -#endif - -/* gSOAP 2.7.4 and higher: fast look-aside buffering is stable */ -#ifndef WITH_FAST -# define WITH_FAST -#endif - -#ifdef WITH_LEANER -# ifndef WITH_LEAN -# define WITH_LEAN -# endif -#endif - -#ifdef WITH_LEAN -# ifdef WITH_COOKIES -# error "Cannot build WITH_LEAN code WITH_COOKIES enabled" -# endif -#endif - -#ifndef STDSOAP_H -#define STDSOAP_H - -#if defined(__vxworks) || defined(__VXWORKS__) -# define VXWORKS -#endif - -#ifdef _WIN32 -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef _WIN32_WCE -# ifndef UNDER_CE -# define UNDER_CE _WIN32_WCE -# endif -#endif - -#ifdef UNDER_CE -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef __BORLANDC__ -# ifdef __WIN32__ -# ifndef WIN32 -# define WIN32 -# endif -# endif -#endif - -#ifdef __CYGWIN__ -# ifndef CYGWIN -# define CYGWIN -# endif -#endif - -#ifdef __SYMBIAN32__ -# define SYMBIAN -# undef WIN32 -#endif - -#if defined(__palmos__) || defined(PALM_GCC) || defined(__PALMOS_TRAPS__) -# ifndef PALM -# define PALM -# endif -#endif - -#if defined(__hpux) -# ifndef HP_UX -# define HP_UX -# endif -#endif - -#if defined(__digital__) && defined(__unix__) -# ifndef TRU64 -# define TRU64 -# endif -#endif - -#ifdef __MVS__ -# ifndef OS390 -# define OS390 -# endif -#endif - -#ifdef HAVE_CONFIG_H -# include "config.h" -# if defined(WITH_OPENSSL) -# ifndef HAVE_OPENSSL_SSL_H -# undef WITH_OPENSSL -# endif -# endif -# if defined(WITH_ZLIB) || defined(WITH_GZIP) -# ifndef HAVE_ZLIB_H -# undef WITH_ZLIB -# undef WITH_GZIP -# endif -# endif -#else -# if defined(UNDER_CE) -# define WITH_NOEMPTYSTRUCT -# define WITH_LEAN -# define HAVE_SSCANF -# elif defined(WIN32) -# define WITH_NOEMPTYSTRUCT -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%I64d" -# define SOAP_ULONG_FORMAT "%I64u" -# elif defined(CYGWIN) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__APPLE__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOD_L -# define HAVE_SSCANF_L -# define HAVE_SPRINTF_L -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(_AIX43) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(_AIX41) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(HP_UX) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(FREEBSD) || defined(__FreeBSD__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOD_L -# define HAVE_SSCANF_L -# define HAVE_SPRINTF_L -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_GETTIMEOFDAY -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%qd" -# define SOAP_ULONG_FORMAT "%qu" -# elif defined(__VMS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__GLIBC__) || defined(__GNU__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOD_L -# define HAVE_SSCANF_L -# define HAVE_SPRINTF_L -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define HAVE_ISNAN -# elif defined(TRU64) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GETTIMEOFDAY -# define HAVE_SYS_TIMEB_H -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define __USE_STD_IOSTREAM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -# elif defined(MAC_CARBON) -# define WITH_NOIO -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOD_L -# define HAVE_SSCANF_L -# define HAVE_SPRINTF_L -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(PALM) -# define WITH_LEAN -# define HAVE_STRTOD /* strtod() is defined in palmFunctions.h */ -# include /* Needs to be included before unix headers */ -# include -# define IGNORE_STDIO_STUBS -# include -# define O_NONBLOCK FNONBIO -# include -# include "palmFunctions.h" -# elif defined(SYMBIAN) -# define WITH_LEAN -# define WITH_NONAMESPACES -# define HAVE_STRTOD /* use STRTOD since sscanf doesn't seem to work */ -# include -# include -# elif defined(VXWORKS) -# ifdef _WRS_KERNEL -# define _POSIX_THREADS 1 -# endif -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GMTIME -# define HAVE_LOCALTIME -# define HAVE_MKTIME -# elif defined(OS390) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(AS400) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__QNX__) || defined(QNX) -/* QNX does not have a working version of strtof */ -# undef HAVE_STRTOF -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define LONG64 long -# define ULONG64 unsigned LONG64 -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -# else -/* Default asumptions on supported functions */ -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# endif -#endif - -#if defined(HAVE_XLOCALE_H) || defined(HAVE_STRTOD_L) || defined(HAVE_STRTOF_L) || defined(HAVE_SSCANF_L) || defined(HAVE_SPRINTF_L) -# include -#endif - -#ifndef WITH_NOSTDLIB -# include -# ifndef PALM -# include -# include -# endif -# include -# include -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -# include -# include -#endif - -#ifdef WITH_NOHTTP -# ifndef WITH_NOIO -# define WITH_NOIO -# undef WITH_COOKIES -# endif -#endif - -/* Suggestion when SOAP_FD_EXCEEDED error occurs: - Some systems allow increasing FD_SETSIZE before including sys/types.h: -#define FD_SETSIZE (2048) -*/ - -#ifndef UNDER_CE -# ifndef PALM -# ifndef WITH_NOIO -# include -# include -# endif -# ifndef WITH_LEAN -# ifdef HAVE_SYS_TIMEB_H -# include /* for ftime() */ -# endif -# include -# endif -# endif -#endif - -#ifdef OPENSERVER -# include -# include -# include - extern int h_errno; -#endif - -#ifndef WITH_NOIO -# ifndef WIN32 -# ifndef PALM -# include -# ifdef VXWORKS -# include -# include -# ifndef _WRS_KERNEL -# include -# endif -# else -# ifndef SYMBIAN -# include -# endif -# endif -# ifdef SUN_OS -# include /* SUN */ -# include /* SUN < 2.8 (?) */ -# endif -# ifdef VXWORKS -# ifdef _WRS_KERNEL -# include -# endif -# else -# include -# endif -# include -# ifdef OS390 -# include -# else -# include /* TCP_NODELAY */ -# endif -# include -# endif -# endif -#endif - -#ifdef WIN32 -# define SOAP_WINSOCKINT int -#else -# define SOAP_WINSOCKINT size_t -#endif - -#ifdef WIN32 -# ifndef UNDER_CE -# include -# include -# endif -# ifdef WITH_IPV6 -# include /* Visual Studio 2005 users: you must install the Platform SDK (R2) */ -# include -# include -# define SOAP_GAI_STRERROR gai_strerrorA -# else -# include /* Visual Studio 2005 users: you must install the Platform SDK (R2) */ -/* # include */ /* Alternative: use winsock2 (not available with eVC) */ -# endif -#else -# ifdef VXWORKS -# include -# include -# include -# endif -# ifndef WITH_NOIO -# ifndef PALM -# include -# include -# include -# include -# ifdef _AIX41 -# include -# endif -# endif -# endif -#endif - -#ifdef WITH_FASTCGI -# include -#endif - -#ifdef WITH_OPENSSL -# define OPENSSL_NO_KRB5 -# include -# include -# include -# include -# include -# ifndef ALLOW_OLD_VERSIONS -# if (OPENSSL_VERSION_NUMBER < 0x00905100L) -# error "Must use OpenSSL 0.9.6 or later" -# endif -# endif -#endif - -#ifdef WITH_GZIP -# ifndef WITH_ZLIB -# define WITH_ZLIB -# endif -#endif - -#ifdef WITH_CASEINSENSITIVETAGS -# define SOAP_STRCMP soap_tag_cmp /* case insensitve XML element/attribute names */ -#else -# define SOAP_STRCMP strcmp /* case sensitive XML element/attribute names */ -#endif - -#ifdef WITH_ZLIB -# include -#endif - -#ifndef WITH_NOSTDLIB -# ifndef PALM -# include /* for isnan() */ -# endif -#endif - -/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */ - -#ifdef __cplusplus -extern "C" { -#endif - -/* Portability: define SOAP_SOCKLEN_T */ -#if defined(_AIX) -# if defined(_AIX43) -# define SOAP_SOCKLEN_T socklen_t -# else -# define SOAP_SOCKLEN_T int -# endif -#elif defined(SOCKLEN_T) -# define SOAP_SOCKLEN_T SOCKLEN_T -#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(__QNX__) || defined(QNX) -# define SOAP_SOCKLEN_T socklen_t -#elif defined(IRIX) || defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS) -# define SOAP_SOCKLEN_T int -#else -# define SOAP_SOCKLEN_T size_t -#endif - -#ifndef SOAP_SOCKET -# ifdef WIN32 -# define SOAP_SOCKET SOCKET -# define soap_closesocket(n) closesocket(n) -# else -# define SOAP_SOCKET int -# define soap_closesocket(n) close(n) -# endif -#endif - -#define SOAP_INVALID_SOCKET ((SOAP_SOCKET)-1) -#define soap_valid_socket(n) ((n) != SOAP_INVALID_SOCKET) - -#ifndef SOAP_GAI_STRERROR -# define SOAP_GAI_STRERROR gai_strerror -#endif - -#ifndef FD_SETSIZE -# define FD_SETSIZE (1024) -#endif - -#if defined(SYMBIAN) -# define LONG64 long -# define ULONG64 unsigned LONG64 -#elif !defined(WIN32) || defined(CYGWIN) || defined(__GLIBC__) || defined(__GNU__) -# ifndef LONG64 -# if defined(__GLIBC__) -# include -# if (__WORDSIZE == 64) -# define LONG64 int64_t -# define ULONG64 uint64_t -# ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%ld" -# endif -# ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%lu" -# endif -# else -# define LONG64 long long -# define ULONG64 unsigned LONG64 -# endif -# else -# define LONG64 long long -# define ULONG64 unsigned LONG64 -# endif -# endif -#elif defined(UNDER_CE) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#elif defined(__BORLANDC__) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#endif - -#ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%lld" /* printf format for 64 bit ints */ -#endif - -#ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%llu" /* printf format for unsigned 64 bit ints */ -#endif - -#if defined(WIN32) && !defined(CYGWIN) -# define soap_int32 __int32 -#elif defined(SYMBIAN) -# define soap_int32 long -#elif defined(PALM) -# define soap_int32 Int32 -#elif defined(_AIX) -# if defined(_AIX43) -# define soap_int32 int32_t -# else -# define soap_int32 signed int -# endif -#else -# define soap_int32 int32_t -#endif - -#ifdef WIN32 -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR WSAEINTR -# define SOAP_EAGAIN WSAEWOULDBLOCK -# define SOAP_EWOULDBLOCK WSAEWOULDBLOCK -# define SOAP_EINPROGRESS WSAEINPROGRESS -# define SOAP_EADDRINUSE WSAEADDRINUSE -#else -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR EINTR -# define SOAP_EAGAIN EAGAIN -# define SOAP_EADDRINUSE EADDRINUSE -# ifdef SYMBIAN -# define SOAP_EWOULDBLOCK 9898 -# define SOAP_EINPROGRESS 9899 -# else -# define SOAP_EWOULDBLOCK EWOULDBLOCK -# define SOAP_EINPROGRESS EINPROGRESS -# endif -#endif - -#ifdef WIN32 -# ifdef UNDER_CE -# define soap_errno GetLastError() -# define soap_socket_errno(s) GetLastError() -# define soap_reset_errno SetLastError(0) -# else -# define soap_errno GetLastError() -# define soap_socket_errno(s) WSAGetLastError() -# define soap_reset_errno SetLastError(0) -# endif -#else -# ifndef WITH_NOIO -# define soap_errno errno -# define soap_socket_errno(s) errno -# define soap_reset_errno (errno = 0) -# else -# define soap_errno 0 -# define soap_socket_errno(s) 0 -# define soap_reset_errno -# endif -#endif - -#ifndef SOAP_BUFLEN -# ifndef WITH_LEAN -# define SOAP_BUFLEN (65536) /* buffer length for socket packets, also used by gethostbyname_r and UDP messages, so don't make this too small */ -# else -# define SOAP_BUFLEN (2048) -# endif -#endif -#ifndef SOAP_LABLEN -# define SOAP_LABLEN (256) /* initial look-aside buffer length */ -#endif -#ifndef SOAP_PTRBLK -# define SOAP_PTRBLK (32) /* block allocation for pointer hash table chains */ -#endif -#ifndef SOAP_PTRHASH -# ifndef WITH_LEAN -# define SOAP_PTRHASH (1024) /* size of pointer analysis hash table (must be power of 2) */ -# else -# define SOAP_PTRHASH (32) -# endif -#endif -#ifndef SOAP_IDHASH -# ifndef WITH_LEAN -# define SOAP_IDHASH (1999) /* prime size of hash table for parsed id/ref */ -# else -# define SOAP_IDHASH (19) /* 19, 199 */ -# endif -#endif -#ifndef SOAP_BLKLEN -# ifndef WITH_LEAN -# define SOAP_BLKLEN (256) /* size of blocks to collect long strings and XML attributes */ -# else -# define SOAP_BLKLEN (32) -# endif -#endif -#ifndef SOAP_TAGLEN -# ifndef WITH_LEAN -# define SOAP_TAGLEN (1024) /* maximum length of XML element tag/attribute name or host/path name + 1 */ -# else -# define SOAP_TAGLEN (64) -# endif -#endif -#ifndef SOAP_HDRLEN -# ifndef WITH_LEAN -# define SOAP_HDRLEN (8192) /* maximum length of HTTP header line (must be >4096 to read cookies) */ -# else -# define SOAP_HDRLEN (1024) -# endif -#endif -#ifndef SOAP_MAXDIMS -# ifndef WITH_LEAN -# define SOAP_MAXDIMS (16) /* maximum array dimensions (array nestings) must be less than 64 to protect soap->tmpbuf */ -# else -# define SOAP_MAXDIMS (4) -# endif -#endif - -#ifndef SOAP_MAXLOGS -# define SOAP_MAXLOGS (3) /* max number of debug logs per struct soap environment */ -# define SOAP_INDEX_RECV (0) -# define SOAP_INDEX_SENT (1) -# define SOAP_INDEX_TEST (2) -#endif - -#ifndef SOAP_MAXKEEPALIVE -# define SOAP_MAXKEEPALIVE (100) /* max iterations to keep server connection alive */ -#endif - -#ifndef SOAP_MAXARRAYSIZE -# define SOAP_MAXARRAYSIZE (100000) /* "trusted" max size of inbound SOAP array for compound array allocation */ -#endif - -#ifdef VXWORKS -# ifdef __INCmathh -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) isNan(num) -# endif -#endif - -#ifdef WIN32 -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) _isnan(num) -#endif - -#ifdef SUN_OS -# define HAVE_ISNAN -#endif - -#ifdef __APPLE__ -# ifdef __cplusplus -# ifndef isnan -extern "C" int isnan(double); -# endif -# endif -# define HAVE_ISNAN -#endif - -#if !defined(HAVE_ISNAN) && (defined(_MATH_H) || defined(_MATH_INCLUDED)) -# define HAVE_ISNAN -#endif - -extern const struct soap_double_nan { unsigned int n1, n2; } soap_double_nan; - -#ifdef VXWORKS -# ifndef FLT_MAX -# define FLT_MAX _ARCH_FLT_MAX -# endif -# ifndef DBL_MAX -# define DBL_MAX _ARCH_DBL_MAX -# endif -#endif - -#ifndef FLT_NAN -# define FLT_NAN (*(float*)(void*)&soap_double_nan) -#endif - -#ifndef FLT_PINFTY -# if defined(FLT_MAX) -# define FLT_PINFTY FLT_MAX -# elif defined(HUGE_VALF) -# define FLT_PINFTY (float)HUGE_VALF -# elif defined(HUGE_VAL) -# define FLT_PINFTY (float)HUGE_VAL -# elif defined(FLOAT_MAX) -# define FLT_PINFTY FLOAT_MAX -# else -# define FLT_PINFTY (3.40282347e+38F) -# endif -#endif - -#ifndef FLT_NINFTY -# define FLT_NINFTY (-FLT_PINFTY) -#endif - -#ifndef DBL_NAN -# define DBL_NAN (*(double*)(void*)&soap_double_nan) -#endif - -#ifndef DBL_PINFTY -# if defined(DBL_MAX) -# define DBL_PINFTY DBL_MAX -# elif defined(HUGE_VALF) -# define DBL_PINFTY (double)HUGE_VALF -# elif defined(HUGE_VAL) -# define DBL_PINFTY (double)HUGE_VAL -# elif defined(DOUBLE_MAX) -# define DBL_PINFTY DOUBLE_MAX -# else -# define DBL_PINFTY (1.7976931348623157e+308) -# endif -#endif - -#ifndef DBL_NINFTY -# define DBL_NINFTY (-DBL_PINFTY) -#endif - -#ifndef soap_isnan -# ifdef HAVE_ISNAN -# define soap_isnan(n) isnan(n) -# else -# define soap_isnan(n) (0) -# endif -#endif - -#define soap_ispinfd(n) ((n) >= DBL_PINFTY) -#define soap_ispinff(n) ((n) >= FLT_PINFTY) -#define soap_isninfd(n) ((n) <= DBL_NINFTY) -#define soap_isninff(n) ((n) <= FLT_NINFTY) - -/* gSOAP error codes */ - -#define SOAP_EOF EOF -#define SOAP_ERR EOF -#define SOAP_OK 0 -#define SOAP_CLI_FAULT 1 -#define SOAP_SVR_FAULT 2 -#define SOAP_TAG_MISMATCH 3 -#define SOAP_TYPE 4 -#define SOAP_SYNTAX_ERROR 5 -#define SOAP_NO_TAG 6 -#define SOAP_IOB 7 -#define SOAP_MUSTUNDERSTAND 8 -#define SOAP_NAMESPACE 9 -#define SOAP_USER_ERROR 10 -#define SOAP_FATAL_ERROR 11 -#define SOAP_FAULT 12 -#define SOAP_NO_METHOD 13 -#define SOAP_NO_DATA 14 -#define SOAP_GET_METHOD 15 -#define SOAP_PUT_METHOD 16 -#define SOAP_DEL_METHOD 17 -#define SOAP_HEAD_METHOD 18 -#define SOAP_HTTP_METHOD 19 -#define SOAP_EOM 20 -#define SOAP_MOE 21 -#define SOAP_HDR 22 -#define SOAP_NULL 23 -#define SOAP_DUPLICATE_ID 24 -#define SOAP_MISSING_ID 25 -#define SOAP_HREF 26 -#define SOAP_UDP_ERROR 27 -#define SOAP_TCP_ERROR 28 -#define SOAP_HTTP_ERROR 29 -#define SOAP_SSL_ERROR 30 -#define SOAP_ZLIB_ERROR 31 -#define SOAP_DIME_ERROR 32 -#define SOAP_DIME_HREF 33 -#define SOAP_DIME_MISMATCH 34 -#define SOAP_DIME_END 35 -#define SOAP_MIME_ERROR 36 -#define SOAP_MIME_HREF 37 -#define SOAP_MIME_END 38 -#define SOAP_VERSIONMISMATCH 39 -#define SOAP_PLUGIN_ERROR 40 -#define SOAP_DATAENCODINGUNKNOWN 41 -#define SOAP_REQUIRED 42 -#define SOAP_PROHIBITED 43 -#define SOAP_OCCURS 44 -#define SOAP_LENGTH 45 -#define SOAP_FD_EXCEEDED 46 - -#define soap_xml_error_check(e) ((e) == SOAP_TAG_MISMATCH || (e) == SOAP_NO_TAG || (e) == SOAP_SYNTAX_ERROR || (e) == SOAP_NAMESPACE || (e) == SOAP_DUPLICATE_ID || (e) == SOAP_MISSING_ID || (e) == SOAP_REQUIRED || (e) == SOAP_PROHIBITED || (e) == SOAP_OCCURS || (e) == SOAP_LENGTH || (e) == SOAP_NULL || (e) == SOAP_HREF) -#define soap_soap_error_check(e) ((e) == SOAP_CLI_FAULT || (e) == SOAP_SVR_FAULT || (e) == SOAP_VERSIONMISMATCH || (e) == SOAP_MUSTUNDERSTAND || (e) == SOAP_FAULT || (e) == SOAP_NO_METHOD) -#define soap_tcp_error_check(e) ((e) == SOAP_EOF || (e) == SOAP_TCP_ERROR) -#define soap_ssl_error_check(e) ((e) == SOAP_SSL_ERROR) -#define soap_zlib_error_check(e) ((e) == SOAP_ZLIB_ERROR) -#define soap_http_error_check(e) ((e) == SOAP_HTTP_ERROR || ((e) >= SOAP_GET_METHOD && (e) <= SOAP_HTTP_METHOD)|| (e) == SOAP_NO_DATA || ((e) >= 100 && (e) < 600)) - -/* gSOAP HTTP response status codes 100 to 599 are reserved */ - -/* Codes 600 to 999 are user definable */ - -/* Exceptional gSOAP HTTP response status codes >= 1000 */ - -#define SOAP_STOP 1000 /* No HTTP response */ -#define SOAP_FORM 1001 /* Form request/response */ -#define SOAP_HTML 1002 /* Custom HTML response */ -#define SOAP_FILE 1003 /* Custom file-based response */ - -/* gSOAP HTTP method codes */ - -#define SOAP_POST 2000 -#define SOAP_GET 2001 - -/* gSOAP DIME */ - -#define SOAP_DIME_CF 0x01 -#define SOAP_DIME_ME 0x02 -#define SOAP_DIME_MB 0x04 -#define SOAP_DIME_VERSION 0x08 /* DIME version 1 */ -#define SOAP_DIME_MEDIA 0x10 -#define SOAP_DIME_ABSURI 0x20 - -/* gSOAP ZLIB */ - -#define SOAP_ZLIB_NONE 0x00 -#define SOAP_ZLIB_DEFLATE 0x01 -#define SOAP_ZLIB_INFLATE 0x02 -#define SOAP_ZLIB_GZIP 0x02 - -/* gSOAP transport, connection, and content encoding modes */ - -typedef soap_int32 soap_mode; - -#define SOAP_IO 0x00000003 /* IO mask */ -#define SOAP_IO_FLUSH 0x00000000 /* flush output immediately, no buffering */ -#define SOAP_IO_BUFFER 0x00000001 /* buffer output in packets of size SOAP_BUFLEN */ -#define SOAP_IO_STORE 0x00000002 /* store entire output to determine length for transport */ -#define SOAP_IO_CHUNK 0x00000003 /* use HTTP chunked transfer AND buffer packets */ - -#define SOAP_IO_UDP 0x00000004 /* TCP or UDP */ - -#define SOAP_IO_LENGTH 0x00000008 /* calc message length (internal) */ -#define SOAP_IO_KEEPALIVE 0x00000010 /* keep connection alive */ - -#define SOAP_ENC_LATIN 0x00000020 /* accept iso-8859-1 encoding */ -#define SOAP_ENC_XML 0x00000040 /* plain XML encoding, no HTTP header */ -#define SOAP_ENC_DIME 0x00000080 -#define SOAP_ENC_MIME 0x00000100 -#define SOAP_ENC_MTOM 0x00000200 -#define SOAP_ENC_ZLIB 0x00000400 -#define SOAP_ENC_SSL 0x00000800 - -#define SOAP_ENC 0x00000FFF /* IO and ENC mask */ - -#define SOAP_XML_STRICT 0x00001000 /* apply strict validation */ -#define SOAP_XML_INDENT 0x00002000 /* emit indented XML */ -#define SOAP_XML_CANONICAL 0x00004000 /* EXC C14N canonical XML */ -#define SOAP_XML_TREE 0x00008000 /* emit XML tree (no id/ref) */ -#define SOAP_XML_GRAPH 0x00010000 -#define SOAP_XML_NIL 0x00020000 -#define SOAP_XML_DOM 0x00040000 -#define SOAP_XML_SEC 0x00080000 /* reserved for WS security */ - -#define SOAP_C_NOIOB 0x00100000 /* don't fault on array index out of bounds (just ignore) */ -#define SOAP_C_UTFSTRING 0x00200000 /* (de)serialize strings with UTF8 content */ -#define SOAP_C_MBSTRING 0x00400000 /* (de)serialize strings with multi-byte content */ -#define SOAP_C_NILSTRING 0x00800000 /* serialize empty strings as nil (omitted) */ - -#define SOAP_DOM_TREE 0x01000000 -#define SOAP_DOM_NODE 0x02000000 -#define SOAP_DOM_ASIS 0x04000000 - -#define SOAP_MIME_POSTCHECK 0x10000000 /* MIME flag (internal) */ - -#define SOAP_IO_DEFAULT SOAP_IO_FLUSH - -/* SSL client/server authentication settings */ - -#define SOAP_SSL_NO_AUTHENTICATION 0x00 /* for testing purposes */ -#define SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION 0x01 /* client requires server to authenticate */ -#define SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION 0x02 /* server requires client to authenticate */ -#define SOAP_SSL_SKIP_HOST_CHECK 0x04 /* client does not check the common name of the host in certificate */ -#define SOAP_SSL_RSA 0x08 /* use RSA */ -#define SOAP_SSLv3_TLSv1 0x00 /* SSL v3 and TLS v1 support by default */ -#define SOAP_SSLv3 0x10 /* SSL v3 only */ -#define SOAP_TLSv1 0x20 /* TLS v1 only */ - -#define SOAP_SSL_DEFAULT (SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION | SOAP_SSLv3_TLSv1) - -/* state */ - -#define SOAP_INIT 1 -#define SOAP_COPY 2 - -#define soap_check_state(soap) (!(soap) || ((soap)->state != SOAP_INIT && (soap)->state != SOAP_COPY)) - -/* part */ - -#define SOAP_BEGIN 0 -#define SOAP_IN_ENVELOPE 2 -#define SOAP_IN_HEADER 3 -#define SOAP_END_HEADER 4 -#define SOAP_NO_BODY 5 -#define SOAP_IN_BODY 6 -#define SOAP_END_BODY 7 -#define SOAP_END_ENVELOPE 8 -#define SOAP_END 9 -#define SOAP_BEGIN_SECURITY 10 -#define SOAP_IN_SECURITY 11 -#define SOAP_END_SECURITY 12 - -/* DEBUG macros */ - -#ifndef WITH_LEAN -# ifdef DEBUG -# ifndef SOAP_DEBUG -# define SOAP_DEBUG -# endif -# ifndef SOAP_MEM_DEBUG -# define SOAP_MEM_DEBUG -# endif -# endif -#endif - -#ifdef SOAP_MEM_DEBUG -# ifndef SOAP_MALLOC -# define SOAP_MALLOC(soap, size) soap_track_malloc(soap, __FILE__, __LINE__, size) -# endif -# ifndef SOAP_FREE -# define SOAP_FREE(soap, ptr) soap_track_free(soap, __FILE__, __LINE__, ptr) -# endif -#endif - -#ifndef SOAP_MALLOC /* use libc malloc */ -# define SOAP_MALLOC(soap, size) malloc(size) -#endif - -#ifndef SOAP_FREE /* use libc free */ -# define SOAP_FREE(soap, ptr) free(ptr) -#endif - -#ifdef SOAP_DEBUG -# ifndef SOAP_MESSAGE -# define SOAP_MESSAGE fprintf -# endif -# ifndef DBGLOG -# define DBGLOG(DBGFILE, CMD) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ - CMD;\ - fflush(fdebug);\ - }\ - }\ -} -# endif -# ifndef DBGMSG -# define DBGMSG(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { fwrite((MSG), 1, (LEN), soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -# ifndef DGBFUN -# define DBGFUN(FNAME) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s()\n", __FILE__, __LINE__, FNAME)) -# define DBGFUN1(FNAME, FMT, ARG) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT")\n", __FILE__, __LINE__, FNAME, (ARG))) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2))) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2", "FMT3")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2), (ARG3))) -# endif -# ifndef DBGHEX -# define DBGHEX(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { int i; char *s;\ - for (s = (char*)(MSG), i = (LEN); i; i--)\ - fprintf(soap->fdebug[SOAP_INDEX_##DBGFILE], "%2.2X ", (int)*s++&0xFF);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -#else -# define DBGLOG(DBGFILE, CMD) -# define DBGMSG(DBGFILE, MSG, LEN) -# define DBGFUN(FNAME) -# define DBGFUN1(FNAME, FMT, ARG) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) -# define DBGHEX(DBGFILE, MSG, LEN) -#endif - -/* UCS-4 requires 32 bits (0-7FFFFFFF, the sign bit is used by gSOAP to distinguish XML entities) */ -typedef soap_int32 soap_wchar; - -/* namespace table row */ -struct Namespace -{ const char *id; - const char *ns; - const char *in; - char *out; -}; - -/* namespace stack */ -struct soap_nlist -{ struct soap_nlist *next; - unsigned int level; /* nesting depth level */ - short index; /* corresponding entry in ns mapping table */ - char *ns; /* only set when parsed ns URI is not in the ns mapping table */ - char id[1]; /* the actual string value flows into the allocated region below this struct */ -}; - -/* block stack for nested block allocations */ -struct soap_blist -{ struct soap_blist *next; - char *ptr; - size_t size; -}; - -/* array layout */ -struct soap_array -{ void *__ptr; - int __size; -}; - -/* pointer serialization management */ -struct soap_plist -{ struct soap_plist *next; - const void *ptr; - const struct soap_array *array; - int type; - int id; - char mark1; - char mark2; -}; - -/* block allocation for pointer serialization management */ -struct soap_pblk -{ struct soap_pblk *next; - struct soap_plist plist[SOAP_PTRBLK]; -}; - -#ifdef SOAP_MEM_DEBUG -/* malloc/free tracking for debugging */ -struct soap_mlist -{ struct soap_mlist *next; - const void *ptr; - const char *file; - int line; - short live; -}; -#endif - -/* class allocation list */ -struct soap_clist -{ struct soap_clist *next; - void *ptr; - int type; - int size; - int (*fdelete)(struct soap_clist*); -}; - -/* attributes */ -struct soap_attribute -{ struct soap_attribute *next; - char *value; - size_t size; - char *ns; - short visible; - char name[1]; /* the actual name string flows into the allocated region below this struct */ -}; - -#ifndef WITH_LEAN -struct soap_cookie -{ struct soap_cookie *next; - char *name; - char *value; - char *domain; - char *path; - time_t expire; /* client-side: local time to expire */ - long maxage; /* server-side: seconds to expire */ - unsigned int version; - short secure; - short session; /* server-side */ - short env; /* server-side: got cookie from client and should not be (re)send */ - short modified; /* server-side: client cookie was modified and should be send */ -}; -#endif - -#ifdef __cplusplus -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); - -class soap_multipart_iterator -{ public: - struct soap_multipart *content; - bool operator==(const soap_multipart_iterator& iter) const - { return content == iter.content; } - bool operator!=(const soap_multipart_iterator& iter) const - { return content != iter.content; } - struct soap_multipart &operator*() const - { return *content; } - soap_multipart_iterator &operator++() - { content = soap_next_multipart(content); return *this; } - soap_multipart_iterator() : content(NULL) - { } - soap_multipart_iterator(struct soap_multipart *p) : content(p) - { } -}; -#endif - -#ifndef WITH_LEANER -struct soap_dime -{ size_t count; - size_t size; - size_t chunksize; - size_t buflen; - char flags; - char *ptr; - const char *id; - const char *type; - const char *options; - struct soap_multipart *list; /* list of DIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -struct soap_mime -{ char *boundary; /* MIME boundary */ - const char *start; /* MIME start ID */ - struct soap_multipart *list; /* list of MIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* RFC2045 MIME content transfer encodings */ -enum soap_mime_encoding -{ SOAP_MIME_NONE, - SOAP_MIME_7BIT, - SOAP_MIME_8BIT, - SOAP_MIME_BINARY, - SOAP_MIME_QUOTED_PRINTABLE, - SOAP_MIME_BASE64, - SOAP_MIME_IETF_TOKEN, - SOAP_MIME_X_TOKEN -}; -#endif - -#ifndef WITH_LEANER -/* DIME/MIME multipart list */ -struct soap_multipart -{ struct soap_multipart *next; - char *ptr; /* points to raw data content */ - size_t size; /* size of data content */ - const char *id; /* DIME/MIME content ID or form data name */ - const char *type; /* DIME/MIME type (MIME type format) */ - const char *options; /* DIME options */ - enum soap_mime_encoding encoding; /* MIME Content-Transfer-Encoding */ - const char *location; /* MIME Content-Location (optional) */ - const char *description; /* MIME Content-Description (optional) */ -#ifdef __cplusplus - typedef soap_multipart_iterator iterator; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* attachment DIME and MTOM XOP forwarding */ -struct soap_xlist -{ struct soap_xlist *next; - unsigned char **ptr; - int *size; - char *id; - char **type; - char **options; -}; -#endif - -/******************************************************************************/ - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_attribute_iterator -{ public: - struct soap_dom_attribute *att; - const char *nstr; - const char *name; - bool operator==(const soap_dom_attribute_iterator&) const; - bool operator!=(const soap_dom_attribute_iterator&) const; - struct soap_dom_attribute &operator*() const; - soap_dom_attribute_iterator &operator++(); - soap_dom_attribute_iterator(); - soap_dom_attribute_iterator(struct soap_dom_attribute*); - ~soap_dom_attribute_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_attribute -{ struct soap_dom_attribute *next; - const char *nstr; - char *name; - char *data; - wchar_t *wide; - struct soap *soap; -#ifdef __cplusplus - typedef soap_dom_attribute_iterator iterator; - struct soap_dom_attribute &set(const char *nstr, const char *name); /* set namespace and name */ - struct soap_dom_attribute &set(const char *data); /* set data */ - soap_dom_attribute_iterator begin(); - soap_dom_attribute_iterator end(); - soap_dom_attribute_iterator find(const char *nstr, const char *name); - void unlink(); - soap_dom_attribute(); - soap_dom_attribute(struct soap *soap); - soap_dom_attribute(struct soap *soap, const char *nstr, const char *name, const char *data); - ~soap_dom_attribute(); -#endif -}; -#endif - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_element_iterator -{ public: - struct soap_dom_element *elt; - const char *nstr; - const char *name; - int type; - bool operator==(const soap_dom_element_iterator&) const; - bool operator!=(const soap_dom_element_iterator&) const; - struct soap_dom_element &operator*() const; - soap_dom_element_iterator &operator++(); - soap_dom_element_iterator(); - soap_dom_element_iterator(struct soap_dom_element*); - ~soap_dom_element_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_element -{ struct soap_dom_element *next; /* next sibling */ - struct soap_dom_element *prnt; /* parent */ - struct soap_dom_element *elts; /* list of child elements */ - struct soap_dom_attribute *atts; /* list of attributes */ - const char *nstr; /* namespace string */ - char *name; /* element tag name */ - char *data; /* element content data (with SOAP_C_UTFSTRING flag set) */ - wchar_t *wide; /* element content data */ - int type; /* optional: serialized C/C++ data type */ - void *node; /* optional: pointer to serialized C/C++ data */ - char *head; /* leading whitespace to start tag */ - char *tail; /* leading whitespace to end tag */ - struct soap *soap; /* soap context that manages this node */ -#ifdef __cplusplus - typedef soap_dom_element_iterator iterator; - struct soap_dom_element &set(const char *nstr, const char *name); - struct soap_dom_element &set(const char *data); - struct soap_dom_element &set(void *node, int type); - struct soap_dom_element &add(struct soap_dom_element*); - struct soap_dom_element &add(struct soap_dom_element&); - struct soap_dom_element &add(struct soap_dom_attribute*); - struct soap_dom_element &add(struct soap_dom_attribute&); - soap_dom_element_iterator begin(); - soap_dom_element_iterator end(); - soap_dom_element_iterator find(const char *nstr, const char *name); - soap_dom_element_iterator find(int type); - void unlink(); - soap_dom_element(); - soap_dom_element(struct soap *soap); - soap_dom_element(struct soap *soap, const char *nstr, const char *name); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type); - ~soap_dom_element(); -#endif -}; -SOAP_FMAC1 struct soap_dom_element * SOAP_FMAC2 soap_dom_next_element(struct soap_dom_element *elt); -SOAP_FMAC1 struct soap_dom_attribute * SOAP_FMAC2 soap_dom_next_attribute(struct soap_dom_attribute *att); -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -} -extern std::ostream &operator<<(std::ostream&, const struct soap_dom_element&); -extern std::istream &operator>>(std::istream&, struct soap_dom_element&); -extern "C" { -#endif - -/******************************************************************************/ - -#ifdef WIN32 -# ifdef SOAP_STD_EXPORTS -# define SOAP_STD_API __declspec(dllexport) -# else -# define SOAP_STD_API -# endif -#else -# define SOAP_STD_API -#endif - -struct SOAP_STD_API soap -{ short state; /* 0 = uninitialized, 1 = initialized, 2 = copy of another soap struct */ - short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table) */ - soap_mode mode; - soap_mode imode; - soap_mode omode; - const char *float_format; /* user-definable format string for floats (<1024 chars) */ - const char *double_format; /* user-definable format string for doubles (<1024 chars) */ - const char *dime_id_format; /* user-definable format string for integer DIME id ( 0, gives socket recv timeout in seconds, < 0 in usec */ - int send_timeout; /* when > 0, gives socket send timeout in seconds, < 0 in usec */ - int connect_timeout; /* when > 0, gives socket connect() timeout in seconds, < 0 in usec */ - int accept_timeout; /* when > 0, gives socket accept() timeout in seconds, < 0 in usec */ - int socket_flags; /* socket recv() and send() flags, e.g. set to MSG_NOSIGNAL to disable sigpipe */ - int connect_flags; /* connect() SOL_SOCKET sockopt flags, e.g. set to SO_DEBUG to debug socket */ - int bind_flags; /* bind() SOL_SOCKET sockopt flags, e.g. set to SO_REUSEADDR to enable reuse */ - int accept_flags; /* accept() SOL_SOCKET sockopt flags */ - const struct Namespace *namespaces; /* Pointer to global namespace mapping table */ - struct Namespace *local_namespaces; /* Local namespace mapping table */ - struct soap_nlist *nlist; /* namespace stack */ - struct soap_blist *blist; /* block allocation stack */ - struct soap_clist *clist; /* class instance allocation list */ - void *alist; /* memory allocation (malloc) list */ - struct soap_ilist *iht[SOAP_IDHASH]; - struct soap_plist *pht[SOAP_PTRHASH]; - struct soap_pblk *pblk; /* plist block allocation */ - short pidx; /* plist block allocation */ - struct SOAP_ENV__Header *header; - struct SOAP_ENV__Fault *fault; - int idnum; - void *user; /* to pass user-defined data */ - struct soap_plugin *plugins; /* linked list of plug-in data */ - char *userid; /* HTTP Basic authorization userid */ - char *passwd; /* HTTP Basic authorization passwd */ - int (*fpost)(struct soap*, const char*, const char*, int, const char*, const char*, size_t); - int (*fget)(struct soap*); - int (*fput)(struct soap*); - int (*fdel)(struct soap*); - int (*fhead)(struct soap*); - int (*fform)(struct soap*); - int (*fposthdr)(struct soap*, const char*, const char*); - int (*fresponse)(struct soap*, int, size_t); - int (*fparse)(struct soap*); - int (*fparsehdr)(struct soap*, const char*, const char*); - int (*fheader)(struct soap*); - int (*fresolve)(struct soap*, const char*, struct in_addr* inaddr); - int (*fconnect)(struct soap*, const char*, const char*, int); - int (*fdisconnect)(struct soap*); - int (*fclosesocket)(struct soap*, SOAP_SOCKET); - int (*fshutdownsocket)(struct soap*, SOAP_SOCKET, int); - SOAP_SOCKET (*fopen)(struct soap*, const char*, const char*, int); - SOAP_SOCKET (*faccept)(struct soap*, SOAP_SOCKET, struct sockaddr*, int *n); - int (*fclose)(struct soap*); - int (*fsend)(struct soap*, const char*, size_t); - size_t (*frecv)(struct soap*, char*, size_t); - int (*fpoll)(struct soap*); - void (*fseterror)(struct soap*, const char **c, const char **s); - int (*fignore)(struct soap*, const char*); - int (*fserveloop)(struct soap*); - void *(*fplugin)(struct soap*, const char*); - void *(*fmalloc)(struct soap*, size_t); -#ifndef WITH_LEANER - int (*fprepareinit)(struct soap*); - int (*fpreparesend)(struct soap*, const char*, size_t); - int (*fpreparerecv)(struct soap*, const char*, size_t); - int (*fpreparefinal)(struct soap*); - void *(*fdimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fdimewriteopen)(struct soap*, const char*, const char*, const char*); - void (*fdimereadclose)(struct soap*, void*); - void (*fdimewriteclose)(struct soap*, void*); - size_t (*fdimeread)(struct soap*, void*, char*, size_t); - int (*fdimewrite)(struct soap*, void*, const char*, size_t); - void *(*fmimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fmimewriteopen)(struct soap*, void*, const char*, const char*, const char*, enum soap_mime_encoding); - void (*fmimereadclose)(struct soap*, void*); - void (*fmimewriteclose)(struct soap*, void*); - size_t (*fmimeread)(struct soap*, void*, char*, size_t); - int (*fmimewrite)(struct soap*, void*, const char*, size_t); -#endif - SOAP_SOCKET master; - SOAP_SOCKET socket; -#if defined(__cplusplus) && !defined(WITH_LEAN) - std::ostream *os; - std::istream *is; -#else - void *os; /* preserve alignment */ - void *is; /* preserve alignment */ -#endif -#ifndef UNDER_CE - int sendfd; - int recvfd; -#else - FILE *sendfd; - FILE *recvfd; -#endif - size_t bufidx; /* index in soap.buf[] */ - size_t buflen; /* length of soap.buf[] content */ - soap_wchar ahead; /* parser lookahead */ - short cdata; /* CDATA parser state */ - short body; /* parsed XML element has a body or not */ - unsigned int level; /* XML nesting level */ - size_t count; /* message length counter */ - size_t length; /* message length as set by HTTP header */ - char *labbuf; /* look-aside buffer */ - size_t lablen; /* look-aside buffer allocated length */ - size_t labidx; /* look-aside buffer index to available part */ - char buf[SOAP_BUFLEN];/* send and receive buffer */ - char msgbuf[1024]; /* in/output buffer for messages >=1024 bytes */ - char tmpbuf[1024]; /* in/output buffer for HTTP/MIME headers, simpleType values, attribute names, and DIME must be >=1024 bytes */ - char tag[SOAP_TAGLEN]; - char id[SOAP_TAGLEN]; - char href[SOAP_TAGLEN]; - char type[SOAP_TAGLEN]; - char arrayType[SOAP_TAGLEN]; - char arraySize[SOAP_TAGLEN]; - char arrayOffset[SOAP_TAGLEN]; - short other; - short position; - int positions[SOAP_MAXDIMS]; - short root; - struct soap_attribute *attributes; /* attribute list */ - short encoding; /* when set, output encodingStyle */ - short mustUnderstand; /* a mustUnderstand element was parsed or is output */ - short null; /* parsed XML is xsi:nil */ - short ns; /* when not set, output full xmlns bindings */ - short part; /* parsing state */ - short alloced; - short peeked; - size_t chunksize; - size_t chunkbuflen; - char endpoint[SOAP_TAGLEN]; - char path[SOAP_TAGLEN]; - char host[SOAP_TAGLEN]; - char *action; - char *authrealm; /* HTTP authentication realm */ - char *prolog; /* XML declaration prolog */ - unsigned long ip; /* IP number */ - int port; /* port number */ - short keep_alive; /* connection should be kept open */ - short tcp_keep_alive; /* enable SO_KEEPALIVE */ - unsigned int tcp_keep_idle; /* set TCP_KEEPIDLE */ - unsigned int tcp_keep_intvl; /* set TCP_KEEPINTVL */ - unsigned int tcp_keep_cnt; /* set TCP_KEEPCNT */ - unsigned int max_keep_alive; /* maximum keep-alive session (default=100) */ - const char *proxy_http_version;/* HTTP version of proxy "1.0" or "1.1" */ - const char *proxy_host; /* Proxy Server host name */ - int proxy_port; /* Proxy Server port (default = 8080) */ - const char *proxy_userid; /* Proxy Authorization user name */ - const char *proxy_passwd; /* Proxy Authorization password */ - const char *proxy_from; /* X-Forwarding-For header returned by proxy */ - int status; /* -1 when request, else error code to be returned by server */ - int error; - int errmode; - int errnum; -#ifndef WITH_LEANER - struct soap_dom_element *dom; - struct soap_dime dime; - struct soap_mime mime; - struct soap_xlist *xlist; -#endif -#if !defined(WITH_LEAN) || defined(SOAP_DEBUG) - const char *logfile[SOAP_MAXLOGS]; - FILE *fdebug[SOAP_MAXLOGS]; - struct soap_mlist *mht[SOAP_PTRHASH]; -#endif -#ifndef WITH_LEAN - const char *c14ninclude; - const char *c14nexclude; - struct soap_cookie *cookies; - const char *cookie_domain; - const char *cookie_path; - int cookie_max; -#endif -#ifndef WITH_NOIO -#ifdef WITH_IPV6 - struct sockaddr_storage peer; /* IPv6: set by soap_accept and by UDP recv */ -#else - struct sockaddr_in peer; /* IPv4: set by soap_connect/soap_accept and by UDP recv */ -#endif -#endif - size_t peerlen; -#ifdef WITH_OPENSSL - int (*fsslauth)(struct soap*); - int (*fsslverify)(int, X509_STORE_CTX*); - BIO *bio; - SSL *ssl; - SSL_CTX *ctx; - SSL_SESSION *session; -#else - void *fsslauth; /* dummy members, to preserve alignment */ - void *fsslverify; - void *bio; - void *ssl; - void *ctx; - void *session; -#endif - unsigned short ssl_flags; - const char *keyfile; - const char *password; - const char *dhfile; - const char *cafile; - const char *capath; - const char *crlfile; - const char *randfile; - char session_host[SOAP_TAGLEN]; - int session_port; -#ifdef WITH_ZLIB - z_stream *d_stream; /* decompression stream */ - uLong z_crc; /* internal gzip crc */ -#else - void *d_stream; /* dummy members, to preserve alignment */ - soap_int32 z_crc; -#endif - short zlib_state; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_INFLATE */ - short zlib_in; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - short zlib_out; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - char *z_buf; /* buffer */ - size_t z_buflen; - unsigned short z_level; /* compression level to be used (0=none, 1=fast to 9=best) */ - float z_ratio_in; /* detected compression ratio compressed_length/length of inbound message */ - float z_ratio_out; /* detected compression ratio compressed_length/length of outbound message */ -#ifdef WMW_RPM_IO - void *rpmreqid; -#endif -#ifdef __cplusplus - soap(); - soap(soap_mode); - soap(soap_mode, soap_mode); - soap(struct soap&); - virtual ~soap(); -#endif -}; - -struct soap_code_map -{ long code; - const char *string; -}; - -/* forwarding list */ -struct soap_flist -{ struct soap_flist *next; - int type; - void *ptr; - unsigned int level; - size_t len; - void (*fcopy)(struct soap*, int, int, void*, size_t, const void*, size_t); -}; - -/* id-ref forwarding list */ -struct soap_ilist -{ struct soap_ilist *next; - int type; - size_t size; - void *link; - void *copy; - struct soap_flist *flist; - void *ptr; - unsigned int level; - char id[1]; /* the actual id string value flows into the allocated region below this struct */ -}; - -struct soap_plugin -{ struct soap_plugin *next; - const char *id; - void *data; - int (*fcopy)(struct soap *soap, struct soap_plugin *dst, struct soap_plugin *src); - void (*fdelete)(struct soap *soap, struct soap_plugin *p); /* should delete fields of plugin only and not free(p) */ -}; - -#ifndef WITH_NONAMESPACES -extern SOAP_NMAC struct Namespace namespaces[]; -#endif - -#ifndef WITH_LEAN -# define soap_get0(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx]) -# define soap_get1(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx++]) -#else -soap_wchar soap_get0(struct soap*); -soap_wchar soap_get1(struct soap*); -#endif - -#define soap_revget1(soap) ((soap)->bufidx--) -#define soap_unget(soap, c) ((soap)->ahead = c) -#define soap_register_plugin(soap, plugin) soap_register_plugin_arg(soap, plugin, NULL) -#define soap_imode(soap, n) ((soap)->mode = (soap)->imode = (n)) -#define soap_set_imode(soap, n) ((soap)->imode |= (n)) -#define soap_clr_imode(soap, n) ((soap)->imode &= ~(n)) -#define soap_omode(soap, n) ((soap)->mode = (soap)->omode = (n)) -#define soap_set_omode(soap, n) ((soap)->omode |= (n)) -#define soap_clr_omode(soap, n) ((soap)->omode &= ~(n)) -#define soap_set_mode(soap, n) ((soap)->imode |= (n), (soap)->omode |= (n)) -#define soap_clr_mode(soap, n) ((soap)->imode &= ~(n), (soap)->omode &= ~(n)) -#define soap_destroy(soap) soap_delete((soap), NULL) - -#ifdef HAVE_STRRCHR -# define soap_strrchr(s, t) strrchr(s, t) -#else - SOAP_FMAC1 char* SOAP_FMAC2 soap_strrchr(const char *s, int t); -#endif - -#ifdef HAVE_STRTOL -# define soap_strtol(s, t, b) strtol(s, t, b) -#else - SOAP_FMAC1 long SOAP_FMAC2 soap_strtol(const char *s, char **t, int b); -#endif - -#ifdef HAVE_STRTOUL -# define soap_strtoul(s, t, b) strtoul(s, t, b) -#else - SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b); -#endif - -#if defined(WITH_OPENSSL) -# define soap_random soap_rand() -SOAP_FMAC1 int SOAP_FMAC2 soap_rand(void); -#elif defined(HAVE_RANDOM) -# define soap_random (int)random() -#else -# define soap_random rand() -#endif - -#ifdef WITH_NOIDREF -# define soap_embedded(s, p, t) (0) -# define soap_id_lookup(s, i, p, t, n, k) (p) -# define soap_id_forward(s, h, p, len, st, tt, n, k, fc) (p) -# define soap_reference(s, a, t) (1) -# define soap_array_reference(s, p, a, n, t) (1) -# define soap_embed(s, p, a, n, t, pp) (0) -# define soap_embedded_id(s, i, p, t) (i) -# define soap_is_embedded(s, p) (0) -# define soap_is_single(s, p) (1) -# define soap_lookup_type(s, i) (0) -# define soap_getindependent(s) (0) -# define soap_putindependent(s) (0) -# define soap_getelement(s, n) (n) -# define soap_putelement(s, p, t, i, n) (0) -# define soap_markelement(s, p, n) (0) -#endif - -SOAP_FMAC1 void SOAP_FMAC2 soap_header(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_fault(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultsubcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultstring(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultdetail(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializefault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getfault(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_ssl_init(); -SOAP_FMAC1 int SOAP_FMAC2 soap_poll(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect_command(struct soap*, int, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect(struct soap*, const char*, const char*); -SOAP_FMAC1 SOAP_SOCKET SOAP_FMAC2 soap_bind(struct soap*, const char*, int, int); -SOAP_FMAC1 SOAP_SOCKET SOAP_FMAC2 soap_accept(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_accept(struct soap*); -SOAP_FMAC1 const char * SOAP_FMAC2 soap_ssl_error(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_puthttphdr(struct soap*, int status, size_t count); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_get_header_attribute(struct soap*, const char*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_key(char*, size_t, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_val(char*, size_t, const char*); - -SOAP_FMAC1 size_t SOAP_FMAC2 soap_hash(const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_endpoint(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_get(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getchar(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_tag_cmp(const char*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_sender_error(struct soap*, const char*, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_receiver_error(struct soap*, const char*, const char*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_raw(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send2(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send3(struct soap*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pututf8(struct soap*, unsigned long); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getutf8(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_putbase64(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_getbase64(struct soap*, int*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_puthex(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_gethex(struct soap*, int*); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_xop_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_dime_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -#endif - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup_id(struct soap*, void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup(struct soap*, const void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_enter(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_pointer_lookup(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -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); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_lookup(struct soap*, const char*); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_enter(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_resolve(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_embedded(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_reference(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_reference(struct soap*, const void *p, const struct soap_array *a, int n, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_embedded_id(struct soap*, int id, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_embedded(struct soap*, struct soap_plist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_single(struct soap*, struct soap_plist*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_embedded(struct soap*, struct soap_plist*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_send(struct soap*); - -SOAP_FMAC1 const struct soap_code_map* SOAP_FMAC2 soap_code(const struct soap_code_map*, const char*); -SOAP_FMAC1 long SOAP_FMAC2 soap_code_int(const struct soap_code_map*, const char*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_code_str(const struct soap_code_map*, long); -SOAP_FMAC1 long SOAP_FMAC2 soap_code_bits(const struct soap_code_map*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_code_list(struct soap*, const struct soap_code_map*, long); - -SOAP_FMAC1 int SOAP_FMAC2 soap_getline(struct soap*, char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_recv(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_malloc(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_dealloc(struct soap*, void*); -SOAP_FMAC1 struct soap_clist * SOAP_FMAC2 soap_link(struct soap*, void*, int, int, int (*fdelete)(struct soap_clist*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_unlink(struct soap*, const void*); -SOAP_FMAC1 void SOAP_FMAC2 soap_free_temp(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_del(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_track_malloc(struct soap*, const char*, int, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_track_free(struct soap*, const char*, int, void*); - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_lookup_type(struct soap*, const char *id); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_lookup(struct soap*, const char *id, void **p, int t, size_t n, unsigned int k); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_forward(struct soap*, const char *id, void *p, size_t len, int st, int tt, size_t n, unsigned int k, void(*fcopy)(struct soap*, int, int, void*, size_t, const void*, size_t)); -#endif -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_enter(struct 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*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_fcopy(struct soap *soap, int st, int tt, void *p, size_t, const void *q, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_size(const int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getoffsets(const char *, const int *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsize(const char *, const char *, int *); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsizes(const char *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getposition(const char *, int *); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsize(struct soap*, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizesoffsets(struct soap*, const char *, const int *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizes(struct soap*, const char *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffset(struct soap*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffsets(struct soap*, const int *, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_closesock(struct soap*); - -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new(void); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new1(soap_mode); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new2(soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_free(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(const struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*, const struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_copy_stream(struct soap*, struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init1(struct soap*, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_init2(struct soap*, soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_end(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_delete(struct soap*, void*); - -#ifdef SOAP_DEBUG -SOAP_FMAC1 void SOAP_FMAC2 soap_set_recv_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_sent_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_test_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_close_logfiles(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_open_logfile(struct soap*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_value(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_tag(struct soap*, const char*, const char *); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_array(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element(struct soap*, const char*, int, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_out(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_begin_out(struct soap*, const char *tag, int id, const char *type, const char *offset); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_ref(struct soap*, const char *tag, int id, int href); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_href(struct soap*, const char *tag, int id, const char *ref, const char *val); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_null(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_id(struct soap*, const char *tag, int id, const void *p, const struct soap_array *a, int d, const char *type, int n); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_result(struct soap*, const char *tag); -SOAP_FMAC1 void SOAP_FMAC2 soap_check_result(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_out(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_start_end_out(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_attribute(struct soap*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_in(struct soap*, const char *tag, int nillable, const char *type); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_in(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_peek_element(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_retry(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_revert(struct soap*); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_strdup(struct soap*, const char*); -SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstrdup(struct soap*, const wchar_t*); -SOAP_FMAC1 const char * SOAP_FMAC2 soap_strsearch(const char *big, const char *little); - -SOAP_FMAC1 int SOAP_FMAC2 soap_string_out(struct soap*, const char *s, int flag); -SOAP_FMAC1 char* SOAP_FMAC2 soap_string_in(struct soap*, int, long, long); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_wstring_out(struct soap*, const wchar_t *s, int flag); -SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstring_in(struct soap*, int, long, long); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_namespace(struct soap*, const char *, const char*, size_t n1, size_t n2); - -SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap*, const struct Namespace*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_local_namespaces(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_namespace(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_push_namespace(struct soap*, const char *,const char *); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_current_namespace(struct soap *soap, const char *tag); - -SOAP_FMAC1 struct soap_nlist* SOAP_FMAC2 soap_lookup_ns(struct soap *soap, const char *tag, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_store_lab(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_append_lab(struct soap*, const char*, size_t); - -SOAP_FMAC1 int SOAP_FMAC2 soap_new_block(struct soap*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_push_block(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_size_block(struct soap*, size_t); -SOAP_FMAC1 char* SOAP_FMAC2 soap_first_block(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_next_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_block_size(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_save_block(struct soap*, char*, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*); -SOAP_FMAC1 int soap_envelope_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_out(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_header(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_response(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_empty_response(struct soap*, int status); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_empty_response(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_fault(struct soap*); - -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap*, FILE*); -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault_location(struct soap*, FILE*); -# ifndef WITH_LEAN -# ifdef __cplusplus -SOAP_FMAC1 void SOAP_FMAC2 soap_stream_fault(struct soap*, std::ostream&); -# endif -SOAP_FMAC1 char* SOAP_FMAC2 soap_sprint_fault(struct soap*, char*, size_t); -# endif -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_s2byte(struct soap*, const char*, char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2short(struct soap*, const char*, short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2int(struct soap*, const char*, int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2long(struct soap*, const char*, long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2LONG64(struct soap*, const char*, LONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2float(struct soap*, const char*, float*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2double(struct soap*, const char*, double*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedByte(struct soap*, const char*, unsigned char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedShort(struct soap*, const char*, unsigned short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedInt(struct soap*, const char*, unsigned int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedLong(struct soap*, const char*, unsigned long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2ULONG64(struct soap*, const char*, ULONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2string(struct soap*, const char*, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2QName(struct soap*, const char*, char**); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_s2wchar(struct soap*, const char*, wchar_t**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2dateTime(struct soap*, const char*, time_t*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2base64(struct soap*, const unsigned char*, char*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2hex(struct soap*, const unsigned char*, char*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_byte2s(struct soap*, char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_short2s(struct soap*, short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_int2s(struct soap*, int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_long2s(struct soap*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_LONG642s(struct soap*, LONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_float2s(struct soap*, float); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_double2s(struct soap*, double); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedByte2s(struct soap*, unsigned char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedShort2s(struct soap*, unsigned short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedInt2s(struct soap*, unsigned int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedLong2s(struct soap*, unsigned long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_ULONG642s(struct soap*, ULONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_QName2s(struct soap*, const char*); - -#ifndef WITH_LEAN -SOAP_FMAC1 const char* SOAP_FMAC2 soap_wchar2s(struct soap*, const wchar_t*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_dateTime2s(struct soap*, time_t); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_base642s(struct soap*, const char*, char*, size_t, int*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_hex2s(struct soap*, const char*, char*, size_t, int*); -#endif - - -SOAP_FMAC1 int* SOAP_FMAC2 soap_inint(struct soap*, const char *tag, int *p, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_inbyte(struct soap*, const char *tag, char *p, const char *, int); -SOAP_FMAC1 long* SOAP_FMAC2 soap_inlong(struct soap*, const char *tag, long *p, const char *, int); -SOAP_FMAC1 LONG64* SOAP_FMAC2 soap_inLONG64(struct soap*, const char *tag, LONG64 *p, const char *, int); -SOAP_FMAC1 short* SOAP_FMAC2 soap_inshort(struct soap*, const char *tag, short *p, const char *, int); -SOAP_FMAC1 float* SOAP_FMAC2 soap_infloat(struct soap*, const char *tag, float *p, const char *, int); -SOAP_FMAC1 double* SOAP_FMAC2 soap_indouble(struct soap*, const char *tag, double *p, const char *, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_inunsignedByte(struct soap*, const char *tag, unsigned char *p, const char *, int); -SOAP_FMAC1 unsigned short* SOAP_FMAC2 soap_inunsignedShort(struct soap*, const char *tag, unsigned short *p, const char *, int); -SOAP_FMAC1 unsigned int* SOAP_FMAC2 soap_inunsignedInt(struct soap*, const char *tag, unsigned int *p, const char *, int); -SOAP_FMAC1 unsigned long* SOAP_FMAC2 soap_inunsignedLong(struct soap*, const char *tag, unsigned long *p, const char *, int); -SOAP_FMAC1 ULONG64* SOAP_FMAC2 soap_inULONG64(struct soap*, const char *tag, ULONG64 *p, const char *, int); -SOAP_FMAC1 char** SOAP_FMAC2 soap_instring(struct soap*, const char *tag, char **p, const char *, int, int, long, long); -SOAP_FMAC1 char** SOAP_FMAC2 soap_inliteral(struct soap*, const char *tag, char **p); - -#ifndef WITH_LEAN -SOAP_FMAC1 time_t* SOAP_FMAC2 soap_indateTime(struct soap*, const char *tag, time_t *p, const char *, int); -SOAP_FMAC1 time_t SOAP_FMAC2 soap_timegm(struct tm*); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwstring(struct soap*, const char *tag, wchar_t **p, const char *, int, long, long); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwliteral(struct soap*, const char *tag, wchar_t **p); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_outbyte(struct soap*, const char *tag, int id, const char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outshort(struct soap*, const char *tag, int id, const short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outint(struct soap*, const char *tag, int id, const int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outlong(struct soap*, const char *tag, int id, const long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outLONG64(struct soap*, const char *tag, int id, const LONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outfloat(struct soap*, const char *tag, int id, const float *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdouble(struct soap*, const char *tag, int id, const double *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedByte(struct soap*, const char *tag, int id, const unsigned char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedShort(struct soap*, const char *tag, int id, const unsigned short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedInt(struct soap*, const char *tag, int id, const unsigned int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedLong(struct soap*, const char *tag, int id, const unsigned long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outULONG64(struct soap*, const char *tag, int id, const ULONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outstring(struct soap*, const char *tag, int id, char *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outliteral(struct soap*, const char *tag, char *const*p, const char *type); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_outdateTime(struct soap*, const char *tag, int id, const time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_outwstring(struct soap*, const char *tag, int id, wchar_t *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwliteral(struct soap*, const char *tag, wchar_t *const*p, const char *type); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_attachment(struct soap *, const char*, int, const void*, const struct soap_array*, const char*, const char*, const char*, int, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, long); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_tell(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_dime_option(struct soap*, unsigned short, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmimehdr(struct soap*, struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_mime(struct soap*, const char *boundary, const char *start); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_mime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_dime_attachment(struct soap*, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_mime_attachment(struct soap*, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description); -SOAP_FMAC1 void SOAP_FMAC2 soap_post_check_mime_attachments(struct soap *soap); -SOAP_FMAC1 int SOAP_FMAC2 soap_check_mime_attachments(struct soap *soap); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_get_mime_attachment(struct soap *soap, void *handle); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_cid(struct soap*, const char*, const char*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_register_plugin_arg(struct soap*, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_lookup_plugin(struct soap*, const char*); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_attr_value(struct soap *soap, const char *name, int flag); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_attr(struct soap *soap, const char *name, const char *value); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_attr(struct soap *soap); - -#ifdef WITH_COOKIES -SOAP_FMAC1 void SOAP_FMAC2 soap_getcookies(struct soap *soap, const char *val); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_encode_cookie(const char*, char*, size_t); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_set_cookie(struct soap*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_env_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern time_t SOAP_FMAC2 soap_cookie_expire(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_expire(struct soap*, const char*, long, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_clr_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_clr_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_getenv_cookies(struct soap*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_copy_cookies(struct soap*, const struct soap*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_free_cookies(struct soap*); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.c b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.c deleted file mode 100644 index 6b7160b..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.c +++ /dev/null @@ -1,13101 +0,0 @@ -/* - -stdsoap2.c[pp] 2.7.6b - -gSOAP runtime - -gSOAP XML Web services tools -Copyright (C) 2000-2005, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under one of the following licenses: -GPL, the gSOAP public license, or Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems, Inc., for the following additions: - - vxWorks compatible --------------------------------------------------------------------------------- -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-2005, 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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- - -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.6b 2005-08-26 12:00:00 GMT") -extern "C" { -#else -SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.7.6b 2005-08-26 12:00:00 GMT") -#endif - -/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale with multibyte support enabled) */ -#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_QT (soap_wchar)(-5) /* XML character '"' */ -#define SOAP_AP (soap_wchar)(-6) /* XML character ''' */ - -#define SOAP_BOM (soap_wchar)(0xFEFF) /* UTF BOM is Unicode FEFF */ - -#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*); - -#ifndef WITH_NOIDREF -static void soap_update_ptrs(struct soap*, char*, char*, long); -static int soap_has_copies(struct soap*, const char*, 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*); -#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*); -static void soap_free_mht(struct soap*); -static void soap_track_unlink(struct soap*, const void*); -#endif - -static int soap_set_error(struct soap*, const char*, const char*, const char*, const char*, int); -static int soap_copy_fault(struct soap*, const char*, const char*, const char*, const char*); -static int soap_getattrval(struct soap*, char*, size_t, soap_wchar); -static void *fplugin(struct soap*, const char*); - -#ifndef WITH_LEAN -static const char *soap_set_validation_fault(struct soap*, const char*, const char*); -static int soap_isnumeric(struct soap*, const char*); -static time_t soap_timegm(struct tm*); -static struct soap_nlist *soap_lookup_ns(struct soap *soap, const char *tag, size_t n); -static struct soap_nlist *soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized); -static void soap_pop_ns(struct soap *soap); -static void soap_utilize_ns(struct soap *soap, const char *tag, size_t n); -#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*); -static int soap_match_cid(const char*, const char*); -static void soap_resolve_attachment(struct soap*, struct soap_multipart*); -#endif - -#ifdef WITH_GZIP -static int soap_getgziphdr(struct soap*); -#endif - -#ifdef WITH_OPENSSL -static void ssl_init(); -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 - -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -static const char *soap_decode(char*, size_t, const char*, const char*); -#endif - -#ifndef WITH_NOHTTP -static soap_wchar soap_getchunkchar(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*); -#endif - -#ifndef WITH_NOIO -static int fsend(struct soap*, const char*, size_t); -static size_t frecv(struct soap*, char*, size_t); -static int tcp_init(struct soap*); -static const char *tcp_error(struct soap*); -#ifndef WITH_IPV6 -static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr); -#endif -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 const char *soap_strerror(struct soap*); -#endif - -#ifdef VXWORKS -static int vx_nonblocking = TRUE; /* ioctl argument */ -#endif - -#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 - -#ifndef WITH_LEAN -static const char soap_indent[11] = "\n\t\t\t\t\t\t\t\t\t"; -/* Alternative indentation form for SOAP_XML_INDENT: -static const char soap_indent[21] = "\n "; -*/ -#endif - -static const char soap_padding[3] = "\0\0"; -#define SOAP_STR_PADDING (soap_padding) -#define SOAP_STR_EOS (soap_padding) -#define SOAP_NON_NULL (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_NOIO -#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 -#endif - -#ifndef WITH_NOHTTP -#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 -#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 WITH_NOIO -#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_socket_errno != SOAP_EAGAIN) - { soap->errnum = soap_socket_errno; - return SOAP_EOF; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - nwritten = SSL_write(soap->ssl, s, n); - else if (soap->bio) - nwritten = BIO_write(soap->bio, s, n); - else -#endif -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - { if (soap->peerlen) - nwritten = sendto((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, soap->peerlen); - else - nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); - /* retry and back-off algorithm */ - /* TODO: this is not very clear from specs so verify and limit conditions under which we should loop (e.g. ENOBUFS) */ - if (nwritten < 0) - { struct timeval timeout; - fd_set fd; - int udp_repeat; - int udp_delay; - if ((soap->connect_flags & SO_BROADCAST)) - udp_repeat = 3; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */ - else - udp_repeat = 1; /* SOAP-over-UDP UNICAST_UDP_REPEAT - 1 */ - udp_delay = (soap_random % 201) + 50; /* UDP_MIN_DELAY .. UDP_MAX_DELAY */ - do - { timeout.tv_sec = 0; - timeout.tv_usec = 1000 * udp_delay; /* ms */ - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); - select((SOAP_SOCKET)(soap->socket + 1), NULL, NULL, &fd, &timeout); - if (soap->peerlen) - nwritten = sendto((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, soap->peerlen); - else - nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); - udp_delay <<= 1; - if (udp_delay > 500) /* UDP_UPPER_DELAY */ - udp_delay = 500; - } - while (nwritten < 0 && --udp_repeat > 0); - } - } - 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 -#ifdef VXWORKS -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - nwritten = (httpBlockPut(soap->rpmreqid, s, n) == 0) ? n : -1; - 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 - nwritten = write((SOAP_SOCKET)soap->sendfd, s, n); -#endif -#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_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; -#ifndef WITH_LEANER - if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - 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_flush(struct soap *soap) -{ register int n = soap->bufidx; - if (n) - { soap->bufidx = 0; -#ifdef WITH_ZLIB - if (soap->mode & SOAP_ENC_ZLIB) - { soap->d_stream.next_in = (Byte*)soap->buf; - soap->d_stream.avail_in = (unsigned int)n; -#ifdef WITH_GZIP - soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)n); -#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 - return soap_flush_raw(soap, soap->buf, n); - } - return SOAP_OK; -} -#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); -#ifndef WITH_LEANER - if (soap->fpreparesend) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - return SOAP_OK; - } -#ifndef WITH_LEANER - 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); -#endif - return soap->error = soap->fsend(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 WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 - if (soap->recv_timeout) - { struct timeval timeout; - fd_set fd; - 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) - { soap->errnum = 0; - return 0; - } - if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN) - { soap->errnum = soap_socket_errno; - return 0; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - { int err; - r = SSL_read(soap->ssl, s, n); - if (r > 0) - return (size_t)r; - err = SSL_get_error(soap->ssl, r); - if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE) - return 0; - } - else if (soap->bio) - { r = BIO_read(soap->bio, s, n); - if (r > 0) - return (size_t)r; - return 0; - } - else -#endif - { -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - { SOAP_SOCKLEN_T k = (SOAP_SOCKLEN_T)sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - r = recvfrom((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, &k); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - soap->peerlen = (size_t)k; -#ifndef WITH_IPV6 - soap->ip = ntohl(soap->peer.sin_addr.s_addr); - soap->port = (int)ntohs(soap->peer.sin_port); -#endif - } - 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_socket_errno != SOAP_EWOULDBLOCK) - { 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); -#ifdef WITH_OPENSSL - if (soap->ssl && SSL_get_error(soap->ssl, r) == SSL_ERROR_WANT_WRITE) - r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); - else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#endif - 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 -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - r = httpBlockRead(soap->rpmreqid, s, n); -#endif - r = read((SOAP_SOCKET)soap->recvfd, s, n); - if (r >= 0) - return (size_t)r; - soap->errnum = soap_errno; - return 0; -#endif -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 from socket %d\n", (unsigned int)soap->buflen, soap->socket)); - DBGMSG(RECV, soap->buf, soap->buflen); - if (soap->buflen) - return soap->buf[soap->bufidx++]; - return EOF; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -static int -soap_isxdigit(int c) -{ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); -} -#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; - soap->error = SOAP_ZLIB_ERROR; - 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 -#ifndef WITH_NOHTTP - 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 (chunked) from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - soap->bufidx = 0; - if (!ret) - return soap->ahead = EOF; - } - else - soap->bufidx = soap->buflen; - soap->buflen = soap->chunkbuflen; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (idx=%u len=%u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen)); - while (!soap_isxdigit((int)(c = soap_getchunkchar(soap)))) - if ((int)c == EOF) - return soap->ahead = 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 soap->ahead = 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 soap->ahead = EOF; - } - soap->buflen = soap->bufidx + soap->chunksize; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to idx=%u len=%u (%s)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen, 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 (%u bytes left)\n", (unsigned int)(soap->buflen - soap->bufidx))); - } - else if (soap->chunkbuflen) - soap->chunksize = 0; - ret = soap->buflen - soap->bufidx; - if (!ret) - goto chunk_again; - } - } - else -#endif - { soap->bufidx = 0; - soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - } -#ifndef WITH_LEANER - if (soap->fpreparerecv && (soap->error = soap->fpreparerecv(soap, soap->buf, ret))) - return soap->error; -#endif -#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; - soap->error = SOAP_ZLIB_ERROR; - 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; - c = soap->ahead; - if (c) - { if (c != EOF) - 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) -{ if (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 - -/******************************************************************************/ -#ifdef WITH_LEAN -soap_wchar -soap_get0(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx]; -} -#endif - -/******************************************************************************/ -#ifdef WITH_LEAN -soap_wchar -soap_get1(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx++]; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -soap_wchar -SOAP_FMAC2 -soap_get(struct soap *soap) -{ register soap_wchar c; - c = soap->ahead; - if (c) - { if (c != EOF) - 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 == '%') - { register int k = 1; - 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) - { if (c == '<') - k++; - else if (c == '>') - { if (--k <= 0) - break; - } - 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 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) -{ char d[2]; - register int i; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!(soap->dom->data = soap_s2hex(soap, s, NULL, n))) - return soap->error; - return SOAP_OK; - } -#endif - 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_hex2s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#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, NULL, 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_base642s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#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 - 1); - p = (unsigned char*)soap_malloc(soap, soap->lablen - k + i - 1); - if (p) - memcpy(p, soap->labbuf, soap->lablen - k + i - 1); - 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 WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_xop_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ /* Check MTOM xop:Include element (within hex/base64Binary) */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - int body = soap->body; /* should save type too? */ - if (!soap_peek_element(soap)) - { if (!soap_element_begin_in(soap, "xop:Include", 0) && *soap->href) - { if (soap_dime_forward(soap, ptr, size, id, type, options)) - return soap->error; - } - if (soap->body && soap_element_end_in(soap, NULL)) - return soap->error; - } - soap->body = body; - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_dime_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ struct soap_xlist *xp = (struct soap_xlist*)SOAP_MALLOC(soap, sizeof(struct soap_xlist)); - *ptr = NULL; - *size = 0; - *id = soap_strdup(soap, soap->href); - *type = NULL; - *options = NULL; - if (!xp) - return soap->error = SOAP_EOM; - xp->next = soap->xlist; - xp->ptr = ptr; - xp->size = size; - xp->id = *id; - xp->type = type; - xp->options = options; - soap->xlist = xp; - return SOAP_OK; -} -#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(soap, 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(soap, 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(soap, p); -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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; -#ifndef WITH_LEANER - register struct soap_xlist *xp; -#endif - 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; - } - } - } - } -#ifndef WITH_LEANER - for (xp = soap->xlist; xp; xp = xp->next) - { if (xp->ptr && (char*)xp->ptr >= start && (char*)xp->ptr < end) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", xp->id?xp->id:"", xp->ptr, (char*)xp->ptr + offset)); - xp->ptr = (unsigned char**)((char*)xp->ptr + offset); - xp->size = (int*)((char*)xp->size + offset); - xp->type = (char**)((char*)xp->type + offset); - xp->options = (char**)((char*)xp->options + offset); - } - } -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, 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 -#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(soap, 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(soap, p); - } - soap->blist = bp->next; - SOAP_FREE(soap, 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); -#ifndef WITH_NOIDREF - if (flag) - soap_update_ptrs(soap, q, q + n, (long)s - (long)q); /* pointers s and q may or may not be related */ -#endif - 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; - if (*attr1 == '[') - attr1++; - n = 1; - for (;;) - { 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; - } - if (!attr1) - break; - 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; - register short i = -1; - register size_t n, k; - n = strlen(id); - k = strlen(ns) + 1; - p = soap->local_namespaces; - if (p) - { for (i = 0; p->id; p++, i++) - { if (p->ns && !strcmp(ns, p->ns)) - { if (p->out) - { SOAP_FREE(soap, p->out); - p->out = NULL; - } - break; - } - if (p->out) - { if (!strcmp(ns, p->out)) - break; - } - else if (p->in) - { if (!soap_tag_cmp(ns, p->in)) - { if ((p->out = (char*)SOAP_MALLOC(soap, k))) - strcpy(p->out, ns); - break; - } - } - } - if (!p || !p->id) - i = -1; - } - if (i >= 0) - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k); - if (!np) - return soap->error = SOAP_EOM; - np->next = soap->nlist; - soap->nlist = np; - np->level = soap->level; - np->index = i; - strcpy(np->id, id); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns)); - if (i < 0) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns)); - } - else - { np->ns = NULL; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id)); - } - 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)); - SOAP_FREE(soap, 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 - || (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 && !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_rand() -{ unsigned char buf[4]; - ssl_init(); - RAND_pseudo_bytes(buf, 4); - return *(int*)buf; -} -#endif - -/******************************************************************************/ -#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)) - { char buf[1024]; - RAND_seed(buf, sizeof(buf)); - while (!RAND_status()) - { int r = rand(); - 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 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); -/* See below */ - 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); - } -/* Suggested alternative approach to check cafile first before the key file: - 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 (!soap->cafile || !SSL_CTX_use_certificate_chain_file(soap->ctx, soap->cafile)) - { 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 or key file", SOAP_SSL_ERROR); - 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 or warning 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 - /* Note: return 1 to 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) -{ BIO *bio; - 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->ctx && (soap->error = soap->fsslauth(soap))) - return SOAP_INVALID_SOCKET; - 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 - bio = BIO_new_socket((SOAP_SOCKET)soap->socket, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, 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 WITH_NOIO -#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 -#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, 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, soap->plugins); - soap->plugins = p; - } - soap->fplugin = fplugin; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; -#endif - soap->fseterror = 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 - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free logfiles\n")); - for (i = 0; i < SOAP_MAXLOGS; i++) - { if (soap->logfile[i]) - { SOAP_FREE(soap, (void*)soap->logfile[i]); - soap->logfile[i] = NULL; - } - soap_close_logfile(soap, i); - } - soap_free_mht(soap); -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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/UDP IP error %d", soap->errnum); - msg = soap->msgbuf; - } - } - } - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static const char* -http_error(struct soap *soap, int status) -{ register const char *msg = SOAP_STR_EOS; -#ifndef WITH_LEAN - msg = soap_str_code(h_http_error_codes, status); - if (!msg) - msg = SOAP_STR_EOS; -#endif - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_IPV6 -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr) -{ soap_int32 iadd = -1; - struct hostent hostent, *host = &hostent; -#ifdef VXWORKS - int hostint; - char *addrcopy = (char*)SOAP_MALLOC(soap, 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 -#if defined(_AIXVERSION_431) || defined(TRU64) - struct hostent_data ht_data; -#endif - iadd = inet_addr(addr); -#endif - if (iadd != -1) - { memcpy(inaddr, &iadd, sizeof(iadd)); -#ifdef VXWORKS - SOAP_FREE(soap, addrcopy); -#endif - 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); -#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; - } - SOAP_FREE(soap, addrcopy); /*free() is placed after the error checking to assure that - * errno captured is that from hostGetByName() */ -#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; - } -#ifdef VXWORKS - inaddr->s_addr = hostint; -#else - memcpy(inaddr, host->h_addr, host->h_length); -#endif - return SOAP_OK; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port) -{ -#ifdef WITH_IPV6 - struct addrinfo hints, *res, *ressave; - int err; -#endif - 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->errnum = 0; - soap_set_sender_error(soap, tcp_error(soap), "TCP init failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->errmode = 0; -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - soap->errmode = 2; - if (soap->proxy_host) - err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &res); - else - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &res); - if (err) - { soap_set_sender_error(soap, gai_strerror(err), "getaddrinfo failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - ressave = res; -again: - fd = (int)socket(res->ai_family, res->ai_socktype, res->ai_protocol); - soap->errmode = 0; -#else -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - fd = (int)socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - fd = (int)socket(AF_INET, SOCK_STREAM, 0); -#endif - if (fd < 0) - { soap->errnum = soap_socket_errno; - soap_set_sender_error(soap, tcp_error(soap), "socket failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#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), "setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - 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), "setsockopt failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && 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), "setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } -#endif -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket %d to host='%s' port=%d\n", fd, host, port)); -#ifndef WITH_IPV6 - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (soap->proxy_host) - { if (soap->fresolve(soap, soap->proxy_host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)soap->proxy_port); - } - else - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)port); - } - soap->errmode = 0; - if ((soap->omode & SOAP_IO_UDP)) - return fd; -#endif -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { vx_nonblocking = TRUE; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */ - } -#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); - } -#elif defined(VXWORKS) - { vx_nonblocking = FALSE; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */ - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK); -#endif -#endif - for (;;) - { -#ifdef WITH_IPV6 - if (connect((SOAP_SOCKET)fd, res->ai_addr, res->ai_addrlen)) -#else - if (connect((SOAP_SOCKET)fd, (struct sockaddr*)&soap->peer, sizeof(soap->peer))) -#endif - { -#ifndef WITH_LEAN - if (soap->connect_timeout && (soap_socket_errno == SOAP_EINPROGRESS || soap_socket_errno == SOAP_EWOULDBLOCK)) - { struct timeval timeout; - SOAP_SOCKLEN_T k; - 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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - k = (SOAP_SOCKLEN_T)sizeof(soap->errnum); - if (!getsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &k) && !soap->errnum) /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - break; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - soap->errnum = soap_socket_errno; - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - else -#endif -#ifdef WITH_IPV6 - if (res->ai_next) - { res = res->ai_next; - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - goto again; - } - 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), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - else - break; - } -#ifdef WITH_IPV6 - soap->peerlen = 0; /* IPv6: already connected so use send() */ - freeaddrinfo(ressave); -#endif -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long blocking = 0; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking); - } -#elif defined(VXWORKS) - { vx_nonblocking = FALSE; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&vx_nonblocking)); /* modified to use fd */ - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK); -#endif -#endif - soap->socket = fd; - soap->imode &= ~SOAP_ENC_SSL; - soap->omode &= ~SOAP_ENC_SSL; - if (!strncmp(endpoint, "https:", 6)) - { -#ifdef WITH_OPENSSL - BIO *bio; - int r; - if (soap->proxy_host) - { short v; - unsigned int k = soap->omode; /* make sure we only parse HTTP */ - size_t n = soap->count; /* save the content length */ - soap->omode &= ~SOAP_ENC; /* 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 SOAP_INVALID_SOCKET; -#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 SOAP_INVALID_SOCKET; - soap->omode = k; - k = soap->imode; - soap->imode &= ~SOAP_ENC; /* mask IO and ENC */ - v = soap->version; /* preserve */ - if (soap_begin_recv(soap)) - return SOAP_INVALID_SOCKET; - soap->version = v; /* restore */ - soap->imode = k; /* restore */ - soap->count = n; /* restore */ - 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 SOAP_INVALID_SOCKET; - } - soap->ssl = SSL_new(soap->ctx); - if (!soap->ssl) - { soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; - } - 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; - bio = BIO_new_socket((SOAP_SOCKET)fd, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, 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 SOAP_INVALID_SOCKET; - } - 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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - 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 SOAP_INVALID_SOCKET; - } - } -#else - soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; -#endif - } - return fd; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_bind(struct soap *soap, const char *host, int port, int backlog) -{ -#ifdef WITH_IPV6 - struct addrinfo *addrinfo; - struct addrinfo hints; - struct addrinfo res; - int err; -#endif -#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 SOAP_INVALID_SOCKET; - } -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - soap->errmode = 2; - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo); - if (addrinfo) - { res = *addrinfo; - soap->peer = *((struct sockaddr_storage*)addrinfo->ai_addr); - soap->peerlen = addrinfo->ai_addrlen; - res.ai_addr = (struct sockaddr*)&soap->peer; - res.ai_addrlen = soap->peerlen; - freeaddrinfo(addrinfo); - } - if (err) - { soap_set_receiver_error(soap, gai_strerror(err), "getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->master = socket(res.ai_family, res.ai_socktype, res.ai_protocol); -#else -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - soap->master = (int)socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - soap->master = (int)socket(AF_INET, SOCK_STREAM, 0); -#endif - soap->errmode = 0; - if (!soap_valid_socket(soap->master)) - { soap->errnum = soap_socket_errno; - soap_set_receiver_error(soap, tcp_error(soap), "socket failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - soap->socket = soap->master; -#endif -#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), "setsockopt failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && 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), "setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && 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), "setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif -#endif -#ifdef WITH_IPV6 - soap->errmode = 0; - if (bind((SOAP_SOCKET)soap->master, res.ai_addr, res.ai_addrlen)) - { 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), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#else - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (host) - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_receiver_error(soap, tcp_error(soap), "get host by name failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } - else - soap->peer.sin_addr.s_addr = htonl(INADDR_ANY); - soap->peer.sin_port = htons((short)port); - soap->errmode = 0; - if (bind((SOAP_SOCKET)soap->master, (struct sockaddr*)&soap->peer, soap->peerlen)) - { 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), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif - if (!(soap->omode & SOAP_IO_UDP) && 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), "listen failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - return soap->master; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_poll(struct soap *soap) -{ -#ifndef WITH_LEAN - struct timeval timeout; - fd_set rfd, sfd, xfd; - int r; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_ZERO(&xfd); - if (soap_valid_socket(soap->socket)) - { FD_SET((SOAP_SOCKET)soap->socket, &rfd); - FD_SET((SOAP_SOCKET)soap->socket, &sfd); - FD_SET((SOAP_SOCKET)soap->socket, &xfd); - r = select((SOAP_SOCKET)(soap->socket + 1), &rfd, &sfd, &xfd, &timeout); - if (r > 0 && FD_ISSET((SOAP_SOCKET)soap->socket, &xfd)) - r = -1; - } - else if (soap_valid_socket(soap->master)) - { FD_SET((SOAP_SOCKET)soap->master, &sfd); - r = select((SOAP_SOCKET)(soap->master + 1), NULL, &sfd, NULL, &timeout); - } - else - return SOAP_OK; - if (r > 0) - { if (soap_valid_socket(soap->socket) - && FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - && (!FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - || recv((SOAP_SOCKET)soap->socket, soap->tmpbuf, 1, MSG_PEEK) > 0)) - return SOAP_OK; - } - else if (r < 0) - { soap->errnum = soap_socket_errno; - if ((soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno != SOAP_EINTR) - { 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 = 0; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Polling: other end down on socket=%d select=%d\n", soap->socket, r)); - return SOAP_EOF; -#else - return SOAP_OK; -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_accept(struct soap *soap, int s, struct sockaddr *a, int *n) -{ int fd; - fd = (int)accept((SOAP_SOCKET)s, a, (SOAP_SOCKLEN_T*)n); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ -#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 WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_accept(struct soap *soap) -{ int n = (int)sizeof(soap->peer); -#ifndef WITH_LEAN - int len = SOAP_BUFLEN; - int set = 1; -#endif - soap->error = SOAP_OK; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - return soap->socket = soap->master; -#endif - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->socket = SOAP_INVALID_SOCKET; - soap->errmode = 0; - soap->keep_alive = 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", "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (soap_socket_errno != SOAP_EINTR) - { soap->errnum = soap_socket_errno; - soap_closesock(soap); - soap_set_sender_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } -#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); - } -#elif defined(VXWORKS) - { vx_nonblocking = FALSE; - 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 -#endif - soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&soap->peer, &n); - soap->peerlen = (size_t)n; - if (soap_valid_socket(soap->socket)) - { -#ifdef WITH_IPV6 -/* Use soap->host to store the numeric form of the remote host */ - getnameinfo((struct sockaddr*)&soap->peer, 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->peer and soap->host */ - soap->port = 0; /* info stored in soap->peer and soap->host */ -#else - soap->ip = ntohl(soap->peer.sin_addr.s_addr); - soap->port = (int)ntohs(soap->peer.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)); -#endif -#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), "setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - 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), "setsockopt failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && 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), "setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && 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), "setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#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); -#elif defined(VXWORKS) - vx_nonblocking = FALSE; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&vx_nonblocking)); - ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)(&vx_nonblocking)); -#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 - } - soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0); - return soap->socket; - } - if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN) - { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host)); - soap->errnum = soap_socket_errno; - soap_set_receiver_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - } - else - { soap->errnum = 0; - soap_set_receiver_error(soap, tcp_error(soap), "no master socket in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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) && !(soap->omode & SOAP_IO_UDP)) - { 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 WITH_NOIO -#ifndef PALM_1 -static int -tcp_closesocket(struct soap *soap, SOAP_SOCKET fd) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket %d\n", (int)fd)); - return closesocket(fd); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET fd, int how) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket %d how=%d\n", (int)fd, 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; - if (status == SOAP_EOF || status == SOAP_TCP_ERROR || status == SOAP_SSL_ERROR || !soap->keep_alive) - { if (soap->fclose && (soap->error = soap->fclose(soap))) - return soap->error; - soap->keep_alive = 0; - } -#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 WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_init_pht(struct soap *soap) -{ register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing pointer hashtable\n")); - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new1(soap_mode mode) -{ return soap_new2(mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new() -{ return soap_new2(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new2(soap_mode imode, soap_mode omode) -{ struct soap *soap = (struct soap*)malloc(sizeof(struct soap)); - if (soap) - soap_init2(soap, imode, omode); - return soap; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_free_pht(struct soap *soap) -{ register struct soap_pblk *pb, *next; - register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n")); - for (pb = soap->pblk; pb; pb = next) - { next = pb->next; - SOAP_FREE(soap, pb); - } - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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; - if (!soap->pblk || soap->pidx >= SOAP_PTRBLK) - { register struct soap_pblk *pb = (struct soap_pblk*)SOAP_MALLOC(soap, sizeof(struct soap_pblk)); - if (!pb) - { soap->error = SOAP_EOM; - return 0; - } - pb->next = soap->pblk; - soap->pblk = pb; - soap->pidx = 0; - } - *ppp = pp = &soap->pblk->plist[soap->pidx++]; - 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=%d\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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -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)) -#ifndef WITH_LEANER - && !soap->fpreparesend -#endif - )) - soap->mode &= ~SOAP_IO_LENGTH; - else - soap->mode |= SOAP_IO_LENGTH; - } -#ifdef WITH_ZLIB - 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; - } -#endif - if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH)) - soap->mode |= SOAP_XML_TREE; -#ifndef WITH_LEANER - if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME)) - soap->mode |= SOAP_ENC_MIME; - else - soap->mode &= ~SOAP_ENC_MTOM; - 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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); -#ifndef WITH_LEANER - soap->dime.count = 0; /* count # of attachments */ - soap->dime.size = 0; /* accumulate total size of attachments */ - if (soap->fprepareinit && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_end_count(struct soap *soap) -{ -#ifndef WITH_LEANER - if (soap->fpreparefinal) - return soap->error = soap->fpreparefinal(soap); -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of count phase\n")); - return SOAP_OK; -} -#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->mode & (SOAP_IO_LENGTH | SOAP_ENC_DIME)); -#ifdef WITH_ZLIB - 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; - } -#endif -#ifdef WITH_UDP - if ((soap->mode & SOAP_IO_UDP)) - { soap->mode |= SOAP_ENC_XML; - if (soap->count > SOAP_BUFLEN) - return soap->error = SOAP_UDP_ERROR; - } -#endif - if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket)) - { if (soap->count || (soap->mode & SOAP_IO_LENGTH) || (soap->mode & SOAP_ENC_XML)) - soap->mode |= SOAP_IO_BUFFER; - else - soap->mode |= SOAP_IO_STORE; - } - soap->mode &= ~SOAP_IO_LENGTH; - 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_MTOM) && (soap->mode & SOAP_ENC_DIME)) - { soap->mode |= SOAP_ENC_MIME; - soap->mode &= ~SOAP_ENC_DIME; - } - else - soap->mode &= ~SOAP_ENC_MTOM; - if (soap->mode & SOAP_ENC_MIME) - soap_select_mime_boundary(soap); -#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 -#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->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=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); - soap->part = SOAP_BEGIN; -#ifndef WITH_LEANER - if (soap->fprepareinit && (soap->mode & SOAP_IO) == SOAP_IO_STORE) - soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 || !a->__ptr) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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; - if (soap->mode & SOAP_XML_TREE) - return id; - 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_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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_attachment(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; - int i; - 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:"")); - i = soap_array_pointer_lookup(soap, p, a, n, t, &pp); - if (!i) - { i = soap_pointer_enter(soap, p, a, n, t, &pp); - if (!i) - { soap->error = SOAP_EOM; - return -1; - } - } - if (id < 0) - id = i; - if (!aid) - { sprintf(soap->tmpbuf, soap->dime_id_format, id); - aid = soap_strdup(soap, soap->tmpbuf); - } - /* Add MTOM xop:Include element when necessary */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - if ((soap->mode & SOAP_ENC_MTOM) && strcmp(tag, "xop:Include")) - { if (soap_element_begin_out(soap, tag, 0, type) - || soap_element_href(soap, "xop:Include", 0, "href", aid) - || soap_element_end_out(soap, tag)) - return soap->error; - } - else 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; - if (soap->mode & SOAP_ENC_MTOM) - content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, (char*)a->__ptr, a->__size); - else - content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, (char*)a->__ptr, a->__size); - if (!content) - { soap->error = SOAP_EOM; - return -1; - } - if (!strncmp(aid, "cid:", 4)) /* RFC 2111 */ - { if (soap->mode & SOAP_ENC_MTOM) - { char *s = (char*)soap_malloc(soap, strlen(aid) - 1); - if (s) - { *s = '<'; - strcpy(s + 1, aid + 4); - strcat(s, ">"); - content->id = s; - } - } - else - content->id = aid + 4; - } - else - content->id = aid; - content->type = atype; - content->options = aoptions; - content->encoding = SOAP_MIME_BINARY; - pp->mark1 = 3; - } - } - else - pp->mark2 = 3; - return -1; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, fp); - } - p = ip->next; - SOAP_FREE(soap, ip); - } - soap->iht[i] = NULL; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_2 -SOAP_FMAC1 -struct soap_ilist * -SOAP_FMAC2 -soap_lookup(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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, 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 -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_malloc(struct soap *soap, size_t n) -{ register char *p; - if (!n) - return (void*)SOAP_NON_NULL; - if (!soap) - return SOAP_MALLOC(soap, n); - n += (-(long)n) & 7; - if (!(p = (char*)SOAP_MALLOC(soap, 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; - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -static void -soap_init_mht(struct soap *soap) -{ register int i; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->mht[i] = NULL; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -static void -soap_free_mht(struct soap *soap) -{ register int i; - register struct soap_mlist *mp, *mq; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - { for (mp = soap->mht[i]; mp; mp = mq) - { mq = mp->next; - if (mp->live) - fprintf(stderr, "%s(%d): malloc() = %p not freed (memory leak or forgot to call soap_end()?)\n", mp->file, mp->line, mp->ptr); - free(mp); - } - soap->mht[i] = NULL; - } -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_track_malloc(struct soap *soap, const char *file, int line, size_t size) -{ register void *p = malloc(size); - if (soap) - { register int h = soap_hash_ptr(p); - register struct soap_mlist *mp = (struct soap_mlist*)malloc(sizeof(struct soap_mlist)); - if (soap->fdebug[SOAP_INDEX_TEST]) - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): malloc(%lu) = %p\n", file, line, (unsigned long)size, p)); - mp->next = soap->mht[h]; - mp->ptr = p; - mp->file = file; - mp->line = line; - mp->live = 1; - soap->mht[h] = mp; - } - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_track_free(struct soap *soap, const char *file, int line, void *p) -{ register int h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - { if (mp->live) - { free(p); - if (soap->fdebug[SOAP_INDEX_TEST]) - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): free(%p)\n", file, line, p)); - mp->live = 0; - } - else - fprintf(stderr, "%s(%d): free(%p) double free of pointer malloced at %s(%d)\n", file, line, p, mp->file, mp->line); - } - else - fprintf(stderr, "%s(%d): free(%p) pointer not malloced\n", file, line, p); -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -static void -soap_track_unlink(struct soap *soap, const void *p) -{ register int h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - mp->live = 0; -} -#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(soap, p); - return; - } - } - soap_delete(soap, p); - } - else - { register char *q; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free all soap_malloc() data\n")); - while (soap->alist) - { q = (char*)soap->alist; - soap->alist = *(void**)q; - q -= *(size_t*)(q + sizeof(void*)); - SOAP_FREE(soap, q); - } - } - /* we must assume these were deallocated: */ - soap->action = NULL; - soap->fault = NULL; - soap->header = NULL; - soap->userid = NULL; - soap->passwd = 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(soap, 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(soap, 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(soap, 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)); -#ifdef SOAP_DEBUG - soap_track_unlink(soap, p); -#endif - 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(soap, q); - return; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 (!p || !id || !*id) - return p; - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, 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 -#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*)) -{ -#ifndef WITH_NOIDREF - struct soap_ilist *ip; -#endif - 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; - } -#ifndef WITH_NOIDREF - if (!id || !*id) -#endif - return p; -#ifndef WITH_NOIDREF - 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_DUPLICATE_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 -} -#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; -#ifndef WITH_NOHTTP - 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++; - } -#endif - 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); - } -#ifndef WITH_LEANER - 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 && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */ -#else - if (soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */ -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send phase\n")); - soap->omode &= ~SOAP_XML_SEC; - soap->count = 0; - soap->part = SOAP_END; - 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_DIME) && soap_getdime(soap)) - return soap->error; - soap->dime.list = soap->dime.first; - soap->dime.first = NULL; - soap->dime.last = NULL; - 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->mime.boundary = 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; -#ifndef WITH_NOIDREF - return soap_resolve(soap); -#else -#ifndef WITH_LEANER - if (soap->xlist) - { if (soap->mode & SOAP_ENC_MTOM) - return soap->error = SOAP_MIME_HREF; - return soap->error = SOAP_DIME_HREF; - } -#endif - return SOAP_OK; -#endif -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_free(struct soap *soap) -{ register struct Namespace *ns; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n")); - while (soap->nlist) - { register struct soap_nlist *np = soap->nlist->next; - SOAP_FREE(soap, 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 attribute storage\n")); - while (soap->attributes) - { register struct soap_attribute *tp = soap->attributes->next; - if (soap->attributes->value) - SOAP_FREE(soap, soap->attributes->value); - SOAP_FREE(soap, soap->attributes); - soap->attributes = tp; - } -#ifdef WITH_FAST - if (soap->labbuf) - SOAP_FREE(soap, soap->labbuf); - soap->labbuf = NULL; - soap->lablen = 0; - soap->labidx = 0; -#endif - ns = soap->local_namespaces; - if (ns) - { for (; ns->id; ns++) - { if (ns->out) - { if (soap->encodingStyle == ns->out) - soap->encodingStyle = SOAP_STR_EOS; - SOAP_FREE(soap, ns->out); - ns->out = NULL; - } - if (soap->encodingStyle == ns->ns) - soap->encodingStyle = SOAP_STR_EOS; - } - SOAP_FREE(soap, soap->local_namespaces); - soap->local_namespaces = NULL; - } -#ifndef WITH_LEANER - while (soap->xlist) - { struct soap_xlist *xp = soap->xlist->next; - SOAP_FREE(soap, soap->xlist); - soap->xlist = xp; - } -#endif -#ifndef WITH_NOIDREF - soap_free_pht(soap); - soap_free_iht(soap); -#endif -} -#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(soap, (void*)soap->logfile[i]); - if (logfile) - if ((s = (char*)SOAP_MALLOC(soap, 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*)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->error = SOAP_OK; - copy->userid = NULL; - copy->passwd = NULL; - copy->nlist = NULL; - copy->blist = NULL; - copy->clist = NULL; - copy->alist = NULL; - copy->attributes = NULL; -#ifdef WITH_FAST - copy->labbuf = NULL; - copy->lablen = 0; - copy->labidx = 0; -#endif -#ifdef SOAP_DEBUG - soap_init_mht(copy); -#endif - copy->local_namespaces = NULL; -#ifndef WITH_NOIDREF - soap_init_iht(copy); - soap_init_pht(copy); -#endif - copy->header = NULL; - copy->fault = NULL; - copy->action = NULL; - *copy->host = '\0'; -#ifndef WITH_LEAN -#ifdef WITH_COOKIES - copy->cookies = soap_copy_cookies(copy); -#else - copy->cookies = NULL; -#endif -#endif -#ifdef SOAP_DEBUG - soap_init_logs(copy); - soap_set_recv_logfile(copy, soap->logfile[SOAP_INDEX_RECV]); - soap_set_sent_logfile(copy, soap->logfile[SOAP_INDEX_SENT]); - soap_set_test_logfile(copy, soap->logfile[SOAP_INDEX_TEST]); -#endif - copy->plugins = NULL; - for (p = soap->plugins; p; p = p->next) - { register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(copy, 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(copy, q, p))) - { SOAP_FREE(copy, 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; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif - soap->fconnect = NULL; - soap->fdisconnect = NULL; -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; -#endif - soap->fseterror = NULL; - soap->fignore = NULL; - soap->fserveloop = NULL; - soap->fplugin = fplugin; -#ifndef WITH_LEANER - soap->fdimereadopen = NULL; - soap->fdimewriteopen = NULL; - soap->fdimereadclose = NULL; - soap->fdimewriteclose = NULL; - soap->fdimeread = NULL; - soap->fdimewrite = NULL; -#endif - 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; -#ifdef WITH_FAST - soap->labbuf = NULL; - soap->lablen = 0; - soap->labidx = 0; -#endif - 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; -#ifndef WITH_LEANER - 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; - soap->xlist = NULL; -#endif -#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->crlfile = 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->c14ninclude = NULL; - soap->c14nexclude = NULL; - soap->cookies = NULL; - soap->cookie_domain = NULL; - soap->cookie_path = NULL; - soap->cookie_max = 32; -#endif -#ifdef SOAP_DEBUG - soap_init_mht(soap); - 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 -#ifdef WMW_RPM_IO - soap->rpmreqid = NULL; -#endif /* WMW_RPM_IO */ -#ifdef PALM - palmNetLibOpen(); -#endif -#ifndef WITH_NOIDREF - soap_init_iht(soap); - soap_init_pht(soap); -#endif - 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, soap_mode mode) -{ soap_init2(soap, mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init2(struct soap *soap, soap_mode imode, soap_mode 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_END; - 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'; -#ifndef WITH_LEANER - soap->dime.chunksize = 0; - soap->dime.buflen = 0; -#endif - 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, 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) -{ register struct Namespace *ns = soap->local_namespaces; - register struct soap_nlist *np, *nq, *nr; - register unsigned int level = soap->level; - soap->namespaces = p; - soap->local_namespaces = NULL; - soap_set_local_namespaces(soap); - /* reverse the namespace 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; - } - } - /* then push on new stack */ - while (np) - { register const char *s; - soap->level = np->level; /* preserve element nesting level */ - s = np->ns; - if (!s && np->index >= 0 && ns) - { s = ns[np->index].out; - if (!s) - s = ns[np->index].ns; - } - if (s && soap_push_namespace(soap, np->id, s)) - return soap->error; - nq = np; - np = np->next; - SOAP_FREE(soap, nq); - } - if (ns) - { register int i; - for (i = 0; ns[i].id; i++) - { if (ns[i].out) - { SOAP_FREE(soap, ns[i].out); - ns[i].out = NULL; - } - } - SOAP_FREE(soap, ns); - } - soap->level = level; /* restore level */ - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -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++; - n *= sizeof(struct Namespace); - ns2 = (struct Namespace*)SOAP_MALLOC(soap, n); - if (ns2) - { memcpy(ns2, soap->namespaces, n); - if (ns2[0].ns) - { if (!strcmp(ns2[0].ns, soap_env1)) - soap->version = 1; - else - soap->version = 2; - } - soap->local_namespaces = ns2; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef PALM_1 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_strsearch(const char *big, const char *little) -{ size_t n = strlen(little); - const char *s = big; - while (s) - { if (!strncmp(s, little, n) && (s[n] == '\0' || s[n] == ' ')) - return s; - s = strchr(s, ' '); - if (s) - s++; - } - return NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static struct soap_nlist * -soap_lookup_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np; - for (np = soap->nlist; np; np = np->next) - { if (!strncmp(np->id, tag, n) && !np->id[n]) - return np; - } - return NULL; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static struct soap_nlist * -soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized) -{ register struct soap_nlist *np; - size_t n, k; - if (soap_strsearch(soap->c14nexclude, id)) - return NULL; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns?ns:"")); - if (!utilized) - { for (np = soap->nlist; np; np = np->next) - { if (!strcmp(np->id, id) && (!np->ns || !strcmp(np->ns, ns))) - break; - } - if (np) - { if (np->index == 1) - utilized = np->index; - else - return NULL; - } - } - n = strlen(id); - if (ns) - k = strlen(ns); - else - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k + 1); - if (!np) - { soap->error = SOAP_EOM; - return NULL; - } - np->next = soap->nlist; - soap->nlist = np; - strcpy(np->id, id); - if (ns) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - } - else - np->ns = NULL; - np->level = soap->level; - np->index = utilized; - return np; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_utilize_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np = soap_lookup_ns(soap, tag, n); - if (np) - { if (np->index == 0) - soap_push_ns(soap, np->id, np->ns, 1); - } - else - { strncpy(soap->tmpbuf, tag, n); - soap->tmpbuf[n] = '\0'; - soap_push_ns(soap, soap->tmpbuf, NULL, 1); - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_pop_ns(struct soap *soap) -{ soap_pop_namespace(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_element(struct soap *soap, const char *tag, int id, const char *type) -{ 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 *elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->soap = soap; - elt->next = NULL; - elt->prnt = soap->dom; - elt->name = soap_strdup(soap, tag); - elt->elts = NULL; - elt->atts = NULL; - elt->nstr = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->node = NULL; - elt->type = 0; - elt->head = NULL; - elt->tail = NULL; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - } - else - { -#endif - soap->level++; -#ifndef WITH_LEAN - if (!soap->ns) - { if (!(soap->mode & SOAP_XML_CANONICAL) - && soap_send(soap, soap->prolog ? soap->prolog : "\n")) - return soap->error; - } - else if (soap->mode & SOAP_XML_INDENT) - { if (soap->ns == 1 && soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - soap->body = 1; - } -#endif - if (soap_send_raw(soap, "<", 1) - || soap_send(soap, tag)) - return soap->error; -#ifdef WITH_DOM - } -#endif - if (!soap->ns) - { struct Namespace *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; /* start with 0 or 2, but should be one to continue */ -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *s = strchr(tag, ':'); - if (s) - soap_utilize_ns(soap, tag, s - tag); - } -#endif - 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; -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *s = strchr(type, ':'); - if (s) - soap_utilize_ns(soap, type, s - type); - } -#endif - } - 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 && (n > 214748364 || c >= '8')) - 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 && (n > 429496729 || c >= '6')) - 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; - } -#ifndef WITH_LEAN - if (type && *type && (soap->mode & SOAP_XML_CANONICAL)) - { const char *s = strchr(type, ':'); - if (s) - soap_utilize_ns(soap, type, s - type); - } -#endif - 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 - register struct soap_dom_attribute **att; - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { att = &soap->dom->atts; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, tp->name); - (*att)->data = soap_strdup(soap, tp->value); - (*att)->wide = NULL; - (*att)->soap = soap; - tp->visible = 0; - } - } - return SOAP_OK; - } -#endif -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { struct soap_nlist *np; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible && tp->name) - { const char *s = strchr(tp->name, ':'); - if (s) - soap_utilize_ns(soap, tp->name, s - tp->name); - } - } - for (np = soap->nlist; np; np = np->next) - { if (np->index == 1 && np->ns) - { sprintf(soap->tmpbuf, "xmlns:%s", np->id); - soap_set_attr(soap, soap->tmpbuf, np->ns); - np->index = 2; - } - } - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { if (soap_send(soap, " ") || 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) - { -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { if (soap_send_raw(soap, ">", 1) - || soap_element_end_out(soap, tag)) - return soap->error; - } - else -#endif - soap->level--; /* decrement level just before /> */ - if (soap_send_raw(soap, "/>", 2)) - return soap->error; - return SOAP_OK; - } - 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 -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - soap_pop_ns(soap); - if (soap->mode & SOAP_XML_INDENT) - { if (!soap->body) - { if (soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - } - soap->body = 0; - } -#endif - if (soap_send_raw(soap, "error; - soap->level--; /* decrement level just before > */ - 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) -{ if (!p || (a && !a->__ptr)) - { soap_element_null(soap, tag, id, type); - return -1; - } -#ifndef WITH_NOIDREF - if (soap->mode & SOAP_XML_TREE) - return 0; - if (id < 0) - { struct soap_plist *pp; - 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; -#else - return 0; -#endif -} -#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); - a->data = soap_strdup(soap, value); - a->wide = NULL; - a->soap = soap; - soap->dom->atts = a; - return SOAP_OK; - } -#endif -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { /* TODO: consider using this code to handle default namespace - if (!strncmp(name, "xmlns", 5) && (name[5] == ':' || name[5] == '\0')) - { if (name[5] == ':') - soap_push_ns(soap, name + 6, value, 0); - else - soap_push_ns(soap, "", value, 0); - } - */ - if (!strncmp(name, "xmlns:", 6)) - soap_push_ns(soap, name + 6, value, 0); - else if (soap_set_attr(soap, name, value)) - return soap->error; - } - else -#endif - { if (soap_send(soap, " ") || 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, 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; - } - } - else if (soap->error == SOAP_NO_TAG && tag && *tag == '-') - soap->error = SOAP_OK; - 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; - register int n = 0; - if (tag && *tag == '-') - return SOAP_OK; - soap->level--; - soap_pop_namespace(soap); -#ifdef WITH_DOM - /* this whitespace or mixed content is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!soap->peeked && !soap_string_in(soap, 3, -1, -1)) - return soap->error; - if (soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - if (soap->peeked) - { if (soap->error == SOAP_NO_TAG) - soap->error = SOAP_OK; - if (*soap->tag) - n++; - soap->peeked = 0; - } - do - { while (((c = soap_get(soap)) != SOAP_TT)) - { if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (c == SOAP_LT) - n++; - else if (c == '/') - { c = soap_get(soap); - if (c == SOAP_GT) - n--; - else - soap_unget(soap, c); - } - } - } while (n--); - s = soap->tag; - while (soap_notblank(c = soap_getutf8(soap))) - *s++ = (char)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 || !*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(soap, 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(soap, tp->value); - tp->value = NULL; - tp->ns = NULL; - } - if (value) - { if (!tp->value) - { tp->size = strlen(value) + 1; - if (!(tp->value = (char*)SOAP_MALLOC(soap, 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; -#ifndef WITH_LEAN - if (!strcmp(name, "wsu:Id")) - { soap->part = SOAP_BEGIN_SECURITY; - strncpy(soap->id, value, sizeof(soap->id)); - soap->id[sizeof(soap->id)-1] = '\0'; - } -#endif - } - 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, soap->attributes->value); - SOAP_FREE(soap, 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 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_store_lab(struct soap *soap, const char *s, size_t n) -{ soap->labidx = 0; - return soap_append_lab(soap, s, n); -} -#endif -#endif - -/******************************************************************************/ -#ifdef WITH_FAST -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -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, soap->lablen); - if (!soap->labbuf) - { if (t) - SOAP_FREE(soap, t); - return soap->error = SOAP_EOM; - } - if (t) - { memcpy(soap->labbuf, t, soap->labidx); - SOAP_FREE(soap, 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) -{ -#ifdef WITH_DOM - register struct soap_dom_attribute **att = NULL; - register char *lead = NULL; -#endif - register struct soap_attribute *tp; - const char *t; - register char *s; - register soap_wchar c; - register int i; - if (soap->peeked) - { if (!*soap->tag) - return soap->error = SOAP_NO_TAG; - return SOAP_OK; - } - soap->peeked = 1; - for (;;) - { c = soap_getutf8(soap); - if (c == SOAP_BOM) - c = soap_get(soap); -#ifdef WITH_DOM - /* whitespace leading to start tag is not insignificant for DOM */ - if (soap_blank(c)) - { soap->labidx = 0; - do - { if (soap_append_lab(soap, NULL, 0)) - return SOAP_EOM; - s = soap->labbuf + soap->labidx; - i = soap->lablen - soap->labidx; - soap->labidx = soap->lablen; - while (soap_blank(c) && i--) - { *s++ = c; - c = soap_get(soap); - } - } - while (soap_blank(c)); - *s = '\0'; - lead = soap_strdup(soap, soap->labbuf); - } -#else - while (soap_blank(c)) - c = soap_get(soap); -#endif - if (c != SOAP_LT) - { *soap->tag = '\0'; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifdef WITH_DOM - /* whitespace leading to end tag is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->tail = soap_strdup(soap, lead); -#endif - return soap->error = SOAP_NO_TAG; - } - s = soap->tag; - do c = soap_getutf8(soap); - while (soap_blank(c)); - i = sizeof(soap->tag); - while (c != '/' && soap_notblank(c)) - { if (--i > 0) - *s++ = (char)c; - c = soap_getutf8(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; -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { register struct soap_dom_element *elt; - elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->next = NULL; - elt->nstr = NULL; - elt->name = soap_strdup(soap, soap->tag); - elt->prnt = soap->dom; - elt->elts = NULL; - elt->atts = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->type = 0; - elt->node = NULL; - elt->head = lead; - elt->tail = NULL; - elt->soap = soap; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - att = &elt->atts; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - tp->visible = 0; - 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; -#ifdef WITH_DOM - /* add attribute name to dom */ - if (att) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, soap->tmpbuf); - (*att)->data = NULL; - (*att)->wide = NULL; - (*att)->soap = soap; - } -#endif - if (!strncmp(soap->tmpbuf, "xmlns", 5)) - { if (soap->tmpbuf[5] == ':') - { soap->tmpbuf[5] = '\0'; - t = soap->tmpbuf + 6; - } - else if (soap->tmpbuf[5]) - t = NULL; - else - 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(soap, 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; - if (soap_store_lab(soap, tp->value, tp->size)) - return soap->error; - if (tp->value) - SOAP_FREE(soap, 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; - } - if (soap->labidx) - tp->size = soap->lablen; - else - { tp->size = strlen(soap->labbuf) + 1; - if (tp->size < SOAP_LABLEN) - tp->size = SOAP_LABLEN; - } - if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size))) - return soap->error = SOAP_EOM; - strcpy(tp->value, soap->labbuf); -#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(soap, n))) - return soap->error = SOAP_EOM; - if (tp->value) - { memcpy(s, tp->value, tp->size); - SOAP_FREE(soap, 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 */ -#ifdef WITH_DOM - if (att) - (*att)->data = soap_strdup(soap, tp->value); -#endif - } - else - tp->visible = 1; /* seen this attribute w/o value */ -#ifdef WITH_DOM - if (att) - att = &(*att)->next; -#endif - if (t && tp->value) - { if (soap_push_namespace(soap, t, tp->value)) - return soap->error; - tp->visible = 0; - } - } -#ifdef WITH_DOM - if (att) - { soap->dom->nstr = soap_dom_current_nstr(soap, soap->tag); - for (att = &soap->dom->atts; *att; att = &(*att)->next) - (*att)->nstr = soap_dom_current_nstr(soap, (*att)->name); - } -#endif - if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (!(soap->body = (c != '/'))) - do c = soap_get(soap); - while (soap_blank(c)); -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { if (!soap->body && soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - 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->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENV:actor")) - || (soap->version == 2 && !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; - } - } - return soap->error = SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_retry(struct soap *soap) -{ soap->error = SOAP_OK; - soap_revert(soap); -} -#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 = 0xFFFFFF80UL; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_strdup(soap, s); - 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: -#ifndef WITH_LEANER -#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 -#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; -#if !defined(WITH_LEANER) && defined(HAVE_WCTOMB) - char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8]; -#else - char buf[8]; -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { n = 1; - soap->peeked = 0; -#ifndef WITH_LEAN - t = soap->tmpbuf; - t[0] = '<'; - strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 1); - strncat(t, ">", sizeof(soap->tmpbuf)); - m = strlen(soap->tag) + 2; -#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: -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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*)"amp;"; - m = 4; - } - 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; -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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; - } -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (flag == 3) - soap->dom->tail = t; - else - soap->dom->data = t; - } -#endif - if (flag == 2) - if (soap_s2QName(soap, t, &t)) - return NULL; - return t; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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) - { wchar_t *r = (wchar_t*)s; - int n = 1; - while (*r++) - n++; - soap->dom->wide = r = (wchar_t*)soap_malloc(soap, n * sizeof(wchar_t)); - while (n--) - *r++ = *s++; - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading wide string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { n = 1; - soap->peeked = 0; - } - } - 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; - } - s = (wchar_t*)soap_save_block(soap, NULL, 0); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->wide = s; -#endif - return s; -} -#endif -#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 ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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 (*soap->href) - p = (int*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(int), 0, NULL); - else if (p) - { if (soap_s2int(soap, soap_value(soap), p)) - return 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 ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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 (*soap->href) - p = (long*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(long), 0, NULL); - else if (p) - { if (soap_s2long(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOLL - char *r; - *p = strtoll(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -# ifdef HAVE_SSCANF - if (sscanf(s, SOAP_LONG_FORMAT, p) != 1) -# endif -#endif - 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 (*soap->href) - p = (LONG64*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(LONG64), 0, NULL); - else if (p) - { if (soap_s2LONG64(soap, soap_value(soap), p)) - return 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 (s == r || *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 (*soap->href) - p = (char*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(char), 0, NULL); - else if (p) - { if (soap_s2byte(soap, soap_value(soap), p)) - return 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 (s == r || *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 (*soap->href) - p = (short*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(short), 0, NULL); - else if (p) - { if (soap_s2short(soap, soap_value(soap), p)) - return 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 (!*s) - return soap->error = SOAP_TYPE; - 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 - { -/* On some systems, strtof appears to be broken or doesn't link: use with caution */ -#if defined(HAVE_STRTOF) - char *r; - *p = strtof((char*)s, &r); - if (*r) -#elif defined(HAVE_STRTOD) - char *r; - *p = (float)strtod(s, &r); - if (*r) -#endif -#ifdef HAVE_SSCANF - if (sscanf(s, "%g", 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 (*soap->href) - p = (float*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(float), 0, NULL); - else if (p) - { if (soap_s2float(soap, soap_value(soap), p)) - return 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 (!*s) - return soap->error = SOAP_TYPE; - 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, "%lg", 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 (*soap->href) - p = (double*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(double), 0, NULL); - else if (p) - { if (soap_s2double(soap, soap_value(soap), p)) - return 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 (s == r || *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 (*soap->href) - p = (unsigned char*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned char), 0, NULL); - else if (p) - { if (soap_s2unsignedByte(soap, soap_value(soap), p)) - return 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_unsignedShort2s(struct soap *soap, unsigned short n) -{ return soap_unsignedLong2s(soap, (unsigned long)n); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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 PALM_2 -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 (s == r || *r || n > 65535) - soap->error = SOAP_TYPE; - *p = (unsigned short)n; - } - return soap->error; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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 (*soap->href) - p = (unsigned short*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned short), 0, NULL); - else if (p) - { if (soap_s2unsignedShort(soap, soap_value(soap), p)) - return 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 ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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 (*soap->href) - p = (unsigned int*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned int), 0, NULL); - else if (p) - { if (soap_s2unsignedInt(soap, soap_value(soap), p)) - return 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 ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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 (*soap->href) - p = (unsigned long*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned long), 0, NULL); - else if (p) - { if (soap_s2unsignedLong(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOULL - char *r; - *p = strtoull(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -# ifdef HAVE_SSCANF - if (sscanf(s, SOAP_ULONG_FORMAT, p) != 1) -# endif -#endif - 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 (*soap->href) - p = (ULONG64*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(ULONG64), 0, NULL); - else if (p) - { if (soap_s2ULONG64(soap, soap_value(soap), p)) - return 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 != '"') - { -#ifndef WITH_LEAN - if (s && (soap->mode & SOAP_XML_CANONICAL)) - { t = strchr(s, ':'); - if (t) - soap_utilize_ns(soap, s, t - s); - } -#endif - 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:_%d", 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)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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; - if (*soap->href) - 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 WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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; - if (*soap->href) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static time_t -soap_timegm(struct tm *T) -{ -#if defined(HAVE_TIMEGM) - return timegm(T); -#else - time_t t, g, z; -#ifdef HAVE_GMTIME_R - struct tm tm, *tmp = &tm; -#else - struct tm *tmp; -#endif - t = mktime(T); - if (t == -1) - return -1; -#ifdef HAVE_GMTIME_R - gmtime_r(&t, tmp); -#else - tmp = gmtime(&t); -#endif - tmp->tm_isdst = 0; - g = mktime(tmp); - if (g == -1) - return -1; - z = g - t; - return t - z; -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_dateTime2s(struct soap *soap, time_t n) -{ struct tm T, *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); - /* 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); -#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+(pT->tm_isdst!=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+(pT->tm_isdst!=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+(pT->tm_isdst!=0), abs(t.timezone)%60); - } - /* 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); - } -# 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+(pT->tm_isdst!=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); - /* 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); -#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]; - const char *t; - memset((void*)&T, 0, sizeof(T)); - zone[sizeof(zone)-1] = '\0'; - if (strchr(s, '-')) - t = "%d-%d-%dT%d:%d:%d%15s"; - else if (strchr(s, ':')) - t = "%4d%2d%2dT%d:%d:%d%15s"; - else /* parse non-XSD-standard alternative ISO 8601 format */ - t = "%4d%2d%2dT%2d%2d%2d%15s"; - sscanf(s, t, &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 == '+' || *s == '-') - { int h = 0, m = 0; - if (s[3] == ':') - { sscanf(s, "%d:%d", &h, &m); - if (h < 0) - m = -m; - } - else - { m = (int)atol(s); - h = m / 100; - m = m % 100; - } - T.tm_hour -= h; - 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 (*soap->href) - p = (time_t*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(time_t), 0, NULL); - else if (p) - { if (soap_s2dateTime(soap, soap_value(soap), p)) - return 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 (soap->local_namespaces && (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, "", 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)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - if (!(p = (char**)soap_malloc(soap, sizeof(char*)))) - return NULL; - if (soap->null) - *p = NULL; - else - *p = soap_string_in(soap, 0, -1, -1); - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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 (soap->local_namespaces && (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, "", t); - return soap_send(soap, soap->tmpbuf); - } - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*)))) - return NULL; - if (soap->null) - *p = NULL; - else - *p = soap_wstring_in(soap, 0, -1, -1); - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_token(struct soap *soap) -{ register size_t i; - register soap_wchar c = 0; - register char *s = soap->tmpbuf; - if (!soap->body) - return SOAP_STR_EOS; - do c = soap_get(soap); - while (soap_blank(c)); - for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++) - { if (c == SOAP_TT || (int)c == EOF || soap_blank(c)) - break; - *s++ = (char)c; - c = soap_get(soap); - } - if ((int)c == EOF || c == SOAP_TT) - soap_unget(soap, c); - *s = '\0'; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element content value='%s'\n", soap->tmpbuf)); - return soap->tmpbuf; /* return non-null pointer */ -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_value(struct soap *soap) -{ register size_t i; - register soap_wchar c = 0; - register char *s = soap->tmpbuf; - if (!soap->body) - return SOAP_STR_EOS; - do c = soap_get(soap); - while (soap_blank(c)); - for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++) - { if (c == SOAP_TT || (int)c == EOF) - break; - *s++ = (char)c; - c = soap_get(soap); - } - for (s--; i > 0; i--, s--) - if (!soap_blank(*s)) - break; - s[1] = '\0'; - if ((int)c == EOF || c == SOAP_TT) - soap_unget(soap, c); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element content value='%s'\n", soap->tmpbuf)); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->data = soap_strdup(soap, soap->tmpbuf); -#endif - return soap->tmpbuf; /* return non-null pointer */ -} -#endif - -/******************************************************************************/ -#if !defined(WITH_LEANER) || !defined(WITH_NOHTTP) -#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' || c == '\n') - break; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - *s++ = (char)c; - } - if (c != '\n') - c = soap_getchar(soap); /* got \r, now get \n */ - if (c == '\n') - { *s = '\0'; - if (i+1 == len) /* empty line: end of HTTP/MIME 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 -#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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the message size with attachments, current count=%lu\n", (unsigned long)count)); - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - { 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 content is %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); - /* count Content-Transfer-Encoding: ...\r\n */ - s = soap_str_code(mime_codes, content->encoding); - 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 content is %lu bytes\n", (unsigned long)content->size)); - } - /* count \r\n--boundary-- */ - count += 6 + n; - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New count is %lu bytes\n", (unsigned long)count)); - 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) -{ while (soap->dime.flags & SOAP_DIME_CF) - { if (soap_getdimehdr(soap)) - return soap->error; - if (soap_move(soap, soap->dime.size)) - return soap->error = SOAP_EOF; - } - if (soap_move(soap, ((soap->dime.size+3)&(~3))-soap_tell(soap))) - return soap->error = SOAP_EOF; - for (;;) - { register struct soap_multipart *content; - if (soap_getdimehdr(soap)) - break; - 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; - soap_resolve_attachment(soap, content); - if (soap->error) - return soap->error; - } - if (soap->error != SOAP_DIME_END) - return soap->error; - return soap->error = SOAP_OK; -} -#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-Disposition")) - content->id = soap_strdup(soap, soap_get_header_attribute(soap, val, "name")); - 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 = 0; - if (!soap->mime.last) - return SOAP_OK; - for (;;) - { register size_t i, m = 0; - register char *s, *t = NULL; - 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 short flag = 0; - if (!(s = (char*)soap_push_block(soap, SOAP_BLKLEN))) - return soap->error = SOAP_EOM; - for (i = 0; i < SOAP_BLKLEN; i++) - { if (m > 0) - { flag = (*t == '\r'); - *s++ = *t++; - m--; - } - else - { if (!flag) - { c = soap_get1(soap); - if ((int)c == EOF) - return soap->error = SOAP_EOF; - } - if (flag || c == '\r') - { t = soap->tmpbuf; - memset(t, 0, sizeof(soap->tmpbuf)); - strcpy(t, "\n--"); - if (soap->mime.boundary) - strncat(t, soap->mime.boundary, sizeof(soap->tmpbuf)-4); - 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); - soap_resolve_attachment(soap, content); - 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' && c != '\n'); - if ((int)c != '\r' || soap_getchar(soap) != '\n') - return soap->error = SOAP_MIME_ERROR; - */ - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -static int -soap_match_cid(const char *s, const char *t) -{ register size_t n; - if (!s) - return 1; - if (!strcmp(s, t)) - return 0; - if (!strncmp(s, "cid:", 4)) - s += 4; - n = strlen(t); - if (*t == '<') - { t++; - n -= 2; - } - if (!strncmp(s, t, n) && !s[n]) - return 0; - return 1; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -static void -soap_resolve_attachment(struct soap *soap, struct soap_multipart *content) -{ if (content->id) - { register struct soap_xlist **xp = &soap->xlist; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving attachment data for id=%s\n", content->id)); - while (*xp) - { register struct soap_xlist *xq = *xp; - if (!soap_match_cid(xq->id, content->id)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Found matching attachment %s for content id=%s\n", xq->id, content->id)); - *xp = xq->next; - *xq->ptr = (unsigned char*)content->ptr; - *xq->size = (int)content->size; - *xq->type = (char*)content->type; - if (content->options) - *xq->options = (char*)content->options; - else - *xq->options = (char*)content->description; - SOAP_FREE(soap, xq); - } - else - xp = &(*xp)->next; - } - } -} -#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, "--"); -} -#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 + 1); - if (!s) - return; - } - strcpy(s, "<>"); - s += 2; - n -= 4; - while (n) - { *s++ = soap_base64o[soap_random & 0x3F]; - n--; - } - strcpy(s, "<>"); - } - if (!soap->mime.start) - soap->mime.start = ""; -} -#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 && !strchr("()<>@,;:\\\"/[]?={}", 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(soap, sizeof(struct soap_cookie)))) - { if ((q->name = (char*)SOAP_MALLOC(soap, 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->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(soap, q->name); - SOAP_FREE(soap, q); - q = NULL; - } - } - } - else - q->modified = 1; - if (q) - { if (q->value) - { SOAP_FREE(soap, q->value); - q->value = NULL; - } - if (q->domain) - { SOAP_FREE(soap, q->domain); - q->domain = NULL; - } - if (q->path) - { SOAP_FREE(soap, q->path); - q->path = NULL; - } - if (value && *value && (q->value = (char*)SOAP_MALLOC(soap, strlen(value)+1))) - strcpy(q->value, value); - if (domain && *domain && (q->domain = (char*)SOAP_MALLOC(soap, strlen(domain)+1))) - strcpy(q->domain, domain); - if (path && *path && (q->path = (char*)SOAP_MALLOC(soap, strlen(path)+1))) - strcpy(q->path, path); - q->session = 1; - q->env = 0; - } - 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", NULL, SOAP_HTTP_ERROR); - return; - } - if (!path) - path = soap->cookie_path; - if (!path) - { soap_set_receiver_error(soap, "Cookie path not set", NULL, 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(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, 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 -char * -SOAP_FMAC2 -soap_env_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)) && p->env) - 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); - *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->error = 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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending cookies for domain=%s path=%s\n", domain, path)); - if (*path == '/') - path++; - while ((q = *p)) - { if (q->expire && now > q->expire) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name)); - SOAP_FREE(soap, q->name); - if (q->value) - SOAP_FREE(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, q); - } - else - { size_t domlen = 0; - if (q->domain) - { const char *s = strchr(q->domain, ':'); - if (s) - domlen = s - q->domain; - else - domlen = strlen(q->domain); - } - if ((!q->domain || !strncmp(q->domain, domain, domlen)) - && (!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 == '/' ? q->path + 1 : 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->error = soap->fposthdr(soap, "Cookie", tmp))) - return soap->error; - } - 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->path) - SOAP_FREE(soap, p->path); - p->path = t; - } - else - { if (path) - SOAP_FREE(soap, 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->domain) - SOAP_FREE(soap, p->domain); - p->domain = t; - } - else - { if (domain) - SOAP_FREE(soap, domain); - domain = t; - } - } - else if (p && !soap_tag_cmp(tmp, "Path")) - { if (p->path) - SOAP_FREE(soap, p->path); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->path = (char*)SOAP_MALLOC(soap, strlen(tmp)+1))) - strcpy(p->path, tmp); - } - else - p->path = NULL; - } - else if (p && !soap_tag_cmp(tmp, "Domain")) - { if (p->domain) - SOAP_FREE(soap, p->domain); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->domain = (char*)SOAP_MALLOC(soap, 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if ((p = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie)))) - { p->name = (char*)SOAP_MALLOC(soap, strlen(tmp)+1); - strcpy(p->name, tmp); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { p->value = (char*)SOAP_MALLOC(soap, 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 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if (domain) - SOAP_FREE(soap, domain); - if (path) - SOAP_FREE(soap, 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(soap, sizeof(struct soap_cookie)))) - return r; - **q = *p; - if (p->name) - { if (((*q)->name = (char*)SOAP_MALLOC(soap, strlen(p->name)+1))) - strcpy((*q)->name, p->name); - } - if (p->value) - { if (((*q)->value = (char*)SOAP_MALLOC(soap, strlen(p->value)+1))) - strcpy((*q)->value, p->value); - } - if (p->domain) - { if (((*q)->domain = (char*)SOAP_MALLOC(soap, strlen(p->domain)+1))) - strcpy((*q)->domain, p->domain); - } - if (p->path) - { if (((*q)->path = (char*)SOAP_MALLOC(soap, 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, 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 */ -#ifndef WITH_NOIDREF - soap_free_iht(soap); -#endif - 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->action = NULL; -#ifndef WITH_LEANER - soap->dom = 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; - soap->xlist = NULL; -#endif -#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 -#ifndef WITH_LEANER - 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 -#ifndef WITH_LEANER - 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 -#endif - { while (soap_blank(c)) - c = soap_getchar(soap); - } - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifndef WITH_NOHTTP - /* if not XML or (start of)BOM or MIME/DIME/ZLIB, assume HTTP header */ - if (c != '<' && c != 0xEF && !(soap->mode & (SOAP_ENC_MIME | SOAP_ENC_DIME | SOAP_ENC_ZLIB))) - { soap->mode &= ~SOAP_IO; - soap->error = soap->fparse(soap); - if (soap->error && soap->error < SOAP_STOP) - { 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; - } -#ifndef WITH_LEANER - else if (soap->fpreparerecv && soap->buflen != soap->bufidx) - soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx); -#endif -#ifdef WITH_ZLIB - if (soap->zlib_in != SOAP_ZLIB_NONE) - { /* 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 - if (soap->error) - { if (soap->error == SOAP_FORM && soap->fform) - { soap->error = soap->fform(soap); - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - } - return soap->error; - } - } -#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 WITH_NOHTTP -#ifndef PALM_1 -static int -http_parse(struct soap *soap) -{ char header[SOAP_HDRLEN], *s; - unsigned short get = 0, status = 0, k = 0; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for HTTP request/response...\n")); - *soap->endpoint = '\0'; - soap->length = 0; - soap->userid = NULL; - soap->passwd = NULL; - soap->action = NULL; - soap->authrealm = NULL; - 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)) - { if (soap->error == SOAP_EOF) - { soap->error = SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "EOF in HTTP header, continue anyway\n")); - break; - } - 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))) - { if (soap->error < SOAP_STOP) - return soap->error; - status = soap->error; - soap->error = SOAP_OK; - } - } - } - if ((s = strchr(soap->msgbuf, ' '))) - { k = (unsigned short)soap_strtoul(s, &s, 10); - if (!soap_blank(*s)) - k = 0; - } - 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 && (((get = !strncmp(soap->msgbuf, "GET ", 4))) || !strncmp(soap->msgbuf, "POST ", 5))) - { size_t m = strlen(soap->endpoint); - size_t n = m + (s - soap->msgbuf) - 5 - (!get); - if (n >= sizeof(soap->endpoint)) - n = sizeof(soap->endpoint) - 1; - strncpy(soap->path, soap->msgbuf + 4 + (!get), n - m); - soap->path[n - m] = '\0'; - strcat(soap->endpoint, soap->path); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint)); - if (get) - { soap->error = soap->fget(soap); - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - return soap->error; - } - if (status) - return soap->error = status; - return SOAP_OK; - } - if (k == 0 || (k >= 200 && k <= 299) || k == 400 || k == 500) - return SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP error %d\n", k)); - return soap_set_receiver_error(soap, "HTTP error", soap->msgbuf, k); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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_get_header_attribute(soap, val, "multipart/form-data")) - { 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 *")) - { int 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 == '"') - { 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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#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) && !(soap->mode & SOAP_ENC_MTOM)) - 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->mode & SOAP_ENC_MTOM)) - { 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) && !(soap->mode & SOAP_ENC_MTOM)) - 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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) -{ soap->part = SOAP_END_ENVELOPE; - return soap_element_end_in(soap, "SOAP-ENV:Envelope"); -} -#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; -#ifndef WITH_LEAN - if ((soap->mode & SOAP_XML_SEC) && soap_set_attr(soap, "wsu:Id", "Body")) - return soap->error; -#endif - if (soap_element(soap, "SOAP-ENV:Body", 0, NULL)) - 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_END_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; - if (soap_element_begin_in(soap, "SOAP-ENV:Body", 0)) - return soap->error; - if (!soap->body) - soap->part = SOAP_NO_BODY; - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_body_end_in(struct soap *soap) -{ if (soap->part == SOAP_NO_BODY) - return SOAP_OK; - soap->part = SOAP_END_BODY; - return soap_element_end_in(soap, "SOAP-ENV:Body"); -} -#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] = '\0'; - soap->host[0] = '\0'; - soap->path[0] = '/'; - soap->path[1] = '\0'; - soap->port = 80; - if (!endpoint || !*endpoint) - return; - if (!strncmp(endpoint, "https:", 6)) - soap->port = 443; - 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; -#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 - for (i = 0; i < n; i++) - { soap->host[i] = s[i]; - if (s[i] == '/' || s[i] == ':') - break; - } -#endif - 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, 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); -#ifndef WITH_LEANER - if (soap->fconnect) - { if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port))) - return soap->error; - } - else -#endif - if (soap->fopen && *soap->host) - { soap->status = http_command; - if (!soap->keep_alive || !soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port || !soap->fpoll || soap->fpoll(soap)) - { soap->keep_alive = 0; /* to force close */ - soap->omode &= ~SOAP_IO_UDP; /* to force close */ - soap_closesock(soap); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect/reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port)); -#ifdef WITH_UDP - if (!strncmp(endpoint, "soap.udp:", 9)) - soap->omode |= SOAP_IO_UDP; -#endif - 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); - } - } - count = soap_count_attachments(soap); - if (soap_begin_send(soap)) - return soap->error; -#ifndef WITH_NOHTTP - 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; -#ifndef WITH_LEANER - if ((k & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = k; - } - else if (action) - soap->action = soap_strdup(soap, action); - if (http_command != SOAP_POST) - return soap_end_send(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2base64(struct soap *soap, const unsigned char *s, char *t, int n) -{ register int 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, int *n) -{ register int i, j, c; - register unsigned long m; - register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = (strlen(s) + 3) / 4 * 3; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - 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 WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2hex(struct soap *soap, const unsigned char *s, char *t, int n) -{ register char *p; - if (!t) - t = (char*)soap_malloc(soap, 2 * n + 1); - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - t[0] = '\0'; - if (s) - { for (; n > 0; n--) - { register int m = *s++; - *t++ = (char)((m >> 4) + (m > 159 ? 'a' - 10 : '0')); - m &= 0x0F; - *t++ = (char)(m + (m > 9 ? 'a' - 10 : '0')); - } - } - *t++ = '\0'; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_hex2s(struct soap *soap, const char *s, char *t, size_t l, int *n) -{ register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = strlen(s) / 2; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - while (l) - { register int d1, d2; - d1 = *s++; - if (!d1) - break; - d2 = *s++; - if (!d2) - break; - *t++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0'); - l--; - } - if (n) - *n = t - p; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_puthttphdr(struct soap *soap, int status, size_t count) -{ register const char *s; -#ifndef WITH_LEANER - register const char *r = NULL; -#endif - register int err; - if (status == SOAP_FILE && soap->http_content) - s = soap->http_content; - else if (status == SOAP_HTML) - s = "text/html; charset=utf-8"; - 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_DIME | SOAP_ENC_MTOM)) - { if (soap->mode & SOAP_ENC_MTOM) - { r = s; - s = "application/xop+xml; charset=utf-8"; - } - else - s = "application/dime"; - } - if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && soap->status != SOAP_GET) - { register const char *t = strchr(s, ';'); - sprintf(soap->tmpbuf, "multipart/related; boundary=\"%s\"; type=\"", soap->mime.boundary); - if (t) - strncat(soap->tmpbuf, s, t - s); - else - strcat(soap->tmpbuf, s); - if (soap->mime.start) - { strcat(soap->tmpbuf, "\"; start=\""); - strcat(soap->tmpbuf, soap->mime.start); - } - strcat(soap->tmpbuf, "\""); - if (r) - { strcat(soap->tmpbuf, "; start-info=\""); - strcat(soap->tmpbuf, r); - strcat(soap->tmpbuf, "\""); - } - 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 -#ifndef WITH_LEANER - if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK) - err = soap->fposthdr(soap, "Transfer-Encoding", "chunked"); - else -#endif - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_get(struct soap *soap) -{ return SOAP_GET_METHOD; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 == '/' ? path + 1 : 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_response(struct soap *soap, int status, size_t count) -{ register int err; -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - httpOutputEnable(soap->rpmreqid); -#endif /* WMW_RPM_IO */ - if (!status || status == SOAP_HTML || status == SOAP_FILE) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "OK 200\n")); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif /* WMW_RPM_IO */ - { 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; -#ifndef WITH_LEAN - 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; - } -#endif - } - 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)); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif /* WMW_RPM_IO */ - { 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 -#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; -#ifndef WITH_NOHTTP - 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; -#ifndef WITH_LEANER - if ((n & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = n; - } -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static const char* -soap_set_validation_fault(struct soap *soap, const char *s, const char *t) -{ if (*soap->tag) - sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element <%s>", s, t?t:SOAP_STR_EOS, soap->tag); - else - sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t?t:SOAP_STR_EOS); - 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 && !*s && soap->fseterror) - soap->fseterror(soap, c, s); - 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_TYPE: - *s = soap_set_validation_fault(soap, "data type mismatch ", soap->type); - break; - case SOAP_SYNTAX_ERROR: - *s = "Well-formedness violation"; - break; - case SOAP_NO_TAG: - *s = "No XML element tag"; - 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_USER_ERROR: - *s = "User error"; - 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_DUPLICATE_ID: - *s = soap_set_validation_fault(soap, "multiple definitions of id ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:DuplicateID"; - break; - case SOAP_MISSING_ID: - *s = soap_set_validation_fault(soap, "missing id for ref ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:MissingID"; - break; - case SOAP_HREF: - *s = soap_set_validation_fault(soap, "incompatible object ref ", soap->id); - break; - case SOAP_FAULT: - break; -#ifndef WITH_NOIO - case SOAP_UDP_ERROR: - *s = "Message too large for UDP packet"; - break; - case SOAP_TCP_ERROR: - *s = tcp_error(soap); - break; -#endif - case SOAP_HTTP_ERROR: - *s = "HTTP error"; - break; - case SOAP_SSL_ERROR: -#ifdef WITH_OPENSSL - *s = "SSL error"; -#else - *s = "OpenSSL not installed: recompile with -DWITH_OPENSSL"; -#endif - break; - case SOAP_PLUGIN_ERROR: - *s = "Plugin registry error"; - break; - case SOAP_DIME_ERROR: - *s = "DIME format error"; - break; - case SOAP_DIME_HREF: - *s = "DIME href to missing attachment"; - break; - case SOAP_DIME_MISMATCH: - *s = "DIME version/transmission error"; - break; - case SOAP_DIME_END: - *s = "End of DIME error"; - break; - case SOAP_MIME_ERROR: - *s = "MIME format error"; - break; - case SOAP_MIME_HREF: - *s = "MIME href to missing attachment"; - break; - case SOAP_MIME_END: - *s = "End of MIME 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/gzip not installed for (de)compression: recompile with -DWITH_GZIP"; -#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, "min/maxOccurs violation", NULL); - break; - case SOAP_LENGTH: - *s = soap_set_validation_fault(soap, "content length violation", NULL); - break; - case SOAP_STOP: - *s = "Stopped: no response sent"; - break; -#endif - case SOAP_EOF: -#ifndef WITH_NOIO - sprintf(soap->msgbuf, "End of file or no input: '%s'", soap_strerror(soap)); - *s = soap->msgbuf; - break; -#else - *s = "End of file or no input"; - break; -#endif - default: -#ifndef WITH_NOHTTP -#ifndef WITH_LEAN - if (soap->error > 200 && soap->error < 600) - { sprintf(soap->msgbuf, "HTTP Error: %d %s", soap->error, http_error(soap, soap->error)); - *s = soap->msgbuf; - } - else -#endif -#endif - { sprintf(soap->msgbuf, "Error %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; - int r = 1; - 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); -#ifndef WITH_NOIO -#ifndef WITH_LEAN - if (soap_valid_socket(soap->socket)) - { struct timeval timeout; - fd_set rfd, sfd; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_SET((SOAP_SOCKET)soap->socket, &rfd); - FD_SET((SOAP_SOCKET)soap->socket, &sfd); - r = select((SOAP_SOCKET)(soap->socket + 1), &rfd, &sfd, NULL, &timeout); - if (r > 0) - { if (!FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - || (FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - && recv((SOAP_SOCKET)soap->socket, soap->tmpbuf, 1, MSG_PEEK) < 0)) - r = 0; - } - } -#endif -#endif - if ((status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) && r > 0) - { 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); - } - soap_end_count(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 WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_send_empty_response(struct soap *soap) -{ soap->count = 0; - if (soap_response(soap, SOAP_OK) || soap_end_send(soap)) - return soap_closesock(soap); - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_recv_empty_response(struct soap *soap) -{ if (soap_begin_recv(soap) || soap_end_recv(soap)) - return soap_closesock(soap); - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static const char* -soap_strerror(struct soap *soap) -{ register int err = soap->errnum; - if (err) - { -#ifndef WIN32 - return strerror(err); -#else - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)&soap->errorstr, sizeof(soap->errorstr), NULL); - return soap->errorstr; -#endif - } - return "Operation interrupted or timed out"; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_set_error(struct soap *soap, const char *faultcode, const char *faultsubcode, const char *faultstring, const char *faultdetail, int soaperror) -{ *soap_faultcode(soap) = faultcode; - if (faultsubcode) - *soap_faultsubcode(soap) = faultsubcode; - *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", NULL, 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", NULL, faultstring, faultdetail, soaperror); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ char *r = NULL, *s = NULL, *t = NULL; - if (faultsubcode) - r = soap_strdup(soap, faultsubcode); - if (faultstring) - s = soap_strdup(soap, faultstring); - if (faultdetail) - t = soap_strdup(soap, faultdetail); - return soap_set_error(soap, faultcode, r, 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_sender_fault_subcode(soap, NULL, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultsubcode, 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_receiver_fault_subcode(soap, NULL, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultsubcode, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault(struct soap *soap, FILE *fd) -{ if (soap->error) - { const char *c, *v = NULL, *s, **d; - d = soap_faultcode(soap); - if (!*d) - soap_set_fault(soap); - c = *d; - if (soap->version == 2) - v = *soap_faultsubcode(soap); - s = *soap_faultstring(soap); - d = soap_faultdetail(soap); - fprintf(fd, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]"); - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault_location(struct soap *soap, FILE *fd) -{ -#ifndef WITH_LEAN - int i, j, c1, c2; - if (soap->error && soap->buflen > 0) - { i = (int)soap->bufidx - 1; - if (i <= 0) - i = 0; - c1 = soap->buf[i]; - soap->buf[i] = '\0'; - if ((int)soap->buflen >= i + 1024) - j = i + 1023; - else - j = (int)soap->buflen - 1; - c2 = soap->buf[j]; - soap->buf[j] = '\0'; - fprintf(fd, "%s%c\n** HERE **\n", soap->buf, c1); - if (soap->bufidx < soap->buflen) - fprintf(fd, "%s\n", soap->buf + soap->bufidx); - soap->buf[i] = c1; - soap->buf[j] = c2; - } -#endif -} -#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(soap, 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(soap, 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 - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.h b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.h deleted file mode 100644 index 17ef597..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6b.h +++ /dev/null @@ -1,2053 +0,0 @@ -/* - -stdsoap2.h 2.7.6b - -gSOAP runtime - -gSOAP XML Web services tools -Copyright (C) 2000-2005, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under one of the following licenses: -GPL, the gSOAP public license, or Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems, Inc., for the following additions (marked WR[...]): - - vxWorks compatible --------------------------------------------------------------------------------- -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-2005, 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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- -*/ - -#ifdef WITH_SOAPDEFS_H -# include "soapdefs.h" /* include user-defined stuff */ -#endif - -#ifndef _THREAD_SAFE -# define _THREAD_SAFE -#endif - -#ifndef OPENSERVER -# ifndef _REENTRANT -# define _REENTRANT -# endif -#endif - -#ifndef SOAP_FMAC1 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC1 -#endif - -#ifndef SOAP_FMAC2 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC2 -#endif - -#ifndef SOAP_FMAC3 /* (de)serializer declaration macro */ -# define SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC3S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC3S SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC4 /* (de)serializer declaration macro */ -# define SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC4S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC4S SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC5 /* stub/skeleton declaration macro */ -# define SOAP_FMAC5 -#endif - -#ifndef SOAP_FMAC6 /* stub/skeleton declaration macro */ -# define SOAP_FMAC6 -#endif - -#ifndef SOAP_CMAC /* class declaration macro */ -# define SOAP_CMAC -#endif - -#ifndef SOAP_NMAC /* namespace table declaration macro */ -# define SOAP_NMAC -#endif - -#ifndef SOAP_SOURCE_STAMP -# define SOAP_SOURCE_STAMP(str) -#endif - -/* gSOAP 2.7.4 and higher: fast look-aside buffering is stable */ -#ifndef WITH_FAST -# define WITH_FAST -#endif - -#ifdef WITH_LEANER -# ifndef WITH_LEAN -# define WITH_LEAN -# endif -#endif - -#ifdef WITH_LEAN -# ifdef WITH_COOKIES -# error "Cannot build WITH_LEAN code WITH_COOKIES enabled" -# endif -#endif - -#ifndef STDSOAP_H -#define STDSOAP_H - -#if defined(__vxworks) || defined(__VXWORKS__) -# define VXWORKS -#endif - -#ifdef _WIN32 -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef UNDER_CE -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef __BORLANDC__ -# ifdef __WIN32__ -# ifndef WIN32 -# define WIN32 -# endif -# endif -#endif - -#ifdef __CYGWIN__ -# ifndef CYGWIN -# define CYGWIN -# endif -#endif - -#ifdef __SYMBIAN32__ -# define SYMBIAN -# undef WIN32 -#endif - -#if defined(__palmos__) || defined(PALM_GCC) || defined(__PALMOS_TRAPS__) -# ifndef PALM -# define PALM -# endif -#endif - -#if defined(__hpux) -# ifndef HP_UX -# define HP_UX -# endif -#endif - -#if defined(__alpha) && !defined(__VMS) -# ifndef TRU64 -# define TRU64 -# endif -#endif - -#ifdef __MVS__ -# ifndef OS390 -# define OS390 -# endif -#endif - -#ifdef HAVE_CONFIG_H -# include "config.h" -# ifdef WITH_OPENSSL -# ifndef HAVE_OPENSSL_SSL_H -# undef WITH_OPENSSL -# endif -# endif -#else -# if defined(UNDER_CE) -# define WITH_LEAN -# define HAVE_SSCANF -# elif defined(WIN32) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%I64d" -# define SOAP_ULONG_FORMAT "%I64u" -# elif defined(CYGWIN) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__APPLE__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(_AIXVERSION_431) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(HP_UX) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(FREEBSD) || defined(__FreeBSD__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_GETTIMEOFDAY -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%qd" -# define SOAP_ULONG_FORMAT "%qu" -# elif defined(__VMS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__GLIBC__) || defined(__GNU__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define HAVE_ISNAN -# elif defined(TRU64) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_GETTIMEOFDAY -# define HAVE_SYS_TIMEB_H -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define __USE_STD_IOSTREAM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -# elif defined(MAC_CARBON) -# define WITH_NOIO -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(PALM) -# define WITH_LEAN -# define HAVE_STRTOD /* strtod() is defined in palmFunctions.h */ -# include /* Needs to be included before unix headers */ -# include -# define IGNORE_STDIO_STUBS -# include -# define O_NONBLOCK FNONBIO -# include -# include "palmFunctions.h" -# elif defined(SYMBIAN) -# define WITH_LEAN -# define WITH_NONAMESPACES -# define HAVE_STRTOD /* use STRTOD since sscanf doesn't seem to work */ -# include -# include -# elif defined(VXWORKS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_PGMTIME_R -# define HAVE_PLOCALTIME_R -# define HAVE_MKTIME -# elif defined(OS390) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MB -# else -/* Default asumptions on supported functions */ -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# endif -#endif - -/* QNX does not have a working version of strtof */ -#if defined(__QNX__) || defined(QNX) -# undef HAVE_STRTOF -#endif - -#ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%lld" /* printf format for 64 bit ints */ -#endif - -#ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%llu" /* printf format for unsigned 64 bit ints */ -#endif - -#ifndef WITH_NOSTDLIB -# include -# ifndef PALM -# include -# include -# endif -# include -# include -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -# include -# include -#endif - -#ifdef WITH_NOHTTP -# ifndef WITH_NOIO -# define WITH_NOIO -# undef WITH_COOKIES -# endif -#endif - -#ifndef UNDER_CE -# ifndef PALM -# ifndef WITH_NOIO -# include -# include -# endif -# ifndef WITH_LEAN -# ifdef HAVE_SYS_TIMEB_H -# include /* for ftime() */ -# endif -# include -# endif -# endif -#endif - -#ifdef OPENSERVER -# include -# include -# include - extern int h_errno; -#endif - -#ifndef WITH_NOIO -# ifndef WIN32 -# ifndef PALM -# include -# ifdef VXWORKS -# include -# include -# endif -# ifndef VXWORKS -# ifndef SYMBIAN -# include -# endif -# endif -# ifdef SUN_OS -# include /* SUN */ -# include /* SUN < 2.8 (?) */ -# endif -# ifdef VXWORKS -# ifdef _WRS_KERNEL -# include -# endif -# else -# include -# endif -# include -# ifdef OS390 -# include -# else -# include /* TCP_NODELAY */ -# endif -# include -# endif -# endif -#endif - -#ifdef WITH_FASTCGI -# include -#endif - -#ifdef WITH_OPENSSL -# define OPENSSL_NO_KRB5 -# include -# include -# include -# ifndef ALLOW_OLD_VERSIONS -# if (OPENSSL_VERSION_NUMBER < 0x00905100L) -# error "Must use OpenSSL 0.9.6 or later" -# endif -# endif -#endif - -#ifdef WITH_GZIP -# ifndef WITH_ZLIB -# define WITH_ZLIB -# endif -#endif - -#ifdef WITH_CASEINSENSITIVETAGS -# define SOAP_STRCMP soap_tag_cmp /* case insensitve XML element/attribute names */ -#else -# define SOAP_STRCMP strcmp /* case sensitive XML element/attribute names */ -#endif - -#ifdef WITH_ZLIB -# include -#endif - -#ifndef WITH_NOSTDLIB -# ifndef PALM -# include /* for isnan() */ -# endif -#endif - -/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef WIN32 -# ifndef UNDER_CE -# include -# include -# endif -# include -/* # include */ /* Alternative: use winsock2 (not available with eVC) */ -# ifdef WITH_IPV6 -# include -# include -# endif -#else -# ifdef VXWORKS -# include -# include -# include -# endif -# ifndef WITH_NOIO -# ifndef PALM -# include -# include -# include -# include -# endif -# endif -#endif - -/* Portability: define SOAP_SOCKLEN_T */ -#if defined(SOCKLEN_T) -# define SOAP_SOCKLEN_T SOCKLEN_T -#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(__QNX__) || defined(QNX) || defined(_AIX) -# define SOAP_SOCKLEN_T socklen_t -#elif defined(IRIX) || defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS) -# define SOAP_SOCKLEN_T int -#else -# define SOAP_SOCKLEN_T size_t -#endif - -#ifdef WIN32 -# define SOAP_SOCKET SOCKET -#else -# define SOAP_SOCKET int -# define closesocket(n) close(n) -#endif - -#define SOAP_INVALID_SOCKET (-1) -#define soap_valid_socket(n) ((n) != SOAP_INVALID_SOCKET) - -#if defined(SYMBIAN) -# define LONG64 long -# define ULONG64 unsigned LONG64 -#elif !defined(WIN32) || defined(__GLIBC__) || defined(__GNU__) -# ifndef LONG64 -# define LONG64 long long -# define ULONG64 unsigned LONG64 -# endif -#elif defined(UNDER_CE) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#elif defined(__BORLANDC__) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#endif - -#if defined(WIN32) -# define soap_int32 __int32 -#elif defined(SYMBIAN) -# define soap_int32 long -#elif defined(PALM) -# define soap_int32 Int32 -#else -# define soap_int32 int32_t -#endif - -#ifdef WIN32 -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR WSAEINTR -# define SOAP_EAGAIN WSAEWOULDBLOCK -# define SOAP_EWOULDBLOCK WSAEWOULDBLOCK -# define SOAP_EINPROGRESS WSAEINPROGRESS -#else -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR EINTR -# define SOAP_EAGAIN EAGAIN -# ifdef SYMBIAN -# define SOAP_EWOULDBLOCK 9898 -# define SOAP_EINPROGRESS 9899 -# else -# define SOAP_EWOULDBLOCK EWOULDBLOCK -# define SOAP_EINPROGRESS EINPROGRESS -# endif -#endif - -#ifdef WIN32 -# ifdef UNDER_CE -# define soap_errno GetLastError() -# define soap_socket_errno GetLastError() -# else -# define soap_errno GetLastError() -# define soap_socket_errno WSAGetLastError() -# endif -#else -# ifndef WITH_NOIO -# define soap_errno errno -# define soap_socket_errno errno -# else -# define soap_errno 0 -# define soap_socket_errno 0 -# endif -#endif - -#ifndef SOAP_BUFLEN -# ifdef WITH_UDP -# define SOAP_BUFLEN (65536) /* max UDP packet size */ -# else -# ifndef WITH_LEAN -# define SOAP_BUFLEN (65536) /* buffer length for socket packets, also used by gethostbyname_r so don't make this too small */ -# else -# define SOAP_BUFLEN (2048) -# endif -# endif -#endif -#ifndef SOAP_LABLEN -# define SOAP_LABLEN (64) /* initial look-aside buffer length */ -#endif -#ifndef SOAP_PTRBLK -# define SOAP_PTRBLK (32) /* block allocation for pointer hash table chains */ -#endif -#ifndef SOAP_PTRHASH -# ifndef WITH_LEAN -# define SOAP_PTRHASH (1024) /* size of pointer analysis hash table (must be power of 2) */ -# else -# define SOAP_PTRHASH (32) -# endif -#endif -#ifndef SOAP_IDHASH -# ifndef WITH_LEAN -# define SOAP_IDHASH (1999) /* prime size of hash table for parsed id/ref */ -# else -# define SOAP_IDHASH (19) /* 19, 199 */ -# endif -#endif -#ifndef SOAP_BLKLEN -# ifndef WITH_LEAN -# define SOAP_BLKLEN (256) /* size of blocks to collect long strings and XML attributes */ -# else -# define SOAP_BLKLEN (32) -# endif -#endif -#ifndef SOAP_TAGLEN -# ifndef WITH_LEAN -# define SOAP_TAGLEN (256) /* maximum length of XML element tag/attribute name or host/path name + 1 */ -# else -# define SOAP_TAGLEN (64) -# endif -#endif -#ifndef SOAP_HDRLEN -# ifndef WITH_LEAN -# define SOAP_HDRLEN (8192) /* maximum length of HTTP header line (must be >4096 to read cookies) */ -# else -# define SOAP_HDRLEN (1024) -# endif -#endif -#ifndef SOAP_MAXDIMS -# ifndef WITH_LEAN -# define SOAP_MAXDIMS (16) /* maximum array dimensions (array nestings) must be less than 64 to protect soap->tmpbuf */ -# else -# define SOAP_MAXDIMS (4) -# endif -#endif - -#ifndef SOAP_MAXLOGS -# define SOAP_MAXLOGS (3) /* max number of debug logs per struct soap environment */ -# define SOAP_INDEX_RECV (0) -# define SOAP_INDEX_SENT (1) -# define SOAP_INDEX_TEST (2) -#endif - -#ifndef SOAP_MAXKEEPALIVE -# define SOAP_MAXKEEPALIVE (100) /* max iterations to keep server connection alive */ -#endif - -#ifndef SOAP_MAXARRAYSIZE -# define SOAP_MAXARRAYSIZE (100000) /* "trusted" max size of inbound SOAP array for compound array allocation */ -#endif - -#ifdef VXWORKS -# ifdef __INCmathh -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) isNan(num) -# endif -#endif - -#ifdef WIN32 -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) _isnan(num) -#endif - -#ifdef SUN_OS -# define soap_isnan(n) isnan(n) -#endif - -#if !defined(HAVE_ISNAN) && (defined(_MATH_H) || defined(_MATH_INCLUDED)) -# define HAVE_ISNAN -#endif - -#ifndef soap_isnan -# ifdef HAVE_ISNAN -# define soap_isnan(n) isnan(n) -# else -# define soap_isnan(_) (0) -# endif -#endif - -extern const struct soap_double_nan { unsigned int n1, n2; } soap_double_nan; - -#ifdef VXWORKS -# ifndef FLT_MAX -# define FLT_MAX _ARCH_FLT_MAX -# endif -# ifndef DBL_MAX -# define DBL_MAX _ARCH_DBL_MAX -# endif -#endif - -#ifndef FLT_NAN -# ifdef HAVE_ISNAN -# define FLT_NAN (*(float*)(void*)&soap_double_nan) -# else -# define FLT_NAN (0.0) -# endif -#endif - -#ifndef FLT_PINFTY -# if defined(FLT_MAX) -# define FLT_PINFTY FLT_MAX -# elif defined(HUGE_VALF) -# define FLT_PINFTY (float)HUGE_VALF -# elif defined(HUGE_VAL) -# define FLT_PINFTY (float)HUGE_VAL -# elif defined(FLOAT_MAX) -# define FLT_PINFTY FLOAT_MAX -# else -# define FLT_PINFTY (3.40282347e+38F) -# endif -#endif - -#ifndef FLT_NINFTY -# define FLT_NINFTY (-FLT_PINFTY) -#endif - -#ifndef DBL_NAN -# ifdef HAVE_ISNAN -# define DBL_NAN (*(double*)(void*)&soap_double_nan) -# else -# define DBL_NAN (0.0) -# endif -#endif - -#ifndef DBL_PINFTY -# if defined(DBL_MAX) -# define DBL_PINFTY DBL_MAX -# elif defined(HUGE_VALF) -# define DBL_PINFTY (double)HUGE_VALF -# elif defined(HUGE_VAL) -# define DBL_PINFTY (double)HUGE_VAL -# elif defined(DOUBLE_MAX) -# define DBL_PINFTY DOUBLE_MAX -# else -# define DBL_PINFTY (1.7976931348623157e+308) -# endif -#endif - -#ifndef DBL_NINFTY -# define DBL_NINFTY (-DBL_PINFTY) -#endif - -#define soap_ispinfd(n) ((n) >= DBL_PINFTY) -#define soap_ispinff(n) ((n) >= FLT_PINFTY) -#define soap_isninfd(n) ((n) <= DBL_NINFTY) -#define soap_isninff(n) ((n) <= FLT_NINFTY) - -/* gSOAP error codes */ - -#define SOAP_EOF EOF -#define SOAP_ERR EOF -#define SOAP_OK 0 -#define SOAP_CLI_FAULT 1 -#define SOAP_SVR_FAULT 2 -#define SOAP_TAG_MISMATCH 3 -#define SOAP_TYPE 4 -#define SOAP_SYNTAX_ERROR 5 -#define SOAP_NO_TAG 6 -#define SOAP_IOB 7 -#define SOAP_MUSTUNDERSTAND 8 -#define SOAP_NAMESPACE 9 -#define SOAP_USER_ERROR 10 -#define SOAP_FATAL_ERROR 11 -#define SOAP_FAULT 12 -#define SOAP_NO_METHOD 13 -#define SOAP_GET_METHOD 14 -#define SOAP_EOM 15 -#define SOAP_NULL 16 -#define SOAP_DUPLICATE_ID 17 -#define SOAP_MISSING_ID 18 -#define SOAP_HREF 19 -#define SOAP_UDP_ERROR 20 -#define SOAP_TCP_ERROR 21 -#define SOAP_HTTP_ERROR 22 -#define SOAP_SSL_ERROR 23 -#define SOAP_ZLIB_ERROR 24 -#define SOAP_DIME_ERROR 25 -#define SOAP_DIME_HREF 26 -#define SOAP_DIME_MISMATCH 27 -#define SOAP_DIME_END 28 -#define SOAP_MIME_ERROR 29 -#define SOAP_MIME_HREF 30 -#define SOAP_MIME_END 31 -#define SOAP_VERSIONMISMATCH 32 -#define SOAP_PLUGIN_ERROR 33 -#define SOAP_DATAENCODINGUNKNOWN 34 -#define SOAP_REQUIRED 35 -#define SOAP_PROHIBITED 36 -#define SOAP_OCCURS 37 -#define SOAP_LENGTH 38 - -#define soap_xml_error_check(e) ((e) == SOAP_TAG_MISMATCH || (e) == SOAP_TAG_END || (e) == SOAP_SYNTAX_ERROR || (e) == SOAP_NAMESPACE || (e) == SOAP_DUPLICATE_ID || (e) == SOAP_MISSING_ID || (e) == SOAP_REQUIRED || (e) == SOAP_PROHIBITED || (e) == SOAP_OCCURS || (e) == SOAP_LENGTH || (e) == SOAP_NULL || (e) == SOAP_HREF) -#define soap_soap_error_check(e) ((e) == SOAP_CLI_FAULT || (e) == SOAP_SVR_FAULT || (e) == SOAP_VERSIONMISMATCH || (e) == SOAP_MUSTUNDERSTAND || (e) == SOAP_FAULT || (e) == SOAP_NO_METHOD) -#define soap_tcp_error_check(e) ((e) == SOAP_EOF || (e) == SOAP_TCP_ERROR) -#define soap_ssl_error_check(e) ((e) == SOAP_SSL_ERROR) -#define soap_zlib_error_check(e) ((e) == SOAP_ZLIB_ERROR) -#define soap_http_error_check(e) ((e) == SOAP_HTTP_ERROR || (e) == SOAP_GET_METHOD || ((e) >= 100 && (e) < 600)) - -/* gSOAP HTTP response status codes 100 to 599 are reserved */ - -/* Codes 600 to 999 are user definable */ - -/* Exceptional gSOAP HTTP response status codes >= 1000 */ - -#define SOAP_STOP 1000 /* No HTTP response */ -#define SOAP_FORM 1001 /* Form request/response */ -#define SOAP_HTML 1002 /* Custom HTML response */ -#define SOAP_FILE 1003 /* Custom file-based response */ - -/* gSOAP HTTP method codes */ - -#define SOAP_POST 2000 -#define SOAP_GET 2001 - -/* gSOAP DIME */ - -#define SOAP_DIME_CF 0x01 -#define SOAP_DIME_ME 0x02 -#define SOAP_DIME_MB 0x04 -#define SOAP_DIME_VERSION 0x08 /* DIME version 1 */ -#define SOAP_DIME_MEDIA 0x10 -#define SOAP_DIME_ABSURI 0x20 - -/* gSOAP ZLIB */ - -#define SOAP_ZLIB_NONE 0x00 -#define SOAP_ZLIB_DEFLATE 0x01 -#define SOAP_ZLIB_INFLATE 0x02 -#define SOAP_ZLIB_GZIP 0x02 - -/* gSOAP transport, connection, and content encoding modes */ - -typedef soap_int32 soap_mode; - -#define SOAP_IO 0x00000003 /* IO mask */ -#define SOAP_IO_FLUSH 0x00000000 /* flush output immediately, no buffering */ -#define SOAP_IO_BUFFER 0x00000001 /* buffer output in packets of size SOAP_BUFLEN */ -#define SOAP_IO_STORE 0x00000002 /* store entire output to determine length for transport */ -#define SOAP_IO_CHUNK 0x00000003 /* use HTTP chunked transfer AND buffer packets */ - -#define SOAP_IO_UDP 0x00000004 -#define SOAP_IO_LENGTH 0x00000008 -#define SOAP_IO_KEEPALIVE 0x00000010 - -#define SOAP_ENC_LATIN 0x00800020 /* iso-8859-1 encoding */ -#define SOAP_ENC_XML 0x00000040 /* plain XML encoding, no HTTP header */ -#define SOAP_ENC_DIME 0x00000080 -#define SOAP_ENC_MIME 0x00000100 -#define SOAP_ENC_MTOM 0x00000200 -#define SOAP_ENC_ZLIB 0x00000400 -#define SOAP_ENC_SSL 0x00000800 - -#define SOAP_ENC 0x00000FFF /* IO and ENC mask */ - -#define SOAP_XML_STRICT 0x00001000 /* strict validation */ -#define SOAP_XML_INDENT 0x00002000 -#define SOAP_XML_CANONICAL 0x00004000 /* EXC C14N canonical XML */ -#define SOAP_XML_TREE 0x00008000 -#define SOAP_XML_GRAPH 0x00010000 -#define SOAP_XML_NIL 0x00020000 -#define SOAP_XML_DOM 0x00040000 -#define SOAP_XML_SEC 0x00080000 /* reserved for WS security */ - -#define SOAP_C_NOIOB 0x00100000 -#define SOAP_C_UTFSTRING 0x00200000 -#define SOAP_C_MBSTRING 0x00400000 - -#define SOAP_DOM_TREE 0x01000000 -#define SOAP_DOM_NODE 0x02000000 -#define SOAP_DOM_ASIS 0x04000000 - -#define SOAP_IO_DEFAULT SOAP_IO_FLUSH - -/* SSL client/server authentication settings */ - -#define SOAP_SSL_NO_AUTHENTICATION 0x00 /* for testing purposes */ -#define SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION 0x01 /* client requires server to authenticate */ -#define SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION 0x02 /* server requires client to authenticate */ - -#define SOAP_SSL_DEFAULT SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION - -/* */ - -#define SOAP_BEGIN 0 -#define SOAP_IN_ENVELOPE 2 -#define SOAP_IN_HEADER 3 -#define SOAP_END_HEADER 4 -#define SOAP_NO_BODY 5 -#define SOAP_IN_BODY 6 -#define SOAP_END_BODY 7 -#define SOAP_END_ENVELOPE 8 -#define SOAP_END 9 -#define SOAP_BEGIN_SECURITY 10 -#define SOAP_IN_SECURITY 11 -#define SOAP_END_SECURITY 12 - -/* DEBUG macros */ - -#ifndef WITH_LEAN -# ifdef DEBUG -# ifndef SOAP_DEBUG -# define SOAP_DEBUG -# endif -# endif -#endif - -#ifdef SOAP_DEBUG -# define SOAP_MALLOC(soap, size) soap_track_malloc(soap, __FILE__, __LINE__, size) -# define SOAP_FREE(soap, ptr) soap_track_free(soap, __FILE__, __LINE__, ptr) -#endif - -#ifndef SOAP_MALLOC /* use libc malloc */ -# define SOAP_MALLOC(soap, size) malloc(size) -#endif - -#ifndef SOAP_FREE /* use libc free */ -# define SOAP_FREE(soap, ptr) free(ptr) -#endif - -#ifdef SOAP_DEBUG -# ifndef SOAP_MESSAGE -# define SOAP_MESSAGE fprintf -# endif -# ifndef DBGLOG -# define DBGLOG(DBGFILE, CMD) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ - CMD;\ - fflush(fdebug);\ - }\ - }\ -} -# endif -# ifndef DBGMSG -# define DBGMSG(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { fwrite((MSG), 1, (LEN), soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -# ifndef DGBFUN -# define DBGFUN(FNAME) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s()\n", __FILE__, __LINE__, FNAME)) -# define DBGFUN1(FNAME, FMT, ARG) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT")\n", __FILE__, __LINE__, FNAME, (ARG))) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2))) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2", "FMT3")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2), (ARG3))) -# endif -# ifndef DBGHEX -# define DBGHEX(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { int i; char *s;\ - for (s = (char*)(MSG), i = (LEN); i; i--)\ - fprintf(soap->fdebug[SOAP_INDEX_##DBGFILE], "%2.2hhX ", *s++);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -#else -# define DBGLOG(DBGFILE, CMD) -# define DBGMSG(DBGFILE, MSG, LEN) -# define DBGFUN(FNAME) -# define DBGFUN1(FNAME, FMT, ARG) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) -# define DBGHEX(DBGFILE, MSG, LEN) -#endif - -/* UCS-4 requires 32 bits (0-7FFFFFFF, the sign bit is used by gSOAP to distinguish XML entities) */ -typedef soap_int32 soap_wchar; - -/* namespace table row */ -struct Namespace -{ const char *id; - const char *ns; - const char *in; - char *out; -}; - -/* namespace stack */ -struct soap_nlist -{ struct soap_nlist *next; - unsigned int level; /* nesting depth level */ - short index; /* corresponding entry in ns mapping table */ - char *ns; /* only set when parsed ns URI is not in the ns mapping table */ - char id[1]; /* the actual string value flows into the allocated region below this struct */ -}; - -/* block stack for nested block allocations */ -struct soap_blist -{ struct soap_blist *next; - char *ptr; - size_t size; -}; - -/* array layout */ -struct soap_array -{ void *__ptr; - int __size; -}; - -/* pointer serialization management */ -struct soap_plist -{ struct soap_plist *next; - const void *ptr; - const struct soap_array *array; - int type; - int id; - char mark1; - char mark2; -}; - -/* block allocation for pointer serialization management */ -struct soap_pblk -{ struct soap_pblk *next; - struct soap_plist plist[SOAP_PTRBLK]; -}; - -#ifdef SOAP_DEBUG -/* malloc/free tracking for debugging */ -struct soap_mlist -{ struct soap_mlist *next; - const void *ptr; - const char *file; - int line; - short live; -}; -#endif - -/* class allocation list */ -struct soap_clist -{ struct soap_clist *next; - void *ptr; - int type; - int size; - void (*fdelete)(struct soap_clist*); -}; - -/* attributes */ -struct soap_attribute -{ struct soap_attribute *next; - char *value; - size_t size; - char *ns; - short visible; - char name[1]; /* the actual name string flows into the allocated region below this struct */ -}; - -struct soap_cookie -{ struct soap_cookie *next; - char *name; - char *value; - char *domain; - char *path; - long expire; /* client-side: local time to expire; server-side: seconds to expire */ - unsigned int version; - short secure; - short session; /* server-side */ - short env; /* server-side: got cookie from client and should not be (re)send */ - short modified; /* server-side: client cookie was modified and should be send */ -}; - -#ifdef __cplusplus -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); - -class soap_multipart_iterator -{ public: - struct soap_multipart *content; - bool operator==(const soap_multipart_iterator& iter) const - { return content == iter.content; } - bool operator!=(const soap_multipart_iterator& iter) const - { return content != iter.content; } - struct soap_multipart &operator*() const - { return *content; } - soap_multipart_iterator &operator++() - { content = soap_next_multipart(content); return *this; } - soap_multipart_iterator() : content(NULL) - { } - soap_multipart_iterator(struct soap_multipart *p) : content(p) - { } -}; -#endif - -#ifndef WITH_LEANER -struct soap_dime -{ size_t count; - size_t size; - size_t chunksize; - size_t buflen; - char flags; - char *ptr; - const char *id; - const char *type; - const char *options; - struct soap_multipart *list; /* list of DIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -struct soap_mime -{ char *boundary; /* MIME boundary */ - const char *start; /* MIME start ID */ - struct soap_multipart *list; /* list of MIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* RFC2045 MIME content transfer encodings */ -enum soap_mime_encoding -{ SOAP_MIME_NONE, - SOAP_MIME_7BIT, - SOAP_MIME_8BIT, - SOAP_MIME_BINARY, - SOAP_MIME_QUOTED_PRINTABLE, - SOAP_MIME_BASE64, - SOAP_MIME_IETF_TOKEN, - SOAP_MIME_X_TOKEN -}; -#endif - -#ifndef WITH_LEANER -/* DIME/MIME multipart list */ -struct soap_multipart -{ struct soap_multipart *next; - char *ptr; /* points to raw data content */ - size_t size; /* size of data content */ - const char *id; /* DIME/MIME content ID or form data name */ - const char *type; /* DIME/MIME type (MIME type format) */ - const char *options; /* DIME options */ - enum soap_mime_encoding encoding; /* MIME Content-Transfer-Encoding */ - const char *location; /* MIME Content-Location (optional) */ - const char *description; /* MIME Content-Description (optional) */ -#ifdef __cplusplus - typedef soap_multipart_iterator iterator; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* attachment DIME and MTOM XOP forwarding */ -struct soap_xlist -{ struct soap_xlist *next; - unsigned char **ptr; - int *size; - char *id; - char **type; - char **options; -}; -#endif - -/******************************************************************************/ - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_attribute_iterator -{ public: - struct soap_dom_attribute *att; - const char *nstr; - const char *name; - bool operator==(const soap_dom_attribute_iterator&) const; - bool operator!=(const soap_dom_attribute_iterator&) const; - struct soap_dom_attribute &operator*() const; - soap_dom_attribute_iterator &operator++(); - soap_dom_attribute_iterator(); - soap_dom_attribute_iterator(struct soap_dom_attribute*); - ~soap_dom_attribute_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_attribute -{ struct soap_dom_attribute *next; - const char *nstr; - char *name; - char *data; - wchar_t *wide; - struct soap *soap; -#ifdef __cplusplus - typedef soap_dom_attribute_iterator iterator; - struct soap_dom_attribute &set(const char *nstr, const char *name); /* set namespace and name */ - struct soap_dom_attribute &set(const char *data); /* set data */ - soap_dom_attribute_iterator begin(); - soap_dom_attribute_iterator end(); - soap_dom_attribute_iterator find(const char *nstr, const char *name); - void unlink(); - soap_dom_attribute(); - soap_dom_attribute(struct soap *soap); - soap_dom_attribute(struct soap *soap, const char *nstr, const char *name, const char *data); - ~soap_dom_attribute(); -#endif -}; -#endif - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_element_iterator -{ public: - struct soap_dom_element *elt; - const char *nstr; - const char *name; - int type; - bool operator==(const soap_dom_element_iterator&) const; - bool operator!=(const soap_dom_element_iterator&) const; - struct soap_dom_element &operator*() const; - soap_dom_element_iterator &operator++(); - soap_dom_element_iterator(); - soap_dom_element_iterator(struct soap_dom_element*); - ~soap_dom_element_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_element -{ struct soap_dom_element *next; /* next sibling */ - struct soap_dom_element *prnt; /* parent */ - struct soap_dom_element *elts; /* list of child elements */ - struct soap_dom_attribute *atts; /* list of attributes */ - const char *nstr; /* namespace string */ - char *name; /* element tag name */ - char *data; /* element content data (with SOAP_C_UTFSTRING flag set) */ - wchar_t *wide; /* element content data */ - int type; /* optional: serialized C/C++ data type */ - void *node; /* optional: pointer to serialized C/C++ data */ - char *head; /* leading whitespace to start tag */ - char *tail; /* leading whitespace to end tag */ - struct soap *soap; /* soap context that manages this node */ -#ifdef __cplusplus - typedef soap_dom_element_iterator iterator; - struct soap_dom_element &set(const char *nstr, const char *name); - struct soap_dom_element &set(const char *data); - struct soap_dom_element &set(void *node, int type); - struct soap_dom_element &add(struct soap_dom_element*); - struct soap_dom_element &add(struct soap_dom_element&); - struct soap_dom_element &add(struct soap_dom_attribute*); - struct soap_dom_element &add(struct soap_dom_attribute&); - soap_dom_element_iterator begin(); - soap_dom_element_iterator end(); - soap_dom_element_iterator find(const char *nstr, const char *name); - soap_dom_element_iterator find(int type); - void unlink(); - soap_dom_element(); - soap_dom_element(struct soap *soap); - soap_dom_element(struct soap *soap, const char *nstr, const char *name); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type); - ~soap_dom_element(); -#endif -}; -SOAP_FMAC1 const char* SOAP_FMAC2 soap_dom_current_nstr(struct soap *soap, const char *tag); -SOAP_FMAC1 struct soap_dom_element * SOAP_FMAC2 soap_dom_next_element(struct soap_dom_element *elt); -SOAP_FMAC1 struct soap_dom_attribute * SOAP_FMAC2 soap_dom_next_attribute(struct soap_dom_attribute *att); -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -} -extern std::ostream &operator<<(std::ostream&, const struct soap_dom_element&); -extern std::istream &operator>>(std::istream&, struct soap_dom_element&); -extern "C" { -#endif - -/******************************************************************************/ - -struct soap -{ short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table) */ - short copy; /* 1 = copy of another soap struct */ - soap_mode mode; - soap_mode imode; - soap_mode omode; - const char *float_format; /* user-definable format string for floats (<1024 chars) */ - const char *double_format; /* user-definable format string for doubles (<1024 chars) */ - const char *dime_id_format; /* user-definable format string for integer DIME id ( 0, gives socket recv timeout in seconds, < 0 in usec */ - int send_timeout; /* when > 0, gives socket send timeout in seconds, < 0 in usec */ - int connect_timeout; /* when > 0, gives socket connect() timeout in seconds, < 0 in usec */ - int accept_timeout; /* when > 0, gives socket accept() timeout in seconds, < 0 in usec */ - int socket_flags; /* socket recv() and send() flags, e.g. set to MSG_NOSIGNAL to disable sigpipe */ - int connect_flags; /* connect() SOL_SOCKET sockopt flags, e.g. set to SO_DEBUG to debug socket */ - int bind_flags; /* bind() SOL_SOCKET sockopt flags, e.g. set to SO_REUSEADDR to enable reuse */ - int accept_flags; /* accept() SOL_SOCKET sockopt flags */ - const struct Namespace *namespaces; /* Pointer to global namespace mapping table */ - struct Namespace *local_namespaces; /* Local namespace mapping table */ - struct soap_nlist *nlist; /* namespace stack */ - struct soap_blist *blist; /* block allocation stack */ - struct soap_clist *clist; /* class instance allocation list */ - void *alist; /* memory allocation (malloc) list */ - struct soap_ilist *iht[SOAP_IDHASH]; - struct soap_plist *pht[SOAP_PTRHASH]; - struct soap_pblk *pblk; /* plist block allocation */ - short pidx; /* plist block allocation */ - struct SOAP_ENV__Header *header; - struct SOAP_ENV__Fault *fault; - int idnum; - void *user; /* to pass user-defined data */ - struct soap_plugin *plugins; /* linked list of plug-in data */ - char *userid; /* HTTP Basic authorization userid */ - char *passwd; /* HTTP Basic authorization passwd */ - int (*fpost)(struct soap*, const char*, const char*, int, const char*, const char*, size_t); - int (*fget)(struct soap*); - int (*fform)(struct soap*); - int (*fposthdr)(struct soap*, const char*, const char*); - int (*fresponse)(struct soap*, int, size_t); - int (*fparse)(struct soap*); - int (*fparsehdr)(struct soap*, const char*, const char*); - int (*fresolve)(struct soap*, const char*, struct in_addr* inaddr); - int (*fconnect)(struct soap*, const char*, const char*, int); - int (*fdisconnect)(struct soap*); - int (*fclosesocket)(struct soap*, SOAP_SOCKET); - int (*fshutdownsocket)(struct soap*, SOAP_SOCKET, int); - int (*fopen)(struct soap*, const char*, const char*, int); - int (*faccept)(struct soap*, int, struct sockaddr*, int *n); - int (*fclose)(struct soap*); - int (*fsend)(struct soap*, const char*, size_t); - size_t (*frecv)(struct soap*, char*, size_t); - int (*fpoll)(struct soap*); - void (*fseterror)(struct soap*, const char **c, const char **s); - int (*fignore)(struct soap*, const char*); - int (*fserveloop)(struct soap*); - void *(*fplugin)(struct soap*, const char*); -#ifndef WITH_LEANER - int (*fprepareinit)(struct soap*); - int (*fpreparesend)(struct soap*, const char*, size_t); - int (*fpreparerecv)(struct soap*, const char*, size_t); - int (*fpreparefinal)(struct soap*); - void *(*fdimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fdimewriteopen)(struct soap*, const char*, const char*, const char*); - void (*fdimereadclose)(struct soap*, void*); - void (*fdimewriteclose)(struct soap*, void*); - size_t (*fdimeread)(struct soap*, void*, char*, size_t); - int (*fdimewrite)(struct soap*, void*, const char*, size_t); -#endif - int master; - int socket; -#if defined(__cplusplus) && !defined(WITH_LEAN) - std::ostream *os; - std::istream *is; -#else - void *os; /* preserve alignment */ - void *is; /* preserve alignment */ -#endif -#ifndef UNDER_CE - int sendfd; - int recvfd; -#else - FILE *sendfd; - FILE *recvfd; -#endif -#ifdef WIN32 - char errorstr[256]; /* buf for FormatMessage() */ -#endif - size_t bufidx; /* index in soap.buf[] */ - size_t buflen; /* length of soap.buf[] content */ - soap_wchar ahead; /* parser lookahead */ - short cdata; /* CDATA parser state */ - short body; /* parsed XML element has a body or not */ - unsigned int level; /* XML nesting level */ - size_t count; /* message length counter */ - size_t length; /* message length as set by HTTP header */ -#ifdef WITH_FAST - char *labbuf; /* look-aside buffer */ - size_t lablen; /* look-aside buffer allocated length */ - size_t labidx; /* look-aside buffer index to available part */ -#endif - char buf[SOAP_BUFLEN];/* send and receive buffer */ - char tmpbuf[1024]; /* in/output buffer for HTTP headers, simpleType values, attribute names, and DIME >=1024 bytes */ - char msgbuf[1024]; /* output buffer for (error) messages <=1024 bytes */ - char tag[SOAP_TAGLEN]; - char id[SOAP_TAGLEN]; - char href[SOAP_TAGLEN]; - char type[SOAP_TAGLEN]; - char arrayType[SOAP_TAGLEN]; - char arraySize[SOAP_TAGLEN]; - char arrayOffset[SOAP_TAGLEN]; - short other; - short position; - int positions[SOAP_MAXDIMS]; - short root; - struct soap_attribute *attributes; /* attribute list */ - short encoding; /* when set, output encodingStyle */ - short mustUnderstand; /* a mustUnderstand element was parsed or is output */ - short keep_alive; /* connection should be kept open */ - short null; /* parsed XML is xsi:nil */ - short ns; /* when not set, output full xmlns bindings */ - short part; /* parsing state */ - short alloced; - short peeked; - size_t chunksize; - size_t chunkbuflen; - char endpoint[SOAP_TAGLEN]; - char path[SOAP_TAGLEN]; - char host[SOAP_TAGLEN]; - char *action; - char *authrealm; /* HTTP authentication realm */ - char *prolog; /* XML declaration prolog */ - unsigned long ip; /* IP number */ - int port; /* port number */ - unsigned int max_keep_alive; - const char *proxy_host; /* Proxy Server host name */ - int proxy_port; /* Proxy Server port (default = 8080) */ - const char *proxy_userid; /* Proxy Authorization user name */ - const char *proxy_passwd; /* Proxy Authorization password */ - int status; /* -1 when request, else error code to be returned by server */ - int error; - int errmode; - int errnum; -#ifndef WITH_LEANER - struct soap_dom_element *dom; - struct soap_dime dime; - struct soap_mime mime; - struct soap_xlist *xlist; -#endif -#if !defined(WITH_LEAN) || defined(SOAP_DEBUG) - const char *logfile[SOAP_MAXLOGS]; - FILE *fdebug[SOAP_MAXLOGS]; - struct soap_mlist *mht[SOAP_PTRHASH]; -#endif -#ifndef WITH_LEAN - const char *c14ninclude; - const char *c14nexclude; - struct soap_cookie *cookies; - const char *cookie_domain; - const char *cookie_path; - int cookie_max; -#endif -#ifndef WITH_NOIO -#ifdef WITH_IPV6 - struct sockaddr_storage peer; /* IPv6: set by soap_accept and by UDP recv */ -#else - struct sockaddr_in peer; /* IPv4: set by soap_connect/soap_accept and by UDP recv */ -#endif - size_t peerlen; -#endif -#ifdef WITH_OPENSSL - int (*fsslauth)(struct soap*); - int (*fsslverify)(int, X509_STORE_CTX*); - BIO *bio; - SSL *ssl; - SSL_CTX *ctx; - short require_server_auth; - short require_client_auth; - short rsa; /* when set, use RSA instead of DH */ - const char *keyfile; - const char *password; - const char *dhfile; - const char *cafile; - const char *capath; - const char *crlfile; - const char *randfile; - SSL_SESSION *session; - char session_host[SOAP_TAGLEN]; - int session_port; -#endif -#ifdef WITH_ZLIB - short zlib_state; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_INFLATE */ - short zlib_in; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - short zlib_out; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - z_stream d_stream; /* decompression stream */ - char z_buf[SOAP_BUFLEN]; /* buffer */ - size_t z_buflen; - unsigned short z_level; /* compression level to be used (0=none, 1=fast to 9=best) */ - uLong z_crc; /* internal gzip crc */ - float z_ratio_in; /* detected compression ratio compressed_length/length of inbound message */ - float z_ratio_out; /* detected compression ratio compressed_length/length of outbound message */ -#endif -/* WR[ */ -#ifdef WMW_RPM_IO - void *rpmreqid; -#endif /* WMW_RPM_IO */ -/* ]WR */ -}; - -struct soap_code_map -{ long code; - const char *string; -}; - -/* forwarding list */ -struct soap_flist -{ struct soap_flist *next; - int type; - void *ptr; - unsigned int level; - void (*fcopy)(struct soap*, int, int, void*, const void*, size_t); -}; - -/* id-ref forwarding list */ -struct soap_ilist -{ struct soap_ilist *next; - int type; - size_t size; - void *link; - void *copy; - struct soap_flist *flist; - void *ptr; - unsigned int level; - char id[1]; /* the actual id string value flows into the allocated region below this struct */ -}; - -struct soap_plugin -{ struct soap_plugin *next; - const char *id; - void *data; - int (*fcopy)(struct soap *soap, struct soap_plugin *dst, struct soap_plugin *src); - void (*fdelete)(struct soap *soap, struct soap_plugin *p); /* should delete fields of plugin only and not free(p) */ -}; - -#ifndef WITH_NONAMESPACES -extern SOAP_NMAC struct Namespace namespaces[]; -#endif - -#ifndef WITH_LEAN -# define soap_get0(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx]) -# define soap_get1(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx++]) -#else -soap_wchar soap_get0(struct soap*); -soap_wchar soap_get1(struct soap*); -#endif - -#define soap_revget1(soap) ((soap)->bufidx--) -#define soap_unget(soap, c) ((soap)->ahead = c) -#define soap_register_plugin(soap, plugin) soap_register_plugin_arg(soap, plugin, NULL) -#define soap_imode(soap, n) ((soap)->mode = (soap)->imode = (n)) -#define soap_set_imode(soap, n) ((soap)->imode |= (n)) -#define soap_clr_imode(soap, n) ((soap)->imode &= ~(n)) -#define soap_omode(soap, n) ((soap)->mode = (soap)->omode = (n)) -#define soap_set_omode(soap, n) ((soap)->omode |= (n)) -#define soap_clr_omode(soap, n) ((soap)->omode &= ~(n)) -#define soap_set_mode(soap, n) ((soap)->imode |= (n), (soap)->omode |= (n)) -#define soap_clr_mode(soap, n) ((soap)->imode &= ~(n), (soap)->omode &= ~(n)) -#define soap_destroy(soap) soap_delete((soap), NULL) - -#ifdef HAVE_STRRCHR -# define soap_strrchr(s, t) strrchr(s, t) -#else - SOAP_FMAC1 char* SOAP_FMAC2 soap_strrchr(const char *s, int t); -#endif - -#ifdef HAVE_STRTOL -# define soap_strtol(s, t, b) strtol(s, t, b) -#else - SOAP_FMAC1 long SOAP_FMAC2 soap_strtol(const char *s, char **t, int b); -#endif - -#ifdef HAVE_STRTOUL -# define soap_strtoul(s, t, b) strtoul(s, t, b) -#else - SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b); -#endif - -#if defined(WITH_OPENSSL) -# define soap_random soap_rand() -SOAP_FMAC1 int SOAP_FMAC2 soap_rand(); -#elif defined(HAVE_RANDOM) -# define soap_random (int)random() -#else -# define soap_random rand() -#endif - -#ifdef WITH_NOIDREF -# define soap_embedded(s, p, t) (0) -# define soap_id_lookup(s, i, p, t, n, k) (p) -# define soap_id_forward(s, h, p, st, tt, n, k, fc) (p) -# define soap_reference(s, a, t) (1) -# define soap_array_reference(s, p, a, n, t) (1) -# define soap_embed(s, p, a, n, t, pp) (0) -# define soap_embedded_id(s, i, p, t) (i) -# define soap_is_embedded(s, p) (0) -# define soap_is_single(s, p) (1) -# define soap_lookup_type(s, i) (0) -# define soap_getindependent(s) (0) -# define soap_putindependent(s) (0) -# define soap_getelement(s, n) (n) -# define soap_putelement(s, p, t, i, n) (0) -# define soap_markelement(s, p, n) (0) -#endif - -SOAP_FMAC1 void SOAP_FMAC2 soap_fault(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultsubcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultstring(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultdetail(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializefault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getfault(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_poll(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect_command(struct soap*, int, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_bind(struct soap*, const char*, int, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_accept(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_accept(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_puthttphdr(struct soap*, int status, size_t count); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_get_header_attribute(struct soap*, const char*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_key(char*, size_t, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_val(char*, size_t, const char*); - -SOAP_FMAC1 size_t SOAP_FMAC2 soap_hash(const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_endpoint(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_get(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getchar(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_tag_cmp(const char*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_sender_error(struct soap*, const char*, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_receiver_error(struct soap*, const char*, const char*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_raw(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send2(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send3(struct soap*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pututf8(struct soap*, unsigned long); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getutf8(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_putbase64(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_getbase64(struct soap*, int*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_puthex(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_gethex(struct soap*, int*); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_xop_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_dime_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -#endif - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup_id(struct soap*, void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup(struct soap*, const void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_enter(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_pointer_lookup(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -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); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_lookup(struct soap*, const char*); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_enter(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_resolve(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_embedded(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_reference(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_reference(struct soap*, const void *p, const struct soap_array *a, int n, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_embedded_id(struct soap*, int id, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_embedded(struct soap*, struct soap_plist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_single(struct soap*, struct soap_plist*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_embedded(struct soap*, struct soap_plist*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_send(struct soap*); - -SOAP_FMAC1 const struct soap_code_map* SOAP_FMAC2 soap_code(const struct soap_code_map*, const char *str); -SOAP_FMAC1 long SOAP_FMAC2 soap_int_code(const struct soap_code_map*, const char *str, long other); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_str_code(const struct soap_code_map*, long code); - -SOAP_FMAC1 int SOAP_FMAC2 soap_getline(struct soap*, char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_recv(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_malloc(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_dealloc(struct soap*, void*); -SOAP_FMAC1 struct soap_clist * SOAP_FMAC2 soap_link(struct soap*, void*, int, int, void (*fdelete)(struct soap_clist*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_unlink(struct soap*, const void*); -SOAP_FMAC1 void SOAP_FMAC2 soap_free(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_track_malloc(struct soap*, const char*, int, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_track_free(struct soap*, const char*, int, void*); - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_lookup_type(struct soap*, const char *id); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_lookup(struct soap*, const char *id, void **p, int t, size_t n, unsigned int k); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_forward(struct soap*, const char *id, void *p, int st, int tt, size_t n, unsigned int k, void(*fcopy)(struct soap*, int, int, void*, const void*, size_t)); -#endif -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_enter(struct 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*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_fcopy(struct soap *soap, int st, int tt, void *p, const void *q, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_size(const int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getoffsets(const char *, const int *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsize(const char *, const char *, int *); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsizes(const char *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getposition(const char *, int *); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsize(struct soap*, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizesoffsets(struct soap*, const char *, const int *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizes(struct soap*, const char *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffset(struct soap*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffsets(struct soap*, const int *, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_closesock(struct soap*); - -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new(void); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new1(soap_mode); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new2(soap_mode, soap_mode); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*,struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init1(struct soap*, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_init2(struct soap*, soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_end(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_delete(struct soap*, void*); - -#ifdef SOAP_DEBUG -SOAP_FMAC1 void SOAP_FMAC2 soap_set_recv_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_sent_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_test_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_close_logfiles(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_open_logfile(struct soap*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_token(struct soap*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_value(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_tag(struct soap*, const char*, const char *); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_array(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element(struct soap*, const char*, int, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_out(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_begin_out(struct soap*, const char *tag, int id, const char *type, const char *offset); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_ref(struct soap*, const char *tag, int id, int href); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_href(struct soap*, const char *tag, int id, const char *ref, const char *val); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_null(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_id(struct soap*, const char *tag, int id, const void *p, const struct soap_array *a, int d, const char *type, int n); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_result(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_out(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_start_end_out(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_attribute(struct soap*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_in(struct soap*, const char *tag, int nillable); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_in(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_peek_element(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_retry(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_revert(struct soap*); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_strdup(struct soap*, const char*); -SOAP_FMAC1 const char * SOAP_FMAC2 soap_strsearch(const char *big, const char *little); - -SOAP_FMAC1 int SOAP_FMAC2 soap_string_out(struct soap*, const char *s, int flag); -SOAP_FMAC1 char* SOAP_FMAC2 soap_string_in(struct soap*, int, long, long); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_wstring_out(struct soap*, const wchar_t *s, int flag); -SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstring_in(struct soap*, int, long, long); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_namespace(struct soap*, const char *, const char*, int n1, int n2); - -SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap*, struct Namespace*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_local_namespaces(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_namespace(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_push_namespace(struct soap*, const char *,const char *); - -SOAP_FMAC1 int SOAP_FMAC2 soap_store_lab(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_append_lab(struct soap*, const char*, size_t); - -SOAP_FMAC1 int SOAP_FMAC2 soap_new_block(struct soap*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_push_block(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_size_block(struct soap*, size_t); -SOAP_FMAC1 char* SOAP_FMAC2 soap_first_block(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_next_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_block_size(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_save_block(struct soap*, char*, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*); -SOAP_FMAC1 int soap_envelope_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_out(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_header(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_response(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_empty_response(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_empty_response(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_fault(struct soap*); - -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap*, FILE*); -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault_location(struct soap*, FILE*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_s2byte(struct soap*, const char*, char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2short(struct soap*, const char*, short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2int(struct soap*, const char*, int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2long(struct soap*, const char*, long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2LONG64(struct soap*, const char*, LONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2float(struct soap*, const char*, float*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2double(struct soap*, const char*, double*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedByte(struct soap*, const char*, unsigned char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedShort(struct soap*, const char*, unsigned short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedInt(struct soap*, const char*, unsigned int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedLong(struct soap*, const char*, unsigned long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2ULONG64(struct soap*, const char*, ULONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2string(struct soap*, const char*, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2QName(struct soap*, const char*, char**); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_s2dateTime(struct soap*, const char*, time_t*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2base64(struct soap*, const unsigned char*, char*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2hex(struct soap*, const unsigned char*, char*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_byte2s(struct soap*, char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_short2s(struct soap*, short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_int2s(struct soap*, int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_long2s(struct soap*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_LONG642s(struct soap*, LONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_float2s(struct soap*, float); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_double2s(struct soap*, double); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedByte2s(struct soap*, unsigned char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedShort2s(struct soap*, unsigned short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedInt2s(struct soap*, unsigned int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedLong2s(struct soap*, unsigned long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_ULONG642s(struct soap*, ULONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_QName2s(struct soap*, const char*); - -#ifndef WITH_LEAN -SOAP_FMAC1 const char* SOAP_FMAC2 soap_dateTime2s(struct soap*, time_t); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_base642s(struct soap*, const char*, char*, size_t, int*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_hex2s(struct soap*, const char*, char*, size_t, int*); -#endif - - -SOAP_FMAC1 int* SOAP_FMAC2 soap_inint(struct soap*, const char *tag, int *p, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_inbyte(struct soap*, const char *tag, char *p, const char *, int); -SOAP_FMAC1 long* SOAP_FMAC2 soap_inlong(struct soap*, const char *tag, long *p, const char *, int); -SOAP_FMAC1 LONG64* SOAP_FMAC2 soap_inLONG64(struct soap*, const char *tag, LONG64 *p, const char *, int); -SOAP_FMAC1 short* SOAP_FMAC2 soap_inshort(struct soap*, const char *tag, short *p, const char *, int); -SOAP_FMAC1 float* SOAP_FMAC2 soap_infloat(struct soap*, const char *tag, float *p, const char *, int); -SOAP_FMAC1 double* SOAP_FMAC2 soap_indouble(struct soap*, const char *tag, double *p, const char *, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_inunsignedByte(struct soap*, const char *tag, unsigned char *p, const char *, int); -SOAP_FMAC1 unsigned short* SOAP_FMAC2 soap_inunsignedShort(struct soap*, const char *tag, unsigned short *p, const char *, int); -SOAP_FMAC1 unsigned int* SOAP_FMAC2 soap_inunsignedInt(struct soap*, const char *tag, unsigned int *p, const char *, int); -SOAP_FMAC1 unsigned long* SOAP_FMAC2 soap_inunsignedLong(struct soap*, const char *tag, unsigned long *p, const char *, int); -SOAP_FMAC1 ULONG64* SOAP_FMAC2 soap_inULONG64(struct soap*, const char *tag, ULONG64 *p, const char *, int); -SOAP_FMAC1 char** SOAP_FMAC2 soap_instring(struct soap*, const char *tag, char **p, const char *, int, int, long, long); -SOAP_FMAC1 char** SOAP_FMAC2 soap_inliteral(struct soap*, const char *tag, char **p); - -#ifndef WITH_LEAN -SOAP_FMAC1 time_t* SOAP_FMAC2 soap_indateTime(struct soap*, const char *tag, time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwstring(struct soap*, const char *tag, wchar_t **p, const char *, int, long, long); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwliteral(struct soap*, const char *tag, wchar_t **p); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_outbyte(struct soap*, const char *tag, int id, const char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outshort(struct soap*, const char *tag, int id, const short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outint(struct soap*, const char *tag, int id, const int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outlong(struct soap*, const char *tag, int id, const long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outLONG64(struct soap*, const char *tag, int id, const LONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outfloat(struct soap*, const char *tag, int id, const float *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdouble(struct soap*, const char *tag, int id, const double *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedByte(struct soap*, const char *tag, int id, const unsigned char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedShort(struct soap*, const char *tag, int id, const unsigned short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedInt(struct soap*, const char *tag, int id, const unsigned int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedLong(struct soap*, const char *tag, int id, const unsigned long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outULONG64(struct soap*, const char *tag, int id, const ULONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outstring(struct soap*, const char *tag, int id, char *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outliteral(struct soap*, const char *tag, char *const*p); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_outdateTime(struct soap*, const char *tag, int id, const time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_outwstring(struct soap*, const char *tag, int id, wchar_t *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwliteral(struct soap*, const char *tag, wchar_t *const*p); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_attachment(struct soap *, const char*, int, const void*, const struct soap_array*, const char*, const char*, const char*, int, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, long); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_tell(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_dime_option(struct soap*, unsigned short, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmimehdr(struct soap*, struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_mime(struct soap*, const char *boundary, const char *start); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_mime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_dime_attachment(struct soap*, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_mime_attachment(struct soap*, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_register_plugin_arg(struct soap*, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_lookup_plugin(struct soap*, const char*); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_attr_value(struct soap *soap, const char *name, int flag); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_attr(struct soap *soap, const char *name, const char *value); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_attr(struct soap *soap); - -#ifdef WITH_COOKIES -SOAP_FMAC1 size_t SOAP_FMAC2 soap_encode_cookie(const char*, char*, size_t); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_set_cookie(struct soap*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_env_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern long SOAP_FMAC2 soap_cookie_expire(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_expire(struct soap*, const char*, long, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_clr_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_clr_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_getenv_cookies(struct soap*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_copy_cookies(struct soap*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_free_cookies(struct soap*); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.c b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.c deleted file mode 100644 index 461bea7..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.c +++ /dev/null @@ -1,13362 +0,0 @@ -/* - -stdsoap2.c[pp] 2.7.6d - -gSOAP runtime - -gSOAP XML Web services tools -Copyright (C) 2000-2005, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under one of the following licenses: -GPL, the gSOAP public license, or Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems Inc., for the following additions under gSOAP public license: - - vxWorks compatible (#define VXWORKS) --------------------------------------------------------------------------------- -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-2005, 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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- - -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. - -*/ - -#ifdef AS400 -# pragma convert(819) /* EBCDIC to ASCII */ -#endif - -#include "stdsoap2.h" - -#ifdef __cplusplus -SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.7.6d 2005-12-29 12:00:00 GMT") -extern "C" { -#else -SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.7.6d 2005-12-29 12:00:00 GMT") -#endif - -/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale with multibyte support enabled) */ -#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_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)) - -#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*); -static void soap_free_mht(struct soap*); -static void soap_track_unlink(struct soap*, const void*); -#endif - -#ifndef PALM_2 -static int soap_set_error(struct soap*, const char*, const char*, const char*, const char*, int); -static int soap_copy_fault(struct soap*, const char*, const char*, const char*, const char*); -static int soap_getattrval(struct soap*, char*, size_t, soap_wchar); -#endif - -#ifndef PALM_1 -static soap_wchar soap_char(struct soap*); -static soap_wchar soap_get_pi(struct soap*); -static int soap_isxdigit(int); -static void *fplugin(struct soap*, const char*); -#ifndef WITH_NOIDREF -static void soap_update_ptrs(struct soap*, char*, char*, long); -static int soap_has_copies(struct soap*, const char*, 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*); -#endif -#endif - -#ifndef WITH_LEAN -static const char *soap_set_validation_fault(struct soap*, const char*, const char*); -static int soap_isnumeric(struct soap*, const char*); -static time_t soap_timegm(struct tm*); -static struct soap_nlist *soap_lookup_ns(struct soap *soap, const char *tag, size_t n); -static struct soap_nlist *soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized); -static void soap_pop_ns(struct soap *soap); -static void soap_utilize_ns(struct soap *soap, const char *tag, size_t n); -#endif - -#ifndef WITH_LEANER -#ifndef PALM_1 -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*); -static int soap_match_cid(struct soap*, const char*, const char*); -static void soap_resolve_attachment(struct soap*, struct soap_multipart*); -#endif -#endif - -#ifdef WITH_GZIP -static int soap_getgziphdr(struct soap*); -#endif - -#ifdef WITH_OPENSSL -static void ssl_init(); -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 - -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#ifndef PALM_1 -static const char *soap_decode(char*, size_t, const char*, const char*); -#endif -#endif - -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static soap_wchar soap_getchunkchar(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*); -#endif -#endif - -#ifndef WITH_NOIO -#ifndef PALM_1 -static int fsend(struct soap*, const char*, size_t); -static size_t frecv(struct soap*, char*, size_t); -static int tcp_init(struct soap*); -static const char *tcp_error(struct soap*); -#ifndef WITH_IPV6 -static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr); -#endif -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 const char *soap_strerror(struct soap*); -#endif -#endif - -#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 - -#ifndef WITH_LEAN -static const char soap_indent[11] = "\n\t\t\t\t\t\t\t\t\t"; -/* Alternative indentation form for SOAP_XML_INDENT: -static const char soap_indent[21] = "\n "; -*/ -#endif - -static const char soap_padding[4] = "\0\0\0"; -#define SOAP_STR_PADDING (soap_padding) -#define SOAP_STR_EOS (soap_padding) -#define SOAP_NON_NULL (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_NOIO -#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 -#endif - -#ifndef WITH_NOHTTP -#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 -#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 WITH_NOIO -#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_socket_errno != SOAP_EAGAIN) - { soap->errnum = soap_socket_errno; - return SOAP_EOF; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - nwritten = SSL_write(soap->ssl, s, n); - else if (soap->bio) - nwritten = BIO_write(soap->bio, s, n); - else -#endif -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - { if (soap->peerlen) - nwritten = sendto((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, soap->peerlen); - else - nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); - /* retry and back-off algorithm */ - /* TODO: this is not very clear from specs so verify and limit conditions under which we should loop (e.g. ENOBUFS) */ - if (nwritten < 0) - { struct timeval timeout; - fd_set fd; - int udp_repeat; - int udp_delay; - if ((soap->connect_flags & SO_BROADCAST)) - udp_repeat = 3; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */ - else - udp_repeat = 1; /* SOAP-over-UDP UNICAST_UDP_REPEAT - 1 */ - udp_delay = (soap_random % 201) + 50; /* UDP_MIN_DELAY .. UDP_MAX_DELAY */ - do - { timeout.tv_sec = 0; - timeout.tv_usec = 1000 * udp_delay; /* ms */ - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); - select((SOAP_SOCKET)(soap->socket + 1), NULL, NULL, &fd, &timeout); - if (soap->peerlen) - nwritten = sendto((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, soap->peerlen); - else - nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); - udp_delay <<= 1; - if (udp_delay > 500) /* UDP_UPPER_DELAY */ - udp_delay = 500; - } - while (nwritten < 0 && --udp_repeat > 0); - } - } - else -#endif -#if !defined(PALM) && !defined(AS400) - 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 -#ifdef VXWORKS -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - nwritten = (httpBlockPut(soap->rpmreqid, s, n) == 0) ? n : -1; - else -#endif - nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w")); -#else - nwritten = write((SOAP_SOCKET)soap->sendfd, s, n); -#endif -#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_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; -#ifndef WITH_LEANER - if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - 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_flush(struct soap *soap) -{ register int n = soap->bufidx; - if (n) - { soap->bufidx = 0; -#ifdef WITH_ZLIB - if (soap->mode & SOAP_ENC_ZLIB) - { soap->d_stream.next_in = (Byte*)soap->buf; - soap->d_stream.avail_in = (unsigned int)n; -#ifdef WITH_GZIP - soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)n); -#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 - return soap_flush_raw(soap, soap->buf, n); - } - return SOAP_OK; -} -#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); -#ifndef WITH_LEANER - if (soap->fpreparesend) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - return SOAP_OK; - } -#ifndef WITH_LEANER - 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); -#endif - return soap->error = soap->fsend(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 WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 - if (soap->recv_timeout) - { struct timeval timeout; - fd_set fd; - 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) - { soap->errnum = 0; - return 0; - } - if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN) - { soap->errnum = soap_socket_errno; - return 0; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - { int err; - r = SSL_read(soap->ssl, s, n); - if (r > 0) - return (size_t)r; - err = SSL_get_error(soap->ssl, r); - if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE) - return 0; - } - else if (soap->bio) - { r = BIO_read(soap->bio, s, n); - if (r > 0) - return (size_t)r; - return 0; - } - else -#endif - { -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - { SOAP_SOCKLEN_T k = (SOAP_SOCKLEN_T)sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - r = recvfrom((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, &k); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - soap->peerlen = (size_t)k; -#ifndef WITH_IPV6 - soap->ip = ntohl(soap->peer.sin_addr.s_addr); - soap->port = (int)ntohs(soap->peer.sin_port); -#endif - } - 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_socket_errno != SOAP_EWOULDBLOCK) - { 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); -#ifdef WITH_OPENSSL - if (soap->ssl && SSL_get_error(soap->ssl, r) == SSL_ERROR_WANT_WRITE) - r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); - else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#endif - 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 -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - r = httpBlockRead(soap->rpmreqid, s, n); - else -#endif - r = read((SOAP_SOCKET)soap->recvfd, s, n); - if (r >= 0) - return (size_t)r; - soap->errnum = soap_errno; - return 0; -#endif -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 from socket %d\n", (unsigned int)soap->buflen, soap->socket)); - DBGMSG(RECV, soap->buf, soap->buflen); - if (soap->buflen) - return soap->buf[soap->bufidx++]; - return EOF; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -static int -soap_isxdigit(int c) -{ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); -} -#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; - soap->error = SOAP_ZLIB_ERROR; - 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 -#ifndef WITH_NOHTTP - 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 (chunked) from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - soap->bufidx = 0; - if (!ret) - return soap->ahead = EOF; - } - else - soap->bufidx = soap->buflen; - soap->buflen = soap->chunkbuflen; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (idx=%u len=%u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen)); - while (!soap_isxdigit((int)(c = soap_getchunkchar(soap)))) - if ((int)c == EOF) - return soap->ahead = 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 soap->ahead = 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 soap->ahead = EOF; - } - soap->buflen = soap->bufidx + soap->chunksize; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to idx=%u len=%u (%s)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen, 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 (%u bytes left)\n", (unsigned int)(soap->buflen - soap->bufidx))); - } - else if (soap->chunkbuflen) - soap->chunksize = 0; - ret = soap->buflen - soap->bufidx; - if (!ret) - goto chunk_again; - } - } - else -#endif - { soap->bufidx = 0; - soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - } -#ifndef WITH_LEANER - if (soap->fpreparerecv && (soap->error = soap->fpreparerecv(soap, soap->buf, ret))) - return soap->error; -#endif -#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; - soap->error = SOAP_ZLIB_ERROR; - 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; - c = soap->ahead; - if (c) - { if (c != EOF) - 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) -{ if (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 - -/******************************************************************************/ -#ifdef WITH_LEAN -soap_wchar -soap_get0(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx]; -} -#endif - -/******************************************************************************/ -#ifdef WITH_LEAN -soap_wchar -soap_get1(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx++]; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -soap_wchar -SOAP_FMAC2 -soap_get(struct soap *soap) -{ register soap_wchar c; - c = soap->ahead; - if (c) - { if (c != EOF) - 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 == '%') - { register int k = 1; - 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); - } - } - else if (c == '?') - c = soap_get_pi(soap); - while ((int)c != EOF) - { if (c == '<') - k++; - else if (c == '>') - { if (--k <= 0) - break; - } - 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 -static soap_wchar -soap_get_pi(struct soap *soap) -{ char buf[64]; - register char *s = buf; - register int i = sizeof(buf); - register soap_wchar c = soap_getchar(soap); - /* This is a quick way to parse XML PI and we could use a callback instead to - * enable applications to intercept processing instructions */ - while ((int)c != EOF && c != '?') - { if (--i > 0) - { if (soap_blank(c)) - c = ' '; - *s++ = (char)c; - } - c = soap_getchar(soap); - } - *s = '\0'; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI \n", buf)); - if (!strncmp(buf, "xml ", 4)) - { s = strstr(buf, " encoding="); - if (s && s[10]) - { if (!soap_tag_cmp(s + 11, "iso-8859-1*") - || !soap_tag_cmp(s + 11, "latin1*")) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to latin1 encoding\n")); - soap->mode |= SOAP_ENC_LATIN; - } - else if (!soap_tag_cmp(s + 11, "utf-8*")) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to utf-8 encoding\n")); - soap->mode &= ~SOAP_ENC_LATIN; - } - } - } - if ((int)c != EOF) - c = soap_getchar(soap); - 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->ahead; - if (c > 0xFF) - { soap->ahead = 0; - return c; - } -again: - c = soap_get(soap); - if (c < 0x80 || (soap->mode & SOAP_ENC_LATIN)) - return c; - c1 = soap_get1(soap); - if (c1 < 0x80) - { soap_revget1(soap); /* doesn't look like this is UTF8 */ - return c; - } - c1 &= 0x3F; - if (c < 0xE0) - return ((soap_wchar)(c & 0x1F) << 6) | c1; - c2 = (soap_wchar)soap_get1(soap) & 0x3F; - if (c == 0xEF && c1 == 0x3B && c2 == 0x3F) /* ignore UTF-8 BOM */ - goto again; - 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) -{ char d[2]; - register int i; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!(soap->dom->data = soap_s2hex(soap, s, NULL, n))) - return soap->error; - return SOAP_OK; - } -#endif - 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_hex2s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#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, NULL, 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_base642s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#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 = soap->lablen - soap->labidx; - soap->labidx = 3 * (soap->lablen / 3); - if (!s) - return NULL; - for (i = 0; i < k - 2; 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 WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_xop_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ /* Check MTOM xop:Include element (within hex/base64Binary) */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - int body = soap->body; /* should save type too? */ - if (!soap_peek_element(soap)) - { if (!soap_element_begin_in(soap, "xop:Include", 0) && *soap->href) - { if (soap_dime_forward(soap, ptr, size, id, type, options)) - return soap->error; - } - if (soap->body && soap_element_end_in(soap, NULL)) - return soap->error; - } - soap->body = body; - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_dime_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ struct soap_xlist *xp = (struct soap_xlist*)SOAP_MALLOC(soap, sizeof(struct soap_xlist)); - *ptr = NULL; - *size = 0; - *id = soap_strdup(soap, soap->href); - *type = NULL; - *options = NULL; - if (!xp) - return soap->error = SOAP_EOM; - xp->next = soap->xlist; - xp->ptr = ptr; - xp->size = size; - xp->id = *id; - xp->type = type; - xp->options = options; - soap->xlist = xp; - return SOAP_OK; -} -#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(soap, 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(soap, 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(soap, p); -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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; -#ifndef WITH_LEANER - register struct soap_xlist *xp; -#endif - 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; - } - } - } - } -#ifndef WITH_LEANER - for (xp = soap->xlist; xp; xp = xp->next) - { if (xp->ptr && (char*)xp->ptr >= start && (char*)xp->ptr < end) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", xp->id?xp->id:"", xp->ptr, (char*)xp->ptr + offset)); - xp->ptr = (unsigned char**)((char*)xp->ptr + offset); - xp->size = (int*)((char*)xp->size + offset); - xp->type = (char**)((char*)xp->type + offset); - xp->options = (char**)((char*)xp->options + offset); - } - } -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, 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 -#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(soap, 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(soap, p); - } - soap->blist = bp->next; - SOAP_FREE(soap, 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); -#ifndef WITH_NOIDREF - if (flag) - soap_update_ptrs(soap, q, q + n, (long)s - (long)q); /* pointers s and q may or may not be related */ -#endif - 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; - if (*attr1 == '[') - attr1++; - n = 1; - for (;;) - { 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; - } - if (!attr1) - break; - 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; - register short i = -1; - register size_t n, k; - n = strlen(id); - k = strlen(ns) + 1; - p = soap->local_namespaces; - if (p) - { for (i = 0; p->id; p++, i++) - { if (p->ns && !strcmp(ns, p->ns)) - { if (p->out) - { SOAP_FREE(soap, p->out); - p->out = NULL; - } - break; - } - if (p->out) - { if (!strcmp(ns, p->out)) - break; - } - else if (p->in) - { if (!soap_tag_cmp(ns, p->in)) - { if ((p->out = (char*)SOAP_MALLOC(soap, k))) - strcpy(p->out, ns); - break; - } - } - } - if (!p || !p->id) - i = -1; - } - if (i >= 0) - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k); - if (!np) - return soap->error = SOAP_EOM; - np->next = soap->nlist; - soap->nlist = np; - np->level = soap->level; - np->index = i; - strcpy(np->id, id); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns)); - if (i < 0) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns)); - } - else - { np->ns = NULL; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id)); - } - 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)); - SOAP_FREE(soap, 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 - || (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_current_namespace(struct soap *soap, const char *tag) -{ register struct soap_nlist *np; - register const char *s; - np = soap->nlist; - if (!(s = strchr(tag, ':'))) - { while (np && *np->id) /* find default namespace, if present */ - np = np->next; - } - else - { while (np && (strncmp(np->id, tag, s - tag) || np->id[s - tag])) - np = np->next; - if (!np) - soap->error = SOAP_NAMESPACE; - } - if (np) - { if (np->index >= 0) - return soap->namespaces[np->index].ns; - if (np->ns) - return soap_strdup(soap, np->ns); - } - return NULL; -} -#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 && !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_rand() -{ unsigned char buf[4]; - ssl_init(); - RAND_pseudo_bytes(buf, 4); - return *(int*)buf; -} -#endif - -/******************************************************************************/ -#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)) - { char buf[1024]; - RAND_seed(buf, sizeof(buf)); - while (!RAND_status()) - { int r = rand(); - 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 directory", SOAP_SSL_ERROR); - if (soap->cafile && soap->require_client_auth) - SSL_CTX_set_client_CA_list(soap->ctx, SSL_load_client_CA_file(soap->cafile)); - } - 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); -/* See below */ - 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); - } -/* Suggested alternative approach to check cafile first before the key file: - 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 (!soap->cafile || !SSL_CTX_use_certificate_chain_file(soap->ctx, soap->cafile)) - { 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 or key file", SOAP_SSL_ERROR); - 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(1024, 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 or warning 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 - /* Note: return 1 to 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) -{ BIO *bio; - 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->ctx && (soap->error = soap->fsslauth(soap))) - return SOAP_INVALID_SOCKET; - 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; -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)&nonblocking); - } -#else - fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)|O_NONBLOCK); -#endif - bio = BIO_new_socket((SOAP_SOCKET)soap->socket, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, 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; - } - } -#if defined(WIN32) - { u_long blocking = 0; - ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)&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 WITH_NOIO -#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 -#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, 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, soap->plugins); - soap->plugins = p; - } - soap->fplugin = fplugin; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; -#endif - soap->fseterror = 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 - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free logfiles\n")); - for (i = 0; i < SOAP_MAXLOGS; i++) - { if (soap->logfile[i]) - { SOAP_FREE(soap, (void*)soap->logfile[i]); - soap->logfile[i] = NULL; - } - soap_close_logfile(soap, i); - } - soap_free_mht(soap); -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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/UDP IP error %d", soap->errnum); - msg = soap->msgbuf; - } - } - } - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static const char* -http_error(struct soap *soap, int status) -{ register const char *msg = SOAP_STR_EOS; -#ifndef WITH_LEAN - msg = soap_str_code(h_http_error_codes, status); - if (!msg) - msg = SOAP_STR_EOS; -#endif - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_IPV6 -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr) -{ soap_int32 iadd = -1; - struct hostent hostent, *host = &hostent; -#ifdef VXWORKS - int hostint; - /* inet_addr(), and hostGetByName() expect "char *"; addr is a "const char *". */ - iadd = inet_addr((char*)addr); -#else -#if defined(_AIXVERSION_431) || defined(TRU64) - struct hostent_data ht_data; -#endif -#ifdef AS400 - iadd = inet_addr((void*)addr); -#else - iadd = inet_addr(addr); -#endif -#endif - if (iadd != -1) - { memcpy(inaddr, &iadd, sizeof(iadd)); - 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); -#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((char*)addr); - if (hostint == ERROR) - { host = NULL; - soap->errnum = soap_errno; - } -#else -#ifdef AS400 - if (!(host = gethostbyname((void*)addr))) - soap->errnum = h_errno; -#else - if (!(host = gethostbyname(addr))) - soap->errnum = h_errno; -#endif -#endif - if (!host) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Host name not found\n")); - return SOAP_ERR; - } -#ifdef VXWORKS - inaddr->s_addr = hostint; -#else - memcpy(inaddr, host->h_addr, host->h_length); -#endif - return SOAP_OK; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port) -{ -#ifdef WITH_IPV6 - struct addrinfo hints, *res, *ressave; - int err; -#endif - 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->errnum = 0; - soap_set_sender_error(soap, tcp_error(soap), "TCP init failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->errmode = 0; -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - soap->errmode = 2; - if (soap->proxy_host) - err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &res); - else - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &res); - if (err) - { soap_set_sender_error(soap, gai_strerror(err), "getaddrinfo failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - ressave = res; -again: - fd = (int)socket(res->ai_family, res->ai_socktype, res->ai_protocol); - soap->errmode = 0; -#else -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - fd = (int)socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - fd = (int)socket(AF_INET, SOCK_STREAM, 0); -#endif - if (fd < 0) - { soap->errnum = soap_socket_errno; - soap_set_sender_error(soap, tcp_error(soap), "socket failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#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), "setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - 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), "setsockopt failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && 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), "setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } -#endif -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket %d to host='%s' port=%d\n", fd, host, port)); -#ifndef WITH_IPV6 - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (soap->proxy_host) - { if (soap->fresolve(soap, soap->proxy_host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)soap->proxy_port); - } - else - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)port); - } - soap->errmode = 0; - if ((soap->omode & SOAP_IO_UDP)) - return fd; -#endif -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&nonblocking)); /* modified to use fd */ - } -#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); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK); -#endif -#endif - for (;;) - { -#ifdef WITH_IPV6 - if (connect((SOAP_SOCKET)fd, res->ai_addr, res->ai_addrlen)) -#else - if (connect((SOAP_SOCKET)fd, (struct sockaddr*)&soap->peer, sizeof(soap->peer))) -#endif - { -#ifndef WITH_LEAN - if (soap->connect_timeout && (soap_socket_errno == SOAP_EINPROGRESS || soap_socket_errno == SOAP_EWOULDBLOCK)) - { struct timeval timeout; - SOAP_SOCKLEN_T k; - 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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - k = (SOAP_SOCKLEN_T)sizeof(soap->errnum); - if (!getsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &k) && !soap->errnum) /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - break; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - soap->errnum = soap_socket_errno; - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - else -#endif -#ifdef WITH_IPV6 - if (res->ai_next) - { res = res->ai_next; - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - goto again; - } - 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), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - else - break; - } -#ifdef WITH_IPV6 - soap->peerlen = 0; /* IPv6: already connected so use send() */ - freeaddrinfo(ressave); -#endif -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long blocking = 0; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK); -#endif -#endif - soap->socket = fd; - soap->imode &= ~SOAP_ENC_SSL; - soap->omode &= ~SOAP_ENC_SSL; - if (!strncmp(endpoint, "https:", 6)) - { -#ifdef WITH_OPENSSL - BIO *bio; - int r; - if (soap->proxy_host) - { short v; - unsigned int k = soap->omode; /* make sure we only parse HTTP */ - size_t n = soap->count; /* save the content length */ - char *userid, *passwd; - soap->omode &= ~SOAP_ENC; /* 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))) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } -#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))) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return soap->error; - } - } -#endif - if ((soap->error = soap->fposthdr(soap, NULL, NULL)) - || soap_flush(soap)) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->omode = k; - k = soap->imode; - soap->imode &= ~SOAP_ENC; /* mask IO and ENC */ - v = soap->version; /* preserve */ - userid = soap->userid; /* preserve */ - passwd = soap->passwd; /* preserve */ - if (soap_begin_recv(soap)) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->userid = userid; /* restore */ - soap->passwd = passwd; /* restore */ - soap->version = v; /* restore */ - soap->imode = k; /* restore */ - soap->count = n; /* restore */ - 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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->ssl = SSL_new(soap->ctx); - if (!soap->ssl) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; - } - 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; - bio = BIO_new_socket((SOAP_SOCKET)fd, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, bio); -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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)fd, &fds); - for (;;) - { int r = select((SOAP_SOCKET)(fd + 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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - continue; - } - } - break; - } -#ifndef WITH_LEAN - if (soap->connect_timeout) -#ifdef WIN32 - { u_long blocking = 0; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } -#else - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; -#endif - } - return fd; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_bind(struct soap *soap, const char *host, int port, int backlog) -{ -#ifdef WITH_IPV6 - struct addrinfo *addrinfo = NULL; - struct addrinfo hints; - struct addrinfo res; - int err; -#endif -#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 SOAP_INVALID_SOCKET; - } -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - soap->errmode = 2; - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo); - if (addrinfo) - { res = *addrinfo; - soap->peer = *((struct sockaddr_storage*)addrinfo->ai_addr); - soap->peerlen = addrinfo->ai_addrlen; - res.ai_addr = (struct sockaddr*)&soap->peer; - res.ai_addrlen = soap->peerlen; - freeaddrinfo(addrinfo); - } - if (err) - { soap_set_receiver_error(soap, gai_strerror(err), "getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->master = socket(res.ai_family, res.ai_socktype, res.ai_protocol); -#else -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - soap->master = (int)socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - soap->master = (int)socket(AF_INET, SOCK_STREAM, 0); -#endif - soap->errmode = 0; - if (!soap_valid_socket(soap->master)) - { soap->errnum = soap_socket_errno; - soap_set_receiver_error(soap, tcp_error(soap), "socket failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - soap->socket = soap->master; -#endif -#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), "setsockopt failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && 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), "setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && 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), "setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif -#endif -#ifdef WITH_IPV6 - soap->errmode = 0; - if (bind((SOAP_SOCKET)soap->master, res.ai_addr, res.ai_addrlen)) - { 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), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#else - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (host) - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_receiver_error(soap, tcp_error(soap), "get host by name failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } - else - soap->peer.sin_addr.s_addr = htonl(INADDR_ANY); - soap->peer.sin_port = htons((short)port); - soap->errmode = 0; - if (bind((SOAP_SOCKET)soap->master, (struct sockaddr*)&soap->peer, soap->peerlen)) - { 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), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif - if (!(soap->omode & SOAP_IO_UDP) && 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), "listen failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - return soap->master; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_poll(struct soap *soap) -{ -#ifndef WITH_LEAN - struct timeval timeout; - fd_set rfd, sfd, xfd; - int r; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_ZERO(&xfd); - if (soap_valid_socket(soap->socket)) - { FD_SET((SOAP_SOCKET)soap->socket, &rfd); - FD_SET((SOAP_SOCKET)soap->socket, &sfd); - FD_SET((SOAP_SOCKET)soap->socket, &xfd); - r = select((SOAP_SOCKET)(soap->socket + 1), &rfd, &sfd, &xfd, &timeout); - if (r > 0 && FD_ISSET((SOAP_SOCKET)soap->socket, &xfd)) - r = -1; - } - else if (soap_valid_socket(soap->master)) - { FD_SET((SOAP_SOCKET)soap->master, &sfd); - r = select((SOAP_SOCKET)(soap->master + 1), NULL, &sfd, NULL, &timeout); - } - else - return SOAP_OK; - if (r > 0) - { -#ifdef WITH_OPENSSL - if (soap->imode & SOAP_ENC_SSL) - { - if (soap_valid_socket(soap->socket) - && FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - && (!FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - || SSL_peek(soap->ssl, soap->tmpbuf, 1) > 0)) - return SOAP_OK; - } - else -#endif - if (soap_valid_socket(soap->socket) - && FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - && (!FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - || recv((SOAP_SOCKET)soap->socket, soap->tmpbuf, 1, MSG_PEEK) > 0)) - return SOAP_OK; - } - else if (r < 0) - { soap->errnum = soap_socket_errno; - if ((soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno != SOAP_EINTR) - { 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 = 0; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Polling: other end down on socket=%d select=%d\n", soap->socket, r)); - return SOAP_EOF; -#else - return SOAP_OK; -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_accept(struct soap *soap, int s, struct sockaddr *a, int *n) -{ int fd; - fd = (int)accept((SOAP_SOCKET)s, a, (SOAP_SOCKLEN_T*)n); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ -#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 WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_accept(struct soap *soap) -{ int n = (int)sizeof(soap->peer); -#ifndef WITH_LEAN - int len = SOAP_BUFLEN; - int set = 1; -#endif - soap->error = SOAP_OK; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - return soap->socket = soap->master; -#endif - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->socket = SOAP_INVALID_SOCKET; - soap->errmode = 0; - soap->keep_alive = 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", "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (soap_socket_errno != SOAP_EINTR) - { soap->errnum = soap_socket_errno; - soap_closesock(soap); - soap_set_sender_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&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); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK); -#endif -#endif - soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&soap->peer, &n); - soap->peerlen = (size_t)n; - if (soap_valid_socket(soap->socket)) - { -#ifdef WITH_IPV6 -/* Use soap->host to store the numeric form of the remote host */ - getnameinfo((struct sockaddr*)&soap->peer, 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->peer and soap->host */ - soap->port = 0; /* info stored in soap->peer and soap->host */ -#else - soap->ip = ntohl(soap->peer.sin_addr.s_addr); - soap->port = (int)ntohs(soap->peer.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)); -#endif -#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), "setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - 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), "setsockopt failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && 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), "setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - 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), "setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && 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), "setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#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); -#elif defined(VXWORKS) - u_long blocking = 0; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&blocking)); - ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)(&blocking)); -#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 - } - soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0); - return soap->socket; - } - if (soap_socket_errno != SOAP_EINTR && soap_socket_errno != SOAP_EAGAIN) - { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host)); - soap->errnum = soap_socket_errno; - soap_set_receiver_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - } - else - { soap->errnum = 0; - soap_set_receiver_error(soap, tcp_error(soap), "no master socket in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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) && !(soap->omode & SOAP_IO_UDP)) - { 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 WITH_NOIO -#ifndef PALM_1 -static int -tcp_closesocket(struct soap *soap, SOAP_SOCKET fd) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket %d\n", (int)fd)); - return closesocket(fd); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET fd, int how) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket %d how=%d\n", (int)fd, 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; - if (status == SOAP_EOF || status == SOAP_TCP_ERROR || status == SOAP_SSL_ERROR || !soap->keep_alive) - { if (soap->fclose && (soap->error = soap->fclose(soap))) - return soap->error; - soap->keep_alive = 0; - } -#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 WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_init_pht(struct soap *soap) -{ register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing pointer hashtable\n")); - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new1(soap_mode mode) -{ return soap_new2(mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new() -{ return soap_new2(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new2(soap_mode imode, soap_mode omode) -{ struct soap *soap = (struct soap*)malloc(sizeof(struct soap)); - if (soap) - soap_init2(soap, imode, omode); - return soap; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_del(struct soap *soap) -{ free(soap); -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_free_pht(struct soap *soap) -{ register struct soap_pblk *pb, *next; - register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n")); - for (pb = soap->pblk; pb; pb = next) - { next = pb->next; - SOAP_FREE(soap, pb); - } - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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; - if (!soap->pblk || soap->pidx >= SOAP_PTRBLK) - { register struct soap_pblk *pb = (struct soap_pblk*)SOAP_MALLOC(soap, sizeof(struct soap_pblk)); - if (!pb) - { soap->error = SOAP_EOM; - return 0; - } - pb->next = soap->pblk; - soap->pblk = pb; - soap->pidx = 0; - } - *ppp = pp = &soap->pblk->plist[soap->pidx++]; - 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=%d\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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -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)) -#ifndef WITH_LEANER - && !soap->fpreparesend -#endif - )) - soap->mode &= ~SOAP_IO_LENGTH; - else - soap->mode |= SOAP_IO_LENGTH; - } -#ifdef WITH_ZLIB - 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; - } -#endif - if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH)) - soap->mode |= SOAP_XML_TREE; -#ifndef WITH_LEANER - if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME)) - soap->mode |= SOAP_ENC_MIME; - else - soap->mode &= ~SOAP_ENC_MTOM; - 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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); -#ifndef WITH_LEANER - soap->dime.count = 0; /* count # of attachments */ - soap->dime.size = 0; /* accumulate total size of attachments */ - if (soap->fprepareinit && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_end_count(struct soap *soap) -{ -#ifndef WITH_LEANER - if (soap->fpreparefinal) - return soap->error = soap->fpreparefinal(soap); -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of count phase\n")); - return SOAP_OK; -} -#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->mode & (SOAP_IO_LENGTH | SOAP_ENC_DIME)); -#ifdef WITH_ZLIB - 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; - } -#endif -#ifdef WITH_UDP - if ((soap->mode & SOAP_IO_UDP)) - { soap->mode |= SOAP_ENC_XML; - if (soap->count > SOAP_BUFLEN) - return soap->error = SOAP_UDP_ERROR; - } -#endif - if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket)) - { if (soap->count || (soap->mode & SOAP_IO_LENGTH) || (soap->mode & SOAP_ENC_XML)) - soap->mode |= SOAP_IO_BUFFER; - else - soap->mode |= SOAP_IO_STORE; - } - soap->mode &= ~SOAP_IO_LENGTH; - 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_MTOM) && (soap->mode & SOAP_ENC_DIME)) - { soap->mode |= SOAP_ENC_MIME; - soap->mode &= ~SOAP_ENC_DIME; - } - else - soap->mode &= ~SOAP_ENC_MTOM; - if (soap->mode & SOAP_ENC_MIME) - soap_select_mime_boundary(soap); -#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 -#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->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=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); - soap->part = SOAP_BEGIN; -#ifndef WITH_LEANER - if (soap->fprepareinit && (soap->mode & SOAP_IO) == SOAP_IO_STORE) - soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 || !a->__ptr) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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; - if (soap->mode & SOAP_XML_TREE) - return id; - 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_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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_attachment(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; - int i; - 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:"")); - i = soap_array_pointer_lookup(soap, p, a, n, t, &pp); - if (!i) - { i = soap_pointer_enter(soap, p, a, n, t, &pp); - if (!i) - { soap->error = SOAP_EOM; - return -1; - } - } - if (id <= 0) - id = i; - if (!aid) - { sprintf(soap->tmpbuf, soap->dime_id_format, id); - aid = soap_strdup(soap, soap->tmpbuf); - } - /* Add MTOM xop:Include element when necessary */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - if ((soap->mode & SOAP_ENC_MTOM) && strcmp(tag, "xop:Include")) - { if (soap_element_begin_out(soap, tag, 0, type) - || soap_element_href(soap, "xop:Include", 0, "href", aid) - || soap_element_end_out(soap, tag)) - return soap->error; - } - else 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; - if (soap->mode & SOAP_ENC_MTOM) - content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, (char*)a->__ptr, a->__size); - else - content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, (char*)a->__ptr, a->__size); - if (!content) - { soap->error = SOAP_EOM; - return -1; - } - if (!strncmp(aid, "cid:", 4)) /* RFC 2111 */ - { if (soap->mode & SOAP_ENC_MTOM) - { char *s = (char*)soap_malloc(soap, strlen(aid) - 1); - if (s) - { *s = '<'; - strcpy(s + 1, aid + 4); - strcat(s, ">"); - content->id = s; - } - } - else - content->id = aid + 4; - } - else - content->id = aid; - content->type = atype; - content->options = aoptions; - content->encoding = SOAP_MIME_BINARY; - pp->mark1 = 3; - } - } - else - pp->mark2 = 3; - return -1; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, fp); - } - p = ip->next; - SOAP_FREE(soap, ip); - } - soap->iht[i] = NULL; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_2 -SOAP_FMAC1 -struct soap_ilist * -SOAP_FMAC2 -soap_lookup(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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, 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 -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_malloc(struct soap *soap, size_t n) -{ register char *p; - if (!n) - return (void*)SOAP_NON_NULL; - if (!soap) - return SOAP_MALLOC(soap, n); - n += (-(long)n) & (sizeof(void*)-1); /* align at 4-, 8- or 16-byte boundary */ - if (!(p = (char*)SOAP_MALLOC(soap, 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; - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -static void -soap_init_mht(struct soap *soap) -{ register int i; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->mht[i] = NULL; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -static void -soap_free_mht(struct soap *soap) -{ register int i; - register struct soap_mlist *mp, *mq; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - { for (mp = soap->mht[i]; mp; mp = mq) - { mq = mp->next; - if (mp->live) - fprintf(stderr, "%s(%d): malloc() = %p not freed (memory leak or forgot to call soap_end()?)\n", mp->file, mp->line, mp->ptr); - free(mp); - } - soap->mht[i] = NULL; - } -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_track_malloc(struct soap *soap, const char *file, int line, size_t size) -{ register void *p = malloc(size); - if (soap) - { register int h = soap_hash_ptr(p); - register struct soap_mlist *mp = (struct soap_mlist*)malloc(sizeof(struct soap_mlist)); - if (soap->fdebug[SOAP_INDEX_TEST]) - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): malloc(%lu) = %p\n", file, line, (unsigned long)size, p)); - mp->next = soap->mht[h]; - mp->ptr = p; - mp->file = file; - mp->line = line; - mp->live = 1; - soap->mht[h] = mp; - } - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_track_free(struct soap *soap, const char *file, int line, void *p) -{ register int h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - { if (mp->live) - { free(p); - if (soap->fdebug[SOAP_INDEX_TEST]) - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): free(%p)\n", file, line, p)); - mp->live = 0; - } - else - fprintf(stderr, "%s(%d): free(%p) double free of pointer malloced at %s(%d)\n", file, line, p, mp->file, mp->line); - } - else - fprintf(stderr, "%s(%d): free(%p) pointer not malloced\n", file, line, p); -} -#endif - -/******************************************************************************/ -#ifdef SOAP_DEBUG -static void -soap_track_unlink(struct soap *soap, const void *p) -{ register int h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - mp->live = 0; -} -#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(soap, p); - return; - } - } - soap_delete(soap, p); - } - else - { register char *q; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free all soap_malloc() data\n")); - while (soap->alist) - { q = (char*)soap->alist; - soap->alist = *(void**)q; - q -= *(size_t*)(q + sizeof(void*)); - SOAP_FREE(soap, q); - } - } - /* we must assume these were deallocated: */ - soap->action = NULL; - soap->fault = NULL; - soap->header = NULL; - soap->userid = NULL; - soap->passwd = 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(soap, 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(soap, 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(soap, 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)); -#ifdef SOAP_DEBUG - soap_track_unlink(soap, p); -#endif - 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(soap, q); - return; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 (!p || !id || !*id) - return p; - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, 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 -#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*)) -{ -#ifndef WITH_NOIDREF - struct soap_ilist *ip; -#endif - 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; - } -#ifndef WITH_NOIDREF - if (!id || !*id) -#endif - return p; -#ifndef WITH_NOIDREF - 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_DUPLICATE_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 -} -#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; -#ifndef WITH_NOHTTP - 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++; - } -#endif - 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); - } -#ifndef WITH_LEANER - 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_TCPFIN -#ifdef WITH_OPENSSL - if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */ -#else - if (soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */ -#endif -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send phase\n")); - soap->omode &= ~SOAP_XML_SEC; - soap->count = 0; - soap->part = SOAP_END; - 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_DIME) && soap_getdime(soap)) - return soap->error; - soap->dime.list = soap->dime.first; - soap->dime.first = NULL; - soap->dime.last = NULL; - 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->mime.boundary = 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; -#ifndef WITH_NOIDREF - return soap_resolve(soap); -#else -#ifndef WITH_LEANER - if (soap->xlist) - { if (soap->mode & SOAP_ENC_MTOM) - return soap->error = SOAP_MIME_HREF; - return soap->error = SOAP_DIME_HREF; - } -#endif - return SOAP_OK; -#endif -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_free(struct soap *soap) -{ register struct Namespace *ns; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n")); - while (soap->nlist) - { register struct soap_nlist *np = soap->nlist->next; - SOAP_FREE(soap, 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 attribute storage\n")); - while (soap->attributes) - { register struct soap_attribute *tp = soap->attributes->next; - if (soap->attributes->value) - SOAP_FREE(soap, soap->attributes->value); - SOAP_FREE(soap, soap->attributes); - soap->attributes = tp; - } -#ifdef WITH_FAST - if (soap->labbuf) - SOAP_FREE(soap, soap->labbuf); - soap->labbuf = NULL; - soap->lablen = 0; - soap->labidx = 0; -#endif - ns = soap->local_namespaces; - if (ns) - { for (; ns->id; ns++) - { if (ns->out) - { if (soap->encodingStyle == ns->out) - soap->encodingStyle = SOAP_STR_EOS; - SOAP_FREE(soap, ns->out); - ns->out = NULL; - } - if (soap->encodingStyle == ns->ns) - soap->encodingStyle = SOAP_STR_EOS; - } - SOAP_FREE(soap, soap->local_namespaces); - soap->local_namespaces = NULL; - } -#ifndef WITH_LEANER - while (soap->xlist) - { struct soap_xlist *xp = soap->xlist->next; - SOAP_FREE(soap, soap->xlist); - soap->xlist = xp; - } -#endif -#ifndef WITH_NOIDREF - soap_free_pht(soap); - soap_free_iht(soap); -#endif -} -#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(soap, (void*)soap->logfile[i]); - if (logfile) - if ((s = (char*)SOAP_MALLOC(soap, 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*)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->error = SOAP_OK; - copy->userid = NULL; - copy->passwd = NULL; - copy->nlist = NULL; - copy->blist = NULL; - copy->clist = NULL; - copy->alist = NULL; - copy->attributes = NULL; -#ifdef WITH_FAST - copy->labbuf = NULL; - copy->lablen = 0; - copy->labidx = 0; -#endif -#ifdef SOAP_DEBUG - soap_init_mht(copy); -#endif - copy->local_namespaces = NULL; -#ifndef WITH_NOIDREF - soap_init_iht(copy); - soap_init_pht(copy); -#endif - copy->header = NULL; - copy->fault = NULL; - copy->action = NULL; -#ifndef WITH_LEAN -#ifdef WITH_COOKIES - copy->cookies = soap_copy_cookies(copy); -#else - copy->cookies = NULL; -#endif -#endif -#ifdef SOAP_DEBUG - soap_init_logs(copy); - soap_set_recv_logfile(copy, soap->logfile[SOAP_INDEX_RECV]); - soap_set_sent_logfile(copy, soap->logfile[SOAP_INDEX_SENT]); - soap_set_test_logfile(copy, soap->logfile[SOAP_INDEX_TEST]); -#endif - copy->plugins = NULL; - for (p = soap->plugins; p; p = p->next) - { register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(copy, 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(copy, q, p))) - { SOAP_FREE(copy, 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; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif - soap->fconnect = NULL; - soap->fdisconnect = NULL; -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; -#endif - soap->fseterror = NULL; - soap->fignore = NULL; - soap->fserveloop = NULL; - soap->fplugin = fplugin; -#ifndef WITH_LEANER - soap->fdimereadopen = NULL; - soap->fdimewriteopen = NULL; - soap->fdimereadclose = NULL; - soap->fdimewriteclose = NULL; - soap->fdimeread = NULL; - soap->fdimewrite = NULL; -#endif - 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; -#ifdef WITH_FAST - soap->labbuf = NULL; - soap->lablen = 0; - soap->labidx = 0; -#endif - 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; -#ifndef WITH_LEANER - 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; - soap->xlist = NULL; -#endif -#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->crlfile = 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->c14ninclude = NULL; - soap->c14nexclude = NULL; - soap->cookies = NULL; - soap->cookie_domain = NULL; - soap->cookie_path = NULL; - soap->cookie_max = 32; -#endif -#ifdef SOAP_DEBUG - soap_init_mht(soap); - 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 -#ifdef WMW_RPM_IO - soap->rpmreqid = NULL; -#endif -#ifdef PALM - palmNetLibOpen(); -#endif -#ifndef WITH_NOIDREF - soap_init_iht(soap); - soap_init_pht(soap); -#endif - 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, soap_mode mode) -{ soap_init2(soap, mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init2(struct soap *soap, soap_mode imode, soap_mode 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_END; - 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'; -#ifndef WITH_LEANER - soap->dime.chunksize = 0; - soap->dime.buflen = 0; -#endif - 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, 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) -{ register struct Namespace *ns = soap->local_namespaces; - register struct soap_nlist *np, *nq, *nr; - register unsigned int level = soap->level; - soap->namespaces = p; - soap->local_namespaces = NULL; - soap_set_local_namespaces(soap); - /* reverse the namespace 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; - } - } - /* then push on new stack */ - while (np) - { register const char *s; - soap->level = np->level; /* preserve element nesting level */ - s = np->ns; - if (!s && np->index >= 0 && ns) - { s = ns[np->index].out; - if (!s) - s = ns[np->index].ns; - } - if (s && soap_push_namespace(soap, np->id, s)) - return soap->error; - nq = np; - np = np->next; - SOAP_FREE(soap, nq); - } - if (ns) - { register int i; - for (i = 0; ns[i].id; i++) - { if (ns[i].out) - { SOAP_FREE(soap, ns[i].out); - ns[i].out = NULL; - } - } - SOAP_FREE(soap, ns); - } - soap->level = level; /* restore level */ - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -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++; - n *= sizeof(struct Namespace); - ns2 = (struct Namespace*)SOAP_MALLOC(soap, n); - if (ns2) - { memcpy(ns2, soap->namespaces, n); - if (ns2[0].ns) - { if (!strcmp(ns2[0].ns, soap_env1)) - soap->version = 1; - else - soap->version = 2; - } - soap->local_namespaces = ns2; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef PALM_1 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_strsearch(const char *big, const char *little) -{ size_t n = strlen(little); - const char *s = big; - while (s) - { if (!strncmp(s, little, n) && (s[n] == '\0' || s[n] == ' ')) - return s; - s = strchr(s, ' '); - if (s) - s++; - } - return NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static struct soap_nlist * -soap_lookup_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np; - for (np = soap->nlist; np; np = np->next) - { if (!strncmp(np->id, tag, n) && !np->id[n]) - return np; - } - return NULL; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static struct soap_nlist * -soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized) -{ register struct soap_nlist *np; - size_t n, k; - if (soap_strsearch(soap->c14nexclude, id)) - return NULL; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns?ns:"")); - if (!utilized) - { for (np = soap->nlist; np; np = np->next) - { if (!strcmp(np->id, id) && (!np->ns || !strcmp(np->ns, ns))) - break; - } - if (np) - { if (np->index == 1) - utilized = np->index; - else - return NULL; - } - } - n = strlen(id); - if (ns) - k = strlen(ns); - else - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k + 1); - if (!np) - { soap->error = SOAP_EOM; - return NULL; - } - np->next = soap->nlist; - soap->nlist = np; - strcpy(np->id, id); - if (ns) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - } - else - np->ns = NULL; - np->level = soap->level; - np->index = utilized; - return np; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_utilize_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np = soap_lookup_ns(soap, tag, n); - if (np) - { if (np->index == 0) - soap_push_ns(soap, np->id, np->ns, 1); - } - else - { strncpy(soap->tmpbuf, tag, n); - soap->tmpbuf[n] = '\0'; - soap_push_ns(soap, soap->tmpbuf, NULL, 1); - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_pop_ns(struct soap *soap) -{ soap_pop_namespace(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_element(struct soap *soap, const char *tag, int id, const char *type) -{ 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 *elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->soap = soap; - elt->next = NULL; - elt->prnt = soap->dom; - elt->name = soap_strdup(soap, tag); - elt->elts = NULL; - elt->atts = NULL; - elt->nstr = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->node = NULL; - elt->type = 0; - elt->head = NULL; - elt->tail = NULL; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - } - else - { -#endif - soap->level++; -#ifndef WITH_LEAN - if (!soap->ns) - { if (!(soap->mode & SOAP_XML_CANONICAL) - && soap_send(soap, soap->prolog ? soap->prolog : "\n")) - return soap->error; - } - else if (soap->mode & SOAP_XML_INDENT) - { if (soap->ns == 1 && soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - soap->body = 1; - } -#endif - if (soap_send_raw(soap, "<", 1) - || soap_send(soap, tag)) - return soap->error; -#ifdef WITH_DOM - } -#endif - if (!soap->ns) - { struct Namespace *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; /* start with 0 or 2, but should be one to continue */ -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *s = strchr(tag, ':'); - if (s) - soap_utilize_ns(soap, tag, s - tag); - } -#endif - 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; -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *s = strchr(type, ':'); - if (s) - soap_utilize_ns(soap, type, s - type); - } -#endif - } - 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 && (n > 214748364 || c >= '8')) - 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 && (n > 429496729 || c >= '6')) - 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; - } -#ifndef WITH_LEAN - if (type && *type && (soap->mode & SOAP_XML_CANONICAL)) - { const char *s = strchr(type, ':'); - if (s) - soap_utilize_ns(soap, type, s - type); - } -#endif - 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 - register struct soap_dom_attribute **att; - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { att = &soap->dom->atts; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, tp->name); - (*att)->data = soap_strdup(soap, tp->value); - (*att)->wide = NULL; - (*att)->soap = soap; - tp->visible = 0; - } - } - return SOAP_OK; - } -#endif -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { struct soap_nlist *np; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible && tp->name) - { const char *s = strchr(tp->name, ':'); - if (s) - soap_utilize_ns(soap, tp->name, s - tp->name); - } - } - for (np = soap->nlist; np; np = np->next) - { if (np->index == 1 && np->ns) - { sprintf(soap->tmpbuf, "xmlns:%s", np->id); - soap_set_attr(soap, soap->tmpbuf, np->ns); - np->index = 2; - } - } - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { if (soap_send(soap, " ") || 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) - { -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { if (soap_send_raw(soap, ">", 1) - || soap_element_end_out(soap, tag)) - return soap->error; - } - else -#endif - soap->level--; /* decrement level just before /> */ - if (soap_send_raw(soap, "/>", 2)) - return soap->error; - return SOAP_OK; - } - 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 -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - soap_pop_ns(soap); - if (soap->mode & SOAP_XML_INDENT) - { if (!soap->body) - { if (soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - } - soap->body = 0; - } -#endif - if (soap_send_raw(soap, "error; - soap->level--; /* decrement level just before > */ - 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) -{ if (!p || (a && !a->__ptr)) - { soap_element_null(soap, tag, id, type); - return -1; - } -#ifndef WITH_NOIDREF - if (soap->mode & SOAP_XML_TREE) - return 0; - if (id < 0) - { struct soap_plist *pp; - 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; -#else - return 0; -#endif -} -#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); - a->data = soap_strdup(soap, value); - a->wide = NULL; - a->soap = soap; - soap->dom->atts = a; - return SOAP_OK; - } -#endif -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { /* TODO: consider using this code to handle default namespace - if (!strncmp(name, "xmlns", 5) && (name[5] == ':' || name[5] == '\0')) - { if (name[5] == ':') - soap_push_ns(soap, name + 6, value, 0); - else - soap_push_ns(soap, "", value, 0); - } - */ - if (!strncmp(name, "xmlns:", 6)) - soap_push_ns(soap, name + 6, value, 0); - else if (soap_set_attr(soap, name, value)) - return soap->error; - } - else -#endif - { if (soap_send(soap, " ") || 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, 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; - } - } - else if (soap->error == SOAP_NO_TAG && tag && *tag == '-') - soap->error = SOAP_OK; - 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; - register int n = 0; - if (tag && *tag == '-') - return SOAP_OK; - soap->level--; - soap_pop_namespace(soap); -#ifdef WITH_DOM - /* this whitespace or mixed content is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!soap->peeked && !soap_string_in(soap, 3, -1, -1)) - return soap->error; - if (soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - if (soap->peeked) - { if (soap->error == SOAP_NO_TAG) - soap->error = SOAP_OK; - if (*soap->tag) - n++; - soap->peeked = 0; - } - do - { while (((c = soap_get(soap)) != SOAP_TT)) - { if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (c == SOAP_LT) - n++; - else if (c == '/') - { c = soap_get(soap); - if (c == SOAP_GT) - n--; - else - soap_unget(soap, c); - } - } - } while (n--); - s = soap->tag; - while (soap_notblank(c = soap_get(soap))) - *s++ = (char)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 || !*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(soap, 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(soap, tp->value); - tp->value = NULL; - tp->ns = NULL; - } - if (value) - { if (!tp->value) - { tp->size = strlen(value) + 1; - if (!(tp->value = (char*)SOAP_MALLOC(soap, 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; -#ifndef WITH_LEAN - if (!strcmp(name, "wsu:Id")) - { soap->part = SOAP_BEGIN_SECURITY; - strncpy(soap->id, value, sizeof(soap->id)); - soap->id[sizeof(soap->id)-1] = '\0'; - } -#endif - } - 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, soap->attributes->value); - SOAP_FREE(soap, 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) -{ register size_t i; - for (i = 0; i < n; i++) - { register soap_wchar c = soap_get(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 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_store_lab(struct soap *soap, const char *s, size_t n) -{ soap->labidx = 0; - return soap_append_lab(soap, s, n); -} -#endif -#endif - -/******************************************************************************/ -#ifdef WITH_FAST -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -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, soap->lablen); - if (!soap->labbuf) - { if (t) - SOAP_FREE(soap, t); - return soap->error = SOAP_EOM; - } - if (t) - { memcpy(soap->labbuf, t, soap->labidx); - SOAP_FREE(soap, 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) -{ -#ifdef WITH_DOM - register struct soap_dom_attribute **att = NULL; - register char *lead = NULL; -#endif - register struct soap_attribute *tp; - const char *t; - register char *s; - register soap_wchar c; - register int i; - if (soap->peeked) - { if (!*soap->tag) - return soap->error = SOAP_NO_TAG; - return SOAP_OK; - } - soap->peeked = 1; - c = soap_getutf8(soap); -#ifdef WITH_DOM - /* whitespace leading to start tag is not insignificant for DOM */ - if (soap_blank(c)) - { soap->labidx = 0; - do - { if (soap_append_lab(soap, NULL, 0)) - return SOAP_EOM; - s = soap->labbuf + soap->labidx; - i = soap->lablen - soap->labidx; - soap->labidx = soap->lablen; - while (soap_blank(c) && i--) - { *s++ = c; - c = soap_getutf8(soap); - } - } - while (soap_blank(c)); - *s = '\0'; - lead = soap_strdup(soap, soap->labbuf); - } -#else - while (soap_blank(c)) - c = soap_getutf8(soap); -#endif - if (c != SOAP_LT) - { *soap->tag = '\0'; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifdef WITH_DOM - /* whitespace leading to end tag is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->tail = soap_strdup(soap, lead); -#endif - return soap->error = SOAP_NO_TAG; - } - s = soap->tag; - do c = soap_get1(soap); - while (soap_blank(c)); - i = sizeof(soap->tag); - while (c != '>' && c != '/' && soap_notblank(c)) - { if (--i > 0) - *s++ = (char)c; - c = soap_get1(soap); - } - while (soap_blank(c)) - c = soap_get1(soap); - *s = '\0'; - 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; -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { register struct soap_dom_element *elt; - elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->next = NULL; - elt->nstr = NULL; - elt->name = soap_strdup(soap, soap->tag); - elt->prnt = soap->dom; - elt->elts = NULL; - elt->atts = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->type = 0; - elt->node = NULL; - elt->head = lead; - elt->tail = NULL; - elt->soap = soap; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - att = &elt->atts; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - tp->visible = 0; - while ((int)c != EOF && c != '>' && c != '/') - { s = soap->tmpbuf; - i = sizeof(soap->tmpbuf); - while (c != '=' && c != '>' && c != '/' && soap_notblank(c)) - { if (--i > 0) - *s++ = (char)c; - c = soap_get1(soap); - } - *s = '\0'; - if (i == sizeof(soap->tmpbuf)) - return soap->error = SOAP_SYNTAX_ERROR; -#ifdef WITH_DOM - /* add attribute name to dom */ - if (att) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, soap->tmpbuf); - (*att)->data = NULL; - (*att)->wide = NULL; - (*att)->soap = soap; - } -#endif - if (!strncmp(soap->tmpbuf, "xmlns", 5)) - { if (soap->tmpbuf[5] == ':') - { soap->tmpbuf[5] = '\0'; - t = soap->tmpbuf + 6; - } - else if (soap->tmpbuf[5]) - t = NULL; - else - 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(soap, 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_get1(soap); - if (c == '=') - { do c = soap_getutf8(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; - if (soap_store_lab(soap, tp->value, tp->size)) - return soap->error; - if (tp->value) - SOAP_FREE(soap, 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; - } - if (soap->labidx) - tp->size = soap->lablen; - else - { tp->size = strlen(soap->labbuf) + 1; - if (tp->size < SOAP_LABLEN) - tp->size = SOAP_LABLEN; - } - if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size))) - return soap->error = SOAP_EOM; - strcpy(tp->value, soap->labbuf); -#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(soap, n))) - return soap->error = SOAP_EOM; - if (tp->value) - { memcpy(s, tp->value, tp->size); - SOAP_FREE(soap, tp->value); - } - soap_save_block(soap, s + tp->size, 0); - tp->value = s; - tp->size = n; -#endif - } - do c = soap_get1(soap); - while (soap_blank(c)); - tp->visible = 2; /* seen this attribute w/ value */ -#ifdef WITH_DOM - if (att) - (*att)->data = soap_strdup(soap, tp->value); -#endif - } - else - tp->visible = 1; /* seen this attribute w/o value */ -#ifdef WITH_DOM - if (att) - att = &(*att)->next; -#endif - if (t && tp->value) - { if (soap_push_namespace(soap, t, tp->value)) - return soap->error; - tp->visible = 0; - } - } -#ifdef WITH_DOM - if (att) - { soap->dom->nstr = soap_current_namespace(soap, soap->tag); - for (att = &soap->dom->atts; *att; att = &(*att)->next) - (*att)->nstr = soap_current_namespace(soap, (*att)->name); - } -#endif - if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (!(soap->body = (c != '/'))) - do c = soap_get1(soap); - while (soap_blank(c)); -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { if (!soap->body && soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - 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->version == 1 && !soap_match_tag(soap, tp->name, "SOAP-ENV:actor")) - || (soap->version == 2 && !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; - } - } - return soap->error = SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_retry(struct soap *soap) -{ soap->error = SOAP_OK; - soap_revert(soap); -} -#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 = 0xFFFFFF80UL; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_strdup(soap, s); - 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: -#ifndef WITH_LEANER -#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 -#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; -#if !defined(WITH_LEANER) && defined(HAVE_WCTOMB) - char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8]; -#else - char buf[8]; -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { n = 1; - soap->peeked = 0; -#ifndef WITH_LEAN - t = soap->tmpbuf; - t[0] = '<'; - strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 1); - strncat(t, ">", sizeof(soap->tmpbuf)); - m = strlen(soap->tag) + 2; -#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: -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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*)"amp;"; - m = 4; - } - 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; -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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; - } -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (flag == 3) - soap->dom->tail = t; - else - soap->dom->data = t; - } -#endif - if (flag == 2) - if (soap_s2QName(soap, t, &t)) - return NULL; - return t; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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) - { wchar_t *r = (wchar_t*)s; - int n = 1; - while (*r++) - n++; - soap->dom->wide = r = (wchar_t*)soap_malloc(soap, n * sizeof(wchar_t)); - while (n--) - *r++ = *s++; - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading wide string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { n = 1; - soap->peeked = 0; - } - } - 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; - } - s = (wchar_t*)soap_save_block(soap, NULL, 0); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->wide = s; -#endif - return s; -} -#endif -#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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = (int)soap_strtol(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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 (*soap->href) - p = (int*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(int), 0, NULL); - else if (p) - { if (soap_s2int(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = soap_strtol(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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 (*soap->href) - p = (long*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(long), 0, NULL); - else if (p) - { if (soap_s2long(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOLL - char *r; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = strtoll(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -# ifdef HAVE_SSCANF - if (sscanf(s, SOAP_LONG_FORMAT, p) != 1) -# endif -#endif - 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 (*soap->href) - p = (LONG64*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(LONG64), 0, NULL); - else if (p) - { if (soap_s2LONG64(soap, soap_value(soap), p)) - return 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 (s == r || *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 (*soap->href) - p = (char*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(char), 0, NULL); - else if (p) - { if (soap_s2byte(soap, soap_value(soap), p)) - return 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 (s == r || *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 (*soap->href) - p = (short*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(short), 0, NULL); - else if (p) - { if (soap_s2short(soap, soap_value(soap), p)) - return 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 (!*s) - return soap->error = SOAP_TYPE; - 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 - { -/* On some systems, strtof appears to be broken or doesn't link: use with caution */ -#if defined(HAVE_STRTOF) - char *r; - *p = strtof((char*)s, &r); - if (*r) -#elif defined(HAVE_STRTOD) - char *r; - *p = (float)strtod(s, &r); - if (*r) -#endif -#ifdef HAVE_SSCANF - if (sscanf(s, "%g", 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 (*soap->href) - p = (float*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(float), 0, NULL); - else if (p) - { if (soap_s2float(soap, soap_value(soap), p)) - return 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 (!*s) - return soap->error = SOAP_TYPE; - 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, "%lg", 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 (*soap->href) - p = (double*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(double), 0, NULL); - else if (p) - { if (soap_s2double(soap, soap_value(soap), p)) - return 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 (s == r || *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 (*soap->href) - p = (unsigned char*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned char), 0, NULL); - else if (p) - { if (soap_s2unsignedByte(soap, soap_value(soap), p)) - return 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_unsignedShort2s(struct soap *soap, unsigned short n) -{ return soap_unsignedLong2s(soap, (unsigned long)n); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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 PALM_2 -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 (s == r || *r || n > 65535) - soap->error = SOAP_TYPE; - *p = (unsigned short)n; - } - return soap->error; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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 (*soap->href) - p = (unsigned short*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned short), 0, NULL); - else if (p) - { if (soap_s2unsignedShort(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = (unsigned int)soap_strtoul(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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 (*soap->href) - p = (unsigned int*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned int), 0, NULL); - else if (p) - { if (soap_s2unsignedInt(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = soap_strtoul(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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 (*soap->href) - p = (unsigned long*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(unsigned long), 0, NULL); - else if (p) - { if (soap_s2unsignedLong(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOULL - char *r; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = strtoull(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -# ifdef HAVE_SSCANF - if (sscanf(s, SOAP_ULONG_FORMAT, p) != 1) -# endif -#endif - 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 (*soap->href) - p = (ULONG64*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(ULONG64), 0, NULL); - else if (p) - { if (soap_s2ULONG64(soap, soap_value(soap), p)) - return 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))) - return soap->error = SOAP_EOM; - if (!(soap->mode & (SOAP_ENC_LATIN | SOAP_C_UTFSTRING))) - { /* TODO: consider truncating UTF8 to ASCII for XML attribute strings? */ - } - 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 != '"') - { -#ifndef WITH_LEAN - if (s && (soap->mode & SOAP_XML_CANONICAL)) - { t = (char*)strchr(s, ':'); - if (t) - soap_utilize_ns(soap, s, t - s); - } -#endif - 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:_%d", 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 WITH_LEAN -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_s2wchar(struct soap *soap, const char *s, wchar_t **t) -{ wchar_t *r; - if (!s) - *t = NULL; - else - { *t = r = (wchar_t*)soap_malloc(soap, sizeof(wchar_t) * (strlen(s) + 1)); - if (!r) - return soap->error; - if (soap->mode & SOAP_ENC_LATIN) - { while (*s) - *r++ = (wchar_t)*s++; - } - else - { /* Convert UTF8 to wchar */ - while (*s) - { register soap_wchar c, c1, c2, c3, c4; - c = *s++; - if (c < 0x80) - *r++ = (wchar_t)c; - else - { c1 = (soap_wchar)*s++ & 0x3F; - if (c < 0xE0) - *r++ = (wchar_t)(((soap_wchar)(c & 0x1F) << 6) | c1); - else - { c2 = (soap_wchar)*s++ & 0x3F; - if (c < 0xF0) - *r++ = (wchar_t)(((soap_wchar)(c & 0x0F) << 12) | (c1 << 6) | c2); - else - { c3 = (soap_wchar)*s++ & 0x3F; - if (c < 0xF8) - *r++ = (wchar_t)(((soap_wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3); - else - { c4 = (soap_wchar)*s++ & 0x3F; - if (c < 0xFC) - *r++ = (wchar_t)(((soap_wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4); - else - *r++ = (wchar_t)(((soap_wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (soap_wchar)(*s++ & 0x3F)); - } - } - } - } - } - } - *r = L'\0'; - } - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_wchar2s(struct soap *soap, const wchar_t *s) -{ register soap_wchar c; - register char *r, *t; - const wchar_t *q = s; - size_t n = 0; - while ((c = *q++)) - { if (c > 0 && c < 0x80) - n++; - else - n += 6; - } - r = t = (char*)soap_malloc(soap, n + 1); - if (r) - { /* Convert wchar to UTF8 */ - while ((c = *s++)) - { if (c > 0 && c < 0x80) - *t++ = (char)c; - else - { 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'; - } - return r; -} -#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)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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 if (soap->null) - *p = NULL; - else - *p = (char*)SOAP_STR_EOS; - if (*soap->href) - 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 WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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 if (soap->null) - *p = NULL; - else - *p = (wchar_t*)SOAP_STR_EOS; - if (*soap->href) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static time_t -soap_timegm(struct tm *T) -{ -#if defined(HAVE_TIMEGM) - return timegm(T); -#else - time_t t, g, z; -#ifdef HAVE_GMTIME_R - struct tm tm, *tmp = &tm; -#else - struct tm *tmp; -#endif - t = mktime(T); - if (t == -1) - return -1; -#ifdef HAVE_GMTIME_R - gmtime_r(&t, tmp); -#else - tmp = gmtime(&t); -#endif - tmp->tm_isdst = 0; - g = mktime(tmp); - if (g == -1) - return -1; - z = g - t; - return t - z; -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_dateTime2s(struct soap *soap, time_t n) -{ struct tm T, *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); - /* 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); -#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+(pT->tm_isdst!=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+(pT->tm_isdst!=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+(pT->tm_isdst!=0), abs(t.timezone)%60); - } - /* 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); - } -# 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+(pT->tm_isdst!=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); - /* 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); -#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]; - const char *t; - memset((void*)&T, 0, sizeof(T)); - zone[sizeof(zone)-1] = '\0'; - if (strchr(s, '-')) - t = "%d-%d-%dT%d:%d:%d%15s"; - else if (strchr(s, ':')) - t = "%4d%2d%2dT%d:%d:%d%15s"; - else /* parse non-XSD-standard alternative ISO 8601 format */ - t = "%4d%2d%2dT%2d%2d%2d%15s"; - sscanf(s, t, &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 == '+' || *s == '-') - { int h = 0, m = 0; - if (s[3] == ':') - { sscanf(s, "%d:%d", &h, &m); - if (h < 0) - m = -m; - } - else - { m = (int)atol(s); - h = m / 100; - m = m % 100; - } - T.tm_hour -= h; - T.tm_min -= m; - } - T.tm_isdst = 0; - *p = soap_timegm(&T); - } - else - { T.tm_isdst = -1; - *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 (*soap->href) - p = (time_t*)soap_id_forward(soap, soap->href, p, t, 0, sizeof(time_t), 0, NULL); - else if (p) - { if (soap_s2dateTime(soap, soap_value(soap), p)) - return 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 (soap->local_namespaces && (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, "", 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)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - if (!(p = (char**)soap_malloc(soap, sizeof(char*)))) - return NULL; - if (soap->body) - *p = soap_string_in(soap, 0, -1, -1); - else if (soap->null) - *p = NULL; - else - *p = (char*)SOAP_STR_EOS; - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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 (soap->local_namespaces && (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, "", t); - return soap_send(soap, soap->tmpbuf); - } - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*)))) - return NULL; - if (soap->body) - *p = soap_wstring_in(soap, 0, -1, -1); - else if (soap->null) - *p = NULL; - else - *p = (wchar_t*)SOAP_STR_EOS; - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_token(struct soap *soap) -{ register size_t i; - register soap_wchar c = 0; - register char *s = soap->tmpbuf; - if (!soap->body) - return SOAP_STR_EOS; - do c = soap_get(soap); - while (soap_blank(c)); - for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++) - { if (c == SOAP_TT || (int)c == EOF || soap_blank(c)) - break; - *s++ = (char)c; - c = soap_get(soap); - } - if ((int)c == EOF || c == SOAP_TT) - soap_unget(soap, c); - *s = '\0'; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element content value='%s'\n", soap->tmpbuf)); - return soap->tmpbuf; /* return non-null pointer */ -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_value(struct soap *soap) -{ register size_t i; - register soap_wchar c = 0; - register char *s = soap->tmpbuf; - if (!soap->body) - return SOAP_STR_EOS; - do c = soap_get(soap); - while (soap_blank(c)); - for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++) - { if (c == SOAP_TT || (int)c == EOF) - break; - *s++ = (char)c; - c = soap_get(soap); - } - for (s--; i > 0; i--, s--) - if (!soap_blank(*s)) - break; - s[1] = '\0'; - if ((int)c == EOF || c == SOAP_TT) - soap_unget(soap, c); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element content value='%s'\n", soap->tmpbuf)); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->data = soap_strdup(soap, soap->tmpbuf); -#endif - return soap->tmpbuf; /* return non-null pointer */ -} -#endif - -/******************************************************************************/ -#if !defined(WITH_LEANER) || !defined(WITH_NOHTTP) -#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' || c == '\n') - break; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - *s++ = (char)c; - } - if (c != '\n') - c = soap_getchar(soap); /* got \r, now get \n */ - if (c == '\n') - { *s = '\0'; - if (i+1 == len) /* empty line: end of HTTP/MIME 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 -#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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the message size with attachments, current count=%lu\n", (unsigned long)count)); - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - { 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 content is %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); - /* count Content-Transfer-Encoding: ...\r\n */ - s = soap_str_code(mime_codes, content->encoding); - 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 content is %lu bytes\n", (unsigned long)content->size)); - } - /* count \r\n--boundary-- */ - count += 6 + n; - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New count is %lu bytes\n", (unsigned long)count)); - 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) -{ while (soap->dime.flags & SOAP_DIME_CF) - { if (soap_getdimehdr(soap)) - return soap->error; - if (soap_move(soap, soap->dime.size)) - return soap->error = SOAP_EOF; - } - if (soap_move(soap, ((soap->dime.size+3)&(~3))-soap_tell(soap))) - return soap->error = SOAP_EOF; - for (;;) - { register struct soap_multipart *content; - if (soap_getdimehdr(soap)) - break; - 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; - soap_resolve_attachment(soap, content); - if (soap->error) - return soap->error; - } - if (soap->error != SOAP_DIME_END) - return soap->error; - return soap->error = SOAP_OK; -} -#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-Disposition")) - content->id = soap_strdup(soap, soap_get_header_attribute(soap, val, "name")); - 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 = 0; - if (!soap->mime.last) - return SOAP_OK; - for (;;) - { register size_t i, m = 0; - register char *s, *t = NULL; - 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 short flag = 0; - 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 - { if (!flag) - { c = soap_get1(soap); - if ((int)c == EOF) - return soap->error = SOAP_EOF; - } - if (flag || c == '\r') - { t = soap->tmpbuf; - memset(t, 0, sizeof(soap->tmpbuf)); - strcpy(t, "\n--"); - if (soap->mime.boundary) - strncat(t, soap->mime.boundary, sizeof(soap->tmpbuf)-4); - do c = soap_getchar(soap); - while (c == *t++); - if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (!*--t) - goto end; - *t = (char)c; - flag = (c == '\r'); - m = t - soap->tmpbuf + 1 - flag; - 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); - soap_resolve_attachment(soap, content); - 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; - } - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -static int -soap_match_cid(struct soap *soap, const char *s, const char *t) -{ register size_t n; - if (!s) - return 1; - if (!strcmp(s, t)) - return 0; - if (!strncmp(s, "cid:", 4)) - s += 4; - n = strlen(t); - if (*t == '<') - { t++; - n -= 2; - } - if (!strncmp(s, t, n) && !s[n]) - return 0; - soap_decode(soap->tmpbuf, sizeof(soap->tmpbuf), s, SOAP_STR_EOS); - if (!strncmp(soap->tmpbuf, t, n) && !soap->tmpbuf[n]) - return 0; - return 1; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -static void -soap_resolve_attachment(struct soap *soap, struct soap_multipart *content) -{ if (content->id) - { register struct soap_xlist **xp = &soap->xlist; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving attachment data for id=%s\n", content->id)); - while (*xp) - { register struct soap_xlist *xq = *xp; - if (!soap_match_cid(soap, xq->id, content->id)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Found matching attachment %s for content id=%s\n", xq->id, content->id)); - *xp = xq->next; - *xq->ptr = (unsigned char*)content->ptr; - *xq->size = (int)content->size; - *xq->type = (char*)content->type; - if (content->options) - *xq->options = (char*)content->options; - else - *xq->options = (char*)content->description; - SOAP_FREE(soap, xq); - } - else - xp = &(*xp)->next; - } - } -} -#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, "--"); -} -#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 = 64; - s = soap->mime.boundary = (char*)soap_malloc(soap, n + 1); - if (!s) - return; - } - strcpy(s, "=="); - s += 2; - n -= 4; - while (n) - { *s++ = soap_base64o[soap_random & 0x3F]; - n--; - } - strcpy(s, "=="); - } - if (!soap->mime.start) - soap->mime.start = ""; -} -#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 && !strchr("()<>@,;:\\\"/[]?={}", 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(soap, sizeof(struct soap_cookie)))) - { if ((q->name = (char*)SOAP_MALLOC(soap, 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->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(soap, q->name); - SOAP_FREE(soap, q); - q = NULL; - } - } - } - else - q->modified = 1; - if (q) - { if (q->value) - { SOAP_FREE(soap, q->value); - q->value = NULL; - } - if (q->domain) - { SOAP_FREE(soap, q->domain); - q->domain = NULL; - } - if (q->path) - { SOAP_FREE(soap, q->path); - q->path = NULL; - } - if (value && *value && (q->value = (char*)SOAP_MALLOC(soap, strlen(value)+1))) - strcpy(q->value, value); - if (domain && *domain && (q->domain = (char*)SOAP_MALLOC(soap, strlen(domain)+1))) - strcpy(q->domain, domain); - if (path && *path && (q->path = (char*)SOAP_MALLOC(soap, strlen(path)+1))) - strcpy(q->path, path); - q->session = 1; - q->env = 0; - } - 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", NULL, SOAP_HTTP_ERROR); - return; - } - if (!path) - path = soap->cookie_path; - if (!path) - { soap_set_receiver_error(soap, "Cookie path not set", NULL, 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(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, 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 -char * -SOAP_FMAC2 -soap_env_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)) && p->env) - 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); - *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->error = 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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending cookies for domain=%s path=%s\n", domain, path)); - if (*path == '/') - path++; - while ((q = *p)) - { if (q->expire && now > q->expire) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name)); - SOAP_FREE(soap, q->name); - if (q->value) - SOAP_FREE(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, q); - } - else - { size_t domlen = 0; - if (q->domain) - { const char *s = strchr(q->domain, ':'); - if (s) - domlen = s - q->domain; - else - domlen = strlen(q->domain); - } - if ((!q->domain || !strncmp(q->domain, domain, domlen)) - && (!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 == '/' ? q->path + 1 : 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->error = soap->fposthdr(soap, "Cookie", tmp))) - return soap->error; - } - 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->path) - SOAP_FREE(soap, p->path); - p->path = t; - } - else - { if (path) - SOAP_FREE(soap, 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->domain) - SOAP_FREE(soap, p->domain); - p->domain = t; - } - else - { if (domain) - SOAP_FREE(soap, domain); - domain = t; - } - } - else if (p && !soap_tag_cmp(tmp, "Path")) - { if (p->path) - SOAP_FREE(soap, p->path); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->path = (char*)SOAP_MALLOC(soap, strlen(tmp)+1))) - strcpy(p->path, tmp); - } - else - p->path = NULL; - } - else if (p && !soap_tag_cmp(tmp, "Domain")) - { if (p->domain) - SOAP_FREE(soap, p->domain); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->domain = (char*)SOAP_MALLOC(soap, 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if ((p = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie)))) - { p->name = (char*)SOAP_MALLOC(soap, strlen(tmp)+1); - strcpy(p->name, tmp); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { p->value = (char*)SOAP_MALLOC(soap, 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 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if (domain) - SOAP_FREE(soap, domain); - if (path) - SOAP_FREE(soap, 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(soap, sizeof(struct soap_cookie)))) - return r; - **q = *p; - if (p->name) - { if (((*q)->name = (char*)SOAP_MALLOC(soap, strlen(p->name)+1))) - strcpy((*q)->name, p->name); - } - if (p->value) - { if (((*q)->value = (char*)SOAP_MALLOC(soap, strlen(p->value)+1))) - strcpy((*q)->value, p->value); - } - if (p->domain) - { if (((*q)->domain = (char*)SOAP_MALLOC(soap, strlen(p->domain)+1))) - strcpy((*q)->domain, p->domain); - } - if (p->path) - { if (((*q)->path = (char*)SOAP_MALLOC(soap, 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, 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 */ -#ifndef WITH_NOIDREF - soap_free_iht(soap); -#endif - 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->action = NULL; -#ifndef WITH_LEANER - soap->dom = 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; - soap->xlist = NULL; -#endif -#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 -#ifndef WITH_LEANER - 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 -#ifndef WITH_LEANER - 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 -#endif - { while (soap_blank(c)) - c = soap_getchar(soap); - } - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifndef WITH_NOHTTP - /* if not XML or (start of)BOM or MIME/DIME/ZLIB, assume HTTP header */ - if (c != '<' && c != 0xEF && !(soap->mode & (SOAP_ENC_MIME | SOAP_ENC_DIME | SOAP_ENC_ZLIB))) - { soap->mode &= ~SOAP_IO; - soap->error = soap->fparse(soap); - if (soap->error && soap->error < SOAP_STOP) - { 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; - } -#ifndef WITH_LEANER - else if (soap->fpreparerecv && soap->buflen != soap->bufidx) - soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx); -#endif -#ifdef WITH_ZLIB - if (soap->zlib_in != SOAP_ZLIB_NONE) - { /* 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 - if (soap->error) - { if (soap->error == SOAP_FORM && soap->fform) - { soap->error = soap->fform(soap); - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - } - return soap->error; - } - } -#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 WITH_NOHTTP -#ifndef PALM_1 -static int -http_parse(struct soap *soap) -{ char header[SOAP_HDRLEN], *s; - unsigned short get = 0, status = 0, k = 0; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for HTTP request/response...\n")); - *soap->endpoint = '\0'; - soap->length = 0; - soap->userid = NULL; - soap->passwd = NULL; - soap->action = NULL; - soap->authrealm = NULL; - 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)) - { if (soap->error == SOAP_EOF) - { soap->error = SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "EOF in HTTP header, continue anyway\n")); - break; - } - 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))) - { if (soap->error < SOAP_STOP) - return soap->error; - status = soap->error; - soap->error = SOAP_OK; - } - } - } - if ((s = strchr(soap->msgbuf, ' '))) - { k = (unsigned short)soap_strtoul(s, &s, 10); - if (!soap_blank(*s)) - k = 0; - } - 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 && (((get = !strncmp(soap->msgbuf, "GET ", 4))) || !strncmp(soap->msgbuf, "POST ", 5))) - { size_t m = strlen(soap->endpoint); - size_t n = m + (s - soap->msgbuf) - 5 - (!get); - if (n >= sizeof(soap->endpoint)) - n = sizeof(soap->endpoint) - 1; - strncpy(soap->path, soap->msgbuf + 4 + (!get), n - m); - soap->path[n - m] = '\0'; - strcat(soap->endpoint, soap->path); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint)); - if (get) - { soap->error = soap->fget(soap); - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - return soap->error; - } - if (status) - return soap->error = status; - return SOAP_OK; - } - if (k == 0 || (k >= 200 && k <= 299) || k == 400 || k == 500) - return SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP error %d\n", k)); - return soap_set_receiver_error(soap, "HTTP error", soap->msgbuf, k); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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_get_header_attribute(soap, val, "multipart/form-data")) - { 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 *")) - { int 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 == '"') - { 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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#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) && !(soap->mode & SOAP_ENC_MTOM)) - 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->mode & SOAP_ENC_MTOM)) - { 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) && !(soap->mode & SOAP_ENC_MTOM)) - 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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) -{ soap->part = SOAP_END_ENVELOPE; - return soap_element_end_in(soap, "SOAP-ENV:Envelope"); -} -#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; -#ifndef WITH_LEAN - if ((soap->mode & SOAP_XML_SEC) && soap_set_attr(soap, "wsu:Id", "Body")) - return soap->error; -#endif - if (soap_element(soap, "SOAP-ENV:Body", 0, NULL)) - 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_END_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; - if (soap_element_begin_in(soap, "SOAP-ENV:Body", 0)) - return soap->error; - if (!soap->body) - soap->part = SOAP_NO_BODY; - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_body_end_in(struct soap *soap) -{ if (soap->part == SOAP_NO_BODY) - return SOAP_OK; - soap->part = SOAP_END_BODY; - return soap_element_end_in(soap, "SOAP-ENV:Body"); -} -#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] = '\0'; - soap->host[0] = '\0'; - soap->path[0] = '/'; - soap->path[1] = '\0'; - soap->port = 80; - if (!endpoint || !*endpoint) - return; - if (!strncmp(endpoint, "https:", 6)) - soap->port = 443; - 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; -#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 - for (i = 0; i < n; i++) - { soap->host[i] = s[i]; - if (s[i] == '/' || s[i] == ':') - break; - } -#endif - 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, 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); -#ifndef WITH_LEANER - if (soap->fconnect) - { if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port))) - return soap->error; - } - else -#endif - if (soap->fopen && *soap->host) - { soap->status = http_command; - if (!soap->keep_alive || !soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port || !soap->fpoll || soap->fpoll(soap)) - { soap->keep_alive = 0; /* to force close */ - soap->omode &= ~SOAP_IO_UDP; /* to force close */ - soap_closesock(soap); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect/reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port)); -#ifdef WITH_UDP - if (!strncmp(endpoint, "soap.udp:", 9)) - soap->omode |= SOAP_IO_UDP; -#endif - 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); - } - } - count = soap_count_attachments(soap); - if (soap_begin_send(soap)) - return soap->error; -#ifndef WITH_NOHTTP - 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; -#ifndef WITH_LEANER - if ((k & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = k; - } - else if (action) - soap->action = soap_strdup(soap, action); - if (http_command != SOAP_POST) - return soap_end_send(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2base64(struct soap *soap, const unsigned char *s, char *t, int n) -{ register int 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, int *n) -{ register int i, j, c; - register unsigned long m; - register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = (strlen(s) + 3) / 4 * 3; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - 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 WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2hex(struct soap *soap, const unsigned char *s, char *t, int n) -{ register char *p; - if (!t) - t = (char*)soap_malloc(soap, 2 * n + 1); - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - t[0] = '\0'; - if (s) - { for (; n > 0; n--) - { register int m = *s++; - *t++ = (char)((m >> 4) + (m > 159 ? 'a' - 10 : '0')); - m &= 0x0F; - *t++ = (char)(m + (m > 9 ? 'a' - 10 : '0')); - } - } - *t++ = '\0'; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_hex2s(struct soap *soap, const char *s, char *t, size_t l, int *n) -{ register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = strlen(s) / 2; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - while (l) - { register int d1, d2; - d1 = *s++; - if (!d1) - break; - d2 = *s++; - if (!d2) - break; - *t++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0'); - l--; - } - if (n) - *n = t - p; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_puthttphdr(struct soap *soap, int status, size_t count) -{ register const char *s = NULL; - register int err = SOAP_OK; -#ifndef WITH_LEANER - register const char *r = NULL; -#endif - if (status == SOAP_FILE && soap->http_content) - s = soap->http_content; - else if (status == SOAP_HTML) - s = "text/html; charset=utf-8"; - else if (count) - { 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_DIME | SOAP_ENC_MTOM)) - { if (soap->mode & SOAP_ENC_MTOM) - { r = s; - s = "application/xop+xml; charset=utf-8"; - } - else - s = "application/dime"; - } - if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && soap->status != SOAP_GET) - { register const char *t = strchr(s, ';'); - sprintf(soap->tmpbuf, "multipart/related; boundary=\"%s\"; type=\"", soap->mime.boundary); - if (t) - strncat(soap->tmpbuf, s, t - s); - else - strcat(soap->tmpbuf, s); - if (soap->mime.start) - { strcat(soap->tmpbuf, "\"; start=\""); - strcat(soap->tmpbuf, soap->mime.start); - } - strcat(soap->tmpbuf, "\""); - if (r) - { strcat(soap->tmpbuf, "; start-info=\""); - strcat(soap->tmpbuf, r); - strcat(soap->tmpbuf, "\""); - } - s = soap->tmpbuf; - } -#endif - if (s && (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 -#ifndef WITH_LEANER - if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK) - err = soap->fposthdr(soap, "Transfer-Encoding", "chunked"); - else -#endif - if (soap->status != SOAP_GET) - { 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_get(struct soap *soap) -{ return SOAP_GET_METHOD; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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"; - 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 == '/' ? path + 1 : 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_response(struct soap *soap, int status, size_t count) -{ register int err; -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - httpOutputEnable(soap->rpmreqid); -#endif - if (!status || status == SOAP_HTML || status == SOAP_FILE) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "OK 200\n")); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif - { 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; -#ifndef WITH_LEAN - 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; - } -#endif - } - 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)); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif - { 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 -#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; -#ifndef WITH_NOHTTP - 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; -#ifndef WITH_LEANER - if ((n & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = n; - } -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static const char* -soap_set_validation_fault(struct soap *soap, const char *s, const char *t) -{ if (*soap->tag) - sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element <%s>", s, t?t:SOAP_STR_EOS, soap->tag); - else - sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t?t:SOAP_STR_EOS); - 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 && !*s && soap->fseterror) - soap->fseterror(soap, c, s); - 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_TYPE: - *s = soap_set_validation_fault(soap, "data type mismatch ", soap->type); - break; - case SOAP_SYNTAX_ERROR: - *s = "Well-formedness violation"; - break; - case SOAP_NO_TAG: - *s = "No XML element tag"; - 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_USER_ERROR: - *s = "User error"; - 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_DUPLICATE_ID: - *s = soap_set_validation_fault(soap, "multiple definitions of id ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:DuplicateID"; - break; - case SOAP_MISSING_ID: - *s = soap_set_validation_fault(soap, "missing id for ref ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:MissingID"; - break; - case SOAP_HREF: - *s = soap_set_validation_fault(soap, "incompatible object ref ", soap->id); - break; - case SOAP_FAULT: - break; -#ifndef WITH_NOIO - case SOAP_UDP_ERROR: - *s = "Message too large for UDP packet"; - break; - case SOAP_TCP_ERROR: - *s = tcp_error(soap); - break; -#endif - case SOAP_HTTP_ERROR: - *s = "HTTP error"; - break; - case SOAP_SSL_ERROR: -#ifdef WITH_OPENSSL - *s = "SSL error"; -#else - *s = "OpenSSL not installed: recompile with -DWITH_OPENSSL"; -#endif - break; - case SOAP_PLUGIN_ERROR: - *s = "Plugin registry error"; - break; - case SOAP_DIME_ERROR: - *s = "DIME format error"; - break; - case SOAP_DIME_HREF: - *s = "DIME href to missing attachment"; - break; - case SOAP_DIME_MISMATCH: - *s = "DIME version/transmission error"; - break; - case SOAP_DIME_END: - *s = "End of DIME error"; - break; - case SOAP_MIME_ERROR: - *s = "MIME format error"; - break; - case SOAP_MIME_HREF: - *s = "MIME href to missing attachment"; - break; - case SOAP_MIME_END: - *s = "End of MIME 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/gzip not installed for (de)compression: recompile with -DWITH_GZIP"; -#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, "min/maxOccurs violation", NULL); - break; - case SOAP_LENGTH: - *s = soap_set_validation_fault(soap, "content length violation", NULL); - break; - case SOAP_STOP: - *s = "Stopped: no response sent"; - break; -#endif - case SOAP_EOF: -#ifndef WITH_NOIO - sprintf(soap->msgbuf, "End of file or no input: '%s'", soap_strerror(soap)); - *s = soap->msgbuf; - break; -#else - *s = "End of file or no input"; - break; -#endif - default: -#ifndef WITH_NOHTTP -#ifndef WITH_LEAN - if (soap->error > 200 && soap->error < 600) - { sprintf(soap->msgbuf, "HTTP Error: %d %s", soap->error, http_error(soap, soap->error)); - *s = soap->msgbuf; - } - else -#endif -#endif - { sprintf(soap->msgbuf, "Error %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; - int r = 1; - 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); -#ifndef WITH_NOIO -#ifndef WITH_LEAN - if (soap_valid_socket(soap->socket)) - { struct timeval timeout; - fd_set rfd, sfd; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_SET((SOAP_SOCKET)soap->socket, &rfd); - FD_SET((SOAP_SOCKET)soap->socket, &sfd); - r = select((SOAP_SOCKET)(soap->socket + 1), &rfd, &sfd, NULL, &timeout); - if (r > 0) - { if (!FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - || (FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - && recv((SOAP_SOCKET)soap->socket, soap->tmpbuf, 1, MSG_PEEK) < 0)) - r = 0; - } - } -#endif -#endif - if ((status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) && r > 0) - { 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); - } - soap_end_count(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 WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_send_empty_response(struct soap *soap) -{ soap->count = 0; - if (soap_response(soap, SOAP_OK) || soap_end_send(soap)) - return soap_closesock(soap); - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_recv_empty_response(struct soap *soap) -{ if (soap_begin_recv(soap) || soap_end_recv(soap)) - return soap_closesock(soap); - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static const char* -soap_strerror(struct soap *soap) -{ register int err = soap->errnum; - if (err) - { -#ifndef WIN32 - return strerror(err); -#else - FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)&soap->errorstr, sizeof(soap->errorstr), NULL); - return soap->errorstr; -#endif - } - return "Operation interrupted or timed out"; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_set_error(struct soap *soap, const char *faultcode, const char *faultsubcode, const char *faultstring, const char *faultdetail, int soaperror) -{ *soap_faultcode(soap) = faultcode; - if (faultsubcode) - *soap_faultsubcode(soap) = faultsubcode; - *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", NULL, 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", NULL, faultstring, faultdetail, soaperror); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ char *r = NULL, *s = NULL, *t = NULL; - if (faultsubcode) - r = soap_strdup(soap, faultsubcode); - if (faultstring) - s = soap_strdup(soap, faultstring); - if (faultdetail) - t = soap_strdup(soap, faultdetail); - return soap_set_error(soap, faultcode, r, 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_sender_fault_subcode(soap, NULL, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultsubcode, 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_receiver_fault_subcode(soap, NULL, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultsubcode, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault(struct soap *soap, FILE *fd) -{ if (soap->error) - { const char *c, *v = NULL, *s, **d; - d = soap_faultcode(soap); - if (!*d) - soap_set_fault(soap); - c = *d; - if (soap->version == 2) - v = *soap_faultsubcode(soap); - s = *soap_faultstring(soap); - d = soap_faultdetail(soap); - fprintf(fd, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]"); - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault_location(struct soap *soap, FILE *fd) -{ -#ifndef WITH_LEAN - int i, j, c1, c2; - if (soap->error && soap->buflen > 0) - { i = (int)soap->bufidx - 1; - if (i <= 0) - i = 0; - c1 = soap->buf[i]; - soap->buf[i] = '\0'; - if ((int)soap->buflen >= i + 1024) - j = i + 1023; - else - j = (int)soap->buflen - 1; - c2 = soap->buf[j]; - soap->buf[j] = '\0'; - fprintf(fd, "%s%c\n** HERE **\n", soap->buf, c1); - if (soap->bufidx < soap->buflen) - fprintf(fd, "%s\n", soap->buf + soap->bufidx); - soap->buf[i] = c1; - soap->buf[j] = c2; - } -#endif -} -#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(soap, 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(soap, 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 - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.h b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.h deleted file mode 100644 index 6047fb6..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.6d.h +++ /dev/null @@ -1,2075 +0,0 @@ -/* - -stdsoap2.h 2.7.6d - -gSOAP runtime - -gSOAP XML Web services tools -Copyright (C) 2000-2005, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under one of the following licenses: -GPL, the gSOAP public license, or Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems, Inc., for the following additions (marked WR[...]): - - vxWorks compatible --------------------------------------------------------------------------------- -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-2005, 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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- -*/ - -#ifdef WITH_SOAPDEFS_H -# include "soapdefs.h" /* include user-defined stuff */ -#endif - -#ifndef _THREAD_SAFE -# define _THREAD_SAFE -#endif - -#ifndef OPENSERVER -# ifndef _REENTRANT -# define _REENTRANT -# endif -#endif - -#ifndef SOAP_FMAC1 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC1 -#endif - -#ifndef SOAP_FMAC2 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC2 -#endif - -#ifndef SOAP_FMAC3 /* (de)serializer declaration macro */ -# define SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC3S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC3S SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC4 /* (de)serializer declaration macro */ -# define SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC4S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC4S SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC5 /* stub/skeleton declaration macro */ -# define SOAP_FMAC5 -#endif - -#ifndef SOAP_FMAC6 /* stub/skeleton declaration macro */ -# define SOAP_FMAC6 -#endif - -#ifndef SOAP_CMAC /* class declaration macro */ -# define SOAP_CMAC -#endif - -#ifndef SOAP_NMAC /* namespace table declaration macro */ -# define SOAP_NMAC -#endif - -#ifndef SOAP_SOURCE_STAMP -# define SOAP_SOURCE_STAMP(str) -#endif - -/* gSOAP 2.7.4 and higher: fast look-aside buffering is stable */ -#ifndef WITH_FAST -# define WITH_FAST -#endif - -#ifdef WITH_LEANER -# ifndef WITH_LEAN -# define WITH_LEAN -# endif -#endif - -#ifdef WITH_LEAN -# ifdef WITH_COOKIES -# error "Cannot build WITH_LEAN code WITH_COOKIES enabled" -# endif -#endif - -#ifndef STDSOAP_H -#define STDSOAP_H - -#if defined(__vxworks) || defined(__VXWORKS__) -# define VXWORKS -#endif - -#ifdef _WIN32 -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef UNDER_CE -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef __BORLANDC__ -# ifdef __WIN32__ -# ifndef WIN32 -# define WIN32 -# endif -# endif -#endif - -#ifdef __CYGWIN__ -# ifndef CYGWIN -# define CYGWIN -# endif -#endif - -#ifdef __SYMBIAN32__ -# define SYMBIAN -# undef WIN32 -#endif - -#if defined(__palmos__) || defined(PALM_GCC) || defined(__PALMOS_TRAPS__) -# ifndef PALM -# define PALM -# endif -#endif - -#if defined(__hpux) -# ifndef HP_UX -# define HP_UX -# endif -#endif - -#if defined(__alpha) && !defined(__VMS) -# ifndef TRU64 -# define TRU64 -# endif -#endif - -#ifdef __MVS__ -# ifndef OS390 -# define OS390 -# endif -#endif - -#ifdef HAVE_CONFIG_H -# include "config.h" -# ifdef WITH_OPENSSL -# ifndef HAVE_OPENSSL_SSL_H -# undef WITH_OPENSSL -# endif -# endif -#else -# if defined(UNDER_CE) -# define WITH_LEAN -# define HAVE_SSCANF -# elif defined(WIN32) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%I64d" -# define SOAP_ULONG_FORMAT "%I64u" -# elif defined(CYGWIN) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__APPLE__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(_AIXVERSION_431) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(HP_UX) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(FREEBSD) || defined(__FreeBSD__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_GETTIMEOFDAY -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%qd" -# define SOAP_ULONG_FORMAT "%qu" -# elif defined(__VMS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__GLIBC__) || defined(__GNU__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define HAVE_ISNAN -# elif defined(TRU64) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_GETTIMEOFDAY -# define HAVE_SYS_TIMEB_H -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define __USE_STD_IOSTREAM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -# elif defined(MAC_CARBON) -# define WITH_NOIO -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(PALM) -# define WITH_LEAN -# define HAVE_STRTOD /* strtod() is defined in palmFunctions.h */ -# include /* Needs to be included before unix headers */ -# include -# define IGNORE_STDIO_STUBS -# include -# define O_NONBLOCK FNONBIO -# include -# include "palmFunctions.h" -# elif defined(SYMBIAN) -# define WITH_LEAN -# define WITH_NONAMESPACES -# define HAVE_STRTOD /* use STRTOD since sscanf doesn't seem to work */ -# include -# include -# elif defined(VXWORKS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_PGMTIME_R -# define HAVE_PLOCALTIME_R -# define HAVE_MKTIME -# elif defined(OS390) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(AS400) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# else -/* Default asumptions on supported functions */ -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# endif -#endif - -/* QNX does not have a working version of strtof */ -#if defined(__QNX__) || defined(QNX) -# undef HAVE_STRTOF -#endif - -#ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%lld" /* printf format for 64 bit ints */ -#endif - -#ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%llu" /* printf format for unsigned 64 bit ints */ -#endif - -#ifndef WITH_NOSTDLIB -# include -# ifndef PALM -# include -# include -# endif -# include -# include -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -# include -# include -#endif - -#ifdef WITH_NOHTTP -# ifndef WITH_NOIO -# define WITH_NOIO -# undef WITH_COOKIES -# endif -#endif - -#ifndef UNDER_CE -# ifndef PALM -# ifndef WITH_NOIO -# include -# include -# endif -# ifndef WITH_LEAN -# ifdef HAVE_SYS_TIMEB_H -# include /* for ftime() */ -# endif -# include -# endif -# endif -#endif - -#ifdef OPENSERVER -# include -# include -# include - extern int h_errno; -#endif - -#ifndef WITH_NOIO -# ifndef WIN32 -# ifndef PALM -# include -# ifdef VXWORKS -# include -# include -# endif -# ifndef VXWORKS -# ifndef SYMBIAN -# include -# endif -# endif -# ifdef SUN_OS -# include /* SUN */ -# include /* SUN < 2.8 (?) */ -# endif -# ifdef VXWORKS -# ifdef _WRS_KERNEL -# include -# endif -# else -# include -# endif -# include -# ifdef OS390 -# include -# else -# include /* TCP_NODELAY */ -# endif -# include -# endif -# endif -#endif - -#ifdef WITH_FASTCGI -# include -#endif - -#ifdef WITH_OPENSSL -# define OPENSSL_NO_KRB5 -# include -# include -# include -# ifndef ALLOW_OLD_VERSIONS -# if (OPENSSL_VERSION_NUMBER < 0x00905100L) -# error "Must use OpenSSL 0.9.6 or later" -# endif -# endif -#endif - -#ifdef WITH_GZIP -# ifndef WITH_ZLIB -# define WITH_ZLIB -# endif -#endif - -#ifdef WITH_CASEINSENSITIVETAGS -# define SOAP_STRCMP soap_tag_cmp /* case insensitve XML element/attribute names */ -#else -# define SOAP_STRCMP strcmp /* case sensitive XML element/attribute names */ -#endif - -#ifdef WITH_ZLIB -# include -#endif - -#ifndef WITH_NOSTDLIB -# ifndef PALM -# include /* for isnan() */ -# endif -#endif - -/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef WIN32 -# ifndef UNDER_CE -# include -# include -# endif -# include -/* # include */ /* Alternative: use winsock2 (not available with eVC) */ -# ifdef WITH_IPV6 -# include -# include -# endif -#else -# ifdef VXWORKS -# include -# include -# include -# endif -# ifndef WITH_NOIO -# ifndef PALM -# include -# include -# include -# include -# endif -# endif -#endif - -/* Portability: define SOAP_SOCKLEN_T */ -#if defined(_AIX) -# define SOAP_SOCKLEN_T socklen_t -#elif defined(SOCKLEN_T) -# define SOAP_SOCKLEN_T SOCKLEN_T -#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(__QNX__) || defined(QNX) -# define SOAP_SOCKLEN_T socklen_t -#elif defined(IRIX) || defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS) -# define SOAP_SOCKLEN_T int -#else -# define SOAP_SOCKLEN_T size_t -#endif - -#ifndef SOAP_SOCKET -# ifdef WIN32 -# define SOAP_SOCKET SOCKET -# else -# define SOAP_SOCKET int -# define closesocket(n) close(n) -# endif -#endif - -#define SOAP_INVALID_SOCKET (-1) -#define soap_valid_socket(n) ((n) != SOAP_INVALID_SOCKET) - -#if defined(SYMBIAN) -# define LONG64 long -# define ULONG64 unsigned LONG64 -#elif !defined(WIN32) || defined(__GLIBC__) || defined(__GNU__) -# ifndef LONG64 -# define LONG64 long long -# define ULONG64 unsigned LONG64 -# endif -#elif defined(UNDER_CE) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#elif defined(__BORLANDC__) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#endif - -#if defined(WIN32) -# define soap_int32 __int32 -#elif defined(SYMBIAN) -# define soap_int32 long -#elif defined(PALM) -# define soap_int32 Int32 -#else -# define soap_int32 int32_t -#endif - -#ifdef WIN32 -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR WSAEINTR -# define SOAP_EAGAIN WSAEWOULDBLOCK -# define SOAP_EWOULDBLOCK WSAEWOULDBLOCK -# define SOAP_EINPROGRESS WSAEINPROGRESS -#else -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR EINTR -# define SOAP_EAGAIN EAGAIN -# ifdef SYMBIAN -# define SOAP_EWOULDBLOCK 9898 -# define SOAP_EINPROGRESS 9899 -# else -# define SOAP_EWOULDBLOCK EWOULDBLOCK -# define SOAP_EINPROGRESS EINPROGRESS -# endif -#endif - -#ifdef WIN32 -# ifdef UNDER_CE -# define soap_errno GetLastError() -# define soap_socket_errno GetLastError() -# define soap_reset_errno SetLastError(0) -# else -# define soap_errno GetLastError() -# define soap_socket_errno WSAGetLastError() -# define soap_reset_errno SetLastError(0) -# endif -#else -# ifndef WITH_NOIO -# define soap_errno errno -# define soap_socket_errno errno -# define soap_reset_errno (errno = 0) -# else -# define soap_errno 0 -# define soap_socket_errno 0 -# define soap_reset_errno -# endif -#endif - -#ifndef SOAP_BUFLEN -# ifdef WITH_UDP -# define SOAP_BUFLEN (65536) /* max UDP packet size */ -# else -# ifndef WITH_LEAN -# define SOAP_BUFLEN (65536) /* buffer length for socket packets, also used by gethostbyname_r so don't make this too small */ -# else -# define SOAP_BUFLEN (2048) -# endif -# endif -#endif -#ifndef SOAP_LABLEN -# define SOAP_LABLEN (64) /* initial look-aside buffer length */ -#endif -#ifndef SOAP_PTRBLK -# define SOAP_PTRBLK (32) /* block allocation for pointer hash table chains */ -#endif -#ifndef SOAP_PTRHASH -# ifndef WITH_LEAN -# define SOAP_PTRHASH (1024) /* size of pointer analysis hash table (must be power of 2) */ -# else -# define SOAP_PTRHASH (32) -# endif -#endif -#ifndef SOAP_IDHASH -# ifndef WITH_LEAN -# define SOAP_IDHASH (1999) /* prime size of hash table for parsed id/ref */ -# else -# define SOAP_IDHASH (19) /* 19, 199 */ -# endif -#endif -#ifndef SOAP_BLKLEN -# ifndef WITH_LEAN -# define SOAP_BLKLEN (256) /* size of blocks to collect long strings and XML attributes */ -# else -# define SOAP_BLKLEN (32) -# endif -#endif -#ifndef SOAP_TAGLEN -# ifndef WITH_LEAN -# define SOAP_TAGLEN (1024) /* maximum length of XML element tag/attribute name or host/path name + 1 */ -# else -# define SOAP_TAGLEN (64) -# endif -#endif -#ifndef SOAP_HDRLEN -# ifndef WITH_LEAN -# define SOAP_HDRLEN (8192) /* maximum length of HTTP header line (must be >4096 to read cookies) */ -# else -# define SOAP_HDRLEN (1024) -# endif -#endif -#ifndef SOAP_MAXDIMS -# ifndef WITH_LEAN -# define SOAP_MAXDIMS (16) /* maximum array dimensions (array nestings) must be less than 64 to protect soap->tmpbuf */ -# else -# define SOAP_MAXDIMS (4) -# endif -#endif - -#ifndef SOAP_MAXLOGS -# define SOAP_MAXLOGS (3) /* max number of debug logs per struct soap environment */ -# define SOAP_INDEX_RECV (0) -# define SOAP_INDEX_SENT (1) -# define SOAP_INDEX_TEST (2) -#endif - -#ifndef SOAP_MAXKEEPALIVE -# define SOAP_MAXKEEPALIVE (100) /* max iterations to keep server connection alive */ -#endif - -#ifndef SOAP_MAXARRAYSIZE -# define SOAP_MAXARRAYSIZE (100000) /* "trusted" max size of inbound SOAP array for compound array allocation */ -#endif - -#ifdef VXWORKS -# ifdef __INCmathh -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) isNan(num) -# endif -#endif - -#ifdef WIN32 -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) _isnan(num) -#endif - -#ifdef SUN_OS -# define soap_isnan(n) isnan(n) -#endif - -#if !defined(HAVE_ISNAN) && (defined(_MATH_H) || defined(_MATH_INCLUDED)) -# define HAVE_ISNAN -#endif - -#ifndef soap_isnan -# ifdef HAVE_ISNAN -# define soap_isnan(n) isnan(n) -# else -# define soap_isnan(_) (0) -# endif -#endif - -extern const struct soap_double_nan { unsigned int n1, n2; } soap_double_nan; - -#ifdef VXWORKS -# ifndef FLT_MAX -# define FLT_MAX _ARCH_FLT_MAX -# endif -# ifndef DBL_MAX -# define DBL_MAX _ARCH_DBL_MAX -# endif -#endif - -#ifndef FLT_NAN -# ifdef HAVE_ISNAN -# define FLT_NAN (*(float*)(void*)&soap_double_nan) -# else -# define FLT_NAN (0.0) -# endif -#endif - -#ifndef FLT_PINFTY -# if defined(FLT_MAX) -# define FLT_PINFTY FLT_MAX -# elif defined(HUGE_VALF) -# define FLT_PINFTY (float)HUGE_VALF -# elif defined(HUGE_VAL) -# define FLT_PINFTY (float)HUGE_VAL -# elif defined(FLOAT_MAX) -# define FLT_PINFTY FLOAT_MAX -# else -# define FLT_PINFTY (3.40282347e+38F) -# endif -#endif - -#ifndef FLT_NINFTY -# define FLT_NINFTY (-FLT_PINFTY) -#endif - -#ifndef DBL_NAN -# ifdef HAVE_ISNAN -# define DBL_NAN (*(double*)(void*)&soap_double_nan) -# else -# define DBL_NAN (0.0) -# endif -#endif - -#ifndef DBL_PINFTY -# if defined(DBL_MAX) -# define DBL_PINFTY DBL_MAX -# elif defined(HUGE_VALF) -# define DBL_PINFTY (double)HUGE_VALF -# elif defined(HUGE_VAL) -# define DBL_PINFTY (double)HUGE_VAL -# elif defined(DOUBLE_MAX) -# define DBL_PINFTY DOUBLE_MAX -# else -# define DBL_PINFTY (1.7976931348623157e+308) -# endif -#endif - -#ifndef DBL_NINFTY -# define DBL_NINFTY (-DBL_PINFTY) -#endif - -#define soap_ispinfd(n) ((n) >= DBL_PINFTY) -#define soap_ispinff(n) ((n) >= FLT_PINFTY) -#define soap_isninfd(n) ((n) <= DBL_NINFTY) -#define soap_isninff(n) ((n) <= FLT_NINFTY) - -/* gSOAP error codes */ - -#define SOAP_EOF EOF -#define SOAP_ERR EOF -#define SOAP_OK 0 -#define SOAP_CLI_FAULT 1 -#define SOAP_SVR_FAULT 2 -#define SOAP_TAG_MISMATCH 3 -#define SOAP_TYPE 4 -#define SOAP_SYNTAX_ERROR 5 -#define SOAP_NO_TAG 6 -#define SOAP_IOB 7 -#define SOAP_MUSTUNDERSTAND 8 -#define SOAP_NAMESPACE 9 -#define SOAP_USER_ERROR 10 -#define SOAP_FATAL_ERROR 11 -#define SOAP_FAULT 12 -#define SOAP_NO_METHOD 13 -#define SOAP_GET_METHOD 14 -#define SOAP_EOM 15 -#define SOAP_NULL 16 -#define SOAP_DUPLICATE_ID 17 -#define SOAP_MISSING_ID 18 -#define SOAP_HREF 19 -#define SOAP_UDP_ERROR 20 -#define SOAP_TCP_ERROR 21 -#define SOAP_HTTP_ERROR 22 -#define SOAP_SSL_ERROR 23 -#define SOAP_ZLIB_ERROR 24 -#define SOAP_DIME_ERROR 25 -#define SOAP_DIME_HREF 26 -#define SOAP_DIME_MISMATCH 27 -#define SOAP_DIME_END 28 -#define SOAP_MIME_ERROR 29 -#define SOAP_MIME_HREF 30 -#define SOAP_MIME_END 31 -#define SOAP_VERSIONMISMATCH 32 -#define SOAP_PLUGIN_ERROR 33 -#define SOAP_DATAENCODINGUNKNOWN 34 -#define SOAP_REQUIRED 35 -#define SOAP_PROHIBITED 36 -#define SOAP_OCCURS 37 -#define SOAP_LENGTH 38 - -#define soap_xml_error_check(e) ((e) == SOAP_TAG_MISMATCH || (e) == SOAP_TAG_END || (e) == SOAP_SYNTAX_ERROR || (e) == SOAP_NAMESPACE || (e) == SOAP_DUPLICATE_ID || (e) == SOAP_MISSING_ID || (e) == SOAP_REQUIRED || (e) == SOAP_PROHIBITED || (e) == SOAP_OCCURS || (e) == SOAP_LENGTH || (e) == SOAP_NULL || (e) == SOAP_HREF) -#define soap_soap_error_check(e) ((e) == SOAP_CLI_FAULT || (e) == SOAP_SVR_FAULT || (e) == SOAP_VERSIONMISMATCH || (e) == SOAP_MUSTUNDERSTAND || (e) == SOAP_FAULT || (e) == SOAP_NO_METHOD) -#define soap_tcp_error_check(e) ((e) == SOAP_EOF || (e) == SOAP_TCP_ERROR) -#define soap_ssl_error_check(e) ((e) == SOAP_SSL_ERROR) -#define soap_zlib_error_check(e) ((e) == SOAP_ZLIB_ERROR) -#define soap_http_error_check(e) ((e) == SOAP_HTTP_ERROR || (e) == SOAP_GET_METHOD || ((e) >= 100 && (e) < 600)) - -/* gSOAP HTTP response status codes 100 to 599 are reserved */ - -/* Codes 600 to 999 are user definable */ - -/* Exceptional gSOAP HTTP response status codes >= 1000 */ - -#define SOAP_STOP 1000 /* No HTTP response */ -#define SOAP_FORM 1001 /* Form request/response */ -#define SOAP_HTML 1002 /* Custom HTML response */ -#define SOAP_FILE 1003 /* Custom file-based response */ - -/* gSOAP HTTP method codes */ - -#define SOAP_POST 2000 -#define SOAP_GET 2001 - -/* gSOAP DIME */ - -#define SOAP_DIME_CF 0x01 -#define SOAP_DIME_ME 0x02 -#define SOAP_DIME_MB 0x04 -#define SOAP_DIME_VERSION 0x08 /* DIME version 1 */ -#define SOAP_DIME_MEDIA 0x10 -#define SOAP_DIME_ABSURI 0x20 - -/* gSOAP ZLIB */ - -#define SOAP_ZLIB_NONE 0x00 -#define SOAP_ZLIB_DEFLATE 0x01 -#define SOAP_ZLIB_INFLATE 0x02 -#define SOAP_ZLIB_GZIP 0x02 - -/* gSOAP transport, connection, and content encoding modes */ - -typedef soap_int32 soap_mode; - -#define SOAP_IO 0x00000003 /* IO mask */ -#define SOAP_IO_FLUSH 0x00000000 /* flush output immediately, no buffering */ -#define SOAP_IO_BUFFER 0x00000001 /* buffer output in packets of size SOAP_BUFLEN */ -#define SOAP_IO_STORE 0x00000002 /* store entire output to determine length for transport */ -#define SOAP_IO_CHUNK 0x00000003 /* use HTTP chunked transfer AND buffer packets */ - -#define SOAP_IO_UDP 0x00000004 -#define SOAP_IO_LENGTH 0x00000008 -#define SOAP_IO_KEEPALIVE 0x00000010 - -#define SOAP_ENC_LATIN 0x00800020 /* iso-8859-1 encoding */ -#define SOAP_ENC_XML 0x00000040 /* plain XML encoding, no HTTP header */ -#define SOAP_ENC_DIME 0x00000080 -#define SOAP_ENC_MIME 0x00000100 -#define SOAP_ENC_MTOM 0x00000200 -#define SOAP_ENC_ZLIB 0x00000400 -#define SOAP_ENC_SSL 0x00000800 - -#define SOAP_ENC 0x00000FFF /* IO and ENC mask */ - -#define SOAP_XML_STRICT 0x00001000 /* strict validation */ -#define SOAP_XML_INDENT 0x00002000 -#define SOAP_XML_CANONICAL 0x00004000 /* EXC C14N canonical XML */ -#define SOAP_XML_TREE 0x00008000 -#define SOAP_XML_GRAPH 0x00010000 -#define SOAP_XML_NIL 0x00020000 -#define SOAP_XML_DOM 0x00040000 -#define SOAP_XML_SEC 0x00080000 /* reserved for WS security */ - -#define SOAP_C_NOIOB 0x00100000 -#define SOAP_C_UTFSTRING 0x00200000 -#define SOAP_C_MBSTRING 0x00400000 - -#define SOAP_DOM_TREE 0x01000000 -#define SOAP_DOM_NODE 0x02000000 -#define SOAP_DOM_ASIS 0x04000000 - -#define SOAP_IO_DEFAULT SOAP_IO_FLUSH - -/* SSL client/server authentication settings */ - -#define SOAP_SSL_NO_AUTHENTICATION 0x00 /* for testing purposes */ -#define SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION 0x01 /* client requires server to authenticate */ -#define SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION 0x02 /* server requires client to authenticate */ - -#define SOAP_SSL_DEFAULT SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION - -/* */ - -#define SOAP_BEGIN 0 -#define SOAP_IN_ENVELOPE 2 -#define SOAP_IN_HEADER 3 -#define SOAP_END_HEADER 4 -#define SOAP_NO_BODY 5 -#define SOAP_IN_BODY 6 -#define SOAP_END_BODY 7 -#define SOAP_END_ENVELOPE 8 -#define SOAP_END 9 -#define SOAP_BEGIN_SECURITY 10 -#define SOAP_IN_SECURITY 11 -#define SOAP_END_SECURITY 12 - -/* DEBUG macros */ - -#ifndef WITH_LEAN -# ifdef DEBUG -# ifndef SOAP_DEBUG -# define SOAP_DEBUG -# endif -# endif -#endif - -#ifdef SOAP_DEBUG -# define SOAP_MALLOC(soap, size) soap_track_malloc(soap, __FILE__, __LINE__, size) -# define SOAP_FREE(soap, ptr) soap_track_free(soap, __FILE__, __LINE__, ptr) -#endif - -#ifndef SOAP_MALLOC /* use libc malloc */ -# define SOAP_MALLOC(soap, size) malloc(size) -#endif - -#ifndef SOAP_FREE /* use libc free */ -# define SOAP_FREE(soap, ptr) free(ptr) -#endif - -#ifdef SOAP_DEBUG -# ifndef SOAP_MESSAGE -# define SOAP_MESSAGE fprintf -# endif -# ifndef DBGLOG -# define DBGLOG(DBGFILE, CMD) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ - CMD;\ - fflush(fdebug);\ - }\ - }\ -} -# endif -# ifndef DBGMSG -# define DBGMSG(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { fwrite((MSG), 1, (LEN), soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -# ifndef DGBFUN -# define DBGFUN(FNAME) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s()\n", __FILE__, __LINE__, FNAME)) -# define DBGFUN1(FNAME, FMT, ARG) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT")\n", __FILE__, __LINE__, FNAME, (ARG))) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2))) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2", "FMT3")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2), (ARG3))) -# endif -# ifndef DBGHEX -# define DBGHEX(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { int i; char *s;\ - for (s = (char*)(MSG), i = (LEN); i; i--)\ - fprintf(soap->fdebug[SOAP_INDEX_##DBGFILE], "%2.2hhX ", *s++);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -#else -# define DBGLOG(DBGFILE, CMD) -# define DBGMSG(DBGFILE, MSG, LEN) -# define DBGFUN(FNAME) -# define DBGFUN1(FNAME, FMT, ARG) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) -# define DBGHEX(DBGFILE, MSG, LEN) -#endif - -/* UCS-4 requires 32 bits (0-7FFFFFFF, the sign bit is used by gSOAP to distinguish XML entities) */ -typedef soap_int32 soap_wchar; - -/* namespace table row */ -struct Namespace -{ const char *id; - const char *ns; - const char *in; - char *out; -}; - -/* namespace stack */ -struct soap_nlist -{ struct soap_nlist *next; - unsigned int level; /* nesting depth level */ - short index; /* corresponding entry in ns mapping table */ - char *ns; /* only set when parsed ns URI is not in the ns mapping table */ - char id[1]; /* the actual string value flows into the allocated region below this struct */ -}; - -/* block stack for nested block allocations */ -struct soap_blist -{ struct soap_blist *next; - char *ptr; - size_t size; -}; - -/* array layout */ -struct soap_array -{ void *__ptr; - int __size; -}; - -/* pointer serialization management */ -struct soap_plist -{ struct soap_plist *next; - const void *ptr; - const struct soap_array *array; - int type; - int id; - char mark1; - char mark2; -}; - -/* block allocation for pointer serialization management */ -struct soap_pblk -{ struct soap_pblk *next; - struct soap_plist plist[SOAP_PTRBLK]; -}; - -#ifdef SOAP_DEBUG -/* malloc/free tracking for debugging */ -struct soap_mlist -{ struct soap_mlist *next; - const void *ptr; - const char *file; - int line; - short live; -}; -#endif - -/* class allocation list */ -struct soap_clist -{ struct soap_clist *next; - void *ptr; - int type; - int size; - void (*fdelete)(struct soap_clist*); -}; - -/* attributes */ -struct soap_attribute -{ struct soap_attribute *next; - char *value; - size_t size; - char *ns; - short visible; - char name[1]; /* the actual name string flows into the allocated region below this struct */ -}; - -struct soap_cookie -{ struct soap_cookie *next; - char *name; - char *value; - char *domain; - char *path; - long expire; /* client-side: local time to expire; server-side: seconds to expire */ - unsigned int version; - short secure; - short session; /* server-side */ - short env; /* server-side: got cookie from client and should not be (re)send */ - short modified; /* server-side: client cookie was modified and should be send */ -}; - -#ifdef __cplusplus -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); - -class soap_multipart_iterator -{ public: - struct soap_multipart *content; - bool operator==(const soap_multipart_iterator& iter) const - { return content == iter.content; } - bool operator!=(const soap_multipart_iterator& iter) const - { return content != iter.content; } - struct soap_multipart &operator*() const - { return *content; } - soap_multipart_iterator &operator++() - { content = soap_next_multipart(content); return *this; } - soap_multipart_iterator() : content(NULL) - { } - soap_multipart_iterator(struct soap_multipart *p) : content(p) - { } -}; -#endif - -#ifndef WITH_LEANER -struct soap_dime -{ size_t count; - size_t size; - size_t chunksize; - size_t buflen; - char flags; - char *ptr; - const char *id; - const char *type; - const char *options; - struct soap_multipart *list; /* list of DIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -struct soap_mime -{ char *boundary; /* MIME boundary */ - const char *start; /* MIME start ID */ - struct soap_multipart *list; /* list of MIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* RFC2045 MIME content transfer encodings */ -enum soap_mime_encoding -{ SOAP_MIME_NONE, - SOAP_MIME_7BIT, - SOAP_MIME_8BIT, - SOAP_MIME_BINARY, - SOAP_MIME_QUOTED_PRINTABLE, - SOAP_MIME_BASE64, - SOAP_MIME_IETF_TOKEN, - SOAP_MIME_X_TOKEN -}; -#endif - -#ifndef WITH_LEANER -/* DIME/MIME multipart list */ -struct soap_multipart -{ struct soap_multipart *next; - char *ptr; /* points to raw data content */ - size_t size; /* size of data content */ - const char *id; /* DIME/MIME content ID or form data name */ - const char *type; /* DIME/MIME type (MIME type format) */ - const char *options; /* DIME options */ - enum soap_mime_encoding encoding; /* MIME Content-Transfer-Encoding */ - const char *location; /* MIME Content-Location (optional) */ - const char *description; /* MIME Content-Description (optional) */ -#ifdef __cplusplus - typedef soap_multipart_iterator iterator; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* attachment DIME and MTOM XOP forwarding */ -struct soap_xlist -{ struct soap_xlist *next; - unsigned char **ptr; - int *size; - char *id; - char **type; - char **options; -}; -#endif - -/******************************************************************************/ - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_attribute_iterator -{ public: - struct soap_dom_attribute *att; - const char *nstr; - const char *name; - bool operator==(const soap_dom_attribute_iterator&) const; - bool operator!=(const soap_dom_attribute_iterator&) const; - struct soap_dom_attribute &operator*() const; - soap_dom_attribute_iterator &operator++(); - soap_dom_attribute_iterator(); - soap_dom_attribute_iterator(struct soap_dom_attribute*); - ~soap_dom_attribute_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_attribute -{ struct soap_dom_attribute *next; - const char *nstr; - char *name; - char *data; - wchar_t *wide; - struct soap *soap; -#ifdef __cplusplus - typedef soap_dom_attribute_iterator iterator; - struct soap_dom_attribute &set(const char *nstr, const char *name); /* set namespace and name */ - struct soap_dom_attribute &set(const char *data); /* set data */ - soap_dom_attribute_iterator begin(); - soap_dom_attribute_iterator end(); - soap_dom_attribute_iterator find(const char *nstr, const char *name); - void unlink(); - soap_dom_attribute(); - soap_dom_attribute(struct soap *soap); - soap_dom_attribute(struct soap *soap, const char *nstr, const char *name, const char *data); - ~soap_dom_attribute(); -#endif -}; -#endif - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_element_iterator -{ public: - struct soap_dom_element *elt; - const char *nstr; - const char *name; - int type; - bool operator==(const soap_dom_element_iterator&) const; - bool operator!=(const soap_dom_element_iterator&) const; - struct soap_dom_element &operator*() const; - soap_dom_element_iterator &operator++(); - soap_dom_element_iterator(); - soap_dom_element_iterator(struct soap_dom_element*); - ~soap_dom_element_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_element -{ struct soap_dom_element *next; /* next sibling */ - struct soap_dom_element *prnt; /* parent */ - struct soap_dom_element *elts; /* list of child elements */ - struct soap_dom_attribute *atts; /* list of attributes */ - const char *nstr; /* namespace string */ - char *name; /* element tag name */ - char *data; /* element content data (with SOAP_C_UTFSTRING flag set) */ - wchar_t *wide; /* element content data */ - int type; /* optional: serialized C/C++ data type */ - void *node; /* optional: pointer to serialized C/C++ data */ - char *head; /* leading whitespace to start tag */ - char *tail; /* leading whitespace to end tag */ - struct soap *soap; /* soap context that manages this node */ -#ifdef __cplusplus - typedef soap_dom_element_iterator iterator; - struct soap_dom_element &set(const char *nstr, const char *name); - struct soap_dom_element &set(const char *data); - struct soap_dom_element &set(void *node, int type); - struct soap_dom_element &add(struct soap_dom_element*); - struct soap_dom_element &add(struct soap_dom_element&); - struct soap_dom_element &add(struct soap_dom_attribute*); - struct soap_dom_element &add(struct soap_dom_attribute&); - soap_dom_element_iterator begin(); - soap_dom_element_iterator end(); - soap_dom_element_iterator find(const char *nstr, const char *name); - soap_dom_element_iterator find(int type); - void unlink(); - soap_dom_element(); - soap_dom_element(struct soap *soap); - soap_dom_element(struct soap *soap, const char *nstr, const char *name); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type); - ~soap_dom_element(); -#endif -}; -SOAP_FMAC1 struct soap_dom_element * SOAP_FMAC2 soap_dom_next_element(struct soap_dom_element *elt); -SOAP_FMAC1 struct soap_dom_attribute * SOAP_FMAC2 soap_dom_next_attribute(struct soap_dom_attribute *att); -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -} -extern std::ostream &operator<<(std::ostream&, const struct soap_dom_element&); -extern std::istream &operator>>(std::istream&, struct soap_dom_element&); -extern "C" { -#endif - -/******************************************************************************/ - -struct soap -{ short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table) */ - short copy; /* 1 = copy of another soap struct */ - soap_mode mode; - soap_mode imode; - soap_mode omode; - const char *float_format; /* user-definable format string for floats (<1024 chars) */ - const char *double_format; /* user-definable format string for doubles (<1024 chars) */ - const char *dime_id_format; /* user-definable format string for integer DIME id ( 0, gives socket recv timeout in seconds, < 0 in usec */ - int send_timeout; /* when > 0, gives socket send timeout in seconds, < 0 in usec */ - int connect_timeout; /* when > 0, gives socket connect() timeout in seconds, < 0 in usec */ - int accept_timeout; /* when > 0, gives socket accept() timeout in seconds, < 0 in usec */ - int socket_flags; /* socket recv() and send() flags, e.g. set to MSG_NOSIGNAL to disable sigpipe */ - int connect_flags; /* connect() SOL_SOCKET sockopt flags, e.g. set to SO_DEBUG to debug socket */ - int bind_flags; /* bind() SOL_SOCKET sockopt flags, e.g. set to SO_REUSEADDR to enable reuse */ - int accept_flags; /* accept() SOL_SOCKET sockopt flags */ - const struct Namespace *namespaces; /* Pointer to global namespace mapping table */ - struct Namespace *local_namespaces; /* Local namespace mapping table */ - struct soap_nlist *nlist; /* namespace stack */ - struct soap_blist *blist; /* block allocation stack */ - struct soap_clist *clist; /* class instance allocation list */ - void *alist; /* memory allocation (malloc) list */ - struct soap_ilist *iht[SOAP_IDHASH]; - struct soap_plist *pht[SOAP_PTRHASH]; - struct soap_pblk *pblk; /* plist block allocation */ - short pidx; /* plist block allocation */ - struct SOAP_ENV__Header *header; - struct SOAP_ENV__Fault *fault; - int idnum; - void *user; /* to pass user-defined data */ - struct soap_plugin *plugins; /* linked list of plug-in data */ - char *userid; /* HTTP Basic authorization userid */ - char *passwd; /* HTTP Basic authorization passwd */ - int (*fpost)(struct soap*, const char*, const char*, int, const char*, const char*, size_t); - int (*fget)(struct soap*); - int (*fform)(struct soap*); - int (*fposthdr)(struct soap*, const char*, const char*); - int (*fresponse)(struct soap*, int, size_t); - int (*fparse)(struct soap*); - int (*fparsehdr)(struct soap*, const char*, const char*); - int (*fresolve)(struct soap*, const char*, struct in_addr* inaddr); - int (*fconnect)(struct soap*, const char*, const char*, int); - int (*fdisconnect)(struct soap*); - int (*fclosesocket)(struct soap*, SOAP_SOCKET); - int (*fshutdownsocket)(struct soap*, SOAP_SOCKET, int); - int (*fopen)(struct soap*, const char*, const char*, int); - int (*faccept)(struct soap*, int, struct sockaddr*, int *n); - int (*fclose)(struct soap*); - int (*fsend)(struct soap*, const char*, size_t); - size_t (*frecv)(struct soap*, char*, size_t); - int (*fpoll)(struct soap*); - void (*fseterror)(struct soap*, const char **c, const char **s); - int (*fignore)(struct soap*, const char*); - int (*fserveloop)(struct soap*); - void *(*fplugin)(struct soap*, const char*); -#ifndef WITH_LEANER - int (*fprepareinit)(struct soap*); - int (*fpreparesend)(struct soap*, const char*, size_t); - int (*fpreparerecv)(struct soap*, const char*, size_t); - int (*fpreparefinal)(struct soap*); - void *(*fdimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fdimewriteopen)(struct soap*, const char*, const char*, const char*); - void (*fdimereadclose)(struct soap*, void*); - void (*fdimewriteclose)(struct soap*, void*); - size_t (*fdimeread)(struct soap*, void*, char*, size_t); - int (*fdimewrite)(struct soap*, void*, const char*, size_t); -#endif - int master; - int socket; -#if defined(__cplusplus) && !defined(WITH_LEAN) - std::ostream *os; - std::istream *is; -#else - void *os; /* preserve alignment */ - void *is; /* preserve alignment */ -#endif -#ifndef UNDER_CE - int sendfd; - int recvfd; -#else - FILE *sendfd; - FILE *recvfd; -#endif -#ifdef WIN32 - char errorstr[256]; /* buf for FormatMessage() */ -#endif - size_t bufidx; /* index in soap.buf[] */ - size_t buflen; /* length of soap.buf[] content */ - soap_wchar ahead; /* parser lookahead */ - short cdata; /* CDATA parser state */ - short body; /* parsed XML element has a body or not */ - unsigned int level; /* XML nesting level */ - size_t count; /* message length counter */ - size_t length; /* message length as set by HTTP header */ -#ifdef WITH_FAST - char *labbuf; /* look-aside buffer */ - size_t lablen; /* look-aside buffer allocated length */ - size_t labidx; /* look-aside buffer index to available part */ -#endif - char buf[SOAP_BUFLEN];/* send and receive buffer */ - char tmpbuf[1024]; /* in/output buffer for HTTP headers, simpleType values, attribute names, and DIME >=1024 bytes */ - char msgbuf[1024]; /* output buffer for (error) messages <=1024 bytes */ - char tag[SOAP_TAGLEN]; - char id[SOAP_TAGLEN]; - char href[SOAP_TAGLEN]; - char type[SOAP_TAGLEN]; - char arrayType[SOAP_TAGLEN]; - char arraySize[SOAP_TAGLEN]; - char arrayOffset[SOAP_TAGLEN]; - short other; - short position; - int positions[SOAP_MAXDIMS]; - short root; - struct soap_attribute *attributes; /* attribute list */ - short encoding; /* when set, output encodingStyle */ - short mustUnderstand; /* a mustUnderstand element was parsed or is output */ - short keep_alive; /* connection should be kept open */ - short null; /* parsed XML is xsi:nil */ - short ns; /* when not set, output full xmlns bindings */ - short part; /* parsing state */ - short alloced; - short peeked; - size_t chunksize; - size_t chunkbuflen; - char endpoint[SOAP_TAGLEN]; - char path[SOAP_TAGLEN]; - char host[SOAP_TAGLEN]; - char *action; - char *authrealm; /* HTTP authentication realm */ - char *prolog; /* XML declaration prolog */ - unsigned long ip; /* IP number */ - int port; /* port number */ - unsigned int max_keep_alive; - const char *proxy_host; /* Proxy Server host name */ - int proxy_port; /* Proxy Server port (default = 8080) */ - const char *proxy_userid; /* Proxy Authorization user name */ - const char *proxy_passwd; /* Proxy Authorization password */ - int status; /* -1 when request, else error code to be returned by server */ - int error; - int errmode; - int errnum; -#ifndef WITH_LEANER - struct soap_dom_element *dom; - struct soap_dime dime; - struct soap_mime mime; - struct soap_xlist *xlist; -#endif -#if !defined(WITH_LEAN) || defined(SOAP_DEBUG) - const char *logfile[SOAP_MAXLOGS]; - FILE *fdebug[SOAP_MAXLOGS]; - struct soap_mlist *mht[SOAP_PTRHASH]; -#endif -#ifndef WITH_LEAN - const char *c14ninclude; - const char *c14nexclude; - struct soap_cookie *cookies; - const char *cookie_domain; - const char *cookie_path; - int cookie_max; -#endif -#ifndef WITH_NOIO -#ifdef WITH_IPV6 - struct sockaddr_storage peer; /* IPv6: set by soap_accept and by UDP recv */ -#else - struct sockaddr_in peer; /* IPv4: set by soap_connect/soap_accept and by UDP recv */ -#endif - size_t peerlen; -#endif -#ifdef WITH_OPENSSL - int (*fsslauth)(struct soap*); - int (*fsslverify)(int, X509_STORE_CTX*); - BIO *bio; - SSL *ssl; - SSL_CTX *ctx; - short require_server_auth; - short require_client_auth; - short rsa; /* when set, use RSA instead of DH */ - const char *keyfile; - const char *password; - const char *dhfile; - const char *cafile; - const char *capath; - const char *crlfile; - const char *randfile; - SSL_SESSION *session; - char session_host[SOAP_TAGLEN]; - int session_port; -#endif -#ifdef WITH_ZLIB - short zlib_state; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_INFLATE */ - short zlib_in; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - short zlib_out; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - z_stream d_stream; /* decompression stream */ - char z_buf[SOAP_BUFLEN]; /* buffer */ - size_t z_buflen; - unsigned short z_level; /* compression level to be used (0=none, 1=fast to 9=best) */ - uLong z_crc; /* internal gzip crc */ - float z_ratio_in; /* detected compression ratio compressed_length/length of inbound message */ - float z_ratio_out; /* detected compression ratio compressed_length/length of outbound message */ -#endif -#ifdef WMW_RPM_IO - void *rpmreqid; -#endif -}; - -struct soap_code_map -{ long code; - const char *string; -}; - -/* forwarding list */ -struct soap_flist -{ struct soap_flist *next; - int type; - void *ptr; - unsigned int level; - void (*fcopy)(struct soap*, int, int, void*, const void*, size_t); -}; - -/* id-ref forwarding list */ -struct soap_ilist -{ struct soap_ilist *next; - int type; - size_t size; - void *link; - void *copy; - struct soap_flist *flist; - void *ptr; - unsigned int level; - char id[1]; /* the actual id string value flows into the allocated region below this struct */ -}; - -struct soap_plugin -{ struct soap_plugin *next; - const char *id; - void *data; - int (*fcopy)(struct soap *soap, struct soap_plugin *dst, struct soap_plugin *src); - void (*fdelete)(struct soap *soap, struct soap_plugin *p); /* should delete fields of plugin only and not free(p) */ -}; - -#ifndef WITH_NONAMESPACES -extern SOAP_NMAC struct Namespace namespaces[]; -#endif - -#ifndef WITH_LEAN -# define soap_get0(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx]) -# define soap_get1(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx++]) -#else -soap_wchar soap_get0(struct soap*); -soap_wchar soap_get1(struct soap*); -#endif - -#define soap_revget1(soap) ((soap)->bufidx--) -#define soap_unget(soap, c) ((soap)->ahead = c) -#define soap_register_plugin(soap, plugin) soap_register_plugin_arg(soap, plugin, NULL) -#define soap_imode(soap, n) ((soap)->mode = (soap)->imode = (n)) -#define soap_set_imode(soap, n) ((soap)->imode |= (n)) -#define soap_clr_imode(soap, n) ((soap)->imode &= ~(n)) -#define soap_omode(soap, n) ((soap)->mode = (soap)->omode = (n)) -#define soap_set_omode(soap, n) ((soap)->omode |= (n)) -#define soap_clr_omode(soap, n) ((soap)->omode &= ~(n)) -#define soap_set_mode(soap, n) ((soap)->imode |= (n), (soap)->omode |= (n)) -#define soap_clr_mode(soap, n) ((soap)->imode &= ~(n), (soap)->omode &= ~(n)) -#define soap_destroy(soap) soap_delete((soap), NULL) - -#ifdef HAVE_STRRCHR -# define soap_strrchr(s, t) strrchr(s, t) -#else - SOAP_FMAC1 char* SOAP_FMAC2 soap_strrchr(const char *s, int t); -#endif - -#ifdef HAVE_STRTOL -# define soap_strtol(s, t, b) strtol(s, t, b) -#else - SOAP_FMAC1 long SOAP_FMAC2 soap_strtol(const char *s, char **t, int b); -#endif - -#ifdef HAVE_STRTOUL -# define soap_strtoul(s, t, b) strtoul(s, t, b) -#else - SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b); -#endif - -#if defined(WITH_OPENSSL) -# define soap_random soap_rand() -SOAP_FMAC1 int SOAP_FMAC2 soap_rand(); -#elif defined(HAVE_RANDOM) -# define soap_random (int)random() -#else -# define soap_random rand() -#endif - -#ifdef WITH_NOIDREF -# define soap_embedded(s, p, t) (0) -# define soap_id_lookup(s, i, p, t, n, k) (p) -# define soap_id_forward(s, h, p, st, tt, n, k, fc) (p) -# define soap_reference(s, a, t) (1) -# define soap_array_reference(s, p, a, n, t) (1) -# define soap_embed(s, p, a, n, t, pp) (0) -# define soap_embedded_id(s, i, p, t) (i) -# define soap_is_embedded(s, p) (0) -# define soap_is_single(s, p) (1) -# define soap_lookup_type(s, i) (0) -# define soap_getindependent(s) (0) -# define soap_putindependent(s) (0) -# define soap_getelement(s, n) (n) -# define soap_putelement(s, p, t, i, n) (0) -# define soap_markelement(s, p, n) (0) -#endif - -SOAP_FMAC1 void SOAP_FMAC2 soap_fault(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultsubcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultstring(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultdetail(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializefault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getfault(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_poll(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect_command(struct soap*, int, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_bind(struct soap*, const char*, int, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_accept(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_accept(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_puthttphdr(struct soap*, int status, size_t count); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_get_header_attribute(struct soap*, const char*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_key(char*, size_t, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_val(char*, size_t, const char*); - -SOAP_FMAC1 size_t SOAP_FMAC2 soap_hash(const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_endpoint(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_get(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getchar(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_tag_cmp(const char*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_sender_error(struct soap*, const char*, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_receiver_error(struct soap*, const char*, const char*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_raw(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send2(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send3(struct soap*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pututf8(struct soap*, unsigned long); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getutf8(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_putbase64(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_getbase64(struct soap*, int*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_puthex(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_gethex(struct soap*, int*); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_xop_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_dime_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -#endif - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup_id(struct soap*, void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup(struct soap*, const void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_enter(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_pointer_lookup(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -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); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_lookup(struct soap*, const char*); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_enter(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_resolve(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_embedded(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_reference(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_reference(struct soap*, const void *p, const struct soap_array *a, int n, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_embedded_id(struct soap*, int id, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_embedded(struct soap*, struct soap_plist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_single(struct soap*, struct soap_plist*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_embedded(struct soap*, struct soap_plist*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_send(struct soap*); - -SOAP_FMAC1 const struct soap_code_map* SOAP_FMAC2 soap_code(const struct soap_code_map*, const char *str); -SOAP_FMAC1 long SOAP_FMAC2 soap_int_code(const struct soap_code_map*, const char *str, long other); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_str_code(const struct soap_code_map*, long code); - -SOAP_FMAC1 int SOAP_FMAC2 soap_getline(struct soap*, char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_recv(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_malloc(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_dealloc(struct soap*, void*); -SOAP_FMAC1 struct soap_clist * SOAP_FMAC2 soap_link(struct soap*, void*, int, int, void (*fdelete)(struct soap_clist*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_unlink(struct soap*, const void*); -SOAP_FMAC1 void SOAP_FMAC2 soap_free(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_track_malloc(struct soap*, const char*, int, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_track_free(struct soap*, const char*, int, void*); - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_lookup_type(struct soap*, const char *id); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_lookup(struct soap*, const char *id, void **p, int t, size_t n, unsigned int k); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_forward(struct soap*, const char *id, void *p, int st, int tt, size_t n, unsigned int k, void(*fcopy)(struct soap*, int, int, void*, const void*, size_t)); -#endif -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_enter(struct 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*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_fcopy(struct soap *soap, int st, int tt, void *p, const void *q, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_size(const int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getoffsets(const char *, const int *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsize(const char *, const char *, int *); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsizes(const char *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getposition(const char *, int *); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsize(struct soap*, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizesoffsets(struct soap*, const char *, const int *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizes(struct soap*, const char *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffset(struct soap*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffsets(struct soap*, const int *, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_closesock(struct soap*); - -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new(void); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new1(soap_mode); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new2(soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_del(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*,struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init1(struct soap*, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_init2(struct soap*, soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_end(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_delete(struct soap*, void*); - -#ifdef SOAP_DEBUG -SOAP_FMAC1 void SOAP_FMAC2 soap_set_recv_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_sent_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_test_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_close_logfiles(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_open_logfile(struct soap*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_token(struct soap*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_value(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_tag(struct soap*, const char*, const char *); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_array(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element(struct soap*, const char*, int, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_out(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_begin_out(struct soap*, const char *tag, int id, const char *type, const char *offset); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_ref(struct soap*, const char *tag, int id, int href); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_href(struct soap*, const char *tag, int id, const char *ref, const char *val); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_null(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_id(struct soap*, const char *tag, int id, const void *p, const struct soap_array *a, int d, const char *type, int n); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_result(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_out(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_start_end_out(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_attribute(struct soap*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_in(struct soap*, const char *tag, int nillable); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_in(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_peek_element(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_retry(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_revert(struct soap*); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_strdup(struct soap*, const char*); -SOAP_FMAC1 const char * SOAP_FMAC2 soap_strsearch(const char *big, const char *little); - -SOAP_FMAC1 int SOAP_FMAC2 soap_string_out(struct soap*, const char *s, int flag); -SOAP_FMAC1 char* SOAP_FMAC2 soap_string_in(struct soap*, int, long, long); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_wstring_out(struct soap*, const wchar_t *s, int flag); -SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstring_in(struct soap*, int, long, long); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_namespace(struct soap*, const char *, const char*, int n1, int n2); - -SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap*, struct Namespace*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_local_namespaces(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_namespace(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_push_namespace(struct soap*, const char *,const char *); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_current_namespace(struct soap *soap, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_store_lab(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_append_lab(struct soap*, const char*, size_t); - -SOAP_FMAC1 int SOAP_FMAC2 soap_new_block(struct soap*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_push_block(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_size_block(struct soap*, size_t); -SOAP_FMAC1 char* SOAP_FMAC2 soap_first_block(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_next_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_block_size(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_save_block(struct soap*, char*, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*); -SOAP_FMAC1 int soap_envelope_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_out(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_header(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_response(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_empty_response(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_empty_response(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_fault(struct soap*); - -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap*, FILE*); -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault_location(struct soap*, FILE*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_s2byte(struct soap*, const char*, char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2short(struct soap*, const char*, short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2int(struct soap*, const char*, int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2long(struct soap*, const char*, long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2LONG64(struct soap*, const char*, LONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2float(struct soap*, const char*, float*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2double(struct soap*, const char*, double*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedByte(struct soap*, const char*, unsigned char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedShort(struct soap*, const char*, unsigned short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedInt(struct soap*, const char*, unsigned int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedLong(struct soap*, const char*, unsigned long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2ULONG64(struct soap*, const char*, ULONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2string(struct soap*, const char*, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2QName(struct soap*, const char*, char**); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_s2wchar(struct soap*, const char*, wchar_t**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2dateTime(struct soap*, const char*, time_t*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2base64(struct soap*, const unsigned char*, char*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2hex(struct soap*, const unsigned char*, char*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_byte2s(struct soap*, char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_short2s(struct soap*, short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_int2s(struct soap*, int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_long2s(struct soap*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_LONG642s(struct soap*, LONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_float2s(struct soap*, float); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_double2s(struct soap*, double); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedByte2s(struct soap*, unsigned char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedShort2s(struct soap*, unsigned short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedInt2s(struct soap*, unsigned int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedLong2s(struct soap*, unsigned long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_ULONG642s(struct soap*, ULONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_QName2s(struct soap*, const char*); - -#ifndef WITH_LEAN -SOAP_FMAC1 const char* SOAP_FMAC2 soap_wchar2s(struct soap*, const wchar_t*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_dateTime2s(struct soap*, time_t); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_base642s(struct soap*, const char*, char*, size_t, int*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_hex2s(struct soap*, const char*, char*, size_t, int*); -#endif - - -SOAP_FMAC1 int* SOAP_FMAC2 soap_inint(struct soap*, const char *tag, int *p, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_inbyte(struct soap*, const char *tag, char *p, const char *, int); -SOAP_FMAC1 long* SOAP_FMAC2 soap_inlong(struct soap*, const char *tag, long *p, const char *, int); -SOAP_FMAC1 LONG64* SOAP_FMAC2 soap_inLONG64(struct soap*, const char *tag, LONG64 *p, const char *, int); -SOAP_FMAC1 short* SOAP_FMAC2 soap_inshort(struct soap*, const char *tag, short *p, const char *, int); -SOAP_FMAC1 float* SOAP_FMAC2 soap_infloat(struct soap*, const char *tag, float *p, const char *, int); -SOAP_FMAC1 double* SOAP_FMAC2 soap_indouble(struct soap*, const char *tag, double *p, const char *, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_inunsignedByte(struct soap*, const char *tag, unsigned char *p, const char *, int); -SOAP_FMAC1 unsigned short* SOAP_FMAC2 soap_inunsignedShort(struct soap*, const char *tag, unsigned short *p, const char *, int); -SOAP_FMAC1 unsigned int* SOAP_FMAC2 soap_inunsignedInt(struct soap*, const char *tag, unsigned int *p, const char *, int); -SOAP_FMAC1 unsigned long* SOAP_FMAC2 soap_inunsignedLong(struct soap*, const char *tag, unsigned long *p, const char *, int); -SOAP_FMAC1 ULONG64* SOAP_FMAC2 soap_inULONG64(struct soap*, const char *tag, ULONG64 *p, const char *, int); -SOAP_FMAC1 char** SOAP_FMAC2 soap_instring(struct soap*, const char *tag, char **p, const char *, int, int, long, long); -SOAP_FMAC1 char** SOAP_FMAC2 soap_inliteral(struct soap*, const char *tag, char **p); - -#ifndef WITH_LEAN -SOAP_FMAC1 time_t* SOAP_FMAC2 soap_indateTime(struct soap*, const char *tag, time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwstring(struct soap*, const char *tag, wchar_t **p, const char *, int, long, long); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwliteral(struct soap*, const char *tag, wchar_t **p); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_outbyte(struct soap*, const char *tag, int id, const char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outshort(struct soap*, const char *tag, int id, const short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outint(struct soap*, const char *tag, int id, const int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outlong(struct soap*, const char *tag, int id, const long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outLONG64(struct soap*, const char *tag, int id, const LONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outfloat(struct soap*, const char *tag, int id, const float *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdouble(struct soap*, const char *tag, int id, const double *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedByte(struct soap*, const char *tag, int id, const unsigned char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedShort(struct soap*, const char *tag, int id, const unsigned short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedInt(struct soap*, const char *tag, int id, const unsigned int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedLong(struct soap*, const char *tag, int id, const unsigned long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outULONG64(struct soap*, const char *tag, int id, const ULONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outstring(struct soap*, const char *tag, int id, char *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outliteral(struct soap*, const char *tag, char *const*p); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_outdateTime(struct soap*, const char *tag, int id, const time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_outwstring(struct soap*, const char *tag, int id, wchar_t *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwliteral(struct soap*, const char *tag, wchar_t *const*p); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_attachment(struct soap *, const char*, int, const void*, const struct soap_array*, const char*, const char*, const char*, int, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, long); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_tell(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_dime_option(struct soap*, unsigned short, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmimehdr(struct soap*, struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_mime(struct soap*, const char *boundary, const char *start); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_mime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_dime_attachment(struct soap*, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_mime_attachment(struct soap*, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_register_plugin_arg(struct soap*, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_lookup_plugin(struct soap*, const char*); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_attr_value(struct soap *soap, const char *name, int flag); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_attr(struct soap *soap, const char *name, const char *value); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_attr(struct soap *soap); - -#ifdef WITH_COOKIES -SOAP_FMAC1 size_t SOAP_FMAC2 soap_encode_cookie(const char*, char*, size_t); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_set_cookie(struct soap*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_env_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern long SOAP_FMAC2 soap_cookie_expire(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_expire(struct soap*, const char*, long, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_clr_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_clr_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_getenv_cookies(struct soap*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_copy_cookies(struct soap*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_free_cookies(struct soap*); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.c b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.c deleted file mode 100644 index 959147e..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.c +++ /dev/null @@ -1,14172 +0,0 @@ -/* - -stdsoap2.c[pp] 2.7.9b - -gSOAP runtime - -gSOAP XML Web services tools -Copyright (C) 2000-2007, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under one of the following licenses: -GPL, the gSOAP public license, or Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems Inc., for the following additions under gSOAP public license: - - vxWorks compatible (#define VXWORKS) --------------------------------------------------------------------------------- -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-2007, 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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- - -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. - -*/ - -#ifdef AS400 -# pragma convert(819) /* EBCDIC to ASCII */ -#endif - -#include "stdsoap2.h" - -#ifdef WIN32 -# pragma comment(lib, "wsock32.lib") -#endif - -#ifdef __cplusplus -SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.7.9b 2007-01-01 12:00:00 GMT") -extern "C" { -#else -SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.7.9 2007-01-01 12:00:00 GMT") -#endif - -/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale with multibyte support enabled) */ -#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_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) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1))) - -#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 SOAP_MEM_DEBUG -static void soap_init_mht(struct soap*); -static void soap_free_mht(struct soap*); -static void soap_track_unlink(struct soap*, const void*); -#endif - -#ifndef PALM_2 -static int soap_set_error(struct soap*, const char*, const char*, const char*, const char*, int); -static int soap_copy_fault(struct soap*, const char*, const char*, const char*, const char*); -static int soap_getattrval(struct soap*, char*, size_t, soap_wchar); -#endif - -#ifndef PALM_1 -static soap_wchar soap_char(struct soap*); -static soap_wchar soap_get_pi(struct soap*); -static int soap_isxdigit(int); -static void *fplugin(struct soap*, const char*); -#ifndef WITH_NOIDREF -static void soap_update_ptrs(struct soap*, char*, char*, char*, char*); -static int soap_has_copies(struct soap*, const char*, 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*); -#endif -#endif - -#ifndef WITH_LEAN -static const char *soap_set_validation_fault(struct soap*, const char*, const char*); -static int soap_isnumeric(struct soap*, const char*); -static time_t soap_timegm(struct tm*); -static struct soap_nlist *soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized); -static void soap_pop_ns(struct soap *soap); -static void soap_utilize_ns(struct soap *soap, const char *tag, size_t n); -#endif - -#ifndef WITH_LEANER -#ifndef PALM_1 -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*); -static void soap_resolve_attachment(struct soap*, struct soap_multipart*); -#endif -#endif - -#ifdef WITH_GZIP -static int soap_getgziphdr(struct soap*); -#endif - -#ifdef WITH_OPENSSL -static int ssl_init_done = 0; -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 - -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#ifndef PALM_1 -static const char *soap_decode(char*, size_t, const char*, const char*); -#endif -#endif - -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static soap_wchar soap_getchunkchar(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*); -#endif -#endif - -#ifndef WITH_NOIO -#ifndef PALM_1 -static int fsend(struct soap*, const char*, size_t); -static size_t frecv(struct soap*, char*, size_t); -static int tcp_init(struct soap*); -static const char *tcp_error(struct soap*); -#ifndef WITH_LEAN -static size_t frecv_stop(struct soap*, char*, size_t); -#endif -#ifndef WITH_IPV6 -static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr); -#endif -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 const char *soap_strerror(struct soap*); -#endif -#endif - -#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 - -#ifndef WITH_LEAN -static const char soap_indent[11] = "\n\t\t\t\t\t\t\t\t\t"; -/* Alternative indentation form for SOAP_XML_INDENT: -static const char soap_indent[21] = "\n "; -*/ -#endif - -#ifndef SOAP_CANARY -# define SOAP_CANARY (0xC0DE) -#endif - -static const char soap_padding[4] = "\0\0\0"; -#define SOAP_STR_PADDING (soap_padding) -#define SOAP_STR_EOS (soap_padding) -#define SOAP_NON_NULL (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_NOIO -#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 -#endif - -#ifndef WITH_NOHTTP -#ifndef WITH_LEAN -static const struct soap_code_map h_http_error_codes[] = -{ { 200, "OK" }, - { 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 -#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 WITH_NOIO -#ifndef PALM_1 -static int -fsend(struct soap *soap, const char *s, size_t n) -{ register int nwritten, err; -#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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - 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; - } - err = soap_socket_errno(soap->socket); - if (err != SOAP_EINTR && err != SOAP_EAGAIN) - { soap->errnum = err; - return SOAP_EOF; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - nwritten = SSL_write(soap->ssl, s, n); - else if (soap->bio) - nwritten = BIO_write(soap->bio, s, n); - else -#endif -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - { if (soap->peerlen) - nwritten = sendto((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, soap->peerlen); - else - nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); - /* retry and back-off algorithm */ - /* TODO: this is not very clear from specs so verify and limit conditions under which we should loop (e.g. ENOBUFS) */ - if (nwritten < 0) - { struct timeval timeout; - fd_set fd; - int udp_repeat; - int udp_delay; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - if ((soap->connect_flags & SO_BROADCAST)) - udp_repeat = 3; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */ - else - udp_repeat = 1; /* SOAP-over-UDP UNICAST_UDP_REPEAT - 1 */ - udp_delay = (soap_random % 201) + 50; /* UDP_MIN_DELAY .. UDP_MAX_DELAY */ - do - { timeout.tv_sec = 0; - timeout.tv_usec = 1000 * udp_delay; /* ms */ - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); - select((SOAP_SOCKET)(soap->socket + 1), NULL, NULL, &fd, &timeout); - if (soap->peerlen) - nwritten = sendto((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, soap->peerlen); - else - nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); - udp_delay <<= 1; - if (udp_delay > 500) /* UDP_UPPER_DELAY */ - udp_delay = 500; - } - while (nwritten < 0 && --udp_repeat > 0); - } - } - else -#endif -#if !defined(PALM) && !defined(AS400) - 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 - err = soap_socket_errno(soap->socket); - if (err && err != SOAP_EINTR && err != SOAP_EWOULDBLOCK && err != SOAP_EAGAIN) - { soap->errnum = err; - 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 -#ifdef VXWORKS -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - nwritten = (httpBlockPut(soap->rpmreqid, s, n) == 0) ? n : -1; - else -#endif - nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w")); -#else - nwritten = write((SOAP_SOCKET)soap->sendfd, s, n); -#endif -#endif -#endif - if (nwritten <= 0) - { err = soap_errno; - if (err && err != SOAP_EINTR && err != SOAP_EWOULDBLOCK && err != SOAP_EAGAIN) - { soap->errnum = err; - 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_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; -#ifndef WITH_LEANER - if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - 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_flush(struct soap *soap) -{ register int n = soap->bufidx; - if (n) - { soap->bufidx = 0; -#ifdef WITH_ZLIB - if (soap->mode & SOAP_ENC_ZLIB) - { soap->d_stream.next_in = (Byte*)soap->buf; - soap->d_stream.avail_in = (unsigned int)n; -#ifdef WITH_GZIP - soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)n); -#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 - return soap_flush_raw(soap, soap->buf, n); - } - return SOAP_OK; -} -#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); -#ifndef WITH_LEANER - if (soap->fpreparesend) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - return SOAP_OK; - } -#ifndef WITH_LEANER - 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); -#endif - return soap->error = soap->fsend(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 WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static size_t -frecv(struct soap *soap, char *s, size_t n) -{ register int r; -#ifdef PALM - register int timeouts = 0; -#endif - 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 - if (soap->recv_timeout) - { struct timeval timeout; - fd_set fd; - 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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return 0; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - 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) - { soap->errnum = 0; - return 0; - } - r = soap_socket_errno(soap->socket); - if (r != SOAP_EINTR && r != SOAP_EAGAIN) - { soap->errnum = r; - return 0; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - { int err; - r = SSL_read(soap->ssl, s, n); - if (r > 0) - return (size_t)r; - err = SSL_get_error(soap->ssl, r); - if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE) - return 0; - } - else if (soap->bio) - { r = BIO_read(soap->bio, s, n); - if (r > 0) - return (size_t)r; - return 0; - } - else -#endif - { -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - { SOAP_SOCKLEN_T k = (SOAP_SOCKLEN_T)sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - r = recvfrom((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, &k); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - soap->peerlen = (size_t)k; -#ifndef WITH_IPV6 - soap->ip = ntohl(soap->peer.sin_addr.s_addr); -#endif - } - else -#endif - r = recv((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); -#ifdef PALM - /* CycleSyncDisplay(curStatusMsg); */ -#endif - if (r >= 0) - return (size_t)r; - r = soap_socket_errno(soap->socket); - if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) - { soap->errnum = r; - return 0; - } - } -#ifndef WITH_LEAN - { struct timeval timeout; - fd_set fd; - timeout.tv_sec = 0; - timeout.tv_usec = 10000; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return 0; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); -#ifdef WITH_OPENSSL - if (soap->ssl && SSL_get_error(soap->ssl, r) == SSL_ERROR_WANT_WRITE) - r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); - else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#endif - if (r < 0 && (r = soap_socket_errno(soap->socket)) != SOAP_EINTR) - { soap->errnum = r; - return 0; - } - } -#endif -#ifdef PALM - if (r < 0 && (r = soap_socket_errno(soap->socket)) == SOAP_EINTR) - { timeouts++; - if (timeouts > 10) - { soap->errnum = r; - return 0; - } - } -#endif - } - } -#ifdef WITH_FASTCGI - return fread(s, 1, n, stdin); -#else -#ifdef UNDER_CE - return fread(s, 1, n, soap->recvfd); -#else -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - r = httpBlockRead(soap->rpmreqid, s, n); - else -#endif - r = read((SOAP_SOCKET)soap->recvfd, s, n); - if (r >= 0) - return (size_t)r; - soap->errnum = soap_errno; - return 0; -#endif -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef WITH_NOIO -#ifndef PALM_1 -static size_t -frecv_stop(struct soap *soap, char *s, size_t n) -{ return 0; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 from socket %d\n", (unsigned int)soap->buflen, soap->socket)); - DBGMSG(RECV, soap->buf, soap->buflen); - if (soap->buflen) - return soap->buf[soap->bufidx++]; - return EOF; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -static int -soap_isxdigit(int c) -{ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); -} -#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; - ret = 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)ret); - 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 (ret) - { soap->count += ret; - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n")); - DBGMSG(RECV, soap->buf, ret); - 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; - soap->error = SOAP_ZLIB_ERROR; - 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; - } - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- compressed ----\n")); - } -#endif -#ifndef WITH_NOHTTP - 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 (chunked) from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - soap->bufidx = 0; - if (!ret) - return soap->ahead = EOF; - } - else - soap->bufidx = soap->buflen; - soap->buflen = soap->chunkbuflen; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (idx=%u len=%u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen)); - while (!soap_isxdigit((int)(c = soap_getchunkchar(soap)))) - { if ((int)c == EOF) - return soap->ahead = 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 soap->ahead = 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 soap->ahead = EOF; - } - soap->buflen = soap->bufidx + soap->chunksize; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to idx=%u len=%u (%s)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen, 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 (%u bytes left)\n", (unsigned int)(soap->buflen - soap->bufidx))); - } - else if (soap->chunkbuflen) - soap->chunksize = 0; - ret = soap->buflen - soap->bufidx; - if (!ret) - goto chunk_again; - } - } - else -#endif - { soap->bufidx = 0; - soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - } -#ifndef WITH_LEANER - if (soap->fpreparerecv && (soap->error = soap->fpreparerecv(soap, soap->buf, ret))) - return soap->error; -#endif -#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; - } - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n")); - DBGMSG(RECV, soap->buf, ret); - } - 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; - soap->error = SOAP_ZLIB_ERROR; - 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; - c = soap->ahead; - if (c) - { if (c != EOF) - 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 *code_map, const char *str) -{ if (code_map && str) - { while (code_map->string) - { if (!strcmp(str, code_map->string)) /* case sensitive */ - return code_map; - code_map++; - } - } - return NULL; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -long -SOAP_FMAC2 -soap_code_int(const struct soap_code_map *code_map, const char *str, long other) -{ if (code_map) - { while (code_map->string) - { if (!soap_tag_cmp(str, code_map->string)) /* case insensitive */ - return code_map->code; - code_map++; - } - } - return other; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_code_str(const struct soap_code_map *code_map, long code) -{ if (!code_map) - return NULL; - while (code_map->code != code && code_map->string) - code_map++; - return code_map->string; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -long -SOAP_FMAC2 -soap_code_bits(const struct soap_code_map *code_map, const char *str) -{ register long bits = 0; - if (code_map) - { while (str && *str) - { const struct soap_code_map *p; - for (p = code_map; p->string; p++) - { register size_t n = strlen(p->string); - if (!strncmp(p->string, str, n) && soap_blank(str[n])) - { bits |= p->code; - str += n; - while (*str > 0 && *str <= 32) - str++; - break; - } - } - if (!p->string) - return 0; - } - } - return bits; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_code_list(struct soap *soap, const struct soap_code_map *code_map, long code) -{ register char *t = soap->tmpbuf; - if (code_map) - { while (code_map->string) - { if (code_map->code & code) - { register const char *s = code_map->string; - if (t != soap->tmpbuf) - *t++ = ' '; - while (*s && t < soap->tmpbuf + sizeof(soap->tmpbuf) - 1) - *t++ = *s++; - if (t == soap->tmpbuf + sizeof(soap->tmpbuf) - 1) - break; - } - code_map++; - } - } - *t = '\0'; - return soap->tmpbuf; -} -#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_code_int(html_entity_codes, tmp, SOAP_UNKNOWN_CHAR); -#else - return SOAP_UNKNOWN_CHAR; /* use this to represent unknown code */ -#endif -} -#endif - -/******************************************************************************/ -#ifdef WITH_LEAN -#ifndef PALM_1 -soap_wchar -soap_get0(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx]; -} -#endif -#endif - -/******************************************************************************/ -#ifdef WITH_LEAN -#ifndef PALM_1 -soap_wchar -soap_get1(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx++]; -} -#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) - { if ((int)c != EOF) - soap->ahead = 0; - } - else - c = soap_get1(soap); - while ((int)c != EOF) - { if (soap->cdata) - { if (c == ']') - { c = soap_get1(soap); - if (c == ']') - { c = soap_get0(soap); - if (c == '>') - { soap->cdata = 0; - soap_get1(soap); - c = soap_get1(soap); - } - else - { soap_unget(soap, ']'); - return ']'; - } - } - else - { soap_revget1(soap); - return ']'; - } - } - else - return c; - } - switch (c) - { case '<': - do c = soap_get1(soap); - while (soap_blank(c)); - if (c == '!' || c == '?' || c == '%') - { register int k = 1; - 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); - } - } - else if (c == '?') - c = soap_get_pi(soap); - while ((int)c != EOF) - { if (c == '<') - k++; - else if (c == '>') - { if (--k <= 0) - break; - } - 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 -static soap_wchar -soap_get_pi(struct soap *soap) -{ char buf[64]; - register char *s = buf; - register int i = sizeof(buf); - register soap_wchar c = soap_getchar(soap); - /* This is a quick way to parse XML PI and we could use a callback instead to - * enable applications to intercept processing instructions */ - while ((int)c != EOF && c != '?') - { if (--i > 0) - { if (soap_blank(c)) - c = ' '; - *s++ = (char)c; - } - c = soap_getchar(soap); - } - *s = '\0'; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI \n", buf)); - if (!strncmp(buf, "xml ", 4)) - { s = strstr(buf, " encoding="); - if (s && s[10]) - { if (!soap_tag_cmp(s + 11, "iso-8859-1*") - || !soap_tag_cmp(s + 11, "latin1*")) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to latin1 encoding\n")); - soap->mode |= SOAP_ENC_LATIN; - } - else if (!soap_tag_cmp(s + 11, "utf-8*")) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to utf-8 encoding\n")); - soap->mode &= ~SOAP_ENC_LATIN; - } - } - } - if ((int)c != EOF) - c = soap_getchar(soap); - 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 < 0x80 && c >= 0x20) - { *tmp = (char)c; - return soap_send_raw(soap, tmp, 1); - } -#ifndef WITH_LEAN - if (c >= 0x80 && (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->ahead; - if (c > 0xFF) - { soap->ahead = 0; - return c; - } -again: - c = soap_get(soap); - if (c < 0x80 || (soap->mode & SOAP_ENC_LATIN)) - return c; - c1 = soap_get1(soap); - if (c1 < 0x80) - { soap_revget1(soap); /* doesn't look like this is UTF8 */ - return c; - } - c1 &= 0x3F; - if (c < 0xE0) - return ((soap_wchar)(c & 0x1F) << 6) | c1; - c2 = (soap_wchar)soap_get1(soap) & 0x3F; - if (c == 0xEF && c1 == 0x3B && c2 == 0x3F) /* ignore UTF-8 BOM */ - goto again; - 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) -{ char d[2]; - register int i; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!(soap->dom->data = soap_s2hex(soap, s, NULL, n))) - return soap->error; - return SOAP_OK; - } -#endif - 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_hex2s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#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, NULL, 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_base642s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#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 = soap->lablen - soap->labidx; - soap->labidx = 3 * (soap->lablen / 3); - if (!s) - return NULL; - for (i = 0; i < k - 2; 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) - { int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; - } - else if (!soap_blank(c)) - { soap->error = SOAP_TYPE; - return NULL; - } - } 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) - { int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; - } - else if (!soap_blank(c)) - { soap->error = SOAP_TYPE; - return NULL; - } - } while (j < 4); - *s++ = (char)((m >> 16) & 0xFF); - *s++ = (char)((m >> 8) & 0xFF); - *s++ = (char)(m & 0xFF); - } - } -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_xop_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ /* Check MTOM xop:Include element (within hex/base64Binary) */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - int body = soap->body; /* should save type too? */ - if (!soap_peek_element(soap)) - { if (!soap_element_begin_in(soap, "xop:Include", 0, NULL) && *soap->href) - { if (soap_dime_forward(soap, ptr, size, id, type, options)) - return soap->error; - } - if (soap->body && soap_element_end_in(soap, NULL)) - return soap->error; - } - soap->body = body; - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_dime_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ struct soap_xlist *xp = (struct soap_xlist*)SOAP_MALLOC(soap, sizeof(struct soap_xlist)); - *ptr = NULL; - *size = 0; - *id = soap_strdup(soap, soap->href); - *type = NULL; - *options = NULL; - if (!xp) - return soap->error = SOAP_EOM; - xp->next = soap->xlist; - xp->ptr = ptr; - xp->size = size; - xp->id = *id; - xp->type = type; - xp->options = options; - soap->xlist = xp; - return SOAP_OK; -} -#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(soap, 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(soap, 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(soap, p); -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_update_ptrs(struct soap *soap, char *start, char *end, char *p1, char *p2) -{ int i; - register struct soap_ilist *ip; - register struct soap_flist *fp; -#ifndef WITH_LEANER - register struct soap_xlist *xp; -#endif - 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 + (p1-p2))); - ip->ptr = (char*)ip->ptr + (p1-p2); - } - 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 + (p1-p2); - } - } - 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 + (p1-p2); - } - } - 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 + (p1-p2); - } - } - } - } -#ifndef WITH_LEANER - for (xp = soap->xlist; xp; xp = xp->next) - { if (xp->ptr && (char*)xp->ptr >= start && (char*)xp->ptr < end) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", xp->id?xp->id:"", xp->ptr, (char*)xp->ptr + (p1-p2))); - xp->ptr = (unsigned char**)((char*)xp->ptr + (p1-p2)); - xp->size = (int*)((char*)xp->size + (p1-p2)); - xp->type = (char**)((char*)xp->type + (p1-p2)); - xp->options = (char**)((char*)xp->options + (p1-p2)); - } - } -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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, fp->len, p, ip->size); - else - soap_fcopy(soap, ip->type, fp->type, fp->ptr, fp->len, p, ip->size); - ip->flist = fp->next; - SOAP_FREE(soap, 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 -#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(soap, 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(soap, p); - } - soap->blist = bp->next; - SOAP_FREE(soap, 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); -#ifndef WITH_NOIDREF - if (flag) - soap_update_ptrs(soap, q, q + n, s, q); -#endif - 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; - if (*attr1 == '[') - attr1++; - n = 1; - for (;;) - { 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; - } - if (!attr1) - break; - 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; - register short i = -1; - register size_t n, k; - n = strlen(id); - k = strlen(ns) + 1; - p = soap->local_namespaces; - if (p) - { for (i = 0; p->id; p++, i++) - { if (p->ns && !strcmp(ns, p->ns)) - { if (p->out) - { SOAP_FREE(soap, p->out); - p->out = NULL; - } - break; - } - if (p->out) - { if (!strcmp(ns, p->out)) - break; - } - else if (p->in) - { if (!soap_tag_cmp(ns, p->in)) - { if ((p->out = (char*)SOAP_MALLOC(soap, k))) - strcpy(p->out, ns); - break; - } - } - } - if (!p || !p->id) - i = -1; - } - if (i >= 0) - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k); - if (!np) - return soap->error = SOAP_EOM; - np->next = soap->nlist; - soap->nlist = np; - np->level = soap->level; - np->index = i; - strcpy(np->id, id); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns)); - if (i < 0) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns)); - } - else - { np->ns = NULL; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id)); - } - 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)); - SOAP_FREE(soap, 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 - || (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_current_namespace(struct soap *soap, const char *tag) -{ register struct soap_nlist *np; - register const char *s; - np = soap->nlist; - if (!(s = strchr(tag, ':'))) - { while (np && *np->id) /* find default namespace, if present */ - np = np->next; - } - else - { while (np && (strncmp(np->id, tag, s - tag) || np->id[s - tag])) - np = np->next; - if (!np) - soap->error = SOAP_NAMESPACE; - } - if (np) - { if (np->index >= 0) - return soap->namespaces[np->index].ns; - if (np->ns) - return soap_strdup(soap, np->ns); - } - return NULL; -} -#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 && !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 - -/******************************************************************************\ - * - * SSL - * -\******************************************************************************/ - -#ifdef WITH_OPENSSL -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_rand() -{ unsigned char buf[4]; - if (!ssl_init_done) - soap_ssl_init(); - RAND_pseudo_bytes(buf, 4); - return *(int*)buf; -} -#endif - -/******************************************************************************/ -#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; - soap->dhfile = dhfile; - soap->randfile = randfile; - soap->ssl_flags = flags | (dhfile == NULL ? SOAP_SSL_RSA : 0); - 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->ssl_flags = flags; - soap->randfile = randfile; - return soap->fsslauth(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_ssl_init() -{ /* Note: for MT systems, the main program MUST call soap_ssl_init() before any threads are started */ - if (!ssl_init_done) - { ssl_init_done = 1; - SSL_library_init(); -#ifndef WITH_LEAN - SSL_load_error_strings(); -#endif - if (!RAND_load_file("/dev/urandom", 1024)) - { char buf[1024]; - RAND_seed(buf, sizeof(buf)); - while (!RAND_status()) - { int r = rand(); - RAND_seed(&r, sizeof(int)); - } - } - } -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_ssl_error(struct soap *soap, int ret) -{ int err = SSL_get_error(soap->ssl, ret); - const char *msg = soap_code_str(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) -{ long flags; - int mode; - if (!ssl_init_done) - 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 directory", SOAP_SSL_ERROR); - if (soap->cafile && (soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION)) - SSL_CTX_set_client_CA_list(soap->ctx, SSL_load_client_CA_file(soap->cafile)); - } - 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); -/* This code assumes a typical scenario, see alternative code below */ - 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); - } -/* Suggested alternative approach to check cafile first before the key file: - 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 (!soap->cafile || !SSL_CTX_use_certificate_chain_file(soap->ctx, soap->cafile)) - { 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 or key file", SOAP_SSL_ERROR); - 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->ssl_flags & SOAP_SSL_RSA)) - { RSA *rsa = RSA_generate_key(1024, 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); - } - flags = (SSL_OP_ALL | SSL_OP_NO_SSLv2); - if ((soap->ssl_flags & SOAP_SSLv3)) - flags |= SSL_OP_NO_TLSv1; - if ((soap->ssl_flags & SOAP_TLSv1)) - flags |= SSL_OP_NO_SSLv3; - SSL_CTX_set_options(soap->ctx, flags); - if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION)) - mode = (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT); - else if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION)) - mode = SSL_VERIFY_PEER; - else - mode = SSL_VERIFY_NONE; - SSL_CTX_set_verify(soap->ctx, mode, 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 or warning 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 - /* Note: return 1 to 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) -{ BIO *bio; - 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->ctx && (soap->error = soap->fsslauth(soap))) - return SOAP_INVALID_SOCKET; - 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; -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)&nonblocking); - } -#else - fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)|O_NONBLOCK); -#endif - bio = BIO_new_socket((SOAP_SOCKET)soap->socket, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, 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; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); - if (r < 0 && (r = soap_socket_errno(soap->socket)) != SOAP_EINTR) - { soap->errnum = r; - return SOAP_EOF; - } - } - else - { soap->errnum = err; - break; - } - } -#if defined(WIN32) - { u_long blocking = 0; - ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &blocking); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)&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, soap_ssl_error(soap, r), "SSL_accept() failed in soap_ssl_accept()", SOAP_SSL_ERROR); - soap_closesock(soap); - return SOAP_SSL_ERROR; - } - if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION)) - { 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 WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_done(struct soap *soap) -{ -#ifdef SOAP_DEBUG - int i; -#endif - if (soap_check_state(soap)) - return; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Done with context\n")); - soap_free_temp(soap); - while (soap->clist) - { struct soap_clist *p = soap->clist->next; - SOAP_FREE(soap, 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->state == SOAP_INIT) - soap->plugins->fdelete(soap, soap->plugins); - SOAP_FREE(soap, soap->plugins); - soap->plugins = p; - } - soap->fplugin = fplugin; - soap->fmalloc = NULL; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif - soap->fheader = NULL; -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; -#endif - soap->fseterror = NULL; - soap->fignore = NULL; - soap->fserveloop = NULL; -#ifdef WITH_OPENSSL - if (soap->session) - { SSL_SESSION_free(soap->session); - soap->session = NULL; - } -#endif - if (soap->state == SOAP_INIT) - { 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 - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free logfiles\n")); - for (i = 0; i < SOAP_MAXLOGS; i++) - { if (soap->logfile[i]) - { SOAP_FREE(soap, (void*)soap->logfile[i]); - soap->logfile[i] = NULL; - } - soap_close_logfile(soap, i); - } - soap_free_mht(soap); - soap->state = 0; -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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_code_str(h_error_codes, soap->errnum); - if (!msg) -#endif - { sprintf(soap->msgbuf, "TCP/UDP IP error %d", soap->errnum); - msg = soap->msgbuf; - } - } - } - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static const char* -http_error(struct soap *soap, int status) -{ register const char *msg = SOAP_STR_EOS; -#ifndef WITH_LEAN - msg = soap_code_str(h_http_error_codes, status); - if (!msg) - msg = SOAP_STR_EOS; -#endif - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_IPV6 -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr) -{ soap_int32 iadd = -1; - struct hostent hostent, *host = &hostent; -#ifdef VXWORKS - int hostint; - /* inet_addr(), and hostGetByName() expect "char *"; addr is a "const char *". */ - iadd = inet_addr((char*)addr); -#else -#if defined(_AIXVERSION_431) || defined(TRU64) - struct hostent_data ht_data; -#endif -#ifdef AS400 - iadd = inet_addr((void*)addr); -#else - iadd = inet_addr(addr); -#endif -#endif - if (iadd != -1) - { memcpy(inaddr, &iadd, sizeof(iadd)); - 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); -#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((char*)addr); - if (hostint == ERROR) - { host = NULL; - soap->errnum = soap_errno; - } -#else -#ifdef AS400 - if (!(host = gethostbyname((void*)addr))) - soap->errnum = h_errno; -#else - if (!(host = gethostbyname(addr))) - soap->errnum = h_errno; -#endif -#endif - if (!host) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Host name not found\n")); - return SOAP_ERR; - } -#ifdef VXWORKS - inaddr->s_addr = hostint; -#else - memcpy(inaddr, host->h_addr, host->h_length); -#endif - return SOAP_OK; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port) -{ -#ifdef WITH_IPV6 - struct addrinfo hints, *res, *ressave; -#endif - register int err, 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->errnum = 0; - soap_set_sender_error(soap, tcp_error(soap), "TCP init failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->errmode = 0; -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - soap->errmode = 2; - if (soap->proxy_host) - err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &res); - else - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &res); - if (err) - { soap_set_sender_error(soap, gai_strerror(err), "getaddrinfo failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - ressave = res; -again: - fd = (int)socket(res->ai_family, res->ai_socktype, res->ai_protocol); - soap->errmode = 0; -#else -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - fd = (int)socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - fd = (int)socket(AF_INET, SOCK_STREAM, 0); -#endif - if (fd < 0) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "socket failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#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(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - else if (soap->connect_flags && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, soap->connect_flags, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - if (soap->keep_alive && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } -#endif -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket %d to host='%s' port=%d\n", fd, host, port)); -#ifndef WITH_IPV6 - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (soap->proxy_host) - { if (soap->fresolve(soap, soap->proxy_host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)soap->proxy_port); - } - else - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)port); - } - soap->errmode = 0; - if ((soap->omode & SOAP_IO_UDP)) - return fd; -#endif -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&nonblocking)); /* modified to use fd */ - } -#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); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK); -#endif -#endif - for (;;) - { -#ifdef WITH_IPV6 - if (connect((SOAP_SOCKET)fd, res->ai_addr, res->ai_addrlen)) -#else - if (connect((SOAP_SOCKET)fd, (struct sockaddr*)&soap->peer, sizeof(soap->peer))) -#endif - { -#ifndef WITH_LEAN - if (soap->connect_timeout && (soap_socket_errno(fd) == SOAP_EINPROGRESS || soap_socket_errno(fd) == SOAP_EWOULDBLOCK)) - { struct timeval timeout; - SOAP_SOCKLEN_T k; - 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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return SOAP_INVALID_SOCKET; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fds); - FD_SET((SOAP_SOCKET)fd, &fds); - for (;;) - { register 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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - r = soap_socket_errno(fd); - if (r != SOAP_EINTR) - { soap->errnum = r; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - k = (SOAP_SOCKLEN_T)sizeof(soap->errnum); - if (!getsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &k) && !soap->errnum) /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - break; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - if (!soap->errnum) - soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - else -#endif -#ifdef WITH_IPV6 - if (res->ai_next) - { res = res->ai_next; - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - goto again; - } - else -#endif - err = soap_socket_errno(fd); - if (err && err != SOAP_EINTR) - { soap->errnum = err; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - else - break; - } -#ifdef WITH_IPV6 - soap->peerlen = 0; /* IPv6: already connected so use send() */ - freeaddrinfo(ressave); -#endif -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long blocking = 0; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK); -#endif -#endif - soap->socket = fd; - soap->imode &= ~SOAP_ENC_SSL; - soap->omode &= ~SOAP_ENC_SSL; - if (!soap_tag_cmp(endpoint, "https:*")) - { -#ifdef WITH_OPENSSL - BIO *bio; - 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 */ - char *userid, *passwd; - char endp[sizeof(soap->endpoint)]; - soap->omode &= ~SOAP_ENC; /* mask IO and ENC */ - soap->omode |= SOAP_IO_BUFFER; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to %s proxy server\n", soap->proxy_http_version)); - sprintf(soap->tmpbuf, "CONNECT %s:%d HTTP/%s", host, port, soap->proxy_http_version); - if (soap_begin_send(soap) - || (soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL))) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } -#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))) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return soap->error; - } - } -#endif - if ((soap->error = soap->fposthdr(soap, NULL, NULL)) - || soap_flush(soap)) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->omode = k; - k = soap->imode; - soap->imode &= ~SOAP_ENC; /* mask IO and ENC */ - strcpy(endp, soap->endpoint); - userid = soap->userid; /* preserve */ - passwd = soap->passwd; /* preserve */ - if ((soap->error = soap->fparse(soap))) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - strcpy(soap->endpoint, endp); /* restore */ - soap->userid = userid; /* restore */ - soap->passwd = passwd; /* restore */ - soap->imode = k; /* restore */ - soap->count = n; /* restore */ - if (soap_begin_send(soap)) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - 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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->ssl = SSL_new(soap->ctx); - if (!soap->ssl) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; - } - 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; - bio = BIO_new_socket((SOAP_SOCKET)fd, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, bio); -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&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, soap_ssl_error(soap, r), "SSL connect failed in tcp_connect()", SOAP_SSL_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return SOAP_INVALID_SOCKET; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fds); - FD_SET((SOAP_SOCKET)fd, &fds); - for (;;) - { int r = select((SOAP_SOCKET)(fd + 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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - continue; - } - } - break; - } -#ifndef WITH_LEAN - if (soap->connect_timeout) -#ifdef WIN32 - { u_long blocking = 0; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK); -#endif -#endif - if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION)) - { int err; - // TODO: add callback to verify server - 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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - if (!(soap->ssl_flags & SOAP_SSL_SKIP_HOST_CHECK)) - { X509_NAME *subj; - int ext_count; - int ok = 0; - X509 *peer; - 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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - ext_count = X509_get_ext_count(peer); - if (ext_count > 0) - { int i; - for (i = 0; i < ext_count; i++) - { X509_EXTENSION *ext = X509_get_ext(peer, i); - const char *ext_str = OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(ext))); - if (ext_str && !strcmp(ext_str, "subjectAltName")) - { X509V3_EXT_METHOD *meth = X509V3_EXT_get(ext); - void *ext_data; - unsigned char *data; - STACK_OF(CONF_VALUE) *val; - int j; - if (!meth) - break; - data = ext->value->data; -#if (OPENSSL_VERSION_NUMBER > 0x00907000L) - if (meth->it) - ext_data = ASN1_item_d2i(NULL, &data, ext->value->length, ASN1_ITEM_ptr(meth->it)); - else - { /* OpenSSL not perfectly portable at this point (?): - Some compilers appear to prefer - meth->d2i(NULL, (const unsigned char**)&data, ... - */ - ext_data = meth->d2i(NULL, &data, ext->value->length); - } -#else - ext_data = meth->d2i(NULL, &data, ext->value->length); -#endif - val = meth->i2v(meth, ext_data, NULL); - for (j = 0; j < sk_CONF_VALUE_num(val); j++) - { CONF_VALUE *nval = sk_CONF_VALUE_value(val, j); - if (nval && !strcmp(nval->name, "DNS") && !strcmp(nval->value, host)) - { ok = 1; - break; - } - } - } - if (ok) - break; - } - } - if (!ok && (subj = X509_get_subject_name(peer))) - { int i = -1; - do - { ASN1_STRING *name; - i = X509_NAME_get_index_by_NID(subj, NID_commonName, i); - if (i == -1) - break; - name = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(subj, i)); - if (name && !soap_tag_cmp((const char*)name, host)) - ok = 1; - else - { unsigned char *tmp = NULL; - ASN1_STRING_to_UTF8(&tmp, name); - if (tmp) - { if (!soap_tag_cmp((const char*)tmp, host)) - ok = 1; - OPENSSL_free(tmp); - } - } - } while (!ok); - } - X509_free(peer); - if (!ok) - { soap_set_sender_error(soap, "SSL error", "SSL certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - } -#else - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; -#endif - } - return fd; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_bind(struct soap *soap, const char *host, int port, int backlog) -{ -#ifdef WITH_IPV6 - struct addrinfo *addrinfo = NULL; - struct addrinfo hints; - struct addrinfo res; - int err; -#endif -#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 SOAP_INVALID_SOCKET; - } -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - soap->errmode = 2; - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo); - if (addrinfo) - { res = *addrinfo; - soap->peer = *((struct sockaddr_storage*)addrinfo->ai_addr); - soap->peerlen = addrinfo->ai_addrlen; - res.ai_addr = (struct sockaddr*)&soap->peer; - res.ai_addrlen = soap->peerlen; - freeaddrinfo(addrinfo); - } - if (err) - { soap_set_receiver_error(soap, gai_strerror(err), "getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->master = socket(res.ai_family, res.ai_socktype, res.ai_protocol); -#else -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - soap->master = (int)socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - soap->master = (int)socket(AF_INET, SOCK_STREAM, 0); -#endif - soap->errmode = 0; - if (!soap_valid_socket(soap->master)) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "socket failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - soap->socket = soap->master; -#endif -#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->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && setsockopt((SOAP_SOCKET)soap->master, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif -#endif -#ifdef WITH_IPV6 - soap->errmode = 0; - if (bind((SOAP_SOCKET)soap->master, res.ai_addr, res.ai_addrlen)) - { soap->errnum = soap_socket_errno(soap->master); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n")); - soap_closesock(soap); - soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#else - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (host) - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_receiver_error(soap, tcp_error(soap), "get host by name failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } - else - soap->peer.sin_addr.s_addr = htonl(INADDR_ANY); - soap->peer.sin_port = htons((short)port); - soap->errmode = 0; - if (bind((SOAP_SOCKET)soap->master, (struct sockaddr*)&soap->peer, soap->peerlen)) - { soap->errnum = soap_socket_errno(soap->master); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n")); - soap_closesock(soap); - soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif - if (!(soap->omode & SOAP_IO_UDP) && listen((SOAP_SOCKET)soap->master, backlog)) - { soap->errnum = soap_socket_errno(soap->master); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n")); - soap_closesock(soap); - soap_set_receiver_error(soap, tcp_error(soap), "listen failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - return soap->master; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_poll(struct soap *soap) -{ -#ifndef WITH_LEAN - struct timeval timeout; - fd_set rfd, sfd, xfd; - int r; - timeout.tv_sec = 0; - timeout.tv_usec = 0; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_ZERO(&xfd); - if (soap_valid_socket(soap->socket)) - { FD_SET((SOAP_SOCKET)soap->socket, &rfd); - FD_SET((SOAP_SOCKET)soap->socket, &sfd); - FD_SET((SOAP_SOCKET)soap->socket, &xfd); - r = select((SOAP_SOCKET)(soap->socket + 1), &rfd, &sfd, &xfd, &timeout); - if (r > 0 && FD_ISSET((SOAP_SOCKET)soap->socket, &xfd)) - r = -1; - } - else if (soap_valid_socket(soap->master)) - { FD_SET((SOAP_SOCKET)soap->master, &sfd); - r = select((SOAP_SOCKET)(soap->master + 1), NULL, &sfd, NULL, &timeout); - } - else - return SOAP_OK; - if (r > 0) - { -#ifdef WITH_OPENSSL - if (soap->imode & SOAP_ENC_SSL) - { - if (soap_valid_socket(soap->socket) - && FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - && (!FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - || SSL_peek(soap->ssl, soap->tmpbuf, 1) > 0)) - return SOAP_OK; - } - else -#endif - if (soap_valid_socket(soap->socket) - && FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - && (!FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - || recv((SOAP_SOCKET)soap->socket, soap->tmpbuf, 1, MSG_PEEK) > 0)) - return SOAP_OK; - } - else if (r < 0) - { soap->errnum = soap_socket_errno(soap->master); - if ((soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno(soap->master) != SOAP_EINTR) - { 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 = 0; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Polling: other end down on socket=%d select=%d\n", soap->socket, r)); - return SOAP_EOF; -#else - return SOAP_OK; -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_accept(struct soap *soap, int s, struct sockaddr *a, int *n) -{ int fd; - fd = (int)accept((SOAP_SOCKET)s, a, (SOAP_SOCKLEN_T*)n); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ -#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 WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_accept(struct soap *soap) -{ int n = (int)sizeof(soap->peer); -#ifndef WITH_LEAN - int len = SOAP_BUFLEN; - int set = 1; -#endif - soap->error = SOAP_OK; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - return soap->socket = soap->master; -#endif - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->socket = SOAP_INVALID_SOCKET; - soap->errmode = 0; - soap->keep_alive = 0; - if (soap_valid_socket(soap->master)) - { register int err; - 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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return SOAP_INVALID_SOCKET; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->master, &fd); - for (;;) - { register 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", "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - r = soap_socket_errno(soap->master); - if (r != SOAP_EINTR) - { soap->errnum = r; - soap_closesock(soap); - soap_set_sender_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&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); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK); -#endif -#endif - soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&soap->peer, &n); - soap->peerlen = (size_t)n; - if (soap_valid_socket(soap->socket)) - { -#ifdef WITH_IPV6 -/* Use soap->host to store the numeric form of the remote host */ - getnameinfo((struct sockaddr*)&soap->peer, 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->peer and soap->host */ - soap->port = 0; /* info stored in soap->peer and soap->host */ -#else - soap->ip = ntohl(soap->peer.sin_addr.s_addr); - soap->port = (int)ntohs(soap->peer.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)); -#endif -#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->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - else if (soap->accept_flags && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, soap->accept_flags, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && setsockopt((SOAP_SOCKET)soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#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); -#elif defined(VXWORKS) - u_long blocking = 0; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&blocking)); - ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)(&blocking)); -#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 - } - soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0); - return soap->socket; - } - err = soap_socket_errno(soap->socket); - if (err != 0 && err != SOAP_EINTR && err != SOAP_EAGAIN) - { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host)); - soap->errnum = err; - soap_set_receiver_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - } - else - { soap->errnum = 0; - soap_set_receiver_error(soap, tcp_error(soap), "no master socket in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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) && !(soap->omode & SOAP_IO_UDP)) - { 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 WITH_NOIO -#ifndef PALM_1 -static int -tcp_closesocket(struct soap *soap, SOAP_SOCKET fd) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket %d\n", (int)fd)); - return soap_closesocket(fd); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET fd, int how) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket %d how=%d\n", (int)fd, 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; - if (status == SOAP_EOF || status == SOAP_TCP_ERROR || status == SOAP_SSL_ERROR || !soap->keep_alive) - { if (soap->fclose && (soap->error = soap->fclose(soap))) - return soap->error; - soap->keep_alive = 0; - } -#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 WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_init_pht(struct soap *soap) -{ register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing pointer hashtable\n")); - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new1(soap_mode mode) -{ return soap_new2(mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new() -{ return soap_new2(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new2(soap_mode imode, soap_mode omode) -{ struct soap *soap = (struct soap*)malloc(sizeof(struct soap)); - if (soap) - soap_init2(soap, imode, omode); - return soap; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_free(struct soap *soap) -{ soap_done(soap); - free(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_del(struct soap *soap) -{ free(soap); -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_free_pht(struct soap *soap) -{ register struct soap_pblk *pb, *next; - register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n")); - for (pb = soap->pblk; pb; pb = next) - { next = pb->next; - SOAP_FREE(soap, pb); - } - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 size_t h; - register struct soap_plist *pp; - if (!soap->pblk || soap->pidx >= SOAP_PTRBLK) - { register struct soap_pblk *pb = (struct soap_pblk*)SOAP_MALLOC(soap, sizeof(struct soap_pblk)); - if (!pb) - { soap->error = SOAP_EOM; - return 0; - } - pb->next = soap->pblk; - soap->pblk = pb; - soap->pidx = 0; - } - *ppp = pp = &soap->pblk->plist[soap->pidx++]; - 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=%d\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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_begin_count(struct soap *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)) -#ifndef WITH_LEANER - && !soap->fpreparesend -#endif - )) - soap->mode &= ~SOAP_IO_LENGTH; - else - soap->mode |= SOAP_IO_LENGTH; - } -#ifdef WITH_ZLIB - 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; - } -#endif - if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH)) - soap->mode |= SOAP_XML_TREE; -#ifndef WITH_LEANER - if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME)) - soap->mode |= SOAP_ENC_MIME; - else - soap->mode &= ~SOAP_ENC_MTOM; - 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_clr_attr(soap); - soap_set_local_namespaces(soap); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); -#ifndef WITH_LEANER - soap->dime.count = 0; /* count # of attachments */ - soap->dime.size = 0; /* accumulate total size of attachments */ - if (soap->fprepareinit && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_end_count(struct soap *soap) -{ -#ifndef WITH_LEANER - if (soap->fpreparefinal) - return soap->error = soap->fpreparefinal(soap); -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of count phase\n")); - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_begin_send(struct soap *soap) -{ soap->error = SOAP_OK; - soap->mode = soap->omode | (soap->mode & (SOAP_IO_LENGTH | SOAP_ENC_DIME)); -#ifdef WITH_ZLIB - 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; - } -#endif -#ifdef WITH_UDP - if ((soap->mode & SOAP_IO_UDP)) - { soap->mode |= SOAP_ENC_XML; - if (soap->count > SOAP_BUFLEN) - return soap->error = SOAP_UDP_ERROR; - } -#endif - if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket)) - { if (soap->count || (soap->mode & SOAP_IO_LENGTH) || (soap->mode & SOAP_ENC_XML)) - soap->mode |= SOAP_IO_BUFFER; - else - soap->mode |= SOAP_IO_STORE; - } - soap->mode &= ~SOAP_IO_LENGTH; - 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_MTOM) && (soap->mode & SOAP_ENC_DIME)) - { soap->mode |= SOAP_ENC_MIME; - soap->mode &= ~SOAP_ENC_DIME; - } - else - soap->mode &= ~SOAP_ENC_MTOM; - if (soap->mode & SOAP_ENC_MIME) - soap_select_mime_boundary(soap); -#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 -#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->idnum = 0; - soap->level = 0; - soap_clr_attr(soap); - soap_set_local_namespaces(soap); -#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=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); - soap->part = SOAP_BEGIN; -#ifndef WITH_LEANER - if (soap->fprepareinit && (soap->mode & SOAP_IO) == SOAP_IO_STORE) - soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 || !a->__ptr) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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; - if (soap->mode & SOAP_XML_TREE) - return id; - 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_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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_attachment(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; - int i; - 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:"")); - i = soap_array_pointer_lookup(soap, p, a, n, t, &pp); - if (!i) - { i = soap_pointer_enter(soap, p, a, n, t, &pp); - if (!i) - { soap->error = SOAP_EOM; - return -1; - } - } - if (id <= 0) - id = i; - if (!aid) - { sprintf(soap->tmpbuf, soap->dime_id_format, id); - aid = soap_strdup(soap, soap->tmpbuf); - } - /* Add MTOM xop:Include element when necessary */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - if ((soap->mode & SOAP_ENC_MTOM) && strcmp(tag, "xop:Include")) - { if (soap_element_begin_out(soap, tag, 0, type) - || soap_element_href(soap, "xop:Include", 0, "href", aid) - || soap_element_end_out(soap, tag)) - return soap->error; - } - else 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; - if (soap->mode & SOAP_ENC_MTOM) - content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, (char*)a->__ptr, a->__size); - else - content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, (char*)a->__ptr, a->__size); - if (!content) - { soap->error = SOAP_EOM; - return -1; - } - if (!strncmp(aid, "cid:", 4)) /* RFC 2111 */ - { if (soap->mode & SOAP_ENC_MTOM) - { char *s = (char*)soap_malloc(soap, strlen(aid) - 1); - if (s) - { *s = '<'; - strcpy(s + 1, aid + 4); - strcat(s, ">"); - content->id = s; - } - } - else - content->id = aid + 4; - } - else - content->id = aid; - content->type = atype; - content->options = aoptions; - content->encoding = SOAP_MIME_BINARY; - pp->mark1 = 3; - } - } - else - pp->mark2 = 3; - return -1; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, fp); - } - p = ip->next; - SOAP_FREE(soap, ip); - } - soap->iht[i] = NULL; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_2 -SOAP_FMAC1 -struct soap_ilist * -SOAP_FMAC2 -soap_lookup(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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, 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 -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_malloc(struct soap *soap, size_t n) -{ register char *p; - if (!n) - return (void*)SOAP_NON_NULL; - if (!soap) - return SOAP_MALLOC(soap, n); - if (soap->fmalloc) - p = (char*)soap->fmalloc(soap, n); - else - { n += sizeof(short); - n += (-(long)n) & (sizeof(void*)-1); /* align at 4-, 8- or 16-byte boundary */ - if (!(p = (char*)SOAP_MALLOC(soap, n + sizeof(void*) + sizeof(size_t)))) - { soap->error = SOAP_EOM; - return NULL; - } - /* set the canary to detect corruption */ - *(short*)(p + n - sizeof(short)) = (short)SOAP_CANARY; - /* keep chain of alloced cells for destruction */ - *(void**)(p + n) = soap->alist; - *(size_t*)(p + n + sizeof(void*)) = n; - soap->alist = p + n; - } - soap->alloced = 1; - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -static void -soap_init_mht(struct soap *soap) -{ register int i; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->mht[i] = NULL; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -static void -soap_free_mht(struct soap *soap) -{ register int i; - register struct soap_mlist *mp, *mq; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - { for (mp = soap->mht[i]; mp; mp = mq) - { mq = mp->next; - if (mp->live) - fprintf(stderr, "%s(%d): malloc() = %p not freed (memory leak or forgot to call soap_end()?)\n", mp->file, mp->line, mp->ptr); - free(mp); - } - soap->mht[i] = NULL; - } -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_track_malloc(struct soap *soap, const char *file, int line, size_t size) -{ register void *p = malloc(size); - if (soap) - { register size_t h = soap_hash_ptr(p); - register struct soap_mlist *mp = (struct soap_mlist*)malloc(sizeof(struct soap_mlist)); - if (soap->fdebug[SOAP_INDEX_TEST]) - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): malloc(%lu) = %p\n", file, line, (unsigned long)size, p)); - mp->next = soap->mht[h]; - mp->ptr = p; - mp->file = file; - mp->line = line; - mp->live = 1; - soap->mht[h] = mp; - } - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_track_free(struct soap *soap, const char *file, int line, void *p) -{ register size_t h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - { if (mp->live) - { free(p); - if (soap->fdebug[SOAP_INDEX_TEST]) - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): free(%p)\n", file, line, p)); - mp->live = 0; - } - else - fprintf(stderr, "%s(%d): free(%p) double free of pointer malloced at %s(%d)\n", file, line, p, mp->file, mp->line); - } - else - fprintf(stderr, "%s(%d): free(%p) pointer not malloced\n", file, line, p); -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -static void -soap_track_unlink(struct soap *soap, const void *p) -{ register size_t h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - mp->live = 0; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_dealloc(struct soap *soap, void *p) -{ if (soap_check_state(soap)) - return; - if (p) - { register char **q; - for (q = (char**)&soap->alist; *q; q = *(char***)q) - { - if (*(short*)(char*)(*q - sizeof(short)) != (short)SOAP_CANARY) - { fprintf(stderr, "Data corruption in dynamic allocation (see logs)\n"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Data corruption:\n")); - DBGHEX(TEST, *q - 200, 200); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n")); - soap->error = SOAP_MOE; - return; - } - 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(soap, p); - return; - } - } - soap_delete(soap, p); - } - else - { register char *q; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free all soap_malloc() data\n")); - while (soap->alist) - { q = (char*)soap->alist; - if (*(short*)(char*)(q - sizeof(short)) != (short)SOAP_CANARY) - { fprintf(stderr, "Data corruption in dynamic allocation (see logs)\n"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Data corruption:\n")); - DBGHEX(TEST, q - 200, 200); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n")); - soap->error = SOAP_MOE; - return; - } - soap->alist = *(void**)q; - q -= *(size_t*)(q + sizeof(void*)); - SOAP_FREE(soap, q); - } - } - /* we must assume these were deallocated: */ - soap->action = NULL; - soap->fault = NULL; - soap->header = NULL; - soap->userid = NULL; - soap->passwd = 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; - if (soap_check_state(soap)) - return; - 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(soap, 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; - q->fdelete(q); - SOAP_FREE(soap, 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(soap, 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)); -#ifdef SOAP_DEBUG - soap_track_unlink(soap, p); -#endif - 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(soap, q); - return; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 (!p || !id || !*id) - return p; - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_2 -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_id_forward(struct soap *soap, const char *href, void *p, size_t len, int st, int tt, size_t n, unsigned int k, void (*fcopy)(struct soap*, int, int, void*, size_t, 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(soap, 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; - fp->len = len; - 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 len=%lu href='%s'\n", st, tt, (unsigned long)n, p, k, (unsigned long)len, 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 -#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*)) -{ -#ifndef WITH_NOIDREF - struct soap_ilist *ip; -#endif - 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; - } -#ifndef WITH_NOIDREF - if (!id || !*id) -#endif - return p; -#ifndef WITH_NOIDREF - 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_DUPLICATE_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 -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_fcopy(struct soap *soap, int st, int tt, void *p, size_t len, 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; -#ifndef WITH_NOHTTP - 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++; - } -#endif - 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); - } -#ifndef WITH_LEANER - 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_TCPFIN -#ifdef WITH_OPENSSL - if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */ -#else - if (soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */ -#endif -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send phase\n")); - soap->omode &= ~SOAP_XML_SEC; - soap->count = 0; - soap->part = SOAP_END; - 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_DIME) && soap_getdime(soap)) - return soap->error; - soap->dime.list = soap->dime.first; - soap->dime.first = NULL; - soap->dime.last = NULL; - /* Check if MIME attachments and mime-post-check flag is set, if set call soap_resolve() and return */ - if (soap->mode & SOAP_ENC_MIME) - { if (soap->mode & SOAP_MIME_POSTCHECK) - { soap_resolve(soap); - return SOAP_OK; - } - if (soap_getmime(soap)) - return soap->error; - } - soap->mime.list = soap->mime.first; - soap->mime.first = NULL; - soap->mime.last = NULL; - soap->mime.boundary = NULL; - if (soap->xlist) - { struct soap_multipart *content; - for (content = soap->mime.list; content; content = content->next) - soap_resolve_attachment(soap, content); - } -#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; -#ifndef WITH_NOIDREF - if (soap_resolve(soap)) - return soap->error; -#endif -#ifndef WITH_LEANER - if (soap->xlist) - { if (soap->mode & SOAP_ENC_MTOM) - return soap->error = SOAP_MIME_HREF; - return soap->error = SOAP_DIME_HREF; - } -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_free_temp(struct soap *soap) -{ register struct Namespace *ns; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n")); - while (soap->nlist) - { register struct soap_nlist *np = soap->nlist->next; - SOAP_FREE(soap, 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 attribute storage\n")); - while (soap->attributes) - { register struct soap_attribute *tp = soap->attributes->next; - if (soap->attributes->value) - SOAP_FREE(soap, soap->attributes->value); - SOAP_FREE(soap, soap->attributes); - soap->attributes = tp; - } -#ifdef WITH_FAST - if (soap->labbuf) - SOAP_FREE(soap, soap->labbuf); - soap->labbuf = NULL; - soap->lablen = 0; - soap->labidx = 0; -#endif - ns = soap->local_namespaces; - if (ns) - { for (; ns->id; ns++) - { if (ns->out) - { if (soap->encodingStyle == ns->out) - soap->encodingStyle = SOAP_STR_EOS; - SOAP_FREE(soap, ns->out); - ns->out = NULL; - } - if (soap->encodingStyle == ns->ns) - soap->encodingStyle = SOAP_STR_EOS; - } - SOAP_FREE(soap, soap->local_namespaces); - soap->local_namespaces = NULL; - } -#ifndef WITH_LEANER - while (soap->xlist) - { struct soap_xlist *xp = soap->xlist->next; - SOAP_FREE(soap, soap->xlist); - soap->xlist = xp; - } -#endif -#ifndef WITH_NOIDREF - soap_free_pht(soap); - soap_free_iht(soap); -#endif -} -#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(soap, (void*)soap->logfile[i]); - if (logfile) - if ((s = (char*)SOAP_MALLOC(soap, 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*)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 (soap_check_state(soap)) - return NULL; - if (copy) - { register struct soap_plugin *p; - memcpy(copy, soap, sizeof(struct soap)); - copy->state = SOAP_COPY; - copy->error = SOAP_OK; - copy->userid = NULL; - copy->passwd = NULL; - copy->nlist = NULL; - copy->blist = NULL; - copy->clist = NULL; - copy->alist = NULL; - copy->attributes = NULL; - copy->labbuf = NULL; - copy->lablen = 0; - copy->labidx = 0; -#ifdef SOAP_DEBUG - soap_init_mht(copy); -#endif - copy->local_namespaces = NULL; -#ifndef WITH_NOIDREF - soap_init_iht(copy); - soap_init_pht(copy); -#endif - copy->header = NULL; - copy->fault = NULL; - copy->action = NULL; -#ifndef WITH_LEAN -#ifdef WITH_COOKIES - copy->cookies = soap_copy_cookies(copy, soap); -#else - copy->cookies = NULL; -#endif -#endif -#ifdef SOAP_DEBUG - soap_init_logs(copy); - soap_set_recv_logfile(copy, soap->logfile[SOAP_INDEX_RECV]); - soap_set_sent_logfile(copy, soap->logfile[SOAP_INDEX_SENT]); - soap_set_test_logfile(copy, soap->logfile[SOAP_INDEX_TEST]); -#endif - copy->plugins = NULL; - for (p = soap->plugins; p; p = p->next) - { register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(copy, 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(copy, q, p))) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not copy plugin '%s'\n", p->id)); - SOAP_FREE(copy, 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_copy_stream(struct soap *copy, struct soap *soap) -{ copy->mode = soap->mode; - copy->imode = soap->imode; - copy->omode = soap->omode; - copy->socket = soap->socket; - copy->recv_timeout = soap->recv_timeout; - copy->send_timeout = soap->send_timeout; -#if defined(__cplusplus) && !defined(WITH_LEAN) - copy->os = soap->os; - copy->is = soap->is; -#endif - copy->sendfd = soap->sendfd; - copy->recvfd = soap->recvfd; - copy->bufidx = soap->bufidx; - copy->buflen = soap->buflen; - copy->ahead = soap->ahead; - copy->cdata = soap->cdata; - copy->chunksize = soap->chunksize; - copy->chunkbuflen = soap->chunkbuflen; - copy->keep_alive = soap->keep_alive; - copy->max_keep_alive = soap->max_keep_alive; -#ifndef WITH_NOIO - copy->peer = soap->peer; - copy->peerlen = soap->peerlen; -#endif -#ifdef WITH_OPENSSL - copy->bio = soap->bio; - copy->ssl = soap->ssl; - copy->ctx = soap->ctx; -#endif -#ifdef WITH_ZLIB - copy->zlib_state = soap->zlib_state; - copy->zlib_in = soap->zlib_in; - copy->zlib_out = soap->zlib_out; - copy->d_stream = soap->d_stream; - copy->z_buflen = soap->z_buflen; - copy->z_level = soap->z_level; - copy->z_crc = soap->z_crc; - copy->z_ratio_in = soap->z_ratio_in; - copy->z_ratio_out = soap->z_ratio_out; - memcpy(copy->z_buf, soap->z_buf, sizeof(soap->z_buf)); -#endif - memcpy(copy->buf, soap->buf, sizeof(soap->buf)); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init(struct soap *soap) -{ soap->state = SOAP_INIT; - soap->version = 0; - soap_imode(soap, SOAP_IO_DEFAULT); - soap_omode(soap, SOAP_IO_DEFAULT); - soap->plugins = NULL; - soap->user = NULL; - soap->userid = NULL; - soap->passwd = NULL; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif - soap->fheader = NULL; - soap->fconnect = NULL; - soap->fdisconnect = NULL; -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif - soap->fseterror = NULL; - soap->fignore = NULL; - soap->fserveloop = NULL; - soap->fplugin = fplugin; - soap->fmalloc = NULL; -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; - soap->fdimereadopen = NULL; - soap->fdimewriteopen = NULL; - soap->fdimereadclose = NULL; - soap->fdimewriteclose = NULL; - soap->fdimeread = NULL; - soap->fdimewrite = NULL; - soap->fmimereadopen = NULL; - soap->fmimewriteopen = NULL; - soap->fmimereadclose = NULL; - soap->fmimewriteclose = NULL; - soap->fmimeread = NULL; - soap->fmimewrite = NULL; -#endif - soap->float_format = "%G"; - soap->double_format = "%lG"; - soap->dime_id_format = "cid:id%d"; /* default DIME id format */ - soap->http_version = "1.1"; - soap->proxy_http_version = "1.0"; - soap->http_content = NULL; - 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; -#ifndef WITH_LEANER - 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; - soap->xlist = NULL; -#endif -#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 - if (!ssl_init_done) - soap_ssl_init(); - soap->fsslauth = ssl_auth_init; - soap->fsslverify = ssl_verify_callback; - soap->bio = NULL; - soap->ssl = NULL; - soap->ctx = NULL; - soap->ssl_flags = SOAP_SSL_DEFAULT; - soap->keyfile = NULL; - soap->password = NULL; - soap->dhfile = NULL; - soap->cafile = NULL; - soap->capath = NULL; - soap->crlfile = 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->c14ninclude = NULL; - soap->c14nexclude = NULL; - soap->cookies = NULL; - soap->cookie_domain = NULL; - soap->cookie_path = NULL; - soap->cookie_max = 32; -#endif -#ifdef SOAP_DEBUG - soap_init_mht(soap); - soap_init_logs(soap); -#endif -#ifdef WMW_RPM_IO - soap->rpmreqid = NULL; -#endif -#ifdef PALM - palmNetLibOpen(); -#endif -#ifndef WITH_NOIDREF - soap_init_iht(soap); - soap_init_pht(soap); -#endif -#ifdef SOAP_DEBUG - soap_set_recv_logfile(soap, "RECV.log"); - soap_set_sent_logfile(soap, "SENT.log"); - soap_set_test_logfile(soap, "TEST.log"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing context\n")); -#endif - soap_begin(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init1(struct soap *soap, soap_mode mode) -{ soap_init2(soap, mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init2(struct soap *soap, soap_mode imode, soap_mode 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, "Reinitializing context\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_END; - 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'; -#ifndef WITH_LEANER - soap->dime.chunksize = 0; - soap->dime.buflen = 0; -#endif - soap_free_temp(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_end(struct soap *soap) -{ register struct soap_clist *cp; - if (soap_check_state(soap)) - return; - soap_free_temp(soap); - soap_dealloc(soap, NULL); - while (soap->clist) - { cp = soap->clist->next; - SOAP_FREE(soap, 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, const struct Namespace *p) -{ register struct Namespace *ns = soap->local_namespaces; - register struct soap_nlist *np, *nq, *nr; - register unsigned int level = soap->level; - soap->namespaces = p; - soap->local_namespaces = NULL; - soap_set_local_namespaces(soap); - /* reverse the namespace 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; - } - } - /* then push on new stack */ - while (np) - { register const char *s; - soap->level = np->level; /* preserve element nesting level */ - s = np->ns; - if (!s && np->index >= 0 && ns) - { s = ns[np->index].out; - if (!s) - s = ns[np->index].ns; - } - if (s && soap_push_namespace(soap, np->id, s)) - return soap->error; - nq = np; - np = np->next; - SOAP_FREE(soap, nq); - } - if (ns) - { register int i; - for (i = 0; ns[i].id; i++) - { if (ns[i].out) - { SOAP_FREE(soap, ns[i].out); - ns[i].out = NULL; - } - } - SOAP_FREE(soap, ns); - } - soap->level = level; /* restore level */ - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -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++; - n *= sizeof(struct Namespace); - ns2 = (struct Namespace*)SOAP_MALLOC(soap, n); - if (ns2) - { memcpy(ns2, soap->namespaces, n); - if (ns2[0].ns) - { if (!strcmp(ns2[0].ns, soap_env1)) - soap->version = 1; - else - soap->version = 2; - } - soap->local_namespaces = ns2; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef PALM_1 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_strsearch(const char *big, const char *little) -{ size_t n = strlen(little); - const char *s = big; - while (s) - { if (!strncmp(s, little, n) && (s[n] == '\0' || s[n] == ' ')) - return s; - s = strchr(s, ' '); - if (s) - s++; - } - return NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef PALM_1 -SOAP_FMAC1 -struct soap_nlist * -SOAP_FMAC2 -soap_lookup_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np; - for (np = soap->nlist; np; np = np->next) - { if (!strncmp(np->id, tag, n) && !np->id[n]) - return np; - } - return NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static struct soap_nlist * -soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized) -{ register struct soap_nlist *np; - size_t n, k; - if (soap_strsearch(soap->c14nexclude, id)) - return NULL; - if (!utilized) - { for (np = soap->nlist; np; np = np->next) - { if (!strcmp(np->id, id) && (!np->ns || !strcmp(np->ns, ns))) - break; - } - if (np) - { if ((np->level < soap->level || !np->ns) && np->index == 1) - utilized = 1; - else - return NULL; - } - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Adding namespace binding (level=%u) '%s' '%s' utilized=%d\n", soap->level, id, ns?ns:"(null)", utilized)); - n = strlen(id); - if (ns) - k = strlen(ns); - else - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k + 1); - if (!np) - { soap->error = SOAP_EOM; - return NULL; - } - np->next = soap->nlist; - soap->nlist = np; - strcpy(np->id, id); - if (ns) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - } - else - np->ns = NULL; - np->level = soap->level; - np->index = utilized; - return np; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_utilize_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np = soap_lookup_ns(soap, tag, n); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Utilizing namespace of '%s'\n", tag)); - if (np) - { if (np->index == 0) - soap_push_ns(soap, np->id, np->ns, 1); - } - else if (strncmp(tag, "xml", 3)) - { strncpy(soap->tmpbuf, tag, n); - soap->tmpbuf[n] = '\0'; - soap_push_ns(soap, soap->tmpbuf, NULL, 1); - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_pop_ns(struct soap *soap) -{ soap_pop_namespace(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_element(struct soap *soap, const char *tag, int id, const char *type) -{ -#ifdef WITH_XMLNS - register const char *s; -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' id='%d' type='%s'\n", tag, id, type?type:"")); -#ifdef WITH_DOM - if (soap->part == SOAP_BEGIN_SECURITY && (soap->mode & SOAP_XML_CANONICAL) && !(soap->mode & SOAP_DOM_ASIS)) - { register struct soap_nlist *np; - /* wsu:Id found: clear xmlns renderings, so re-emit them for exc-c14n */ - for (np = soap->nlist; np; np = np->next) - { if (np->index == 2) - np->index = 0; - } - } - if (soap->mode & SOAP_XML_DOM) - { register struct soap_dom_element *elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->soap = soap; - elt->next = NULL; - elt->prnt = soap->dom; - elt->name = soap_strdup(soap, tag); - elt->elts = NULL; - elt->atts = NULL; - elt->nstr = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->node = NULL; - elt->type = 0; - elt->head = NULL; - elt->tail = NULL; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - } - else - { -#endif - soap->level++; -#ifndef WITH_LEAN - if (!soap->ns) - { if (!(soap->mode & SOAP_XML_CANONICAL) - && soap_send(soap, soap->prolog ? soap->prolog : "\n")) - return soap->error; - } - else if (soap->mode & SOAP_XML_INDENT) - { if (soap->ns == 1 && soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - soap->body = 1; - } -#endif -#ifdef WITH_XMLNS - s = strchr(tag, ':'); - if (s && strncmp(tag, "SOAP-ENV", s - tag)) - { struct Namespace *ns = soap->local_namespaces; - size_t n = s - tag; - if (soap_send_raw(soap, "<", 1) - || soap_send(soap, s + 1)) - return soap->error; - if (soap->nlist && !strncmp(soap->nlist->id, tag, n) && !soap->nlist->id[n]) - ns = NULL; - for (; ns && ns->id; ns++) - { if (*ns->id && (ns->out || ns->ns) && !strncmp(ns->id, tag, n) && !ns->id[n]) - { soap_push_ns(soap, ns->id, ns->out ? ns->out : ns->ns, 0); - if (soap_attribute(soap, "xmlns", ns->out ? ns->out : ns->ns)) - return soap->error; - break; - } - } - } - else -#endif - if (soap_send_raw(soap, "<", 1) - || soap_send(soap, tag)) - return soap->error; -#ifdef WITH_DOM - } -#endif - if (!soap->ns) - { struct Namespace *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; /* start with 0 or 2, but should be one to continue */ -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *t = strchr(tag, ':'); - if (t) - soap_utilize_ns(soap, tag, t - tag); - } -#endif - if (id > 0) - { sprintf(soap->tmpbuf, "_%d", id); - if (soap_attribute(soap, "id", soap->tmpbuf)) - return soap->error; - } - if (type && *type && (!(soap->mode & SOAP_XML_SEC) || soap->part == SOAP_IN_BODY)) - { if (soap_attribute(soap, "xsi:type", type)) - return soap->error; -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *t = strchr(type, ':'); - if (t) - soap_utilize_ns(soap, type, t - type); - } -#endif - } - if (soap->null && soap->position > 0) - { register 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; - if (soap->part == SOAP_BEGIN_SECURITY && (soap->mode & SOAP_XML_CANONICAL)) - soap->part = SOAP_IN_SECURITY; - 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 && (n > 214748364 || c >= '8')) - 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 && (n > 429496729 || c >= '6')) - 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; - } -#ifndef WITH_LEAN - if (type && *type && (soap->mode & SOAP_XML_CANONICAL)) - { const char *s = strchr(type, ':'); - if (s) - soap_utilize_ns(soap, type, s - type); - } -#endif - 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; -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { struct soap_nlist *np; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible && tp->name) - { const char *s = strchr(tp->name, ':'); - if (s) - soap_utilize_ns(soap, tp->name, s - tp->name); - } - } - for (np = soap->nlist; np; np = np->next) - { if (np->index == 1 && np->ns) - { sprintf(soap->tmpbuf, "xmlns:%s", np->id); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enabling utilized binding (level=%u) %s='%s'\n", np->level, soap->tmpbuf, np->ns)); - soap_set_attr(soap, soap->tmpbuf, np->ns); - np->index = 2; - } - } - } -#endif -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { register struct soap_dom_attribute **att; - att = &soap->dom->atts; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, tp->name); - (*att)->data = soap_strdup(soap, tp->value); - (*att)->wide = NULL; - (*att)->soap = soap; - att = &(*att)->next; - tp->visible = 0; - } - } - return SOAP_OK; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { -#ifdef WITH_XMLNS - const char *s = strchr(tp->name, ':'); - if (s) - { size_t n = s - tp->name; - if (soap->nlist && !strncmp(soap->nlist->id, tp->name, n) && !soap->nlist->id[n]) - s++; - else - s = tp->name; - if (soap_send(soap, " ") || soap_send(soap, s)) - return soap->error; - } - else -#endif - if (soap_send(soap, " ") || 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) - { -#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 - soap->level--; /* decrement level just before /> */ - if (soap_send_raw(soap, "/>", 2)) - return soap->error; - return SOAP_OK; - } - 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 -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - soap_pop_ns(soap); - if (soap->mode & SOAP_XML_INDENT) - { if (!soap->body) - { if (soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - } - soap->body = 0; - } -#endif -#ifdef WITH_XMLNS - { const char *s = strchr(tag, ':'); - if (s && strncmp(tag, "SOAP-ENV", s - tag)) - { soap_pop_ns(soap); - tag = s + 1; - } - } -#endif - if (soap_send_raw(soap, "error; - soap->level--; /* decrement level just before > */ - 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; - const char *s = "href"; - if (soap->version == 2) - { s = "SOAP-ENC:ref"; - n = 1; - } - sprintf(soap->href, "#_%d", href); - return soap_element_href(soap, tag, id, s, 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) -{ if (!p || (a && !a->__ptr)) - { soap_element_null(soap, tag, id, type); - return -1; - } -#ifndef WITH_NOIDREF - if (soap->mode & SOAP_XML_TREE) - return 0; - if (id < 0) - { struct soap_plist *pp; - 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; -#else - return 0; -#endif -} -#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_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_check_result(struct soap *soap, const char *tag) -{ if (soap->version == 2 && soap->encodingStyle) - { soap_instring(soap, ":result", NULL, NULL, 0, 2, -1, -1); - /* should compare tag to element's QName value? */ - } -} -#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->mode & SOAP_XML_CANONICAL) && 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); - a->data = soap_strdup(soap, value); - a->wide = NULL; - a->soap = soap; - soap->dom->atts = a; - return SOAP_OK; - } -#endif -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { /* TODO: consider using this code to handle default namespace bindings - if (!strncmp(name, "xmlns", 5) && (name[5] == ':' || name[5] == '\0')) - { if (name[5] == ':') - soap_push_ns(soap, name + 6, value, 0); - else - soap_push_ns(soap, "", value, 0); - } - */ - if (!strncmp(name, "xmlns:", 6)) - soap_push_ns(soap, name + 6, value, 0); - else if (soap_set_attr(soap, name, value)) - return soap->error; - } - else -#endif - { if (soap_send(soap, " ") || 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, int nillable, const char *type) -{ 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; - if (type && *soap->type && soap_match_tag(soap, soap->type, type)) - return soap->error = SOAP_TYPE; - } - } - else if (soap->error == SOAP_NO_TAG && tag && *tag == '-') - soap->error = SOAP_OK; - 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; - register int n = 0; - if (tag && *tag == '-') - return SOAP_OK; - soap->level--; - soap_pop_namespace(soap); -#ifdef WITH_DOM - /* this whitespace or mixed content is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!soap->peeked && !soap_string_in(soap, 3, -1, -1)) - return soap->error; - if (soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - if (soap->peeked) - { if (soap->error == SOAP_NO_TAG) - soap->error = SOAP_OK; - if (*soap->tag) - n++; - soap->peeked = 0; - } - do - { while (((c = soap_get(soap)) != SOAP_TT)) - { if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (c == SOAP_LT) - n++; - else if (c == '/') - { c = soap_get(soap); - if (c == SOAP_GT) - n--; - else - soap_unget(soap, c); - } - } - } while (n--); - s = soap->tag; - n = sizeof(soap->tag); - while (soap_notblank(c = soap_get(soap))) - { if (--n > 0) - *s++ = (char)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 || !*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 (tp->visible && !soap_match_tag(soap, tp->name, name)) - break; - } - if (tp) - { 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(soap, 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, ':'); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inserting attribute %s for c14n\n", 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 (tp->visible) - { return SOAP_OK; - } - 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(soap, tp->value); - tp->value = NULL; - tp->ns = NULL; - } - if (value) - { if (!tp->value) - { tp->size = strlen(value) + 1; - if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size))) - return soap->error = SOAP_EOM; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute value for %s (%p)\n", tp->name, tp->value)); - } - strcpy(tp->value, value); - if (!strncmp(tp->name, "xmlns:", 6)) - tp->ns = tp->value; - tp->visible = 2; -#ifndef WITH_LEAN - if (!strcmp(name, "wsu:Id")) - { soap->part = SOAP_BEGIN_SECURITY; - strncpy(soap->id, value, sizeof(soap->id)); - soap->id[sizeof(soap->id)-1] = '\0'; - } -#endif - } - 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; - if (soap->attributes->value) - SOAP_FREE(soap, soap->attributes->value); - SOAP_FREE(soap, 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) -{ register size_t i; - for (i = 0; i < n; i++) - { register soap_wchar c = soap_get(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 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_store_lab(struct soap *soap, const char *s, size_t n) -{ soap->labidx = 0; - return soap_append_lab(soap, s, n); -} -#endif -#endif - -/******************************************************************************/ -#ifdef WITH_FAST -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -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, soap->lablen); - if (!soap->labbuf) - { if (t) - SOAP_FREE(soap, t); - return soap->error = SOAP_EOM; - } - if (t) - { memcpy(soap->labbuf, t, soap->labidx); - SOAP_FREE(soap, 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) -{ -#ifdef WITH_DOM - register struct soap_dom_attribute **att = NULL; - register char *lead = NULL; -#endif - register struct soap_attribute *tp; - const char *t; - register char *s; - register soap_wchar c; - register int i; - if (soap->peeked) - { if (!*soap->tag) - return soap->error = SOAP_NO_TAG; - return SOAP_OK; - } - soap->peeked = 1; - c = soap_getutf8(soap); -#ifdef WITH_DOM - /* whitespace leading to start tag is not insignificant for DOM */ - if (soap_blank(c)) - { soap->labidx = 0; - do - { if (soap_append_lab(soap, NULL, 0)) - return SOAP_EOM; - s = soap->labbuf + soap->labidx; - i = soap->lablen - soap->labidx; - soap->labidx = soap->lablen; - while (soap_blank(c) && i--) - { *s++ = c; - c = soap_getutf8(soap); - } - } - while (soap_blank(c)); - *s = '\0'; - lead = soap_strdup(soap, soap->labbuf); - } -#else - while (soap_blank(c)) - c = soap_getutf8(soap); -#endif - if (c != SOAP_LT) - { *soap->tag = '\0'; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifdef WITH_DOM - /* whitespace leading to end tag is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->tail = soap_strdup(soap, lead); -#endif - return soap->error = SOAP_NO_TAG; - } - s = soap->tag; - do c = soap_get1(soap); - while (soap_blank(c)); - i = sizeof(soap->tag); - while (c != '>' && c != '/' && soap_notblank(c) && (int)c != EOF) - { if (--i > 0) - *s++ = (char)c; - c = soap_get1(soap); - } - while (soap_blank(c)) - c = soap_get1(soap); - *s = '\0'; - 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; -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { register struct soap_dom_element *elt; - elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->next = NULL; - elt->nstr = NULL; - elt->name = soap_strdup(soap, soap->tag); - elt->prnt = soap->dom; - elt->elts = NULL; - elt->atts = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->type = 0; - elt->node = NULL; - elt->head = lead; - elt->tail = NULL; - elt->soap = soap; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - att = &elt->atts; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - tp->visible = 0; - while ((int)c != EOF && c != '>' && c != '/') - { s = soap->tmpbuf; - i = sizeof(soap->tmpbuf); - while (c != '=' && c != '>' && c != '/' && soap_notblank(c) && (int)c != EOF) - { if (--i > 0) - *s++ = (char)c; - c = soap_get1(soap); - } - *s = '\0'; - if (i == sizeof(soap->tmpbuf)) - return soap->error = SOAP_SYNTAX_ERROR; -#ifdef WITH_DOM - /* add attribute name to dom */ - if (att) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, soap->tmpbuf); - (*att)->data = NULL; - (*att)->wide = NULL; - (*att)->soap = soap; - } -#endif - if (!strncmp(soap->tmpbuf, "xmlns", 5)) - { if (soap->tmpbuf[5] == ':') - { soap->tmpbuf[5] = '\0'; - t = soap->tmpbuf + 6; - } - else if (soap->tmpbuf[5]) - t = NULL; - else - 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(soap, 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_get1(soap); - if (c == '=') - { do c = soap_getutf8(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; - if (soap_store_lab(soap, tp->value, tp->size)) - return soap->error; - if (tp->value) - SOAP_FREE(soap, 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; - } - if (soap->labidx) - tp->size = soap->lablen; - else - { tp->size = strlen(soap->labbuf) + 1; - if (tp->size < SOAP_LABLEN) - tp->size = SOAP_LABLEN; - } - if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size))) - return soap->error = SOAP_EOM; - strcpy(tp->value, soap->labbuf); -#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(soap, n))) - return soap->error = SOAP_EOM; - if (tp->value) - { memcpy(s, tp->value, tp->size); - SOAP_FREE(soap, tp->value); - } - soap_save_block(soap, s + tp->size, 0); - tp->value = s; - tp->size = n; -#endif - } - do c = soap_get1(soap); - while (soap_blank(c)); - tp->visible = 2; /* seen this attribute w/ value */ -#ifdef WITH_DOM - if (att) - (*att)->data = soap_strdup(soap, tp->value); -#endif - } - else - tp->visible = 1; /* seen this attribute w/o value */ -#ifdef WITH_DOM - if (att) - att = &(*att)->next; -#endif - if (t && tp->value) - { if (soap_push_namespace(soap, t, tp->value)) - return soap->error; - tp->visible = 0; - } - } -#ifdef WITH_DOM - if (att) - { soap->dom->nstr = soap_current_namespace(soap, soap->tag); - for (att = &soap->dom->atts; *att; att = &(*att)->next) - (*att)->nstr = soap_current_namespace(soap, (*att)->name); - } -#endif - if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (!(soap->body = (c != '/'))) - do c = soap_get1(soap); - while (soap_blank(c)); -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { if (!soap->body && soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible && tp->value) - { if (!strcmp(tp->name, "id")) - { if (soap->version > 0 - || (soap->mode & SOAP_XML_GRAPH)) - { *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")) - { if (soap->version == 1 - || (soap->mode & SOAP_XML_GRAPH) - || (soap->mode & SOAP_ENC_MTOM)) - { strncpy(soap->href, tp->value, sizeof(soap->href) - 1); - 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_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; - } - else if (soap->version == 1) - { if (!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_match_tag(soap, tp->name, "SOAP-ENC:offset")) - strncpy(soap->arrayOffset, tp->value, sizeof(soap->arrayOffset)); - else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:position")) - soap->position = soap_getposition(tp->value, soap->positions); - else if (!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:mustUnderstand") - && (!strcmp(tp->value, "1") || !strcmp(tp->value, "true"))) - soap->mustUnderstand = 1; - else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:actor")) - { if ((!soap->actor || strcmp(soap->actor, tp->value)) - && strcmp(tp->value, "http://schemas.xmlsoap.org/soap/actor/next")) - soap->other = 1; - } - } - else if (soap->version == 2) - { if (!strcmp(tp->name, "ref") - || !soap_match_tag(soap, tp->name, "SOAP-ENC: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, "SOAP-ENC:itemType")) - strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1); - else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:arraySize")) - strncpy(soap->arraySize, tp->value, sizeof(soap->arraySize) - 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, "SOAP-ENV:role")) - { if ((!soap->actor || strcmp(soap->actor, tp->value)) - && strcmp(tp->value, "http://www.w3.org/2003/05/soap-envelope/role/next")) - soap->other = 1; - } - } - } - } - return soap->error = SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_retry(struct soap *soap) -{ soap->error = SOAP_OK; - soap_revert(soap); -} -#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 = 0xFFFFFF80UL; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_strdup(soap, s); - return SOAP_OK; - } -#endif - if (soap->mode & SOAP_C_UTFSTRING) - mask = 0; - t = s; - while ((c = *t++)) - { switch (c) - { - case 0x09: - if (flag) - { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, " ", 5)) - return soap->error; - s = t; - } - break; - case 0x0A: - 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 0x0D: - 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: -#ifndef WITH_LEANER -#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 -#endif - if ((c & mask) || !(c & 0xFFFFFFE0UL)) - { 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; -#if !defined(WITH_LEANER) && defined(HAVE_WCTOMB) - char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8]; -#else - char buf[8]; -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { n = 1; - soap->peeked = 0; -#ifndef WITH_LEAN - t = soap->tmpbuf; - t[0] = '<'; - strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 1); - strncat(t, ">", sizeof(soap->tmpbuf)); - m = strlen(soap->tag) + 2; -#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: -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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*)"amp;"; - m = 4; - } - 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; -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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; - } -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (flag == 3) - soap->dom->tail = t; - else - soap->dom->data = t; - } -#endif - if (flag == 2) - if (soap_s2QName(soap, t, &t)) - return NULL; - return t; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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) - { wchar_t *r = (wchar_t*)s; - int n = 1; - while (*r++) - n++; - soap->dom->wide = r = (wchar_t*)soap_malloc(soap, n * sizeof(wchar_t)); - while (n--) - *r++ = *s++; - return SOAP_OK; - } -#endif - while ((c = *s++)) - { switch (c) - { - case 0x09: - if (flag) - t = " "; - else - t = "\t"; - break; - case 0x0A: - if (flag || !(soap->mode & SOAP_XML_CANONICAL)) - t = " "; - else - t = "\n"; - break; - case 0x0D: - 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 >= 0x20 && 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading wide string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { n = 1; - soap->peeked = 0; - } - } - 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; - } - s = (wchar_t*)soap_save_block(soap, NULL, 0); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->wide = s; -#endif - return s; -} -#endif -#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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = (int)soap_strtol(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (int*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(int), 0, NULL); - else if (p) - { if (soap_s2int(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = soap_strtol(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (long*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(long), 0, NULL); - else if (p) - { if (soap_s2long(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOLL - char *r; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = strtoll(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -# ifdef HAVE_SSCANF - if (sscanf(s, SOAP_LONG_FORMAT, p) != 1) -# endif -#endif - 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, NULL)) - 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 (*soap->href) - p = (LONG64*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(LONG64), 0, NULL); - else if (p) - { if (soap_s2LONG64(soap, soap_value(soap), p)) - return 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 (s == r || *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, NULL)) - 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 (*soap->href) - p = (char*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(char), 0, NULL); - else if (p) - { if (soap_s2byte(soap, soap_value(soap), p)) - return 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 (s == r || *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, NULL)) - 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 (*soap->href) - p = (short*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(short), 0, NULL); - else if (p) - { if (soap_s2short(soap, soap_value(soap), p)) - return 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) -{ char *s; - if (soap_isnan((double)n)) - s = "NaN"; - else if (soap_ispinff(n)) - s = "INF"; - else if (soap_isninff(n)) - s = "-INF"; - else - { char *t; - s = soap->tmpbuf; - sprintf(soap->tmpbuf, soap->float_format, n); - t = strchr(s, ','); /* convert decimal comma to DP */ - if (t) - *t = '.'; - } - 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 (!*s) - return soap->error = SOAP_TYPE; - 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 - { -/* On some systems, strtof appears to be broken or doesn't link: use with caution */ -#if defined(HAVE_STRTOF) - char *r; - *p = strtof((char*)s, &r); - if (*r) -#elif defined(HAVE_STRTOD) - char *r; - *p = (float)strtod(s, &r); - if (*r) -#endif -#ifdef HAVE_SSCANF - if (sscanf(s, "%g", 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, NULL)) - 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 (*soap->href) - p = (float*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(float), 0, NULL); - else if (p) - { if (soap_s2float(soap, soap_value(soap), p)) - return 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) -{ char *s; - if (soap_isnan(n)) - s = "NaN"; - else if (soap_ispinfd(n)) - s = "INF"; - else if (soap_isninfd(n)) - s = "-INF"; - else - { char *t; - s = soap->tmpbuf; - sprintf(soap->tmpbuf, soap->double_format, n); - t = strchr(s, ','); /* convert decimal comma to DP */ - if (t) - *t = '.'; - } - 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 (!*s) - return soap->error = SOAP_TYPE; - 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, "%lg", 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, NULL)) - 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 (*soap->href) - p = (double*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(double), 0, NULL); - else if (p) - { if (soap_s2double(soap, soap_value(soap), p)) - return 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 (s == r || *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, NULL)) - 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 (*soap->href) - p = (unsigned char*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned char), 0, NULL); - else if (p) - { if (soap_s2unsignedByte(soap, soap_value(soap), p)) - return 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_unsignedShort2s(struct soap *soap, unsigned short n) -{ return soap_unsignedLong2s(soap, (unsigned long)n); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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 PALM_2 -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 (s == r || *r || n > 65535) - soap->error = SOAP_TYPE; - *p = (unsigned short)n; - } - return soap->error; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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, NULL)) - 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 (*soap->href) - p = (unsigned short*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned short), 0, NULL); - else if (p) - { if (soap_s2unsignedShort(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = (unsigned int)soap_strtoul(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (unsigned int*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned int), 0, NULL); - else if (p) - { if (soap_s2unsignedInt(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = soap_strtoul(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (unsigned long*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned long), 0, NULL); - else if (p) - { if (soap_s2unsignedLong(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOULL - char *r; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = strtoull(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -# ifdef HAVE_SSCANF - if (sscanf(s, SOAP_ULONG_FORMAT, p) != 1) -# endif -#endif - 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, NULL)) - 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 (*soap->href) - p = (ULONG64*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(ULONG64), 0, NULL); - else if (p) - { if (soap_s2ULONG64(soap, soap_value(soap), p)) - return 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) - { if (!(*t = soap_strdup(soap, s))) - return soap->error = SOAP_EOM; - if (!(soap->mode & (SOAP_ENC_LATIN | SOAP_C_UTFSTRING))) - { /* TODO: consider truncating UTF8 to ASCII for regular XML attribute strings? */ - } - } - 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 = soap->nlist; - const char *p; - /* if there is no namespace stack, or prefix is "xml" then pass string */ - if (!np || !strncmp(s, "xml:", 4)) - { *t = soap_strdup(soap, s); - return SOAP_OK; - } - /* else we normalize the QName by replacing its prefix */ - 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); - } - else - *t = NULL; - 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 != '"') - { -#ifndef WITH_LEAN - if (s && (soap->mode & SOAP_XML_CANONICAL)) - { t = (char*)strchr(s, ':'); - if (t) - soap_utilize_ns(soap, s, t - s); - } -#endif - 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:_%d", 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 WITH_LEAN -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_s2wchar(struct soap *soap, const char *s, wchar_t **t) -{ wchar_t *r; - if (!s) - *t = NULL; - else - { *t = r = (wchar_t*)soap_malloc(soap, sizeof(wchar_t) * (strlen(s) + 1)); - if (!r) - return soap->error; - if (soap->mode & SOAP_ENC_LATIN) - { while (*s) - *r++ = (wchar_t)*s++; - } - else - { /* Convert UTF8 to wchar */ - while (*s) - { register soap_wchar c, c1, c2, c3, c4; - c = *s++; - if (c < 0x80) - *r++ = (wchar_t)c; - else - { c1 = (soap_wchar)*s++ & 0x3F; - if (c < 0xE0) - *r++ = (wchar_t)(((soap_wchar)(c & 0x1F) << 6) | c1); - else - { c2 = (soap_wchar)*s++ & 0x3F; - if (c < 0xF0) - *r++ = (wchar_t)(((soap_wchar)(c & 0x0F) << 12) | (c1 << 6) | c2); - else - { c3 = (soap_wchar)*s++ & 0x3F; - if (c < 0xF8) - *r++ = (wchar_t)(((soap_wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3); - else - { c4 = (soap_wchar)*s++ & 0x3F; - if (c < 0xFC) - *r++ = (wchar_t)(((soap_wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4); - else - *r++ = (wchar_t)(((soap_wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (soap_wchar)(*s++ & 0x3F)); - } - } - } - } - } - } - *r = L'\0'; - } - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_wchar2s(struct soap *soap, const wchar_t *s) -{ register soap_wchar c; - register char *r, *t; - const wchar_t *q = s; - size_t n = 0; - while ((c = *q++)) - { if (c > 0 && c < 0x80) - n++; - else - n += 6; - } - r = t = (char*)soap_malloc(soap, n + 1); - if (r) - { /* Convert wchar to UTF8 */ - while ((c = *s++)) - { if (c > 0 && c < 0x80) - *t++ = (char)c; - else - { 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'; - } - return r; -} -#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) - return soap->error; - if (!**p && (soap->mode & SOAP_C_NILSTRING)) - return soap_element_null(soap, tag, id, type); - if (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, NULL)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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 if (soap->null) - *p = NULL; - else - *p = (char*)SOAP_STR_EOS; - if (*soap->href) - 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 WITH_LEANER -#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) - return soap->error; - if (!**p && (soap->mode & SOAP_C_NILSTRING)) - return soap_element_null(soap, tag, id, type); - if (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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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, NULL)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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 if (soap->null) - *p = NULL; - else - *p = (wchar_t*)SOAP_STR_EOS; - if (*soap->href) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static time_t -soap_timegm(struct tm *T) -{ -#if defined(HAVE_TIMEGM) - return timegm(T); -#else - time_t t, g, z; -#ifdef HAVE_GMTIME_R - struct tm tm, *tmp = &tm; -#else - struct tm *tmp; -#endif - t = mktime(T); - if (t == -1) - return -1; -#ifdef HAVE_GMTIME_R - gmtime_r(&t, tmp); -#else - tmp = gmtime(&t); -#endif - tmp->tm_isdst = 0; - g = mktime(tmp); - if (g == -1) - return -1; - z = g - t; - return t - z; -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_dateTime2s(struct soap *soap, time_t n) -{ struct tm T, *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); - /* 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); -#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+(pT->tm_isdst!=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+(pT->tm_isdst!=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)) - { -#ifdef __BORLANDC__ - ::ftime(&t); -#else - ftime(&t); -#endif - strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); - sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60); - } - /* 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); - } -# else - if ((pT = localtime(&n))) - { -#ifdef __BORLANDC__ - ::ftime(&t); -#else - ftime(&t); -#endif - strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); - sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=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); - /* 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); -#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[32]; - const char *t; - memset((void*)&T, 0, sizeof(T)); - zone[sizeof(zone)-1] = '\0'; - if (strchr(s, '-')) - t = "%d-%d-%dT%d:%d:%d%31s"; - else if (strchr(s, ':')) - t = "%4d%2d%2dT%d:%d:%d%31s"; - else /* parse non-XSD-standard alternative ISO 8601 format */ - t = "%4d%2d%2dT%2d%2d%2d%31s"; - sscanf(s, t, &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 == '+' || *s == '-') - { int h = 0, m = 0; - if (s[3] == ':') - { sscanf(s, "%d:%d", &h, &m); - if (h < 0) - m = -m; - } - else - { m = (int)atol(s); - h = m / 100; - m = m % 100; - } - T.tm_hour -= h; - T.tm_min -= m; - } - T.tm_isdst = 0; - *p = soap_timegm(&T); - } - else - { T.tm_isdst = -1; - *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, NULL)) - 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 (*soap->href) - p = (time_t*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(time_t), 0, NULL); - else if (p) - { if (soap_s2dateTime(soap, soap_value(soap), p)) - return 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, const char *type) -{ int i; - const char *t = NULL; - if (tag && *tag != '-') - { if (soap->local_namespaces && (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++; - if (soap_element(soap, t, 0, type) - || soap_attribute(soap, "xmlns", soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS) - || soap_element_start_end_out(soap, NULL)) - return soap->error; - } - else - { t = tag; - if (soap_element_begin_out(soap, t, 0, type)) - return soap->error; - } - } - if (p && *p) - { if (soap_send(soap, *p)) - return soap->error; - } - if (t) - return soap_element_end_out(soap, t); - 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, NULL)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - if (!(p = (char**)soap_malloc(soap, sizeof(char*)))) - return NULL; - if (soap->body) - *p = soap_string_in(soap, 0, -1, -1); - else if (soap->null) - *p = NULL; - else - *p = (char*)SOAP_STR_EOS; - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p, const char *type) -{ int i; - const char *t = NULL; - if (tag && *tag != '-') - { if (soap->local_namespaces && (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++; - if (soap_element(soap, t, 0, type) - || soap_attribute(soap, "xmlns", soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS) - || soap_element_start_end_out(soap, NULL)) - return soap->error; - } - else - { t = tag; - if (soap_element_begin_out(soap, t, 0, type)) - return soap->error; - } - if (soap_send(soap, soap->tmpbuf)) - return soap->error; - } - if (p) - { wchar_t c; - const wchar_t *s = *p; - while ((c = *s++)) - { if (soap_pututf8(soap, (unsigned long)c)) - return soap->error; - } - } - if (t) - return soap_element_end_out(soap, t); - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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, NULL)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*)))) - return NULL; - if (soap->body) - *p = soap_wstring_in(soap, 0, -1, -1); - else if (soap->null) - *p = NULL; - else - *p = (wchar_t*)SOAP_STR_EOS; - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_value(struct soap *soap) -{ register size_t i; - register soap_wchar c = 0; - register char *s = soap->tmpbuf; - if (!soap->body) - return SOAP_STR_EOS; - do c = soap_get(soap); - while (soap_blank(c)); - for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++) - { if (c == SOAP_TT || (int)c == EOF) - break; - *s++ = (char)c; - c = soap_get(soap); - } - for (s--; i > 0; i--, s--) - { if (!soap_blank(*s)) - break; - } - s[1] = '\0'; - if ((int)c == EOF || c == SOAP_TT) - soap_unget(soap, c); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element content value='%s'\n", soap->tmpbuf)); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->data = soap_strdup(soap, soap->tmpbuf); -#endif - return soap->tmpbuf; /* return non-null pointer */ -} -#endif - -/******************************************************************************/ -#if !defined(WITH_LEANER) || !defined(WITH_NOHTTP) -#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' || c == '\n') - break; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - *s++ = (char)c; - } - if (c != '\n') - c = soap_getchar(soap); /* got \r, now get \n */ - if (c == '\n') - { *s = '\0'; - if (i+1 == len) /* empty line: end of HTTP/MIME 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 -#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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the message size with attachments, current count=%lu\n", (unsigned long)count)); - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - { 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 content is %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); - /* count Content-Transfer-Encoding: ...\r\n */ - s = soap_code_str(mime_codes, content->encoding); - 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->description); - /* count \r\n...content */ - count += 2 + content->size; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Size of MIME attachment content is %lu bytes\n", (unsigned long)content->size)); - } - /* count \r\n--boundary-- */ - count += 6 + n; - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New count is %lu bytes\n", (unsigned long)count)); - 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 (!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)content->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) -{ while (soap->dime.flags & SOAP_DIME_CF) - { if (soap_getdimehdr(soap)) - return soap->error; - if (soap_move(soap, soap->dime.size)) - return soap->error = SOAP_EOF; - } - if (soap_move(soap, ((soap->dime.size+3)&(~3))-soap_tell(soap))) - return soap->error = SOAP_EOF; - for (;;) - { register struct soap_multipart *content; - if (soap_getdimehdr(soap)) - break; - 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; - if (soap->error) - return soap->error; - soap_resolve_attachment(soap, content); - } - if (soap->error != SOAP_DIME_END) - return soap->error; - return soap->error = SOAP_OK; -} -#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-Disposition")) - content->id = soap_strdup(soap, soap_get_header_attribute(soap, val, "name")); - 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_code_int(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) -{ while (soap_get_mime_attachment(soap, NULL)) - ; - return soap->error; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_post_check_mime_attachments(struct soap *soap) -{ soap->imode |= SOAP_MIME_POSTCHECK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_check_mime_attachments(struct soap *soap) -{ if (soap->mode & SOAP_MIME_POSTCHECK) - return soap_get_mime_attachment(soap, NULL) != NULL; - return 0; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -struct soap_multipart * -SOAP_FMAC2 -soap_get_mime_attachment(struct soap *soap, void *handle) -{ register soap_wchar c = 0; - register size_t i, m = 0; - register char *s, *t = NULL; - register struct soap_multipart *content; - register short flag = 0; - if (!(soap->mode & SOAP_ENC_MIME)) - return NULL; - content = soap->mime.last; - if (!content) - { if (soap_getmimehdr(soap)) - return NULL; - content = soap->mime.last; - } - else if (content != soap->mime.first) - { if (soap->fmimewriteopen && ((content->ptr = (char*)soap->fmimewriteopen(soap, (void*)handle, content->id, content->type, content->description, content->encoding)) || soap->error)) - { if (!content->ptr) - return NULL; - } - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id=%s type=%s\n", content->id?content->id:"", content->type?content->type:"")); - if (!content->ptr && soap_new_block(soap)) - { soap->error = SOAP_EOM; - return NULL; - } - for (;;) - { if (content->ptr) - s = soap->tmpbuf; - else if (!(s = (char*)soap_push_block(soap, sizeof(soap->tmpbuf)))) - { soap->error = SOAP_EOM; - return NULL; - } - for (i = 0; i < sizeof(soap->tmpbuf); i++) - { if (m > 0) - { *s++ = *t++; - m--; - } - else - { if (!flag) - { c = soap_get1(soap); - if ((int)c == EOF) - { soap->error = SOAP_EOF; - return NULL; - } - } - if (flag || c == '\r') - { t = soap->msgbuf; - memset(t, 0, sizeof(soap->msgbuf)); - strcpy(t, "\n--"); - if (soap->mime.boundary) - strncat(t, soap->mime.boundary, sizeof(soap->msgbuf)-4); - do c = soap_getchar(soap); - while (c == *t++); - if ((int)c == EOF) - { soap->error = SOAP_EOF; - return NULL; - } - if (!*--t) - goto end; - *t = (char)c; - flag = (c == '\r'); - m = t - soap->msgbuf + 1 - flag; - t = soap->msgbuf; - c = '\r'; - } - *s++ = (char)c; - } - } - if (content->ptr && soap->fmimewrite) - { if ((soap->error = soap->fmimewrite(soap, (void*)content->ptr, soap->tmpbuf, i))) - break; - } - } -end: - *s = '\0'; /* force 0-terminated */ - if (content->ptr) - { if (!soap->error && soap->fmimewrite) - soap->error = soap->fmimewrite(soap, (void*)content->ptr, soap->tmpbuf, i); - if (soap->fmimewriteclose) - soap->fmimewriteclose(soap, (void*)content->ptr); - if (soap->error) - return NULL; - } - else - { content->size = soap_size_block(soap, i+1)-1; - content->ptr = soap_save_block(soap, NULL, 0); - } - soap_resolve_attachment(soap, content); - if (c == '-' && soap_getchar(soap) == '-') - { soap->mode &= ~SOAP_ENC_MIME; - if ((soap->mode & SOAP_MIME_POSTCHECK) && soap_end_recv(soap)) - return NULL; - } - else - { while (c != '\r' && (int)c != EOF && soap_blank(c)) - c = soap_getchar(soap); - if (c != '\r' || soap_getchar(soap) != '\n') - { soap->error = SOAP_MIME_ERROR; - return NULL; - } - if (soap_getmimehdr(soap)) - return NULL; - } - return content; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_match_cid(struct soap *soap, const char *s, const char *t) -{ register size_t n; - if (!s) - return 1; - if (!strcmp(s, t)) - return 0; - if (!strncmp(s, "cid:", 4)) - s += 4; - n = strlen(t); - if (*t == '<') - { t++; - n -= 2; - } - if (!strncmp(s, t, n) && !s[n]) - return 0; - soap_decode(soap->tmpbuf, sizeof(soap->tmpbuf), s, SOAP_STR_EOS); - if (!strncmp(soap->tmpbuf, t, n) && !soap->tmpbuf[n]) - return 0; - return 1; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -static void -soap_resolve_attachment(struct soap *soap, struct soap_multipart *content) -{ if (content->id) - { register struct soap_xlist **xp = &soap->xlist; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving attachment data for id=%s\n", content->id)); - while (*xp) - { register struct soap_xlist *xq = *xp; - if (!soap_match_cid(soap, xq->id, content->id)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Found matching attachment %s for content id=%s\n", xq->id, content->id)); - *xp = xq->next; - *xq->ptr = (unsigned char*)content->ptr; - *xq->size = (int)content->size; - *xq->type = (char*)content->type; - if (content->options) - *xq->options = (char*)content->options; - else - *xq->options = (char*)content->description; - SOAP_FREE(soap, xq); - } - else - xp = &(*xp)->next; - } - } -} -#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_code_str(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) - { void *handle; - if (soap->fmimereadopen && ((handle = soap->fmimereadopen(soap, (void*)content->ptr, content->id, content->type, content->description)) || soap->error)) - { size_t size = content->size; - if (!handle) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimereadopen failed\n")); - return soap->error; - } - if (soap_putmimehdr(soap, content)) - return soap->error; - if (!size) - { if ((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 MIME\n")); - do - { size = soap->fmimeread(soap, handle, soap->tmpbuf, sizeof(soap->tmpbuf)); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimeread returned %lu bytes\n", (unsigned long)size)); - if (soap_send_raw(soap, soap->tmpbuf, size)) - break; - } while (size); - } - else - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error: cannot chunk streaming MIME (no HTTP chunking)\n")); - } - } - else - { do - { size_t bufsize; - if (size < sizeof(soap->tmpbuf)) - bufsize = size; - else - bufsize = sizeof(soap->tmpbuf); - if (!(bufsize = soap->fmimeread(soap, handle, soap->tmpbuf, bufsize))) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)content->size)); - soap->error = SOAP_EOF; - break; - } - if (soap_send_raw(soap, soap->tmpbuf, bufsize)) - break; - size -= bufsize; - } while (size); - } - if (soap->fmimereadclose) - soap->fmimereadclose(soap, handle); - } - else - { 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, "--"); -} -#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 = 64; - s = soap->mime.boundary = (char*)soap_malloc(soap, n + 1); - if (!s) - return; - } - strcpy(s, "=="); - s += 2; - n -= 4; - while (n) - { *s++ = soap_base64o[soap_random & 0x3F]; - n--; - } - strcpy(s, "=="); - } - if (!soap->mime.start) - soap->mime.start = ""; -} -#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; - if (soap->fmimeread) - return SOAP_OK; - 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 - -/******************************************************************************\ - * - * HTTP cookie handling - * -\******************************************************************************/ - -#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 && !strchr("()<>@,;:\\\"/[]?={}", 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 = SOAP_STR_EOS; - else if (*path == '/') - path++; - n = strlen(path); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Search cookie %s domain=%s path=%s\n", name, domain?domain:"(null)", path?path:"(null)")); - for (p = soap->cookies; p; p = p->next) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie in database: %s=%s domain=%s path=%s env=%hd\n", p->name, p->value?p->value:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", p->env)); - if (!strcmp(p->name, name) - && p->domain - && p->path - && !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:"(null)", domain?domain:"(null)", path?path:"(null)")); - if (!domain) - domain = soap->cookie_domain; - if (!path) - path = soap->cookie_path; - if (!path) - path = SOAP_STR_EOS; - else if (*path == '/') - path++; - q = soap_cookie(soap, name, domain, path); - if (!q) - { if ((q = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie)))) - { if ((q->name = (char*)SOAP_MALLOC(soap, strlen(name)+1))) - strcpy(q->name, name); - q->value = NULL; - q->domain = NULL; - q->path = NULL; - q->expire = -1; - q->maxage = -1; - q->version = 1; - q->secure = 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 && path && strcmp((*p)->path, path) < 0) - break; - if (n) - { q->next = *p; - *p = q; - } - else - { SOAP_FREE(soap, q->name); - SOAP_FREE(soap, q); - q = NULL; - } - } - } - else - q->modified = 1; - if (q) - { if (q->value) - { SOAP_FREE(soap, q->value); - q->value = NULL; - } - if (q->domain) - { SOAP_FREE(soap, q->domain); - q->domain = NULL; - } - if (q->path) - { SOAP_FREE(soap, q->path); - q->path = NULL; - } - if (value && *value && (q->value = (char*)SOAP_MALLOC(soap, strlen(value)+1))) - strcpy(q->value, value); - if (domain && (q->domain = (char*)SOAP_MALLOC(soap, strlen(domain)+1))) - strcpy(q->domain, domain); - if (path && (q->path = (char*)SOAP_MALLOC(soap, strlen(path)+1))) - strcpy(q->path, path); - q->session = 1; - q->env = 0; - } - 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) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie domain not set\n", name?name:"(null)")); - return; - } - if (!path) - path = soap->cookie_path; - if (!path) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie path not set\n", name?name:"(null)")); - 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(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, 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 -char * -SOAP_FMAC2 -soap_env_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)) && p->env) - return p->value; - return NULL; -} - -/******************************************************************************/ -SOAP_FMAC1 -time_t -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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie expiration max-age %ld: %s domain=%s path=%s\n", expire, name, domain?domain:"(null)", path?path:"(null)")); - if ((p = soap_cookie(soap, name, domain, path))) - { p->maxage = 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 && s-tmp < 4060) - { sprintf(s, ";Version=%u", p->version); - s += strlen(s); - } - if (p->maxage >= 0 && s-tmp < 4060) - { sprintf(s, ";Max-Age=%ld", p->maxage); - s += strlen(s); - } - if (p->secure && s-tmp < 4073) - strcpy(s, ";Secure"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set-Cookie: %s\n", tmp)); - if ((soap->error = 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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending cookies for domain=%s path=%s\n", domain, path)); - if (*path == '/') - path++; - while ((q = *p)) - { if (q->expire && now > q->expire) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name)); - SOAP_FREE(soap, q->name); - if (q->value) - SOAP_FREE(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, q); - } - else - { size_t domlen = 0; - if (q->domain) - { const char *s = strchr(q->domain, ':'); - if (s) - domlen = s - q->domain; - else - domlen = strlen(q->domain); - } - if ((!q->domain || !strncmp(q->domain, domain, domlen)) - && (!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 && *q->path && (int)strlen(q->path) < tmp-s+4080) - { sprintf(s, ";$Path=\"/%s\"", (*q->path == '/' ? q->path + 1 : 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->error = soap->fposthdr(soap, "Cookie", tmp))) - return soap->error; - } - 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->path) - SOAP_FREE(soap, p->path); - p->path = t; - } - else - { if (path) - SOAP_FREE(soap, 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->domain) - SOAP_FREE(soap, p->domain); - p->domain = t; - } - else - { if (domain) - SOAP_FREE(soap, domain); - domain = t; - } - } - else if (p && !soap_tag_cmp(tmp, "Path")) - { if (p->path) - SOAP_FREE(soap, p->path); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->path = (char*)SOAP_MALLOC(soap, strlen(tmp)+1))) - strcpy(p->path, tmp); - } - else - p->path = NULL; - } - else if (p && !soap_tag_cmp(tmp, "Domain")) - { if (p->domain) - SOAP_FREE(soap, p->domain); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->domain = (char*)SOAP_MALLOC(soap, 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:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if ((p = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie)))) - { p->name = (char*)SOAP_MALLOC(soap, strlen(tmp)+1); - strcpy(p->name, tmp); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { p->value = (char*)SOAP_MALLOC(soap, strlen(tmp)+1); - strcpy(p->value, tmp); - } - else - p->value = NULL; - if (domain) - p->domain = domain; - else - { p->domain = (char*)SOAP_MALLOC(soap, strlen(soap->host)+1); - strcpy(p->domain, soap->host); - } - if (path) - p->path = path; - else - { p->path = (char*)SOAP_MALLOC(soap, strlen(soap->path)+1); - strcpy(p->path, soap->path); - } - p->expire = 0; - p->secure = 0; - p->version = version; - } - } - } - 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:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if (domain) - SOAP_FREE(soap, domain); - if (path) - SOAP_FREE(soap, 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 *copy, 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(copy, sizeof(struct soap_cookie)))) - return r; - **q = *p; - if (p->name) - { if (((*q)->name = (char*)SOAP_MALLOC(copy, strlen(p->name)+1))) - strcpy((*q)->name, p->name); - } - if (p->value) - { if (((*q)->value = (char*)SOAP_MALLOC(copy, strlen(p->value)+1))) - strcpy((*q)->value, p->value); - } - if (p->domain) - { if (((*q)->domain = (char*)SOAP_MALLOC(copy, strlen(p->domain)+1))) - strcpy((*q)->domain, p->domain); - } - if (p->path) - { if (((*q)->path = (char*)SOAP_MALLOC(copy, 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, 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)c != 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_temp(soap); - soap_set_local_namespaces(soap); - soap->version = 0; /* don't assume we're parsing SOAP content by default */ -#ifndef WITH_NOIDREF - soap_free_iht(soap); -#endif - 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->action = NULL; - soap->status = 0; -#ifndef WITH_LEANER - soap->dom = 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; - soap->xlist = NULL; -#endif -#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 -#ifndef WITH_LEANER - 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 -#ifndef WITH_LEANER - 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 -#endif - { while (soap_blank(c)) - c = soap_getchar(soap); - } - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifndef WITH_NOHTTP - /* if not XML or (start of)BOM or MIME/DIME/ZLIB, assume HTTP header */ - if (c != '<' && c != 0xEF && !(soap->mode & (SOAP_ENC_MIME | SOAP_ENC_DIME | SOAP_ENC_ZLIB))) - { soap->mode &= ~SOAP_IO; - soap->error = soap->fparse(soap); - if (soap->error && soap->error < SOAP_STOP) - { 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; - } -#ifndef WITH_LEANER - else if (soap->fpreparerecv && soap->buflen != soap->bufidx) - soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx); -#endif - /* Note: fparse should not use soap_unget to push back last char */ - if (soap_get0(soap) == (int)EOF) - { if (soap->status == 200) - return soap->error = SOAP_NO_DATA; - return soap->error = soap->status; - } -#ifdef WITH_ZLIB - if (soap->zlib_in != SOAP_ZLIB_NONE) -#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 - if (soap->error) - { if (soap->error == SOAP_FORM && soap->fform) - { soap->error = soap->fform(soap); - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - } - return soap->error; - } - } -#endif -#ifndef WITH_LEANER - if (soap->mode & SOAP_ENC_MIME) - { if (soap_getmimehdr(soap)) - return soap->error; - if (soap->mime.start) - { do - { if (!soap->mime.last->id) - break; - if (!soap_match_cid(soap, soap->mime.start, soap->mime.last->id)) - break; - } while (soap_get_mime_attachment(soap, NULL)); - } - 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 WITH_NOHTTP -#ifndef PALM_1 -static int -http_parse(struct soap *soap) -{ char header[SOAP_HDRLEN], *s; - unsigned short get = 0, status = 0, k = 0; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for HTTP request/response...\n")); - *soap->endpoint = '\0'; - soap->length = 0; - soap->userid = NULL; - soap->passwd = NULL; - soap->action = NULL; - soap->authrealm = NULL; - 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)) - { if (soap->error == SOAP_EOF) - { soap->error = SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "EOF in HTTP header, continue anyway\n")); - break; - } - 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))) - { if (soap->error < SOAP_STOP) - return soap->error; - status = soap->error; - soap->error = SOAP_OK; - } - } - } - if ((s = strchr(soap->msgbuf, ' '))) - { k = (unsigned short)soap_strtoul(s, &s, 10); - if (!soap_blank(*s)) - k = 0; - } - else - k = 0; - } while (k == 100); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Finished HTTP header parsing, status = %d\n", k)); - 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 && (((get = !strncmp(soap->msgbuf, "GET ", 4))) || !strncmp(soap->msgbuf, "POST ", 5))) - { size_t m = strlen(soap->endpoint); - size_t n = m + (s - soap->msgbuf) - 5 - (!get); - if (n >= sizeof(soap->endpoint)) - n = sizeof(soap->endpoint) - 1; - strncpy(soap->path, soap->msgbuf + 4 + (!get), n - m); - soap->path[n - m] = '\0'; - strcat(soap->endpoint, soap->path); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint)); - if (get) - { soap->error = soap->fget(soap); - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - return soap->error; - } - if (status) - return soap->error = status; - } - soap->status = k; - if (k == 0 || k == 200 || (((k > 200 && k <= 299) || k == 400 || k == 500) && ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK || soap->length > 0))) - return SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP error %d\n", k)); - return soap_set_receiver_error(soap, "HTTP Error", soap->msgbuf, k); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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")) - { soap->http_content = soap_strdup(soap, val); - 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_get_header_attribute(soap, val, "multipart/form-data")) - { 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 *")) - { int 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 == '"') - { 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, "Cookie2") - || !soap_tag_cmp(key, "Set-Cookie") - || !soap_tag_cmp(key, "Set-Cookie2")) - soap_getcookies(soap, val); -#endif - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#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 && strlen(soap->mime.boundary) + strlen(soap->mime.start) < sizeof(soap->tmpbuf) - 80 ) - { const char *s; - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - s = "application/dime"; - else if (soap->version == 2) - { if (soap->mode & SOAP_ENC_MTOM) - s = "application/xop+xml; charset=utf-8; type=application/soap+xml"; - else - 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->mode & SOAP_ENC_MTOM)) - { 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)) + (soap->dime.type ? ((strlen(soap->dime.type)+3)&(~3)) : 0); - } - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - 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, NULL)) - { -#ifndef WITH_LEAN - if (!soap_element_begin_in(soap, "html", 0, NULL)) - { /* get HTML from buffer, stop receiving to avoid HTML parsing issues */ - char *s; -#ifndef WITH_NOIO - size_t (*f)(struct soap*, char*, size_t) = soap->frecv; - soap->frecv = frecv_stop; -#endif - soap_revert(soap); - s = soap_string_in(soap, 1, -1, -1); -#ifndef WITH_NOIO - soap->frecv = f; -#endif - return soap_set_receiver_error(soap, "HTTP Error", s, SOAP_HTTP_ERROR); - } -#endif - 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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) -{ soap->part = SOAP_END_ENVELOPE; - return soap_element_end_in(soap, "SOAP-ENV:Envelope"); -} -#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; -#ifndef WITH_LEAN - if ((soap->mode & SOAP_XML_SEC) && soap_set_attr(soap, "wsu:Id", "Body")) - return soap->error; -#endif - if (soap_element(soap, "SOAP-ENV:Body", 0, NULL)) - 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_END_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; - if (soap_element_begin_in(soap, "SOAP-ENV:Body", 0, NULL)) - return soap->error; - if (!soap->body) - soap->part = SOAP_NO_BODY; - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_body_end_in(struct soap *soap) -{ if (soap->part == SOAP_NO_BODY) - return SOAP_OK; - soap->part = SOAP_END_BODY; - return soap_element_end_in(soap, "SOAP-ENV:Body"); -} -#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; - else if (soap->error == SOAP_OK && soap->fheader) - soap->error = soap->fheader(soap); - 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] = '\0'; - soap->host[0] = '\0'; - soap->path[0] = '/'; - soap->path[1] = '\0'; - soap->port = 80; - if (!endpoint || !*endpoint) - return; -#ifdef WITH_OPENSSL - if (!soap_tag_cmp(endpoint, "https:*")) - soap->port = 443; -#endif - strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint) - 1); - soap->endpoint[sizeof(soap->endpoint) - 1] = '\0'; - 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; -#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 - for (i = 0; i < n; i++) - { soap->host[i] = s[i]; - if (s[i] == '/' || s[i] == ':') - break; - } -#endif - 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, 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); -#ifndef WITH_LEANER - if (soap->fconnect) - { if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port))) - return soap->error; - } - else -#endif - if (soap->fopen && *soap->host) - { soap->status = http_command; - if (!soap->keep_alive || !soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port || !soap->fpoll || soap->fpoll(soap)) - { soap->keep_alive = 0; /* to force close */ - soap->omode &= ~SOAP_IO_UDP; /* to force close */ - soap_closesock(soap); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect/reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port)); -#ifdef WITH_UDP - if (!strncmp(endpoint, "soap.udp:", 9)) - soap->omode |= SOAP_IO_UDP; -#endif - 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); - } - } - count = soap_count_attachments(soap); - if (soap_begin_send(soap)) - return soap->error; -#ifndef WITH_NOHTTP - soap->action = soap_strdup(soap, action); - 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; -#ifndef WITH_LEANER - if ((k & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = k; - } - if (http_command != SOAP_POST) - return soap_end_send(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2base64(struct soap *soap, const unsigned char *s, char *t, int n) -{ register int 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, int *n) -{ register int i, j, c; - register unsigned long m; - register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = (strlen(s) + 3) / 4 * 3; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - 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) - { int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; - } - else if (!soap_blank(c)) - { soap->error = SOAP_TYPE; - return NULL; - } - } - *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 WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2hex(struct soap *soap, const unsigned char *s, char *t, int n) -{ register char *p; - if (!t) - t = (char*)soap_malloc(soap, 2 * n + 1); - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - t[0] = '\0'; - if (s) - { for (; n > 0; n--) - { register int m = *s++; - *t++ = (char)((m >> 4) + (m > 159 ? 'a' - 10 : '0')); - m &= 0x0F; - *t++ = (char)(m + (m > 9 ? 'a' - 10 : '0')); - } - } - *t++ = '\0'; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_hex2s(struct soap *soap, const char *s, char *t, size_t l, int *n) -{ register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = strlen(s) / 2; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - while (l) - { register int d1, d2; - d1 = *s++; - if (!d1) - break; - d2 = *s++; - if (!d2) - break; - *t++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0'); - l--; - } - if (n) - *n = t - p; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_puthttphdr(struct soap *soap, int status, size_t count) -{ register const char *s = "text/xml; charset=utf-8"; - register int err = SOAP_OK; -#ifndef WITH_LEANER - register const char *r = NULL; -#endif - if (status == SOAP_FILE && soap->http_content) - s = soap->http_content; - else if (status == SOAP_HTML) - s = "text/html; charset=utf-8"; - else if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)) - { if (soap->version == 2) - s = "application/soap+xml; charset=utf-8"; - } -#ifndef WITH_LEANER - if (soap->mode & (SOAP_ENC_DIME | SOAP_ENC_MTOM)) - { if (soap->mode & SOAP_ENC_MTOM) - { r = s; - s = "application/xop+xml; charset=utf-8"; - } - else - s = "application/dime"; - } - if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && soap->status != SOAP_GET && strlen(soap->mime.boundary) + strlen(soap->mime.start ? soap->mime.start : SOAP_STR_EOS) < sizeof(soap->tmpbuf) - 80) - { register const char *t = strchr(s, ';'); - sprintf(soap->tmpbuf, "multipart/related; boundary=\"%s\"; type=\"", soap->mime.boundary); - if (t) - strncat(soap->tmpbuf, s, t - s); - else - strcat(soap->tmpbuf, s); - if (soap->mime.start) - { strcat(soap->tmpbuf, "\"; start=\""); - strcat(soap->tmpbuf, soap->mime.start); - } - strcat(soap->tmpbuf, "\""); - if (r) - { strcat(soap->tmpbuf, "; start-info=\""); - strcat(soap->tmpbuf, r); - strcat(soap->tmpbuf, "\""); - } - s = soap->tmpbuf; - } -#endif - if (s && (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 -#ifndef WITH_LEANER - if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK) - err = soap->fposthdr(soap, "Transfer-Encoding", "chunked"); - else -#endif - if (s && soap->status != SOAP_GET) - { 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_get(struct soap *soap) -{ return SOAP_GET_METHOD; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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"; - else - s = "POST"; -#ifdef PALM - if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6)) && strncmp(endpoint, "_beam:", 6) && strncmp(endpoint, "_local:", 7) && strncmp(endpoint, "_btobex:", 8)) -#else - if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6))) -#endif - return SOAP_OK; - if (strlen(endpoint) + strlen(soap->http_version) > sizeof(soap->tmpbuf) - 80) - return soap->error = SOAP_EOM; - if (soap->proxy_host && soap_tag_cmp(endpoint, "https:*")) - sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version); - else - sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, (*path == '/' ? path + 1 : 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 (soap->version == 1 || (action && *action && strlen(action) < sizeof(soap->tmpbuf) - 2)) - { sprintf(soap->tmpbuf, "\"%s\"", action?action:""); - if ((err = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf))) - return err; - } - return soap->fposthdr(soap, NULL, NULL); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_response(struct soap *soap, int status, size_t count) -{ register int err; -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - httpOutputEnable(soap->rpmreqid); -#endif - if (strlen(soap->http_version) > 4) - return soap->error = SOAP_EOM; - if (!status || status == SOAP_HTML || status == SOAP_FILE) - { const char *s; - if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)) - s = "200 OK"; - else - s = "202 ACCEPTED"; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Status = %s\n", s)); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif - { 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; - } - 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; -#ifndef WITH_LEAN - if (status == 401) - { sprintf(soap->tmpbuf, "Basic realm=\"%s\"", strlen(soap->authrealm) < sizeof(soap->tmpbuf) - 14 ? 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; - } -#endif - } - 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)); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif - { 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))) /* CGI */ - 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 -#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; -#ifndef WITH_NOHTTP - 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; -#ifndef WITH_LEANER - if ((n & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = n; - } -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static const char* -soap_set_validation_fault(struct soap *soap, const char *s, const char *t) -{ if (*soap->tag) - sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element <%s>", s, t?t:SOAP_STR_EOS, soap->tag); - else - sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t?t:SOAP_STR_EOS); - 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 (soap->fseterror) - soap->fseterror(soap, c, s); - 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_TYPE: - *s = soap_set_validation_fault(soap, "data type mismatch ", soap->type); - break; - case SOAP_SYNTAX_ERROR: - *s = "Well-formedness violation"; - break; - case SOAP_NO_TAG: - *s = "No XML element tag"; - 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_USER_ERROR: - *s = "User error"; - 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_NO_DATA: - *s = "Data required for operation"; - break; - case SOAP_GET_METHOD: - *s = "HTTP GET method not implemented"; - break; - case SOAP_EOM: - *s = "Out of memory"; - break; - case SOAP_MOE: - *s = "Memory overflow or corruption error"; - 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_DUPLICATE_ID: - *s = soap_set_validation_fault(soap, "multiple definitions of id ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:DuplicateID"; - break; - case SOAP_MISSING_ID: - *s = soap_set_validation_fault(soap, "missing id for ref ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:MissingID"; - break; - case SOAP_HREF: - *s = soap_set_validation_fault(soap, "incompatible object ref ", soap->id); - break; - case SOAP_FAULT: - break; -#ifndef WITH_NOIO - case SOAP_UDP_ERROR: - *s = "Message too large for UDP packet"; - break; - case SOAP_TCP_ERROR: - *s = tcp_error(soap); - break; -#endif - case SOAP_HTTP_ERROR: - *s = "An HTTP processing error occurred"; - break; - case SOAP_SSL_ERROR: -#ifdef WITH_OPENSSL - *s = "SSL error"; -#else - *s = "OpenSSL not installed: recompile with -DWITH_OPENSSL"; -#endif - break; - case SOAP_PLUGIN_ERROR: - *s = "Plugin registry error"; - break; - case SOAP_DIME_ERROR: - *s = "DIME format error"; - break; - case SOAP_DIME_HREF: - *s = "DIME href to missing attachment"; - break; - case SOAP_DIME_MISMATCH: - *s = "DIME version/transmission error"; - break; - case SOAP_DIME_END: - *s = "End of DIME error"; - break; - case SOAP_MIME_ERROR: - *s = "MIME format error"; - break; - case SOAP_MIME_HREF: - *s = "MIME href to missing attachment"; - break; - case SOAP_MIME_END: - *s = "End of MIME 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/gzip not installed for (de)compression: recompile with -DWITH_GZIP"; -#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, "min/maxOccurs violation", NULL); - break; - case SOAP_LENGTH: - *s = soap_set_validation_fault(soap, "content length violation", NULL); - break; - case SOAP_FD_EXCEEDED: - *s = "Maximum number of open connections was reached"; - break; - case SOAP_STOP: - *s = "Stopped: no response sent"; - break; -#endif - case SOAP_EOF: -#ifndef WITH_NOIO - sprintf(soap->msgbuf, "End of file or no input: '%s'", soap_strerror(soap)); - *s = soap->msgbuf; - break; -#else - *s = "End of file or no input"; - break; -#endif - default: -#ifndef WITH_NOHTTP -#ifndef WITH_LEAN - if (soap->error > 200 && soap->error < 600) - { sprintf(soap->msgbuf, "HTTP Error: %d %s", soap->error, http_error(soap, soap->error)); - *s = soap->msgbuf; - } - else -#endif -#endif - { sprintf(soap->msgbuf, "Error %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; - int r = 1; - 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); -#ifndef WITH_NOIO -#ifndef WITH_LEAN - if (soap_valid_socket(soap->socket)) - { struct timeval timeout; - fd_set rfd, sfd; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_SET((SOAP_SOCKET)soap->socket, &rfd); - FD_SET((SOAP_SOCKET)soap->socket, &sfd); - r = select((SOAP_SOCKET)(soap->socket + 1), &rfd, &sfd, NULL, &timeout); - if (r > 0) - { if (!FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - || (FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - && recv((SOAP_SOCKET)soap->socket, soap->tmpbuf, 1, MSG_PEEK) < 0)) - r = 0; - } - } -#endif -#endif - if ((status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) && r > 0) - { 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); - } - soap_end_count(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 WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_send_empty_response(struct soap *soap, int status) -{ register soap_mode m = soap->omode; - soap->count = 0; - if ((m & SOAP_IO) == SOAP_IO_CHUNK) - { soap->omode &= ~SOAP_IO_CHUNK; - soap->omode |= SOAP_IO_BUFFER; - } - if (soap_response(soap, status) || soap_end_send(soap)) - { soap->omode = m; - return soap_closesock(soap); - } - soap->omode = m; - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_recv_empty_response(struct soap *soap) -{ if (soap_begin_recv(soap) || soap_end_recv(soap)) - { if (soap->error != 202) - return soap_closesock(soap); - soap->error = SOAP_OK; - } - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static const char* -soap_strerror(struct soap *soap) -{ register int err = soap->errnum; - if (err) - { -#ifndef WIN32 - return strerror(err); -#else -#ifndef UNDER_CE - DWORD len; - *soap->msgbuf = '\0'; - len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)soap->msgbuf, (DWORD)sizeof(soap->msgbuf), NULL); -#else - DWORD i, len; - *soap->msgbuf = '\0'; - len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)soap->msgbuf, (DWORD)(sizeof(soap->msgbuf)/sizeof(TCHAR)), NULL); - for (i = 0; i <= len; i++) - { if (((TCHAR*)soap->msgbuf)[i] < 0x80) - soap->msgbuf[i] = (char)((TCHAR*)soap->msgbuf)[i]; - else - soap->msgbuf[i] = '?'; - } -#endif - return soap->msgbuf; -#endif - } - return "Operation interrupted or timed out"; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_set_error(struct soap *soap, const char *faultcode, const char *faultsubcode, const char *faultstring, const char *faultdetail, int soaperror) -{ *soap_faultcode(soap) = faultcode; - if (faultsubcode) - *soap_faultsubcode(soap) = faultsubcode; - *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", NULL, 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", NULL, faultstring, faultdetail, soaperror); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ char *r = NULL, *s = NULL, *t = NULL; - if (faultsubcode) - r = soap_strdup(soap, faultsubcode); - if (faultstring) - s = soap_strdup(soap, faultstring); - if (faultdetail) - t = soap_strdup(soap, faultdetail); - return soap_set_error(soap, faultcode, r, 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_sender_fault_subcode(soap, NULL, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultsubcode, 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_receiver_fault_subcode(soap, NULL, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultsubcode, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault(struct soap *soap, FILE *fd) -{ if (soap_check_state(soap)) - fprintf(fd, "Error: soap struct not initialized\n"); - else if (soap->error) - { const char *c, *v = NULL, *s, **d; - d = soap_faultcode(soap); - if (!*d) - soap_set_fault(soap); - c = *d; - if (soap->version == 2) - v = *soap_faultsubcode(soap); - s = *soap_faultstring(soap); - d = soap_faultdetail(soap); - fprintf(fd, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]"); - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault_location(struct soap *soap, FILE *fd) -{ -#ifndef WITH_LEAN - int i, j, c1, c2; - if (soap->error && soap->bufidx <= soap->buflen && soap->buflen > 0 && soap->buflen <= SOAP_BUFLEN) - { i = (int)soap->bufidx - 1; - if (i <= 0) - i = 0; - c1 = soap->buf[i]; - soap->buf[i] = '\0'; - if ((int)soap->buflen >= i + 1024) - j = i + 1023; - else - j = (int)soap->buflen - 1; - c2 = soap->buf[j]; - soap->buf[j] = '\0'; - fprintf(fd, "%s%c\n\n", soap->buf, c1); - if (soap->bufidx < soap->buflen) - fprintf(fd, "%s\n", soap->buf + soap->bufidx); - soap->buf[i] = c1; - soap->buf[j] = c2; - } -#endif -} -#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(soap, 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(soap, 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 - -/******************************************************************************\ - * - * C++ soap struct methods - * -\******************************************************************************/ - -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::soap() -{ soap_init(this); -} -#endif -#endif - -/******************************************************************************/ -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::soap(soap_mode m) -{ soap_init1(this, m); -} -#endif -#endif - -/******************************************************************************/ -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::soap(soap_mode im, soap_mode om) -{ soap_init2(this, im, om); -} -#endif -#endif - -/******************************************************************************/ -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::soap(struct soap& soap) -{ soap_copy_context(this, &soap); -} -#endif -#endif - -/******************************************************************************/ -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::~soap() -{ soap_destroy(this); - soap_end(this); - soap_done(this); -} -#endif -#endif - -/******************************************************************************/ diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.h b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.h deleted file mode 100644 index 2a8928b..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9b.h +++ /dev/null @@ -1,2166 +0,0 @@ -/* - -stdsoap2.h 2.7.9b - -gSOAP runtime - -gSOAP XML Web services tools -Copyright (C) 2000-2007, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under one of the following licenses: -GPL, the gSOAP public license, or Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems, Inc., for the following additions (marked WR[...]): - - vxWorks compatible --------------------------------------------------------------------------------- -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-2007, 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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- -*/ - -#ifdef WITH_SOAPDEFS_H -# include "soapdefs.h" /* include user-defined stuff */ -#endif - -#ifndef _THREAD_SAFE -# define _THREAD_SAFE -#endif - -#ifndef OPENSERVER -# ifndef _REENTRANT -# define _REENTRANT -# endif -#endif - -#ifndef SOAP_FMAC1 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC1 -#endif - -#ifndef SOAP_FMAC2 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC2 -#endif - -#ifndef SOAP_FMAC3 /* (de)serializer declaration macro */ -# define SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC3S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC3S SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC4 /* (de)serializer declaration macro */ -# define SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC4S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC4S SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC5 /* stub/skeleton declaration macro */ -# define SOAP_FMAC5 -#endif - -#ifndef SOAP_FMAC6 /* stub/skeleton declaration macro */ -# define SOAP_FMAC6 -#endif - -#ifndef SOAP_CMAC /* class declaration macro */ -# define SOAP_CMAC -#endif - -#ifndef SOAP_NMAC /* namespace table declaration macro */ -# define SOAP_NMAC -#endif - -#ifndef SOAP_SOURCE_STAMP -# define SOAP_SOURCE_STAMP(str) -#endif - -/* gSOAP 2.7.4 and higher: fast look-aside buffering is stable */ -#ifndef WITH_FAST -# define WITH_FAST -#endif - -#ifdef WITH_LEANER -# ifndef WITH_LEAN -# define WITH_LEAN -# endif -#endif - -#ifdef WITH_LEAN -# ifdef WITH_COOKIES -# error "Cannot build WITH_LEAN code WITH_COOKIES enabled" -# endif -#endif - -#ifndef STDSOAP_H -#define STDSOAP_H - -#if defined(__vxworks) || defined(__VXWORKS__) -# define VXWORKS -#endif - -#ifdef _WIN32 -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef _WIN32_WCE -# ifndef UNDER_CE -# define UNDER_CE _WIN32_WCE -# endif -#endif - -#ifdef UNDER_CE -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef __BORLANDC__ -# ifdef __WIN32__ -# ifndef WIN32 -# define WIN32 -# endif -# endif -#endif - -#ifdef __CYGWIN__ -# ifndef CYGWIN -# define CYGWIN -# endif -#endif - -#ifdef __SYMBIAN32__ -# define SYMBIAN -# undef WIN32 -#endif - -#if defined(__palmos__) || defined(PALM_GCC) || defined(__PALMOS_TRAPS__) -# ifndef PALM -# define PALM -# endif -#endif - -#if defined(__hpux) -# ifndef HP_UX -# define HP_UX -# endif -#endif - -#if defined(__alpha) && !defined(__VMS) -# ifndef TRU64 -# define TRU64 -# endif -#endif - -#ifdef __MVS__ -# ifndef OS390 -# define OS390 -# endif -#endif - -#ifdef HAVE_CONFIG_H -# include "config.h" -# ifdef WITH_OPENSSL -# ifndef HAVE_OPENSSL_SSL_H -# undef WITH_OPENSSL -# endif -# endif -#else -# if defined(UNDER_CE) -# define WITH_LEAN -# define HAVE_SSCANF -# elif defined(WIN32) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%I64d" -# define SOAP_ULONG_FORMAT "%I64u" -# elif defined(CYGWIN) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__APPLE__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(_AIXVERSION_431) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(HP_UX) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(FREEBSD) || defined(__FreeBSD__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_GETTIMEOFDAY -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%qd" -# define SOAP_ULONG_FORMAT "%qu" -# elif defined(__VMS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__GLIBC__) || defined(__GNU__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define HAVE_ISNAN -# elif defined(TRU64) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GETTIMEOFDAY -# define HAVE_SYS_TIMEB_H -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define __USE_STD_IOSTREAM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -# elif defined(MAC_CARBON) -# define WITH_NOIO -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(PALM) -# define WITH_LEAN -# define HAVE_STRTOD /* strtod() is defined in palmFunctions.h */ -# include /* Needs to be included before unix headers */ -# include -# define IGNORE_STDIO_STUBS -# include -# define O_NONBLOCK FNONBIO -# include -# include "palmFunctions.h" -# elif defined(SYMBIAN) -# define WITH_LEAN -# define WITH_NONAMESPACES -# define HAVE_STRTOD /* use STRTOD since sscanf doesn't seem to work */ -# include -# include -# elif defined(VXWORKS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_PGMTIME_R -# define HAVE_PLOCALTIME_R -# define HAVE_MKTIME -# elif defined(OS390) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(AS400) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__QNX__) || defined(QNX) -/* QNX does not have a working version of strtof */ -# undef HAVE_STRTOF -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define LONG64 long -# define ULONG64 unsigned LONG64 -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -# else -/* Default asumptions on supported functions */ -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# endif -#endif - -#ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%lld" /* printf format for 64 bit ints */ -#endif - -#ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%llu" /* printf format for unsigned 64 bit ints */ -#endif - -#ifndef WITH_NOSTDLIB -# include -# ifndef PALM -# include -# include -# endif -# include -# include -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -# include -# include -#endif - -#ifdef WITH_NOHTTP -# ifndef WITH_NOIO -# define WITH_NOIO -# undef WITH_COOKIES -# endif -#endif - -#ifndef UNDER_CE -# ifndef PALM -# ifndef WITH_NOIO -# include -# include -# endif -# ifndef WITH_LEAN -# ifdef HAVE_SYS_TIMEB_H -# include /* for ftime() */ -# endif -# include -# endif -# endif -#endif - -#ifdef OPENSERVER -# include -# include -# include - extern int h_errno; -#endif - -#ifndef WITH_NOIO -# ifndef WIN32 -# ifndef PALM -# include -# ifdef VXWORKS -# include -# include -# endif -# ifndef VXWORKS -# ifndef SYMBIAN -# include -# endif -# endif -# ifdef SUN_OS -# include /* SUN */ -# include /* SUN < 2.8 (?) */ -# endif -# ifdef VXWORKS -# ifdef _WRS_KERNEL -# include -# endif -# else -# include -# endif -# include -# ifdef OS390 -# include -# else -# include /* TCP_NODELAY */ -# endif -# include -# endif -# endif -#endif - -#ifdef WITH_FASTCGI -# include -#endif - -#ifdef WITH_OPENSSL -# define OPENSSL_NO_KRB5 -# include -# include -# include -# include -# include -# ifndef ALLOW_OLD_VERSIONS -# if (OPENSSL_VERSION_NUMBER < 0x00905100L) -# error "Must use OpenSSL 0.9.6 or later" -# endif -# endif -#endif - -#ifdef WITH_GZIP -# ifndef WITH_ZLIB -# define WITH_ZLIB -# endif -#endif - -#ifdef WITH_CASEINSENSITIVETAGS -# define SOAP_STRCMP soap_tag_cmp /* case insensitve XML element/attribute names */ -#else -# define SOAP_STRCMP strcmp /* case sensitive XML element/attribute names */ -#endif - -#ifdef WITH_ZLIB -# include -#endif - -#ifndef WITH_NOSTDLIB -# ifndef PALM -# include /* for isnan() */ -# endif -#endif - -/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef WIN32 -# ifndef UNDER_CE -# include -# include -# endif -# include -/* # include */ /* Alternative: use winsock2 (not available with eVC) */ -# ifdef WITH_IPV6 -# include -# include -# endif -#else -# ifdef VXWORKS -# include -# include -# include -# endif -# ifndef WITH_NOIO -# ifndef PALM -# include -# include -# include -# include -# endif -# endif -#endif - -/* Portability: define SOAP_SOCKLEN_T */ -#if defined(_AIX) -# define SOAP_SOCKLEN_T socklen_t -#elif defined(SOCKLEN_T) -# define SOAP_SOCKLEN_T SOCKLEN_T -#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(__QNX__) || defined(QNX) -# define SOAP_SOCKLEN_T socklen_t -#elif defined(IRIX) || defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS) -# define SOAP_SOCKLEN_T int -#else -# define SOAP_SOCKLEN_T size_t -#endif - -#ifndef SOAP_SOCKET -# ifdef WIN32 -# define SOAP_SOCKET SOCKET -# define soap_closesocket(n) closesocket(n) -# else -# define SOAP_SOCKET int -# define soap_closesocket(n) close(n) -# endif -#endif - -#define SOAP_INVALID_SOCKET (-1) -#define soap_valid_socket(n) ((n) != SOAP_INVALID_SOCKET) - -#ifndef FD_SETSIZE -# define FD_SETSIZE (1024) -#endif - -#if defined(SYMBIAN) -# define LONG64 long -# define ULONG64 unsigned LONG64 -#elif !defined(WIN32) || defined(CYGWIN) || defined(__GLIBC__) || defined(__GNU__) -# ifndef LONG64 -# define LONG64 long long -# define ULONG64 unsigned LONG64 -# endif -#elif defined(UNDER_CE) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#elif defined(__BORLANDC__) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#endif - -#if defined(WIN32) && !defined(CYGWIN) -# define soap_int32 __int32 -#elif defined(SYMBIAN) -# define soap_int32 long -#elif defined(PALM) -# define soap_int32 Int32 -#else -# define soap_int32 int32_t -#endif - -#ifdef WIN32 -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR WSAEINTR -# define SOAP_EAGAIN WSAEWOULDBLOCK -# define SOAP_EWOULDBLOCK WSAEWOULDBLOCK -# define SOAP_EINPROGRESS WSAEINPROGRESS -#else -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR EINTR -# define SOAP_EAGAIN EAGAIN -# ifdef SYMBIAN -# define SOAP_EWOULDBLOCK 9898 -# define SOAP_EINPROGRESS 9899 -# else -# define SOAP_EWOULDBLOCK EWOULDBLOCK -# define SOAP_EINPROGRESS EINPROGRESS -# endif -#endif - -#ifdef WIN32 -# ifdef UNDER_CE -# define soap_errno GetLastError() -# define soap_socket_errno(s) GetLastError() -# define soap_reset_errno SetLastError(0) -# else -# define soap_errno GetLastError() -# define soap_socket_errno(s) WSAGetLastError() -# define soap_reset_errno SetLastError(0) -# endif -#else -# ifndef WITH_NOIO -# define soap_errno errno -# define soap_socket_errno(s) errno -# define soap_reset_errno (errno = 0) -# else -# define soap_errno 0 -# define soap_socket_errno(s) 0 -# define soap_reset_errno -# endif -#endif - -#ifndef SOAP_BUFLEN -# ifdef WITH_UDP -# define SOAP_BUFLEN (65536) /* max UDP packet size */ -# else -# ifndef WITH_LEAN -# define SOAP_BUFLEN (65536) /* buffer length for socket packets, also used by gethostbyname_r so don't make this too small */ -# else -# define SOAP_BUFLEN (2048) -# endif -# endif -#endif -#ifndef SOAP_LABLEN -# define SOAP_LABLEN (256) /* initial look-aside buffer length */ -#endif -#ifndef SOAP_PTRBLK -# define SOAP_PTRBLK (32) /* block allocation for pointer hash table chains */ -#endif -#ifndef SOAP_PTRHASH -# ifndef WITH_LEAN -# define SOAP_PTRHASH (1024) /* size of pointer analysis hash table (must be power of 2) */ -# else -# define SOAP_PTRHASH (32) -# endif -#endif -#ifndef SOAP_IDHASH -# ifndef WITH_LEAN -# define SOAP_IDHASH (1999) /* prime size of hash table for parsed id/ref */ -# else -# define SOAP_IDHASH (19) /* 19, 199 */ -# endif -#endif -#ifndef SOAP_BLKLEN -# ifndef WITH_LEAN -# define SOAP_BLKLEN (256) /* size of blocks to collect long strings and XML attributes */ -# else -# define SOAP_BLKLEN (32) -# endif -#endif -#ifndef SOAP_TAGLEN -# ifndef WITH_LEAN -# define SOAP_TAGLEN (1024) /* maximum length of XML element tag/attribute name or host/path name + 1 */ -# else -# define SOAP_TAGLEN (64) -# endif -#endif -#ifndef SOAP_HDRLEN -# ifndef WITH_LEAN -# define SOAP_HDRLEN (8192) /* maximum length of HTTP header line (must be >4096 to read cookies) */ -# else -# define SOAP_HDRLEN (1024) -# endif -#endif -#ifndef SOAP_MAXDIMS -# ifndef WITH_LEAN -# define SOAP_MAXDIMS (16) /* maximum array dimensions (array nestings) must be less than 64 to protect soap->tmpbuf */ -# else -# define SOAP_MAXDIMS (4) -# endif -#endif - -#ifndef SOAP_MAXLOGS -# define SOAP_MAXLOGS (3) /* max number of debug logs per struct soap environment */ -# define SOAP_INDEX_RECV (0) -# define SOAP_INDEX_SENT (1) -# define SOAP_INDEX_TEST (2) -#endif - -#ifndef SOAP_MAXKEEPALIVE -# define SOAP_MAXKEEPALIVE (100) /* max iterations to keep server connection alive */ -#endif - -#ifndef SOAP_MAXARRAYSIZE -# define SOAP_MAXARRAYSIZE (100000) /* "trusted" max size of inbound SOAP array for compound array allocation */ -#endif - -#ifdef VXWORKS -# ifdef __INCmathh -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) isNan(num) -# endif -#endif - -#ifdef WIN32 -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) _isnan(num) -#endif - -#ifdef SUN_OS -# define HAVE_ISNAN -#endif - -#ifdef __APPLE__ -# ifdef __cplusplus -# ifndef isnan -extern "C" int isnan(double); -# endif -# endif -# define HAVE_ISNAN -#endif - -#if !defined(HAVE_ISNAN) && (defined(_MATH_H) || defined(_MATH_INCLUDED)) -# define HAVE_ISNAN -#endif - -extern const struct soap_double_nan { unsigned int n1, n2; } soap_double_nan; - -#ifdef VXWORKS -# ifndef FLT_MAX -# define FLT_MAX _ARCH_FLT_MAX -# endif -# ifndef DBL_MAX -# define DBL_MAX _ARCH_DBL_MAX -# endif -#endif - -#ifndef FLT_NAN -# define FLT_NAN (*(float*)(void*)&soap_double_nan) -#endif - -#ifndef FLT_PINFTY -# if defined(FLT_MAX) -# define FLT_PINFTY FLT_MAX -# elif defined(HUGE_VALF) -# define FLT_PINFTY (float)HUGE_VALF -# elif defined(HUGE_VAL) -# define FLT_PINFTY (float)HUGE_VAL -# elif defined(FLOAT_MAX) -# define FLT_PINFTY FLOAT_MAX -# else -# define FLT_PINFTY (3.40282347e+38F) -# endif -#endif - -#ifndef FLT_NINFTY -# define FLT_NINFTY (-FLT_PINFTY) -#endif - -#ifndef DBL_NAN -# define DBL_NAN (*(double*)(void*)&soap_double_nan) -#endif - -#ifndef DBL_PINFTY -# if defined(DBL_MAX) -# define DBL_PINFTY DBL_MAX -# elif defined(HUGE_VALF) -# define DBL_PINFTY (double)HUGE_VALF -# elif defined(HUGE_VAL) -# define DBL_PINFTY (double)HUGE_VAL -# elif defined(DOUBLE_MAX) -# define DBL_PINFTY DOUBLE_MAX -# else -# define DBL_PINFTY (1.7976931348623157e+308) -# endif -#endif - -#ifndef DBL_NINFTY -# define DBL_NINFTY (-DBL_PINFTY) -#endif - -#ifndef soap_isnan -# ifdef HAVE_ISNAN -# define soap_isnan(n) isnan(n) -# else -# define soap_isnan(n) (0) -# endif -#endif - -#define soap_ispinfd(n) ((n) >= DBL_PINFTY) -#define soap_ispinff(n) ((n) >= FLT_PINFTY) -#define soap_isninfd(n) ((n) <= DBL_NINFTY) -#define soap_isninff(n) ((n) <= FLT_NINFTY) - -/* gSOAP error codes */ - -#define SOAP_EOF EOF -#define SOAP_ERR EOF -#define SOAP_OK 0 -#define SOAP_CLI_FAULT 1 -#define SOAP_SVR_FAULT 2 -#define SOAP_TAG_MISMATCH 3 -#define SOAP_TYPE 4 -#define SOAP_SYNTAX_ERROR 5 -#define SOAP_NO_TAG 6 -#define SOAP_IOB 7 -#define SOAP_MUSTUNDERSTAND 8 -#define SOAP_NAMESPACE 9 -#define SOAP_USER_ERROR 10 -#define SOAP_FATAL_ERROR 11 -#define SOAP_FAULT 12 -#define SOAP_NO_METHOD 13 -#define SOAP_NO_DATA 14 -#define SOAP_GET_METHOD 15 -#define SOAP_EOM 16 -#define SOAP_MOE 17 -#define SOAP_NULL 18 -#define SOAP_DUPLICATE_ID 19 -#define SOAP_MISSING_ID 20 -#define SOAP_HREF 21 -#define SOAP_UDP_ERROR 22 -#define SOAP_TCP_ERROR 23 -#define SOAP_HTTP_ERROR 24 -#define SOAP_SSL_ERROR 25 -#define SOAP_ZLIB_ERROR 26 -#define SOAP_DIME_ERROR 27 -#define SOAP_DIME_HREF 28 -#define SOAP_DIME_MISMATCH 29 -#define SOAP_DIME_END 30 -#define SOAP_MIME_ERROR 31 -#define SOAP_MIME_HREF 32 -#define SOAP_MIME_END 33 -#define SOAP_VERSIONMISMATCH 34 -#define SOAP_PLUGIN_ERROR 35 -#define SOAP_DATAENCODINGUNKNOWN 36 -#define SOAP_REQUIRED 37 -#define SOAP_PROHIBITED 38 -#define SOAP_OCCURS 39 -#define SOAP_LENGTH 40 -#define SOAP_FD_EXCEEDED 41 - -#define soap_xml_error_check(e) ((e) == SOAP_TAG_MISMATCH || (e) == SOAP_TAG_END || (e) == SOAP_SYNTAX_ERROR || (e) == SOAP_NAMESPACE || (e) == SOAP_DUPLICATE_ID || (e) == SOAP_MISSING_ID || (e) == SOAP_REQUIRED || (e) == SOAP_PROHIBITED || (e) == SOAP_OCCURS || (e) == SOAP_LENGTH || (e) == SOAP_NULL || (e) == SOAP_HREF) -#define soap_soap_error_check(e) ((e) == SOAP_CLI_FAULT || (e) == SOAP_SVR_FAULT || (e) == SOAP_VERSIONMISMATCH || (e) == SOAP_MUSTUNDERSTAND || (e) == SOAP_FAULT || (e) == SOAP_NO_METHOD) -#define soap_tcp_error_check(e) ((e) == SOAP_EOF || (e) == SOAP_TCP_ERROR) -#define soap_ssl_error_check(e) ((e) == SOAP_SSL_ERROR) -#define soap_zlib_error_check(e) ((e) == SOAP_ZLIB_ERROR) -#define soap_http_error_check(e) ((e) == SOAP_HTTP_ERROR || (e) == SOAP_GET_METHOD || (e) == SOAP_NO_DATA || ((e) >= 100 && (e) < 600)) - -/* gSOAP HTTP response status codes 100 to 599 are reserved */ - -/* Codes 600 to 999 are user definable */ - -/* Exceptional gSOAP HTTP response status codes >= 1000 */ - -#define SOAP_STOP 1000 /* No HTTP response */ -#define SOAP_FORM 1001 /* Form request/response */ -#define SOAP_HTML 1002 /* Custom HTML response */ -#define SOAP_FILE 1003 /* Custom file-based response */ - -/* gSOAP HTTP method codes */ - -#define SOAP_POST 2000 -#define SOAP_GET 2001 - -/* gSOAP DIME */ - -#define SOAP_DIME_CF 0x01 -#define SOAP_DIME_ME 0x02 -#define SOAP_DIME_MB 0x04 -#define SOAP_DIME_VERSION 0x08 /* DIME version 1 */ -#define SOAP_DIME_MEDIA 0x10 -#define SOAP_DIME_ABSURI 0x20 - -/* gSOAP ZLIB */ - -#define SOAP_ZLIB_NONE 0x00 -#define SOAP_ZLIB_DEFLATE 0x01 -#define SOAP_ZLIB_INFLATE 0x02 -#define SOAP_ZLIB_GZIP 0x02 - -/* gSOAP transport, connection, and content encoding modes */ - -typedef soap_int32 soap_mode; - -#define SOAP_IO 0x00000003 /* IO mask */ -#define SOAP_IO_FLUSH 0x00000000 /* flush output immediately, no buffering */ -#define SOAP_IO_BUFFER 0x00000001 /* buffer output in packets of size SOAP_BUFLEN */ -#define SOAP_IO_STORE 0x00000002 /* store entire output to determine length for transport */ -#define SOAP_IO_CHUNK 0x00000003 /* use HTTP chunked transfer AND buffer packets */ - -#define SOAP_IO_UDP 0x00000004 /* TCP or UDP */ - -#define SOAP_IO_LENGTH 0x00000008 /* calc message length (internal) */ -#define SOAP_IO_KEEPALIVE 0x00000010 /* keep connection alive */ - -#define SOAP_ENC_LATIN 0x00000020 /* accept iso-8859-1 encoding */ -#define SOAP_ENC_XML 0x00000040 /* plain XML encoding, no HTTP header */ -#define SOAP_ENC_DIME 0x00000080 -#define SOAP_ENC_MIME 0x00000100 -#define SOAP_ENC_MTOM 0x00000200 -#define SOAP_ENC_ZLIB 0x00000400 -#define SOAP_ENC_SSL 0x00000800 - -#define SOAP_ENC 0x00000FFF /* IO and ENC mask */ - -#define SOAP_XML_STRICT 0x00001000 /* apply strict validation */ -#define SOAP_XML_INDENT 0x00002000 /* emit indented XML */ -#define SOAP_XML_CANONICAL 0x00004000 /* EXC C14N canonical XML */ -#define SOAP_XML_TREE 0x00008000 /* emit XML tree (no id/ref) */ -#define SOAP_XML_GRAPH 0x00010000 -#define SOAP_XML_NIL 0x00020000 -#define SOAP_XML_DOM 0x00040000 -#define SOAP_XML_SEC 0x00080000 /* reserved for WS security */ - -#define SOAP_C_NOIOB 0x00100000 /* don't fault on array index out of bounds (just ignore) */ -#define SOAP_C_UTFSTRING 0x00200000 /* (de)serialize strings with UTF8 content */ -#define SOAP_C_MBSTRING 0x00400000 /* (de)serialize strings with multi-byte content */ -#define SOAP_C_NILSTRING 0x00800000 /* serialize empty strings as nil (omitted) */ - -#define SOAP_DOM_TREE 0x01000000 -#define SOAP_DOM_NODE 0x02000000 -#define SOAP_DOM_ASIS 0x04000000 - -#define SOAP_MIME_POSTCHECK 0x10000000 /* MIME flag (internal) */ - -#define SOAP_IO_DEFAULT SOAP_IO_FLUSH - -/* SSL client/server authentication settings */ - -#define SOAP_SSL_NO_AUTHENTICATION 0x00 /* for testing purposes */ -#define SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION 0x01 /* client requires server to authenticate */ -#define SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION 0x02 /* server requires client to authenticate */ -#define SOAP_SSL_SKIP_HOST_CHECK 0x04 /* client does not check the common name of the host in certificate */ -#define SOAP_SSL_RSA 0x06 /* use RSA */ -#define SOAP_SSLv3_TLSv1 0x00 /* SSL v3 and TLS v1 support by default */ -#define SOAP_SSLv3 0x10 /* SSL v3 only */ -#define SOAP_TLSv1 0x20 /* TLS v1 only */ - -#define SOAP_SSL_DEFAULT (SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION | SOAP_SSLv3_TLSv1) - -/* state */ - -#define SOAP_INIT 1 -#define SOAP_COPY 2 - -#define soap_check_state(soap) (!(soap) || ((soap)->state != SOAP_INIT && (soap)->state != SOAP_COPY)) - -/* part */ - -#define SOAP_BEGIN 0 -#define SOAP_IN_ENVELOPE 2 -#define SOAP_IN_HEADER 3 -#define SOAP_END_HEADER 4 -#define SOAP_NO_BODY 5 -#define SOAP_IN_BODY 6 -#define SOAP_END_BODY 7 -#define SOAP_END_ENVELOPE 8 -#define SOAP_END 9 -#define SOAP_BEGIN_SECURITY 10 -#define SOAP_IN_SECURITY 11 -#define SOAP_END_SECURITY 12 - -/* DEBUG macros */ - -#ifndef WITH_LEAN -# ifdef DEBUG -# ifndef SOAP_DEBUG -# define SOAP_DEBUG -# endif -# ifndef SOAP_MEM_DEBUG -# define SOAP_MEM_DEBUG -# endif -# endif -#endif - -#ifdef SOAP_MEM_DEBUG -# ifndef SOAP_MALLOC -# define SOAP_MALLOC(soap, size) soap_track_malloc(soap, __FILE__, __LINE__, size) -# endif -# ifndef SOAP_FREE -# define SOAP_FREE(soap, ptr) soap_track_free(soap, __FILE__, __LINE__, ptr) -# endif -#endif - -#ifndef SOAP_MALLOC /* use libc malloc */ -# define SOAP_MALLOC(soap, size) malloc(size) -#endif - -#ifndef SOAP_FREE /* use libc free */ -# define SOAP_FREE(soap, ptr) free(ptr) -#endif - -#ifdef SOAP_DEBUG -# ifndef SOAP_MESSAGE -# define SOAP_MESSAGE fprintf -# endif -# ifndef DBGLOG -# define DBGLOG(DBGFILE, CMD) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ - CMD;\ - fflush(fdebug);\ - }\ - }\ -} -# endif -# ifndef DBGMSG -# define DBGMSG(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { fwrite((MSG), 1, (LEN), soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -# ifndef DGBFUN -# define DBGFUN(FNAME) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s()\n", __FILE__, __LINE__, FNAME)) -# define DBGFUN1(FNAME, FMT, ARG) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT")\n", __FILE__, __LINE__, FNAME, (ARG))) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2))) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2", "FMT3")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2), (ARG3))) -# endif -# ifndef DBGHEX -# define DBGHEX(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { int i; char *s;\ - for (s = (char*)(MSG), i = (LEN); i; i--)\ - fprintf(soap->fdebug[SOAP_INDEX_##DBGFILE], "%2.2X ", (int)*s++&0xFF);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -#else -# define DBGLOG(DBGFILE, CMD) -# define DBGMSG(DBGFILE, MSG, LEN) -# define DBGFUN(FNAME) -# define DBGFUN1(FNAME, FMT, ARG) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) -# define DBGHEX(DBGFILE, MSG, LEN) -#endif - -/* UCS-4 requires 32 bits (0-7FFFFFFF, the sign bit is used by gSOAP to distinguish XML entities) */ -typedef soap_int32 soap_wchar; - -/* namespace table row */ -struct Namespace -{ const char *id; - const char *ns; - const char *in; - char *out; -}; - -/* namespace stack */ -struct soap_nlist -{ struct soap_nlist *next; - unsigned int level; /* nesting depth level */ - short index; /* corresponding entry in ns mapping table */ - char *ns; /* only set when parsed ns URI is not in the ns mapping table */ - char id[1]; /* the actual string value flows into the allocated region below this struct */ -}; - -/* block stack for nested block allocations */ -struct soap_blist -{ struct soap_blist *next; - char *ptr; - size_t size; -}; - -/* array layout */ -struct soap_array -{ void *__ptr; - int __size; -}; - -/* pointer serialization management */ -struct soap_plist -{ struct soap_plist *next; - const void *ptr; - const struct soap_array *array; - int type; - int id; - char mark1; - char mark2; -}; - -/* block allocation for pointer serialization management */ -struct soap_pblk -{ struct soap_pblk *next; - struct soap_plist plist[SOAP_PTRBLK]; -}; - -#ifdef SOAP_MEM_DEBUG -/* malloc/free tracking for debugging */ -struct soap_mlist -{ struct soap_mlist *next; - const void *ptr; - const char *file; - int line; - short live; -}; -#endif - -/* class allocation list */ -struct soap_clist -{ struct soap_clist *next; - void *ptr; - int type; - int size; - void (*fdelete)(struct soap_clist*); -}; - -/* attributes */ -struct soap_attribute -{ struct soap_attribute *next; - char *value; - size_t size; - char *ns; - short visible; - char name[1]; /* the actual name string flows into the allocated region below this struct */ -}; - -#ifndef WITH_LEAN -struct soap_cookie -{ struct soap_cookie *next; - char *name; - char *value; - char *domain; - char *path; - time_t expire; /* client-side: local time to expire */ - long maxage; /* server-side: seconds to expire */ - unsigned int version; - short secure; - short session; /* server-side */ - short env; /* server-side: got cookie from client and should not be (re)send */ - short modified; /* server-side: client cookie was modified and should be send */ -}; -#endif - -#ifdef __cplusplus -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); - -class soap_multipart_iterator -{ public: - struct soap_multipart *content; - bool operator==(const soap_multipart_iterator& iter) const - { return content == iter.content; } - bool operator!=(const soap_multipart_iterator& iter) const - { return content != iter.content; } - struct soap_multipart &operator*() const - { return *content; } - soap_multipart_iterator &operator++() - { content = soap_next_multipart(content); return *this; } - soap_multipart_iterator() : content(NULL) - { } - soap_multipart_iterator(struct soap_multipart *p) : content(p) - { } -}; -#endif - -#ifndef WITH_LEANER -struct soap_dime -{ size_t count; - size_t size; - size_t chunksize; - size_t buflen; - char flags; - char *ptr; - const char *id; - const char *type; - const char *options; - struct soap_multipart *list; /* list of DIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -struct soap_mime -{ char *boundary; /* MIME boundary */ - const char *start; /* MIME start ID */ - struct soap_multipart *list; /* list of MIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* RFC2045 MIME content transfer encodings */ -enum soap_mime_encoding -{ SOAP_MIME_NONE, - SOAP_MIME_7BIT, - SOAP_MIME_8BIT, - SOAP_MIME_BINARY, - SOAP_MIME_QUOTED_PRINTABLE, - SOAP_MIME_BASE64, - SOAP_MIME_IETF_TOKEN, - SOAP_MIME_X_TOKEN -}; -#endif - -#ifndef WITH_LEANER -/* DIME/MIME multipart list */ -struct soap_multipart -{ struct soap_multipart *next; - char *ptr; /* points to raw data content */ - size_t size; /* size of data content */ - const char *id; /* DIME/MIME content ID or form data name */ - const char *type; /* DIME/MIME type (MIME type format) */ - const char *options; /* DIME options */ - enum soap_mime_encoding encoding; /* MIME Content-Transfer-Encoding */ - const char *location; /* MIME Content-Location (optional) */ - const char *description; /* MIME Content-Description (optional) */ -#ifdef __cplusplus - typedef soap_multipart_iterator iterator; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* attachment DIME and MTOM XOP forwarding */ -struct soap_xlist -{ struct soap_xlist *next; - unsigned char **ptr; - int *size; - char *id; - char **type; - char **options; -}; -#endif - -/******************************************************************************/ - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_attribute_iterator -{ public: - struct soap_dom_attribute *att; - const char *nstr; - const char *name; - bool operator==(const soap_dom_attribute_iterator&) const; - bool operator!=(const soap_dom_attribute_iterator&) const; - struct soap_dom_attribute &operator*() const; - soap_dom_attribute_iterator &operator++(); - soap_dom_attribute_iterator(); - soap_dom_attribute_iterator(struct soap_dom_attribute*); - ~soap_dom_attribute_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_attribute -{ struct soap_dom_attribute *next; - const char *nstr; - char *name; - char *data; - wchar_t *wide; - struct soap *soap; -#ifdef __cplusplus - typedef soap_dom_attribute_iterator iterator; - struct soap_dom_attribute &set(const char *nstr, const char *name); /* set namespace and name */ - struct soap_dom_attribute &set(const char *data); /* set data */ - soap_dom_attribute_iterator begin(); - soap_dom_attribute_iterator end(); - soap_dom_attribute_iterator find(const char *nstr, const char *name); - void unlink(); - soap_dom_attribute(); - soap_dom_attribute(struct soap *soap); - soap_dom_attribute(struct soap *soap, const char *nstr, const char *name, const char *data); - ~soap_dom_attribute(); -#endif -}; -#endif - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_element_iterator -{ public: - struct soap_dom_element *elt; - const char *nstr; - const char *name; - int type; - bool operator==(const soap_dom_element_iterator&) const; - bool operator!=(const soap_dom_element_iterator&) const; - struct soap_dom_element &operator*() const; - soap_dom_element_iterator &operator++(); - soap_dom_element_iterator(); - soap_dom_element_iterator(struct soap_dom_element*); - ~soap_dom_element_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_element -{ struct soap_dom_element *next; /* next sibling */ - struct soap_dom_element *prnt; /* parent */ - struct soap_dom_element *elts; /* list of child elements */ - struct soap_dom_attribute *atts; /* list of attributes */ - const char *nstr; /* namespace string */ - char *name; /* element tag name */ - char *data; /* element content data (with SOAP_C_UTFSTRING flag set) */ - wchar_t *wide; /* element content data */ - int type; /* optional: serialized C/C++ data type */ - void *node; /* optional: pointer to serialized C/C++ data */ - char *head; /* leading whitespace to start tag */ - char *tail; /* leading whitespace to end tag */ - struct soap *soap; /* soap context that manages this node */ -#ifdef __cplusplus - typedef soap_dom_element_iterator iterator; - struct soap_dom_element &set(const char *nstr, const char *name); - struct soap_dom_element &set(const char *data); - struct soap_dom_element &set(void *node, int type); - struct soap_dom_element &add(struct soap_dom_element*); - struct soap_dom_element &add(struct soap_dom_element&); - struct soap_dom_element &add(struct soap_dom_attribute*); - struct soap_dom_element &add(struct soap_dom_attribute&); - soap_dom_element_iterator begin(); - soap_dom_element_iterator end(); - soap_dom_element_iterator find(const char *nstr, const char *name); - soap_dom_element_iterator find(int type); - void unlink(); - soap_dom_element(); - soap_dom_element(struct soap *soap); - soap_dom_element(struct soap *soap, const char *nstr, const char *name); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type); - ~soap_dom_element(); -#endif -}; -SOAP_FMAC1 struct soap_dom_element * SOAP_FMAC2 soap_dom_next_element(struct soap_dom_element *elt); -SOAP_FMAC1 struct soap_dom_attribute * SOAP_FMAC2 soap_dom_next_attribute(struct soap_dom_attribute *att); -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -} -extern std::ostream &operator<<(std::ostream&, const struct soap_dom_element&); -extern std::istream &operator>>(std::istream&, struct soap_dom_element&); -extern "C" { -#endif - -/******************************************************************************/ - -#ifdef WIN32 -# ifdef SOAP_STD_EXPORTS -# define SOAP_STD_API __declspec(dllexport) -# else -# define SOAP_STD_API -# endif -#else -# define SOAP_STD_API -#endif - -struct SOAP_STD_API soap -{ short state; /* 0 = uninitialized, 1 = initialized, 2 = copy of another soap struct */ - short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table) */ - soap_mode mode; - soap_mode imode; - soap_mode omode; - const char *float_format; /* user-definable format string for floats (<1024 chars) */ - const char *double_format; /* user-definable format string for doubles (<1024 chars) */ - const char *dime_id_format; /* user-definable format string for integer DIME id ( 0, gives socket recv timeout in seconds, < 0 in usec */ - int send_timeout; /* when > 0, gives socket send timeout in seconds, < 0 in usec */ - int connect_timeout; /* when > 0, gives socket connect() timeout in seconds, < 0 in usec */ - int accept_timeout; /* when > 0, gives socket accept() timeout in seconds, < 0 in usec */ - int socket_flags; /* socket recv() and send() flags, e.g. set to MSG_NOSIGNAL to disable sigpipe */ - int connect_flags; /* connect() SOL_SOCKET sockopt flags, e.g. set to SO_DEBUG to debug socket */ - int bind_flags; /* bind() SOL_SOCKET sockopt flags, e.g. set to SO_REUSEADDR to enable reuse */ - int accept_flags; /* accept() SOL_SOCKET sockopt flags */ - const struct Namespace *namespaces; /* Pointer to global namespace mapping table */ - struct Namespace *local_namespaces; /* Local namespace mapping table */ - struct soap_nlist *nlist; /* namespace stack */ - struct soap_blist *blist; /* block allocation stack */ - struct soap_clist *clist; /* class instance allocation list */ - void *alist; /* memory allocation (malloc) list */ - struct soap_ilist *iht[SOAP_IDHASH]; - struct soap_plist *pht[SOAP_PTRHASH]; - struct soap_pblk *pblk; /* plist block allocation */ - short pidx; /* plist block allocation */ - struct SOAP_ENV__Header *header; - struct SOAP_ENV__Fault *fault; - int idnum; - void *user; /* to pass user-defined data */ - struct soap_plugin *plugins; /* linked list of plug-in data */ - char *userid; /* HTTP Basic authorization userid */ - char *passwd; /* HTTP Basic authorization passwd */ - int (*fpost)(struct soap*, const char*, const char*, int, const char*, const char*, size_t); - int (*fget)(struct soap*); - int (*fform)(struct soap*); - int (*fposthdr)(struct soap*, const char*, const char*); - int (*fresponse)(struct soap*, int, size_t); - int (*fparse)(struct soap*); - int (*fparsehdr)(struct soap*, const char*, const char*); - int (*fheader)(struct soap*); - int (*fresolve)(struct soap*, const char*, struct in_addr* inaddr); - int (*fconnect)(struct soap*, const char*, const char*, int); - int (*fdisconnect)(struct soap*); - int (*fclosesocket)(struct soap*, SOAP_SOCKET); - int (*fshutdownsocket)(struct soap*, SOAP_SOCKET, int); - int (*fopen)(struct soap*, const char*, const char*, int); - int (*faccept)(struct soap*, int, struct sockaddr*, int *n); - int (*fclose)(struct soap*); - int (*fsend)(struct soap*, const char*, size_t); - size_t (*frecv)(struct soap*, char*, size_t); - int (*fpoll)(struct soap*); - void (*fseterror)(struct soap*, const char **c, const char **s); - int (*fignore)(struct soap*, const char*); - int (*fserveloop)(struct soap*); - void *(*fplugin)(struct soap*, const char*); - void *(*fmalloc)(struct soap*, size_t); -#ifndef WITH_LEANER - int (*fprepareinit)(struct soap*); - int (*fpreparesend)(struct soap*, const char*, size_t); - int (*fpreparerecv)(struct soap*, const char*, size_t); - int (*fpreparefinal)(struct soap*); - void *(*fdimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fdimewriteopen)(struct soap*, const char*, const char*, const char*); - void (*fdimereadclose)(struct soap*, void*); - void (*fdimewriteclose)(struct soap*, void*); - size_t (*fdimeread)(struct soap*, void*, char*, size_t); - int (*fdimewrite)(struct soap*, void*, const char*, size_t); - void *(*fmimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fmimewriteopen)(struct soap*, void*, const char*, const char*, const char*, enum soap_mime_encoding); - void (*fmimereadclose)(struct soap*, void*); - void (*fmimewriteclose)(struct soap*, void*); - size_t (*fmimeread)(struct soap*, void*, char*, size_t); - int (*fmimewrite)(struct soap*, void*, const char*, size_t); -#endif - int master; - int socket; -#if defined(__cplusplus) && !defined(WITH_LEAN) - std::ostream *os; - std::istream *is; -#else - void *os; /* preserve alignment */ - void *is; /* preserve alignment */ -#endif -#ifndef UNDER_CE - int sendfd; - int recvfd; -#else - FILE *sendfd; - FILE *recvfd; -#endif - size_t bufidx; /* index in soap.buf[] */ - size_t buflen; /* length of soap.buf[] content */ - soap_wchar ahead; /* parser lookahead */ - short cdata; /* CDATA parser state */ - short body; /* parsed XML element has a body or not */ - unsigned int level; /* XML nesting level */ - size_t count; /* message length counter */ - size_t length; /* message length as set by HTTP header */ - char *labbuf; /* look-aside buffer */ - size_t lablen; /* look-aside buffer allocated length */ - size_t labidx; /* look-aside buffer index to available part */ - char buf[SOAP_BUFLEN];/* send and receive buffer */ - char tmpbuf[1024]; /* in/output buffer for HTTP/MIME headers, simpleType values, attribute names, and DIME must be >=1024 bytes */ - char msgbuf[1024]; /* in/output buffer for messages >=1024 bytes */ - char tag[SOAP_TAGLEN]; - char id[SOAP_TAGLEN]; - char href[SOAP_TAGLEN]; - char type[SOAP_TAGLEN]; - char arrayType[SOAP_TAGLEN]; - char arraySize[SOAP_TAGLEN]; - char arrayOffset[SOAP_TAGLEN]; - short other; - short position; - int positions[SOAP_MAXDIMS]; - short root; - struct soap_attribute *attributes; /* attribute list */ - short encoding; /* when set, output encodingStyle */ - short mustUnderstand; /* a mustUnderstand element was parsed or is output */ - short keep_alive; /* connection should be kept open */ - short null; /* parsed XML is xsi:nil */ - short ns; /* when not set, output full xmlns bindings */ - short part; /* parsing state */ - short alloced; - short peeked; - size_t chunksize; - size_t chunkbuflen; - char endpoint[SOAP_TAGLEN]; - char path[SOAP_TAGLEN]; - char host[SOAP_TAGLEN]; - char *action; - char *authrealm; /* HTTP authentication realm */ - char *prolog; /* XML declaration prolog */ - unsigned long ip; /* IP number */ - int port; /* port number */ - unsigned int max_keep_alive; - const char *proxy_http_version;/* HTTP version of proxy "1.0" or "1.1" */ - const char *proxy_host; /* Proxy Server host name */ - int proxy_port; /* Proxy Server port (default = 8080) */ - const char *proxy_userid; /* Proxy Authorization user name */ - const char *proxy_passwd; /* Proxy Authorization password */ - int status; /* -1 when request, else error code to be returned by server */ - int error; - int errmode; - int errnum; -#ifndef WITH_LEANER - struct soap_dom_element *dom; - struct soap_dime dime; - struct soap_mime mime; - struct soap_xlist *xlist; -#endif -#if !defined(WITH_LEAN) || defined(SOAP_DEBUG) - const char *logfile[SOAP_MAXLOGS]; - FILE *fdebug[SOAP_MAXLOGS]; - struct soap_mlist *mht[SOAP_PTRHASH]; -#endif -#ifndef WITH_LEAN - const char *c14ninclude; - const char *c14nexclude; - struct soap_cookie *cookies; - const char *cookie_domain; - const char *cookie_path; - int cookie_max; -#endif -#ifndef WITH_NOIO -#ifdef WITH_IPV6 - struct sockaddr_storage peer; /* IPv6: set by soap_accept and by UDP recv */ -#else - struct sockaddr_in peer; /* IPv4: set by soap_connect/soap_accept and by UDP recv */ -#endif -#endif - size_t peerlen; -#ifdef WITH_OPENSSL - int (*fsslauth)(struct soap*); - int (*fsslverify)(int, X509_STORE_CTX*); - BIO *bio; - SSL *ssl; - SSL_CTX *ctx; - unsigned short ssl_flags; - const char *keyfile; - const char *password; - const char *dhfile; - const char *cafile; - const char *capath; - const char *crlfile; - const char *randfile; - SSL_SESSION *session; - char session_host[SOAP_TAGLEN]; - int session_port; -#endif -#ifdef WITH_ZLIB - short zlib_state; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_INFLATE */ - short zlib_in; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - short zlib_out; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - z_stream d_stream; /* decompression stream */ - char z_buf[SOAP_BUFLEN]; /* buffer */ - size_t z_buflen; - unsigned short z_level; /* compression level to be used (0=none, 1=fast to 9=best) */ - uLong z_crc; /* internal gzip crc */ - float z_ratio_in; /* detected compression ratio compressed_length/length of inbound message */ - float z_ratio_out; /* detected compression ratio compressed_length/length of outbound message */ -#endif -#ifdef WMW_RPM_IO - void *rpmreqid; -#endif -#ifndef WITH_LEAN -#ifdef __cplusplus - soap(); - soap(soap_mode); - soap(soap_mode, soap_mode); - soap(struct soap&); - ~soap(); -#endif -#endif -}; - -struct soap_code_map -{ long code; - const char *string; -}; - -/* forwarding list */ -struct soap_flist -{ struct soap_flist *next; - int type; - void *ptr; - unsigned int level; - size_t len; - void (*fcopy)(struct soap*, int, int, void*, size_t, const void*, size_t); -}; - -/* id-ref forwarding list */ -struct soap_ilist -{ struct soap_ilist *next; - int type; - size_t size; - void *link; - void *copy; - struct soap_flist *flist; - void *ptr; - unsigned int level; - char id[1]; /* the actual id string value flows into the allocated region below this struct */ -}; - -struct soap_plugin -{ struct soap_plugin *next; - const char *id; - void *data; - int (*fcopy)(struct soap *soap, struct soap_plugin *dst, struct soap_plugin *src); - void (*fdelete)(struct soap *soap, struct soap_plugin *p); /* should delete fields of plugin only and not free(p) */ -}; - -#ifndef WITH_NONAMESPACES -extern SOAP_NMAC struct Namespace namespaces[]; -#endif - -#ifndef WITH_LEAN -# define soap_get0(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx]) -# define soap_get1(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx++]) -#else -soap_wchar soap_get0(struct soap*); -soap_wchar soap_get1(struct soap*); -#endif - -#define soap_revget1(soap) ((soap)->bufidx--) -#define soap_unget(soap, c) ((soap)->ahead = c) -#define soap_register_plugin(soap, plugin) soap_register_plugin_arg(soap, plugin, NULL) -#define soap_imode(soap, n) ((soap)->mode = (soap)->imode = (n)) -#define soap_set_imode(soap, n) ((soap)->imode |= (n)) -#define soap_clr_imode(soap, n) ((soap)->imode &= ~(n)) -#define soap_omode(soap, n) ((soap)->mode = (soap)->omode = (n)) -#define soap_set_omode(soap, n) ((soap)->omode |= (n)) -#define soap_clr_omode(soap, n) ((soap)->omode &= ~(n)) -#define soap_set_mode(soap, n) ((soap)->imode |= (n), (soap)->omode |= (n)) -#define soap_clr_mode(soap, n) ((soap)->imode &= ~(n), (soap)->omode &= ~(n)) -#define soap_destroy(soap) soap_delete((soap), NULL) - -#ifdef HAVE_STRRCHR -# define soap_strrchr(s, t) strrchr(s, t) -#else - SOAP_FMAC1 char* SOAP_FMAC2 soap_strrchr(const char *s, int t); -#endif - -#ifdef HAVE_STRTOL -# define soap_strtol(s, t, b) strtol(s, t, b) -#else - SOAP_FMAC1 long SOAP_FMAC2 soap_strtol(const char *s, char **t, int b); -#endif - -#ifdef HAVE_STRTOUL -# define soap_strtoul(s, t, b) strtoul(s, t, b) -#else - SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b); -#endif - -#if defined(WITH_OPENSSL) -# define soap_random soap_rand() -SOAP_FMAC1 int SOAP_FMAC2 soap_rand(void); -#elif defined(HAVE_RANDOM) -# define soap_random (int)random() -#else -# define soap_random rand() -#endif - -#ifdef WITH_NOIDREF -# define soap_embedded(s, p, t) (0) -# define soap_id_lookup(s, i, p, t, n, k) (p) -# define soap_id_forward(s, h, p, len, st, tt, n, k, fc) (p) -# define soap_reference(s, a, t) (1) -# define soap_array_reference(s, p, a, n, t) (1) -# define soap_embed(s, p, a, n, t, pp) (0) -# define soap_embedded_id(s, i, p, t) (i) -# define soap_is_embedded(s, p) (0) -# define soap_is_single(s, p) (1) -# define soap_lookup_type(s, i) (0) -# define soap_getindependent(s) (0) -# define soap_putindependent(s) (0) -# define soap_getelement(s, n) (n) -# define soap_putelement(s, p, t, i, n) (0) -# define soap_markelement(s, p, n) (0) -#endif - -SOAP_FMAC1 void SOAP_FMAC2 soap_fault(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultsubcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultstring(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultdetail(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializefault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getfault(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_ssl_init(void); -SOAP_FMAC1 int SOAP_FMAC2 soap_poll(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect_command(struct soap*, int, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_bind(struct soap*, const char*, int, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_accept(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_accept(struct soap*); -SOAP_FMAC1 const char * SOAP_FMAC2 soap_ssl_error(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_puthttphdr(struct soap*, int status, size_t count); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_get_header_attribute(struct soap*, const char*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_key(char*, size_t, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_val(char*, size_t, const char*); - -SOAP_FMAC1 size_t SOAP_FMAC2 soap_hash(const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_endpoint(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_get(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getchar(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_tag_cmp(const char*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_sender_error(struct soap*, const char*, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_receiver_error(struct soap*, const char*, const char*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_raw(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send2(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send3(struct soap*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pututf8(struct soap*, unsigned long); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getutf8(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_putbase64(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_getbase64(struct soap*, int*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_puthex(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_gethex(struct soap*, int*); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_xop_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_dime_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -#endif - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup_id(struct soap*, void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup(struct soap*, const void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_enter(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_pointer_lookup(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -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); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_lookup(struct soap*, const char*); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_enter(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_resolve(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_embedded(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_reference(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_reference(struct soap*, const void *p, const struct soap_array *a, int n, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_embedded_id(struct soap*, int id, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_embedded(struct soap*, struct soap_plist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_single(struct soap*, struct soap_plist*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_embedded(struct soap*, struct soap_plist*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_send(struct soap*); - -SOAP_FMAC1 const struct soap_code_map* SOAP_FMAC2 soap_code(const struct soap_code_map*, const char*); -SOAP_FMAC1 long SOAP_FMAC2 soap_code_int(const struct soap_code_map*, const char*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_code_str(const struct soap_code_map*, long); -SOAP_FMAC1 long SOAP_FMAC2 soap_code_bits(const struct soap_code_map*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_code_list(struct soap*, const struct soap_code_map*, long); - -SOAP_FMAC1 int SOAP_FMAC2 soap_getline(struct soap*, char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_recv(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_malloc(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_dealloc(struct soap*, void*); -SOAP_FMAC1 struct soap_clist * SOAP_FMAC2 soap_link(struct soap*, void*, int, int, void (*fdelete)(struct soap_clist*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_unlink(struct soap*, const void*); -SOAP_FMAC1 void SOAP_FMAC2 soap_free_temp(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_del(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_track_malloc(struct soap*, const char*, int, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_track_free(struct soap*, const char*, int, void*); - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_lookup_type(struct soap*, const char *id); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_lookup(struct soap*, const char *id, void **p, int t, size_t n, unsigned int k); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_forward(struct soap*, const char *id, void *p, size_t len, int st, int tt, size_t n, unsigned int k, void(*fcopy)(struct soap*, int, int, void*, size_t, const void*, size_t)); -#endif -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_enter(struct 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*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_fcopy(struct soap *soap, int st, int tt, void *p, size_t, const void *q, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_size(const int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getoffsets(const char *, const int *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsize(const char *, const char *, int *); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsizes(const char *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getposition(const char *, int *); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsize(struct soap*, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizesoffsets(struct soap*, const char *, const int *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizes(struct soap*, const char *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffset(struct soap*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffsets(struct soap*, const int *, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_closesock(struct soap*); - -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new(void); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new1(soap_mode); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new2(soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_free(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*, struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_copy_stream(struct soap*, struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init1(struct soap*, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_init2(struct soap*, soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_end(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_delete(struct soap*, void*); - -#ifdef SOAP_DEBUG -SOAP_FMAC1 void SOAP_FMAC2 soap_set_recv_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_sent_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_test_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_close_logfiles(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_open_logfile(struct soap*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_value(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_tag(struct soap*, const char*, const char *); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_array(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element(struct soap*, const char*, int, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_out(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_begin_out(struct soap*, const char *tag, int id, const char *type, const char *offset); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_ref(struct soap*, const char *tag, int id, int href); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_href(struct soap*, const char *tag, int id, const char *ref, const char *val); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_null(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_id(struct soap*, const char *tag, int id, const void *p, const struct soap_array *a, int d, const char *type, int n); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_result(struct soap*, const char *tag); -SOAP_FMAC1 void SOAP_FMAC2 soap_check_result(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_out(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_start_end_out(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_attribute(struct soap*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_in(struct soap*, const char *tag, int nillable, const char *type); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_in(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_peek_element(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_retry(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_revert(struct soap*); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_strdup(struct soap*, const char*); -SOAP_FMAC1 const char * SOAP_FMAC2 soap_strsearch(const char *big, const char *little); - -SOAP_FMAC1 int SOAP_FMAC2 soap_string_out(struct soap*, const char *s, int flag); -SOAP_FMAC1 char* SOAP_FMAC2 soap_string_in(struct soap*, int, long, long); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_wstring_out(struct soap*, const wchar_t *s, int flag); -SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstring_in(struct soap*, int, long, long); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_namespace(struct soap*, const char *, const char*, int n1, int n2); - -SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap*, const struct Namespace*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_local_namespaces(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_namespace(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_push_namespace(struct soap*, const char *,const char *); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_current_namespace(struct soap *soap, const char *tag); - -SOAP_FMAC1 struct soap_nlist* SOAP_FMAC2 soap_lookup_ns(struct soap *soap, const char *tag, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_store_lab(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_append_lab(struct soap*, const char*, size_t); - -SOAP_FMAC1 int SOAP_FMAC2 soap_new_block(struct soap*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_push_block(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_size_block(struct soap*, size_t); -SOAP_FMAC1 char* SOAP_FMAC2 soap_first_block(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_next_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_block_size(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_save_block(struct soap*, char*, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*); -SOAP_FMAC1 int soap_envelope_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_out(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_header(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_response(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_empty_response(struct soap*, int status); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_empty_response(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_fault(struct soap*); - -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap*, FILE*); -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault_location(struct soap*, FILE*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_s2byte(struct soap*, const char*, char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2short(struct soap*, const char*, short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2int(struct soap*, const char*, int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2long(struct soap*, const char*, long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2LONG64(struct soap*, const char*, LONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2float(struct soap*, const char*, float*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2double(struct soap*, const char*, double*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedByte(struct soap*, const char*, unsigned char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedShort(struct soap*, const char*, unsigned short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedInt(struct soap*, const char*, unsigned int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedLong(struct soap*, const char*, unsigned long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2ULONG64(struct soap*, const char*, ULONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2string(struct soap*, const char*, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2QName(struct soap*, const char*, char**); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_s2wchar(struct soap*, const char*, wchar_t**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2dateTime(struct soap*, const char*, time_t*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2base64(struct soap*, const unsigned char*, char*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2hex(struct soap*, const unsigned char*, char*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_byte2s(struct soap*, char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_short2s(struct soap*, short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_int2s(struct soap*, int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_long2s(struct soap*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_LONG642s(struct soap*, LONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_float2s(struct soap*, float); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_double2s(struct soap*, double); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedByte2s(struct soap*, unsigned char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedShort2s(struct soap*, unsigned short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedInt2s(struct soap*, unsigned int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedLong2s(struct soap*, unsigned long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_ULONG642s(struct soap*, ULONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_QName2s(struct soap*, const char*); - -#ifndef WITH_LEAN -SOAP_FMAC1 const char* SOAP_FMAC2 soap_wchar2s(struct soap*, const wchar_t*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_dateTime2s(struct soap*, time_t); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_base642s(struct soap*, const char*, char*, size_t, int*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_hex2s(struct soap*, const char*, char*, size_t, int*); -#endif - - -SOAP_FMAC1 int* SOAP_FMAC2 soap_inint(struct soap*, const char *tag, int *p, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_inbyte(struct soap*, const char *tag, char *p, const char *, int); -SOAP_FMAC1 long* SOAP_FMAC2 soap_inlong(struct soap*, const char *tag, long *p, const char *, int); -SOAP_FMAC1 LONG64* SOAP_FMAC2 soap_inLONG64(struct soap*, const char *tag, LONG64 *p, const char *, int); -SOAP_FMAC1 short* SOAP_FMAC2 soap_inshort(struct soap*, const char *tag, short *p, const char *, int); -SOAP_FMAC1 float* SOAP_FMAC2 soap_infloat(struct soap*, const char *tag, float *p, const char *, int); -SOAP_FMAC1 double* SOAP_FMAC2 soap_indouble(struct soap*, const char *tag, double *p, const char *, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_inunsignedByte(struct soap*, const char *tag, unsigned char *p, const char *, int); -SOAP_FMAC1 unsigned short* SOAP_FMAC2 soap_inunsignedShort(struct soap*, const char *tag, unsigned short *p, const char *, int); -SOAP_FMAC1 unsigned int* SOAP_FMAC2 soap_inunsignedInt(struct soap*, const char *tag, unsigned int *p, const char *, int); -SOAP_FMAC1 unsigned long* SOAP_FMAC2 soap_inunsignedLong(struct soap*, const char *tag, unsigned long *p, const char *, int); -SOAP_FMAC1 ULONG64* SOAP_FMAC2 soap_inULONG64(struct soap*, const char *tag, ULONG64 *p, const char *, int); -SOAP_FMAC1 char** SOAP_FMAC2 soap_instring(struct soap*, const char *tag, char **p, const char *, int, int, long, long); -SOAP_FMAC1 char** SOAP_FMAC2 soap_inliteral(struct soap*, const char *tag, char **p); - -#ifndef WITH_LEAN -SOAP_FMAC1 time_t* SOAP_FMAC2 soap_indateTime(struct soap*, const char *tag, time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwstring(struct soap*, const char *tag, wchar_t **p, const char *, int, long, long); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwliteral(struct soap*, const char *tag, wchar_t **p); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_outbyte(struct soap*, const char *tag, int id, const char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outshort(struct soap*, const char *tag, int id, const short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outint(struct soap*, const char *tag, int id, const int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outlong(struct soap*, const char *tag, int id, const long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outLONG64(struct soap*, const char *tag, int id, const LONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outfloat(struct soap*, const char *tag, int id, const float *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdouble(struct soap*, const char *tag, int id, const double *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedByte(struct soap*, const char *tag, int id, const unsigned char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedShort(struct soap*, const char *tag, int id, const unsigned short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedInt(struct soap*, const char *tag, int id, const unsigned int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedLong(struct soap*, const char *tag, int id, const unsigned long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outULONG64(struct soap*, const char *tag, int id, const ULONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outstring(struct soap*, const char *tag, int id, char *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outliteral(struct soap*, const char *tag, char *const*p, const char *type); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_outdateTime(struct soap*, const char *tag, int id, const time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_outwstring(struct soap*, const char *tag, int id, wchar_t *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwliteral(struct soap*, const char *tag, wchar_t *const*p, const char *type); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_attachment(struct soap *, const char*, int, const void*, const struct soap_array*, const char*, const char*, const char*, int, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, long); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_tell(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_dime_option(struct soap*, unsigned short, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmimehdr(struct soap*, struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_mime(struct soap*, const char *boundary, const char *start); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_mime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_dime_attachment(struct soap*, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_mime_attachment(struct soap*, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description); -SOAP_FMAC1 void SOAP_FMAC2 soap_post_check_mime_attachments(struct soap *soap); -SOAP_FMAC1 int SOAP_FMAC2 soap_check_mime_attachments(struct soap *soap); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_get_mime_attachment(struct soap *soap, void *handle); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_cid(struct soap*, const char*, const char*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_register_plugin_arg(struct soap*, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_lookup_plugin(struct soap*, const char*); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_attr_value(struct soap *soap, const char *name, int flag); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_attr(struct soap *soap, const char *name, const char *value); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_attr(struct soap *soap); - -#ifdef WITH_COOKIES -SOAP_FMAC1 void SOAP_FMAC2 soap_getcookies(struct soap *soap, const char *val); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_encode_cookie(const char*, char*, size_t); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_set_cookie(struct soap*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_env_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern time_t SOAP_FMAC2 soap_cookie_expire(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_expire(struct soap*, const char*, long, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_clr_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_clr_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_getenv_cookies(struct soap*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_copy_cookies(struct soap*, struct soap*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_free_cookies(struct soap*); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif - diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.c b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.c deleted file mode 100644 index efff89b..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.c +++ /dev/null @@ -1,14414 +0,0 @@ -/* - -stdsoap2.c[pp] 2.7.9d - -gSOAP runtime - -gSOAP XML Web services tools -Copyright (C) 2000-2007, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under one of the following licenses: -GPL, the gSOAP public license, or Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems Inc., for the following additions under gSOAP public license: - - vxWorks compatible (#define VXWORKS) --------------------------------------------------------------------------------- -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-2007, 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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- - -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. - -*/ - -#ifdef AS400 -# pragma convert(819) /* EBCDIC to ASCII */ -#endif - -#include "stdsoap2.h" - -#ifdef WIN32 -# pragma comment(lib, "wsock32.lib") -#endif - -#ifdef __cplusplus -SOAP_SOURCE_STAMP("@(#) stdsoap2.cpp ver 2.7.9d 2007-02-19 12:00:00 GMT") -extern "C" { -#else -SOAP_SOURCE_STAMP("@(#) stdsoap2.c ver 2.7.9d 2007-02-19 12:00:00 GMT") -#endif - -/* 8bit character representing unknown/nonrepresentable character data (e.g. not supported by current locale with multibyte support enabled) */ -#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_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) - -#ifdef WIN32 -#define soap_hash_ptr(p) ((PtrToUlong(p) >> 3) & (SOAP_PTRHASH - 1)) -#else -#define soap_hash_ptr(p) ((size_t)(((unsigned long)(p) >> 3) & (SOAP_PTRHASH-1))) -#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 SOAP_MEM_DEBUG -static void soap_init_mht(struct soap*); -static void soap_free_mht(struct soap*); -static void soap_track_unlink(struct soap*, const void*); -#endif - -#ifndef PALM_2 -static int soap_set_error(struct soap*, const char*, const char*, const char*, const char*, int); -static int soap_copy_fault(struct soap*, const char*, const char*, const char*, const char*); -static int soap_getattrval(struct soap*, char*, size_t, soap_wchar); -#endif - -#ifndef PALM_1 -static soap_wchar soap_char(struct soap*); -static soap_wchar soap_get_pi(struct soap*); -static int soap_isxdigit(int); -static void *fplugin(struct soap*, const char*); -#ifndef WITH_NOIDREF -static void soap_update_ptrs(struct soap*, char*, char*, char*, char*); -static int soap_has_copies(struct soap*, const char*, 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*); -#endif -#endif - -#ifndef WITH_LEAN -static const char *soap_set_validation_fault(struct soap*, const char*, const char*); -static int soap_isnumeric(struct soap*, const char*); -static time_t soap_timegm(struct tm*); -static struct soap_nlist *soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized); -static void soap_pop_ns(struct soap *soap); -static void soap_utilize_ns(struct soap *soap, const char *tag, size_t n); -#endif - -#ifndef WITH_LEANER -#ifndef PALM_1 -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*); -static void soap_resolve_attachment(struct soap*, struct soap_multipart*); -#endif -#endif - -#ifdef WITH_GZIP -static int soap_getgziphdr(struct soap*); -#endif - -#ifdef WITH_OPENSSL -static int ssl_init_done = 0; -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 - -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#ifndef PALM_1 -static const char *soap_decode(char*, size_t, const char*, const char*); -#endif -#endif - -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static soap_wchar soap_getchunkchar(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*); -#endif -#endif - -#ifndef WITH_NOIO -#ifndef PALM_1 -static int fsend(struct soap*, const char*, size_t); -static size_t frecv(struct soap*, char*, size_t); -static int tcp_init(struct soap*); -static const char *tcp_error(struct soap*); -#ifndef WITH_LEAN -static size_t frecv_stop(struct soap*, char*, size_t); -#endif -#ifndef WITH_IPV6 -static int tcp_gethost(struct soap*, const char *addr, struct in_addr *inaddr); -#endif -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 const char *soap_strerror(struct soap*); -#endif -#endif - -#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 - -#ifndef WITH_LEAN -static const char soap_indent[11] = "\n\t\t\t\t\t\t\t\t\t"; -/* Alternative indentation form for SOAP_XML_INDENT: -static const char soap_indent[21] = "\n "; -*/ -#endif - -#ifndef SOAP_CANARY -# define SOAP_CANARY (0xC0DE) -#endif - -static const char soap_padding[4] = "\0\0\0"; -#define SOAP_STR_PADDING (soap_padding) -#define SOAP_STR_EOS (soap_padding) -#define SOAP_NON_NULL (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_NOIO -#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 -#endif - -#ifndef WITH_NOHTTP -#ifndef WITH_LEAN -static const struct soap_code_map h_http_error_codes[] = -{ { 200, "OK" }, - { 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 -#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 WITH_NOIO -#ifndef PALM_1 -static int -fsend(struct soap *soap, const char *s, size_t n) -{ register int nwritten, err; -#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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); - for (;;) - { register int r; -#ifdef WITH_OPENSSL - if (soap->ssl) - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, &fd, &fd, &timeout); - else -#endif - r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); - if (r > 0) - break; - if (!r) - { soap->errnum = 0; - return SOAP_EOF; - } - err = soap_socket_errno(soap->socket); - if (err != SOAP_EINTR && err != SOAP_EAGAIN) - { soap->errnum = err; - return SOAP_EOF; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - nwritten = SSL_write(soap->ssl, s, n); - else if (soap->bio) - nwritten = BIO_write(soap->bio, s, n); - else -#endif -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - { if (soap->peerlen) - nwritten = sendto((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, soap->peerlen); - else - nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); - /* retry and back-off algorithm */ - /* TODO: this is not very clear from specs so verify and limit conditions under which we should loop (e.g. ENOBUFS) */ - if (nwritten < 0) - { struct timeval timeout; - fd_set fd; - int udp_repeat; - int udp_delay; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - if ((soap->connect_flags & SO_BROADCAST)) - udp_repeat = 3; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */ - else - udp_repeat = 1; /* SOAP-over-UDP UNICAST_UDP_REPEAT - 1 */ - udp_delay = (soap_random % 201) + 50; /* UDP_MIN_DELAY .. UDP_MAX_DELAY */ - do - { timeout.tv_sec = 0; - timeout.tv_usec = 1000 * udp_delay; /* ms */ - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); - select((SOAP_SOCKET)(soap->socket + 1), NULL, NULL, &fd, &timeout); - if (soap->peerlen) - nwritten = sendto((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, soap->peerlen); - else - nwritten = send((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); - udp_delay <<= 1; - if (udp_delay > 500) /* UDP_UPPER_DELAY */ - udp_delay = 500; - } - while (nwritten < 0 && --udp_repeat > 0); - } - } - else -#endif -#if !defined(PALM) && !defined(AS400) - 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) - { register int r; -#ifdef WITH_OPENSSL - if (soap->ssl && (r = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && r != SSL_ERROR_WANT_READ && r != SSL_ERROR_WANT_WRITE) - return SOAP_EOF; -#endif - err = soap_socket_errno(soap->socket); - if (err == SOAP_EWOULDBLOCK || err == SOAP_EAGAIN) - { -#ifndef WITH_LEAN - struct timeval timeout; - fd_set fd; - if (soap->send_timeout > 0) - { timeout.tv_sec = soap->send_timeout; - timeout.tv_usec = 0; - } - else if (soap->send_timeout < 0) - { timeout.tv_sec = -soap->send_timeout/1000000; - timeout.tv_usec = -soap->send_timeout%1000000; - } - else - { timeout.tv_sec = 0; - timeout.tv_usec = 10000; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); -#ifdef WITH_OPENSSL - if (soap->ssl && r == SSL_ERROR_WANT_READ) - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); - else - r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); -#else - r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); -#endif - if (r < 0 && (r = soap_socket_errno(soap->socket)) != SOAP_EINTR) - { soap->errnum = r; - return SOAP_EOF; - } -#endif - } - else if (err && err != SOAP_EINTR) - { soap->errnum = err; - 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 -#ifdef VXWORKS -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - nwritten = (httpBlockPut(soap->rpmreqid, s, n) == 0) ? n : -1; - else -#endif - nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w")); -#else - nwritten = write((SOAP_SOCKET)soap->sendfd, s, n); -#endif -#endif -#endif - if (nwritten <= 0) - { err = soap_errno; - if (err && err != SOAP_EINTR && err != SOAP_EWOULDBLOCK && err != SOAP_EAGAIN) - { soap->errnum = err; - 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_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; -#ifndef WITH_LEANER - if (soap->fpreparesend && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - 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_flush(struct soap *soap) -{ register int n = soap->bufidx; - if (n) - { soap->bufidx = 0; -#ifdef WITH_ZLIB - if (soap->mode & SOAP_ENC_ZLIB) - { soap->d_stream.next_in = (Byte*)soap->buf; - soap->d_stream.avail_in = (unsigned int)n; -#ifdef WITH_GZIP - soap->z_crc = crc32(soap->z_crc, (Byte*)soap->buf, (unsigned int)n); -#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 - return soap_flush_raw(soap, soap->buf, n); - } - return SOAP_OK; -} -#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); -#ifndef WITH_LEANER - if (soap->fpreparesend) - return soap->error = soap->fpreparesend(soap, s, n); -#endif - return SOAP_OK; - } -#ifndef WITH_LEANER - 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); -#endif - return soap->error = soap->fsend(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 WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static size_t -frecv(struct soap *soap, char *s, size_t n) -{ register int r; -#ifdef PALM - register int timeouts = 10; -#endif - 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 (;;) - { -#ifdef WITH_OPENSSL - register int err = 0; -#endif -#ifndef WITH_LEAN - if (soap->recv_timeout) - { struct timeval timeout; - fd_set fd; - 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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return 0; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); - for (;;) - { -#ifdef WITH_OPENSSL - if (soap->ssl) - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, &fd, &fd, &timeout); - else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#endif - if (r > 0) - break; - if (!r) - { soap->errnum = 0; - return 0; - } - r = soap_socket_errno(soap->socket); - if (r != SOAP_EINTR && r != SOAP_EAGAIN) - { soap->errnum = r; - return 0; - } - } - } -#endif -#ifdef WITH_OPENSSL - if (soap->ssl) - { r = SSL_read(soap->ssl, s, n); - if (r > 0) - return (size_t)r; - err = SSL_get_error(soap->ssl, r); - if (err != SSL_ERROR_NONE && err != SSL_ERROR_WANT_READ && err != SSL_ERROR_WANT_WRITE) - return 0; - } - else if (soap->bio) - { r = BIO_read(soap->bio, s, n); - if (r > 0) - return (size_t)r; - return 0; - } - else -#endif - { -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - { SOAP_SOCKLEN_T k = (SOAP_SOCKLEN_T)sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - r = recvfrom((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags, (struct sockaddr*)&soap->peer, &k); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - soap->peerlen = (size_t)k; -#ifndef WITH_IPV6 - soap->ip = ntohl(soap->peer.sin_addr.s_addr); -#endif - } - else -#endif - r = recv((SOAP_SOCKET)soap->socket, s, n, soap->socket_flags); -#ifdef PALM - /* CycleSyncDisplay(curStatusMsg); */ -#endif - if (r >= 0) - return (size_t)r; - r = soap_socket_errno(soap->socket); - if (r != SOAP_EINTR && r != SOAP_EAGAIN && r != SOAP_EWOULDBLOCK) - { soap->errnum = r; - return 0; - } - } -#ifndef WITH_LEAN - { struct timeval timeout; - fd_set fd; - if (soap->recv_timeout > 0) - { timeout.tv_sec = soap->recv_timeout; - timeout.tv_usec = 0; - } - else if (soap->recv_timeout < 0) - { timeout.tv_sec = -soap->recv_timeout/1000000; - timeout.tv_usec = -soap->recv_timeout%1000000; - } - else - { timeout.tv_sec = 0; - timeout.tv_usec = 10000; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return 0; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); -#ifdef WITH_OPENSSL - if (soap->ssl && err == SSL_ERROR_WANT_WRITE) - r = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); - else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#else - r = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); -#endif - if (r < 0 && (r = soap_socket_errno(soap->socket)) != SOAP_EINTR) - { soap->errnum = r; - return 0; - } - if (!r && soap->recv_timeout) - { soap->errnum = 0; - return 0; - } - } -#endif -#ifdef PALM - r = soap_socket_errno(soap->socket); - if (r != SOAP_EINTR && timeouts-- <= 0) - { soap->errnum = r; - return 0; - } -#endif - } - } -#ifdef WITH_FASTCGI - return fread(s, 1, n, stdin); -#else -#ifdef UNDER_CE - return fread(s, 1, n, soap->recvfd); -#else -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - r = httpBlockRead(soap->rpmreqid, s, n); - else -#endif - r = read((SOAP_SOCKET)soap->recvfd, s, n); - if (r >= 0) - return (size_t)r; - soap->errnum = soap_errno; - return 0; -#endif -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef WITH_NOIO -#ifndef PALM_1 -static size_t -frecv_stop(struct soap *soap, char *s, size_t n) -{ return 0; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 from socket %d\n", (unsigned int)soap->buflen, soap->socket)); - DBGMSG(RECV, soap->buf, soap->buflen); - if (soap->buflen) - return soap->buf[soap->bufidx++]; - return EOF; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -static int -soap_isxdigit(int c) -{ return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'); -} -#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; - ret = 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)ret); - 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 (ret) - { soap->count += ret; - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n")); - DBGMSG(RECV, soap->buf, ret); - 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; - soap->error = SOAP_ZLIB_ERROR; - 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; - } - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- compressed ----\n")); - } -#endif -#ifndef WITH_NOHTTP - 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 (chunked) from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - soap->bufidx = 0; - if (!ret) - return soap->ahead = EOF; - } - else - soap->bufidx = soap->buflen; - soap->buflen = soap->chunkbuflen; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Getting chunk size (idx=%u len=%u)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen)); - while (!soap_isxdigit((int)(c = soap_getchunkchar(soap)))) - { if ((int)c == EOF) - return soap->ahead = 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 soap->ahead = 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 soap->ahead = EOF; - } - soap->buflen = soap->bufidx + soap->chunksize; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Moving buf len to idx=%u len=%u (%s)\n", (unsigned int)soap->bufidx, (unsigned int)soap->buflen, 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 (%u bytes left)\n", (unsigned int)(soap->buflen - soap->bufidx))); - } - else if (soap->chunkbuflen) - soap->chunksize = 0; - ret = soap->buflen - soap->bufidx; - if (!ret) - goto chunk_again; - } - } - else -#endif - { soap->bufidx = 0; - soap->buflen = ret = soap->frecv(soap, soap->buf, SOAP_BUFLEN); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Read %u bytes from socket %d\n", (unsigned int)ret, soap->socket)); - DBGMSG(RECV, soap->buf, ret); - } -#ifndef WITH_LEANER - if (soap->fpreparerecv && (soap->error = soap->fpreparerecv(soap, soap->buf, ret))) - return soap->error; -#endif -#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; - } - DBGLOG(RECV, SOAP_MESSAGE(fdebug, "\n---- decompressed ----\n")); - DBGMSG(RECV, soap->buf, ret); - } - 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; - soap->error = SOAP_ZLIB_ERROR; - 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; - c = soap->ahead; - if (c) - { if (c != EOF) - 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 *code_map, const char *str) -{ if (code_map && str) - { while (code_map->string) - { if (!strcmp(str, code_map->string)) /* case sensitive */ - return code_map; - code_map++; - } - } - return NULL; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -long -SOAP_FMAC2 -soap_code_int(const struct soap_code_map *code_map, const char *str, long other) -{ if (code_map) - { while (code_map->string) - { if (!soap_tag_cmp(str, code_map->string)) /* case insensitive */ - return code_map->code; - code_map++; - } - } - return other; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_code_str(const struct soap_code_map *code_map, long code) -{ if (!code_map) - return NULL; - while (code_map->code != code && code_map->string) - code_map++; - return code_map->string; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -long -SOAP_FMAC2 -soap_code_bits(const struct soap_code_map *code_map, const char *str) -{ register long bits = 0; - if (code_map) - { while (str && *str) - { const struct soap_code_map *p; - for (p = code_map; p->string; p++) - { register size_t n = strlen(p->string); - if (!strncmp(p->string, str, n) && soap_blank(str[n])) - { bits |= p->code; - str += n; - while (*str > 0 && *str <= 32) - str++; - break; - } - } - if (!p->string) - return 0; - } - } - return bits; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_code_list(struct soap *soap, const struct soap_code_map *code_map, long code) -{ register char *t = soap->tmpbuf; - if (code_map) - { while (code_map->string) - { if (code_map->code & code) - { register const char *s = code_map->string; - if (t != soap->tmpbuf) - *t++ = ' '; - while (*s && t < soap->tmpbuf + sizeof(soap->tmpbuf) - 1) - *t++ = *s++; - if (t == soap->tmpbuf + sizeof(soap->tmpbuf) - 1) - break; - } - code_map++; - } - } - *t = '\0'; - return soap->tmpbuf; -} -#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_code_int(html_entity_codes, tmp, SOAP_UNKNOWN_CHAR); -#else - return SOAP_UNKNOWN_CHAR; /* use this to represent unknown code */ -#endif -} -#endif - -/******************************************************************************/ -#ifdef WITH_LEAN -#ifndef PALM_1 -soap_wchar -soap_get0(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx]; -} -#endif -#endif - -/******************************************************************************/ -#ifdef WITH_LEAN -#ifndef PALM_1 -soap_wchar -soap_get1(struct soap *soap) -{ if (soap->bufidx >= soap->buflen && soap_recv(soap)) - return EOF; - return (unsigned char)soap->buf[soap->bufidx++]; -} -#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) - { if ((int)c != EOF) - soap->ahead = 0; - } - else - c = soap_get1(soap); - while ((int)c != EOF) - { if (soap->cdata) - { if (c == ']') - { c = soap_get1(soap); - if (c == ']') - { c = soap_get0(soap); - if (c == '>') - { soap->cdata = 0; - soap_get1(soap); - c = soap_get1(soap); - } - else - { soap_unget(soap, ']'); - return ']'; - } - } - else - { soap_revget1(soap); - return ']'; - } - } - else - return c; - } - switch (c) - { case '<': - do c = soap_get1(soap); - while (soap_blank(c)); - if (c == '!' || c == '?' || c == '%') - { register int k = 1; - 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); - } - } - else if (c == '?') - c = soap_get_pi(soap); - while ((int)c != EOF) - { if (c == '<') - k++; - else if (c == '>') - { if (--k <= 0) - break; - } - 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 -static soap_wchar -soap_get_pi(struct soap *soap) -{ char buf[64]; - register char *s = buf; - register int i = sizeof(buf); - register soap_wchar c = soap_getchar(soap); - /* This is a quick way to parse XML PI and we could use a callback instead to - * enable applications to intercept processing instructions */ - while ((int)c != EOF && c != '?') - { if (--i > 0) - { if (soap_blank(c)) - c = ' '; - *s++ = (char)c; - } - c = soap_getchar(soap); - } - *s = '\0'; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "XML PI \n", buf)); - if (!strncmp(buf, "xml ", 4)) - { s = strstr(buf, " encoding="); - if (s && s[10]) - { if (!soap_tag_cmp(s + 11, "iso-8859-1*") - || !soap_tag_cmp(s + 11, "latin1*")) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to latin1 encoding\n")); - soap->mode |= SOAP_ENC_LATIN; - } - else if (!soap_tag_cmp(s + 11, "utf-8*")) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Switching to utf-8 encoding\n")); - soap->mode &= ~SOAP_ENC_LATIN; - } - } - } - if ((int)c != EOF) - c = soap_getchar(soap); - 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 < 0x80 && c >= 0x20) - { *tmp = (char)c; - return soap_send_raw(soap, tmp, 1); - } -#ifndef WITH_LEAN - if (c >= 0x80 && (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->ahead; - if (c > 0xFF) - { soap->ahead = 0; - return c; - } -again: - c = soap_get(soap); - if (c < 0x80 || (soap->mode & SOAP_ENC_LATIN)) - return c; - c1 = soap_get1(soap); - if (c1 < 0x80) - { soap_revget1(soap); /* doesn't look like this is UTF8 */ - return c; - } - c1 &= 0x3F; - if (c < 0xE0) - return ((soap_wchar)(c & 0x1F) << 6) | c1; - c2 = (soap_wchar)soap_get1(soap) & 0x3F; - if (c == 0xEF && c1 == 0x3B && c2 == 0x3F) /* ignore UTF-8 BOM */ - goto again; - 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) -{ char d[2]; - register int i; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!(soap->dom->data = soap_s2hex(soap, s, NULL, n))) - return soap->error; - return SOAP_OK; - } -#endif - 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_hex2s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#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, NULL, 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_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_string_in(soap, 0, -1, -1); - return (unsigned char*)soap_base642s(soap, soap->dom->data, NULL, 0, n); - } -#endif -#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 = soap->lablen - soap->labidx; - soap->labidx = 3 * (soap->lablen / 3); - if (!s) - return NULL; - for (i = 0; i < k - 2; 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) - { int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; - } - else if (!soap_blank(c + '+')) - { soap->error = SOAP_TYPE; - return NULL; - } - } 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) - { int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; - } - else if (!soap_blank(c)) - { soap->error = SOAP_TYPE; - return NULL; - } - } while (j < 4); - *s++ = (char)((m >> 16) & 0xFF); - *s++ = (char)((m >> 8) & 0xFF); - *s++ = (char)(m & 0xFF); - } - } -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_xop_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ /* Check MTOM xop:Include element (within hex/base64Binary) */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - int body = soap->body; /* should save type too? */ - if (!soap_peek_element(soap)) - { if (!soap_element_begin_in(soap, "xop:Include", 0, NULL) && *soap->href) - { if (soap_dime_forward(soap, ptr, size, id, type, options)) - return soap->error; - } - if (soap->body && soap_element_end_in(soap, NULL)) - return soap->error; - } - soap->body = body; - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_dime_forward(struct soap *soap, unsigned char **ptr, int *size, char **id, char **type, char **options) -{ struct soap_xlist *xp = (struct soap_xlist*)SOAP_MALLOC(soap, sizeof(struct soap_xlist)); - *ptr = NULL; - *size = 0; - *id = soap_strdup(soap, soap->href); - *type = NULL; - *options = NULL; - if (!xp) - return soap->error = SOAP_EOM; - xp->next = soap->xlist; - xp->ptr = ptr; - xp->size = size; - xp->id = *id; - xp->type = type; - xp->options = options; - soap->xlist = xp; - return SOAP_OK; -} -#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(soap, 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(soap, 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(soap, p); -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_update_ptrs(struct soap *soap, char *start, char *end, char *p1, char *p2) -{ int i; - register struct soap_ilist *ip; - register struct soap_flist *fp; -#ifndef WITH_LEANER - register struct soap_xlist *xp; -#endif - 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 + (p1-p2))); - ip->ptr = (char*)ip->ptr + (p1-p2); - } - 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 + (p1-p2); - } - } - 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 + (p1-p2); - } - } - 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 + (p1-p2); - } - } - } - } -#ifndef WITH_LEANER - for (xp = soap->xlist; xp; xp = xp->next) - { if (xp->ptr && (char*)xp->ptr >= start && (char*)xp->ptr < end) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Update id='%s' %p -> %p\n", xp->id?xp->id:"", xp->ptr, (char*)xp->ptr + (p1-p2))); - xp->ptr = (unsigned char**)((char*)xp->ptr + (p1-p2)); - xp->size = (int*)((char*)xp->size + (p1-p2)); - xp->type = (char**)((char*)xp->type + (p1-p2)); - xp->options = (char**)((char*)xp->options + (p1-p2)); - } - } -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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, fp->len, p, ip->size); - else - soap_fcopy(soap, ip->type, fp->type, fp->ptr, fp->len, p, ip->size); - ip->flist = fp->next; - SOAP_FREE(soap, 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 -#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(soap, 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(soap, p); - } - soap->blist = bp->next; - SOAP_FREE(soap, 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); -#ifndef WITH_NOIDREF - if (flag) - soap_update_ptrs(soap, q, q + n, s, q); -#endif - 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; - if (*attr1 == '[') - attr1++; - n = 1; - for (;;) - { 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; - } - if (!attr1) - break; - 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; - register short i = -1; - register size_t n, k; - n = strlen(id); - k = strlen(ns) + 1; - p = soap->local_namespaces; - if (p) - { for (i = 0; p->id; p++, i++) - { if (p->ns && !strcmp(ns, p->ns)) - { if (p->out) - { SOAP_FREE(soap, p->out); - p->out = NULL; - } - break; - } - if (p->out) - { if (!strcmp(ns, p->out)) - break; - } - else if (p->in) - { if (!soap_tag_cmp(ns, p->in)) - { if ((p->out = (char*)SOAP_MALLOC(soap, k))) - strcpy(p->out, ns); - break; - } - } - } - if (!p || !p->id) - i = -1; - } - if (i >= 0) - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k); - if (!np) - return soap->error = SOAP_EOM; - np->next = soap->nlist; - soap->nlist = np; - np->level = soap->level; - np->index = i; - strcpy(np->id, id); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push namespace binding (level=%u) '%s' '%s'\n", soap->level, id, ns)); - if (i < 0) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push NOT OK: no match found for '%s' in namespace mapping table (added to stack anyway)\n", ns)); - } - else - { np->ns = NULL; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Push OK ('%s' matches '%s' in namespace table)\n", id, p->id)); - } - 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)); - SOAP_FREE(soap, 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 - || (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->error = SOAP_SYNTAX_ERROR; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_current_namespace(struct soap *soap, const char *tag) -{ register struct soap_nlist *np; - register const char *s; - np = soap->nlist; - if (!(s = strchr(tag, ':'))) - { while (np && *np->id) /* find default namespace, if present */ - np = np->next; - } - else - { while (np && (strncmp(np->id, tag, s - tag) || np->id[s - tag])) - np = np->next; - if (!np) - soap->error = SOAP_NAMESPACE; - } - if (np) - { if (np->index >= 0) - return soap->namespaces[np->index].ns; - if (np->ns) - return soap_strdup(soap, np->ns); - } - return NULL; -} -#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 && !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; - register int err; - 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 && (err = 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)); - if (err == SOAP_NAMESPACE) - return SOAP_TAG_MISMATCH; - return err; - } - } - else if (SOAP_STRCMP(tag1, t + 1)) - return SOAP_TAG_MISMATCH; - else if (t != tag2 && (err = 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)); - if (err == SOAP_NAMESPACE) - return SOAP_TAG_MISMATCH; - return err; - } - 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 - -/******************************************************************************\ - * - * SSL - * -\******************************************************************************/ - -#ifdef WITH_OPENSSL -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_rand() -{ unsigned char buf[4]; - if (!ssl_init_done) - soap_ssl_init(); - RAND_pseudo_bytes(buf, 4); - return *(int*)buf; -} -#endif - -/******************************************************************************/ -#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; - soap->dhfile = dhfile; - soap->randfile = randfile; - soap->ssl_flags = flags | (dhfile == NULL ? SOAP_SSL_RSA : 0); - 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->ssl_flags = flags; - soap->randfile = randfile; - return soap->fsslauth(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_ssl_init() -{ /* Note: for MT systems, the main program MUST call soap_ssl_init() before any threads are started */ - if (!ssl_init_done) - { ssl_init_done = 1; - SSL_library_init(); -#ifndef WITH_LEAN - SSL_load_error_strings(); -#endif - if (!RAND_load_file("/dev/urandom", 1024)) - { char buf[1024]; - RAND_seed(buf, sizeof(buf)); - while (!RAND_status()) - { int r = rand(); - RAND_seed(&r, sizeof(int)); - } - } - } -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_ssl_error(struct soap *soap, int ret) -{ int err = SSL_get_error(soap->ssl, ret); - const char *msg = soap_code_str(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) -{ long flags; - int mode; - if (!ssl_init_done) - 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); - /* Alters the behavior of SSL read/write: - SSL_CTX_set_mode(soap->ctx, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_AUTO_RETRY); - */ - } - 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 directory", SOAP_SSL_ERROR); - if (soap->cafile && (soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION)) - SSL_CTX_set_client_CA_list(soap->ctx, SSL_load_client_CA_file(soap->cafile)); - } - 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); -/* This code assumes a typical scenario, see alternative code below */ - 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); - } -/* Suggested alternative approach to check cafile first before the key file: - 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 (!soap->cafile || !SSL_CTX_use_certificate_chain_file(soap->ctx, soap->cafile)) - { 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 or key file", SOAP_SSL_ERROR); - 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->ssl_flags & SOAP_SSL_RSA)) - { RSA *rsa = RSA_generate_key(1024, 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); - } - flags = (SSL_OP_ALL | SSL_OP_NO_SSLv2); - if ((soap->ssl_flags & SOAP_SSLv3)) - flags |= SSL_OP_NO_TLSv1; - if ((soap->ssl_flags & SOAP_TLSv1)) - flags |= SSL_OP_NO_SSLv3; - SSL_CTX_set_options(soap->ctx, flags); - if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION)) - mode = (SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT); - else if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION)) - mode = SSL_VERIFY_PEER; - else - mode = SSL_VERIFY_NONE; - SSL_CTX_set_verify(soap->ctx, mode, 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 or warning 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 - /* Note: return 1 to 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) -{ BIO *bio; - int timeouts, r, s; - 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->ctx && (soap->error = soap->fsslauth(soap))) - return SOAP_INVALID_SOCKET; - 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; - /* Set SSL sockets to non-blocking */ -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)soap->socket, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)&nonblocking); - } -#else - fcntl((SOAP_SOCKET)soap->socket, F_SETFL, fcntl((SOAP_SOCKET)soap->socket, F_GETFL)|O_NONBLOCK); -#endif - bio = BIO_new_socket((SOAP_SOCKET)soap->socket, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, bio); - timeouts = 100; /* 10 sec retries, 100 times 0.1 sec */ - 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; - timeout.tv_sec = 0; - timeout.tv_usec = 100000; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->socket, &fd); - if (err == SSL_ERROR_WANT_READ) - s = select((SOAP_SOCKET)(soap->socket + 1), &fd, NULL, &fd, &timeout); - else - s = select((SOAP_SOCKET)(soap->socket + 1), NULL, &fd, &fd, &timeout); - if (s < 0 && (s = soap_socket_errno(soap->socket)) != SOAP_EINTR) - { soap->errnum = s; - break; - } - } - else - { soap->errnum = err; - break; - } - if (timeouts-- <= 0) - break; - } - if (r <= 0) - { soap_set_receiver_error(soap, soap_ssl_error(soap, r), "SSL_accept() failed in soap_ssl_accept()", SOAP_SSL_ERROR); - soap_closesock(soap); - return SOAP_SSL_ERROR; - } - if ((soap->ssl_flags & SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION)) - { 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 WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_done(struct soap *soap) -{ -#ifdef SOAP_DEBUG - int i; -#endif - if (soap_check_state(soap)) - return; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Done with context\n")); - soap_free_temp(soap); - while (soap->clist) - { struct soap_clist *p = soap->clist->next; - SOAP_FREE(soap, 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->state == SOAP_INIT) - soap->plugins->fdelete(soap, soap->plugins); - SOAP_FREE(soap, soap->plugins); - soap->plugins = p; - } - soap->fplugin = fplugin; - soap->fmalloc = NULL; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif - soap->fheader = NULL; -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; -#endif - soap->fseterror = NULL; - soap->fignore = NULL; - soap->fserveloop = NULL; -#ifdef WITH_OPENSSL - if (soap->session) - { SSL_SESSION_free(soap->session); - soap->session = NULL; - } -#endif - if (soap->state == SOAP_INIT) - { 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 - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free logfiles\n")); - for (i = 0; i < SOAP_MAXLOGS; i++) - { if (soap->logfile[i]) - { SOAP_FREE(soap, (void*)soap->logfile[i]); - soap->logfile[i] = NULL; - } - soap_close_logfile(soap, i); - } - soap_free_mht(soap); - soap->state = 0; -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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_code_str(h_error_codes, soap->errnum); - if (!msg) -#endif - { sprintf(soap->msgbuf, "TCP/UDP IP error %d", soap->errnum); - msg = soap->msgbuf; - } - } - } - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static const char* -http_error(struct soap *soap, int status) -{ register const char *msg = SOAP_STR_EOS; -#ifndef WITH_LEAN - msg = soap_code_str(h_http_error_codes, status); - if (!msg) - msg = SOAP_STR_EOS; -#endif - return msg; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_IPV6 -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_gethost(struct soap *soap, const char *addr, struct in_addr *inaddr) -{ soap_int32 iadd = -1; - struct hostent hostent, *host = &hostent; -#ifdef VXWORKS - int hostint; - /* inet_addr(), and hostGetByName() expect "char *"; addr is a "const char *". */ - iadd = inet_addr((char*)addr); -#else -#if defined(_AIXVERSION_431) || defined(TRU64) - struct hostent_data ht_data; -#endif -#ifdef AS400 - iadd = inet_addr((void*)addr); -#else - iadd = inet_addr(addr); -#endif -#endif - if (iadd != -1) - { memcpy(inaddr, &iadd, sizeof(iadd)); - return SOAP_OK; - } -#if defined(__GLIBC__) || defined(FREEBSD) || defined(__FreeBSD__) - 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); -#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((char*)addr); - if (hostint == ERROR) - { host = NULL; - soap->errnum = soap_errno; - } -#else -#ifdef AS400 - if (!(host = gethostbyname((void*)addr))) - soap->errnum = h_errno; -#else - if (!(host = gethostbyname(addr))) - soap->errnum = h_errno; -#endif -#endif - if (!host) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Host name not found\n")); - return SOAP_ERR; - } -#ifdef VXWORKS - inaddr->s_addr = hostint; -#else - memcpy(inaddr, host->h_addr, host->h_length); -#endif - return SOAP_OK; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_connect(struct soap *soap, const char *endpoint, const char *host, int port) -{ -#ifdef WITH_IPV6 - struct addrinfo hints, *res, *ressave; -#endif - register int fd, err = 0; -#ifndef WITH_LEAN - int retry = 10; - 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->errnum = 0; - soap_set_sender_error(soap, tcp_error(soap), "TCP init failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->errmode = 0; -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - soap->errmode = 2; - if (soap->proxy_host) - err = getaddrinfo(soap->proxy_host, soap_int2s(soap, soap->proxy_port), &hints, &res); - else - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &res); - if (err) - { soap_set_sender_error(soap, gai_strerror(err), "getaddrinfo failed in tcp_connect()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - ressave = res; -again: - fd = (int)socket(res->ai_family, res->ai_socktype, res->ai_protocol); - soap->errmode = 0; -#else -again: -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - fd = (int)socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - fd = (int)socket(AF_INET, SOCK_STREAM, 0); -#endif - if (fd < 0) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "socket failed in tcp_connect()", SOAP_TCP_ERROR); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#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(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - } - else if (soap->connect_flags && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, soap->connect_flags, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - if (soap->keep_alive && setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && setsockopt((SOAP_SOCKET)fd, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#endif -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Opening socket %d to host='%s' port=%d\n", fd, host, port)); -#ifndef WITH_IPV6 - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (soap->proxy_host) - { if (soap->fresolve(soap, soap->proxy_host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get proxy host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)soap->proxy_port); - } - else - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_sender_error(soap, tcp_error(soap), "get host by name failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - soap->peer.sin_port = htons((short)port); - } - soap->errmode = 0; - if ((soap->omode & SOAP_IO_UDP)) - { -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return fd; - } -#endif -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&nonblocking)); /* modified to use fd */ - } -#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); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK); -#endif -#endif - for (;;) - { -#ifdef WITH_IPV6 - if (connect((SOAP_SOCKET)fd, res->ai_addr, res->ai_addrlen)) -#else - if (connect((SOAP_SOCKET)fd, (struct sockaddr*)&soap->peer, sizeof(soap->peer))) -#endif - { err = soap_socket_errno(fd); -#ifndef WITH_LEAN - if (err == SOAP_EADDRINUSE) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - if (retry-- > 0) - goto again; - } - else if (soap->connect_timeout && (err == SOAP_EINPROGRESS || err == SOAP_EWOULDBLOCK)) - { struct timeval timeout; - SOAP_SOCKLEN_T k; - 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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fds); - FD_SET((SOAP_SOCKET)fd, &fds); - for (;;) - { register 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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - r = soap_socket_errno(fd); - if (r != SOAP_EINTR) - { soap->errnum = r; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - } - k = (SOAP_SOCKLEN_T)sizeof(soap->errnum); - if (!getsockopt((SOAP_SOCKET)fd, SOL_SOCKET, SO_ERROR, (char*)&soap->errnum, &k) && !soap->errnum) /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ - break; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - if (!soap->errnum) - soap->errnum = soap_socket_errno(fd); - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } -#endif -#ifdef WITH_IPV6 - if (res->ai_next) - { res = res->ai_next; - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - goto again; - } -#endif - if (err && err != SOAP_EINTR) - { soap->errnum = err; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not connect to host\n")); - soap_set_sender_error(soap, tcp_error(soap), "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); -#ifdef WITH_IPV6 - freeaddrinfo(ressave); -#endif - return SOAP_INVALID_SOCKET; - } - } - else - break; - } -#ifdef WITH_IPV6 - soap->peerlen = 0; /* IPv6: already connected so use send() */ - freeaddrinfo(ressave); -#endif -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long blocking = 0; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &blocking); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)&~O_NONBLOCK); -#endif -#endif - soap->socket = fd; - soap->imode &= ~SOAP_ENC_SSL; - soap->omode &= ~SOAP_ENC_SSL; - if (!soap_tag_cmp(endpoint, "https:*")) - { -#ifdef WITH_OPENSSL - BIO *bio; - 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 */ - char *userid, *passwd; - char endp[sizeof(soap->endpoint)]; - soap->omode &= ~SOAP_ENC; /* mask IO and ENC */ - soap->omode |= SOAP_IO_BUFFER; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connecting to %s proxy server\n", soap->proxy_http_version)); - sprintf(soap->tmpbuf, "CONNECT %s:%d HTTP/%s", host, port, soap->proxy_http_version); - if (soap_begin_send(soap) - || (soap->error = soap->fposthdr(soap, soap->tmpbuf, NULL))) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } -#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))) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return soap->error; - } - } -#endif - if ((soap->error = soap->fposthdr(soap, NULL, NULL)) - || soap_flush(soap)) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->omode = k; - k = soap->imode; - soap->imode &= ~SOAP_ENC; /* mask IO and ENC */ - strcpy(endp, soap->endpoint); - userid = soap->userid; /* preserve */ - passwd = soap->passwd; /* preserve */ - if ((soap->error = soap->fparse(soap))) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - strcpy(soap->endpoint, endp); /* restore */ - soap->userid = userid; /* restore */ - soap->passwd = passwd; /* restore */ - soap->imode = k; /* restore */ - soap->count = n; /* restore */ - if (soap_begin_send(soap)) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - 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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - soap->ssl = SSL_new(soap->ctx); - if (!soap->ssl) - { soap->fclosesocket(soap, (SOAP_SOCKET)fd); - soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; - } - 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; - bio = BIO_new_socket((SOAP_SOCKET)fd, BIO_NOCLOSE); - SSL_set_bio(soap->ssl, bio, bio); - /* Connect timeout: set SSL sockets to non-blocking */ -#ifndef WITH_LEAN - if (soap->connect_timeout) -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&nonblocking)); - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK); -#endif -#endif - /* Try connecting until success or timeout */ - 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, soap_ssl_error(soap, r), "SSL connect failed in tcp_connect()", SOAP_SSL_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - 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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return SOAP_INVALID_SOCKET; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fds); - FD_SET((SOAP_SOCKET)fd, &fds); - for (;;) - { int r = select((SOAP_SOCKET)(fd + 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", "connect failed in tcp_connect()", SOAP_TCP_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - continue; - } - } - break; - } - /* Set SSL sockets to non-blocking */ -#ifndef WITH_LEAN -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)fd, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)fd, FIONBIO, (int)(&nonblocking)); - } -#else - fcntl((SOAP_SOCKET)fd, F_SETFL, fcntl((SOAP_SOCKET)fd, F_GETFL)|O_NONBLOCK); -#endif -#endif - /* Check server credentials when required */ - if ((soap->ssl_flags & SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION)) - { 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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - if (!(soap->ssl_flags & SOAP_SSL_SKIP_HOST_CHECK)) - { X509_NAME *subj; - int ext_count; - int ok = 0; - X509 *peer; - 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); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - ext_count = X509_get_ext_count(peer); - if (ext_count > 0) - { int i; - for (i = 0; i < ext_count; i++) - { X509_EXTENSION *ext = X509_get_ext(peer, i); - const char *ext_str = OBJ_nid2sn(OBJ_obj2nid(X509_EXTENSION_get_object(ext))); - if (ext_str && !strcmp(ext_str, "subjectAltName")) - { X509V3_EXT_METHOD *meth = X509V3_EXT_get(ext); - void *ext_data; - unsigned char *data; - STACK_OF(CONF_VALUE) *val; - int j; - if (!meth) - break; - data = ext->value->data; -#if (OPENSSL_VERSION_NUMBER > 0x00907000L) - if (meth->it) - ext_data = ASN1_item_d2i(NULL, &data, ext->value->length, ASN1_ITEM_ptr(meth->it)); - else - { /* OpenSSL not perfectly portable at this point (?): - Some compilers appear to prefer - meth->d2i(NULL, (const unsigned char**)&data, ... - or - meth->d2i(NULL, &data, ext->value->length); - */ - ext_data = meth->d2i(NULL, &data, ext->value->length); - } -#else - ext_data = meth->d2i(NULL, &data, ext->value->length); -#endif - val = meth->i2v(meth, ext_data, NULL); - for (j = 0; j < sk_CONF_VALUE_num(val); j++) - { CONF_VALUE *nval = sk_CONF_VALUE_value(val, j); - if (nval && !strcmp(nval->name, "DNS") && !strcmp(nval->value, host)) - { ok = 1; - break; - } - } - } - if (ok) - break; - } - } - if (!ok && (subj = X509_get_subject_name(peer))) - { int i = -1; - do - { ASN1_STRING *name; - i = X509_NAME_get_index_by_NID(subj, NID_commonName, i); - if (i == -1) - break; - name = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(subj, i)); - if (name && !soap_tag_cmp(host, (const char*)name)) - ok = 1; - else - { unsigned char *tmp = NULL; - ASN1_STRING_to_UTF8(&tmp, name); - if (tmp) - { if (!soap_tag_cmp(host, (const char*)tmp)) - ok = 1; - OPENSSL_free(tmp); - } - } - } while (!ok); - } - X509_free(peer); - if (!ok) - { soap_set_sender_error(soap, "SSL error", "SSL certificate host name mismatch in tcp_connect()", SOAP_SSL_ERROR); - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - return SOAP_INVALID_SOCKET; - } - } - } -#else - soap->fclosesocket(soap, (SOAP_SOCKET)fd); - soap->error = SOAP_SSL_ERROR; - return SOAP_INVALID_SOCKET; -#endif - } - return fd; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_bind(struct soap *soap, const char *host, int port, int backlog) -{ -#ifdef WITH_IPV6 - struct addrinfo *addrinfo = NULL; - struct addrinfo hints; - struct addrinfo res; - int err; -#endif -#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 SOAP_INVALID_SOCKET; - } -#ifdef WITH_IPV6 - memset((void*)&hints, 0, sizeof(hints)); - hints.ai_family = PF_UNSPEC; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - hints.ai_socktype = SOCK_DGRAM; - else -#endif - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - soap->errmode = 2; - err = getaddrinfo(host, soap_int2s(soap, port), &hints, &addrinfo); - if (addrinfo) - { res = *addrinfo; - soap->peer = *((struct sockaddr_storage*)addrinfo->ai_addr); - soap->peerlen = addrinfo->ai_addrlen; - res.ai_addr = (struct sockaddr*)&soap->peer; - res.ai_addrlen = soap->peerlen; - freeaddrinfo(addrinfo); - } - if (err) - { soap_set_receiver_error(soap, gai_strerror(err), "getaddrinfo failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - soap->master = socket(res.ai_family, res.ai_socktype, res.ai_protocol); -#else -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - soap->master = (int)socket(AF_INET, SOCK_DGRAM, 0); - else -#endif - soap->master = (int)socket(AF_INET, SOCK_STREAM, 0); -#endif - soap->errmode = 0; - if (!soap_valid_socket(soap->master)) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "socket failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - soap->socket = soap->master; -#endif -#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->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)soap->master, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && setsockopt((SOAP_SOCKET)soap->master, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->master); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif -#endif -#ifdef WITH_IPV6 - soap->errmode = 0; - if (bind((SOAP_SOCKET)soap->master, res.ai_addr, res.ai_addrlen)) - { soap->errnum = soap_socket_errno(soap->master); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n")); - soap_closesock(soap); - soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#else - soap->peerlen = sizeof(soap->peer); - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->peer.sin_family = AF_INET; - soap->errmode = 2; - if (host) - { if (soap->fresolve(soap, host, &soap->peer.sin_addr)) - { soap_set_receiver_error(soap, tcp_error(soap), "get host by name failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } - else - soap->peer.sin_addr.s_addr = htonl(INADDR_ANY); - soap->peer.sin_port = htons((short)port); - soap->errmode = 0; - if (bind((SOAP_SOCKET)soap->master, (struct sockaddr*)&soap->peer, soap->peerlen)) - { soap->errnum = soap_socket_errno(soap->master); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n")); - soap_closesock(soap); - soap_set_receiver_error(soap, tcp_error(soap), "bind failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -#endif - if (!(soap->omode & SOAP_IO_UDP) && listen((SOAP_SOCKET)soap->master, backlog)) - { soap->errnum = soap_socket_errno(soap->master); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not bind to host\n")); - soap_closesock(soap); - soap_set_receiver_error(soap, tcp_error(soap), "listen failed in soap_bind()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - return soap->master; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_poll(struct soap *soap) -{ -#ifndef WITH_LEAN - struct timeval timeout; - fd_set rfd, sfd, xfd; - int r; - timeout.tv_sec = 0; - timeout.tv_usec = 0; -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - return SOAP_FD_EXCEEDED; /* Hint: MUST increase FD_SETSIZE */ -#endif - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_ZERO(&xfd); - if (soap_valid_socket(soap->socket)) - { FD_SET((SOAP_SOCKET)soap->socket, &rfd); - FD_SET((SOAP_SOCKET)soap->socket, &sfd); - FD_SET((SOAP_SOCKET)soap->socket, &xfd); - r = select((SOAP_SOCKET)(soap->socket + 1), &rfd, &sfd, &xfd, &timeout); - if (r > 0 && FD_ISSET((SOAP_SOCKET)soap->socket, &xfd)) - r = -1; - } - else if (soap_valid_socket(soap->master)) - { FD_SET((SOAP_SOCKET)soap->master, &sfd); - r = select((SOAP_SOCKET)(soap->master + 1), NULL, &sfd, NULL, &timeout); - } - else - return SOAP_OK; - if (r > 0) - { -#ifdef WITH_OPENSSL - if (soap->imode & SOAP_ENC_SSL) - { - if (soap_valid_socket(soap->socket) - && FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - && (!FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - || SSL_peek(soap->ssl, soap->tmpbuf, 1) > 0)) - return SOAP_OK; - } - else -#endif - if (soap_valid_socket(soap->socket) - && FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - && (!FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - || recv((SOAP_SOCKET)soap->socket, soap->tmpbuf, 1, MSG_PEEK) > 0)) - return SOAP_OK; - } - else if (r < 0) - { soap->errnum = soap_socket_errno(soap->master); - if ((soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) && soap_socket_errno(soap->master) != SOAP_EINTR) - { 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 = 0; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Polling: other end down on socket=%d select=%d\n", soap->socket, r)); - return SOAP_EOF; -#else - return SOAP_OK; -#endif -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_accept(struct soap *soap, int s, struct sockaddr *a, int *n) -{ int fd; - fd = (int)accept((SOAP_SOCKET)s, a, (SOAP_SOCKLEN_T*)n); /* portability note: see SOAP_SOCKLEN_T definition in stdsoap2.h */ -#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 WITH_NOIO -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_accept(struct soap *soap) -{ int n = (int)sizeof(soap->peer); -#ifndef WITH_LEAN - int len = SOAP_BUFLEN; - int set = 1; -#endif - soap->error = SOAP_OK; -#ifdef WITH_UDP - if ((soap->omode & SOAP_IO_UDP)) - return soap->socket = soap->master; -#endif - memset((void*)&soap->peer, 0, sizeof(soap->peer)); - soap->socket = SOAP_INVALID_SOCKET; - soap->errmode = 0; - soap->keep_alive = 0; - if (soap_valid_socket(soap->master)) - { register int err; - 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; - } -#ifndef WIN32 - if ((int)soap->socket >= (int)FD_SETSIZE) - { soap->error = SOAP_FD_EXCEEDED; - return SOAP_INVALID_SOCKET; /* Hint: MUST increase FD_SETSIZE */ - } -#endif - FD_ZERO(&fd); - FD_SET((SOAP_SOCKET)soap->master, &fd); - for (;;) - { register int r = select((SOAP_SOCKET)(soap->master + 1), &fd, &fd, &fd, &timeout); - if (r > 0) - break; - if (!r) - { soap->errnum = 0; - soap_set_receiver_error(soap, "Timeout", "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - r = soap_socket_errno(soap->master); - if (r != SOAP_EINTR) - { soap->errnum = r; - soap_closesock(soap); - soap_set_sender_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } - } -#if defined(WIN32) - { u_long nonblocking = 1; - ioctlsocket((SOAP_SOCKET)soap->master, FIONBIO, &nonblocking); - } -#elif defined(VXWORKS) - { u_long nonblocking = 1; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&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); - } -#elif defined(VXWORKS) - { u_long blocking = 0; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&blocking)); - } -#else - fcntl((SOAP_SOCKET)soap->master, F_SETFL, fcntl((SOAP_SOCKET)soap->master, F_GETFL)&~O_NONBLOCK); -#endif -#endif - soap->socket = soap->faccept(soap, soap->master, (struct sockaddr*)&soap->peer, &n); - soap->peerlen = (size_t)n; - if (soap_valid_socket(soap->socket)) - { -#ifdef WITH_IPV6 -/* Use soap->host to store the numeric form of the remote host */ - getnameinfo((struct sockaddr*)&soap->peer, 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->peer and soap->host */ - soap->port = 0; /* info stored in soap->peer and soap->host */ -#else - soap->ip = ntohl(soap->peer.sin_addr.s_addr); - soap->port = (int)ntohs(soap->peer.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)); -#endif -#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->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_LINGER failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - else if (soap->accept_flags && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, soap->accept_flags, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) && setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_KEEPALIVE failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_SNDBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_SNDBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - if (setsockopt((SOAP_SOCKET)soap->socket, SOL_SOCKET, SO_RCVBUF, (char*)&len, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt SO_RCVBUF failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#ifdef TCP_NODELAY - if (!(soap->omode & SOAP_IO_UDP) && setsockopt((SOAP_SOCKET)soap->socket, IPPROTO_TCP, TCP_NODELAY, (char*)&set, sizeof(int))) - { soap->errnum = soap_socket_errno(soap->socket); - soap_set_receiver_error(soap, tcp_error(soap), "setsockopt TCP_NODELAY failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } -#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); -#elif defined(VXWORKS) - u_long blocking = 0; - ioctl((SOAP_SOCKET)soap->master, FIONBIO, (int)(&blocking)); - ioctl((SOAP_SOCKET)soap->socket, FIONBIO, (int)(&blocking)); -#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 - } - soap->keep_alive = (((soap->imode | soap->omode) & SOAP_IO_KEEPALIVE) != 0); - return soap->socket; - } - err = soap_socket_errno(soap->socket); - if (err != 0 && err != SOAP_EINTR && err != SOAP_EAGAIN) - { DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Accept failed from %s\n", soap->host)); - soap->errnum = err; - soap_set_receiver_error(soap, tcp_error(soap), "accept failed in soap_accept()", SOAP_TCP_ERROR); - soap_closesock(soap); - return SOAP_INVALID_SOCKET; - } - } - } - else - { soap->errnum = 0; - soap_set_receiver_error(soap, tcp_error(soap), "no master socket in soap_accept()", SOAP_TCP_ERROR); - return SOAP_INVALID_SOCKET; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#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); - soap->session = NULL; - } - 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 == 0) - { if (soap_valid_socket(soap->socket)) - { struct timeval timeout; - fd_set fd; - if (soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1)) - { /* - wait up to 10 seconds for close_notify to be sent by peer (if peer not - present, this avoids calling SSL_shutdown() which has a lengthy return - timeout) - */ -#ifndef WIN32 - if ((int)soap->socket < (int)FD_SETSIZE) - { -#endif - timeout.tv_sec = 10; - timeout.tv_usec = 0; - 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->socket) != SOAP_EINTR) - { soap->errnum = 0; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Connection lost...\n")); - soap->fclosesocket(soap, (SOAP_SOCKET)soap->socket); - soap->socket = SOAP_INVALID_SOCKET; - SSL_free(soap->ssl); - soap->ssl = NULL; - ERR_remove_state(0); - return SOAP_OK; - } -#ifndef WIN32 - } -#endif - } - } - r = SSL_shutdown(soap->ssl); - } - if (r != 1) - { s = ERR_get_error(); - if (s) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown failed: %d\n", SSL_get_error(soap->ssl, r))); - if (soap_valid_socket(soap->socket) && !(soap->omode & SOAP_IO_UDP)) - { soap->fclosesocket(soap, (SOAP_SOCKET)soap->socket); - soap->socket = SOAP_INVALID_SOCKET; - } - SSL_free(soap->ssl); - soap->ssl = NULL; - ERR_remove_state(0); - return SOAP_SSL_ERROR; - } - } - SSL_free(soap->ssl); - soap->ssl = NULL; - ERR_remove_state(0); - } -#endif - if (soap_valid_socket(soap->socket) && !(soap->omode & SOAP_IO_UDP)) - { 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 WITH_NOIO -#ifndef PALM_1 -static int -tcp_closesocket(struct soap *soap, SOAP_SOCKET fd) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Close socket %d\n", (int)fd)); - return soap_closesocket(fd); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static int -tcp_shutdownsocket(struct soap *soap, SOAP_SOCKET fd, int how) -{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Shutdown socket %d how=%d\n", (int)fd, 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; - if (status == SOAP_EOF || status == SOAP_TCP_ERROR || status == SOAP_SSL_ERROR || !soap->keep_alive) - { if (soap->fclose && (soap->error = soap->fclose(soap))) - return soap->error; - soap->keep_alive = 0; - } -#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 WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_init_pht(struct soap *soap) -{ register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing pointer hashtable\n")); - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new1(soap_mode mode) -{ return soap_new2(mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new() -{ return soap_new2(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -struct soap* -SOAP_FMAC2 -soap_new2(soap_mode imode, soap_mode omode) -{ struct soap *soap = (struct soap*)malloc(sizeof(struct soap)); - if (soap) - soap_init2(soap, imode, omode); - return soap; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_free(struct soap *soap) -{ soap_done(soap); - free(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_del(struct soap *soap) -{ free(soap); -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_1 -static void -soap_free_pht(struct soap *soap) -{ register struct soap_pblk *pb, *next; - register int i; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free pointer hashtable\n")); - for (pb = soap->pblk; pb; pb = next) - { next = pb->next; - SOAP_FREE(soap, pb); - } - soap->pblk = NULL; - soap->pidx = 0; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->pht[i] = NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 size_t h; - register struct soap_plist *pp; - if (!soap->pblk || soap->pidx >= SOAP_PTRBLK) - { register struct soap_pblk *pb = (struct soap_pblk*)SOAP_MALLOC(soap, sizeof(struct soap_pblk)); - if (!pb) - { soap->error = SOAP_EOM; - return 0; - } - pb->next = soap->pblk; - soap->pblk = pb; - soap->pidx = 0; - } - *ppp = pp = &soap->pblk->plist[soap->pidx++]; - 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=%d\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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_begin_count(struct soap *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)) -#ifndef WITH_LEANER - && !soap->fpreparesend -#endif - )) - soap->mode &= ~SOAP_IO_LENGTH; - else - soap->mode |= SOAP_IO_LENGTH; - } -#ifdef WITH_ZLIB - 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; - } -#endif - if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH)) - soap->mode |= SOAP_XML_TREE; -#ifndef WITH_LEANER - if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME)) - soap->mode |= SOAP_ENC_MIME; - else - soap->mode &= ~SOAP_ENC_MTOM; - 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_clr_attr(soap); - soap_set_local_namespaces(soap); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin count phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); -#ifndef WITH_LEANER - soap->dime.count = 0; /* count # of attachments */ - soap->dime.size = 0; /* accumulate total size of attachments */ - if (soap->fprepareinit && (soap->mode & SOAP_IO) != SOAP_IO_STORE) - return soap->error = soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_end_count(struct soap *soap) -{ -#ifndef WITH_LEANER - if (soap->fpreparefinal) - return soap->error = soap->fpreparefinal(soap); -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of count phase\n")); - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_begin_send(struct soap *soap) -{ soap->error = SOAP_OK; - soap->mode = soap->omode | (soap->mode & (SOAP_IO_LENGTH | SOAP_ENC_DIME)); -#ifdef WITH_ZLIB - 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; - } -#endif -#ifdef WITH_UDP - if ((soap->mode & SOAP_IO_UDP)) - { soap->mode |= SOAP_ENC_XML; - if (soap->count > SOAP_BUFLEN) - return soap->error = SOAP_UDP_ERROR; - } -#endif - if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket)) - { if (soap->count || (soap->mode & SOAP_IO_LENGTH) || (soap->mode & SOAP_ENC_XML)) - soap->mode |= SOAP_IO_BUFFER; - else - soap->mode |= SOAP_IO_STORE; - } - soap->mode &= ~SOAP_IO_LENGTH; - 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_MTOM) && (soap->mode & SOAP_ENC_DIME)) - { soap->mode |= SOAP_ENC_MIME; - soap->mode &= ~SOAP_ENC_DIME; - } - else - soap->mode &= ~SOAP_ENC_MTOM; - if (soap->mode & SOAP_ENC_MIME) - soap_select_mime_boundary(soap); -#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 -#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->idnum = 0; - soap->level = 0; - soap_clr_attr(soap); - soap_set_local_namespaces(soap); -#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=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count)); - soap->part = SOAP_BEGIN; -#ifndef WITH_LEANER - if (soap->fprepareinit && (soap->mode & SOAP_IO) == SOAP_IO_STORE) - soap->fprepareinit(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 || !a->__ptr) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 = NULL; - if (soap->mode & SOAP_XML_TREE) - return id; - 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_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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_attachment(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; - int i; - 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:"")); - i = soap_array_pointer_lookup(soap, p, a, n, t, &pp); - if (!i) - { i = soap_pointer_enter(soap, p, a, n, t, &pp); - if (!i) - { soap->error = SOAP_EOM; - return -1; - } - } - if (id <= 0) - id = i; - if (!aid) - { sprintf(soap->tmpbuf, soap->dime_id_format, id); - aid = soap_strdup(soap, soap->tmpbuf); - } - /* Add MTOM xop:Include element when necessary */ - /* TODO: this code to be obsoleted with new import/xop.h conventions */ - if ((soap->mode & SOAP_ENC_MTOM) && strcmp(tag, "xop:Include")) - { if (soap_element_begin_out(soap, tag, 0, type) - || soap_element_href(soap, "xop:Include", 0, "href", aid) - || soap_element_end_out(soap, tag)) - return soap->error; - } - else 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; - if (soap->mode & SOAP_ENC_MTOM) - content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, (char*)a->__ptr, a->__size); - else - content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, (char*)a->__ptr, a->__size); - if (!content) - { soap->error = SOAP_EOM; - return -1; - } - if (!strncmp(aid, "cid:", 4)) /* RFC 2111 */ - { if (soap->mode & SOAP_ENC_MTOM) - { char *s = (char*)soap_malloc(soap, strlen(aid) - 1); - if (s) - { *s = '<'; - strcpy(s + 1, aid + 4); - strcat(s, ">"); - content->id = s; - } - } - else - content->id = aid + 4; - } - else - content->id = aid; - content->type = atype; - content->options = aoptions; - content->encoding = SOAP_MIME_BINARY; - pp->mark1 = 3; - } - } - else - pp->mark2 = 3; - return -1; -} -#endif -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, fp); - } - p = ip->next; - SOAP_FREE(soap, ip); - } - soap->iht[i] = NULL; - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_2 -SOAP_FMAC1 -struct soap_ilist * -SOAP_FMAC2 -soap_lookup(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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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(soap, 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 -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_malloc(struct soap *soap, size_t n) -{ register char *p; - if (!n) - return (void*)SOAP_NON_NULL; - if (!soap) - return SOAP_MALLOC(soap, n); - if (soap->fmalloc) - p = (char*)soap->fmalloc(soap, n); - else - { n += sizeof(short); - n += (-(long)n) & (sizeof(void*)-1); /* align at 4-, 8- or 16-byte boundary */ - if (!(p = (char*)SOAP_MALLOC(soap, n + sizeof(void*) + sizeof(size_t)))) - { soap->error = SOAP_EOM; - return NULL; - } - /* set the canary to detect corruption */ - *(short*)(p + n - sizeof(short)) = (short)SOAP_CANARY; - /* keep chain of alloced cells for destruction */ - *(void**)(p + n) = soap->alist; - *(size_t*)(p + n + sizeof(void*)) = n; - soap->alist = p + n; - } - soap->alloced = 1; - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -static void -soap_init_mht(struct soap *soap) -{ register int i; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - soap->mht[i] = NULL; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -static void -soap_free_mht(struct soap *soap) -{ register int i; - register struct soap_mlist *mp, *mq; - for (i = 0; i < (int)SOAP_PTRHASH; i++) - { for (mp = soap->mht[i]; mp; mp = mq) - { mq = mp->next; - if (mp->live) - fprintf(stderr, "%s(%d): malloc() = %p not freed (memory leak or forgot to call soap_end()?)\n", mp->file, mp->line, mp->ptr); - free(mp); - } - soap->mht[i] = NULL; - } -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_track_malloc(struct soap *soap, const char *file, int line, size_t size) -{ register void *p = malloc(size); - if (soap) - { register size_t h = soap_hash_ptr(p); - register struct soap_mlist *mp = (struct soap_mlist*)malloc(sizeof(struct soap_mlist)); - if (soap->fdebug[SOAP_INDEX_TEST]) - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): malloc(%lu) = %p\n", file, line, (unsigned long)size, p)); - mp->next = soap->mht[h]; - mp->ptr = p; - mp->file = file; - mp->line = line; - mp->live = 1; - soap->mht[h] = mp; - } - return p; -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_track_free(struct soap *soap, const char *file, int line, void *p) -{ register size_t h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - { if (mp->live) - { free(p); - if (soap->fdebug[SOAP_INDEX_TEST]) - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): free(%p)\n", file, line, p)); - mp->live = 0; - } - else - fprintf(stderr, "%s(%d): free(%p) double free of pointer malloced at %s(%d)\n", file, line, p, mp->file, mp->line); - } - else - fprintf(stderr, "%s(%d): free(%p) pointer not malloced\n", file, line, p); -} -#endif - -/******************************************************************************/ -#ifdef SOAP_MEM_DEBUG -static void -soap_track_unlink(struct soap *soap, const void *p) -{ register size_t h = soap_hash_ptr(p); - register struct soap_mlist *mp; - for (mp = soap->mht[h]; mp; mp = mp->next) - if (mp->ptr == p) - break; - if (mp) - mp->live = 0; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_dealloc(struct soap *soap, void *p) -{ if (soap_check_state(soap)) - return; - if (p) - { register char **q; - for (q = (char**)&soap->alist; *q; q = *(char***)q) - { - if (*(short*)(char*)(*q - sizeof(short)) != (short)SOAP_CANARY) - { fprintf(stderr, "Data corruption in dynamic allocation (see logs)\n"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Data corruption:\n")); - DBGHEX(TEST, *q - 200, 200); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n")); - soap->error = SOAP_MOE; - return; - } - 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(soap, p); - return; - } - } - soap_delete(soap, p); - } - else - { register char *q; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free all soap_malloc() data\n")); - while (soap->alist) - { q = (char*)soap->alist; - if (*(short*)(char*)(q - sizeof(short)) != (short)SOAP_CANARY) - { fprintf(stderr, "Data corruption in dynamic allocation (see logs)\n"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Data corruption:\n")); - DBGHEX(TEST, q - 200, 200); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "\n")); - soap->error = SOAP_MOE; - return; - } - soap->alist = *(void**)q; - q -= *(size_t*)(q + sizeof(void*)); - SOAP_FREE(soap, q); - } - } - /* we must assume these were deallocated: */ - soap->action = NULL; - soap->fault = NULL; - soap->header = NULL; - soap->userid = NULL; - soap->passwd = 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; - if (soap_check_state(soap)) - return; - cp = &soap->clist; - if (p) - { while (*cp) - { if (p == (*cp)->ptr) - { register struct soap_clist *q = *cp; - *cp = q->next; - if (q->fdelete(q)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: deletion callback failed for object type %d\n", q->ptr, q->type)); -#ifdef SOAP_MEM_DEBUG - fprintf(stderr, "new(object type = %d) = %p not freed: deletion callback failed\n", q->type, q->ptr); -#endif - } - SOAP_FREE(soap, 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->fdelete(q)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not dealloc data %p: deletion callback failed for object type %d\n", q->ptr, q->type)); -#ifdef SOAP_MEM_DEBUG - fprintf(stderr, "new(object type = %d) = %p not freed: deletion callback failed\n", q->type, q->ptr); -#endif - } - SOAP_FREE(soap, q); - } - } -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -struct soap_clist * -SOAP_FMAC2 -soap_link(struct soap *soap, void *p, int t, int n, int (*fdelete)(struct soap_clist*)) -{ register struct soap_clist *cp; - if ((cp = (struct soap_clist*)SOAP_MALLOC(soap, 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)); -#ifdef SOAP_DEBUG - soap_track_unlink(soap, p); -#endif - 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(soap, q); - return; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#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 (!p || !id || !*id) - return p; - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOIDREF -#ifndef PALM_2 -SOAP_FMAC1 -void* -SOAP_FMAC2 -soap_id_forward(struct soap *soap, const char *href, void *p, size_t len, int st, int tt, size_t n, unsigned int k, void (*fcopy)(struct soap*, int, int, void*, size_t, 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(soap, 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; - fp->len = len; - 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 len=%lu href='%s'\n", st, tt, (unsigned long)n, p, k, (unsigned long)len, 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 -#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*)) -{ -#ifndef WITH_NOIDREF - struct soap_ilist *ip; -#endif - 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; - } -#ifndef WITH_NOIDREF - if (!id || !*id) -#endif - return p; -#ifndef WITH_NOIDREF - 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_DUPLICATE_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 -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_fcopy(struct soap *soap, int st, int tt, void *p, size_t len, 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; -#ifndef WITH_NOHTTP - 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++; - } -#endif - 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); - } -#ifndef WITH_LEANER - 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_TCPFIN -#ifdef WITH_OPENSSL - if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */ -#else - if (soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP)) - soap->fshutdownsocket(soap, (SOAP_SOCKET)soap->socket, 1); /* Send TCP FIN */ -#endif -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send phase\n")); - soap->omode &= ~SOAP_XML_SEC; - soap->count = 0; - soap->part = SOAP_END; - 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_DIME) && soap_getdime(soap)) - return soap->error; - soap->dime.list = soap->dime.first; - soap->dime.first = NULL; - soap->dime.last = NULL; - /* Check if MIME attachments and mime-post-check flag is set, if set call soap_resolve() and return */ - if (soap->mode & SOAP_ENC_MIME) - { -#ifndef WITH_NOIDREF - if (soap->mode & SOAP_MIME_POSTCHECK) - { soap_resolve(soap); - return SOAP_OK; - } -#endif - if (soap_getmime(soap)) - return soap->error; - } - soap->mime.list = soap->mime.first; - soap->mime.first = NULL; - soap->mime.last = NULL; - soap->mime.boundary = NULL; - if (soap->xlist) - { struct soap_multipart *content; - for (content = soap->mime.list; content; content = content->next) - soap_resolve_attachment(soap, content); - } -#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; -#ifndef WITH_NOIDREF - if (soap_resolve(soap)) - return soap->error; -#endif -#ifndef WITH_LEANER - if (soap->xlist) - { if (soap->mode & SOAP_ENC_MTOM) - return soap->error = SOAP_MIME_HREF; - return soap->error = SOAP_DIME_HREF; - } -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_free_temp(struct soap *soap) -{ register struct Namespace *ns; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Free namespace stack\n")); - while (soap->nlist) - { register struct soap_nlist *np = soap->nlist->next; - SOAP_FREE(soap, 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 attribute storage\n")); - while (soap->attributes) - { register struct soap_attribute *tp = soap->attributes->next; - if (soap->attributes->value) - SOAP_FREE(soap, soap->attributes->value); - SOAP_FREE(soap, soap->attributes); - soap->attributes = tp; - } -#ifdef WITH_FAST - if (soap->labbuf) - SOAP_FREE(soap, soap->labbuf); - soap->labbuf = NULL; - soap->lablen = 0; - soap->labidx = 0; -#endif - ns = soap->local_namespaces; - if (ns) - { for (; ns->id; ns++) - { if (ns->out) - { if (soap->encodingStyle == ns->out) - soap->encodingStyle = SOAP_STR_EOS; - SOAP_FREE(soap, ns->out); - ns->out = NULL; - } - if (soap->encodingStyle == ns->ns) - soap->encodingStyle = SOAP_STR_EOS; - } - SOAP_FREE(soap, soap->local_namespaces); - soap->local_namespaces = NULL; - } -#ifndef WITH_LEANER - while (soap->xlist) - { struct soap_xlist *xp = soap->xlist->next; - SOAP_FREE(soap, soap->xlist); - soap->xlist = xp; - } -#endif -#ifndef WITH_NOIDREF - soap_free_pht(soap); - soap_free_iht(soap); -#endif -} -#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) -{ const char *s; - char *t = NULL; - soap_close_logfile(soap, i); - s = soap->logfile[i]; - soap->logfile[i] = logfile; - if (s) - SOAP_FREE(soap, (void*)s); - if (logfile) - if ((t = (char*)SOAP_MALLOC(soap, strlen(logfile) + 1))) - strcpy(t, logfile); - soap->logfile[i] = t; -} -#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*)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 (soap_check_state(soap)) - return NULL; - if (copy) - { register struct soap_plugin *p; - memcpy(copy, soap, sizeof(struct soap)); - copy->state = SOAP_COPY; - copy->error = SOAP_OK; - copy->userid = NULL; - copy->passwd = NULL; - copy->nlist = NULL; - copy->blist = NULL; - copy->clist = NULL; - copy->alist = NULL; - copy->attributes = NULL; - copy->labbuf = NULL; - copy->lablen = 0; - copy->labidx = 0; -#ifdef SOAP_DEBUG - soap_init_mht(copy); -#endif - copy->local_namespaces = NULL; -#ifndef WITH_NOIDREF - soap_init_iht(copy); - soap_init_pht(copy); -#endif - copy->header = NULL; - copy->fault = NULL; - copy->action = NULL; -#ifndef WITH_LEAN -#ifdef WITH_COOKIES - copy->cookies = soap_copy_cookies(copy, soap); -#else - copy->cookies = NULL; -#endif -#endif -#ifdef SOAP_DEBUG - soap_init_logs(copy); - soap_set_recv_logfile(copy, soap->logfile[SOAP_INDEX_RECV]); - soap_set_sent_logfile(copy, soap->logfile[SOAP_INDEX_SENT]); - soap_set_test_logfile(copy, soap->logfile[SOAP_INDEX_TEST]); -#endif - copy->plugins = NULL; - for (p = soap->plugins; p; p = p->next) - { register struct soap_plugin *q = (struct soap_plugin*)SOAP_MALLOC(copy, 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(copy, q, p))) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Could not copy plugin '%s'\n", p->id)); - SOAP_FREE(copy, 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_copy_stream(struct soap *copy, struct soap *soap) -{ copy->mode = soap->mode; - copy->imode = soap->imode; - copy->omode = soap->omode; - copy->socket = soap->socket; - copy->recv_timeout = soap->recv_timeout; - copy->send_timeout = soap->send_timeout; -#if defined(__cplusplus) && !defined(WITH_LEAN) - copy->os = soap->os; - copy->is = soap->is; -#endif - copy->sendfd = soap->sendfd; - copy->recvfd = soap->recvfd; - copy->bufidx = soap->bufidx; - copy->buflen = soap->buflen; - copy->ahead = soap->ahead; - copy->cdata = soap->cdata; - copy->chunksize = soap->chunksize; - copy->chunkbuflen = soap->chunkbuflen; - copy->keep_alive = soap->keep_alive; - copy->max_keep_alive = soap->max_keep_alive; -#ifndef WITH_NOIO - copy->peer = soap->peer; - copy->peerlen = soap->peerlen; -#endif -#ifdef WITH_OPENSSL - copy->bio = soap->bio; - copy->ssl = soap->ssl; - copy->ctx = soap->ctx; -#endif -#ifdef WITH_ZLIB - copy->zlib_state = soap->zlib_state; - copy->zlib_in = soap->zlib_in; - copy->zlib_out = soap->zlib_out; - copy->d_stream = soap->d_stream; - copy->z_buflen = soap->z_buflen; - copy->z_level = soap->z_level; - copy->z_crc = soap->z_crc; - copy->z_ratio_in = soap->z_ratio_in; - copy->z_ratio_out = soap->z_ratio_out; - memcpy(copy->z_buf, soap->z_buf, sizeof(soap->z_buf)); -#endif - memcpy(copy->buf, soap->buf, sizeof(soap->buf)); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init(struct soap *soap) -{ soap->state = SOAP_INIT; - soap->version = 0; - soap_imode(soap, SOAP_IO_DEFAULT); - soap_omode(soap, SOAP_IO_DEFAULT); - soap->plugins = NULL; - soap->user = NULL; - soap->userid = NULL; - soap->passwd = NULL; -#ifndef WITH_NOHTTP - soap->fpost = http_post; - soap->fget = http_get; - soap->fform = NULL; - soap->fposthdr = http_post_header; - soap->fresponse = http_response; - soap->fparse = http_parse; - soap->fparsehdr = http_parse_header; -#endif - soap->fheader = NULL; - soap->fconnect = NULL; - soap->fdisconnect = NULL; -#ifndef WITH_NOIO -#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->fopen = NULL; - soap->fclose = NULL; - soap->fpoll = NULL; -#endif - soap->fseterror = NULL; - soap->fignore = NULL; - soap->fserveloop = NULL; - soap->fplugin = fplugin; - soap->fmalloc = NULL; -#ifndef WITH_LEANER - soap->fprepareinit = NULL; - soap->fpreparesend = NULL; - soap->fpreparerecv = NULL; - soap->fpreparefinal = NULL; - soap->fdimereadopen = NULL; - soap->fdimewriteopen = NULL; - soap->fdimereadclose = NULL; - soap->fdimewriteclose = NULL; - soap->fdimeread = NULL; - soap->fdimewrite = NULL; - soap->fmimereadopen = NULL; - soap->fmimewriteopen = NULL; - soap->fmimereadclose = NULL; - soap->fmimewriteclose = NULL; - soap->fmimeread = NULL; - soap->fmimewrite = NULL; -#endif - soap->float_format = "%G"; - soap->double_format = "%lG"; - soap->dime_id_format = "cid:id%d"; /* default DIME id format */ - soap->http_version = "1.1"; - soap->proxy_http_version = "1.0"; - soap->http_content = NULL; - 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; -#ifndef WITH_LEANER - 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; - soap->xlist = NULL; -#endif -#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_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->c14ninclude = NULL; - soap->c14nexclude = NULL; - soap->cookies = NULL; - soap->cookie_domain = NULL; - soap->cookie_path = NULL; - soap->cookie_max = 32; -#endif -#ifdef SOAP_DEBUG - soap_init_mht(soap); - soap_init_logs(soap); -#endif -#ifdef WMW_RPM_IO - soap->rpmreqid = NULL; -#endif -#ifdef PALM - palmNetLibOpen(); -#endif -#ifndef WITH_NOIDREF - soap_init_iht(soap); - soap_init_pht(soap); -#endif -#ifdef SOAP_DEBUG - soap_set_recv_logfile(soap, "RECV.log"); - soap_set_sent_logfile(soap, "SENT.log"); - soap_set_test_logfile(soap, "TEST.log"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing context\n")); -#endif -#ifdef WITH_OPENSSL - if (!ssl_init_done) - { soap_ssl_init(); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing OpenSSL, version=%ld\n", (long)OPENSSL_VERSION_NUMBER)); - } - soap->fsslauth = ssl_auth_init; - soap->fsslverify = ssl_verify_callback; - soap->bio = NULL; - soap->ssl = NULL; - soap->ctx = NULL; - soap->ssl_flags = SOAP_SSL_DEFAULT; - soap->keyfile = NULL; - soap->password = NULL; - soap->dhfile = NULL; - soap->cafile = NULL; - soap->capath = NULL; - soap->crlfile = NULL; - soap->randfile = NULL; - soap->session = NULL; -#endif - soap_begin(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init1(struct soap *soap, soap_mode mode) -{ soap_init2(soap, mode, mode); -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_init2(struct soap *soap, soap_mode imode, soap_mode 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, "Reinitializing context\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_END; - 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'; -#ifndef WITH_LEANER - soap->dime.chunksize = 0; - soap->dime.buflen = 0; -#endif - soap_free_temp(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_end(struct soap *soap) -{ if (soap_check_state(soap)) - return; - soap_free_temp(soap); - soap_dealloc(soap, NULL); - while (soap->clist) - { register struct soap_clist *cp = soap->clist->next; - SOAP_FREE(soap, 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, const struct Namespace *p) -{ register struct Namespace *ns = soap->local_namespaces; - register struct soap_nlist *np, *nq, *nr; - register unsigned int level = soap->level; - soap->namespaces = p; - soap->local_namespaces = NULL; - soap_set_local_namespaces(soap); - /* reverse the namespace 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; - } - } - /* then push on new stack */ - while (np) - { register const char *s; - soap->level = np->level; /* preserve element nesting level */ - s = np->ns; - if (!s && np->index >= 0 && ns) - { s = ns[np->index].out; - if (!s) - s = ns[np->index].ns; - } - if (s && soap_push_namespace(soap, np->id, s)) - return soap->error; - nq = np; - np = np->next; - SOAP_FREE(soap, nq); - } - if (ns) - { register int i; - for (i = 0; ns[i].id; i++) - { if (ns[i].out) - { SOAP_FREE(soap, ns[i].out); - ns[i].out = NULL; - } - } - SOAP_FREE(soap, ns); - } - soap->level = level; /* restore level */ - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -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++; - n *= sizeof(struct Namespace); - ns2 = (struct Namespace*)SOAP_MALLOC(soap, n); - if (ns2) - { memcpy(ns2, soap->namespaces, n); - if (ns2[0].ns) - { if (!strcmp(ns2[0].ns, soap_env1)) - soap->version = 1; - else - soap->version = 2; - } - soap->local_namespaces = ns2; - } - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef PALM_1 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_strsearch(const char *big, const char *little) -{ size_t n = strlen(little); - const char *s = big; - while (s) - { if (!strncmp(s, little, n) && (s[n] == '\0' || s[n] == ' ')) - return s; - s = strchr(s, ' '); - if (s) - s++; - } - return NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -#ifndef PALM_1 -SOAP_FMAC1 -struct soap_nlist * -SOAP_FMAC2 -soap_lookup_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np; - for (np = soap->nlist; np; np = np->next) - { if (!strncmp(np->id, tag, n) && !np->id[n]) - return np; - } - return NULL; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static struct soap_nlist * -soap_push_ns(struct soap *soap, const char *id, const char *ns, short utilized) -{ register struct soap_nlist *np; - size_t n, k; - if (soap_strsearch(soap->c14nexclude, id)) - return NULL; - if (!utilized) - { for (np = soap->nlist; np; np = np->next) - { if (!strcmp(np->id, id) && (!np->ns || !strcmp(np->ns, ns))) - break; - } - if (np) - { if ((np->level < soap->level || !np->ns) && np->index == 1) - utilized = 1; - else - return NULL; - } - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Adding namespace binding (level=%u) '%s' '%s' utilized=%d\n", soap->level, id, ns?ns:"(null)", utilized)); - n = strlen(id); - if (ns) - k = strlen(ns); - else - k = 0; - np = (struct soap_nlist*)SOAP_MALLOC(soap, sizeof(struct soap_nlist) + n + k + 1); - if (!np) - { soap->error = SOAP_EOM; - return NULL; - } - np->next = soap->nlist; - soap->nlist = np; - strcpy(np->id, id); - if (ns) - { np->ns = np->id + n + 1; - strcpy(np->ns, ns); - } - else - np->ns = NULL; - np->level = soap->level; - np->index = utilized; - return np; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_utilize_ns(struct soap *soap, const char *tag, size_t n) -{ register struct soap_nlist *np = soap_lookup_ns(soap, tag, n); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Utilizing namespace of '%s'\n", tag)); - if (np) - { if (np->index == 0) - soap_push_ns(soap, np->id, np->ns, 1); - } - else if (strncmp(tag, "xml", 3)) - { strncpy(soap->tmpbuf, tag, n); - soap->tmpbuf[n] = '\0'; - soap_push_ns(soap, soap->tmpbuf, NULL, 1); - } -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static void -soap_pop_ns(struct soap *soap) -{ soap_pop_namespace(soap); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_element(struct soap *soap, const char *tag, int id, const char *type) -{ -#ifdef WITH_XMLNS - register const char *s; -#endif - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag='%s' id='%d' type='%s'\n", tag, id, type?type:"")); -#ifdef WITH_DOM - if (soap->part == SOAP_BEGIN_SECURITY && (soap->mode & SOAP_XML_CANONICAL) && !(soap->mode & SOAP_DOM_ASIS)) - { register struct soap_nlist *np; - /* wsu:Id found: clear xmlns renderings, so re-emit them for exc-c14n */ - for (np = soap->nlist; np; np = np->next) - { if (np->index == 2) - np->index = 0; - } - } - if (soap->mode & SOAP_XML_DOM) - { register struct soap_dom_element *elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->soap = soap; - elt->next = NULL; - elt->prnt = soap->dom; - elt->name = soap_strdup(soap, tag); - elt->elts = NULL; - elt->atts = NULL; - elt->nstr = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->node = NULL; - elt->type = 0; - elt->head = NULL; - elt->tail = NULL; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - } - else - { -#endif - soap->level++; -#ifndef WITH_LEAN - if (!soap->ns) - { if (!(soap->mode & SOAP_XML_CANONICAL) - && soap_send(soap, soap->prolog ? soap->prolog : "\n")) - return soap->error; - } - else if (soap->mode & SOAP_XML_INDENT) - { if (soap->ns == 1 && soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - soap->body = 1; - } -#endif -#ifdef WITH_XMLNS - s = strchr(tag, ':'); - if (s && strncmp(tag, "SOAP-ENV", s - tag)) - { struct Namespace *ns = soap->local_namespaces; - size_t n = s - tag; - if (soap_send_raw(soap, "<", 1) - || soap_send(soap, s + 1)) - return soap->error; - if (soap->nlist && !strncmp(soap->nlist->id, tag, n) && !soap->nlist->id[n]) - ns = NULL; - for (; ns && ns->id; ns++) - { if (*ns->id && (ns->out || ns->ns) && !strncmp(ns->id, tag, n) && !ns->id[n]) - { soap_push_ns(soap, ns->id, ns->out ? ns->out : ns->ns, 0); - if (soap_attribute(soap, "xmlns", ns->out ? ns->out : ns->ns)) - return soap->error; - break; - } - } - } - else -#endif - if (soap_send_raw(soap, "<", 1) - || soap_send(soap, tag)) - return soap->error; -#ifdef WITH_DOM - } -#endif - if (!soap->ns) - { struct Namespace *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; /* start with 0 or 2, but should be one to continue */ -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *t = strchr(tag, ':'); - if (t) - soap_utilize_ns(soap, tag, t - tag); - } -#endif - if (id > 0) - { sprintf(soap->tmpbuf, "_%d", id); - if (soap_attribute(soap, "id", soap->tmpbuf)) - return soap->error; - } - if (type && *type && (!(soap->mode & SOAP_XML_SEC) || soap->part == SOAP_IN_BODY)) - { if (soap_attribute(soap, "xsi:type", type)) - return soap->error; -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { const char *t = strchr(type, ':'); - if (t) - soap_utilize_ns(soap, type, t - type); - } -#endif - } - if (soap->null && soap->position > 0) - { register 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; - if (soap->part == SOAP_BEGIN_SECURITY && (soap->mode & SOAP_XML_CANONICAL)) - soap->part = SOAP_IN_SECURITY; - 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 && (n > 214748364 || c >= '8')) - 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 && (n > 429496729 || c >= '6')) - 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; - } -#ifndef WITH_LEAN - if (type && *type && (soap->mode & SOAP_XML_CANONICAL)) - { const char *s = strchr(type, ':'); - if (s) - soap_utilize_ns(soap, type, s - type); - } -#endif - 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; -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { struct soap_nlist *np; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible && tp->name) - { const char *s = strchr(tp->name, ':'); - if (s) - soap_utilize_ns(soap, tp->name, s - tp->name); - } - } - for (np = soap->nlist; np; np = np->next) - { if (np->index == 1 && np->ns) - { sprintf(soap->tmpbuf, "xmlns:%s", np->id); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Enabling utilized binding (level=%u) %s='%s'\n", np->level, soap->tmpbuf, np->ns)); - soap_set_attr(soap, soap->tmpbuf, np->ns); - np->index = 2; - } - } - } -#endif -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { register struct soap_dom_attribute **att; - att = &soap->dom->atts; - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, tp->name); - (*att)->data = soap_strdup(soap, tp->value); - (*att)->wide = NULL; - (*att)->soap = soap; - att = &(*att)->next; - tp->visible = 0; - } - } - return SOAP_OK; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible) - { -#ifdef WITH_XMLNS - const char *s = strchr(tp->name, ':'); - if (s) - { size_t n = s - tp->name; - if (soap->nlist && !strncmp(soap->nlist->id, tp->name, n) && !soap->nlist->id[n]) - s++; - else - s = tp->name; - if (soap_send(soap, " ") || soap_send(soap, s)) - return soap->error; - } - else -#endif - if (soap_send(soap, " ") || 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) - { -#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 - soap->level--; /* decrement level just before /> */ - if (soap_send_raw(soap, "/>", 2)) - return soap->error; - return SOAP_OK; - } - 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 -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - soap_pop_ns(soap); - if (soap->mode & SOAP_XML_INDENT) - { if (!soap->body) - { if (soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1)) - return soap->error; - } - soap->body = 0; - } -#endif -#ifdef WITH_XMLNS - { const char *s = strchr(tag, ':'); - if (s && strncmp(tag, "SOAP-ENV", s - tag)) - { soap_pop_ns(soap); - tag = s + 1; - } - } -#endif - if (soap_send_raw(soap, "error; - soap->level--; /* decrement level just before > */ - 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; - const char *s = "href"; - if (soap->version == 2) - { s = "SOAP-ENC:ref"; - n = 1; - } - sprintf(soap->href, "#_%d", href); - return soap_element_href(soap, tag, id, s, 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) -{ if (!p || (a && !a->__ptr)) - { soap_element_null(soap, tag, id, type); - return -1; - } -#ifndef WITH_NOIDREF - if (soap->mode & SOAP_XML_TREE) - return 0; - if (id < 0) - { struct soap_plist *pp; - 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; -#else - return 0; -#endif -} -#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_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_check_result(struct soap *soap, const char *tag) -{ if (soap->version == 2 && soap->encodingStyle) - { soap_instring(soap, ":result", NULL, NULL, 0, 2, -1, -1); - /* should compare tag to element's QName value? */ - } -} -#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->mode & SOAP_XML_CANONICAL) && 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); - a->data = soap_strdup(soap, value); - a->wide = NULL; - a->soap = soap; - soap->dom->atts = a; - return SOAP_OK; - } -#endif -#ifndef WITH_LEAN - if (soap->mode & SOAP_XML_CANONICAL) - { /* TODO: consider using this code to handle default namespace bindings - if (!strncmp(name, "xmlns", 5) && (name[5] == ':' || name[5] == '\0')) - { if (name[5] == ':') - soap_push_ns(soap, name + 6, value, 0); - else - soap_push_ns(soap, "", value, 0); - } - */ - if (!strncmp(name, "xmlns:", 6)) - soap_push_ns(soap, name + 6, value, 0); - else if (soap_set_attr(soap, name, value)) - return soap->error; - } - else -#endif - { if (soap_send(soap, " ") || 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, int nillable, const char *type) -{ 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; - if (type && *soap->type && soap_match_tag(soap, soap->type, type)) - return soap->error = SOAP_TYPE; - } - } - else if (soap->error == SOAP_NO_TAG && tag && *tag == '-') - soap->error = SOAP_OK; - 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 int n = 0; - if (tag && *tag == '-') - return SOAP_OK; - if (soap->error == SOAP_NO_TAG) - soap->error = SOAP_OK; -#ifdef WITH_DOM - /* this whitespace or mixed content is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (!soap->peeked && !soap_string_in(soap, 3, -1, -1)) - return soap->error; - if (soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - if (soap->peeked) - { if (*soap->tag) - n++; - soap->peeked = 0; - } - do - { while (((c = soap_get(soap)) != SOAP_TT)) - { if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (c == SOAP_LT) - n++; - else if (c == '/') - { c = soap_get(soap); - if (c == SOAP_GT) - n--; - else - soap_unget(soap, c); - } - } - } while (n--); - s = soap->tag; - n = sizeof(soap->tag); - while (soap_notblank(c = soap_get(soap))) - { if (--n > 0) - *s++ = (char)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 || !*tag || !soap_match_tag(soap, soap->tag, tag)) - { soap->level--; - soap_pop_namespace(soap); - 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 (tp->visible && !soap_match_tag(soap, tp->name, name)) - break; - } - if (tp) - { 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(soap, 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, ':'); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Inserting attribute %s for c14n\n", 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 (tp->visible) - { return SOAP_OK; - } - 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(soap, tp->value); - tp->value = NULL; - tp->ns = NULL; - } - if (value) - { if (!tp->value) - { tp->size = strlen(value) + 1; - if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size))) - return soap->error = SOAP_EOM; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Allocate attribute value for %s (%p)\n", tp->name, tp->value)); - } - strcpy(tp->value, value); - if (!strncmp(tp->name, "xmlns:", 6)) - tp->ns = tp->value; - tp->visible = 2; -#ifndef WITH_LEAN - if (!strcmp(name, "wsu:Id")) - { soap->part = SOAP_BEGIN_SECURITY; - strncpy(soap->id, value, sizeof(soap->id)); - soap->id[sizeof(soap->id)-1] = '\0'; - } -#endif - } - 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; - if (soap->attributes->value) - SOAP_FREE(soap, soap->attributes->value); - SOAP_FREE(soap, 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) -{ register size_t i; - for (i = 0; i < n; i++) - { register soap_wchar c = soap_get(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 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_store_lab(struct soap *soap, const char *s, size_t n) -{ soap->labidx = 0; - return soap_append_lab(soap, s, n); -} -#endif -#endif - -/******************************************************************************/ -#ifdef WITH_FAST -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -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, soap->lablen); - if (!soap->labbuf) - { if (t) - SOAP_FREE(soap, t); - return soap->error = SOAP_EOM; - } - if (t) - { memcpy(soap->labbuf, t, soap->labidx); - SOAP_FREE(soap, 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) -{ -#ifdef WITH_DOM - register struct soap_dom_attribute **att = NULL; - register char *lead = NULL; -#endif - register struct soap_attribute *tp; - const char *t; - register char *s; - register soap_wchar c; - register int i; - if (soap->peeked) - { if (!*soap->tag) - return soap->error = SOAP_NO_TAG; - return SOAP_OK; - } - soap->peeked = 1; - c = soap_getutf8(soap); -#ifdef WITH_DOM - /* whitespace leading to start tag is not insignificant for DOM */ - if (soap_blank(c)) - { soap->labidx = 0; - do - { if (soap_append_lab(soap, NULL, 0)) - return SOAP_EOM; - s = soap->labbuf + soap->labidx; - i = soap->lablen - soap->labidx; - soap->labidx = soap->lablen; - while (soap_blank(c) && i--) - { *s++ = c; - c = soap_getutf8(soap); - } - } - while (soap_blank(c)); - *s = '\0'; - lead = soap_strdup(soap, soap->labbuf); - } -#else - while (soap_blank(c)) - c = soap_getutf8(soap); -#endif - if (c != SOAP_LT) - { *soap->tag = '\0'; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifdef WITH_DOM - /* whitespace leading to end tag is not insignificant for DOM */ - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->tail = soap_strdup(soap, lead); -#endif - return soap->error = SOAP_NO_TAG; - } - s = soap->tag; - do c = soap_get1(soap); - while (soap_blank(c)); - i = sizeof(soap->tag); - while (c != '>' && c != '/' && soap_notblank(c) && (int)c != EOF) - { if (--i > 0) - *s++ = (char)c; - c = soap_get1(soap); - } - while (soap_blank(c)) - c = soap_get1(soap); - *s = '\0'; - 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; -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { register struct soap_dom_element *elt; - elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element)); - if (!elt) - return soap->error = SOAP_EOM; - elt->next = NULL; - elt->nstr = NULL; - elt->name = soap_strdup(soap, soap->tag); - elt->prnt = soap->dom; - elt->elts = NULL; - elt->atts = NULL; - elt->data = NULL; - elt->wide = NULL; - elt->type = 0; - elt->node = NULL; - elt->head = lead; - elt->tail = NULL; - elt->soap = soap; - if (soap->dom) - { struct soap_dom_element *p = soap->dom->elts; - if (p) - { while (p->next) - p = p->next; - p->next = elt; - } - else - soap->dom->elts = elt; - } - soap->dom = elt; - att = &elt->atts; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - tp->visible = 0; - while ((int)c != EOF && c != '>' && c != '/') - { s = soap->tmpbuf; - i = sizeof(soap->tmpbuf); - while (c != '=' && c != '>' && c != '/' && soap_notblank(c) && (int)c != EOF) - { if (--i > 0) - *s++ = (char)c; - c = soap_get1(soap); - } - *s = '\0'; - if (i == sizeof(soap->tmpbuf)) - return soap->error = SOAP_SYNTAX_ERROR; -#ifdef WITH_DOM - /* add attribute name to dom */ - if (att) - { *att = (struct soap_dom_attribute*)soap_malloc(soap, sizeof(struct soap_dom_attribute)); - if (!*att) - return soap->error = SOAP_EOM; - (*att)->next = NULL; - (*att)->nstr = NULL; - (*att)->name = soap_strdup(soap, soap->tmpbuf); - (*att)->data = NULL; - (*att)->wide = NULL; - (*att)->soap = soap; - } -#endif - if (!strncmp(soap->tmpbuf, "xmlns", 5)) - { if (soap->tmpbuf[5] == ':') - { soap->tmpbuf[5] = '\0'; - t = soap->tmpbuf + 6; - } - else if (soap->tmpbuf[5]) - t = NULL; - else - 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(soap, 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_get1(soap); - if (c == '=') - { do c = soap_getutf8(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; - if (soap_store_lab(soap, tp->value, tp->size)) - return soap->error; - if (tp->value) - SOAP_FREE(soap, 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; - } - if (soap->labidx) - tp->size = soap->lablen; - else - { tp->size = strlen(soap->labbuf) + 1; - if (tp->size < SOAP_LABLEN) - tp->size = SOAP_LABLEN; - } - if (!(tp->value = (char*)SOAP_MALLOC(soap, tp->size))) - return soap->error = SOAP_EOM; - strcpy(tp->value, soap->labbuf); -#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(soap, n))) - return soap->error = SOAP_EOM; - if (tp->value) - { memcpy(s, tp->value, tp->size); - SOAP_FREE(soap, tp->value); - } - soap_save_block(soap, s + tp->size, 0); - tp->value = s; - tp->size = n; -#endif - } - do c = soap_get1(soap); - while (soap_blank(c)); - tp->visible = 2; /* seen this attribute w/ value */ -#ifdef WITH_DOM - if (att) - (*att)->data = soap_strdup(soap, tp->value); -#endif - } - else - tp->visible = 1; /* seen this attribute w/o value */ -#ifdef WITH_DOM - if (att) - att = &(*att)->next; -#endif - if (t && tp->value) - { if (soap_push_namespace(soap, t, tp->value)) - return soap->error; - tp->visible = 0; - } - } -#ifdef WITH_DOM - if (att) - { soap->dom->nstr = soap_current_namespace(soap, soap->tag); - for (att = &soap->dom->atts; *att; att = &(*att)->next) - (*att)->nstr = soap_current_namespace(soap, (*att)->name); - } -#endif - if ((int)c == EOF) - return soap->error = SOAP_EOF; - if (!(soap->body = (c != '/'))) - do c = soap_get1(soap); - while (soap_blank(c)); -#ifdef WITH_DOM - if (soap->mode & SOAP_XML_DOM) - { if (!soap->body && soap->dom->prnt) - soap->dom = soap->dom->prnt; - } -#endif - for (tp = soap->attributes; tp; tp = tp->next) - { if (tp->visible && tp->value) - { if (!strcmp(tp->name, "id")) - { if (soap->version > 0 - || (soap->mode & SOAP_XML_GRAPH)) - { *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")) - { if (soap->version == 1 - || (soap->mode & SOAP_XML_GRAPH) - || (soap->mode & SOAP_ENC_MTOM)) - { strncpy(soap->href, tp->value, sizeof(soap->href) - 1); - 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_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; - } - else if (soap->version == 1) - { if (!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_match_tag(soap, tp->name, "SOAP-ENC:offset")) - strncpy(soap->arrayOffset, tp->value, sizeof(soap->arrayOffset)); - else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:position")) - soap->position = soap_getposition(tp->value, soap->positions); - else if (!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:mustUnderstand") - && (!strcmp(tp->value, "1") || !strcmp(tp->value, "true"))) - soap->mustUnderstand = 1; - else if (!soap_match_tag(soap, tp->name, "SOAP-ENV:actor")) - { if ((!soap->actor || strcmp(soap->actor, tp->value)) - && strcmp(tp->value, "http://schemas.xmlsoap.org/soap/actor/next")) - soap->other = 1; - } - } - else if (soap->version == 2) - { if (!strcmp(tp->name, "ref") - || !soap_match_tag(soap, tp->name, "SOAP-ENC: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, "SOAP-ENC:itemType")) - strncpy(soap->arrayType, tp->value, sizeof(soap->arrayType) - 1); - else if (!soap_match_tag(soap, tp->name, "SOAP-ENC:arraySize")) - strncpy(soap->arraySize, tp->value, sizeof(soap->arraySize) - 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, "SOAP-ENV:role")) - { if ((!soap->actor || strcmp(soap->actor, tp->value)) - && strcmp(tp->value, "http://www.w3.org/2003/05/soap-envelope/role/next")) - soap->other = 1; - } - } - } - } - return soap->error = SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_retry(struct soap *soap) -{ soap->error = SOAP_OK; - soap_revert(soap); -} -#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 = 0xFFFFFF80UL; -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { soap->dom->data = soap_strdup(soap, s); - return SOAP_OK; - } -#endif - if (soap->mode & SOAP_C_UTFSTRING) - mask = 0; - t = s; - while ((c = *t++)) - { switch (c) - { - case 0x09: - if (flag) - { if (soap_send_raw(soap, s, t - s - 1) || soap_send_raw(soap, " ", 5)) - return soap->error; - s = t; - } - break; - case 0x0A: - 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 0x0D: - 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: -#ifndef WITH_LEANER -#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 -#endif - if ((c & mask) || !(c & 0xFFFFFFE0UL)) - { 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; -#if !defined(WITH_LEANER) && defined(HAVE_WCTOMB) - char buf[MB_LEN_MAX > 8 ? MB_LEN_MAX : 8]; -#else - char buf[8]; -#endif - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { n = 1; - soap->peeked = 0; -#ifndef WITH_LEAN - t = soap->tmpbuf; - t[0] = '<'; - strncpy(t + 1, soap->tag, sizeof(soap->tmpbuf) - 1); - strncat(t, ">", sizeof(soap->tmpbuf)); - m = strlen(soap->tag) + 2; -#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: -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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*)"amp;"; - m = 4; - } - 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; -#ifndef WITH_LEANER -#ifdef HAVE_WCTOMB - if (soap->mode & SOAP_C_MBSTRING) - { m = wctomb(buf, c & 0x7FFFFFFF); - if (m >= 1 && m <= (int)MB_CUR_MAX) - { t = buf; - *s++ = *t++; - m--; - } - else - { *s++ = SOAP_UNKNOWN_CHAR; - m = 0; - } - } - else -#endif -#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; - } -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - { if (flag == 3) - soap->dom->tail = t; - else - soap->dom->data = t; - } -#endif - if (flag == 2) - if (soap_s2QName(soap, t, &t)) - return NULL; - return t; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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) - { wchar_t *r = (wchar_t*)s; - int n = 1; - while (*r++) - n++; - soap->dom->wide = r = (wchar_t*)soap_malloc(soap, n * sizeof(wchar_t)); - while (n--) - *r++ = *s++; - return SOAP_OK; - } -#endif - while ((c = *s++)) - { switch (c) - { - case 0x09: - if (flag) - t = " "; - else - t = "\t"; - break; - case 0x0A: - if (flag || !(soap->mode & SOAP_XML_CANONICAL)) - t = " "; - else - t = "\n"; - break; - case 0x0D: - 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 >= 0x20 && 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Reading wide string content\n")); - if (soap->peeked) - { if (!soap->body) - return NULL; - if (*soap->tag) - { n = 1; - soap->peeked = 0; - } - } - 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; - } - s = (wchar_t*)soap_save_block(soap, NULL, 0); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->wide = s; -#endif - return s; -} -#endif -#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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = (int)soap_strtol(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (int*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(int), 0, NULL); - else if (p) - { if (soap_s2int(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = soap_strtol(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (long*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(long), 0, NULL); - else if (p) - { if (soap_s2long(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOLL - char *r; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = strtoll(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -# ifdef HAVE_SSCANF - if (sscanf(s, SOAP_LONG_FORMAT, p) != 1) -# endif -#endif - 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, NULL)) - 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 (*soap->href) - p = (LONG64*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(LONG64), 0, NULL); - else if (p) - { if (soap_s2LONG64(soap, soap_value(soap), p)) - return 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 (s == r || *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, NULL)) - 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 (*soap->href) - p = (char*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(char), 0, NULL); - else if (p) - { if (soap_s2byte(soap, soap_value(soap), p)) - return 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 (s == r || *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, NULL)) - 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 (*soap->href) - p = (short*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(short), 0, NULL); - else if (p) - { if (soap_s2short(soap, soap_value(soap), p)) - return 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) -{ char *s, *t; - if (soap_isnan((double)n)) - return "NaN"; - if (soap_ispinff(n)) - return "INF"; - if (soap_isninff(n)) - return "-INF"; - s = soap->tmpbuf; - sprintf(soap->tmpbuf, soap->float_format, n); - t = strchr(s, ','); /* convert decimal comma to DP */ - if (t) - *t = '.'; - 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 (!*s) - return soap->error = SOAP_TYPE; - 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 - { -/* On some systems, strtof appears to be broken or doesn't link: use with caution */ -#if defined(HAVE_STRTOF) - char *r; - *p = strtof((char*)s, &r); - if (*r) -#elif defined(HAVE_STRTOD) - char *r; - *p = (float)strtod(s, &r); - if (*r) -#endif -#ifdef HAVE_SSCANF - if (sscanf(s, "%g", 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, NULL)) - 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 (*soap->href) - p = (float*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(float), 0, NULL); - else if (p) - { if (soap_s2float(soap, soap_value(soap), p)) - return 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) -{ char *s, *t; - if (soap_isnan(n)) - return "NaN"; - if (soap_ispinfd(n)) - return "INF"; - if (soap_isninfd(n)) - return "-INF"; - s = soap->tmpbuf; - sprintf(soap->tmpbuf, soap->double_format, n); - t = strchr(s, ','); /* convert decimal comma to DP */ - if (t) - *t = '.'; - 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 (!*s) - return soap->error = SOAP_TYPE; - 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, "%lg", 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, NULL)) - 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 (*soap->href) - p = (double*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(double), 0, NULL); - else if (p) - { if (soap_s2double(soap, soap_value(soap), p)) - return 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 (s == r || *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, NULL)) - 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 (*soap->href) - p = (unsigned char*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned char), 0, NULL); - else if (p) - { if (soap_s2unsignedByte(soap, soap_value(soap), p)) - return 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_unsignedShort2s(struct soap *soap, unsigned short n) -{ return soap_unsignedLong2s(soap, (unsigned long)n); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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 PALM_2 -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 (s == r || *r || n > 65535) - soap->error = SOAP_TYPE; - *p = (unsigned short)n; - } - return soap->error; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -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, NULL)) - 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 (*soap->href) - p = (unsigned short*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned short), 0, NULL); - else if (p) - { if (soap_s2unsignedShort(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = (unsigned int)soap_strtoul(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (unsigned int*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned int), 0, NULL); - else if (p) - { if (soap_s2unsignedInt(soap, soap_value(soap), p)) - return 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; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = soap_strtoul(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) - 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, NULL)) - 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 (*soap->href) - p = (unsigned long*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(unsigned long), 0, NULL); - else if (p) - { if (soap_s2unsignedLong(soap, soap_value(soap), p)) - return 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) - { -#ifdef HAVE_STRTOULL - char *r; -#ifndef WITH_NOIO -#ifndef WITH_LEAN - soap_reset_errno; -#endif -#endif - *p = strtoull(s, &r, 10); - if ((s == r && (soap->mode & SOAP_XML_STRICT)) || *r -#ifndef WITH_NOIO -#ifndef WITH_LEAN - || soap_errno == SOAP_ERANGE -#endif -#endif - ) -#else -# ifdef HAVE_SSCANF - if (sscanf(s, SOAP_ULONG_FORMAT, p) != 1) -# endif -#endif - 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, NULL)) - 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 (*soap->href) - p = (ULONG64*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(ULONG64), 0, NULL); - else if (p) - { if (soap_s2ULONG64(soap, soap_value(soap), p)) - return 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) - { if (!(*t = soap_strdup(soap, s))) - return soap->error = SOAP_EOM; - if (!(soap->mode & (SOAP_ENC_LATIN | SOAP_C_UTFSTRING))) - { /* TODO: consider truncating UTF8 to ASCII for regular XML attribute strings? */ - } - } - 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 = soap->nlist; - const char *p; - /* if there is no namespace stack, or prefix is "xml" then pass string */ - if (!np || !strncmp(s, "xml:", 4)) - { *t = soap_strdup(soap, s); - return SOAP_OK; - } - /* else we normalize the QName by replacing its prefix */ - 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); - } - else - *t = NULL; - 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 != '"') - { -#ifndef WITH_LEAN - if (s && (soap->mode & SOAP_XML_CANONICAL)) - { t = (char*)strchr(s, ':'); - if (t) - soap_utilize_ns(soap, s, t - s); - } -#endif - 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:_%d", 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 WITH_LEAN -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_s2wchar(struct soap *soap, const char *s, wchar_t **t) -{ wchar_t *r; - if (!s) - *t = NULL; - else - { *t = r = (wchar_t*)soap_malloc(soap, sizeof(wchar_t) * (strlen(s) + 1)); - if (!r) - return soap->error; - if (soap->mode & SOAP_ENC_LATIN) - { while (*s) - *r++ = (wchar_t)*s++; - } - else - { /* Convert UTF8 to wchar */ - while (*s) - { register soap_wchar c, c1, c2, c3, c4; - c = *s++; - if (c < 0x80) - *r++ = (wchar_t)c; - else - { c1 = (soap_wchar)*s++ & 0x3F; - if (c < 0xE0) - *r++ = (wchar_t)(((soap_wchar)(c & 0x1F) << 6) | c1); - else - { c2 = (soap_wchar)*s++ & 0x3F; - if (c < 0xF0) - *r++ = (wchar_t)(((soap_wchar)(c & 0x0F) << 12) | (c1 << 6) | c2); - else - { c3 = (soap_wchar)*s++ & 0x3F; - if (c < 0xF8) - *r++ = (wchar_t)(((soap_wchar)(c & 0x07) << 18) | (c1 << 12) | (c2 << 6) | c3); - else - { c4 = (soap_wchar)*s++ & 0x3F; - if (c < 0xFC) - *r++ = (wchar_t)(((soap_wchar)(c & 0x03) << 24) | (c1 << 18) | (c2 << 12) | (c3 << 6) | c4); - else - *r++ = (wchar_t)(((soap_wchar)(c & 0x01) << 30) | (c1 << 24) | (c2 << 18) | (c3 << 12) | (c4 << 6) | (soap_wchar)(*s++ & 0x3F)); - } - } - } - } - } - } - *r = L'\0'; - } - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_wchar2s(struct soap *soap, const wchar_t *s) -{ register soap_wchar c; - register char *r, *t; - const wchar_t *q = s; - size_t n = 0; - while ((c = *q++)) - { if (c > 0 && c < 0x80) - n++; - else - n += 6; - } - r = t = (char*)soap_malloc(soap, n + 1); - if (r) - { /* Convert wchar to UTF8 */ - while ((c = *s++)) - { if (c > 0 && c < 0x80) - *t++ = (char)c; - else - { 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'; - } - return r; -} -#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) - return soap->error; - if (!**p && (soap->mode & SOAP_C_NILSTRING)) - return soap_element_null(soap, tag, id, type); - if (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, NULL)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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; - if (!**p && (!tag || *tag == '-')) - { soap->error = SOAP_NO_TAG; - return NULL; - } - } - else if (soap->null) - *p = NULL; - else - *p = (char*)SOAP_STR_EOS; - if (*soap->href) - 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 WITH_LEANER -#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) - return soap->error; - if (!**p && (soap->mode & SOAP_C_NILSTRING)) - return soap_element_null(soap, tag, id, type); - if (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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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, NULL)) - { if (!tag || *tag != '-' || soap->error != SOAP_NO_TAG) - return NULL; - soap->error = SOAP_OK; - } - 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; - if (!**p && (!tag || *tag == '-')) - { soap->error = SOAP_NO_TAG; - return NULL; - } - } - else if (soap->null) - *p = NULL; - else - *p = (wchar_t*)SOAP_STR_EOS; - if (*soap->href) - 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 -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static time_t -soap_timegm(struct tm *T) -{ -#if defined(HAVE_TIMEGM) - return timegm(T); -#else - time_t t, g, z; -#ifdef HAVE_GMTIME_R - struct tm tm, *tmp = &tm; -#else - struct tm *tmp; -#endif - t = mktime(T); - if (t == -1) - return -1; -#ifdef HAVE_GMTIME_R - gmtime_r(&t, tmp); -#else - tmp = gmtime(&t); -#endif - tmp->tm_isdst = 0; - g = mktime(tmp); - if (g == -1) - return -1; - z = g - t; - return t - z; -#endif -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_dateTime2s(struct soap *soap, time_t n) -{ struct tm T, *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); - /* 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); -#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+(pT->tm_isdst!=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+(pT->tm_isdst!=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)) - { -#ifdef __BORLANDC__ - ::ftime(&t); -#else - ftime(&t); -#endif - strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); - sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=0), abs(t.timezone)%60); - } - /* 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); - } -# else - if ((pT = localtime(&n))) - { -#ifdef __BORLANDC__ - ::ftime(&t); -#else - ftime(&t); -#endif - strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%S", pT); - sprintf(soap->tmpbuf + strlen(soap->tmpbuf), "%+03d:%02d", -t.timezone/60+(pT->tm_isdst!=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); - /* 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); -#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[32]; - const char *t; - memset((void*)&T, 0, sizeof(T)); - zone[sizeof(zone)-1] = '\0'; - if (strchr(s, '-')) - t = "%d-%d-%dT%d:%d:%d%31s"; - else if (strchr(s, ':')) - t = "%4d%2d%2dT%d:%d:%d%31s"; - else /* parse non-XSD-standard alternative ISO 8601 format */ - t = "%4d%2d%2dT%2d%2d%2d%31s"; - sscanf(s, t, &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 == '+' || *s == '-') - { int h = 0, m = 0; - if (s[3] == ':') - { sscanf(s, "%d:%d", &h, &m); - if (h < 0) - m = -m; - } - else - { m = (int)atol(s); - h = m / 100; - m = m % 100; - } - T.tm_hour -= h; - T.tm_min -= m; - } - T.tm_isdst = 0; - *p = soap_timegm(&T); - } - else - { T.tm_isdst = -1; - *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, NULL)) - 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 (*soap->href) - p = (time_t*)soap_id_forward(soap, soap->href, p, 0, t, 0, sizeof(time_t), 0, NULL); - else if (p) - { if (soap_s2dateTime(soap, soap_value(soap), p)) - return 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, const char *type) -{ int i; - const char *t = NULL; - if (tag && *tag != '-') - { if (soap->local_namespaces && (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++; - if (soap_element(soap, t, 0, type) - || soap_attribute(soap, "xmlns", soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS) - || soap_element_start_end_out(soap, NULL)) - return soap->error; - } - else - { t = tag; - if (soap_element_begin_out(soap, t, 0, type)) - return soap->error; - } - } - if (p && *p) - { if (soap_send(soap, *p)) - return soap->error; - } - if (t) - return soap_element_end_out(soap, t); - 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, NULL)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - { if (!(p = (char**)soap_malloc(soap, sizeof(char*)))) - return NULL; - } - if (soap->body) - { *p = soap_string_in(soap, 0, -1, -1); - if (!*p) - return NULL; - if (!**p && (!tag || *tag == '-')) - { soap->error = SOAP_NO_TAG; - return NULL; - } - } - else if (soap->null) - *p = NULL; - else - *p = (char*)SOAP_STR_EOS; - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_outwliteral(struct soap *soap, const char *tag, wchar_t *const*p, const char *type) -{ int i; - const char *t = NULL; - if (tag && *tag != '-') - { if (soap->local_namespaces && (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++; - if (soap_element(soap, t, 0, type) - || soap_attribute(soap, "xmlns", soap->local_namespaces[i].ns ? soap->local_namespaces[i].ns : SOAP_STR_EOS) - || soap_element_start_end_out(soap, NULL)) - return soap->error; - } - else - { t = tag; - if (soap_element_begin_out(soap, t, 0, type)) - return soap->error; - } - if (soap_send(soap, soap->tmpbuf)) - return soap->error; - } - if (p) - { wchar_t c; - const wchar_t *s = *p; - while ((c = *s++)) - { if (soap_pututf8(soap, (unsigned long)c)) - return soap->error; - } - } - if (t) - return soap_element_end_out(soap, t); - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#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, NULL)) - { if (soap->error != SOAP_NO_TAG || soap_unget(soap, soap_get(soap)) == SOAP_TT) - return NULL; - soap->error = SOAP_OK; - } - if (!p) - { if (!(p = (wchar_t**)soap_malloc(soap, sizeof(wchar_t*)))) - return NULL; - } - if (soap->body) - { *p = soap_wstring_in(soap, 0, -1, -1); - if (!*p) - return NULL; - if (!**p && (!tag || *tag == '-')) - { soap->error = SOAP_NO_TAG; - return NULL; - } - } - else if (soap->null) - *p = NULL; - else - *p = (wchar_t*)SOAP_STR_EOS; - if (soap->body && soap_element_end_in(soap, tag)) - return NULL; - return p; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -const char * -SOAP_FMAC2 -soap_value(struct soap *soap) -{ register size_t i; - register soap_wchar c = 0; - register char *s = soap->tmpbuf; - if (!soap->body) - return SOAP_STR_EOS; - do c = soap_get(soap); - while (soap_blank(c)); - for (i = 0; i < sizeof(soap->tmpbuf) - 1; i++) - { if (c == SOAP_TT || (int)c == EOF) - break; - *s++ = (char)c; - c = soap_get(soap); - } - for (s--; i > 0; i--, s--) - { if (!soap_blank(*s)) - break; - } - s[1] = '\0'; - if ((int)c == EOF || c == SOAP_TT) - soap_unget(soap, c); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element content value='%s'\n", soap->tmpbuf)); -#ifdef WITH_DOM - if ((soap->mode & SOAP_XML_DOM) && soap->dom) - soap->dom->data = soap_strdup(soap, soap->tmpbuf); -#endif - return soap->tmpbuf; /* return non-null pointer */ -} -#endif - -/******************************************************************************/ -#if !defined(WITH_LEANER) || !defined(WITH_NOHTTP) -#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' || c == '\n') - break; - if ((int)c == EOF) - return soap->error = SOAP_EOF; - *s++ = (char)c; - } - if (c != '\n') - c = soap_getchar(soap); /* got \r, now get \n */ - if (c == '\n') - { *s = '\0'; - if (i+1 == len) /* empty line: end of HTTP/MIME 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 -#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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Calculating the message size with attachments, current count=%lu\n", (unsigned long)count)); - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - { 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 content is %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); - /* count Content-Transfer-Encoding: ...\r\n */ - s = soap_code_str(mime_codes, content->encoding); - 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->description); - /* count \r\n...content */ - count += 2 + content->size; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Size of MIME attachment content is %lu bytes\n", (unsigned long)content->size)); - } - /* count \r\n--boundary-- */ - count += 6 + n; - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "New count is %lu bytes\n", (unsigned long)count)); - 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 (!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)content->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) -{ while (soap->dime.flags & SOAP_DIME_CF) - { if (soap_getdimehdr(soap)) - return soap->error; - if (soap_move(soap, soap->dime.size)) - return soap->error = SOAP_EOF; - } - if (soap_move(soap, ((soap->dime.size+3)&(~3))-soap_tell(soap))) - return soap->error = SOAP_EOF; - for (;;) - { register struct soap_multipart *content; - if (soap_getdimehdr(soap)) - break; - 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; - if (soap->error) - return soap->error; - soap_resolve_attachment(soap, content); - } - if (soap->error != SOAP_DIME_END) - return soap->error; - return soap->error = SOAP_OK; -} -#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-Disposition")) - content->id = soap_strdup(soap, soap_get_header_attribute(soap, val, "name")); - 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_code_int(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) -{ while (soap_get_mime_attachment(soap, NULL)) - ; - return soap->error; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_post_check_mime_attachments(struct soap *soap) -{ soap->imode |= SOAP_MIME_POSTCHECK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_check_mime_attachments(struct soap *soap) -{ if (soap->mode & SOAP_MIME_POSTCHECK) - return soap_get_mime_attachment(soap, NULL) != NULL; - return 0; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -struct soap_multipart * -SOAP_FMAC2 -soap_get_mime_attachment(struct soap *soap, void *handle) -{ register soap_wchar c = 0; - register size_t i, m = 0; - register char *s, *t = NULL; - register struct soap_multipart *content; - register short flag = 0; - if (!(soap->mode & SOAP_ENC_MIME)) - return NULL; - content = soap->mime.last; - if (!content) - { if (soap_getmimehdr(soap)) - return NULL; - content = soap->mime.last; - } - else if (content != soap->mime.first) - { if (soap->fmimewriteopen && ((content->ptr = (char*)soap->fmimewriteopen(soap, (void*)handle, content->id, content->type, content->description, content->encoding)) || soap->error)) - { if (!content->ptr) - return NULL; - } - } - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Parsing MIME content id=%s type=%s\n", content->id?content->id:"", content->type?content->type:"")); - if (!content->ptr && soap_new_block(soap)) - { soap->error = SOAP_EOM; - return NULL; - } - for (;;) - { if (content->ptr) - s = soap->tmpbuf; - else if (!(s = (char*)soap_push_block(soap, sizeof(soap->tmpbuf)))) - { soap->error = SOAP_EOM; - return NULL; - } - for (i = 0; i < sizeof(soap->tmpbuf); i++) - { if (m > 0) - { *s++ = *t++; - m--; - } - else - { if (!flag) - { c = soap_get1(soap); - if ((int)c == EOF) - { soap->error = SOAP_EOF; - return NULL; - } - } - if (flag || c == '\r') - { t = soap->msgbuf; - memset(t, 0, sizeof(soap->msgbuf)); - strcpy(t, "\n--"); - if (soap->mime.boundary) - strncat(t, soap->mime.boundary, sizeof(soap->msgbuf)-4); - do c = soap_getchar(soap); - while (c == *t++); - if ((int)c == EOF) - { soap->error = SOAP_EOF; - return NULL; - } - if (!*--t) - goto end; - *t = (char)c; - flag = (c == '\r'); - m = t - soap->msgbuf + 1 - flag; - t = soap->msgbuf; - c = '\r'; - } - *s++ = (char)c; - } - } - if (content->ptr && soap->fmimewrite) - { if ((soap->error = soap->fmimewrite(soap, (void*)content->ptr, soap->tmpbuf, i))) - break; - } - } -end: - *s = '\0'; /* force 0-terminated */ - if (content->ptr) - { if (!soap->error && soap->fmimewrite) - soap->error = soap->fmimewrite(soap, (void*)content->ptr, soap->tmpbuf, i); - if (soap->fmimewriteclose) - soap->fmimewriteclose(soap, (void*)content->ptr); - if (soap->error) - return NULL; - } - else - { content->size = soap_size_block(soap, i+1)-1; - content->ptr = soap_save_block(soap, NULL, 0); - } - soap_resolve_attachment(soap, content); - if (c == '-' && soap_getchar(soap) == '-') - { soap->mode &= ~SOAP_ENC_MIME; - if ((soap->mode & SOAP_MIME_POSTCHECK) && soap_end_recv(soap)) - return NULL; - } - else - { while (c != '\r' && (int)c != EOF && soap_blank(c)) - c = soap_getchar(soap); - if (c != '\r' || soap_getchar(soap) != '\n') - { soap->error = SOAP_MIME_ERROR; - return NULL; - } - if (soap_getmimehdr(soap)) - return NULL; - } - return content; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_match_cid(struct soap *soap, const char *s, const char *t) -{ register size_t n; - if (!s) - return 1; - if (!strcmp(s, t)) - return 0; - if (!strncmp(s, "cid:", 4)) - s += 4; - n = strlen(t); - if (*t == '<') - { t++; - n -= 2; - } - if (!strncmp(s, t, n) && !s[n]) - return 0; - soap_decode(soap->tmpbuf, sizeof(soap->tmpbuf), s, SOAP_STR_EOS); - if (!strncmp(soap->tmpbuf, t, n) && !soap->tmpbuf[n]) - return 0; - return 1; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_LEANER -#ifndef PALM_1 -static void -soap_resolve_attachment(struct soap *soap, struct soap_multipart *content) -{ if (content->id) - { register struct soap_xlist **xp = &soap->xlist; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Resolving attachment data for id=%s\n", content->id)); - while (*xp) - { register struct soap_xlist *xq = *xp; - if (!soap_match_cid(soap, xq->id, content->id)) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Found matching attachment %s for content id=%s\n", xq->id, content->id)); - *xp = xq->next; - *xq->ptr = (unsigned char*)content->ptr; - *xq->size = (int)content->size; - *xq->type = (char*)content->type; - if (content->options) - *xq->options = (char*)content->options; - else - *xq->options = (char*)content->description; - SOAP_FREE(soap, xq); - } - else - xp = &(*xp)->next; - } - } -} -#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_code_str(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) - { void *handle; - if (soap->fmimereadopen && ((handle = soap->fmimereadopen(soap, (void*)content->ptr, content->id, content->type, content->description)) || soap->error)) - { size_t size = content->size; - if (!handle) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimereadopen failed\n")); - return soap->error; - } - if (soap_putmimehdr(soap, content)) - return soap->error; - if (!size) - { if ((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 MIME\n")); - do - { size = soap->fmimeread(soap, handle, soap->tmpbuf, sizeof(soap->tmpbuf)); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimeread returned %lu bytes\n", (unsigned long)size)); - if (soap_send_raw(soap, soap->tmpbuf, size)) - break; - } while (size); - } - else - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error: cannot chunk streaming MIME (no HTTP chunking)\n")); - } - } - else - { do - { size_t bufsize; - if (size < sizeof(soap->tmpbuf)) - bufsize = size; - else - bufsize = sizeof(soap->tmpbuf); - if (!(bufsize = soap->fmimeread(soap, handle, soap->tmpbuf, bufsize))) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "fmimeread failed: insufficient data (%lu bytes remaining from %lu bytes)\n", (unsigned long)size, (unsigned long)content->size)); - soap->error = SOAP_EOF; - break; - } - if (soap_send_raw(soap, soap->tmpbuf, bufsize)) - break; - size -= bufsize; - } while (size); - } - if (soap->fmimereadclose) - soap->fmimereadclose(soap, handle); - } - else - { 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, "--"); -} -#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 = 64; - s = soap->mime.boundary = (char*)soap_malloc(soap, n + 1); - if (!s) - return; - } - strcpy(s, "=="); - s += 2; - n -= 4; - while (n) - { *s++ = soap_base64o[soap_random & 0x3F]; - n--; - } - strcpy(s, "=="); - } - if (!soap->mime.start) - soap->mime.start = ""; -} -#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; - if (soap->fmimeread) - return SOAP_OK; - 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 - -/******************************************************************************\ - * - * HTTP cookie handling - * -\******************************************************************************/ - -#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 && !strchr("()<>@,;:\\\"/[]?={}", 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 = SOAP_STR_EOS; - else if (*path == '/') - path++; - n = strlen(path); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Search cookie %s domain=%s path=%s\n", name, domain?domain:"(null)", path?path:"(null)")); - for (p = soap->cookies; p; p = p->next) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie in database: %s=%s domain=%s path=%s env=%hd\n", p->name, p->value?p->value:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", p->env)); - if (!strcmp(p->name, name) - && p->domain - && p->path - && !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; - if (!domain) - domain = soap->cookie_domain; - if (!path) - path = soap->cookie_path; - if (!path) - path = SOAP_STR_EOS; - else if (*path == '/') - path++; - q = soap_cookie(soap, name, domain, path); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set %scookie: %s=%s domain=%s path=%s\n", q ? "" : "new ", name, value?value:"(null)", domain?domain:"(null)", path?path:"(null)")); - if (!q) - { if ((q = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie)))) - { if ((q->name = (char*)SOAP_MALLOC(soap, strlen(name)+1))) - strcpy(q->name, name); - q->value = NULL; - q->domain = NULL; - q->path = NULL; - q->expire = 0; - q->maxage = -1; - q->version = 1; - q->secure = 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 && path && strcmp((*p)->path, path) < 0) - break; - if (n) - { q->next = *p; - *p = q; - } - else - { SOAP_FREE(soap, q->name); - SOAP_FREE(soap, q); - q = NULL; - } - } - } - else - q->modified = 1; - if (q) - { if (q->value) - { SOAP_FREE(soap, q->value); - q->value = NULL; - } - if (q->domain) - { SOAP_FREE(soap, q->domain); - q->domain = NULL; - } - if (q->path) - { SOAP_FREE(soap, q->path); - q->path = NULL; - } - if (value && *value && (q->value = (char*)SOAP_MALLOC(soap, strlen(value)+1))) - strcpy(q->value, value); - if (domain && (q->domain = (char*)SOAP_MALLOC(soap, strlen(domain)+1))) - strcpy(q->domain, domain); - if (path && (q->path = (char*)SOAP_MALLOC(soap, strlen(path)+1))) - strcpy(q->path, path); - q->session = 1; - q->env = 0; - } - 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) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie domain not set\n", name?name:"(null)")); - return; - } - if (!path) - path = soap->cookie_path; - if (!path) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Error in clear cookie %s: cookie path not set\n", name?name:"(null)")); - 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(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, 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 -char * -SOAP_FMAC2 -soap_env_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)) && p->env) - return p->value; - return NULL; -} - -/******************************************************************************/ -SOAP_FMAC1 -time_t -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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set cookie expiration max-age %ld: %s domain=%s path=%s\n", expire, name, domain?domain:"(null)", path?path:"(null)")); - if ((p = soap_cookie(soap, name, domain, path))) - { p->maxage = 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 -#ifdef WITH_OPENSSL - || (!p->env && !soap->ssl == !p->secure) -#endif - ) - { 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) - { strcpy(s, ";Domain="); - strcat(s, p->domain); - } - else if (soap->cookie_domain && (int)strlen(soap->cookie_domain) < tmp-s+4064) - { strcpy(s, ";Domain="); - strcat(s, soap->cookie_domain); - } - strcat(s, ";Path=/"); - s += strlen(s); - if (p->path) - t = p->path; - else - t = soap->cookie_path; - if (t) - { if (*t == '/') - t++; - if ((int)strlen(t) < tmp-s+4064) - { if (strchr(t, '%')) /* already URL encoded? */ - { strcpy(s, t); - s += strlen(s); - } - else - s += soap_encode_cookie(t, s, tmp-s+4064); - } - } - if (p->version > 0 && s-tmp < 4060) - { sprintf(s, ";Version=%u", p->version); - s += strlen(s); - } - if (p->maxage >= 0 && s-tmp < 4060) - { sprintf(s, ";Max-Age=%ld", p->maxage); - s += strlen(s); - } - if (s-tmp < 4073 - && (p->secure -#ifdef WITH_OPENSSL - || soap->ssl -#endif - )) - strcpy(s, ";Secure"); - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Set-Cookie: %s\n", tmp)); - if ((soap->error = 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; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending cookies for domain=%s path=%s\n", domain, path)); - if (*path == '/') - path++; - while ((q = *p)) - { if (q->expire && now > q->expire) - { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Cookie %s expired\n", q->name)); - SOAP_FREE(soap, q->name); - if (q->value) - SOAP_FREE(soap, q->value); - if (q->domain) - SOAP_FREE(soap, q->domain); - if (q->path) - SOAP_FREE(soap, q->path); - *p = q->next; - SOAP_FREE(soap, q); - } - else - { int flag; - char *t = q->domain; - size_t n = 0; - if (!t) - flag = 1; - else - { const char *r = strchr(t, ':'); - if (r) - n = r - t; - else - n = strlen(t); - flag = !strncmp(t, domain, n); - } - /* domain-level cookies */ - if (!flag) - { struct hostent *hostent = gethostbyname(domain); - if (hostent) - { char *r = strchr(hostent->h_name, '.'); - if (!r) - r = hostent->h_name; - flag = !strncmp(t, r, n); - } - } - if (flag - && (!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 && *q->path && (int)strlen(q->path) < tmp-s+4080) - { sprintf(s, ";$Path=\"/%s\"", (*q->path == '/' ? q->path + 1 : 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->error = soap->fposthdr(soap, "Cookie", tmp))) - return soap->error; - } - 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->path) - SOAP_FREE(soap, p->path); - p->path = t; - } - else - { if (path) - SOAP_FREE(soap, 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(soap, strlen(tmp)+1))) - strcpy(t, tmp); - } - else - t = NULL; - if (p) - { if (p->domain) - SOAP_FREE(soap, p->domain); - p->domain = t; - } - else - { if (domain) - SOAP_FREE(soap, domain); - domain = t; - } - } - else if (p && !soap_tag_cmp(tmp, "Path")) - { if (p->path) - SOAP_FREE(soap, p->path); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->path = (char*)SOAP_MALLOC(soap, strlen(tmp)+1))) - strcpy(p->path, tmp); - } - else - p->path = NULL; - } - else if (p && !soap_tag_cmp(tmp, "Domain")) - { if (p->domain) - SOAP_FREE(soap, p->domain); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { if ((p->domain = (char*)SOAP_MALLOC(soap, 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:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if ((p = (struct soap_cookie*)SOAP_MALLOC(soap, sizeof(struct soap_cookie)))) - { p->name = (char*)SOAP_MALLOC(soap, strlen(tmp)+1); - strcpy(p->name, tmp); - s = soap_decode_val(tmp, sizeof(tmp), s); - if (*tmp) - { p->value = (char*)SOAP_MALLOC(soap, strlen(tmp)+1); - strcpy(p->value, tmp); - } - else - p->value = NULL; - if (domain) - p->domain = domain; - else if (*soap->host) - { p->domain = (char*)SOAP_MALLOC(soap, strlen(soap->host)+1); - strcpy(p->domain, soap->host); - } - else - p->domain = NULL; - if (path) - p->path = path; - else if (soap->path && *soap->path) - { p->path = (char*)SOAP_MALLOC(soap, strlen(soap->path)+1); - strcpy(p->path, soap->path); - } - else - { p->path = (char*)SOAP_MALLOC(soap, 2); - strcpy(p->path, "/"); - } - p->expire = 0; - p->secure = 0; - p->version = version; - } - } - } - 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:"(null)", p->domain?p->domain:"(null)", p->path?p->path:"(null)", 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } - if (domain) - SOAP_FREE(soap, domain); - if (path) - SOAP_FREE(soap, 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 *copy, 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(copy, sizeof(struct soap_cookie)))) - return r; - **q = *p; - if (p->name) - { if (((*q)->name = (char*)SOAP_MALLOC(copy, strlen(p->name)+1))) - strcpy((*q)->name, p->name); - } - if (p->value) - { if (((*q)->value = (char*)SOAP_MALLOC(copy, strlen(p->value)+1))) - strcpy((*q)->value, p->value); - } - if (p->domain) - { if (((*q)->domain = (char*)SOAP_MALLOC(copy, strlen(p->domain)+1))) - strcpy((*q)->domain, p->domain); - } - if (p->path) - { if (((*q)->path = (char*)SOAP_MALLOC(copy, 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(soap, p->name); - if (p->value) - SOAP_FREE(soap, p->value); - if (p->domain) - SOAP_FREE(soap, p->domain); - if (p->path) - SOAP_FREE(soap, p->path); - SOAP_FREE(soap, p); - } -} - -/******************************************************************************/ -#endif /* WITH_COOKIES */ - -/******************************************************************************/ -#ifdef WITH_GZIP -#ifndef PALM_1 -static int -soap_getgziphdr(struct soap *soap) -{ int i; - soap_wchar c = 0, 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)c != 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_temp(soap); - soap_set_local_namespaces(soap); - soap->version = 0; /* don't assume we're parsing SOAP content by default */ -#ifndef WITH_NOIDREF - soap_free_iht(soap); -#endif - 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->action = NULL; - soap->status = 0; -#ifndef WITH_LEANER - soap->dom = 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; - soap->xlist = NULL; -#endif -#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 -#ifndef WITH_LEANER - 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 -#ifndef WITH_LEANER - 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 -#endif - { while (soap_blank(c)) - c = soap_getchar(soap); - } - if ((int)c == EOF) - return soap->error = SOAP_EOF; - soap_unget(soap, c); -#ifndef WITH_NOHTTP - /* if not XML or (start of)BOM or MIME/DIME/ZLIB, assume HTTP header */ - if (c != '<' && c != 0xEF && !(soap->mode & (SOAP_ENC_MIME | SOAP_ENC_DIME | SOAP_ENC_ZLIB))) - { soap->mode &= ~SOAP_IO; - soap->error = soap->fparse(soap); - if (soap->error && soap->error < SOAP_STOP) - { soap->keep_alive = 0; /* force close later */ - return soap->error; - } - if (soap->error == SOAP_STOP) - return soap->error; - if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK) - { soap->chunkbuflen = soap->buflen; - soap->buflen = soap->bufidx; - soap->chunksize = 0; - } -#ifndef WITH_LEANER - else if (soap->fpreparerecv && soap->buflen != soap->bufidx) - soap->fpreparerecv(soap, soap->buf + soap->bufidx, soap->buflen - soap->bufidx); -#endif - /* Note: fparse should not use soap_unget to push back last char */ - if (soap_get0(soap) == (int)EOF) - { if (soap->status == 200) - return soap->error = SOAP_NO_DATA; - return soap->error = soap->status; - } -#ifdef WITH_ZLIB - if (soap->zlib_in != SOAP_ZLIB_NONE) -#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 - if (soap->error) - { if (soap->error == SOAP_FORM && soap->fform) - { soap->error = soap->fform(soap); - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - } - return soap->error; - } - } -#endif -#ifndef WITH_LEANER - if (soap->mode & SOAP_ENC_MIME) - { if (soap_getmimehdr(soap)) - return soap->error; - if (soap->mime.start) - { do - { if (!soap->mime.last->id) - break; - if (!soap_match_cid(soap, soap->mime.start, soap->mime.last->id)) - break; - } while (soap_get_mime_attachment(soap, NULL)); - } - 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 WITH_NOHTTP -#ifndef PALM_1 -static int -http_parse(struct soap *soap) -{ char header[SOAP_HDRLEN], *s; - unsigned short get = 0, status = 0, k = 0; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Waiting for HTTP request/response...\n")); - *soap->endpoint = '\0'; - soap->length = 0; - soap->userid = NULL; - soap->passwd = NULL; - soap->action = NULL; - soap->authrealm = NULL; - 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)) - { if (soap->error == SOAP_EOF) - { soap->error = SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "EOF in HTTP header, continue anyway\n")); - break; - } - 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))) - { if (soap->error < SOAP_STOP) - return soap->error; - status = soap->error; - soap->error = SOAP_OK; - } - } - } - if ((s = strchr(soap->msgbuf, ' '))) - { k = (unsigned short)soap_strtoul(s, &s, 10); - if (!soap_blank(*s)) - k = 0; - } - else - k = 0; - } while (k == 100); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Finished HTTP header parsing, status = %d\n", k)); - 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 && (((get = !strncmp(soap->msgbuf, "GET ", 4))) || !strncmp(soap->msgbuf, "POST ", 5))) - { size_t m = strlen(soap->endpoint); - size_t n = m + (s - soap->msgbuf) - 5 - (!get); - if (m > n) - m = n; - if (n >= sizeof(soap->endpoint)) - n = sizeof(soap->endpoint) - 1; - strncpy(soap->path, soap->msgbuf + 4 + (!get), n - m); - soap->path[n - m] = '\0'; - strcat(soap->endpoint, soap->path); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Target endpoint='%s'\n", soap->endpoint)); - if (get) - { soap->error = soap->fget(soap); - if (soap->error == SOAP_OK) - soap->error = SOAP_STOP; /* prevents further processing */ - return soap->error; - } - if (status) - return soap->error = status; - } - soap->status = k; - if (k == 0 || k == 200 || (((k > 200 && k <= 299) || k == 400 || k == 500) && ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK || soap->length > 0))) - return SOAP_OK; - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "HTTP error %d\n", k)); - return soap_set_receiver_error(soap, "HTTP Error", soap->msgbuf, k); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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")) - { soap->http_content = soap_strdup(soap, val); - 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_get_header_attribute(soap, val, "multipart/form-data")) - { 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 *")) - { int 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 == '"') - { 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, "Cookie2") - || !soap_tag_cmp(key, "Set-Cookie") - || !soap_tag_cmp(key, "Set-Cookie2")) - soap_getcookies(soap, val); -#endif - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#endif - -/******************************************************************************/ -#if !defined(WITH_NOHTTP) || !defined(WITH_LEANER) -#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 -#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 && strlen(soap->mime.boundary) + strlen(soap->mime.start) < sizeof(soap->tmpbuf) - 80 ) - { const char *s; - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - s = "application/dime"; - else if (soap->version == 2) - { if (soap->mode & SOAP_ENC_MTOM) - s = "application/xop+xml; charset=utf-8; type=application/soap+xml"; - else - 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->mode & SOAP_ENC_MTOM)) - { 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)) + (soap->dime.type ? ((strlen(soap->dime.type)+3)&(~3)) : 0); - } - if ((soap->mode & SOAP_ENC_DIME) && !(soap->mode & SOAP_ENC_MTOM)) - 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, NULL)) - { -#ifndef WITH_LEAN - if (!soap_element_begin_in(soap, "html", 0, NULL)) - { /* get HTML from buffer, stop receiving to avoid HTML parsing issues */ - char *s; -#ifndef WITH_NOIO - size_t (*f)(struct soap*, char*, size_t) = soap->frecv; - soap->frecv = frecv_stop; -#endif - soap_revert(soap); - s = soap_string_in(soap, 1, -1, -1); -#ifndef WITH_NOIO - soap->frecv = f; -#endif - return soap_set_receiver_error(soap, "HTTP Error", s, SOAP_HTTP_ERROR); - } -#endif - 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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(soap, p[1].out); - if ((p[1].out = (char*)SOAP_MALLOC(soap, 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) -{ soap->part = SOAP_END_ENVELOPE; - return soap_element_end_in(soap, "SOAP-ENV:Envelope"); -} -#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; -#ifndef WITH_LEAN - if ((soap->mode & SOAP_XML_SEC) && soap_set_attr(soap, "wsu:Id", "Body")) - return soap->error; -#endif - if (soap_element(soap, "SOAP-ENV:Body", 0, NULL)) - 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_END_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; - if (soap_element_begin_in(soap, "SOAP-ENV:Body", 0, NULL)) - return soap->error; - if (!soap->body) - soap->part = SOAP_NO_BODY; - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_body_end_in(struct soap *soap) -{ if (soap->part == SOAP_NO_BODY) - return SOAP_OK; - soap->part = SOAP_END_BODY; - return soap_element_end_in(soap, "SOAP-ENV:Body"); -} -#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; - else if (soap->error == SOAP_OK && soap->fheader) - soap->error = soap->fheader(soap); - 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] = '\0'; - soap->host[0] = '\0'; - soap->path[0] = '/'; - soap->path[1] = '\0'; - soap->port = 80; - if (!endpoint || !*endpoint) - return; -#ifdef WITH_OPENSSL - if (!soap_tag_cmp(endpoint, "https:*")) - soap->port = 443; -#endif - strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint) - 1); - soap->endpoint[sizeof(soap->endpoint) - 1] = '\0'; - 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; -#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 - for (i = 0; i < n; i++) - { soap->host[i] = s[i]; - if (s[i] == '/' || s[i] == ':') - break; - } -#endif - 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, 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); -#ifndef WITH_LEANER - if (soap->fconnect) - { if ((soap->error = soap->fconnect(soap, endpoint, soap->host, soap->port))) - return soap->error; - } - else -#endif - if (soap->fopen && *soap->host) - { soap->status = http_command; - if (!soap->keep_alive || !soap_valid_socket(soap->socket) || strcmp(soap->host, host) || soap->port != port || !soap->fpoll || soap->fpoll(soap)) - { soap->keep_alive = 0; /* to force close */ - soap->omode &= ~SOAP_IO_UDP; /* to force close */ - soap_closesock(soap); - DBGLOG(TEST,SOAP_MESSAGE(fdebug, "Connect/reconnect to host='%s' path='%s' port=%d\n", soap->host, soap->path, soap->port)); -#ifdef WITH_UDP - if (!strncmp(endpoint, "soap.udp:", 9)) - soap->omode |= SOAP_IO_UDP; -#endif - 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); - } - } - count = soap_count_attachments(soap); - if (soap_begin_send(soap)) - return soap->error; - if (http_command != SOAP_POST) - { soap->mode &= ~SOAP_IO; - soap->mode |= SOAP_IO_BUFFER; - } -#ifndef WITH_NOHTTP - soap->action = soap_strdup(soap, action); - 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; -#ifndef WITH_LEANER - if ((k & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = k; - } - if (http_command != SOAP_POST) - return soap_end_send(soap); -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2base64(struct soap *soap, const unsigned char *s, char *t, int n) -{ register int 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, int *n) -{ register int i, j, c; - register unsigned long m; - register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = (strlen(s) + 3) / 4 * 3; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - 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) - { int b = soap_base64i[c]; - if (b >= 64) - { soap->error = SOAP_TYPE; - return NULL; - } - m = (m << 6) + b; - j++; - } - else if (!soap_blank(c + '+')) - { soap->error = SOAP_TYPE; - return NULL; - } - } - *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 WITH_LEAN -SOAP_FMAC1 -char* -SOAP_FMAC2 -soap_s2hex(struct soap *soap, const unsigned char *s, char *t, int n) -{ register char *p; - if (!t) - t = (char*)soap_malloc(soap, 2 * n + 1); - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - t[0] = '\0'; - if (s) - { for (; n > 0; n--) - { register int m = *s++; - *t++ = (char)((m >> 4) + (m > 159 ? 'a' - 10 : '0')); - m &= 0x0F; - *t++ = (char)(m + (m > 9 ? 'a' - 10 : '0')); - } - } - *t++ = '\0'; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -SOAP_FMAC1 -const char* -SOAP_FMAC2 -soap_hex2s(struct soap *soap, const char *s, char *t, size_t l, int *n) -{ register const char *p; - if (!s || !*s) - { if (n) - *n = 0; - if (soap->error) - return NULL; - return SOAP_NON_NULL; - } - if (!t) - { l = strlen(s) / 2; - t = (char*)soap_malloc(soap, l); - } - if (!t) - { soap->error = SOAP_EOM; - return NULL; - } - p = t; - while (l) - { register int d1, d2; - d1 = *s++; - if (!d1) - break; - d2 = *s++; - if (!d2) - break; - *t++ = ((d1 >= 'A' ? (d1 & 0x7) + 9 : d1 - '0') << 4) + (d2 >= 'A' ? (d2 & 0x7) + 9 : d2 - '0'); - l--; - } - if (n) - *n = t - p; - return p; -} -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_puthttphdr(struct soap *soap, int status, size_t count) -{ if (soap->status != SOAP_GET) - { register const char *s = "text/xml; charset=utf-8"; - register int err = SOAP_OK; -#ifndef WITH_LEANER - register const char *r = NULL; -#endif - if (status == SOAP_FILE && soap->http_content) - s = soap->http_content; - else if (status == SOAP_HTML) - s = "text/html; charset=utf-8"; - else if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)) - { if (soap->version == 2) - s = "application/soap+xml; charset=utf-8"; - } -#ifndef WITH_LEANER - if (soap->mode & (SOAP_ENC_DIME | SOAP_ENC_MTOM)) - { if (soap->mode & SOAP_ENC_MTOM) - { r = s; - s = "application/xop+xml; charset=utf-8"; - } - else - s = "application/dime"; - } - if ((soap->mode & SOAP_ENC_MIME) && soap->mime.boundary && strlen(soap->mime.boundary) + strlen(soap->mime.start ? soap->mime.start : SOAP_STR_EOS) < sizeof(soap->tmpbuf) - 80) - { register const char *t = strchr(s, ';'); - sprintf(soap->tmpbuf, "multipart/related; boundary=\"%s\"; type=\"", soap->mime.boundary); - if (t) - strncat(soap->tmpbuf, s, t - s); - else - strcat(soap->tmpbuf, s); - if (soap->mime.start) - { strcat(soap->tmpbuf, "\"; start=\""); - strcat(soap->tmpbuf, soap->mime.start); - } - strcat(soap->tmpbuf, "\""); - if (r) - { strcat(soap->tmpbuf, "; start-info=\""); - strcat(soap->tmpbuf, r); - strcat(soap->tmpbuf, "\""); - } - s = soap->tmpbuf; - } -#endif - if (s && (err = soap->fposthdr(soap, "Content-Type", s))) - return err; -#ifdef WITH_ZLIB - if (soap->omode & SOAP_ENC_ZLIB) - { err = soap->fposthdr(soap, "Content-Encoding", soap->zlib_out == SOAP_ZLIB_GZIP ? "gzip" : "deflate"); - if (err) - return err; - } -#endif -#ifndef WITH_LEANER - if ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK) - err = soap->fposthdr(soap, "Transfer-Encoding", "chunked"); - else -#endif - if (s) - { 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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_get(struct soap *soap) -{ return SOAP_GET_METHOD; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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"; - else - s = "POST"; -#ifdef PALM - if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6)) && strncmp(endpoint, "_beam:", 6) && strncmp(endpoint, "_local:", 7) && strncmp(endpoint, "_btobex:", 8)) -#else - if (!endpoint || (soap_tag_cmp(endpoint, "http:*") && soap_tag_cmp(endpoint, "https:*") && strncmp(endpoint, "httpg:", 6))) -#endif - return SOAP_OK; - if (strlen(endpoint) + strlen(soap->http_version) > sizeof(soap->tmpbuf) - 80) - return soap->error = SOAP_EOM; - if (soap->proxy_host && soap_tag_cmp(endpoint, "https:*")) - sprintf(soap->tmpbuf, "%s %s HTTP/%s", s, endpoint, soap->http_version); - else - sprintf(soap->tmpbuf, "%s /%s HTTP/%s", s, (*path == '/' ? path + 1 : 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 (soap->status != SOAP_GET && (soap->version == 1 || (action && *action && strlen(action) < sizeof(soap->tmpbuf) - 2))) - { sprintf(soap->tmpbuf, "\"%s\"", action?action:""); - if ((err = soap->fposthdr(soap, "SOAPAction", soap->tmpbuf))) - return err; - } - return soap->fposthdr(soap, NULL, NULL); -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#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 -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -static int -http_response(struct soap *soap, int status, size_t count) -{ register int err; -#ifdef WMW_RPM_IO - if (soap->rpmreqid) - httpOutputEnable(soap->rpmreqid); -#endif - if (strlen(soap->http_version) > 4) - return soap->error = SOAP_EOM; - if (!status || status == SOAP_HTML || status == SOAP_FILE) - { const char *s; - if (count || ((soap->omode & SOAP_IO) == SOAP_IO_CHUNK)) - s = "200 OK"; - else - s = "202 ACCEPTED"; - DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Status = %s\n", s)); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif - { 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; - } - 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; -#ifndef WITH_LEAN - if (status == 401) - { sprintf(soap->tmpbuf, "Basic realm=\"%s\"", strlen(soap->authrealm) < sizeof(soap->tmpbuf) - 14 ? 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; - } -#endif - } - 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)); -#ifdef WMW_RPM_IO - if (soap->rpmreqid || soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* RPM behaves as if standalone */ -#else - if (soap_valid_socket(soap->master) || soap_valid_socket(soap->socket)) /* standalone application */ -#endif - { 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))) /* CGI */ - 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 -#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; -#ifndef WITH_NOHTTP - 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; -#ifndef WITH_LEANER - if ((n & SOAP_IO) == SOAP_IO_CHUNK) - { if (soap_flush(soap)) - return soap->error; - } -#endif - soap->mode = n; - } -#endif - return SOAP_OK; -} -#endif - -/******************************************************************************/ -#ifndef WITH_LEAN -static const char* -soap_set_validation_fault(struct soap *soap, const char *s, const char *t) -{ if (*soap->tag) - sprintf(soap->msgbuf, "Validation constraint violation: %s%s in element <%s>", s, t?t:SOAP_STR_EOS, soap->tag); - else - sprintf(soap->msgbuf, "Validation constraint violation: %s%s", s, t?t:SOAP_STR_EOS); - 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 (soap->fseterror) - soap->fseterror(soap, c, s); - 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_TYPE: - *s = soap_set_validation_fault(soap, "data type mismatch ", soap->type); - break; - case SOAP_SYNTAX_ERROR: - *s = "Well-formedness violation"; - break; - case SOAP_NO_TAG: - *s = "No XML element tag"; - 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 error", NULL); - break; - case SOAP_USER_ERROR: - *s = "User error"; - 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_NO_DATA: - *s = "Data required for operation"; - break; - case SOAP_GET_METHOD: - *s = "HTTP GET method not implemented"; - break; - case SOAP_EOM: - *s = "Out of memory"; - break; - case SOAP_MOE: - *s = "Memory overflow or memory corruption error"; - 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_DUPLICATE_ID: - *s = soap_set_validation_fault(soap, "multiple definitions of id ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:DuplicateID"; - break; - case SOAP_MISSING_ID: - *s = soap_set_validation_fault(soap, "missing id for ref ", soap->id); - if (soap->version == 2) - *soap_faultsubcode(soap) = "SOAP-ENC:MissingID"; - break; - case SOAP_HREF: - *s = soap_set_validation_fault(soap, "incompatible object ref ", soap->id); - break; - case SOAP_FAULT: - break; -#ifndef WITH_NOIO - case SOAP_UDP_ERROR: - *s = "Message too large for UDP packet"; - break; - case SOAP_TCP_ERROR: - *s = tcp_error(soap); - break; -#endif - case SOAP_HTTP_ERROR: - *s = "An HTTP processing error occurred"; - break; - case SOAP_SSL_ERROR: -#ifdef WITH_OPENSSL - *s = "SSL error"; -#else - *s = "OpenSSL not installed: recompile with -DWITH_OPENSSL"; -#endif - break; - case SOAP_PLUGIN_ERROR: - *s = "Plugin registry error"; - break; - case SOAP_DIME_ERROR: - *s = "DIME format error"; - break; - case SOAP_DIME_HREF: - *s = "DIME href to missing attachment"; - break; - case SOAP_DIME_MISMATCH: - *s = "DIME version/transmission error"; - break; - case SOAP_DIME_END: - *s = "End of DIME error"; - break; - case SOAP_MIME_ERROR: - *s = "MIME format error"; - break; - case SOAP_MIME_HREF: - *s = "MIME href to missing attachment"; - break; - case SOAP_MIME_END: - *s = "End of MIME 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/gzip not installed for (de)compression: recompile with -DWITH_GZIP"; -#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, "min/maxOccurs violation", NULL); - break; - case SOAP_LENGTH: - *s = soap_set_validation_fault(soap, "content length violation", NULL); - break; - case SOAP_FD_EXCEEDED: - *s = "Maximum number of open connections was reached"; - break; - case SOAP_STOP: - *s = "Stopped: no response sent"; - break; -#endif - case SOAP_EOF: -#ifndef WITH_NOIO - strcpy(soap->msgbuf, soap_strerror(soap)); -#ifndef WITH_LEAN - if (strlen(soap->msgbuf) + 25 < sizeof(soap->msgbuf)) - { memmove(soap->msgbuf + 25, soap->msgbuf, strlen(soap->msgbuf) + 1); - memcpy(soap->msgbuf, "End of file or no input: ", 25); - } -#endif - *s = soap->msgbuf; - break; -#else - *s = "End of file or no input"; - break; -#endif - default: -#ifndef WITH_NOHTTP -#ifndef WITH_LEAN - if (soap->error > 200 && soap->error < 600) - { sprintf(soap->msgbuf, "HTTP Error: %d %s", soap->error, http_error(soap, soap->error)); - *s = soap->msgbuf; - } - else -#endif -#endif - { sprintf(soap->msgbuf, "Error %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; - int r = 1; - 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); -#ifndef WITH_NOIO -#ifndef WITH_LEAN - if (soap_valid_socket(soap->socket)) - { struct timeval timeout; - fd_set rfd, sfd; - timeout.tv_sec = 0; - timeout.tv_usec = 0; - FD_ZERO(&rfd); - FD_ZERO(&sfd); - FD_SET((SOAP_SOCKET)soap->socket, &rfd); - FD_SET((SOAP_SOCKET)soap->socket, &sfd); - r = select((SOAP_SOCKET)(soap->socket + 1), &rfd, &sfd, NULL, &timeout); - if (r > 0) - { if (!FD_ISSET((SOAP_SOCKET)soap->socket, &sfd) - || (FD_ISSET((SOAP_SOCKET)soap->socket, &rfd) - && recv((SOAP_SOCKET)soap->socket, soap->tmpbuf, 1, MSG_PEEK) < 0)) - r = 0; - } - } -#endif -#endif - if ((status != SOAP_EOF || (!soap->recv_timeout && !soap->send_timeout)) && r > 0) - { 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); - } - soap_end_count(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 WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_send_empty_response(struct soap *soap, int status) -{ register soap_mode m = soap->omode; - soap->count = 0; - if ((m & SOAP_IO) == SOAP_IO_CHUNK) - { soap->omode &= ~SOAP_IO_CHUNK; - soap->omode |= SOAP_IO_BUFFER; - } - if (soap_response(soap, status) || soap_end_send(soap)) - { soap->omode = m; - return soap_closesock(soap); - } - soap->omode = m; - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOHTTP -#ifndef PALM_1 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_recv_empty_response(struct soap *soap) -{ if (soap_begin_recv(soap) || soap_end_recv(soap)) - { if (soap->error != 202) - return soap_closesock(soap); - soap->error = SOAP_OK; - } - return SOAP_OK; -} -#endif -#endif - -/******************************************************************************/ -#ifndef WITH_NOIO -#ifndef PALM_1 -static const char* -soap_strerror(struct soap *soap) -{ register int err = soap->errnum; - if (err) - { -#ifndef WIN32 - return strerror(err); -#else -#ifndef UNDER_CE - DWORD len; - *soap->msgbuf = '\0'; - len = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)soap->msgbuf, (DWORD)sizeof(soap->msgbuf), NULL); -#else - DWORD i, len; - *soap->msgbuf = '\0'; - len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, 0, (LPTSTR)soap->msgbuf, (DWORD)(sizeof(soap->msgbuf)/sizeof(TCHAR)), NULL); - for (i = 0; i <= len; i++) - { if (((TCHAR*)soap->msgbuf)[i] < 0x80) - soap->msgbuf[i] = (char)((TCHAR*)soap->msgbuf)[i]; - else - soap->msgbuf[i] = '?'; - } -#endif - return soap->msgbuf; -#endif - } - return "Operation interrupted or timed out"; -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_set_error(struct soap *soap, const char *faultcode, const char *faultsubcode, const char *faultstring, const char *faultdetail, int soaperror) -{ *soap_faultcode(soap) = faultcode; - if (faultsubcode) - *soap_faultsubcode(soap) = faultsubcode; - *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", NULL, 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", NULL, faultstring, faultdetail, soaperror); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -static int -soap_copy_fault(struct soap *soap, const char *faultcode, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ char *r = NULL, *s = NULL, *t = NULL; - if (faultsubcode) - r = soap_strdup(soap, faultsubcode); - if (faultstring) - s = soap_strdup(soap, faultstring); - if (faultdetail) - t = soap_strdup(soap, faultdetail); - return soap_set_error(soap, faultcode, r, 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_sender_fault_subcode(soap, NULL, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_sender_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Sender" : "SOAP-ENV:Client", faultsubcode, 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_receiver_fault_subcode(soap, NULL, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -SOAP_FMAC1 -int -SOAP_FMAC2 -soap_receiver_fault_subcode(struct soap *soap, const char *faultsubcode, const char *faultstring, const char *faultdetail) -{ return soap_copy_fault(soap, soap->version == 2 ? "SOAP-ENV:Receiver" : "SOAP-ENV:Server", faultsubcode, faultstring, faultdetail); -} -#endif - -/******************************************************************************/ -#ifndef PALM_2 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault(struct soap *soap, FILE *fd) -{ if (soap_check_state(soap)) - fprintf(fd, "Error: soap struct not initialized\n"); - else if (soap->error) - { const char *c, *v = NULL, *s, **d; - d = soap_faultcode(soap); - if (!*d) - soap_set_fault(soap); - c = *d; - if (soap->version == 2) - v = *soap_faultsubcode(soap); - s = *soap_faultstring(soap); - d = soap_faultdetail(soap); - fprintf(fd, "%s%d fault: %s [%s]\n\"%s\"\nDetail: %s\n", soap->version ? "SOAP 1." : "Error ", soap->version ? (int)soap->version : soap->error, c, v ? v : "no subcode", s ? s : "[no reason]", d && *d ? *d : "[no detail]"); - } -} -#endif -#endif - -/******************************************************************************/ -#ifndef PALM_1 -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 -void -SOAP_FMAC2 -soap_print_fault_location(struct soap *soap, FILE *fd) -{ -#ifndef WITH_LEAN - int i, j, c1, c2; - if (soap->error && soap->bufidx <= soap->buflen && soap->buflen > 0 && soap->buflen <= SOAP_BUFLEN) - { i = (int)soap->bufidx - 1; - if (i <= 0) - i = 0; - c1 = soap->buf[i]; - soap->buf[i] = '\0'; - if ((int)soap->buflen >= i + 1024) - j = i + 1023; - else - j = (int)soap->buflen - 1; - c2 = soap->buf[j]; - soap->buf[j] = '\0'; - fprintf(fd, "%s%c\n\n", soap->buf, c1); - if (soap->bufidx < soap->buflen) - fprintf(fd, "%s\n", soap->buf + soap->bufidx); - soap->buf[i] = c1; - soap->buf[j] = c2; - } -#endif -} -#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(soap, 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(soap, 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 - -/******************************************************************************\ - * - * C++ soap struct methods - * -\******************************************************************************/ - -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::soap() -{ soap_init(this); -} -#endif -#endif - -/******************************************************************************/ -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::soap(soap_mode m) -{ soap_init1(this, m); -} -#endif -#endif - -/******************************************************************************/ -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::soap(soap_mode im, soap_mode om) -{ soap_init2(this, im, om); -} -#endif -#endif - -/******************************************************************************/ -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::soap(struct soap& soap) -{ soap_copy_context(this, &soap); -} -#endif -#endif - -/******************************************************************************/ -#ifdef __cplusplus -#ifndef WITH_LEAN -soap::~soap() -{ soap_destroy(this); - soap_end(this); - soap_done(this); -} -#endif -#endif - -/******************************************************************************/ diff --git a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.h b/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.h deleted file mode 100644 index 44efa13..0000000 --- a/org.glite.security.gsoap-plugin/src/stdsoap2_2.7.9d.h +++ /dev/null @@ -1,2184 +0,0 @@ -/* - -stdsoap2.h 2.7.9d - -gSOAP runtime - -gSOAP XML Web services tools -Copyright (C) 2000-2007, Robert van Engelen, Genivia Inc., All Rights Reserved. -This part of the software is released under one of the following licenses: -GPL, the gSOAP public license, or Genivia's license for commercial use. --------------------------------------------------------------------------------- -Contributors: - -Wind River Systems, Inc., for the following additions (marked WR[...]): - - vxWorks compatible --------------------------------------------------------------------------------- -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-2007, 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 --------------------------------------------------------------------------------- -A commercial use license is available from Genivia, Inc., contact@genivia.com --------------------------------------------------------------------------------- -*/ - -#ifdef WITH_SOAPDEFS_H -# include "soapdefs.h" /* include user-defined stuff */ -#endif - -#ifndef _THREAD_SAFE -# define _THREAD_SAFE -#endif - -#ifndef OPENSERVER -# ifndef _REENTRANT -# define _REENTRANT -# endif -#endif - -#ifndef SOAP_FMAC1 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC1 -#endif - -#ifndef SOAP_FMAC2 /* stdsoap2.h declaration macro */ -# define SOAP_FMAC2 -#endif - -#ifndef SOAP_FMAC3 /* (de)serializer declaration macro */ -# define SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC3S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC3S SOAP_FMAC3 -#endif - -#ifndef SOAP_FMAC4 /* (de)serializer declaration macro */ -# define SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC4S /* string converter for (de)serializer declaration macro */ -# define SOAP_FMAC4S SOAP_FMAC4 -#endif - -#ifndef SOAP_FMAC5 /* stub/skeleton declaration macro */ -# define SOAP_FMAC5 -#endif - -#ifndef SOAP_FMAC6 /* stub/skeleton declaration macro */ -# define SOAP_FMAC6 -#endif - -#ifndef SOAP_CMAC /* class declaration macro */ -# define SOAP_CMAC -#endif - -#ifndef SOAP_NMAC /* namespace table declaration macro */ -# define SOAP_NMAC -#endif - -#ifndef SOAP_SOURCE_STAMP -# define SOAP_SOURCE_STAMP(str) -#endif - -/* gSOAP 2.7.4 and higher: fast look-aside buffering is stable */ -#ifndef WITH_FAST -# define WITH_FAST -#endif - -#ifdef WITH_LEANER -# ifndef WITH_LEAN -# define WITH_LEAN -# endif -#endif - -#ifdef WITH_LEAN -# ifdef WITH_COOKIES -# error "Cannot build WITH_LEAN code WITH_COOKIES enabled" -# endif -#endif - -#ifndef STDSOAP_H -#define STDSOAP_H - -#if defined(__vxworks) || defined(__VXWORKS__) -# define VXWORKS -#endif - -#ifdef _WIN32 -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef _WIN32_WCE -# ifndef UNDER_CE -# define UNDER_CE _WIN32_WCE -# endif -#endif - -#ifdef UNDER_CE -# ifndef WIN32 -# define WIN32 -# endif -#endif - -#ifdef __BORLANDC__ -# ifdef __WIN32__ -# ifndef WIN32 -# define WIN32 -# endif -# endif -#endif - -#ifdef __CYGWIN__ -# ifndef CYGWIN -# define CYGWIN -# endif -#endif - -#ifdef __SYMBIAN32__ -# define SYMBIAN -# undef WIN32 -#endif - -#if defined(__palmos__) || defined(PALM_GCC) || defined(__PALMOS_TRAPS__) -# ifndef PALM -# define PALM -# endif -#endif - -#if defined(__hpux) -# ifndef HP_UX -# define HP_UX -# endif -#endif - -#if defined(__alpha) && !defined(__VMS) -# ifndef TRU64 -# define TRU64 -# endif -#endif - -#ifdef __MVS__ -# ifndef OS390 -# define OS390 -# endif -#endif - -#ifdef HAVE_CONFIG_H -# include "config.h" -# ifdef WITH_OPENSSL -# ifndef HAVE_OPENSSL_SSL_H -# undef WITH_OPENSSL -# endif -# endif -#else -# if defined(UNDER_CE) -# define WITH_LEAN -# define HAVE_SSCANF -# elif defined(WIN32) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%I64d" -# define SOAP_ULONG_FORMAT "%I64u" -# elif defined(CYGWIN) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__APPLE__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(_AIXVERSION_431) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(HP_UX) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(FREEBSD) || defined(__FreeBSD__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_GETTIMEOFDAY -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%qd" -# define SOAP_ULONG_FORMAT "%qu" -# elif defined(__VMS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__GLIBC__) || defined(__GNU__) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_STRTOLL -# define HAVE_STRTOULL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_TIMEGM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define HAVE_ISNAN -# elif defined(TRU64) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_GETTIMEOFDAY -# define HAVE_SYS_TIMEB_H -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define __USE_STD_IOSTREAM -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -# elif defined(MAC_CARBON) -# define WITH_NOIO -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(PALM) -# define WITH_LEAN -# define HAVE_STRTOD /* strtod() is defined in palmFunctions.h */ -# include /* Needs to be included before unix headers */ -# include -# define IGNORE_STDIO_STUBS -# include -# define O_NONBLOCK FNONBIO -# include -# include "palmFunctions.h" -# elif defined(SYMBIAN) -# define WITH_LEAN -# define WITH_NONAMESPACES -# define HAVE_STRTOD /* use STRTOD since sscanf doesn't seem to work */ -# include -# include -# elif defined(VXWORKS) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_PGMTIME_R -# define HAVE_PLOCALTIME_R -# define HAVE_MKTIME -# elif defined(OS390) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(AS400) -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# elif defined(__QNX__) || defined(QNX) -/* QNX does not have a working version of strtof */ -# undef HAVE_STRTOF -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# define LONG64 long -# define ULONG64 unsigned LONG64 -# define SOAP_LONG_FORMAT "%ld" -# define SOAP_ULONG_FORMAT "%lu" -# else -/* Default asumptions on supported functions */ -# define HAVE_STRRCHR -# define HAVE_STRTOD -# define HAVE_SSCANF -# define HAVE_STRTOL -# define HAVE_STRTOUL -# define HAVE_SYS_TIMEB_H -# define HAVE_FTIME -# define HAVE_RAND_R -# define HAVE_GETHOSTBYNAME_R -# define HAVE_GMTIME_R -# define HAVE_LOCALTIME_R -# define HAVE_WCTOMB -# define HAVE_MBTOWC -# endif -#endif - -#ifndef WITH_NOSTDLIB -# include -# ifndef PALM -# include -# include -# endif -# include -# include -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -# include -# include -#endif - -#ifdef WITH_NOHTTP -# ifndef WITH_NOIO -# define WITH_NOIO -# undef WITH_COOKIES -# endif -#endif - -#ifndef UNDER_CE -# ifndef PALM -# ifndef WITH_NOIO -# include -# include -# endif -# ifndef WITH_LEAN -# ifdef HAVE_SYS_TIMEB_H -# include /* for ftime() */ -# endif -# include -# endif -# endif -#endif - -#ifdef OPENSERVER -# include -# include -# include - extern int h_errno; -#endif - -#ifndef WITH_NOIO -# ifndef WIN32 -# ifndef PALM -# include -# ifdef VXWORKS -# include -# include -# endif -# ifndef VXWORKS -# ifndef SYMBIAN -# include -# endif -# endif -# ifdef SUN_OS -# include /* SUN */ -# include /* SUN < 2.8 (?) */ -# endif -# ifdef VXWORKS -# ifdef _WRS_KERNEL -# include -# endif -# else -# include -# endif -# include -# ifdef OS390 -# include -# else -# include /* TCP_NODELAY */ -# endif -# include -# endif -# endif -#endif - -#ifdef WITH_FASTCGI -# include -#endif - -#ifdef WITH_OPENSSL -# define OPENSSL_NO_KRB5 -# include -# include -# include -# include -# include -# ifndef ALLOW_OLD_VERSIONS -# if (OPENSSL_VERSION_NUMBER < 0x00905100L) -# error "Must use OpenSSL 0.9.6 or later" -# endif -# endif -#endif - -#ifdef WITH_GZIP -# ifndef WITH_ZLIB -# define WITH_ZLIB -# endif -#endif - -#ifdef WITH_CASEINSENSITIVETAGS -# define SOAP_STRCMP soap_tag_cmp /* case insensitve XML element/attribute names */ -#else -# define SOAP_STRCMP strcmp /* case sensitive XML element/attribute names */ -#endif - -#ifdef WITH_ZLIB -# include -#endif - -#ifndef WITH_NOSTDLIB -# ifndef PALM -# include /* for isnan() */ -# endif -#endif - -/* #define DEBUG */ /* Uncomment to debug sending (in file SENT.log) receiving (in file RECV.log) and messages (in file TEST.log) */ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef WIN32 -# ifndef UNDER_CE -# include -# include -# endif -# include -/* # include */ /* Alternative: use winsock2 (not available with eVC) */ -# ifdef WITH_IPV6 -# include -# include -# endif -#else -# ifdef VXWORKS -# include -# include -# include -# endif -# ifndef WITH_NOIO -# ifndef PALM -# include -# include -# include -# include -# endif -# endif -#endif - -/* Portability: define SOAP_SOCKLEN_T */ -#if defined(_AIX) -# define SOAP_SOCKLEN_T socklen_t -#elif defined(SOCKLEN_T) -# define SOAP_SOCKLEN_T SOCKLEN_T -#elif defined(__socklen_t_defined) || defined(_SOCKLEN_T) || defined(CYGWIN) || defined(FREEBSD) || defined(__FreeBSD__) || defined(__QNX__) || defined(QNX) -# define SOAP_SOCKLEN_T socklen_t -#elif defined(IRIX) || defined(WIN32) || defined(__APPLE__) || defined(HP_UX) || defined(SUN_OS) || defined(OPENSERVER) || defined(TRU64) || defined(VXWORKS) -# define SOAP_SOCKLEN_T int -#else -# define SOAP_SOCKLEN_T size_t -#endif - -#ifndef SOAP_SOCKET -# ifdef WIN32 -# define SOAP_SOCKET SOCKET -# define soap_closesocket(n) closesocket(n) -# else -# define SOAP_SOCKET int -# define soap_closesocket(n) close(n) -# endif -#endif - -#define SOAP_INVALID_SOCKET (-1) -#define soap_valid_socket(n) ((n) != SOAP_INVALID_SOCKET) - -#ifndef FD_SETSIZE -# define FD_SETSIZE (1024) -#endif - -#if defined(SYMBIAN) -# define LONG64 long -# define ULONG64 unsigned LONG64 -#elif !defined(WIN32) || defined(CYGWIN) || defined(__GLIBC__) || defined(__GNU__) -# ifndef LONG64 -# if defined(__GLIBC__) -# include -# if (__WORDSIZE == 64) -# define LONG64 int64_t -# define ULONG64 uint64_t -# ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%ld" -# endif -# ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%lu" -# endif -# else -# define LONG64 long long -# define ULONG64 unsigned LONG64 -# endif -# else -# define LONG64 long long -# define ULONG64 unsigned LONG64 -# endif -# endif -#elif defined(UNDER_CE) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#elif defined(__BORLANDC__) -# define LONG64 __int64 -# define ULONG64 unsigned LONG64 -#endif - -#ifndef SOAP_LONG_FORMAT -# define SOAP_LONG_FORMAT "%lld" /* printf format for 64 bit ints */ -#endif - -#ifndef SOAP_ULONG_FORMAT -# define SOAP_ULONG_FORMAT "%llu" /* printf format for unsigned 64 bit ints */ -#endif - -#if defined(WIN32) && !defined(CYGWIN) -# define soap_int32 __int32 -#elif defined(SYMBIAN) -# define soap_int32 long -#elif defined(PALM) -# define soap_int32 Int32 -#else -# define soap_int32 int32_t -#endif - -#ifdef WIN32 -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR WSAEINTR -# define SOAP_EAGAIN WSAEWOULDBLOCK -# define SOAP_EWOULDBLOCK WSAEWOULDBLOCK -# define SOAP_EINPROGRESS WSAEINPROGRESS -# define SOAP_EADDRINUSE WSAEADDRINUSE -#else -# define SOAP_ERANGE ERANGE -# define SOAP_EINTR EINTR -# define SOAP_EAGAIN EAGAIN -# define SOAP_EADDRINUSE EADDRINUSE -# ifdef SYMBIAN -# define SOAP_EWOULDBLOCK 9898 -# define SOAP_EINPROGRESS 9899 -# else -# define SOAP_EWOULDBLOCK EWOULDBLOCK -# define SOAP_EINPROGRESS EINPROGRESS -# endif -#endif - -#ifdef WIN32 -# ifdef UNDER_CE -# define soap_errno GetLastError() -# define soap_socket_errno(s) GetLastError() -# define soap_reset_errno SetLastError(0) -# else -# define soap_errno GetLastError() -# define soap_socket_errno(s) WSAGetLastError() -# define soap_reset_errno SetLastError(0) -# endif -#else -# ifndef WITH_NOIO -# define soap_errno errno -# define soap_socket_errno(s) errno -# define soap_reset_errno (errno = 0) -# else -# define soap_errno 0 -# define soap_socket_errno(s) 0 -# define soap_reset_errno -# endif -#endif - -#ifndef SOAP_BUFLEN -# ifdef WITH_UDP -# define SOAP_BUFLEN (65536) /* max UDP packet size */ -# else -# ifndef WITH_LEAN -# define SOAP_BUFLEN (65536) /* buffer length for socket packets, also used by gethostbyname_r so don't make this too small */ -# else -# define SOAP_BUFLEN (2048) -# endif -# endif -#endif -#ifndef SOAP_LABLEN -# define SOAP_LABLEN (256) /* initial look-aside buffer length */ -#endif -#ifndef SOAP_PTRBLK -# define SOAP_PTRBLK (32) /* block allocation for pointer hash table chains */ -#endif -#ifndef SOAP_PTRHASH -# ifndef WITH_LEAN -# define SOAP_PTRHASH (1024) /* size of pointer analysis hash table (must be power of 2) */ -# else -# define SOAP_PTRHASH (32) -# endif -#endif -#ifndef SOAP_IDHASH -# ifndef WITH_LEAN -# define SOAP_IDHASH (1999) /* prime size of hash table for parsed id/ref */ -# else -# define SOAP_IDHASH (19) /* 19, 199 */ -# endif -#endif -#ifndef SOAP_BLKLEN -# ifndef WITH_LEAN -# define SOAP_BLKLEN (256) /* size of blocks to collect long strings and XML attributes */ -# else -# define SOAP_BLKLEN (32) -# endif -#endif -#ifndef SOAP_TAGLEN -# ifndef WITH_LEAN -# define SOAP_TAGLEN (1024) /* maximum length of XML element tag/attribute name or host/path name + 1 */ -# else -# define SOAP_TAGLEN (64) -# endif -#endif -#ifndef SOAP_HDRLEN -# ifndef WITH_LEAN -# define SOAP_HDRLEN (8192) /* maximum length of HTTP header line (must be >4096 to read cookies) */ -# else -# define SOAP_HDRLEN (1024) -# endif -#endif -#ifndef SOAP_MAXDIMS -# ifndef WITH_LEAN -# define SOAP_MAXDIMS (16) /* maximum array dimensions (array nestings) must be less than 64 to protect soap->tmpbuf */ -# else -# define SOAP_MAXDIMS (4) -# endif -#endif - -#ifndef SOAP_MAXLOGS -# define SOAP_MAXLOGS (3) /* max number of debug logs per struct soap environment */ -# define SOAP_INDEX_RECV (0) -# define SOAP_INDEX_SENT (1) -# define SOAP_INDEX_TEST (2) -#endif - -#ifndef SOAP_MAXKEEPALIVE -# define SOAP_MAXKEEPALIVE (100) /* max iterations to keep server connection alive */ -#endif - -#ifndef SOAP_MAXARRAYSIZE -# define SOAP_MAXARRAYSIZE (100000) /* "trusted" max size of inbound SOAP array for compound array allocation */ -#endif - -#ifdef VXWORKS -# ifdef __INCmathh -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) isNan(num) -# endif -#endif - -#ifdef WIN32 -# include -# ifndef HAVE_ISNAN -# define HAVE_ISNAN -# endif -# define soap_isnan(num) _isnan(num) -#endif - -#ifdef SUN_OS -# define HAVE_ISNAN -#endif - -#ifdef __APPLE__ -# ifdef __cplusplus -# ifndef isnan -extern "C" int isnan(double); -# endif -# endif -# define HAVE_ISNAN -#endif - -#if !defined(HAVE_ISNAN) && (defined(_MATH_H) || defined(_MATH_INCLUDED)) -# define HAVE_ISNAN -#endif - -extern const struct soap_double_nan { unsigned int n1, n2; } soap_double_nan; - -#ifdef VXWORKS -# ifndef FLT_MAX -# define FLT_MAX _ARCH_FLT_MAX -# endif -# ifndef DBL_MAX -# define DBL_MAX _ARCH_DBL_MAX -# endif -#endif - -#ifndef FLT_NAN -# define FLT_NAN (*(float*)(void*)&soap_double_nan) -#endif - -#ifndef FLT_PINFTY -# if defined(FLT_MAX) -# define FLT_PINFTY FLT_MAX -# elif defined(HUGE_VALF) -# define FLT_PINFTY (float)HUGE_VALF -# elif defined(HUGE_VAL) -# define FLT_PINFTY (float)HUGE_VAL -# elif defined(FLOAT_MAX) -# define FLT_PINFTY FLOAT_MAX -# else -# define FLT_PINFTY (3.40282347e+38F) -# endif -#endif - -#ifndef FLT_NINFTY -# define FLT_NINFTY (-FLT_PINFTY) -#endif - -#ifndef DBL_NAN -# define DBL_NAN (*(double*)(void*)&soap_double_nan) -#endif - -#ifndef DBL_PINFTY -# if defined(DBL_MAX) -# define DBL_PINFTY DBL_MAX -# elif defined(HUGE_VALF) -# define DBL_PINFTY (double)HUGE_VALF -# elif defined(HUGE_VAL) -# define DBL_PINFTY (double)HUGE_VAL -# elif defined(DOUBLE_MAX) -# define DBL_PINFTY DOUBLE_MAX -# else -# define DBL_PINFTY (1.7976931348623157e+308) -# endif -#endif - -#ifndef DBL_NINFTY -# define DBL_NINFTY (-DBL_PINFTY) -#endif - -#ifndef soap_isnan -# ifdef HAVE_ISNAN -# define soap_isnan(n) isnan(n) -# else -# define soap_isnan(n) (0) -# endif -#endif - -#define soap_ispinfd(n) ((n) >= DBL_PINFTY) -#define soap_ispinff(n) ((n) >= FLT_PINFTY) -#define soap_isninfd(n) ((n) <= DBL_NINFTY) -#define soap_isninff(n) ((n) <= FLT_NINFTY) - -/* gSOAP error codes */ - -#define SOAP_EOF EOF -#define SOAP_ERR EOF -#define SOAP_OK 0 -#define SOAP_CLI_FAULT 1 -#define SOAP_SVR_FAULT 2 -#define SOAP_TAG_MISMATCH 3 -#define SOAP_TYPE 4 -#define SOAP_SYNTAX_ERROR 5 -#define SOAP_NO_TAG 6 -#define SOAP_IOB 7 -#define SOAP_MUSTUNDERSTAND 8 -#define SOAP_NAMESPACE 9 -#define SOAP_USER_ERROR 10 -#define SOAP_FATAL_ERROR 11 -#define SOAP_FAULT 12 -#define SOAP_NO_METHOD 13 -#define SOAP_NO_DATA 14 -#define SOAP_GET_METHOD 15 -#define SOAP_EOM 16 -#define SOAP_MOE 17 -#define SOAP_NULL 18 -#define SOAP_DUPLICATE_ID 19 -#define SOAP_MISSING_ID 20 -#define SOAP_HREF 21 -#define SOAP_UDP_ERROR 22 -#define SOAP_TCP_ERROR 23 -#define SOAP_HTTP_ERROR 24 -#define SOAP_SSL_ERROR 25 -#define SOAP_ZLIB_ERROR 26 -#define SOAP_DIME_ERROR 27 -#define SOAP_DIME_HREF 28 -#define SOAP_DIME_MISMATCH 29 -#define SOAP_DIME_END 30 -#define SOAP_MIME_ERROR 31 -#define SOAP_MIME_HREF 32 -#define SOAP_MIME_END 33 -#define SOAP_VERSIONMISMATCH 34 -#define SOAP_PLUGIN_ERROR 35 -#define SOAP_DATAENCODINGUNKNOWN 36 -#define SOAP_REQUIRED 37 -#define SOAP_PROHIBITED 38 -#define SOAP_OCCURS 39 -#define SOAP_LENGTH 40 -#define SOAP_FD_EXCEEDED 41 - -#define soap_xml_error_check(e) ((e) == SOAP_TAG_MISMATCH || (e) == SOAP_TAG_END || (e) == SOAP_SYNTAX_ERROR || (e) == SOAP_NAMESPACE || (e) == SOAP_DUPLICATE_ID || (e) == SOAP_MISSING_ID || (e) == SOAP_REQUIRED || (e) == SOAP_PROHIBITED || (e) == SOAP_OCCURS || (e) == SOAP_LENGTH || (e) == SOAP_NULL || (e) == SOAP_HREF) -#define soap_soap_error_check(e) ((e) == SOAP_CLI_FAULT || (e) == SOAP_SVR_FAULT || (e) == SOAP_VERSIONMISMATCH || (e) == SOAP_MUSTUNDERSTAND || (e) == SOAP_FAULT || (e) == SOAP_NO_METHOD) -#define soap_tcp_error_check(e) ((e) == SOAP_EOF || (e) == SOAP_TCP_ERROR) -#define soap_ssl_error_check(e) ((e) == SOAP_SSL_ERROR) -#define soap_zlib_error_check(e) ((e) == SOAP_ZLIB_ERROR) -#define soap_http_error_check(e) ((e) == SOAP_HTTP_ERROR || (e) == SOAP_GET_METHOD || (e) == SOAP_NO_DATA || ((e) >= 100 && (e) < 600)) - -/* gSOAP HTTP response status codes 100 to 599 are reserved */ - -/* Codes 600 to 999 are user definable */ - -/* Exceptional gSOAP HTTP response status codes >= 1000 */ - -#define SOAP_STOP 1000 /* No HTTP response */ -#define SOAP_FORM 1001 /* Form request/response */ -#define SOAP_HTML 1002 /* Custom HTML response */ -#define SOAP_FILE 1003 /* Custom file-based response */ - -/* gSOAP HTTP method codes */ - -#define SOAP_POST 2000 -#define SOAP_GET 2001 - -/* gSOAP DIME */ - -#define SOAP_DIME_CF 0x01 -#define SOAP_DIME_ME 0x02 -#define SOAP_DIME_MB 0x04 -#define SOAP_DIME_VERSION 0x08 /* DIME version 1 */ -#define SOAP_DIME_MEDIA 0x10 -#define SOAP_DIME_ABSURI 0x20 - -/* gSOAP ZLIB */ - -#define SOAP_ZLIB_NONE 0x00 -#define SOAP_ZLIB_DEFLATE 0x01 -#define SOAP_ZLIB_INFLATE 0x02 -#define SOAP_ZLIB_GZIP 0x02 - -/* gSOAP transport, connection, and content encoding modes */ - -typedef soap_int32 soap_mode; - -#define SOAP_IO 0x00000003 /* IO mask */ -#define SOAP_IO_FLUSH 0x00000000 /* flush output immediately, no buffering */ -#define SOAP_IO_BUFFER 0x00000001 /* buffer output in packets of size SOAP_BUFLEN */ -#define SOAP_IO_STORE 0x00000002 /* store entire output to determine length for transport */ -#define SOAP_IO_CHUNK 0x00000003 /* use HTTP chunked transfer AND buffer packets */ - -#define SOAP_IO_UDP 0x00000004 /* TCP or UDP */ - -#define SOAP_IO_LENGTH 0x00000008 /* calc message length (internal) */ -#define SOAP_IO_KEEPALIVE 0x00000010 /* keep connection alive */ - -#define SOAP_ENC_LATIN 0x00000020 /* accept iso-8859-1 encoding */ -#define SOAP_ENC_XML 0x00000040 /* plain XML encoding, no HTTP header */ -#define SOAP_ENC_DIME 0x00000080 -#define SOAP_ENC_MIME 0x00000100 -#define SOAP_ENC_MTOM 0x00000200 -#define SOAP_ENC_ZLIB 0x00000400 -#define SOAP_ENC_SSL 0x00000800 - -#define SOAP_ENC 0x00000FFF /* IO and ENC mask */ - -#define SOAP_XML_STRICT 0x00001000 /* apply strict validation */ -#define SOAP_XML_INDENT 0x00002000 /* emit indented XML */ -#define SOAP_XML_CANONICAL 0x00004000 /* EXC C14N canonical XML */ -#define SOAP_XML_TREE 0x00008000 /* emit XML tree (no id/ref) */ -#define SOAP_XML_GRAPH 0x00010000 -#define SOAP_XML_NIL 0x00020000 -#define SOAP_XML_DOM 0x00040000 -#define SOAP_XML_SEC 0x00080000 /* reserved for WS security */ - -#define SOAP_C_NOIOB 0x00100000 /* don't fault on array index out of bounds (just ignore) */ -#define SOAP_C_UTFSTRING 0x00200000 /* (de)serialize strings with UTF8 content */ -#define SOAP_C_MBSTRING 0x00400000 /* (de)serialize strings with multi-byte content */ -#define SOAP_C_NILSTRING 0x00800000 /* serialize empty strings as nil (omitted) */ - -#define SOAP_DOM_TREE 0x01000000 -#define SOAP_DOM_NODE 0x02000000 -#define SOAP_DOM_ASIS 0x04000000 - -#define SOAP_MIME_POSTCHECK 0x10000000 /* MIME flag (internal) */ - -#define SOAP_IO_DEFAULT SOAP_IO_FLUSH - -/* SSL client/server authentication settings */ - -#define SOAP_SSL_NO_AUTHENTICATION 0x00 /* for testing purposes */ -#define SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION 0x01 /* client requires server to authenticate */ -#define SOAP_SSL_REQUIRE_CLIENT_AUTHENTICATION 0x02 /* server requires client to authenticate */ -#define SOAP_SSL_SKIP_HOST_CHECK 0x04 /* client does not check the common name of the host in certificate */ -#define SOAP_SSL_RSA 0x08 /* use RSA */ -#define SOAP_SSLv3_TLSv1 0x00 /* SSL v3 and TLS v1 support by default */ -#define SOAP_SSLv3 0x10 /* SSL v3 only */ -#define SOAP_TLSv1 0x20 /* TLS v1 only */ - -#define SOAP_SSL_DEFAULT (SOAP_SSL_REQUIRE_SERVER_AUTHENTICATION | SOAP_SSLv3_TLSv1) - -/* state */ - -#define SOAP_INIT 1 -#define SOAP_COPY 2 - -#define soap_check_state(soap) (!(soap) || ((soap)->state != SOAP_INIT && (soap)->state != SOAP_COPY)) - -/* part */ - -#define SOAP_BEGIN 0 -#define SOAP_IN_ENVELOPE 2 -#define SOAP_IN_HEADER 3 -#define SOAP_END_HEADER 4 -#define SOAP_NO_BODY 5 -#define SOAP_IN_BODY 6 -#define SOAP_END_BODY 7 -#define SOAP_END_ENVELOPE 8 -#define SOAP_END 9 -#define SOAP_BEGIN_SECURITY 10 -#define SOAP_IN_SECURITY 11 -#define SOAP_END_SECURITY 12 - -/* DEBUG macros */ - -#ifndef WITH_LEAN -# ifdef DEBUG -# ifndef SOAP_DEBUG -# define SOAP_DEBUG -# endif -# ifndef SOAP_MEM_DEBUG -# define SOAP_MEM_DEBUG -# endif -# endif -#endif - -#ifdef SOAP_MEM_DEBUG -# ifndef SOAP_MALLOC -# define SOAP_MALLOC(soap, size) soap_track_malloc(soap, __FILE__, __LINE__, size) -# endif -# ifndef SOAP_FREE -# define SOAP_FREE(soap, ptr) soap_track_free(soap, __FILE__, __LINE__, ptr) -# endif -#endif - -#ifndef SOAP_MALLOC /* use libc malloc */ -# define SOAP_MALLOC(soap, size) malloc(size) -#endif - -#ifndef SOAP_FREE /* use libc free */ -# define SOAP_FREE(soap, ptr) free(ptr) -#endif - -#ifdef SOAP_DEBUG -# ifndef SOAP_MESSAGE -# define SOAP_MESSAGE fprintf -# endif -# ifndef DBGLOG -# define DBGLOG(DBGFILE, CMD) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { FILE *fdebug = soap->fdebug[SOAP_INDEX_##DBGFILE];\ - CMD;\ - fflush(fdebug);\ - }\ - }\ -} -# endif -# ifndef DBGMSG -# define DBGMSG(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile((struct soap*)soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { fwrite((MSG), 1, (LEN), soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -# ifndef DGBFUN -# define DBGFUN(FNAME) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s()\n", __FILE__, __LINE__, FNAME)) -# define DBGFUN1(FNAME, FMT, ARG) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT")\n", __FILE__, __LINE__, FNAME, (ARG))) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2))) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) DBGLOG(TEST, SOAP_MESSAGE(fdebug, "%s(%d): %s("FMT1", "FMT2", "FMT3")\n", __FILE__, __LINE__, FNAME, (ARG1), (ARG2), (ARG3))) -# endif -# ifndef DBGHEX -# define DBGHEX(DBGFILE, MSG, LEN) \ -{ if (soap)\ - { if (!soap->fdebug[SOAP_INDEX_##DBGFILE])\ - soap_open_logfile(soap, SOAP_INDEX_##DBGFILE);\ - if (soap->fdebug[SOAP_INDEX_##DBGFILE])\ - { int i; char *s;\ - for (s = (char*)(MSG), i = (LEN); i; i--)\ - fprintf(soap->fdebug[SOAP_INDEX_##DBGFILE], "%2.2X ", (int)*s++&0xFF);\ - fflush(soap->fdebug[SOAP_INDEX_##DBGFILE]);\ - }\ - }\ -} -# endif -#else -# define DBGLOG(DBGFILE, CMD) -# define DBGMSG(DBGFILE, MSG, LEN) -# define DBGFUN(FNAME) -# define DBGFUN1(FNAME, FMT, ARG) -# define DBGFUN2(FNAME, FMT1, ARG1, FMT2, ARG2) -# define DBGFUN3(FNAME, FMT1, ARG1, FMT2, ARG2, FMT3, ARG3) -# define DBGHEX(DBGFILE, MSG, LEN) -#endif - -/* UCS-4 requires 32 bits (0-7FFFFFFF, the sign bit is used by gSOAP to distinguish XML entities) */ -typedef soap_int32 soap_wchar; - -/* namespace table row */ -struct Namespace -{ const char *id; - const char *ns; - const char *in; - char *out; -}; - -/* namespace stack */ -struct soap_nlist -{ struct soap_nlist *next; - unsigned int level; /* nesting depth level */ - short index; /* corresponding entry in ns mapping table */ - char *ns; /* only set when parsed ns URI is not in the ns mapping table */ - char id[1]; /* the actual string value flows into the allocated region below this struct */ -}; - -/* block stack for nested block allocations */ -struct soap_blist -{ struct soap_blist *next; - char *ptr; - size_t size; -}; - -/* array layout */ -struct soap_array -{ void *__ptr; - int __size; -}; - -/* pointer serialization management */ -struct soap_plist -{ struct soap_plist *next; - const void *ptr; - const struct soap_array *array; - int type; - int id; - char mark1; - char mark2; -}; - -/* block allocation for pointer serialization management */ -struct soap_pblk -{ struct soap_pblk *next; - struct soap_plist plist[SOAP_PTRBLK]; -}; - -#ifdef SOAP_MEM_DEBUG -/* malloc/free tracking for debugging */ -struct soap_mlist -{ struct soap_mlist *next; - const void *ptr; - const char *file; - int line; - short live; -}; -#endif - -/* class allocation list */ -struct soap_clist -{ struct soap_clist *next; - void *ptr; - int type; - int size; - int (*fdelete)(struct soap_clist*); -}; - -/* attributes */ -struct soap_attribute -{ struct soap_attribute *next; - char *value; - size_t size; - char *ns; - short visible; - char name[1]; /* the actual name string flows into the allocated region below this struct */ -}; - -#ifndef WITH_LEAN -struct soap_cookie -{ struct soap_cookie *next; - char *name; - char *value; - char *domain; - char *path; - time_t expire; /* client-side: local time to expire */ - long maxage; /* server-side: seconds to expire */ - unsigned int version; - short secure; - short session; /* server-side */ - short env; /* server-side: got cookie from client and should not be (re)send */ - short modified; /* server-side: client cookie was modified and should be send */ -}; -#endif - -#ifdef __cplusplus -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); - -class soap_multipart_iterator -{ public: - struct soap_multipart *content; - bool operator==(const soap_multipart_iterator& iter) const - { return content == iter.content; } - bool operator!=(const soap_multipart_iterator& iter) const - { return content != iter.content; } - struct soap_multipart &operator*() const - { return *content; } - soap_multipart_iterator &operator++() - { content = soap_next_multipart(content); return *this; } - soap_multipart_iterator() : content(NULL) - { } - soap_multipart_iterator(struct soap_multipart *p) : content(p) - { } -}; -#endif - -#ifndef WITH_LEANER -struct soap_dime -{ size_t count; - size_t size; - size_t chunksize; - size_t buflen; - char flags; - char *ptr; - const char *id; - const char *type; - const char *options; - struct soap_multipart *list; /* list of DIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -struct soap_mime -{ char *boundary; /* MIME boundary */ - const char *start; /* MIME start ID */ - struct soap_multipart *list; /* list of MIME attachments received */ - struct soap_multipart *first, *last; /* temporary in/out queue */ -#ifdef __cplusplus - soap_multipart_iterator begin() - { soap_multipart_iterator iter(list); return iter; }; - soap_multipart_iterator end() - { soap_multipart_iterator iter(NULL); return iter; }; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* RFC2045 MIME content transfer encodings */ -enum soap_mime_encoding -{ SOAP_MIME_NONE, - SOAP_MIME_7BIT, - SOAP_MIME_8BIT, - SOAP_MIME_BINARY, - SOAP_MIME_QUOTED_PRINTABLE, - SOAP_MIME_BASE64, - SOAP_MIME_IETF_TOKEN, - SOAP_MIME_X_TOKEN -}; -#endif - -#ifndef WITH_LEANER -/* DIME/MIME multipart list */ -struct soap_multipart -{ struct soap_multipart *next; - char *ptr; /* points to raw data content */ - size_t size; /* size of data content */ - const char *id; /* DIME/MIME content ID or form data name */ - const char *type; /* DIME/MIME type (MIME type format) */ - const char *options; /* DIME options */ - enum soap_mime_encoding encoding; /* MIME Content-Transfer-Encoding */ - const char *location; /* MIME Content-Location (optional) */ - const char *description; /* MIME Content-Description (optional) */ -#ifdef __cplusplus - typedef soap_multipart_iterator iterator; -#endif -}; -#endif - -#ifndef WITH_LEANER -/* attachment DIME and MTOM XOP forwarding */ -struct soap_xlist -{ struct soap_xlist *next; - unsigned char **ptr; - int *size; - char *id; - char **type; - char **options; -}; -#endif - -/******************************************************************************/ - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_attribute_iterator -{ public: - struct soap_dom_attribute *att; - const char *nstr; - const char *name; - bool operator==(const soap_dom_attribute_iterator&) const; - bool operator!=(const soap_dom_attribute_iterator&) const; - struct soap_dom_attribute &operator*() const; - soap_dom_attribute_iterator &operator++(); - soap_dom_attribute_iterator(); - soap_dom_attribute_iterator(struct soap_dom_attribute*); - ~soap_dom_attribute_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_attribute -{ struct soap_dom_attribute *next; - const char *nstr; - char *name; - char *data; - wchar_t *wide; - struct soap *soap; -#ifdef __cplusplus - typedef soap_dom_attribute_iterator iterator; - struct soap_dom_attribute &set(const char *nstr, const char *name); /* set namespace and name */ - struct soap_dom_attribute &set(const char *data); /* set data */ - soap_dom_attribute_iterator begin(); - soap_dom_attribute_iterator end(); - soap_dom_attribute_iterator find(const char *nstr, const char *name); - void unlink(); - soap_dom_attribute(); - soap_dom_attribute(struct soap *soap); - soap_dom_attribute(struct soap *soap, const char *nstr, const char *name, const char *data); - ~soap_dom_attribute(); -#endif -}; -#endif - -#ifndef WITH_LEANER -#ifdef __cplusplus -class soap_dom_element_iterator -{ public: - struct soap_dom_element *elt; - const char *nstr; - const char *name; - int type; - bool operator==(const soap_dom_element_iterator&) const; - bool operator!=(const soap_dom_element_iterator&) const; - struct soap_dom_element &operator*() const; - soap_dom_element_iterator &operator++(); - soap_dom_element_iterator(); - soap_dom_element_iterator(struct soap_dom_element*); - ~soap_dom_element_iterator(); -}; -#endif -#endif - -#ifndef WITH_LEANER -struct soap_dom_element -{ struct soap_dom_element *next; /* next sibling */ - struct soap_dom_element *prnt; /* parent */ - struct soap_dom_element *elts; /* list of child elements */ - struct soap_dom_attribute *atts; /* list of attributes */ - const char *nstr; /* namespace string */ - char *name; /* element tag name */ - char *data; /* element content data (with SOAP_C_UTFSTRING flag set) */ - wchar_t *wide; /* element content data */ - int type; /* optional: serialized C/C++ data type */ - void *node; /* optional: pointer to serialized C/C++ data */ - char *head; /* leading whitespace to start tag */ - char *tail; /* leading whitespace to end tag */ - struct soap *soap; /* soap context that manages this node */ -#ifdef __cplusplus - typedef soap_dom_element_iterator iterator; - struct soap_dom_element &set(const char *nstr, const char *name); - struct soap_dom_element &set(const char *data); - struct soap_dom_element &set(void *node, int type); - struct soap_dom_element &add(struct soap_dom_element*); - struct soap_dom_element &add(struct soap_dom_element&); - struct soap_dom_element &add(struct soap_dom_attribute*); - struct soap_dom_element &add(struct soap_dom_attribute&); - soap_dom_element_iterator begin(); - soap_dom_element_iterator end(); - soap_dom_element_iterator find(const char *nstr, const char *name); - soap_dom_element_iterator find(int type); - void unlink(); - soap_dom_element(); - soap_dom_element(struct soap *soap); - soap_dom_element(struct soap *soap, const char *nstr, const char *name); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, const char *data); - soap_dom_element(struct soap *soap, const char *nstr, const char *name, void *node, int type); - ~soap_dom_element(); -#endif -}; -SOAP_FMAC1 struct soap_dom_element * SOAP_FMAC2 soap_dom_next_element(struct soap_dom_element *elt); -SOAP_FMAC1 struct soap_dom_attribute * SOAP_FMAC2 soap_dom_next_attribute(struct soap_dom_attribute *att); -#endif - -#if defined(__cplusplus) && !defined(WITH_LEAN) -} -extern std::ostream &operator<<(std::ostream&, const struct soap_dom_element&); -extern std::istream &operator>>(std::istream&, struct soap_dom_element&); -extern "C" { -#endif - -/******************************************************************************/ - -#ifdef WIN32 -# ifdef SOAP_STD_EXPORTS -# define SOAP_STD_API __declspec(dllexport) -# else -# define SOAP_STD_API -# endif -#else -# define SOAP_STD_API -#endif - -struct SOAP_STD_API soap -{ short state; /* 0 = uninitialized, 1 = initialized, 2 = copy of another soap struct */ - short version; /* 1 = SOAP1.1 and 2 = SOAP1.2 (set automatically from namespace URI in nsmap table) */ - soap_mode mode; - soap_mode imode; - soap_mode omode; - const char *float_format; /* user-definable format string for floats (<1024 chars) */ - const char *double_format; /* user-definable format string for doubles (<1024 chars) */ - const char *dime_id_format; /* user-definable format string for integer DIME id ( 0, gives socket recv timeout in seconds, < 0 in usec */ - int send_timeout; /* when > 0, gives socket send timeout in seconds, < 0 in usec */ - int connect_timeout; /* when > 0, gives socket connect() timeout in seconds, < 0 in usec */ - int accept_timeout; /* when > 0, gives socket accept() timeout in seconds, < 0 in usec */ - int socket_flags; /* socket recv() and send() flags, e.g. set to MSG_NOSIGNAL to disable sigpipe */ - int connect_flags; /* connect() SOL_SOCKET sockopt flags, e.g. set to SO_DEBUG to debug socket */ - int bind_flags; /* bind() SOL_SOCKET sockopt flags, e.g. set to SO_REUSEADDR to enable reuse */ - int accept_flags; /* accept() SOL_SOCKET sockopt flags */ - const struct Namespace *namespaces; /* Pointer to global namespace mapping table */ - struct Namespace *local_namespaces; /* Local namespace mapping table */ - struct soap_nlist *nlist; /* namespace stack */ - struct soap_blist *blist; /* block allocation stack */ - struct soap_clist *clist; /* class instance allocation list */ - void *alist; /* memory allocation (malloc) list */ - struct soap_ilist *iht[SOAP_IDHASH]; - struct soap_plist *pht[SOAP_PTRHASH]; - struct soap_pblk *pblk; /* plist block allocation */ - short pidx; /* plist block allocation */ - struct SOAP_ENV__Header *header; - struct SOAP_ENV__Fault *fault; - int idnum; - void *user; /* to pass user-defined data */ - struct soap_plugin *plugins; /* linked list of plug-in data */ - char *userid; /* HTTP Basic authorization userid */ - char *passwd; /* HTTP Basic authorization passwd */ - int (*fpost)(struct soap*, const char*, const char*, int, const char*, const char*, size_t); - int (*fget)(struct soap*); - int (*fform)(struct soap*); - int (*fposthdr)(struct soap*, const char*, const char*); - int (*fresponse)(struct soap*, int, size_t); - int (*fparse)(struct soap*); - int (*fparsehdr)(struct soap*, const char*, const char*); - int (*fheader)(struct soap*); - int (*fresolve)(struct soap*, const char*, struct in_addr* inaddr); - int (*fconnect)(struct soap*, const char*, const char*, int); - int (*fdisconnect)(struct soap*); - int (*fclosesocket)(struct soap*, SOAP_SOCKET); - int (*fshutdownsocket)(struct soap*, SOAP_SOCKET, int); - int (*fopen)(struct soap*, const char*, const char*, int); - int (*faccept)(struct soap*, int, struct sockaddr*, int *n); - int (*fclose)(struct soap*); - int (*fsend)(struct soap*, const char*, size_t); - size_t (*frecv)(struct soap*, char*, size_t); - int (*fpoll)(struct soap*); - void (*fseterror)(struct soap*, const char **c, const char **s); - int (*fignore)(struct soap*, const char*); - int (*fserveloop)(struct soap*); - void *(*fplugin)(struct soap*, const char*); - void *(*fmalloc)(struct soap*, size_t); -#ifndef WITH_LEANER - int (*fprepareinit)(struct soap*); - int (*fpreparesend)(struct soap*, const char*, size_t); - int (*fpreparerecv)(struct soap*, const char*, size_t); - int (*fpreparefinal)(struct soap*); - void *(*fdimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fdimewriteopen)(struct soap*, const char*, const char*, const char*); - void (*fdimereadclose)(struct soap*, void*); - void (*fdimewriteclose)(struct soap*, void*); - size_t (*fdimeread)(struct soap*, void*, char*, size_t); - int (*fdimewrite)(struct soap*, void*, const char*, size_t); - void *(*fmimereadopen)(struct soap*, void*, const char*, const char*, const char*); - void *(*fmimewriteopen)(struct soap*, void*, const char*, const char*, const char*, enum soap_mime_encoding); - void (*fmimereadclose)(struct soap*, void*); - void (*fmimewriteclose)(struct soap*, void*); - size_t (*fmimeread)(struct soap*, void*, char*, size_t); - int (*fmimewrite)(struct soap*, void*, const char*, size_t); -#endif - int master; - int socket; -#if defined(__cplusplus) && !defined(WITH_LEAN) - std::ostream *os; - std::istream *is; -#else - void *os; /* preserve alignment */ - void *is; /* preserve alignment */ -#endif -#ifndef UNDER_CE - int sendfd; - int recvfd; -#else - FILE *sendfd; - FILE *recvfd; -#endif - size_t bufidx; /* index in soap.buf[] */ - size_t buflen; /* length of soap.buf[] content */ - soap_wchar ahead; /* parser lookahead */ - short cdata; /* CDATA parser state */ - short body; /* parsed XML element has a body or not */ - unsigned int level; /* XML nesting level */ - size_t count; /* message length counter */ - size_t length; /* message length as set by HTTP header */ - char *labbuf; /* look-aside buffer */ - size_t lablen; /* look-aside buffer allocated length */ - size_t labidx; /* look-aside buffer index to available part */ - char buf[SOAP_BUFLEN];/* send and receive buffer */ - char msgbuf[1024]; /* in/output buffer for messages >=1024 bytes */ - char tmpbuf[1024]; /* in/output buffer for HTTP/MIME headers, simpleType values, attribute names, and DIME must be >=1024 bytes */ - char tag[SOAP_TAGLEN]; - char id[SOAP_TAGLEN]; - char href[SOAP_TAGLEN]; - char type[SOAP_TAGLEN]; - char arrayType[SOAP_TAGLEN]; - char arraySize[SOAP_TAGLEN]; - char arrayOffset[SOAP_TAGLEN]; - short other; - short position; - int positions[SOAP_MAXDIMS]; - short root; - struct soap_attribute *attributes; /* attribute list */ - short encoding; /* when set, output encodingStyle */ - short mustUnderstand; /* a mustUnderstand element was parsed or is output */ - short keep_alive; /* connection should be kept open */ - short null; /* parsed XML is xsi:nil */ - short ns; /* when not set, output full xmlns bindings */ - short part; /* parsing state */ - short alloced; - short peeked; - size_t chunksize; - size_t chunkbuflen; - char endpoint[SOAP_TAGLEN]; - char path[SOAP_TAGLEN]; - char host[SOAP_TAGLEN]; - char *action; - char *authrealm; /* HTTP authentication realm */ - char *prolog; /* XML declaration prolog */ - unsigned long ip; /* IP number */ - int port; /* port number */ - unsigned int max_keep_alive; - const char *proxy_http_version;/* HTTP version of proxy "1.0" or "1.1" */ - const char *proxy_host; /* Proxy Server host name */ - int proxy_port; /* Proxy Server port (default = 8080) */ - const char *proxy_userid; /* Proxy Authorization user name */ - const char *proxy_passwd; /* Proxy Authorization password */ - int status; /* -1 when request, else error code to be returned by server */ - int error; - int errmode; - int errnum; -#ifndef WITH_LEANER - struct soap_dom_element *dom; - struct soap_dime dime; - struct soap_mime mime; - struct soap_xlist *xlist; -#endif -#if !defined(WITH_LEAN) || defined(SOAP_DEBUG) - const char *logfile[SOAP_MAXLOGS]; - FILE *fdebug[SOAP_MAXLOGS]; - struct soap_mlist *mht[SOAP_PTRHASH]; -#endif -#ifndef WITH_LEAN - const char *c14ninclude; - const char *c14nexclude; - struct soap_cookie *cookies; - const char *cookie_domain; - const char *cookie_path; - int cookie_max; -#endif -#ifndef WITH_NOIO -#ifdef WITH_IPV6 - struct sockaddr_storage peer; /* IPv6: set by soap_accept and by UDP recv */ -#else - struct sockaddr_in peer; /* IPv4: set by soap_connect/soap_accept and by UDP recv */ -#endif -#endif - size_t peerlen; -#ifdef WITH_OPENSSL - int (*fsslauth)(struct soap*); - int (*fsslverify)(int, X509_STORE_CTX*); - BIO *bio; - SSL *ssl; - SSL_CTX *ctx; - unsigned short ssl_flags; - const char *keyfile; - const char *password; - const char *dhfile; - const char *cafile; - const char *capath; - const char *crlfile; - const char *randfile; - SSL_SESSION *session; - char session_host[SOAP_TAGLEN]; - int session_port; -#endif -#ifdef WITH_ZLIB - short zlib_state; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_INFLATE */ - short zlib_in; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - short zlib_out; /* SOAP_ZLIB_NONE, SOAP_ZLIB_DEFLATE, or SOAP_ZLIB_GZIP */ - z_stream d_stream; /* decompression stream */ - char z_buf[SOAP_BUFLEN]; /* buffer */ - size_t z_buflen; - unsigned short z_level; /* compression level to be used (0=none, 1=fast to 9=best) */ - uLong z_crc; /* internal gzip crc */ - float z_ratio_in; /* detected compression ratio compressed_length/length of inbound message */ - float z_ratio_out; /* detected compression ratio compressed_length/length of outbound message */ -#endif -#ifdef WMW_RPM_IO - void *rpmreqid; -#endif -#ifndef WITH_LEAN -#ifdef __cplusplus - soap(); - soap(soap_mode); - soap(soap_mode, soap_mode); - soap(struct soap&); - ~soap(); -#endif -#endif -}; - -struct soap_code_map -{ long code; - const char *string; -}; - -/* forwarding list */ -struct soap_flist -{ struct soap_flist *next; - int type; - void *ptr; - unsigned int level; - size_t len; - void (*fcopy)(struct soap*, int, int, void*, size_t, const void*, size_t); -}; - -/* id-ref forwarding list */ -struct soap_ilist -{ struct soap_ilist *next; - int type; - size_t size; - void *link; - void *copy; - struct soap_flist *flist; - void *ptr; - unsigned int level; - char id[1]; /* the actual id string value flows into the allocated region below this struct */ -}; - -struct soap_plugin -{ struct soap_plugin *next; - const char *id; - void *data; - int (*fcopy)(struct soap *soap, struct soap_plugin *dst, struct soap_plugin *src); - void (*fdelete)(struct soap *soap, struct soap_plugin *p); /* should delete fields of plugin only and not free(p) */ -}; - -#ifndef WITH_NONAMESPACES -extern SOAP_NMAC struct Namespace namespaces[]; -#endif - -#ifndef WITH_LEAN -# define soap_get0(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx]) -# define soap_get1(soap) (((soap)->bufidx>=(soap)->buflen && soap_recv(soap)) ? EOF : (unsigned char)(soap)->buf[(soap)->bufidx++]) -#else -soap_wchar soap_get0(struct soap*); -soap_wchar soap_get1(struct soap*); -#endif - -#define soap_revget1(soap) ((soap)->bufidx--) -#define soap_unget(soap, c) ((soap)->ahead = c) -#define soap_register_plugin(soap, plugin) soap_register_plugin_arg(soap, plugin, NULL) -#define soap_imode(soap, n) ((soap)->mode = (soap)->imode = (n)) -#define soap_set_imode(soap, n) ((soap)->imode |= (n)) -#define soap_clr_imode(soap, n) ((soap)->imode &= ~(n)) -#define soap_omode(soap, n) ((soap)->mode = (soap)->omode = (n)) -#define soap_set_omode(soap, n) ((soap)->omode |= (n)) -#define soap_clr_omode(soap, n) ((soap)->omode &= ~(n)) -#define soap_set_mode(soap, n) ((soap)->imode |= (n), (soap)->omode |= (n)) -#define soap_clr_mode(soap, n) ((soap)->imode &= ~(n), (soap)->omode &= ~(n)) -#define soap_destroy(soap) soap_delete((soap), NULL) - -#ifdef HAVE_STRRCHR -# define soap_strrchr(s, t) strrchr(s, t) -#else - SOAP_FMAC1 char* SOAP_FMAC2 soap_strrchr(const char *s, int t); -#endif - -#ifdef HAVE_STRTOL -# define soap_strtol(s, t, b) strtol(s, t, b) -#else - SOAP_FMAC1 long SOAP_FMAC2 soap_strtol(const char *s, char **t, int b); -#endif - -#ifdef HAVE_STRTOUL -# define soap_strtoul(s, t, b) strtoul(s, t, b) -#else - SOAP_FMAC1 unsigned long SOAP_FMAC2 soap_strtoul(const char *s, char **t, int b); -#endif - -#if defined(WITH_OPENSSL) -# define soap_random soap_rand() -SOAP_FMAC1 int SOAP_FMAC2 soap_rand(void); -#elif defined(HAVE_RANDOM) -# define soap_random (int)random() -#else -# define soap_random rand() -#endif - -#ifdef WITH_NOIDREF -# define soap_embedded(s, p, t) (0) -# define soap_id_lookup(s, i, p, t, n, k) (p) -# define soap_id_forward(s, h, p, len, st, tt, n, k, fc) (p) -# define soap_reference(s, a, t) (1) -# define soap_array_reference(s, p, a, n, t) (1) -# define soap_embed(s, p, a, n, t, pp) (0) -# define soap_embedded_id(s, i, p, t) (i) -# define soap_is_embedded(s, p) (0) -# define soap_is_single(s, p) (1) -# define soap_lookup_type(s, i) (0) -# define soap_getindependent(s) (0) -# define soap_putindependent(s) (0) -# define soap_getelement(s, n) (n) -# define soap_putelement(s, p, t, i, n) (0) -# define soap_markelement(s, p, n) (0) -#endif - -SOAP_FMAC1 void SOAP_FMAC2 soap_fault(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultsubcode(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultstring(struct soap*); -SOAP_FMAC1 const char** SOAP_FMAC2 soap_faultdetail(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializeheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putheader(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getheader(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_serializefault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putfault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getfault(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_ssl_init(void); -SOAP_FMAC1 int SOAP_FMAC2 soap_poll(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect_command(struct soap*, int, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_connect(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_bind(struct soap*, const char*, int, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_accept(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_accept(struct soap*); -SOAP_FMAC1 const char * SOAP_FMAC2 soap_ssl_error(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_server_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_ssl_client_context(struct soap*, unsigned short, const char*, const char*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_puthttphdr(struct soap*, int status, size_t count); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_get_header_attribute(struct soap*, const char*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_key(char*, size_t, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_decode_val(char*, size_t, const char*); - -SOAP_FMAC1 size_t SOAP_FMAC2 soap_hash(const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_endpoint(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_flush(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_get(struct soap*); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getchar(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_tag_cmp(const char*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_sender_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_receiver_fault_subcode(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_sender_error(struct soap*, const char*, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_receiver_error(struct soap*, const char*, const char*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_raw(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_raw(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send2(struct soap*, const char*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_send3(struct soap*, const char*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_pututf8(struct soap*, unsigned long); -SOAP_FMAC1 soap_wchar SOAP_FMAC2 soap_getutf8(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_putbase64(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_getbase64(struct soap*, int*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_puthex(struct soap*, const unsigned char*, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_gethex(struct soap*, int*); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_xop_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_dime_forward(struct soap*, unsigned char**, int*, char**, char**, char**); -#endif - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup_id(struct soap*, void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_lookup(struct soap*, const void *p, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_pointer_enter(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_pointer_lookup(struct soap*, const void *p, const struct soap_array *a, int n, int t, struct soap_plist**); -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); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_lookup(struct soap*, const char*); -SOAP_FMAC1 struct soap_ilist* SOAP_FMAC2 soap_enter(struct soap*, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_resolve(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_embedded(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_reference(struct soap*, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_reference(struct soap*, const void *p, const struct soap_array *a, int n, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_embedded_id(struct soap*, int id, const void *p, int t); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_embedded(struct soap*, struct soap_plist*); -SOAP_FMAC1 int SOAP_FMAC2 soap_is_single(struct soap*, struct soap_plist*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_embedded(struct soap*, struct soap_plist*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_count(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_send(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_send(struct soap*); - -SOAP_FMAC1 const struct soap_code_map* SOAP_FMAC2 soap_code(const struct soap_code_map*, const char*); -SOAP_FMAC1 long SOAP_FMAC2 soap_code_int(const struct soap_code_map*, const char*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_code_str(const struct soap_code_map*, long); -SOAP_FMAC1 long SOAP_FMAC2 soap_code_bits(const struct soap_code_map*, const char*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_code_list(struct soap*, const struct soap_code_map*, long); - -SOAP_FMAC1 int SOAP_FMAC2 soap_getline(struct soap*, char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_begin_recv(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_end_recv(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_malloc(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_dealloc(struct soap*, void*); -SOAP_FMAC1 struct soap_clist * SOAP_FMAC2 soap_link(struct soap*, void*, int, int, int (*fdelete)(struct soap_clist*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_unlink(struct soap*, const void*); -SOAP_FMAC1 void SOAP_FMAC2 soap_free_temp(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_del(struct soap*); - -SOAP_FMAC1 void* SOAP_FMAC2 soap_track_malloc(struct soap*, const char*, int, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_track_free(struct soap*, const char*, int, void*); - -#ifndef WITH_NOIDREF -SOAP_FMAC1 int SOAP_FMAC2 soap_lookup_type(struct soap*, const char *id); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_lookup(struct soap*, const char *id, void **p, int t, size_t n, unsigned int k); -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_forward(struct soap*, const char *id, void *p, size_t len, int st, int tt, size_t n, unsigned int k, void(*fcopy)(struct soap*, int, int, void*, size_t, const void*, size_t)); -#endif -SOAP_FMAC1 void* SOAP_FMAC2 soap_id_enter(struct 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*)); -SOAP_FMAC1 void SOAP_FMAC2 soap_fcopy(struct soap *soap, int st, int tt, void *p, size_t, const void *q, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_size(const int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getoffsets(const char *, const int *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsize(const char *, const char *, int *); -SOAP_FMAC1 int SOAP_FMAC2 soap_getsizes(const char *, int *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_getposition(const char *, int *); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsize(struct soap*, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizesoffsets(struct soap*, const char *, const int *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putsizes(struct soap*, const char *, const int *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffset(struct soap*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_putoffsets(struct soap*, const int *, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_closesock(struct soap*); - -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new(void); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new1(soap_mode); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_new2(soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_free(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy(struct soap*); -SOAP_FMAC1 struct soap *SOAP_FMAC2 soap_copy_context(struct soap*, struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_copy_stream(struct soap*, struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_init1(struct soap*, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_init2(struct soap*, soap_mode, soap_mode); -SOAP_FMAC1 void SOAP_FMAC2 soap_done(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_cleanup(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_begin(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_end(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_delete(struct soap*, void*); - -#ifdef SOAP_DEBUG -SOAP_FMAC1 void SOAP_FMAC2 soap_set_recv_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_sent_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_test_logfile(struct soap*, const char*); -SOAP_FMAC1 void SOAP_FMAC2 soap_close_logfiles(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_open_logfile(struct soap*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_value(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_tag(struct soap*, const char*, const char *); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_array(struct soap*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element(struct soap*, const char*, int, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_out(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_array_begin_out(struct soap*, const char *tag, int id, const char *type, const char *offset); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_ref(struct soap*, const char *tag, int id, int href); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_href(struct soap*, const char *tag, int id, const char *ref, const char *val); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_null(struct soap*, const char *tag, int id, const char *type); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_id(struct soap*, const char *tag, int id, const void *p, const struct soap_array *a, int d, const char *type, int n); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_result(struct soap*, const char *tag); -SOAP_FMAC1 void SOAP_FMAC2 soap_check_result(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_out(struct soap*, const char *tag); -SOAP_FMAC1 int SOAP_FMAC2 soap_element_start_end_out(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_attribute(struct soap*, const char*, const char*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_begin_in(struct soap*, const char *tag, int nillable, const char *type); - -SOAP_FMAC1 int SOAP_FMAC2 soap_element_end_in(struct soap*, const char *tag); - -SOAP_FMAC1 int SOAP_FMAC2 soap_peek_element(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_retry(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_revert(struct soap*); - -SOAP_FMAC1 char* SOAP_FMAC2 soap_strdup(struct soap*, const char*); -SOAP_FMAC1 const char * SOAP_FMAC2 soap_strsearch(const char *big, const char *little); - -SOAP_FMAC1 int SOAP_FMAC2 soap_string_out(struct soap*, const char *s, int flag); -SOAP_FMAC1 char* SOAP_FMAC2 soap_string_in(struct soap*, int, long, long); - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_wstring_out(struct soap*, const wchar_t *s, int flag); -SOAP_FMAC1 wchar_t* SOAP_FMAC2 soap_wstring_in(struct soap*, int, long, long); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_match_namespace(struct soap*, const char *, const char*, int n1, int n2); - -SOAP_FMAC1 int SOAP_FMAC2 soap_set_namespaces(struct soap*, const struct Namespace*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_local_namespaces(struct soap*); - -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_namespace(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_push_namespace(struct soap*, const char *,const char *); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_current_namespace(struct soap *soap, const char *tag); - -SOAP_FMAC1 struct soap_nlist* SOAP_FMAC2 soap_lookup_ns(struct soap *soap, const char *tag, size_t n); - -SOAP_FMAC1 int SOAP_FMAC2 soap_store_lab(struct soap*, const char*, size_t); -SOAP_FMAC1 int SOAP_FMAC2 soap_append_lab(struct soap*, const char*, size_t); - -SOAP_FMAC1 int SOAP_FMAC2 soap_new_block(struct soap*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_push_block(struct soap*, size_t); -SOAP_FMAC1 void SOAP_FMAC2 soap_pop_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_size_block(struct soap*, size_t); -SOAP_FMAC1 char* SOAP_FMAC2 soap_first_block(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_next_block(struct soap*); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_block_size(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_save_block(struct soap*, char*, int); -SOAP_FMAC1 void SOAP_FMAC2 soap_end_block(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_out(struct soap*); -SOAP_FMAC1 int soap_envelope_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_envelope_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_out(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_out(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_body_begin_in(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_body_end_in(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_header(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_response(struct soap*, int); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_empty_response(struct soap*, int status); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_empty_response(struct soap*); - -SOAP_FMAC1 int SOAP_FMAC2 soap_send_fault(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_recv_fault(struct soap*); - -#ifndef WITH_NOSTDLIB -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault(struct soap*, FILE*); -SOAP_FMAC1 void SOAP_FMAC2 soap_print_fault_location(struct soap*, FILE*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_s2byte(struct soap*, const char*, char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2short(struct soap*, const char*, short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2int(struct soap*, const char*, int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2long(struct soap*, const char*, long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2LONG64(struct soap*, const char*, LONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2float(struct soap*, const char*, float*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2double(struct soap*, const char*, double*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedByte(struct soap*, const char*, unsigned char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedShort(struct soap*, const char*, unsigned short*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedInt(struct soap*, const char*, unsigned int*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2unsignedLong(struct soap*, const char*, unsigned long*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2ULONG64(struct soap*, const char*, ULONG64*); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2string(struct soap*, const char*, char**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2QName(struct soap*, const char*, char**); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_s2wchar(struct soap*, const char*, wchar_t**); -SOAP_FMAC1 int SOAP_FMAC2 soap_s2dateTime(struct soap*, const char*, time_t*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2base64(struct soap*, const unsigned char*, char*, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_s2hex(struct soap*, const unsigned char*, char*, int); -#endif - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_byte2s(struct soap*, char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_short2s(struct soap*, short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_int2s(struct soap*, int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_long2s(struct soap*, long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_LONG642s(struct soap*, LONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_float2s(struct soap*, float); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_double2s(struct soap*, double); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedByte2s(struct soap*, unsigned char); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedShort2s(struct soap*, unsigned short); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedInt2s(struct soap*, unsigned int); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_unsignedLong2s(struct soap*, unsigned long); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_ULONG642s(struct soap*, ULONG64); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_QName2s(struct soap*, const char*); - -#ifndef WITH_LEAN -SOAP_FMAC1 const char* SOAP_FMAC2 soap_wchar2s(struct soap*, const wchar_t*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_dateTime2s(struct soap*, time_t); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_base642s(struct soap*, const char*, char*, size_t, int*); -SOAP_FMAC1 const char* SOAP_FMAC2 soap_hex2s(struct soap*, const char*, char*, size_t, int*); -#endif - - -SOAP_FMAC1 int* SOAP_FMAC2 soap_inint(struct soap*, const char *tag, int *p, const char *, int); -SOAP_FMAC1 char* SOAP_FMAC2 soap_inbyte(struct soap*, const char *tag, char *p, const char *, int); -SOAP_FMAC1 long* SOAP_FMAC2 soap_inlong(struct soap*, const char *tag, long *p, const char *, int); -SOAP_FMAC1 LONG64* SOAP_FMAC2 soap_inLONG64(struct soap*, const char *tag, LONG64 *p, const char *, int); -SOAP_FMAC1 short* SOAP_FMAC2 soap_inshort(struct soap*, const char *tag, short *p, const char *, int); -SOAP_FMAC1 float* SOAP_FMAC2 soap_infloat(struct soap*, const char *tag, float *p, const char *, int); -SOAP_FMAC1 double* SOAP_FMAC2 soap_indouble(struct soap*, const char *tag, double *p, const char *, int); -SOAP_FMAC1 unsigned char* SOAP_FMAC2 soap_inunsignedByte(struct soap*, const char *tag, unsigned char *p, const char *, int); -SOAP_FMAC1 unsigned short* SOAP_FMAC2 soap_inunsignedShort(struct soap*, const char *tag, unsigned short *p, const char *, int); -SOAP_FMAC1 unsigned int* SOAP_FMAC2 soap_inunsignedInt(struct soap*, const char *tag, unsigned int *p, const char *, int); -SOAP_FMAC1 unsigned long* SOAP_FMAC2 soap_inunsignedLong(struct soap*, const char *tag, unsigned long *p, const char *, int); -SOAP_FMAC1 ULONG64* SOAP_FMAC2 soap_inULONG64(struct soap*, const char *tag, ULONG64 *p, const char *, int); -SOAP_FMAC1 char** SOAP_FMAC2 soap_instring(struct soap*, const char *tag, char **p, const char *, int, int, long, long); -SOAP_FMAC1 char** SOAP_FMAC2 soap_inliteral(struct soap*, const char *tag, char **p); - -#ifndef WITH_LEAN -SOAP_FMAC1 time_t* SOAP_FMAC2 soap_indateTime(struct soap*, const char *tag, time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwstring(struct soap*, const char *tag, wchar_t **p, const char *, int, long, long); -SOAP_FMAC1 wchar_t** SOAP_FMAC2 soap_inwliteral(struct soap*, const char *tag, wchar_t **p); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_outbyte(struct soap*, const char *tag, int id, const char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outshort(struct soap*, const char *tag, int id, const short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outint(struct soap*, const char *tag, int id, const int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outlong(struct soap*, const char *tag, int id, const long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outLONG64(struct soap*, const char *tag, int id, const LONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outfloat(struct soap*, const char *tag, int id, const float *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outdouble(struct soap*, const char *tag, int id, const double *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedByte(struct soap*, const char *tag, int id, const unsigned char *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedShort(struct soap*, const char *tag, int id, const unsigned short *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedInt(struct soap*, const char *tag, int id, const unsigned int *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outunsignedLong(struct soap*, const char *tag, int id, const unsigned long *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outULONG64(struct soap*, const char *tag, int id, const ULONG64 *p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outstring(struct soap*, const char *tag, int id, char *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outliteral(struct soap*, const char *tag, char *const*p, const char *type); - -#ifndef WITH_LEAN -SOAP_FMAC1 int SOAP_FMAC2 soap_outdateTime(struct soap*, const char *tag, int id, const time_t *p, const char *, int); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_outwstring(struct soap*, const char *tag, int id, wchar_t *const*p, const char *, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_outwliteral(struct soap*, const char *tag, wchar_t *const*p, const char *type); -#endif - -#ifndef WITH_LEANER -SOAP_FMAC1 int SOAP_FMAC2 soap_attachment(struct soap *, const char*, int, const void*, const struct soap_array*, const char*, const char*, const char*, int, const char*, int); -SOAP_FMAC1 int SOAP_FMAC2 soap_move(struct soap*, long); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_tell(struct soap*); -SOAP_FMAC1 char* SOAP_FMAC2 soap_dime_option(struct soap*, unsigned short, const char*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putdime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmimehdr(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_getmime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmimehdr(struct soap*, struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_putmime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_set_mime(struct soap*, const char *boundary, const char *start); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_dime(struct soap*); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_mime(struct soap*); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_dime_attachment(struct soap*, char *ptr, size_t size, const char *type, const char *id, unsigned short optype, const char *option); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_mime_attachment(struct soap*, char *ptr, size_t size, enum soap_mime_encoding encoding, const char *type, const char *id, const char *location, const char *description); -SOAP_FMAC1 void SOAP_FMAC2 soap_post_check_mime_attachments(struct soap *soap); -SOAP_FMAC1 int SOAP_FMAC2 soap_check_mime_attachments(struct soap *soap); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_get_mime_attachment(struct soap *soap, void *handle); -SOAP_FMAC1 struct soap_multipart* SOAP_FMAC2 soap_next_multipart(struct soap_multipart*); -SOAP_FMAC1 int SOAP_FMAC2 soap_match_cid(struct soap*, const char*, const char*); -#endif - -SOAP_FMAC1 int SOAP_FMAC2 soap_register_plugin_arg(struct soap*, int (*fcreate)(struct soap*, struct soap_plugin*, void*), void*); -SOAP_FMAC1 void* SOAP_FMAC2 soap_lookup_plugin(struct soap*, const char*); - -SOAP_FMAC1 const char* SOAP_FMAC2 soap_attr_value(struct soap *soap, const char *name, int flag); -SOAP_FMAC1 int SOAP_FMAC2 soap_set_attr(struct soap *soap, const char *name, const char *value); -SOAP_FMAC1 void SOAP_FMAC2 soap_clr_attr(struct soap *soap); - -#ifdef WITH_COOKIES -SOAP_FMAC1 void SOAP_FMAC2 soap_getcookies(struct soap *soap, const char *val); -SOAP_FMAC1 size_t SOAP_FMAC2 soap_encode_cookie(const char*, char*, size_t); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_set_cookie(struct soap*, const char*, const char*, const char*, const char*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern char* SOAP_FMAC2 soap_env_cookie_value(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern time_t SOAP_FMAC2 soap_cookie_expire(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_expire(struct soap*, const char*, long, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_set_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_clr_cookie_session(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_clr_cookie(struct soap*, const char*, const char*, const char*); -SOAP_FMAC1 extern int SOAP_FMAC2 soap_getenv_cookies(struct soap*); -SOAP_FMAC1 extern struct soap_cookie* SOAP_FMAC2 soap_copy_cookies(struct soap*, struct soap*); -SOAP_FMAC1 extern void SOAP_FMAC2 soap_free_cookies(struct soap*); -#endif - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif diff --git a/org.glite.security.gsoap-plugin/test/test_gsplugin_cxx.cpp b/org.glite.security.gsoap-plugin/test/test_gsplugin_cxx.cpp deleted file mode 100644 index 4caad45..0000000 --- a/org.glite.security.gsoap-plugin/test/test_gsplugin_cxx.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include - -#include "stdsoap2.h" -#include "glite_gsplugin.h" - -#define TEST_STR "123456789ABCDEF" - -int main() { - struct soap *mydlo = NULL; - glite_gsplugin_Context gsplugin_ctx = NULL; - int ok1, ok2; - - // test 1 - stdsoap2.c compatibility - if ((mydlo = soap_new()) == NULL) { - std::cerr << "Couldn't create soap" << std::endl; - return 1; - } - soap_set_endpoint(mydlo, TEST_STR); - std::cout << mydlo->endpoint << std::endl; - ok1 = strcmp(mydlo->endpoint, TEST_STR); - - // test 2 - glite_gsplugin.c compatibility - // - // not real test, just may crash in bad test case on calling - // soap->fdelete where will be other function - if ( glite_gsplugin_init_context(&gsplugin_ctx) ) { - std::cerr << "Couldn't create gSOAP plugin context" << std::endl; - goto err; - } - if (soap_register_plugin_arg(mydlo, glite_gsplugin, gsplugin_ctx)) { - std::cerr << "Couldn't register gSoap plugin" << std::endl; - goto err; - } - - soap_done(mydlo); - free(mydlo); - glite_gsplugin_free_context(gsplugin_ctx); - return ok1 && ok2; - -err: - if (gsplugin_ctx) glite_gsplugin_free_context(gsplugin_ctx); - if (mydlo) soap_destroy(mydlo); - return 1; -} - -Namespace namespaces[] = {{NULL, NULL, NULL, NULL}}; diff --git a/org.glite.security.gss/LICENSE b/org.glite.security.gss/LICENSE deleted file mode 100644 index 259a91f..0000000 --- a/org.glite.security.gss/LICENSE +++ /dev/null @@ -1,69 +0,0 @@ -LICENSE file for EGEE Middleware -================================ - -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), Finlan -University of Bergen (UiB), Norway -Council for the Central Laboratory of the Research Councils (CCLRC), United Kingdom - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -3. The end-user documentation included with the redistribution, if -any, must include the following acknowledgment: "This product includes -software developed by The EU EGEE Project (http://cern.ch/eu-egee/)." -Alternatively, this acknowledgment may appear in the software itself, if -and wherever such third-party acknowledgments normally appear. - -4. The names EGEE and the EU EGEE Project must not be -used to endorse or promote products derived from this software without -prior written permission. For written permission, please contact -. - -5. You are under no obligation whatsoever to provide anyone with any -bug fixes, patches, or upgrades to the features, functionality or -performance of the Software ("Enhancements") that you may develop over -time; however, if you choose to provide your Enhancements to The EU -EGEE Project, or if you choose to otherwise publish or distribute your -Enhancements, in source code form without contemporaneously requiring -end users of The EU EGEE Proejct to enter into a separate written license -agreement for such Enhancements, then you hereby grant The EU EGEE Project -a non-exclusive, royalty-free perpetual license to install, use, copy, -modify, prepare derivative works, incorporate into the EGEE Middleware -or any other computer software, distribute, and sublicense your -Enhancements or derivative works thereof, in binary and source code -form (if any), whether developed by The EU EGEE Project or third parties. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL PROJECT OR ITS CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -This software consists of voluntary contributions made by many -individuals on behalf of the EU EGEE Prject. For more information on The -EU EGEE Project, please see http://cern.ch/eu-egee/. For more information on -EGEE Middleware, please see http://egee-jra1.web.cern.ch/egee-jra1/ - - diff --git a/org.glite.security.gss/Makefile b/org.glite.security.gss/Makefile deleted file mode 100644 index 37d3921..0000000 --- a/org.glite.security.gss/Makefile +++ /dev/null @@ -1,140 +0,0 @@ -# defaults -top_srcdir=.. -builddir=build -top_builddir=${top_srcdir}/${builddir} -stagedir=. -globalprefix=glite -package=gss -version=1.0.0 -PREFIX=/opt/glite - -glite_location=/opt/glite -globus_prefix=/opt/globus -nothrflavour=gcc32 -thrflavour=gcc32pthr - -CC=gcc - --include Makefile.inc --include ../Makefile.inc - -offset=0 -version_info:=-version-info ${shell \ - perl -e '$$,=":"; @F=split "\\.","${version}"; print $$F[0]+$$F[1]+${offset},$$F[2],$$F[1]' } - -# version_info=-version-info `echo ${version} | cut -d. -f1,2 | tr . :` - -VPATH=${top_srcdir}/src:${top_srcdir}/test - -TEST_LIBS:=-L${cppunit_prefix}/${libdir} -lcppunit -TEST_INC:=-I${cppunit_prefix}/include - -default: all - -DEBUG:=-g -O0 -W -Wall -Wno-unused-parameter -# not for globus, gsoap: -Werror - -CFLAGS:= ${DEBUG} \ - -DVERSION=\"${version}\" \ - -I. -I${top_srcdir}/interface \ - -I${stagedir}/include \ - -I${cares_prefix}/include \ - ${COVERAGE_FLAGS} -D_GNU_SOURCE -DDATAGRID_EXTENSION - -LDFLAGS:=${COVERAGE_FLAGS} - -COMPILE:=libtool --mode=compile ${CC} ${CFLAGS} -LINK:=libtool --mode=link ${CC} -rpath ${stagedir}/${libdir} ${LDFLAGS} -LINKXX:=libtool --mode=link ${CXX} -rpath ${stagedir}/${libdir} ${LDFLAGS} -INSTALL:=libtool --mode=install install - -GLOBUS_INC:= -I${globus_prefix}/include/${nothrflavour} -GLOBUS_THR_INC:= -I${globus_prefix}/include/${thrflavour} - -GLOBUS_LIBS:= -L${globus_prefix}/lib \ - -lglobus_common_${nothrflavour} \ - -lglobus_gssapi_gsi_${nothrflavour} \ - -GLOBUS_THR_LIBS:= -L${globus_prefix}/lib \ - -lglobus_common_${thrflavour} \ - -lglobus_gssapi_gsi_${thrflavour} - -ARES_LIBS:=-L${cares_prefix}/lib -lcares - -EX_LIBS:= ${GLOBUS_LIBS} ${ARES_LIBS} -EX_THRLIBS := ${GLOBUS_THR_LIBS} ${ARES_LIBS} - -HDRS:=glite_gss.h - -GSS_OBJS:=glite_gss.o -GSS_LOBJS:=${GSS_OBJS:.o=.lo} -GSS_THROBJS:=${GSS_OBJS:.o=.thr.o} -GSS_THRLOBJS:=${GSS_OBJS:.o=.thr.lo} - -GSS_STATICLIB:=libglite_security_gss_${nothrflavour}.a -GSS_THRSTATICLIB:=libglite_security_gss_${thrflavour}.a -GSS_LTLIB:=libglite_security_gss_${nothrflavour}.la -GSS_THRLTLIB:=libglite_security_gss_${thrflavour}.la - -${GSS_STATICLIB}: ${GSS_OBJS} - ar crv $@ ${GSS_OBJS} - ranlib $@ - -${GSS_THRSTATICLIB}: ${GSS_THROBJS} - ar crv $@ ${GSS_THROBJS} - ranlib $@ - -${GSS_LTLIB}: ${GSS_OBJS} - ${LINK} ${version_info} -o $@ ${GSS_LOBJS} ${EX_LIBS} - -${GSS_THRLTLIB}: ${GSS_THROBJS} - ${LINK} ${version_info} -o $@ ${GSS_THRLOBJS} ${EX_THRLIBS} - - -all compile: \ - ${GSS_STATICLIB} ${GSS_LTLIB} ${GSS_THRSTATICLIB} ${GSS_THRLTLIB} \ - examples - -check: compile check.gss - -check.gss: test_gss - # ./test_gss out.xml - echo test_gss not run automatically util we have got some credentials in X509_USER_PROXY - -test_gss: test_gss.o - ${LINKXX} -o $@ test_gss.o ${GSS_LTLIB} ${TEST_LIBS} ${GLOBUS_LIBS} ${EX_LIBS} - -test_coverage: - -mkdir coverage - cd coverage && $(MAKE) -f ../Makefile top_srcdir=../../ COVERAGE_FLAGS="-fprofile-arcs -ftest-coverage" check - cd coverage && for i in ${OBJS}; do gcov -o .libs/ $$i ; done - -examples: - -doc: - -stage: - $(MAKE) install PREFIX=${stagedir} DOSTAGE=yes - -install: - -mkdir -p ${PREFIX}/${libdir} - -mkdir -p ${PREFIX}/share/doc/${package}-${version} - -mkdir -p ${PREFIX}/include/glite/security - ${INSTALL} -m 755 ${GSS_LTLIB} ${GSS_THRLTLIB} ${PREFIX}/${libdir} - ${INSTALL} -m 644 ${top_srcdir}/LICENSE ${PREFIX}/share/doc/${package}-${version} - cd ${top_srcdir}/interface && ${INSTALL} -m 644 ${HDRS} ${PREFIX}/include/glite/security/ - if [ x${DOSTAGE} = xyes ]; then \ - install -m 644 ${GSS_STATICLIB} ${GSS_THRSTATICLIB} ${PREFIX}/${libdir}; \ - fi - -clean: - rm -rf *.o *.lo *.a *.la .libs test_gss - -%.o: %.c - ${COMPILE} ${GLOBUS_INC} -o $@ -c $< - -%.thr.o: %.c - ${COMPILE} ${GLOBUS_THR_INC} -o $@ -c $< - -test_gss.o: %.o: %.cpp - ${CXX} -c ${CFLAGS} ${GLOBUS_INC} ${TEST_INC} -Wno-error $< diff --git a/org.glite.security.gss/configure b/org.glite.security.gss/configure deleted file mode 100755 index b3a5b00..0000000 --- a/org.glite.security.gss/configure +++ /dev/null @@ -1,698 +0,0 @@ -#!/usr/bin/perl - -# WARNING: Don't edit this file unless it is the master copy in org.glite.lb -# -# For the purpose of standalone builds of lb/jobid/lbjp-common components -# it is copied on tagging - -# $Header$ - -use Getopt::Long; - -my $pwd = `pwd`; chomp $pwd; -my $prefix = $pwd.'/stage'; -my $stagedir; -my $staged; -my $module; -my $thrflavour = 'gcc64dbgpthr'; -my $nothrflavour = 'gcc64dbg'; -my $mode = 'build'; -my $help = 0; -my $listmodules; -my $version; -my $output; -my $lb_tag = ''; -my $lbjp_tag = ''; -my $jp_tag = ''; -my $sec_tag = ''; -my $jobid_tag = ''; -my $libdir = 'lib'; - -my @nodes = qw/client server logger utils doc ws-test db jpprimary jpindex jpclient/; -my %enable_nodes; -my %disable_nodes; - -my %extern_prefix = ( - cares => '/opt/c-ares', - classads => '/opt/classads', - cppunit => '/usr', - expat => '/usr', - globus => '/opt/globus', - jglobus => '/opt/globus', - gsoap => '/usr', - mysql => '/usr', - 'mysql-devel' => '', - 'mysql-server' => '', - voms => '/opt/glite', - gridsite => '/opt/glite', - lcas => '/opt/glite', - ant => '/usr', - jdk => '/usr', - libtar => '/usr', -); - -my %jar = ( - 'commons-codec' => '/usr/share/java/commons-codec-1.3.jar', -); - - -my %glite_prefix; -my %need_externs; -my %need_externs_type; -my %need_jars; -my %extrafull; -my %extranodmod; -my %deps; -my %deps_type; -my %topbuild; - -my %lbmodules = ( - 'lb' => [ qw/client common doc logger server state-machine types utils ws-interface ws-test/], - 'security' => [qw/gss gsoap-plugin/], - 'lbjp-common' => [qw/db maildir server-bones trio jp-interface/], - 'jobid' => [qw/api-c api-cpp/], - 'jp' => [ qw/client doc index primary server-common ws-interface/ ], - ); - - -my @opts = ( - 'prefix=s' => \$prefix, - 'staged=s' => \$staged, - 'module=s' => \$module, - 'thrflavour=s' => \$thrflavour, - 'nothrflavour=s' => \$nothrflavour, - 'mode=s' => \$mode, - 'listmodules=s' => \$listmodules, - 'version=s' => \$version, - 'output=s' => \$output, - 'stage=s' => \$stagedir, - 'lb-tag=s' => \$lb_tag, - 'lbjp-common-tag=s' => \$lbjp_tag, - 'jp-tag=s' => \$jp_tag, - 'security-tag=s' => \$sec_tag, - 'jobid-tag=s' => \$jobid_tag, - 'help' => \$help, - 'libdir=s' => \$libdir, -); - -for (@nodes) { - $enable_nodes{$_} = 0; - $disable_nodes{$_} = 0; - - push @opts,"disable-$_",\$disable_nodes{$_}; - push @opts,"enable-$_",\$enable_nodes{$_}; -} - -push @opts,"with-$_=s",\$extern_prefix{$_} for keys %extern_prefix; -push @opts,"with-$_=s",\$jar{$_} for keys %jar; - -my @keeparg = @ARGV; - -GetOptions @opts or die "Errors parsing command line\n"; - -$extern_prefix{'mysql-devel'}=$extern_prefix{mysql} if $extern_prefix{'mysql-devel'} eq ''; -$extern_prefix{'mysql-server'}=$extern_prefix{mysql} if $extern_prefix{'mysql-server'} eq ''; - -if ($help) { usage(); exit 0; } - -if ($listmodules) { - my @m = map "org.glite.$listmodules.$_",@{$lbmodules{$listmodules}}; - print "@m\n"; - exit 0; -} - -warn "$0: --version and --output make sense only in --mode=etics\n" - if ($version || $output) && $mode ne 'etics'; - -my $en; -for (keys %enable_nodes) { $en = 1 if $enable_nodes{$_}; } - -my $dis; -for (keys %disable_nodes) { $dis = 1 if $disable_nodes{$_}; } - -die "--enable-* and --disable-* are mutually exclusive\n" - if $en && $dis; - -die "--module cannot be used with --enable-* or --disable-*\n" - if $module && ($en || $dis); - -die "$module: unknown module\n" if $module && ! grep $module,@{$lbmodules{lb}},@{$lbmodules{security}},{$lbmodules{jp}}; - -if ($dis) { - for (@nodes) { - $enable_nodes{$_} = 1 unless $disable_nodes{$_}; - } -} - -if (!$en && !$dis) { $enable_nodes{$_} = 1 for (@nodes) } ; - -for (keys %enable_nodes) { delete $enable_nodes{$_} unless $enable_nodes{$_}; } - -$stagedir = $prefix unless $stagedir; - -if ($mode eq 'build') { - print "Writing config.status\n"; - open CONF,">config.status" or die "config.status: $!\n"; - print CONF "$0 @keeparg\n"; - close CONF; -} - - -my @modules; -my %aux; - -if ($module) { -# push @modules,split(/[,.]+/,$module); - push @modules,$module; -} -else { - @modules = map(($extranodmod{$_} ? $extranodmod{$_} : 'lb.'.$_),(keys %enable_nodes)); - - my $n; - - do { - local $"="\n"; - $n = $#modules; - push @modules,(map @{$deps{$_}},@modules); - - undef %aux; @aux{@modules} = (1) x ($#modules+1); - @modules = keys %aux; - } while ($#modules > $n); -} - -@aux{@modules} = (1) x ($#modules+1); -delete $aux{$_} for (split /,/,$staged); -@modules = keys %aux; - -mode_build() if $mode eq 'build'; -mode_checkout() if $mode eq 'checkout'; -mode_etics($module) if $mode eq 'etics'; - -sub mode_build { - print "\nBuilding modules: @modules\n"; - - my @ext = map @{$need_externs{$_}},@modules; - my @myjars = map @{$need_jars{$_}},@modules; - undef %aux; @aux{@ext} = 1; - @ext = keys %aux; - undef %aux; @aux{@myjars} = (1) x ($#myjars+1); - @myjars = keys %aux; - - print "\nRequired externals:\n"; - print "\t$_: $extern_prefix{$_}\n" for @ext; - print "\t$_: $jar{$_}\n" for @myjars; - print "\nThis is a poor-man configure, it's up to you to have sources and externals there\n\n"; - - mkinc($_) for @modules; - - print "Creating Makefile\n"; - - open MAK,">Makefile" or die "Makefile: $!\n"; - - print MAK "all: @modules\n\nclean:\n"; - - for (@modules) { - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - print MAK "\tcd $full$build && \${MAKE} clean\n" - } - - print MAK "\ndistclean:\n"; - - for (@modules) { - my $full = full($_); - print MAK $topbuild{$_} ? - "\tcd $full$build && \${MAKE} distclean\n" : - "\trm -rf $full$build\n" - } - - print MAK "\n"; - - for (@modules) { - my %ldeps; undef %ldeps; - @ldeps{@{$deps{$_}}} = 1; - for my $x (split /,/,$staged) { delete $ldeps{$x}; } - my @dnames = $module ? () : keys %ldeps; - - my $full = full($_); - my $build = $topbuild{$_} ? '': '/build'; - - print MAK "$_: @dnames\n\tcd $full$build && \${MAKE} && \${MAKE} install\n\n"; - } - - close MAK; -} - -sub mode_checkout() { - for (@modules) { - my $module = $_; - my $tag = ""; - if ($lb_tag){ - for (@{$lbmodules{lb}}){ - if ("lb.".$_ eq $module){ - $tag = '-r '.$lb_tag; - } - } - } - if ($lbjp_tag){ - for (@{$lbmodules{'lbjp-common'}}){ - if ("lbjp-common.".$_ eq $module){ - $tag = '-r '.$lbjp_tag; - } - } - } - if ($jp_tag){ - for (@{$lbmodules{'jp'}}){ - if ("jp.".$_ eq $module){ - $tag = '-r '.$jp_tag; - } - } - } - if ($sec_tag){ - for (@{$lbmodules{security}}){ - if ("security.".$_ eq $module){ - $tag = '-r '.$sec_tag; - } - } - } - if ($jobid_tag){ - for (@{$lbmodules{jobid}}){ - if ("jobid.".$_ eq $module){ - $tag = '-r '.$jobid_tag; - } - } - } - #if (grep {"lb.".$_ eq $module} @{$lbmodules{lb}}){ - # print "found"; - #} - $_ = full($_); - print "\n*** Checking out $_\n"; - system("cvs checkout $tag $_") == 0 or die "cvs checkout $tag $_: $?\n"; - } -} - -BEGIN{ -%need_externs_aux = ( - 'lb.client' => [ qw/cppunit:B classads/ ], - 'lb.client-java' => [ qw/ant:B jglobus jdk:B/ ], - 'lb.common' => [ qw/expat cppunit:B classads/ ], - 'lb.doc' => [], - 'lb.logger' => [ qw/cppunit:B/ ], - 'lb.server' => [ qw/globus_essentials:R globus:B expat cares mysql:R mysql-server:R mysql-devel:B cppunit:B gsoap:B classads voms lcas gridsite/ ], - 'lb.state-machine' => [ qw/classads/ ], - 'lb.utils' => [ qw/cppunit:B/ ], - 'lb.ws-interface' => [], - 'lb.ws-test' => [ qw/gsoap:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/mysql:R mysql-devel:B/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw/cppunit:B/ ], - 'lbjp-common.jp-interface' => [ qw/cppunit:B/ ], - 'security.gss' => [ qw/globus_essentials:R globus:B cares cppunit:B/ ], - 'security.gsoap-plugin' => [ qw/cppunit:B globus_essentials:R globus:B cares gsoap:B/ ], - 'jobid.api-c' => [ qw/cppunit:B/ ], - 'jobid.api-cpp' => [ qw/cppunit:B/ ], - 'jobid.api-java' => [ qw/ant:B jdk:B/ ], - 'jp.client' => [ qw/gsoap libtar globus_essentials:R globus:B/ ], - 'jp.doc' => [], - 'jp.index' => [ qw/gsoap globus_essentials:R globus:B/ ], - 'jp.primary' => [ qw/classads gsoap libtar globus_essentials:R globus:B/ ], - 'jp.server-common' => [], - 'jp.ws-interface' => [], -); - -for my $ext (keys %need_externs_aux) { - for (@{$need_externs_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$need_externs{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $need_externs_type{$ext}->{$1} = $type; - } -} - -%need_jars = ( - 'jobid.api-java' => [ qw/commons-codec/ ], -); - -for my $jar (keys %need_jars) { - for (@{$need_jars{$jar}}) { - $need_externs_type{$jar}->{$_} = 'BR'; # XXX - } -} - -%deps_aux = ( - 'lb.client' => [ qw/ - lb.types:B lb.common - lbjp-common.trio - jobid.api-cpp jobid.api-c - security.gss - / ], - 'lb.client-java' => [ qw/ - lb.types:B - jobid.api-java - / ], - 'lb.common' => [ qw/ - jobid.api-cpp jobid.api-c - lb.types:B lbjp-common.trio security.gss - / ], - 'lb.doc' => [ qw/lb.types:B/ ], - 'lb.logger' => [ qw/ - lbjp-common.trio - jobid.api-c - lb.common - security.gss - / ], - 'lb.server' => [ qw/ - lb.ws-interface lb.types:B lb.common lb.state-machine - lbjp-common.db lbjp-common.server-bones lbjp-common.trio lbjp-common.maildir - jobid.api-c - security.gsoap-plugin security.gss - / ], - 'lb.state-machine' => [ qw/lb.types:B lb.common lbjp-common.jp-interface security.gss/ ], - 'lb.utils' => [ qw/ - lbjp-common.jp-interface - jobid.api-c - lbjp-common.trio lbjp-common.maildir - lb.client lb.state-machine - / ], - 'lb.ws-test' => [ qw/security.gsoap-plugin lb.ws-interface/ ], - 'lb.ws-interface' => [ qw/lb.types:B/ ], - 'lb.types' => [ qw// ], - 'lbjp-common.db' => [ qw/lbjp-common.trio/ ], - 'lbjp-common.maildir' => [ qw// ], - 'lbjp-common.server-bones' => [ qw// ], - 'lbjp-common.trio' => [ qw// ], - 'security.gss' => [ qw// ], - 'security.gsoap-plugin' => [ qw/security.gss/ ], - 'jobid.api-c' => [ qw// ], - 'jobid.api-cpp' => [ qw/jobid.api-c/ ], - 'jobid.api-java' => [ qw// ], - - 'lbjp-common.jp-interface' => [ qw/lbjp-common.db jobid.api-c/ ], - - 'jp.client' => [ qw/ - jp.ws-interface - lbjp-common.jp-interface lbjp-common.maildir - jobid.api-c - security.gsoap-plugin - / ], - 'jp.doc' => [ qw// ], - 'jp.index' => [ qw/ - jp.server-common jp.ws-interface - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.primary' => [ qw/ - jobid.api-c - jp.server-common jp.ws-interface - lb.state-machine - lbjp-common.jp-interface lbjp-common.trio lbjp-common.db lbjp-common.server-bones - security.gsoap-plugin - / ], - 'jp.server-common' => [ qw/ - lbjp-common.jp-interface lbjp-common.db - / ], - 'jp.ws-interface' => [ qw// ], -); - -for my $ext (keys %deps_aux) { - for (@{$deps_aux{$ext}}) { - /([^:]*)(?::(.*))?/; - push @{$deps{$ext}},$1; - my $type = $2 ? $2 : 'BR'; - $deps_type{$ext}->{$1} = $type; - } -} - - -%extrafull = ( gridsite=>'org.gridsite.core'); - -#( java => 'client-java' ); -%extranodmod = ( - db => 'lbjp-common.db', - jpprimary => 'jp.primary', - jpindex => 'jp.index', - jpclient => 'jp.client', -); - -my @t = qw/lb.client-java jobid.api-java lb.types/; -@topbuild{@t} = (1) x ($#t+1); -} - -sub full -{ - my $short = shift; - return $extrafull{$short} ? $extrafull{$short} : 'org.glite.'.$short; -} - -sub mkinc -{ - my %aux; - undef %aux; - my @m=qw/ -lb.client lb.doc lb.state-machine lb.ws-interface lb.logger lb.types lb.common lb.server lb.utils lb.ws-test lb.client-java -security.gss security.gsoap-plugin -jobid.api-c jobid.api-cpp jobid.api-java -lbjp-common.db lbjp-common.maildir lbjp-common.server-bones lbjp-common.trio lbjp-common.jp-interface -jp.client jp.doc jp.index jp.primary jp.server-common jp.ws-interface -/; - @aux{@m} = (1) x ($#m+1); - - my $short = shift; - my $full = full $short; - - unless ($aux{$short}) { - print "Makefile.inc not needed in $full\n"; - return; - } - - my $build = ''; - - unless ($topbuild{$_}) { - $build = '/build'; - unless (-d "$full/build") { - mkdir "$full/build" or die "mkdir $full/build: $!\n"; - } - unlink "$full/build/Makefile"; - symlink "../Makefile","$full/build/Makefile" or die "symlink ../Makefile $full/build/Makefile: $!\n"; - } - - open MKINC,">$full$build/Makefile.inc" - or die "$full$build/Makefile.inc: $!\n"; - - print "Creating $full$build/Makefile.inc\n"; - - print MKINC qq{ -PREFIX = $prefix -stagedir = $stagedir -thrflavour = $thrflavour -nothrflavour = $nothrflavour -libdir = $libdir -}; - - for (@{$need_externs{$short}}) { - print MKINC "${_}_prefix = $extern_prefix{$_}\n" - } - - for (@{$need_jars{$short}}) { - print MKINC "${_}_jar = $jar{$_}\n" - } - - my $need_gsoap = 0; - for (@{$need_externs{$short}}) { $need_gsoap = 1 if $_ eq 'gsoap'; } - - print MKINC "gsoap_default_version=".gsoap_version()."\n" if $need_gsoap; - - close MKINC; -} - -my %etics_externs; -my %etics_projects; -BEGIN{ - %etics_externs = ( - globus_essentials=>'vdt_globus_essentials', - globus=>'globus', - cares=>'c-ares', - voms=>'org.glite.security.voms-api-cpp', - gridsite=>'org.gridsite.shared', - lcas=>'org.glite.security.lcas', - ); - %etics_projects = ( - vdt=>[qw/globus globus_essentials/], - 'org.glite'=>[qw/voms gridsite lcas/], - ); -}; - -sub mode_etics { - $fmod = shift; - - die "$0: --module required with --etics\n" unless $fmod; - - my ($subsys,$module) = split /\./,$fmod; - - my ($major,$minor,$rev,$age); - - if ($version) { - $version =~ /([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)-(.+)/; - ($major,$minor,$rev,$age) = ($1,$2,$3,$4); - } - else { - open V,"org.glite.$subsys.$module/project/version.properties" - or die "org.glite.$subsys.$module/project/version.properties: $!\n"; - - while ($_ = ) { - chomp; - ($major,$minor,$rev) = ($1,$2,$3) if /module\.version\s*=\s*([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)/; - $age = $1 if /module\.age\s*=\s*([[:digit:]]+)/; - } - close V; - } - - my @copts = (); - my %ge; - @ge{@{$etics_projects{'org.glite'}}} = (1) x ($#{$etics_projects{'org.glite'}}+1); - - for (@{$need_externs{"$subsys.$module"}}) { - if ($need_externs_type{"$subsys.$module"}->{$_}=~/B/) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - push @copts,$ge{$_} ? "--with-$_=\${stageDir}" : "--with-$_=\${$eext.location}"; - } - } - - for (@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - push @copts,"--with-$_ \${$eext.location}/$_*.jar"; - } - - - my $conf = "glite-$subsys-${module}_R_${major}_${minor}_${rev}_${age}"; - my $file = $output ? $output : "$conf.ini"; - open C,">$file" or die "$file: $!\n"; - - my $buildroot = $topbuild{"$subsys.$module"} ? '' : "build.root = build\n"; - - my $confdir = $topbuild{"$subsys.$module"} ? '..' : '../..'; - - print STDERR "Writing $file\n"; - print C qq{ -[Configuration-$conf] -profile = None -moduleName = org.glite.$subsys.$module -displayName = $conf -description = org.glite.$subsys.$module -projectName = org.glite -age = $age -deploymentType = None -tag = $conf -version = $major.$minor.$rev -path = \${projectName}/\${moduleName}/\${version}/\${platformName}/\${packageName}-\${version}-\${age}.tar.gz - -[Platform-default:VcsCommand] -displayName = None -description = None -tag = cvs -d \${vcsroot} tag -R \${tag} \${moduleName} -branch = None -commit = None -checkout = cvs -d \${vcsroot} co -r \${tag} \${moduleName} - -[Platform-default:BuildCommand] -postpublish = None -packaging = None -displayName = None -description = None -doc = None -prepublish = None -publish = None -compile = make -init = None -install = make install -clean = make clean -test = make check -configure = cd $confdir && \${moduleName}/configure --thrflavour=\${globus.thr.flavor} --nothrflavour=\${globus.nothr.flavor} --prefix=\${prefix} --stage=\${stageDir} --libdir=\${libdir} --module $subsys.$module @copts -checkstyle = None - -[Platform-default:Property] -$buildroot - -[Platform-default:DynamicDependency] - -}; - for (@{$need_externs{"$subsys.$module"}},@{$need_jars{"$subsys.$module"}}) { - my $eext = $etics_externs{$_} ? $etics_externs{$_} : $_; - - my $proj = 'externals'; - for my $p (keys %etics_projects) { - for $m (@{$etics_projects{$p}}) { - $proj = $p if $m eq $_; - } - } - - my $type = $need_externs_type{"$subsys.$module"}->{$_}; - print C "$proj|$eext = $type\n"; - } - - for (@{$deps{"$subsys.$module"}}) { - my $type = $deps_type{"$subsys.$module"}->{$_}; - print C "org.glite|org.glite.$_ = $type\n"; - } - - close C; -} - -sub gsoap_version { - local $_; - my $gsoap_version; - open S,"$extern_prefix{gsoap}/bin/soapcpp2 -v 2>&1 |" or die "$extern_prefix{gsoap}/bin/soapcpp2: $!\n"; - - while ($_ = ) { - chomp; - - $gsoap_version = $1 if /The gSOAP Stub and Skeleton Compiler for C and C\+\+ ([.[:digit:][:alpha:]]+)$/; - } - close S; - return $gsoap_version; -} - - -sub usage { - my @ext = keys %extern_prefix; - my @myjars, keys %jar; - - print STDERR qq{ -usage: $0 options - -General options (defaults in []): - --prefix=PREFIX destination directory [./stage] - --staged=module,module,... what is already in PREFIX (specify without org.glite.) - --thrflavour=flavour - --nothrflavour=flavour threaded and non-treaded flavours [gcc64dbgpthr,gcc64dbg] - --listmodules=subsys list modules of a subsystem - --libdir=libdir typically [lib,lib64] postfix - -Mode of operation: - --mode={checkout|build|etics} what to do [build] - -What to build: - --module=module build this module only (mostly in-Etics operation) - --enable-NODE build this "node" (set of modules) only. Available nodes are - @{$lbmodules{lb}},@{$lbmodules{security}} - --disable-NODE don't build this node - --lb-tag=tag checkout LB modules with specific tag - --jp-tag=tag checkout JP modules with specific tag - --lbjp-common-tag=tag checkout lbjp-common modules with specific tag - --security-tag=tag checkout security modules with specific tag - --jobid-tag=tag checkout jobid modules with specific tag - -Dependencies: - --with-EXTERNAL=PATH where to look for an external. Required externals - (not all for all modules) are: - @ext - --with-JAR=JAR where to look for jars. Required jars are: - @myjars - Summary of what will be used is always printed - -}; - -} diff --git a/org.glite.security.gss/interface/glite_gss.h b/org.glite.security.gss/interface/glite_gss.h deleted file mode 100644 index ae3971c..0000000 --- a/org.glite.security.gss/interface/glite_gss.h +++ /dev/null @@ -1,163 +0,0 @@ -#ifndef __EDG_WORKLOAD_LOGGING_COMMON_LB_GSS_H__ -#define __EDG_WORKLOAD_LOGGING_COMMON_LB_GSS_H__ - -#ident "$Header$" - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -enum { - EDG_WLL_GSS_OK = 0, /* no GSS errors */ - EDG_WLL_GSS_ERROR_GSS = -1, /* GSS specific error, call edg_wll_get_gss_error() for details */ - EDG_WLL_GSS_ERROR_TIMEOUT = -2, /* Timeout */ - EDG_WLL_GSS_ERROR_EOF = -3, /* EOF occured */ - EDG_WLL_GSS_ERROR_ERRNO = -4, /* System error. See errno */ - EDG_WLL_GSS_ERROR_HERRNO = -5 /* Resolver error. See h_errno */ -}; - -enum { - EDG_WLL_GSS_FLAG_DELEG = 1, - EDG_WLL_GSS_FLAG_CONF = 16, - EDG_WLL_GSS_FLAG_INTEG = 32, - EDG_WLL_GSS_FLAG_ANON = 64, -}; - -typedef void * edg_wll_GssCtx; - -typedef struct _edg_wll_GssConnection { - edg_wll_GssCtx context; - int sock; - char *buffer; - size_t bufsize; -} edg_wll_GssConnection; - -typedef struct _edg_wll_GssStatus { - unsigned int major_status; - unsigned int minor_status; -} edg_wll_GssStatus; - -typedef struct _edg_wll_GssPrincipal_data { - char *name; - unsigned int flags; -#if 0 - char **fqans; - char **voms_groups; /* needed for legacy LB server authZ mechanism */ - edg_wll_GssOid authn_mech; -#endif -} edg_wll_GssPrincipal_data; -typedef struct _edg_wll_GssPrincipal_data *edg_wll_GssPrincipal; - -typedef struct _edg_wll_GssCred_data { - void *gss_cred; - time_t lifetime; - char *name; -} _edg_wll_GssCred_data; -typedef struct _edg_wll_GssCred_data *edg_wll_GssCred; - -int -edg_wll_gss_initialize(void); - -int -edg_wll_gss_acquire_cred_gsi(const char *cert_file, - const char *key_file, - edg_wll_GssCred *cred, - edg_wll_GssStatus* gss_code); - -int -edg_wll_gss_release_cred(edg_wll_GssCred *cred, - edg_wll_GssStatus* gss_code); - -int -edg_wll_gss_connect(edg_wll_GssCred cred, - char const *hostname, - int port, - struct timeval *timeout, - edg_wll_GssConnection *connection, - edg_wll_GssStatus* gss_code); - -int -edg_wll_gss_accept(edg_wll_GssCred cred, - int sock, - struct timeval *timeout, - edg_wll_GssConnection *connection, - edg_wll_GssStatus* gss_code); - -int -edg_wll_gss_read(edg_wll_GssConnection *connection, - void *buf, - size_t bufsize, - struct timeval *timeout, - edg_wll_GssStatus* gss_code); - -int -edg_wll_gss_write(edg_wll_GssConnection *connection, - const void *buf, - size_t bufsize, - struct timeval *timeout, - edg_wll_GssStatus* gss_code); - -int -edg_wll_gss_read_full(edg_wll_GssConnection *connection, - void *buf, - size_t bufsize, - struct timeval *timeout, - size_t *total, - edg_wll_GssStatus* gss_code); - -int -edg_wll_gss_write_full(edg_wll_GssConnection *connection, - const void *buf, - size_t bufsize, - struct timeval *timeout, - size_t *total, - edg_wll_GssStatus* gss_code); - -int -edg_wll_gss_watch_creds(const char * proxy_file, - time_t * proxy_mtime); - -int -edg_wll_gss_get_error(edg_wll_GssStatus* gss_code, - const char *prefix, - char **errmsg); - -int -edg_wll_gss_close(edg_wll_GssConnection *connection, - struct timeval *timeout); - -int -edg_wll_gss_reject(int sock); - -int -edg_wll_gss_get_client_conn(edg_wll_GssConnection *connection, - edg_wll_GssPrincipal *principal, - edg_wll_GssStatus* gss_code); - -int -edg_wll_gss_get_client_pem(edg_wll_GssConnection *connection, - const char *my_cert_file, const char *my_key_file, - char **pem_string); - -void -edg_wll_gss_free_princ(edg_wll_GssPrincipal principal); - -int -edg_wll_gss_gethostname(char *name, int len); - -char * -edg_wll_gss_normalize_subj(char *in, - int replace_in); - -int -edg_wll_gss_equal_subj(const char *a, - const char *b); - - -#ifdef __cplusplus -} -#endif - -#endif /* __EDG_WORKLOAD_LOGGING_COMMON_LB_GSS_H__ */ diff --git a/org.glite.security.gss/project/ChangeLog b/org.glite.security.gss/project/ChangeLog deleted file mode 100644 index 18cd54c..0000000 --- a/org.glite.security.gss/project/ChangeLog +++ /dev/null @@ -1,17 +0,0 @@ -2.0.0-1 -- LB 2.0 release - -2.0.0-2 -- proper reference to cppunit - -2.0.0-3 -- globus flavors added to configure - -2.0.0-4 -- Module repacked. - -2.0.0-5 -- New age to fix an erroneous lock - -2.0.0-6 -- install libraries into $libdir diff --git a/org.glite.security.gss/project/package.description b/org.glite.security.gss/project/package.description deleted file mode 100644 index 3fc8dce..0000000 --- a/org.glite.security.gss/project/package.description +++ /dev/null @@ -1 +0,0 @@ -glite-security-gss wraps GSS functions (and several non-GSS Globus calls) to a secure network communication library with strict timing control (via timeout arguments) of all remote operations. diff --git a/org.glite.security.gss/project/package.summary b/org.glite.security.gss/project/package.summary deleted file mode 100644 index 4b2ef0e..0000000 --- a/org.glite.security.gss/project/package.summary +++ /dev/null @@ -1 +0,0 @@ -Wrapper of Globus GSS/SSL implementation used by gLite LB and JP diff --git a/org.glite.security.gss/project/version.properties b/org.glite.security.gss/project/version.properties deleted file mode 100644 index 28b3be3..0000000 --- a/org.glite.security.gss/project/version.properties +++ /dev/null @@ -1,3 +0,0 @@ -# $Header$ -module.version=2.0.0 -module.age=6 diff --git a/org.glite.security.gss/src/glite_gss.c b/org.glite.security.gss/src/glite_gss.c deleted file mode 100644 index a62e2e7..0000000 --- a/org.glite.security.gss/src/glite_gss.c +++ /dev/null @@ -1,1482 +0,0 @@ -#ident "$Header$" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "glite_gss.h" - -#define tv_sub(a,b) {\ - (a).tv_usec -= (b).tv_usec;\ - (a).tv_sec -= (b).tv_sec;\ - if ((a).tv_usec < 0) {\ - (a).tv_sec--;\ - (a).tv_usec += 1000000;\ - }\ -} - -struct asyn_result { - struct hostent *ent; - int err; -}; - -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); -} - -/* ares callback handler for ares_gethostbyname() */ -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_addr_list[0]) { - arp->ent->h_addr_list = - (char **) malloc(2 * sizeof(char *)); - if (arp->ent->h_addr_list == NULL) { - arp->err = NETDB_INTERNAL; - break; - } - arp->ent->h_addr_list[0] = - malloc(sizeof(struct in_addr)); - if (arp->ent->h_addr_list[0] == NULL) { - free(arp->ent->h_addr_list); - arp->err = NETDB_INTERNAL; - break; - } - memcpy(arp->ent->h_addr_list[0], h->h_addr_list[0], - sizeof(struct in_addr)); - arp->ent->h_addr_list[1] = NULL; - 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 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); - } -} - -static int asyn_gethostbyname(char **addrOut, char const *name, 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 *) calloc (sizeof(*ar.ent),1); - -/* query DNS server asynchronously */ - ares_gethostbyname(channel, name, AF_INET, 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) { - *addrOut = malloc(sizeof(struct in_addr)); - memcpy(*addrOut,ar.ent->h_addr_list[0], sizeof(struct in_addr)); - free_hostent(ar.ent); - } - return(ar.err); -} - -static int -do_connect(int *s, char const *hostname, int port, struct timeval *timeout) -{ - int sock; - struct timeval before,after,to; - struct sockaddr_in a; - int sock_err; - socklen_t err_len; - char *addr; - int h_errno; - int opt; - - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0) return EDG_WLL_GSS_ERROR_ERRNO; - - opt = 1; - setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,&opt,sizeof opt); - - if (timeout) { - int flags = fcntl(sock, F_GETFL, 0); - if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) - return EDG_WLL_GSS_ERROR_ERRNO; - gettimeofday(&before,NULL); - } - - if (timeout) { - switch (h_errno = asyn_gethostbyname(&addr, hostname, timeout)) { - case NETDB_SUCCESS: - memset(&a,0,sizeof a); - a.sin_family = AF_INET; - memcpy(&a.sin_addr.s_addr,addr,sizeof a.sin_addr.s_addr); - a.sin_port = htons(port); - free(addr); - break; - case TRY_AGAIN: - close(sock); - return EDG_WLL_GSS_ERROR_TIMEOUT; - case NETDB_INTERNAL: - /* fall through */ - default: - close(sock); - /* h_errno may be thread safe with Linux pthread libs, - * but such an assumption is not portable - */ - errno = h_errno; - return EDG_WLL_GSS_ERROR_HERRNO; - } - } else { - struct hostent *hp; - - hp = gethostbyname(hostname); - if (hp == NULL) { - close(sock); - errno = h_errno; - return EDG_WLL_GSS_ERROR_HERRNO; - } - - memset(&a,0,sizeof a); - a.sin_family = AF_INET; - memcpy(&a.sin_addr.s_addr, hp->h_addr_list[0], sizeof(a.sin_addr.s_addr)); - a.sin_port = htons(port); - } - - if (connect(sock,(struct sockaddr *) &a,sizeof a) < 0) { - if (timeout && errno == EINPROGRESS) { - fd_set fds; - FD_ZERO(&fds); - FD_SET(sock,&fds); - memcpy(&to,timeout,sizeof to); - gettimeofday(&before,NULL); - switch (select(sock+1,NULL,&fds,NULL,&to)) { - case -1: close(sock); - return EDG_WLL_GSS_ERROR_ERRNO; - case 0: close(sock); - return EDG_WLL_GSS_ERROR_TIMEOUT; - } - gettimeofday(&after,NULL); - tv_sub(after,before); - tv_sub(*timeout,after); - - err_len = sizeof sock_err; - if (getsockopt(sock,SOL_SOCKET,SO_ERROR,&sock_err,&err_len)) { - close(sock); - return EDG_WLL_GSS_ERROR_ERRNO; - } - if (sock_err) { - close(sock); - errno = sock_err; - return EDG_WLL_GSS_ERROR_ERRNO; - } - } - else { - close(sock); - return EDG_WLL_GSS_ERROR_ERRNO; - } - } - - *s = sock; - return 0; -} - -static int -send_token(int sock, void *token, size_t token_length, struct timeval *to) -{ - size_t num_written = 0; - ssize_t count; - fd_set fds; - struct timeval timeout,before,after; - int ret; - - if (to) { - memcpy(&timeout,to,sizeof(timeout)); - gettimeofday(&before,NULL); - } - - - ret = 0; - while(num_written < token_length) { - FD_ZERO(&fds); - FD_SET(sock,&fds); - switch (select(sock+1, NULL, &fds, NULL, to ? &timeout : NULL)) { - case 0: ret = EDG_WLL_GSS_ERROR_TIMEOUT; - goto end; - break; - case -1: ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - break; - } - - count = write(sock, ((char *)token) + num_written, - token_length - num_written); - if(count < 0) { - if(errno == EINTR) - continue; - else { - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - } - num_written += count; - } - -end: - if (to) { - gettimeofday(&after,NULL); - tv_sub(after,before); - tv_sub(*to,after); - if (to->tv_sec < 0) { - to->tv_sec = 0; - to->tv_usec = 0; - } - } - - return ret; -} - -static int -recv_token(int sock, void **token, size_t *token_length, struct timeval *to) -{ - ssize_t count; - char buf[4098]; - char *t = NULL; - char *tmp; - size_t tl = 0; - fd_set fds; - struct timeval timeout,before,after; - int ret; - - if (to) { - memcpy(&timeout,to,sizeof(timeout)); - gettimeofday(&before,NULL); - } - - ret = 0; - do { - FD_ZERO(&fds); - FD_SET(sock,&fds); - switch (select(sock+1, &fds, NULL, NULL, to ? &timeout : NULL)) { - case 0: - ret = EDG_WLL_GSS_ERROR_TIMEOUT; - goto end; - break; - case -1: - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - break; - } - - count = read(sock, buf, sizeof(buf)); - if (count < 0) { - if (errno == EINTR) - continue; - else { - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - } - - if (count==0) { - if (tl==0) - return EDG_WLL_GSS_ERROR_EOF; - else goto end; - } - tmp=realloc(t, tl + count); - if (tmp == NULL) { - errno = ENOMEM; - return EDG_WLL_GSS_ERROR_ERRNO; - } - t = tmp; - memcpy(t + tl, buf, count); - tl += count; - - } while (count < 0); /* restart on EINTR */ - -end: - if (to) { - gettimeofday(&after,NULL); - tv_sub(after,before); - tv_sub(*to,after); - if (to->tv_sec < 0) { - to->tv_sec = 0; - to->tv_usec = 0; - } - } - - if (ret == 0) { - *token = t; - *token_length = tl; - } else - free(t); - - return ret; -} - -static int -create_proxy(const char *cert_file, const char *key_file, char **proxy_file) -{ - char buf[4096]; - int in, out; - char *name = NULL; - int ret, len; - - *proxy_file = NULL; - - asprintf(&name, "%s/%d.lb.XXXXXX", P_tmpdir, getpid()); - - out = mkstemp(name); - if (out < 0) - return EDG_WLL_GSS_ERROR_ERRNO; - - in = open(cert_file, O_RDONLY); - if (in < 0) { - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - while ((ret = read(in, buf, sizeof(buf))) > 0) { - len = write(out, buf, ret); - if (len != ret) { - ret = -1; - break; - } - } - close(in); - if (ret < 0) { - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - - len = write(out, "\n", 1); - if (len != 1) { - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - - in = open(key_file, O_RDONLY); - if (in < 0) { - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - while ((ret = read(in, buf, sizeof(buf))) > 0) { - len = write(out, buf, ret); - if (len != ret) { - ret = -1; - break; - } - } - close(in); - if (ret < 0) { - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - - ret = 0; - *proxy_file = name; - -end: - close(out); - if (ret) { - unlink(name); - free(name); - } - - return ret; -} - -static int -destroy_proxy(char *proxy_file) -{ - /* XXX we should erase the contents safely (i.e. overwrite with 0's) */ - unlink(proxy_file); - return 0; -} - -int -edg_wll_gss_acquire_cred_gsi(const char *cert_file, const char *key_file, edg_wll_GssCred *cred, - edg_wll_GssStatus* gss_code) -{ - OM_uint32 major_status = 0, minor_status, minor_status2; - gss_cred_id_t gss_cred = GSS_C_NO_CREDENTIAL; - gss_buffer_desc buffer = GSS_C_EMPTY_BUFFER; - gss_name_t gss_name = GSS_C_NO_NAME; - OM_uint32 lifetime; - char *proxy_file = NULL; - char *name = NULL; - int ret; - - if ((cert_file == NULL && key_file != NULL) || - (cert_file != NULL && key_file == NULL)) - return EINVAL; - - if (cert_file == NULL) { - major_status = gss_acquire_cred(&minor_status, GSS_C_NO_NAME, 0, - GSS_C_NO_OID_SET, GSS_C_BOTH, - &gss_cred, NULL, NULL); - if (GSS_ERROR(major_status)) { - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } - } else { - proxy_file = (char *)cert_file; - if (strcmp(cert_file, key_file) != 0 && - (ret = create_proxy(cert_file, key_file, &proxy_file))) { - proxy_file = NULL; - goto end; - } - - asprintf((char**)&buffer.value, "X509_USER_PROXY=%s", proxy_file); - if (buffer.value == NULL) { - errno = ENOMEM; - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - buffer.length = strlen(proxy_file); - - major_status = gss_import_cred(&minor_status, &gss_cred, GSS_C_NO_OID, 1, - &buffer, 0, NULL); - free(buffer.value); - if (GSS_ERROR(major_status)) { - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } - } - - /* gss_import_cred() doesn't check validity of credential loaded, so let's - * verify it now */ - major_status = gss_inquire_cred(&minor_status, gss_cred, &gss_name, - &lifetime, NULL, NULL); - if (GSS_ERROR(major_status)) { - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } - - /* Must cast to time_t since OM_uint32 is unsinged and hence we couldn't - * detect negative values. */ - if ((time_t) lifetime <= 0) { - major_status = GSS_S_CREDENTIALS_EXPIRED; - minor_status = 0; /* XXX */ - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } - - major_status = gss_display_name(&minor_status, gss_name, &buffer, NULL); - if (GSS_ERROR(major_status)) { - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } - name = buffer.value; - memset(&buffer, 0, sizeof(buffer)); - - *cred = calloc(1, sizeof(**cred)); - if (*cred == NULL) { - ret = EDG_WLL_GSS_ERROR_ERRNO; - free(name); - goto end; - } - - (*cred)->gss_cred = gss_cred; - gss_cred = GSS_C_NO_CREDENTIAL; - (*cred)->lifetime = lifetime; - (*cred)->name = name; - - ret = 0; - -end: - if (cert_file && key_file && proxy_file && strcmp(cert_file, key_file) != 0) { - destroy_proxy(proxy_file); - free(proxy_file); - } - - if (gss_name != GSS_C_NO_NAME) - gss_release_name(&minor_status2, &gss_name); - - if (gss_cred != GSS_C_NO_CREDENTIAL) - gss_release_cred(&minor_status2, &gss_cred); - - if (GSS_ERROR(major_status)) { - if (gss_code) { - gss_code->major_status = major_status; - gss_code->minor_status = minor_status; - } - ret = EDG_WLL_GSS_ERROR_GSS; - } - - return ret; -} - -/* XXX XXX This is black magic. "Sometimes" server refuses the client with SSL - * * alert "certificate expired" even if it is not true. In this case the server - * * slave terminates (which helps, usually), and we can reconnect transparently. - * */ - -/* This string appears in the error message in this case */ -#define _EXPIRED_ALERT_MESSAGE "function SSL3_READ_BYTES: sslv3 alert certificate expired" -#define _EXPIRED_ALERT_RETRY_COUNT 10 /* default number of slaves, hope that not all - are in the bad state */ -#define _EXPIRED_ALERT_RETRY_DELAY 10 /* ms */ - -/* XXX XXX This is black magic. "Sometimes" server refuses the client with SSL - * * alert "certificate expired" even if it is not true. In this case the server - * * slave terminates (which helps, usually), and we can reconnect transparently. - * */ - -/* This string appears in the error message in this case */ -#define _EXPIRED_ALERT_MESSAGE "function SSL3_READ_BYTES: sslv3 alert certificate expired" -#define _EXPIRED_ALERT_RETRY_COUNT 10 /* default number of slaves, hope that not all - are in the bad state */ -#define _EXPIRED_ALERT_RETRY_DELAY 10 /* ms */ - -int -edg_wll_gss_connect(edg_wll_GssCred cred, char const *hostname, int port, - struct timeval *timeout, edg_wll_GssConnection *connection, - edg_wll_GssStatus* gss_code) -{ - int sock, ret; - OM_uint32 maj_stat, min_stat, min_stat2, req_flags; - int context_established = 0; - gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER; - gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; - gss_name_t server = GSS_C_NO_NAME; - gss_ctx_id_t context = GSS_C_NO_CONTEXT; - char *servername = NULL; - int retry = _EXPIRED_ALERT_RETRY_COUNT; - - maj_stat = min_stat = min_stat2 = req_flags = 0; - memset(connection, 0, sizeof(*connection)); - - /* GSI specific */ - req_flags = GSS_C_GLOBUS_SSL_COMPATIBLE; - - ret = do_connect(&sock, hostname, port, timeout); - if (ret) - return ret; - - /* XXX find appropriate fqdn */ - asprintf (&servername, "host@%s", hostname); - if (servername == NULL) { - errno = ENOMEM; - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - input_token.value = servername; - input_token.length = strlen(servername) + 1; - - maj_stat = gss_import_name(&min_stat, &input_token, - GSS_C_NT_HOSTBASED_SERVICE, &server); - if (GSS_ERROR(maj_stat)) { - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } - - free(servername); - memset(&input_token, 0, sizeof(input_token)); - - /* XXX if cred == GSS_C_NO_CREDENTIAL set the ANONYMOUS flag */ - - do { /* XXX: the black magic above */ - - do { /* XXX: the black magic above */ - - /* XXX prepsat na do {} while (maj_stat == CONT) a osetrit chyby*/ - while (!context_established) { - /* XXX verify ret_flags match what was requested */ - maj_stat = gss_init_sec_context(&min_stat, cred->gss_cred, &context, - GSS_C_NO_NAME, GSS_C_NO_OID, - req_flags | GSS_C_MUTUAL_FLAG | GSS_C_CONF_FLAG, - 0, GSS_C_NO_CHANNEL_BINDINGS, - &input_token, NULL, &output_token, - NULL, NULL); - if (input_token.length > 0) { - free(input_token.value); - input_token.length = 0; - } - - if (output_token.length != 0) { - ret = send_token(sock, output_token.value, output_token.length, timeout); - gss_release_buffer(&min_stat2, &output_token); - if (ret) - goto end; - } - - if (GSS_ERROR(maj_stat)) { - if (context != GSS_C_NO_CONTEXT) { - gss_delete_sec_context(&min_stat2, &context, &output_token); - context = GSS_C_NO_CONTEXT; - if (output_token.length) { - send_token(sock, output_token.value, output_token.length, timeout); - gss_release_buffer(&min_stat2, &output_token); - } - } - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } - - if(maj_stat & GSS_S_CONTINUE_NEEDED) { - ret = recv_token(sock, &input_token.value, &input_token.length, timeout); - if (ret) - goto end; - } else - context_established = 1; - } - - /* XXX check ret_flags matches to what was requested */ - - /* retry on false "certificate expired" */ - if (ret == EDG_WLL_GSS_ERROR_GSS) { - edg_wll_GssStatus gss_stat; - char *msg = NULL; - - gss_stat.major_status = maj_stat; - gss_stat.minor_status = min_stat; - edg_wll_gss_get_error(&gss_stat,"",&msg); - - if (strstr(msg,_EXPIRED_ALERT_MESSAGE)) { - usleep(_EXPIRED_ALERT_RETRY_DELAY); - retry--; - } - else retry = 0; - - free(msg); - } - else retry = 0; - - } while (retry); - - /* retry on false "certificate expired" */ - if (ret == EDG_WLL_GSS_ERROR_GSS) { - edg_wll_GssStatus gss_stat; - char *msg = NULL; - - gss_stat.major_status = maj_stat; - gss_stat.minor_status = min_stat; - edg_wll_gss_get_error(&gss_stat,"",&msg); - - if (strstr(msg,_EXPIRED_ALERT_MESSAGE)) { - usleep(_EXPIRED_ALERT_RETRY_DELAY); - retry--; - } - else retry = 0; - - free(msg); - } - else retry = 0; - - } while (retry); - - connection->sock = sock; - connection->context = context; - servername = NULL; - ret = 0; - -end: - if (ret == EDG_WLL_GSS_ERROR_GSS && gss_code) { - gss_code->major_status = maj_stat; - gss_code->minor_status = min_stat; - } - if (server != GSS_C_NO_NAME) - gss_release_name(&min_stat2, &server); - if (servername == NULL) - free(servername); - if (ret) - close(sock); - - return ret; -} - -int -edg_wll_gss_accept(edg_wll_GssCred cred, int sock, struct timeval *timeout, - edg_wll_GssConnection *connection, edg_wll_GssStatus* gss_code) -{ - OM_uint32 maj_stat, min_stat, min_stat2; - OM_uint32 ret_flags = 0; - gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER; - gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; - gss_name_t client_name = GSS_C_NO_NAME; - gss_ctx_id_t context = GSS_C_NO_CONTEXT; - int ret; - - maj_stat = min_stat = min_stat2 = 0; - memset(connection, 0, sizeof(*connection)); - - /* GSI specific */ - ret_flags = GSS_C_GLOBUS_SSL_COMPATIBLE; - - do { - ret = recv_token(sock, &input_token.value, &input_token.length, timeout); - if (ret) - goto end; - - if (client_name != GSS_C_NO_NAME) - gss_release_name(&min_stat2, &client_name); - - maj_stat = gss_accept_sec_context(&min_stat, &context, - cred->gss_cred, &input_token, - GSS_C_NO_CHANNEL_BINDINGS, - &client_name, NULL, &output_token, - &ret_flags, NULL, NULL); - if (input_token.length > 0) { - free(input_token.value); - input_token.length = 0; - } - - if (output_token.length) { - ret = send_token(sock, output_token.value, output_token.length, timeout); - gss_release_buffer(&min_stat2, &output_token); - if (ret) - goto end; - } - } while(maj_stat & GSS_S_CONTINUE_NEEDED); - - if (GSS_ERROR(maj_stat)) { - if (context != GSS_C_NO_CONTEXT) { - gss_delete_sec_context(&min_stat2, &context, &output_token); - context = GSS_C_NO_CONTEXT; - if (output_token.length) { - send_token(sock, output_token.value, output_token.length, timeout); - gss_release_buffer(&min_stat2, &output_token); - } - } - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } - -#if 0 - maj_stat = gss_display_name(&min_stat, client_name, &output_token, NULL); - gss_release_buffer(&min_stat2, &output_token); - if (GSS_ERROR(maj_stat)) { - /* XXX close context ??? */ - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } -#endif - - connection->sock = sock; - connection->context = context; - ret = 0; - -end: - if (ret == EDG_WLL_GSS_ERROR_GSS && gss_code) { - gss_code->major_status = maj_stat; - gss_code->minor_status = min_stat; - } - if (client_name != GSS_C_NO_NAME) - gss_release_name(&min_stat2, &client_name); - - return ret; -} - -int -edg_wll_gss_write(edg_wll_GssConnection *connection, const void *buf, size_t bufsize, - struct timeval *timeout, edg_wll_GssStatus* gss_code) -{ - OM_uint32 maj_stat, min_stat; - gss_buffer_desc input_token; - gss_buffer_desc output_token; - int ret; - - input_token.value = (void*)buf; - input_token.length = bufsize; - - maj_stat = gss_wrap (&min_stat, connection->context, 1, GSS_C_QOP_DEFAULT, - &input_token, NULL, &output_token); - if (GSS_ERROR(maj_stat)) { - if (gss_code) { - gss_code->minor_status = min_stat; - gss_code->major_status = maj_stat; - } - - return EDG_WLL_GSS_ERROR_GSS; - } - - ret = send_token(connection->sock, output_token.value, output_token.length, - timeout); - gss_release_buffer(&min_stat, &output_token); - - return ret; -} - - -int -edg_wll_gss_read(edg_wll_GssConnection *connection, void *buf, size_t bufsize, - struct timeval *timeout, edg_wll_GssStatus* gss_code) -{ - OM_uint32 maj_stat, min_stat, min_stat2; - gss_buffer_desc input_token; - gss_buffer_desc output_token; - size_t i, len; - int ret; - - if (connection->bufsize > 0) { - len = (connection->bufsize < bufsize) ? connection->bufsize : bufsize; - memcpy(buf, connection->buffer, len); - if (connection->bufsize - len == 0) { - free(connection->buffer); - connection->buffer = NULL; - } else { - for (i = 0; i < connection->bufsize - len; i++) - connection->buffer[i] = connection->buffer[i+len]; - } - connection->bufsize -= len; - - return len; - } - - do { - ret = recv_token(connection->sock, &input_token.value, &input_token.length, - timeout); - if (ret) - return ret; - - ERR_clear_error(); - maj_stat = gss_unwrap(&min_stat, connection->context, &input_token, - &output_token, NULL, NULL); - gss_release_buffer(&min_stat2, &input_token); - if (GSS_ERROR(maj_stat)) { - if (gss_code) { - gss_code->minor_status = min_stat; - gss_code->major_status = maj_stat; - } - return EDG_WLL_GSS_ERROR_GSS; - } - } while (maj_stat == 0 && output_token.length == 0 && output_token.value == NULL); - - if (output_token.length > bufsize) { - connection->bufsize = output_token.length - bufsize; - connection->buffer = malloc(connection->bufsize); - if (connection->buffer == NULL) { - connection->bufsize = 0; - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - memcpy(connection->buffer, output_token.value + bufsize, connection->bufsize); - output_token.length = bufsize; - } - - memcpy(buf, output_token.value, output_token.length); - ret = output_token.length; - -end: - gss_release_buffer(&min_stat, &output_token); - - return ret; -} - -int -edg_wll_gss_read_full(edg_wll_GssConnection *connection, void *buf, - size_t bufsize, struct timeval *timeout, size_t *total, - edg_wll_GssStatus* gss_code) -{ - size_t len, i; - *total = 0; - - if (connection->bufsize > 0) { - len = (connection->bufsize < bufsize) ? connection->bufsize : bufsize; - memcpy(buf, connection->buffer, len); - if (connection->bufsize - len == 0) { - free(connection->buffer); - connection->buffer = NULL; - } else { - for (i = 0; i < connection->bufsize - len; i++) - connection->buffer[i] = connection->buffer[i+len]; - } - connection->bufsize -= len; - *total = len; - } - - while (*total < bufsize) { - int len; - - len = edg_wll_gss_read(connection, buf+*total, bufsize-*total, - timeout, gss_code); - if (len < 0) return len; - *total += len; - } - - return 0; -} - -int -edg_wll_gss_write_full(edg_wll_GssConnection *connection, const void *buf, - size_t bufsize, struct timeval *timeout, size_t *total, - edg_wll_GssStatus* gss_code) -{ - return edg_wll_gss_write(connection, buf, bufsize, timeout, gss_code); -} - -/* Request credential reload each 60 seconds in order to work around - * Globus bug (not reloading expired CRLs) - */ -#define GSS_CRED_WATCH_LIMIT 60 -int -edg_wll_gss_watch_creds(const char *proxy_file, time_t *last_time) -{ - struct stat pstat; - time_t now; - - now = time(NULL); - - if ( now >= (*last_time+GSS_CRED_WATCH_LIMIT) ) { - *last_time = now; - return 1; - } - - if (!proxy_file) return 0; - if (stat(proxy_file,&pstat)) return -1; - - if ( pstat.st_mtime >= *last_time ) { - *last_time = now + 1; - return 1; - } - - return 0; -} - -int -edg_wll_gss_close(edg_wll_GssConnection *con, struct timeval *timeout) -{ - OM_uint32 min_stat; - gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; - struct timeval def_timeout = { 0, 100000}; - - if (con->context != GSS_C_NO_CONTEXT) { - gss_delete_sec_context(&min_stat, (gss_ctx_id_t *)&con->context, &output_token); - -#if 0 - /* XXX: commented out till timeout handling in caller is fixed */ - - /* send the buffer (if any) to the peer. GSSAPI specs doesn't - * recommend sending it, but we want SSL compatibility */ - if (output_token.length && con->sock>=0) { - send_token(con->sock, output_token.value, output_token.length, - timeout ? timeout : &def_timeout); - } -#endif - gss_release_buffer(&min_stat, &output_token); - - /* XXX can socket be open even if context == GSS_C_NO_CONTEXT) ? */ - /* XXX ensure that edg_wll_GssConnection is created with sock set to -1 */ - if (con->sock >= 0) - close(con->sock); - } - if (con->buffer) - free(con->buffer); - memset(con, 0, sizeof(*con)); - con->context = GSS_C_NO_CONTEXT; - con->sock = -1; - return 0; -} - -int -edg_wll_gss_get_error(edg_wll_GssStatus *gss_err, const char *prefix, char **msg) -{ - OM_uint32 maj_stat, min_stat; - OM_uint32 msg_ctx = 0; - gss_buffer_desc maj_status_string = GSS_C_EMPTY_BUFFER; - gss_buffer_desc min_status_string = GSS_C_EMPTY_BUFFER; - char *str = NULL; - char *line, *tmp; - - str = strdup(prefix); - do { - maj_stat = gss_display_status(&min_stat, gss_err->major_status, - GSS_C_GSS_CODE, GSS_C_NO_OID, - &msg_ctx, &maj_status_string); - if (GSS_ERROR(maj_stat)) - break; - maj_stat = gss_display_status(&min_stat, gss_err->minor_status, - GSS_C_MECH_CODE, GSS_C_NULL_OID, - &msg_ctx, &min_status_string); - if (GSS_ERROR(maj_stat)) { - gss_release_buffer(&min_stat, &maj_status_string); - break; - } - - asprintf(&line, ": %s (%s)", (char *)maj_status_string.value, - (char *)min_status_string.value); - gss_release_buffer(&min_stat, &maj_status_string); - gss_release_buffer(&min_stat, &min_status_string); - - tmp = realloc(str, strlen(str) + strlen(line) + 1); - if (tmp == NULL) { - /* abort() ? */ - free(line); - free(str); - str = "WARNING: Not enough memory to produce error message"; - break; - } - str = tmp; - strcat(str, line); - free(line); - } while (!GSS_ERROR(maj_stat) && msg_ctx != 0); - - *msg = str; - return 0; -} - -int -edg_wll_gss_oid_equal(const gss_OID a, const gss_OID b) -{ - if (a == b) - return 1; - else { - if (a == GSS_C_NO_OID || b == GSS_C_NO_OID || a->length != b->length) - return 0; - else - return (memcmp(a->elements, b->elements, a->length) == 0); - } -} - -int -edg_wll_gss_reject(int sock) -{ - /* XXX is it possible to cut & paste edg_wll_ssl_reject() ? */ - return 0; -} - - -int -edg_wll_gss_initialize(void) -{ - int ret; - - ret = globus_module_activate(GLOBUS_GSI_GSSAPI_MODULE); - if (ret != GLOBUS_SUCCESS) { - errno = EINVAL; - ret = EDG_WLL_GSS_ERROR_ERRNO; - } - return ret; -} - -int -edg_wll_gss_release_cred(edg_wll_GssCred *cred, edg_wll_GssStatus* gss_code) -{ - OM_uint32 maj_stat, min_stat; - int ret = 0; - - if (gss_code) - gss_code->major_status = gss_code->minor_status = 0; - - if (cred == NULL || *cred == NULL) - return ret; - - if ((*cred)->gss_cred) { - maj_stat = gss_release_cred(&min_stat, (gss_cred_id_t*)&(*cred)->gss_cred); - if (GSS_ERROR(maj_stat)) { - ret = EDG_WLL_GSS_ERROR_GSS; - if (gss_code) { - gss_code->major_status = maj_stat; - gss_code->minor_status = min_stat; - } - } - } - - if ((*cred)->name) - free((*cred)->name); - - free(*cred); - *cred = NULL; - - return ret; -} - -int -edg_wll_gss_get_client_conn(edg_wll_GssConnection *connection, - edg_wll_GssPrincipal *principal, - edg_wll_GssStatus* gss_code) -{ - gss_buffer_desc token = GSS_C_EMPTY_BUFFER; - OM_uint32 maj_stat, min_stat, ctx_flags; - gss_name_t client_name = GSS_C_NO_NAME; - edg_wll_GssPrincipal p; - int ret; - - maj_stat = gss_inquire_context(&min_stat, connection->context, &client_name, - NULL, NULL, NULL, &ctx_flags, NULL, NULL); - if (GSS_ERROR(maj_stat)) - goto end; - - maj_stat = gss_display_name(&min_stat, client_name, &token, NULL); - if (GSS_ERROR(maj_stat)) - goto end; - - p = calloc(1, sizeof(*p)); - if (p == NULL) { - errno = ENOMEM; - ret = EDG_WLL_GSS_ERROR_ERRNO; - goto end; - } - - p->name = strdup(token.value); - p->flags = ctx_flags; - - *principal = p; - ret = 0; - -end: - if (GSS_ERROR(maj_stat)) { - ret = EDG_WLL_GSS_ERROR_GSS; - if (gss_code) { - gss_code->major_status = maj_stat; - gss_code->minor_status = min_stat; - } - } - - if (token.length) - gss_release_buffer(&min_stat, &token); - if (client_name != GSS_C_NO_NAME) - gss_release_name(&min_stat, &client_name); - - return ret; -} - -/* Beware, this call manipulates with environment variables and is not - thread-safe */ -static int -get_peer_cred(edg_wll_GssConnection *gss, const char *my_cert_file, - const char *my_key_file, STACK_OF(X509) **chain, - edg_wll_GssStatus* gss_code) -{ - 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 *p_cert; - char *orig_cert = NULL, *orig_key = NULL; - - maj_stat = gss_export_sec_context(&min_stat, (gss_ctx_id_t *) &gss->context, - &buffer); - if (GSS_ERROR(maj_stat)) { - if (gss_code) { - gss_code->major_status = maj_stat; - gss_code->minor_status = min_stat; - } - return EDG_WLL_GSS_ERROR_GSS; - } - - /* 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. - * */ - - orig_cert = getenv("X509_USER_CERT"); - orig_key = getenv("X509_USER_KEY"); - - if (my_cert_file) - setenv("X509_USER_CERT", my_cert_file, 1); - if (my_key_file) - setenv("X509_USER_KEY", my_key_file, 1); - - maj_stat = gss_import_sec_context(&min_stat, &buffer, - (gss_ctx_id_t *)&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)) { - if (gss_code) { - gss_code->major_status = maj_stat; - gss_code->minor_status = min_stat; - } - ret = EDG_WLL_GSS_ERROR_GSS; - goto end; - } - - bio = BIO_new(BIO_s_mem()); - if (bio == NULL) { - ret = ENOMEM; - 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 = EINVAL; - goto end; - } - SSL_SESSION_free(session); - - cert_chain = sk_X509_new_null(); - - 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 = EINVAL; - goto end; - } - - for(index = 0; index < length; index++) { - p_cert = d2i_X509_bio(bio, NULL); - if (p_cert == NULL) { - ret = EINVAL; - sk_X509_pop_free(cert_chain, X509_free); - goto end; - } - - sk_X509_push(cert_chain, p_cert); - } - - *chain = cert_chain; - ret = 0; - -end: - gss_release_buffer(&min_stat, &buffer); - - return ret; -} - -int -edg_wll_gss_get_client_pem(edg_wll_GssConnection *connection, - const char *my_cert_file, const char *my_key_file, - char **pem_string) -{ - char *tmp = NULL; - STACK_OF(X509) *chain = NULL; - BIO *bio = NULL; - int ret, i; - size_t total_len, l; - - ret = get_peer_cred(connection, my_cert_file, my_key_file, &chain, NULL); - if (ret) - return ret; - - bio = BIO_new(BIO_s_mem()); - if (bio == NULL) { - ret = ENOMEM; - goto end; - } - - for (i = 0; i < sk_X509_num(chain); i++) { - ret = PEM_write_bio_X509(bio, sk_X509_value(chain, i)); - if (ret <= 0) { - ret = EINVAL; - goto end; - } - } - - total_len = BIO_pending(bio); - if (total_len <= 0) { - ret = EINVAL; - goto end; - } - - tmp = malloc(total_len + 1); - if (tmp == NULL) { - ret = ENOMEM; - goto end; - } - - l = 0; - while (l < total_len) { - ret = BIO_read(bio, tmp+l, total_len-l); - if (ret <= 0) { - ret = EINVAL; - goto end; - } - l += ret; - } - - tmp[total_len] = '\0'; - *pem_string = tmp; - tmp = NULL; - - ret = 0; - -end: - sk_X509_pop_free(chain, X509_free); - if (bio) - BIO_free(bio); - if (tmp) - free(tmp); - - return ret; -} - -void -edg_wll_gss_free_princ(edg_wll_GssPrincipal principal) -{ - if (principal == NULL) - return; - - if (principal->name) - free(principal->name); - - free(principal); -} - -int -edg_wll_gss_gethostname(char *name, int len) -{ - int ret; - - ret = globus_module_activate(GLOBUS_COMMON_MODULE); - if (ret != GLOBUS_SUCCESS) { - ret = gethostname(name, len); - return ret; - } - ret = globus_libc_gethostname(name, len); - globus_module_deactivate(GLOBUS_COMMON_MODULE); - - return ret; -} - -char * -edg_wll_gss_normalize_subj(char *in, int replace_in) -{ - char *new, *ptr; - size_t len; - - if (in == NULL) return NULL; - if (replace_in) - new = in; - else - new = strdup(in); - - while ((ptr = strstr(new, "/emailAddress="))) { - memcpy(ptr, "/Email=",7); - memmove(ptr+7, ptr+14, strlen(ptr+14)+1); - } - - len = strlen(new); - while (len > 9 && !strcmp(new+len-9, "/CN=proxy")) { - *(new+len-9) = '\0'; - len -= 9; - } - - return new; -} - -int -edg_wll_gss_equal_subj(const char *a, const char *b) -{ - char *an,*bn; - int res; - - an = edg_wll_gss_normalize_subj((char*)a, 0); - bn = edg_wll_gss_normalize_subj((char*)b, 0); - - if (!an || !bn) - res = 0; - else - res = !strcmp(an,bn); - - free(an); free(bn); - return res; -} diff --git a/org.glite.security.gss/test/test_gss.cpp b/org.glite.security.gss/test/test_gss.cpp deleted file mode 100644 index 28739c2..0000000 --- a/org.glite.security.gss/test/test_gss.cpp +++ /dev/null @@ -1,199 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "glite_gss.h" - -class GSSTest: public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(GSSTest); - CPPUNIT_TEST(echo); - CPPUNIT_TEST(echo); - CPPUNIT_TEST(bigecho); - CPPUNIT_TEST(errorTest); - CPPUNIT_TEST_SUITE_END(); - -public: - void echo(); - void bigecho(); - void errorTest(); - - void setUp(); - -private: - edg_wll_GssCred my_cred; - int sock, port; - struct timeval timeout; - - void replier(); -}; - - -void GSSTest::replier() { - edg_wll_GssConnection conn; - edg_wll_GssStatus stat; - struct sockaddr_in a; - socklen_t alen = sizeof(a); - int s, len; - char buf[8*BUFSIZ]; - - std::cerr << "replier " << getpid() << std::endl; - - if ( (s = accept(sock, (struct sockaddr *) &a, &alen)) < 0 ) exit(1); - - if ( edg_wll_gss_accept(my_cred, s, &timeout, &conn, &stat) ) exit(1); - - while ( (len = edg_wll_gss_read(&conn, buf, sizeof(buf), &timeout, &stat)) >= 0 ) { - if ( edg_wll_gss_write(&conn, buf, len, &timeout, &stat) ) exit(1); - } - - exit(0); -} - - -void GSSTest::setUp(void) { - pid_t pid; - edg_wll_GssStatus stat; - struct sockaddr_in a; - socklen_t alen = sizeof(a); - char * cred_file = NULL; - char * key_file = NULL; - char * to = getenv("GSS_TEST_TIMEOUT"); - - timeout.tv_sec = to ? atoi(to) : 10 ; - timeout.tv_usec = 0; - - key_file = cred_file = getenv("X509_USER_PROXY"); - CPPUNIT_ASSERT_MESSAGE("credential file", cred_file); - - if (edg_wll_gss_acquire_cred_gsi(cred_file, key_file, &my_cred, &stat)) - CPPUNIT_ASSERT_MESSAGE("gss_acquire_cred", 0); - - sock = socket(PF_INET,SOCK_STREAM,0); - CPPUNIT_ASSERT_MESSAGE("socket()", sock >= 0); - - a.sin_family = AF_INET; - a.sin_port = 0; - a.sin_addr.s_addr = INADDR_ANY; - - if (bind(sock,(struct sockaddr *) &a,sizeof(a))) { - CPPUNIT_ASSERT_MESSAGE("bind()", 0); - } - - if (listen(sock,1)) { - CPPUNIT_ASSERT_MESSAGE("listen()", 0); - } - - getsockname(sock,(struct sockaddr *) &a,&alen); - port = ntohs(a.sin_port); - - if ( !(pid = fork()) ) replier(); - else close(sock); -} - - - -void GSSTest::echo() -{ - edg_wll_GssConnection conn; - edg_wll_GssStatus stat; - size_t total; - int err; - char buf[] = "f843fejwfanczn nc4*&686%$$&^(*)*#$@WSH"; - char buf2[100]; - - std::cerr << "echo " << getpid() << std::endl; - - err = edg_wll_gss_connect(my_cred, "localhost", port, &timeout, &conn, &stat); - CPPUNIT_ASSERT_MESSAGE("edg_wll_gss_connect()", !err); - - err = edg_wll_gss_write(&conn, buf, strlen(buf)+1, &timeout, &stat); - CPPUNIT_ASSERT_MESSAGE("edg_wll_gss_write()", !err); - - err = edg_wll_gss_read_full(&conn, buf2, strlen(buf)+1, &timeout, &total, &stat); - CPPUNIT_ASSERT_MESSAGE("edg_wll_gss_read_full()", !err); - - CPPUNIT_ASSERT(strlen(buf)+1 == total && !strcmp(buf,buf2) ); - - edg_wll_gss_close(&conn, &timeout); - -} - -void GSSTest::bigecho() -{ - edg_wll_GssConnection conn; - edg_wll_GssStatus stat; - size_t total; - int err; - char buf[7*BUFSIZ]; - char buf2[7*BUFSIZ]; - - std::cerr << "bigecho " << getpid() << std::endl; - - err = edg_wll_gss_connect(my_cred, "localhost", port, &timeout, &conn, &stat); - CPPUNIT_ASSERT_MESSAGE("edg_wll_gss_connect()", !err); - - err = edg_wll_gss_write(&conn, buf, sizeof buf, &timeout, &stat); - CPPUNIT_ASSERT_MESSAGE("edg_wll_gss_write()", !err); - - err = edg_wll_gss_read_full(&conn, buf2, sizeof buf2, &timeout, &total, &stat); - CPPUNIT_ASSERT_MESSAGE("edg_wll_gss_read_full()", !err); - - CPPUNIT_ASSERT(sizeof buf == total && !memcmp(buf,buf2,sizeof buf) ); - - edg_wll_gss_close(&conn, &timeout); - -} - - -void GSSTest::errorTest() -{ - edg_wll_GssConnection conn; - edg_wll_GssStatus stat; - int err; - char * msg = NULL; - - - err = edg_wll_gss_connect(my_cred, "xxx.example.net", port, &timeout, &conn, &stat); - if (err) edg_wll_gss_get_error(&stat, "gss_connect()", &msg); - CPPUNIT_ASSERT_MESSAGE("edg_wll_gss_get_error()", msg); -} - - -CPPUNIT_TEST_SUITE_REGISTRATION( GSSTest ); - -int main (int ac,const char *av[]) -{ - assert(ac == 2); - std::ofstream xml(av[1]); - - CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - CppUnit::TestRunner runner; - - CppUnit::TestResult controller; - CppUnit::TestResultCollector result; - controller.addListener( &result ); - - runner.addTest(suite); - runner.run(controller); - - - CppUnit::XmlOutputter xout( &result, xml ); - CppUnit::CompilerOutputter tout( &result, std::cout); - xout.write(); - tout.write(); - - return result.wasSuccessful() ? 0 : 1 ; -} -- 1.8.2.3