gSOAP 正则表达式验证
gSOAP regex validation
我的 WSDL 中有一个模式限制,定义如下:
<complexType name="xxxXXX">
<attribute name="state" use="optional">
<simpleType>
<restriction base="xs:string">
<pattern value="((\-1)|[0-5])(;((\-1)|[0-5]))*"/>
</restriction>
</simpleType>
</attribute>
</complexType>
但是当我使用 state="" 发出请求时,gSOAP 会接受它。我看到我必须定义函数 fsvalidate
(此处为 https://www.genivia.com/doc/databinding/html/),但它似乎从未被调用(不会触发断点)。
此外,生成的 gsoap 代码不包含正则表达式,即使工具 wsdl2h 生成了这个:
class ns1__xxxXXX
{ public:
@/// Content pattern is "((\-1)|[0-5])(;((\-1)|[0-5]))*".
std::string
*state 0; ///< Optional attribute.
/// A handle to the soap struct that manages this instance (automatically set).
struct soap *soap ;
};
也许我遗漏了一代的一些选项,但我没有在 wsdl2h (https://linux.die.net/man/1/wsdl2h) 和 soapcpp2
上找到任何想法
附加信息:
我在 gSOAP 生成的代码中搜索 fsvalidate,我发现:
#ifndef WITH_LEANER
if (pattern && soap->fsvalidate && (soap->error = soap->fsvalidate(soap, pattern, s)))
return NULL;
#endif
然而,它似乎总是以 NULL 模式调用.. (!(t = soap_string_in(soap, 1, 0, -1, NULL)))
.
注意:我正在使用 gSOAP 2.8.23。
-- 编辑:
我按照@Alex 的建议从 complexType 中提取类型,如下所示:
<xs:simpleType name="stateType">
<xs:restriction base="xs:string">
<xs:pattern value="((\-1)|[0-5])(;((\-1)|[0-5]))*"/>
</xs:restriction>
</xs:simpleType>
<complexType name="xxxXXX">
<attribute name="state" type="tns:stateType" use="optional" />
</complexType>
而且 wsdl2h 似乎产生了一些好东西:
/// Content pattern is "((\-1)|[0-5])(;((\-1)|[0-5]))*".
typedef std::string ns1__stateType "((\-1)|[0-5])(;((\-1)|[0-5]))*";
class ns1__xxxXXX
{ public:
/// Attribute "state" of XSD type "http://new.webservice.namespace":stateType.
@ns1__stateType* state 0;
但是gsoap生成的最终类型是std::string:
class SOAP_CMAC ns1__xxxXXX
{
public:
std::string *state;
当然,它不会验证正则表达式。
似乎忽略了本地正则表达式模式(即 class 的本地模式),但非本地模式工作正常。要强制执行模式验证,必须从 complexType 中提取模式(从 class 中提取):
typedef std::string ns1__xxxXXX_string "((\-1)|[0-5])(;((\-1)|[0-5]))*";
class ns1__xxxXXX
{ public:
ns1__xxxXXX_string *state;
然后设置 fsvalidate() 回调以根据模式检查字符串内容。
这是一个烦人的限制。我建议向 https://sourceforge.net/p/gsoap2/bugs/
提交 bug/feature 请求
我的 WSDL 中有一个模式限制,定义如下:
<complexType name="xxxXXX">
<attribute name="state" use="optional">
<simpleType>
<restriction base="xs:string">
<pattern value="((\-1)|[0-5])(;((\-1)|[0-5]))*"/>
</restriction>
</simpleType>
</attribute>
</complexType>
但是当我使用 state="" 发出请求时,gSOAP 会接受它。我看到我必须定义函数 fsvalidate
(此处为 https://www.genivia.com/doc/databinding/html/),但它似乎从未被调用(不会触发断点)。
此外,生成的 gsoap 代码不包含正则表达式,即使工具 wsdl2h 生成了这个:
class ns1__xxxXXX
{ public:
@/// Content pattern is "((\-1)|[0-5])(;((\-1)|[0-5]))*".
std::string
*state 0; ///< Optional attribute.
/// A handle to the soap struct that manages this instance (automatically set).
struct soap *soap ;
};
也许我遗漏了一代的一些选项,但我没有在 wsdl2h (https://linux.die.net/man/1/wsdl2h) 和 soapcpp2
上找到任何想法附加信息:
我在 gSOAP 生成的代码中搜索 fsvalidate,我发现:
#ifndef WITH_LEANER
if (pattern && soap->fsvalidate && (soap->error = soap->fsvalidate(soap, pattern, s)))
return NULL;
#endif
然而,它似乎总是以 NULL 模式调用.. (!(t = soap_string_in(soap, 1, 0, -1, NULL)))
.
注意:我正在使用 gSOAP 2.8.23。
-- 编辑:
我按照@Alex 的建议从 complexType 中提取类型,如下所示:
<xs:simpleType name="stateType">
<xs:restriction base="xs:string">
<xs:pattern value="((\-1)|[0-5])(;((\-1)|[0-5]))*"/>
</xs:restriction>
</xs:simpleType>
<complexType name="xxxXXX">
<attribute name="state" type="tns:stateType" use="optional" />
</complexType>
而且 wsdl2h 似乎产生了一些好东西:
/// Content pattern is "((\-1)|[0-5])(;((\-1)|[0-5]))*".
typedef std::string ns1__stateType "((\-1)|[0-5])(;((\-1)|[0-5]))*";
class ns1__xxxXXX
{ public:
/// Attribute "state" of XSD type "http://new.webservice.namespace":stateType.
@ns1__stateType* state 0;
但是gsoap生成的最终类型是std::string:
class SOAP_CMAC ns1__xxxXXX
{
public:
std::string *state;
当然,它不会验证正则表达式。
似乎忽略了本地正则表达式模式(即 class 的本地模式),但非本地模式工作正常。要强制执行模式验证,必须从 complexType 中提取模式(从 class 中提取):
typedef std::string ns1__xxxXXX_string "((\-1)|[0-5])(;((\-1)|[0-5]))*";
class ns1__xxxXXX
{ public:
ns1__xxxXXX_string *state;
然后设置 fsvalidate() 回调以根据模式检查字符串内容。
这是一个烦人的限制。我建议向 https://sourceforge.net/p/gsoap2/bugs/
提交 bug/feature 请求