diff src/util.c @ 7134:67f9b43c402a

[gaim-migrate @ 7701] I think this is the fifth Yahoo authentication method Gaim's seen in its days. Please tell me if anything stops working. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Fri, 03 Oct 2003 23:01:13 +0000
parents b003397b16fe
children d14e026611c0
line wrap: on
line diff
--- a/src/util.c	Fri Oct 03 21:57:44 2003 +0000
+++ b/src/util.c	Fri Oct 03 23:01:13 2003 +0000
@@ -1918,6 +1918,64 @@
 	}
 }
 
+char *
+gaim_url_decode(const char *str)
+{
+	static char buf[BUF_LEN];
+	int i, j = 0;
+	char *bum;
+
+	g_return_val_if_fail(str != NULL, NULL);
+
+	for (i = 0; i < strlen(str); i++) {
+		char hex[3];
+
+		if (str[i] != '%')
+			buf[j++] = str[i];
+		else {
+			strncpy(hex, str + ++i, 2);
+			hex[2] = '\0';
+
+			/* i is pointing to the start of the number */
+			i++;
+
+			/*
+			 * Now it's at the end and at the start of the for loop
+			 * will be at the next character.
+			 */
+			buf[j++] = strtol(hex, NULL, 16);
+		}
+	}
+
+	buf[j] = '\0';
+
+	if (!g_utf8_validate(buf, -1, (const char **)&bum))
+		*bum = '\0';
+
+	return buf;
+}
+
+char *
+gaim_url_encode(const char *str)
+{
+	static char buf[BUF_LEN];
+	int i, j = 0;
+
+	g_return_val_if_fail(str != NULL, NULL);
+
+	for (i = 0; i < strlen(str); i++) {
+		if (isalnum(str[i]))
+			buf[j++] = str[i];
+		else {
+			sprintf(buf + j, "%%%02x", (unsigned char)str[i]);
+			j += 3;
+		}
+	}
+
+	buf[j] = '\0';
+
+	return buf;
+}
 
 /**************************************************************************
  * UTF8 String Functions