Index: main/trunk/greenstone2/runtime-src/src/recpt/authenaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/authenaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/authenaction.cpp	(revision 28899)
@@ -308,5 +308,5 @@
   //      _authen:hiddenargs_   to contain all the arguments that were
   //                            explicitly set
-  disp.setmacro ("messagestatus", "authen", ("_authen:message" + args["us"]
+  disp.setmacro ("messagestatus", "authen", ("_authen:message" + encodeForHTML(args["us"])
 					     + "_"));
   // change style of header and footer if page is a frame
@@ -339,5 +339,5 @@
 	saveconfset.find((*args_here).first) == saveconfset.end()) {
       hiddenargs += "<input type=hidden name=\"" + (*args_here).first +
-	"\" value=\"_cgiarg" + (*args_here).first + "_\">\n";
+	"\" value=\"_cgiarg" + (*args_here).first + "Attrsafe_\">\n";
     }
     ++args_here;
Index: main/trunk/greenstone2/runtime-src/src/recpt/basequeryaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/basequeryaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/basequeryaction.cpp	(revision 28899)
@@ -796,5 +796,5 @@
 	textout << outconvert << disp 
 		<< "Location: _gwcgi_?e=_compressedoptions_&a=d&c=" 
-		<< collection << "&cl=search&d=" << (*section).OID 
+		<< encodeForURL(collection) << "&cl=search&d=" << (*section).OID
 		<< "&srn=" << srn << "&srp=" << srp << "\n\n";
 	textout << flush;
Index: main/trunk/greenstone2/runtime-src/src/recpt/depositoraction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/depositoraction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/depositoraction.cpp	(revision 28899)
@@ -707,5 +707,5 @@
   if ((depositor_page == "select") || (stepstring == "step")) {
           textout << outconvert << disp << ("_depositor:header_\n")
-	      << ("_depositor:" + depositor_page + "content_\n")
+		  << ("_depositor:" + encodeForHTML(depositor_page) + "content_\n")
 	      << ("_depositor:footer_\n");
 	  
@@ -771,5 +771,5 @@
       // output page ("bild" page was already output above)
       textout << outconvert << disp << ("_depositor:header_\n")
-	      << ("_depositor:" + depositor_page + "content_\n")
+	      << ("_depositor:" + encodeForHTML(depositor_page) + "content_\n")
 	      << ("_depositor:footer_\n");
     }
Index: main/trunk/greenstone2/runtime-src/src/recpt/documentaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/documentaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/documentaction.cpp	(revision 28899)
@@ -607,5 +607,5 @@
       outlink = "_httpdocument_&amp;d=" + response.docInfo[0].metadata["section"].values[0];
 #else
-      outlink = "_httpdocumenthandle_("+args["c"]+","+response.docInfo[0].metadata["section"].values[0]+")";
+      outlink = "_httpdocumenthandle_("+encodeForURL(args["c"])+","+response.docInfo[0].metadata["section"].values[0]+")";
 #endif
 
@@ -1066,8 +1066,8 @@
 #ifndef DOCHANDLE
 		<< "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d=" 
-		<< args["d"] << "\">"
+		<< encodeForURL(args["d"]) << "\">"
 #else
 		<< "<frame name=\"documenttop\" frameborder=0 src=\"_httpdocumenthandle_(" 
-		<< args["c"] << "," << args["d"] << ")\">"
+		<< encodeForURL(args["c"]) << "," << encodeForURL(args["d"]) << ")\">"
 #endif
 		<< "<noframes>\n"
@@ -1143,8 +1143,8 @@
 			#ifndef DOCHANDLE
 				<< "<frame name=\"documenttop\" frameborder=0 src=\"_gwcgi_?_optsite_e=_compressedoptions_&a=d&d=" 
-				<< args["d"] << "\">"
+				<< encodeForURL(args["d"]) << "\">"
 			#else
 				<< "<frame name=\"documenttop\" frameborder=0 src=\"_httpdocumenthandle_(" 
-				<< args["c"] << "," << args["d"] << ")\">"
+				<< encodeForURL(args["c"]) << "," << encodeForURL(args["d"]) << ")\">"
 			#endif
 				<< "<noframes>\n"
@@ -1462,5 +1462,5 @@
       			logout << text_t2ascii
 	     			<< "documentaction::output_document: call to QueryFilter failed "
-	     			<< "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
+			        << "for " << args["c"] << " collection (" << get_comerror_string (err) << ")\n";
       			highlight = false;
     		} 
@@ -1645,8 +1645,8 @@
   if (haschildren) {
 #ifndef DOCHANLE
-    disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
-		   "&amp;d=" + arg_d + ".fc");
+    disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + encodeForURL(args["cl"]) +
+		   "&amp;d=" + encodeForURL(arg_d) + ".fc");
 #else
-    disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+arg_d + ".fc)";
+    disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+encodeForURL(args["c"])+","+encodeForURL(arg_d) + ".fc)";
 
 #endif
@@ -1658,8 +1658,8 @@
       if (!(*h).empty()) {
 #ifndef DOCHANLE
-	disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
+	disp.setmacro ("httpnextarrow", "document", "_httpdocument_&amp;cl=" + encodeForURL(args["cl"]) +
 		       "&amp;d=" + *h);
 #else
-	disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+args["c"]+","+*h+")";
+	disp.setmacro ("httpnextarrow", "document", "_httpdocumenthandle_("+encodeForURL(args["c"])+","+*h+")";
 
 #endif
@@ -1674,8 +1674,8 @@
   if (!previous_sibling.empty()) {
 #ifndef DOCHANDLE
-    disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
+    disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + encodeForURL(args["cl"]) +
 		   "&amp;d=" + previous_sibling);
 #else
-    disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+ previous_sibling+")");
+    disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+encodeForURL(args["c"])+","+ previous_sibling+")");
 
 #endif
@@ -1684,8 +1684,8 @@
     if (countchar(arg_d.begin(), arg_d.end(), '.')) {
 #ifndef DOCHANDLE
-      disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + args["cl"] +
+      disp.setmacro ("httpprevarrow", "document", "_httpdocument_&amp;cl=" + encodeForURL(args["cl"]) +
 		     "&amp;d=" + get_parent(arg_d));
 #else
-      disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+args["c"]+","+get_parent(arg_d)+")");
+      disp.setmacro ("httpprevarrow", "document", "_httpdocumenthandle_("+encodeForURL(args["c"])+","+get_parent(arg_d)+")");
 
 #endif
Index: main/trunk/greenstone2/runtime-src/src/recpt/dynamicclassifieraction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/dynamicclassifieraction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/dynamicclassifieraction.cpp	(revision 28899)
@@ -151,5 +151,5 @@
   if (cinfo->dynamic_classifiers.find(arg_dcl) == cinfo->dynamic_classifiers.end())
   {
-    textout << outconvert << disp << "Error: Invalid dcl value \"" << arg_dcl << "\".\n";
+    textout << outconvert << disp << "Error: Invalid dcl value \"" << encodeForHTML(arg_dcl) << "\".\n";
     textout << outconvert << disp << "_dynamicclassifier:footer_\n";
     return true;
Index: main/trunk/greenstone2/runtime-src/src/recpt/gtiaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/gtiaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/gtiaction.cpp	(revision 28899)
@@ -386,5 +386,5 @@
   languageinfo_tmap loaded_languages = recpt->get_configinfo().languages;
   disp.setmacro("gtitargetlanguagename", "gti", loaded_languages[target_language_code].longname);
-  disp.setmacro("gtitranslationfiledesc", "gti", "_gti:textgti" + translation_file_key + "_");
+  disp.setmacro("gtitranslationfiledesc", "gti", "_gti:textgti" + encodeForHTML(translation_file_key) + "_");
 
   if (query_string == "") {
@@ -496,6 +496,6 @@
     disp.setmacro("gtitargetfilepath", "gti", gti_response.translation_files_key_to_target_file_path_mapping[translation_file_key]);
   }
-  disp.setmacro("gtitranslationfiledesc", "gti", "_gti:textgti" + translation_file_key + "_");
-  disp.setmacro("gtiviewtranslationfileinaction", "gti", "_gti:gtiview" + translation_file_key + "inaction_");
+  disp.setmacro("gtitranslationfiledesc", "gti", "_gti:textgti" + encodeForHTML(translation_file_key) + "_");
+  disp.setmacro("gtiviewtranslationfileinaction", "gti", "_gti:gtiview" + encodeForHTML(translation_file_key) + "inaction_");
 
   disp.setmacro("gtinumchunkstranslated", "gti", gti_response.translation_files_key_to_num_chunks_translated_mapping[translation_file_key]);
@@ -660,5 +660,5 @@
  do_gti_request(gti_arguments, logout); 
 
- disp.setmacro("gtiglihelpzipfilepath", "gti", target_language_code + "_GLIHelp.zip");
+ disp.setmacro("gtiglihelpzipfilepath", "gti", encodeForURL(target_language_code) + "_GLIHelp.zip");
 
  return true;
Index: main/trunk/greenstone2/runtime-src/src/recpt/pageaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/pageaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/pageaction.cpp	(revision 28899)
@@ -212,5 +212,5 @@
 	      
 	      text_t link = "_gwcgi_?"+optsite+"a=p&amp;p=about&amp;c=" + *collist_here;
-	      link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"];
+	      link += "&amp;l=" + encodeForURL(args["l"]) + "&amp;w=" + encodeForURL(args["w"]);
 
 	      // We are "dynamically" overriding so to speak the
@@ -335,9 +335,9 @@
 	      if (cinfo->isCollectGroup) {
 		link = "<a class=\"collectiontitle\" href=\"_gwcgi_?"+optsite+"a=p&amp;p=home&amp;g=" + *collist_here;
-		link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"] + "\">";
+		link += "&amp;l=" + encodeForURL(args["l"]) + "&amp;w=" + encodeForURL(args["w"]) + "\">";
 	      }
 	      else {
 		link = "<a class=\"collectiontitle\" href=\"_gwcgi_?"+optsite+"a=p&amp;p=about&amp;c=" + *collist_here;
-		link += "&amp;l=" + args["l"] + "&amp;w=" + args["w"] + "\">";
+		link += "&amp;l=" + encodeForURL(args["l"]) + "&amp;w=" + encodeForURL(args["w"]) + "\">";
 	      }
 	      
@@ -515,5 +515,5 @@
 
 void pageaction::set_macro_to_file_contents (displayclass &disp, const text_t &macroname,
-					     const text_t &packagename, const text_t &filename) {
+					     const text_t &packagename, const text_t &filename, bool encode) {
 
   text_t filecontent;
@@ -531,4 +531,10 @@
     file_in.close();
   }
+
+  // if we ever need to encode the contents into HTML, call this function with encode=true
+  if(encode) {
+    filecontent = encodeForHTML(filecontent);
+  }
+
   disp.setmacro (macroname, packagename, dm_safe(filecontent));
 }
Index: main/trunk/greenstone2/runtime-src/src/recpt/pageaction.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/pageaction.h	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/pageaction.h	(revision 28899)
@@ -85,5 +85,5 @@
 
   void set_macro_to_file_contents (displayclass &disp, const text_t &macroname,
-				   const text_t &packagename, const text_t &filename);
+				   const text_t &packagename, const text_t &filename, bool encode=false);
 
   void set_language_encoding_macros(displayclass &disp, cgiargsclass &args,
Index: main/trunk/greenstone2/runtime-src/src/recpt/phindaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/phindaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/phindaction.cpp	(revision 28899)
@@ -152,5 +152,5 @@
 
   unsigned long count_l, count_e, count_d;
-  unsigned long phrase = args["ppnum"].getulong();
+  unsigned long phrase = args["ppnum"].getulong(); // needn't encodeFor<web> on vars which have getulong() applied
   text_t &word = args["pptext"];
   unsigned long first_e = args["pfe"].getulong();
@@ -208,5 +208,5 @@
     
     if (result.empty()) {
-      output_error("phindaction: The search term ("+word+") does not occur in the collection",
+      output_error("phindaction: The search term ("+encodeForHTML(word)+") does not occur in the collection",
 		   textout, outconvert, disp, logout, XMLmode);
       return true;
@@ -255,5 +255,5 @@
   if (XMLmode) {
     textout << "<phinddata id=\"" << phrase 
-	    << "\" text=\"" << word 
+	    << "\" text=\"" << encodeForHTMLAttr(word) 
 	    << "\" tf=\"" << tf 
 	    << "\" ef=\"" << ef 
@@ -262,8 +262,8 @@
 	    << "\">\n";
   } else {
-    textout << "<html><head><title>" << word << "</title></head>\n"
+    textout << "<html><head><title>" << encodeForHTML(word) << "</title></head>\n"
 	    << "<body><center>\n"
-	    << "<p><h1>" << word << "</h1>\n"
-	    << "<p><b>"<< word << "</b> occurs " 
+	    << "<p><h1>" << encodeForHTML(word) << "</h1>\n"
+	    << "<p><b>"<< encodeForHTML(word) << "</b> occurs " 
 	    << tf << " times in " << df << " documents\n";
   }
@@ -316,5 +316,5 @@
 	  textout << outconvert << disp 
 		  << "<br><a href=\"_gwcgi_?"
-		  << "c=" << args["c"]
+		  << "c=" << encodeForURL(args["c"])
 		  << "&ppnum=" << phrase 
 		  << "&pfe=" << first_e 
@@ -328,5 +328,5 @@
 	textout << outconvert << disp
 		<< "<br><a href=\"_gwcgi_?"
-		<< "c=" << args["c"]
+		<< "c=" << encodeForURL(args["c"])
 		<< "&ppnum=" << phrase 
 		<< "&pfe=" << first_e 
@@ -379,5 +379,5 @@
 	  textout << outconvert << disp 
 		  << "<br><a href=\"_gwcgi_?"
-		  << "c=" << args["c"]
+		  << "c=" << encodeForURL(args["c"])
 		  << "&ppnum=" << phrase 
 		  << "&pfe=" << first_e 
@@ -391,5 +391,5 @@
 	textout << outconvert << disp
 		<< "<br><a href=\"_gwcgi_?"
-		<< "c=" << args["c"]
+		<< "c=" << encodeForURL(args["c"])
 		<< "&ppnum=" << phrase 
 		<< "&pfe=" << first_e 
@@ -453,5 +453,5 @@
 	  textout << outconvert << disp
 		  << "<br><a href=\"_gwcgi_?"
-		  << "c=" << args["c"]
+		  << "c=" << encodeForURL(args["c"])
 		  << "&ppnum=" << phrase 
 		  << "&pfe=" << first_e 
@@ -465,5 +465,5 @@
 	textout << outconvert << disp 
 		<< "<br><a href=\"_gwcgi_?"
-		<< "c=" << args["c"]
+		<< "c=" << encodeForURL(args["c"])
 		<< "&ppnum=" << phrase 
 		<< "&pfe=" << first_e 
@@ -742,5 +742,5 @@
       textout << "<tr valign=top><td>" << type << "</td><td>";
       textout << outconvert << disp
-	      << "<a href=\"_gwcgi_?c=" << collection;
+	      << "<a href=\"_gwcgi_?c=" << encodeForURL(collection);
       textout << "&ppnum=" << phrase << "\">" << text << "</a>"
 	      << "</td><td>" << tf << "</td><td>" << df << "</td></tr>\n";
@@ -847,8 +847,12 @@
 	      << "\" df=\"" << df;
       if (!prefix.empty()) {
-	textout << "\" prefix=\"" << prefix;
+	text_t prefix_txt; 
+	fromUCArray(prefix, prefix_txt);
+	textout << "\" prefix=\"" << encodeForHTMLAttr(prefix_txt);
       }
       if (!suffix.empty()) {
-	textout << "\" suffix=\"" << suffix;
+	text_t suffix_txt; 
+	fromUCArray(suffix, suffix_txt);
+	textout << "\" suffix=\"" << encodeForHTMLAttr(suffix_txt);
       }
       textout << "\"/>\n";
@@ -856,12 +860,12 @@
       textout << outconvert << disp 
 	      << "<tr valign=top><td align=right><a href=\"_gwcgi_?"
-	      << "c=" << collection << "&ppnum=" << phrase << "\">";
+	      << "c=" << encodeForURL(collection) << "&ppnum=" << phrase << "\">";
       textout << prefix << "</a></td>";
       textout <<outconvert << disp
 	      << "<td align=center><a href=\"_gwcgi_?"
-	      << "c=" << collection << "&ppnum=" << phrase << "\">"
-	      << body << "</a></td>"
+	      << "c=" << encodeForURL(collection) << "&ppnum=" << phrase << "\">"
+	      << encodeForHTML(body) << "</a></td>"
 	      << "<td align=left><a href=\"_gwcgi_?"
-	      << "c=" << collection << "&ppnum=" << phrase << "\">";
+	      << "c=" << encodeForURL(collection) << "&ppnum=" << phrase << "\">";
       textout << suffix << "</a></td>"
 	      << "<td>" << tf << "</td><td>" << df << "</td></tr>\n";
@@ -986,5 +990,5 @@
       textout << outconvert << disp
 	      << "<tr valign=top><td><a href=\"_gwcgi_?"
-	      << "c=" << collection;
+	      << "c=" << encodeForURL(collection);
       textout << "&a=d&d=" << hash << "\">" << title << "</a>"
 	      << "</td><td>" << freq << "</td></tr>\n"; 
@@ -1057,4 +1061,18 @@
 }
 
+void phindaction::fromUCArray(const UCArray &arrin, text_t &txtout) {
+  txtout.clear();
+  if (txtout.capacity() < arrin.size() + 1) {
+    txtout.reserve(arrin.size() + 1);
+  }
+  vector<unsigned char>::const_iterator here = arrin.begin();
+  vector<unsigned char>::const_iterator end = arrin.end();
+  while (here != end) {
+    txtout.push_back(*here); // don't need to cast unsigned char to unsigned short
+    ++here;
+  }
+}
+
+
 void phindaction::output_error (const text_t &message, ostream &textout, 
 				outconvertclass &outconvert,
Index: main/trunk/greenstone2/runtime-src/src/recpt/phindaction.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/phindaction.h	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/phindaction.h	(revision 28899)
@@ -93,4 +93,5 @@
 
   void toUCArray(const text_t &in, UCArray &out);
+  void fromUCArray(const UCArray &arrin, text_t &txtout);
 
   void output_error (const text_t &message, ostream &textout, 
Index: main/trunk/greenstone2/runtime-src/src/recpt/pingaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/pingaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/pingaction.cpp	(revision 28899)
@@ -76,5 +76,5 @@
 	textout << outconvert << "Ping";
   } else {
-	textout << outconvert << "Ping for \"" << args["c"] << "\"";
+        textout << outconvert << "Ping for \"" << encodeForHTML(args["c"]) << "\"";
   }
 
Index: main/trunk/greenstone2/runtime-src/src/recpt/queryaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/queryaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/queryaction.cpp	(revision 28899)
@@ -747,7 +747,7 @@
 	  << "<input type=\"hidden\" name=\"ccp\" value=\"1\">\n"
 	  << "<center><table width=\"_pagewidth_\"><tr valign=\"top\">\n"
-	  << "<td>Select collections to search for \"" << args["q"] 
-	  << "\" <i>(index=" << index << " subcollection=" << subcollection
-	  << " language=" << language << ")</i></td>\n"
+	  << "<td>Select collections to search for \"" << encodeForHTML(args["q"])
+	  << "\" <i>(index=" << encodeForHTML(index) << " subcollection=" << encodeForHTML(subcollection)
+	  << " language=" << encodeForHTML(language) << ")</i></td>\n"
 	  << "<td><input type=\"submit\" value=\"_query:textbeginsearch_\"></td>\n"
 	  << "</tr></table></center>\n"
Index: main/trunk/greenstone2/runtime-src/src/recpt/receptionist.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/receptionist.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/receptionist.cpp	(revision 28899)
@@ -1533,11 +1533,13 @@
     text_t urlsafe = encodeForURL(macrovalue);
     text_t jssafe = encodeForJavascript(macrovalue); // with default setting will return \\x and \\u for macro files
-    text_t csssafe = encodeForCSS(macrovalue);
+    text_t csssafe = encodeForCSS(macrovalue); // not yet used anywhere, but is available for use in macros
+    text_t sqlsafe = encodeForSQL(macrovalue);
 
     disp.setmacro ("cgiarg" + (*argshere).first + "Htmlsafe", displayclass::defaultpackage, htmlsafe);    
     disp.setmacro ("cgiarg" + (*argshere).first + "Attrsafe", displayclass::defaultpackage, attrsafe);
+    disp.setmacro ("cgiarg" + (*argshere).first + "Urlsafe", displayclass::defaultpackage, urlsafe);
     disp.setmacro ("cgiarg" + (*argshere).first + "Jssafe", displayclass::defaultpackage, jssafe);
     disp.setmacro ("cgiarg" + (*argshere).first + "Csssafe", displayclass::defaultpackage, csssafe);
-    disp.setmacro ("cgiarg" + (*argshere).first + "Urlsafe", displayclass::defaultpackage, urlsafe);
+    disp.setmacro ("cgiarg" + (*argshere).first + "Sqlsafe", displayclass::defaultpackage, sqlsafe);
     
 
Index: main/trunk/greenstone2/runtime-src/src/recpt/rssaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/rssaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/rssaction.cpp	(revision 28899)
@@ -70,5 +70,5 @@
 	  << "  <link>_httpdomain__httppageabout_</link>\n"
 	  << "  <description>_collectionextra_</description>\n"
-	  << "  <language>_cgiargl_</language>\n"
+	  << "  <language>_cgiarglHtmlsafe_</language>\n"
 	  << "  <pubDate>Thu, 23 Aug 1999 07:00:00 GMT</pubDate>\n"
 	  << "  <lastBuildDate>Thu, 23 Aug 1999 16:20:26 GMT</lastBuildDate>\n"
@@ -122,8 +122,8 @@
   // If ever adding a custom macro file like rss.dm that mentions the package, need to list rss.dm in etc/main.cfg
 
-  if(disp.havemacro("Global", "httpdomain") == 0) { // if using rss package, willcheck rss and Global packages in order. And if not found:
+  if(disp.havemacro("Global", "httpdomain") == 0) { // if using rss package, will check rss and Global packages in order. And if not found:
     
     if(!args["hostname"].empty()) {
-      disp.setmacro("httpdomain", "Global", "http://" + args["hostname"]);
+      disp.setmacro("httpdomain", "Global", "http://" + encodeForURL(args["hostname"]));
     } 
     else { // we shouldn't have to get here
Index: main/trunk/greenstone2/runtime-src/src/recpt/securitytools.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/securitytools.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/securitytools.cpp	(revision 28899)
@@ -136,11 +136,10 @@
 }
 
-
-text_t encodeForMySQL(const text_t& in, const text_t& immuneChars, const SQLMode mode) {
-  text_t out;
-  text_t::const_iterator here = in.begin();
-  text_t::const_iterator end = in.end();
-  while (here != end) {
-    out += encodeForMySQL(immuneChars, *here, mode); // IMMUNE_SQL and STANDARD SQLMode by default
+text_t encodeForSQL(const text_t& in, const text_t& immuneChars, const SQLMode mode) {
+  text_t out;
+  text_t::const_iterator here = in.begin();
+  text_t::const_iterator end = in.end();
+  while (here != end) {
+    out += encodeForSQL(immuneChars, *here, mode); // IMMUNE_SQL and STANDARD SQLMode by default
     ++here;
   }
@@ -320,4 +319,7 @@
 
 /* 
+
+ C++ port of OWASP-ESAPI for MySQL. Not sure if this is is the same for SQLite
+
 http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/MySQLCodec.java
  Defense Option 3 of https://www.owasp.org/index.php/SQL_Injection_Prevention_Cheat_Sheet
@@ -335,5 +337,5 @@
 
 */
-text_t encodeForMySQL(const text_t& immuneChars, const unsigned short in, const SQLMode mode) {
+text_t encodeForSQL(const text_t& immuneChars, const unsigned short in, const SQLMode mode) {
   
   text_t result = "";
@@ -392,4 +394,5 @@
 }
 
+// Unused at present.
 // See Codec.hex[] initialization and Codec.getHexForNonAlphanumeric(c) and Codec.toHex(c)
 // http://code.google.com/p/owasp-esapi-java/source/browse/trunk/src/main/java/org/owasp/esapi/codecs/Codec.java
Index: main/trunk/greenstone2/runtime-src/src/recpt/securitytools.h
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/securitytools.h	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/securitytools.h	(revision 28899)
@@ -28,5 +28,6 @@
 text_t encodeForHTMLAttr(const text_t& input, const text_t& immuneChars=IMMUNE_HTMLATTR);
 text_t encodeForCSS(const text_t& input, const text_t& immuneChars=IMMUNE_CSS);
-text_t encodeForMySQL(const text_t& input, const text_t& immuneChars=IMMUNE_SQL, const SQLMode mode=STANDARD);
+// C++ port of OWASP-ESAPI for MySQL, not sure if this is is the same for SQLite
+text_t encodeForSQL(const text_t& input, const text_t& immuneChars=IMMUNE_SQL, const SQLMode mode=STANDARD);
 
 // Character conversions
@@ -35,5 +36,5 @@
 text_t encodeForJavascript(const text_t& immuneChars, const unsigned short input, bool dmsafe);
 text_t encodeForCSS(const text_t& immuneChars, const unsigned short input);
-text_t encodeForMySQL(const text_t& immuneChars, const unsigned short input, const SQLMode mode);
+text_t encodeForSQL(const text_t& immuneChars, const unsigned short input, const SQLMode mode);
 
 
Index: main/trunk/greenstone2/runtime-src/src/recpt/sqlqueryaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/sqlqueryaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/sqlqueryaction.cpp	(revision 28899)
@@ -270,5 +270,5 @@
   if (args["qt"]=="0" && args["sqlqto"] != "1") { // normal text search
     unsafe_cgi_arg("ALL", args["q"]);
-    formattedstring = "SELECT DISTINCT docOID FROM document_metadata WHERE " + args["q"];    
+    formattedstring = "SELECT DISTINCT docOID FROM document_metadata WHERE " + encodeForSQL(args["q"]);    
   }
   else if (args["qt"]=="1" || args["sqlqto"]=="1"){ // form search
Index: main/trunk/greenstone2/runtime-src/src/recpt/statusaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/statusaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/statusaction.cpp	(revision 28899)
@@ -353,5 +353,5 @@
     arg_value = args.getarg (ainfo.shortname);
     if (arg_value == NULL) textout << outconvert << "<td></td></tr>\n";
-    else textout << outconvert << "<td>\"" << *arg_value << "\"</td></tr>\n";
+    else textout << outconvert << "<td>\"" << encodeForHTML(*arg_value) << "\"</td></tr>\n";
     
     ++argsinfohere;
@@ -547,6 +547,6 @@
   
   if (rprotolist_here == rprotolist_end) {
-    textout << outconvert << "Protocol \"" << arg_pr << "\" with collection \""
-	    << arg_c << "\" was not found\n";
+    textout << outconvert << "Protocol \"" << encodeForHTML(arg_pr) << "\" with collection \""
+	    << encodeForHTML(arg_c) << "\" was not found\n";
 
   } else {
@@ -819,11 +819,14 @@
     text_t errorpage = "<p><pre>\n";
 
+    text_t errorpage_content;
     char c;
     errin.get(c);
     while (!errin.eof ()) {
-      errorpage.push_back(c);
+      errorpage_content.push_back(c);
       errin.get(c);
     }
-    
+    // need to ensure that error_log displayed from Admin pages is encoded/safe for an HTML context
+    errorpage += encodeForHTML(errorpage_content);
+
     errorpage += "</pre>\n";
     errin.close();
@@ -849,5 +852,5 @@
   text_t llssite_cfg = filename_cat (gsdlhome, "llssite.cfg");
 #else
-  text_t llssite_cfg = "llssite.cfg";
+  text_t llssite_cfg = filename_cat (gsdlhome, "llssite.cfg"); //"llssite.cfg";
 #endif
 
@@ -1138,5 +1141,5 @@
   else {
     output_errorpage (outconvert, textout, logout, 
-		      "Unknown page \"" + arg_p + "\".\n");
+		      "Unknown page \"" + encodeForHTML(arg_p) + "\".\n");
   }
 
Index: main/trunk/greenstone2/runtime-src/src/recpt/usersaction.cpp
===================================================================
--- main/trunk/greenstone2/runtime-src/src/recpt/usersaction.cpp	(revision 28898)
+++ main/trunk/greenstone2/runtime-src/src/recpt/usersaction.cpp	(revision 28899)
@@ -235,12 +235,12 @@
     if (user_database->get_user_info(*users_here, userinfo) == ERRNO_SUCCEED) {
       textout << outconvert << disp
-	      << "<tr><td bgcolor=\"\\#eeeeee\">" << userinfo.username << "</td>\n"
+	      << "<tr><td bgcolor=\"\\#eeeeee\">" << encodeForHTML(userinfo.username) << "</td>\n"
        	      << "<td bgcolor=\"\\#eeeeee\">" << (char *) (userinfo.enabled ? "enabled" : "disabled") << "</td>\n"
-	      << "<td bgcolor=\"\\#eeeeee\">" << userinfo.groups << "&nbsp;</td>\n"
-	      << "<td bgcolor=\"\\#eeeeee\">" << userinfo.comment << "&nbsp;</td>\n"
+	      << "<td bgcolor=\"\\#eeeeee\">" << encodeForHTML(userinfo.groups) << "&nbsp;</td>\n"
+	      << "<td bgcolor=\"\\#eeeeee\">" << encodeForHTML(userinfo.comment) << "&nbsp;</td>\n"
 	      << "<td><a href=\"_httpcurrentdocument_&a=um&uma=edituser&umun="
-	      << userinfo.username << "\">_userslistusers:textedituser_</a> "
+	      << encodeForHTML(userinfo.username) << "\">_userslistusers:textedituser_</a> "
 	      << "<a href=\"_httpcurrentdocument_&a=um&uma=deleteuser&umun="
-	      << userinfo.username << "\">_userslistusers:textdeleteuser_</a>"
+	      << encodeForHTML(userinfo.username) << "\">_userslistusers:textdeleteuser_</a>"
 	      << "</td></tr>\n\n";
 
