changeset 5426:8d8bf0d31a23

[gaim-migrate @ 5805] i'm cleaning out my tree 1. new tobase64 function that works better 2. new date/time stamp parsing stuff for jabber 3. other misc stuff, not deserving of specific mention committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 18 May 2003 05:45:18 +0000
parents 73bde657e212
children 04e1e40b99b0
files VERSION configure.in src/protocols/jabber/jabber.c src/protocols/jabber/libxode.h src/proxy.c src/util.c src/util.h
diffstat 7 files changed, 112 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/VERSION	Sun May 18 05:00:12 2003 +0000
+++ b/VERSION	Sun May 18 05:45:18 2003 +0000
@@ -1,1 +1,1 @@
-0.63cvs
+0.64cvs
--- a/configure.in	Sun May 18 05:00:12 2003 +0000
+++ b/configure.in	Sun May 18 05:45:18 2003 +0000
@@ -1,7 +1,7 @@
 dnl Process this file with autoconf to produce a configure script.
 AC_INIT(src/main.c)
 AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE([gaim], [0.63])
+AM_INIT_AUTOMAKE([gaim], [0.64cvs])
 
 
 
--- a/src/protocols/jabber/jabber.c	Sun May 18 05:00:12 2003 +0000
+++ b/src/protocols/jabber/jabber.c	Sun May 18 05:45:18 2003 +0000
@@ -1244,40 +1244,72 @@
 }
 
 
-static time_t iso8601_to_time(char *timestamp)
+static time_t str_to_time(char *timestamp)
 {
-	struct tm t;
-	time_t retval = 0;
-	char tz[6] = "";
-	localtime_r(NULL, &t);
-
-	if(sscanf(timestamp, "%04d%02d%02dT%02d:%02d:%02d%5s",
-		&t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec, tz))
-	{
-		t.tm_year -= 1900;
-		t.tm_mon -= 1;
-		retval = mktime(&t);
-#		ifdef HAVE_TM_GMTOFF
-			retval += t.tm_gmtoff;
-#		else
-#		        ifdef HAVE_TIMEZONE
-				tzset();	/* making sure */
-				retval -= timezone;
-#		        endif
-#		endif
-
-		if(tz[0] == '+' || tz[0] == '-') {
-			int hr, min;
-			if(sscanf(tz+1, "%2d%2d", &hr, &min)) {
-				if(tz[0] == '+')
-					retval -= (hr*60 + min)*60;
-				else
-					retval += (hr*60 + min)*60;
+    struct tm t;
+    time_t retval = 0;
+	char buf[32];
+	char *c;
+	int tzoff = 0;
+
+	time(&retval);
+	localtime_r(&retval, &t);
+
+	snprintf(buf, sizeof(buf), "%s", timestamp);
+	c = buf;
+
+	/* 4 digit year */
+	if(!sscanf(c, "%04d", &t.tm_year)) return 0;
+	c+=4;
+	if(*c == '-')
+		c++;
+
+	t.tm_year -= 1900;
+
+	/* 2 digit month */
+	if(!sscanf(c, "%02d", &t.tm_mon)) return 0;
+	c+=2;
+	if(*c == '-')
+		c++;
+
+	t.tm_mon -= 1;
+
+	/* 2 digit day */
+	if(!sscanf(c, "%02d", &t.tm_mday)) return 0;
+	c+=2;
+
+	if(*c == 'T') { /* we have more than a date, keep going */
+		c++; /* skip the "T" */
+
+		/* 2 digit hour */
+		if(sscanf(c, "%02d:%02d:%02d", &t.tm_hour, &t.tm_min, &t.tm_sec)) {
+			int tzhrs, tzmins;
+			c+=8;
+			if(*c == '.') /* dealing with precision we don't care about */
+				c += 4;
+
+			if((*c == '+' || *c == '-') &&
+					sscanf(c+1, "%02d:%02d", &tzhrs, &tzmins)) {
+				tzoff = tzhrs*60*60 + tzmins*60;
+				if(*c == '+')
+					tzoff *= -1;
 			}
+
+#ifdef HAVE_TM_GMTOFF
+				tzoff += t.tm_gmtoff;
+#else
+#	ifdef HAVE_TIMEZONE
+				tzset();    /* making sure */
+				tzoff -= timezone;
+#	endif
+#endif
 		}
 	}
-
-	return retval;
+	retval = mktime(&t);
+
+	retval += tzoff;
+
+    return retval;
 }
 
 static void jabber_handlemessage(gjconn gjc, jpacket p)
@@ -1302,7 +1334,8 @@
 	while(y) {
 		if(NSCHECK(y, NS_DELAY)) {
 			char *timestamp = xmlnode_get_attrib(y, "stamp");
-			time_sent = iso8601_to_time(timestamp);
+			if(timestamp)
+				time_sent = str_to_time(timestamp);
 		} else if(NSCHECK(y, "jabber:x:event")) {
 			if(xmlnode_get_tag(y, "composing"))
 				typing = TRUE;
@@ -1856,7 +1889,7 @@
 		x = xmlnode_get_nextsibling(x);
 	}
 
-	x = jutil_presnew(0, NULL, "Online");
+	x = xmlnode_new_tag("presence");
 	gjab_send(gjc, x);
 	xmlnode_free(x);
 }
--- a/src/protocols/jabber/libxode.h	Sun May 18 05:00:12 2003 +0000
+++ b/src/protocols/jabber/libxode.h	Sun May 18 05:45:18 2003 +0000
@@ -194,7 +194,7 @@
 int sha_hash(int *data, int *hash);
 int sha_init(int *hash);
 char *shahash(char *str);	/* NOT THREAD SAFE */
-void shahash_r(const char* str, char hashbuf[40]); /* USE ME */
+void shahash_r(const char* str, char hashbuf[41]); /* USE ME */
 
 int strprintsha(char *dest, int *hashval);
 
--- a/src/proxy.c	Sun May 18 05:00:12 2003 +0000
+++ b/src/proxy.c	Sun May 18 05:45:18 2003 +0000
@@ -785,7 +785,7 @@
 	if (phb->gpi->proxyuser) {
 		char *t1, *t2;
 		t1 = g_strdup_printf("%s:%s", phb->gpi->proxyuser, phb->gpi->proxypass);
-		t2 = tobase64(t1);
+		t2 = tobase64(t1, -1);
 		g_free(t1);
 		g_return_if_fail(request_len < sizeof(request));
 		request_len += g_snprintf(request + request_len, sizeof(request) - request_len, "Proxy-Authorization: Basic %s\r\n", t2);
--- a/src/util.c	Sun May 18 05:00:12 2003 +0000
+++ b/src/util.c	Sun May 18 05:45:18 2003 +0000
@@ -350,59 +350,52 @@
 	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
 	"0123456789+/";
 
-/* XXX Find bug */
-char *tobase64(const char *text)
+/* This was borrowed from the Kame source, and then tweaked to our needs */
+char *tobase64(const unsigned char *buf, size_t len)
 {
-	char *out = NULL;
-	const char *c;
-	unsigned int tmp = 0;
-	int len = 0, n = 0;
+	char *s, *rv;
+	unsigned tmp;
 
-	c = text;
+	if(len < 0)
+		len = strlen(buf);
+
+	s = g_malloc((4 * (len + 1)) / 3 + 1);
 
-	while (*c) {
-		tmp = tmp << 8;
-		tmp += *c;
-		n++;
-
-		if (n == 3) {
-			out = g_realloc(out, len + 4);
-			out[len] = alphabet[(tmp >> 18) & 0x3f];
-			out[len + 1] = alphabet[(tmp >> 12) & 0x3f];
-			out[len + 2] = alphabet[(tmp >> 6) & 0x3f];
-			out[len + 3] = alphabet[tmp & 0x3f];
-			len += 4;
-			tmp = 0;
-			n = 0;
-		}
-		c++;
+	rv = s;
+	while (len >= 3) {
+		tmp = buf[0] << 16 | buf[1] << 8 | buf[2];
+		s[0] = alphabet[tmp >> 18];
+		s[1] = alphabet[(tmp >> 12) & 077];
+		s[2] = alphabet[(tmp >> 6) & 077];
+		s[3] = alphabet[tmp & 077];
+		len -= 3;
+		buf += 3;
+		s += 4;
 	}
-	switch (n) {
 
-	case 2:
-		tmp <<= 8;
-		out = g_realloc(out, len + 5);
-		out[len] = alphabet[(tmp >> 18) & 0x3f];
-		out[len + 1] = alphabet[(tmp >> 12) & 0x3f];
-		out[len + 2] = alphabet[(tmp >> 6) & 0x3f];
-		out[len + 3] = '=';
-		out[len + 4] = 0;
-		break;
-	case 1:
-		tmp <<= 16;
-		out = g_realloc(out, len + 5);
-		out[len] = alphabet[(tmp >> 18) & 0x3f];
-		out[len + 1] = alphabet[(tmp >> 12) & 0x3f];
-		out[len + 2] = '=';
-		out[len + 3] = '=';
-		out[len + 4] = 0;
-		break;
-	case 0:
-		out = g_realloc(out, len + 1);
-		out[len] = 0;
-		break;
+	/* RFC 1521 enumerates these three possibilities... */
+	switch(len) {
+		case 2:
+			tmp = buf[0] << 16 | buf[1] << 8;
+			s[0] = alphabet[(tmp >> 18) & 077];
+			s[1] = alphabet[(tmp >> 12) & 077];
+			s[2] = alphabet[(tmp >> 6) & 077];
+			s[3] = '=';
+			s[4] = '\0';
+			break;
+		case 1:
+			tmp = buf[0] << 16;
+			s[0] = alphabet[(tmp >> 18) & 077];
+			s[1] = alphabet[(tmp >> 12) & 077];
+			s[2] = s[3] = '=';
+			s[4] = '\0';
+			break;
+		case 0:
+			s[0] = '\0';
+			break;
 	}
-	return out;
+
+	return rv;
 }
 
 
--- a/src/util.h	Sun May 18 05:00:12 2003 +0000
+++ b/src/util.h	Sun May 18 05:45:18 2003 +0000
@@ -43,13 +43,14 @@
 /**
  * Converts a string to its base-64 equivalent.
  *
- * @param str The string to convert.
+ * @param buf The data to convert.
+ * @param len The length of the data, or -1 if it's a NULL-terminated string.
  *
  * @return The base-64 version of @a str.
  *
  * @see frombase64()
  */
-char *tobase64(const char *str);
+char *tobase64(const unsigned char *buf, size_t len);
 
 /**
  * Converts a string back from its base-64 equivalent.