Example #1
2
/**
 * filter_line_fsck: (skip)
 * Filter one line - decide what to do with it.
 *
 * Returns: Zero or positive number as a percentage, -1 if not a percentage, -2 on an error
 */
static gint8 filter_line_fsck (const gchar * line, guint8 total_stages, GError **error) {
    static GRegex *output_regex = NULL;
    GMatchInfo *match_info;
    gint8 perc = -1;

    if (output_regex == NULL) {
        /* Compile regular expression that matches to e2fsck progress output */
        output_regex = g_regex_new ("^([0-9][0-9]*) ([0-9][0-9]*) ([0-9][0-9]*) (/.*)", 0, 0, error);
        if (output_regex == NULL) {
            return -2;
        }
    }

    /* Execute regular expression */
    if (g_regex_match (output_regex, line, 0, &match_info)) {
        guint8 stage;
        gint64 val_cur;
        gint64 val_total;

        /* The output_regex ensures we have a number in these matches, so we can skip
         * tests for conversion errors.
         */
        stage = (guint8) g_ascii_strtoull (g_match_info_fetch (match_info, 1), (char **)NULL, 10);
        val_cur = g_ascii_strtoll (g_match_info_fetch (match_info, 2), (char **)NULL, 10);
        val_total = g_ascii_strtoll (g_match_info_fetch (match_info, 3), (char **)NULL, 10);
        perc = compute_percents (stage, total_stages, val_cur, val_total);
    } else {
        g_match_info_free (match_info);
        return -1;
    }
    g_match_info_free (match_info);
    return perc;
}
Example #2
0
static char *get_floppy_label(const char* path) {
    if (!path || path[0] == '\0') {
        return g_strdup("");
    }
    char *name = g_path_get_basename(path);
#ifdef USE_GLIB
    GError *error = NULL;
    GRegex *re = g_regex_new(
                     "([A-Za-z0-9_ ]*[Dd][Ii][Ss][Kk][A-Za-z0-9_ ]*)",
                     0, 0, &error);
    if (error) {
        fs_emu_log(" *** error\n");
        return name;
    }
    GMatchInfo *mi = NULL;
    if (!g_regex_match(re, name, 0, &mi) || !g_match_info_matches(mi)) {
        //fs_emu_log(" *** false\n");
        g_match_info_free(mi);
        g_regex_unref(re);
        return name;
    }
    //fs_emu_log(" *** ok?\n");
    char *result = g_match_info_fetch(mi, 1);
    g_match_info_free(mi);
    g_regex_unref(re);
    if (!result) {
        return name;
    }
    g_free(name);
    return result;
#else
    return name;
#endif
}
Example #3
0
/**
 * summer_download_youtube_new:
 * @item: a SummerItemData, containing information about the download.
 *
 * Creates a new #SummerDownloadYoutube.
 *
 * You're not supposed to call this function directly - instead, use the
 * factory %summer_create_download, which will go through all downloaders,
 * looking for one that's suitable.
 *
 * Returns: a newly created #SummerDownloadYoutube object if the item's mime
 * and url is suitable, otherwise %NULL.
 */
SummerDownload*
summer_download_youtube_new (SummerItemData *item)
{
	if (item->web_url == NULL)
		return NULL;

	GError *error = NULL;
	GRegex *v = g_regex_new ("^((?:http://)?(?:\\w+\\.)?youtube\\.com/(?:v/|(?:watch(?:\\.php)?)?\\?(?:.+&)?v=))?([0-9A-Za-z_-]+)(?(1)[&/].*)?$", 0, 0, &error);
	if (error) {
		g_warning ("Error compiling regex: %s", error->message);
		g_clear_error (&error);
		return NULL;
	}

	GMatchInfo *info;
	g_regex_match (v, item->web_url, 0, &info);
	
	if (g_match_info_matches (info)) {
		g_regex_unref (v);
		SummerDownloadYoutube *dl;
		SummerDownloadableData *dlable = summer_item_data_append_downloadable (
			item, NULL, NULL, 0);
		dl = g_object_new (SUMMER_TYPE_DOWNLOAD_YOUTUBE, 
			"item", item, "downloadable", dlable, NULL);
		g_object_unref (dlable);
		dl->priv->v = g_match_info_fetch (info, 2);
		g_match_info_free (info);
		return SUMMER_DOWNLOAD (dl);
	}
	g_match_info_free (info);
	
	return NULL;
}
Example #4
0
File: rules.c Project: aihua/moloch
void moloch_rules_load_complete()
{
    char      **bpfs;
    GRegex     *regex = g_regex_new(":\\s*(\\d+)\\s*$", 0, 0, 0);
    int         i;

    bpfs = moloch_config_str_list(NULL, "dontSaveBPFs", NULL);
    int pos = moloch_field_by_exp("_maxPacketsToSave");
    gint start_pos;
    if (bpfs) {
        for (i = 0; bpfs[i]; i++) {
            int n = loading.rulesLen[MOLOCH_RULE_TYPE_SESSION_SETUP]++;
            MolochRule_t *rule = loading.rules[MOLOCH_RULE_TYPE_SESSION_SETUP][n] = MOLOCH_TYPE_ALLOC0(MolochRule_t);
            rule->filename = "dontSaveBPFs";
            moloch_field_ops_init(&rule->ops, 1, MOLOCH_FIELD_OPS_FLAGS_COPY);

            GMatchInfo *match_info = 0;
            g_regex_match(regex, bpfs[i], 0, &match_info);
            if (g_match_info_matches(match_info)) {
                g_match_info_fetch_pos (match_info, 1, &start_pos, NULL);
                rule->bpf = g_strndup(bpfs[i], start_pos-1);
                moloch_field_ops_add(&rule->ops, pos, g_match_info_fetch(match_info, 1), -1);
            } else {
                rule->bpf = g_strdup(bpfs[i]);
                moloch_field_ops_add(&rule->ops, pos, "1", -1);
            }
            g_match_info_free(match_info);
        }
        g_strfreev(bpfs);
    }

    bpfs = moloch_config_str_list(NULL, "minPacketsSaveBPFs", NULL);
    pos = moloch_field_by_exp("_minPacketsBeforeSavingSPI");
    if (bpfs) {
        for (i = 0; bpfs[i]; i++) {
            int n = loading.rulesLen[MOLOCH_RULE_TYPE_SESSION_SETUP]++;
            MolochRule_t *rule = loading.rules[MOLOCH_RULE_TYPE_SESSION_SETUP][n] = MOLOCH_TYPE_ALLOC0(MolochRule_t);
            rule->filename = "minPacketsSaveBPFs";
            moloch_field_ops_init(&rule->ops, 1, MOLOCH_FIELD_OPS_FLAGS_COPY);

            GMatchInfo *match_info = 0;
            g_regex_match(regex, bpfs[i], 0, &match_info);
            if (g_match_info_matches(match_info)) {
                g_match_info_fetch_pos (match_info, 1, &start_pos, NULL);
                rule->bpf = g_strndup(bpfs[i], start_pos-1);
                moloch_field_ops_add(&rule->ops, pos, g_match_info_fetch(match_info, 1), -1);
            } else {
                rule->bpf = g_strdup(bpfs[i]);
                moloch_field_ops_add(&rule->ops, pos, "1", -1);
            }
            g_match_info_free(match_info);
        }
        g_strfreev(bpfs);
    }
    g_regex_unref(regex);

    memcpy(&current, &loading, sizeof(loading));
    memset(&loading, 0, sizeof(loading));
}
Example #5
0
/* splits an input string into a date-time part and an optional operator part.
   operator can be any of "=", "<", ">", "<=", ">=" and "<>".
   range notation [x;y] can also be used
   datetime values should follow the pattern YYYY:mm:dd HH:MM:SS
   but only year part is mandatory

   datetime and operator are returned as pointers to null terminated strings in g_mallocated
   memory (to be g_free'd after use) - or NULL if no match is found.
*/
void dt_collection_split_operator_datetime(const gchar *input, char **number1, char **number2, char **operator)
{
  GRegex *regex;
  GMatchInfo *match_info;
  int match_count;

  *number1 = *number2 = *operator= NULL;

  // we test the range expression first
  // 2 elements : date-time1 and  date-time2
  regex = g_regex_new("^\\s*\\[\\s*(\\d{4}[:\\d\\s]*)\\s*;\\s*(\\d{4}[:\\d\\s]*)\\s*\\]\\s*$", 0, 0, NULL);
  g_regex_match_full(regex, input, -1, 0, 0, &match_info, NULL);
  match_count = g_match_info_get_match_count(match_info);

  if(match_count == 3)
  {
    gchar *txt = g_match_info_fetch(match_info, 1);
    gchar *txt2 = g_match_info_fetch(match_info, 2);

    *number1 = _dt_collection_compute_datetime(">=", txt);
    *number2 = _dt_collection_compute_datetime("<=", txt2);
    *operator= g_strdup("[]");

    g_free(txt);
    g_free(txt2);
    g_match_info_free(match_info);
    g_regex_unref(regex);
    return;
  }

  g_match_info_free(match_info);
  g_regex_unref(regex);

  // and we test the classic comparaison operators
  // 2 elements : operator and date-time
  regex = g_regex_new("^\\s*(=|<|>|<=|>=|<>)?\\s*(\\d{4}[:\\d\\s]*)?\\s*%?\\s*$", 0, 0, NULL);
  g_regex_match_full(regex, input, -1, 0, 0, &match_info, NULL);
  match_count = g_match_info_get_match_count(match_info);

  if(match_count == 3)
  {
    *operator= g_match_info_fetch(match_info, 1);
    gchar *txt = g_match_info_fetch(match_info, 2);

    if(strcmp(*operator, "") == 0 || strcmp(*operator, "=") == 0 || strcmp(*operator, "<>") == 0)
      *number1 = dt_util_dstrcat(*number1, "%s%%", txt);
    else
      *number1 = _dt_collection_compute_datetime(*operator, txt);

    g_free(txt);
  }

  // ensure operator is not null
  if(!*operator) *operator= g_strdup("");

  g_match_info_free(match_info);
  g_regex_unref(regex);
}
Example #6
0
void buses_load() {
	if(g_mkdir_with_parents(getProgData("pacebus"),0755) != 0
		|| g_mkdir_with_parents(getProgData("ctabus"),0755) != 0) {
		g_warning("Couldn't create buses folders");
	}
	GDir* pacebuses = g_dir_open(getProgData("pacebus"),0,NULL);
	GDir* ctabuses   = g_dir_open(getProgData("ctabus"),0,NULL);
	const gchar *name;
	GRegex *regex;
	GMatchInfo *match_info;
	GtkComboBox *paceroutes = GTK_COMBO_BOX(glade_xml_get_widget(xml, "paceroutes"));
	GtkComboBox *ctaroutes = GTK_COMBO_BOX(glade_xml_get_widget(xml, "ctaroutes"));
	
	/* clear these routes first, bad experiences if we don't 
	   hopefully its ok to reuse model like this, i doubt we gotta clear it
	*/
	GtkListStore* model = GTK_LIST_STORE(gtk_combo_box_get_model(paceroutes));
	gtk_list_store_clear(model);
	model = GTK_LIST_STORE(gtk_combo_box_get_model(ctaroutes));
	gtk_list_store_clear(model);

	/* handle pace buses first */
	name = g_dir_read_name(pacebuses);
	regex = g_regex_new("(\\d+)map\\.pdf$",0,0,NULL);
	while (name != NULL) {
		//check we got the right kind....we skip schedules, hope that if theres a map theres both
		if(g_regex_match(regex,name,0,&match_info)) {
			gchar *busroute = g_match_info_fetch (match_info, 1);
			gtk_combo_box_append_text(paceroutes,busroute);
			g_free(busroute);
		}
		g_match_info_free(match_info);
		name = g_dir_read_name(pacebuses);
	}
	g_regex_unref(regex);
	g_dir_close(pacebuses);
	
	/* now for CTA stuff */
	name = g_dir_read_name(ctabuses);
	regex = g_regex_new("(\\d+)\\.pdf$",0,0,NULL);
	while(name != NULL) {
		/* this would only not match if people are putting crap in the directory */
		if(g_regex_match(regex,name,0,&match_info)) {
			gchar *busroute = g_match_info_fetch (match_info, 1);
			gtk_combo_box_append_text(ctaroutes,busroute);
			g_free(busroute);
		}
		g_match_info_free(match_info);
		name = g_dir_read_name(ctabuses);
	}
	g_regex_unref(regex);
	g_dir_close(ctabuses);
}
Example #7
0
static gboolean c_connect_set_hubaddr(char *addr) {
  // Validate and parse
  GRegex *reg = g_regex_new(
    //   1 - proto                2 - host             3 - port                       4 - kp
    "^(?:(dchub|nmdcs?|adcs?)://)?([^ :/<>\\(\\)]+)(?::([0-9]+))?(?:/|/\\?kp=SHA256\\/([a-zA-Z2-7]{52}))?$",
    0, 0, NULL);
  g_assert(reg);
  GMatchInfo *nfo;
  if(!g_regex_match(reg, addr, 0, &nfo)) {
    ui_m(NULL, 0, "Invalid URL format."); // not very specific
    g_regex_unref(reg);
    return FALSE;
  }
  g_regex_unref(reg);
  char *proto = g_match_info_fetch(nfo, 1);
  char *kp = g_match_info_fetch(nfo, 4);

  if(kp && *kp && strcmp(proto, "adcs") != 0 && strcmp(proto, "nmdcs") != 0) {
    ui_m(NULL, 0, "Keyprint is only valid for adcs:// or nmdcs:// URLs.");
    g_match_info_free(nfo);
    g_free(proto);
    g_free(kp);
    return FALSE;
  }

  char *host = g_match_info_fetch(nfo, 2);
  char *port = g_match_info_fetch(nfo, 3);
  g_match_info_free(nfo);

  struct ui_tab *tab = ui_tab_cur->data;
  char *old = g_strdup(var_get(tab->hub->id, VAR_hubaddr));

  // Reconstruct (without the kp) and save
  GString *a = g_string_new("");
  g_string_printf(a, "%s://%s:%s/", !proto || !*proto ? "dchub" : proto, host, !port || !*port ? "411" : port);
  var_set(tab->hub->id, VAR_hubaddr, a->str, NULL);

  // Save kp if specified, or throw it away if the URL changed
  if(kp && *kp)
    var_set(tab->hub->id, VAR_hubkp, kp, NULL);
  else if(old && strcmp(old, a->str) != 0)
    var_set(tab->hub->id, VAR_hubkp, NULL, NULL);

  g_string_free(a, TRUE);
  g_free(old);
  g_free(proto);
  g_free(kp);
  g_free(host);
  g_free(port);
  return TRUE;
}
Example #8
0
static void
cb_media_downloader_load_twitter_video (CbMediaDownloader *downloader,
                                        CbMedia           *media)
{
  SoupMessage *msg = soup_message_new ("GET", media->url);
  GRegex      *regex;
  GMatchInfo  *match_info;

  soup_session_send_message (downloader->soup_session, msg);
  if (msg->status_code != SOUP_STATUS_OK)
    {
      mark_invalid (media);
      g_object_unref (msg);
      return;
    }

  regex = g_regex_new ("<img src=\"(.*?)\" class=\"animated-gif-thumbnail", 0, 0, NULL);
  g_regex_match (regex, (const char *)msg->response_body->data, 0, &match_info);

  if (g_match_info_get_match_count (match_info) > 0)
    {
      g_assert (media->type == CB_MEDIA_TYPE_ANIMATED_GIF);
      media->url = g_match_info_fetch (match_info, 1);

      g_regex_unref (regex);
      g_match_info_free (match_info);
      g_object_unref (msg);
      return;
    }
  else
    {
      g_regex_unref (regex);
      g_match_info_free (match_info);

      regex = g_regex_new ("<source video-src=\"(.*?)\"", 0, 0, NULL);
      g_regex_match (regex, (const char *)msg->response_body->data, 0, &match_info);
      media->url = g_match_info_fetch (match_info, 1);
      media->type = CB_MEDIA_TYPE_TWITTER_VIDEO;
    }

  g_regex_unref (regex);
  g_match_info_free (match_info);

  regex = g_regex_new ("poster=\"(.*?)\"", 0, 0, NULL);
  g_regex_match (regex, (const char *)msg->response_body->data, 0, &match_info);
  media->thumb_url = g_match_info_fetch (match_info, 1);

  g_regex_unref (regex);
  g_match_info_free (match_info);
  g_object_unref (msg);
}
Example #9
0
File: ttx.c Project: djcb/ttx
static gboolean
get_address_maybe (TTXProviderMgr *prov_mgr, Opts *opts, GError **err)
{
	GRegex *rx;
	GMatchInfo *minfo;
	char* str;
	const char *addr;

	minfo = NULL;
	str   = NULL;

	if (!opts->params || !opts->params[0])
		return TRUE; /* nothing to do here */

	addr = opts->params[0];

	rx = g_regex_new ("(\\w+):(\\d{3})(/(\\d{1,2}))?", 0, 0, err);
	if (!rx)
		return FALSE;

	if (!g_regex_match (rx, addr, 0, &minfo)) {
		g_printerr (_("invalid link; expected: "
			      "<provider-id>:<page>[/<subpage>]\n"
			      "e.g., nos:101/1 or yle:200\n"));
		g_match_info_free (minfo);
		g_regex_unref (rx);
		return FALSE;
	}

	opts->prov_id = g_match_info_fetch (minfo, 1);
	str = g_match_info_fetch (minfo, 2);

	opts->page = atoi (str);
	g_free (str);

	if (g_match_info_get_match_count (minfo) < 5)
		opts->subpage = 1;
	else {
		str = g_match_info_fetch (minfo, 4);
		opts->subpage = atoi (str);
		g_free (str);
	}

	g_match_info_free (minfo);
	g_regex_unref (rx);

	return check_address (prov_mgr, opts->prov_id, opts->page,
			      opts->subpage);
}
Example #10
0
/* splits an input string into a number part and an optional operator part.
   number can be a decimal integer or rational numerical item.
   operator can be any of "=", "<", ">", "<=", ">=" and "<>".

   number and operator are returned as pointers to null terminated strings in g_mallocated
   memory (to be g_free'd after use) - or NULL if no match is found.
*/
void
dt_collection_split_operator_number (const gchar *input, char **number, char **operator)
{
  GRegex *regex;
  GMatchInfo *match_info;
  int match_count;

  *number = *operator = NULL;
   
  regex = g_regex_new("\\s*(=|<|>|<=|>=|<>)?\\s*([0-9]+\\.?[0-9]*)\\s*", 0, 0, NULL);
  g_regex_match_full(regex, input, -1, 0, 0, &match_info, NULL);
  match_count = g_match_info_get_match_count(match_info);

  if(match_count == 3)
  {
    *operator = g_match_info_fetch(match_info, 1);
    *number = g_match_info_fetch(match_info, 2);

    if(*operator && strcmp(*operator, "") == 0)
    {
      g_free(*operator);
      *operator = NULL;
    }
  }

  g_match_info_free(match_info);
  g_regex_unref(regex);
} 
Example #11
0
void latex_analyse_errors(GuLatex* lc)
{
  gchar* result = NULL;
  GError* err = NULL;
  GRegex* match_str = NULL;
  GMatchInfo* match_info;

  if (!(match_str = g_regex_new(":(\\d+):", G_REGEX_DOTALL, 0, &err))) {
    slog(L_ERROR, "g_regex_new (): %s\n", err->message);
    g_error_free(err);
    return;
  }

  if (lc->compilelog == NULL) printf("null\n");

  if (g_regex_match(match_str, lc->compilelog, 0, &match_info)) {
    gint count = 0;
    while (g_match_info_matches(match_info)) {
      if (count + 1 == BUFSIZ) break;
      result = g_match_info_fetch(match_info, 1);
      lc->errorlines[count++] = atoi(result);
      g_free(result);
      g_match_info_next(match_info, NULL);
    }
  }
  if (!lc->errorlines[0])
    lc->errorlines[0] = -1;
  g_match_info_free(match_info);
  g_regex_unref(match_str);
}
Example #12
0
gchar*
sch_text_get_attribute_value(const SchText *shape)
{
    gchar *value = NULL;

    if (shape != NULL)
    {
        SchTextClass *klasse = SCH_TEXT_GET_CLASS(shape);

        if ((klasse != NULL) && (klasse->regex != NULL))
        {
            GMatchInfo *match_info;
            gchar *string = sch_text_get_string(shape);

            g_regex_match(klasse->regex, string, 0, &match_info);

            if (g_match_info_matches(match_info))
            {
                value = g_match_info_fetch(match_info, 2);
            }

            g_match_info_free(match_info);
            g_free(string);
        }
    }

    return value;
}
Example #13
0
GPtrArray* getCVEUrls(const string &changelog)
{
    GPtrArray *cve_urls = g_ptr_array_new();

    // Regular expression to find cve references
    GRegex *regex;
    GMatchInfo *match_info;
    regex = g_regex_new("CVE-\\d{4}-\\d{4,}",
                        G_REGEX_CASELESS,
                        G_REGEX_MATCH_NEWLINE_ANY,
                        0);
    g_regex_match (regex, changelog.c_str(), G_REGEX_MATCH_NEWLINE_ANY, &match_info);
    while (g_match_info_matches(match_info)) {
        gchar *cve = g_match_info_fetch (match_info, 0);
        gchar *cveLink;

        cveLink = g_strdup_printf("http://web.nvd.nist.gov/view/vuln/detail?vulnId=%s", cve);
        g_ptr_array_add(cve_urls, (gpointer) cveLink);

        g_free(cve);
        g_match_info_next(match_info, NULL);
    }
    g_match_info_free(match_info);
    g_regex_unref(regex);

    // NULL terminate
    g_ptr_array_add(cve_urls, NULL);

    return cve_urls;
}
Example #14
0
/**
 * gstreamill_get_job:
 * @uri: (in): access uri, e.g. /live/test/encoder/0
 *
 * Get the Job by access uri.
 *
 * Returns: job
 */
Job *gstreamill_get_job (Gstreamill *gstreamill, gchar *uri)
{
        Job *job = NULL;
        GRegex *regex;
        GMatchInfo *match_info;
        gchar *name = NULL;

        regex = g_regex_new ("^/(live|dvr)/(?<name>[^/]*)/.*", G_REGEX_OPTIMIZE, 0, NULL);
        match_info = NULL;
        g_regex_match (regex, uri, 0, &match_info);
        g_regex_unref (regex);
        if (g_match_info_matches (match_info)) {
                name = g_match_info_fetch_named (match_info, "name");
        }

        if (name != NULL) {
                job = get_job (gstreamill, name);
                g_free (name);
        }
        if (match_info != NULL) {
                g_match_info_free (match_info);
        }

        return job;
}
Example #15
0
static GList *
get_camera_module_paths (const gchar *path)
{
    GRegex *pattern;
    GDir *dir;
    GList *result = NULL;

    pattern = g_regex_new (MODULE_PATTERN, 0, 0, NULL);
    dir = g_dir_open (path, 0, NULL);

    if (dir != NULL) {
        GMatchInfo *match_info = NULL;
        const gchar *name = g_dir_read_name (dir);

        while (name != NULL) {
            if (g_regex_match (pattern, name, 0, &match_info))
                result = g_list_append (result, g_build_filename (path, name, NULL));

            g_match_info_free (match_info);
            name = g_dir_read_name (dir);
        }
    }

    g_dir_close (dir);
    g_regex_unref (pattern);

    return result;
}
Example #16
0
int
s3_regexec_wrap(regex_t *regex,
           const char *str,
           size_t nmatch,
           regmatch_t pmatch[],
           int eflags)
{
    GMatchInfo *match_info;
    int ret = REG_NOERROR;
    guint i;

    g_assert(regex && *regex);
    g_regex_match(*regex, str, eflags, &match_info);
    if (g_match_info_matches(match_info)) {
        g_assert(g_match_info_get_match_count(match_info) <= (glong) nmatch);
        for (i = 0; i < nmatch; i++) {
            pmatch[i].rm_eo = pmatch[i].rm_so = -1;
            g_match_info_fetch_pos(match_info, i, &pmatch[i].rm_so, &pmatch[i].rm_eo);
        }
    } else {
        ret = REG_NOMATCH;
    }
    g_match_info_free(match_info);
    return ret;
}
Example #17
0
/**
 * ggit_config_match:
 * @config: a #GgitConfig.
 * @regex: a #GRegex.
 * @match_info: (out) (allow-none): a #GMatchInfo.
 * @error: a #GError for error reporting, or %NULL.
 *
 * Matches a configuration against a regular expression. @match_info will
 * contain the match information if the return value is not %NULL, otherwise
 * @error will be set.
 *
 * Returns: (allow-none): the value of that matched configuration
 *
 **/
const gchar *
ggit_config_match (GgitConfig  *config,
                   GRegex      *regex,
                   GMatchInfo **match_info,
                   GError     **error)
{
	MatchInfo info = {0,};

	g_return_val_if_fail (GGIT_IS_CONFIG (config), FALSE);
	g_return_val_if_fail (regex != NULL, FALSE);
	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

	info.regex = regex;

	ggit_config_foreach (config, (GgitConfigCallback)match_foreach, &info, NULL);

	if (info.ret)
	{
		if (match_info)
		{
			*match_info = info.ret;
		}
		else
		{
			g_match_info_free (info.ret);
		}
	}

	if (!info.value)
	{
		_ggit_error_set (error, GGIT_ERROR_NOTFOUND);
	}

	return info.value;
}
Example #18
0
File: irc.c Project: donthi/ircbot
irc_msg* irc_next_message(irc_connection *con)
{
    gboolean ret;
    GMatchInfo *info;
    irc_msg *ircmsg = NULL;
    char *raw_msg = irc_next_message_rawstr(con);

    if (!raw_msg) goto ircmsg_out;

    ret = g_regex_match(irc_msg_regex_pattern, raw_msg, 0, &info);

    int matches = g_match_info_get_match_count(info);
    if (matches != 5) goto ircmsg_out;

    ircmsg = malloc(sizeof(irc_msg));
    if (!ircmsg) goto ircmsg_out;

    Copy_match(info, 1, ircmsg->source);
    Copy_match(info, 2, ircmsg->command);
    Copy_match(info, 3, ircmsg->target);
    Copy_match(info, 4, ircmsg->params);

ircmsg_out:
    g_match_info_free(info);
    return ircmsg;
}
Example #19
0
gboolean
gm_entry_text_is_valid (GmEntry *self)
{
  GMatchInfo *match_info = NULL;
  gboolean success = FALSE;
  gchar *value = NULL;

  g_return_val_if_fail (GM_IS_ENTRY (self), success);

  const char *content = gtk_entry_get_text (GTK_ENTRY (self));
  value = g_strdup (content);
  value = g_strstrip (value);
  // First check if value is empty or not
  if (!g_strcmp0 (value, "")) {
    g_free (value);
    return self->priv->allow_empty;
  }
  g_free (value);

  // Here, value is not empty, we check the regex
  if (!self->priv->regex)
    return TRUE;

  g_regex_match (self->priv->regex, content, 0, &match_info);

  if (g_match_info_matches (match_info))
    success = TRUE;

  g_match_info_free (match_info);

  return success;
}
Example #20
0
Ref<String>
regexMatch (Regex *regex,
	    ConstMemoryDesc const &mdesc,
	    int match_num)
{
    GMatchInfo *match_info = NULL;

    gboolean match = g_regex_match_full ((GRegex*) regex->regex,
					 (const gchar*) mdesc.getMemory (),
					 // FIXME Overflow check
					 (gssize) mdesc.getLength (),
					 0, // start_position
					 (GRegexMatchFlags) 0,
					 &match_info,
					 NULL);
    if (!match)
	return grab (new String);

    gchar *ret_str = g_match_info_fetch (match_info, match_num);
    abortIf (ret_str == NULL);

    g_match_info_free (match_info);

    return grab (static_cast <String*> (new String_ExtAlloc (ret_str,
							     countStrLength (ret_str),
							     regex_free_callback)));
}
static void
rakia_codec_param_parse_telephone_event (const gchar *fmtp,
    TpMediaStreamType media_type,
    RakiaSipCodec *codec)
{
  GMatchInfo *match = NULL;
  gint end_pos = 0;

  g_assert (dtmf_events_regex != NULL);

  /* Parse the events list */

  g_regex_match (dtmf_events_regex, fmtp, 0, &match);

  if (g_match_info_matches (match))
    {
      gchar *events;

      events = g_match_info_fetch (match, 1);
      rakia_sip_codec_add_param (codec, "events", events);
      g_free (events);
      g_match_info_fetch_pos (match, 0, NULL, &end_pos);
    }

  g_match_info_free (match);

  /* Parse the remaining parameters, if any */
  rakia_codec_param_parse_generic (fmtp + end_pos, media_type, codec);
}
Example #22
0
void
mc_search_free (mc_search_t * lc_mc_search)
{
    if (lc_mc_search == NULL)
        return;

    g_free (lc_mc_search->original);
#ifdef HAVE_CHARSET
    g_free (lc_mc_search->original_charset);
#endif
    g_free (lc_mc_search->error_str);

    if (lc_mc_search->conditions != NULL)
        mc_search__conditions_free (lc_mc_search->conditions);

#ifdef SEARCH_TYPE_GLIB
    if (lc_mc_search->regex_match_info != NULL)
        g_match_info_free (lc_mc_search->regex_match_info);
#else /* SEARCH_TYPE_GLIB */
    g_free (lc_mc_search->regex_match_info);
#endif /* SEARCH_TYPE_GLIB */

    if (lc_mc_search->regex_buffer != NULL)
        g_string_free (lc_mc_search->regex_buffer, TRUE);

    g_free (lc_mc_search);
}
Example #23
0
static gint
match_foreach (const gchar *name,
               const gchar *value,
               MatchInfo   *info)
{
	if (g_regex_match (info->regex, name, (GRegexMatchFlags)0, &info->ret))
	{
		if (info->callback)
		{
			gint ret;

			ret = info->callback (info->ret, value, info->user_data);
			g_match_info_free (info->ret);

			return ret;
		}
		else
		{
			info->value = value;

			/* Semi arbitrary error */
			return GGIT_ERROR_EXISTS;
		}
	}

	return GIT_OK;
}
static int
_parse_kcmdline (void)
{
        int ret = CMDLINE_UNSET;
        GRegex *regex;
        GMatchInfo *match;
        char *contents;
        char *word;
        const char *arg;

        if (!g_file_get_contents ("/proc/cmdline", &contents, NULL, NULL))
                return ret;

        regex = g_regex_new ("gnome.fallback=(\\S+)", 0, G_REGEX_MATCH_NOTEMPTY, NULL);
        if (!g_regex_match (regex, contents, G_REGEX_MATCH_NOTEMPTY, &match))
                goto out;

        word = g_match_info_fetch (match, 0);
        g_debug ("Found command-line match '%s'", word);
        arg = word + strlen ("gnome.fallback=");
        if (*arg != '0' && *arg != '1')
                fprintf (stderr, "gnome-session-is-accelerated: Invalid value '%s' for gnome.fallback passed in kernel command line.\n", arg);
        else
                ret = atoi (arg);
        g_free (word);

out:
        g_match_info_free (match);
        g_regex_unref (regex);
        g_free (contents);

        g_debug ("Command-line parsed to %d", ret);

        return ret;
}
Example #25
0
gboolean biblio_detect_bibliography (GuBiblio* bc, GuEditor* ec) {
    gchar* content = NULL;
    gchar* bibfn = NULL;
    gchar** result = NULL;
    GMatchInfo *match_info;
    GRegex* bib_regex = NULL;
    gboolean state = FALSE;

    content = editor_grab_buffer (ec);
    bib_regex = g_regex_new ("^[^%]*\\\\bibliography{\\s*([^{}\\s]*)\\s*}",
        G_REGEX_MULTILINE, 0, NULL);
    if (g_regex_match (bib_regex, content, 0, &match_info)) {
        result = g_match_info_fetch_all (match_info);
        if (result[1]) {
            if (!STR_EQU (result[1] +strlen (result[1]) -4, ".bib"))
                bibfn = g_strconcat (result[1], ".bib", NULL);
            else
                bibfn = g_strdup (result[1]);
            state = editor_fileinfo_update_biblio (ec, bibfn);
            g_free (bibfn);
        }
        slog (L_INFO, "Detect bibliography file: %s\n", ec->bibfile);
        g_strfreev (result);
    }
    g_free (content);
    g_match_info_free (match_info);
    g_regex_unref (bib_regex);
    return state;
}
Example #26
0
static gchar *
gdb_find_register_function (const gchar *path)
{
	GFile *file;
	gchar *function = NULL;
	gchar *content = NULL;

	file = g_file_new_for_path (path);

	if (g_file_load_contents (file, NULL, &content, NULL, NULL, NULL))
	{
		GRegex *regex;
		GMatchInfo *match;

		regex = g_regex_new ("^def\\s+(register\\w*)\\s*\\(\\w+\\)\\s*:", G_REGEX_CASELESS | G_REGEX_MULTILINE, 0, NULL);
		if (g_regex_match (regex, content, 0, &match))
		{
			function = g_match_info_fetch (match, 1);
			g_match_info_free (match);
		}
		g_regex_unref (regex);
		g_free (content);
	}

	g_object_unref (file);

	return function;
}
Example #27
0
Reader *tokenize(char *line) {
    GRegex *regex;
    GMatchInfo *matchInfo;
    GError *err = NULL;

    Reader *reader = reader_new();

    regex = g_regex_new ("[\\s ,]*(~@|[\\[\\]{}()'`~@]|\"(?:[\\\\].|[^\\\\\"])*\"|;.*|[^\\s \\[\\]{}()'\"`~@,;]*)", 0, 0, &err);   
    g_regex_match (regex, line, 0, &matchInfo);

    if (err != NULL) {
        fprintf(stderr, "Tokenize error: %s\n", err->message);
        return NULL;
    }
    
    while (g_match_info_matches(matchInfo)) {
        gchar *result = g_match_info_fetch(matchInfo, 1);
        if (result[0] != '\0' && result[0] != ';') {
            reader_append(reader, result);
        }
        g_match_info_next(matchInfo, &err);
    }
    g_match_info_free(matchInfo);
    g_regex_unref(regex);
    if (reader->array->len == 0) {
        reader_free(reader);
        return NULL;
    } else {
        return reader;
    }
}
Example #28
0
static mc_search__found_cond_t
mc_search__regex_found_cond_one (mc_search_t * mc_search, mc_search_regex_t * regex,
                                 GString * search_str)
{
#ifdef SEARCH_TYPE_GLIB
    GError *error = NULL;

    if (!g_regex_match_full
        (regex, search_str->str, -1, 0, G_REGEX_MATCH_NEWLINE_ANY, &mc_search->regex_match_info,
         &error)) {
        g_match_info_free (mc_search->regex_match_info);
        mc_search->regex_match_info = NULL;
        if (error) {
            mc_search->error = MC_SEARCH_E_REGEX;
            mc_search->error_str = str_conv_gerror_message (error, _(" Regular expression error "));
            g_error_free (error);
            return COND__FOUND_ERROR;
        }
        return COND__NOT_FOUND;
    }
    mc_search->num_rezults = g_match_info_get_match_count (mc_search->regex_match_info);
#else /* SEARCH_TYPE_GLIB */
    mc_search->num_rezults = pcre_exec (regex, mc_search->regex_match_info,
                                        search_str->str, search_str->len - 1, 0, 0, mc_search->iovector,
                                        MC_SEARCH__NUM_REPLACE_ARGS);
    if (mc_search->num_rezults < 0) {
        return COND__NOT_FOUND;
    }
#endif /* SEARCH_TYPE_GLIB */
    return COND__FOUND_OK;

}
Example #29
0
static gint encoder_extract_streams (Encoder *encoder, gchar **bins)
{
        GRegex *regex;
        GMatchInfo *match_info;
        EncoderStream *stream;
        gchar *bin, **p;

        p = bins;
        while (*p != NULL) {
                bin = *p;
                regex = g_regex_new ("appsrc *name=(?<name>[^ ]*)", G_REGEX_OPTIMIZE, 0, NULL);
                g_regex_match (regex, bin, 0, &match_info);
                g_regex_unref (regex);
                if (g_match_info_matches (match_info)) {
                        stream = (EncoderStream *)g_malloc (sizeof (EncoderStream));
                        stream->name = g_match_info_fetch_named (match_info, "name");
                        g_match_info_free (match_info);
                        g_array_append_val (encoder->streams, stream);
                        GST_INFO ("encoder stream %s found %s", stream->name, bin);

                } else if (g_str_has_prefix (bin, "appsrc")) {
                        GST_ERROR ("appsrc name property must be set");
                        return 1;
                }
                p++;
        }

        return 0;
}
gboolean
is_ip4_address (gchar * in_address)
{
	gchar *pattern =
	    "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.((\\{\\d{1,3}\\.\\.\\d{1,3}\\})|\\d{1,3})$";
	gchar *address = g_strdup (in_address);
	gboolean result = FALSE;
	gchar *tmp;
	GRegex *regex = g_regex_new (pattern, 0, 0, NULL);
	GMatchInfo *match_info;

	if (!address)
		goto done;
	g_strstrip (address);
	if ((tmp = strstr (address, "/")) != NULL)
		*tmp = '\0';
	if ((tmp = strstr (address, " ")) != NULL)
		*tmp = '\0';
	g_regex_match (regex, address, 0, &match_info);
	result = g_match_info_matches (match_info);
      done:
	if (match_info)
		g_match_info_free (match_info);
	g_regex_unref (regex);
	g_free (address);
	return result;
}