diff lib/misc.c @ 168:c505d9ba9d53

2003-6-6 Brian Masney <masneyb@gftp.org> * lib/gftp.h - if USE_SSL is defined, include the OpenSSL headers. Added read_function, write_function and post_connect function pointers to gftp_request structure. Added SSL object to gftp_request structure if USE_SSL is defined. Added protocol number and init function declarations for the HTTPS protocol * lib/options.h - added HTTPS to the list of supported protocols * lib/protocols.c lib/cache.c lib/rfc2068.c lib/rfc959.c lib/sshv2.c - renamed gftp_read(), gftp_write() and gftp_set_sockblocking() to gftp_fd_read(), gftp_fd_write() and gftp_fd_set_sockblocking() respectively * lib/bookmark.c lib/local.c * lib/misc.c lib/rfc2068.c - moved base64_encode() to misc.c * lib/protocols.c - improved parsing of URLs. Rather than calling gftp_read() or gftp_write() directly, call the read_function or write_function that is set in the request structure. Expanded tabs to spaces. Cleanup for parsing of timestamps. In gftp_connect_server(), if a post_connect function pointer is set, call it after we are connected to the server. Improvements to gftp_get_line (). * lib/httpcommon.h lib/rfc2068.c - moved rfc2068_params structure to httpcommon.h. Fix for chunked file transfers, they were not handled at all before. Made the I/O calls a little more generic so that we can read from either a socket or a SSL connection. * lib/sslcommon.c - added generic SSL layer * lib/https.c - added support for the HTTPS protocol. It piggy backs off of the existing HTTP support and uses the generic SSL layer * src/gtk/bookmarks.c src/gtk/chmod_dialog.c src/gtk/gftp-gtk.c src/gtk/menu-items.c src/gtk/misc-gtk.c src/gtk/options_dialog.c src/gtk/view_dialog.c - set the window icon name to the gFTP <version> * configure.in - added lib back to SUBDIRS (oops) * lib/Makefile.am - added https.c, sslcommon.c and httpcommon.h
author masneyb
date Sun, 08 Jun 2003 15:04:40 +0000
parents 12a043d992a1
children 4c288d05b26a
line wrap: on
line diff
--- a/lib/misc.c	Wed May 28 18:37:28 2003 +0000
+++ b/lib/misc.c	Sun Jun 08 15:04:40 2003 +0000
@@ -529,10 +529,8 @@
   gftp_transfer * tdata;
 
   tdata = g_malloc0 (sizeof (*tdata));
-/* FIXME
-  tdata->statmutex = G_STATIC_MUTEX_INIT;
-  tdata->structmutex = G_STATIC_MUTEX_INIT;
-*/
+  g_static_mutex_init (&tdata->statmutex);
+  g_static_mutex_init (&tdata->structmutex);
   return (tdata);
 }
 
@@ -989,3 +987,51 @@
   return (sent);
 }
 
+
+char *
+base64_encode (char *str)
+{
+
+/* The standard to Base64 encoding can be found in RFC2045 */
+
+  char *newstr, *newpos, *fillpos, *pos;
+  unsigned char table[64], encode[3];
+  int i, num;
+
+  for (i = 0; i < 26; i++)
+    {
+      table[i] = 'A' + i;
+      table[i + 26] = 'a' + i;
+    }
+
+  for (i = 0; i < 10; i++)
+    table[i + 52] = '0' + i;
+
+  table[62] = '+';
+  table[63] = '-';
+
+  num = strlen (str) / 3;
+  if (strlen (str) % 3 > 0)
+    num++;
+  newstr = g_malloc (num * 4 + 1);
+  newstr[num * 4] = '\0';
+  newpos = newstr;
+
+  pos = str;
+  while (*pos != '\0')
+    {
+      memset (encode, 0, sizeof (encode));
+      for (i = 0; i < 3 && *pos != '\0'; i++)
+	encode[i] = *pos++;
+
+      fillpos = newpos;
+      *newpos++ = table[encode[0] >> 2];
+      *newpos++ = table[(encode[0] & 3) << 4 | encode[1] >> 4];
+      *newpos++ = table[(encode[1] & 0xF) << 2 | encode[2] >> 6];
+      *newpos++ = table[encode[2] & 0x3F];
+      while (i < 3)
+	fillpos[++i] = '=';
+    }
+  return (newstr);
+}
+