예제 #1
0
파일: rules.c 프로젝트: 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));
}
static gboolean
parse_octi_response (const gchar *response,
                     MMModemAccessTechnology *access_technology)
{
    MMModemAccessTechnology current = MM_MODEM_ACCESS_TECHNOLOGY_UNKNOWN;
    const gchar *p;
    GRegex *r;
    GMatchInfo *match_info;
    gchar *str;
    gboolean success = FALSE;

    p = mm_strip_tag (response, "_OCTI:");
    r = g_regex_new ("(\\d),(\\d)", G_REGEX_UNGREEDY, 0, NULL);
    g_assert (r != NULL);

    g_regex_match (r, p, 0, &match_info);
    if (g_match_info_matches (match_info)) {
        str = g_match_info_fetch (match_info, 2);
        if (str && octi_to_mm (str[0], &current)) {
            *access_technology = current;
            success = TRUE;
        }
        g_free (str);
    }
    g_match_info_free (match_info);
    g_regex_unref (r);

    return success;
}
예제 #3
0
static gboolean is_http_progress_play_url (RequestData *request_data)
{
        GRegex *regex = NULL;
        GMatchInfo *match_info = NULL;
        gchar *e;
        gint index;

        if (request_data->parameters[0] != '\0') {
                GST_WARNING ("parameters is needless : %s?%s", request_data->uri, request_data->parameters);
                return FALSE;
        }

        index = -1;
        regex = g_regex_new ("^/live/.*/encoder/(?<encoder>[0-9]+)$", G_REGEX_OPTIMIZE, 0, NULL);
        g_regex_match (regex, request_data->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_DEBUG ("not http progress play uri: %s", request_data->uri);
                return FALSE;
        }

        return TRUE;
}
예제 #4
0
파일: sch-text.c 프로젝트: bert/gparts
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;
}
예제 #5
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;
}
예제 #6
0
파일: latex.c 프로젝트: aitjcize/Gummi
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);
}
예제 #7
0
파일: menu.c 프로젝트: jens-maus/fs-uae
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
}
예제 #8
0
파일: url.c 프로젝트: KrullKorg/libzakcgi
void
hook (GMatchInfo *minfo, gpointer user_data)
{
    GString *str = (GString *)user_data;

    g_string_append_printf (str, "FROM THE HOOK<br/><br/>\n");

    while (g_match_info_matches (minfo))
    {
        guint n = g_match_info_get_match_count (minfo);
        g_string_append_printf (str, "Match count: %d<br/><br/>\n", n);
        gchar *word = g_match_info_fetch (minfo, 0);
        g_string_append_printf (str, "Found: %s<br/><br/>\n", word);
        g_free (word);

        guint i;
        for (i = 1; i < n; i++)
        {
            gchar *word = g_match_info_fetch (minfo, i);
            g_string_append_printf (str, "sub %d: %s<br/><br/>\n", i, word);
            g_free (word);
        }

        if (n > 1)
        {
            word = g_match_info_fetch_named (minfo, "controller");
            g_string_append_printf (str, "sub named controller: %s<br/><br/>\n", word);
            g_free (word);
        }

        g_match_info_next (minfo, NULL);
    }
}
static gint sdp_get_codec_pt_for_type(const gchar * sdp, const gchar * type)
{
	gchar *result = NULL;
	gchar * expr_str = g_strdup_printf("m=%s[ \t]+[0-9]+[ \t]+UDP/TLS/RTP/SAVPF[ \t]+[0-9]+", type);
	GRegex *regex = g_regex_new(expr_str, 0, 0, NULL);
	gint codec_pt = -1;
	
	g_free(expr_str);
	
	if (regex != NULL) {
		GMatchInfo *matchInfo;
		g_regex_match(regex, sdp, 0, &matchInfo);
	
		if (g_match_info_matches(matchInfo)) {
			result = g_match_info_fetch(matchInfo, 0);
				
			if (result) {							
				gchar * sscanf_str = g_strdup_printf("m=%s%%*[ \t]%%*d%%*[ \t]UDP/TLS/RTP/SAVPF%%*[ \t]%%d", type);	 
				sscanf(result, sscanf_str, &codec_pt);
				 
				g_free(sscanf_str);
				g_free(result);
			}
		}
			
		g_regex_unref(regex);
	}
	
	return codec_pt;
}
예제 #10
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;
}
예제 #11
0
static GHashTable *
parse_schema (gchar *schema)
{
	GRegex *regex;
	GMatchInfo *match;
	GError *error = NULL;
	GHashTable *hash;

	hash = g_hash_table_new(g_str_hash, g_str_equal);
	regex = g_regex_new("(\\w+)=\"(.*?)\"", 0, 0, &error);

	if (error) {
		HASHFS_DEBUG("Failed to create regex: %s", error->message);

		g_error_free(error);

		return NULL;
	}

	g_regex_match(regex, schema, 0, &match);
	while (g_match_info_matches(match)) {
		gchar *key = g_match_info_fetch(match, 1);
		gchar *val = g_match_info_fetch(match, 2);

		g_hash_table_insert(hash, key, val);

		g_match_info_next(match, NULL);
	}

	g_match_info_free(match);
	g_regex_unref(regex);

	return hash;
}
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;
}
예제 #13
0
static void
kms_webrtc_session_parse_turn_url (KmsWebrtcSession * self)
{
  GRegex *regex;
  GMatchInfo *match_info = NULL;

  g_free (self->turn_user);
  self->turn_user = NULL;
  g_free (self->turn_password);
  self->turn_password = NULL;
  g_free (self->turn_address);
  self->turn_address = NULL;

  if ((self->turn_url == NULL)
      || (g_strcmp0 ("", self->turn_url) == 0)) {
    GST_INFO_OBJECT (self, "TURN server info cleared");
    return;
  }

  regex =
      g_regex_new
      ("^(?<user>.+):(?<password>.+)@(?<address>[0-9.]+):(?<port>[0-9]+)(\\?transport=(?<transport>(udp|tcp|tls)))?$",
      0, 0, NULL);
  g_regex_match (regex, self->turn_url, 0, &match_info);
  g_regex_unref (regex);

  if (g_match_info_matches (match_info)) {
    gchar *port_str;
    gchar *turn_transport;

    self->turn_user = g_match_info_fetch_named (match_info, "user");
    self->turn_password = g_match_info_fetch_named (match_info, "password");
    self->turn_address = g_match_info_fetch_named (match_info, "address");

    port_str = g_match_info_fetch_named (match_info, "port");
    self->turn_port = g_ascii_strtoll (port_str, NULL, 10);
    g_free (port_str);

    self->turn_transport = TURN_PROTOCOL_UDP;   /* default */
    turn_transport = g_match_info_fetch_named (match_info, "transport");
    if (turn_transport != NULL) {
      if (g_strcmp0 ("tcp", turn_transport) == 0) {
        self->turn_transport = TURN_PROTOCOL_TCP;
      } else if (g_strcmp0 ("tls", turn_transport) == 0) {
        self->turn_transport = TURN_PROTOCOL_TLS;
      }
      g_free (turn_transport);
    }

    GST_INFO_OBJECT (self, "TURN server info set (%s)", self->turn_url);
  } else {
    GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
        ("URL '%s' not allowed. It must have this format: 'user:password@address:port(?transport=[udp|tcp|tls])'",
            self->turn_url),
        ("URL '%s' not allowed. It must have this format: 'user:password@address:port(?transport=[udp|tcp|tls])'",
            self->turn_url));
  }

  g_match_info_free (match_info);
}
예제 #14
0
파일: s3-util.c 프로젝트: TonyChiang/amanda
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;
}
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);
}
예제 #16
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;
}
예제 #17
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;
    }
}
예제 #18
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;
}
gint sdp_get_codec_pt(const gchar * sdp, idilia_codec codec)
{
	gint pt = -1;
	const gchar * codec_str = get_codec_name(codec);
	gchar * expr_str = g_strdup_printf("a=rtpmap:[0-9]+[ \t]+%s/", codec_str);
	
	GRegex *regex = g_regex_new(expr_str, 0, 0, NULL);
	g_free(expr_str);

	if (regex != NULL) {
		GMatchInfo *matchInfo;
		g_regex_match(regex, sdp, 0, &matchInfo);
	
		if (g_match_info_matches(matchInfo)) {
			gchar *result = g_match_info_fetch(matchInfo, 0);
		
			if (result) {
				gchar * sscanf_str = g_strdup_printf("a=rtpmap:%%d%%*[ \t]%s/", codec_str);
				sscanf(result, sscanf_str, &pt);
				
				g_free(sscanf_str);
				g_free(result);
			}
		}
		g_regex_unref(regex);
	}

	return pt;
}
예제 #20
0
파일: gm-entry.c 프로젝트: GNOME/ekiga
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;
}
예제 #21
0
static gint encoder_extract_streams (Encoder *encoder, gchar **bins)
{
    GRegex *regex;
    GMatchInfo *match_info;
    EncoderStream *stream, *segment_reference_stream = NULL;
    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);
            stream->is_segment_reference = FALSE;
            if (g_str_has_prefix (stream->name, "video") && strstr (bin, "x264enc") != NULL) {
                /* with video encoder */
                encoder->has_video = TRUE;
                if (!encoder->has_tssegment) {
                    segment_reference_stream = stream;
                    encoder->has_audio_only = FALSE;
                }
            }
            GST_INFO ("encoder stream %s found %s", stream->name, bin);

            if (g_str_has_prefix (stream->name, "audio")) {
                if (!(encoder->has_tssegment || encoder->has_video)) {
                    encoder->has_audio_only = TRUE;
                    segment_reference_stream = stream;
                }
            }

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

        if (strstr (bin, "tssegment") != NULL) {
            /* has tssegment element */
            encoder->has_tssegment = TRUE;
            encoder->has_video = FALSE;
            encoder->has_audio_only = FALSE;
            segment_reference_stream = NULL;
        }
        p++;
    }

    if (segment_reference_stream != NULL) {
        segment_reference_stream->is_segment_reference = TRUE;
    }

    return 0;
}
예제 #22
0
파일: snippets.c 프로젝트: bqv/gummi-vim
GuSnippetInfo* snippets_parse (char* snippet) {
    gint i, start, end;
    GError* err = NULL;
    gchar** result = NULL;
    GRegex* regex = NULL;
    GMatchInfo* match_info = NULL;
    const gchar* holders[] = { "\\$([0-9]+)", "\\${([0-9]*):?([^}]*)}",
                               "\\$(FILENAME)", "\\${(FILENAME)}",
                               "\\$(BASENAME)", "\\${(BASENAME)}",
                               "\\$(SELECTED_TEXT)", "\\${(SELECTED_TEXT)}"
                               /* Anyway to combine these? */
                            };

    GuSnippetInfo* info = snippet_info_new (snippet);

    for (i = 0; i < sizeof(holders) / sizeof(holders[0]); ++i) {
        if (! (regex = g_regex_new (holders[i], G_REGEX_DOTALL, 0, &err))) {
            slog (L_ERROR, "g_regex_new (): %s\n", err->message);
            g_error_free (err);
            return info;
        }
        g_regex_match (regex, snippet, 0, &match_info);
        while (g_match_info_matches (match_info)) {
            result = g_match_info_fetch_all (match_info);
            g_match_info_fetch_pos (match_info, 0, &start, &end);

            /* Convert start, end to UTF8 offset */
            char* s_start = g_substr(snippet, 0, start);
            char* s_end = g_substr(snippet, 0, end);
            start = g_utf8_strlen(s_start, -1);
            end = g_utf8_strlen(s_end, -1);
            g_free(s_start);
            g_free(s_end);

            if (i < 2) {
                snippet_info_append_holder (info, atoi (result[1]), start,
                        end -start, result[2]);
            } else {
                snippet_info_append_holder (info, -1, start, end -start,
                        result[1]);
            }
            slog (L_DEBUG, "Placeholder: (%s, %s, %s)\n", result[0], result[1],
                    result[2]);
            g_match_info_next (match_info, NULL);
            g_strfreev (result);
        }
        g_regex_unref (regex);
        g_match_info_free (match_info);
    }
    info->einfo = g_list_sort (info->einfo, snippet_info_pos_cmp);
    info->einfo_sorted = g_list_copy (info->einfo);
    info->einfo_sorted = g_list_sort (info->einfo_sorted, snippet_info_num_cmp);

    return info;
}
예제 #23
0
파일: Search.cpp 프로젝트: cnirrad/ViLike
//
// Protected
//
bool
SearchSupport::find_all( const Glib::ustring &pattern )
{
    m_matches.clear();

    Glib::ustring text = m_buffer->get_text();

    GRegex *regex;
    GMatchInfo *match_info;
    GRegexCompileFlags compile_flags;
    GRegexMatchFlags match_options;
    GError *error = NULL;

    regex = g_regex_new( pattern.data(), 
                         compile_flags, 
                         match_options, &error );

    if ( error )
    {
        g_print("Error while creating regex: %s\n", error->message);
        return false;
    }

    
    if (!g_regex_match( regex, text.data(), 
                        match_options, &match_info ))
    {
        return false;
    }

    gint start, end;

    int idx=0;
    while (g_match_info_matches(match_info))
    {
        if (!g_match_info_fetch_pos( match_info, 0, &start, &end ))
        {
            m_matches.clear();
            return false;
        }

        MatchInfo *info = new MatchInfo();
        info->start_pos = start;
        info->end_pos = end;
        m_matches.push_back( info );

        g_match_info_next( match_info, NULL ); 
    }

    g_match_info_free( match_info );
    g_regex_unref( regex );

    return true;
}
예제 #24
0
파일: url.c 프로젝트: N3X15/hexchat
static int
do_an_re(const char *word, int *start, int *end, int *type)
{
	typedef struct func_s {
		GRegex *(*fn)(void);
		int type;
	} func_t;
	func_t funcs[] =
	{
		{ re_url, WORD_URL },
		{ re_email, WORD_EMAIL },
		{ re_channel, WORD_CHANNEL },
		{ re_host6, WORD_HOST6 },
		{ re_host, WORD_HOST },
		{ re_path, WORD_PATH },
		{ re_nick, WORD_NICK }
	};

	GMatchInfo *gmi;
	int k;

	for (k = 0; k < sizeof funcs / sizeof (func_t); k++)
	{
		g_regex_match (funcs[k].fn(), word, 0, &gmi);
		if (!g_match_info_matches (gmi))
		{
			g_match_info_free (gmi);
			continue;
		}
		while (g_match_info_matches (gmi))
		{
			g_match_info_fetch_pos (gmi, 0, start, end);
			g_match_info_next (gmi, NULL);
		}
		g_match_info_free (gmi);
		*type = funcs[k].type;
		return TRUE;
	}

	return FALSE;
}
예제 #25
0
파일: urlregex.c 프로젝트: Like-all/mcabber
static inline void scr_log_urls(const gchar *string)
{
  GMatchInfo *match_info;

  g_regex_match_full(url_regex, string, -1, 0, 0, &match_info, NULL);
  while (g_match_info_matches(match_info)) {
    gchar *url = g_match_info_fetch(match_info, 0);
    scr_print_logwindow(url);
    g_free(url);
    g_match_info_next(match_info, NULL);
  }
  g_match_info_free(match_info);
}
예제 #26
0
파일: url.c 프로젝트: Farow/hexchat
void
url_check_line (char *buf, int len)
{
	GRegex *re(void);
	GMatchInfo *gmi;
	char *po = buf;
	int i;

	/* Skip over message prefix */
	if (*po == ':')
	{
		po = strchr (po, ' ');
		if (!po)
			return;
		po++;
	}
	/* Allow only commands from the above list */
	for (i = 0; i < ARRAY_SIZE (commands); i++)
	{
		char *cmd = commands[i];
		int len = strlen (cmd);

		if (strncmp (cmd, po, len) == 0)
		{
			po += len;
			break;
		}
	}
	if (i == ARRAY_SIZE (commands))
		return;

	/* Skip past the channel name or user nick */
	po = strchr (po, ' ');
	if (!po)
		return;
	po++;

	g_regex_match(re_url(), po, 0, &gmi);
	while (g_match_info_matches(gmi))
	{
		int start, end;

		g_match_info_fetch_pos(gmi, 0, &start, &end);
		while (end > start && (po[end - 1] == '\r' || po[end - 1] == '\n'))
			end--;
		if (g_strstr_len (po + start, end - start, "://"))
			url_add(po + start, end - start);
		g_match_info_next(gmi, NULL);
	}
	g_match_info_free(gmi);
}
예제 #27
0
static void
scan_matches(GRegex *regex, const char *string, GPtrArray *dst)
{
    GMatchInfo *match_info;
    char *match;

    g_regex_match(regex, string, G_REGEX_MATCH_NOTEMPTY, &match_info);
    while (g_match_info_matches(match_info)) {
        match = g_match_info_fetch(match_info, 1);
        g_ptr_array_add(dst, match);
        g_match_info_next(match_info, NULL);
    }
    g_match_info_free(match_info);
}
예제 #28
0
파일: url.c 프로젝트: Farow/hexchat
static gboolean
regex_match (const GRegex *re, const char *word, int *start, int *end)
{
	GMatchInfo *gmi;

	g_regex_match (re, word, 0, &gmi);
	
	if (!g_match_info_matches (gmi))
	{
		g_match_info_free (gmi);
		return FALSE;
	}
	
	while (g_match_info_matches (gmi))
	{
		g_match_info_fetch_pos (gmi, 0, start, end);
		g_match_info_next (gmi, NULL);
	}
	
	g_match_info_free (gmi);
	
	return TRUE;
}
예제 #29
0
static void
parse_unsolicited (MMPortSerial *port, GByteArray *response)
{
    MMPortSerialAt *self = MM_PORT_SERIAL_AT (port);
    GSList *iter;

    /* Remove echo */
    if (self->priv->remove_echo)
        mm_port_serial_at_remove_echo (response);

    for (iter = self->priv->unsolicited_msg_handlers; iter; iter = iter->next) {
        MMAtUnsolicitedMsgHandler *handler = (MMAtUnsolicitedMsgHandler *) iter->data;
        GMatchInfo *match_info;
        gboolean matches;

        if (!handler->enable)
            continue;

        matches = g_regex_match_full (handler->regex,
                                      (const char *) response->data,
                                      response->len,
                                      0, 0, &match_info, NULL);
        if (handler->callback) {
            while (g_match_info_matches (match_info)) {
                handler->callback (self, match_info, handler->user_data);
                g_match_info_next (match_info, NULL);
            }
        }

        g_match_info_free (match_info);

        if (matches) {
            /* Remove matches */
            char *str;
            int result_len = response->len;

            str = g_regex_replace_eval (handler->regex,
                                        (const char *) response->data,
                                        response->len,
                                        0, 0,
                                        remove_eval_cb, &result_len, NULL);

            g_byte_array_remove_range (response, 0, response->len);
            g_byte_array_append (response, (const guint8 *) str, result_len);
            g_free (str);
        }
    }
}
gchar * sdp_set_video_codec(const gchar * sdp_offer, idilia_codec video_codec) {
	
	gchar * sdp_answer = NULL;
	
	gint current_codec_pt = sdp_get_codec_pt_for_type(sdp_offer, "video");
	gint desired_codec_pt = sdp_get_codec_pt(sdp_offer, video_codec);
	
	/* do nothing in case the preferred codec is already selected, or if it does not exist in the SDP */
	if (current_codec_pt == desired_codec_pt || video_codec == IDILIA_CODEC_INVALID) {
		
		return g_strdup(sdp_offer);
		
	} else {
		gchar *result = NULL;		
		GRegex *regex = g_regex_new("m=video[ \t]+[0-9]+[ \t]+UDP/TLS/RTP/SAVPF[ \t]+[0-9]+[ \t]+[0-9]+", 0, 0, NULL);
		gint codec1 = -1, codec2 = -1;
		gint port_video = -1;
		if (regex != NULL) {
			GMatchInfo *matchInfo;
			g_regex_match(regex, sdp_offer, 0, &matchInfo);
			
			if (g_match_info_matches(matchInfo)) {
				result = g_match_info_fetch(matchInfo, 0);
				
				if (result) {					
					sscanf(result,"m=video%*[ \t]%d%*[ \t]UDP/TLS/RTP/SAVPF%*[ \t]%d%*[ \t]%d" ,&port_video,&codec1,&codec2);
					if (codec2 != desired_codec_pt) {
						codec1 = codec2;
					}
					
					gchar *new_line = g_strdup_printf("m=video %d UDP/TLS/RTP/SAVPF %d %d",port_video, desired_codec_pt, codec1);
					
					sdp_answer = str_replace_once(sdp_offer, result, new_line);
					
					g_free(new_line);
					g_free(result);
				}
			}
			else {
				sdp_answer = g_strdup(sdp_offer);
			}
			
			g_regex_unref(regex);
		}
	}
	
	return sdp_answer;
}