예제 #1
0
void
gb_source_view_set_search_regex (GbSourceView *view,
                                 GRegex       *search_regex)
{
   GbSourceViewPrivate *priv;

   g_return_if_fail(GB_IS_SOURCE_VIEW(view));

   priv = view->priv;

   g_clear_pointer(&priv->search_text, g_free);
   g_clear_pointer(&priv->search_regex, g_regex_unref);

   if (search_regex) {
      priv->search_regex = g_regex_ref(search_regex);
   }

   gb_source_view_update_search(view);

   if (priv->has_matches) {
      gb_source_view_move_next_match(view);
   }

   g_object_notify_by_pspec(G_OBJECT(view), gParamSpecs[PROP_SEARCH_REGEX]);
   g_object_notify_by_pspec(G_OBJECT(view), gParamSpecs[PROP_SEARCH_TEXT]);
}
예제 #2
0
void
mm_port_serial_at_add_unsolicited_msg_handler (MMPortSerialAt *self,
                                               GRegex *regex,
                                               MMPortSerialAtUnsolicitedMsgFn callback,
                                               gpointer user_data,
                                               GDestroyNotify notify)
{
    GSList *existing;
    MMAtUnsolicitedMsgHandler *handler;

    g_return_if_fail (MM_IS_PORT_SERIAL_AT (self));
    g_return_if_fail (regex != NULL);

    existing = g_slist_find_custom (self->priv->unsolicited_msg_handlers,
                                    regex,
                                    (GCompareFunc)unsolicited_msg_handler_cmp);
    if (existing) {
        handler = existing->data;
        /* We OVERWRITE any existing one, so if any context data existing, free it */
        if (handler->notify)
            handler->notify (handler->user_data);
    } else {
        handler = g_slice_new (MMAtUnsolicitedMsgHandler);
        self->priv->unsolicited_msg_handlers = g_slist_append (self->priv->unsolicited_msg_handlers, handler);
        handler->regex = g_regex_ref (regex);
    }

    handler->callback = callback;
    handler->enable = TRUE;
    handler->user_data = user_data;
    handler->notify = notify;
}
예제 #3
0
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) {
		uri_regex = g_regex_new (URI_REGEX, 0, 0, NULL);
	}

	return g_regex_ref (uri_regex);
}
예제 #4
0
/**
 * Extract the host name and the remote file path from a URL.
 * @param remotePath [in] Remote filename as a URL.
 * @param hostname [out] Pointer to where the hostname is stored.
 * @param filename [out] Pointer to where the filepath is stored.
 * @return \a true if the host and file path could be extracted, or \a false
 *         otherwise.
 * Test: unit test (test-uploadqueue.c).
 */
STATIC bool
ExtractHostAndFilepath(
	const char *remotePath,
	char       **hostname,
	char       **filepath
	                   )
{
	GMatchInfo *matchInfo;

	/* Grep the hostname. */
	g_regex_ref( regexes.hostname );
	g_regex_match( regexes.hostname, remotePath, 0, &matchInfo );
	*hostname = g_match_info_fetch( matchInfo, 2 );
	g_match_info_free( matchInfo );
	g_regex_unref( regexes.hostname );
	/* Grep the file path. */
	g_regex_ref( regexes.removeHost );
	g_regex_match( regexes.removeHost, remotePath, 0, &matchInfo );
	*filepath = g_match_info_fetch( matchInfo, 1 );
	g_match_info_free( matchInfo );
	g_regex_unref( regexes.removeHost );

	return( true );
}
예제 #5
0
파일: filter.c 프로젝트: nshi/falcon
gboolean falcon_filter_register(gboolean is_dir, const gchar *pattern,
                                falcon_filter_func func)
{
	GRegex *regex = NULL;
	GRegex *key = NULL;
	GSList *list = NULL;
	falcon_filter_t *value = NULL;

	if (!pattern) {
		g_warning(_("Failed to register filter with no pattern."));
		return FALSE;
	}

	regex = falcon_filter_regex_new(pattern);
	if (!regex)
		return FALSE;

	g_mutex_lock(lock);
	if (!registry) {
		g_critical(_("Filter registry uninitialized."
		             " Failed to register filter with pattern %s"), pattern);
		g_mutex_unlock(lock);
		return FALSE;
	}

	if (!g_hash_table_lookup_extended(registry, regex, (gpointer *)&key,
	                                  (gpointer *)&list)) {
		g_regex_ref(regex);
		key = regex;
	}

	value = g_new0(falcon_filter_t, 1);
	value->is_dir = is_dir;
	value->func = func;

	if (g_slist_find_custom(list, &value, falcon_filter_compare)) {
		g_free(value);
		g_mutex_unlock(lock);
		return FALSE;
	}

	list = g_slist_append(list, value);
	g_hash_table_insert(registry, key, list);

	g_regex_unref(regex);
	g_mutex_unlock(lock);
	return 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);
}
예제 #7
0
파일: misc-macro.c 프로젝트: bert/gparts
GRegex*
misc_macro_new_regex(void)
{
    static GRegex *regex = NULL;

    if (regex == NULL)
    {
        regex = g_regex_new(
                    "\\$\\((\\w+)\\)",    /* pattern */
                    0,                    /* compile_options */
                    0,                    /* match_options */
                    NULL                  /* error */
                );
    }

    if (regex != NULL)
    {
        g_regex_ref(regex);
    }

    return regex;
}
void
mm_at_serial_port_add_unsolicited_msg_handler (MMAtSerialPort *self,
                                               GRegex *regex,
                                               MMAtSerialUnsolicitedMsgFn callback,
                                               gpointer user_data,
                                               GDestroyNotify notify)
{
    MMAtUnsolicitedMsgHandler *handler;
    MMAtSerialPortPrivate *priv;

    g_return_if_fail (MM_IS_AT_SERIAL_PORT (self));
    g_return_if_fail (regex != NULL);

    handler = g_slice_new (MMAtUnsolicitedMsgHandler);
    handler->regex = g_regex_ref (regex);
    handler->callback = callback;
    handler->user_data = user_data;
    handler->notify = notify;

    priv = MM_AT_SERIAL_PORT_GET_PRIVATE (self);
    priv->unsolicited_msg_handlers = g_slist_append (priv->unsolicited_msg_handlers, handler);
}
예제 #9
0
static void
gb_source_view_update_search (GbSourceView *view)
{
   GbSourceViewPrivate *priv;
   GRegexCompileFlags flags = 0;
   GtkTextBuffer *buffer;
   GtkTextIter begin;
   GtkTextIter end;
   GMatchInfo *match_info = NULL;
   GtkTextTag *search_tag;
   gboolean has_matches = FALSE;
   GRegex *regex = NULL;
   gchar *text;
   gchar *escaped;

   g_assert(GB_IS_SOURCE_VIEW(view));

   priv = view->priv;

   buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(view));
   gtk_text_buffer_get_bounds(buffer, &begin, &end);

   search_tag = gb_source_view_ref_search_tag(view);
   gtk_text_buffer_remove_tag(buffer, search_tag, &begin, &end);

   if (g_str_empty0(priv->search_text) && !priv->search_regex) {
      goto cleanup;
   }

   if (priv->search_text) {
      if (!priv->search_case_sensitive) {
         flags = G_REGEX_CASELESS;
      }
      escaped = g_regex_escape_string(priv->search_text, -1);
      regex = g_regex_new(escaped, flags, 0, NULL);
      g_free(escaped);
   } else if (priv->search_regex) {
      regex = g_regex_ref(priv->search_regex);
   }

   if (regex) {
      text = gtk_text_buffer_get_text(buffer, &begin, &end, TRUE);
      if (g_regex_match(regex, text, 0, &match_info)) {
         guint count;
         guint i;
         gint begin_pos;
         gint end_pos;

         do {
            count = g_match_info_get_match_count(match_info);
            for (i = 0; i < count; i++) {
               if (g_match_info_fetch_pos(match_info, i, &begin_pos, &end_pos)) {
                  gtk_text_buffer_get_iter_at_offset(buffer, &begin, begin_pos);
                  gtk_text_buffer_get_iter_at_offset(buffer, &end, end_pos);
                  gtk_text_buffer_apply_tag(buffer, search_tag, &begin, &end);
                  has_matches = TRUE;
               }
            }
         } while (g_match_info_next(match_info, NULL));
      }
      g_match_info_free(match_info);
      g_regex_unref(regex);
      g_free(text);
   }

cleanup:
   if (priv->has_matches != has_matches) {
      priv->has_matches = has_matches;
      g_object_notify_by_pspec(G_OBJECT(view), gParamSpecs[PROP_HAS_MATCHES]);
   }

   gtk_widget_queue_draw(GTK_WIDGET(view));
   g_object_unref(search_tag);
}
예제 #10
0
파일: filter.c 프로젝트: sinoory/webv8
static gpointer _g_regex_ref0 (gpointer self) {
#line 19 "/home/luyue/new/Webkit2Browser/Source/midori/extensions/adblock/filter.vala"
	return self ? g_regex_ref (self) : NULL;
#line 128 "filter.c"
}
예제 #11
0
STATIC char*
InitiateMultipartUpload(
	S3COMM        *s3Comm,
	CURL          *curl,
	sqlite3_int64 fileId,
	uid_t         uid,
	gid_t         gid,
	int           permissions,
	char          *filepath
	                    )
{
	struct curl_slist *headers;
	char              amzHeader[ 50 ];
	char              *url;
	char              *response;
	int               responseLength;
	GMatchInfo        *matchInfo;
	char              *uploadId;
	int               status;

	/* Generate the uid, gid, and permissions headers. */
	headers = NULL;
	sprintf( amzHeader, "x-amz-meta-uid:%d", (int) uid );
	headers = curl_slist_append( headers, strdup( amzHeader ) );
	sprintf( amzHeader, "x-amz-meta-gid:%d", (int) gid );
	headers = curl_slist_append( headers, strdup( amzHeader ) );
	sprintf( amzHeader, "x-amz-meta-mode:%d", (int) permissions );
	headers = curl_slist_append( headers, strdup( amzHeader ) );
	curl_easy_setopt( curl, CURLOPT_HTTPHEADER, headers );
	/* Send a multipart upload initiation request. */
	url = malloc( strlen( filepath ) + sizeof( "?uploads" ) );
	strcpy( url, filepath );
	strcat( url, "?uploads" );
	curl_easy_reset( curl );
#ifdef AUTOTEST_SKIP_COMMUNICATIONS
	status = 0;
#else
	printf( "Executing HTTP request\n" );
	status = s3_SubmitS3Request( s3Comm, "POST", headers, url,
								 (void**) (&response), &responseLength );
#endif
	DeleteCurlSlistAndContents( headers );
	free( url );

#ifndef AUTOTEST_SKIP_COMMUNICATIONS
	/* Get the upload ID from the response. */
	g_regex_ref( regexes.getUploadId );
	if( g_regex_match( regexes.getUploadId, response, 0, &matchInfo ) )
	{
		uploadId = g_match_info_fetch( matchInfo, 1 );
	}
	g_match_info_free( matchInfo );
	g_regex_unref( regexes.getUploadId );
	/* Set the upload ID in the transfers table. */
	Query_SetUploadId( fileId, uploadId );
#else
	uploadId = strdup( "---etag not set---" );
#endif
	if( status != 0 )
	{
		fprintf( stderr,
				 "Unable to decode multipart upload initiation response\n" );
	}

	return( uploadId );
}
예제 #12
0
/**
 * Start the next download in the download queue. This function must be
 * started as a thread so that it does not block other downloads.
 * @param ctx [in] Pointer to a DownloadStarter structure. The structure is
 *        freed from memory.
 * @return Nothing.
 * Test: unit test (test-downloadqueue.c).
 */
STATIC void*
BeginDownload(
	void *ctx
	          )
{
	int                         socketHandle;
	struct DownloadStarter      *downloadStarter;
	int                         downloader;
	struct DownloadSubscription *subscription;

	CURL              *curl;
	S3COMM            *s3Comm;
	struct curl_slist *headers;
	char              *downloadPath;
	char              *remotePath;
	char              *bucket;
	char              *keyId;
	char              *secretKey;
	char              *downloadFile;
	FILE              *downFile;
	const char        *hostname;
	GMatchInfo        *matchInfo;
	int               status;
	const char        *filepath;

	char              *parentname;
	uid_t             parentUid;
	gid_t             parentGid;
	char              *filename;
	uid_t             uid;
	gid_t             gid;
	int               permissions;

	struct timeval    now;
	struct timespec   oneMinute;

	downloadStarter = (struct DownloadStarter*) ctx;
	downloader      = downloadStarter->downloader;
	subscription    = downloadStarter->subscription;
	socketHandle    = downloadStarter->socket;
	free( ctx );

	curl   = transferers[ downloader ].curl;
	s3Comm = transferers[ downloader ].s3Comm;

	/* Fetch local filename, remote filename, bucket, keyId, and
	   secretKey. */
	pthread_mutex_lock( &mainLoop_mutex );
	Query_GetDownload( subscription->fileId, &bucket, &remotePath,
					   &downloadPath, &keyId, &secretKey );
	/* Set the path for the local file and open it for writing. */
	downloadFile = malloc( strlen( CACHE_INPROGRESS )
						   + strlen( downloadPath ) + sizeof( char ) );
	strcpy( downloadFile, CACHE_INPROGRESS );
	strcat( downloadFile, downloadPath );
	free( downloadPath );
	downFile = fopen( downloadFile, "w" );
	/* Set user write-only and mandatory locking (the latter is indicated by
	   group-execute off and set-group-ID on). */
/* OW: removed while debugging.
	chmod( downloadFile, S_IWUSR | S_ISGID );
*/

	/* Extract the hostname from the remote filename. */
	g_regex_ref( regexes.hostname );
	g_regex_match( regexes.hostname, remotePath, 0, &matchInfo );
	hostname = g_match_info_fetch( matchInfo, 2 );
	g_match_info_free( matchInfo );
	g_regex_unref( regexes.hostname );
	s3Comm->bucket    = (char*) bucket;
	s3Comm->keyId     = (char*) keyId;
	s3Comm->secretKey = (char*) secretKey;
	s3Comm->region    = HostnameToRegion( remotePath );

	g_regex_ref( regexes.hostname );
	g_regex_match( regexes.removeHost, remotePath, 0, &matchInfo );
	filepath = g_match_info_fetch( matchInfo, 1 );
	headers = BuildS3Request( s3Comm, "GET", hostname, NULL, filepath );
	free( bucket );
	free( keyId );
	free( secretKey );
	free( (char*) hostname );
	free( (char*) filepath );
	g_match_info_free( matchInfo );
	g_regex_unref( regexes.hostname );

	/* Download the file and wait until it has been received. */
	curl_easy_reset( curl );
	curl_easy_setopt( curl, CURLOPT_WRITEDATA, downFile );
	curl_easy_setopt( curl, CURLOPT_HTTPHEADER, headers );

	curl_easy_setopt( curl, CURLOPT_URL, remotePath );

	pthread_mutex_unlock( &mainLoop_mutex );
#ifdef AUTOTEST_SKIP_COMMUNICATIONS
	status = 0;
#else
	printf( "Executing HTTP request\n" );
	status = curl_easy_perform( curl );
#endif
	DeleteCurlSlistAndContents( headers );
	free( remotePath );
	fclose( downFile );

	if( status == 0 )
	{
		/* Determine the owners and the permissions of the file. */
		pthread_mutex_lock( &mainLoop_mutex );
	    Query_GetOwners( subscription->fileId,
						 &parentname, &parentUid, &parentGid,
						 &filename, &uid, &gid, &permissions );
		/* Set the permissions while we still own the file. */
		pthread_mutex_unlock( &mainLoop_mutex );
		chmod( downloadFile, permissions );
		free( downloadFile );
		/* Grant appropriate rights to the file and move it into the shared
		   cache folder. */
		MoveToSharedCache( socketHandle, parentname, parentUid, parentGid,
						   filename, uid, gid );
		free( parentname );
		free( filename );

		/* Lock the queue to prevent threads from subscribing to this
		   download after we broadcast a signal that the file is available. */
		pthread_mutex_lock( &mainLoop_mutex );
		/* Remove the file from the download queue and the downloads table. */
		g_queue_remove( &downloadQueue, subscription );
		status = Query_DeleteTransfer( subscription->fileId );
		Query_MarkFileAsCached( subscription->fileId );
		/* Mark the downloader as ready for another download. */
		transferers[ downloader ].isReady = true;
		/* Before signaling to the subscribers that the file is available,
		   make sure none of them can acknowledge before we're ready to
		   receive the acknowledgment. */
		pthread_mutex_lock( &subscription->acknowledgeMutex );
		pthread_mutex_lock( &subscription->waitMutex );
		subscription->downloadActive = false;
		/* Inform the subscribers that the file is available. */
		pthread_cond_broadcast( &subscription->waitCond );
		/* Inform the queue processor that a download slot is available. */
		pthread_cond_signal( &mainLoop_cond );
		pthread_mutex_unlock( &mainLoop_mutex );
		pthread_mutex_unlock( &subscription->waitMutex );
		/* Wait for the last subscriber to acknowledge that the subscription
		   count is zero. If no response is received within a minute, probably
		   some subscribers are dead. */
		if( subscription->subscribers != 0 )
		{
			gettimeofday( &now, NULL );
			oneMinute.tv_sec  = now.tv_sec + 60;
			oneMinute.tv_nsec = 0;
			pthread_cond_timedwait( &subscription->acknowledgeCond,
									&subscription->acknowledgeMutex,
									&oneMinute );
		}
		pthread_mutex_unlock( &subscription->acknowledgeMutex );
		/* Delete the subscription entry whether all threads have acknowledged
		   or not. */
		free( subscription );
	}

	pthread_exit( NULL );
}