[BACK]Return to fetch.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ftp

Diff for /src/usr.bin/ftp/fetch.c between version 1.41 and 1.42

version 1.41, 2002/12/19 01:52:09 version 1.42, 2002/12/30 23:04:42
Line 73 
Line 73 
 static int      url_get(const char *, const char *, const char *);  static int      url_get(const char *, const char *, const char *);
 void            aborthttp(int);  void            aborthttp(int);
 void            abortfile(int);  void            abortfile(int);
 char            hextochar(const char *);  char            hextochar(const char *);
 char            *urldecode(const char *);  char            *urldecode(const char *);
   
 #define FTP_URL         "ftp://"        /* ftp URL prefix */  #define FTP_URL         "ftp://"        /* ftp URL prefix */
 #define HTTP_URL        "http://"       /* http URL prefix */  #define HTTP_URL        "http://"       /* http URL prefix */
Line 190 
Line 190 
                 }                  }
                 *--path = '/';                  /* add / back to real path */                  *--path = '/';                  /* add / back to real path */
                 path = strchr(host, '/');       /* remove trailing / on host */                  path = strchr(host, '/');       /* remove trailing / on host */
                 if (! EMPTYSTRING(path))                  if (!EMPTYSTRING(path))
                         *path++ = '\0';                          *path++ = '\0';
                 path = line;                  path = line;
         }          }
Line 227 
Line 227 
                         goto cleanup_url_get;                          goto cleanup_url_get;
                 }                  }
                 oldintr = signal(SIGINT, abortfile);                  oldintr = signal(SIGINT, abortfile);
   
                 bytes = 0;                  bytes = 0;
                 hashbytes = mark;                  hashbytes = mark;
                 progressmeter(-1);                  progressmeter(-1);
   
                 if ((buf = malloc(4096)) == NULL)                  if ((buf = malloc(4096)) == NULL)
                         errx(1, "Can't allocate memory for transfer buffer\n");                          errx(1, "Can't allocate memory for transfer buffer\n");
   
                 /* Finally, suck down the file. */                  /* Finally, suck down the file. */
                 i = 0;                  i = 0;
                 while ((len = read(s, buf, 4096)) > 0) {                  while ((len = read(s, buf, 4096)) > 0) {
Line 269 
Line 269 
                 if (verbose)                  if (verbose)
                         fputs("Successfully retrieved file.\n", ttyout);                          fputs("Successfully retrieved file.\n", ttyout);
                 (void)signal(SIGINT, oldintr);                  (void)signal(SIGINT, oldintr);
   
                 rval = 0;                  rval = 0;
                 goto cleanup_url_get;                  goto cleanup_url_get;
         }          }
Line 377 
Line 377 
                          * send them the port number.                           * send them the port number.
                          */                           */
                         if (port && strcmp(port, "80") != 0)                          if (port && strcmp(port, "80") != 0)
                                 fprintf(fin, "GET /%s HTTP/1.0\r\nHost: [%s]:%s\r\n%s\r\n\r\n",                                  fprintf(fin,
                                       "GET /%s HTTP/1.0\r\nHost: [%s]:%s\r\n%s\r\n\r\n",
                                     path, h, port, HTTP_USER_AGENT);                                      path, h, port, HTTP_USER_AGENT);
                         else                          else
                                 fprintf(fin, "GET /%s HTTP/1.0\r\nHost: [%s]\r\n%s\r\n\r\n",                                  fprintf(fin,
                                       "GET /%s HTTP/1.0\r\nHost: [%s]\r\n%s\r\n\r\n",
                                     path, h, HTTP_USER_AGENT);                                      path, h, HTTP_USER_AGENT);
                         free(h);                          free(h);
                 } else {                  } else {
                         if (port && strcmp(port, "80") != 0)                          if (port && strcmp(port, "80") != 0)
                                 fprintf(fin, "GET /%s HTTP/1.0\r\nHost: %s:%s\r\n%s\r\n\r\n",                                  fprintf(fin,
                                       "GET /%s HTTP/1.0\r\nHost: %s:%s\r\n%s\r\n\r\n",
                                     path, host, port, HTTP_USER_AGENT);                                      path, host, port, HTTP_USER_AGENT);
                         else                          else
                                 fprintf(fin, "GET /%s HTTP/1.0\r\nHost: %s\r\n%s\r\n\r\n",                                  fprintf(fin,
                                       "GET /%s HTTP/1.0\r\nHost: %s\r\n%s\r\n\r\n",
                                     path, host, HTTP_USER_AGENT);                                      path, host, HTTP_USER_AGENT);
                 }                  }
         }          }
Line 681 
Line 685 
                                 host = passend + 1;                                  host = passend + 1;
                                 *userend = *passend = '\0';                                  *userend = *passend = '\0';
                                 passagain = strchr(host, '@');                                  passagain = strchr(host, '@');
                                 if (strchr(pass, '@') != NULL ||                                  if (strchr(pass, '@') != NULL ||
                                     (passagain != NULL && passagain < dir)) {                                      (passagain != NULL && passagain < dir)) {
                                         warnx(at_encoding_warning);                                          warnx(at_encoding_warning);
                                         goto bad_ftp_url;                                          goto bad_ftp_url;
                                 }                                  }
   
                                 if (EMPTYSTRING(user) || EMPTYSTRING(pass)) {                                  if (EMPTYSTRING(user) || EMPTYSTRING(pass)) {
 bad_ftp_url:  bad_ftp_url:
Line 754 
Line 758 
                 /*                  /*
                  * Extract the file and (if present) directory name.                   * Extract the file and (if present) directory name.
                  */                   */
                 if (! EMPTYSTRING(dir)) {                  if (!EMPTYSTRING(dir)) {
                         cp = strrchr(dir, '/');                          cp = strrchr(dir, '/');
                         if (cp != NULL) {                          if (cp != NULL) {
                                 *cp++ = '\0';                                  *cp++ = '\0';
Line 765 
Line 769 
                         }                          }
                 }                  }
                 if (debug)                  if (debug)
                         fprintf(ttyout, "user %s:%s host %s port %s dir %s file %s\n",                          fprintf(ttyout,
                               "user %s:%s host %s port %s dir %s file %s\n",
                             user, pass, host, portnum, dir, file);                              user, pass, host, portnum, dir, file);
   
                 /*                  /*
Line 781 
Line 786 
                         xargv[1] = host;                          xargv[1] = host;
                         xargv[2] = NULL;                          xargv[2] = NULL;
                         xargc = 2;                          xargc = 2;
                         if (! EMPTYSTRING(portnum)) {                          if (!EMPTYSTRING(portnum)) {
                                 xargv[2] = portnum;                                  xargv[2] = portnum;
                                 xargv[3] = NULL;                                  xargv[3] = NULL;
                                 xargc = 3;                                  xargc = 3;
Line 807 
Line 812 
                 xargv[1] = "/";                  xargv[1] = "/";
                 xargv[2] = NULL;                  xargv[2] = NULL;
                 cd(2, xargv);                  cd(2, xargv);
                 if (! dirchange) {                  if (!dirchange) {
                         rval = argpos + 1;                          rval = argpos + 1;
                         continue;                          continue;
                 }                  }
   
                 dirhasglob = filehasglob = 0;                  dirhasglob = filehasglob = 0;
                 if (doglob) {                  if (doglob) {
                         if (! EMPTYSTRING(dir) &&                          if (!EMPTYSTRING(dir) &&
                             strpbrk(dir, "*?[]{}") != NULL)                              strpbrk(dir, "*?[]{}") != NULL)
                                 dirhasglob = 1;                                  dirhasglob = 1;
                         if (! EMPTYSTRING(file) &&                          if (!EMPTYSTRING(file) &&
                             strpbrk(file, "*?[]{}") != NULL)                              strpbrk(file, "*?[]{}") != NULL)
                                 filehasglob = 1;                                  filehasglob = 1;
                 }                  }
   
                 /* Change directories, if necessary. */                  /* Change directories, if necessary. */
                 if (! EMPTYSTRING(dir) && !dirhasglob) {                  if (!EMPTYSTRING(dir) && !dirhasglob) {
                         xargv[0] = "cd";                          xargv[0] = "cd";
                         xargv[1] = dir;                          xargv[1] = dir;
                         xargv[2] = NULL;                          xargv[2] = NULL;
                         cd(2, xargv);                          cd(2, xargv);
                         if (! dirchange) {                          if (!dirchange) {
                                 rval = argpos + 1;                                  rval = argpos + 1;
                                 continue;                                  continue;
                         }                          }
Line 878 
Line 883 
 }  }
   
 char *  char *
 urldecode(str)  urldecode(str)
         const char *str;          const char *str;
 {  {
         char *ret;          char *ret;
         char c;          char c;
         int i, reallen;          int i, reallen;
   
         if (str == NULL)          if (str == NULL)
                 return NULL;                  return NULL;
         if ((ret = malloc(strlen(str)+1)) == NULL)          if ((ret = malloc(strlen(str)+1)) == NULL)
                 err(1, "Can't allocate memory for URL decoding");                  err(1, "Can't allocate memory for URL decoding");

Legend:
Removed from v.1.41  
changed lines
  Added in v.1.42