Example #1
0
static guint
mx_icon_theme_hash (GThemedIcon *icon)
{
  const gchar * const *names = g_themed_icon_get_names (icon);
  return g_str_hash (names[0]);
}
Example #2
0
static guint joinpart_key_hash(const struct joinpart_key *key)
{
	g_return_val_if_fail(key != NULL, 0);

	return g_direct_hash(key->conv) + g_str_hash(key->user);
}
static guint
groupwise_hash_folder_name (gconstpointer key)
{
	return g_str_hash (key);
}
Example #4
0
static guint
_purple_conversations_hconv_hash(struct _purple_hconv *hc)
{
	return g_str_hash(hc->name) ^ hc->im ^ g_direct_hash(hc->account);
}
static void
add_hash (guint *hash, char *s)
{
	if (s)
		*hash ^= g_str_hash(s);
}
Example #6
0
File: filter.c Project: nshi/falcon
static inline guint falcon_filter_regex_hash(gconstpointer key)
{
	const GRegex *regex = (const GRegex *)key;
	return g_str_hash(g_regex_get_pattern(regex));
}
Example #7
0
guint flist_str_hash(const char *nick) {
    char *lc = g_utf8_strdown(nick, -1);
    guint bucket = g_str_hash(lc);
    g_free(lc);
    return bucket;
}
Example #8
0
static guint
cg_hash (GOColorGroup const *key)
{
	return g_str_hash (key->name);
}
static guint
eva_socket_address_symbolic_hash       (EvaSocketAddress *addr)
{
  return g_str_hash (EVA_SOCKET_ADDRESS_SYMBOLIC (addr)->name) + 100000;
}
static guint
id_hash (gconstpointer key)
{
	const ECalComponentId *id = key;
	return g_str_hash (id->uid) ^ (id->rid ? g_str_hash (id->rid) : 0);
}
Example #11
0
static void
dissect_k12(tvbuff_t* tvb,packet_info* pinfo,proto_tree* tree)
{
	static dissector_handle_t data_handles[] = {NULL,NULL};
	proto_item* k12_item;
	proto_tree* k12_tree;
	proto_item* stack_item;
	dissector_handle_t sub_handle = NULL;
	dissector_handle_t* handles;
	guint i;

	k12_item = proto_tree_add_protocol_format(tree, proto_k12, tvb, 0, 0,
						  "Packet from: '%s' (0x%.8x)",
						  pinfo->pseudo_header->k12.input_name,
						  pinfo->pseudo_header->k12.input);

	k12_tree = proto_item_add_subtree(k12_item, ett_k12);

	proto_tree_add_uint(k12_tree, hf_k12_port_id, tvb, 0,0,pinfo->pseudo_header->k12.input);
	proto_tree_add_string(k12_tree, hf_k12_port_name, tvb, 0,0,pinfo->pseudo_header->k12.input_name);
	stack_item = proto_tree_add_string(k12_tree, hf_k12_stack_file, tvb, 0,0,pinfo->pseudo_header->k12.stack_file);

	k12_item = proto_tree_add_uint(k12_tree, hf_k12_port_type, tvb, 0, 0,
				       pinfo->pseudo_header->k12.input_type);

	k12_tree = proto_item_add_subtree(k12_item, ett_port);

	switch ( pinfo->pseudo_header->k12.input_type ) {
		case K12_PORT_DS0S:
			proto_tree_add_uint(k12_tree, hf_k12_ts, tvb, 0,0,pinfo->pseudo_header->k12.input_info.ds0mask);
			break;
		case K12_PORT_ATMPVC:
		{
		gchar* circuit_str = ep_strdup_printf("%u:%u:%u",
						      (guint)pinfo->pseudo_header->k12.input_info.atm.vp,
						      (guint)pinfo->pseudo_header->k12.input_info.atm.vc,
						      (guint)pinfo->pseudo_header->k12.input_info.atm.cid);

			    /*
			     * XXX: this is prone to collisions!
			     * we need an uniform way to manage circuits between dissectors
			     */
		pinfo->circuit_id = g_str_hash(circuit_str);

		proto_tree_add_uint(k12_tree, hf_k12_atm_vp, tvb, 0, 0,
				    pinfo->pseudo_header->k12.input_info.atm.vp);
		proto_tree_add_uint(k12_tree, hf_k12_atm_vc, tvb, 0, 0,
				    pinfo->pseudo_header->k12.input_info.atm.vc);
		if (pinfo->pseudo_header->k12.input_info.atm.cid)
		    proto_tree_add_uint(k12_tree, hf_k12_atm_cid, tvb, 0, 0,
					pinfo->pseudo_header->k12.input_info.atm.cid);
			    break;
		}
		default:
			break;
	}

	handles = se_tree_lookup32(port_handles, pinfo->pseudo_header->k12.input);

	if (! handles ) {
		for (i=0 ; i < nk12_handles; i++) {
			if ( epan_strcasestr(pinfo->pseudo_header->k12.stack_file, k12_handles[i].match)
			     || epan_strcasestr(pinfo->pseudo_header->k12.input_name, k12_handles[i].match) ) {
				handles = k12_handles[i].handles;
				break;
			}
		}

		if (!handles) {
			data_handles[0] = data_handle;
			handles = data_handles;
		}

		se_tree_insert32(port_handles, pinfo->pseudo_header->k12.input, handles);

	}

	if (handles == data_handles) {
		proto_tree* stack_tree = proto_item_add_subtree(stack_item,ett_stack_item);
		proto_item* item;

		item = proto_tree_add_text(stack_tree,tvb,0,0,
					   "Warning: stk file not matched in the 'K12 Protocols' table");
		PROTO_ITEM_SET_GENERATED(item);
		expert_add_info_format(pinfo, item, PI_UNDECODED, PI_WARN, "unmatched stk file");

		item = proto_tree_add_text(stack_tree,tvb,0,0,
					   "Info: You can edit the 'K12 Protocols' table from Preferences->Protocols->k12xx");
		PROTO_ITEM_SET_GENERATED(item);

		call_dissector(data_handle, tvb, pinfo, tree);
		return;
	}

	/* Setup subdissector information */

	for (i = 0; handles[i] && handles[i+1]; ++i) {
		if (handles[i] == sscop_handle) {
			sscop_payload_info *p_sscop_info = p_get_proto_data(pinfo->fd, proto_sscop);
			if (!p_sscop_info) {
				p_sscop_info = se_alloc0(sizeof(sscop_payload_info));
                p_add_proto_data(pinfo->fd, proto_sscop, p_sscop_info);
                p_sscop_info->subdissector = handles[i+1];
			}
		}
		/* Add more protocols here */
	}

	sub_handle = handles[0];

	/* Setup information required by certain protocols */
	if (sub_handle == fp_handle) {
		fp_info *p_fp_info = p_get_proto_data(pinfo->fd, proto_fp);
		if (!p_fp_info) {
			p_fp_info = se_alloc0(sizeof(fp_info));
            p_add_proto_data(pinfo->fd, proto_fp, p_fp_info);

            fill_fp_info(p_fp_info,
                         pinfo->pseudo_header->k12.extra_info,
                         pinfo->pseudo_header->k12.extra_length);
		}
	}

	call_dissector(sub_handle, tvb, pinfo, tree);
}
Example #12
0
static guint
str_hash0 (gconstpointer str)
{
  return str ? g_str_hash (str) : 0;
}
gboolean gebr_comm_protocol_receive_data(struct gebr_comm_protocol *protocol, GString * data)
{
	gchar **splits;
	gboolean reached_end = FALSE;

	while (!reached_end && data->len) {
		gsize missing;

		/* if so, this is a new message; otherwise, another part
		 * of the argument of protocol->message
		 */
		if (!protocol->message->hash) {
			gint erase_len;
			gchar *strtol_endptr;

			splits = g_strsplit(data->str, " ", 3);
			gint n_tokens = g_strv_length(splits);
			if (n_tokens < 2)
				goto err;

			/* code */
			if (g_hash_table_lookup(gebr_comm_protocol_defs.hash_table, splits[0]) == NULL) {
				g_string_assign(data, "");
				goto err;
			}
			protocol->message->hash = g_str_hash(splits[0]);
			/* argument size */
			strtol_endptr = NULL;
			protocol->message->argument_size = strtol(splits[1], &strtol_endptr, 10);
			if (errno == ERANGE)
				goto err;

			/* the missing bytes to complete the read of argument */
			missing = protocol->message->argument_size;
			/* erase code and size from data */
			erase_len = strlen(splits[0]) + 1 + strlen(splits[1]) + ((n_tokens == 2) ? 0 : 1);
			g_string_erase(data, 0, erase_len);

			g_strfreev(splits);
		} else {
			missing = protocol->message->argument_size - protocol->message->argument->len;
		}

		/* if so, protocol->message has now received its
		 * argument entirely using > because there must be a line feed.
		 */
		reached_end = data->len > missing; 
		if (reached_end) {
			struct gebr_comm_message *queued;

			g_string_append_len(protocol->message->argument, data->str, missing);
			g_string_erase(data, 0, missing + 1);

			/* add to the list of messages */
			queued = protocol->message;
			protocol->messages = g_list_prepend(protocol->messages, queued);
			protocol->message = gebr_comm_message_new();
		} else {
			g_string_append(protocol->message->argument, data->str);
			g_string_erase(data, 0, -1);
		}
	}

	return TRUE;

 err:	g_strfreev(splits);
	return FALSE;
}
static void
remote_query_info_ready_cb (GObject *obj,
                            GAsyncResult *res,
                            gpointer user_data)
{
  PdfLoadJob *job = user_data;
  GError *error = NULL;
  GFile *pdf_file;
  GFileInfo *info;
  const gchar *content_type;
  gchar *tmp_name;
  gchar *tmp_path;

  info = g_file_query_info_finish (G_FILE (obj),
                                   res, &error);

  if (error != NULL) {
    pdf_load_job_complete_error (job, error);
    return;
  }

  job->original_file_mtime =
    g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);

  tmp_name = g_strdup_printf ("gnome-documents-%u.pdf", g_str_hash (job->uri));
  tmp_path = g_build_filename (g_get_user_cache_dir (), "gnome-documents", NULL);
  job->pdf_path =
    g_build_filename (tmp_path, tmp_name, NULL);
  g_mkdir_with_parents (tmp_path, 0700);

  content_type = g_file_info_get_content_type (info);

  if (!content_type_is_native (content_type)) {
    GFileIOStream *iostream;

    job->download_file = g_file_new_tmp (NULL, &iostream, &error);
    if (error != NULL) {
      pdf_load_job_complete_error (job, error);
      return;
    }

    /* We don't need the iostream. */
    g_io_stream_close (G_IO_STREAM (iostream), NULL, NULL);
  } else {
    job->download_file = g_file_new_for_path (job->pdf_path);
  }

  pdf_file = g_file_new_for_path (job->pdf_path);

  g_file_query_info_async (pdf_file,
                           G_FILE_ATTRIBUTE_TIME_MODIFIED,
                           G_FILE_QUERY_INFO_NONE,
                           G_PRIORITY_DEFAULT,
                           job->cancellable,
                           remote_cache_query_info_ready_cb,
                           job);

  g_free (tmp_name);
  g_free (tmp_path);
  g_object_unref (pdf_file);
  g_object_unref (info);
}
guint key_hash(struct ObjCacheKey* key)
{
    return g_str_hash(key->bus_name) + g_str_hash(key->path) +
        g_str_hash(key->iface) + g_direct_hash(key->connection);
}
static void
openoffice_cache_query_info_original_ready_cb (GObject *source,
                                               GAsyncResult *res,
                                               gpointer user_data)
{
  PdfLoadJob *job = user_data;
  GError *error = NULL;
  GFileInfo *info;
  guint64 mtime;
  gchar *pdf_path, *tmp_name, *tmp_path;
  GFile *cache_file;

  info = g_file_query_info_finish (G_FILE (source), res, &error);

  if (error != NULL) {
    /* try to create the cache anyway - if the source file
     * is really not readable we'll fail again soon.
     */
    pdf_load_job_openoffice_refresh_cache (job);

    g_error_free (error);
    return;
  }

  /* If we are converting a downloaded file then we already know its
   * mtime. Moreover, we we don't want to find the mtime of the
   * temporary file.
   */
  if (job->original_file_mtime == 0)
    job->original_file_mtime = mtime =
      g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);

  g_object_unref (info);

  tmp_path = g_build_filename (g_get_user_cache_dir (), "gnome-documents", NULL);
  g_mkdir_with_parents (tmp_path, 0700);

  /* If we are converting a downloaded file then we already know its
   * location in the cache. Moreover, we we don't want to hash the
   * temporary file.
   */
  if (job->pdf_path == NULL)
    {
      tmp_name = g_strdup_printf ("gnome-documents-%u.pdf", g_str_hash (job->uri));
      job->pdf_path = pdf_path =
        g_build_filename (tmp_path, tmp_name, NULL);
      g_free (tmp_name);
    }

  g_free (tmp_path);

  cache_file = g_file_new_for_path (pdf_path);
  g_file_query_info_async (cache_file,
                           G_FILE_ATTRIBUTE_TIME_MODIFIED,
                           G_FILE_QUERY_INFO_NONE,
                           G_PRIORITY_DEFAULT,
                           job->cancellable,
                           openoffice_cache_query_info_ready_cb,
                           job);

  g_object_unref (cache_file);
}
Example #17
0
gcp_msg_t* gcp_msg(packet_info* pinfo, int o, gboolean keep_persistent_data) {
    gcp_msg_t* m;
    guint32 framenum = (guint32)pinfo->num;
    guint32 offset = (guint32)o;
    address* src = &(pinfo->src);
    address* dst = &(pinfo->dst);
    address* lo_addr;
    address* hi_addr;

    if (keep_persistent_data) {
        wmem_tree_key_t key[3];

        key[0].length = 1;
        key[0].key = &(framenum);
        key[1].length = 1;
        key[1].key = &offset;
        key[2].length = 0;
        key[2].key =NULL;

        if (( m = (gcp_msg_t *)wmem_tree_lookup32_array(msgs,key) )) {
            m->committed = TRUE;
            return m;
        } else {
            m = wmem_new(wmem_file_scope(), gcp_msg_t);
            m->framenum = framenum;
            m->time = pinfo->abs_ts;
            m->trxs = NULL;
            m->committed = FALSE;

            wmem_tree_insert32_array(msgs,key,m);
        }
    } else {
        m = wmem_new0(wmem_packet_scope(), gcp_msg_t);
        m->framenum = framenum;
        m->trxs = NULL;
        m->committed = FALSE;
    }

    if (cmp_address(src, dst) < 0)  {
        lo_addr = src;
        hi_addr = dst;
    } else {
        lo_addr = dst;
        hi_addr = src;
    }

    switch(lo_addr->type) {
        case AT_NONE:
            m->lo_addr = 0;
            m->hi_addr = 0;
            break;
        case AT_IPv4:
            memcpy((guint8*)&(m->hi_addr),hi_addr->data,4);
            memcpy((guint8*)&(m->lo_addr),lo_addr->data,4);
            break;
        case AT_SS7PC:
            m->hi_addr = mtp3_pc_hash((const mtp3_addr_pc_t *)hi_addr->data);
            m->lo_addr = mtp3_pc_hash((const mtp3_addr_pc_t *)lo_addr->data);
            break;
        default:
            /* XXX: heuristic and error prone */
            m->hi_addr = g_str_hash(address_to_str(wmem_packet_scope(), hi_addr));
            m->lo_addr = g_str_hash(address_to_str(wmem_packet_scope(), lo_addr));
        break;
    }

    return m;
}
Example #18
0
gcp_msg_t* gcp_msg(packet_info* pinfo, int o, gboolean keep_persistent_data) {
    gcp_msg_t* m;
    guint32 framenum = (guint32)pinfo->fd->num;
    guint32 offset = (guint32)o;
    address* src = &(pinfo->src);
    address* dst = &(pinfo->dst);
    address* lo_addr;
    address* hi_addr;

    if (keep_persistent_data) {
        emem_tree_key_t key[] = {
            {1,&(framenum)},
            {1,&offset},
            {0,NULL}
        };

        if (( m = se_tree_lookup32_array(msgs,key) )) {
            m->commited = TRUE;
            return m;
        } else {
            m = se_alloc(sizeof(gcp_msg_t));
            m->framenum = framenum;
            m->time = pinfo->fd->abs_ts;
            m->trxs = NULL;
            m->commited = FALSE;

            se_tree_insert32_array(msgs,key,m);
        }
    } else {
        m = ep_new0(gcp_msg_t);
        m->framenum = framenum;
        m->trxs = NULL;
        m->commited = FALSE;
    }

    if (CMP_ADDRESS(src, dst) < 0)  {
        lo_addr = src;
        hi_addr = dst;
    } else {
        lo_addr = dst;
        hi_addr = src;
    }

    switch(lo_addr->type) {
        case AT_NONE:
            m->lo_addr = 0;
            m->hi_addr = 0;
            break;
        case AT_IPv4:
            memcpy((guint8*)&(m->hi_addr),hi_addr->data,4);
            memcpy((guint8*)&(m->lo_addr),lo_addr->data,4);
            break;
        case AT_SS7PC:
            m->hi_addr = mtp3_pc_hash((const mtp3_addr_pc_t *)hi_addr->data);
            m->lo_addr = mtp3_pc_hash((const mtp3_addr_pc_t *)lo_addr->data);
            break;
        default:
            /* XXX: heuristic and error prone */
            m->hi_addr = g_str_hash(ep_address_to_str(hi_addr));
            m->lo_addr = g_str_hash(ep_address_to_str(lo_addr));
        break;
    }

    return m;
}
Example #19
0
/* Pass in the pspec so we can get the generic type. For example, a 
 * held in a GParamSpec allowing OBJECT, but the value could be of type
 * VipsImage. generics are much faster to compare.
 */
static unsigned int
vips_value_hash( GParamSpec *pspec, GValue *value )
{
	GType generic = G_PARAM_SPEC_TYPE( pspec );

	/* Not compile-time constants, so we have to use a set of if()s. Could
	 * make a table at run time I guess.
	 */

	if( generic == G_TYPE_PARAM_BOOLEAN )
		return( (unsigned int) g_value_get_boolean( value ) );
	else if( generic == G_TYPE_PARAM_CHAR )
		return( (unsigned int) VIPS_VALUE_GET_CHAR( value ) );
	else if( generic == G_TYPE_PARAM_UCHAR )
		return( (unsigned int) g_value_get_uchar( value ) );
	else if( generic == G_TYPE_PARAM_INT )
		return( (unsigned int) g_value_get_int( value ) );
	else if( generic == G_TYPE_PARAM_UINT )
		return( (unsigned int) g_value_get_uint( value ) );
	else if( generic == G_TYPE_PARAM_LONG )
		return( (unsigned int) g_value_get_long( value ) );
	else if( generic == G_TYPE_PARAM_ULONG )
		return( (unsigned int) g_value_get_ulong( value ) );
	else if( generic == G_TYPE_PARAM_ENUM )
		return( (unsigned int) g_value_get_enum( value ) );
	else if( generic == G_TYPE_PARAM_FLAGS )
		return( (unsigned int) g_value_get_flags( value ) );
	else if( generic == G_TYPE_PARAM_UINT64 ) {
		guint64 i = g_value_get_uint64( value );

		return( INT64_HASH( (gint64 *) &i ) );
	}
	else if( generic == G_TYPE_PARAM_INT64 ) {
		gint64 i = g_value_get_int64( value );

		return( INT64_HASH( &i ) );
	}
	else if( generic == G_TYPE_PARAM_FLOAT ) {
		float f = g_value_get_float( value );

		return( g_direct_hash( (void *) &f ) );
	}
	else if( generic == G_TYPE_PARAM_DOUBLE ) {
		double d = g_value_get_double( value );

		return( DOUBLE_HASH( &d ) );
	}
	else if( generic == G_TYPE_PARAM_STRING ) {
		const char *s = g_value_get_string( value );

		return( s ? g_str_hash( s ) : 0 );
	}
	else if( generic == G_TYPE_PARAM_BOXED ) {
		void *p = g_value_get_boxed( value );

		return( p ? g_direct_hash( p ) : 0 );
	}
	else if( generic == G_TYPE_PARAM_POINTER ) {
		void *p = g_value_get_pointer( value );

		return( p ? g_direct_hash( p ) : 0 );
	}
	else if( generic == G_TYPE_PARAM_OBJECT ) {
		void *p = g_value_get_object( value );

		return( p ? g_direct_hash( p ) : 0 );
	}
	else {
		/* Fallback: convert to a string and hash that. 
		 * This is very slow, print a warning if we use it 
		 * so we can add another case.
		 */
		char *s;
		unsigned int hash;

		s = g_strdup_value_contents( value ); 
		hash = g_str_hash( s );

		printf( "vips_value_hash: no case for %s\n", s );
		printf( "\ttype %d, %s\n", 
			(int) G_VALUE_TYPE( value ),
			g_type_name( G_VALUE_TYPE( value ) ) );
		printf( "\tgeneric %d, %s\n", 
			(int) G_VALUE_TYPE( generic ),
			g_type_name( generic ) );

		g_free( s );

		return( hash );
	}
}
Example #20
0
static guint hash_func(gconstpointer a)
{
    const HashKey *key = a;
    return g_str_hash(key->symbol) + g_str_hash(key->filename);
}
static guint
attname_hash (gconstpointer key)
{
	return g_str_hash (((AttName*) key)->att_name);
}
   /*
     Takes a string and returns its hash table index
   */
static gint
bel_hash_func( gconstpointer str ) {
  return g_str_hash( str );
}
Example #23
0
PRIVATE unsigned int egg_hash_value(const void* key)
{
    HEGGINDEXCACHEKEY lp_cache_key = (HEGGINDEXCACHEKEY)key;

    return g_str_hash((char*)(lp_cache_key+1));
}
static guint
themed_icon_key_hash (ThemedIconKey *key)
{
	return g_str_hash (key->filename) ^ key->size;
}
Example #25
0
static uint buffer_hash(gconstpointer key) {
    buffer *b = (buffer *)key;

    return g_str_hash(b->ptr);
}