- json_tokener_reset(jbus->tokener);
- *obj = json_tokener_parse_ex(jbus->tokener, msg, -1);
- if (json_tokener_get_error(jbus->tokener) == json_tokener_success)
- return 1;
- json_object_put(*obj);
- *obj = NULL;
- return 0;
-}
-
-static DBusHandlerResult incoming_resp(DBusConnection *connection, DBusMessage *message, struct jbus *jbus, int iserror)
-{
- int status;
- const char *str;
- struct jrespw *jrw, **prv;
- struct json_object *reply;
- dbus_uint32_t serial;
-
- /* search for the waiter */
- serial = dbus_message_get_reply_serial(message);
- prv = &jbus->waiters;
- while ((jrw = *prv) != NULL && jrw->serial != serial)
- prv = &jrw->next;
- if (jrw == NULL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- *prv = jrw->next;
-
- /* retrieve the string value */
- if (dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
- status = 0;
- else {
- status = -1;
- str = NULL;
- reply = NULL;
- }
-
- /* treat it */
- if (jrw->onresp_s)
- jrw->onresp_s(iserror ? -1 : status, str, jrw->data);
- else {
- status = parse(jbus, str, &reply) - 1;
- jrw->onresp_j(iserror ? -1 : status, reply, jrw->data);
- json_object_put(reply);
- }
-
- free(jrw);
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static DBusHandlerResult incoming_call(DBusConnection *connection, DBusMessage *message, struct jbus *jbus)
-{
- struct jservice *srv;
- struct jreq *jreq;
- const char *str;
- const char *method;
- struct json_object *query;
-
- /* search for the service */
- if (!matchitf(jbus, message))
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- method = dbus_message_get_member(message);
- if (method == NULL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- srv = jbus->services;
- while(srv != NULL && strcmp(method, srv->method))
- srv = srv->next;
- if (srv == NULL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
- /* handle the message */
- jreq = malloc(sizeof * jreq);
- if (jreq == NULL)
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
- jreq->request = dbus_message_ref(message);
- jreq->connection = dbus_connection_ref(jbus->connection);
-
- /* retrieve the string value */
- if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &str, DBUS_TYPE_INVALID))
- return reply_invalid_request(jreq);
- if (srv->oncall_s) {
- /* handling strings only */
- srv->oncall_s(jreq, str);
- }
- else {
- /* handling json only */
- if (!parse(jbus, str, &query))
- return reply_invalid_request(jreq);
- srv->oncall_j(jreq, query);
- json_object_put(query);
- }
- return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static DBusHandlerResult incoming_signal(DBusConnection *connection, DBusMessage *message, struct jbus *jbus)
-{
- struct jsignal *sig;
- const char *str;
- const char *name;