Remove _ from global variables.

SVN revision: 16426
This commit is contained in:
sebastid 2005-08-30 10:17:10 +00:00 committed by sebastid
parent 19d9aa1452
commit b72979a68e
1 changed files with 71 additions and 60 deletions

View File

@ -85,19 +85,19 @@ static void _ecore_con_dns_cache_free(Ecore_Con_Dns_Cache *cache);
static int _ecore_con_hostname_get(unsigned char *buf, char *hostname, static int _ecore_con_hostname_get(unsigned char *buf, char *hostname,
int pos, int length); int pos, int length);
static int _init = 0; static int dns_init = 0;
static struct in_addr _servers[SERVERS]; static struct in_addr servers[SERVERS];
static int _server_count; static int server_count;
static char *_search[6]; static char *search[6];
static int _search_count = 0; static int search_count = 0;
static char *_domain = NULL; static char *domain = NULL;
static uint16_t _id = 0; static uint16_t dns_id = 0;
static Ecore_Con_Dns_Cache *_cache = NULL; static Ecore_Con_Dns_Cache *dns_cache = NULL;
#define SET_16BIT(p, v) \ #define SET_16BIT(p, v) \
(((p)[0]) = ((v) >> 8) & 0xff), \ (((p)[0]) = ((v) >> 8) & 0xff), \
@ -114,11 +114,11 @@ ecore_con_dns_init(void)
char *p, *p2; char *p, *p2;
int ret; int ret;
_init++; dns_init++;
if (_init > 1) return 1; if (dns_init > 1) return 1;
memset(_servers, 0, sizeof(_servers)); memset(servers, 0, sizeof(servers));
_server_count = 0; server_count = 0;
file = fopen("/etc/resolv.conf", "rb"); file = fopen("/etc/resolv.conf", "rb");
if (!file) return 0; if (!file) return 0;
@ -141,10 +141,10 @@ ecore_con_dns_init(void)
if (!strncmp(buf, "nameserver", 10)) if (!strncmp(buf, "nameserver", 10))
{ {
if (_server_count >= SERVERS) continue; if (server_count >= SERVERS) continue;
_servers[_server_count].s_addr = inet_addr(p); servers[server_count].s_addr = inet_addr(p);
_server_count++; server_count++;
} }
else if (!strncmp(buf, "domain", 6)) else if (!strncmp(buf, "domain", 6))
{ {
@ -154,18 +154,18 @@ ecore_con_dns_init(void)
if (*p == '.') if (*p == '.')
p++; p++;
/* Get the domain */ /* Get the domain */
_domain = strdup(p); domain = strdup(p);
/* clear search */ /* clear search */
for (i = 0; i < _search_count; i++) for (i = 0; i < search_count; i++)
{ {
free(_search[i]); free(search[i]);
_search[i] = NULL; search[i] = NULL;
} }
_search_count = 0; search_count = 0;
} }
else if (!strncmp(buf, "search", 6)) else if (!strncmp(buf, "search", 6))
{ {
while ((p) && (_search_count < 6)) while ((p) && (search_count < 6))
{ {
/* Remove whitespace */ /* Remove whitespace */
while ((*p) && (isspace(*p))) while ((*p) && (isspace(*p)))
@ -180,15 +180,15 @@ ecore_con_dns_init(void)
if (p2) if (p2)
*p2 = 0; *p2 = 0;
/* Get this element */ /* Get this element */
_search[_search_count] = strdup(p); search[search_count] = strdup(p);
_search_count++; search_count++;
if (p2) p = p2 + 1; if (p2) p = p2 + 1;
else p = NULL; else p = NULL;
} }
if (_domain) if (domain)
{ {
free(_domain); free(domain);
_domain = NULL; domain = NULL;
} }
} }
else if (!strncmp(buf, "sortlist", 8)) else if (!strncmp(buf, "sortlist", 8))
@ -202,13 +202,13 @@ ecore_con_dns_init(void)
} }
fclose(file); fclose(file);
if (!_server_count) if (!server_count)
{ {
/* We should try localhost */ /* We should try localhost */
_servers[_server_count].s_addr = inet_addr("127.0.0.1"); servers[server_count].s_addr = inet_addr("127.0.0.1");
_server_count++; server_count++;
} }
if ((!_search_count) && (!_domain)) if ((!search_count) && (!domain))
{ {
/* Get domain from hostname */ /* Get domain from hostname */
ret = gethostname(buf, sizeof(buf)); ret = gethostname(buf, sizeof(buf));
@ -218,7 +218,7 @@ ecore_con_dns_init(void)
if (p) if (p)
{ {
p++; p++;
_domain = strdup(p); domain = strdup(p);
} }
} }
} }
@ -229,19 +229,30 @@ ecore_con_dns_init(void)
void void
ecore_con_dns_shutdown(void) ecore_con_dns_shutdown(void)
{ {
Ecore_List2 *l;
int i; int i;
_init--; dns_init--;
if (_init > 0) return; if (dns_init > 0) return;
if (_domain) for (l = (Ecore_List2 *)dns_cache; l;)
{ {
free(_domain); Ecore_Con_Dns_Cache *current;
_domain = NULL;
current = (Ecore_Con_Dns_Cache *)l;
l = l->next;
_ecore_con_dns_cache_free(current);
} }
for (i = 0; i < _search_count; i++) dns_cache = NULL;
free(_search[i]);
_search_count = 0; if (domain)
{
free(domain);
domain = NULL;
}
for (i = 0; i < search_count; i++)
free(search[i]);
search_count = 0;
} }
int int
@ -253,10 +264,10 @@ ecore_con_dns_lookup(const char *name,
Ecore_Con_Dns_Cache *current; Ecore_Con_Dns_Cache *current;
Ecore_List2 *l; Ecore_List2 *l;
if (!_server_count) return 0; if (!server_count) return 0;
if ((!name) || (!*name)) return 0; if ((!name) || (!*name)) return 0;
for (l = (Ecore_List2 *)_cache; l;) for (l = (Ecore_List2 *)dns_cache; l;)
{ {
double time; double time;
int i; int i;
@ -267,7 +278,7 @@ ecore_con_dns_lookup(const char *name,
time = ecore_time_get(); time = ecore_time_get();
if ((time - current->time) > current->ttl) if ((time - current->time) > current->ttl)
{ {
_cache = _ecore_list2_remove(_cache, current); dns_cache = _ecore_list2_remove(dns_cache, current);
_ecore_con_dns_cache_free(current); _ecore_con_dns_cache_free(current);
} }
else else
@ -277,8 +288,8 @@ ecore_con_dns_lookup(const char *name,
{ {
if (done_cb) if (done_cb)
done_cb(data, current->he); done_cb(data, current->he);
_cache = _ecore_list2_remove(_cache, current); dns_cache = _ecore_list2_remove(dns_cache, current);
_cache = _ecore_list2_prepend(_cache, current); dns_cache = _ecore_list2_prepend(dns_cache, current);
return 1; return 1;
} }
for (i = 0; current->he->h_aliases[i]; i++) for (i = 0; current->he->h_aliases[i]; i++)
@ -287,8 +298,8 @@ ecore_con_dns_lookup(const char *name,
{ {
if (done_cb) if (done_cb)
done_cb(data, current->he); done_cb(data, current->he);
_cache = _ecore_list2_remove(_cache, current); dns_cache = _ecore_list2_remove(dns_cache, current);
_cache = _ecore_list2_prepend(_cache, current); dns_cache = _ecore_list2_prepend(dns_cache, current);
return 1; return 1;
} }
} }
@ -387,7 +398,7 @@ _ecore_con_dns_ghbn(Ecore_Con_Dns_Query *query, const char *hostname)
total_len += QFIXEDSZ; total_len += QFIXEDSZ;
/* We're crazy, just ask all servers! */ /* We're crazy, just ask all servers! */
for (i = 0; i < _server_count; i++) for (i = 0; i < server_count; i++)
{ {
struct sockaddr_in sin; struct sockaddr_in sin;
@ -400,7 +411,7 @@ _ecore_con_dns_ghbn(Ecore_Con_Dns_Query *query, const char *hostname)
memset(&sin, 0, sizeof(sin)); memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr = _servers[i]; sin.sin_addr = servers[i];
sin.sin_port = htons(NAMESERVER_PORT); sin.sin_port = htons(NAMESERVER_PORT);
if (connect(query->socket[i], (struct sockaddr *) &sin, sizeof(sin)) == -1) if (connect(query->socket[i], (struct sockaddr *) &sin, sizeof(sin)) == -1)
{ {
@ -412,7 +423,7 @@ _ecore_con_dns_ghbn(Ecore_Con_Dns_Query *query, const char *hostname)
} }
/* qid */ /* qid */
query->id[i] = ++_id; query->id[i] = ++dns_id;
SET_16BIT(buf, query->id[i]); SET_16BIT(buf, query->id[i]);
if (send(query->socket[i], buf, total_len, 0) == -1) if (send(query->socket[i], buf, total_len, 0) == -1)
@ -470,7 +481,7 @@ _ecore_con_cb_fd_handler(void *data, Ecore_Fd_Handler *fd_handler)
/* Check if this message is for us */ /* Check if this message is for us */
id = GET_16BIT(buf); id = GET_16BIT(buf);
found = 0; found = 0;
for (i = 0; i < _server_count; i++) for (i = 0; i < server_count; i++)
{ {
if (query->id[i] == id) if (query->id[i] == id)
{ {
@ -584,19 +595,19 @@ _ecore_con_cb_fd_handler(void *data, Ecore_Fd_Handler *fd_handler)
cache->ttl = ttl; cache->ttl = ttl;
cache->time = ecore_time_get(); cache->time = ecore_time_get();
cache->he = he; cache->he = he;
_cache = _ecore_list2_prepend(_cache, cache); dns_cache = _ecore_list2_prepend(dns_cache, cache);
/* Check cache size */ /* Check cache size */
i = 1; i = 1;
l = (Ecore_List2 *)_cache; l = (Ecore_List2 *)dns_cache;
while ((l = l->next)) while ((l = l->next))
i++; i++;
/* Remove old stuff if cache to big */ /* Remove old stuff if cache to big */
if (i > 16) if (i > 16)
{ {
cache = (Ecore_Con_Dns_Cache *)((Ecore_List2 *)_cache)->last; cache = (Ecore_Con_Dns_Cache *)((Ecore_List2 *)dns_cache)->last;
_cache = _ecore_list2_remove(_cache, cache); dns_cache = _ecore_list2_remove(dns_cache, cache);
_ecore_con_dns_cache_free(cache); _ecore_con_dns_cache_free(cache);
} }
} }
@ -624,7 +635,7 @@ error:
} }
found = 0; found = 0;
for (i = 0; i < _server_count; i++) for (i = 0; i < server_count; i++)
{ {
if (query->fd_handlers[i] == fd_handler) if (query->fd_handlers[i] == fd_handler)
{ {
@ -645,9 +656,9 @@ error:
char buf[256]; char buf[256];
/* Should we look more? */ /* Should we look more? */
if ((_domain) && (query->search++)) if ((domain) && (query->search++))
{ {
if (snprintf(buf, sizeof(buf), "%s.%s", query->searchname, _domain) < sizeof(buf)) if (snprintf(buf, sizeof(buf), "%s.%s", query->searchname, domain) < sizeof(buf))
{ {
_ecore_con_dns_ghbn(query, buf); _ecore_con_dns_ghbn(query, buf);
} }
@ -658,9 +669,9 @@ error:
_ecore_con_dns_query_free(query); _ecore_con_dns_query_free(query);
} }
} }
else if ((++query->search) < _search_count) else if ((++query->search) < search_count)
{ {
if (snprintf(buf, sizeof(buf), "%s.%s", query->searchname, _search[query->search]) < sizeof(buf)) if (snprintf(buf, sizeof(buf), "%s.%s", query->searchname, search[query->search]) < sizeof(buf))
{ {
_ecore_con_dns_ghbn(query, buf); _ecore_con_dns_ghbn(query, buf);
} }
@ -687,7 +698,7 @@ _ecore_con_dns_query_free(Ecore_Con_Dns_Query *query)
{ {
int i; int i;
for (i = 0; i < _server_count; i++) for (i = 0; i < server_count; i++)
{ {
if (query->socket[i]) close(query->socket[i]); if (query->socket[i]) close(query->socket[i]);
query->socket[i] = 0; query->socket[i] = 0;