View the DQSD CVS repository here:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dqsd/

Update of /cvsroot/dqsd/dqsd
In directory sc8-pr-cvs1:/tmp/cvs-serv5292

Modified Files:
        search.htm 
Added Files:
        httpinst.js 
Log Message:
Refactored httpinst:
- /local saves the search to localsearches instead of the default; searches
- /o forces overwrite of existing search with the same name without asking
- Supports proto-less URLs. Uses isURL to recognize, validate and canonicalize URLs
- Better validation overall
- Moved to its own file, httpinst.js, which is included from search.htm

--- NEW FILE: httpinst.js ---

// Called from def() in search.htm. If this is determined to be an httpinst command, 
parses arguments and runs installFromUrl
function httpinst(q)
{
        // See if the call is aimed for us, and extract args
  if(q.search("httpinst ") != 0)
  {
        return false; // let this pass to other handlers
  }
  
  var terms = q.substr(9, q.length);

        // Parse arguments
        var destinationFolder = 'searches';
        var forceOverwrite = false;
        
        var args = parseArgs(terms, "local, o");
        for(var n = 0; n < args.switches.length; ++n)
        {
                switch(args.switches[n].name)
                {
                case "local":
                        destinationFolder = "localsearches";
                        break;
                case "o":
                        forceOverwrite = true;
                        break;
                }
        }

        // Validate URL arg
        var searchUrl = isURL(args.q);
        if(!searchUrl)
        {
                alert(args.q + " does not appear to be a valid URL");
        }
        else
        {               
                // Call worker  
                installFromUrl(searchUrl, destinationFolder, forceOverwrite);
        }
        
        return true;
}

// Reads XML file from searchUrl and writes it to destFolder, silently overwriting 
existing files if forceOverwrite is true
function installFromUrl(searchUrl, destFolder, forceOverwrite)
{
  try
  { 
                // Parse out search filename
                var searchName = searchFilenameFromUrl(searchUrl);
        var outputFilePath = destFolder + "/" + searchName;
        
        // Request search xml from provided URL
          var xmlHttp = new ActiveXObject("Microsoft.XmlHttp")
          xmlHttp.open("GET", searchUrl, false);
          xmlHttp.send();

                // Verify that response is well-formed
                var xmlDom = xmlHttp.responseXml;
          if(xmlDom.parseError.errorCode != 0)
          {
            throw new Error(0, "Search is not well-formed.\nParse error: " + 
xmlDom.parseError.reason + " line: " + xmlDom.parseError.line.toString() + ", col: " + 
xmlDom.parseError.linepos.toString() + "\n" + xmlDom.parseError.srcText);
          }
                
                if(!forceOverwrite)
                {
                        // Check if file already exists
                        var fileSearches = getFiles(outputFilePath);
                        if(fileSearches.length > 0)
                        {
                                forceOverwrite = confirm("There's already a search 
called " + searchName + " in your " + destFolder + " folder. Do you wish to overwrite 
it?");
                        }
                }
                
                if(forceOverwrite)
                {
                        // Save xml file to destination directory
                        writeFile(outputFilePath, xmlHttp.responseText);
        
                        // Tell the user all went well, and reload if asked to
                        if(confirm("Successfully installed search " + searchName + 
".\n\nWould you like to reload the toolbar?"))
                        {
                                reload();               
                        }
                }
  }
  catch(e)
  {
                alert("Unable to install search from " + searchUrl + ".\nError 
message: " + e.message);
  }
}

// Gets the search filename from an URL (everything after the last slash, must end 
with .xml)
function searchFilenameFromUrl(searchUrl)
{
        var searchName = "";
        
        try
        {
                // Parse out search filename
                for(var p = searchUrl.length - 1; p > 0; --p)
                {
                        if(searchUrl.charAt(p) == '/')
                        {
                                searchName = searchUrl.substr(p + 1, searchUrl.length 
- p);
                                break;
                        }
                }
                
                // May not be empty
                if(searchName == "")
                {
                        throw new Error(0, "Failed to find search filename in URL: " + 
searchUrl);
                }
                
                // Must end with ".xml"
                if(!/\.xml$/.test(searchName))
                {
                        throw new Error(0, "Not a valid search filename: " + 
searchName);
                }               
        }
        catch(e)
        {
                throw e;
        }

        return searchName;
}
Index: search.htm
===================================================================
RCS file: /cvsroot/dqsd/dqsd/search.htm,v
retrieving revision 1.173
retrieving revision 1.174
diff -C2 -d -r1.173 -r1.174
*** search.htm  25 Jun 2003 19:20:43 -0000      1.173
--- search.htm  27 Jun 2003 12:08:12 -0000      1.174
***************
*** 134,137 ****
--- 134,138 ----
  <script type='text/jscript' src="strings.js"></script>
  <script type='text/jscript' src="version.js"></script>
+ <script type='text/jscript' src="httpinst.js"></script>
  
  <script type='text/jscript'>
***************
*** 196,206 ****
    if(t == "refreshicons")   { refreshIcons(); return false; }
  
!   // Handle quick-installation
!   if(t.search("httpinst ") == 0)
!   {
!       var searchUrl = t.substr(9, t.length);
!       httpInstall(searchUrl);
!       return false;
!   }
  
    // anything below adds something to the history
--- 197,202 ----
    if(t == "refreshicons")   { refreshIcons(); return false; }
  
!   // HTTP-installation
!   if (httpinst(t)) return false;
  
    // anything below adds something to the history
***************
*** 926,980 ****
     }
  }
- 
- function httpInstall(searchUrl)
- {
-   try
-   {
-       // Request search xml from provided URL
-         var xmlHttp = new ActiveXObject("Microsoft.XmlHttp")
-         xmlHttp.open("GET", searchUrl, false);
-         xmlHttp.send();
- 
-               // Verify wellformed-ness of response
-               var xmlDom = xmlHttp.responseXml;
-         if(xmlDom.parseError.errorCode != 0)
-         {
-           alert("Search retrieved from " + searchUrl + " is not well-formed.\nParse 
error: " + xmlDom.parseError.reason);
-           return false;
-         }
-               
-               // Parse out search filename
-               var searchName = "";
-               for(var p = searchUrl.length - 1; p > 0; --p)
-               {
-                       if(searchUrl.charAt(p) == '/')
-                       {
-                               searchName = searchUrl.substr(p + 1, searchUrl.length 
- p);
-                               break;
-                       }
-               }
-               
-               if(searchName == "")
-               {
-                       alert("Failed to find search filename in URL " + searchUrl);
-                       return false;
-               }
- 
-               // Save xml file to localsearches directory
-               writeFile("localsearches/" + searchName, xmlHttp.responseText);
- 
-               // Tell the user all went well
-               if(confirm("Successfully installed search " + searchName + ".\nWould 
you like to reload the toolbar?"))
-               {
-                       // Reload
-                       reload();               
-               }
-   }
-   catch(e)
-   {
-               alert("Unable to install search from " + searchUrl + ".\nError 
message: " + e.message);
-   }
- }
- 
  </script>
  </body>
--- 922,925 ----




-------------------------------------------------------
This SF.Net email is sponsored by: INetU
Attention Web Developers & Consultants: Become An INetU Hosting Partner.
Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission!
INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php
_______________________________________________
DQSD-CVS mailing list
https://lists.sourceforge.net/lists/listinfo/dqsd-cvs
DQSD CVS repository:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/dqsd/

Reply via email to