📄 validator1.cpp
字号:
/////////////////////////////////////////////////////////////////////////////
// $Id: validator1.cpp,v 1.4 2001/09/11 11:45:54 rosimildo Exp $
//
// Copyright (c) 2001 Exor International Inc. All rights reserved.
//
// MODULE DESCRIPTION:
// Callback entry points to implement the SOAP validator
// form the UserLand site.
//
// MODIFICATION/HISTORY:
//
// $Log: validator1.cpp,v $
// Revision 1.4 2001/09/11 11:45:54 rosimildo
// changed copyright from Technopoint to Exit; updated version to 0.9
//
// Revision 1.3 2001/04/19 17:30:26 rosimildo
// Added Support for CGI processes.
//
// Revision 1.2 2001/03/11 15:40:29 rosimildo
// Updated License to all files.
//
//
// 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
/**
*
* #1 - CALL: validator1.countTheEntities (string) returns struct
*
* DESCRIPTION:
* This handler takes a single parameter, a string, that contains
* any number of predefined entities, namely <, >, &, ' and ".
*
* Your handler must return a struct that contains five fields,
* all numbers:
*
* ctLeftAngleBrackets,
* ctRightAngleBrackets,
* ctAmpersands,
* ctApostrophes,
* ctQuotes.
*
* To validate, the numbers must be correct.
*/
int validator_countTheEntities( esoap::MethodDataBlock *mdata )
{
SYSLOG( "Method: countTheEntities\n" );
// let's access the parameters...
esoap::Method *m = mdata->in()->getMethod();
esoap::String s = m->getParameter( 0 )->getString();
int lt = 0;
int gt = 0;
int amp = 0;
int quote = 0;
int apos = 0;
const char *str = s.c_str();
while( *str )
{
switch( *str++ )
{
case '<':
lt++;
break;
case '>':
gt++;
break;
case '&':
amp++;
break;
case '\"':
quote++;
break;
case '\'':
apos++;
break;
}
}
esoap::String respName = m->getName();
respName += "Response";
esoap::Method *resp = mdata->out()->setMethod( respName.c_str(),
m->getURI().c_str() );
esoap::Parameter *any = new esoap::Parameter( "struct" );
any->addInteger( "ctLeftAngleBrackets", lt );
any->addInteger( "ctRightAngleBrackets", gt );
any->addInteger( "ctAmpersands", amp );
any->addInteger( "ctApostrophes", apos );
any->addInteger( "ctQuotes", quote );
resp->addParameter( any );
return 0;
}
/**
* #2 - CALL: validator1.easyStructTest (struct) returns number
*
* This handler takes a single parameter, a struct, containing at
* least three elements named moe, larry and curly, all <i4>s.
* Your handler must add the three numbers and return the result.
*
*/
int validator_easyStructTest( esoap::MethodDataBlock *mdata )
{
SYSLOG( "Method: easyStructTest\n" );
// let's access the parameters...
esoap::Method *m = mdata->in()->getMethod();
esoap::Parameter *p = m->getParameter( 0 );
esoap::Parameter *moe = p->getParameter( "moe" );
esoap::Parameter *larry = p->getParameter( "larry" );
esoap::Parameter *curly = p->getParameter( "curly" );
assert( moe && larry && curly );
int res = moe->getInteger() + larry->getInteger() + curly->getInteger();
esoap::String respName = m->getName();
respName += "Response";
esoap::Method *resp = mdata->out()->setMethod( respName.c_str(),
m->getURI().c_str() );
resp->addInteger( "result", res );
return 0;
}
/**
* #3 - CALL: validator1.echoStructTest( struct ) returns struct
*
* This handler takes a single parameter, a struct.
* Your handler must return the struct.
*
*/
int validator_echoStructTest( esoap::MethodDataBlock *mdata )
{
SYSLOG( "Method: echoStructTest \n" );
// let's access the parameters...
esoap::Method *m = mdata->in()->getMethod();
esoap::Parameter *param = m->removeParameter( 0 );
esoap::String respName = m->getName();
respName += "Response";
esoap::Method *resp = mdata->out()->setMethod( respName.c_str(),
m->getURI().c_str() );
resp->addParameter( param );
return 0;
}
/**
* #4 - CALL validator1.manyTypesTest( number, boolean, string,
* double, dateTime, base64) returns array
*
* This handler takes six parameters, and returns an array containing
* all the parameters.
*
*/
int validator_manyTypesTest( esoap::MethodDataBlock *mdata )
{
SYSLOG( "Method: manyTypesTest\n" );
// let's access the parameters...
esoap::Method *m = mdata->in()->getMethod();
assert( m->getParameterCount() == 6 );
esoap::String respName = m->getName();
respName += "Response";
esoap::Method *resp = mdata->out()->setMethod( respName.c_str(),
m->getURI().c_str() );
// array type, is un-named...
esoap::Array *a = new esoap::Array;
a->setType( "xsd:ur-type[]" );
while( m->getParameterCount() )
{
esoap::Parameter *param = m->removeParameter( 0 );
a->addParameter( param );
}
resp->addParameter( a );
return 0;
}
/**
* #5 - CALL validator1.moderateSizeArrayCheck (array) returns string
*
* This handler takes a single parameter, which is an array containing
* between 100 and 200 elements. Each of the items is a string,
* your handler must return a string containing the concatenated text
* of the first and last elements.
*
*/
int validator_moderateSizeArrayCheck( esoap::MethodDataBlock *mdata )
{
SYSLOG( "Method: moderateSizeArrayCheck\n" );
// let's access the parameters...
esoap::Method *m = mdata->in()->getMethod();
esoap::Parameter *param = m->getParameter( 0 );
size_t param_count = param->getParameterCount();
esoap::String result = param->getParameter( 0 )->getString();
result += param->getParameter( param_count -1 )->getString();
esoap::String respName = m->getName();
respName += "Response";
esoap::Method *resp = mdata->out()->setMethod( respName.c_str(),
m->getURI().c_str() );
resp->addString( "return", result.c_str() );
return 0;
}
/**
* #6 - CALL: validator1.nestedStructTest (struct) returns number
*
* This handler takes a single parameter, a struct, that models a daily calendar.
* At the top level, there is one struct for each year. Each year is broken down
* into months, and months into days. Most of the days are empty in the struct
* you receive, but the entry for April 1, 2000 contains a least three elements
* named moe, larry and curly, all <i4>s.
*
* Your handler must add the three numbers and return the result.
*
*
* Ken MacLeod: "This description isn't clear, I expected '2000.April.1'
* when in fact it's '2000.04.01'. Adding a note saying that month and day are
* two-digits with leading 0s, and January is 01 would help." Done.
*
*/
int validator_nestedStructTest( esoap::MethodDataBlock *mdata )
{
SYSLOG( "Method: nestedStructTest\n" );
// let's access the parameters...
esoap::Method *m = mdata->in()->getMethod();
esoap::Parameter *param = m->getParameter( 0 );
// SYSLOG( "param: %s\n", param->getName().c_str() );
esoap::Parameter *year = param->getParameter( "year2000" );
esoap::Parameter *month = year->getParameter( "month04" );
esoap::Parameter *day = month->getParameter( "day01" );
esoap::Parameter *moe = day->getParameter( "moe" );
esoap::Parameter *larry = day->getParameter( "larry" );
esoap::Parameter *curly = day->getParameter( "curly" );
assert( moe && larry && curly );
int res = moe->getInteger() + larry->getInteger() + curly->getInteger();
// SYSLOG( "res: %d\n", res );
esoap::String respName = m->getName();
respName += "Response";
esoap::Method *resp = mdata->out()->setMethod( respName.c_str(),
m->getURI().c_str() );
resp->addInteger( "result", res );
return 0;
}
/**
* #7 - CALL: validator1.simpleStructReturnTest (number) returns struct
*
* This handler takes one parameter, and returns a struct containing three elements,
* times10, times100 and times1000, the result of multiplying the number by
* 10, 100 and 1000.
*/
int validator_simpleStructReturnTest( esoap::MethodDataBlock *mdata )
{
SYSLOG( "Method: simpleStructReturnTest\n" );
// let's access the parameters...
esoap::Method *m = mdata->in()->getMethod();
esoap::Parameter *param = m->getParameter( 0 );
assert( param );
int value = param->getInteger();
esoap::String respName = m->getName();
respName += "Response";
esoap::Method *resp = mdata->out()->setMethod( respName.c_str(),
m->getURI().c_str() );
esoap::Parameter *any = new esoap::Parameter( "struct" );
any->addInteger( "times10", value*10 );
any->addInteger( "times100", value*100 );
any->addInteger( "times1000", value*1000 );
resp->addParameter( any );
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -