[prev in list] [next in list] [prev in thread] [next in thread] 

List:       rpm-cvs
Subject:    [CVS] RPM: rpm/ CHANGES rpm/rpmio/ rpmwget.c
From:       "Jeff Johnson" <jbj () rpm5 ! org>
Date:       2008-06-30 14:18:21
Message-ID: 20080630141821.4F374348490 () rpm5 ! org
[Download RAW message or body]

  RPM Package Manager, CVS Repository
  http://rpm5.org/cvs/
  ____________________________________________________________________________

  Server: rpm5.org                         Name:   Jeff Johnson
  Root:   /v/rpm/cvs                       Email:  jbj@rpm5.org
  Module: rpm                              Date:   30-Jun-2008 16:18:21
  Branch: HEAD                             Handle: 2008063014181902

  Modified files:
    rpm                     CHANGES
    rpm/rpmio               rpmwget.c

  Log:
    - rpmwget: stub in a minimal (but functional) URI copy.

  Summary:
    Revision    Changes     Path
    1.2446      +1  -0      rpm/CHANGES
    1.4         +92 -11     rpm/rpmio/rpmwget.c
  ____________________________________________________________________________

  patch -p0 <<'@@ .'
  Index: rpm/CHANGES
  ============================================================================
  $ cvs diff -u -r1.2445 -r1.2446 CHANGES
  --- rpm/CHANGES	30 Jun 2008 00:06:26 -0000	1.2445
  +++ rpm/CHANGES	30 Jun 2008 14:18:19 -0000	1.2446
  @@ -1,5 +1,6 @@
   
   5.1.0 -> 5.2a0:
  +    - jbj: rpmwget: stub in a minimal (but functional) URI copy.
       - jbj: rpmwget: refactor options into a static structure.
       - jbj: fix: specspo lookup broke because of 2nd tagName call side-effect.
       - jbj: rpmwget: parse all wget options.
  @@ .
  patch -p0 <<'@@ .'
  Index: rpm/rpmio/rpmwget.c
  ============================================================================
  $ cvs diff -u -r1.3 -r1.4 rpmwget.c
  --- rpm/rpmio/rpmwget.c	30 Jun 2008 00:06:27 -0000	1.3
  +++ rpm/rpmio/rpmwget.c	30 Jun 2008 14:18:21 -0000	1.4
  @@ -8,7 +8,9 @@
   #define _KFB(n) (1U << (n))
   #define _WFB(n) (_KFB(n) | 0x40000000)
   
  +#ifdef	NOTYET	/* XXX XXX identify useful global bits first. */
   #define F_ISSET(_f, _F, _FLAG) (((_f) & ((_F##_FLAGS_##_FLAG) & ~0x40000000)) != \
_F##_FLAGS_NONE)  +#endif
   
   /**
    */
  @@ -100,6 +102,13 @@
   /**
    */
   struct rpmwget_s {
  +    char * b;
  +    size_t blen;
  +    const char * ifn;
  +    FD_t ifd;
  +    const char * ofn;
  +    FD_t ofd;
  +   
       /* --- Startup --- */
       const char * execute_cmd;		/*!< -e,--execute ... */
   
  @@ -125,10 +134,9 @@
       int limit_rate;			/*!<    --limit-rate ... */
       int bind_address;			/*!<    --bind-address ... */
       const char * prefer;		/*!<    --prefer-family ... */
  -
  -    const char * _Xwdl_output_file;	/*!< -O,--output-document ... */
  -    const char * _Xwdl_user;		/*!<    --user ... */
  -    const char * _Xwdl_password;	/*!<    --password ... */
  +    const char * document_file;		/*!< -O,--output-document ... */
  +    const char * user;			/*!<    --user ... */
  +    const char * password;		/*!<    --password ... */
   
       /* --- Directories --- */
       const char * dir_prefix;		/*!< -P,--directory-prefix ... */
  @@ -178,6 +186,7 @@
   
   /*@unchecked@*/
   static struct rpmwget_s __rpmwget = {
  +    .debug = -1,
       .verbose = -1,
       .http_ext = ".html"
   };
  @@ -185,6 +194,56 @@
   /*@unchecked@*/
   static rpmwget _rpmwget = &__rpmwget;
   
  +/*==============================================================*/
  +static int wgetCopy(rpmwget wget)
  +{
  +    const char * ibn;
  +    size_t nw, wlen = 0;
  +    size_t nr, rlen = 0;
  +    int rc = 1;		/* assume failure */
  +
  +    if ((ibn = strrchr(wget->ifn, '/')) != NULL)
  +	ibn++;
  +    else
  +	ibn = wget->ifn;
  +    if (*ibn == '\0')
  +	ibn = "index.html";
  +    wget->ofn = (wget->document_file ? wget->document_file : ibn);
  +
  +if (wget->debug < 0)
  +fprintf(stderr, "--> wgetCopy(%p) %s => %s\n", wget, wget->ifn, wget->ofn);
  +
  +    wget->ifd = Fopen(wget->ifn, "r.ufdio");
  +    if (wget->ifd == NULL || Ferror(wget->ifd))
  +	goto exit;
  +    wget->ofd = Fopen(wget->ofn, "o.ufdio");
  +    if (wget->ofd == NULL || Ferror(wget->ofd))
  +	goto exit;
  +
  +    while ((nr = Fread(wget->b, 1, wget->blen, wget->ifd)) > 0
  +	&& !Ferror(wget->ifd))
  +    {
  +	rlen += nr;
  +	if ((nw = Fwrite(wget->b, 1, nr, wget->ofd) != nr) || Ferror(wget->ofd))
  +	    break;
  +	wlen += nw;
  +    }
  +    if (nr == 0)
  +	rc = 0;
  +
  +exit:
  +    if (wget->ifd != NULL) {
  +	(void) Fclose(wget->ifd);
  +	wget->ifd = NULL;
  +    }
  +    if (wget->ofd != NULL) {
  +	(void) Fclose(wget->ofd);
  +	wget->ofd = NULL;
  +    }
  +    return rc;
  +}
  +
  +/*==============================================================*/
   /**
    */
   static void rpmwgetArgCallback(poptContext con,
  @@ -251,7 +310,7 @@
   	N_("set number of retries to NUMBER (0 unlimits)."), N_("NUMBER") },
     { "retry-connrefused", '\0', POPT_BIT_SET,	&rpmioWDLFlags, WDL_FLAGS_RETRYCONN,
   	N_("retry even if connection is refused."), NULL },
  -  { "output-document", 'O', POPT_ARG_STRING,	&__rpmwget._Xwdl_output_file, 0,
  +  { "output-document", 'O', POPT_ARG_STRING,	&__rpmwget.document_file, 0,
   	N_("write documents to FILE."), N_("FILE") },
     { "no-clobber", '\0', POPT_BIT_SET,	&rpmioWDLFlags, WDL_FLAGS_NOCLOBBER,
   	N_("skip downloads that would download to existing files."), NULL },
  @@ -308,9 +367,9 @@
   	N_("connect only to IPv6 addresses."), NULL },
     { "prefer-family", '\0', POPT_ARG_STRING,	&__rpmwget.prefer, 0,
   	N_("connect first to addresses of specified family, one of IPv6, IPv4, or \
                none."), N_("FAMILY") },
  -  { "user", '\0', POPT_ARG_STRING,	&__rpmwget._Xwdl_user, 0,
  +  { "user", '\0', POPT_ARG_STRING,	&__rpmwget.user, 0,
   	N_("set both ftp and http user to USER."), N_("USER") },
  -  { "password", '\0', POPT_ARG_STRING,	&__rpmwget._Xwdl_password, 0,
  +  { "password", '\0', POPT_ARG_STRING,	&__rpmwget.password, 0,
   	N_("set both ftp and http password to PASS."), N_("PASS") },
     POPT_TABLEEND
   };
  @@ -379,6 +438,9 @@
   	N_("use the POST method; send contents of FILE."), N_("FILE") },
     { "content-disposition", '\0', POPT_BIT_SET,	&rpmioHttpFlags, 0,
   	N_("honor the Content-Disposition header when choosing local file names \
(EXPERIMENTAL)."), NULL },  +/* XXX negated options */
  +  { "no-content-disposition", '\0', POPT_BIT_CLR|POPT_ARGFLAG_DOC_HIDDEN, \
&rpmioHttpFlags, 0,  +	N_("honor the Content-Disposition header when choosing local \
                file names (EXPERIMENTAL)."), NULL },
     { "auth-no-challenge", '\0', POPT_BIT_SET,	&rpmioHttpFlags, \
HTTP_FLAGS_NOCHALLENGE,  N_("Send Basic HTTP authentication information without first \
waiting for the server's challenge."), NULL },  POPT_TABLEEND
  @@ -538,16 +600,31 @@
   	/*@modifies __assert_program_name, _rpmrepo,
   		rpmGlobalMacroContext, fileSystem, internalState @*/
   {
  -    poptContext optCon = rpmioInit(argc, argv, optionsTable);
  +    rpmwget wget = _rpmwget;
  +    poptContext optCon;
       const char ** av = NULL;
       int ac;
  -    int rc = 1;		/* assume failure. */
  +    int rc = 0;		/* assume success. */
  +    int xx;
       int i;
   
   /*@-observertrans -readonlytrans @*/
  -    __progname = "rpmgenpkglist";
  +    __progname = "rpmwget";
   /*@=observertrans =readonlytrans @*/
   
  +    wget->blen = 16 * BUFSIZ;
  +    wget->b = xmalloc(wget->blen);
  +    wget->b[0] = '\0';
  +
  +    optCon = rpmioInit(argc, argv, optionsTable);
  +    if (wget->debug < 0) {
  +	fprintf(stderr, "==> %s", __progname);
  +	for (i = 1; argv[i] != NULL; i++) {
  +	    fprintf(stderr, " %s", argv[i]);
  +	}
  +	fprintf(stderr, "\n");
  +    }
  +
       av = poptGetArgs(optCon);
       if (av == NULL || av[0] == NULL) {
   	poptPrintUsage(optCon, stderr, 0);
  @@ -557,10 +634,14 @@
   
       if (av != NULL)
       for (i = 0; i < ac; i++) {
  +	wget->ifn = av[i];
  +	if ((xx = wgetCopy(_rpmwget)) != 0)
  +	    rc = 256;
       }
  -    rc = 0;
   
   exit:
  +    wget->b = _free(wget->b);
  +
       optCon = rpmioFini(optCon);
   
       return rc;
  @@ .
______________________________________________________________________
RPM Package Manager                                    http://rpm5.org
CVS Sources Repository                                rpm-cvs@rpm5.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic