Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions src/chrome/content/contentHandler/docomo.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ firemobilesimulator.contentHandler.docomo = {
ndDocument.addEventListener("keypress", firemobilesimulator.contentHandler.common.createAccessKeyFunction(["accesskey"]), false);

// formのUTN送信
// uid=NULLGWDOCOMOのPOST送信
// オープンiエリアの場合のメソッドを強制的にGETに書き換え
// ##本当はhttp-on-modify-requestで書き換えたい##
var formTags = ndDocument.getElementsByTagName("form");
for (var i = 0; i < formTags.length; i++) {
var formTag = formTags[i];
Expand All @@ -96,29 +93,6 @@ firemobilesimulator.contentHandler.docomo = {
dump("setlcs for form tag\n");
formTag.addEventListener("submit", setLcsFunction, false);
}

// オープンiエリアの場合のメソッドを強制的にGETに書き換え
var action = formTag.getAttribute("action");
if (action && action == "http://w1m.docomo.ne.jp/cp/iarea") {
formTag.setAttribute("method", "GET");
}

// uid=NULLGWDOCOMOのPOST送信
var method = formTag.getAttribute("method");
if (method && method.toUpperCase() == "POST") {
var inputTags = formTag.getElementsByTagName("input");
for (var j = 0; j < inputTags.length; j++) {
var inputTag = inputTags[j];
var key = inputTag.getAttribute("name");
var value = inputTag.value;
if (key && value && key.toUpperCase() == "UID"
&& value.toUpperCase() == "NULLGWDOCOMO") {
dump("replace uid\n");
var uid = firemobilesimulator.common.carrier.getId(firemobilesimulator.common.carrier.idType.DOCOMO_UID,deviceId);
inputTag.value = uid;
}
}
}
}
}
};
};
99 changes: 95 additions & 4 deletions src/components/msimModifyHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ myHTTPListener.prototype = {
var rewriteFlag = false;
var as = uri.asciiSpec;
var qs = "";
var ps = null;

var uid = firemobilesimulator.common.carrier.getId(firemobilesimulator.common.carrier.idType.DOCOMO_UID,id);
var ser = firemobilesimulator.common.carrier.getId(firemobilesimulator.common.carrier.idType.DOCOMO_SER,id);
Expand Down Expand Up @@ -176,6 +177,53 @@ myHTTPListener.prototype = {
as = parts[0] + "?" + qs;
}

// POSTパラメータ解析&UID送信
if (httpChannel.requestMethod == "POST") {
var uploadChannel = subject.QueryInterface(Ci.nsIUploadChannel);

if (uploadChannel.uploadStream != null) {
var seekable = uploadChannel.uploadStream;
seekable.QueryInterface(Ci.nsISeekableStream);
var stream = Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
stream.init(uploadChannel.uploadStream);

var valid = false;
for (var line = processLine(stream); line; line = processLine(stream)) {
var header = line.match(/^([^:]+):\s?(.*)/);

if (header == null)
continue;

if (header[1].toLowerCase() == "content-type" && header[2].toLowerCase() == "application/x-www-form-urlencoded")
valid = true;
}

if (valid) {
var postParams = stream.read(stream.available());
//dump("[msim]POST parameter: "+postParams+"\n");

var values = postParams.split("&");

if (uri.scheme != "https") {
// HTTPSではUID送信とiモードID送信は行わない

values = values.map(function(value) {
//dump("[msim]value: "+value+"\n");
if (value.toUpperCase() == "UID=NULLGWDOCOMO") {
dump("[msim]send uid:"+uid+" for docomo.\n");
value = value.substr(0, 3) + "=" + uid;
rewriteFlag = true;
}
return value;
});
}
ps = values.join("&");
//dump("[msim]replace POST parameter: "+ps+"\n");
}
seekable.seek(0, 0);
}
}

var lcsFlag = firemobilesimulator.common.pref
.getBoolPref("msim.temp.lcsflag");
if (true == lcsFlag) {
Expand Down Expand Up @@ -212,7 +260,12 @@ myHTTPListener.prototype = {
}

if (uri.host == "w1m.docomo.ne.jp") {
var param = qs ? "?" + qs : "";
var param = "";
if (httpChannel.requestMethod == "GET") {
param = qs ? "?" + qs : "";
} else if (httpChannel.requestMethod == "POST") {
param = ps ? "?" + ps : "";
}
var path = uri.path.split("?", 2)[0];
if (path == "/cp/iarea") {
// オープンiエリア対応
Expand All @@ -224,7 +277,7 @@ myHTTPListener.prototype = {
} else if (rewriteFlag) {
dump("[msim]rewrite for DoCoMo\n");
//dump("[msim]rewrite for docomo\n");
rewriteURI(subject, as);
rewriteURI(subject, as, ps);
}
} else if (carrier == "SB") {
var type = firemobilesimulator.common.pref.copyUnicharPref("msim.devicelist."+id+".type1");
Expand Down Expand Up @@ -292,19 +345,57 @@ myHTTPListener.prototype = {
])
};

function rewriteURI(subject, url) {
function rewriteURI(subject, url, postStr) {
var documentLoad = subject.loadFlags & (1<<16);
//TODO: <img src="...">の指定などでrewriteする場合に対応要
if (documentLoad) {
subject.loadFlags = Ci.nsICachingChannel.LOAD_ONLY_FROM_CACHE;
subject.cancel(Cr.NS_ERROR_FAILURE);
var webNav = subject.notificationCallbacks
.getInterface(Ci.nsIWebNavigation);
webNav.loadURI(url, Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
var uploadChannel = subject.QueryInterface(Ci.nsIUploadChannel);
var uploadStream = uploadChannel.uploadStream;
if (postStr != null) {
if (uploadStream instanceof Ci.nsIMIMEInputStream){
//dump("[msim]uploadStream is nsIMIMEInputStream\n");
var inputStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
inputStream.setData(postStr, postStr.length);

inputStream.QueryInterface(Ci.nsISeekableStream);
inputStream.seek(0, 0);
inputStream.QueryInterface(Ci.nsIInputStream);
uploadStream.setData(inputStream);
} else if (uploadStream instanceof Ci.nsIStringInputStream) {
//dump("[msim]uploadStream is nsIStringInputStream\n");
var contentType = "Content-Type: application/x-www-form-urlencoded\r\n";
var contentLength = "Content-Length: " + postStr.length + "\r\n";
uploadStream.setData(contentType + contentLength + "\r\n" + postStr, contentType.length + contentLength.length + 2 + postStr.length);
}
//dump("[msim]set upload stream: "+postStr+"\n");
}

webNav.loadURI(url, Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, uploadStream, null);
//webNav.loadURI(url, subject.loadFlags, null, null, null);
}
}

function processLine(stream) {
var line = "";
var size = stream.available();

for (var i = 0; i < size; i++) {
var c = stream.read(1);

if (c == '\n')
break;

if (c != '\r')
line += c;
}

return line;
}

if (XPCOMUtils.generateNSGetFactory) {
// Firefox >= 4
var NSGetFactory = XPCOMUtils.generateNSGetFactory([myHTTPListener]);
Expand Down