static JsonObject *trg_prefs_get_tree_view_props(TrgTreeView * tv)
{
    TrgTreeViewPrivate *priv = TRG_TREE_VIEW_GET_PRIVATE(tv);
    JsonObject *root = trg_prefs_get_root(priv->prefs);
    const gchar *className = priv->configId
        && strlen(priv->configId) >
        0 ? priv->configId : G_OBJECT_TYPE_NAME(tv);
    JsonObject *obj;
    JsonObject *tvProps = NULL;

    if (!json_object_has_member(root, TRG_PREFS_KEY_TREE_VIEWS)) {
        obj = json_object_new();
        json_object_set_object_member(root, TRG_PREFS_KEY_TREE_VIEWS, obj);
    } else {
        obj =
            json_object_get_object_member(root, TRG_PREFS_KEY_TREE_VIEWS);
    }

    if (!json_object_has_member(obj, className)) {
        tvProps = json_object_new();
        json_object_set_object_member(obj, className, tvProps);
    } else {
        tvProps = json_object_get_object_member(obj, className);
    }

    return tvProps;
}
Exemplo n.º 2
0
Arquivo: json.c Projeto: GNOME/gegl
static guint
install_properties(JsonOpClass *json_op_class)
{
    GObjectClass *object_class = G_OBJECT_CLASS (json_op_class);
    JsonObject *root = json_op_class->json_root;
    guint prop = 1;

    // Exported ports
    if (json_object_has_member(root, "inports")) {
        JsonObject *inports = json_object_get_object_member(root, "inports");
        GList *inport_names = json_object_get_members(inports);
        GList *l;
        for (l = inport_names; l != NULL; l = l->next) {
            const gchar *name = l->data;
            JsonObject *conn = json_object_get_object_member(inports, name);
            const gchar *proc = json_object_get_string_member(conn, "process");
            const gchar *port = json_object_get_string_member(conn, "port");
            JsonObject *processes = json_object_get_object_member(root, "processes");
            JsonObject *p = json_object_get_object_member(processes, proc);
            const gchar *component = json_object_get_string_member(p, "component");

            {
              GParamSpec *target_spec = NULL;
              gchar *opname = component2geglop(component);
              // HACK: should avoid instantiating node to determine prop
              GeglNode *n = gegl_node_new();
              g_assert(n);
              gegl_node_set(n, "operation", opname, NULL);
              target_spec = gegl_node_find_property(n, port);
              if (target_spec) {
                GParamSpec *spec = copy_param_spec(target_spec, name);
                PropertyTarget *t = property_target_new(g_strdup(proc), g_strdup(port));
                g_hash_table_insert(json_op_class->properties, GINT_TO_POINTER(prop), t);
                g_object_class_install_property (object_class, prop, spec);
                prop++;
              }
              g_object_unref(n);
              g_free(opname);
            }
        }

        g_list_free(inport_names);
    }

/*
    if (json_object_has_member(root, "outports")) {
        JsonObject *outports = json_object_get_object_member(root, "outports");
        GList *outport_names = json_object_get_members(outports);
        for (int i=0; i<g_list_length(outport_names); i++) {
            const gchar *name = g_list_nth_data(outport_names, i);
            JsonObject *conn = json_object_get_object_member(outports, name);
            const gchar *proc = json_object_get_string_member(conn, "process");
            const gchar *port = json_object_get_string_member(conn, "port");
            graph_add_port(self, GraphOutPort, name, proc, port);
        }
    }
*/
  return prop-1;
}
Exemplo n.º 3
0
void
cb_mini_tweet_parse (CbMiniTweet *t,
                     JsonObject  *obj)
{
  GDateTime *time;
  JsonObject *extended_object;
  const char *tweet_text;

  if (json_object_has_member (obj, "extended_tweet"))
    extended_object = json_object_get_object_member (obj, "extended_tweet");
  else
    extended_object = obj;

  time = cb_utils_parse_date (json_object_get_string_member (obj, "created_at"));

  t->id = json_object_get_int_member (obj, "id");
  if (json_object_has_member (extended_object, "full_text"))
    tweet_text = json_object_get_string_member (extended_object, "full_text");
  else
    tweet_text = json_object_get_string_member (extended_object, "text");

  if (json_object_has_member (extended_object, "display_text_range"))
    {
      /* We only remove the prefix */
      guint start = (guint)json_array_get_int_element (
                          json_object_get_array_member (extended_object, "display_text_range"),
                          0);
      guint i;
      const char *p = tweet_text;

      /* Skip ahead */
      for (i = 0; i < start; i ++)
        p = g_utf8_next_char (p);

      t->text = g_strdup (p);
      t->display_range_start = start;
    }
  else
    {
      t->text = g_strdup (tweet_text);
      t->display_range_start= 0;
    }

  t->created_at = g_date_time_to_unix (time);
  cb_user_identity_parse (&t->author, json_object_get_object_member (obj, "user"));

  g_date_time_unref (time);
}
Exemplo n.º 4
0
Arquivo: ui.c Projeto: imgflo/imgflo
static void
on_web_socket_message(SoupWebsocketConnection *ws,
                      SoupWebsocketDataType type,
                      GBytes *message,
                      void *user_data)
{
	const gchar *data;
	gsize len;

	data = g_bytes_get_data (message, &len);
	imgflo_debug("RECV: %.*s\n", (int)len, data);

    JsonParser *parser = json_parser_new();
    gboolean success = json_parser_load_from_data(parser, data, len, NULL);
    if (success) {
        JsonNode *r = json_parser_get_root(parser);
        g_assert(JSON_NODE_HOLDS_OBJECT(r));
        JsonObject *root = json_node_get_object(r);

        const gchar *protocol = json_object_get_string_member(root, "protocol");
        const gchar *command = json_object_get_string_member(root, "command");

        JsonNode *pnode = json_object_get_member(root, "payload");
        JsonObject *payload = JSON_NODE_HOLDS_OBJECT(pnode) ? json_object_get_object_member(root, "payload") : NULL;

        UiConnection *ui = (UiConnection *)user_data;
        ui_connection_handle_message(ui, protocol, command, payload, ws);

    } else {
        imgflo_warning("Unable to parse WebSocket message as JSON");
    }

    g_object_unref(parser);
}
Exemplo n.º 5
0
// FIXME: check for memory leaks
void Network::writeJSON(JSONcontext* ctx,const char* file){
   GError *error;
   JsonGenerator* gen=json_generator_new ();
   json_generator_set_root(gen,ctx->root);
   JsonArray* jnodes=json_object_get_array_member(json_node_get_object (ctx->root),"nodes");
   
   int i;
   int n=nodes->size();
   
   for(i=0;i<n;i++){ // add x,y position to json object
      JsonObject *node=json_array_get_object_element(jnodes,(*(ctx->nodeidx))[i]); //get corresponding json node using nodeidx
      JsonObject *data=json_object_get_object_member(node,"data");
      json_object_set_double_member(data,"x",(*nodes)[i].pts.x);
      json_object_set_double_member(data,"y",(*nodes)[i].pts.y);
   }
   
   json_generator_to_file(gen,file,&error);
   if (error)
   {
      g_print ("Unable to write `%s': %s\n", file, error->message);
      g_error_free (error);
      abort();
   }
   
}
Exemplo n.º 6
0
static JsonObject *gphoto_parse_response(dt_gphoto_context_t *ctx, GString *response)
{
  GError *error = NULL;
  gboolean ret = json_parser_load_from_data(ctx->json_parser, response->str, response->len, &error);

  if(ret)
  {
    JsonNode *root = json_parser_get_root(ctx->json_parser);
    // we should always have a dict
    g_return_val_if_fail((json_node_get_node_type(root) == JSON_NODE_OBJECT), NULL);

    JsonObject *rootdict = json_node_get_object(root);
    if(json_object_has_member(rootdict, "error"))
    {
      JsonObject *errorstruct = json_object_get_object_member(rootdict, "error");
      g_return_val_if_fail((errorstruct != NULL), NULL);
      const gchar *errormessage = json_object_get_string_member(errorstruct, "message");
      g_return_val_if_fail((errormessage != NULL), NULL);
      g_string_assign(ctx->errmsg, errormessage);
      return NULL;
    }

    return rootdict;
  }
  else // not a json response, can be the upload-token
  {
    ctx->response = g_string_new(response->str);
    return NULL;
  }
}
Exemplo n.º 7
0
static void
pb_process_frame(PushBulletAccount *pba, const gchar *frame)
{
	JsonParser *parser = json_parser_new();
	JsonNode *root;
	
	purple_debug_info("pushbullet", "got frame data: %s\n", frame);
	
	if (!json_parser_load_from_data(parser, frame, -1, NULL))
	{
		purple_debug_error("pushbullet", "Error parsing response: %s\n", frame);
		return;
	}
	
	root = json_parser_get_root(parser);
	
	if (root != NULL) {
		JsonObject *message = json_node_get_object(root);
		const gchar *type = json_object_get_string_member(message, "type");
		if (purple_strequal(type, "tickle")) {
			pb_get_everything_since(pba, purple_account_get_int(pba->account, "last_message_timestamp", 0));
		} else if (purple_strequal(type, "push")) {
			JsonObject *push = json_object_get_object_member(message, "push");
			//{"type":"push","targets":["stream","android","ios"],"push":{"guid":"purple6e94d282","type":"messaging_extension_reply","package_name":"com.pushbullet.android","target_device_iden":"uffvytgsjAoIRwhIL6","conversation_iden":"+6421478252","message":"test2"}}
			//{"type":"push","targets":["stream"],"push":{"type":"sms_changed"}}
			type = json_object_get_string_member(push, "type");
			if (purple_strequal(type, "sms_changed")) {
				pb_get_phone_threads(pba, NULL);
			}
		}
	}
	
	g_object_unref(parser);
}
Exemplo n.º 8
0
static void
progress_cb (JsonObject *result, gpointer user_data)
{
	GsApp *app = user_data;
	JsonArray *tasks;
	GList *task_list, *l;
	gint64 done = 0, total = 0;

	tasks = json_object_get_array_member (result, "tasks");
	task_list = json_array_get_elements (tasks);

	for (l = task_list; l != NULL; l = l->next) {
		JsonObject *task, *progress;
		gint64 task_done, task_total;

		task = json_node_get_object (l->data);
		progress = json_object_get_object_member (task, "progress");
		task_done = json_object_get_int_member (progress, "done");
		task_total = json_object_get_int_member (progress, "total");

		done += task_done;
		total += task_total;
	}

	gs_app_set_progress (app, (guint) (100 * done / total));

	g_list_free (task_list);
}
Exemplo n.º 9
0
/**
 * Returns a cometd_advice pointer that should be free'd by the caller.
 * Returns NULL if advice cannot be found.
 *
 * See also: http://svn.cometd.com/trunk/bayeux/bayeux.html#toc_32
 */
cometd_advice*
cometd_msg_advice(JsonNode* node)
{
    g_return_val_if_fail(JSON_NODE_HOLDS_OBJECT (node), NULL);

    JsonObject* obj = json_node_get_object(node);
    cometd_advice* advice = NULL;
    JsonObject* advice_obj = NULL;

    if (json_object_has_member(obj, COMETD_MSG_ADVICE_FIELD))
        advice_obj = json_object_get_object_member(obj, COMETD_MSG_ADVICE_FIELD);

    if (!advice_obj)
        return NULL;

    const char* reconnect = json_object_get_string_member(advice_obj,
                            "reconnect");
    const guint64 interval = json_object_get_int_member(advice_obj, "interval");

    if (reconnect || interval)
    {
        advice = cometd_advice_new();
        advice->interval = interval;

        if (strcmp("none", reconnect) == 0) {
            advice->reconnect = COMETD_RECONNECT_NONE;
        } else if (strcmp("handshake", reconnect) == 0) {
            advice->reconnect = COMETD_RECONNECT_HANDSHAKE;
        } else if (strcmp("retry", reconnect) == 0) {
            advice->reconnect = COMETD_RECONNECT_RETRY;
        }
    }

    return advice;
}
Exemplo n.º 10
0
END_TEST

START_TEST (test_cometd_new_publish_message)
{
    cometd_conn_set_client_id(g_instance->conn, "testid");
    const char* expected_channel = "/baz/bar";
    JsonNode* node = cometd_json_str2node("{ \"hey\": \"now\" }");
    JsonNode* message = cometd_new_publish_message(g_instance,
                        expected_channel,
                        node);

    JsonObject* obj = json_node_get_object(message);

    const gchar* actual_channel = json_object_get_string_member(obj,
                                  COMETD_MSG_CHANNEL_FIELD);

    ck_assert_str_eq(expected_channel, actual_channel);

    JsonObject* data = json_object_get_object_member(obj,
                       COMETD_MSG_DATA_FIELD);

    const char* value = json_object_get_string_member(data, "hey");
    ck_assert_str_eq("now", value);

    json_node_free(message);
    json_node_free(node);
}
Exemplo n.º 11
0
void
snarf_alert_add_tags(snarf_alert_t *alert, char *tags)
{
    gchar **taglist  = NULL;
    char  **p        = NULL;
    int     tagcount = 0;
    char   *tag      = NULL;

    JsonObject * rootobj = json_node_get_object (alert->msg);
    JsonObject * envelopeobj = json_object_get_object_member(rootobj,"envelope");

    JsonArray *analysis_tags=json_array_new();

    taglist = g_strsplit_set(tags, ", \t\n\v\f\r", 0);
    for (p = taglist, tagcount = 0; p && *p; p++)
    {
	tag=*p;
	if (!strlen(tag))
	{
	    continue;
	}
 	json_array_add_string_element(analysis_tags,tag);
    }

    json_object_set_array_member(envelopeobj,"analysis_tags",analysis_tags);

}
Exemplo n.º 12
0
static gboolean
ipcam_event_input_msg_handler_update_param(IpcamEventInputMsgHandler *handler, const gchar *name, JsonObject *value_obj)
{
    IpcamIConfig *iconfig;
    g_object_get(G_OBJECT(handler), "app", &iconfig, NULL);
    GList *members, *item;
    Schedules *sche = g_new(Schedules, 1);
    GVariant *value = NULL;
    gboolean ret = FALSE;

    members = json_object_get_members(value_obj);
    for (item = g_list_first(members); item; item = g_list_next(item))
    {
        const gchar *sub_name = item->data;
        if (g_str_equal(sub_name, "enable"))
        {
            value = g_variant_new_boolean(json_object_get_boolean_member(value_obj, sub_name));
        }
        else if (g_str_equal(sub_name, "schedules"))
        {
            gint i = 0;
            JsonObject *sub_obj = json_object_get_object_member(value_obj, sub_name);
            for (i = ENUM_MON; i < ENUM_WEEKDAY_LAST; i++)
            {
                if (json_object_has_member(sub_obj, weekday_name[i]))
                {
                    sche->schedule[i] = (gchar *)json_object_get_string_member(sub_obj, weekday_name[i]);
                }
                else
                {
                    sche->schedule[i] = g_malloc0(1);
                }
            }
            if (IS_64BIT_MACHINE)
            {
                value = g_variant_new_uint64(GPOINTER_TO_SIZE(sche));
            }
            else
            {
                value = g_variant_new_uint32(GPOINTER_TO_SIZE(sche));
            }
        }
        else
        {
            g_warn_if_reached();
        }

        if (value)
        {
            ret = ipcam_iconfig_update(iconfig, IPCAM_EVENT_INPUT_TYPE, name, sub_name, value);
            g_variant_unref(value);
            value = NULL;
        }
    }
    g_free(sche);
    g_list_free(members);

    return ret;
}
Exemplo n.º 13
0
static gboolean flist_process_profile(FListAccount *fla, JsonObject *root) {
    FListProfiles *flp = _flist_profiles(fla);
    JsonObject *info;
    GList *categories, *cur;
    GHashTable *profile;
    const gchar *error;

    error = json_object_get_string_member(root, "error");
    if(error && strlen(error) > 0) {
        purple_debug_info(FLIST_DEBUG, "We requested a profile from the Web API, but it returned an error. Error Message: %s\n", error);
        return FALSE; //user probably opted out of API access
    }

    profile = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
    info = json_object_get_object_member(root, "info");
    categories = json_object_get_members(info);

    cur = categories;
    while(cur) {
        JsonObject *field_group;
        JsonArray *field_array;
        guint i, len;

        field_group = json_object_get_object_member(info, cur->data);
        field_array = json_object_get_array_member(field_group, "items");

        len = json_array_get_length(field_array);
        for(i = 0; i < len; i++) {
            JsonObject *field_object = json_array_get_object_element(field_array, i);
            const gchar *field_name = json_object_get_string_member(field_object, "name");
            gchar *unescaped = flist_html_unescape_utf8(json_object_get_string_member(field_object, "value"));
            gchar *field_value = purple_markup_escape_text(unescaped, strlen(unescaped));
            g_hash_table_insert(profile, (gpointer) field_name, (gpointer) field_value);
            g_free(unescaped);
        }

        cur = cur->next;
    }
    g_list_free(categories);

    flist_show_profile(fla->pc, flp->character, profile, FALSE, flp->profile_info);

    g_hash_table_destroy(profile);

    return TRUE;
}
Exemplo n.º 14
0
static void
pb_got_phone_threads(PushBulletAccount *pba, JsonNode *node, gpointer user_data)
{
	PurpleAccount *account = pba->account;
	JsonObject *rootobj = json_node_get_object(node);
	JsonObject *data = json_object_get_object_member(rootobj, "data");
	JsonArray *threads = json_object_get_array_member(data, "threads");
	gint i;
	guint len;
	gchar *device = user_data;
	gint last_message_timestamp = purple_account_get_int(account, "last_message_timestamp", 0);
	gint newest_phone_message_id = purple_account_get_int(account, "newest_phone_message_id", 0);
	
	for(i = 0, len = json_array_get_length(threads); i < len; i++)
	{
		JsonObject *thread = json_array_get_object_element(threads, i);
		const gchar *id = json_object_get_string_member(thread, "id");
		JsonArray *recipients = json_object_get_array_member(thread, "recipients");
		const gchar *from = NULL;
		
		if (json_array_get_length(recipients) > 0) {
			JsonObject *first_recipient = json_array_get_object_element(recipients, 0);
			from = json_object_get_string_member(first_recipient, "number");
			
			if (json_object_has_member(first_recipient, "thumbnail")) {
				pb_set_base64_icon_for_buddy(json_object_get_string_member(first_recipient, "thumbnail"), purple_find_buddy(account, from));
			}
		}
		if (from == NULL) {
			continue;
		}
		if (json_object_has_member(thread, "latest"))
		{
			JsonObject *latest = json_object_get_object_member(thread, "latest");
			gint64 timestamp = json_object_get_int_member(latest, "timestamp");
			gint msgid = atoi(json_object_get_string_member(latest, "id"));
			
			if (timestamp > last_message_timestamp || msgid > newest_phone_message_id) {
				pb_get_phone_thread_by_id(pba, device, id, from);
			}
		}
		
	}
	
	g_free(device);
}
Exemplo n.º 15
0
Arquivo: json.c Projeto: GNOME/gegl
/* json_op_class */
static const gchar *
metadata_get_property(JsonObject *root, const gchar *prop) {
  if (json_object_has_member(root, "properties")) {
      JsonObject *properties = json_object_get_object_member(root, "properties");
      if (json_object_has_member(properties, prop)) {
        return json_object_get_string_member(properties, prop);
      }
  }
  return NULL;
}
Exemplo n.º 16
0
void
snarf_alert_set_generator(snarf_alert_t *alert, char *name, char *version) 
{

    JsonObject * rootobj = json_node_get_object (alert->msg);
    JsonObject * envelopeobj = json_object_get_object_member(rootobj,"envelope");

    json_object_set_string_member(envelopeobj,"generator",name);
    json_object_set_string_member(envelopeobj,"version",version);

}
Exemplo n.º 17
0
static void ggp_ggdrive_auth_done(PurpleHttpConnection *hc,
	PurpleHttpResponse *response, gpointer user_data)
{
	PurpleConnection *gc = purple_http_conn_get_purple_connection(hc);
	ggp_edisc_session_data *sdata = ggp_edisc_get_sdata(gc);
	JsonParser *parser;
	JsonObject *result;
	int status = -1;

	g_return_if_fail(sdata != NULL);

	sdata->auth_request = NULL;

	if (!purple_http_response_is_successful(response)) {
		purple_debug_misc("gg", "ggp_ggdrive_auth_done: authentication "
			"failed due to unsuccessful request (code = %d)\n",
			purple_http_response_get_code(response));
		ggp_ggdrive_auth_results(gc, FALSE);
		return;
	}

	parser = ggp_json_parse(purple_http_response_get_data(response, NULL));
	result = json_node_get_object(json_parser_get_root(parser));
	result = json_object_get_object_member(result, "result");
	if (json_object_has_member(result, "status"))
		status = json_object_get_int_member(result, "status");
	g_object_unref(parser);

	if (status != 0 ) {
		purple_debug_misc("gg", "ggp_ggdrive_auth_done: authentication "
			"failed due to bad result (status=%d)\n", status);
		if (purple_debug_is_verbose())
			purple_debug_misc("gg", "ggp_ggdrive_auth_done: "
				"result = %s\n",
				purple_http_response_get_data(response, NULL));
		ggp_ggdrive_auth_results(gc, FALSE);
		return;
	}

	sdata->security_token = g_strdup(purple_http_response_get_header(
		response, "X-gged-security-token"));
	if (!sdata->security_token) {
		purple_debug_misc("gg", "ggp_ggdrive_auth_done: authentication "
			"failed due to missing security token header\n");
		ggp_ggdrive_auth_results(gc, FALSE);
		return;
	}

	if (purple_debug_is_unsafe())
		purple_debug_misc("gg", "ggp_ggdrive_auth_done: "
			"security_token=%s\n", sdata->security_token);
	ggp_ggdrive_auth_results(gc, TRUE);
}
/**
 * couchdb_struct_field_get_struct_field:
 * @sf: A #CouchdbStructField object
 * @field: Name of the field
 *
 * Retrieve the value of a struct field from the given struct field.
 *
 * Return value: The value of the given field.
 */
CouchdbStructField *
couchdb_struct_field_get_struct_field (CouchdbStructField *sf, const char *field)
{
	g_return_val_if_fail (sf != NULL, NULL);
	g_return_val_if_fail (field != NULL, NULL);

	if (!json_object_has_member (sf->json_object, field))
		return NULL;

	return couchdb_struct_field_new_from_json_object (
		json_object_get_object_member (sf->json_object, field));
}
Exemplo n.º 19
0
void
snarf_alert_add_double_field(snarf_alert_t *alert,
                             const char    *name,
                             double         value)
{
JsonObject * rootobj = json_node_get_object (alert->msg);
JsonObject * bodyobj = json_object_get_object_member(rootobj,"body");
JsonNode * doublenode = json_node_alloc();
doublenode=json_node_init_double(doublenode,value);
json_object_set_member(bodyobj,name,doublenode);

}
Exemplo n.º 20
0
void
snarf_alert_add_int_field(snarf_alert_t *alert,
                          const char    *name,
                          int64_t        value)
{

JsonObject * rootobj = json_node_get_object (alert->msg);
JsonObject * bodyobj = json_object_get_object_member(rootobj,"body");
JsonNode * intnode = json_node_alloc();
intnode=json_node_init_int(intnode,value);
json_object_set_member(bodyobj,name,intnode);

}
Exemplo n.º 21
0
static gboolean
gs_plugin_odrs_load_ratings (GsPlugin *plugin, const gchar *fn, GError **error)
{
	GsPluginData *priv = gs_plugin_get_data (plugin);
	GList *l;
	JsonNode *json_root;
	JsonObject *json_item;
	g_autoptr(GList) apps = NULL;
	g_autoptr(JsonParser) json_parser = NULL;

	/* remove all existing */
	g_hash_table_remove_all (priv->ratings);

	/* parse the data and find the success */
	json_parser = json_parser_new ();
	if (!json_parser_load_from_file (json_parser, fn, error)) {
		gs_utils_error_convert_json_glib (error);
		return FALSE;
	}
	json_root = json_parser_get_root (json_parser);
	if (json_root == NULL) {
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_INVALID_FORMAT,
				     "no ratings root");
		return FALSE;
	}
	if (json_node_get_node_type (json_root) != JSON_NODE_OBJECT) {
		g_set_error_literal (error,
				     GS_PLUGIN_ERROR,
				     GS_PLUGIN_ERROR_INVALID_FORMAT,
				     "no ratings array");
		return FALSE;
	}

	/* parse each app */
	json_item = json_node_get_object (json_root);
	apps = json_object_get_members (json_item);
	for (l = apps; l != NULL; l = l->next) {
		const gchar *app_id = (const gchar *) l->data;
		JsonObject *json_app = json_object_get_object_member (json_item, app_id);
		g_autoptr(GArray) ratings = NULL;;
		ratings = gs_plugin_odrs_load_ratings_for_app (json_app);
		if (ratings->len == 6) {
			g_hash_table_insert (priv->ratings,
					     g_strdup (app_id),
					     g_array_ref (ratings));
		}
	}
	return TRUE;
}
Exemplo n.º 22
0
static gboolean
ipcam_event_cover_msg_handler_put_action_impl(IpcamMessageHandler *handler, JsonNode *request, JsonNode **response)
{
    JsonBuilder *builder = json_builder_new();
    JsonObject *req_obj;
    GList *members, *item;

    req_obj = json_object_get_object_member(json_node_get_object(request), "items");
    members = json_object_get_members(req_obj);

    json_builder_begin_object(builder);
    json_builder_set_member_name(builder, "items");
    json_builder_begin_object(builder);
    for (item = g_list_first(members); item; item = g_list_next(item))
    {
        const gchar *name = item->data;
        if (g_str_equal(name, "region1") ||
            g_str_equal(name, "region2"))
        {
            JsonObject *value_obj = json_object_get_object_member(req_obj, name);
            ipcam_event_cover_msg_handler_update_param(IPCAM_EVENT_COVER_MSG_HANDLER(handler), name, value_obj);
            json_builder_set_member_name(builder, name);
            json_builder_begin_object(builder);
            ipcam_event_cover_msg_handler_read_param(IPCAM_EVENT_COVER_MSG_HANDLER(handler), builder, name);
            json_builder_end_object(builder);
        }
    }
    json_builder_end_object(builder);
    json_builder_end_object(builder);

    g_list_free(members);

    *response = json_builder_get_root(builder);

    g_object_unref(builder);

    return TRUE;
}
Exemplo n.º 23
0
void ease_flickr_service_iconview_add_thumbnail_from_json (EaseFlickrService* self, JsonArray* array, guint index, JsonNode* element) {
#line 372 "ease-import-flickr-service.c"
	JsonObject* photo;
	gint64 farm;
	char* secret;
	char* server;
	char* id;
	EaseFlickrMedia* image;
	char* _tmp0_;
	char* _tmp1_;
	char* _tmp2_;
	char* _tmp3_;
	char* _tmp4_;
#line 124 "ease-import-flickr-service.vala"
	g_return_if_fail (self != NULL);
#line 124 "ease-import-flickr-service.vala"
	g_return_if_fail (array != NULL);
#line 124 "ease-import-flickr-service.vala"
	g_return_if_fail (element != NULL);
#line 128 "ease-import-flickr-service.vala"
	photo = _json_object_ref0 (json_node_get_object (element));
#line 129 "ease-import-flickr-service.vala"
	farm = json_object_get_int_member (photo, "farm");
#line 130 "ease-import-flickr-service.vala"
	secret = g_strdup (json_object_get_string_member (photo, "secret"));
#line 131 "ease-import-flickr-service.vala"
	server = g_strdup (json_object_get_string_member (photo, "server"));
#line 132 "ease-import-flickr-service.vala"
	id = g_strdup (json_object_get_string_member (photo, "id"));
#line 134 "ease-import-flickr-service.vala"
	image = ease_flickr_media_new ();
#line 135 "ease-import-flickr-service.vala"
	((EasePluginImportMedia*) image)->file_link = (_tmp0_ = g_strdup_printf (EASE_FLICKR_SERVICE_URL_FORMAT, farm, server, id, secret, "z"), _g_free0 (((EasePluginImportMedia*) image)->file_link), _tmp0_);
#line 136 "ease-import-flickr-service.vala"
	((EasePluginImportMedia*) image)->thumb_link = (_tmp1_ = g_strdup_printf (EASE_FLICKR_SERVICE_URL_FORMAT, farm, server, id, secret, "m"), _g_free0 (((EasePluginImportMedia*) image)->thumb_link), _tmp1_);
#line 139 "ease-import-flickr-service.vala"
	image->title = (_tmp2_ = g_strdup (json_object_get_string_member (photo, "title")), _g_free0 (image->title), _tmp2_);
#line 140 "ease-import-flickr-service.vala"
	image->description = (_tmp3_ = g_strdup (json_object_get_string_member (json_object_get_object_member (photo, "description"), "_content")), _g_free0 (image->description), _tmp3_);
#line 143 "ease-import-flickr-service.vala"
	image->author = (_tmp4_ = g_strdup (json_object_get_string_member (photo, "owner")), _g_free0 (image->author), _tmp4_);
#line 145 "ease-import-flickr-service.vala"
	ease_plugin_import_service_add_media ((EasePluginImportService*) self, (EasePluginImportMedia*) image);
#line 414 "ease-import-flickr-service.c"
	_g_object_unref0 (image);
	_g_free0 (id);
	_g_free0 (server);
	_g_free0 (secret);
	_json_object_unref0 (photo);
}
Exemplo n.º 24
0
static void
skypeweb_got_vm_info(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
{
	PurpleConversation *conv = user_data;
	JsonObject *obj, *response, *media_stream;
	const gchar *filename;
	
	if (node == NULL || json_node_get_node_type(node) != JSON_NODE_OBJECT)
		return;
	obj = json_node_get_object(node);
	
	response = json_object_get_object_member(obj, "response");
	media_stream = json_object_get_object_member(response, "media_stream");
	filename = json_object_get_string_member(media_stream, "filename");
	
	if (filename != NULL) {
		// Need to keep retrying this url until it comes back with status:ok
		gchar *url = g_strdup_printf("/vod/api-create?assetId=%s&profile=mp4-vm", purple_url_encode(filename));
		skypeweb_post_or_get(sa, SKYPEWEB_METHOD_GET | SKYPEWEB_METHOD_SSL, "media.vm.skype.com", url, NULL, skypeweb_got_vm_download_info, conv, TRUE);
		g_free(url);
	}

}
Exemplo n.º 25
0
static gboolean
picasa_web_utils_parse_json_response (SoupMessage  *msg,
				      JsonNode    **node,
				      GError      **error)
{
	JsonParser *parser;
	SoupBuffer *body;

	g_return_val_if_fail (msg != NULL, FALSE);
	g_return_val_if_fail (node != NULL, FALSE);

	*node = NULL;

	if ((msg->status_code != 200) && (msg->status_code != 400)) {
		*error = g_error_new (SOUP_HTTP_ERROR,
				      msg->status_code,
				      "%s",
				      soup_status_get_phrase (msg->status_code));
		return FALSE;
	}

	body = soup_message_body_flatten (msg->response_body);
	parser = json_parser_new ();
	if (json_parser_load_from_data (parser, body->data, body->length, error)) {
		JsonObject *obj;

		*node = json_node_copy (json_parser_get_root (parser));

		obj = json_node_get_object (*node);
		if (json_object_has_member (obj, "error")) {
			JsonObject *error_obj;

			error_obj = json_object_get_object_member (obj, "error");
			*error = g_error_new (WEB_SERVICE_ERROR,
					      json_object_get_int_member (error_obj, "code"),
					      "%s",
					      json_object_get_string_member (error_obj, "message"));

			json_node_free (*node);
			*node = NULL;
		}
	}

	g_object_unref (parser);
	soup_buffer_free (body);

	return *node != NULL;
}
Exemplo n.º 26
0
void ipcam_itrain_update_szyc_setting(IpcamITrain *itrain, JsonNode *body)
{
    JsonObject *items_obj = json_object_get_object_member(json_node_get_object(body), "items");
	GList *members, *item;

	members = json_object_get_members(items_obj);
	for (item = g_list_first(members); item; item = g_list_next(item)) {
		const gchar *name = (const gchar *)item->data;
		gchar *key;
		if (asprintf(&key, "szyc:%s", (const gchar *)item->data) > 0) {
			const gchar *value = json_object_get_string_member(items_obj, name);
			ipcam_itrain_set_string_property(itrain, key, value);
			g_free(key);
		}
	}
    g_list_free(members);
}
Exemplo n.º 27
0
static int ggp_edisc_parse_error(const gchar *data)
{
	JsonParser *parser;
	JsonObject *result;
	int error_id;

	parser = ggp_json_parse(data);
	result = json_node_get_object(json_parser_get_root(parser));
	result = json_object_get_object_member(result, "result");
	error_id = json_object_get_int_member(result, "appStatus");
	purple_debug_info("gg", "edisc error: %s (%d)\n",
		json_object_get_string_member(result, "errorMsg"),
		error_id);
	g_object_unref(parser);

	return error_id;
}
Exemplo n.º 28
0
void
snarf_alert_add_text_field(snarf_alert_t *alert,
                           const char    *name,
                           const char    *value)
{

// Add text field to body
JsonNode *node;

JsonObject * rootobj = json_node_get_object (alert->msg);
JsonObject * bodyobj = json_object_get_object_member(rootobj,"body");

JsonNode * stringnode = json_node_alloc();
stringnode=json_node_init_string(stringnode,value);
json_object_set_member(bodyobj,name,stringnode);

}
Exemplo n.º 29
0
static JsonObject *
get_changes (const gchar *macaroon, gchar **discharges,
             const gchar *change_id,
             GCancellable *cancellable, GError **error)
{
    g_autofree gchar *path = NULL;
    guint status_code;
    g_autofree gchar *reason_phrase = NULL;
    g_autofree gchar *response_type = NULL;
    g_autofree gchar *response = NULL;
    g_autoptr(JsonParser) parser = NULL;
    JsonObject *root, *result;

    path = g_strdup_printf ("/v2/changes/%s", change_id);
    if (!send_request ("GET", path, NULL,
                       macaroon, discharges,
                       &status_code, &reason_phrase,
                       &response_type, &response, NULL,
                       cancellable, error))
        return NULL;

    if (status_code != SOUP_STATUS_OK) {
        g_set_error (error,
                     GS_PLUGIN_ERROR,
                     GS_PLUGIN_ERROR_FAILED,
                     "snapd returned status code %u: %s",
                     status_code, reason_phrase);
        return NULL;
    }

    parser = parse_result (response, response_type, error);
    if (parser == NULL)
        return NULL;
    root = json_node_get_object (json_parser_get_root (parser));
    result = json_object_get_object_member (root, "result");
    if (result == NULL) {
        g_set_error (error,
                     GS_PLUGIN_ERROR,
                     GS_PLUGIN_ERROR_FAILED,
                     "snapd returned no result");
        return NULL;
    }

    return json_object_ref (result);
}
Exemplo n.º 30
0
static JsonNode *query_network_address(IpcamIAjax *iajax)
{
	const gchar *token = ipcam_base_app_get_config(IPCAM_BASE_APP(iajax), "token");
	IpcamRequestMessage *req_msg;
	IpcamMessage *resp_msg;
    JsonBuilder *builder;
	JsonNode *addr_node = NULL;
	gboolean ret;

	builder = json_builder_new();
	json_builder_begin_object(builder);
	json_builder_set_member_name(builder, "items");
	json_builder_begin_array(builder);
	json_builder_add_string_value(builder, "address");
	json_builder_end_array(builder);
	json_builder_end_object(builder);

	req_msg = g_object_new(IPCAM_REQUEST_MESSAGE_TYPE,
	                       "action", "get_network",
	                       "body", json_builder_get_root(builder),
	                       NULL);
	ipcam_base_app_send_message(IPCAM_BASE_APP(iajax), IPCAM_MESSAGE(req_msg),
	                            "iconfig", token, NULL, 5);
	ret = ipcam_base_app_wait_response(IPCAM_BASE_APP(iajax),
	                                   ipcam_request_message_get_id(req_msg),
	                                   5000, &resp_msg);
	if (ret)
	{
		JsonNode *resp_body;
		JsonObject *items_obj;

		g_object_get(G_OBJECT(resp_msg), "body", &resp_body, NULL);

		items_obj = json_object_get_object_member(json_node_get_object(resp_body), "items");
		addr_node = json_node_copy(json_object_get_member(items_obj, "address"));

		g_object_unref(resp_msg);
	}

	g_object_unref(req_msg);
	g_object_unref(builder);

	return addr_node;
}