diff lib/misc.c @ 944:5b681cba67b2

2008-01-24 Brian Masney <masneyb@gftp.org> * lib/gftp.h lib/rfc959.c lib/protocols.c lib/misc.c - don't store the structure from getaddrinfo()/gethostbyname() in the gftp_request structure. Instead, store the address of the current server in a separate pointer.
author masneyb
date Thu, 24 Jan 2008 23:31:26 +0000
parents 7b5aa0420fe2
children a490d94a5b8e
line wrap: on
line diff
--- a/lib/misc.c	Thu Jan 24 23:29:20 2008 +0000
+++ b/lib/misc.c	Thu Jan 24 23:31:26 2008 +0000
@@ -461,6 +461,8 @@
   while (templist != NULL)
     {
       tempfle = templist->data;
+      templist->data = NULL;
+
       gftp_file_destroy (tempfle, 1);
       templist = templist->next;
     }
@@ -488,6 +490,7 @@
   if (fle->destfile)
     newfle->destfile = g_strdup (fle->destfile);
 
+  newfle->user_data = NULL;
   return (newfle);
 }
 
@@ -591,41 +594,26 @@
     newreq->account = g_strdup (req->account);
   if (req->directory)
     newreq->directory = g_strdup (req->directory);
+  if (req->url_prefix)
+    newreq->url_prefix = g_strdup (req->url_prefix);
   newreq->port = req->port;
   newreq->use_proxy = req->use_proxy;
   newreq->logging_function = req->logging_function;
   newreq->ai_family = req->ai_family;
 
-  if (req->hostp)
+#if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
+  if (req->remote_addr == NULL)
     {
-#if defined (HAVE_GETADDRINFO) && defined (HAVE_GAI_STRERROR)
-      struct addrinfo *hostp = req->hostp;
-      struct addrinfo *newhostp = newreq->hostp;
-      
-      while (hostp != NULL)
-        {
-          newhostp = g_malloc (sizeof(struct addrinfo));
-          memcpy (newhostp, hostp, sizeof (struct addrinfo));
-          newhostp->ai_addr = g_malloc (sizeof (struct sockaddr));
-          memcpy(newhostp->ai_addr, hostp->ai_addr, sizeof (struct sockaddr));
-          if (hostp->ai_canonname)
-            newhostp->ai_canonname = strdup(hostp->ai_canonname);
-
-          if (req->current_hostp == hostp)
-            newreq->current_hostp = newhostp;
-
-          hostp = hostp->ai_next; newhostp = newhostp->ai_next;
-        }
-#else
-      newreq->hostp = g_malloc (sizeof (struct hostent));
-      memcpy(newreq->hostp, req->hostp, sizeof (struct hostent));
-      newreq->host = req->host;
-      newreq->curhost = req->curhost;
-#endif
+      newreq->remote_addr = NULL;
+      newreq->remote_addr_len = 0;
     }
   else
-    newreq->hostp = NULL;
-  newreq->free_hostp = 1;
+    {
+      newreq->remote_addr = g_malloc0 (req->remote_addr_len);
+      memcpy (newreq->remote_addr, req->remote_addr, req->remote_addr_len);
+      newreq->remote_addr_len = req->remote_addr_len;
+    }
+#endif
 
   gftp_copy_local_options (&newreq->local_options_vars, 
                            &newreq->local_options_hash,
@@ -942,8 +930,6 @@
 }
 
 
-#if !defined (HAVE_GETADDRINFO) || !defined (HAVE_GAI_STRERROR)
-
 struct hostent *
 r_gethostbyname (const char *name, struct hostent *result_buf, int *h_errnop)
 {
@@ -970,7 +956,6 @@
   return (hent);
 }
 
-#endif /* !HAVE_GETADDRINFO */
 
 struct servent *
 r_getservbyname (const char *name, const char *proto,
@@ -1027,7 +1012,7 @@
   if (slen % 3 > 0)
     num++;
 
-  newstr = g_malloc ((gulong) num * 4 + 1);
+  newstr = g_malloc0 ((gulong) num * 4 + 1);
   newstr[num * 4] = '\0';
   newpos = newstr;
 
@@ -1264,7 +1249,7 @@
   if (strcmp (password, "@EMAIL@") == 0)
     return (g_strdup (password));
 
-  newstr = g_malloc ((gulong) strlen (password) * 2 + 2);
+  newstr = g_malloc0 ((gulong) strlen (password) * 2 + 2);
   newpos = newstr;
   
   *newpos++ = '$';
@@ -1292,7 +1277,7 @@
     return (g_strdup (password));
 
   passwordpos = password + 1;
-  newstr = g_malloc ((gulong) strlen (passwordpos) / 2 + 1);
+  newstr = g_malloc0 ((gulong) strlen (passwordpos) / 2 + 1);
   newpos = newstr;
  
   error = 0;