static inline bool jboolean_to_string_append (jvalue_ref jref, JStreamRef generating) { bool result = (generating->boolean (generating, jboolean_deref(jref)->value) != NULL); if (UNLIKELY(!result)) { PJ_LOG_ERR("Schema validation error, bool did not validate against schema"); } return result; }
static bool inject_default_jbool(void *ctxt, jvalue_ref ref) { JSAXContextRef context = (JSAXContextRef)ctxt; return context->m_handlers->yajl_boolean(context, jboolean_deref(ref)->value); }
static inline bool jsax_parse_inject_internal(JSAXContextRef ctxt, jvalue_ref key, jvalue_ref value) { assert (ctxt != NULL); assert (value != NULL); yajl_callbacks *cbs = ctxt->m_handlers; raw_buffer str; if (key) { str = jstring_get_fast(key); if (UNLIKELY(!cbs->yajl_map_key(ctxt, (const unsigned char *)str.m_str, str.m_len))) return false; } switch (value->m_type) { case JV_OBJECT: { jobject_key_value keyval; if (UNLIKELY(!cbs->yajl_start_map(ctxt))) return false; for (jobject_iter i = jobj_iter_init(value); jobj_iter_is_valid(i); i = jobj_iter_next(i)) { jobj_iter_deref(i, &keyval); if (UNLIKELY(!jsax_parse_inject(ctxt, keyval.key, keyval.value))) return false; } if (UNLIKELY(!cbs->yajl_end_map(ctxt))) return false; break; } case JV_ARRAY: { jvalue_ref item; if (UNLIKELY(!cbs->yajl_start_array(ctxt))) return false; for (ssize_t i = jarray_size(value) - 1; i >= 0; i--) { item = jarray_get(value, i); if (UNLIKELY(!jsax_parse_inject(ctxt, NULL, item))) return false; } if (UNLIKELY(!cbs->yajl_end_array(ctxt))) return false; break; } case JV_STR: { str = jstring_get_fast(value); if (UNLIKELY(!cbs->yajl_string(ctxt, (const unsigned char *)str.m_str, str.m_len))) return false; break; } case JV_NUM: { assert (value->value.val_num.m_type == NUM_RAW); // this numeric string should have come directly from a schema - we don't do any conversion internally. // how did this state occur? CHECK_CONDITION_RETURN_VALUE(value->value.val_num.m_type != NUM_RAW, false, "Some internal problem parsing schema"); str = jnumber_deref_raw(value); if (UNLIKELY(!cbs->yajl_number(ctxt, str.m_str, str.m_len))) return false; break; } case JV_BOOL: { if (UNLIKELY(!cbs->yajl_boolean(ctxt, jboolean_deref(value)))) return false; break; } case JV_NULL: { if (UNLIKELY(!cbs->yajl_null(ctxt))) return false; break; } default: { // how can this occur? - memory corruption? PJ_SCHEMA_ERR("Internal error - schema is corrupt"); return false; } } return true; }