fix MessageSend servlet response if called for passive peer

pull/51/head
reger 9 years ago
parent de46879637
commit 27a238062f

@ -7,48 +7,48 @@
<body id="MessageSend">
#%env/templates/header.template%#
#(mode)#
<!-- =========================== write message =========================== -->
<!-- (mode=0) =========================== write message =========================== -->
<h2>Send message</h2>
#(permission)#
<!-- we have no permission to send the message -->
<p>You cannot send a message to <strong>#[peerName]#</strong>.<br />
The peer does not respond. It was now removed from the peer-list.
</p>
::
<!-- we have the permission to send the message -->
<p>The peer <b>#[peerName]#</b> is alive and responded:</p>
<p><tt class="MessageBackground">#[response]#
You are allowed to send me a message &le; #[messagesize]# kb and an
attachment &le; #[attachmentsize]#.</tt>
</p>
#(permission)#
<!-- we have no permission to send the message -->
<p>You cannot send a message to <strong>#[peerName]#</strong>.<br />
The peer does not respond. It was now removed from the peer-list.
</p>
::
<!-- we have the permission to send the message -->
<p>The peer <b>#[peerName]#</b> is alive and responded:</p>
<p><tt class="MessageBackground">#[response]#
You are allowed to send me a message &le; #[messagesize]# kb and an
attachment &le; #[attachmentsize]#.</tt>
</p>
<form action="MessageSend_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
<form action="MessageSend_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
<fieldset>
<legend>Your Message</legend>
<dl>
<dt>
<label for="subject">Subject:</label>
</dt>
<dd>
<input name="subject" id="subject" type="text" size="80" maxlength="80" value="#[subject]#" />
</dd>
<dt>
<label for="message">Text:</label>
</dt>
<dd>
<textarea name="message" id="message" cols="80" rows="8">#[message]#</textarea>
<p class="help">
You can use <a href="WikiHelp.html" onclick="window.open('WikiHelp.html','WikiHelp','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');return false;">Wiki Code</a> here.
</p>
</dd>
</dl>
<legend>Your Message</legend>
<dl>
<dt>
<label for="subject">Subject:</label>
</dt>
<dd>
<input name="subject" id="subject" type="text" size="80" maxlength="80" value="#[subject]#" />
</dd>
<dt>
<label for="message">Text:</label>
</dt>
<dd>
<textarea name="message" id="message" cols="80" rows="8">#[message]#</textarea>
<p class="help">
You can use <a href="WikiHelp.html" onclick="window.open('WikiHelp.html','WikiHelp','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');return false;">Wiki Code</a> here.
</p>
</dd>
</dl>
<input type="hidden" name="hash" value="#[hash]#" />
<input type="hidden" name="messagesize" value="#[messagesize]#" />
<input type="hidden" name="attachmentsize" value="#[attachmentsize]#" />
<input name="new" type="submit" value="Enter" />
<input type="submit" name="preview" value="Preview" />
</fieldset>
</form>
</form>
::
<!-- peer cannot respond -->
<p>
@ -57,19 +57,19 @@
</p>
#(/permission)#
::
<!-- =========================== preview message =========================== -->
<!-- (mode=1) =========================== preview message =========================== -->
<h2>Preview message</h2>
#(permission)#
<!-- we have no permission to send the message -->
<p>You cannot send a message to <strong>#[peerName]#</strong>.<br />
The peer does not respond. It was now removed from the peer-list.
The peer does not respond. It was now removed from the peer-list.
</p>
::
<!-- we have the permission to send the message -->
<p>The peer <b>#[peerName]#</b> is alive and responded:</p>
<p><tt class="MessageBackground">#[response]#
You are allowed to send me a message &le; #[messagesize]# kb and an
attachment &le; #[attachmentsize]#.</tt>
You are allowed to send me a message &le; #[messagesize]# kb and an
attachment &le; #[attachmentsize]#.</tt>
</p>
<p>The message has not been sent yet!</p>
@ -91,24 +91,24 @@
<form action="MessageSend_p.html" method="post" enctype="multipart/form-data" accept-charset="UTF-8">
<fieldset>
<legend>Your Message</legend>
<dl>
<dt>
<label for="subject">Subject:</label>
</dt>
<dd>
<input name="subject" id="subject" type="text" size="80" maxlength="80" value="#[subject]#" />
</dd>
<dt>
<label for="message">Text:</label>
</dt>
<dd>
<textarea name="message" id="message" cols="80" rows="8">#[message]#</textarea>
<p class="help">
You can use <a href="WikiHelp.html" onclick="window.open('WikiHelp.html','WikiHelp','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');return false;">Wiki Code</a> here.
</p>
</dd>
</dl>
<legend>Your Message</legend>
<dl>
<dt>
<label for="subject">Subject:</label>
</dt>
<dd>
<input name="subject" id="subject" type="text" size="80" maxlength="80" value="#[subject]#" />
</dd>
<dt>
<label for="message">Text:</label>
</dt>
<dd>
<textarea name="message" id="message" cols="80" rows="8">#[message]#</textarea>
<p class="help">
You can use <a href="WikiHelp.html" onclick="window.open('WikiHelp.html','WikiHelp','toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=640,height=480');return false;">Wiki Code</a> here.
</p>
</dd>
</dl>
<input type="hidden" name="hash" value="#[hash]#" />
<input type="hidden" name="messagesize" value="#[messagesize]#" />
<input type="hidden" name="attachmentsize" value="#[attachmentsize]#" />
@ -124,16 +124,16 @@
</p>
#(/permission)#
::
<!-- =========================== send message =========================== -->
<!-- (mode=2) =========================== send message =========================== -->
<h2>Send message</h2>
#(status)#
<!-- Message send successfully -->
<p>Your message has been sent. The target peer responded:</p>
<p class="Message"><tt>#[response]#</tt></p>
:: <!-- Message could not be send -->
<p>The target peer is alive but did not receive your message. Sorry.</p>
<p>
Here is a copy of your message, so you can copy it to save it for further attempts:
@ -142,12 +142,12 @@
<tt>#[message]#</tt>
</p>
#(/status)#
::
<!-- illegal usage of this page -->
<p>You cannot call this page directly. Instead, use a link on the <a href="Network.html">Network</a> page.</p>
<!-- (mode=3) ==== illegal usage of this page ==== -->
<p>You cannot call this page directly. Instead, use a link on the <a href="Network.html?page=1&maxCount=1000">Network</a> page.</p>
#(/mode)#
#%env/templates/footer.template%#
</body>
</html>

@ -60,7 +60,7 @@ public class MessageSend_p {
final serverObjects prop = new serverObjects();
if ((post == null) || (post.get("hash","").isEmpty())) {
prop.put("mode", "2");
prop.put("mode", "3");
return prop;
}
@ -78,52 +78,58 @@ public class MessageSend_p {
// open an editor page for the message
// first ask if the other peer is online, and also what kind of document it accepts
Seed seed = sb.peers.getConnected(ASCII.getBytes(hash));
for(String ip: seed.getIPs()) {
final Map<String, String> result = Protocol.permissionMessage(seed.getPublicAddress(ip), hash);
//System.out.println("DEBUG: permission request result = " + result.toString());
String peerName;
Seed targetPeer = null;
if (hash.equals(sb.peers.mySeed().hash)) {
peerName = sb.peers.mySeed().get(Seed.NAME,"nameless");
} else {
targetPeer = sb.peers.getConnected(hash);
if (targetPeer == null)
peerName = "nameless";
else
peerName = targetPeer.get(Seed.NAME,"nameless");
}
prop.putXML("mode_permission_peerName", peerName);
final String response = (result == null) ? null : result.get("response");
if (response == null || result == null) {
// we don't have permission or other peer does not exist
prop.put("mode_permission", "0");
if (targetPeer != null) {
sb.peers.peerActions.interfaceDeparture(targetPeer, ip);
if (seed != null) {
for (String ip : seed.getIPs()) {
final Map<String, String> result = Protocol.permissionMessage(seed.getPublicAddress(ip), hash);
//System.out.println("DEBUG: permission request result = " + result.toString());
String peerName;
Seed targetPeer = null;
if (hash.equals(sb.peers.mySeed().hash)) {
peerName = sb.peers.mySeed().get(Seed.NAME, "nameless");
} else {
targetPeer = sb.peers.getConnected(hash);
if (targetPeer == null) {
peerName = "nameless";
} else {
peerName = targetPeer.get(Seed.NAME, "nameless");
}
}
} else {
prop.put("mode_permission", "1");
// write input form
try {
final int messagesize = Integer.parseInt(result.get("messagesize"));
final int attachmentsize = Integer.parseInt(result.get("attachmentsize"));
prop.putXML("mode_permission_response", response);
prop.put("mode_permission_messagesize", messagesize);
prop.put("mode_permission_attachmentsize", attachmentsize);
prop.putXML("mode_permission_subject", subject);
prop.putXML("mode_permission_message", message);
prop.putHTML("mode_permission_hash", hash);
if (post.containsKey("preview")) {
prop.putWiki(sb.peers.mySeed().getPublicAddress(ip), "mode_permission_previewmessage", message);
prop.putXML("mode_permission_peerName", peerName);
final String response = (result == null) ? null : result.get("response");
if (response == null || result == null) {
// we don't have permission or other peer does not exist
prop.put("mode_permission", "0");
if (targetPeer != null) {
sb.peers.peerActions.interfaceDeparture(targetPeer, ip);
}
} else {
prop.put("mode_permission", "1");
// write input form
try {
final int messagesize = Integer.parseInt(result.get("messagesize"));
final int attachmentsize = Integer.parseInt(result.get("attachmentsize"));
prop.putXML("mode_permission_response", response);
prop.put("mode_permission_messagesize", messagesize);
prop.put("mode_permission_attachmentsize", attachmentsize);
prop.putXML("mode_permission_subject", subject);
prop.putXML("mode_permission_message", message);
prop.putHTML("mode_permission_hash", hash);
if (post.containsKey("preview")) {
prop.putWiki(sb.peers.mySeed().getPublicAddress(ip), "mode_permission_previewmessage", message);
}
} catch (final NumberFormatException e) {
// "unresolved pattern", the remote peer is alive but had an exception
prop.put("mode_permission", "2");
}
} catch (final NumberFormatException e) {
// "unresolved pattern", the remote peer is alive but had an exception
prop.put("mode_permission", "2");
}
}
} else { // seed == null
prop.put("mode_permission", "0");
prop.putXML("mode_permission_peerName", "a passive peer");
}
} else {
prop.put("mode", "2");
@ -140,7 +146,7 @@ public class MessageSend_p {
SeedDB seedDB = sb.peers;
// prepare request
final String salt = crypt.randomSalt();
// send request
final Map<String, ContentBody> parts = Protocol.basicRequestParts(Switchboard.getSwitchboard(), hash, salt);
parts.put("process", UTF8.StringBody("post"));

Loading…
Cancel
Save