static void read_callback(void* user_data, gchar* line) { struct read_context* rc = (struct read_context*)user_data; if (rc->state == 0) { if (memcmp(line, "InfoKey: ", 9) == 0) { rc->state = 1; rc->key = g_strdup(line + 9); } } else { if (memcmp(line, "InfoValue: ", 11) == 0) { rc->state = 0; gchar* value = g_strdup(line + 11); g_datalist_set_data_full(&rc->result, rc->key, value, g_free); g_free(rc->key); rc->key = NULL; } } }
static gboolean gfire_sq_gamespy_parse_chunk(gfire_sq_gamespy_data *p_sq_data, GData **p_datalist, const unsigned char *p_data, guint p_len, gboolean *p_done) { if(*p_data != '\\') return FALSE; // Make sure the data is zero-terminated gchar *strdata = g_strndup((const gchar*)p_data, p_len); // Parse all key/value pairs gboolean final = FALSE; gchar **chunks = g_strsplit(strdata + 1, "\\", -1); g_free(strdata); gchar **cur = chunks; while(*cur) { gchar *key = *cur++; if(g_strcmp0(key, "final") == 0) final = TRUE; else if(!strlen(key)) break; gchar *value = *cur++; if(!value) break; g_datalist_set_data_full(p_datalist, key, g_strdup(gfire_strip_invalid_utf8(value)), g_free); }
static gboolean gfire_sq_savage_parse(gfire_game_server *p_server, guint16 p_ping, gboolean p_full, const unsigned char *p_data, guint p_len) { static guint8 check[] = { 0x9e, 0x4c, 0x23, 0x00, 0x00, 0xcf }; if(p_len < 12 || memcmp(p_data, check, 6) != 0 || memcmp(p_data + 7, "GFSQ", 4) != 0) return FALSE; p_server->data = g_new0(gfire_game_server_data, 1); p_server->data->driver = &gf_sq_savage_driver; p_server->data->ping = p_ping; gfire_sq_savage_data *gsdata = p_server->data->proto_data = g_new0(gfire_sq_savage_data, 1); g_datalist_init(&gsdata->info); // Parse const gchar *section = (const gchar*)p_data + 12; guint offset = 0; while(offset < p_len) { gchar **chunks = g_strsplit(section, "\xff", -1); gchar **pos = chunks; while(*pos) { char **pieces = g_strsplit(*pos, "\xfe", -1); if(g_strv_length(pieces) != 2) { g_strfreev(pieces); pos++; continue; } if(g_strcmp0(pieces[0], "players") == 0) gsdata->players = g_strsplit(pieces[1], "\n", -1); else g_datalist_set_data_full(&gsdata->info, pieces[0], g_strdup(pieces[1]), g_free); g_strfreev(pieces); pos++; } g_strfreev(chunks); offset += strlen(section) + 1; section = (const gchar*)p_data + offset + 2; // skip 0x00 and 0xff } if(g_datalist_get_data(&gsdata->info, "name")) p_server->data->name = gfire_sq_savage_strip_color_codes(g_datalist_get_data(&gsdata->info, "name")); if(g_datalist_get_data(&gsdata->info, "world")) p_server->data->map = g_strdup(g_datalist_get_data(&gsdata->info, "world")); if(g_datalist_get_data(&gsdata->info, "cnum")) sscanf(g_datalist_get_data(&gsdata->info, "cnum"), "%u", &p_server->data->players); if(g_datalist_get_data(&gsdata->info, "cmax")) sscanf(g_datalist_get_data(&gsdata->info, "cmax"), "%u", &p_server->data->max_players); return FALSE; }
static void primary_selection_changed_cb (ESourceSelector *selector, EImportTarget *target) { g_datalist_set_data_full ( &target->data, "vcard-source", g_object_ref (e_source_selector_get_primary_selection (selector)), g_object_unref); }
int qipu_set_info (qipu_t *qipu, const char *token, const char *value) { gpointer data; data = g_strdup (value); g_datalist_set_data_full (&qipu->tv_list, token, data, free); return 0; }
static guint64 get_code( GbdEmitter* _self,gchar* key ) { GbdX11emitter* const self = GBD_X11EMITTER( _self ); GbdX11emitterPrivate* const priv = self->priv; if( !priv->srcdata ) { GFile* file = g_file_new_for_path( GBD_X11EMITTER_SRC ); if( !load_file( self,file,NULL ) ) { g_critical( "GBoard X11-Emitter could not parse X11 keysymdef.h at " GBD_X11EMITTER_SRC ); return 0; } g_object_unref( file ); } guint64* code,symval = 0; if( ( code = g_datalist_get_data( &priv->mapcache,key ) ) ) return *code; else code = g_malloc( sizeof( guint64 ) ); g_seekable_seek( G_SEEKABLE( priv->srcstream ),0,G_SEEK_SET,NULL,NULL ); GDataInputStream* dis = priv->srcdata; gchar* line; gsize len = strlen( key ); gchar* keytoken = g_malloc( sizeof( gchar )*len+sizeof( KEYDEF_PREFIX )+1 ); sprintf( keytoken,KEYDEF_PREFIX "%s",key ); len = strlen( keytoken ); GError* err = NULL; while( line = g_data_input_stream_read_line( dis,NULL,NULL,&err ) ) { if( !strncmp( keytoken,line,len )&& g_ascii_isspace( line[ len ] ) ) { if( sscanf( line+len," %" G_GINT64_MODIFIER "x ",&symval ) ) { g_free( line ); break; } } g_free( line ); } if( err ) { g_error( "%s",err->message ); g_error_unref( &err ); } if( symval ) { guint64 codeval = XKeysymToKeycode( priv->dpy,symval ); *code = codeval; g_datalist_set_data_full( &priv->mapcache,key,code,g_free ); if( !codeval ) g_warning( "Could not find code for key '%s', Keysym-Value " G_GINT64_FORMAT,key,symval ); return codeval; } return 0; }
static GtkWidget * csv_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im) { EShell *shell; GtkWidget *vbox, *selector, *scrolled_window; ESourceRegistry *registry; ESource *primary; const gchar *extension_name; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); shell = e_shell_get_default (); registry = e_shell_get_registry (shell); extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK; scrolled_window = gtk_scrolled_window_new (NULL, NULL); g_object_set (G_OBJECT (scrolled_window), "hscrollbar-policy", GTK_POLICY_AUTOMATIC, "vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL); gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 6); selector = e_source_selector_new (registry, extension_name); e_source_selector_set_show_toggles ( E_SOURCE_SELECTOR (selector), FALSE); gtk_container_add (GTK_CONTAINER (scrolled_window), selector); primary = g_datalist_get_data (&target->data, "csv-source"); if (primary == NULL) { GList *list; list = e_source_registry_list_sources (registry, extension_name); if (list != NULL) { primary = g_object_ref (list->data); g_datalist_set_data_full ( &target->data, "csv-source", primary, (GDestroyNotify) g_object_unref); } g_list_free_full (list, (GDestroyNotify) g_object_unref); } e_source_selector_set_primary_selection ( E_SOURCE_SELECTOR (selector), primary); g_signal_connect ( selector, "primary_selection_changed", G_CALLBACK (primary_selection_changed_cb), target); gtk_widget_show_all (vbox); return vbox; }
/** * camel_url_set_param: * @url: a #CamelURL * @name: name of the param to set * @value: value of the param to set * * Set a param on the #CamelURL. **/ void camel_url_set_param (CamelURL *url, const gchar *name, const gchar *value) { g_return_if_fail (url != NULL); if (value) g_datalist_set_data_full (&url->params, name, g_strdup (value), g_free); else g_datalist_remove_data (&url->params, name); }
static void primary_selection_changed_cb (ESourceSelector *selector, EImportTarget *target) { ESource *source; source = e_source_selector_ref_primary_selection (selector); g_return_if_fail (source != NULL); g_datalist_set_data_full ( &target->data, "csv-source", source, (GDestroyNotify) g_object_unref); }
static void gnome_calendar_import (EImport *ei, EImportTarget *target, EImportImporter *im) { icalcomponent *icalcomp = NULL; gchar *filename; gint do_calendar, do_tasks; ICalIntelligentImporter *ici; /* This is pretty shitty, everything runs in the gui thread and can block * for quite some time */ do_calendar = GPOINTER_TO_INT (g_datalist_get_data (&target->data, "gnomecal-do-cal")); do_tasks = GPOINTER_TO_INT (g_datalist_get_data (&target->data, "gnomecal-do-tasks")); /* If neither is selected, just return. */ if (!do_calendar && !do_tasks) return; /* Load the Gnome Calendar file and convert to iCalendar. */ filename = g_build_filename (g_get_home_dir (), "user-cal.vcf", NULL); icalcomp = load_vcalendar_file (filename); g_free (filename); /* If we couldn't load the file, just return. FIXME: Error message? */ if (icalcomp) { ici = g_malloc0 (sizeof (*ici)); ici->ei = ei; ici->target = target; ici->cancellable = g_cancellable_new (); ici->icalcomp = icalcomp; g_datalist_set_data_full (&target->data, "gnomecal-data", ici, free_ici); prepare_events (ici->icalcomp, &ici->tasks); if (do_calendar) { open_default_source (ici, E_CAL_CLIENT_SOURCE_TYPE_EVENTS, gc_import_events); return; } prepare_tasks (ici->icalcomp, ici->tasks); if (do_tasks) { open_default_source (ici, E_CAL_CLIENT_SOURCE_TYPE_TASKS, gc_import_tasks); return; } } e_import_complete (ei, target); }
/** * 创建待接收文件区域. * @return 主窗体 */ GtkWidget *DialogPeer::CreateFileToReceiveArea() { GtkWidget *frame, *hbox, *vbox, *button ,*pbar, *sw, *treeview; GtkTreeModel *model; frame = gtk_frame_new(_("File to be receive.")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); pbar = gtk_progress_bar_new(); g_datalist_set_data(&widset, "file-receive-progress-bar-widget", pbar); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pbar),_("Receiving progress.")); hbox = gtk_hbox_new(FALSE,1); gtk_box_pack_start(GTK_BOX(hbox),pbar,TRUE,TRUE,0); button = gtk_button_new_with_label(_("Accept")); g_signal_connect_swapped(button, "clicked", G_CALLBACK(ReceiveFile), this); g_datalist_set_data(&widset, "file-receive-accept-button", button); gtk_box_pack_start(GTK_BOX(hbox),button,FALSE,TRUE,0); button = gtk_button_new_with_label(_("Refuse")); gtk_box_pack_start(GTK_BOX(hbox),button,FALSE,TRUE,0); g_signal_connect_swapped(button, "clicked", G_CALLBACK(RemoveSelectedRcv), this); g_datalist_set_data(&widset, "file-receive-refuse-button", button); button = gtk_button_new_with_label(_("Detial")); gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0); g_signal_connect_swapped(button, "clicked", G_CALLBACK(OpenTransDlg), NULL); vbox = gtk_vbox_new(FALSE,0); gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); model = CreateFileToReceiveModel(); g_datalist_set_data_full(&mdlset, "file-to-receive-model", model, GDestroyNotify(g_object_unref)); treeview = CreateFileToReceiveTree(model); g_datalist_set_data(&widset, "file-to-receive-treeview-widget", treeview); g_object_set_data(G_OBJECT(treeview), "dialog", this); gtk_container_add(GTK_CONTAINER(sw), treeview); gtk_box_pack_end(GTK_BOX(vbox),sw,TRUE,TRUE,0); gtk_container_add(GTK_CONTAINER(frame), vbox); return frame; }
/** * 创建已接收文件区域. * @return 主窗体 */ GtkWidget *DialogPeer::CreateFileReceivedArea() { GtkWidget *frame, *sw, *treeview; GtkTreeModel *model; frame = gtk_frame_new(_("File received.")); gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN); sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); model = CreateFileReceivedModel(); g_datalist_set_data_full(&mdlset, "file-received-model", model, GDestroyNotify(g_object_unref)); treeview = CreateFileReceivedTree(model); g_datalist_set_data(&widset, "file-received-treeview-widget", treeview); g_object_set_data(G_OBJECT(treeview), "dialog", this); gtk_container_add(GTK_CONTAINER(sw), treeview); gtk_container_add(GTK_CONTAINER(frame), sw); return frame; }
static GtkWidget * vcard_getwidget (EImport *ei, EImportTarget *target, EImportImporter *im) { GtkWidget *vbox, *selector; ESource *primary; ESourceList *source_list; /* FIXME Better error handling */ if (!e_book_client_get_sources (&source_list, NULL)) return NULL; vbox = gtk_vbox_new (FALSE, FALSE); selector = e_source_selector_new (source_list); e_source_selector_show_selection (E_SOURCE_SELECTOR (selector), FALSE); gtk_box_pack_start (GTK_BOX (vbox), selector, FALSE, TRUE, 6); primary = g_datalist_get_data(&target->data, "vcard-source"); if (primary == NULL) { primary = e_source_list_peek_source_any (source_list); g_object_ref (primary); g_datalist_set_data_full ( &target->data, "vcard-source", primary, (GDestroyNotify) g_object_unref); } e_source_selector_set_primary_selection ( E_SOURCE_SELECTOR (selector), primary); g_object_unref (source_list); g_signal_connect ( selector, "primary_selection_changed", G_CALLBACK (primary_selection_changed_cb), target); gtk_widget_show_all (vbox); return vbox; }
static void button_toggled_cb (GtkWidget *widget, struct _selector_data *sd) { ESourceSelector *selector; ESource *source; GtkNotebook *notebook; selector = E_SOURCE_SELECTOR (sd->selector); source = e_source_selector_ref_primary_selection (selector); g_return_if_fail (source != NULL); g_datalist_set_data_full ( &sd->target->data, "primary-source", source, (GDestroyNotify) g_object_unref); g_datalist_set_data ( &sd->target->data, "primary-type", GINT_TO_POINTER (import_type_map[sd->page])); notebook = GTK_NOTEBOOK (sd->notebook); gtk_notebook_set_current_page (notebook, sd->page); }
/** * 接收好友文件信息. */ 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); } }
/** * 初始化声音系统. */ void SoundSystem::InitSublayer() { GstElement *pipeline; GstElement *filesrc, *decode, *volume, *convert, *sink; GstBus *bus; gst_init(NULL, NULL); pipeline = gst_pipeline_new("sound-system"); g_datalist_set_data_full(&eltset, "pipeline-element", pipeline, GDestroyNotify(gst_object_unref)); filesrc = gst_element_factory_make("filesrc", "source"); g_datalist_set_data(&eltset, "filesrc-element", filesrc); decode = gst_element_factory_make("decodebin", "decode"); g_datalist_set_data(&eltset, "decode-element", decode); volume = gst_element_factory_make("volume", "volume"); g_datalist_set_data(&eltset, "volume-element", volume); convert = gst_element_factory_make("audioconvert", "convert"); g_datalist_set_data(&eltset, "convert-element", convert); sink = gst_element_factory_make("autoaudiosink", "output"); g_datalist_set_data(&eltset, "output-element", sink); gst_bin_add_many(GST_BIN(pipeline), filesrc, decode, volume, convert, sink, NULL); gst_element_link_many(filesrc, decode, NULL); gst_element_link_many(volume, convert, sink, NULL); g_signal_connect_swapped(decode, "pad-added", G_CALLBACK(LinkElement), &eltset); bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline)); gst_bus_add_signal_watch(GST_BUS(bus)); g_signal_connect_swapped(bus, "message::error", G_CALLBACK(ErrorMessageOccur), this); g_signal_connect_swapped(bus, "message::eos", G_CALLBACK(EosMessageOccur), this); gst_object_unref(bus); g_object_set(volume, "volume", progdt.volume, NULL); }
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; }
/** * camel_url_new_with_base: * @base: a base URL * @url_string: the URL * * Parses @url_string relative to @base. * * Returns: a parsed #CamelURL **/ CamelURL * camel_url_new_with_base (CamelURL *base, const gchar *url_string) { CamelURL *url; const gchar *end, *hash, *colon, *semi, *at, *slash, *question; const gchar *p; #ifdef G_OS_WIN32 const gchar *start = url_string; #endif g_return_val_if_fail (url_string != NULL, NULL); url = g_new0 (CamelURL, 1); /* See RFC1808 for details. IF YOU CHANGE ANYTHING IN THIS * FUNCTION, RUN tests/misc/url AFTERWARDS. */ /* Find fragment. RFC 1808 2.4.1 */ end = hash = strchr (url_string, '#'); if (hash) { if (hash[1]) { url->fragment = g_strdup (hash + 1); camel_url_decode (url->fragment); } } else end = url_string + strlen (url_string); /* Find protocol: initial [a-z+.-]* substring until ":" */ p = url_string; while (p < end && (isalnum ((guchar) * p) || *p == '.' || *p == '+' || *p == '-')) p++; if (p > url_string && *p == ':') { url->protocol = g_strndup (url_string, p - url_string); camel_strdown (url->protocol); url_string = p + 1; } if (!*url_string && !base) return url; #ifdef G_OS_WIN32 if (url->protocol && !strcmp (url->protocol, "file")) { url->path = g_filename_from_uri (start, &url->host, NULL); return url; } #endif /* Check for authority */ if (strncmp (url_string, "//", 2) == 0) { url_string += 2; slash = url_string + strcspn (url_string, "/#"); at = strchr (url_string, '@'); if (at && at < slash) { colon = strchr (url_string, ':'); if (colon && colon < at) { /* XXX We used to extract and store the * password here, now we just eat it. */ } else { colon = at; } semi = strchr (url_string, ';'); if (semi && semi < colon && !g_ascii_strncasecmp (semi, ";auth=", 6)) { url->authmech = g_strndup ( semi + 6, colon - semi - 6); camel_url_decode (url->authmech); } else { url->authmech = NULL; semi = colon; } url->user = g_strndup (url_string, semi - url_string); camel_url_decode (url->user); url_string = at + 1; } else url->user = url->authmech = NULL; /* Find host and port. */ colon = strchr (url_string, ':'); if (colon && colon < slash) { url->host = g_strndup (url_string, colon - url_string); url->port = strtoul (colon + 1, NULL, 10); } else { url->host = g_strndup (url_string, slash - url_string); camel_url_decode (url->host); url->port = 0; } url_string = slash; } /* Find query */ question = memchr (url_string, '?', end - url_string); if (question) { if (question[1]) { url->query = g_strndup ( question + 1, end - (question + 1)); camel_url_decode (url->query); } end = question; } /* Find parameters */ semi = memchr (url_string, ';', end - url_string); if (semi) { if (semi[1]) { const gchar *cur, *p, *eq; gchar *name, *value; for (cur = semi + 1; cur < end; cur = p + 1) { p = memchr (cur, ';', end - cur); if (!p) p = end; eq = memchr (cur, '=', p - cur); if (eq) { name = g_strndup (cur, eq - cur); value = g_strndup (eq + 1, p - (eq + 1)); camel_url_decode (value); } else { name = g_strndup (cur, p - cur); value = g_strdup (""); } camel_url_decode (name); g_datalist_set_data_full ( &url->params, name, value, g_free); g_free (name); } } end = semi; } if (end != url_string) { url->path = g_strndup (url_string, end - url_string); camel_url_decode (url->path); } /* Apply base URL. Again, this is spelled out in RFC 1808. */ if (base && !url->protocol && url->host) url->protocol = g_strdup (base->protocol); else if (base && !url->protocol) { if (!url->user && !url->authmech && !url->host && !url->port && !url->path && !url->params && !url->query && !url->fragment) url->fragment = g_strdup (base->fragment); url->protocol = g_strdup (base->protocol); url->user = g_strdup (base->user); url->authmech = g_strdup (base->authmech); url->host = g_strdup (base->host); url->port = base->port; if (!url->path) { url->path = g_strdup (base->path); if (!url->params) { g_datalist_foreach (&base->params, copy_param, &url->params); if (!url->query) url->query = g_strdup (base->query); } } else if (*url->path != '/') { gchar *newpath, *last, *p, *q; /* the base->path is NULL if given Content-Base url was without last slash, * i.e. like "http://example.com" (this expected only "http://example.com/") */ last = base->path ? strrchr (base->path, '/') : NULL; if (last) { newpath = g_strdup_printf ( "%.*s/%s", (gint)(last - base->path), base->path, url->path); } else newpath = g_strdup_printf ("/%s", url->path); /* Remove "./" where "." is a complete segment. */ for (p = newpath + 1; *p; ) { if (*(p - 1) == '/' && *p == '.' && *(p + 1) == '/') memmove (p, p + 2, strlen (p + 2) + 1); else p++; } /* Remove "." at end. */ if (p > newpath + 2 && *(p - 1) == '.' && *(p - 2) == '/') *(p - 1) = '\0'; /* Remove "<segment>/../" where <segment> != ".." */ for (p = newpath + 1; *p; ) { if (!strncmp (p, "../", 3)) { p += 3; continue; } q = strchr (p + 1, '/'); if (!q) break; if (strncmp (q, "/../", 4) != 0) { p = q + 1; continue; } memmove (p, q + 4, strlen (q + 4) + 1); p = newpath + 1; } /* Remove "<segment>/.." at end */ q = strrchr (newpath, '/'); if (q && !strcmp (q, "/..")) { p = q - 1; while (p > newpath && *p != '/') p--; if (strncmp (p, "/../", 4) != 0) *(p + 1) = 0; } g_free (url->path); url->path = newpath; } } return url; }
/** * e_uri_new: * @uri_string: The uri to represent as an #EUri. * * Creates an #EUri representation of the uri given in @uri_string. * * Returns: The newly-allocated #EUri structure. **/ EUri * e_uri_new (const gchar *uri_string) { EUri *uri; const gchar *end, *hash, *colon, *semi, *at, *slash, *question; const gchar *p; if (!uri_string) return NULL; uri = g_new0 (EUri, 1); /* find fragment */ end = hash = strchr (uri_string, '#'); if (hash && hash[1]) { uri->fragment = g_strdup (hash + 1); uri_decode (uri->fragment); } else end = uri_string + strlen (uri_string); /* find protocol: initial [a-z+.-]* substring until ":" */ p = uri_string; while (p < end && (isalnum ((guchar) *p) || *p == '.' || *p == '+' || *p == '-')) p++; if (p > uri_string && *p == ':') { uri->protocol = g_ascii_strdown (uri_string, p - uri_string); uri_string = p + 1; } else uri->protocol = g_strdup ("file"); if (!*uri_string) return uri; /* check for authority */ if (strncmp (uri_string, "//", 2) == 0) { uri_string += 2; slash = uri_string + strcspn (uri_string, "/#"); at = strchr (uri_string, '@'); if (at && at < slash) { const gchar *at2; /* this is for cases where username contains '@' at it, like: * http://[email protected]@server.addr.com/path * We skip all at-s before the slash here. */ while (at2 = strchr (at + 1, '@'), at2 && at2 < slash) { at = at2; } } if (at && at < slash) { colon = strchr (uri_string, ':'); if (colon && colon < at) { uri->passwd = g_strndup (colon + 1, at - colon - 1); uri_decode (uri->passwd); } else { uri->passwd = NULL; colon = at; } semi = strchr (uri_string, ';'); if (semi && semi < colon && !g_ascii_strncasecmp (semi, ";auth=", 6)) { uri->authmech = g_strndup (semi + 6, colon - semi - 6); uri_decode (uri->authmech); } else { uri->authmech = NULL; semi = colon; } uri->user = g_strndup (uri_string, semi - uri_string); uri_decode (uri->user); uri_string = at + 1; } else uri->user = uri->passwd = uri->authmech = NULL; /* find host and port */ colon = strchr (uri_string, ':'); if (colon && colon < slash) { uri->host = g_strndup (uri_string, colon - uri_string); uri->port = strtoul (colon + 1, NULL, 10); } else { uri->host = g_strndup (uri_string, slash - uri_string); uri_decode (uri->host); uri->port = 0; } uri_string = slash; } /* find query */ question = memchr (uri_string, '?', end - uri_string); if (question) { if (question[1]) { uri->query = g_strndup (question + 1, end - (question + 1)); uri_decode (uri->query); } end = question; } /* find parameters */ semi = memchr (uri_string, ';', end - uri_string); if (semi) { if (semi[1]) { const gchar *cur, *ptr, *eq; gchar *name, *value; for (cur = semi + 1; cur < end; cur = ptr + 1) { ptr = memchr (cur, ';', end - cur); if (!ptr) ptr = end; eq = memchr (cur, '=', ptr - cur); if (eq) { name = g_strndup (cur, eq - cur); value = g_strndup (eq + 1, ptr - (eq + 1)); uri_decode (value); } else { name = g_strndup (cur, ptr - cur); value = g_strdup (""); } uri_decode (name); g_datalist_set_data_full ( &uri->params, name, value, g_free); g_free (name); } } end = semi; } if (end != uri_string) { uri->path = g_strndup (uri_string, end - uri_string); uri_decode (uri->path); } return uri; }
/** * e2k_uri_new: * @uri_string: the URI * * Parses @uri_string. * * Return value: a parsed %E2kUri **/ E2kUri * e2k_uri_new (const char *uri_string) { E2kUri *uri; const char *end, *hash, *colon, *semi, *at, *slash; const char *question, *p; uri = g_new0 (E2kUri, 1); /* Find fragment. */ end = hash = strchr (uri_string, '#'); if (hash && hash[1]) { uri->fragment = g_strdup (hash + 1); e2k_uri_decode (uri->fragment); } else end = uri_string + strlen (uri_string); /* Find protocol: initial [a-z+.-]* substring until ":" */ p = uri_string; while (p < end && (isalnum ((unsigned char)*p) || *p == '.' || *p == '+' || *p == '-')) p++; if (p > uri_string && *p == ':') { uri->protocol = g_ascii_strdown (uri_string, p - uri_string); uri_string = p + 1; } if (!*uri_string) return uri; /* Check for authority */ if (strncmp (uri_string, "//", 2) == 0) { uri_string += 2; slash = uri_string + strcspn (uri_string, "/#"); at = strchr (uri_string, '@'); if (at && at < slash) { char *backslash; colon = strchr (uri_string, ':'); if (colon && colon < at) { uri->passwd = g_strndup (colon + 1, at - colon - 1); e2k_uri_decode (uri->passwd); } else { uri->passwd = NULL; colon = at; } semi = strchr(uri_string, ';'); if (semi && semi < colon && !g_ascii_strncasecmp (semi, ";auth=", 6)) { uri->authmech = g_strndup (semi + 6, colon - semi - 6); e2k_uri_decode (uri->authmech); } else { uri->authmech = NULL; semi = colon; } uri->user = g_strndup (uri_string, semi - uri_string); e2k_uri_decode (uri->user); uri_string = at + 1; backslash = strchr (uri->user, '\\'); if (!backslash) backslash = strchr (uri->user, '/'); if (backslash) { uri->domain = uri->user; *backslash = '\0'; uri->user = g_strdup (backslash + 1); } } else uri->user = uri->passwd = uri->domain = NULL; /* Find host and port. */ colon = strchr (uri_string, ':'); if (colon && colon < slash) { uri->host = g_strndup (uri_string, colon - uri_string); uri->port = strtoul (colon + 1, NULL, 10); } else { uri->host = g_strndup (uri_string, slash - uri_string); e2k_uri_decode (uri->host); uri->port = 0; } uri_string = slash; } /* Find query */ question = memchr (uri_string, '?', end - uri_string); if (question) { if (question[1]) { uri->query = g_strndup (question + 1, end - (question + 1)); e2k_uri_decode (uri->query); } end = question; } /* Find parameters */ semi = memchr (uri_string, ';', end - uri_string); if (semi) { if (semi[1]) { const char *cur, *p, *eq; char *name, *value; for (cur = semi + 1; cur < end; cur = p + 1) { p = memchr (cur, ';', end - cur); if (!p) p = end; eq = memchr (cur, '=', p - cur); if (eq) { name = g_strndup (cur, eq - cur); value = g_strndup (eq + 1, p - (eq + 1)); e2k_uri_decode (value); } else { name = g_strndup (cur, p - cur); value = g_strdup (""); } e2k_uri_decode (name); g_datalist_set_data_full (&uri->params, name, value, g_free); g_free (name); } } end = semi; } if (end != uri_string) { uri->path = g_strndup (uri_string, end - uri_string); e2k_uri_decode (uri->path); } return uri; }
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; }