JsonArray *get_torrents_removed(JsonObject * response) { if (G_UNLIKELY(json_object_has_member(response, FIELD_REMOVED))) return json_object_get_array_member(response, FIELD_REMOVED); else return NULL; }
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); }
// 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; }
static gboolean update_for_meta (CockpitMetrics *self, JsonObject *meta, gboolean reset) { JsonArray *array; JsonObject *info; JsonArray *instances; guint length; gchar const *derive; array = json_object_get_array_member (meta, "metrics"); g_return_val_if_fail (array != NULL, FALSE); length = json_array_get_length (array); if (self->priv->metric_info == NULL) { self->priv->n_metrics = length; self->priv->metric_info = g_new0 (MetricInfo, length); self->priv->last_data = g_new0 (double *, length); self->priv->next_data = g_new0 (double *, length); self->priv->derived = g_new0 (double *, length); reset = TRUE; }
/** * gfbgraph_connectable_default_parse_connected_data: * @self: a #GFBGraphConnectable. * @payload: a const #gchar with the response string from the Facebook Graph API. * @error: (allow-none): a #GError or %NULL. * * In most cases, #GFBGraphConnectable implementers can use this function in order to parse * the response when a gfbgraph_node_get_connection_nodes() is executed and the * gfbgraph_connectable_parse_connected_data() was called. * * Normally, Facebook Graph API returns the connections in the same way, using JSON objects, * with a root object called "data". * * Returns: (element-type GFBGraphNode) (transfer full): a newly-allocated #GList of #GFBGraphNode with the same #GType as @self. **/ GList* gfbgraph_connectable_default_parse_connected_data (GFBGraphConnectable *self, const gchar *payload, GError **error) { GList *nodes_list = NULL; JsonParser *jparser; GType node_type; node_type = G_OBJECT_TYPE (self); jparser = json_parser_new (); if (json_parser_load_from_data (jparser, payload, -1, error)) { JsonNode *root_jnode; JsonObject *main_jobject; JsonArray *nodes_jarray; int i = 0; root_jnode = json_parser_get_root (jparser); main_jobject = json_node_get_object (root_jnode); nodes_jarray = json_object_get_array_member (main_jobject, "data"); for (i = 0; i < json_array_get_length (nodes_jarray); i++) { JsonNode *jnode; GFBGraphNode *node; jnode = json_array_get_element (nodes_jarray, i); node = GFBGRAPH_NODE (json_gobject_deserialize (node_type, jnode)); nodes_list = g_list_append (nodes_list, node); } } g_clear_object (&jparser); return nodes_list; }
gboolean _rpmostree_jsonutil_append_string_array_to (JsonObject *object, const char *member_name, GPtrArray *array, GError **error) { JsonArray *jarray = json_object_get_array_member (object, member_name); guint i, len; if (!jarray) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "No member '%s' found", member_name); return FALSE; } len = json_array_get_length (jarray); for (i = 0; i < len; i++) { const char *v = _rpmostree_jsonutil_array_require_string_element (jarray, i, error); if (!v) return FALSE; g_ptr_array_add (array, g_strdup (v)); } return TRUE; }
static gboolean ipcam_event_cover_msg_handler_get_action_impl(IpcamMessageHandler *handler, JsonNode *request, JsonNode **response) { JsonBuilder *builder = json_builder_new(); JsonArray *req_array; int i; req_array = json_object_get_array_member(json_node_get_object(request), "items"); json_builder_begin_object(builder); json_builder_set_member_name(builder, "items"); json_builder_begin_object(builder); for (i = 0; i < json_array_get_length(req_array); i++) { const gchar *name = json_array_get_string_element(req_array, i); if (g_str_equal(name, "region1") || g_str_equal(name, "region2")) { 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); *response = json_builder_get_root(builder); g_object_unref(builder); return TRUE; }
// 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(); } }
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); }
static guint json_array_size (JsonObject *object, const char *name) { if (!json_object_has_member (object, name)) return 0; return json_array_get_length (json_object_get_array_member (object, name)); }
static int json_object_get_member_size (JsonObject *obj, const char *member_name) { if (!obj || !json_object_has_member (obj, member_name)) return 0; return (int)json_array_get_length (json_object_get_array_member (obj, member_name)); }
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); } }
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); }
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); }
void trg_tree_view_setup_columns(TrgTreeView * tv) { TrgTreeViewPrivate *priv = TRG_TREE_VIEW_GET_PRIVATE(tv); JsonObject *props = trg_prefs_get_tree_view_props(tv); GList *columns, *widths, *cli, *wli; if (!json_object_has_member(props, TRG_PREFS_KEY_TV_COLUMNS) || !json_object_has_member(props, TRG_PREFS_KEY_TV_WIDTHS)) { GList *li; for (li = priv->columns; li; li = g_list_next(li)) { trg_column_description *desc = (trg_column_description *) li->data; if (desc && !(desc->flags & TRG_COLUMN_EXTRA)) trg_tree_view_add_column(tv, desc, -1); } return; } columns = json_array_get_elements(json_object_get_array_member (props, TRG_PREFS_KEY_TV_COLUMNS)); widths = json_array_get_elements(json_object_get_array_member (props, TRG_PREFS_KEY_TV_WIDTHS)); for (cli = columns, wli = widths; cli && wli; cli = g_list_next(cli), wli = g_list_next(wli)) { trg_column_description *desc = trg_tree_view_find_column(tv, json_node_get_string ((JsonNode *) cli-> data)); if (desc) { gint64 width = json_node_get_int((JsonNode *) wli->data); trg_tree_view_add_column(tv, desc, width); } } g_list_free(columns); g_list_free(widths); }
void add_file_id_to_array(JsonObject * args, const gchar * key, gint index) { JsonArray *array; if (json_object_has_member(args, key)) { array = json_object_get_array_member(args, key); } else { array = json_array_new(); json_object_set_array_member(args, key, array); } json_array_add_int_element(array, index); }
void gml_gtk_widget_set_file (GmlGtkWidget *gml, gchar *f) { JsonParser *parser = NULL; JsonNode *node = NULL; JsonObject *obj = NULL; JsonArray *arr = NULL; GError *error = NULL; GList *l = NULL; GList *p = NULL; parser = json_parser_new (); json_parser_load_from_file (parser, f, &error); if (error) { g_print ("Unable to parse `%s': %s\n", f, error->message); g_error_free (error); g_object_unref (parser); return; } node = json_parser_get_root (parser); obj = json_node_get_object (node); l = json_object_get_members (obj); for (p = l; p; p = p->next) { if (!strcmp (p->data, "width")) { gml->width = json_object_get_int_member (obj, p->data); } else if (!strcmp (p->data, "height")) { gml->height = json_object_get_int_member (obj, p->data); } else if (!strcmp (p->data, "color")) { clutter_color_from_string (&(gml->stage_color), json_object_get_string_member (obj, p->data)); } else if (!strcmp (p->data, "elements")) { GList *al = NULL; GList *ap = NULL; JsonObject *arro = NULL; // parsing elements arr = json_object_get_array_member (obj, p->data); al = json_array_get_elements (arr); for (ap = al; ap; ap = ap->next) { arro = json_node_get_object (ap->data); gml_gtk_widget_create_element (gml->stage, arro); } } } g_list_free (l); g_object_unref (parser); gtk_widget_set_size_request (gml->clutter_widget, gml->width, gml->height); clutter_stage_set_color (CLUTTER_STAGE (gml->stage), &(gml->stage_color)); }
/** * couchdb_struct_field_get_array_field: * @sf: A #CouchdbStructField object * @field: Name of the field * * Retrieve the value of an array field from the given struct field. * * Return value: The value of the given field. */ CouchdbArrayField * couchdb_struct_field_get_array_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_array_field_new_from_json_array ( json_object_get_array_member (sf->json_object, field)); }
JsonArray * gs_snapd_find (const gchar *macaroon, gchar **discharges, gchar **values, GCancellable *cancellable, GError **error) { g_autoptr(GString) path = NULL; g_autofree gchar *query = NULL; g_autofree gchar *escaped = 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; JsonArray *result; path = g_string_new ("/v2/find?q="); query = g_strjoinv (" ", values); escaped = soup_uri_encode (query, NULL); g_string_append (path, escaped); if (!send_request ("GET", path->str, 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_array_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_array_ref (result); }
/** * @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; }
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); }
/** * @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; }
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); } }
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; }
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); }
JsonArray * gs_snapd_list (const gchar *macaroon, gchar **discharges, GCancellable *cancellable, GError **error) { 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; JsonArray *result; if (!send_request ("GET", "/v2/snaps", 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_array_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_array_ref (result); }
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); } } }
/** * @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; }
GList* cometd_msg_supported_connection_types(JsonNode* node) { g_return_val_if_fail(JSON_NODE_HOLDS_OBJECT (node), NULL); JsonObject* obj = json_node_get_object(node); JsonArray* arr = json_object_get_array_member(obj, "supportedConnectionTypes"); if (!arr) return NULL; GList *types = NULL, *ielem = NULL; GList* items = json_array_get_elements(arr); for (ielem = items; ielem; ielem = g_list_next(ielem)) types = g_list_prepend(types, json_node_dup_string(ielem->data)); types = g_list_reverse(types); g_list_free(items); return types; }
/* Prepare a root filesystem, taking mainly the contents of /usr from yumroot */ static gboolean create_rootfs_from_yumroot_content (GFile *targetroot, GFile *yumroot, JsonObject *treefile, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; glnx_fd_close int src_rootfs_fd = -1; glnx_fd_close int target_root_dfd = -1; gs_unref_object GFile *kernel_path = NULL; gs_unref_object GFile *initramfs_path = NULL; gs_unref_hashtable GHashTable *preserve_groups_set = NULL; gboolean container = FALSE; if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (yumroot), TRUE, &src_rootfs_fd, error)) goto out; if (!_rpmostree_jsonutil_object_get_optional_boolean_member (treefile, "container", &container, error)) goto out; g_print ("Preparing kernel\n"); if (!container && !do_kernel_prep (yumroot, treefile, cancellable, error)) goto out; g_print ("Initializing rootfs\n"); if (!init_rootfs (targetroot, cancellable, error)) goto out; if (!glnx_opendirat (AT_FDCWD, gs_file_get_path_cached (targetroot), TRUE, &target_root_dfd, error)) goto out; g_print ("Migrating /etc/passwd to /usr/lib/\n"); if (!rpmostree_passwd_migrate_except_root (yumroot, RPM_OSTREE_PASSWD_MIGRATE_PASSWD, NULL, cancellable, error)) goto out; if (json_object_has_member (treefile, "etc-group-members")) { JsonArray *etc_group_members = json_object_get_array_member (treefile, "etc-group-members"); preserve_groups_set = _rpmostree_jsonutil_jsarray_strings_to_set (etc_group_members); } g_print ("Migrating /etc/group to /usr/lib/\n"); if (!rpmostree_passwd_migrate_except_root (yumroot, RPM_OSTREE_PASSWD_MIGRATE_GROUP, preserve_groups_set, cancellable, error)) goto out; /* NSS configuration to look at the new files */ { gs_unref_object GFile *yumroot_etc = g_file_resolve_relative_path (yumroot, "etc"); if (!replace_nsswitch (yumroot_etc, cancellable, error)) goto out; } /* We take /usr from the yum content */ g_print ("Moving /usr to target\n"); { gs_unref_object GFile *usr = g_file_get_child (yumroot, "usr"); if (!move_to_dir (usr, targetroot, cancellable, error)) goto out; } /* Except /usr/local -> ../var/usrlocal */ g_print ("Linking /usr/local -> ../var/usrlocal\n"); { gs_unref_object GFile *target_usrlocal = g_file_resolve_relative_path (targetroot, "usr/local"); if (!gs_shutil_rm_rf (target_usrlocal, cancellable, error)) goto out; if (!g_file_make_symbolic_link (target_usrlocal, "../var/usrlocal", cancellable, error)) goto out; } /* And now we take the contents of /etc and put them in /usr/etc */ g_print ("Moving /etc to /usr/etc\n"); { gs_unref_object GFile *yumroot_etc = g_file_get_child (yumroot, "etc"); gs_unref_object GFile *target_usretc = g_file_resolve_relative_path (targetroot, "usr/etc"); if (!gs_file_rename (yumroot_etc, target_usretc, cancellable, error)) goto out; } if (!migrate_rpm_and_yumdb (targetroot, yumroot, cancellable, error)) goto out; if (!convert_var_to_tmpfiles_d (src_rootfs_fd, target_root_dfd, cancellable, error)) goto out; /* Move boot, but rename the kernel/initramfs to have a checksum */ if (!container) { gs_unref_object GFile *yumroot_boot = g_file_get_child (yumroot, "boot"); gs_unref_object GFile *target_boot = g_file_get_child (targetroot, "boot"); gs_unref_object GFile *target_usrlib = g_file_resolve_relative_path (targetroot, "usr/lib"); gs_unref_object GFile *target_usrlib_ostree_boot = g_file_resolve_relative_path (target_usrlib, "ostree-boot"); RpmOstreePostprocessBootLocation boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH; const char *boot_location_str = NULL; g_print ("Moving /boot\n"); if (!_rpmostree_jsonutil_object_get_optional_string_member (treefile, "boot_location", &boot_location_str, error)) goto out; if (boot_location_str != NULL) { if (strcmp (boot_location_str, "legacy") == 0) boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_LEGACY; else if (strcmp (boot_location_str, "both") == 0) boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH; else if (strcmp (boot_location_str, "new") == 0) boot_location = RPMOSTREE_POSTPROCESS_BOOT_LOCATION_NEW; else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid boot location '%s'", boot_location_str); goto out; } } if (!gs_file_ensure_directory (target_usrlib, TRUE, cancellable, error)) goto out; switch (boot_location) { case RPMOSTREE_POSTPROCESS_BOOT_LOCATION_LEGACY: { g_print ("Using boot location: legacy\n"); if (!gs_file_rename (yumroot_boot, target_boot, cancellable, error)) goto out; } break; case RPMOSTREE_POSTPROCESS_BOOT_LOCATION_BOTH: { g_print ("Using boot location: both\n"); if (!gs_file_rename (yumroot_boot, target_boot, cancellable, error)) goto out; /* Hardlink the existing content, only a little ugly as * we'll end up sha256'ing it twice, but oh well. */ if (!gs_shutil_cp_al_or_fallback (target_boot, target_usrlib_ostree_boot, cancellable, error)) goto out; } break; case RPMOSTREE_POSTPROCESS_BOOT_LOCATION_NEW: { g_print ("Using boot location: new\n"); if (!gs_file_rename (yumroot_boot, target_usrlib_ostree_boot, cancellable, error)) goto out; } break; } } /* Also carry along toplevel compat links */ g_print ("Copying toplevel compat symlinks\n"); { guint i; const char *toplevel_links[] = { "lib", "lib64", "lib32", "bin", "sbin" }; for (i = 0; i < G_N_ELEMENTS (toplevel_links); i++) { gs_unref_object GFile *srcpath = g_file_get_child (yumroot, toplevel_links[i]); if (g_file_query_file_type (srcpath, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL) == G_FILE_TYPE_SYMBOLIC_LINK) { if (!move_to_dir (srcpath, targetroot, cancellable, error)) goto out; } } } g_print ("Adding tmpfiles-ostree-integration.conf\n"); { gs_unref_object GFile *src_pkglibdir = g_file_new_for_path (PKGLIBDIR); gs_unref_object GFile *src_tmpfilesd = g_file_get_child (src_pkglibdir, "tmpfiles-ostree-integration.conf"); gs_unref_object GFile *target_tmpfilesd = g_file_resolve_relative_path (targetroot, "usr/lib/tmpfiles.d/tmpfiles-ostree-integration.conf"); gs_unref_object GFile *target_tmpfilesd_parent = g_file_get_parent (target_tmpfilesd); if (!gs_file_ensure_directory (target_tmpfilesd_parent, TRUE, cancellable, error)) goto out; if (!g_file_copy (src_tmpfilesd, target_tmpfilesd, 0, cancellable, NULL, NULL, error)) goto out; } ret = TRUE; out: return ret; }