From:	SMTP%"VMSGopher-L@trln.lib.unc.edu"  9-APR-1994 10:02:19.65
To:	EVERHART
CC:	
Subj:	Re: Problem with log file from "VMSGOPHER SERVER 1.2VMS-1 TRLN_K"

X-Listname: Gopher for VMS implementation and testing
    <VMSGopher-L@trln.lib.unc.edu>
Warnings-To: <>
Errors-To: postmaster@trln.lib.unc.edu
Sender: postmaster@trln.lib.unc.edu
Date: Fri, 08 Apr 1994 13:33:42 -0700
From: Stan_Peters@byu.edu (Stan Peters)
Reply-To: VMSGopher-L@trln.lib.unc.edu
Subject: Re: Problem with log file from "VMSGOPHER SERVER 1.2VMS-1 TRLN_K"
X-Sender: peterss@acs1.byu.edu
To: VMSGopher-L@trln.lib.unc.edu, Chris Pierce <pierccm@WKUVX1.WKU.EDU>
Cc: JLW@psulias.psu.edu
Message-Id: <01HAXN2MMHLER5NEX0@yvax.byu.edu>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7BIT

At 11:06 AM 4/8/94 -0400, J.Lance Wilkinson, 814-865-1818 wrote:
>         The TRLN_K version has a patch recommended by Stan Peters a few
>         months ago which I agreed with when Dennis was getting ready to
>         package up his _K revision and asked me, but admittedly I have
>         never tried (blush; I should have known never to approve of code
>         I haven't tried but just eyeballed ;-{).  I know that Rollover:
>         Weekly works, since that's what I've been using here since I
>         first implemented the Rollover: facility.  You might try that as
>         a workaround, but somebody with the TRLN_K revision may have to
>         just step through the code under the Debugger to see just exactly
>         what's wrong here.  It's probably something really silly and so
>         obvious that everybody who's looked at the code so far just skipped
>         past it.

I guess I better speak up because my integrity is being called into
question. ;-)

What I found and was fixed in _K was a TYPO. (For the case of rollover:
never, GDCsetCaching was being called instead of GDCsetRollover). This fix
has (apparently) uncovered another long standing bug!

What has just now been uncovered is a LOGIC flaw in the same area of code.
You're gonna get a chuckle when you see the flaw. There are a series of
'if' tests that (are intended to) check to see what type of rollover is
wanted. These 'if's are (erroneously) written as a series of independent
tests. They should instead be written as a single, long,

        if - else if - ... - else if - else

statment. Or as a switch statement.

As the code is now written, what is happening is that the final if test says

        if rollover in config file says "weekly"
        then
           set rollover to weekly
        else
           set rollover to never

This OVERRIDES all the previous tests for daily, monthly, hourly, or
annually. So, if you set WEEKLY in your config file, you get WEEKLY
behaviour. If you set anything else, you get NEVER behavior. (See why
WEEKLY is working for you, Lance?)

It was intended that the final 'else' catch the case of none of the
previous if tests evaluating to true. But in fact, as written, the else
only matches up with the 'weekly' test.

The reason the old code (with the typo) worked is because (now get this!!)
if you specified rollover: never in your config file, NONE of the if tests
matched, so rollover was never set. But since rollover is initialized to 0
(zero), which is what ROLLOVER_NEVER just happens to be (see
GOPHERDCONF.H), the net effect is that rollover gets set (actually left as)
'never'. If you specified something other than weekly or never, the
appropriate value for rollover that was set by the previous if tests didn't
get clobbered by the "else" clause (because that clause went and clobbered
the Caching setting).

Of course, there was also the side effect that whenever rollover was
anything other than 'weekly', GDCsetCaching was being called and Caching
set to 0. But since the VMS gopher ignores caching, this had no visible
side effects.

-Stan

P.S. So the easiest solution would appear to be to change

     else if (strcasecmp(token, "Rollover")==0) {
            if (strncasecmp(rest, "DAILY", 5)==0)
                GDCsetRollover(gdc,ROLLOVER_DAILY);
            if (strncasecmp(rest, "MONTHLY", 7)==0)
                GDCsetRollover(gdc,ROLLOVER_MONTHLY);
            if (strncasecmp(rest, "HOURLY", 6)==0)
                GDCsetRollover(gdc,ROLLOVER_HOURLY);
            if (strncasecmp(rest, "ANNUALLY", 8)==0)
                GDCsetRollover(gdc,ROLLOVER_ANNUALLY);
            if (strncasecmp(rest, "WEEKLY", 6)==0)
                GDCsetRollover(gdc,ROLLOVER_WEEKLY);
            else
                GDCsetRollover(gdc, ROLLOVER_NEVER);
to read

     else if (strcasecmp(token, "Rollover")==0) {
            if (strncasecmp(rest, "DAILY", 5)==0)
                GDCsetRollover(gdc,ROLLOVER_DAILY);
            else if (strncasecmp(rest, "MONTHLY", 7)==0)
                GDCsetRollover(gdc,ROLLOVER_MONTHLY);
            else if (strncasecmp(rest, "HOURLY", 6)==0)
                GDCsetRollover(gdc,ROLLOVER_HOURLY);
            else if (strncasecmp(rest, "ANNUALLY", 8)==0)
                GDCsetRollover(gdc,ROLLOVER_ANNUALLY);
            else if (strncasecmp(rest, "WEEKLY", 6)==0)
                GDCsetRollover(gdc,ROLLOVER_WEEKLY);
            else
                GDCsetRollover(gdc, ROLLOVER_NEVER);

eg, add 'else ' in front of the last four 'if' tokens.

P.P.S. Having uncovered the reason for and solved a bug that wasn't really
of my doing, does this exonerate me?

--
  Stan Peters                  Manager, Academic Computing Services
  Stan_Peters@byu.edu          Brigham Young University - Provo, UT


