/* ewsnNotificationServiceBindingService.cpp
   Generated by gSOAP 2.8.21 from NotificationService.h

Copyright(C) 2000-2014, Robert van Engelen, Genivia Inc. All Rights Reserved.
The generated code is released under one of the following licenses:
GPL or Genivia's license for commercial use.
This program is released under the GPL with the additional exemption that
compiling, linking, and/or using OpenSSL is allowed.
*/

#include "ewsnNotificationServiceBindingService.h"

namespace ewsn {

NotificationServiceBindingService::NotificationServiceBindingService()
{	NotificationServiceBindingService_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);
}

NotificationServiceBindingService::NotificationServiceBindingService(const struct soap &_soap) : soap(_soap)
{ }

NotificationServiceBindingService::NotificationServiceBindingService(soap_mode iomode)
{	NotificationServiceBindingService_init(iomode, iomode);
}

NotificationServiceBindingService::NotificationServiceBindingService(soap_mode imode, soap_mode omode)
{	NotificationServiceBindingService_init(imode, omode);
}

NotificationServiceBindingService::~NotificationServiceBindingService()
{ }

void NotificationServiceBindingService::NotificationServiceBindingService_init(soap_mode imode, soap_mode omode)
{	soap_imode(this, imode);
	soap_omode(this, omode);
	static const struct Namespace namespaces[] =
{
	{"SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/", NULL},
	{"SOAP-ENC", "http://www.w3.org/2003/05/soap-encoding", "http://schemas.xmlsoap.org/soap/encoding/", NULL},
	{"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL},
	{"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL},
	{"ewsn2", "http://schemas.microsoft.com/exchange/services/2006/types", NULL, NULL},
	{"ewsn3", "http://schemas.microsoft.com/exchange/services/2006/messages/NotificationServiceBinding", NULL, NULL},
	{"ewsn", "http://schemas.microsoft.com/exchange/services/2006/messages", NULL, NULL},
	{"ewsn4", "http://schemas.microsoft.com/exchange/services/2006/messages/NotificationServiceBinding12", NULL, NULL},
	{NULL, NULL, NULL, NULL}
};
	soap_set_namespaces(this, namespaces);
}

void NotificationServiceBindingService::destroy()
{	soap_destroy(this);
	soap_end(this);
}

void NotificationServiceBindingService::reset()
{	destroy();
	soap_done(this);
	soap_initialize(this);
	NotificationServiceBindingService_init(SOAP_IO_DEFAULT, SOAP_IO_DEFAULT);
}

#ifndef WITH_PURE_VIRTUAL
NotificationServiceBindingService *NotificationServiceBindingService::copy()
{	NotificationServiceBindingService *dup = SOAP_NEW_COPY(NotificationServiceBindingService(*(struct soap*)this));
	return dup;
}
#endif

int NotificationServiceBindingService::soap_close_socket()
{	return soap_closesock(this);
}

int NotificationServiceBindingService::soap_force_close_socket()
{	return soap_force_closesock(this);
}

int NotificationServiceBindingService::soap_senderfault(const char *string, const char *detailXML)
{	return ::soap_sender_fault(this, string, detailXML);
}

int NotificationServiceBindingService::soap_senderfault(const char *subcodeQName, const char *string, const char *detailXML)
{	return ::soap_sender_fault_subcode(this, subcodeQName, string, detailXML);
}

int NotificationServiceBindingService::soap_receiverfault(const char *string, const char *detailXML)
{	return ::soap_receiver_fault(this, string, detailXML);
}

int NotificationServiceBindingService::soap_receiverfault(const char *subcodeQName, const char *string, const char *detailXML)
{	return ::soap_receiver_fault_subcode(this, subcodeQName, string, detailXML);
}

void NotificationServiceBindingService::soap_print_fault(FILE *fd)
{	::soap_print_fault(this, fd);
}

#ifndef WITH_LEAN
#ifndef WITH_COMPAT
void NotificationServiceBindingService::soap_stream_fault(std::ostream& os)
{	::soap_stream_fault(this, os);
}
#endif

char *NotificationServiceBindingService::soap_sprint_fault(char *buf, size_t len)
{	return ::soap_sprint_fault(this, buf, len);
}
#endif

void NotificationServiceBindingService::soap_noheader()
{	this->header = NULL;
}

const SOAP_ENV__Header *NotificationServiceBindingService::soap_header()
{	return this->header;
}

int NotificationServiceBindingService::run(int port)
{	if (soap_valid_socket(this->master) || soap_valid_socket(bind(NULL, port, 100)))
	{	for (;;)
		{	if (!soap_valid_socket(accept()) || serve())
				break;
			soap_destroy(this);
			soap_end(this);
		}
	}
	return this->error;
}

SOAP_SOCKET NotificationServiceBindingService::bind(const char *host, int port, int backlog)
{	return soap_bind(this, host, port, backlog);
}

SOAP_SOCKET NotificationServiceBindingService::accept()
{	return soap_accept(this);
}

#if defined(WITH_OPENSSL) || defined(WITH_GNUTLS)
int NotificationServiceBindingService::ssl_accept()
{	return soap_ssl_accept(this);
}
#endif

int NotificationServiceBindingService::serve()
{
#ifndef WITH_FASTCGI
	unsigned int k = this->max_keep_alive;
#endif
	do
	{

#ifndef WITH_FASTCGI
		if (this->max_keep_alive > 0 && !--k)
			this->keep_alive = 0;
#endif

		if (soap_begin_serve(this))
		{	if (this->error >= SOAP_STOP)
				continue;
			return this->error;
		}
		if (dispatch() || (this->fserveloop && this->fserveloop(this)))
		{
#ifdef WITH_FASTCGI
			soap_send_fault(this);
#else
			return soap_send_fault(this);
#endif
		}

#ifdef WITH_FASTCGI
		soap_destroy(this);
		soap_end(this);
	} while (1);
#else
	} while (this->keep_alive);
#endif
	return SOAP_OK;
}

static int serve___ewsn3__SendNotification(NotificationServiceBindingService*);

int NotificationServiceBindingService::dispatch()
{	soap_peek_element(this);
	if (!soap_match_tag(this, this->tag, "ewsn:SendNotification"))
		return serve___ewsn3__SendNotification(this);
	return this->error = SOAP_NO_METHOD;
}

static int serve___ewsn3__SendNotification(NotificationServiceBindingService *soap)
{	struct __ewsn3__SendNotification soap_tmp___ewsn3__SendNotification;
	ewsn__SendNotificationResultType ewsn__SendNotificationResult;
	ewsn__SendNotificationResult.soap_default(soap);
	soap_default___ewsn3__SendNotification(soap, &soap_tmp___ewsn3__SendNotification);
	if (!soap_get___ewsn3__SendNotification(soap, &soap_tmp___ewsn3__SendNotification, "-ewsn3:SendNotification", NULL))
		return soap->error;
	if (soap_body_end_in(soap)
	 || soap_envelope_end_in(soap)
	 || soap_end_recv(soap))
		return soap->error;
	soap->error = soap->SendNotification(soap_tmp___ewsn3__SendNotification.ewsn__SendNotification, ewsn__SendNotificationResult);
	if (soap->error)
		return soap->error;
	soap->encodingStyle = NULL;
	soap_serializeheader(soap);
	ewsn__SendNotificationResult.soap_serialize(soap);
	if (soap_begin_count(soap))
		return soap->error;
	if (soap->mode & SOAP_IO_LENGTH)
	{	if (soap_envelope_begin_out(soap)
		 || soap_putheader(soap)
		 || soap_body_begin_out(soap)
		 || ewsn__SendNotificationResult.soap_put(soap, "ewsn:SendNotificationResult", "")
		 || soap_body_end_out(soap)
		 || soap_envelope_end_out(soap))
			 return soap->error;
	};
	if (soap_end_count(soap)
	 || soap_response(soap, SOAP_OK)
	 || soap_envelope_begin_out(soap)
	 || soap_putheader(soap)
	 || soap_body_begin_out(soap)
	 || ewsn__SendNotificationResult.soap_put(soap, "ewsn:SendNotificationResult", "")
	 || soap_body_end_out(soap)
	 || soap_envelope_end_out(soap)
	 || soap_end_send(soap))
		return soap->error;
	return soap_closesock(soap);
}

} // namespace ewsn

/* End of server object code */
