Bugs in Importer fixed (mostly encoding-related)

main
Inga 🏳‍🌈 14 years ago
parent 4ab799675c
commit 6f73cb6119
  1. 2
      Builder/IISMainHandler/build.txt
  2. 2
      ImportConsole/Program.cs
  3. 12
      Importer/ShallerConnector.cs
  4. 5
      Importer/ShallerGateway.cs

@ -42,7 +42,7 @@ namespace FLocal.ImportConsole {
AbstractChange addAccount = new InsertChange(
Account.TableSpec.instance,
new Dictionary<string,AbstractFieldValue>() {
{ Account.TableSpec.FIELD_NAME, new ScalarFieldValue(userName) },
{ Account.TableSpec.FIELD_NAME, new ScalarFieldValue(userName.ToLower()) },
{ Account.TableSpec.FIELD_NEEDSMIGRATION, new ScalarFieldValue("1") },
{ Account.TableSpec.FIELD_PASSWORDHASH, new ScalarFieldValue("*") },
{ Account.TableSpec.FIELD_USERID, new ReferenceFieldValue(addUser) },

@ -10,6 +10,12 @@ using System.IO;
namespace FLocal.Importer {
class ShallerConnector {
public static Encoding encoding {
get {
return Encoding.GetEncoding(1251);
}
}
public static string getPageContent(string requestUrl, Dictionary<string, string> postData, CookieContainer cookies) {
string baseUrl = ConfigurationManager.AppSettings["Importer_BaseUrl"];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseUrl + requestUrl);
@ -21,9 +27,9 @@ namespace FLocal.Importer {
StringBuilder postBuilder = new StringBuilder();
foreach(KeyValuePair<string, string> kvp in postData) {
postBuilder.Append(HttpUtility.UrlEncode(kvp.Key));
postBuilder.Append(HttpUtility.UrlEncode(kvp.Key, encoding));
postBuilder.Append('=');
postBuilder.Append(HttpUtility.UrlEncode(kvp.Value));
postBuilder.Append(HttpUtility.UrlEncode(kvp.Value, encoding));
}
byte[] postBytes = Encoding.ASCII.GetBytes(postBuilder.ToString());
@ -39,7 +45,7 @@ namespace FLocal.Importer {
request.UserAgent = "ShallerConnector v0.1";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
cookies.Add(response.Cookies);
using(StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(1251))) {
using(StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) {
return reader.ReadToEnd();
}
}

@ -9,7 +9,8 @@ namespace FLocal.Importer {
public class ShallerGateway {
public static string getUserInfoAsString(string userName) {
return ShallerConnector.getPageContent("showprofile.php?User=" + userName + "&What=login&showlite=l", new Dictionary<string,string>(), new System.Net.CookieContainer());
//if(userName != HttpUtility.UrlEncode(userName, ShallerConnector.encoding)) throw new ApplicationException("'" + userName + "':showprofile.php?User=" + HttpUtility.UrlEncode(userName, ShallerConnector.encoding) + "&What=login&showlite=l");
return ShallerConnector.getPageContent("showprofile.php?User=" + HttpUtility.UrlEncode(userName, ShallerConnector.encoding) + "&What=login&showlite=l", new Dictionary<string,string>(), new System.Net.CookieContainer());
}
private static Dictionary<string, Regex> regexInfoCache = new Dictionary<string, Regex>();
@ -50,7 +51,7 @@ namespace FLocal.Importer {
MatchCollection matches = matcher.Matches(content);
HashSet<string> result = new HashSet<string>();
foreach(Match match in matches) {
result.Add(match.Groups[1].Value);
result.Add(HttpUtility.UrlDecode(match.Groups[1].Value, ShallerConnector.encoding).Trim());
}
return result;
}

Loading…
Cancel
Save