Exemplo n.º 1
0
static void
twitter_status_build (TwitterStatus *status,
                      JsonNode      *node)
{
  TwitterStatusPrivate *priv = status->priv;
  JsonObject *obj;
  JsonNode *member;

  if (!node || JSON_NODE_TYPE (node) != JSON_NODE_OBJECT)
    return;

  obj = json_node_get_object (node);

  member = json_object_get_member (obj, "user");
  if (member)
    {
      priv->user = twitter_user_new_from_node (member);
      g_object_ref_sink (priv->user);

      priv->user_changed_id = g_signal_connect (priv->user, "changed",
                                                G_CALLBACK (user_changed_cb),
                                                status);
    }

  member = json_object_get_member (obj, "source");
  if (member)
    priv->source = json_node_dup_string (member);

  member = json_object_get_member (obj, "created_at");
  if (member)
    priv->created_at = json_node_dup_string (member);

  member = json_object_get_member (obj, "id");
  if (member)
    priv->id = json_node_get_int (member);

  member = json_object_get_member (obj, "truncated");
  if (member)
    priv->truncated = json_node_get_boolean (member);

  member = json_object_get_member (obj, "text");
  if (member)
    priv->text = json_node_dup_string (member);

  member = json_object_get_member (obj, "in_reply_to_user_id");
  if (member)
    priv->in_reply_to_user_id = json_node_get_int (member);

  member = json_object_get_member (obj, "in_reply_to_status_id");
  if (member)
    priv->in_reply_to_status_id = json_node_get_int (member);
}
Exemplo n.º 2
0
/**
 * json_reader_get_int_value:
 * @reader: a #JsonReader
 *
 * Retrieves the integer value of the current position of @reader
 *
 * Return value: the integer value
 *
 * Since: 0.12
 */
gint64
json_reader_get_int_value (JsonReader *reader)
{
  JsonNode *node;

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

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

  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 0;
    }

  return json_node_get_int (reader->priv->current_node);
}
gboolean
_rpmostree_jsonutil_object_get_optional_int_member (JsonObject     *object,
                                                    const char     *member_name,
                                                    gint64         *out_value,
                                                    gboolean       *found,
                                                    GError        **error)
{
  gboolean ret = FALSE;
  JsonNode *node = json_object_get_member (object, member_name);

  if (node != NULL)
    {
      if (!_jsonutil_node_check_int (node))
        {
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Member '%s' is not an integer", member_name);
          goto out;
        }
      if (found)
        *found = TRUE;
      *out_value = json_node_get_int (node);
    }
  else
    {
      if (found)
        *found = FALSE;
      *out_value = 0;
    }

  ret = TRUE;
 out:
  return ret;
}
Exemplo n.º 4
0
/*!
 * Convert the specified \c JsonNode into a string.
 *
 * \param node \c JsonNode.
 * \return Newly-allocated string on success, else \c NULL.
 */
static gchar *
clr_oci_json_string (JsonNode* node) {
	gchar buffer[NODE_BUF_SIZE];
	GType valueType = json_node_get_value_type(node);

	switch (valueType) {
	case G_TYPE_STRING:
		return json_node_dup_string(node);

	case G_TYPE_DOUBLE:
	case G_TYPE_FLOAT:
		g_snprintf(buffer, NODE_BUF_SIZE, "%f", json_node_get_double(node));
		break;

	case G_TYPE_INT:
	case G_TYPE_INT64:
		g_snprintf(buffer, NODE_BUF_SIZE, "%ld", json_node_get_int(node));
		break;

	case G_TYPE_BOOLEAN:
		if (json_node_get_boolean(node)) {
			g_snprintf(buffer, NODE_BUF_SIZE, "%s", "true");
		} else {
			g_snprintf(buffer, NODE_BUF_SIZE, "%s", "false");
		}
		break;

	default:
		g_snprintf(buffer, NODE_BUF_SIZE, "%s", "Unknown type");
		break;
	}

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

    if (node)
        return json_node_get_int(node);
    else
        return 0;
}
Exemplo n.º 6
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;
}
Exemplo n.º 7
0
/**
 * json_reader_get_int_value:
 * @reader: a #JsonReader
 *
 * Retrieves the integer value of the current position of @reader
 *
 * Return value: the integer value
 *
 * Since: 0.12
 */
gint64
json_reader_get_int_value (JsonReader *reader)
{
  g_return_val_if_fail (JSON_IS_READER (reader), 0);
  json_reader_return_val_if_error_set (reader, 0);

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

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

  return json_node_get_int (reader->priv->current_node);
}
Exemplo n.º 8
0
/**
 * json_array_get_int_element:
 * @array: a #JsonArray
 * @index_: the index of the element to retrieve
 *
 * Conveniently retrieves the integer value of the element at @index_
 * inside @array
 *
 * See also: json_array_get_element(), json_node_get_int()
 *
 * Return value: the integer value
 *
 * Since: 0.8
 */
gint64
json_array_get_int_element (JsonArray *array,
                            guint      index_)
{
  JsonNode *node;

  g_return_val_if_fail (array != NULL, 0);
  g_return_val_if_fail (index_ < array->elements->len, 0);

  node = g_ptr_array_index (array->elements, index_);
  g_return_val_if_fail (node != NULL, 0);
  g_return_val_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE, 0);

  return json_node_get_int (node);
}
Exemplo n.º 9
0
/**
 * json_object_get_int_member:
 * @object: a #JsonObject
 * @member_name: the name of the member
 *
 * Convenience function that retrieves the integer value
 * stored in @member_name of @object
 *
 * See also: json_object_get_member()
 *
 * Return value: the integer value of the object's member
 *
 * Since: 0.8
 */
gint64
json_object_get_int_member (JsonObject  *object,
                            const gchar *member_name)
{
  JsonNode *node;

  g_return_val_if_fail (object != NULL, 0);
  g_return_val_if_fail (member_name != NULL, 0);

  node = object_get_member_internal (object, member_name);
  g_return_val_if_fail (node != NULL, 0);
  g_return_val_if_fail (JSON_NODE_TYPE (node) == JSON_NODE_VALUE, 0);

  return json_node_get_int (node);
}
Exemplo n.º 10
0
gint64
json_get_int (JsonNode *node, const gchar *keyName)
{
	JsonObject *obj;
	JsonNode *key;
	
	obj = json_node_get_object (node);
	if (!obj)
		return 0;
		
	key = json_object_get_member (obj, keyName);
	if (!key)
		return 0;
	
	return json_node_get_int (key);
}
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)));
}
Exemplo n.º 12
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);
    }
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
0
static void parse_message(PurpleConnection *pc, FacebookAccount *fba,
	JsonObject *messageObj, const char* from, const char* to,
	PurpleConversationType type)
{
	gint64 message_time;
	const gchar *message;

	purple_debug_info("facebook", "message from %s to %s\n", from, to);

	message = json_node_get_string(
		json_object_get_member(messageObj, "text"));

	message_time = fb_time_kludge(json_node_get_int(
				json_object_get_member(messageObj, "time")));

	if (type == PURPLE_CONV_TYPE_CHAT)
		fb_conversation_handle_chat(fba, from, to, message_time, message, TRUE);
	else
		fb_conversation_handle_message(fba, from, to, message_time, message, TRUE);			
}
Exemplo n.º 16
0
static gboolean
read_config_file(AppContext *app, GError **err)
{
  JsonNode *root;
  JsonParser *parser;
  parser = json_parser_new ();
  if (!json_parser_load_from_file (parser, app->config_filename, err)) {
    g_object_unref(parser);
    return FALSE;
  }
  root = json_parser_get_root(parser);
  if (JSON_NODE_HOLDS_OBJECT(root)) {
    JsonNode *value_node;
    JsonObject *root_obj = json_node_get_object(root);
    value_node = json_object_get_member(root_obj, "extensionPort");
    if (value_node && JSON_NODE_HOLDS_VALUE(value_node)) {
      app->http_port = json_node_get_int(value_node);
    }
    value_node = json_object_get_member(root_obj, "httpRootPath");
    if (value_node && JSON_NODE_HOLDS_VALUE(value_node)) {
      GFile *base;
      GFile *http_root;
      GFile *config;
      char *path = json_node_dup_string(value_node);
      config = g_file_new_for_path(app->config_filename);
      base = g_file_get_parent(config);
      g_object_unref(config);
      g_free(app->http_root);
      http_root = g_file_resolve_relative_path (base, path);
      g_free(path);
      g_object_unref(base);
      if (http_root) {
	app->http_root = g_file_get_path(http_root);
	g_debug("HTTP root: %s", app->http_root);
	g_object_unref(http_root);
      }
    }
  }
  g_object_unref(parser);
  return TRUE;
}
Exemplo n.º 17
0
Arquivo: util.c Projeto: hean01/castio
void
js_util_pushjsonnode(js_State *state, JsonNode *node)
{
  GType type;

  if (!JSON_NODE_HOLDS_VALUE(node))
  {
    js_pushundefined(state);
    return;
  }

  type = json_node_get_value_type(node);
  if (type == G_TYPE_STRING)
    js_pushstring(state, json_node_get_string(node));
  else if (type == G_TYPE_INT)
    js_pushnumber(state, json_node_get_int(node));
  else if (type == G_TYPE_BOOLEAN)
    js_pushboolean(state, json_node_get_boolean(node));
  else
    js_pushundefined(state);
}
Exemplo n.º 18
0
static void spin_prefs_cb(PurpleUtilFetchUrlData* url_data,
			  gpointer userp,JsonNode* node,
			  const gchar* error_message)
{
  PurpleConnection* gc = (PurpleConnection*) userp;
  JsonNode *prefsok/* ,*diablock */;
  JsonObject *object;
  /* gint diablock_value; */
  PurpleAccount* account;
  SpinData* spin;

  if(!PURPLE_CONNECTION_IS_VALID(gc))
    return;

  spin = (SpinData*) gc->proto_data;
  account = purple_connection_get_account(gc);

  if(!node)
    {
      gchar* err_text = g_strdup_printf(_("Could not receive prefs: %s"),
					error_message);
      purple_connection_error_reason(gc,PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
				     err_text);
      g_free(err_text);
      return;
    }

  if(JSON_NODE_TYPE(node) != JSON_NODE_OBJECT)
    {
      purple_connection_error_reason(gc,PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
				     _("Invalid prefs format received"));
      return;
    }

  object = json_node_get_object(node);
  
  prefsok = json_object_get_member(object,"prefsok");

  if(!prefsok || JSON_NODE_TYPE(prefsok) != JSON_NODE_VALUE
     || !json_node_get_int(prefsok))
    {
      purple_connection_error_reason(gc,PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
				     _("Prefs not OK"));
      return;
    }

  /* diablock = json_object_get_member(object,"diablock"); */
  /* if(!diablock || JSON_NODE_TYPE(diablock) != JSON_NODE_VALUE) */
  /*   { */
  /*     purple_connection_error_reason(gc,PURPLE_CONNECTION_ERROR_NETWORK_ERROR, */
  /* 				     _("Invalid prefs entry received")); */
  /*     return; */
  /*   } */
  
  /* if(json_node_get_value_type(diablock) == G_TYPE_STRING) */
  /*   diablock_value = g_ascii_strtoll(json_node_get_string(diablock),NULL,10); */
  /* else */
  /*   diablock_value = json_node_get_int(diablock); */

  /* switch(diablock_value) */
  /*   { */
  /*   case 0: */
  /*     account->perm_deny = PURPLE_PRIVACY_DENY_USERS; */
  /*     break; */
  /*   case 1: */
  /*     account->perm_deny = PURPLE_PRIVACY_DENY_ALL; */
  /*     break; */
  /*   case 2: */
  /*     account->perm_deny = PURPLE_PRIVACY_ALLOW_BUDDYLIST; */
  /*     break; */
  /*   } */

  spin_connect_add_state(spin,SPIN_STATE_GOT_INITIAL_PREFS);
}
Exemplo n.º 19
0
/* Params utils */
static gboolean
melo_jsonrpc_add_node (JsonNode *node, JsonObject *schema,
                       JsonObject *obj, JsonArray *array)
{
  GType vtype = G_TYPE_INVALID;
  const gchar *s_name;
  const gchar *s_type;
  JsonNodeType type;

  /* Get name and type from schema */
  s_name = json_object_get_string_member (schema, "name");
  s_type = json_object_get_string_member (schema, "type");
  if (!s_name || !s_type)
    return FALSE;

  /* Get type */
  type = json_node_get_node_type (node);
  if (type == JSON_NODE_VALUE)
    vtype = json_node_get_value_type (node);

  /* Check type:
   * We check only first letter of the type string.
   */
  switch (s_type[0]) {
    case 'b':
      /* Boolean: check type */
      if (vtype != G_TYPE_BOOLEAN)
        return FALSE;

      /* Add to object / array */
      if (obj || array) {
        gboolean v;
        v = json_node_get_boolean (node);
        if (obj)
          json_object_set_boolean_member (obj, s_name, v);
        else
          json_array_add_boolean_element (array, v);
        break;
      }
      break;
    case 'i':
      /* Integer: check type */
      if (vtype != G_TYPE_INT64)
        return FALSE;

      /* Add to object / array */
      if (obj || array) {
        gint64 v;
        v = json_node_get_int (node);
        if (obj)
          json_object_set_int_member (obj, s_name, v);
        else
          json_array_add_int_element (array, v);
      }
      break;
    case 'd':
      /* Double: check type */
      if (vtype != G_TYPE_DOUBLE)
        return FALSE;

      /* Add to object / array */
      if (obj || array) {
        gdouble v;
        v = json_node_get_double (node);
        if (obj)
          json_object_set_double_member (obj, s_name, v);
        else
          json_array_add_double_element (array, v);
      }
      break;
    case 's':
      /* String: check type */
      if (vtype != G_TYPE_STRING)
        return FALSE;

      /* Add to object / array */
      if (obj || array) {
        const gchar *v;
        v = json_node_get_string (node);
        if (obj)
          json_object_set_string_member (obj, s_name, v);
        else
          json_array_add_string_element (array, v);
      }
      break;
    case 'o':
      /* Object: check type */
      if (type != JSON_NODE_OBJECT)
        return FALSE;

      /* Add to object / array */
      if (obj || array) {
        JsonObject *v;
        v = json_node_dup_object (node);
        if (obj)
          json_object_set_object_member (obj, s_name, v);
        else
          json_array_add_object_element (array, v);
      }
      break;
    case 'a':
      /* Array: check type */
      if (type != JSON_NODE_ARRAY)
        return FALSE;

      /* Add to object / array */
      if (obj || array) {
        JsonArray *v;
        v = json_node_dup_array (node);
        if (obj)
          json_object_set_array_member (obj, s_name, v);
        else
          json_array_add_array_element (array, v);
      }
      break;
    default:
      return FALSE;
  }
  return TRUE;
}
static gboolean
parse_json (GssAdaptive * adaptive, JsonParser * parser, const char *dir,
    const char *requested_version)
{
  JsonNode *node;
  JsonObject *obj;
  JsonNode *n;
  JsonArray *version_array;
  int version;
  int len;
  int i;

  g_return_val_if_fail (adaptive != NULL, FALSE);
  g_return_val_if_fail (parser != NULL, FALSE);
  g_return_val_if_fail (dir != NULL, FALSE);

  node = json_parser_get_root (parser);
  obj = json_node_get_object (node);

  n = json_object_get_member (obj, "manifest_version");
  version = json_node_get_int (n);
  if (version != 0) {
    GST_ERROR ("bad version %d", version);
    return FALSE;
  }

  n = json_object_get_member (obj, "versions");
  version_array = json_node_get_array (n);
  len = json_array_get_length (version_array);
  for (i = 0; i < len; i++) {
    JsonArray *files_array;
    int files_len;
    const char *version_string;
    int j;

    n = json_array_get_element (version_array, i);
    if (n == NULL)
      return FALSE;
    obj = json_node_get_object (n);
    if (obj == NULL)
      return FALSE;

    n = json_object_get_member (obj, "version");
    if (n == NULL)
      return FALSE;
    version_string = json_node_get_string (n);
    if (version_string == NULL)
      return FALSE;

    if (strcmp (version_string, requested_version) != 0)
      continue;

    n = json_object_get_member (obj, "files");
    if (n == NULL)
      return FALSE;
    files_array = json_node_get_array (n);
    if (files_array == NULL)
      return FALSE;
    files_len = json_array_get_length (files_array);

    if (files_len == 0)
      return FALSE;

    for (j = 0; j < files_len; j++) {
      const char *filename;
      char *full_fn;

      n = json_array_get_element (files_array, j);
      if (n == NULL)
        return FALSE;
      if (json_node_get_node_type (n) == JSON_NODE_OBJECT) {
        obj = json_node_get_object (n);
        if (obj) {
          n = json_object_get_member (obj, "filename");
          if (n == NULL)
            return FALSE;
        }
      }
      filename = json_node_get_string (n);
      if (filename == NULL)
        return FALSE;

      full_fn = g_strdup_printf ("%s/%s", dir, filename);
      load_file (adaptive, full_fn);
      g_free (full_fn);
    }

    return TRUE;
  }
  GST_ERROR ("requested version not found: %s", requested_version);
  return FALSE;
}
Exemplo n.º 21
0
gint64 Settings::getInt(const char* path){
  JsonNode* node = getNode(path);
  gint64 value = json_node_get_int (node);
  json_node_free(node);
  return value;
}
static GValue *getValue(JsonNode *node)
{
    GValue *p = new GValue;
    GValue &ret = *p;

    switch (JSON_NODE_TYPE(node))
    {
    case JSON_NODE_OBJECT:
        {
            JsonObject *node_object;
            node_object = json_node_get_object (node);
            g_assert (node_object != NULL);

            GHashTable *object = g_hash_table_new(g_str_hash, g_str_equal);
            json_object_foreach_member(node_object, parseMembers, object);

            g_value_init(&ret, G_TYPE_HASH_TABLE);
            g_value_set_boxed(&ret, object);
        }
        break;
    case JSON_NODE_ARRAY:
        {
            JsonArray *node_array;
            node_array = json_node_get_array (node);
            g_assert (node_array != NULL);

            GValueArray *array = g_value_array_new(0);
            json_array_foreach_element(node_array, parseElements, array);

            g_value_init(&ret, G_TYPE_VALUE_ARRAY);
            g_value_set_boxed(&ret, array);
        }
        break;
    case JSON_NODE_VALUE:
        {
            switch (json_node_get_value_type(node))
            {
            case G_TYPE_INT64:
                {
                    gint64 val = json_node_get_int(node);
                    g_value_init (&ret, G_TYPE_INT64);
                    g_value_set_int64(&ret, val);
                }
                break;

            case G_TYPE_DOUBLE:
                {
                    double val = json_node_get_double(node);
                    g_value_init (&ret, G_TYPE_INT64);
                    g_value_set_double(&ret, val);
                }
                break;

            case G_TYPE_BOOLEAN:
                {
                    bool val = json_node_get_boolean(node);
                    g_value_init (&ret, G_TYPE_INT64);
                    g_value_set_boolean(&ret, val);
                }
                break;

            case G_TYPE_STRING:
                {
                    const gchar * str = json_node_get_string(node);
                    g_value_init (&ret, G_TYPE_STRING);
                    g_value_set_string(&ret, str);
                }
                break;
            default:
                break;
            }
        }
        break;
    case JSON_NODE_NULL:
        break;
    }
    return &ret;
}
Exemplo n.º 23
0
static void spin_receive_friends_cb(PurpleUtilFetchUrlData* url_data,
				    gpointer userp,
				    JsonNode* node,
				    const gchar* error_message)
{
  PurpleConnection* gc = (PurpleConnection*) userp;
  
  if(!PURPLE_CONNECTION_IS_VALID(gc))
    return;

  if(!node)
    {
      purple_debug_error("spin","friend list error:%s\n",error_message);
      purple_connection_error_reason(gc,PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
				     _("could not receive friend list"));
      return;
    }
  
  SpinData* spin = (SpinData*) gc->proto_data;
  PurpleAccount* account = purple_connection_get_account(gc);
  GHashTable* found_buddies = g_hash_table_new(g_direct_hash,g_direct_equal);
  GSList* account_buddies = purple_find_buddies(account,NULL);
  
  if(!node || JSON_NODE_TYPE(node) != JSON_NODE_ARRAY)
    {
      purple_connection_error_reason
	(gc,PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
	 _("invalid friend list format"));
      goto exit;
    }
  JsonArray* friends = json_node_get_array(node);
  guint i;
  for(i = 0; i < json_array_get_length(friends); ++i)
    {
      node = json_array_get_element(friends,i);
      JsonArray* entry;
      if(JSON_NODE_TYPE(node) != JSON_NODE_ARRAY
	 || json_array_get_length(entry = json_node_get_array(node)) != 7)
	{
	  purple_debug_info("spin","invalid friend list entry\n");
	  continue;
	}

      const gchar* id = json_node_get_string(json_array_get_element(entry,0));
      const gchar* name = json_node_get_string(json_array_get_element(entry,1));
      guint online = json_node_get_int(json_array_get_element(entry,2));
      const gchar* away = json_node_get_string(json_array_get_element(entry,3));
      const gchar* photo =json_node_get_string(json_array_get_element(entry,5));
      purple_debug_info("spin","got friend info: %s %s %i %s %s\n",
			id,name,online,	away,photo);
      if(!name || !away || !photo || !id)
	continue;

      PurpleBuddy* buddy = spin_sync_buddy(spin,account_buddies,id,name,
					   online,away,photo);
      g_hash_table_insert(found_buddies,buddy,(gpointer)0x1);
    }

  GSList* b;
  for(b = account_buddies; b; b = b->next)
    {
      if(!g_hash_table_lookup(found_buddies,b->data))
	{
	  spin_notify_nick_removed
	    (spin,purple_buddy_get_name((PurpleBuddy*) b->data));
	  purple_blist_remove_buddy((PurpleBuddy*)b->data);
	}
    }

  spin_connect_add_state(spin,SPIN_STATE_GOT_INITIAL_FRIEND_LIST);

 exit:
  g_slist_free(account_buddies);
  g_hash_table_destroy(found_buddies);
}
Exemplo n.º 24
0
static void got_new_messages(FacebookAccount *fba, const gchar *data,
		gsize data_len, gpointer userdata)
{
	JsonParser *parser;

	PurpleConnection *pc = userdata;

	purple_debug_misc("facebook", "got new messages:\n%s\n", data);

	/* for (;;);{"t":"msg","c":"p_800753867","ms":[{"type":"msg",
		"msg":{"text":"yes","time":1211176515861,"clientTime":1211176514750,
		"msgID":"367146364"},"from":596176850,"to":800753867,
		"from_name":"Jeremy Lawson","to_name":"Eion Robb",
		"from_first_name":"Jeremy","to_first_name":"Eion"}]} */
	/* for (;;);{"t":"refresh"} */
	/* for (;;);{"t":"msg","c":"p_800753867","ms":[{"type":"msg",
		"msg":{"text":"p**n head","time":1211177326689,"clientTime":1211177325,
		"msgID":"-1992480367"},"from":800753867,"to":596176850,
		"from_name":"Eion Robb","to_name":"Jeremy Lawson",
		"from_first_name":"Eion","to_first_name":"Jeremy"}]} */
	/* for (;;);{"t":"msg","c":"p_800753867","ms":[{"type":"typ","st":1,
		"from":596176850,"to":800753867},{"type":"msg","msg":{"text":"nubile!",
		"time":1211177334019,"clientTime":1211177326690,"msgID":"696260545"},
		"from":596176850,"to":800753867,"from_name":"Jeremy Lawson",
		"to_name":"Eion Robb","from_first_name":"Jeremy","to_first_name":"Eion"},
		{"type":"msg","msg":{"text":"test2","time":1211177336688,
		"clientTime":1211177326691,"msgID":"1527815367"},"from":596176850,
		"to":800753867,"from_name":"Jeremy Lawson","to_name":"Eion Robb",
		"from_first_name":"Jeremy","to_first_name":"Eion"},{"type":"msg",
		"msg":{"text":"ahhhhhhh!","time":1211177344361,"clientTime":1211177326692,
		"msgID":"4028916254"},"from":596176850,"to":800753867,
		"from_name":"Jeremy Lawson","to_name":"Eion Robb",
		"from_first_name":"Jeremy","to_first_name":"Eion"}]} */
	/* for (;;);{"t":"msg","c":"p_800753867","ms":[{"type":"msg",
		"msg":{"text":"2","time":1211178167261,"clientTime":1211178164656,
		"msgID":"3382240259"},"from":596176850,"to":800753867,
		"from_name":"Jeremy Lawson","to_name":"Eion Robb",
		"from_first_name":"Jeremy","to_first_name":"Eion"}]} */
	/* for (;;);{"t":"refresh", "seq":1} */

	parser = fb_get_parser(data, data_len);
	if (!parser)
	{
		/* Sometimes proxies will return incorrect data, so we just shrug 
		 * it off.
		 * TODO: Only do this for proxies.  And when we do it, keep track
		 * of consecutive failures in the case something is actually
		 * wrong with Facebook.  Eventually this condition should cause
		 * failure */
		/* Continue looping, waiting for more messages */
		purple_debug_error("facebook",
				"got data back, but it's not even json\n");
				
		fb_get_new_messages(fba);
		return;
	}

	JsonObject *objnode = fb_get_json_object(parser, NULL);

	if (json_object_has_member(objnode, "t")) {
		const gchar* command = json_node_get_string(json_object_get_member(objnode, "t"));
		if (g_str_equal(command, "refresh")) {
			if (json_object_has_member(objnode, "seq")) {
				fba->message_fetch_sequence = json_node_get_int(
					json_object_get_member(objnode, "seq"));
			}

			/* grab history items for all open conversations */
			GList *conversations = purple_get_conversations();
			while (conversations != NULL) {
				PurpleConversation *conv =
					(PurpleConversation *)conversations->data;
				if (fb_conversation_is_fb(conv)) {
					purple_debug_info("facebook",
						"checking for dropped messages with %s\n",
						conv->name);
					fb_history_fetch(fba, conv->name, FALSE);
				}
				conversations = conversations->next;
			}

			/* refresh means that the channel is invalid */
			fb_reconnect(fba);
			json_parser_free(parser);
			return;
		} else if (g_str_equal(command, "continue")) {
			/* continue means that the server wants us to remake the connection.
 			 * continue the loop and wait for messages. noop. */
		} else if (g_str_equal(command, "msg")) {
			parse_new_messages(pc, fba,
				json_node_get_array(json_object_get_member(objnode, "ms")));
		}
	}
	
	if (json_object_has_member(objnode, "s"))
	{
		gint new_seq = json_node_get_int(json_object_get_member(objnode, "s"));
		fba->message_fetch_sequence = new_seq;
	}

	json_parser_free(parser);

	/* Continue looping, waiting for more messages */
	fb_get_new_messages(fba);
}
Exemplo n.º 25
0
i3ipcCon *i3ipc_con_new(i3ipcCon *parent, JsonObject *data, i3ipcConnection *conn) {
  i3ipcCon *con;
  con = g_object_new(I3IPC_TYPE_CON, NULL);

  g_object_ref(conn);
  con->priv->conn = conn;

  if (!json_object_get_null_member(data, "percent"))
    con->priv->percent = json_object_get_double_member(data, "percent");

  if (!json_object_get_null_member(data, "window"))
    con->priv->window = json_object_get_int_member(data, "window");

  if (json_object_has_member(data, "window_properties")) {
    JsonObject *window_properties = json_object_get_object_member(data, "window_properties");

    if (json_object_has_member(window_properties, "class"))
      con->priv->window_class = g_strdup(json_object_get_string_member(window_properties, "class"));
  }

  if (json_object_has_member(data, "mark")) {
    con->priv->mark = g_strdup(json_object_get_string_member(data, "mark"));
  }

  con->priv->name = g_strdup(json_object_get_string_member(data, "name"));
  con->priv->focused = json_object_get_boolean_member(data, "focused");
  con->priv->fullscreen_mode = json_object_get_boolean_member(data, "fullscreen_mode");
  con->priv->urgent = json_object_get_boolean_member(data, "urgent");
  con->priv->layout = g_strdup(json_object_get_string_member(data, "layout"));
  con->priv->orientation = g_strdup(json_object_get_string_member(data, "orientation"));
  con->priv->current_border_width = json_object_get_int_member(data, "current_border_width");
  con->priv->border = g_strdup(json_object_get_string_member(data, "border"));
  con->priv->id = json_object_get_int_member(data, "id");

  JsonNode *con_type_node = json_object_get_member(data, "type");

  /* XXX: In the development version, the "type" property is a string of the
   * type, but in the current stable version (4.7.2) it is an integer as
   * defined in i3's data header. When the next version comes out, the case
   * where type is a number should be removed. */
  if (json_node_get_value_type(con_type_node) == G_TYPE_STRING) {
    con->priv->type = g_strdup(json_node_get_string(con_type_node));
  } else {
    int con_type_int = (int)json_node_get_int(con_type_node);
    switch (con_type_int)
    {
      case 0:
        con->priv->type = g_strdup("root");
        break;
      case 1:
        con->priv->type = g_strdup("output");
        break;
      case 2:
      case 3:
        con->priv->type = g_strdup("con");
        break;
      case 4:
        con->priv->type = g_strdup("workspace");
        break;
      case 5:
        con->priv->type = g_strdup("dockarea");
        break;
    }
  }

  if (parent) {
    g_object_ref(parent);
    con->priv->parent = parent;
  }

  JsonObject *rect_data = json_object_get_object_member(data, "rect");

  con->priv->rect->x = json_object_get_int_member(rect_data, "x");
  con->priv->rect->y = json_object_get_int_member(rect_data, "y");
  con->priv->rect->width = json_object_get_int_member(rect_data, "width");
  con->priv->rect->height = json_object_get_int_member(rect_data, "height");

  if (json_object_has_member(data, "deco_rect")) {
    JsonObject *deco_rect_data = json_object_get_object_member(data, "deco_rect");

    con->priv->deco_rect->x = json_object_get_int_member(deco_rect_data, "x");
    con->priv->deco_rect->y = json_object_get_int_member(deco_rect_data, "y");
    con->priv->deco_rect->width = json_object_get_int_member(deco_rect_data, "width");
    con->priv->deco_rect->height = json_object_get_int_member(deco_rect_data, "height");
  }

  JsonArray *nodes_array = json_object_get_array_member(data, "nodes");
  json_array_foreach_element(nodes_array, i3ipc_con_initialize_nodes, con);

  JsonArray *floating_nodes_array = json_object_get_array_member(data, "floating_nodes");
  json_array_foreach_element(floating_nodes_array, i3ipc_con_initialize_floating_nodes, con);

  JsonArray *focus_array = json_object_get_array_member(data, "focus");
  guint len = json_array_get_length(focus_array);
  for (int i = 0; i < len; i += 1) {
    con->priv->focus = g_list_append(con->priv->focus, GINT_TO_POINTER(json_array_get_int_element(focus_array, i)));
  }

  return con;
}
Exemplo n.º 26
0
static void
postal_http_handle_v1_users_user_badge (UrlRouter         *router,
                                        SoupServer        *server,
                                        SoupMessage       *message,
                                        const gchar       *path,
                                        GHashTable        *params,
                                        GHashTable        *query,
                                        SoupClientContext *client,
                                        gpointer           user_data)
{
   const gchar *user;
   PostalHttp *http = user_data;
   JsonNode *node = NULL;
   GError *error = NULL;
   guint badge;

   ENTRY;

   g_assert(router);
   g_assert(SOUP_IS_SERVER(server));
   g_assert(SOUP_IS_MESSAGE(message));
   g_assert(path);
   g_assert(params);
   g_assert(g_hash_table_contains(params, "user"));
   g_assert(client);
   g_assert(POSTAL_IS_HTTP(http));

   user = g_hash_table_lookup(params, "user");

   if (message->method == SOUP_METHOD_PUT) {
      if (!(node = postal_http_parse_body(message, &error)) ||
          !JSON_NODE_HOLDS_VALUE(node)) {
         if (!error) {
            error = g_error_new(JSON_PARSER_ERROR,
                                JSON_PARSER_ERROR_UNKNOWN,
                                _("JSON must contain integer."));
         }
         postal_http_reply_error(http, message, error);
         GOTO(cleanup);
      }
      badge = json_node_get_int(node);
      g_object_set_data(G_OBJECT(message), "http", http);
      postal_service_set_user_badge(http->priv->service,
                                    user,
                                    badge,
                                    NULL,
                                    postal_http_set_user_badge_cb,
                                    g_object_ref(message));
      soup_server_pause_message(server, message);
      EXIT;
   }

   soup_message_set_status(message, SOUP_STATUS_METHOD_NOT_ALLOWED);

cleanup:
   g_clear_error(&error);
   if (node) {
      json_node_free(node);
   }

   EXIT;
}
Exemplo n.º 27
0
void
fb_got_facepile(FacebookAccount *fba, const gchar *data, gsize data_len, gpointer user_data)
{
	gchar *group = user_data;
	JsonParser *parser;
	JsonObject *object, *payload, *user_obj;
	JsonArray *facepile;
	PurpleConversation *conv;
	PurpleConvChat *chat;
	gchar *uid;
	guint i;
	PurpleGroup *pgroup;
	
	purple_debug_info("facebook", "got facepile %s\n", data?data:"(null)");
	
	conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, group, fba->account);
	chat = PURPLE_CONV_CHAT(conv);
	
	parser = fb_get_parser(data, data_len);
	
	if (!parser)
	{
		purple_debug_warning("facebook",
			"could not fetch facepile for group %s\n", group);
		g_free(group);
		return;
	}
	
	object = fb_get_json_object(parser, NULL);
	payload = json_node_get_object(
		json_object_get_member(object, "payload"));
	facepile = json_node_get_array(
		json_object_get_member(payload, "facepile_click_info"));
	
	pgroup = purple_find_group(DEFAULT_GROUP_NAME);
	if (!pgroup)
	{
		pgroup = purple_group_new(DEFAULT_GROUP_NAME);
		purple_blist_add_group(pgroup, NULL);
	}

	purple_conv_chat_clear_users(chat);
	uid = g_strdup_printf("%" G_GINT64_FORMAT, fba->uid);
	purple_conv_chat_add_user(chat, uid, NULL, PURPLE_CBFLAGS_NONE, FALSE);
	if (!purple_find_buddy(fba->account, uid))
	{
		PurpleBuddy *buddy = purple_buddy_new(fba->account, uid, "You");
		purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE);
		purple_blist_add_buddy(buddy, NULL, pgroup, NULL);
	}
	g_free(uid);
	
	for (i = 0; i < json_array_get_length(facepile); i++)
	{
		user_obj = json_node_get_object(
			json_array_get_element(facepile, i));
		uid = g_strdup_printf("%" G_GINT64_FORMAT, (gint64)json_node_get_int(json_object_get_member(user_obj, "uid")));
		
		purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv), uid, NULL, PURPLE_CBFLAGS_NONE, FALSE);
		
		if (!purple_find_buddy(fba->account, uid))
		{
			const char *alias = json_node_get_string(json_object_get_member(user_obj, "name"));
			PurpleBuddy *buddy = purple_buddy_new(fba->account, uid, alias);
			purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE);
			purple_blist_add_buddy(buddy, NULL, pgroup, NULL);
		}
		
		g_free(uid);
	}
	
	g_free(group);
}
Exemplo n.º 28
0
void got_reconnect_json(FacebookAccount *fba, const gchar *data, gsize data_len, gpointer userdata)
{
	JsonParser *parser;
	JsonObject *objnode;
	gchar *error_message;

	parser = fb_get_parser(data, data_len);

	if (!parser) {
		purple_debug_error("facebook", "couldn't parse reconnect data\n");
		purple_debug_info("facebook", "page content: %s\n", data);
		purple_connection_error_reason(fba->pc,
				PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
				_("Chat service currently unavailable"));
		return;
	}

	objnode = fb_get_json_object(parser, &error_message);
	
	if (error_message != NULL)
	{
		if (json_node_get_int(json_object_get_member(objnode, "error")) == 1356007)
		{
			//There'll normally be an error message if chat is down for maintenance
			purple_connection_error_reason(fba->pc,
				PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE,
				error_message);
			g_free(error_message);
			json_parser_free(parser);
			return;
		}
	}

	JsonObject *payload = json_node_get_object(json_object_get_member(objnode, "payload"));
	
	/* eg {"host":"channel01"} */
	const gchar *new_channel_host = json_node_get_string(json_object_get_member(payload, "host"));

	if (new_channel_host == NULL)
	{
		purple_debug_error("facebook", "couldn't find new channel number\n");
		purple_debug_info("facebook", "page content: %s\n", data);
		purple_connection_error_reason(fba->pc,
				PURPLE_CONNECTION_ERROR_NETWORK_ERROR,
				_("Error fetching channel; did you log in elsewhere?"));
		json_parser_free(parser);
		return;
	}
	
	g_free(fba->channel_number);
	fba->channel_number = g_strdup(new_channel_host);
	
	gint new_seq = json_node_get_int(json_object_get_member(payload, "seq"));
	fba->message_fetch_sequence = new_seq;
	
	/*
	 * Now that we have a channel number we can start looping and
	 * waiting for messages
	 */
	fb_get_new_messages(fba);
	json_parser_free(parser);
}
Exemplo n.º 29
0
/**
 * json_node_equal:
 * @a: (type JsonNode): a JSON node
 * @b: (type JsonNode): another JSON node
 *
 * Check whether @a and @b are equal #JsonNodes, meaning they have the same
 * type and same values (checked recursively). Note that integer values are
 * compared numerically, ignoring type, so a double value 4.0 is equal to the
 * integer value 4.
 *
 * Returns: %TRUE if @a and @b are equal; %FALSE otherwise
 * Since: 1.2
 */
gboolean
json_node_equal (gconstpointer  a,
                 gconstpointer  b)
{
  JsonNode *node_a, *node_b;  /* unowned */

  node_a = (JsonNode *) a;
  node_b = (JsonNode *) b;

  /* Identity comparison. */
  if (node_a == node_b)
    return TRUE;

  /* Eliminate mismatched types rapidly. */
  if (!json_type_is_a (node_a, node_b) &&
      !json_type_is_a (node_b, node_a))
    {
      return FALSE;
    }

  switch (node_a->type)
    {
    case JSON_NODE_NULL:
      /* Types match already. */
      return TRUE;
    case JSON_NODE_ARRAY:
      return json_array_equal (json_node_get_array (node_a),
                               json_node_get_array (node_b));
    case JSON_NODE_OBJECT:
      return json_object_equal (json_node_get_object (node_a),
                                json_node_get_object (node_b));
    case JSON_NODE_VALUE:
      /* Handled below. */
      break;
    default:
      g_assert_not_reached ();
    }

  /* Handle values. */
  switch (node_a->data.value->type)
    {
    case JSON_VALUE_NULL:
      /* Types already match. */
      return TRUE;
    case JSON_VALUE_BOOLEAN:
      return (json_node_get_boolean (node_a) == json_node_get_boolean (node_b));
    case JSON_VALUE_STRING:
      return json_string_equal (json_node_get_string (node_a),
                                json_node_get_string (node_b));
    case JSON_VALUE_DOUBLE:
    case JSON_VALUE_INT: {
      gdouble val_a, val_b;
      JsonValueType value_type_a, value_type_b;

      value_type_a = node_a->data.value->type;
      value_type_b = node_b->data.value->type;

      /* Integer comparison doesn’t need to involve doubles… */
      if (value_type_a == JSON_VALUE_INT &&
          value_type_b == JSON_VALUE_INT)
        {
          return (json_node_get_int (node_a) ==
                  json_node_get_int (node_b));
        }

      /* …but everything else does. We can use bitwise double equality here,
       * since we’re not doing any calculations which could introduce floating
       * point error. We expect that the doubles in the JSON nodes come directly
       * from strtod() or similar, so should be bitwise equal for equal string
       * representations.
       *
       * Interesting background reading:
       * http://randomascii.wordpress.com/2012/06/26/\
       *   doubles-are-not-floats-so-dont-compare-them/
       */
      if (value_type_a == JSON_VALUE_INT)
        val_a = json_node_get_int (node_a);
      else
        val_a = json_node_get_double (node_a);

      if (value_type_b == JSON_VALUE_INT)
        val_b = json_node_get_int (node_b);
      else
        val_b = json_node_get_double (node_b);

      return (val_a == val_b);
    }
    case JSON_VALUE_INVALID:
    default:
      g_assert_not_reached ();
    }
}
Exemplo n.º 30
0
static void parse_new_messages(PurpleConnection *pc, FacebookAccount *fba, JsonArray *messages)
{
	int i;
	PurpleBuddy *buddy;

	purple_debug_info("facebook", "parsing new messages\n");

	for (i = 0; i < json_array_get_length(messages); i++) {
		const gchar *type;
		gchar *from, *to;
		

		JsonObject *object = json_node_get_object(json_array_get_element(messages, i));
		type = json_node_get_string(json_object_get_member(object, "type"));

		from = g_strdup_printf("%" G_GINT64_FORMAT, (gint64)json_node_get_int(json_object_get_member(object, "from")));
		to = g_strdup_printf("%" G_GINT64_FORMAT, (gint64)json_node_get_int(json_object_get_member(object, "to")));
		
		/* Use the in-line buddy name if the buddy list hasn't been downloaded yet */
		buddy = purple_find_buddy(pc->account, from);
		if (buddy == NULL || buddy->server_alias == NULL || buddy->alias == NULL)
		{
			if (json_object_has_member(object, "from_name"))
			{
				const gchar *from_name = json_node_get_string(json_object_get_member(
					object, "from_name"));
				fb_blist_set_alias(fba, from, from_name);
			}
		}

		if (from && to && g_str_equal(type, "msg")) {
			JsonObject *messageObj = json_node_get_object(json_object_get_member(object, "msg"));
			parse_message(pc, fba, messageObj, from, to, PURPLE_CONV_TYPE_IM);
		} else if (from && g_str_equal(type, "typ")) {
			purple_debug_info("facebook", "handling typing notification\n");

			gint typing = json_node_get_int(json_object_get_member(object, "st"));
			if (typing == 0) {
				serv_got_typing(pc, from, 10, PURPLE_NOT_TYPING);
			} else {
				serv_got_typing(pc, from, 10, PURPLE_TYPING);
			}
		} else if (g_str_equal(type, "group_msg")) {
			PurpleConversation *conv = fb_find_chat(fba, to);
			
			if (conv != NULL)
			{			
				if (json_object_has_member(object, "to_name"))
				{
					const gchar *to_name = json_node_get_string(json_object_get_member(
						object, "to_name"));
					purple_conversation_set_title(conv, to_name);

					PurpleChat *chat = purple_blist_find_chat(fba->account, to);
					purple_blist_alias_chat(chat, to_name);
				}
				if (!purple_conv_chat_cb_find(PURPLE_CONV_CHAT(conv), from))
				{
					purple_conv_chat_add_user(PURPLE_CONV_CHAT(conv), from, NULL, PURPLE_CBFLAGS_NONE, FALSE);
				}
				if (!purple_find_buddy(fba->account, from))
				{
					const char *from_name = json_node_get_string(json_object_get_member(
						object, "from_name"));
					buddy = purple_buddy_new(fba->account, from, from_name);
					purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE);
					purple_blist_add_buddy(buddy, NULL, purple_find_group(DEFAULT_GROUP_NAME), NULL);
				}
			}

			JsonObject *messageObj = json_node_get_object(json_object_get_member(object, "msg"));
			parse_message(pc, fba, messageObj, from, to, PURPLE_CONV_TYPE_CHAT);
		}

		/*
		 * we've received something from a buddy, assume they're online
		 * only if it's not from ourselves
		 */
		if (from && fba->uid != atoll(from)) {
			purple_prpl_got_user_status(
				fba->account, from, 
				purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);

		}
	
		g_free(from);
		g_free(to);

		fba->message_fetch_sequence++;
	}
}