Skip to content
This repository has been archived by the owner on Nov 21, 2021. It is now read-only.

Commit

Permalink
Merge pull request #92 from rolandweber/various-20191110
Browse files Browse the repository at this point in the history
Bunch of improvements
  • Loading branch information
rolandweber authored Nov 10, 2019
2 parents 257f4b1 + 6b9dd98 commit 1f2e6ec
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 82 deletions.
18 changes: 16 additions & 2 deletions ant/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
terms of the Creative Commons CC0 1.0 Universal license.
https://creativecommons.org/publicdomain/zero/1.0/
-->
<project name="setup" basedir="..">
<project name="setup" basedir=".."
xmlns:if="ant:if" xmlns:unless="ant:unless">
<!-- ${basedir} is the root directory for input files (source).
${projectdir} is the root directory for all generated files.
To treat ${basedir} as read-only, point ${projectdir} somewhere else.
Expand Down Expand Up @@ -62,7 +63,11 @@
</presetdef>


<presetdef name="jdoc.pty">
<condition property="use-javadoc-stylesheet">
<equals arg1="${ant.java.version}" arg2="1.8" />
</condition>

<presetdef name="jdoc.pty" if:set="use-javadoc-stylesheet">
<javadoc failonerror="true"
access="protected"
stylesheetfile="src/main/prose/pityoulish-jdocs.css"
Expand All @@ -72,6 +77,15 @@
</javadoc>
</presetdef>

<presetdef name="jdoc.pty" unless:set="use-javadoc-stylesheet">
<javadoc failonerror="true"
access="protected"
nohelp="true"
encoding="ISO-8859-1"
>
</javadoc>
</presetdef>


<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Targets: timestamps and cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void putMessage(String tictok, String text)

try {
// Ticket and TicketManager are thread safe, MessageBoard is not
Ticket tick = ticketMgr.lookupTicket(tictok, null);
Ticket tick = ticketMgr.lookupTicket(tictok, null, Util.getClientHost());
if (tick.punch())
{
synchronized (msgBoard) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void publishOutlet(String tictok, DirectMessageOutlet outlet)
Ticket tick = null;
try {
// Ticket and TicketManager are thread safe
tick = ticketMgr.lookupTicket(tictok, null);
tick = ticketMgr.lookupTicket(tictok, null, Util.getClientHost());
if (!tick.punch())
throw Catalog.log(logger, "publishOutlet", Catalog.TICKET_USED_UP_1
.asApiX(tick.getToken()));
Expand Down Expand Up @@ -149,7 +149,7 @@ public void unpublishOutlet(String tictok)

try {
// Ticket and TicketManager are thread safe
Ticket tick = ticketMgr.lookupTicket(tictok, null);
Ticket tick = ticketMgr.lookupTicket(tictok, null, Util.getClientHost());
if (tick.punch())
{
final String username = tick.getUsername();
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/pityoulish/jrmi/server/RemoteTicketIssuerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public String obtainTicket(String username)
throw Catalog.log(logger, "obtainTicket", apix);

try {
Ticket tick = ticketMgr.obtainTicket(username, null);
Ticket tick = ticketMgr.obtainTicket(username, null,
Util.getClientHost());

System.out.println(Catalog.REPORT_OBTAIN_TICKET_2.format
(username, tick.getToken()));
Expand All @@ -87,7 +88,7 @@ public void returnTicket(String tictok)
throw Catalog.log(logger, "returnTicket", apix);

try {
Ticket tick = ticketMgr.lookupTicket(tictok, null);
Ticket tick = ticketMgr.lookupTicket(tictok, null, Util.getClientHost());
ticketMgr.returnTicket(tick);

System.out.println(Catalog.REPORT_RETURN_TICKET_1.format
Expand All @@ -110,10 +111,11 @@ public String replaceTicket(String tictok)
throw Catalog.log(logger, "replaceTicket", apix);

try {
Ticket tick = ticketMgr.lookupTicket(tictok, null);
Ticket tick = ticketMgr.lookupTicket(tictok, null, Util.getClientHost());
ticketMgr.returnTicket(tick);

tick = ticketMgr.obtainTicket(tick.getUsername(), null);
tick = ticketMgr.obtainTicket(tick.getUsername(), null,
Util.getClientHost());

System.out.println(Catalog.REPORT_REPLACE_TICKET_2.format
(tick.getUsername(), tick.getToken()));
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/pityoulish/jrmi/server/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* This work is released into the Public Domain under the
* terms of the Creative Commons CC0 1.0 Universal license.
* https://creativecommons.org/publicdomain/zero/1.0/
*/
package pityoulish.jrmi.server;

import java.rmi.server.RemoteServer;
import java.rmi.server.ServerNotActiveException;


/**
* Server-side utility methods.
*/
public class Util
{
/** Disabled default constructor. */
private Util()
{
throw new UnsupportedOperationException("no instances of this class");
}


/**
* Determines the host from which the remote call initiates, if available.
*
* @return the calling host, or <code>null</code>
*/
public static String getClientHost()
{
String host = null;

try {
host = RemoteServer.getClientHost();
} catch (ServerNotActiveException snax) {
// ignore
}

return host;
}

}
1 change: 1 addition & 0 deletions src/main/java/pityoulish/sockets/client/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum Catalog implements TextEntry
RECEIVE_TOO_LONG_2,
RECEIVE_INCOMPLETE_0,
RECEIVE_EXCESS_DATA_2,
RECEIVE_HTTP_INSTEAD_OF_TLV_0,

CONSOLE_INFO_TEXT_1,
CONSOLE_ERROR_TEXT_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ RECEIVE_INCOMPLETE_0 = \
RECEIVE_EXCESS_DATA_2 = \
MBSC022: Excess data after response: {0} > {1}

RECEIVE_HTTP_INSTEAD_OF_TLV_0 = \
MBSC023: Received HTTP response instead of a TLV.


# All-uppercase terms in the CONSOLE_ messages are TLV types.
# Treat them like message codes and keep them literally in translations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ RECEIVE_INCOMPLETE_0 = \
RECEIVE_EXCESS_DATA_2 = \
MBSC022: \u00dcbersch\u00fcssige Daten nach der Antwort: {0} > {1}

RECEIVE_HTTP_INSTEAD_OF_TLV_0 = \
MBSC023: HTTP statt einem TLV empfangen.


# All-uppercase terms in the CONSOLE_ messages are TLV types.
# Treat them like message codes and keep them literally in translations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ public ByteBuffer readResponse(Socket sock)
pos += count;
}

if ((data[0] == 'H') &&
(data[1] == 'T') &&
(data[2] == 'T') &&
(data[3] == 'P') ) {
// happens often enough to merit a dedicated check and error message
throw new Exception(Catalog.RECEIVE_HTTP_INSTEAD_OF_TLV_0.format());
}

// Responses are in TLV format, see ASN.1 BER
// byte 1: type of the response
// byte 2: length of length, value 0x82 indicating 2 bytes for the length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public MsgBoardRequestHandlerImpl(UserMessageBoard umb, TicketManager tm)
}

try {
Ticket tick = ticketMgr.lookupTicket(mbreq.getTicket(), address);
Ticket tick = ticketMgr.lookupTicket(mbreq.getTicket(), address, null);
if (tick.punch())
{
msgBoard.putMessage(tick.getUsername(), mbreq.getText());
Expand Down Expand Up @@ -178,7 +178,8 @@ public MsgBoardRequestHandlerImpl(UserMessageBoard umb, TicketManager tm)
}

try {
Ticket tick = ticketMgr.obtainTicket(mbreq.getOriginator(), address);
Ticket tick = ticketMgr.obtainTicket(mbreq.getOriginator(),
address, null);

return new MsgBoardResponseImpl.Ticket(tick.getToken());

Expand Down Expand Up @@ -215,7 +216,7 @@ public MsgBoardRequestHandlerImpl(UserMessageBoard umb, TicketManager tm)
}

try {
Ticket tick = ticketMgr.lookupTicket(mbreq.getTicket(), address);
Ticket tick = ticketMgr.lookupTicket(mbreq.getTicket(), address, null);
ticketMgr.returnTicket(tick);

} catch (TicketException tx) {
Expand Down Expand Up @@ -253,10 +254,10 @@ public MsgBoardRequestHandlerImpl(UserMessageBoard umb, TicketManager tm)
}

try {
Ticket tick = ticketMgr.lookupTicket(mbreq.getTicket(), address);
Ticket tick = ticketMgr.lookupTicket(mbreq.getTicket(), address, null);
ticketMgr.returnTicket(tick);

tick = ticketMgr.obtainTicket(tick.getUsername(), address);
tick = ticketMgr.obtainTicket(tick.getUsername(), address, null);

return new MsgBoardResponseImpl.Ticket(tick.getToken());

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/pityoulish/tickets/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ public enum Catalog implements TextEntry
WRONG_TOKEN,
WRONG_USERNAME,
WRONG_NETWORK_ADDRESS,
WRONG_NETWORK_HOST,
TICKET_NOT_FOUND_1,
TICKET_EXPIRED,
USER_ALREADY_HAS_TICKET_1,
ADDRESS_ALREADY_HAS_TICKET_1,
HOST_ALREADY_HAS_TICKET_1,

USERNAME_EMPTY,
USERNAME_TOO_SHORT_1,
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/pityoulish/tickets/CatalogData.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,36 @@ WRONG_USERNAME = \
WRONG_NETWORK_ADDRESS = \
MBTM004: Wrong network address.

WRONG_NETWORK_HOST = \
MBTM005: Wrong host name.

TICKET_NOT_FOUND_1 = \
MBTM005: Ticket "{0}" not found.
MBTM006: Ticket "{0}" not found.

TICKET_EXPIRED = \
MBTM006: Ticket already expired.
MBTM007: Ticket already expired.

USER_ALREADY_HAS_TICKET_1 = \
MBTM007: User "{0}" already has a ticket.
MBTM008: User "{0}" already has a ticket.

ADDRESS_ALREADY_HAS_TICKET_1 = \
MBTM008: Network address {0} already has a ticket.
MBTM009: Network address {0} already has a ticket.

HOST_ALREADY_HAS_TICKET_1 = \
MBTM010: Host {0} already has a ticket.


USERNAME_EMPTY = \
MBTM009: The username is empty.
MBTM011: The username is empty.

USERNAME_TOO_SHORT_1 = \
MBTM010: The username is too short, minimum length is {0}.
MBTM012: The username is too short, minimum length is {0}.

USERNAME_TOO_LONG_1 = \
MBTM011: The username is too long, maximum length is {0}.
MBTM013: The username is too long, maximum length is {0}.

USERNAME_BAD_CHARACTER = \
MBTM012: The username contains an invalid character.
MBTM014: The username contains an invalid character.

TOKEN_EMPTY = \
MBTM013: The ticket token is empty.
MBTM015: The ticket token is empty.
24 changes: 15 additions & 9 deletions src/main/java/pityoulish/tickets/CatalogData_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,36 @@ WRONG_USERNAME = \
WRONG_NETWORK_ADDRESS = \
MBTM004: Falsche Netzwerkadresse.

WRONG_NETWORK_HOST = \
MBTM005: Falscher Rechnername.

TICKET_NOT_FOUND_1 = \
MBTM005: Ticket "{0}" nicht gefunden.
MBTM006: Ticket "{0}" nicht gefunden.

TICKET_EXPIRED = \
MBTM006: Ticket abgelaufen.
MBTM007: Ticket abgelaufen.

USER_ALREADY_HAS_TICKET_1 = \
MBTM007: Benutzer "{0}" hat schon ein Ticket.
MBTM008: Benutzer "{0}" hat schon ein Ticket.

ADDRESS_ALREADY_HAS_TICKET_1 = \
MBTM008: Netzwerkadresse {0} hat schon ein Ticket.
MBTM009: Netzwerkadresse {0} hat schon ein Ticket.

HOST_ALREADY_HAS_TICKET_1 = \
MBTM010: Rechner {0} hat schon ein Ticket.


USERNAME_EMPTY = \
MBTM009: Der Benutzername ist leer.
MBTM011: Der Benutzername ist leer.

USERNAME_TOO_SHORT_1 = \
MBTM010: Der Benutzername ist zu kurz. Mindestl\u00e4nge: {0}
MBTM012: Der Benutzername ist zu kurz. Mindestl\u00e4nge: {0}

USERNAME_TOO_LONG_1 = \
MBTM011: Der Benutzername ist zu lang. Maximale L\u00e4nge: {0}
MBTM013: Der Benutzername ist zu lang. Maximale L\u00e4nge: {0}

USERNAME_BAD_CHARACTER = \
MBTM012: Der Benutzername enth\u00e4lt ein ung\u00fcltiges Zeichen.
MBTM014: Der Benutzername enth\u00e4lt ein ung\u00fcltiges Zeichen.

TOKEN_EMPTY = \
MBTM013: Das Ticketk\u00fcrzel ist leer.
MBTM015: Das Ticketk\u00fcrzel ist leer.
Loading

0 comments on commit 1f2e6ec

Please sign in to comment.