Example #1
0
static GSList *hosts_to_cache (void) {
  GSList *hosts = NULL;
  GSList *allhosts;
  GSList *tmp;
  struct host *h;
  time_t curtime = time (NULL);

  allhosts = all_hosts ();

  for (tmp = allhosts; tmp; tmp = tmp->next) {
    h = (struct host *) tmp->data;
    if (h->name && h->refreshed && 
                              h->refreshed < curtime + HOST_CACHE_MAX_AGE*2) {
      hosts = g_slist_prepend (hosts, h);
      host_ref (h);
    }
  }

  host_list_free (allhosts);

  hosts = g_slist_sort (hosts, (GCompareFunc) host_cache_sorting_helper);

  if (g_slist_length (hosts) > HOST_CACHE_MAX_SIZE) {
    tmp = g_slist_nth (hosts, HOST_CACHE_MAX_SIZE - 1);
    host_list_free (tmp->next);
    tmp->next = NULL;
  }

  return hosts;
}
Example #2
0
GSList *merge_hosts_to_resolve (GSList *hosts, GSList *servers) {
  struct host *h;
  time_t curtime = time (NULL);

  for (; servers; servers = servers->next) {
    h = ((struct server *) servers->data)->host;
    if (h->refreshed == 0 || h->refreshed >= curtime + HOST_CACHE_MAX_AGE)
    {
//      hosts = host_list_add (hosts, h);
      hosts = g_slist_prepend (hosts, h);
      host_ref(h);
    }
  }
  
  hosts = slist_sort_remove_dups(hosts,(GCompareFunc)host_sorting_helper,(void(*)(void*))host_unref);

  return hosts;
}
Example #3
0
GSList *all_hosts (void) {
  GSList *list = NULL;
  GSList *tmp;
  struct host *h;
  int i;

  if (!hosts.nodes)
    return NULL;

  for (i = 0; i < hosts.num; i++) {
    for (tmp = hosts.nodes[i]; tmp; tmp = tmp->next) {
      h = (struct host *) tmp->data;
      list = g_slist_prepend (list, h);
      host_ref (h);
    }
  }

  return list;
}
Example #4
0
File: srv-prop.c Project: IR4T4/xqf
struct server_props *properties_new (struct host *host, unsigned short port) {
	struct server_props *p;

	p = g_malloc (sizeof (struct server_props));

	p->host = host;
	host_ref (host);

	p->port = port;
	p->custom_cfg = NULL;
	p->server_password = NULL;
	p->spectator_password = NULL;
	p->rcon_password = NULL;
	p->reserved_slots =0;
	p->sucks = 0;
	p->comment = NULL;

	props_list = g_slist_append (props_list, p);

	return p;
}
Example #5
0
static GSList *host_cache_read_list (FILE *f) {
  GSList *hosts = NULL;
  char buf[1024];
  char *token[4];
  int n;
  struct host *h;
  time_t refreshed;
  char *endptr;

  while (fgets (buf, 1024, f)) {
    n = tokenize (buf, token, 4, " \t\n\r");
    if (n == 3) {
      refreshed = strtoul (token[0], &endptr, 10);
      if (endptr == token[0])	/* It's not a number */
	continue;

      h = host_add (token[1]);

      if (h) {
	if (h->name)
	  g_free (h->name);

	h->name = g_strdup (token[2]);
	h->refreshed = refreshed;

//	hosts = host_list_add (hosts, h);
	hosts = g_slist_prepend (hosts, h);
	host_ref(h);
      }
    }
  }

  hosts = slist_sort_remove_dups(hosts,(GCompareFunc)host_sorting_helper,(void(*)(void*))host_unref);

  return hosts;
}