/** * @brief If message contains subscribe:true, add the message to subscription list using the default key '/category/method'. * * This is equivalent to LSSubscriptionAdd(sh, key, message, lserror) * where the key is LSMessageGetKind(message). * * @param sh * @param message * @param subscribed * @param lserror * * @retval */ bool LSSubscriptionProcess (LSHandle *sh, LSMessage *message, bool *subscribed, LSError *lserror) { JSchemaInfo schemaInfo; jschema_info_init(&schemaInfo, jschema_all(), NULL, NULL); bool retVal = false; bool subscribePayload = false; jvalue_ref subObj = NULL; const char *payload = LSMessageGetPayload(message); jvalue_ref object = jdom_parse(j_cstr_to_buffer(payload), DOMOPT_NOOPT, &schemaInfo); if (jis_null(object)) { _LSErrorSet(lserror, MSGID_LS_INVALID_JSON, -1, "Unable to parse JSON: %s", payload); goto exit; } if (!jobject_get_exists(object, J_CSTR_TO_BUF("subscribe"), &subObj) || subObj == NULL || !jis_boolean(subObj)) { subscribePayload = false; /* FIXME: I think retVal should be false, but I don't know if anyone * is relying on this behavior. If set to false, make sure to set * LSError */ retVal = true; } else { (void)jboolean_get(subObj, &subscribePayload);/* TODO: handle appropriately */ retVal = true; } if (subscribePayload) { const char *key = LSMessageGetKind(message); retVal = LSSubscriptionAdd(sh, key, message, lserror); } if (retVal && subscribePayload) { *subscribed = true; } else { *subscribed = false; } exit: j_release(&object); return retVal; }
bool luna_service_message_get_boolean(jvalue_ref parsed_obj, const char *name, bool default_value) { jvalue_ref boolean_obj; bool value; if (!jobject_get_exists(parsed_obj, j_str_to_buffer(name, strlen(name)), &boolean_obj) || !jis_boolean(boolean_obj)) return default_value; jboolean_get(boolean_obj, &value); return value; }
bool JValue::isBoolean() const { return jis_boolean(m_jval); }