static void router_rule_compile (RouterRule *rule, JsonObject *object) { RouterMatch *match; GList *names, *l; JsonNode *node; gint i; g_assert (rule->matches == NULL); names = json_object_get_members (object); rule->matches = g_new0 (RouterMatch, g_list_length (names) + 1); for (l = names, i = 0; l != NULL; l = g_list_next (l), i++) { match = &rule->matches[i]; match->name = g_strdup (l->data); node = json_object_get_member (object, l->data); /* A glob style string pattern */ if (JSON_NODE_HOLDS_VALUE (node) && json_node_get_value_type (node) == G_TYPE_STRING) match->glob = g_pattern_spec_new (json_node_get_string (node)); /* A null matches anything */ if (!JSON_NODE_HOLDS_NULL (node)) match->node = json_node_copy (node); } /* The last match has a null name */ g_list_free (names); }
/** * json_array_get_object_element: * @array: a #JsonArray * @index_: the index of the element to retrieve * * Conveniently retrieves the object from the element at @index_ * inside @array * * See also: json_array_get_element(), json_node_get_object() * * Return value: (transfer none): the object * * Since: 0.8 */ JsonObject * json_array_get_object_element (JsonArray *array, guint index_) { JsonNode *node; g_return_val_if_fail (array != NULL, NULL); g_return_val_if_fail (index_ < array->elements->len, NULL); node = g_ptr_array_index (array->elements, index_); g_return_val_if_fail (node != NULL, NULL); g_return_val_if_fail (JSON_NODE_HOLDS_OBJECT (node) || JSON_NODE_HOLDS_NULL (node), NULL); if (JSON_NODE_HOLDS_NULL (node)) return NULL; return json_node_get_object (node); }
/** * json_array_get_string_element: * @array: a #JsonArray * @index_: the index of the element to retrieve * * Conveniently retrieves the string value of the element at @index_ * inside @array * * See also: json_array_get_element(), json_node_get_string() * * Return value: the string value; the returned string is owned by * the #JsonArray and should not be modified or freed * * Since: 0.8 */ G_CONST_RETURN gchar * json_array_get_string_element (JsonArray *array, guint index_) { JsonNode *node; g_return_val_if_fail (array != NULL, NULL); g_return_val_if_fail (index_ < array->elements->len, NULL); node = g_ptr_array_index (array->elements, index_); g_return_val_if_fail (node != NULL, NULL); g_return_val_if_fail (JSON_NODE_HOLDS_VALUE (node) || JSON_NODE_HOLDS_NULL (node), NULL); if (JSON_NODE_HOLDS_NULL (node)) return NULL; return json_node_get_string (node); }
/** * json_object_get_object_member: * @object: a #JsonObject * @member_name: the name of the member * * Convenience function that retrieves the object * stored in @member_name of @object * * See also: json_object_get_member() * * Return value: (transfer none): the object inside the object's member * * Since: 0.8 */ JsonObject * json_object_get_object_member (JsonObject *object, const gchar *member_name) { JsonNode *node; g_return_val_if_fail (object != NULL, NULL); g_return_val_if_fail (member_name != NULL, NULL); node = object_get_member_internal (object, member_name); g_return_val_if_fail (node != NULL, NULL); g_return_val_if_fail (JSON_NODE_HOLDS_OBJECT (node) || JSON_NODE_HOLDS_NULL (node), NULL); if (JSON_NODE_HOLDS_NULL (node)) return NULL; return json_node_get_object (node); }
/** * json_object_get_string_member: * @object: a #JsonObject * @member_name: the name of the member * * Convenience function that retrieves the string value * stored in @member_name of @object * * See also: json_object_get_member() * * Return value: the string value of the object's member * * Since: 0.8 */ G_CONST_RETURN gchar * json_object_get_string_member (JsonObject *object, const gchar *member_name) { JsonNode *node; g_return_val_if_fail (object != NULL, NULL); g_return_val_if_fail (member_name != NULL, NULL); node = object_get_member_internal (object, member_name); g_return_val_if_fail (node != NULL, NULL); g_return_val_if_fail (JSON_NODE_HOLDS_VALUE (node) || JSON_NODE_HOLDS_NULL (node), NULL); if (JSON_NODE_HOLDS_NULL (node)) return NULL; return json_node_get_string (node); }
/** * json_reader_get_null_value: * @reader: a #JsonReader * * Checks whether the value of the current position of @reader is 'null' * * Return value: %TRUE if 'null' is set, and %FALSE otherwise * * Since: 0.12 */ gboolean json_reader_get_null_value (JsonReader *reader) { g_return_val_if_fail (JSON_IS_READER (reader), FALSE); json_reader_return_val_if_error_set (reader, FALSE); if (reader->priv->current_node == NULL) return FALSE; return JSON_NODE_HOLDS_NULL (reader->priv->current_node); }
/** * json_reader_get_null_value: * @reader: a #JsonReader * * Checks whether the value of the current position of @reader is 'null' * * Return value: %TRUE if 'null' is set, and %FALSE otherwise * * Since: 0.12 */ gboolean json_reader_get_null_value (JsonReader *reader) { g_return_val_if_fail (JSON_IS_READER (reader), FALSE); json_reader_return_val_if_error_set (reader, FALSE); if (reader->priv->current_node == NULL) { json_reader_set_error (reader, JSON_READER_ERROR_INVALID_NODE, _("No node available at the current position")); return FALSE; } return JSON_NODE_HOLDS_NULL (reader->priv->current_node); }
/** * json_object_get_null_member: * @object: a #JsonObject * @member_name: the name of the member * * Convenience function that checks whether the value * stored in @member_name of @object is null * * See also: json_object_get_member() * * Return value: %TRUE if the value is null * * Since: 0.8 */ gboolean json_object_get_null_member (JsonObject *object, const gchar *member_name) { JsonNode *node; g_return_val_if_fail (object != NULL, FALSE); g_return_val_if_fail (member_name != NULL, FALSE); node = object_get_member_internal (object, member_name); g_return_val_if_fail (node != NULL, FALSE); if (JSON_NODE_HOLDS_NULL (node)) return TRUE; if (JSON_NODE_HOLDS_OBJECT (node)) return json_node_get_object (node) == NULL; if (JSON_NODE_HOLDS_ARRAY (node)) return json_node_get_array (node) == NULL; return FALSE; }
/** * json_array_get_null_element: * @array: a #JsonArray * @index_: the index of the element to retrieve * * Conveniently retrieves whether the element at @index_ is set to null * * See also: json_array_get_element(), JSON_NODE_TYPE(), %JSON_NODE_NULL * * Return value: %TRUE if the element is null * * Since: 0.8 */ gboolean json_array_get_null_element (JsonArray *array, guint index_) { JsonNode *node; g_return_val_if_fail (array != NULL, FALSE); g_return_val_if_fail (index_ < array->elements->len, FALSE); node = g_ptr_array_index (array->elements, index_); g_return_val_if_fail (node != NULL, FALSE); if (JSON_NODE_HOLDS_NULL (node)) return TRUE; if (JSON_NODE_HOLDS_ARRAY (node)) return json_node_get_array (node) == NULL; if (JSON_NODE_HOLDS_OBJECT (node)) return json_node_get_object (node) == NULL; return FALSE; }