}
boost::property_tree::ptree root;
- boost::property_tree::read_json(requestStream, root);
+ try
+ {
+ boost::property_tree::read_json(requestStream, root);
+ }
+ catch(boost::property_tree::json_parser::json_parser_error &e)
+ {
+ return OCRepresentation();
+ }
boost::property_tree::ptree payload = root.get_child("oc", boost::property_tree::ptree());
OCRepresentation root_resource;
std::vector<OCRepresentation> children;
#include <uri.h> // libcoap
#include <option.h> // libcoap
}
-
+namespace OC{
+ // Helper function to escape special character.
+ std::string escapeString(const std::string& value)
+ {
+ std::ostringstream stringStream;
+ for (auto iter = value.cbegin(); iter != value.cend(); iter++)
+ {
+ switch (*iter)
+ {
+ case '\\': stringStream << "\\\\";
+ break;
+ case '"': stringStream << "\\\"";
+ break;
+ case '/': stringStream << "\\/";
+ break;
+ case '\b': stringStream << "\\b";
+ break;
+ case '\f': stringStream << "\\f";
+ break;
+ case '\n': stringStream << "\\n";
+ break;
+ case '\r': stringStream << "\\r";
+ break;
+ case '\t': stringStream << "\\t";
+ break;
+ default: stringStream << *iter;
+ break;
+ }
+ }
+ return stringStream.str();
+ }
+}
// [TODO] remove this function
// this function is just a temporary patch for Sudarshan
// it seems that the C stack is parsing and giving out the query separately.
#define __INTEL_OCAPI_H_2014_07_10
#include <string>
+#include <sstream>
#include <vector>
#include <map>
namespace OC {
+
class OCResource;
} // namespace OC
// Used in GET, PUT, POST, DELETE methods on links to other resources of a collection.
const std::string BATCH_INTERFACE = "oc.mi.b";
+ // Helper function to escape character in a string.
+ std::string escapeString(const std::string& value);
+
class OCRepresentation
{
m_resourceInterfaces = resourceInterfaces;
}
};
-
} // namespace OC
#endif
std::stringstream requestStream;
requestStream << requestPayload;
boost::property_tree::ptree root;
- boost::property_tree::read_json(requestStream, root);
+ try
+ {
+ boost::property_tree::read_json(requestStream, root);
+ }
+ catch(boost::property_tree::json_parser::json_parser_error &e)
+ {
+ //TOD: log this
+ return;
+ }
// TODO this expects the representation oc:{} and not oc:[{}]
// this representation is fine when setting for simple resource.
{
payload << ',';
}
- payload << "\""<<itr->first<<"\":" << itr->second.front();
+ payload << "\""<<itr->first<<"\":\""<< itr->second.front()<<"\"";
}
payload << "}}";
{
payload << ',';
}
- payload << "\""<<itr->first<<"\":" << itr->second.front();
+ payload << "\""<<itr->first<<"\":\""<< itr->second.front()<<"\"";
}
payload << "}}";
payload << ',';
}
// cout << itr->first << ":" <, itr->second.front() << endl;
- payload << "\""<<itr->first<<"\":" << itr->second.front();
+ payload << "\""<<itr->first<<"\":\""<< itr->second.front()<<"\"";
+
}
payload << "}}";