Forums
You may post here on any subjects related to this site or the software therein.
(Most everything on this site is tied into the forums so that you may leave or post comments about it.)
RE:cfx_secfile
From: Lewis Sellers Date: January 28 2003 5:24 PM
| | Done. Quick enough.
Mind you I just added an "EOL" parm to the tag and I DON'T have a copy of ColdFusion installed to actually check if it works.
Basically EOL can be any of the following: "Windows", "Unix", "Macintosh" or "CRLF", "LF", "LFLF".
If it works... well, I'll just email it to you as you left an email address. If it works I'll properly package it up later next week after this web site settles on it's new server.
--min
cfx_secfile
From: Bob Jacoby Date: March 24 2003 11:48 AM
| | cfx_secfile converts end of line characters to windows style upon writes. cffile doesn't. Since cfx_secfile is supposed to mirror the functionality of cffile I consider this a bug in cfx_secfile. For most cases this isn't a big deal, but for some it is (hashing for example). Is there a fix in the works? I havn't coded in C++ so can't fix this myself.
Here's a cut and paste from a test page I wrote to show this in greater detail. It uses a login/password of test/test. You will need to create this login/password for your cfx_secfile and switch the dir variable in the below code if you want to run it in your local environment:
Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Testing the cfx_secfile tag</title>
</head>
<body>
<cfoutput>
<b>Intro</b>
<br/>
This page tests the functionality of the cfx_secfile tag for the read and write actions by comparing it to in-memory
representation of the string to be written and the actions of cffile, which cfx_secfile is supposed to mirror.
The test utilizes the CF hash function to uniquely identify a string (which includes all "hidden" characters such
whitespace).
<ol>
<cfset dir = "c:devenvapache2htdocs">
<li>Set a variable, stringA, to a test string 'A', that spans multiple lines.</li>
<cfset stringA="What would you do for a">
<cfset stringA=stringA & "
klondike bar?">
<i><pre>stringA=#stringA#</pre></i>
<li>Take a hash of string 'A'. This is the control hash value. For a string 'B' to be considered the same as 'A' the hash of 'B' must be the same.</li>
<i><pre>stringA Hash: #hash(stringA)#</PRE></i>
<li>Use cfx_secfile to write the variable, stringA, to a file</li>
<cfx_secfile USERNAME="test"
PASSWORD="test"
action="WRITE"
file="#dir#cfxwrite.xml"
output="#stringA#"
addnewline="No">
<i><pre>File written: #dir#cfxwrite.xml</pre></i>
<li>Use cfx_secfile to read the file written by cfx_secfile back to a variable</li>
<cfx_secfile USERNAME="test"
PASSWORD="test"
action="read"
file="#dir#cfxwrite.xml"
variable="CFXReadOfCFXWrite" >
<i><pre>variable read=#CFXReadOfCFXWrite#</pre></i>
<li>Take a hash of the read in variable and compare to the hash of string 'A'. Note: The hashes are different</li>
<i><PRE>Hash of CFXReadOfCFXWrite=#hash(CFXReadOfCFXWrite)# is unequal to #hash(stringA)#</PRE></i>
<li>Use cffile to read the file written by cfx_secfile in to a variable</li>
<cffile action = "read"
file = "#dir#cfxwrite.xml"
variable = "CFReadOfCFXWrite">
<i><PRE>variable read=#CFReadOfCFXWrite#</PRE></i>
<li>Take a hash of the read in variable and compare to the hash of string 'A'. Note: The hashes are different, but this hash is the same as the hash of variable created by cfx_secfile when it read in the same file</li>
<i><PRE>
Hash of CFReadOfCFXWrite=#hash(CFReadOfCFXWrite)# is unequal to #hash(stringA)#
</PRE></i>
<li>Use cffile to write the variable, stringA, to a file</li>
<cffile action = "write"
file = "#dir#cfwrite.xml"
output = "#stringA#"
addNewLine = "No"
>
<i><pre>File written: #dir#cfwrite.xml</pre></i>
<li>Use cfx_secfile to read the file written by cffile back to a variable</li>
<cfx_secfile USERNAME="test"
PASSWORD="test"
action="read"
file="#dir#cfwrite.xml"
variable="CFXReadOfCFWrite" >
<i><PRE>variable read=#CFXReadOfCFWrite#</PRE></i>
<li>Take a hash of the read in variable and compare to the hash of string 'A'. Note: The hashes are the same</li>
<i><PRE>Hash of CFXReadOfCFWrite=#hash(CFXReadOfCFWrite)# is equal to #hash(stringA)#</PRE></i>
<li>Use cffile to read the file written by cffile in to a variable</li>
<cffile action = "read"
file = "#dir#cfwrite.xml"
variable = "CFReadOfCFWrite">
<i><PRE>variable read=#CFReadOfCFWrite#</PRE></i>
<li>Take a hash of the read in variable and compare to the hash of string 'A'. Note: The hashes are the same</li>
<i><pre>Hash of CFReadOfCFWrite=#hash(CFReadOfCFWrite)# is equal to #hash(stringA)#</pre></i>
</ol>
<P>
<b>Additional Info:</b>
<br/>
You now have 2 files written to disk. One was written by cffile, one was written by cfx_secfile. If you look at the files and view the whitespace you will notice that there are different line terminination characters at the end of the line. Researching further it appears CFFile writes the file with unix style line termination while cfx_secfile writes the file in windows style line termination. This is only relevant for writing to windows machines. I did not test and do not know what style cffile and cfx_secfile use to write to unix or other machines. In order to see this for yourself your text viewer must be able to show these differences, rather than automatically convert them to whatever system you're using. I used the BeyondCompare comparison tool. Word, wordperfect, and other editor tools were not able to show this.
<br/><br/>
To test my theory of line termination I used the program WS_FTP to convert the file written by cfx_secfile to unix style line termination. This file matched perfectly with what was written by cffile (including whitespace). To further test I read in the converted file using cfx_secfile and calculated the hash. It correctly reproduced the hash. This conclusively proves that differences in the line termination (specifically unix vs windows) is what is responsible for the hashing differences.
<br/><br/>
As a quick fix to converting the files I tried reading the files written by cfx_secfile and rewriting them using cffile. However, this does not work. CFFile preserves the style of the file read in.
</P>
<P>
<b>Conclusion</b>
<br>
There are two possible conclusions based on your point of view:
<br><br>
1. cfx_secfile incorrectly writes files to disk - at least for the windows system. It does not mirror the format of cffile or the in-memory representation of the string prior to writing. cfx_secfile does not meet the claim that it functionally mirrors cffile. I would like to see an attribute added to allow for writing to the various styles (unix, mac, windows, etc).
<br><br>
2.cffile incorrectly writes files to a windows machine. It should convert the EOL symbol to that used for windows. I would like to see an additional attribute added to allow for writing to the various styles (unix, mac, windows, etc).
<br><br>
Regardless of where you feel the fault lies cfx_secfile does not meet the claim that it functionally mirrors cffile. Generally this isn't a big deal. However, it is a significant (and showstopper) difference when whitespace inconsistencies are a concern. For example, the current webSTEERS Copy of Record (COR) implementation uses cfx_secfile to write the COR to disk. Prior to writing to disk it takes a hash of the in-memory representation of the COR (stored in a variable). As shown during the above tests this hash can not be reproduced regardless of whether cffile or cfx_secfile is used to read the file back in. To reproduce the hash the written file must first be converted to unix style.
</P>
<P>
Direct any questions or comments to Bob Jacoby
</P>
</body>
</html>
</cfoutput>
RE:cfx_secfile
From: Lewis Sellers Date: March 28 2003 4:55 PM
| | Hello.
As far as changing the CRLF output sequence to LF, that's easy enough. Done. Less than a minute to make the change.
I haven't checked yet with a hex editor (it's a type of editor that lets you see the exact byte differences in files) but I assume you're entirely correct. As I recall Unix uses LF for end of line markers, Windows CR LF and Macintosh (at least before the current Unix-based MacOS) used LFLF (I think).
It wouldn't be very difficult at all to add a new parameter to choose the EOL marker style. Probably less than 30 minutes of work all together.... If I had ColdFusion installed locally. :) Haven't used it in months. Hmm. I'll have to hunt down the disc first.
Besides that and being busy today, the folks I'm co-located with are moving servers monday (so I'm not even sure any of these messages will survive the change). I can see about doing something about it next week however.
(Damn, this message window is too small. Will have to fix later.)
--min
|