Exemple #1
0
void vi_x86_core_write_checkpoint(struct vi_x86_core_t *core, FILE *f)
{
    struct vi_x86_context_t *context;
    struct vi_x86_inst_t *inst;

    int num_contexts;
    int num_insts;
    int count;

    char *context_name;
    char *inst_name;

    /* Number of contexts */
    num_contexts = hash_table_count(core->context_table);
    count = fwrite(&num_contexts, 1, 4, f);
    if (count != 4)
        fatal("%s: cannot write checkpoint", __FUNCTION__);

    /* Contexts */
    HASH_TABLE_FOR_EACH(core->context_table, context_name, context)
    str_write_to_file(f, context_name);

    /* Number of instructions */
    num_insts = hash_table_count(core->inst_table);
    count = fwrite(&num_insts, 1, 4, f);
    if (count != 4)
        fatal("%s: cannot write checkpoint", __FUNCTION__);

    /* Instructions */
    HASH_TABLE_FOR_EACH(core->inst_table, inst_name, inst)
    vi_x86_inst_write_checkpoint(inst, f);
}
Exemple #2
0
void vi_si_compute_unit_write_checkpoint(struct vi_si_compute_unit_t *compute_unit, FILE *f)
{
	int num_work_groups;
	int num_insts;

	int count;

	char *work_group_name;
	char *inst_name;

	struct vi_si_work_group_t *work_group;
	struct vi_si_inst_t *inst;

	/* Write number of work-groups */
	num_work_groups = hash_table_count(compute_unit->work_group_table);
	count = fwrite(&num_work_groups, 1, 4, f);
	if (count != 4)
		fatal("%s: cannot write checkpoint", __FUNCTION__);

	/* Write work-groups */
	HASH_TABLE_FOR_EACH(compute_unit->work_group_table, work_group_name, work_group)
		vi_si_work_group_write_checkpoint(work_group, f);

	/* Write number of instructions */
	num_insts = hash_table_count(compute_unit->inst_table);
	count = fwrite(&num_insts, 1, 4, f);
	if (count != 4)
		fatal("%s: cannot write checkpoint", __FUNCTION__);

	/* Write instructions */
	HASH_TABLE_FOR_EACH(compute_unit->inst_table, inst_name, inst)
		vi_si_inst_write_checkpoint(inst, f);
}
Exemple #3
0
void
print_broken_links (void)
{
  hash_table_iterator iter;
  int num_elems;

  if (!nonexisting_urls_set)
    {
      logprintf (LOG_NOTQUIET, _("Found no broken links.\n\n"));
      return;
    }

  num_elems = hash_table_count (nonexisting_urls_set);
  assert (num_elems > 0);

  logprintf (LOG_NOTQUIET, ngettext("Found %d broken link.\n\n",
                                    "Found %d broken links.\n\n", num_elems),
             num_elems);

  for (hash_table_iterate (nonexisting_urls_set, &iter);
       hash_table_iter_next (&iter); )
    {
      /* Struct url_list *list; */
      const char *url = (const char *) iter.key;

      logprintf (LOG_NOTQUIET, _("%s\n"), url);
    }
  logputs (LOG_NOTQUIET, "\n");
}
void auth_server_connection_deinit(struct auth_server_connection **_conn)
{
        struct auth_server_connection *conn = *_conn;

	*_conn = NULL;

	auth_server_connection_disconnect(conn, "deinitializing");
	i_assert(hash_table_count(conn->requests) == 0);
	hash_table_destroy(&conn->requests);
	array_free(&conn->available_auth_mechs);
	pool_unref(&conn->pool);
}
void auth_request_handler_unref(struct auth_request_handler **_handler)
{
        struct auth_request_handler *handler = *_handler;

	*_handler = NULL;

	i_assert(handler->refcount > 0);
	if (--handler->refcount > 0)
		return;

	i_assert(hash_table_count(handler->requests) == 0);

	/* notify parent that we're done with all requests */
	handler->callback(NULL, handler->context);

	hash_table_destroy(&handler->requests);
	pool_unref(&handler->pool);
}
// write_classes
void write_classes(Val stream)
{
    Val classes =  VAR(Aruntime_environmentA)->
            Decode<Environment>()->m_classes;

    Val count  = hash_table_count(classes);

    format(Qt, L"  write ~D classes.~%", count);
    format(stream, L"~%// ~D classes~%", count);

    foreach (EnumHashTable, oEnum, classes)
    {
        Val klass = oEnum.GetVal();
        if (klass->Is<Instance>())
        {
            write_class(stream, klass);
        }
    } // for each entry
Exemple #7
0
static void
discard_matching_cookie (struct cookie *cookie)
{
  struct cookie *prev, *victim;

  if (!cookies_hash_table
      || !hash_table_count (cookies_hash_table))
    /* No elements == nothing to discard. */
    return;

  victim = find_matching_cookie (cookie, &prev);
  if (victim)
    {
      if (prev)
	/* Simply unchain the victim. */
	prev->next = victim->next;
      else
	{
	  /* VICTIM was head of its chain.  We need to place a new
	     cookie at the head.  */

	  char *hostport;
	  char *chain_key = NULL;
	  int res;

	  SET_HOSTPORT (victim->domain, victim->port, hostport);
	  res = hash_table_get_pair (cookies_hash_table, hostport,
				     &chain_key, NULL);
	  assert (res != 0);
	  if (!victim->next)
	    {
	      /* VICTIM was the only cookie in the chain.  Destroy the
		 chain and deallocate the chain key.  */

	      hash_table_remove (cookies_hash_table, hostport);
	      xfree (chain_key);
	    }
	  else
	    hash_table_put (cookies_hash_table, chain_key, victim->next);
	}
      delete_cookie (victim);
      DEBUGP (("Discarded old cookie.\n"));
    }
}
Exemple #8
0
static void bin_config_elem_list_save(struct hash_table_t *elem_list, gzFile f)
{
	struct bin_config_elem_t *elem;
	int num_elem;

	char *var;
	int var_len;

	/* Empty list */
	assert(sizeof(int) == 4);
	if (!elem_list)
	{
		num_elem = 0;
		gzwrite(f, &num_elem, 4);
		return;
	}

	/* Number of elements */
	num_elem = hash_table_count(elem_list);
	gzwrite(f, &num_elem, 4);

	/* List of elements */
	for (var = hash_table_find_first(elem_list, (void **) &elem); elem;
		var = hash_table_find_next(elem_list, (void **) &elem))
	{
		/* Variable name */
		var_len = strlen(var);
		gzwrite(f, &var_len, 4);
		gzwrite(f, var, var_len);

		/* Variable value */
		gzwrite(f, &elem->size, 4);
		if (elem->data)
			gzwrite(f, elem->data, elem->size);

		/* Child elements */
		bin_config_elem_list_save(elem->child_elem_list, f);

	}
}
Exemple #9
0
void
save_cookies (const char *file)
{
  FILE *fp;

  if (!cookies_hash_table
      || !hash_table_count (cookies_hash_table))
    /* no cookies stored; nothing to do. */
    return;

  DEBUGP (("Saving cookies to %s.\n", file));

  cookies_now = time (NULL);

  fp = fopen (file, "w");
  if (!fp)
    {
      logprintf (LOG_NOTQUIET, _("Cannot open cookies file `%s': %s\n"),
		 file, strerror (errno));
      return;
    }

  fputs ("# HTTP cookie file.\n", fp);
  fprintf (fp, "# Generated by Wget on %s.\n", datetime_str (NULL));
  fputs ("# Edit at your own risk.\n\n", fp);

  hash_table_map (cookies_hash_table, save_cookies_mapper, fp);

  if (ferror (fp))
    logprintf (LOG_NOTQUIET, _("Error writing to `%s': %s\n"),
	       file, strerror (errno));

  if (fclose (fp) < 0)
    logprintf (LOG_NOTQUIET, _("Error closing `%s': %s\n"),
	       file, strerror (errno));

  DEBUGP (("Done saving cookies.\n"));
}
static void
auth_server_connection_remove_requests(struct auth_server_connection *conn,
				       const char *disconnect_reason)
{
	static const char *const temp_failure_args[] = { "temp", NULL };
	struct hash_iterate_context *iter;
	void *key;
	struct auth_client_request *request;
	time_t created, oldest = 0;
	unsigned int request_count = 0;

	if (hash_table_count(conn->requests) == 0)
		return;

	iter = hash_table_iterate_init(conn->requests);
	while (hash_table_iterate(iter, conn->requests, &key, &request)) {
		if (!auth_client_request_is_aborted(request)) {
			request_count++;
			created = auth_client_request_get_create_time(request);
			if (oldest > created || oldest == 0)
				oldest = created;
		}

		auth_client_request_server_input(request,
			AUTH_REQUEST_STATUS_INTERNAL_FAIL,
			temp_failure_args);
	}
	hash_table_iterate_deinit(&iter);
	hash_table_clear(conn->requests, FALSE);

	if (request_count > 0) {
		i_warning("Auth connection closed with %u pending requests "
			  "(max %u secs, pid=%s, %s)", request_count,
			  (unsigned int)(ioloop_time - oldest),
			  my_pid, disconnect_reason);
	}
}
Exemple #11
0
bool str_table_is_empty(struct str_table *table)
{
	return hash_table_count(table->hash) == 0;
}
unsigned int master_login_auth_request_count(struct master_login_auth *auth)
{
	return hash_table_count(auth->requests);
}
Exemple #13
0
static void
convert_links_in_hashtable (struct hash_table *downloaded_set,
                            int is_css,
                            int *file_count)
{
    int i;

    int cnt;
    char **file_array;

    cnt = 0;
    if (downloaded_set)
        cnt = hash_table_count (downloaded_set);
    if (cnt == 0)
        return;
    file_array = alloca_array (char *, cnt);
    string_set_to_array (downloaded_set, file_array);

    for (i = 0; i < cnt; i++)
    {
        struct urlpos *urls, *cur_url;
        char *url;
        char *file = file_array[i];

        /* Determine the URL of the file.  get_urls_{html,css} will need
           it.  */
        url = hash_table_get (dl_file_url_map, file);
        if (!url)
        {
            DEBUGP (("Apparently %s has been removed.\n", file));
            continue;
        }

        DEBUGP (("Scanning %s (from %s)\n", file, url));

        /* Parse the file...  */
        urls = is_css ? get_urls_css_file (file, url) :
               get_urls_html (file, url, NULL, NULL);

        /* We don't respect meta_disallow_follow here because, even if
           the file is not followed, we might still want to convert the
           links that have been followed from other files.  */

        for (cur_url = urls; cur_url; cur_url = cur_url->next)
        {
            char *local_name;
            struct url *u;
            struct iri *pi;

            if (cur_url->link_base_p)
            {
                /* Base references have been resolved by our parser, so
                   we turn the base URL into an empty string.  (Perhaps
                   we should remove the tag entirely?)  */
                cur_url->convert = CO_NULLIFY_BASE;
                continue;
            }

            /* We decide the direction of conversion according to whether
               a URL was downloaded.  Downloaded URLs will be converted
               ABS2REL, whereas non-downloaded will be converted REL2ABS.  */

            pi = iri_new ();
            set_uri_encoding (pi, opt.locale, true);

            u = url_parse (cur_url->url->url, NULL, pi, true);
            if (!u)
                continue;

            local_name = hash_table_get (dl_url_file_map, u->url);

            /* Decide on the conversion type.  */
            if (local_name)
            {
                /* We've downloaded this URL.  Convert it to relative
                   form.  We do this even if the URL already is in
                   relative form, because our directory structure may
                   not be identical to that on the server (think `-nd',
                   `--cut-dirs', etc.)  */
                cur_url->convert = CO_CONVERT_TO_RELATIVE;
                cur_url->local_name = xstrdup (local_name);
                DEBUGP (("will convert url %s to local %s\n", u->url, local_name));
            }
            else
            {
                /* We haven't downloaded this URL.  If it's not already
                   complete (including a full host name), convert it to
                   that form, so it can be reached while browsing this
                   HTML locally.  */
                if (!cur_url->link_complete_p)
                    cur_url->convert = CO_CONVERT_TO_COMPLETE;
                cur_url->local_name = NULL;
                DEBUGP (("will convert url %s to complete\n", u->url));
            }

            url_free (u);
            iri_free (pi);
        }

        /* Convert the links in the file.  */
        convert_links (file, urls);
        ++*file_count;

        /* Free the data.  */
        free_urlpos (urls);
    }
}
unsigned int
auth_request_handler_get_request_count(struct auth_request_handler *handler)
{
	return hash_table_count(handler->requests);
}
Exemple #15
0
static int passwd_file_open(struct passwd_file *pw, bool startup,
			    const char **error_r)
{
	const char *no_args = NULL;
	struct istream *input;
	const char *line;
	struct stat st;
	time_t start_time, end_time;
	unsigned int time_secs;
	int fd;

	fd = open(pw->path, O_RDONLY);
	if (fd == -1) {
		if (errno == EACCES)
			*error_r = eacces_error_get("open", pw->path);
		else {
			*error_r = t_strdup_printf("open(%s) failed: %m",
						   pw->path);
		}
		return -1;
	}

	if (fstat(fd, &st) != 0) {
		*error_r = t_strdup_printf("fstat(%s) failed: %m",
					   pw->path);
		i_close_fd(&fd);
		return -1;
	}

	pw->fd = fd;
	pw->stamp = st.st_mtime;
	pw->size = st.st_size;

	pw->pool = pool_alloconly_create(MEMPOOL_GROWING"passwd_file", 10240);
	hash_table_create(&pw->users, pw->pool, 0, str_hash, strcmp);

	start_time = time(NULL);
	input = i_stream_create_fd(pw->fd, (size_t)-1, FALSE);
	i_stream_set_return_partial_line(input, TRUE);
	while ((line = i_stream_read_next_line(input)) != NULL) {
		if (*line == '\0' || *line == ':' || *line == '#')
			continue; /* no username or comment */

		T_BEGIN {
			const char *const *args = t_strsplit(line, ":");
			if (args[1] != NULL) {
				/* at least username+password */
				passwd_file_add(pw, args[0], args[1], args+2);
			} else {
				/* only username */
				passwd_file_add(pw, args[0], NULL, &no_args);
			}
		} T_END;
	}
	i_stream_destroy(&input);
	end_time = time(NULL);
	time_secs = end_time - start_time;

	if ((time_secs > PARSE_TIME_STARTUP_WARN_SECS && startup) ||
	    (time_secs > PARSE_TIME_RELOAD_WARN_SECS && !startup)) {
		i_warning("passwd-file %s: Reading %u users took %u secs",
			  pw->path, hash_table_count(pw->users), time_secs);
	} else if (pw->db->debug) {
		i_debug("passwd-file %s: Read %u users in %u secs",
			pw->path, hash_table_count(pw->users), time_secs);
	}
	return 0;
}