示例#1
0
GQueue *network_connection_pool_get_conns(network_connection_pool *pool, GString *username, GString *UNUSED_PARAM(default_db)) {
	GQueue *conns = NULL;


	if (username && username->len > 0) {
		conns = g_hash_table_lookup(pool->users, username);
		/**
		 * if we know this use, return a authed connection 
		 */
		g_debug("%s: (get_conns) get user-specific idling connection for '%s' -> %p", G_STRLOC, username->str, conns);
        if (conns) return conns;
	}

	/**
	 * we don't have a entry yet, check the others if we have more than 
	 * min_idle waiting
	 */

    if (pool->use_mid_idle) {
        conns = g_hash_table_find(pool->users, find_idle_conns, &(pool->mid_idle_connections));
        if (conns && conns->length > pool->mid_idle_connections) {
            pool->use_mid_idle = FALSE;
		    g_debug("%s: (get_conns) init phase complete for user '%s' -> %p", G_STRLOC, username->str, conns);
        }
    } else {
        conns = g_hash_table_find(pool->users, find_idle_conns, &(pool->min_idle_connections));
    }

	g_debug("%s: (get_conns) try to find max-idling conns for user '%s' -> %p", G_STRLOC, username ? username->str : "", conns);

	return conns;
}
示例#2
0
gboolean dls_upnp_device_context_exist(dls_device_t *device,
				       dls_device_context_t *context)
{
	gpointer result;
	guint i;
	gboolean found = FALSE;
	dls_upnp_t *upnp = dls_server_get_upnp();

	if (upnp == NULL)
		goto on_exit;

	/* Check if the device still exist */
	result = g_hash_table_find(upnp->server_udn_map, prv_device_find,
				   device);

	if (result == NULL)
		if (g_hash_table_find(upnp->server_uc_map, prv_device_uc_find,
				      device) == NULL)
			goto on_exit;

	/* Search if the context still exist in the device */
	for (i = 0; i < device->contexts->len; ++i) {
		if (g_ptr_array_index(device->contexts, i) == context) {
			found = TRUE;
			break;
		}
	}

on_exit:
	return found;
}
示例#3
0
MsnSwitchBoard *
msn_session_find_swboard_with_conv (const MsnSession *session,
                                    const PurpleConversation *conv)
{
    MsnSwitchBoard *swboard;

    g_return_val_if_fail (session, NULL);
    g_return_val_if_fail (conv, NULL);

    swboard = g_hash_table_find (session->conversations, find_sb_conv, (gpointer) conv);
    if (!swboard)
        swboard = g_hash_table_find (session->chats, find_sb_conv, (gpointer) conv);

    return swboard;
}
示例#4
0
文件: da_payee.c 项目: hdd/homebank
/**
 * da_pay_get_by_name:
 * 
 * Get an payee structure by its name
 * 
 * Return value: Payee * or NULL if not found
 *
 */
Payee *
da_pay_get_by_name(gchar *name)
{
	DB( g_print("da_pay_get_by_name\n") );

	return g_hash_table_find(GLOBALS->h_pay, (GHRFunc)da_pay_name_grfunc, name);
}
void
ags_lv2_urid_manager_test_map()
{
  AgsLv2UridManager *urid_manager;

  uint32_t id;
    
  GValue value = {0,};

  urid_manager = ags_lv2_urid_manager_get_instance();

  id = ags_lv2_urid_manager_map(NULL,
				AGS_LV2_URID_MANAGER_TEST_MAP_URI);

  g_value_init(&value,
	       G_TYPE_ULONG);
  g_value_set_ulong(&value,
		    id);

  CU_ASSERT(g_hash_table_find(urid_manager->urid,
			      ags_lv2_urid_manager_test_map_ghrfunc,
			      &value) != NULL);

  g_object_unref(urid_manager);
}
示例#6
0
/**
 * da_cat_get_by_name:
 *
 * Get a category structure by its name
 *
 * Return value: Category * or NULL if not found
 *
 */
Category *
da_cat_get_by_name(gchar *name)
{
	DB( g_print("da_cat_get_by_name\n") );

	return g_hash_table_find(GLOBALS->h_cat, (GHRFunc)da_cat_name_grfunc, name);
}
示例#7
0
JingleSession *
jingle_session_find_by_jid(JabberStream *js, const gchar *jid)
{
	return js->sessions != NULL ?
			g_hash_table_find(js->sessions,
			find_by_jid_ghr, (gpointer)jid) : NULL;
}
示例#8
0
GQueue *network_connection_pool_get_conns(network_connection_pool *pool, GString *username, GString *UNUSED_PARAM(default_db)) {
	GQueue *conns = NULL;


	if (username && username->len > 0) {
		conns = g_hash_table_lookup(pool->users, username);
		/**
		 * if we know this use, return a authed connection 
		 */
#ifdef DEBUG_CONN_POOL
		g_debug("%s: (get_conns) get user-specific idling connection for '%s' -> %p", G_STRLOC, username->str, conns);
#endif
		if (conns) return conns;
	}

	/**
	 * we don't have a entry yet, check the others if we have more than 
	 * min_idle waiting
	 */

	conns = g_hash_table_find(pool->users, find_idle_conns, &(pool->min_idle_connections));
#ifdef DEBUG_CONN_POOL
	g_debug("%s: (get_conns) try to find max-idling conns for user '%s' -> %p", G_STRLOC, username ? username->str : "", conns);
#endif

	return conns;
}
示例#9
0
文件: foo.c 项目: gonewbee/myTest
int main(int argc, char *argv[]) {
	GHashTable *hash = g_hash_table_new(g_str_hash, g_str_equal);
	// 插入
	g_hash_table_insert(hash, "one", "aaaa");
	g_hash_table_insert(hash, "two", "bbbb");
	g_hash_table_insert(hash, "three", "cccc");
	g_printf("There are %d keys in the hash\n", g_hash_table_size(hash));

	char *key = "one";
	// 查找
	g_printf("The value of [%s] is %s\n", key, g_hash_table_lookup(hash, key));
	char *key2 = "four";
	g_printf("The value of [%s] is %s\n", key2, g_hash_table_lookup(hash, key2));

	// 删除
	gboolean found = g_hash_table_remove(hash, key);
	g_printf("The key [%s] was %sfound and removed\n", key, found ? "" : "not ");

	// 遍历
	g_hash_table_foreach(hash, zs_hash_table_func, "g_hash_table_foreach");

	gpointer v = g_hash_table_find(hash, zs_hash_table_finder, NULL);
	g_printf("v is %s\n", v);

	g_hash_table_destroy(hash);
	return 0;
}
static void on_item_changed (MateBG *bg, AppearanceData *data) {
  GtkTreeModel *model;
  GtkTreeIter iter;
  GtkTreePath *path;
  MateWPItem *item;

  item = g_hash_table_find (data->wp_hash, predicate, bg);

  if (!item)
    return;

  model = gtk_tree_row_reference_get_model (item->rowref);
  path = gtk_tree_row_reference_get_path (item->rowref);

  if (gtk_tree_model_get_iter (model, &iter, path)) {
    GdkPixbuf *pixbuf;

    g_signal_handlers_block_by_func (bg, G_CALLBACK (on_item_changed), data);

    pixbuf = mate_wp_item_get_thumbnail (item,
                                          data->thumb_factory,
                                          data->thumb_width,
                                          data->thumb_height);
    if (pixbuf) {
      gtk_list_store_set (GTK_LIST_STORE (data->wp_model), &iter, 0, pixbuf, -1);
      g_object_unref (pixbuf);
    }

    g_signal_handlers_unblock_by_func (bg, G_CALLBACK (on_item_changed), data);
  }
}
示例#11
0
struct account *
account_by_name(char *name)
{
    PGresult *res;
    int acct_id;

    // First check to see if we already have it in memory
    struct account *acct = g_hash_table_find(account_cache,
                                             account_name_matches,
                                             name);

    if (acct)
        return acct;

    // Apprently, we don't, so look it up on the db
    res = sql_query("select idnum from accounts where lower(name)='%s'",
        tmp_sqlescape(tmp_tolower(name)));
    if (PQntuples(res) != 1)
        return NULL;
    acct_id = atoi(PQgetvalue(res, 0, 0));

    // Now try to load it
    CREATE(acct, struct account, 1);
    if (load_account(acct, acct_id))
        return acct;

    free(acct);
    return NULL;
}
示例#12
0
static inline void store_string_location (MonoProfiler *prof, const gchar *string, guint32 hash, size_t len)
{
	StringLocation *location = (StringLocation *)g_hash_table_lookup (prof->string_locations_hash, &hash);
	SavedString *saved;
	SavedStringFindInfo info;
	guint32 *hashptr;

	if (location)
		return;

	info.hash = hash;
	info.len = len;

	/* Expensive but unavoidable... */
	saved = (SavedString*)g_hash_table_find (prof->saved_strings_hash, saved_strings_find_func, &info);
	hashptr = (guint32*)g_malloc (sizeof (guint32));
	*hashptr = hash;
	location = (StringLocation*)g_malloc0 (sizeof (location));

	g_hash_table_insert (prof->string_locations_hash, hashptr, location);
	if (!saved)
		return;

	g_hash_table_remove (prof->saved_strings_hash, saved->string);
	location->hint = build_hint (saved);
}
static struct CallConference *
find_call_conference_by_conference (TfCallChannel *channel,
    GstObject *conference)
{
  return g_hash_table_find (channel->fsconferences, find_conf_func,
      conference);
}
示例#14
0
文件: glib.c 项目: sjokkis/gjs
static gboolean
remove_or_steal_one(GHashTable *hash,
                    void      **key_p,
                    void      **value_p,
                    gboolean    steal)
{
    StoreOneData sod;

    sod.key = NULL;
    sod.value = NULL;
    g_hash_table_find(hash, get_first_one_predicate, &sod);

    if (sod.key == NULL)
        return FALSE;

    if (key_p)
        *key_p = sod.key;
    if (value_p)
        *value_p = sod.value;

    if (steal)
        g_hash_table_steal(hash, sod.key);
    else
        g_hash_table_remove(hash, sod.key);

    return sod.value != NULL;
}
示例#15
0
文件: server.c 项目: cascadeo/lasso
/**
 * lasso_server_get_first_providerID:
 * @server: a #LassoServer
 *
 * Looks up and returns the provider ID of a known provider
 *
 * Return value:(transfer full)(allow-none): the provider ID, NULL if there are no providers.  This
 * string must be freed by the caller.
 **/
gchar*
lasso_server_get_first_providerID(LassoServer *server)
{
	gchar *providerID = NULL;

	g_hash_table_find(server->providers, (GHRFunc)get_first_providerID, &providerID);
	return g_strdup(providerID);
}
示例#16
0
MMSOfonoModem*
mms_ofono_manager_modem_for_imsi(
    MMSOfonoManager* ofono,
    const char* imsi)
{
    return ofono ? g_hash_table_find(ofono->modems,
        mms_ofono_manager_modem_imsi_find_cb, (void*)imsi) : NULL;
}
示例#17
0
/** 
* Unload (or DELETE) tests from server, done in reverse order starting from last test
* @param test Test details
* @testpath base path to tests
*/
void tests_unload_tests(testcase* test,gchar* testpath) {
	
	jsonreply *deldata = NULL;
	jsonreply *delresp = NULL;
	gchar *url = NULL;
	gchar *value = NULL;
	
	// Go through the sequence in reverse
	for(gint testidx = g_slist_length(test_sequence) -1 ; testidx >= 0; testidx--) {

		// First the login information need to be added, then tasks in number order
		gchar* searchparam = g_slist_nth_data(test_sequence,testidx);
		
#ifdef G_MESSAGES_DEBUG
		g_print("Press enter to DELETE test \"%s\" file id=\"%s\"",test->name,searchparam);
		gchar c = '0';
		while(c != '\n') c = getc(stdin);
#endif
		
		// Get item in test sequence
		testfile* tfile = (testfile*)g_hash_table_find(test->files,
			(GHRFunc)find_from_hash_table, 
			searchparam);
		
		// If we got a reply we can get all details
		if(tfile->recv) {
		
			// First (here last) is login, it is always first in the list
			if(testidx == 0) {
				value = get_value_of_member(tfile->recv,"user_guid",NULL);

				deldata = create_delete_reply("user_guid",value);
			
				if(deldata && value) {
					url = g_strjoin("/",test->URL,"SignOut",value,NULL);
					delresp = http_post(url,deldata,"GET");
				}
			}
		
			// Rest in reverse order
			else if(tfile->need_delete){
				
				value = get_value_of_member(tfile->recv,"guid",NULL);

				if(value) {
					deldata = create_delete_reply("guid",value);			
					url = g_strjoin("/",test->URL,tfile->path,value,NULL);
					delresp = http_post(url,deldata,"DELETE");
				}
			}
		}
		g_free(value);
		g_free(url);
		free_jsonreply(delresp);
		free_jsonreply(deldata);
	}
	
}
示例#18
0
文件: server.c 项目: cascadeo/lasso
/**
 * lasso_server_get_providerID_from_hash:
 * @server: a #LassoServer
 * @b64_hash: the base64-encoded provider ID hash
 *
 * Looks up a #LassoProvider whose ID hash is @b64_hash and returns its
 * provider ID.
 *
 * Return value:(transfer full)(allow-none): the provider ID, NULL if it was not found.
 **/
gchar*
lasso_server_get_providerID_from_hash(LassoServer *server, gchar *b64_hash)
{
	gchar *providerID = b64_hash; /* kludge */

	if (g_hash_table_find(server->providers, (GHRFunc)get_providerID_with_hash, &providerID))
		return g_strdup(providerID);
	return NULL;
}
示例#19
0
Category *
da_cat_get_by_fullname(gchar *fullname)
{
struct fullcatcontext ctx;
gchar **typestr;
Category *item = NULL;

	DB( g_print("da_cat_get_by_fullname\n") );

	//g_strstrip(fullname);
	typestr = g_strsplit(fullname, ":", 2);
	if( g_strv_length(typestr) == 2 )
	{
		ctx.parent = 0;
		ctx.name = typestr[0];
		DB( g_print(" [x:x] try to find the parent : '%s'\n", typestr[0]) );

		Category *parent = g_hash_table_find(GLOBALS->h_cat, (GHRFunc)da_cat_fullname_grfunc, &ctx);
		if( parent != NULL )
		{
			ctx.parent = parent->key;
			ctx.name = typestr[1];

			DB( g_print(" [x:x] and searching sub %d '%s'\n", ctx.parent, ctx.name) );
			
			item = g_hash_table_find(GLOBALS->h_cat, (GHRFunc)da_cat_fullname_grfunc, &ctx);
		}
	}
	else
	{
		ctx.parent = 0;
		ctx.name = fullname;

		DB( g_print(" [x] try to '%s'\n", fullname) );

		item = g_hash_table_find(GLOBALS->h_cat, (GHRFunc)da_cat_fullname_grfunc, &ctx);
	}

	g_strfreev(typestr);

	DB( g_print(" return value %x\n", item) );

	return item;
}
示例#20
0
文件: client_mngr.c 项目: regit/nufw
user_session_t *look_for_username(const gchar * username)
{
	void *ret;
	lock_client_datas();
	ret =
	    g_hash_table_find(client_conn_hash, look_for_username_callback,
			      (void *) username);
	unlock_client_datas();
	return ret;
}
示例#21
0
static gboolean
egg_file_format_filter_filter (const GtkFileFilterInfo *info,
                               gpointer                 data)
{
  EggFileFormatFilterInfo *self = data;

  return NULL != g_hash_table_find (self->extension_set,
                                    egg_file_format_filter_find,
                                    (gpointer) info);
}
/**
 * cinnamon_app_system_lookup_app:
 *
 * Find a #CinnamonApp corresponding to an id.
 *
 * Return value: (transfer none): The #CinnamonApp for id, or %NULL if none
 */
CinnamonApp *
cinnamon_app_system_lookup_app (CinnamonAppSystem   *self,
                             const char       *id)
{
  CinnamonApp *result;

  result = g_hash_table_lookup (self->priv->id_to_app, id);
  if (result == NULL) {
    result = g_hash_table_find (self->priv->id_to_app, (GHRFunc) case_insensitive_search, id);
  }
  return result;
}
void
csm_store_foreach (CsmStore    *store,
                   CsmStoreFunc func,
                   gpointer     user_data)
{
        g_return_if_fail (store != NULL);
        g_return_if_fail (func != NULL);

        g_hash_table_find (store->priv->objects,
                           (GHRFunc)func,
                           user_data);
}
示例#24
0
int main(int argc, char** argv) {
    GHashTable* hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
            NULL,
            (GDestroyNotify)value_destroyed);
    g_hash_table_insert(hash, GINT_TO_POINTER(6), GINT_TO_POINTER(36));
    g_hash_table_insert(hash, GINT_TO_POINTER(10), GINT_TO_POINTER(12));
    g_hash_table_insert(hash, GINT_TO_POINTER(20), GINT_TO_POINTER(22));
    gpointer item_ptr = g_hash_table_find(hash, (GHRFunc)finder, NULL);
    gint item = GPOINTER_TO_INT(item_ptr);
    printf("%d + %d == 42\n", item, 42-item);
    g_hash_table_destroy(hash);
    return 0;
}
示例#25
0
/**
 * da_cat_get_key_by_name:
 *
 * Get a category key by its name
 *
 * Return value: the category key or -1 if not found
 *
 */
guint32
da_cat_get_key_by_name(gchar *name)
{
Category *cat;

	DB( g_print("da_cat_get_key_by_name\n") );

	cat = g_hash_table_find(GLOBALS->h_cat, (GHRFunc)da_cat_name_grfunc, name);
	if( cat == NULL)
		return -1;

	return cat->key;
}
示例#26
0
文件: color.c 项目: ActionLuzifer/mc
static size_t
tty_color_get_next__color_pair_number (void)
{
    size_t cp_count, cp;

    cp_count = g_hash_table_size (mc_tty_color__hashtable);
    for (cp = 0; cp < cp_count; cp++)
        if (g_hash_table_find (mc_tty_color__hashtable, tty_color_get_next_cpn_cb,
                               GSIZE_TO_POINTER (cp)) == NULL)
            break;

    return cp;
}
示例#27
0
文件: server.c 项目: cascadeo/lasso
/**
 * lasso_server_get_first_providerID_by_role
 * @server: a #LassoServer
 * @role: the #LassoProviderRole of the researched provider
 *
 * Looks up and returns the provider ID of known provider with the given role.
 *
 * Return value: the provider ID, NULL if there are no providers. This string
 *     must be freed by the caller.
 */
gchar *
lasso_server_get_first_providerID_by_role(const LassoServer *server, LassoProviderRole role)
{
	LassoProvider *a_provider;
	a_provider = LASSO_PROVIDER(g_hash_table_find(server->providers,
		(GHRFunc) get_first_providerID_by_role,
		(gpointer)role));
	if (a_provider) {
		return g_strdup(a_provider->ProviderID);
	} else {
		return NULL;
	}
}
示例#28
0
文件: color.c 项目: sfionov/mc-dev
static int
tty_color_get_next__color_pair_number ()
{
    int cp_count = g_hash_table_size (mc_tty_color__hashtable);
    int cp = 0;

    for (cp = 0; cp < cp_count; cp++) {
        if (g_hash_table_find (mc_tty_color__hashtable, tty_color_get_next_cpn_cb, (gpointer) cp) ==
            NULL)
            return cp;
    }
    return cp;
}
示例#29
0
gint is_falling_letter(gunichar  unichar)
{
  GooCanvasItem *item;

  if ((item = g_hash_table_find(letters_table,
			       unichar_comp,
				&unichar)))
    {
      player_win(item);
      return TRUE;
    }
  return FALSE;
}
示例#30
0
文件: mx-icon-theme.c 项目: 3v1n0/mx
static void
mx_icon_theme_load_fallbacks (MxIconTheme *theme,
                              GKeyFile    *theme_file,
                              gboolean     root)
{
  MxIconThemePrivate *priv = theme->priv;
  gchar *fallbacks = g_key_file_get_string (theme_file,
                                            "Icon Theme",
                                            "Inherits",
                                            NULL);

  /* If this isn't the root theme, add it to the list of fallbacks */
  if (!root)
    priv->theme_fallbacks = g_list_append (priv->theme_fallbacks,
                                           theme_file);

  /* Check the list of fallbacks in this theme and add any that we haven't
   * already.
   */
  if (fallbacks)
    {
      gint i = 0;
      gint fallbacks_len = strlen (fallbacks);

      g_strdelimit (fallbacks, ",", '\0');

      while (i < fallbacks_len)
        {
          gchar *fallback = fallbacks + i;
          i += strlen (fallback) + 1;

          /* Skip hicolor, we keep it loaded all the time */
          if (g_str_equal (fallback, "hicolor"))
            continue;

          /* Skip if we've already loaded this theme */
          if (g_hash_table_find (priv->theme_path_hash,
                                 mx_icon_theme_find_name_cb,
                                 fallback))
            continue;

          /* Load this theme and store itself and its fallbacks in the
           * list of fallbacks.
           */
          theme_file = mx_icon_theme_load_theme (theme, fallback);
          if (theme_file)
            mx_icon_theme_load_fallbacks (theme, theme_file, FALSE);
        }
      g_free (fallbacks);
    }
}