/* Build the RDP server from information in the JSON object */
Server *
rdp_server_new_from_json (JsonObject * object)
{
	RdpServer * server = g_object_new(RDP_SERVER_TYPE, NULL);

	if (json_object_has_member(object, JSON_SERVER_NAME)) {
		JsonNode * node = json_object_get_member(object, JSON_SERVER_NAME);
		if (JSON_NODE_TYPE(node) == JSON_NODE_VALUE && json_node_get_value_type(node) == G_TYPE_STRING) {
			const gchar * name = json_node_get_string(node);
			server->parent.name = g_strdup(name);
		}
	}

	if (json_object_has_member(object, JSON_URI)) {
		JsonNode * node = json_object_get_member(object, JSON_URI);
		if (JSON_NODE_TYPE(node) == JSON_NODE_VALUE && json_node_get_value_type(node) == G_TYPE_STRING) {
			const gchar * uri = json_node_get_string(node);
			server->parent.uri = g_strdup(uri);
		}
	}

	if (json_object_has_member(object, JSON_USERNAME)) {
		JsonNode * node = json_object_get_member(object, JSON_USERNAME);
		if (JSON_NODE_TYPE(node) == JSON_NODE_VALUE && json_node_get_value_type(node) == G_TYPE_STRING) {
			const gchar * username = json_node_get_string(node);
			server->username = g_strdup(username);
		}
	}

	if (json_object_has_member(object, JSON_PASSWORD)) {
		JsonNode * node = json_object_get_member(object, JSON_PASSWORD);
		if (JSON_NODE_TYPE(node) == JSON_NODE_VALUE && json_node_get_value_type(node) == G_TYPE_STRING) {
			const gchar * password = json_node_get_string(node);
			server->password = g_strdup(password);
			mlock(server->password, strlen(server->password));
		}
	}

	if (json_object_has_member(object, JSON_DOMAIN)) {
		JsonNode * node = json_object_get_member(object, JSON_DOMAIN);
		if (JSON_NODE_TYPE(node) == JSON_NODE_VALUE && json_node_get_value_type(node) == G_TYPE_STRING) {
			const gchar * domain = json_node_get_string(node);
			server->domain = g_strdup(domain);
		}
	}

	if (json_object_has_member(object, JSON_DOMAIN_REQ)) {
		JsonNode * node = json_object_get_member(object, JSON_DOMAIN_REQ);
		if (JSON_NODE_TYPE(node) == JSON_NODE_VALUE && json_node_get_value_type(node) == G_TYPE_BOOLEAN) {
			server->domain_required = json_node_get_boolean(node);
		}
	}

	return SERVER(server);
}
void network_checking(void)
{
    int fd;
    
	http_down("/files.json", "http://lab.rt-thread.org/realboard/lpc4088/files.json");
    fd = open("/files.json", O_RDONLY, 0);
    if (fd >= 0)
    {
        int length;
        char *ptr;
        
        length = lseek(fd, 0, SEEK_END);
        if (length > 0)
        {
            lseek(fd, 0, SEEK_SET);
            
            ptr = (char*)rt_malloc(length);
            if (ptr != RT_NULL)
            {
                struct json_tree* tree;
                
                length = read(fd, ptr, length);
                tree = json_tree_parse(ptr, length);
                if (tree != RT_NULL)
                {
                    int index = 0;
                    struct json_node* node;

                    while (1)
                    {
                        const char *url;
                        const char *local_url;
                        
                        node = json_node_get_array(&(tree->root), index, RT_NULL);
                        if (node == RT_NULL) break;
                        index ++;
                        
                        url = json_node_get_string(node, "url", RT_NULL);
                        local_url = json_node_get_string(node, "local_url", RT_NULL);
                        
                        rt_kprintf("%s=>%s\n", local_url, url);
                    }
                    
                    json_tree_destroy(tree);
                }
                
                rt_free(ptr);
            }
        }
        
        close(fd);
    }
}
Пример #3
0
/** 
 * Utility function for turning a json node into a string.
 */
gchar *glib_jsonrpc_json_to_string(JsonNode *node)
{
  // Simplify for string. Should probably be optional.
  if (json_node_get_string (node) != NULL)
    return g_strdup(json_node_get_string (node));

  // Serialize response into content_string
  JsonGenerator *gen = json_generator_new ();
  gsize len;
  json_generator_set_root (gen, node);
  gchar *json_string = json_generator_to_data(gen, &len);
  g_object_unref (gen);
  return json_string;
}
Пример #4
0
static gboolean
clutter_alpha_parse_custom_node (ClutterScriptable *scriptable,
                                 ClutterScript     *script,
                                 GValue            *value,
                                 const gchar       *name,
                                 JsonNode          *node)
{
  if (strncmp (name, "function", 8) == 0)
    {
      const gchar *func_name = json_node_get_string (node);

      g_value_init (value, G_TYPE_POINTER);
      g_value_set_pointer (value, resolve_alpha_func (func_name));

      return TRUE;
    }

  /* we need to do this because we use gulong in place
   * of ClutterAnimationMode for ClutterAlpha:mode
   */
  if (strncmp (name, "mode", 4) == 0)
    {
      gulong mode;

      mode = _clutter_script_resolve_animation_mode (node);

      g_value_init (value, G_TYPE_ULONG);
      g_value_set_ulong (value, mode);

      return TRUE;
    }

  return FALSE;
}
Пример #5
0
static gboolean
parse_emojione_category (JsonNode  *node,
                         EmojiData *data)
{
    const gchar *category;
    GSList *duplicated;

    if (json_node_get_node_type (node) != JSON_NODE_VALUE) {
        g_warning ("'category' element is not string");
        return FALSE;
    }

    category = json_node_get_string (node);

    if (category == NULL || *category == '\0')
        return TRUE;

    duplicated = g_slist_find_custom (data->annotations,
                                      category,
                                      (GCompareFunc) g_strcmp0);
    if (duplicated == NULL) {
        data->annotations = g_slist_prepend (data->annotations,
                                             g_strdup (category));
    }

    return TRUE;
}
Пример #6
0
/**
 * server_new_from_json:
 * @object: JSON object with server definition
 *
 * Looks at the type and then uses a subclassed function to build the
 * server.
 *
 * Return value: A new Server object or NULL if error
 */
Server *
server_new_from_json (JsonObject * object)
{
	g_return_val_if_fail(object != NULL, NULL);

	if (!json_object_has_member(object, "Protocol")) {
		return NULL;
	}

	JsonNode * proto_node = json_object_get_member(object, "Protocol");
	if (JSON_NODE_TYPE(proto_node) != JSON_NODE_VALUE) {
		return NULL;
	}
	if (json_node_get_value_type(proto_node) != G_TYPE_STRING) {
		return NULL;
	}

	const gchar * proto = json_node_get_string(proto_node);
	Server * newserver = NULL;

	if (g_strcmp0(proto, "ICA") == 0 || g_strcmp0(proto, "ica") == 0) {
		newserver = citrix_server_new_from_json(object);
	}
	else if (g_strcmp0(proto, "freerdp") == 0 || g_strcmp0(proto, "rdp") == 0 || g_strcmp0(proto, "RDP") == 0 || g_strcmp0(proto, "FreeRDP") == 0) {
		newserver = rdp_server_new_from_json(object);
	}
	else if (g_strcmp0(proto, "x2go") == 0 || g_strcmp0(proto, "X2go") == 0 || g_strcmp0(proto, "X2Go") == 0 || g_strcmp0(proto, "X2GO") == 0 || g_strcmp0(proto, "x2GO") == 0 || g_strcmp0(proto, "x2gO") == 0) {
		newserver = x2go_server_new_from_json(object);
	}

	return newserver;
}
Пример #7
0
static void
add_alias_to_listing (GHashTable *listing,
                      CockpitPackage *package,
                      JsonNode *node)
{
  const gchar *value;

  if (JSON_NODE_HOLDS_VALUE (node) && json_node_get_value_type (node) == G_TYPE_STRING)
    {
      value = json_node_get_string (node);
      if (validate_package (value))
        {
          g_hash_table_replace (listing, (gchar *)value, cockpit_package_ref (package));
          g_debug ("%s: package has alias: %s", package->name, value);
        }
      else
        {
          g_message ("invalid \"alias\" package name: \"%s\"", value);
        }
    }
  else
    {
      g_message ("invalid \"alias\" value type: \"%s\"", json_node_type_name (node));
    }
}
gboolean
_rpmostree_jsonutil_object_get_optional_string_member (JsonObject     *object,
						       const char     *member_name,
						       const char    **out_value,
						       GError        **error)
{
  gboolean ret = FALSE;
  JsonNode *node = json_object_get_member (object, member_name);

  if (node != NULL)
    {
      *out_value = json_node_get_string (node);
      if (!*out_value)
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Member '%s' is not a string", member_name);
          goto out;
        }
    }
  else
    *out_value = NULL;

  ret = TRUE;
 out:
  return ret;
}
Пример #9
0
/**
 * json_reader_get_string_value:
 * @reader: a #JsonReader
 *
 * Retrieves the string value of the current position of @reader
 *
 * Return value: the string value
 *
 * Since: 0.12
 */
const gchar *
json_reader_get_string_value (JsonReader *reader)
{
  JsonNode *node;

  g_return_val_if_fail (JSON_IS_READER (reader), NULL);
  json_reader_return_val_if_error_set (reader, NULL);

  if (reader->priv->current_node == NULL)
    {
      json_reader_set_error (reader, JSON_READER_ERROR_INVALID_NODE,
                             _("No node available at the current position"));
      return NULL;
    }

  node = reader->priv->current_node;

  if (!JSON_NODE_HOLDS_VALUE (node))
    {
      json_reader_set_error (reader, JSON_READER_ERROR_NO_VALUE,
                             _("The current position holds a '%s' and not a value"),
                             json_node_type_get_name (JSON_NODE_TYPE (node)));
      return NULL;
    }

  if (json_node_get_value_type (node) != G_TYPE_STRING)
    {
      json_reader_set_error (reader, JSON_READER_ERROR_INVALID_TYPE,
                             _("The current position does not hold a string type"));
      return NULL;
    }

  return json_node_get_string (reader->priv->current_node);
}
trg_response *dispatch_str(TrgClient * tc, gchar * req)
{
    trg_response *response = g_new0(trg_response, 1);
    GError *decode_error = NULL;
    JsonNode *result;

    trg_http_perform(tc, req, response);
    g_free(req);

    if (response->status == CURLE_OK)
        response->obj = trg_deserialize(response, &decode_error);

    g_free(response->raw);
    response->raw = NULL;

    if (response->status != CURLE_OK)
        return response;

    if (decode_error) {
        g_error("JSON decoding error: %s", decode_error->message);
        g_error_free(decode_error);
        response->status = FAIL_JSON_DECODE;
        return response;
    }

    result = json_object_get_member(response->obj, FIELD_RESULT);
    if (!result || g_strcmp0(json_node_get_string(result), FIELD_SUCCESS))
        response->status = FAIL_RESPONSE_UNSUCCESSFUL;

    return response;
}
Пример #11
0
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);
}
Пример #12
0
/**
 * json_node_dup_string:
 * @node: a #JsonNode of type %JSON_NODE_VALUE
 *
 * Gets a copy of the string value stored inside a #JsonNode
 *
 * Return value: (transfer full): a newly allocated string containing a copy
 *   of the #JsonNode contents. Use g_free() to free the allocated resources
 */
gchar *
json_node_dup_string (JsonNode *node)
{
  g_return_val_if_fail (JSON_NODE_IS_VALID (node), NULL);

  return g_strdup (json_node_get_string (node));
}
Пример #13
0
/**
 * json_node_dup_string:
 * @node: a #JsonNode of type %JSON_NODE_VALUE
 *
 * Gets a copy of the string value stored inside a #JsonNode
 *
 * Return value: (transfer full): a newly allocated string containing a copy
 *   of the #JsonNode contents. Use g_free() to free the allocated resources
 */
gchar *
json_node_dup_string (JsonNode *node)
{
  g_return_val_if_fail (node != NULL, NULL);

  return g_strdup (json_node_get_string (node));
}
gchar *trg_prefs_get_string(TrgPrefs * p, const gchar * key, int flags)
{
    JsonNode *node = trg_prefs_get_value(p, key, JSON_NODE_VALUE, flags);

    if (node)
        return g_strdup(json_node_get_string(node));
    else
        return NULL;
}
Пример #15
0
void rm_json_cache_parse_entry(_U JsonArray *array, _U guint index,
                               JsonNode *element_node, RmTrie *file_trie) {
    if(JSON_NODE_TYPE(element_node) != JSON_NODE_OBJECT) {
        return;
    }

    JsonObject *object = json_node_get_object(element_node);
    JsonNode *mtime_node = json_object_get_member(object, "mtime");
    JsonNode *path_node = json_object_get_member(object, "path");
    JsonNode *cksum_node = json_object_get_member(object, "checksum");
    JsonNode *type_node = json_object_get_member(object, "type");

    if(mtime_node && path_node && cksum_node && type_node) {
        RmStat stat_buf;
        const char *path = json_node_get_string(path_node);
        const char *cksum = json_node_get_string(cksum_node);
        const char *type = json_node_get_string(type_node);

        if(g_strcmp0(type, "duplicate_file") && g_strcmp0(type, "unfinished_cksum")) {
            /* some other file that has a checksum for weird reasons.
             * This is here to prevent errors like reporting files with
             * empty checksums as duplicates.
             * */
            return;
        }

        if(rm_sys_stat(path, &stat_buf) == -1) {
            /* file does not appear to exist */
            return;
        }

        if(json_node_get_int(mtime_node) < rm_sys_stat_mtime_seconds(&stat_buf)) {
            /* file is newer than stored checksum */
            return;
        }

        char *cksum_copy = g_strdup(cksum);
        if(!rm_trie_set_value(file_trie, path, cksum_copy)) {
            g_free(cksum_copy);
        }
        rm_log_debug_line("* Adding cache entry %s (%s)", path, cksum);
    }
}
Пример #16
0
gint json_node_get_parse_int_member(JsonNode *node, gboolean *success) {
    switch(json_node_get_value_type(node)) {
    case G_TYPE_INT64:
        if(success) *success = TRUE; return json_node_get_int(node);
    case G_TYPE_STRING:
        return flist_parse_int(json_node_get_string(node), success);
    }
    if(success) *success = FALSE;
    return 0;
}
Пример #17
0
static gboolean
parse_emojione_shortname (JsonNode  *node,
                          EmojiData *data)
{
#if 0
    const gchar *shortname;
    gchar *head, *s;
    int length;
    GSList *duplicated;

    if (json_node_get_node_type (node) != JSON_NODE_VALUE) {
        g_warning ("'shortname' element is not string");
        return FALSE;
    }

    /* The format is ':short_name:' */
    shortname = json_node_get_string (node);
    if (shortname == 0 || *shortname == '\0')
        return TRUE;
    if (*shortname != ':') {
        g_warning ("'shortname' format is different: %s", shortname);
        return FALSE;
    }

    length = strlen (shortname);
    head  = g_new0 (gchar, length);
    strcpy (head, shortname + 1);
    for (s = head; *s; s++) {
        if (*s == ':') {
            *s = '\0';
            break;
        } else if (*s == '_') {
            *s = ' ';
        }
    }

    if (head == NULL || *head == '\0') {
        g_warning ("'shortname' format is different: %s", shortname);
        g_free (head);
        return FALSE;
    }

    duplicated = g_slist_find_custom (data->annotations,
                                      head,
                                      (GCompareFunc) g_strcmp0);
    if (duplicated == NULL) {
        data->annotations = g_slist_prepend (data->annotations,
                                             head);
    } else {
       g_free (head);
    }

#endif
    return TRUE;
}
Пример #18
0
void
cockpit_package_dump (void)
{
  GHashTable *listing;
  GHashTable *by_name;
  GHashTableIter iter;
  CockpitPackage *package;
  GList *names, *l;
  const gchar *prefix;
  JsonArray *array;
  guint i;

  listing = cockpit_package_listing (NULL);
  by_name = g_hash_table_new (g_str_hash, g_str_equal);

  g_hash_table_iter_init (&iter, listing);
  while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&package))
    g_hash_table_replace (by_name, package->name, package);

  names = g_hash_table_get_keys (by_name);
  names = g_list_sort (names, (GCompareFunc)strcmp);
  for (l = names; l != NULL; l = g_list_next (l))
    {
      package = g_hash_table_lookup (by_name, l->data);
      g_print ("%s: %s\n", package->name, package->directory);
      if (package->checksum)
        g_print ("    checksum: %s\n", package->checksum);

      if (package->alias)
        {
          prefix = "    alias: ";
          if (JSON_NODE_HOLDS_ARRAY (package->alias))
            {
              array = json_node_get_array (package->alias);
              for (i = 0; i < json_array_get_length (array); i++)
                {
                  g_print ("%s%s\n", prefix, json_array_get_string_element (array, i));
                  prefix = "           ";
                }
            }
          else
            {
              g_print ("%s%s\n", prefix, json_node_get_string (package->alias));
            }
        }
    }

  g_list_free (names);
  g_hash_table_unref (by_name);
  g_hash_table_unref (listing);
}
Пример #19
0
/**
 * json_reader_get_string_value:
 * @reader: a #JsonReader
 *
 * Retrieves the string value of the current position of @reader
 *
 * Return value: the string value
 *
 * Since: 0.12
 */
G_CONST_RETURN gchar *
json_reader_get_string_value (JsonReader *reader)
{
  g_return_val_if_fail (JSON_IS_READER (reader), NULL);
  json_reader_return_val_if_error_set (reader, NULL);

  if (reader->priv->current_node == NULL)
    return NULL;

  if (!JSON_NODE_HOLDS_VALUE (reader->priv->current_node))
    return NULL;

  return json_node_get_string (reader->priv->current_node);
}
Пример #20
0
gui_element_p gui_element_create(gui_element_p parent, json_node_p config) {

    char *name = json_node_get_string(config, ".name");
    char *type = json_node_get_string(config, ".type");

    if (0 == name || 0 == type) {        
        return 0;
    }

    gui_element_p element = (gui_element_p)malloc(sizeof(gui_element_t));
    element->name = name;

    if (strcmp("frame", type) == 0) {
        element = (gui_element_p)malloc(sizeof(gui_element_t));
        gui_element_set_frame(element, config);
    } else if (strcmp("button", type) == 0) {
        element = (gui_element_p)malloc(sizeof(gui_element_t));
        gui_element_set_frame(element, config);
    } else {
        LOGF("Invalid gui element type %s", type);
        return 0;
    }
}
Пример #21
0
gboolean fb_process_friend_lists(FacebookAccount *fba,
		JsonObject *buddy_list)
{
	JsonObject *fl_obj;
	GList *friend_list_ids, *cur;

	purple_debug_info("facebook", "processing friend list data\n");

	if (!json_object_has_member(buddy_list, "flData"))
	{
		purple_debug_info("facebook", "no friend list data\n");
		return FALSE;
	}


	fl_obj = json_node_get_object(json_object_get_member(
			buddy_list, "flData"));
	friend_list_ids = json_object_get_members(fl_obj);
	for (cur = friend_list_ids; cur != NULL; cur = cur->next)
	{
		gchar *id;
		const gchar *name;
		JsonObject *data;

		id = (gchar *) cur->data;
		data = json_node_get_object(json_object_get_member(
				fl_obj, id));
		name = json_node_get_string(json_object_get_member(
				data, "n"));
		if (name) {
			// Either -1 isnt a valid JSON string or JSON-glib does
			// this wrong.  I'm too tired to tell the difference.
			if (g_str_equal(id, "_1")) {
				id = "-1";
			}
			purple_debug_info("facebook",
					"got friend list %s with id %s\n",
					name, id);
			g_hash_table_insert(fba->friend_lists,
					g_strdup(id), g_strdup(name));
			g_hash_table_insert(fba->friend_lists_reverse,
					g_utf8_strdown(name, -1), g_strdup(id));
		}
	}

	g_list_free(friend_list_ids);

	return TRUE;
}
Пример #22
0
/**
 * 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_TYPE (node) == JSON_NODE_VALUE, NULL);

  return json_node_get_string (node);
}
Пример #23
0
const gchar *
json_get_string (JsonNode *node, const gchar *keyName)
{
	JsonObject *obj;
	JsonNode *key;
	
	obj = json_node_get_object (node);
	if (!obj)
		return NULL;
		
	key = json_object_get_member (obj, keyName);
	if (!key)
		return NULL;
	
	return json_node_get_string (key);
}
Пример #24
0
static void
object_to_headers (JsonObject *object,
                   const gchar *header,
                   JsonNode *node,
                   gpointer user_data)
{
  GHashTable *headers = user_data;
  const gchar *value = json_node_get_string (node);

  g_return_if_fail (value != NULL);

  if (g_ascii_strcasecmp (header, "Content-Length") == 0 ||
      g_ascii_strcasecmp (header, "Connection") == 0)
    return;

  g_hash_table_insert (headers, g_strdup (header), g_strdup (value));
}
Пример #25
0
/**
 * 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);
}
static void _iterate_json_object(JsonObject *object,
                          const gchar *member_name,
                          JsonNode *member_node,
                          gpointer user_data)
{
    GHashTable* params = user_data;
    
    if (json_node_get_node_type(member_node) != JSON_NODE_VALUE)
        return;
    if (json_node_get_value_type(member_node) == G_TYPE_STRING)
        g_hash_table_insert(params, 
                            g_strdup(member_name),
                            g_strdup(json_node_get_string(member_node)));
    else if (json_node_get_value_type(member_node) == G_TYPE_INT64)
        g_hash_table_insert(params, 
                            g_strdup(member_name),
                            g_strdup_printf("%"G_GINT64_FORMAT, json_node_get_int(member_node)));
}
Пример #27
0
/**
 * 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
 */
const 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);
}
Пример #28
0
void trg_tree_view_setup_columns(TrgTreeView * tv)
{
    TrgTreeViewPrivate *priv = TRG_TREE_VIEW_GET_PRIVATE(tv);
    JsonObject *props = trg_prefs_get_tree_view_props(tv);
    GList *columns, *widths, *cli, *wli;

    if (!json_object_has_member(props, TRG_PREFS_KEY_TV_COLUMNS)
        || !json_object_has_member(props, TRG_PREFS_KEY_TV_WIDTHS)) {
        GList *li;
        for (li = priv->columns; li; li = g_list_next(li)) {
            trg_column_description *desc =
                (trg_column_description *) li->data;
            if (desc && !(desc->flags & TRG_COLUMN_EXTRA))
                trg_tree_view_add_column(tv, desc, -1);
        }
        return;
    }

    columns =
        json_array_get_elements(json_object_get_array_member
                                (props, TRG_PREFS_KEY_TV_COLUMNS));
    widths =
        json_array_get_elements(json_object_get_array_member
                                (props, TRG_PREFS_KEY_TV_WIDTHS));

    for (cli = columns, wli = widths; cli && wli;
         cli = g_list_next(cli), wli = g_list_next(wli)) {
        trg_column_description *desc = trg_tree_view_find_column(tv,
                                                                 json_node_get_string
                                                                 ((JsonNode
                                                                   *)
                                                                  cli->
                                                                  data));
        if (desc) {
            gint64 width = json_node_get_int((JsonNode *) wli->data);
            trg_tree_view_add_column(tv, desc, width);
        }
    }

    g_list_free(columns);
    g_list_free(widths);
}
Пример #29
0
static int output_json_node_value (JsonNode *node,
				   PRN *prn)
{
    GType type = 0;
    int err = 0;

    if (null_node(node)) {
	gretl_errmsg_set("jsonget: got a null node");
	return E_DATA;
    }

    type = json_node_get_value_type(node);

#if 0
    fprintf(stderr, "jsonget: node type %s\n", g_type_name(type));
#endif    
    
    if (!handled_type(type)) {
	gretl_errmsg_sprintf("jsonget: unhandled object type '%s'", 
			     g_type_name(type));
	err = E_DATA;
    } else if (type == G_TYPE_STRING) {
	const gchar *s = json_node_get_string(node);

	if (s != NULL) {
	    pputs(prn, s);
	} else {
	    err = E_DATA;
	}	
    } else if (type == G_TYPE_DOUBLE) {
	double x = json_node_get_double(node);

	pprintf(prn, "%.15g", x);
    } else {
	gint64 k = json_node_get_int(node);
	double x = (double) k;

	pprintf(prn, "%.15g", x);
    }

    return err;
}
Пример #30
0
static void
debug_print_json_node (char * msg, JsonNode * node)
{
  g_assert (node != NULL);
 
  gchar * buffer;
  if (json_node_get_node_type (node) == JSON_NODE_VALUE)
    {
     buffer = g_strdup ( json_node_get_string (node) ); /* we should check number, boolean too */
    }
  else
   {
     JsonGenerator *gen = json_generator_new();
     json_generator_set_root (gen, node);
     buffer = json_generator_to_data (gen,NULL);
     g_object_unref (gen);
   }
  g_message("%s - Json Node of type %d: %s\n",msg, (gint)json_node_get_node_type (node), buffer);
  g_free (buffer);
}