static void ibus_serializable_init (IBusSerializable *object) { IBusSerializablePrivate *priv; priv = IBUS_SERIALIZABLE_GET_PRIVATE (object); priv->attachments = NULL; g_datalist_init (&priv->attachments); }
void _init_source(gpointer key, GQuark source_id, gpointer user_data) { NubeSource *source = g_datalist_id_get_data(&available_sources, source_id); if (!source) { g_printerr("Unknown source: %s\n", g_quark_to_string(source_id)); exit(1); } g_datalist_init(&source->data); source->init_func(source, source->user_data); g_datalist_id_set_data(&used_sources, source_id, source); }
static gboolean gst_object_set_name_default (GstObject * object) { const gchar *type_name; gint count; gchar *name; GQuark q; guint i, l; /* to ensure guaranteed uniqueness across threads, only one thread * may ever assign a name */ G_LOCK (object_name_mutex); if (!object_name_counts) { g_datalist_init (&object_name_counts); } q = g_type_qname (G_OBJECT_TYPE (object)); count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q)); g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count + 1)); G_UNLOCK (object_name_mutex); /* GstFooSink -> foosink<N> */ type_name = g_quark_to_string (q); if (strncmp (type_name, "Gst", 3) == 0) type_name += 3; name = g_strdup_printf ("%s%d", type_name, count); l = strlen (name); for (i = 0; i < l; i++) name[i] = g_ascii_tolower (name[i]); GST_OBJECT_LOCK (object); if (G_UNLIKELY (object->parent != NULL)) goto had_parent; g_free (object->name); object->name = name; GST_OBJECT_UNLOCK (object); return TRUE; had_parent: { g_free (name); GST_WARNING ("parented objects can't be renamed"); GST_OBJECT_UNLOCK (object); return FALSE; } }
inline void gs_set_player(player_t* player) { thread_tls_initonce(&tls_player); thread_tls_set(&tls_player, player); if(!player) { GData* transact_data; thread_tls_initonce(&tls_transact_data); transact_data = (GData*)thread_tls_get(&tls_transact_data); g_datalist_clear(&transact_data); g_datalist_init(&transact_data); thread_tls_set(&tls_transact_data, transact_data); } }
qipu_t * qipu_new () { qipu_t * qipu; qipu = calloc (1, sizeof (qipu_t)); if (qipu == NULL) { acc_err (_ ("Memory error.\n")); return NULL; } g_datalist_init (&qipu->tv_list); return qipu; }
gint main (gint argc, const gchar * const argv[]) { prev_time_set = emtr_util_get_current_time (CLOCK_MONOTONIC, &prev_time); g_datalist_init (&humanity_by_session_id); GDBusProxy *systemd_dbus_proxy = systemd_dbus_proxy_new (); GDBusProxy *login_dbus_proxy = login_dbus_proxy_new (); GDBusProxy *network_dbus_proxy = network_dbus_proxy_new (); GFileMonitor *location_file_monitor = location_file_monitor_new (); GMainLoop *main_loop = g_main_loop_new (NULL, TRUE); g_idle_add ((GSourceFunc) record_location_metric, NULL); g_idle_add ((GSourceFunc) record_os_version, NULL); g_idle_add ((GSourceFunc) increment_boot_count, NULL); g_idle_add ((GSourceFunc) record_live_boot, NULL); g_idle_add ((GSourceFunc) record_image_version, NULL); g_idle_add ((GSourceFunc) record_location_label, NULL); g_idle_add ((GSourceFunc) record_network_id, GINT_TO_POINTER (TRUE)); g_idle_add ((GSourceFunc) record_windows_licenses, NULL); g_timeout_add_seconds (RECORD_UPTIME_INTERVAL_SECONDS / 2, (GSourceFunc) record_uptime, NULL); eins_hwinfo_start (); g_unix_signal_add (SIGHUP, (GSourceFunc) quit_main_loop, main_loop); g_unix_signal_add (SIGINT, (GSourceFunc) quit_main_loop, main_loop); g_unix_signal_add (SIGTERM, (GSourceFunc) quit_main_loop, main_loop); g_unix_signal_add (SIGUSR1, (GSourceFunc) quit_main_loop, main_loop); g_unix_signal_add (SIGUSR2, (GSourceFunc) quit_main_loop, main_loop); g_main_loop_run (main_loop); record_logout_for_all_remaining_sessions (); record_shutdown (); g_main_loop_unref (main_loop); g_clear_object (&systemd_dbus_proxy); g_clear_object (&login_dbus_proxy); g_clear_object (&network_dbus_proxy); g_clear_object (&location_file_monitor); return EXIT_SUCCESS; }
/** * e_import_target_new: * @ep: Parent EImport object. * @type: type, up to implementor * @size: Size of object to allocate. * * Allocate a new import target suitable for this class. Implementing * classes will define the actual content of the target. **/ void *e_import_target_new(EImport *ep, int type, size_t size) { EImportTarget *t; if (size < sizeof(EImportTarget)) { g_warning ("Size less than size of EImportTarget\n"); size = sizeof (EImportTarget); } t = g_malloc0(size); t->import = ep; g_object_ref(ep); t->type = type; g_datalist_init(&t->data); return t; }
static inline struct ipoddisk_node * ipoddisk_new_node (struct ipoddisk_node *parent, gchar *key, ipoddisk_node_type type) { struct ipoddisk_node *node = g_slice_new(struct ipoddisk_node); assert (parent == NULL || key != NULL); node->nd_type = type; if (type != IPODDISK_NODE_LEAF) /* leaf node has no children */ g_datalist_init(&node->nd_children); if (parent != NULL) ipoddisk_add_child(parent, node, key); return node; }
static void static_set_qdata (TpHandleRepoIface *repo, TpHandle handle, GQuark key_id, gpointer data, GDestroyNotify destroy) { TpStaticHandleRepo *self = TP_STATIC_HANDLE_REPO (repo); guint i; g_return_if_fail (handle > 0); g_return_if_fail (handle <= self->last_handle); if (!self->datalists) { self->datalists = g_new (GData *, self->last_handle); for (i = 0; i < self->last_handle; i++) { g_datalist_init (self->datalists + i); } }
double S57_resetScamin(_S57_geo *geo) // reset scamin from att val { return_if_null(geo); if (NULL == geo->attribs) g_datalist_init(&geo->attribs); GString *valstr = S57_getAttVal(geo, "SCAMIN"); //double val = (NULL==valstr) ? INFINITY : S52_atof(valstr->str); double val = (NULL==valstr) ? UNKNOWN : S52_atof(valstr->str); geo->scamin = val; return geo->scamin; //return geo->scamin = (NULL==S57_getAttVal(geo, "SCAMIN")) ? UNKNOWN : S52_atof(valstr->str); }
GncABImExContextImport * gnc_ab_import_context(AB_IMEXPORTER_CONTEXT *context, guint awaiting, gboolean execute_txns, AB_BANKING *api, GtkWidget *parent) { GncABImExContextImport *data = g_new(GncABImExContextImport, 1); g_return_val_if_fail(context, NULL); /* Do not await and ignore at the same time */ g_return_val_if_fail(!(awaiting & AWAIT_BALANCES) || !(awaiting & IGNORE_BALANCES), NULL); g_return_val_if_fail(!(awaiting & AWAIT_TRANSACTIONS) || !(awaiting & IGNORE_TRANSACTIONS), NULL); /* execute_txns must be FALSE if txns are not awaited */ g_return_val_if_fail(awaiting & AWAIT_TRANSACTIONS || !execute_txns, NULL); /* An api is needed for the jobs */ g_return_val_if_fail(!execute_txns || api, NULL); data->awaiting = awaiting; data->txn_found = FALSE; data->execute_txns = execute_txns; data->api = api; data->parent = parent; data->job_list = AB_Job_List2_new(); data->tmp_job_list = NULL; data->generic_importer = NULL; g_datalist_init(&data->tmp_job_list); /* Import transactions */ if (!(awaiting & IGNORE_TRANSACTIONS)) AB_ImExporterContext_AccountInfoForEach(context, txn_accountinfo_cb, data); /* Check balances */ if (!(awaiting & IGNORE_BALANCES)) AB_ImExporterContext_AccountInfoForEach(context, bal_accountinfo_cb, data); return data; }
/** * g_dataset_remove_data: * @l: the location identifying the dataset. * @k: the string identifying the data element. * * Removes a data element corresponding to a string. Its destroy * function is called if it has been set. **/ void g_dataset_id_set_data_full (gconstpointer dataset_location, GQuark key_id, gpointer data, GDestroyNotify destroy_func) { GDataset *dataset; g_return_if_fail (dataset_location != NULL); if (!data) g_return_if_fail (destroy_func == NULL); if (!key_id) { if (data) g_return_if_fail (key_id > 0); else return; } G_LOCK (g_dataset_global); if (!g_dataset_location_ht) g_data_initialize (); dataset = g_dataset_lookup (dataset_location); if (!dataset) { dataset = g_slice_new (GDataset); #ifdef GSTREAMER_LITE if (dataset == NULL) { G_UNLOCK (g_dataset_global); return; } #endif // GSTREAMER_LITE dataset->location = dataset_location; g_datalist_init (&dataset->datalist); g_hash_table_insert (g_dataset_location_ht, (gpointer) dataset->location, dataset); } g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset); G_UNLOCK (g_dataset_global); }
/** * 接收好友文件信息. */ void UdpData::RecvPalFile() { uint32_t packetno, commandno; const char *ptr; pthread_t pid; GData *para; packetno = iptux_get_dec_number(buf, ':', 1); commandno = iptux_get_dec_number(buf, ':', 4); ptr = iptux_skip_string(buf, size, 1); /* 只有当此为共享文件信息或文件信息不为空才需要接收 */ if ((commandno & IPTUX_SHAREDOPT) || (ptr && *ptr != '\0')) { para = NULL; g_datalist_init(¶); g_datalist_set_data(¶, "palinfo", cthrd.GetPalFromList(ipv4)); g_datalist_set_data_full(¶, "extra-data", g_strdup(ptr), GDestroyNotify(g_free)); g_datalist_set_data(¶, "packetno", GUINT_TO_POINTER(packetno)); g_datalist_set_data(¶, "commandno", GUINT_TO_POINTER(commandno)); pthread_create(&pid, NULL, ThreadFunc(RecvFile::RecvEntry), para); pthread_detach(pid); } }
GData *S57_setAtt(_S57_geo *geoData, const char *name, const char *val) { return_if_null(geoData); return_if_null(name); return_if_null(val); GQuark qname = g_quark_from_string(name); GString *value = g_string_new(val); if (NULL == geoData->attribs) g_datalist_init(&geoData->attribs); #ifdef S52_USE_SUPP_LINE_OVERLAP //if ((0==S52_strncmp(S57_getName(geoData), "Edge", 4)) && (0==S52_strncmp(name, "RCID", 4))) { if ((0==g_strcmp0(S57_getName(geoData), "Edge")) && (0==g_strcmp0(name, "RCID"))) { geoData->rcidstr = value; } #endif g_datalist_id_set_data_full(&geoData->attribs, qname, value, _string_free); return geoData->attribs; }
static gboolean crank_composite_def_add_compositable (CrankComposite *composite, CrankCompositable *compositable, GError **error) { CrankCompositePrivate *priv = crank_composite_get_instance_private (composite); guint i; // First check a compositable is already. if (crank_composite_contains_compositable (composite, compositable)) { g_set_error (error, CRANK_COMPOSITE_ERROR, CRANK_COMPOSITE_ERROR_ALREADY_HAS_COMPOSITABLE, "Compositable is already added to compositable.\n" "%s@%p <= %s@%p", G_OBJECT_TYPE_NAME (composite), composite, G_OBJECT_TYPE_NAME (compositable), compositable); return FALSE; } // Do adding else if (crank_compositable_adding (compositable, composite, error)) { Percompositable percompositable; percompositable.compositable = g_object_ref_sink (compositable); g_datalist_init (& percompositable.dictionary); g_array_append_val (priv->data, percompositable); g_object_notify_by_pspec ((GObject*)composite, pspecs[PROP_NCOMPOSITABLES]); return TRUE; } else { return FALSE; } }
static guint gfire_sq_gamespy2_parseInfo(gfire_sq_gamespy2_data *p_gsdata, const unsigned char *p_data, guint p_len) { guint pos = 0; g_datalist_init(&p_gsdata->info); while(pos < p_len) { int keylen = strlen((const char*)p_data + pos); if(!keylen) break; const char *key = (const char*)p_data + pos; pos += keylen + 1; const char *value = (const char*)p_data + pos; pos += strlen((const char*)p_data + pos) + 1; g_datalist_set_data_full(&p_gsdata->info, key, g_strdup(value), g_free); } return pos + 2; }
static gboolean gst_object_set_name_default (GstObject * object) { const gchar *type_name; gint count; gchar *name, *tmp; gboolean result; GQuark q; /* to ensure guaranteed uniqueness across threads, only one thread * may ever assign a name */ G_LOCK (object_name_mutex); if (!object_name_counts) { g_datalist_init (&object_name_counts); } q = g_type_qname (G_OBJECT_TYPE (object)); count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q)); g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count + 1)); G_UNLOCK (object_name_mutex); /* GstFooSink -> foosinkN */ type_name = g_quark_to_string (q); if (strncmp (type_name, "Gst", 3) == 0) type_name += 3; tmp = g_strdup_printf ("%s%d", type_name, count); name = g_ascii_strdown (tmp, -1); g_free (tmp); result = gst_object_set_name (object, name); g_free (name); return result; }
void _tarif_rebuild(gint tarif_id, GSList ** tarif) { gchar *cmd = NULL; sqlite3_stmt *stmt = NULL; GSList *link = NULL; g_assert(tarif_id > 0 && tarif != NULL); _tarif_clear(tarif_id); cmd = sqlite3_mprintf("select id, days, stime, hourprice from tarifs\n" "where tarif = %d;", tarif_id); sqlite3_prepare(ccl->db, cmd, -1, &stmt, NULL); sqlite3_free(cmd); while (sqlite3_step(stmt) == SQLITE_ROW) { CCL_tarifpart *part = NULL; guint days = sqlite3_column_double(stmt, 1); guint hour = 0; guint min = 0; guint stime = 0; gint i; gchar *cmd2 = NULL; sqlite3_stmt *stmt2 = NULL; GData ** prices = g_malloc0(sizeof(GData *)); gint id = 0; id = sqlite3_column_int(stmt, 0); /* Load prices */ g_datalist_init(prices); cmd2 = sqlite3_mprintf("select mins, price from prices\n" "where tarifpart = %d;", id); sqlite3_prepare(ccl->db, cmd2, -1, &stmt2, NULL); sqlite3_free(cmd2); while (sqlite3_step(stmt2) == SQLITE_ROW) { gint mins; guint price; mins = sqlite3_column_int(stmt2, 0); price = sqlite3_column_double(stmt2, 1); g_datalist_id_set_data(prices, mins, GINT_TO_POINTER(price)); } sqlite3_finalize(stmt2); /* Add tarifpart */ sscanf((gchar *) sqlite3_column_text(stmt, 2), "%u:%u", &hour, &min); stime = hour * 60 + min; for (i = 0; i < 7; i++) { if ((1 << i) & days) { part = g_new0(CCL_tarifpart, 1); part->stime = stime + i * 24 * 60; part->id = sqlite3_column_int(stmt, 0); part->hprice = sqlite3_column_double(stmt, 3); part->prices = prices; *tarif = g_slist_insert_sorted(*tarif, part, _TarifCompareFunc); } } } sqlite3_finalize(stmt); /* Now i am going to remove unnessesary links to clean things */ link = *tarif; while (link) { GSList *nextlink = g_slist_next(link); CCL_tarifpart *part = (CCL_tarifpart *) link->data; if (!nextlink) link = NULL; else if (((CCL_tarifpart *) nextlink->data)->id == part->id) { *tarif = g_slist_remove_link(*tarif, nextlink); g_free(nextlink->data); nextlink->data = NULL; g_slist_free_1(nextlink); } else link = nextlink; } /* If the first link in the list does not start on sunday at 00:00 * * insert the last one there, so things don't broke on calculation */ if (*tarif && 0 != ((CCL_tarifpart *) (*tarif)->data)->stime) { CCL_tarifpart *newpart = g_new0(CCL_tarifpart, 1); CCL_tarifpart *lastpart = NULL; GSList *link = *tarif; while (link->next) link = link->next; lastpart = (CCL_tarifpart *) link->data; newpart->id = lastpart->id; newpart->hprice = lastpart->hprice; newpart->stime = 0; newpart->prices = lastpart->prices; *tarif = g_slist_prepend(*tarif, newpart); } /* add it to the list */ g_datalist_id_set_data(&ccl->tarifs, tarif_id, *tarif); }
GScanner* g_scanner_new (const GScannerConfig *config_templ) { GScanner *scanner; if (!config_templ) config_templ = &g_scanner_config_template; scanner = g_new0 (GScanner, 1); scanner->user_data = NULL; scanner->max_parse_errors = 0; scanner->parse_errors = 0; scanner->input_name = NULL; g_datalist_init (&scanner->qdata); scanner->config = g_new0 (GScannerConfig, 1); scanner->config->case_sensitive = config_templ->case_sensitive; scanner->config->cset_skip_characters = config_templ->cset_skip_characters; if (!scanner->config->cset_skip_characters) scanner->config->cset_skip_characters = ""; scanner->config->cset_identifier_first = config_templ->cset_identifier_first; scanner->config->cset_identifier_nth = config_templ->cset_identifier_nth; scanner->config->cpair_comment_single = config_templ->cpair_comment_single; scanner->config->skip_comment_multi = config_templ->skip_comment_multi; scanner->config->skip_comment_single = config_templ->skip_comment_single; scanner->config->scan_comment_multi = config_templ->scan_comment_multi; scanner->config->scan_identifier = config_templ->scan_identifier; scanner->config->scan_identifier_1char = config_templ->scan_identifier_1char; scanner->config->scan_identifier_NULL = config_templ->scan_identifier_NULL; scanner->config->scan_symbols = config_templ->scan_symbols; scanner->config->scan_binary = config_templ->scan_binary; scanner->config->scan_octal = config_templ->scan_octal; scanner->config->scan_float = config_templ->scan_float; scanner->config->scan_hex = config_templ->scan_hex; scanner->config->scan_hex_dollar = config_templ->scan_hex_dollar; scanner->config->scan_string_sq = config_templ->scan_string_sq; scanner->config->scan_string_dq = config_templ->scan_string_dq; scanner->config->numbers_2_int = config_templ->numbers_2_int; scanner->config->int_2_float = config_templ->int_2_float; scanner->config->identifier_2_string = config_templ->identifier_2_string; scanner->config->char_2_token = config_templ->char_2_token; scanner->config->symbol_2_token = config_templ->symbol_2_token; scanner->config->scope_0_fallback = config_templ->scope_0_fallback; scanner->token = G_TOKEN_NONE; scanner->value.v_int = 0; scanner->line = 1; scanner->position = 0; scanner->next_token = G_TOKEN_NONE; scanner->next_value.v_int = 0; scanner->next_line = 1; scanner->next_position = 0; scanner->symbol_table = g_hash_table_new (g_scanner_key_hash, g_scanner_key_equal); scanner->input_fd = -1; scanner->text = NULL; scanner->text_end = NULL; scanner->buffer = NULL; scanner->scope_id = 0; scanner->msg_handler = g_scanner_msg_handler; return scanner; }
static void ServerPool_Init () { g_datalist_init (&connectionPool); }
/** * 类构造函数. */ SoundSystem::SoundSystem():eltset(NULL), persist(false) { g_datalist_init(&eltset); gettimeofday(×tamp, NULL); }
void scripts_load() { GSList* dir; GList* s; unsigned i; char path[PATH_MAX]; if (!scriptdata) { g_datalist_init(&scriptdata); } /* g_datalist_get_data(&scriptdata, "foo"); g_datalist_set_data_full(&scriptdata,"foo",value,g_free); */ for (dir = scriptdirs; dir; dir = g_slist_next(dir)) { GList* s = dir_to_list(dir->data, script_filter); scripts = merge_sorted_string_lists(scripts, s); } for (s = scripts; s; s = g_list_next(s)) { unsigned version; config_section_iterator* sit; Script* script; const char* filename = s->data; char* errtitle = _("Script error"); // already known? if (g_datalist_get_data(&scriptdata, filename)) { continue; } script = script_new(); snprintf(path, sizeof(path), "/scripts/%s/General", filename); config_push_prefix(path); version = config_get_int("xqf version"); script->summary = config_get_string("summary"); script->author = config_get_string("author"); script->license = config_get_string("license"); config_pop_prefix(); if (version > MAX_SCRIPT_VERSION) { dialog_ok(errtitle, _("Script %s has version %d, xqf only supports version %d."), filename, version, MAX_SCRIPT_VERSION); script_free(script); continue; } if (!script->summary) { dialog_ok(errtitle, _("Script %s missing summary."), filename); script_free(script); continue; } if (!script->author) { dialog_ok(errtitle, _("Script %s missing author."), filename); script_free(script); continue; } if (!script->license) { dialog_ok(errtitle, _("Script %s missing license."), filename); script_free(script); continue; } script->name = g_strdup(filename); snprintf(path, sizeof(path), "/scripts/%s/Action", filename); config_push_prefix(path); for (i = 0; i < NUM_ACTIONS; ++i) { gboolean on = config_get_bool(action_key[i]); if (on) { action[i] = g_slist_prepend(action[i], script); } } config_pop_prefix(); // treat script property 'enabled' as option as it has a widget // so it's easier to handle later { ScriptOption* opt; snprintf(path, sizeof(path), "/" CONFIG_FILE "/scripts/%s/enabled=false", filename); opt = scriptoption_new("bool"); opt->enable = config_get_bool(path); // Translator: whether this plugin script is enabled opt->name = _("Enabled"); opt->section = g_strdup("enabled"); script->options = g_slist_prepend(script->options, opt); } snprintf(path, sizeof(path), "/scripts/%s", filename); sit = config_init_section_iterator(path); while (sit) { char* sname = NULL; sit = config_section_iterator_next(sit, &sname); if (strlen(sname) > 7 && !strncmp(sname, "option ", 7)) { char* typestr; char* name; ScriptOption* opt; char settings_path[PATH_MAX]; snprintf(settings_path, sizeof(settings_path), "/" CONFIG_FILE "/scripts/%s/%s", filename, sname); snprintf(path, sizeof(path), "/scripts/%s/%s", filename, sname); config_push_prefix(path); typestr = config_get_string("type"); name = config_get_string("name"); opt = scriptoption_new(typestr); g_free(typestr); if (!opt || !name) { xqf_warning("script %s: invalid option %s", filename, sname+7); goto next; } opt->name = name; opt->section = sname; switch(opt->type) { case SCRIPT_OPTION_TYPE_LIST: { config_key_iterator* it; it = config_init_iterator(path); if (!opt->list) { opt->list = g_ptr_array_new(); } while (it) { char* key = NULL; char* val = NULL; it = config_iterator_next(it, &key, &val); if (!strncmp(key, "value",5)) { g_ptr_array_add(opt->list, val); } else { g_free(val); } g_free(key); } } // fall through case SCRIPT_OPTION_TYPE_STRING: case SCRIPT_OPTION_TYPE_INT: { char* defval = NULL; char* curval = NULL; defval = config_get_string("default"); curval = config_get_string(settings_path); if (curval) { opt->defval = g_strdup(curval); } else if (defval) { opt->defval = g_strdup(defval); } g_free(defval); g_free(curval); } break; case SCRIPT_OPTION_TYPE_BOOL: { gboolean defval; gboolean curval; int is_deflt = 0; defval = config_get_bool("default=false"); curval = config_get_bool_with_default(settings_path, &is_deflt); if (is_deflt) { opt->enable = defval; } else { opt->enable = curval; } } break; case SCRIPT_OPTION_TYPE_INVALID: xqf_error("unreachable code"); break; } script->options = g_slist_prepend(script->options, opt); next: config_pop_prefix(); } } script->options = g_slist_reverse(script->options); g_datalist_set_data_full(&scriptdata, filename, script, (GDestroyNotify)script_free); snprintf(path, sizeof(path), "/scripts/%s", filename); config_drop_file(path); } }
static gboolean gfire_sq_ase_parse(gfire_game_server *p_server, guint16 p_ping, gboolean p_full, const unsigned char *p_data, guint p_len) { if(memcmp(p_data, "EYE1", 4) != 0) return FALSE; gfire_sq_ase_data *data = g_new0(gfire_sq_ase_data, 1); guint offset = 4; gchar *tempstr; // General server data data->game_name = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!data->game_name) goto error; tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!tempstr) goto error; data->game_port = atoi(tempstr); g_free(tempstr); data->server_name = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!data->server_name) goto error; data->game_type = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!data->game_type) goto error; data->map = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!data->map) goto error; data->version = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!data->version) goto error; tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!tempstr) goto error; data->password = (*tempstr == '1'); g_free(tempstr); tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!tempstr) goto error; data->num_players = atoi(tempstr); g_free(tempstr); tempstr = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!tempstr) goto error; data->max_players = atoi(tempstr); g_free(tempstr); // Server rules g_datalist_init(&data->rules); while(1) { gchar *key = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!key) break; gchar *value = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, FALSE)); if(!value) { g_free(key); goto error; } g_datalist_set_data_full(&data->rules, key, value, g_free); g_free(key); } // Players while(p_len > offset) { gfire_sq_ase_player *player = g_new0(gfire_sq_ase_player, 1); guint8 flags = *(p_data + offset++); if(flags & 1) { player->name = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE)); if(!player->name) { free_ase_player(player); break; } } if(flags & 2) { player->team = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE)); if(!player->team) { free_ase_player(player); break; } } if(flags & 4) { player->skin = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE)); if(!player->skin) { free_ase_player(player); break; } } if(flags & 8) { player->score = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE)); if(!player->score) { free_ase_player(player); break; } } if(flags & 16) { player->ping = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE)); if(!player->ping) { free_ase_player(player); break; } } if(flags & 32) { player->time = gfire_strip_invalid_utf8(parse_string(p_data, p_len, &offset, TRUE)); if(!player->time) { free_ase_player(player); break; } } data->players = g_slist_append(data->players, player); } // Hack for some servers... if(g_datalist_get_data(&data->rules, "numplayers")) data->num_players = atoi(g_datalist_get_data(&data->rules, "numplayers")); // Copy values into the standard container p_server->data = g_new0(gfire_game_server_data, 1); p_server->data->driver = &gf_sq_ase_driver; p_server->data->proto_data = data; p_server->data->name = gfire_sq_ase_strip_color_codes(data->server_name); p_server->data->map = g_strdup(data->map); p_server->data->players = data->num_players; p_server->data->max_players = data->max_players; p_server->data->ping = p_ping; // No more packets to request! return FALSE; error: free_ase_data(data); return FALSE; }
static void instance_init( GbdX11emitter* self ) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE( self,GBD_TYPE_X11EMITTER,GbdX11emitterPrivate ); g_datalist_init( &self->priv->mapcache ); self->priv->dpy = GDK_SCREEN_XDISPLAY( gdk_screen_get_default( ) ); }
static void _set_name (GESTimelineElement * self, const gchar * wanted_name) { const gchar *type_name; gchar *lowcase_type; gint count; GQuark q; guint i, l; gchar *name = NULL; if (!object_name_counts) { g_datalist_init (&object_name_counts); } q = g_type_qname (G_OBJECT_TYPE (self)); count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q)); /* GstFooSink -> foosink<N> */ type_name = g_quark_to_string (q); if (strncmp (type_name, "GES", 3) == 0) type_name += 3; lowcase_type = g_strdup (type_name); l = strlen (lowcase_type); for (i = 0; i < l; i++) lowcase_type[i] = g_ascii_tolower (lowcase_type[i]); if (wanted_name == NULL) { /* give the 20th "uriclip" element and the first "uriclip2" (if needed in the future) * different names */ l = strlen (type_name); if (l > 0 && g_ascii_isdigit (type_name[l - 1])) { name = g_strdup_printf ("%s-%d", lowcase_type, count++); } else { name = g_strdup_printf ("%s%d", lowcase_type, count++); } } else { /* If the wanted name uses the same 'namespace' as default, make * sure it does not badly interfere with our counting system */ if (g_str_has_prefix (wanted_name, lowcase_type)) { guint64 tmpcount = g_ascii_strtoull (&wanted_name[strlen (lowcase_type)], NULL, 10); if (tmpcount > count) { count = tmpcount + 1; GST_DEBUG_OBJECT (self, "Using same naming %s but updated count to %i", wanted_name, count); } else if (tmpcount < count) { name = g_strdup_printf ("%s%d", lowcase_type, count); count++; GST_DEBUG_OBJECT (self, "Name %s already allocated, giving: %s instead" " New count is %i", wanted_name, name, count); } else { count++; GST_DEBUG_OBJECT (self, "Perfect name, just bumping object count"); } } if (name == NULL) name = g_strdup (wanted_name); } g_free (lowcase_type); g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count)); g_free (self->name); self->name = name; }