flimflam: Fix compilation errors when compiling with glib 2.32.

This CL makes the following changes to make the code compatible with
glib 2.30 and 2.32:
- Include glib.h instead of glib/ghash.h as the latter should not be
  included directly.
- Use g_ascii_strcasecmp() instead of g_strcasecmp() for
  case-insensitive comparison of ASCII-only strings. g_strcasecmp() has
  been deprecated.
- Use g_atomic_int_add() instead of g_atomic_int_exchange_and_add().
  g_atomic_int_add() is identical to g_atomic_int_exchange_and_add()
  since glib 2.30 where the latter has been deprecated.
- Use g_io_channel_read_chars() instead of g_io_channel_read() for
  reading binary data from an unbuffered GIO channel without encoding.

BUG=chromium-os:34103
TEST=emerge flimflam with glib 2.30.2 and 2.32.4

Change-Id: I6333472ba8071566de3d0eafd446bcc58f003062
Reviewed-on: https://gerrit.chromium.org/gerrit/32655
Commit-Ready: Ben Chan <benchan@chromium.org>
Reviewed-by: Ben Chan <benchan@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
diff --git a/plugins/modem.c b/plugins/modem.c
index 027df9c..4d70a69 100644
--- a/plugins/modem.c
+++ b/plugins/modem.c
@@ -127,16 +127,17 @@
 	struct modem_data *modem = user_data;
 	struct modem_cmd *cmd;
 	GSList *list;
-	gsize len;
-	GIOError err;
+	gsize len = 0;
+	GIOStatus status;
 
 	if (condition & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
 		return FALSE;
 
-	err = g_io_channel_read(channel, modem->buf + modem->offset,
-				sizeof(modem->buf) - modem->offset, &len);
-	if (err) {
-		if (err == G_IO_ERROR_AGAIN)
+	status = g_io_channel_read_chars(channel, modem->buf + modem->offset,
+					 sizeof(modem->buf) - modem->offset,
+					 &len, NULL);
+	if (status != G_IO_STATUS_NORMAL) {
+		if (status == G_IO_STATUS_AGAIN)
 			return TRUE;
 		return FALSE;
 	}
@@ -234,6 +235,12 @@
 
 	modem->channel = g_io_channel_unix_new(fd);
 	g_io_channel_set_close_on_unref(modem->channel, TRUE);
+	if (g_io_channel_set_encoding(modem->channel, NULL, NULL)
+		!= G_IO_STATUS_NORMAL) {
+		g_io_channel_unref(modem->channel);
+		return -1;
+	}
+	g_io_channel_set_buffered(modem->channel, FALSE);
 
 	modem->watch = g_io_add_watch(modem->channel,
 				G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
diff --git a/plugins/vpn.c b/plugins/vpn.c
index cbb642c..d6204d3 100644
--- a/plugins/vpn.c
+++ b/plugins/vpn.c
@@ -46,8 +46,7 @@
 
 #include <dbus/dbus.h>
 
-#include <glib/ghash.h>
-#include <glib/gprintf.h>
+#include <glib.h>
 
 #include <connman/provider.h>
 #include <connman/log.h>
diff --git a/src/log.c b/src/log.c
index 3651a4c..ff93a56 100644
--- a/src/log.c
+++ b/src/log.c
@@ -241,7 +241,8 @@
 	for (tagp = taglist; (tag = *tagp) != NULL; tagp++) {
 		struct _debugtag *dtag = NULL;
 		for (j = 0; j < G_N_ELEMENTS(debugtags); j++) {
-			if (g_strcasecmp(tag, debugtags[j].tagname) == 0) {
+			if (g_ascii_strcasecmp(tag, debugtags[j].tagname)
+			    == 0) {
 				dtag = &debugtags[j];
 				debugmask |= dtag->mask;
 				break;
diff --git a/src/notifier.c b/src/notifier.c
index ca56e06..610f285 100644
--- a/src/notifier.c
+++ b/src/notifier.c
@@ -137,7 +137,7 @@
 	_DBG_NOTIFIER("type %d", type);
 
 	if (istracked(type) &&
-	    g_atomic_int_exchange_and_add(&registered[type], 1) == 0)
+	    g_atomic_int_add(&registered[type], 1) == 0)
 		technology_registered(type);
 }
 
@@ -175,7 +175,7 @@
 	_DBG_NOTIFIER("type %d", type);
 
 	if (istracked(type) &&
-	    g_atomic_int_exchange_and_add(&enabled[type], 1) == 0) {
+	    g_atomic_int_add(&enabled[type], 1) == 0) {
 		technology_enabled(type, TRUE);
 	}
 }
@@ -202,7 +202,7 @@
 	_DBG_NOTIFIER("type %d", type);
 
 	if (istracked(type) &&
-	    g_atomic_int_exchange_and_add(&connected[type], 1) == 0) {
+	    g_atomic_int_add(&connected[type], 1) == 0) {
 		technology_connected(type);
 	}
 }
diff --git a/src/rfkill.c b/src/rfkill.c
index 0b9f59c..cc723f6 100644
--- a/src/rfkill.c
+++ b/src/rfkill.c
@@ -65,17 +65,18 @@
 	struct rfkill_event *event = (void *) buf;
 	char sysname[32];
 	connman_bool_t blocked;
-	gsize len;
-	GIOError err;
+	gsize len = 0;
+	GIOStatus status;
 
 	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
 		return FALSE;
 
 	memset(buf, 0, sizeof(buf));
 
-	err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf), &len);
-	if (err) {
-		if (err == G_IO_ERROR_AGAIN)
+	status = g_io_channel_read_chars(chan, (gchar *) buf,
+						sizeof(buf), &len, NULL);
+	if (status != G_IO_STATUS_NORMAL) {
+		if (status == G_IO_STATUS_AGAIN)
 			return TRUE;
 		return FALSE;
 	}
@@ -119,6 +120,12 @@
 
 	channel = g_io_channel_unix_new(fd);
 	g_io_channel_set_close_on_unref(channel, TRUE);
+	if (g_io_channel_set_encoding(channel, NULL, NULL)
+		!= G_IO_STATUS_NORMAL) {
+		g_io_channel_unref(channel);
+		return -1;
+	}
+	g_io_channel_set_buffered(channel, FALSE);
 
 	g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
 							rfkill_event, NULL);
diff --git a/src/rtnl.c b/src/rtnl.c
index a3b3784..cbd7e1d 100644
--- a/src/rtnl.c
+++ b/src/rtnl.c
@@ -778,17 +778,18 @@
 				GIOCondition cond, gpointer data)
 {
 	unsigned char buf[4096];
-	gsize len;
-	GIOError err;
+	gsize len = 0;
+	GIOStatus status;
 
 	if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
 		return FALSE;
 
 	memset(buf, 0, sizeof(buf));
 
-	err = g_io_channel_read(chan, (gchar *) buf, sizeof(buf), &len);
-	if (err) {
-		if (err == G_IO_ERROR_AGAIN)
+	status = g_io_channel_read_chars(chan, (gchar *) buf,
+						sizeof(buf), &len, NULL);
+	if (status != G_IO_STATUS_NORMAL) {
+		if (status == G_IO_STATUS_AGAIN)
 			return TRUE;
 		return FALSE;
 	}
@@ -1093,6 +1094,12 @@
 
 	channel = g_io_channel_unix_new(sk);
 	g_io_channel_set_close_on_unref(channel, TRUE);
+	if (g_io_channel_set_encoding(channel, NULL, NULL)
+		!= G_IO_STATUS_NORMAL) {
+		g_io_channel_unref(channel);
+		return -1;
+	}
+	g_io_channel_set_buffered(channel, FALSE);
 
 	g_io_add_watch(channel, G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR,
 							netlink_event, NULL);
diff --git a/src/service.c b/src/service.c
index f266f55..85d3f81 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1170,9 +1170,9 @@
 
 static enum connman_service_check_portal check_portal_from_str(const char *str)
 {
-	if (g_strcasecmp(str, "true") == 0)
+	if (g_ascii_strcasecmp(str, "true") == 0)
 		return CONNMAN_SERVICE_CHECK_PORTAL_TRUE;
-	if (g_strcasecmp(str, "false") == 0)
+	if (g_ascii_strcasecmp(str, "false") == 0)
 		return CONNMAN_SERVICE_CHECK_PORTAL_FALSE;
 	return CONNMAN_SERVICE_CHECK_PORTAL_AUTO;
 }
diff --git a/src/task.c b/src/task.c
index 726aa20..254243c 100644
--- a/src/task.c
+++ b/src/task.c
@@ -107,7 +107,7 @@
 	if (task == NULL)
 		return NULL;
 
-	counter = g_atomic_int_exchange_and_add(&task_counter, 1);
+	counter = g_atomic_int_add(&task_counter, 1);
 
 	task->path = g_strdup_printf("/task/%d", counter);
 	task->pid = -1;