static gboolean _parse_uri(const char* uri, gboolean* secure, char** host, char** resource) { static GRegex* regex = NULL; GMatchInfo *match_info = NULL; g_return_val_if_fail(uri != NULL, FALSE); g_return_val_if_fail(secure != NULL, FALSE); g_return_val_if_fail(host != NULL, FALSE); g_return_val_if_fail(resource != NULL, FALSE); // precompile regexp G_LOCK(regex); if (regex == NULL) regex = g_regex_new("^([a-z]+)://([a-z0-9.-]+(:([0-9]+))?)(/.+)?$", G_REGEX_CASELESS, 0, NULL); G_UNLOCK(regex); if (!g_regex_match(regex, uri, 0, &match_info)) { g_match_info_free(match_info); return FALSE; } // check schema char* schema = g_match_info_fetch(match_info, 1); if (!g_ascii_strcasecmp("http", schema)) *secure = 0; else if (!g_ascii_strcasecmp("https", schema)) *secure = 1; else { g_free(schema); g_match_info_free(match_info); return FALSE; } g_free(schema); *host = g_match_info_fetch(match_info, 2); *resource = g_match_info_fetch(match_info, 5); if (*resource == NULL) *resource = g_strdup("/RPC2"); g_match_info_free(match_info); return TRUE; }
void plank_services_logger_initialize (const gchar* app_name) { const gchar* _tmp0_ = NULL; const gchar* _tmp1_ = NULL; const gchar* _tmp2_ = NULL; GeeArrayList* _tmp3_ = NULL; GError * _inner_error_ = NULL; g_return_if_fail (app_name != NULL); _tmp0_ = plank_services_logger_get_AppName (); _tmp1_ = _tmp0_; _tmp2_ = app_name; plank_services_logger_set_AppName (_tmp2_); plank_services_logger_is_writing = FALSE; _tmp3_ = gee_array_list_new (PLANK_SERVICES_LOGGER_TYPE_LOG_MESSAGE, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL); _g_object_unref0 (plank_services_logger_log_queue); plank_services_logger_log_queue = _tmp3_; { GRegex* _tmp4_ = NULL; GRegex* _tmp5_ = NULL; GRegex* _tmp6_ = NULL; _tmp5_ = g_regex_new ("[(]?.*?([^/]*?)(\\.2)?\\.vala(:\\d+)[)]?:\\s*(.*)", 0, 0, &_inner_error_); _tmp4_ = _tmp5_; if (_inner_error_ != NULL) { goto __catch31_g_error; } _tmp6_ = _tmp4_; _tmp4_ = NULL; _g_regex_unref0 (plank_services_logger_re); plank_services_logger_re = _tmp6_; _g_regex_unref0 (_tmp4_); } goto __finally31; __catch31_g_error: { g_clear_error (&_inner_error_); _inner_error_ = NULL; } __finally31: if (_inner_error_ != NULL) { g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return; } g_log_set_default_handler (_plank_services_logger_glib_log_func_glog_func, NULL); }
PhotosQuery * photos_query_builder_single_query (PhotosSearchContextState *state, gint flags, const gchar *resource) { GRegex *regex; gchar *replacement; gchar *sparql; gchar *tmp; tmp = photos_query_builder_query (state, FALSE, flags, NULL); regex = g_regex_new ("\\?urn", 0, 0, NULL); replacement = g_strconcat ("<", resource, ">", NULL); sparql = g_regex_replace (regex, tmp, -1, 0, replacement, 0, NULL); g_free (replacement); g_free (tmp); g_regex_unref (regex); return photos_query_new (state, sparql); }
static gboolean replace_nsswitch (GFile *target_usretc, GCancellable *cancellable, GError **error) { gboolean ret = FALSE; gs_unref_object GFile *nsswitch_conf = g_file_get_child (target_usretc, "nsswitch.conf"); gs_free char *nsswitch_contents = NULL; gs_free char *new_nsswitch_contents = NULL; static gsize regex_initialized; static GRegex *passwd_regex; if (g_once_init_enter (®ex_initialized)) { passwd_regex = g_regex_new ("^(passwd|group):\\s+files(.*)$", G_REGEX_MULTILINE, 0, NULL); g_assert (passwd_regex); g_once_init_leave (®ex_initialized, 1); } nsswitch_contents = gs_file_load_contents_utf8 (nsswitch_conf, cancellable, error); if (!nsswitch_contents) goto out; new_nsswitch_contents = g_regex_replace (passwd_regex, nsswitch_contents, -1, 0, "\\1: files altfiles\\2", 0, error); if (!new_nsswitch_contents) goto out; if (!g_file_replace_contents (nsswitch_conf, new_nsswitch_contents, strlen (new_nsswitch_contents), NULL, FALSE, 0, NULL, cancellable, error)) goto out; ret = TRUE; out: return ret; }
static void termit_search_prepare_regex(const gchar* searchRegex) { gint page = gtk_notebook_get_current_page(GTK_NOTEBOOK(termit.notebook)); TERMIT_GET_TAB_BY_INDEX(pTab, page); if (strlen(searchRegex) == 0) { vte_terminal_search_set_gregex(VTE_TERMINAL(pTab->vte), NULL); } else { GRegex* currSearchRegex = vte_terminal_search_get_gregex(VTE_TERMINAL(pTab->vte)); if (!currSearchRegex || strcmp(searchRegex, g_regex_get_pattern(currSearchRegex)) != 0) { GError* err = NULL; GRegex* regex = g_regex_new(searchRegex, 0, 0, &err); if (err) { TRACE("failed to compile regex [%s]: skipping", searchRegex); return; } vte_terminal_search_set_gregex(VTE_TERMINAL(pTab->vte), regex); } } }
/** * gtk_source_regex_new: * @pattern: the regular expression. * @flags: compile options for @pattern. * @error: location to store the error occuring, or %NULL to ignore errors. * * Creates a new regex. * * Returns: a newly-allocated #GtkSourceRegex. */ GtkSourceRegex * _gtk_source_regex_new (const gchar *pattern, GRegexCompileFlags flags, GError **error) { GtkSourceRegex *regex; g_return_val_if_fail (pattern != NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); if (find_single_byte_escape (pattern)) { g_set_error_literal (error, G_REGEX_ERROR, G_REGEX_ERROR_COMPILE, _("using \\C is not supported in language definitions")); return NULL; } regex = g_slice_new0 (GtkSourceRegex); regex->ref_count = 1; if (g_regex_match (get_start_ref_regex (), pattern, 0, NULL)) { regex->resolved = FALSE; regex->u.info.pattern = g_strdup (pattern); regex->u.info.flags = flags; } else { regex->resolved = TRUE; regex->u.regex.regex = g_regex_new (pattern, flags | G_REGEX_OPTIMIZE | G_REGEX_NEWLINE_LF, 0, error); if (regex->u.regex.regex == NULL) { g_slice_free (GtkSourceRegex, regex); regex = NULL; } } return regex; }
static gchar* apedax_format_date(const gchar* datefield) { GRegex *re; gchar *result; GError *re_err = NULL; gwy_debug("Compiling the Regular expression."); re = g_regex_new(REGPATTERN, 0, 0, &re_err); g_assert(!re_err); result = g_regex_replace(re, datefield, -1, 0, "\\3-\\2-\\1 \\4 \\5", 0, &re_err); if (re_err) { g_warning("Invalid date field (%s)", re_err->message); g_clear_error(&re_err); } g_regex_unref(re); return result; }
static void get_address_from_ip(const char *text, std::string &ipstr, std::string &address) { GMatchInfo *match_info; GRegex *regex = g_regex_new ("(((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))\\.){3}((\\d{1,2})|(1\\d{2})|(2[0-4]\\d)|(25[0-5]))", (GRegexCompileFlags)0, (GRegexMatchFlags)0, NULL); g_regex_match (regex, text, (GRegexMatchFlags)0, &match_info); if (g_match_info_matches(match_info)) { gchar *word = g_match_info_fetch (match_info, 0); ipstr = word; g_free (word); } g_match_info_free (match_info); g_regex_unref (regex); if (ipstr.empty()) return; std::string datafilename = plugin_info->datadir; datafilename += G_DIR_SEPARATOR_S "data" G_DIR_SEPARATOR_S "QQWry.Dat"; FILE *fp = g_fopen(datafilename.c_str(), "rb"); if (!fp) { gchar *msg = g_strdup_printf(_("Error: Open file %s failed!"), datafilename.c_str()); address = msg; g_free(msg); return; } unsigned long index_start,index_end; getHead(fp,&index_start,&index_end); unsigned long ip = getIP(ipstr.c_str()); unsigned long current=searchIP(fp,index_start,index_end,ip); std::string country,location; getAddress(fp,getValue(fp,current+4,3),country,location); gchar *c = g_convert(country.c_str(), -1, "UTF-8", "GB18030", NULL, NULL, NULL); if (c) { address += c; address += ' '; g_free(c); } gchar *l = g_convert(location.c_str(), -1, "UTF-8", "GB18030", NULL, NULL, NULL); if (l) { address += l; g_free(l); } fclose(fp); }
static int regexp_set(struct objlist *obj, N_VALUE *inst, N_VALUE *rval, int argc, char **argv) { struct oregexp_local *local; GRegex *regexp; char *str; _getobj(obj, "_local", inst, &local); str = (char *) argv[2]; if (str == NULL || str[0] == '\0') { if (local->regexp) { g_regex_unref(local->regexp); } local->regexp = NULL; del_array_element(local->array); return 0; } if (! g_utf8_validate(str, -1, NULL)) { error(obj, ERR_INVALID_UTF8); return 1; } regexp = g_regex_new(str, 0, 0, NULL); if (regexp == NULL) { error(obj, ERR_REGEXP); return 1; } if (local->regexp) { g_regex_unref(local->regexp); } local->regexp = regexp; del_array_element(local->array); return 0; }
static OwrLocalMediaSource *maybe_create_source_from_filename(const gchar *name) { static GRegex *regex; GMatchInfo *match_info = NULL; OwrLocalMediaSource *source = NULL; gchar *index_str; gint index; gchar *filename; gchar *device_name; if (g_once_init_enter(®ex)) { GRegex *r; r = g_regex_new("^video(0|[1-9][0-9]*)$", G_REGEX_OPTIMIZE, 0, NULL); g_assert(r); g_once_init_leave(®ex, r); } if (g_regex_match(regex, name, 0, &match_info)) { index_str = g_match_info_fetch(match_info, 1); index = g_ascii_strtoll(index_str, NULL, 10); g_free(index_str); filename = g_strdup_printf("/dev/%s", name); device_name = get_v4l2_device_name(filename); g_free(filename); filename = NULL; if (!device_name) return NULL; source = _owr_local_media_source_new_cached(index, device_name, OWR_MEDIA_TYPE_VIDEO, OWR_SOURCE_TYPE_CAPTURE); g_debug("v4l: filename match: %s", device_name); g_free(device_name); } g_match_info_free(match_info); return source; }
static gboolean check_regex (LogviewFilterManager *manager, const gchar *regex) { GtkWidget *dialog; GError *error = NULL; GRegex *reg; if (!strlen (regex)) { dialog = gtk_message_dialog_new (GTK_WINDOW(manager), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", _("Regular expression is empty!")); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); return FALSE; } reg = g_regex_new (regex, 0, 0, &error); if (error) { dialog = gtk_message_dialog_new (GTK_WINDOW (manager), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Regular expression is invalid: %s"), error->message); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); g_error_free (error); return FALSE; } g_regex_unref (reg); return TRUE; }
static void list_files(gchar *base, const gchar *filter) { GDir *dir; gchar const *file_name; dir = g_dir_open(base, 0, NULL); gchar *display_base = g_strconcat(base, G_DIR_SEPARATOR_S, NULL); GString *g_display_base = g_string_new(display_base); utils_string_replace_first(g_display_base, base_directory, ""); g_free(display_base); GRegex *regex = g_regex_new(filter, G_REGEX_CASELESS, 0, NULL); foreach_dir(file_name, dir) { if(row_pos > MAX_LIST) { break; } gchar *path = g_build_path(G_DIR_SEPARATOR_S, base, file_name, NULL); if(g_file_test(path, G_FILE_TEST_IS_DIR)) { if(g_regex_match(pathRegexSetting.regex, file_name, 0, NULL)) { g_free(path); continue; } list_files(path, filter); } else { if(g_regex_match(nameRegexSetting.regex, file_name, 0, NULL)) { g_free(path); continue; } if(regex != NULL && g_regex_match(regex, include_path ? path : file_name, 0, NULL)) { gtk_tree_store_append(list, &row, NULL); gtk_tree_store_set(list, &row, 0, g_display_base->str, 1, file_name, -1); row_pos++; } } g_free(path); } g_string_free(g_display_base, TRUE); g_dir_close(dir); g_regex_unref(regex); }
static void rclib_lyric_instance_init(RCLibLyric *lyric) { RCLibLyricPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE(lyric, RCLIB_TYPE_LYRIC, RCLibLyricPrivate); lyric->priv = priv; priv->parsed_data1.seq = g_sequence_new((GDestroyNotify) rclib_lyric_lyric_data_free); priv->parsed_data2.seq = g_sequence_new((GDestroyNotify) rclib_lyric_lyric_data_free); priv->regex = g_regex_new("(?P<time>\\[[0-9]+:[0-9]+([\\.:][0-9]+)*\\])|" "(?P<text>[^\\]]*$)|(?P<title>\\[ti:.+\\])|(?P<artist>\\[ar:.+\\])|" "(?P<album>\\[al:.+\\])|(?P<author>\\[by:.+\\])|" "(?P<offset>\\[offset:.+\\])", 0, 0, NULL); priv->timer = g_timeout_add(100, (GSourceFunc)rclib_lyric_watch_timer, NULL); priv->tag_found_handler = rclib_core_signal_connect("tag-found", G_CALLBACK(rclib_lyric_tag_found_cb), lyric); priv->uri_changed_handler = rclib_core_signal_connect("uri-changed", G_CALLBACK(rclib_lyric_uri_changed_cb), lyric); }
static gchar * replace_string (gchar **string, const gchar *search, const char *replacement) { GRegex *regex; gchar *res; g_return_val_if_fail (*string != NULL, NULL); g_return_val_if_fail (string != NULL, NULL); g_return_val_if_fail (search != NULL, *string); g_return_val_if_fail (replacement != NULL, *string); regex = g_regex_new (search, 0, 0, NULL); res = g_regex_replace_literal (regex, *string, -1, 0, replacement, 0, NULL); g_regex_unref (regex); /* The given string is freed and replaced by the resulting replacement */ g_free (*string); *string = res; return res; }
static void matchesLoader(const gchar* pattern, struct lua_State* ls, int index, void* data) { TRACE("pattern=%s index=%d data=%p", pattern, index, data); if (!lua_isfunction(ls, index)) { ERROR("match [%s] without function: skipping", pattern); return; } GArray* matches = (GArray*)data; struct Match match = {}; GError* err = NULL; match.regex = g_regex_new(pattern, 0, 0, &err); if (err) { TRACE("failed to compile regex [%s]: skipping", pattern); return; } match.flags = 0; match.pattern = g_strdup(pattern); termit_config_get_function(&match.lua_callback, ls, index); g_array_append_val(matches, match); }
static gchar* get_indent (const gchar *string) { /* Print all uppercase-only words. */ GRegex *regex; GMatchInfo *match_info; gchar *word = NULL; regex = g_regex_new ("^\\s*", 0, 0, NULL); g_regex_match (regex, string, 0, &match_info); while (g_match_info_matches (match_info)) { word = g_match_info_fetch (match_info, 0); break; } g_match_info_free (match_info); g_regex_unref (regex); return word; }
static gboolean validate_domainname (const gchar *key, const gchar *value, GError **error) { GRegex *regex; regex = g_regex_new ("^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\\.)+[A-Za-z]{2,13}$", 0, 0, NULL); if (!g_regex_match_full (regex, value, -1, 0, 0, NULL, NULL)) { g_regex_unref (regex); *error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, _("'%s' entry must contain a valid domain name"), key); return FALSE; } g_regex_unref (regex); return TRUE; }
static gboolean parse_bootlink (const char *bootlink, int *out_entry_bootversion, char **out_osname, char **out_bootcsum, int *out_treebootserial, GError **error) { gboolean ret = FALSE; __attribute__((cleanup(match_info_cleanup))) GMatchInfo *match = NULL; g_autofree char *bootversion_str = NULL; g_autofree char *treebootserial_str = NULL; static gsize regex_initialized; static GRegex *regex; if (g_once_init_enter (®ex_initialized)) { regex = g_regex_new ("^/ostree/boot.([01])/([^/]+)/([^/]+)/([0-9]+)$", 0, 0, NULL); g_assert (regex); g_once_init_leave (®ex_initialized, 1); } if (!g_regex_match (regex, bootlink, 0, &match)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid ostree= argument '%s', expected ostree=/ostree/boot.BOOTVERSION/OSNAME/BOOTCSUM/TREESERIAL", bootlink); goto out; } bootversion_str = g_match_info_fetch (match, 1); *out_entry_bootversion = (int)g_ascii_strtoll (bootversion_str, NULL, 10); *out_osname = g_match_info_fetch (match, 2); *out_bootcsum = g_match_info_fetch (match, 3); treebootserial_str = g_match_info_fetch (match, 4); *out_treebootserial = (int)g_ascii_strtoll (treebootserial_str, NULL, 10); ret = TRUE; out: return ret; }
static void ggu_git_get_version_parse_output (GguGit *obj, const gchar *output, GSimpleAsyncResult *result, GCancellable *cancellable) { GRegex *re; GMatchInfo *infos; GError *err = NULL; GetVersionOp *op; op = g_malloc (sizeof *op); op->success = FALSE; re = g_regex_new ("([0-9]+)(?:\\.([0-9]+)(?:\\.([0-9]+)(?:\\.([0-9]+))?)?)?", 0, 0, &err); if (! re) { g_warning ("Regex compilation failed: %s", err->message); g_error_free (err); } else { if (g_regex_match (re, output, 0, &infos)) { gchar *match; op->success = TRUE; #define GET_INT_MATCH(n) \ ((match = g_match_info_fetch (infos, (n))) \ ? atoi (match) \ : 0) op->v[0] = GET_INT_MATCH (1); g_free (match); op->v[1] = GET_INT_MATCH (2); g_free (match); op->v[2] = GET_INT_MATCH (3); g_free (match); op->v[3] = GET_INT_MATCH (4); g_free (match); #undef GET_INT_MATCH } g_match_info_free (infos); g_regex_unref (re); } g_simple_async_result_set_op_res_gpointer (result, op, g_free); }
static void receive_line(const struct sr_dev_inst *sdi) { struct dev_context *devc; const struct agdmm_recv *recvs, *recv; GRegex *reg; GMatchInfo *match; int i; devc = sdi->priv; /* Strip CRLF */ while (devc->buflen) { if (*(devc->buf + devc->buflen - 1) == '\r' || *(devc->buf + devc->buflen - 1) == '\n') *(devc->buf + --devc->buflen) = '\0'; else break; } sr_spew("Received '%s'.", devc->buf); recv = NULL; recvs = devc->profile->recvs; for (i = 0; (&recvs[i])->recv_regex; i++) { reg = g_regex_new((&recvs[i])->recv_regex, 0, 0, NULL); if (g_regex_match(reg, (char *)devc->buf, 0, &match)) { recv = &recvs[i]; break; } g_match_info_unref(match); g_regex_unref(reg); } if (recv) { recv->recv(sdi, match); g_match_info_unref(match); g_regex_unref(reg); } else sr_dbg("Unknown line '%s'.", devc->buf); /* Done with this. */ devc->buflen = 0; }
/** * gstreamill_get_encoder_output: * @uri: (in): access uri, e.g. /live/test/encoder/0 * * Get the EncoderOutput by access uri. * * Returns: the encoder output */ EncoderOutput * gstreamill_get_encoder_output (Gstreamill *gstreamill, gchar *uri) { Job *job; gint index; GRegex *regex = NULL; GMatchInfo *match_info = NULL; gchar *e; index = -1; regex = g_regex_new ("^/live/.*/encoder/(?<encoder>[0-9]+).*", G_REGEX_OPTIMIZE, 0, NULL); g_regex_match (regex, uri, 0, &match_info); if (g_match_info_matches (match_info)) { e = g_match_info_fetch_named (match_info, "encoder"); index = g_ascii_strtoll (e, NULL, 10); g_free (e); } if (match_info != NULL) { g_match_info_free (match_info); } if (regex != NULL) { g_regex_unref (regex); } if (index == -1) { GST_INFO ("Not a encoder uri: %s", uri); return NULL; } job = gstreamill_get_job (gstreamill, uri); if (job == NULL) { GST_ERROR ("Job %s not found.", uri); return NULL; } if (index >= job->output->encoder_count) { GST_ERROR ("Encoder %s not found.", uri); return NULL; } g_mutex_lock (&(job->access_mutex)); job->current_access += 1; g_mutex_unlock (&(job->access_mutex)); return &job->output->encoders[index]; }
/* Substitute each occurrence of the regular expression "regex" in "s" * with "subst". The result is returned in a newly allocate string * that must be freed with g_free(). */ static char* regsub(const char* regex, const char* s, const char* subst, GError** err) { char* rv = NULL; GRegex* prog = NULL; /* How glib propagates exceptions. */ if (err && *err) { goto out; } /* Compile regex. */ prog = g_regex_new(regex, G_REGEX_CASELESS | G_REGEX_RAW | G_REGEX_NO_AUTO_CAPTURE | G_REGEX_OPTIMIZE, 0, err); if (err && *err) { goto out; } /* Substitute. */ rv = g_regex_replace_literal(prog, s, -1, 0, subst, 0, err); if (err && *err) { goto out; } out: /* Clean up. */ if (prog) { g_regex_unref(prog); } return rv; }
static gchar * get_stream_id_from_padname (const gchar * name) { GMatchInfo *match_info = NULL; GRegex *regex; gchar *id = NULL; if (name == NULL) return NULL; regex = g_regex_new ("^sink_(?<id>\\d+)", 0, 0, NULL); g_regex_match (regex, name, 0, &match_info); if (g_match_info_matches (match_info)) id = g_match_info_fetch_named (match_info, "id"); g_match_info_free (match_info); g_regex_unref (regex); return id; }
//make sure we don't have file:/// gchar *get_full_command(const gchar *command, const gchar *file) { gchar *fc; GRegex *regex; regex = g_regex_new("%f", G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL); if (g_regex_match (regex,command,0,0)) { //if using custom complex command, replace %f with filename fc = g_strstrip(g_regex_replace_literal(regex, command, -1, 0, get_file_path(file), 0, NULL)); } else { fc = g_strjoin (" ", command, g_strjoin("", "\"", get_file_path(file), "\"", NULL), NULL); } g_regex_unref(regex); return fc; }
/** * Initialize the advanced_search system. */ void advanced_search_init(void) { int i = 0; GString *string = g_string_new("("); if (search_regex) { g_regex_unref(search_regex); search_regex = NULL; } for (i = 0; i < MPD_TAG_NUM_OF_ITEM_TYPES; i++) { if (mpd_server_tag_supported(connection, i)) { g_string_append(string, mpdTagItemKeys[i]); if (i < (MPD_TAG_NUM_OF_ITEM_TYPES - 1)) g_string_append(string, "|"); } } g_string_append(string, ")[ ]*[=:][ ]*|[ ]*(\\|\\|)[ ]*"); search_regex = g_regex_new(string->str, G_REGEX_CASELESS, 0, NULL); g_string_free(string, TRUE); }
static GRegex * uri_regex_dup_singleton (void) { static GRegex *uri_regex = NULL; /* We intentionally leak the regex so it's not recomputed */ if (!uri_regex) { GError *error = NULL; uri_regex = g_regex_new (URI_REGEX, 0, 0, &error); if (uri_regex == NULL) { g_warning ("Failed to create reg exp: %s", error->message); g_error_free (error); return NULL; } } return g_regex_ref (uri_regex); }
gboolean jobdesc_is_valid (gchar *job) { JSON_Value *val; JSON_Object *obj; GRegex *regex; GMatchInfo *match_info; gchar *name; val = json_parse_string_with_comments(job); if (val == NULL) { GST_ERROR ("parse job error."); return FALSE; } else if (json_value_get_type (val) != JSONObject){ GST_ERROR ("job is not a json object."); json_value_free (val); return FALSE; } obj = json_value_get_object (val); name = (gchar *)json_object_get_string (obj, "name"); if ((name == NULL) || (strlen (name) < 4)) { GST_ERROR ("invalid job with name property invalid"); json_value_free (val); return FALSE; } regex = g_regex_new ("[`~!@#$%^&*()+=|\\{[\\]}:;\"\'<,>.?/]", G_REGEX_OPTIMIZE, 0, NULL); g_regex_match (regex, name, 0, &match_info); g_regex_unref (regex); if (g_match_info_matches (match_info)) { GST_ERROR ("invalid job name: %s", name); g_match_info_free (match_info); json_value_free (val); return FALSE; } json_value_free (val); return TRUE; }
gboolean mu_contacts_foreach (MuContacts *self, MuContactsForeachFunc func, gpointer user_data, const char *pattern, size_t *num) { EachContactData ecdata; g_return_val_if_fail (self, FALSE); g_return_val_if_fail (func, FALSE); if (pattern) { GError *err; err = NULL; ecdata._rx = g_regex_new (pattern, G_REGEX_CASELESS|G_REGEX_OPTIMIZE, 0, &err); if (!ecdata._rx) { g_warning ("error in regexp '%s': %s", pattern, err->message); g_error_free (err); return FALSE; } } else ecdata._rx = NULL; ecdata._func = func; ecdata._user_data = user_data; ecdata._num = 0; g_hash_table_foreach (self->_hash, (GHFunc)each_contact, &ecdata); if (ecdata._rx) g_regex_unref (ecdata._rx); if (num) *num = ecdata._num; return TRUE; }
static void logview_filter_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { LogviewFilterPrivate* priv = LOGVIEW_FILTER (object)->priv; switch (prop_id) { case PROP_NAME: priv->name = g_value_dup_string (value); break; case PROP_REGEX: { GError* err; const gchar* regex; err = NULL; regex = g_value_get_string (value); priv->regex = g_regex_new (regex, 0, 0, &err); if (err) { g_regex_unref (priv->regex); priv->regex = NULL; g_warning ("Couldn't create GRegex object: %s", err->message); g_error_free (err); } break; } case PROP_TEXTTAG: { if (priv->tag) { g_object_unref (priv->tag); } priv->tag = g_value_dup_object (value); break; } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static char* get_httpd_config (const char *httpd_program) { gchar *standard_output; gchar *cmd_line; GMatchInfo *match_info; gchar *version_number = NULL; gchar *config; cmd_line = g_strdup_printf ("%s -v", httpd_program); if (! g_spawn_command_line_sync (cmd_line, &standard_output, NULL, NULL, NULL)) { g_free (cmd_line); return NULL; } g_free (cmd_line); if (version_regex == NULL) { version_regex = g_regex_new ("\\d\\.\\d", 0, 0, NULL); } if (g_regex_match (version_regex, standard_output, 0, &match_info)) { while (g_match_info_matches (match_info)) { version_number = g_match_info_fetch (match_info, 0); break; } g_match_info_free (match_info); g_free (standard_output); } else { /* Failed to parse httpd version number */ g_warning ("Could not parse '%s' as a version for httpd", standard_output); g_free (standard_output); /* assume it is 2.2 */ version_number = g_strdup ("2.2"); } config = g_strdup_printf (HTTPD_CONFIG_TEMPLATE, version_number); g_free (version_number); return config; }