static gboolean kms_connection_ext_add_answer_attributes (KmsISdpMediaExtension * ext, const GstSDPMedia * offer, GstSDPMedia * answer, GError ** error) { GArray *ips_offered, *ips_answered; ips_offered = g_array_sized_new (FALSE, FALSE, sizeof (GValue), KMS_RESERVED_CONNECTION_SIZE); ips_answered = g_array_sized_new (FALSE, FALSE, sizeof (GValue), KMS_RESERVED_CONNECTION_SIZE); g_array_set_clear_func (ips_offered, (GDestroyNotify) g_value_unset); g_array_set_clear_func (ips_answered, (GDestroyNotify) g_value_unset); kms_connection_ext_get_connection_attrs (ext, offer, ips_offered); g_signal_emit (G_OBJECT (ext), obj_signals[SIGNAL_ON_ANSWER_IPS], 0, ips_offered, ips_answered); kms_connection_attr_ext_add_ips (ext, answer, ips_answered); g_array_unref (ips_offered); g_array_unref (ips_answered); return TRUE; }
guint nm_fake_rdisc_add_ra (NMFakeRDisc *self, guint seconds_after_previous, NMRDiscDHCPLevel dhcp_level, int hop_limit, guint32 mtu) { NMFakeRDiscPrivate *priv = NM_FAKE_RDISC_GET_PRIVATE (self); static guint counter = 1; FakeRa *ra; ra = g_malloc0 (sizeof (*ra)); ra->id = counter++; ra->when = seconds_after_previous; ra->dhcp_level = dhcp_level; ra->hop_limit = hop_limit; ra->mtu = mtu; ra->gateways = g_array_new (FALSE, FALSE, sizeof (NMRDiscGateway)); ra->addresses = g_array_new (FALSE, FALSE, sizeof (NMRDiscAddress)); ra->routes = g_array_new (FALSE, FALSE, sizeof (NMRDiscRoute)); ra->dns_servers = g_array_new (FALSE, FALSE, sizeof (NMRDiscDNSServer)); ra->dns_domains = g_array_new (FALSE, FALSE, sizeof (NMRDiscDNSDomain)); g_array_set_clear_func (ra->dns_domains, ra_dns_domain_free); priv->ras = g_slist_append (priv->ras, ra); return ra->id; }
static void cb_user_counter_init (CbUserCounter *counter) { counter->changed = FALSE; counter->user_infos = g_array_new (FALSE, TRUE, sizeof (CbUserInfo)); g_array_set_clear_func (counter->user_infos, (GDestroyNotify)cb_user_info_destroy); }
static void gst_rtp_ulpfec_dec_init (GstRtpUlpFecDec * self) { self->srcpad = gst_pad_new_from_static_template (&srctemplate, "src"); self->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink"); GST_PAD_SET_PROXY_CAPS (self->sinkpad); GST_PAD_SET_PROXY_ALLOCATION (self->sinkpad); gst_pad_set_chain_function (self->sinkpad, GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_chain)); gst_pad_set_event_function (self->sinkpad, GST_DEBUG_FUNCPTR (gst_rtp_ulpfec_dec_handle_sink_event)); gst_element_add_pad (GST_ELEMENT (self), self->srcpad); gst_element_add_pad (GST_ELEMENT (self), self->sinkpad); self->fec_pt = DEFAULT_FEC_PT; self->next_seqnum = g_random_int_range (0, G_MAXINT16); self->chain_return_val = GST_FLOW_OK; self->have_caps_ssrc = FALSE; self->caps_ssrc = 0; self->info_fec = g_ptr_array_new (); self->info_arr = g_array_new (FALSE, TRUE, sizeof (RtpUlpFecMapInfo)); g_array_set_clear_func (self->info_arr, (GDestroyNotify) rtp_ulpfec_map_info_unmap); self->scratch_buf = g_array_new (FALSE, TRUE, sizeof (guint8)); }
static void transport_stream_init (TransportStream * stream) { stream->ptmap = g_array_new (FALSE, TRUE, sizeof (PtMapItem)); g_array_set_clear_func (stream->ptmap, (GDestroyNotify) clear_ptmap_item); stream->remote_ssrcmap = g_array_new (FALSE, TRUE, sizeof (SsrcMapItem)); }
static gboolean gst_isoff_traf_box_parse (GstTrafBox * traf, GstByteReader * reader) { gboolean had_tfhd = FALSE; memset (traf, 0, sizeof (*traf)); traf->trun = g_array_new (FALSE, FALSE, sizeof (GstTrunBox)); g_array_set_clear_func (traf->trun, (GDestroyNotify) gst_isoff_trun_box_clear); while (gst_byte_reader_get_remaining (reader) > 0) { guint32 fourcc; guint header_size; guint64 size; if (!gst_isoff_parse_box_header (reader, &fourcc, NULL, &header_size, &size)) goto error; if (gst_byte_reader_get_remaining (reader) < size - header_size) goto error; switch (fourcc) { case GST_ISOFF_FOURCC_TFHD:{ GstByteReader sub_reader; gst_byte_reader_get_sub_reader (reader, &sub_reader, size - header_size); if (!gst_isoff_tfhd_box_parse (&traf->tfhd, &sub_reader)) goto error; had_tfhd = TRUE; break; } case GST_ISOFF_FOURCC_TRUN:{ GstByteReader sub_reader; GstTrunBox trun; gst_byte_reader_get_sub_reader (reader, &sub_reader, size - header_size); if (!gst_isoff_trun_box_parse (&trun, &sub_reader)) goto error; g_array_append_val (traf->trun, trun); break; } default: gst_byte_reader_skip (reader, size - header_size); break; } } if (!had_tfhd) goto error; return TRUE; error: gst_isoff_traf_box_clear (traf); return FALSE; }
GstMoofBox * gst_isoff_moof_box_parse (GstByteReader * reader) { GstMoofBox *moof; gboolean had_mfhd = FALSE; moof = g_new0 (GstMoofBox, 1); moof->traf = g_array_new (FALSE, FALSE, sizeof (GstTrafBox)); g_array_set_clear_func (moof->traf, (GDestroyNotify) gst_isoff_traf_box_clear); while (gst_byte_reader_get_remaining (reader) > 0) { guint32 fourcc; guint header_size; guint64 size; if (!gst_isoff_parse_box_header (reader, &fourcc, NULL, &header_size, &size)) goto error; if (gst_byte_reader_get_remaining (reader) < size - header_size) goto error; switch (fourcc) { case GST_ISOFF_FOURCC_MFHD:{ GstByteReader sub_reader; gst_byte_reader_get_sub_reader (reader, &sub_reader, size - header_size); if (!gst_isoff_mfhd_box_parse (&moof->mfhd, &sub_reader)) goto error; had_mfhd = TRUE; break; } case GST_ISOFF_FOURCC_TRAF:{ GstByteReader sub_reader; GstTrafBox traf; gst_byte_reader_get_sub_reader (reader, &sub_reader, size - header_size); if (!gst_isoff_traf_box_parse (&traf, &sub_reader)) goto error; g_array_append_val (moof->traf, traf); break; } default: gst_byte_reader_skip (reader, size - header_size); break; } } if (!had_mfhd) goto error; return moof; error: gst_isoff_moof_box_free (moof); return NULL; }
static GArray * _get_ref_frame_cache (GstValidateSsim * self, const gchar * ref_file) { GFile *ref_dir_file = NULL; GFileInfo *info; GFileEnumerator *fenum; GArray *frames = NULL; gchar *ref_dir = NULL; ref_dir = g_path_get_dirname (ref_file); frames = g_hash_table_lookup (self->priv->ref_frames_cache, ref_file); if (frames) goto done; ref_dir_file = g_file_new_for_path (ref_dir); if (!(fenum = g_file_enumerate_children (ref_dir_file, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, NULL))) { GST_INFO ("%s is not a folder", ref_dir); goto done; } for (info = g_file_enumerator_next_file (fenum, NULL, NULL); info; info = g_file_enumerator_next_file (fenum, NULL, NULL)) { Frame iframe; const gchar *display_name = g_file_info_get_display_name (info); if (!_filename_get_timestamp (self, display_name, &iframe.ts)) { g_object_unref (info); continue; } iframe.path = g_build_path (G_DIR_SEPARATOR_S, ref_dir, g_file_info_get_name (info), NULL); g_object_unref (info); if (!frames) { frames = g_array_new (TRUE, TRUE, sizeof (Frame)); g_array_set_clear_func (frames, (GDestroyNotify) _free_frame); } g_array_append_val (frames, iframe); } if (frames) { g_array_sort (frames, (GCompareFunc) _sort_frames); g_hash_table_insert (self->priv->ref_frames_cache, g_strdup (ref_dir), frames); } done: g_clear_object (&ref_dir_file); g_free (ref_dir); return frames; }
static void nmt_newt_popup_init (NmtNewtPopup *popup) { NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (popup); priv->entries = g_array_sized_new (FALSE, FALSE, sizeof (NmtNewtPopupEntry), 10); g_array_set_clear_func (priv->entries, (GDestroyNotify) popup_entry_clear_func); }
static void _gtk_style_cascade_init (GtkStyleCascade *cascade) { cascade->scale = 1; cascade->providers = g_array_new (FALSE, FALSE, sizeof (GtkStyleProviderData)); g_array_set_clear_func (cascade->providers, style_provider_data_clear); }
static void kms_sdp_media_handler_init (KmsSdpMediaHandler * self) { self->priv = KMS_SDP_MEDIA_HANDLER_GET_PRIVATE (self); self->priv->bwtypes = g_array_new (FALSE, TRUE, sizeof (GstSDPBandwidth)); g_array_set_clear_func (self->priv->bwtypes, (GDestroyNotify) gst_sdp_bandwidth_clear); self->priv->id = -1; self->priv->parent = NULL; }
static GArray * sparql_buffer_new (void) { GArray *array; array = g_array_new (FALSE, FALSE, sizeof (SparqlUpdate)); g_array_set_clear_func (array, (GDestroyNotify) sparql_update_clear); return array; }
static GArray * gb_beautifier_config_get_map (GbBeautifierWorkbenchAddin *self, const gchar *path) { GArray *map; g_autofree gchar *file_name = NULL; g_autoptr(GKeyFile) key_file = NULL; g_auto(GStrv) lang_ids = NULL; gsize nb_lang_ids; GError *error = NULL; g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self)); g_assert (!ide_str_empty0 (path)); map = g_array_new (TRUE, TRUE, sizeof (GbBeautifierMapEntry)); g_array_set_clear_func (map, map_entry_clear_func); file_name = g_build_filename (path, "global.ini", NULL); key_file = g_key_file_new (); if (!g_file_test (file_name, G_FILE_TEST_EXISTS)) { g_debug ("%s doesn't exist", file_name); return map; } if (g_key_file_load_from_file (key_file, file_name, G_KEY_FILE_NONE, &error) && NULL != (lang_ids = g_key_file_get_groups (key_file, &nb_lang_ids))) { for (gint i = 0; i < nb_lang_ids; ++i) { g_autofree gchar *mapped_lang_id = NULL; g_autofree gchar *default_profile = NULL; GbBeautifierMapEntry entry; gchar *lang_id = lang_ids [i]; if (!is_a_lang_id (self, lang_id) || NULL == (mapped_lang_id = g_key_file_get_string (key_file, lang_id, "map", NULL))) continue; if (gb_beautifier_map_check_duplicates (self, map, lang_id)) continue; default_profile = g_key_file_get_string (key_file, lang_id, "default", NULL); entry.lang_id = g_strdup (lang_id); entry.mapped_lang_id = g_steal_pointer (&mapped_lang_id); entry.default_profile = g_steal_pointer (&default_profile); g_array_append_val (map, entry); } } return map; }
void match_array_free(GArray* matches) { #if GLIB_CHECK_VERSION(2, 32, 0) g_array_set_clear_func(matches, match_destroyNotify); #else for (unsigned int i=0; i< matches->len; ++i) { Match* tmp = g_array_index(matches, Match*, i); match_free(tmp); } #endif g_array_free(matches, TRUE); }
static void clutter_gesture_action_init (ClutterGestureAction *self) { self->priv = clutter_gesture_action_get_instance_private (self); self->priv->points = g_array_sized_new (FALSE, TRUE, sizeof (GesturePoint), 3); g_array_set_clear_func (self->priv->points, (GDestroyNotify) gesture_point_unset); self->priv->requested_nb_points = 1; self->priv->edge = CLUTTER_GESTURE_TRIGGER_EDGE_NONE; }
GArray * gb_beautifier_config_get_entries (GbBeautifierWorkbenchAddin *self) { IdeContext *context; IdeVcs *vcs; GArray *entries; GArray *map = NULL; g_autofree gchar *project_config_path = NULL; g_autofree gchar *user_config_path = NULL; g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self)); entries = g_array_new (TRUE, TRUE, sizeof (GbBeautifierConfigEntry)); g_array_set_clear_func (entries, config_entry_clear_func); /* User wide config: ~/.config/gnome-builder/beautifier_plugin */ user_config_path = g_build_filename (g_get_user_config_dir (), ide_get_program_name (), "beautifier_plugin", NULL); map = gb_beautifier_config_get_map (self, user_config_path); add_entries_from_base_path (self, user_config_path, entries, map); if (map != NULL) g_array_free (map, TRUE); /* Project wide config */ if (NULL != (context = ide_workbench_get_context (self->workbench)) && NULL != (vcs = ide_context_get_vcs (context))) { GFile *workdir; g_autofree gchar *workdir_path = NULL; workdir = ide_vcs_get_working_directory (vcs); workdir_path = g_file_get_path (workdir); project_config_path = g_build_filename (workdir_path, ".beautifier", NULL); map = gb_beautifier_config_get_map (self, project_config_path); add_entries_from_base_path (self, project_config_path, entries, map); if (map != NULL) g_array_free (map, TRUE); } /* System wide config */ map = gb_beautifier_config_get_map (self, GB_BEAUTIFIER_PLUGIN_DATADIR); add_entries_from_base_path (self, GB_BEAUTIFIER_PLUGIN_DATADIR, entries, map); if (map != NULL) g_array_free (map, TRUE); return entries; }
static void eos_shard_writer_v2_init (EosShardWriterV2 *self) { g_mutex_init (&self->lock); constant_pool_init (&self->cpool); self->blobs = g_ptr_array_new_with_free_func ((GDestroyNotify) eos_shard_writer_v2_blob_entry_free); self->records = g_array_new (FALSE, TRUE, sizeof (struct eos_shard_writer_v2_record_entry)); g_array_set_clear_func (self->records, (GDestroyNotify) eos_shard_writer_v2_record_entry_clear); self->csum_to_data_start = g_hash_table_new (csum_hash, csum_equal); }
END_TEST START_TEST (test_query_creator_load_limit_gb) { RhythmDBQuery *query; GArray *array; query = rhythmdb_query_parse (db, RHYTHMDB_QUERY_END); array = g_array_sized_new (FALSE, TRUE, sizeof (GValue), 0); g_array_set_clear_func (array, (GDestroyNotify) g_value_unset); rb_value_array_append_data (array, G_TYPE_UINT64, (guint64)(14 * 1000)); query_creator_test_load_query (db, query, RHYTHMDB_QUERY_MODEL_LIMIT_SIZE, array, "Title", GTK_SORT_ASCENDING); rhythmdb_query_free (query); g_array_unref (array); }
struct qio_ev* qio_ev_new( const gchar *ev_path, const gchar *json, const gboolean internal) { struct qio_ev ev = { .ev_path = g_strdup(ev_path), .json = g_strdup(json), .internal = internal, .subs = g_array_new(FALSE, FALSE, sizeof(struct qio_ev_sub)), }; g_array_set_clear_func(ev.subs, _sub_clear); return g_slice_copy(sizeof(ev), &ev); } void qio_ev_free(struct qio_ev *ev) { g_free(ev->ev_path); g_free(ev->json); g_array_free(ev->subs, TRUE); g_slice_free1(sizeof(*ev), ev); }
static GArray * parse_mode_combination_string_list (const gchar *modes_str, GError **error) { GArray *supported_mode_combinations; gchar **mode_combinations; MMModemMode all = MM_MODEM_MODE_NONE; gboolean has_all = FALSE; guint i; mode_combinations = g_strsplit (modes_str, ",", -1); supported_mode_combinations = g_array_sized_new (FALSE, FALSE, sizeof (MMHuaweiSyscfgexCombination), g_strv_length (mode_combinations)); g_array_set_clear_func (supported_mode_combinations, (GDestroyNotify)huawei_syscfgex_combination_free); for (i = 0; mode_combinations[i]; i++) { MMHuaweiSyscfgexCombination combination; mode_combinations[i] = mm_strip_quotes (mode_combinations[i]); if (!parse_mode_combination_string (mode_combinations[i], &combination.allowed, &combination.preferred)) continue; if (combination.allowed != MM_MODEM_MODE_ANY) { combination.mode_str = g_strdup (mode_combinations[i]); g_array_append_val (supported_mode_combinations, combination); all |= combination.allowed; } else { /* don't add the all_combination here, we may have more * combinations in the loop afterwards */ has_all = TRUE; } } g_strfreev (mode_combinations); /* Add here the all_combination */ if (has_all) { MMHuaweiSyscfgexCombination combination; combination.allowed = all; combination.preferred = MM_MODEM_MODE_NONE; combination.mode_str = g_strdup ("00"); g_array_append_val (supported_mode_combinations, combination); } /* If we didn't build a valid array of combinations, return an error */ if (supported_mode_combinations->len == 0) { g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED, "Cannot parse list of allowed mode combinations: '%s'", modes_str); g_array_unref (supported_mode_combinations); return NULL; } return supported_mode_combinations; }
gchar * hdr_format_string (const gchar *data, gssize len) { g_autofree gchar *copy = NULL; g_autoptr(GString) out = NULL; g_autoptr(GArray) ar = NULL; g_auto(GStrv) chunks = NULL; guint long_ret = 0; guint long_ret_star = 0; guint long_ident = 0; guint long_ptype = 0; guint long_star = 0; ar = g_array_new (FALSE, FALSE, sizeof (Chunk)); g_array_set_clear_func (ar, (GDestroyNotify)clear_chunk); if (data == NULL || *data == 0) return g_strdup (""); if (len < 0) len = strlen (data); copy = g_strndup (data, len); chunks = g_strsplit (copy, ";", 0); for (guint i = 0; chunks[i]; i++) { g_strstrip (chunks[i]); if (!*chunks[i]) continue; if (!push_chunk (ar, chunks[i])) return NULL; } if (ar->len == 0) return NULL; out = g_string_new (NULL); #if 0 for (guint i = 0; i < ar->len; i++) { const Chunk *chunk = &g_array_index (ar, Chunk, i); } #endif for (guint i = 0; i < ar->len; i++) { const Chunk *chunk = &g_array_index (ar, Chunk, i); g_autofree gchar *rtype = NULL; guint n_star = 0; parse_rtype (chunk->return_type, &rtype, &n_star); long_ret = MAX (long_ret, strlen (rtype)); long_ret_star = MAX (long_ret_star, n_star); long_ident = MAX (long_ident, strlen (chunk->identifier)); for (const GSList *iter = chunk->params; iter; iter = iter->next) { Parameter *p = iter->data; long_star = MAX (long_star, p->n_star); if (p->type) long_ptype = MAX (long_ptype, strlen (p->type)); } } for (guint i = 0; i < ar->len; i++) { const Chunk *chunk = &g_array_index (ar, Chunk, i); guint n_star = 0; guint off; guint space; guint rlen; if (chunk->pre) g_string_append_printf (out, "%s\n", chunk->pre); off = out->len; if (chunk->return_type) { g_autofree gchar *rtype = NULL; parse_rtype (chunk->return_type, &rtype, &n_star); rlen = strlen (rtype); g_string_append (out, rtype); } else { g_string_append (out, "void"); rlen = 4; } for (guint j = rlen; j < long_ret; j++) g_string_append_c (out, ' '); g_string_append_c (out, ' '); for (guint j = 0; j < long_ret_star - n_star; j++) g_string_append_c (out, ' '); for (guint j = 0; j < n_star; j++) g_string_append_c (out, '*'); g_string_append (out, chunk->identifier); rlen = strlen (chunk->identifier); for (guint j = rlen; j < long_ident; j++) g_string_append_c (out, ' '); g_string_append (out, " ("); space = out->len - off; if (chunk->params == NULL) g_string_append (out, "void"); for (const GSList *iter = chunk->params; iter; iter = iter->next) { Parameter *p = iter->data; if (p->ellipsis) { g_string_append (out, "..."); break; } if (p->type == NULL) { g_warning ("Unexpected NULL value for type"); continue; } g_string_append (out, p->type); for (guint j = strlen (p->type); j < long_ptype; j++) g_string_append_c (out, ' '); g_string_append_c (out, ' '); for (guint j = p->n_star; j < long_star; j++) g_string_append_c (out, ' '); for (guint j = 0; j < p->n_star; j++) g_string_append_c (out, '*'); g_string_append (out, p->name); if (iter->next) { g_string_append (out, ",\n"); for (guint j = 0; j < space; j++) g_string_append_c (out, ' '); } } g_string_append_c (out, ')'); if (chunk->post) g_string_append_printf (out, " %s", chunk->post); g_string_append (out, ";\n"); } return g_string_free (g_steal_pointer (&out), FALSE); }
void cb_user_counter_query_by_prefix (CbUserCounter *counter, sqlite3 *db, const char *prefix, guint max_results, CbUserInfo **results, int *n_results) { char *sql; char *err; guint i; struct { GArray *infos; guint lowest_score; } query_data; g_return_if_fail (CB_IS_USER_COUNTER (counter)); g_return_if_fail (prefix != NULL); g_return_if_fail (results != NULL); g_return_if_fail (max_results > 0); g_return_if_fail (n_results != NULL); query_data.infos = g_array_new (FALSE, TRUE, sizeof (CbUserInfo)); query_data.lowest_score = G_MAXINT; g_array_set_clear_func (query_data.infos, (GDestroyNotify)cb_user_info_destroy); for (i = 0; i < counter->user_infos->len; i ++) { const CbUserInfo *ui = &g_array_index (counter->user_infos, CbUserInfo, i); char *user_name; char *screen_name; gboolean full = query_data.infos->len >= max_results; /* Will already be in the results from the sql query */ if (!ui->changed) continue; if (full && ui->score < query_data.lowest_score) continue; screen_name = g_utf8_strdown (ui->screen_name, -1); user_name = g_utf8_strdown (ui->user_name, -1); if (g_str_has_prefix (screen_name, prefix) || g_str_has_prefix (user_name, prefix)) { CbUserInfo *new_ui; /* Copy user info into result array */ g_array_set_size (query_data.infos, query_data.infos->len + 1); new_ui = &g_array_index (query_data.infos, CbUserInfo, query_data.infos->len - 1); new_ui->user_id = ui->user_id; new_ui->screen_name = g_strdup (ui->screen_name); new_ui->user_name = g_strdup (ui->user_name); new_ui->score = ui->score; query_data.lowest_score = MIN (query_data.lowest_score, ui->score); } g_free (user_name); g_free (screen_name); } if (query_data.infos->len == 0) query_data.lowest_score = -1; sql = g_strdup_printf ("SELECT `id`, `screen_name`, `user_name`, `score` " "FROM `user_cache` WHERE `screen_name` LIKE '%s%%' " "OR `user_name` LIKE '%s%%' ORDER BY `score` DESC LIMIT %d " "COLLATE NOCASE;", prefix, prefix, max_results); sqlite3_exec (db, sql, query_sqlite_cb, &query_data, &err); if (err != NULL) { g_critical ("%s SQL Error: %s", __FUNCTION__, err); sqlite3_free (err); } /* Now sort after score */ g_array_sort (query_data.infos, score_sort); /* Remove everything after max_results */ if (query_data.infos->len > max_results) g_array_remove_range (query_data.infos, max_results, query_data.infos->len - max_results); g_assert (query_data.infos->len <= max_results); /* Just use the GArray's data */ *n_results = query_data.infos->len; *results = (CbUserInfo*) g_array_free (query_data.infos, FALSE); g_free (sql); }
static void _gtk_css_image_linear_init (GtkCssImageLinear *linear) { linear->stops = g_array_new (FALSE, FALSE, sizeof (GtkCssImageLinearColorStop)); g_array_set_clear_func (linear->stops, gtk_css_image_clear_color_stop); }
static gboolean kms_sdp_sdes_ext_add_answer_attributes (KmsISdpMediaExtension * ext, const GstSDPMedia * offer, GstSDPMedia * answer, GError ** error) { GValue key = G_VALUE_INIT; gboolean ret = TRUE, supported; GArray *keys; guint i; if ((gst_sdp_media_get_attribute_val (answer, "keymgt")) != NULL) { /* rfc4568 [7.5] */ /* If the answerer supports both "a=crypto" and "a=keymgt", the answer */ /* MUST include either "a=crypto" or "a=keymgt", but not both. */ return TRUE; } if (answer->key.type != NULL) { /* rfc4568: [7.5] */ /* If the answerer supports both "a=crypto" and "k=", the answer */ /* MUST include either "a=crypto" or "k=" but not both. */ return TRUE; } keys = g_array_sized_new (FALSE, FALSE, sizeof (GValue), 3); /* Sets a function to clear an element of array */ g_array_set_clear_func (keys, (GDestroyNotify) g_value_unset); for (i = 0;; i++) { GValue val = G_VALUE_INIT; const gchar *attr_val; attr_val = gst_sdp_media_get_attribute_val_n (offer, CRYPTO_ATTR, i); if (attr_val == NULL) { break; } if (!kms_sdp_sdes_ext_parse_key_attr (ext, attr_val, &val)) { if (G_IS_VALUE (&val)) { g_value_unset (&val); } continue; } g_array_append_val (keys, val); } if (!ret || keys->len == 0) { goto end; } g_signal_emit (G_OBJECT (ext), obj_signals[SIGNAL_ON_ANSWER_KEYS], 0, keys, &key, &supported); if (!supported) { /* If none of the crypto attributes are valid or none of the valid ones */ /* are supported, the offered media stream MUST be rejected */ GST_WARNING_OBJECT (ext, "Rejecting offer because no crypto attributes are supported"); gst_sdp_media_set_port_info (answer, 0, 1); goto end; } if (!selected_valid_key (keys, &key)) { /* Same tag and crypto-suite must be selected in the answer */ GST_WARNING_OBJECT (ext, "Asnwer key does not match with offered key"); gst_sdp_media_set_port_info (answer, 0, 1); } else { ret = kms_sdp_sdes_ext_add_answer_key (ext, answer, &key, error); } g_value_unset (&key); end: g_array_unref (keys); return ret; }
static void _gtk_css_image_radial_init (GtkCssImageRadial *radial) { radial->stops = g_array_new (FALSE, FALSE, sizeof (GtkCssImageRadialColorStop)); g_array_set_clear_func (radial->stops, gtk_css_image_clear_color_stop); }
static void eos_shard_writer_v1_init (EosShardWriterV1 *self) { self->entries = g_array_new (FALSE, TRUE, sizeof (struct eos_shard_writer_v1_record_entry)); g_array_set_clear_func (self->entries, (GDestroyNotify) eos_shard_writer_v1_record_entry_clear); }
static void ide_clang_service_parse_worker (GTask *task, gpointer source_object, gpointer task_data, GCancellable *cancellable) { g_autoptr(IdeClangTranslationUnit) ret = NULL; g_autoptr(IdeHighlightIndex) index = NULL; g_autoptr(IdeFile) file_copy = NULL; IdeClangService *self = source_object; CXTranslationUnit tu = NULL; ParseRequest *request = task_data; IdeContext *context; const gchar * const *argv; GFile *gfile; gsize argc = 0; const gchar *detail_error = NULL; enum CXErrorCode code; GArray *ar = NULL; gsize i; g_assert (G_IS_TASK (task)); g_assert (IDE_IS_CLANG_SERVICE (source_object)); g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); g_assert (IDE_IS_FILE (request->file)); file_copy = g_object_ref (request->file); ar = g_array_new (FALSE, FALSE, sizeof (struct CXUnsavedFile)); g_array_set_clear_func (ar, clear_unsaved_file); for (i = 0; i < request->unsaved_files->len; i++) { IdeUnsavedFile *iuf = g_ptr_array_index (request->unsaved_files, i); struct CXUnsavedFile uf; GBytes *content; GFile *file; file = ide_unsaved_file_get_file (iuf); content = ide_unsaved_file_get_content (iuf); uf.Filename = g_file_get_path (file); uf.Contents = g_bytes_get_data (content, NULL); uf.Length = g_bytes_get_size (content); g_array_append_val (ar, uf); } argv = (const gchar * const *)request->command_line_args; argc = argv ? g_strv_length (request->command_line_args) : 0; EGG_COUNTER_INC (ParseAttempts); code = clang_parseTranslationUnit2 (request->index, request->source_filename, argv, argc, (struct CXUnsavedFile *)(void *)ar->data, ar->len, request->options, &tu); switch (code) { case CXError_Success: index = ide_clang_service_build_index (self, tu, request); #ifdef IDE_ENABLE_TRACE ide_highlight_index_dump (index); #endif break; case CXError_Failure: detail_error = _("Unknown failure"); break; case CXError_Crashed: detail_error = _("Clang crashed"); break; case CXError_InvalidArguments: detail_error = _("Invalid arguments"); break; case CXError_ASTReadError: detail_error = _("AST read error"); break; default: break; } if (!tu) { g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, _("Failed to create translation unit: %s"), detail_error ? detail_error : ""); goto cleanup; } context = ide_object_get_context (source_object); gfile = ide_file_get_file (request->file); ret = _ide_clang_translation_unit_new (context, tu, gfile, index, request->sequence); g_task_return_pointer (task, g_object_ref (ret), g_object_unref); cleanup: g_array_unref (ar); }