ifnet: constify tons of stuff

Use 'const char *' where appropriate.
This commit is contained in:
Dan Williams
2010-10-29 13:56:23 -05:00
parent 090329d0be
commit 8a6e2b6560
11 changed files with 461 additions and 424 deletions

View File

@@ -60,40 +60,34 @@ strip_string (gchar * str, gchar t)
}
gboolean
is_hex (gchar * value)
is_hex (const char *value)
{
gchar *p;
const char *p = value;
if (!value)
if (!p)
return FALSE;
p = value;
while (*p) {
if (!isxdigit (*p)) {
if (!isxdigit (*p++))
return FALSE;
}
p++;
}
return TRUE;
}
gboolean
is_ascii (gchar * value)
is_ascii (const char *value)
{
gchar *p;
const char *p = value;
p = value;
while (*p) {
if (!isascii (*p)) {
if (!isascii (*p++))
return FALSE;
}
p++;
}
return TRUE;
}
gboolean
is_true (char *str)
is_true (const char *str)
{
if (!g_ascii_strcasecmp (str, "yes")
|| !g_ascii_strcasecmp (str, "true"))
@@ -195,7 +189,7 @@ ifnet_plugin_error_quark (void)
}
gboolean
reload_parsers ()
reload_parsers (void)
{
ifnet_destroy ();
wpa_parser_destroy ();
@@ -206,7 +200,7 @@ reload_parsers ()
}
gchar *
read_hostname (gchar * path)
read_hostname (const char *path)
{
gchar *contents = NULL, *result = NULL, *tmp;
gchar **all_lines = NULL;
@@ -235,21 +229,23 @@ read_hostname (gchar * path)
}
gboolean
write_hostname (const gchar * hostname, gchar * path)
write_hostname (const gchar *hostname, const char *path)
{
gchar *contents = g_strdup_printf ("#Generated by NetworkManager\n"
"hostname=\"%s\"\n", hostname);
gboolean result = g_file_set_contents (path, contents, -1, NULL);
gboolean result;
char *contents;
contents = g_strdup_printf ("#Generated by NetworkManager\n"
"hostname=\"%s\"\n", hostname);
result = g_file_set_contents (path, contents, -1, NULL);
g_free (contents);
return result;
}
gboolean
is_static_ip4 (gchar * conn_name)
is_static_ip4 (const char *conn_name)
{
gchar *data = ifnet_get_data (conn_name, "config");
gchar *dhcp6;
const char *data = ifnet_get_data (conn_name, "config");
const char *dhcp6;
if (!data)
return FALSE;
@@ -270,9 +266,9 @@ is_static_ip4 (gchar * conn_name)
}
gboolean
is_static_ip6 (gchar * conn_name)
is_static_ip6 (const char *conn_name)
{
gchar *data = ifnet_get_data (conn_name, "config");
const char *data = ifnet_get_data (conn_name, "config");
if (!data)
return TRUE;
@@ -280,9 +276,9 @@ is_static_ip6 (gchar * conn_name)
}
gboolean
is_ip4_address (gchar * in_address)
is_ip4_address (const char *in_address)
{
gchar *pattern =
const char *pattern =
"\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.((\\{\\d{1,3}\\.\\.\\d{1,3}\\})|\\d{1,3})$";
gchar *address = g_strdup (in_address);
gboolean result = FALSE;
@@ -308,17 +304,15 @@ is_ip4_address (gchar * in_address)
}
gboolean
is_ip6_address (gchar * in_address)
is_ip6_address (const char *in_address)
{
struct in6_addr tmp_ip6_addr;
gchar *tmp;
gchar *address = g_strdup (in_address);
gchar *tmp, *address;
gboolean result = FALSE;
if (!address) {
g_free (address);
if (!in_address)
return FALSE;
}
address = g_strdup (in_address);
g_strstrip (address);
if ((tmp = strchr (address, '/')) != NULL)
*tmp = '\0';
@@ -330,7 +324,7 @@ is_ip6_address (gchar * in_address)
}
gboolean
has_ip6_address (gchar * conn_name)
has_ip6_address (const char *conn_name)
{
gchar **ipset;
guint length;
@@ -353,30 +347,29 @@ has_ip6_address (gchar * conn_name)
}
gboolean
has_default_route (gchar * conn_name, gboolean (*check_fn) (gchar *))
has_default_route (const char *conn_name, gboolean (*check_fn) (const char *))
{
gchar *routes = NULL, *tmp, *end;
char *routes = NULL, *end, *tmp;
gboolean success = FALSE;
g_return_val_if_fail (conn_name != NULL, FALSE);
tmp = ifnet_get_data (conn_name, "routes");
if (!tmp)
routes = g_strdup (ifnet_get_data (conn_name, "routes"));
if (!routes)
return FALSE;
routes = g_strdup (tmp);
tmp = strstr (routes, "default via ");
if (!tmp) {
goto error;
if (tmp) {
tmp += strlen ("default via ");
g_strstrip (tmp);
if ((end = strstr (tmp, "\"")) != NULL)
*end = '\0';
if (check_fn (tmp))
success = TRUE;
}
tmp += strlen ("default via ");
g_strstrip (tmp);
if ((end = strstr (tmp, "\"")) != NULL)
*end = '\0';
if (check_fn (tmp)) {
g_free (routes);
return TRUE;
}
error:
g_free (routes);
return FALSE;
return success;
}
static ip_block *
@@ -529,28 +522,28 @@ get_ip6_next_hop (gchar * next_hop)
}
ip_block *
convert_ip4_config_block (gchar * conn_name)
convert_ip4_config_block (const char *conn_name)
{
gchar **ipset;
guint length;
guint i;
gchar *ip;
guint32 def_gateway;
gchar *routes;
guint32 def_gateway = 0;
const char *routes;
gchar *pos;
ip_block *start = NULL, *current = NULL, *iblock = NULL;
gchar *pattern =
const char *pattern =
"((\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.)\\{(\\d{1,3})\\.\\.(\\d{1,3})\\}(/\\d{1,2}))";
GRegex *regex = g_regex_new (pattern, 0, 0, NULL);
g_return_val_if_fail (conn_name != NULL, NULL);
ipset = g_strsplit (ifnet_get_data (conn_name, "config"), "\" \"", 0);
length = g_strv_length (ipset);
routes = ifnet_get_data (conn_name, "routes");
if (routes)
def_gateway = get_ip4_gateway (strstr (routes, "default"));
else
def_gateway = 0;
for (i = 0; i < length; i++) {
ip = ipset[i];
ip = strip_string (ip, '"');
@@ -559,9 +552,13 @@ convert_ip4_config_block (gchar * conn_name)
gchar *ip_start, *ip_prefix;
gchar *begin_str, *end_str;
int begin, end, j;
GRegex *regex;
GMatchInfo *match_info;
regex = g_regex_new (pattern, 0, 0, NULL);
g_regex_match (regex, ip, 0, &match_info);
g_regex_unref (regex);
if (!g_match_info_matches (match_info)) {
g_match_info_free (match_info);
continue;
@@ -620,12 +617,11 @@ convert_ip4_config_block (gchar * conn_name)
}
}
g_strfreev (ipset);
g_regex_unref (regex);
return start;
}
ip6_block *
convert_ip6_config_block (gchar * conn_name)
convert_ip6_config_block (const char *conn_name)
{
gchar **ipset;
guint length;
@@ -654,16 +650,17 @@ convert_ip6_config_block (gchar * conn_name)
}
ip_block *
convert_ip4_routes_block (gchar * conn_name)
convert_ip4_routes_block (const char *conn_name)
{
gchar **ipset;
guint length;
guint i;
gchar *ip;
gchar *routes;
const char *routes;
ip_block *start = NULL, *current = NULL, *iblock = NULL;
g_return_val_if_fail (conn_name != NULL, NULL);
routes = ifnet_get_data (conn_name, "routes");
if (!routes)
return NULL;
@@ -691,13 +688,13 @@ convert_ip4_routes_block (gchar * conn_name)
}
ip6_block *
convert_ip6_routes_block (gchar * conn_name)
convert_ip6_routes_block (const char *conn_name)
{
gchar **ipset;
guint length;
guint i;
gchar *ip, *tmp_addr;
gchar *routes;
const char *routes;
ip6_block *start = NULL, *current = NULL, *iblock = NULL;
struct in6_addr *tmp_ip6_addr;
@@ -766,18 +763,22 @@ destroy_ip6_block (ip6_block * iblock)
}
void
set_ip4_dns_servers (NMSettingIP4Config * s_ip4, gchar * conn_name)
set_ip4_dns_servers (NMSettingIP4Config *s_ip4, const char *conn_name)
{
gchar *dns_servers = ifnet_get_data (conn_name, "dns_servers");
gchar **server_list;
const char *dns_servers;
gchar **server_list, *stripped;
guint length, i;
struct in_addr tmp_ip4_addr;
guint32 new_dns;
dns_servers = ifnet_get_data (conn_name, "dns_servers");
if (!dns_servers)
return;
strip_string (dns_servers, '"');
server_list = g_strsplit (dns_servers, " ", 0);
stripped = g_strdup (dns_servers);
strip_string (stripped, '"');
server_list = g_strsplit (stripped, " ", 0);
g_free (stripped);
length = g_strv_length (server_list);
if (length)
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_IGNORE_AUTO_DNS,
@@ -803,17 +804,22 @@ set_ip4_dns_servers (NMSettingIP4Config * s_ip4, gchar * conn_name)
}
void
set_ip6_dns_servers (NMSettingIP6Config * s_ip6, gchar * conn_name)
set_ip6_dns_servers (NMSettingIP6Config *s_ip6, const char *conn_name)
{
gchar *dns_servers = ifnet_get_data (conn_name, "dns_servers");
gchar **server_list;
const char *dns_servers;
gchar **server_list, *stripped;
guint length, i;
struct in6_addr tmp_ip6_addr;
dns_servers = ifnet_get_data (conn_name, "dns_servers");
if (!dns_servers)
return;
strip_string (dns_servers, '"');
server_list = g_strsplit (dns_servers, " ", 0);
stripped = g_strdup (dns_servers);
strip_string (stripped, '"');
server_list = g_strsplit (stripped, " ", 0);
g_free (stripped);
length = g_strv_length (server_list);
if (length)
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_IGNORE_AUTO_DNS,
@@ -839,7 +845,7 @@ set_ip6_dns_servers (NMSettingIP6Config * s_ip6, gchar * conn_name)
}
gboolean
is_managed (gchar * conn_name)
is_managed (const char *conn_name)
{
gchar *config;
@@ -855,13 +861,14 @@ is_managed (gchar * conn_name)
void
get_dhcp_hostname_and_client_id (char **hostname, char **client_id)
{
gchar *dhcp_client = ifnet_get_global_setting ("main", "dhcp");
const char *dhcp_client;
const gchar *dhcpcd_conf = "/etc/dhcpcd.conf";
const gchar *dhclient_conf = "/etc/dhcp/dhclient.conf";
gchar *line = NULL, *tmp = NULL, *contents = NULL;
gchar **all_lines;
guint line_num, i;
dhcp_client = ifnet_get_global_setting ("main", "dhcp");
*hostname = NULL;
*client_id = NULL;
if (dhcp_client) {