void ao_payload_cap(st_ao_packet* pck, st_http_data* http_data) { GList* tlist = g_list_first(pl_targets); while (tlist) { // Target st_pl_target* target = (st_pl_target*) tlist->data; // HTTP matching if (target->cap_type == PL_CAP_HTTP) { // Match path and host gint match_path = 0; if (target->cap_http_path && http_data->req_url) match_path = g_regex_match_simple(target->cap_http_path, http_data->req_url, 0, 0) ? 2 : 1; gint match_host = 0; if (target->cap_http_host && http_data->hdr_host) match_host = g_regex_match_simple(target->cap_http_host, http_data->hdr_host, 0, 0) ? 2 : 1; // Check if matches g_print("[pay] http match! path=%d, host=%d\n", match_path, match_host); if ((match_path == 2 || match_host == 2) && !(match_path == 1 || match_host == 1)) { ao_payload_inj(pck, target); return; } } // Next target tlist = g_list_next(tlist); } }
static void hev_scgi_handler_filebox_handle (HevSCGIHandler *self, GObject *scgi_task) { HevSCGIHandlerFileboxPrivate *priv = HEV_SCGI_HANDLER_FILEBOX_GET_PRIVATE(self); GObject *request = NULL; GHashTable *req_hash_table = NULL; gchar *request_uri = NULL; gsize request_uri_len; g_debug("%s:%d[%s]", __FILE__, __LINE__, __FUNCTION__); request = hev_scgi_task_get_request (HEV_SCGI_TASK (scgi_task)); req_hash_table = hev_scgi_request_get_header_hash_table (HEV_SCGI_REQUEST (request)); request_uri = g_hash_table_lookup (req_hash_table, "REQUEST_URI"); request_uri_len = strlen (request_uri); request_uri += (priv->base_uri_len > request_uri_len) ? request_uri_len : priv->base_uri_len; if (g_regex_match_simple ("^upload$", request_uri, 0, 0)) { /* uploader */ hev_scgi_handler_filebox_handle_upload (self, scgi_task); } else if (g_regex_match_simple ("^query\\?(.+)$", request_uri, 0, 0)) { /* querier */ hev_scgi_handler_filebox_handle_query (self, scgi_task); } else if (g_regex_match_simple ("^delete\\?(.+)$", request_uri, 0, 0)) { /* deleter */ hev_scgi_handler_filebox_handle_delete (self, scgi_task); } else { /* downloader */ hev_scgi_handler_filebox_handle_download (self, scgi_task); } }
static gchar figure_out_comma_fix_char(const gchar *line) { gchar *comma, *end; /* Not a number, try again. */ if (!g_ascii_strtod(line, &end) && end == line) return 0; /* There are decimal dots => POSIX. */ if (strchr(line, '.')) return ' '; /* There are no commas => POSIX. */ comma = strchr(line, ','); if (!comma) return ' '; /* There are spaces after commas => POSIX. */ if (g_regex_match_simple(",[ \t]", line, G_REGEX_NO_AUTO_CAPTURE, 0)) return ' '; /* There is a contiguous block of digits and commas => POSIX. */ if (g_regex_match_simple("[0-9],[0-9]+,[0-9]", line, G_REGEX_NO_AUTO_CAPTURE, 0)) return ' '; /* There are commas and may actually be inside numbers. Assume the decimal * separator is coma. */ return '.'; }
/** \brief Determine if name is generic. * \param satname The satellite name that might be old. * * This function determines if the satellite name is generic. Examples of this are the names YYYY-NNNAAA * international ID names used by Celestrak. Also space-track.org will give items names of OBJECT A as * well until the name is advertised. * */ static gboolean is_computer_generated_name (gchar *satname) { /* celestrak generic satellite name */ if (g_regex_match_simple ("\\d{4,}-\\d{3,}",satname,0,0)){ return (TRUE); } /* space-track generic satellite name */ if (g_regex_match_simple ("OBJECT",satname,0,0)){ return (TRUE); } return (FALSE); }
gboolean get_special_wait_from_window_data (gchar *res_name, gchar * class_name,const gchar *title) { /* Exec,Name,filename, special_id. If all in the first 3 match then the special_id is returned. TODO put data into a separate file TODO optimize the regex handling. */ WindowWait *iter; for (iter = windows_to_wait; iter->wait; iter++) { gboolean match = TRUE; #ifdef DEBUG g_debug ("%s: iter->res_name = %s, res_name = %s",__func__,iter->res_name,res_name); #endif if (iter->res_name) { match = res_name && g_regex_match_simple(iter->res_name, res_name,0,0); if (!match) continue; } #ifdef DEBUG g_debug ("%s: iter->class_name = %s, class_name = %s",__func__,iter->class_name,class_name); #endif if (iter->class_name) { match = class_name && g_regex_match_simple(iter->class_name, class_name,0,0); if (!match) continue; } #ifdef DEBUG g_debug ("%s: iter->title = %s, title = %s",__func__,iter->title,title); #endif if (iter->title) { match = title && g_regex_match_simple(iter->title, title,0,0); if (!match) continue; } #ifdef DEBUG g_debug ("%s: Special Wait Window ID:",__func__); #endif return TRUE; } return FALSE; }
/** * @return GList of cflags (strings) in a format like /usr/include/my_foo_lib. * @return NULL on error. */ static GList * sdb_system_get_normalized_cflags (const gchar *chars) { gchar **flags; gint i; GList *good_flags; const gchar *curr_flag; /* We should receive here something like * '-I/usr/include/gimp-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include'. * Split up the chars and take a decision if we like it or not. */ flags = g_strsplit (chars, " ", -1); i = 0; /* if, after the while loop, good_flags is != NULL that means that we found * some good flags to include for a future scan */ good_flags = NULL; while ((curr_flag = flags[i++]) != NULL) { /* '-I/usr/include/gimp-2.0' would be good, but '/usr/include/' wouldn't. */ if (g_regex_match_simple ("\\.*/include/\\w+", curr_flag, 0, 0) == TRUE) { /* FIXME the +2. It's to skip the -I */ DEBUG_PRINT ("adding %s to good_flags", curr_flag +2); /* FIXME the +2. It's to skip the -I */ good_flags = g_list_prepend (good_flags, g_strdup (curr_flag + 2)); } } g_strfreev (flags); return good_flags; }
gchar *rc_tag_find_file(const gchar *dirname, const gchar *str, const gchar *extname) { gchar extname_regstr[256]; GDir *gdir; gchar *rfilename = NULL; const gchar *fname_foreach = NULL; if(dirname==NULL || str==NULL || extname==NULL) return NULL; if(strlen(str)<=0) return NULL; gdir = g_dir_open(dirname, 0, NULL); if(gdir==NULL) return NULL; bzero(extname_regstr, 256); g_snprintf(extname_regstr, 255, "(%s)$", extname); while((fname_foreach=g_dir_read_name(gdir))!=NULL) { if(g_regex_match_simple(extname_regstr, fname_foreach, G_REGEX_CASELESS, 0)) { if(g_str_has_prefix(fname_foreach, str)) { rfilename = g_build_filename(dirname, fname_foreach, NULL); break; } } } g_dir_close(gdir); return rfilename; }
void cons_check_version(gboolean not_available_msg) { char *latest_release = release_get_latest(); if (latest_release != NULL) { gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); if (relase_valid) { if (release_is_new(latest_release)) { win_print_time(console, '-'); wprintw(console->win, "A new version of Profanity is available: %s", latest_release); win_print_time(console, '-'); wprintw(console->win, "Check <http://www.profanity.im> for details.\n"); free(latest_release); win_print_time(console, '-'); wprintw(console->win, "\n"); } else { if (not_available_msg) { cons_show("No new version available."); cons_show(""); } } ui_console_dirty(); cons_alert(); } } }
static void regexp_test () { gint i; gchar *indent; const gchar *text = texts[0]; for (i = 1; text != NULL; i++) { g_debug ("new line"); if (g_regex_match_simple ("{\\.*[^}]*\\.*$", text, 0, 0)) { printf ("%s\n", text); indent = get_indent (text); if (indent) { printf ("%s print();\n", indent); g_free (indent); } } else { printf ("%s (NOT)\n", text); } text = texts[i]; } }
static void check_status (const gchar *status) { gchar *pattern; if (getenv ("DEBUG")) g_print ("%s\n", status); if (failed) return; statuses = g_list_append (statuses, g_strdup (status)); /* Try and match against expected */ pattern = get_script_line (); if (!pattern || !g_regex_match_simple (pattern, status, 0, 0)) { fail (NULL, pattern); return; } script_iter = script_iter->next; /* Restart timeout */ if (status_timeout) g_source_remove (status_timeout); status_timeout = g_timeout_add (STATUS_TIMEOUT, status_timeout_cb, NULL); run_commands (); }
gboolean open_app_pattern_match (const gchar *pattern_name, const gchar *content, GError **error) { OpenAppRegex data [] = { {"blank", "[\\s]+", G_REGEX_MATCH_ANCHORED, N_("It is not blank")}, {"notblank", "[^\\s]+", G_REGEX_MATCH_PARTIAL, N_("Should not be blank")}, {"email", "[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}", G_REGEX_MATCH_ANCHORED, N_("Enter the valid email address")}, {"password", "[a-zA-Z0-9]{8,}$", G_REGEX_MATCH_ANCHORED, N_("The password should be >=8 alphanumeric chars")}, {NULL, NULL, 0, NULL}, }; gint i; if (!content || !content [0]) { g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_MATCH, _("The text should not be NULL")); return FALSE; } for (i = 0; data [i].name; i++) { if (strcasecmp (pattern_name, data [i].name) == 0) { if (g_regex_match_simple (data [i].pattern, content, G_REGEX_OPTIMIZE, data [i].flags)) { return TRUE; } else { g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_MATCH, _(data [i].message)); return FALSE; } } } g_set_error (error, G_REGEX_ERROR, G_REGEX_ERROR_MATCH, _("Cannot find the <%s> pattern\n"), pattern_name); return FALSE; }
/*! \brief gets called to set the entry backgroup color based on a match or not \param entry is a pointer to the MaskEntry structure */ G_MODULE_EXPORT void mask_entry_set_background (MaskEntry *entry) { gchar *tmpbuf = NULL; gchar *tmpstr = NULL; gint len = 0; static const GdkColor error_color = { 0, 65535, 60000, 60000 }; if (entry->mask) { tmpstr = g_utf8_normalize(gtk_entry_get_text (GTK_ENTRY (entry)),-1,G_NORMALIZE_DEFAULT); tmpbuf = g_utf8_casefold(tmpstr,-1); g_free(tmpstr); if (g_regex_match_simple(tmpbuf,entry->mask, (GRegexCompileFlags)0,(GRegexMatchFlags)0)) { gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, &error_color); g_free(tmpbuf); return; } g_free(tmpbuf); } gtk_widget_modify_base (GTK_WIDGET (entry), GTK_STATE_NORMAL, NULL); return; }
gchar *add_links_to_text(const gchar * original) { /* return if original already contains links */ if (g_regex_match_simple("<a\\s.*>", original, 0, 0)) { return g_strdup(original); } gchar *newText, *url, *link; GMatchInfo *match_info; GRegex *regex = g_regex_new("(https?://[a-zA-Z0-9_\\-\\./?=&]+)", 0, 0, NULL); // extract url and build escaped link g_regex_match(regex, original, 0, &match_info); url = g_match_info_fetch(match_info, 1); if(url) { link = g_markup_printf_escaped("<a href='%s'>%s</a>", url, url); newText = g_regex_replace(regex, original, -1, 0, link, 0, NULL); g_free(url); g_free(link); } else { newText = g_strdup(original); } g_regex_unref(regex); g_match_info_unref(match_info); return newText; }
bool Actions::match_pattern( const char * source, const String & pattern ) { bool result = false; if ( ! source ) { if ( pattern.empty() ) { result = true; } else { result = match_pattern( "", pattern ); } } else if ( strlen( source ) == 0 && pattern.empty() ) { result = true; } else { if ( pattern.empty() ) { result = false; } else { result = g_regex_match_simple( pattern.c_str(), source, GRegexCompileFlags( 0 ), GRegexMatchFlags( 0 ) ); } } return result; }
soundfile_t * soundfile_open_read(const char *path) { dp(30, "path=%s \n", path); soundfile_t *s = salloc(sizeof *s); s->m = sft_read; if (g_regex_match_simple ("\\.wv$", path, 0, 0)) { char error[80] = {0}; int flags = 0; int norm_offset = 0; s->t = sft_wavpack; s->p = WavpackOpenFileInput(path, error, flags, norm_offset); if (!s->p) die("can not open input file '%s'", path); s->bits_per_sample = WavpackGetBitsPerSample(s->p); s->channels = WavpackGetNumChannels(s->p); s->samplerate = WavpackGetSampleRate(s->p); s->frames = WavpackGetNumSamples(s->p); } else { SF_INFO infile_info = {0}; if (strcmp(path, "-")) s->p = sf_open(path, SFM_READ, &infile_info); else s->p = sf_open_fd(0, SFM_READ, &infile_info, 0); if (!s->p) die("can not open input file '%s'", path); s->t = sft_libsndfile; s->channels = infile_info.channels; s->samplerate = infile_info.samplerate; s->frames = infile_info.frames; } return s; }
static void _ask_for_auth_confirmation_response_cb (GtkDialog *dialog, gint response, gpointer data) { gboolean valid = FALSE; if (response == GTK_RESPONSE_CLOSE) { const gchar *vercode_part1 = NULL; const gchar *vercode_part2 = NULL; const gchar *vercode_part3 = NULL; g_autofree gchar *vercode_full = NULL; vercode_part1 = _get_entry_code_for_dialog (dialog, "vercode-1"); vercode_part2 = _get_entry_code_for_dialog (dialog, "vercode-2"); vercode_part3 = _get_entry_code_for_dialog (dialog, "vercode-3"); vercode_full = g_strdup_printf ("%s-%s-%s", vercode_part1, vercode_part2, vercode_part3); /* Ensure the user enters a valid verification code */ if (g_regex_match_simple ("[0-9]{3}(-[0-9]{3}){2}", vercode_full, 0, 0)) { frogr_controller_complete_auth (frogr_controller_get_instance(), vercode_full); valid = TRUE; } else frogr_util_show_error_dialog (GTK_WINDOW (dialog), _("Invalid verification code")); } if (response == GTK_RESPONSE_CANCEL || valid) gtk_widget_destroy (GTK_WIDGET (dialog)); }
int check(gchar *const link) { int valid = 0; CURL *curl; CURLcode curl_res; buffer = g_string_sized_new(65536); curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, link); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, save_downloaded_content); curl_res = curl_easy_perform(curl); curl_easy_cleanup(curl); if (curl_res == CURLE_OK) { if (g_regex_match_simple("var\\ current_file\\ =\\ \\{.*\"mimetype\":\"video\".*\\}", buffer->str, 0, 0)) valid = 1; } } g_string_free(buffer, FALSE); return valid; }
static gboolean history_is_visible(GtkTreeModel* model, GtkTreeIter* iter, gpointer data UNUSED) { /* Skip conferences */ if (is_conference(model, iter)) return TRUE; // Fetch the call description const gchar *text = NULL; const gchar *id = NULL; gtk_tree_model_get(model, iter, COLUMN_ACCOUNT_DESC, &text, COLUMN_ID, &id, -1); callable_obj_t *history_entry = calllist_get_call(history_tab, id); gboolean ret = TRUE; if (text && history_entry) { // Filter according to the type of call // MISSED, INCOMING, OUTGOING, ALL const gchar* search = gtk_entry_get_text(history_searchbar_widget); if (!search || !*search) return TRUE; SearchType search_type = get_current_history_search_type(); ret = g_regex_match_simple(search, text, G_REGEX_CASELESS, 0); if (search_type == SEARCH_ALL) return ret; else // We need a match on the history_state and the current search type ret = ret && search_type_matches_state(search_type, history_entry->_history_state); } return ret; }
/* Finds out if route file has new or older format * Returns TRUE - new syntax (ADDRESS<n>=a.b.c.d ...), error opening file or empty * FALSE - older syntax, i.e. argument to 'ip route add' (1.2.3.0/24 via 11.22.33.44) */ gboolean utils_has_route_file_new_syntax (const char *filename) { char *contents = NULL; gsize len = 0; gboolean ret = FALSE; const char *pattern = "^[[:space:]]*ADDRESS[0-9]+="; g_return_val_if_fail (filename != NULL, TRUE); if (!g_file_get_contents (filename, &contents, &len, NULL)) return TRUE; if (len <= 0) { ret = TRUE; goto gone; } if (g_regex_match_simple (pattern, contents, G_REGEX_MULTILINE, 0)) ret = TRUE; gone: g_free (contents); return ret; }
/** * Determine if the string vector contains any element which * matches the specified regex. * * \param strv String vector. * \param regex Regular expression. * * \return \c true on success, else \c false. */ gboolean strv_contains_regex (gchar **strv, const char *regex) { gchar **s; gboolean ret; g_assert (strv); g_assert (regex); for (s = strv; s && *s; s++) { /* Handle lines that contain an allocated string * terminator only. */ if (! g_strcmp0 (*s, "")) { continue; } ret = g_regex_match_simple (regex, *s, 0, 0); if (ret) { return true; } } return false; }
static void window_changed_cb(RoccatEventhandlerHost *host, gchar const *title, gpointer user_data) { PyraEventhandler *eventhandler = PYRA_EVENTHANDLER(user_data); PyraEventhandlerPrivate *priv = eventhandler->priv; guint profile_index; guint game_file_index; gchar *pattern; for (profile_index = 0; profile_index < PYRA_PROFILE_NUM; ++profile_index) { if (priv->rmp[profile_index] == NULL) continue; for (game_file_index = 0; game_file_index < PYRA_GAMEFILE_NUM; ++game_file_index) { pattern = pyra_rmp_get_game_file_name(priv->rmp[profile_index], game_file_index); if (strcmp(pattern, "") == 0) { g_free(pattern); continue; } if (g_regex_match_simple(pattern, title, 0, 0)) { set_profile(eventhandler, profile_index + 1); g_free(pattern); return; } g_free(pattern); } } set_profile(eventhandler, pyra_configuration_get_default_profile_number(priv->config)); return; }
static gboolean exo_open_uri_known_category (const gchar *uri, const gchar *scheme, gboolean *succeed) { guint i; const gchar *category = NULL; g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (scheme != NULL, FALSE); /* check if the scheme matches a known preferred application type */ for (i = 0; category == NULL && i < G_N_ELEMENTS (known_schemes); i++) { if (g_regex_match_simple (known_schemes[i].pattern, scheme, G_REGEX_CASELESS, 0)) { /* launch the preferred application */ *succeed = exo_open_launch_category (known_schemes[i].category, uri); /* we always return, because we found a matching scheme */ return TRUE; } } return FALSE; }
static gboolean logcat_text_read_packet(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf, gint file_type) { gint8 *pd; gchar cbuff[WTAP_MAX_PACKET_SIZE]; gchar *ret = NULL; do { ret = file_gets(cbuff, WTAP_MAX_PACKET_SIZE, fh); } while (NULL != ret && 3 > strlen(cbuff) && !file_eof(fh)); if (NULL == ret || 3 > strlen(cbuff)) { return FALSE; } if (WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG == file_type && !g_regex_match_simple(SPECIAL_STRING, cbuff, (GRegexCompileFlags)((gint) G_REGEX_ANCHORED | (gint) G_REGEX_RAW), G_REGEX_MATCH_NOTEMPTY)) { gint64 file_off = 0; gchar lbuff[WTAP_MAX_PACKET_SIZE]; int err; gchar *ret2 = NULL; file_off = file_tell(fh); ret2 = file_gets(lbuff,WTAP_MAX_PACKET_SIZE, fh); while (NULL != ret2 && 2 < strlen(lbuff) && !file_eof(fh)) { g_strlcat(cbuff,lbuff,WTAP_MAX_PACKET_SIZE); file_off = file_tell(fh); ret2 = file_gets(lbuff,WTAP_MAX_PACKET_SIZE, fh); } if(NULL == ret2 || 2 < strlen(lbuff)) { return FALSE; } file_seek(fh,file_off,SEEK_SET,&err); } phdr->rec_type = REC_TYPE_PACKET; phdr->caplen = (guint32)strlen(cbuff); phdr->len = phdr->caplen; ws_buffer_assure_space(buf, phdr->caplen + 1); pd = ws_buffer_start_ptr(buf); if ((WTAP_FILE_TYPE_SUBTYPE_LOGCAT_TIME == file_type || WTAP_FILE_TYPE_SUBTYPE_LOGCAT_THREADTIME == file_type || WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG == file_type) && '-' != cbuff[0]) { /* the last part filters out the -- beginning of... lines */ if (WTAP_FILE_TYPE_SUBTYPE_LOGCAT_LONG == file_type) { get_time(cbuff+2, phdr); } else { get_time(cbuff, phdr); } } else { phdr->presence_flags = 0; phdr->ts.secs = (time_t) 0; phdr->ts.nsecs = (int) 0; } memcpy(pd, cbuff, phdr->caplen + 1); return TRUE; }
soundfile_t * soundfile_open_write(const char *path, int n_channels, double sampling_rate) { dp(30, "path=%s n_channels=%d sampling_rate=%g\n", path, n_channels, sampling_rate); soundfile_t *s = salloc(sizeof *s); s->m = sft_write; s->channels = n_channels; s->samplerate = sampling_rate; if (g_regex_match_simple ("\\.wv$", path, 0, 0)) { s->t = sft_wavpack; s->file = fopen(path, "w+b"); if (!s->file) die("can not open output file '%s'", path); WavpackContext *wpc = s->p = WavpackOpenFileOutput(write_block, s, NULL); if (!s->p) die("can not open input file '%s'", path); WavpackConfig config = {0}; config.bytes_per_sample = 2; s->bits_per_sample = config.bits_per_sample = 16; config.channel_mask = n_channels == 1 ? 4 : 3; // Microsoft standard: 4 == mono, 3 == stereo config.num_channels = n_channels; config.sample_rate = sampling_rate; if (!WavpackSetConfiguration(wpc, &config, -1)) die("WavpackSetConfiguration failed: %s\n", WavpackGetErrorMessage(wpc)); if (!WavpackPackInit(wpc)) die("WavpackPackInit failed: %s\n", WavpackGetErrorMessage(wpc)); } else { SF_INFO outfile_info = {0}; outfile_info.samplerate = sampling_rate; outfile_info.channels = n_channels; outfile_info.format = SF_FORMAT_PCM_16; if (g_regex_match_simple ("\\.flac$", path, 0, 0)) outfile_info.format |= SF_FORMAT_FLAC; else outfile_info.format |= SF_FORMAT_WAV; if (strcmp(path, "-")) s->p = sf_open(path, SFM_WRITE, &outfile_info); else s->p = sf_open_fd(1, SFM_WRITE, &outfile_info, 0); // write to stdout if name is "-" if (!s->p) die("can not open output file '%s'", path); s->t = sft_libsndfile; } return s; }
gboolean extcap_complex_get_bool(extcap_complex *comp) { if ( comp == NULL || comp->_val == NULL ) return FALSE; if ( comp->complex_type != EXTCAP_ARG_BOOLEAN && comp->complex_type != EXTCAP_ARG_BOOLFLAG ) return FALSE; return g_regex_match_simple(EXTCAP_BOOLEAN_REGEX, comp->_val, G_REGEX_CASELESS, (GRegexMatchFlags)0 ); }
static int _osync_version_match(char *pattern, char* string, OSyncError **error) { osync_assert(pattern); osync_assert(string); if(!strlen(pattern)) return 1; /* Only newer versions of glib support regular expressions */ /* On Windows the glib regular expressions are required */ #if GLIB_MAJOR_VERSION < 3 && GLIB_MINOR_VERSION < 14 regex_t *preg = osync_try_malloc0(sizeof(regex_t), error); if(!preg) goto error; int ret = regcomp(preg, pattern, 0); char *errbuf; size_t errbuf_size; if(ret) { errbuf_size = regerror(ret, preg, NULL, 0); errbuf = osync_try_malloc0(errbuf_size, error); if(!errbuf) goto error_and_free; regerror(ret, preg, errbuf, errbuf_size); osync_error_set(error, OSYNC_ERROR_GENERIC, "%s", errbuf); osync_free(errbuf); goto error_and_free; } ret = regexec(preg, string, 0, NULL, 0); regfree(preg); osync_free(preg); if(ret != 0) { if(ret == REG_NOMATCH) return 0; errbuf_size = regerror(ret, preg, NULL, 0); errbuf = osync_try_malloc0(errbuf_size, error); if(!errbuf) goto error; regerror(ret, preg, errbuf, errbuf_size); osync_error_set(error, OSYNC_ERROR_GENERIC, "%s", errbuf); osync_free(errbuf); goto error; } return 1; error_and_free: regfree(preg); osync_free(preg); error: return -1; #else /* GLIB_MAJOR_VERSION < 3 && GLIB_MINOR_VERSION < 14 */ return g_regex_match_simple(pattern, string, 0, 0); #endif }
static gboolean is_banner_icon_image (const gchar *filename) { /* Check if this screenshot was uploaded as "banner-icon.png" or "banner-icon.jpg". * The server optionally adds a 7 character suffix onto it if it would collide with * an existing name, e.g. "banner-icon_Ugn6pmj.png" * See https://forum.snapcraft.io/t/improve-method-for-setting-featured-snap-banner-image-in-store/ */ return g_regex_match_simple ("^banner-icon(?:_[a-zA-Z0-9]{7})?\\.(?:png|jpg)$", filename, 0, 0); }
/** * gssdp_resource_browser_set_target: * @resource_browser: A #GSSDPResourceBrowser * @target: The browser target * * Sets the browser target of @resource_browser to @target. **/ void gssdp_resource_browser_set_target (GSSDPResourceBrowser *resource_browser, const char *target) { char *pattern; char *version; const char *version_pattern; GError *error; GSSDPResourceBrowserPrivate *priv; g_return_if_fail (GSSDP_IS_RESOURCE_BROWSER (resource_browser)); g_return_if_fail (target != NULL); priv = gssdp_resource_browser_get_instance_private (resource_browser); g_return_if_fail (!priv->active); g_free (priv->target); priv->target = g_strdup (target); g_clear_pointer (&priv->target_regex, g_regex_unref); version_pattern = "([0-9]+)"; /* Make sure we have enough room for version pattern */ pattern = g_strndup (target, strlen (target) + strlen (version_pattern)); version = g_strrstr (pattern, ":"); if (version != NULL && (g_strstr_len (pattern, -1, "uuid:") != pattern || version != g_strstr_len (pattern, -1, ":")) && g_regex_match_simple (version_pattern, version + 1, G_REGEX_ANCHORED, G_REGEX_MATCH_ANCHORED)) { priv->version = atoi (version + 1); strcpy (version + 1, version_pattern); } error = NULL; priv->target_regex = g_regex_new (pattern, 0, 0, &error); if (error) { g_warning ("Error compiling regular expression '%s': %s", pattern, error->message); g_error_free (error); } g_free (pattern); g_object_notify (G_OBJECT (resource_browser), "target"); }
GList * empathy_log_manager_get_dates (EmpathyLogManager *manager, McAccount *account, const gchar *chat_id, gboolean chatroom) { GList *dates = NULL; gchar *date; gchar *directory; GDir *dir; const gchar *filename; const gchar *p; g_return_val_if_fail (EMPATHY_IS_LOG_MANAGER (manager), NULL); g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); g_return_val_if_fail (chat_id != NULL, NULL); directory = log_manager_get_dir (manager, account, chat_id, chatroom); dir = g_dir_open (directory, 0, NULL); if (!dir) { DEBUG ("Could not open directory:'%s'", directory); g_free (directory); return NULL; } DEBUG ("Collating a list of dates in:'%s'", directory); while ((filename = g_dir_read_name (dir)) != NULL) { if (!g_str_has_suffix (filename, LOG_FILENAME_SUFFIX)) { continue; } p = strstr (filename, LOG_FILENAME_SUFFIX); date = g_strndup (filename, p - filename); if (!date) { continue; } if (!g_regex_match_simple ("\\d{8}", date, 0, 0)) { continue; } dates = g_list_insert_sorted (dates, date, (GCompareFunc) strcmp); } g_free (directory); g_dir_close (dir); DEBUG ("Parsed %d dates", g_list_length (dates)); return dates; }
/** * Ensure the specified timestamp is in the expected ISO-8601 format. * * An example timestamp is: * * 2016-05-12T16:45:05.567822Z * * \param timestamp String to check. * * \return \c true on success, else \c false. */ gboolean check_timestamp_format (const gchar *timestamp) { return g_regex_match_simple ( "\\b" /* start of string */ "\\d{4}-\\d{2}-\\d{2}" /* YYYY-MM-DD */ "T" /* time separator */ "\\d{2}:\\d{2}:\\d{2}" /* HH:MM:SS */ "\\.\\d{6}" /* ".XXXXXX" (microseconds) */ "\\S*" /* timezone (or "Z" for localtime) */ "\\b", /* end of string */ timestamp, 0, 0); }