Skip to content

Commit

Permalink
fix unresolved_pattern on missing post parameter api/message.html
Browse files Browse the repository at this point in the history
  • Loading branch information
reger committed Apr 14, 2017
1 parent f664384 commit d3df8a4
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions htroot/yacy/message.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ public static String dateString(final Date date) {
}

public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
if (post == null || env == null) { return null; }

// return variable that accumulates replacements
final Switchboard sb = (Switchboard) env;
final serverObjects prop = new serverObjects();

prop.put("messagesize", "0");
prop.put("attachmentsize", "0");
prop.put("response", "-1"); // request rejected

if ((post == null) || (env == null)) return prop;
if (!Protocol.authentifyRequest(post, env)) return prop;

Expand All @@ -74,22 +78,17 @@ public static serverObjects respond(final RequestHeader header, final serverObje
final int messagesize = 10240;
final int attachmentsize = 0;

prop.put("messagesize", "0");
prop.put("attachmentsize", "0");

final String youare = post.get("youare", ""); // seed hash of the target peer, needed for network stability
// check if we are the right target and requester has correct information about this peer
if ((sb.peers.mySeed() == null) || (!(sb.peers.mySeed().hash.equals(youare)))) {
// this request has a wrong target
prop.put("response", "-1"); // request rejected
return prop;
}

if ((sb.isRobinsonMode()) &&
(!((sb.isPublicRobinson()) ||
(sb.isInMyCluster(header.getRemoteAddr()))))) {
if ((sb.isRobinsonMode())
&& (!((sb.isPublicRobinson())
|| (sb.isInMyCluster(header.getRemoteAddr()))))) {
// if we are a robinson cluster, answer only if this client is known by our network definition
prop.put("response", "-1"); // request rejected
return prop;
}

Expand All @@ -107,28 +106,28 @@ public static serverObjects respond(final RequestHeader header, final serverObje
// post: post message to message board
final String otherSeedString = post.get("myseed", "");
if (otherSeedString.isEmpty()) {
prop.put("response", "-1"); // request rejected
// request rejected
return prop;
}
//Date remoteTime = yacyCore.parseUniversalDate((String) post.get(yacySeed.MYTIME)); // read remote time
Seed otherSeed;
try {
otherSeed = Seed.genRemoteSeed(otherSeedString, false, ias == null ? null : ias.getHostAddress());
} catch (final IOException e) {
prop.put("response", "-1"); // don't accept messages for bad seeds
// don't accept messages for bad seeds
return prop;
}

String subject = crypt.simpleDecode(post.get("subject", "")); // message's subject
String message = crypt.simpleDecode(post.get("message", "")); // message body
if (subject == null || message == null) {
prop.put("response", "-1"); // don't accept empty messages
// don't accept empty messages
return prop;
}
message = message.trim();
subject = subject.trim();
if (subject.isEmpty() || message.isEmpty()) {
prop.put("response", "-1"); // don't accept empty messages
// don't accept empty messages
return prop;
}

Expand Down Expand Up @@ -156,7 +155,6 @@ public static serverObjects respond(final RequestHeader header, final serverObje

}
}
// System.out.println("respond = " + prop.toString());

// return rewrite properties
return prop;
Expand Down

0 comments on commit d3df8a4

Please sign in to comment.