⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 add_integers.cpp

📁 ESOAP一款专注于嵌入式的WEB SERVICE开发的软件。
💻 CPP
字号:
/////////////////////////////////////////////////////////////////////////////
// $Id: add_integers.cpp,v 1.8 2001/09/11 11:45:53 rosimildo Exp $
//
// Copyright (c) 2001 Exor International Inc. All rights reserved.
//
// MODULE DESCRIPTION: 
// Callback entry points to implement the SOAP Interop test suite.
//
// MODIFICATION/HISTORY:
//
// $Log: add_integers.cpp,v $
// Revision 1.8  2001/09/11 11:45:53  rosimildo
// changed copyright from Technopoint to Exit; updated version to 0.9
//
// Revision 1.7  2001/08/14 14:21:45  rosimildo
// added dateTime to get_types example.
//
// Revision 1.6  2001/07/31 00:26:36  rosimildo
// Added anyType; Added shared_ptr support from boost.
//
// Revision 1.5  2001/07/17 01:06:09  rosimildo
// Added new primitive type hexBinary.
//
// Revision 1.4  2001/07/07 14:43:58  rosimildo
// Added xsd:decimal type.
//
// Revision 1.3  2001/06/23 15:46:28  rosimildo
// Upagrade to 2001 XML Schema.
//
// Revision 1.2  2001/05/03 19:52:27  rosimildo
// Added code to handle shutdown of the Abyss server.
//
// Revision 1.1  2001/04/19 17:30:26  rosimildo
// Added Support for CGI processes.
//
//
// Created 2001/02/08 Rosimildo da Silva, ConnectTel Inc.
// [rdasilva@connecttel.com]
//
/////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <assert.h>

#include "soap_server.h"
#include "soap_envelope.h"
#include "syslogpp.h"

/* must be the last include */
#ifdef MEMWATCH
#include <memwatch.h>
#endif

/**
 * The SOAP server framework call this method to add two parameters..
 */
int methodAdd( esoap::MethodDataBlock *mdata )
{
  static int raw = 0;
  SYSLOG( "Method: add called( %d )\n", raw );
  esoap::Parameter *pa; 
  esoap::Parameter *pb;

  // let's access the parameters...
  esoap::Method *m = mdata->in()->getMethod();
  pa = m->getParameter( "a" );
  pb = m->getParameter( "b" );

  if( pa && pb )
  {
    SYSLOG( "adding parameters\n" );
    esoap::String respName = "returnResponse";
    esoap::Method *resp = mdata->out()->setMethod( respName.c_str() );
    resp->setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" );
    int res = pa->getInteger() + pb->getInteger();
    resp->addInteger( "sum", res );
    resp->addInteger( "raw", raw++ );
  }
  else
  {
    SYSLOG( "Error: parameter not found\n" );
    esoap::Fault *resp = mdata->out()->setFault( esoap::Fault::Server, 
                                               "Server Error" );
    resp->addToDetail( new esoap::Parameter( "message", "Parameters not found" ) );
  }
  return 0;
}


/**
 * The SOAP server framework call this method to add the
 * all parameters passed in a SOAP array.
 */
int methodAddArray( esoap::MethodDataBlock *mdata )
{
  static int raw = 0;
  SYSLOG( "Method: addArray called( %d )\n", raw );
  esoap::Array *a; 

  SYSLOG( "getting parameters\n" );
  // let's access the parameters...
  esoap::Method *m = mdata->in()->getMethod();
  a = (esoap::Array *)m->getParameter( 0 );
  if( a )
  {
     int sum = 0;
     SYSLOG( "adding parameters\n" );
	 for( size_t i = 0; i < a->getParameterCount(); i++ )
	 {
	    sum += a->getParameter( i )->getInteger();  
	 }     
     esoap::String respName = m->getName();
     respName += "Response";
     esoap::Method *resp = mdata->out()->setMethod( respName.c_str() );
     resp->addInteger( "sum", sum );
     resp->addInteger( "raw", raw++ );
  }
  else
  {
    SYSLOG( "Error: parameter not found\n" );
    esoap::Fault *resp = mdata->out()->setFault( esoap::Fault::Server, 
                                               "Server Error" );
    resp->addToDetail( new esoap::Parameter( "message", "Parameters not found" ) );
  }
  return 0;
}


int supportedTypes( esoap::MethodDataBlock *mdata )
{
  SYSLOG( "Method: supportedTypes\n" );

  esoap::String respName = mdata->in()->getMethod()->getName();
  respName += "Response";
  esoap::Method *resp  = mdata->out()->setMethod( respName.c_str() );
  resp->setEncodingStyle( "http://schemas.xmlsoap.org/soap/encoding/" );

//
// NOTE: This is not strictly following the SOAP spec.This is a 
// debugging call to help to the dump the data on the wire for all
// types support by the library.
//

  // list all simple types ...
  resp->addInteger( "int", 1 );
  resp->addString(  "string", "Hello World: check parsing of \"<\" and \"&\"." );
  resp->addBoolean( "boolean", true );
  resp->addFloat(  "float", 1.23f );

  // array type ....
  esoap::Array *a = new esoap::Array;
  a->addInteger( 0 );
  a->addInteger( 1 );
  a->addInteger( 2 );
  resp->addParameter( a );

  // complex data types...
  esoap::Parameter *any = new esoap::Parameter( "struct" );
  any->addInteger( "age", 1 );
  any->addString(  "name", "Joe" );
  any->addBoolean( "married", true );
  any->addByte( "A", 'A' );
  any->addShort( "B", (short)1 );
  any->addLong( "C", (INT64)2 );
  any->addUnsignedByte( "D", (unsigned char)3 );
  any->addUnsignedShort( "E", (unsigned short)4 );
  any->addUnsignedInt( "F", (unsigned short)5 );
  any->addUnsignedLong( "G", (UINT64)6 );
  any->addDouble( "H", 2.46 );
  any->addDecimal( "Dec", "1.00" );
  any->addDecimal( "Dec1", "100" );

  esoap::Parameter *at = new esoap::Parameter( "anyType", "123", esoap::xsd_anyType );
  any->addAnyType( "anyType", esoap::AnyType( at ) );

  resp->addParameter( any );

  resp->addTimeInstant( "tm1", 0 );
  resp->addTimeInstant( "tm2", 100 );

  esoap::Parameter *b64 = new esoap::Parameter( "b64" );
  long x = 0x12345678;
  b64->encode( ( char *)&x, sizeof( x ) );
  resp->addParameter( b64 );

  esoap::Parameter *b64str = new esoap::Parameter( "b64_string" );
  const char *y = "ABCabc";
  b64str->encode( ( char *)y, strlen( y ) );
  resp->addParameter( b64str );

  esoap::Parameter *tmNow = new esoap::Parameter( "time" );
  tmNow->setTimeInstantNow();

  esoap::Parameter *nil = new esoap::Parameter( "nil" );
  nil->setNull();
  resp->addParameter( nil );

  x = 0x1234ABCDL;
  esoap::Packet hex;
  hex.append( ( char *)&x, sizeof( x ) );
  resp->addHexBinary( "hexBinary", hex );

  // let's add some info about the client requesting the data....
  esoap::String reqValue;

  reqValue = esoap::Server::instance()->httpHeaderValue(
                                            mdata->request(), "user-agent" );
  if( reqValue.size() )  resp->addString(  "user-agent", reqValue.c_str() );

  reqValue = esoap::Server::instance()->httpHeaderValue(
                                            mdata->request(), "host" );
  if( reqValue.size() )  resp->addString(  "host", reqValue.c_str() );

  return 0;
}


/**
 */
int methodMemCheck( esoap::MethodDataBlock *mdata )
{
  SYSLOG( "Method: memory check\n" );
  // let's access the parameters...
  esoap::Method *m = mdata->in()->getMethod();
  esoap::String respName = m->getName();
  respName += "Response";
  esoap::Method *resp = mdata->out()->setMethod( respName.c_str() );

#ifdef MEMWATCH
  mwAutoCheck( 1 );
  mwFlushNow();
  SYSLOG( "Method: memory check is complete.\n" );
#endif

  resp->addString( "result", "Done" );

  esoap::Server::instance()->terminate();
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -