//TODO: Verify that ALL requests get sent via LWS_CALLBACK_HTTP, so we can use that instead of LWS_CALLBACK_RECIEVE
//TODO: Do we want exceptions, or just to return an invalid json reply? Probably an invalid json reply.
DebugOut() << __SMALLFILE__ << ":" << __LINE__ << " Requested: " << (char*)in << "\n";
- GError* error = nullptr;
+ std::string tempInput((char*)in);
json_object *rootobject;
json_tokener *tokener = json_tokener_new();
enum json_tokener_error err;
do
{
- rootobject = json_tokener_parse_ex(tokener, (char*)in,len);
+ rootobject = json_tokener_parse_ex(tokener, tempInput.c_str(),len);
} while ((err = json_tokener_get_error(tokener)) == json_tokener_continue);
if (err != json_tokener_success)
{
fprintf(stderr, "Error: %s\n", json_tokener_error_desc(err));
+ throw std::runtime_error("JSON Parsing error");
// Handle errors, as appropriate for your application.
}
+ if(!rootobject)
+ {
+ DebugOut(0)<<"failed to parse json: "<<tempInput<<endl;
+ }
+
if (tokener->char_offset < len) // XXX shouldn't access internal fields
{
// Handle extra characters after parsed object as desired.
// e.g. issue an error, parse another object from that point, etc...
+
}
// Success, use jobj here.
json_object *typeobject = json_object_object_get(rootobject,"type");
if(condition & G_IO_ERR)
{
- DebugOut(0)<<"websocketsink polling error."<<endl;
+ DebugOut(0)<< __SMALLFILE__ <<":"<< __LINE__ <<" websocketsink polling error."<<endl;
}
if (condition & G_IO_HUP)
{
DebugOut() << "getRanged methodReply has been recieved, without a request being in!. This is likely due to a request coming in after the timeout has elapsed.\n";
}
- while (propertylist.size() > 0)
- {
-
- AbstractPropertyType *type = propertylist.front();
- delete type;
- propertylist.pop_front();
- }
}
else if (name == "get")
{
json_object_put(dataobject);
}
json_object_put(rootobject);
- ///TODO: this will probably explode:
- //mlc: I agree with Kevron here, it does explode.
- //if(error) g_error_free(error);
-
break;
}
DebugOut(5) << __SMALLFILE__ << ":" << __LINE__ << "Adding poll for websocket IO channel" << endl;
//Add a FD to the poll list.
GIOChannel *chan = g_io_channel_unix_new(libwebsocket_get_socket_fd(wsi));
+
/// TODO: I changed this to be more consistent with the websocket sink end. it may not be correct. TEST
g_io_add_watch(chan,GIOCondition(G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP),(GIOFunc)gioPollingFunc,0);
g_io_channel_set_close_on_unref(chan,true);
g_io_channel_unref(chan); //Pass ownership of the GIOChannel to the watch.
-
- //g_io_add_watch(chan,G_IO_PRI,(GIOFunc)gioPollingFunc,0);
- //g_io_add_watch(chan,G_IO_ERR,(GIOFunc)gioPollingFunc,0);
- //g_io_add_watch(chan,G_IO_HUP,(GIOFunc)gioPollingFunc,0);
-
break;
}
s << "{\"type\":\"method\",\"name\":\"get\",\"data\":[\"" << reply->property << "\"],\"transactionid\":\"" << uuid << "\"}";
string replystr = s.str();
- DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Reply:" << replystr <<endl;
+ DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Sending:" << replystr <<endl;
//printf("Reply: %s\n",replystr.c_str());
char *new_response = new char[LWS_SEND_BUFFER_PRE_PADDING + strlen(replystr.c_str()) + LWS_SEND_BUFFER_POST_PADDING];
new_response+=LWS_SEND_BUFFER_PRE_PADDING;