📄 propertylist.cpp
字号:
if (attrStream.bad()) value = -1; #endif if (value < 0) { log.StartDiagnostic(0) << L"PropertyList::GetFetchobjCacheAttrs - " L"Invalid value for " << propName << L" of " << attr << L"."; log.EndDiagnostic(); throw VXIException::InterpreterEvent(EV_ERROR_SEMANTIC, L"invalid maxage value"); } // (1.3) Add value to fetchobj VXIInteger * val = VXIIntegerCreate(value); if (val == NULL) throw VXIException::OutOfMemory(); VXIvalueResult r = VXIMapSetProperty(fetchobj.GetValue(), INET_CACHE_CONTROL_MAX_AGE, reinterpret_cast<VXIValue*>(val)); } // (2) Attribute: maxstale // (2.1) Get the attribute - first locally, then from the defaults. attr.erase(); elem.GetAttribute(ATTRIBUTE_MAXSTALE, attr); if (attr.empty()) { switch (type) { case PropertyList::Audio: propName = L"audiomaxstale"; break; case PropertyList::Document: propName = L"documentmaxstale"; break; case PropertyList::Grammar: propName = L"grammarmaxstale"; break; case PropertyList::Object: propName = L"objectmaxstale"; break; case PropertyList::Script: propName = L"scriptmaxstale"; break; } attr = toString(GetProperty(propName)); } // (2.2) Process the value. if (!attr.empty()) { VXIint value = -1; #if defined(__GNUC__) // The G++ 2.95/3.0 implementation of basic_stringstream is faulty. VXIchar * temp; value = VXIint(wcstol(attr.c_str(), &temp, 10)); if (*temp) value = -1; #else std::basic_stringstream<VXIchar> attrStream(attr); attrStream >> value; if (attrStream.bad()) value = -1; #endif if (value < 0) { log.StartDiagnostic(0) << L"PropertyList::GetFetchobjCacheAttrs - " L"Invalid value for " << propName << L" of " << attr << L"."; log.EndDiagnostic(); throw VXIException::InterpreterEvent(EV_ERROR_SEMANTIC, L"invalid maxstale value"); } // (2.3) Add value to fetchobj VXIInteger * val = VXIIntegerCreate(value); if (val == NULL) throw VXIException::OutOfMemory(); VXIvalueResult r = VXIMapSetProperty(fetchobj.GetValue(), INET_CACHE_CONTROL_MAX_AGE, reinterpret_cast<VXIValue*>(val)); } // (3) Attribute: fetchtimeout // (3.1) Get the attribute - first locally, then from the defaults. attr.erase(); elem.GetAttribute(ATTRIBUTE_FETCHTIMEOUT, attr); if (attr.empty()) attr = toString(GetProperty(L"fetchtimeout")); // (3.2) Process the value. if (!attr.empty()) { VXIint value; if (!ConvertTimeToMilliseconds(log, attr, value)) { log.StartDiagnostic(0) << L"PropertyList::GetFetchobjTimeout - " L"Invalid value for fetchtimeout of " << attr << L"."; log.EndDiagnostic(); throw VXIException::InterpreterEvent(EV_ERROR_SEMANTIC, L"invalid fetchtimeout value"); } // throw an bad.fetch if the fetchtimeout = 0 if( value == 0 ) throw VXIException::InterpreterEvent(EV_ERROR_BADFETCH, L"fetchtimeout value is 0s"); // (3.3) Add value to fetchobj VXIInteger * str = VXIIntegerCreate(value); if (str == NULL) throw VXIException::OutOfMemory(); VXIvalueResult r = VXIMapSetProperty(fetchobj.GetValue(),INET_TIMEOUT_DOWNLOAD, reinterpret_cast<VXIValue*>(str)); } // (4) Base uri from inet attr.erase(); elem.GetAttribute(ATTRIBUTE_BASE, attr); if (attr.empty()) { const VXIchar* tmp = GetProperty(PropertyList::BaseURI); if( tmp ) attr = tmp; } if( !attr.empty() ) { VXIString * base = VXIStringCreate(attr.c_str()); if (base == NULL) throw VXIException::OutOfMemory(); VXIMapSetProperty(fetchobj.GetValue(), INET_URL_BASE, reinterpret_cast<VXIValue*>(base)); } #pragma message ("PropertyList::GetFetchobjCacheAttrs - ignoring fetchhint") } bool PropertyList::GetFetchobjSubmitAttributes(const VXMLElement & elem, VXIMapHolder & submitData, VXIMapHolder & fetchobj) const { // (1) Set submit method. // (1.1) Get the attribute - first locally, then from the defaults. vxistring attr; elem.GetAttribute(ATTRIBUTE_METHOD, attr); // (1.2) Process the value. const VXIchar * value = NULL; if (attr == L"get" || attr.empty()) value = INET_SUBMIT_METHOD_GET; else if (attr == L"post") value = INET_SUBMIT_METHOD_POST; else { log.StartDiagnostic(0) << L"PropertyList::GetFetchobjSubmitMethod - " L"Bad value (" << ATTRIBUTE_METHOD << L" = \"" << attr << L"\"), " L"defaulting to " << INET_SUBMIT_METHOD_DEFAULT << L"."; log.EndDiagnostic(); value = INET_SUBMIT_METHOD_DEFAULT; } // (1.3) Add value to fetchobj VXIString * str = VXIStringCreate(value); if (str == NULL) throw VXIException::OutOfMemory(); VXIvalueResult r = VXIMapSetProperty(fetchobj.GetValue(), INET_SUBMIT_METHOD, reinterpret_cast<VXIValue*>(str)); if (r != VXIvalue_RESULT_SUCCESS) return false; // (2) Get encoding for the submit. // (2.1) Get the attribute. if (!elem.GetAttribute(ATTRIBUTE_ENCTYPE, attr)) attr = L"application/x-www-form-urlencoded"; // (2.2) Add value to fetchobj str = VXIStringCreate(attr.c_str()); if (str == NULL) throw VXIException::OutOfMemory(); r = VXIMapSetProperty(fetchobj.GetValue(), INET_SUBMIT_MIME_TYPE, reinterpret_cast<VXIValue*>(str)); if (r != VXIvalue_RESULT_SUCCESS) return false; // (3) Set the submit data. r = VXIMapSetProperty(fetchobj.GetValue(), INET_URL_QUERY_ARGS, reinterpret_cast<VXIValue*>(submitData.Release())); return r == VXIvalue_RESULT_SUCCESS; } bool PropertyList::GetFetchobjBase(VXIMapHolder & fetchobj) const { const VXIchar * base = GetProperty(PropertyList::BaseURI); if (base != NULL) AddParamValue(fetchobj, INET_URL_BASE, base); return true; } bool PropertyList::GetFetchobjURIs(const VXMLElement & elem, VXIMapHolder & fetchobj, vxistring & url, vxistring & fragment) const { fragment = L""; // The URI may be decomposed into three elements - the base, a relative // address, and a fragment corresponding to a dialog within that module. // (1) First the base. GetFetchobjBase(fetchobj); // (2) Then determine if there is a fragment at all. if (url.empty()) return false; vxistring::size_type pos = url.find('#'); if (pos == vxistring::npos) return true; // (3) There was a fragment. if (pos + 1 < url.length()) fragment = url.substr(pos + 1, url.length() - pos - 1); url.erase(pos); return true; } //**************************************************************** //* Recognition & Grammar property related. //**************************************************************** bool PropertyList::PushProperties(const VXMLElement & doc) { // (1) Find the last non-empty level. unsigned int i; for (i = LAST_PROP - 1; i > 0; --i) if (!properties[i].empty()) break; bool addsForbidden = (i == LAST_PROP - 1); STRINGMAP & propmap = properties[i + 1]; // This is the first empty level. // (2) Add properties at that point. bool foundSomething = false; for (VXMLNodeIterator it(doc); it; ++it) { VXMLNode child = *it; if (child.GetType() != VXMLNode::Type_VXMLElement) continue; const VXMLElement & elem = reinterpret_cast<const VXMLElement &>(child); VXMLElementType nodeName = elem.GetName(); if (nodeName == NODE_PROPERTY) { if (addsForbidden) { log.LogError(999,SimpleLogger::MESSAGE,L"property list size exceeded"); return false; } vxistring name; vxistring value; elem.GetAttribute(ATTRIBUTE_NAME, name); elem.GetAttribute(ATTRIBUTE_VALUE, value); // This added the name / value pair, converting to vxistrings. propmap.insert(propmap.end(), STRINGMAP::value_type(name, value)); foundSomething = true; } } return foundSomething; } void PropertyList::PopProperties() { // Find the last non-empty level. unsigned int i; for (i = LAST_PROP - 1; i > 0; --i) if (!properties[i].empty()) break; // Clear it. properties[i].clear(); } void PropertyList::PopPropertyLevel(PropertyLevel l) { if( l < LAST_PROP && !properties[l].empty()) { properties[l].clear(); } } // This starts at the lowest level, inserting entries into a newly created map. // Values at higher levels will overwrite keys with identical names. // void PropertyList::GetProperties(VXIMapHolder & m) const { // (1) Collapse the values down into a single map. STRINGMAP collapsed; PROPERTIES::const_iterator i; for (i = properties.begin(); i != properties.end(); ++i) { for (STRINGMAP::const_iterator j = (*i).begin(); j != (*i).end(); ++j) { collapsed[(*j).first] = (*j).second; } } // (2) Create a new map & copy the values over. STRINGMAP::const_iterator j; for (j = collapsed.begin(); j != collapsed.end(); ++j) { VXIString * value = VXIStringCreate((*j).second.c_str()); if (value == NULL) throw VXIException::OutOfMemory(); // Set this key. VXIMapSetProperty(m.GetValue(), (*j).first.c_str(), reinterpret_cast<VXIValue *>(value)); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -