コード例 #1
0
ファイル: skypeweb_contacts.c プロジェクト: rtmf/skype4pidgin
static void
skypeweb_got_authrequests(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
{
	JsonArray *requests;
	guint index, length;
	time_t latest_timestamp = 0;
	
	requests = json_node_get_array(node);
	length = json_array_get_length(requests);
	for(index = 0; index < length; index++)
	{
		JsonObject *request = json_array_get_object_element(requests, index);
		const gchar *event_time_iso = json_object_get_string_member(request, "event_time_iso");
		const gchar *sender = json_object_get_string_member(request, "sender");
		const gchar *greeting = json_object_get_string_member(request, "greeting");
		time_t event_timestamp = purple_str_to_time(event_time_iso, TRUE, NULL, NULL, NULL);
		
		latest_timestamp = MAX(latest_timestamp, event_timestamp);
		if (sa->last_authrequest && event_timestamp <= sa->last_authrequest)
			continue;
		
		purple_account_request_authorization(
				sa->account, sender, NULL,
				NULL, greeting, FALSE,
				skypeweb_auth_accept_cb, skypeweb_auth_reject_cb, purple_buddy_new(sa->account, sender, NULL));
		
	}
	
	sa->last_authrequest = latest_timestamp;
}
コード例 #2
0
// Check if an app is graphical by checking if it uses a known GUI interface.
// This doesn't necessarily mean that every binary uses this interfaces, but is probably true.
// https://bugs.launchpad.net/bugs/1595023
static gboolean
is_graphical (GsApp *app, GCancellable *cancellable)
{
	g_autoptr(JsonObject) result = NULL;
	JsonArray *plugs;
	guint i;
	g_autoptr(GError) error = NULL;

	result = gs_snapd_get_interfaces (NULL, NULL, cancellable, &error);
	if (result == NULL) {
		g_warning ("Failed to check interfaces: %s", error->message);
		return FALSE;
	}

	plugs = json_object_get_array_member (result, "plugs");
	for (i = 0; i < json_array_get_length (plugs); i++) {
		JsonObject *plug = json_array_get_object_element (plugs, i);
		const gchar *interface;

		// Only looks at the plugs for this snap
		if (g_strcmp0 (json_object_get_string_member (plug, "snap"), gs_app_get_id (app)) != 0)
			continue;

		interface = json_object_get_string_member (plug, "interface");
		if (interface == NULL)
			continue;

		if (g_strcmp0 (interface, "unity7") == 0 || g_strcmp0 (interface, "x11") == 0 || g_strcmp0 (interface, "mir") == 0)
			return TRUE;
	}

	return FALSE;
}
コード例 #3
0
static void
process_results (RBPodcastSearchITunes *search, JsonParser *parser)
{
	JsonObject *container;
	JsonArray *results;
	guint i;

	container = json_node_get_object (json_parser_get_root (parser));
	results = json_node_get_array (json_object_get_member (container, "results"));

	for (i = 0; i < json_array_get_length (results); i++) {
		JsonObject *feed;
		RBPodcastChannel *channel;

		feed = json_array_get_object_element (results, i);

		/* check wrapperType==track, kind==podcast ? */

		channel = g_new0 (RBPodcastChannel, 1);

		channel->url = g_strdup (json_object_get_string_member (feed, "collectionViewUrl"));
		channel->title = g_strdup (json_object_get_string_member (feed, "collectionName"));
		channel->author = g_strdup (json_object_get_string_member (feed, "artistName"));
		channel->img = g_strdup (json_object_get_string_member (feed, "artworkUrl100"));	/* 100? */
		channel->is_opml = FALSE;

		channel->num_posts = json_object_get_int_member (feed, "trackCount");

		rb_debug ("got result %s (%s)", channel->title, channel->url);
		rb_podcast_search_result (RB_PODCAST_SEARCH (search), channel);
		rb_podcast_parse_channel_free (channel);
	}
}
コード例 #4
0
ファイル: network.cpp プロジェクト: fugufisch/biographer
// 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();
   }
   
}
コード例 #5
0
static void
process_results (RBPodcastSearchMiroGuide *search, JsonParser *parser)
{
	JsonArray *results;
	guint i;

	results = json_node_get_array (json_parser_get_root (parser));

	for (i = 0; i < json_array_get_length (results); i++) {
		JsonObject *feed;
		JsonArray *items;
		RBPodcastChannel *channel;
		int j;

		feed = json_array_get_object_element (results, i);

		channel = g_new0 (RBPodcastChannel, 1);
		channel->url = g_strdup (json_object_get_string_member (feed, "url"));
		channel->title = g_strdup (json_object_get_string_member (feed, "name"));
		channel->author = g_strdup (json_object_get_string_member (feed, "publisher"));		/* hrm */
		channel->img = g_strdup (json_object_get_string_member (feed, "thumbnail_url"));
		channel->is_opml = FALSE;
		rb_debug ("feed %d: url %s, name \"%s\"", i, channel->url, channel->title);

		items = json_object_get_array_member (feed, "item");
		for (j = 0; j < json_array_get_length (items); j++) {
			JsonObject *episode = json_array_get_object_element (items, j);
			RBPodcastItem *item;

			item = g_new0 (RBPodcastItem, 1);
			item->title = g_strdup (json_object_get_string_member (episode, "name"));
			item->url = g_strdup (json_object_get_string_member (episode, "url"));
			item->description = g_strdup (json_object_get_string_member (episode, "description"));
			item->pub_date = totem_pl_parser_parse_date (json_object_get_string_member (episode, "date"), FALSE);
			item->filesize = json_object_get_int_member (episode, "size");
			rb_debug ("item %d: title \"%s\", url %s", j, item->title, item->url);

			channel->posts = g_list_prepend (channel->posts, item);
		}
		channel->posts = g_list_reverse (channel->posts);
		rb_debug ("finished parsing items");

		rb_podcast_search_result (RB_PODCAST_SEARCH (search), channel);
		rb_podcast_parse_channel_free (channel);
	}
}
コード例 #6
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);
}
コード例 #7
0
static void
list_command_completed (gpointer data)
{
	FrCommandUnarchiver *unar_comm = FR_COMMAND_UNARCHIVER (data);
	JsonParser          *parser;
	GError              *error = NULL;

	parser = json_parser_new ();
	if (json_parser_load_from_stream (parser, unar_comm->stream, NULL, &error)) {
		JsonObject *root;

		root = json_node_get_object (json_parser_get_root (parser));

		if (json_object_get_int_member (root, "lsarFormatVersion") == LSAR_SUPPORTED_FORMAT) {
			JsonArray *content;
			int        i;

			content = json_object_get_array_member (root, "lsarContents");
			for (i = 0; i < json_array_get_length (content); i++) {
				JsonObject *entry;
				FileData   *fdata;
				const char *filename;

				entry = json_array_get_object_element (content, i);
				fdata = file_data_new ();
				fdata->size = json_object_get_int_member (entry, "XADFileSize");
				fdata->modified = mktime_from_string (json_object_get_string_member (entry, "XADLastModificationDate"));
				if (json_object_has_member (entry, "XADIsEncrypted"))
					fdata->encrypted = json_object_get_int_member (entry, "XADIsEncrypted") == 1;

				filename = json_object_get_string_member (entry, "XADFileName");
				if (*filename == '/') {
					fdata->full_path = g_strdup (filename);
					fdata->original_path = fdata->full_path;
				}
				else {
					fdata->full_path = g_strconcat ("/", filename, NULL);
					fdata->original_path = fdata->full_path + 1;
				}

				fdata->link = NULL;
				if (json_object_has_member (entry, "XADIsDirectory"))
					fdata->dir = json_object_get_int_member (entry, "XADIsDirectory") == 1;
				if (fdata->dir)
					fdata->name = _g_path_get_dir_name (fdata->full_path);
				else
					fdata->name = g_strdup (_g_path_get_basename (fdata->full_path));
				fdata->path = _g_path_remove_level (fdata->full_path);

				fr_archive_add_file (FR_ARCHIVE (unar_comm), fdata);
			}
		}
	}

	g_object_unref (parser);
}
コード例 #8
0
void trg_prefs_load(TrgPrefs * p)
{
    TrgPrefsPrivate *priv = p->priv;
    JsonParser *parser = json_parser_new();
    JsonNode *root;
    guint n_profiles;
    JsonArray *profiles;

    gboolean parsed = json_parser_load_from_file(parser, priv->file, NULL);

    if (!parsed) {
        trg_prefs_empty_init(p);
        g_object_unref(parser);
        return;
    }

    root = json_parser_get_root(parser);
    if (root) {
        priv->user = json_node_copy(root);
        priv->userObj = json_node_get_object(priv->user);
    }

    g_object_unref(parser);

    if (!root) {
        trg_prefs_empty_init(p);
        return;
    }

    if (!json_object_has_member(priv->userObj, TRG_PREFS_KEY_PROFILES)) {
        profiles = json_array_new();
        json_object_set_array_member(priv->userObj, TRG_PREFS_KEY_PROFILES,
                                     profiles);
    } else {
        profiles = json_object_get_array_member(priv->userObj,
                                                TRG_PREFS_KEY_PROFILES);
    }

    n_profiles = json_array_get_length(profiles);

    if (n_profiles < 1) {
        priv->profile = trg_prefs_new_profile_object();
        json_array_add_object_element(profiles, priv->profile);
        trg_prefs_set_int(p, TRG_PREFS_KEY_PROFILE_ID, 0,
                          TRG_PREFS_GLOBAL);
    } else {
        gint profile_id = trg_prefs_get_int(p, TRG_PREFS_KEY_PROFILE_ID,
                                            TRG_PREFS_GLOBAL);
        if (profile_id >= n_profiles)
            trg_prefs_set_int(p, TRG_PREFS_KEY_PROFILE_ID, profile_id = 0,
                              TRG_PREFS_GLOBAL);

        priv->profile =
            json_array_get_object_element(profiles, profile_id);
    }
}
コード例 #9
0
ファイル: wldictquery.c プロジェクト: wiiiky/wdict
static void onTaskReadyCallback(GObject * source, GAsyncResult * res,
                                gpointer userData)
{
    GError *err = NULL;
    //WlDictQuery *query=WL_DICT_QUERY(source);
    TaskData *td = g_task_get_task_data(G_TASK(res));
    gchar *responseBody = g_task_propagate_pointer(G_TASK(res), &err);
    if (err) {                  /* Error */
        if (td->cb)
            td->cb(td->from, td->to, td->src, NULL, td->cbData, err);
        return;
    }

    JsonParser *parser = json_parser_new();
    if (!json_parser_load_from_data(parser, responseBody, -1, &err)) {
        if (td->cb)
            td->cb(td->from, td->to, td->src, NULL, td->cbData, err);
        g_message("%s", responseBody);
        return;
    }
    JsonNode *rootNode = json_parser_get_root(parser);
    JsonObject *rootObj = json_node_get_object(rootNode);
    const gchar *from = json_object_get_string_member(rootObj, "from");
    const gchar *to = json_object_get_string_member(rootObj, "to");

    if (json_object_has_member(rootObj, "error_code")) {
        /* 查询出错 */
        const gchar *error_msg =
            json_object_get_string_member(rootObj, "error_msg");
        const gchar *error_code =
            json_object_get_string_member(rootObj, "error_code");
        if (td->cb) {
            GError *error =
                g_error_new(G_IO_ERROR, atoi(error_code), "%s", error_msg);
            td->cb(wl_dict_lang_get_enum(from), wl_dict_lang_get_enum(to),
                   json_object_get_string_member(rootObj, "query"), NULL,
                   td->cbData, error);
            g_error_free(error);
        }
        g_object_unref(parser);
        return;
    }

    JsonArray *results =
        json_object_get_array_member(rootObj, "trans_result");
    gint i, len = json_array_get_length(results);
    for (i = 0; i < len; i++) {
        JsonObject *resEle = json_array_get_object_element(results, i);
        const gchar *src = json_object_get_string_member(resEle, "src");
        const gchar *dst = json_object_get_string_member(resEle, "dst");
        if (td->cb)
            td->cb(wl_dict_lang_get_enum(from),
                   wl_dict_lang_get_enum(to), src, dst, td->cbData, NULL);
    }
    g_object_unref(parser);
}
コード例 #10
0
ファイル: skypeweb_contacts.c プロジェクト: rtmf/skype4pidgin
static void
skypeweb_got_friend_profiles(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
{
	JsonArray *contacts;
	PurpleBuddy *buddy;
	SkypeWebBuddy *sbuddy;
	gint index, length;
	
	if (node == NULL || json_node_get_node_type(node) != JSON_NODE_ARRAY)
		return;
	contacts = json_node_get_array(node);
	length = json_array_get_length(contacts);
	
	for(index = 0; index < length; index++)
	{
		JsonObject *contact = json_array_get_object_element(contacts, index);
		
		const gchar *username = json_object_get_string_member(contact, "username");
		const gchar *new_avatar;
		
		buddy = purple_find_buddy(sa->account, username);
		if (!buddy)
			continue;
		sbuddy = purple_buddy_get_protocol_data(buddy);
		if (sbuddy == NULL) {
			sbuddy = g_new0(SkypeWebBuddy, 1);
			purple_buddy_set_protocol_data(buddy, sbuddy);
			sbuddy->skypename = g_strdup(username);
			sbuddy->sa = sa;
		}
		
		g_free(sbuddy->display_name); sbuddy->display_name = g_strdup(json_object_get_string_member(contact, "displayname"));
		purple_serv_got_alias(sa->pc, username, sbuddy->display_name);
		if (json_object_has_member(contact, "lastname")) {
			gchar *fullname = g_strconcat(json_object_get_string_member(contact, "firstname"), " ", json_object_get_string_member(contact, "lastname"), NULL);
			
			purple_blist_server_alias_buddy(buddy, fullname);
			
			g_free(fullname);
		} else {
			purple_blist_server_alias_buddy(buddy, json_object_get_string_member(contact, "firstname"));
		}
		
		new_avatar = json_object_get_string_member(contact, "avatarUrl");
		if (new_avatar && *new_avatar && (!sbuddy->avatar_url || !g_str_equal(sbuddy->avatar_url, new_avatar))) {
			g_free(sbuddy->avatar_url);
			sbuddy->avatar_url = g_strdup(new_avatar);			
			skypeweb_get_icon(buddy);
		}
		
		g_free(sbuddy->mood); sbuddy->mood = g_strdup(json_object_get_string_member(contact, "mood"));
	}
}
コード例 #11
0
ファイル: googlephoto.c プロジェクト: TurboGit/darktable
/**
 * @return a GList of dt_gphoto_album_ts associated to the user
 */
static GList *gphoto_get_album_list(dt_gphoto_context_t *ctx, gboolean *ok)
{
  if(!ok) return NULL;

  *ok = TRUE;
  GList *album_list = NULL;

  GList *args = NULL;

//  args = _gphoto_query_add_arguments(args, "pageSize", "50"); // max for list albums

  JsonObject *reply = gphoto_query_get(ctx, GOOGLE_GPHOTO "v1/albums", NULL);
  if(reply == NULL) goto error;

  do
  {
    JsonArray *jsalbums = json_object_get_array_member(reply, "albums");

    for(gint i = 0; i < json_array_get_length(jsalbums); i++)
    {
      JsonObject *obj = json_array_get_object_element(jsalbums, i);
      if(obj == NULL) continue;

      dt_gphoto_album_t *album = _json_new_album(obj);
      if(album)
        album_list = g_list_append(album_list, album);
    }

    args = NULL;

//    args = _gphoto_query_add_arguments(args, "pageSize", "50"); // max for list albums

    if(json_object_has_member(reply, "nextPageToken"))
      args = _gphoto_query_add_arguments(args, "pageToken", json_object_get_string_member(reply, "nextPageToken"));
    else
      break;

    reply = gphoto_query_get(ctx, GOOGLE_GPHOTO "v1/albums", args);
    if(reply == NULL) goto error;
  } while(true);

  return album_list;

error:
  *ok = FALSE;
  g_list_free_full(album_list, (GDestroyNotify)gphoto_album_destroy);
  return NULL;
}
コード例 #12
0
ファイル: facebook.c プロジェクト: rgo/darktable
/**
 * @return a GList of FBAlbums associated to the user
 */
static GList *fb_get_album_list(FBContext *ctx, gboolean *ok)
{
  if(!ok) return NULL;

  *ok = TRUE;
  GList *album_list = NULL;

  GHashTable *args = g_hash_table_new((GHashFunc)g_str_hash, (GEqualFunc)g_str_equal);
  g_hash_table_insert(args, "fields", "id,name,can_upload");
  JsonObject *reply = fb_query_get(ctx, "me/albums", args);
  g_hash_table_destroy(args);

  if(reply == NULL) goto error;

  JsonArray *jsalbums = json_object_get_array_member(reply, "data");
  if(jsalbums == NULL) goto error;

  guint i;
  for(i = 0; i < json_array_get_length(jsalbums); i++)
  {
    JsonObject *obj = json_array_get_object_element(jsalbums, i);
    if(obj == NULL) continue;

    JsonNode *canupload_node = json_object_get_member(obj, "can_upload");
    if(canupload_node == NULL || !json_node_get_boolean(canupload_node)) continue;

    FBAlbum *album = fb_album_init();
    if(album == NULL) goto error;

    const char *id = json_object_get_string_member(obj, "id");
    const char *name = json_object_get_string_member(obj, "name");
    if(id == NULL || name == NULL)
    {
      fb_album_destroy(album);
      goto error;
    }
    album->id = g_strdup(id);
    album->name = g_strdup(name);
    album_list = g_list_append(album_list, album);
  }
  return album_list;

error:
  *ok = FALSE;
  g_list_free_full(album_list, (GDestroyNotify)fb_album_destroy);
  return NULL;
}
コード例 #13
0
ファイル: f-list_profile.c プロジェクト: Snipa22/fchat-pidgin
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;
}
コード例 #14
0
static void
pb_got_phonebook(PushBulletAccount *pba, JsonNode *node, gpointer user_data)
{
	PurpleAccount *account = pba->account;
	JsonObject *rootobj = json_node_get_object(node);
	JsonArray *phonebook = json_object_get_array_member(rootobj, "phonebook");
	gint i;
	guint len;
	gchar *device = user_data;
	PurpleGroup *pbgroup;
	
	pbgroup = purple_find_group("PushBullet");
	if (!pbgroup)
	{
		pbgroup = purple_group_new("PushBullet");
		purple_blist_add_group(pbgroup, NULL);
	}
	
	for(i = 0, len = json_array_get_length(phonebook); i < len; i++)
	{
		JsonObject *number = json_array_get_object_element(phonebook, i);
		const gchar *name = json_object_get_string_member(number, "name");
		const gchar *phone = json_object_get_string_member(number, "phone");
		const gchar *phone_type = json_object_get_string_member(number, "phone_type");
		PurpleBuddy *pbuddy;
		
		//Only handle the right 'type' of phone number. 
		//home, mobile, work, other
		if (purple_account_get_bool(account, "mobile_contacts_only", FALSE) && phone_type[0] != 'm')
			continue;
		
		pbuddy = purple_find_buddy(account, phone);
		if (!pbuddy)
		{
			pbuddy = purple_buddy_new(account, phone, name);
			purple_blist_add_buddy(pbuddy, NULL, pbgroup, NULL);
			purple_debug_info("pushbullet", "Added buddy %s %s\n", phone, name);
		}
		
		purple_prpl_got_user_status(account, phone, "mobile", NULL);
		purple_prpl_got_user_status(account, phone, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);
	}
	
	g_free(device);
}
コード例 #15
0
ファイル: skypeweb_contacts.c プロジェクト: rtmf/skype4pidgin
static void
skypeweb_got_vm_download_info(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
{
	PurpleConversation *conv = user_data;
	PurpleXfer *xfer;
	JsonObject *obj, *file;
	JsonArray *files;
	gint64 fileSize;
	const gchar *url, *assetId, *status;
	gchar *filename;
	
	if (node == NULL || json_node_get_node_type(node) != JSON_NODE_OBJECT)
		return;
	obj = json_node_get_object(node);
	
	files = json_object_get_array_member(obj, "files");
	file = json_array_get_object_element(files, 0);
	if (file != NULL) {
		status = json_object_get_string_member(file, "status");
		if (status && g_str_equal(status, "ok")) {
			assetId = json_object_get_string_member(obj, "assetId");
			fileSize = json_object_get_int_member(file, "fileSize");
			url = json_object_get_string_member(file, "url");
			(void) url;
			
			filename = g_strconcat(assetId, ".mp4", NULL);
			
			xfer = purple_xfer_new(sa->account, PURPLE_XFER_RECEIVE, conv->name);
			purple_xfer_set_size(xfer, fileSize);
			purple_xfer_set_filename(xfer, filename);
			json_object_ref(file);
			purple_xfer_set_protocol_data(xfer, file);
			purple_xfer_set_init_fnc(xfer, skypeweb_init_vm_download);
			purple_xfer_set_cancel_recv_fnc(xfer, skypeweb_cancel_vm_download);
			purple_xfer_add(xfer);
			
			g_free(filename);
		} else if (status && g_str_equal(status, "running")) {
			//skypeweb_download_video_message(sa, sid??????, conv);
		}
	}
}
コード例 #16
0
gchar *torrent_get_full_dir(JsonObject * obj)
{
    gchar *containing_path, *name, *delim;
    const gchar *location;
    JsonArray *files = torrent_get_files(obj);
    JsonObject *firstFile;

    location = json_object_get_string_member(obj, FIELD_DOWNLOAD_DIR);
    firstFile = json_array_get_object_element(files, 0);
    name = g_strdup(json_object_get_string_member(firstFile, TFILE_NAME));

    if ((delim = g_strstr_len(name, -1, "/"))) {
        *delim = '\0';
        containing_path = g_strdup_printf("%s/%s", location, name);
    } else {
        containing_path = g_strdup(location);
    }

    g_free(name);
    return containing_path;
}
コード例 #17
0
ファイル: facebook.c プロジェクト: chubinou/darktable
/**
 * @return a GList of FBAlbums associated to the user
 */
static GList *fb_get_album_list(FBContext *ctx, gboolean* ok)
{
  if (ok) *ok = TRUE;
  GList *album_list = NULL;

  JsonObject *reply = fb_query_get(ctx, "me/albums", NULL);
  if (reply == NULL)
    goto error;

  JsonArray *jsalbums = json_object_get_array_member(reply, "data");
  if (jsalbums == NULL)
    goto error;

  guint i;
  for (i = 0; i < json_array_get_length(jsalbums); i++)
  {
    JsonObject *obj = json_array_get_object_element(jsalbums, i);
    if (obj == NULL)
      continue;

    JsonNode* canupload_node = json_object_get_member(obj, "can_upload");
    if (canupload_node == NULL || !json_node_get_boolean(canupload_node))
      continue;

    FBAlbum *album = fb_album_init();
    const char* id = json_object_get_string_member(obj, "id");
    const char* name = json_object_get_string_member(obj, "name");
    if (id == NULL || name == NULL)
      goto error;
    album->id = g_strdup(id);
    album->name = g_strdup(name);
    album_list = g_list_append(album_list, album);
  }
  return album_list;

error:
  *ok = FALSE;
  g_list_free_full(album_list, (GDestroyNotify)fb_album_destroy);
  return NULL;
}
コード例 #18
0
gboolean
gs_plugin_add_installed (GsPlugin *plugin,
			 GsAppList *list,
			 GCancellable *cancellable,
			 GError **error)
{
	g_autofree gchar *macaroon = NULL;
	g_auto(GStrv) discharges = NULL;
	g_autoptr(JsonArray) result = NULL;
	guint i;

	get_macaroon (plugin, &macaroon, &discharges);
	result = gs_snapd_list (macaroon, discharges, cancellable, error);
	if (result == NULL)
		return FALSE;

	for (i = 0; i < json_array_get_length (result); i++) {
		JsonObject *package = json_array_get_object_element (result, i);
		g_autoptr(GsApp) app = NULL;
		const gchar *status, *name;

		status = json_object_get_string_member (package, "status");
		if (g_strcmp0 (status, "active") != 0)
			continue;

		/* create a unique ID for deduplication, TODO: branch? */
		name = json_object_get_string_member (package, "name");
		app = gs_app_new (name);
		gs_app_set_scope (app, AS_APP_SCOPE_SYSTEM);
		gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_SNAP);
		gs_app_set_management_plugin (app, "snap");
		gs_app_set_kind (app, AS_APP_KIND_DESKTOP);
		gs_app_add_quirk (app, AS_APP_QUIRK_NOT_REVIEWABLE);
		refine_app (plugin, app, package, TRUE, cancellable);
		gs_app_list_add (list, app);
	}

	return TRUE;
}
コード例 #19
0
ファイル: msg.c プロジェクト: foobarfighter/c-cometd-client
/**
 * Takes a JsonNode and does its best to determine if
 * it's an ack payload with a successful ack message in
 * it.
 */
gboolean
cometd_msg_is_successful(JsonNode* node)
{
    JsonObject* msg = NULL;
    JsonArray* array = NULL;
    gboolean success = FALSE;

    switch (JSON_NODE_TYPE (node))
    {
    case JSON_NODE_ARRAY:
        array = json_node_get_array(node);
        msg = json_array_get_length(array) > 0 ?
              json_array_get_object_element(array, 0) : NULL;
        break;
    case JSON_NODE_OBJECT:
        msg = json_node_get_object(node);
        break;
    }

    if (msg != NULL && json_object_has_member(msg, COMETD_MSG_SUCCESSFUL_FIELD))
        success = json_object_get_boolean_member(msg, COMETD_MSG_SUCCESSFUL_FIELD);

    return success;
}
コード例 #20
0
ファイル: facebook-photo.c プロジェクト: KapTmaN/gthumb
static gboolean
facebook_photo_deserialize_property (JsonSerializable *serializable,
                                     const gchar      *property_name,
                                     GValue           *value,
                                     GParamSpec       *pspec,
                                     JsonNode         *property_node)
{
    FacebookPhoto *self = FACEBOOK_PHOTO (serializable);

    if (pspec->value_type == GTH_TYPE_DATETIME) {
        GTimeVal timeval;

        if (g_time_val_from_iso8601 (json_node_get_string (property_node), &timeval)) {
            GthDateTime *datetime;

            datetime = gth_datetime_new ();
            gth_datetime_from_timeval (datetime, &timeval);
            g_object_set (self, property_name, datetime, NULL);

            gth_datetime_free (datetime);

            return TRUE;
        }

        return FALSE;
    }

    if (pspec->value_type == FACEBOOK_TYPE_IMAGE_LIST) {
        GList     *images = NULL;
        JsonArray *array;
        int        i;

        array = json_node_get_array (property_node);
        for (i = 0; i < json_array_get_length (array); i++) {
            JsonObject *image_obj;

            image_obj = json_array_get_object_element (array, i);
            if (image_obj != NULL) {
                FacebookImage *image;

                image = facebook_image_new ();
                _g_strset (&image->source, json_object_get_string_member (image_obj, "source"));
                image->width = json_object_get_int_member (image_obj, "width");
                image->height = json_object_get_int_member (image_obj, "height");

                images = g_list_prepend (images, image);
            }
        }

        images = g_list_reverse (images);
        g_object_set (self, property_name, images, NULL);

        facebook_image_list_free (images);

        return TRUE;
    }

    return json_serializable_default_deserialize_property (serializable,
            property_name,
            value,
            pspec,
            property_node);
}
コード例 #21
0
ファイル: skypeweb_contacts.c プロジェクト: rtmf/skype4pidgin
static void
skypeweb_get_friend_list_cb(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
{
	JsonObject *obj;
	JsonArray *contacts;
	PurpleGroup *group = NULL;
	GSList *users_to_fetch = NULL;
	guint index, length;
	
	obj = json_node_get_object(node);
	contacts = json_object_get_array_member(obj, "contacts");
	length = json_array_get_length(contacts);
	
	for(index = 0; index < length; index++)
	{
		JsonObject *contact = json_array_get_object_element(contacts, index);
		const gchar *id = json_object_get_string_member(contact, "id");
		const gchar *display_name = json_object_get_string_member(contact, "display_name");
		const gchar *avatar_url = NULL;
		gboolean authorized = json_object_get_boolean_member(contact, "authorized");
		gboolean blocked = json_object_get_boolean_member(contact, "blocked");
		const gchar *type = json_object_get_string_member(contact, "type");
		
		JsonObject *name = json_object_get_object_member(contact, "name");
		const gchar *firstname = json_object_get_string_member(name, "first");
		const gchar *surname = NULL;
		PurpleBuddy *buddy;
		
		//TODO make this work for "pstn"
		if (!g_str_equal(type, "skype") && !g_str_equal(type, "msn"))
			continue;
		
		if (json_object_has_member(contact, "suggested") && json_object_get_boolean_member(contact, "suggested") && !authorized) {
			// suggested buddies wtf? some kind of advertising?
			continue;
		}
		
		buddy = purple_find_buddy(sa->account, id);
		if (!buddy)
		{
			if (!group)
			{
				group = purple_blist_find_group("Skype");
				if (!group)
				{
					group = purple_group_new("Skype");
					purple_blist_add_group(group, NULL);
				}
			}
			buddy = purple_buddy_new(sa->account, id, display_name);
			purple_blist_add_buddy(buddy, NULL, group, NULL);
		}
		
		if (json_object_has_member(name, "surname"))
			surname = json_object_get_string_member(name, "surname");

		// try to free the sbuddy here. no-op if it's not set before, otherwise prevents a leak.
		skypeweb_buddy_free(buddy);
		
		SkypeWebBuddy *sbuddy = g_new0(SkypeWebBuddy, 1);
		sbuddy->skypename = g_strdup(id);
		sbuddy->sa = sa;
		sbuddy->fullname = g_strconcat(firstname, (surname ? " " : NULL), surname, NULL);
		sbuddy->display_name = g_strdup(display_name);
		sbuddy->authorized = authorized;
		sbuddy->blocked = blocked;
		sbuddy->avatar_url = g_strdup(purple_buddy_icons_get_checksum_for_user(buddy));
		
		sbuddy->buddy = buddy;
		purple_buddy_set_protocol_data(buddy, sbuddy);
		
		purple_serv_got_alias(sa->pc, id, sbuddy->display_name);
		purple_blist_server_alias_buddy(buddy, sbuddy->fullname);
		
		if (json_object_has_member(contact, "avatar_url")) {
			avatar_url = json_object_get_string_member(contact, "avatar_url");
			if (avatar_url && *avatar_url && (!sbuddy->avatar_url || !g_str_equal(sbuddy->avatar_url, avatar_url))) {
				g_free(sbuddy->avatar_url);
				sbuddy->avatar_url = g_strdup(avatar_url);			
				skypeweb_get_icon(buddy);
			}
		}
		
		if (blocked == TRUE) {
			purple_privacy_deny_add(sa->account, id, TRUE);
		} else {
			users_to_fetch = g_slist_prepend(users_to_fetch, sbuddy->skypename);
		}
	}
	
	if (users_to_fetch)
	{
		//skypeweb_get_friend_profiles(sa, users_to_fetch);
		skypeweb_subscribe_to_contact_status(sa, users_to_fetch);
		g_slist_free(users_to_fetch);
	}
}
コード例 #22
0
ファイル: network.cpp プロジェクト: fugufisch/biographer
// FIXME: check for memory leaks
JSONcontext* Network::readJSON(const char* file){
   JsonParser *parser;
   JsonObject *obj;
   JsonArray *jnodes;
   JsonArray *jedges;
   int i,k;
   JSONcontext* ctx=new JSONcontext();
   GError *error;
   g_type_init ();
   parser = json_parser_new ();
   
   error = NULL;
   json_parser_load_from_file (parser, file, &error);
   if (error)
   {
      g_print ("Unable to parse `%s': %s\n", file, error->message);
      g_error_free (error);
      g_object_unref (parser);
      abort();
   }
   addCompartment(0,"unknown"); // add dummy compartment, may be overwritten by compartment from json
   ctx->root = json_node_copy(json_parser_get_root(parser)); // needs to be copied ??
   obj=json_node_get_object (ctx->root);
   jnodes=json_object_get_array_member(obj,"nodes");
   jedges=json_object_get_array_member(obj,"edges");
   g_print ("%i nodes\n",json_array_get_length(jnodes));
   for (i=0;i<json_array_get_length(jnodes);i++){
      JsonObject *n=json_array_get_object_element(jnodes,i);
      JsonObject *data=json_object_get_object_member(n,"data");
      const char* type=json_object_get_string_member(n,"type");
      const char* id=json_object_get_string_member(n,"id");
      if (json_object_has_member(n,"is_abstract") && (json_object_get_boolean_member(n,"is_abstract") || json_object_get_int_member(n,"is_abstract"))){
         continue;
      }
      if (!json_object_has_member(n,"index")){
         g_print ("no index defined for %s %s\n",type,id);
         abort();
      }
      int idx=json_object_get_int_member(n,"index");
      g_print ("node %d %s id %s\n",idx,type,id);
      if(strcmp(type,"Compartment")==0){
         addCompartment(idx,id);
      } else {
         double x=json_object_get_double_member(data,"x");
         double y=json_object_get_double_member(data,"y");
         double w=json_object_get_double_member(data,"width");
         double h=json_object_get_double_member(data,"height");
         double d=json_object_get_double_member(data,"dir");
         int c=json_object_get_int_member(data,"compartmentidx");
         for(k=0;k<7;k++){
            if(strcmp(jnodetypes[k],type)==0)break;
         }
         if (k==7){
            g_print ("unknown node type %s\n",type);
            abort();
         }
         addNode(idx,inodetypes[k],id,w,h,x,y,d,c);
         if (idx>=ctx->nodeidx->size()) ctx->nodeidx->resize(idx+1);
         (*(ctx->nodeidx))[idx]=i;
      }
   }
   g_print ("%i edges\n",json_array_get_length(jedges));
   for (i=0;i<json_array_get_length(jedges);i++){
      JsonObject *e=json_array_get_object_element(jedges,i);
      const char* type=json_object_get_string_member(e,"type");
      if ((!json_object_has_member(e,"sourceidx")) || (!json_object_has_member(e,"targetidx"))){
         g_print ("no source/targetindex defined for edge %s %i",type,i);
         abort;
      }
      for(k=0;k<7;k++){
         if(strcmp(edgetypes[k],type)==0)break;
      }
      int from=json_object_get_int_member(e,"sourceidx");
      int to=json_object_get_int_member(e,"targetidx");
      addEdge(from,to,(Edgetype)k);
      g_print ("edge %s %i -> %i\n",edgetypes[k],from,to);
   }
   g_object_unref(parser);
   return ctx;
}
コード例 #23
0
static void
_got_trending_topic_updates_cb (RestProxyCall *call,
                                const GError  *error_in,
                                GObject       *weak_object,
                                gpointer       userdata)
{
  SwTwitterItemViewPrivate *priv = GET_PRIVATE (weak_object);
  SwItemView *item_view = SW_ITEM_VIEW (weak_object);
  SwSet *set;
  JsonParser *parser;
  JsonObject *root_o;
  SwService *service;
  GError *error = NULL;

  if (error_in) {
    g_warning (G_STRLOC ": Error getting trending topic data: %s", error_in->message);
    return;
  }

  service = sw_item_view_get_service (SW_ITEM_VIEW (item_view));

  set = sw_item_set_new ();
  parser = json_parser_new ();

  if (!json_parser_load_from_data (parser,
                                   rest_proxy_call_get_payload (call),
                                   rest_proxy_call_get_payload_length (call),
                                   &error))
  {
    g_warning (G_STRLOC ": error parsing json: %s", error->message);
  } else {
    JsonNode *root_n;
    JsonObject *trends_o;
    JsonArray *trends_a;
    GList *values;
    gint i;

    root_n = json_parser_get_root (parser);
    root_o = json_node_get_object (root_n);

    trends_o = json_object_get_object_member (root_o, "trends");

    /* We have to assume just the one object member */
    if (json_object_get_size (trends_o) == 1)
    {
      values = json_object_get_values (trends_o);
      trends_a = json_node_get_array ((JsonNode *)(values->data));

      for (i = 0; i < json_array_get_length (trends_a); i++)
      {
        JsonObject *trend_o;
        SwItem *item;

        item = sw_item_new ();
        sw_item_set_service (item, service);

        trend_o = json_array_get_object_element (trends_a, i);

        sw_item_take (item, "date", sw_time_t_to_string (time(NULL)));
        sw_item_put (item, "id", json_object_get_string_member (trend_o,
                                                                "name"));
        sw_item_put (item, "content", json_object_get_string_member (trend_o,
                                                                     "name"));

        sw_set_add (set, (GObject *)item);
        g_object_unref (item);
      }
      g_list_free (values);
    }
  }


  sw_item_view_set_from_set (SW_ITEM_VIEW (item_view),
                             set);

  /* Save the results of this set to the cache */
  sw_cache_save (service,
                 priv->query,
                 priv->params,
                 set);

  sw_set_unref (set);
  g_object_unref (parser);
}
コード例 #24
0
ファイル: skypeweb_contacts.c プロジェクト: rtmf/skype4pidgin
void
skypeweb_search_users_text_cb(SkypeWebAccount *sa, JsonNode *node, gpointer user_data)
{
	JsonArray *resultsarray = NULL;
	gint index, length;
	GString *userids;
	gchar *search_term = user_data;

	PurpleNotifySearchResults *results;
	PurpleNotifySearchColumn *column;
	
	resultsarray = json_node_get_array(node);
	length = json_array_get_length(resultsarray);
	
	if (length == 0)
	{
		gchar *primary_text = g_strdup_printf("Your search for the user \"%s\" returned no results", search_term);
		purple_notify_warning(sa->pc, "No users found", primary_text, "");
		g_free(primary_text);
		g_free(search_term);
		return;
	}
	
	userids = g_string_new("");
	
	resultsarray = json_node_get_array(node);
	for(index = 0; index < length; index++)
	{
		JsonObject *result = json_array_get_object_element(resultsarray, index);
		g_string_append_printf(userids, "%s,", json_object_get_string_member(result, "skypewebid"));
	}

	
	results = purple_notify_searchresults_new();
	if (results == NULL)
	{
		g_free(search_term);
		return;
	}
		
	/* columns: Friend ID, Name, Network */
	column = purple_notify_searchresults_column_new(_("Skype Name"));
	purple_notify_searchresults_column_add(results, column);
	column = purple_notify_searchresults_column_new(_("Display Name"));
	purple_notify_searchresults_column_add(results, column);
	column = purple_notify_searchresults_column_new(_("City"));
	purple_notify_searchresults_column_add(results, column);
	column = purple_notify_searchresults_column_new(_("Country"));
	purple_notify_searchresults_column_add(results, column);
	
	purple_notify_searchresults_button_add(results,
			PURPLE_NOTIFY_BUTTON_ADD,
			skypeweb_search_results_add_buddy);
	
	for(index = 0; index < length; index++)
	{
		JsonObject *contact = json_array_get_object_element(resultsarray, index);
		JsonObject *contactcards = json_object_get_object_member(contact, "ContactCards");
		JsonObject *skypecontact = json_object_get_object_member(contactcards, "Skype");
		JsonObject *currentlocation = json_object_get_object_member(contactcards, "CurrentLocation");
		
		/* the row in the search results table */
		/* prepend to it backwards then reverse to speed up adds */
		GList *row = NULL;
		
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(skypecontact, "SkypeName")));
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(skypecontact, "DisplayName")));
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(currentlocation, "City")));
		row = g_list_prepend(row, g_strdup(json_object_get_string_member(currentlocation, "Country")));
		
		row = g_list_reverse(row);
		
		purple_notify_searchresults_row_add(results, row);
	}
	
	purple_notify_searchresults(sa->pc, NULL, search_term, NULL,
			results, NULL, NULL);
}
コード例 #25
0
ファイル: json.c プロジェクト: GNOME/gegl
static void
attach (GeglOperation *operation)
{
  JsonOp *self = (JsonOp *)operation;
  GeglNode  *gegl = operation->node;
  JsonArray *connections;
  GList *l;

  // Processes
  JsonObject *root = self->json_root;
  JsonObject *processes = json_object_get_object_member(root, "processes");

  GList *process_names = json_object_get_members(processes);
  for (l = process_names; l != NULL; l = l->next) {
      const gchar *name = l->data;
      JsonObject *proc = json_object_get_object_member(processes, name);
      const gchar *component = json_object_get_string_member(proc, "component");
      gchar *opname = component2geglop(component);

      GeglNode *node = gegl_node_new_child (gegl, "operation", opname, NULL);
      gegl_operation_meta_watch_node (operation, node);
      g_assert(node);
      g_hash_table_insert(self->nodes, (gpointer)g_strdup(name), (gpointer)node);
      g_free(opname);
  }
  g_list_free(process_names);

  // Connections
  connections = json_object_get_array_member(root, "connections");
  g_assert(connections);
  for (int i=0; i<json_array_get_length(connections); i++) {
      JsonObject *conn = json_array_get_object_element(connections, i);
      JsonObject *tgt = json_object_get_object_member(conn, "tgt");
      const gchar *tgt_proc = json_object_get_string_member(tgt, "process");
      const gchar *tgt_port = json_object_get_string_member(tgt, "port");
      GeglNode *tgt_node = g_hash_table_lookup(self->nodes, tgt_proc);
      JsonNode *srcnode;

      g_assert(tgt_node);

      srcnode = json_object_get_member(conn, "src");
      if (srcnode) {
          // Connection
          JsonObject *src = json_object_get_object_member(conn, "src");
          const gchar *src_proc = json_object_get_string_member(src, "process");
          const gchar *src_port = json_object_get_string_member(src, "port");
          GeglNode *src_node = g_hash_table_lookup(self->nodes, src_proc);

          g_assert(src_node);

          gegl_node_connect_to (src_node, src_port, tgt_node, tgt_port);
      } else {
          // IIP
          JsonNode *datanode = json_object_get_member(conn, "data");
          GValue value = G_VALUE_INIT;
          GParamSpec *paramspec;

          g_assert(JSON_NODE_HOLDS_VALUE(datanode));
          json_node_get_value(datanode, &value);
          paramspec = gegl_node_find_property(tgt_node, tgt_port);

          set_prop(tgt_node, tgt_port, paramspec, &value);
          g_value_unset(&value);
      }
  }


  // 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);
      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");
          GeglNode *node = g_hash_table_lookup(self->nodes, proc);

          g_assert(node);

          if (g_strcmp0(name, "input") == 0) {
              GeglNode *input = gegl_node_get_input_proxy (gegl, "input");
              gegl_node_connect_to (input, "output", node, "input");
          } else {
            gegl_operation_meta_redirect (operation, name, node, port);
          }
      }

      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 (l = outport_names; l != NULL; l = l->next) {
          const gchar *name = l->data;
          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");
          GeglNode *node = g_hash_table_lookup(self->nodes, proc);
          g_assert(node);

          if (g_strcmp0(name, "output") == 0) {
            GeglNode *proxy = gegl_node_get_output_proxy (gegl, "output");
            gegl_node_connect_to (node, port, proxy, "input");
          } else {
            g_warning("Unsupported output '%s' exported in .json file", name);
          }
      }

      g_list_free(outport_names);
  }

}
コード例 #26
0
ファイル: f-list_profile.c プロジェクト: Snipa22/fchat-pidgin
static void flist_global_profile_cb(FListWebRequestData *req_data,
        gpointer user_data, JsonObject *root, const gchar *error_message) {
    FListAccount *fla = user_data;
    FListProfiles *flp = _flist_profiles(fla);
    JsonObject *info;
    GList *categories, *cur;

    flp->global_profile_request = NULL;

    if(!root) {
        purple_debug_warning(FLIST_DEBUG, "Failed to obtain the global list of profile fields. Error Message: %s\n", error_message);
        return;
    }

    info = json_object_get_object_member(root, "info");
    if(!info) {
        purple_debug_warning(FLIST_DEBUG, "We received the global list of profile fields, but it was empty.\n");
        return;
    }

    purple_debug_info(FLIST_DEBUG, "Processing global profile fields...\n");

    flp->category_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, flist_profile_field_category_free);

    categories = json_object_get_members(info);
    cur = categories;
    while(cur) {
        const gchar *group_name;
        JsonObject *field_group;
        JsonArray *field_array;
        FListProfileFieldCategory *category;
        guint i, len;

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

        category = g_new0(FListProfileFieldCategory, 1);
        category->name = g_strdup(group_name);

        len = json_array_get_length(field_array);
        for(i = 0; i < len; i++) {
            JsonObject *field_object = json_array_get_object_element(field_array, i);
            FListProfileField *field = g_new0(FListProfileField, 1);
            field->category = category;
            field->fieldid = g_strdup_printf("%d", (gint) json_object_get_int_member(field_object, "id"));
            field->name = g_strdup(json_object_get_string_member(field_object, "name"));
            category->fields = g_slist_prepend(category->fields, field);
            if(fla->debug_mode) {
                purple_debug_info(FLIST_DEBUG,
                        "Global profile field processed. (ID: %s) (Category: %s) (Name: %s)\n",
                        field->fieldid, field->category->name, field->name);
            }
        }
        category->fields = g_slist_sort(category->fields, (GCompareFunc) flist_profile_field_cmp);
        flp->category_list = g_slist_append(flp->category_list, category);
        g_hash_table_insert(flp->category_table, g_strdup(category->name), category);
        cur = g_list_next(cur);
    }
    g_list_free(categories);

    purple_debug_info(FLIST_DEBUG, "Global profile fields processed. (Categories: %d)\n", g_hash_table_size(flp->category_table));
}
コード例 #27
0
static void
refine_app (GsPlugin *plugin, GsApp *app, JsonObject *package, gboolean from_search, GCancellable *cancellable)
{
	g_autofree gchar *macaroon = NULL;
	g_auto(GStrv) discharges = NULL;
	const gchar *status, *icon_url, *launch_name = NULL;
	g_autoptr(GdkPixbuf) icon_pixbuf = NULL;
	gint64 size = -1;

	get_macaroon (plugin, &macaroon, &discharges);

	status = json_object_get_string_member (package, "status");
	if (g_strcmp0 (status, "installed") == 0 || g_strcmp0 (status, "active") == 0) {
		const gchar *update_available;

		update_available = json_object_has_member (package, "update_available") ?
			json_object_get_string_member (package, "update_available") : NULL;
		if (update_available)
			gs_app_set_state (app, AS_APP_STATE_UPDATABLE);
		else {
			if (gs_app_get_state (app) == AS_APP_STATE_AVAILABLE)
				gs_app_set_state (app, AS_APP_STATE_UNKNOWN);
			gs_app_set_state (app, AS_APP_STATE_INSTALLED);
		}
	} else if (g_strcmp0 (status, "not installed") == 0 || g_strcmp0 (status, "available") == 0) {
		gs_app_set_state (app, AS_APP_STATE_AVAILABLE);
	}
	gs_app_set_name (app, GS_APP_QUALITY_HIGHEST,
			 json_object_get_string_member (package, "summary"));
	gs_app_set_summary (app, GS_APP_QUALITY_HIGHEST,
			    json_object_get_string_member (package, "summary"));
	gs_app_set_description (app, GS_APP_QUALITY_HIGHEST,
				json_object_get_string_member (package, "description"));
	gs_app_set_version (app, json_object_get_string_member (package, "version"));
	if (json_object_has_member (package, "installed-size")) {
		size = json_object_get_int_member (package, "installed-size");
		if (size > 0)
			gs_app_set_size_installed (app, (guint64) size);
	}
	if (json_object_has_member (package, "download-size")) {
		size = json_object_get_int_member (package, "download-size");
		if (size > 0)
			gs_app_set_size_download (app, (guint64) size);
	}
	gs_app_add_quirk (app, AS_APP_QUIRK_PROVENANCE);
	icon_url = json_object_get_string_member (package, "icon");
	if (g_str_has_prefix (icon_url, "/")) {
		g_autofree gchar *icon_data = NULL;
		gsize icon_data_length;
		g_autoptr(GError) error = NULL;

		icon_data = gs_snapd_get_resource (macaroon, discharges, icon_url, &icon_data_length, cancellable, &error);
		if (icon_data != NULL) {
			g_autoptr(GdkPixbufLoader) loader = NULL;

			loader = gdk_pixbuf_loader_new ();
			gdk_pixbuf_loader_write (loader,
						 (guchar *) icon_data,
						 icon_data_length,
						 NULL);
			gdk_pixbuf_loader_close (loader, NULL);
			icon_pixbuf = g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader));
		}
		else
			g_printerr ("Failed to get icon: %s\n", error->message);
	}
	else {
		g_autoptr(SoupMessage) message = NULL;
		g_autoptr(GdkPixbufLoader) loader = NULL;

		message = soup_message_new (SOUP_METHOD_GET, icon_url);
		if (message != NULL) {
			soup_session_send_message (gs_plugin_get_soup_session (plugin), message);
			loader = gdk_pixbuf_loader_new ();
			gdk_pixbuf_loader_write (loader,
						 (guint8 *) message->response_body->data,
						 (gsize) message->response_body->length,
						 NULL);
			gdk_pixbuf_loader_close (loader, NULL);
			icon_pixbuf = g_object_ref (gdk_pixbuf_loader_get_pixbuf (loader));
		}
	}

	if (icon_pixbuf) {
		gs_app_set_pixbuf (app, icon_pixbuf);
	} else {
		g_autoptr(AsIcon) icon = as_icon_new ();
		as_icon_set_kind (icon, AS_ICON_KIND_STOCK);
		as_icon_set_name (icon, "package-x-generic");
		gs_app_add_icon (app, icon);
	}

	if (json_object_has_member (package, "screenshots") && gs_app_get_screenshots (app)->len <= 0) {
		JsonArray *screenshots;
		guint i;

		screenshots = json_object_get_array_member (package, "screenshots");
		for (i = 0; i < json_array_get_length (screenshots); i++) {
			JsonObject *screenshot = json_array_get_object_element (screenshots, i);
			g_autoptr(AsScreenshot) ss = NULL;
			g_autoptr(AsImage) image = NULL;

			ss = as_screenshot_new ();
			as_screenshot_set_kind (ss, AS_SCREENSHOT_KIND_NORMAL);
			image = as_image_new ();
			as_image_set_url (image, json_object_get_string_member (screenshot, "url"));
			as_image_set_kind (image, AS_IMAGE_KIND_SOURCE);
			as_screenshot_add_image (ss, image);
			gs_app_add_screenshot (app, ss);
		}
	}

	if (!from_search) {
		JsonArray *apps;

		apps = json_object_get_array_member (package, "apps");
		if (apps && json_array_get_length (apps) > 0)
			launch_name = json_object_get_string_member (json_array_get_object_element (apps, 0), "name");

		if (launch_name)
			gs_app_set_metadata (app, "snap::launch-name", launch_name);
		else
			gs_app_add_quirk (app, AS_APP_QUIRK_NOT_LAUNCHABLE);
	}
}
コード例 #28
0
static void
pb_got_everything(PushBulletAccount *pba, JsonNode *node, gpointer user_data)
{
	JsonObject *rootobj = json_node_get_object(node);
	JsonArray *devices = json_object_has_member(rootobj, "devices") ? json_object_get_array_member(rootobj, "devices") : NULL;
	JsonArray *pushes = json_object_has_member(rootobj, "pushes") ? json_object_get_array_member(rootobj, "pushes") : NULL;
	JsonArray *contacts = json_object_has_member(rootobj, "contacts") ? json_object_get_array_member(rootobj, "contacts") : NULL;
	JsonArray *chats = json_object_has_member(rootobj, "chats") ? json_object_get_array_member(rootobj, "chats") : NULL;
	JsonArray *texts = json_object_has_member(rootobj, "texts") ? json_object_get_array_member(rootobj, "texts") : NULL;
	gint i;
	guint len;
	PurpleGroup *pbgroup;
	
	pbgroup = purple_find_group("PushBullet");
	if (!pbgroup)
	{
		pbgroup = purple_group_new("PushBullet");
		purple_blist_add_group(pbgroup, NULL);
	}
	
	if (json_object_has_member(rootobj, "error")) {
		JsonObject *error = json_object_get_object_member(rootobj, "error");
		const gchar *type = json_object_get_string_member(error, "type");
		const gchar *message = json_object_get_string_member(error, "message");
		
		//TODO check type
		purple_connection_error_reason(pba->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, message);
		return;
	}
	
	if (devices != NULL) {
		for(i = 0, len = json_array_get_length(devices); i < len; i++) {
			JsonObject *device = json_array_get_object_element(devices, i);
			
			if (pba->main_sms_device == NULL && json_object_get_boolean_member(device, "has_sms")) {
				pba->main_sms_device = g_strdup(json_object_get_string_member(device, "iden"));
				purple_account_set_string(pba->account, "main_sms_device", pba->main_sms_device);
				
				pb_get_phonebook(pba, pba->main_sms_device);
				
				if (!pba->websocket) {
					pb_start_polling(pba);
				}
				
				break; //TODO handle more than one
			}
		}
	}
	
	if (pushes != NULL) {
		gint last_message_timestamp = purple_account_get_int(pba->account, "last_message_timestamp", 0);
		for(i = json_array_get_length(pushes); i > 0; i--) {
			JsonObject *push = json_array_get_object_element(pushes, i - 1);
			const gchar *type = json_object_get_string_member(push, "type");
			gdouble modified;
			time_t timestamp;
			gboolean dismissed;
			
			if (!type)
				continue;
			
			modified = json_object_get_double_member(push, "modified");
			timestamp = (time_t) modified;
			dismissed = json_object_get_boolean_member(push, "dismissed");
			
			if (timestamp <= last_message_timestamp || dismissed) {
				continue;
			}
			
			// {"active":true,"iden":"uffvytgsjApuAUIFRk","created":1.438895081423904e+09,"modified":1.438895081432786e+09,"type":"file","dismissed":false,"guid":"153b70f0-f7a6-4db9-a6f4-28b99fa416f1","direction":"self","sender_iden":"uffvytg","sender_email":"*****@*****.**","sender_email_normalized":"*****@*****.**","sender_name":"Eion Robb","receiver_iden":"uffvytg","receiver_email":"*****@*****.**","receiver_email_normalized":"*****@*****.**","target_device_iden":"uffvytgsjz7O3P0Jl6","source_device_iden":"uffvytgsjAoIRwhIL6","file_name":"IMG_20150807_084618.jpg","file_type":"image/jpeg","file_url":"https://dl.pushbulletusercontent.com/FHOZdyzfvnoYZY0DP6oK1rGKiJpWCPc0/IMG_20150807_084618.jpg","image_width":4128,"image_height":2322,"image_url":"https://lh3.googleusercontent.com/WY5TK7h3mzD32qMcnxtqt-4PrYcWW1uWDHnRW2x1oJK8mnYk2v4HbZrRjIQkiYdxMKQSdNI8GGPqfO6s6tEyuRVLzeA"}
			
			if (purple_strequal(type, "note") || purple_strequal(type, "link") || purple_strequal(type, "file")) {
				const gchar *from = json_object_get_string_member(push, "sender_email_normalized");
				const gchar *body = json_object_get_string_member(push, "body");
				const gchar *direction = json_object_get_string_member(push, "direction");
				gchar *body_html;
				
				if (from == NULL) {
					if (!json_object_has_member(push, "sender_name")) {
						purple_debug_error("pushbullet", "no sender name/email\n");
						continue;
					}
					from = json_object_get_string_member(push, "sender_name");
				}
				
				if (body && *body) {
					body_html = purple_strdup_withhtml(body);
				} else {
					const gchar *title = json_object_get_string_member(push, "title");
					if (title && *title) {
						body_html = purple_strdup_withhtml(title);
					} else {
						body_html = "Message";
					}
				}
				
				if (json_object_has_member(push, "url")) {
					gchar *body_with_link = g_strconcat("<a href=\"", json_object_get_string_member(push, "url"), "\">", body_html, "</a>", NULL);
					g_free(body_html);
					body_html = body_with_link;
					
				} else if (json_object_has_member(push, "image_url")) {
					const gchar *image_url = json_object_get_string_member(push, "image_url");
					PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, from, pba->account);
					
					if (conv == NULL)
					{
						conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, pba->account, from);
					}
					pb_download_image_to_conv(image_url, conv);
					
				} else if (json_object_has_member(push, "file_url")) {
					gchar *body_with_link;
					const gchar *file_name = json_object_get_string_member(push, "file_name");
					
					if (file_name && *file_name) {
						g_free(body_html);
						body_html = purple_strdup_withhtml(file_name);
					}
					
					body_with_link= g_strconcat("<a href=\"", json_object_get_string_member(push, "file_url"), "\">", json_object_get_string_member(push, "file_name"), "</a>", NULL);
					g_free(body_html);
					body_html = body_with_link;
				}
				
				if (direction[0] != 'o') {
					serv_got_im(pba->pc, from, body_html, PURPLE_MESSAGE_RECV, timestamp);
				} else {
					const gchar *guid = json_object_get_string_member(push, "guid");
					from = json_object_get_string_member(push, "receiver_email_normalized");
					
					if (!guid || !g_hash_table_remove(pba->sent_messages_hash, guid)) {
						PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, from, pba->account);
						if (conv == NULL)
						{
							conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, pba->account, from);
						}
						purple_conversation_write(conv, from, body_html, PURPLE_MESSAGE_SEND, timestamp);
					}
				}
				
				g_free(body_html);
			}
				
			purple_account_set_int(pba->account, "last_message_timestamp", MAX(purple_account_get_int(pba->account, "last_message_timestamp", 0), timestamp));
		}
	}
	
	if (contacts != NULL) {
		for(i = 0, len = json_array_get_length(contacts); i < len; i++) {
			JsonObject *contact = json_array_get_object_element(contacts, i);
			const gchar *email = json_object_get_string_member(contact, "email_normalized");
			const gchar *name = json_object_get_string_member(contact, "name");
			const gchar *image_url = json_object_get_string_member(contact, "image_url");
			
			PurpleBuddy *buddy = purple_find_buddy(pba->account, email);
			if (buddy == NULL)
			{
				buddy = purple_buddy_new(pba->account, email, name);
				purple_blist_add_buddy(buddy, NULL, pbgroup, NULL);
			}
			purple_prpl_got_user_status(pba->account, email, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);
		}
	}
	
	if (chats != NULL) {
		for(i = 0, len = json_array_get_length(chats); i < len; i++) {
			JsonObject *chat = json_array_get_object_element(chats, i);
			JsonObject *contact = json_object_get_object_member(chat, "with");
			const gchar *email = json_object_get_string_member(contact, "email_normalized");
			const gchar *name = json_object_get_string_member(contact, "name");
			const gchar *image_url = json_object_get_string_member(contact, "image_url");
			
			PurpleBuddy *buddy = purple_find_buddy(pba->account, email);
			if (buddy == NULL)
			{
				buddy = purple_buddy_new(pba->account, email, name);
				purple_blist_add_buddy(buddy, NULL, pbgroup, NULL);
			}
			purple_prpl_got_user_status(pba->account, email, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);
		}
	}
	
	if (texts != NULL) {
		for(i = 0, len = json_array_get_length(texts); i < len; i++) {
			JsonObject *text = json_array_get_object_element(texts, i);
		}
	}
}
コード例 #29
0
static void
push_gcm_client_deliver_cb (SoupSession *session,
                            SoupMessage *message,
                            gpointer     user_data)
{
   GSimpleAsyncResult *simple = user_data;
   const gchar *str;
   JsonObject *obj;
   JsonParser *p = NULL;
   JsonArray *ar;
   JsonNode *root;
   JsonNode *node;
   gboolean removed;
   GError *error = NULL;
   GList *list;
   gsize length;
   guint i;

   ENTRY;

   g_assert(SOUP_IS_SESSION(session));
   g_assert(SOUP_IS_MESSAGE(message));
   g_assert(G_IS_SIMPLE_ASYNC_RESULT(simple));

   switch (message->status_code) {
   case SOUP_STATUS_OK:
      break;
   case SOUP_STATUS_BAD_REQUEST:
      /*
       * TODO: Log that there was a JSON encoding error likely.
       */
      break;
   case SOUP_STATUS_UNAUTHORIZED:
      g_simple_async_result_set_error(simple,
                                      SOUP_HTTP_ERROR,
                                      message->status_code,
                                      _("GCM request unauthorized."));
      GOTO(failure);
   default:
      if (SOUP_STATUS_IS_SERVER_ERROR(message->status_code) &&
          (str = soup_message_headers_get_one(message->response_headers,
                                              "Retry-After"))) {
         /*
          * TODO: Implement exponential back-off.
          */
      }
      g_simple_async_result_set_error(simple,
                                      SOUP_HTTP_ERROR,
                                      message->status_code,
                                      _("Unknown failure occurred."));
      break;
   }

   if (!message->response_body->data || !message->response_body->length) {
      g_simple_async_result_set_error(simple,
                                      SOUP_HTTP_ERROR,
                                      SOUP_STATUS_IO_ERROR,
                                      _("No data was received from GCM."));
      GOTO(failure);
   }

   p = json_parser_new();

   if (!json_parser_load_from_data(p,
                                   message->response_body->data,
                                   message->response_body->length,
                                   &error)) {
      g_simple_async_result_take_error(simple, error);
      GOTO(failure);
   }

   list = g_object_get_data(G_OBJECT(simple), "identities");

   if ((root = json_parser_get_root(p)) &&
       JSON_NODE_HOLDS_OBJECT(root) &&
       (obj = json_node_get_object(root)) &&
       json_object_has_member(obj, "results") &&
       (node = json_object_get_member(obj, "results")) &&
       JSON_NODE_HOLDS_ARRAY(node) &&
       (ar = json_node_get_array(node))) {
      length = json_array_get_length(ar);
      for (i = 0; i < length && list; i++, list = list->next) {
         /*
          * TODO: Handle the case that the device_token has been renamed.
          */
         removed = FALSE;
         if ((obj = json_array_get_object_element(ar, i)) &&
             json_object_has_member(obj, "error") &&
             (node = json_object_get_member(obj, "error")) &&
             JSON_NODE_HOLDS_VALUE(node) &&
             (str = json_node_get_string(node))) {
            if (!g_strcmp0(str, "MissingRegistration")) {
               removed = TRUE;
            } else if (!g_strcmp0(str, "InvalidRegistration")) {
               removed = TRUE;
            } else if (!g_strcmp0(str, "MismatchSenderId")) {
            } else if (!g_strcmp0(str, "NotRegistered")) {
               removed = TRUE;
            } else if (!g_strcmp0(str, "MessageTooBig")) {
            } else if (!g_strcmp0(str, "InvalidDataKey")) {
            } else if (!g_strcmp0(str, "InvalidTtl")) {
            }

            if (removed) {
               g_assert(PUSH_IS_GCM_IDENTITY(list->data));
               g_signal_emit(session, gSignals[IDENTITY_REMOVED], 0, list->data);
            }
         }
      }
   }

   g_simple_async_result_set_op_res_gboolean(simple, TRUE);

failure:
   g_simple_async_result_complete_in_idle(simple);
   g_object_unref(simple);
   if (p) {
      g_object_unref(p);
   }

   EXIT;
}
コード例 #30
0
static void
pb_got_phone_thread(PushBulletAccount *pba, JsonNode *node, gpointer user_data)
{
	PurpleAccount *account = pba->account;
	PurpleConnection *pc = pba->pc;
	JsonObject *rootobj = json_node_get_object(node);
	JsonObject *data = json_object_get_object_member(rootobj, "data");
	JsonArray *thread = json_object_get_array_member(data, "thread");
	gint i;
	guint len;
	gchar *from = user_data;
	PurpleConversation *conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, from, account);
	gint purple_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);
	
	/*
	{"id":"652","type":"sms","timestamp":1440484608,"direction":"outgoing","body":"message","status":"sent"},
	{"id":"5","type":"mms","timestamp":1440484096,"direction":"incoming","recipient_index":0,"body":"","image_urls":["url1234"]}
	*/
	for(i = json_array_get_length(thread); i > 0; i--)
	{
		JsonObject *message = json_array_get_object_element(thread, i - 1);
		gint64 timestamp = json_object_get_int_member(message, "timestamp");
		const gchar *direction = json_object_get_string_member(message, "direction");
		const gchar *body = json_object_get_string_member(message, "body");
		gint id = atoi(json_object_get_string_member(message, "id"));
		
		if (timestamp > purple_last_message_timestamp || id > newest_phone_message_id) {
			gchar *body_html = purple_strdup_withhtml(body);
			if (direction[0] != 'o') {
				serv_got_im(pc, from, body_html, PURPLE_MESSAGE_RECV, timestamp);
			} else {
				const gchar *guid = json_object_get_string_member(message, "guid");
				if (!guid || !g_hash_table_remove(pba->sent_messages_hash, guid)) {
					if (conv == NULL)
					{
						conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, from);
					}
					purple_conversation_write(conv, from, body_html, PURPLE_MESSAGE_SEND, timestamp);
				}
			}
			g_free(body_html);
			
			if (json_object_has_member(message, "image_urls")) {
				JsonArray *image_urls = json_object_get_array_member(message, "image_urls");
				guint j, image_urls_len;
				
				if (conv == NULL)
				{
					conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, from);
				}
				
				for(j = 0, image_urls_len = json_array_get_length(image_urls); j < image_urls_len; j++) {
					const gchar *image_url = json_array_get_string_element(thread, j);
					
					pb_download_image_to_conv(image_url, conv);
				}
			}
			
			purple_account_set_int(account, "last_message_timestamp", MAX(purple_account_get_int(account, "last_message_timestamp", 0), timestamp));
			purple_account_set_int(account, "newest_phone_message_id", MAX(purple_account_get_int(account, "newest_phone_message_id", 0), id));
		}
	}
	
	g_free(from);
}