EXIT terminates the daemon, DUMP returns the whole list but this is not handled by portDaemonCommand.
The return message may be the following
REGISTER id hostaddr port mode
LOOKUP id hostaddr port mode
REMOVE id hostaddr port mode
WARNING REGISTER ...
ERROR ...
Usually, the command is returned with the information about the processed port. The WARNING message occurs when an id has been replaced ERROR messages indicate syntax or user errors (host not found, etc)
Example strings:
"REGISTER a1 taltos 2002 TRANSIENT"
--> REGISTER a1 128.220.233.33 2002 TRANSIENT
"REGISTER a2 tarkus 2004 PERMANENT"
--> REGISTER a2 128.220.233.34 2004 PERMANENT
"LOOKUP a2"
--> LOOKUP a2 128.220.233.34 2004 PERMANENT
"LOOKUP a1"
--> LOOKUP a1 128.220.233.33 2002 TRANSIENT
"REGISTER a2 tilos 2005 TRANSIENT"
--> WARNING REGISTER a2 128.220.233.34 2004 PERMANENT was replaced by a2 128.220.233.47 2005 TRANSIENT
"LOOKUP a1"
--> ERROR LOOKUP Id Cannot find id a1: LOOKUP a1
For each attempt to read sockfd wait at most timeout seconds.
Read at most bufferMaxLenght-1 characters. Add a terminating
'\0' at the end of characters read into _buffer.
Return:
-2 when no newline is encountered (before EOF or buffer space runs out).
-3 if timeout forces a return.
-1 read (recv), select calls return an error.
0 o.w.
Bugs:
1. Any data after the '\n' is lost.
Comments:
1. Scheme for infinite timeout is left out. Does not seem essential.
int readLine(const RWSocketPortal& portal, uint16 timeout, char* _buffer,
uint16 bufferMaxLength);
The return values are
0 OK, request complete, msg contains returned string.
1 WARNING, a REGISTER command has replaced an existing entry
2 ERROR, the msg contains an unprocessable string (syntax error)
or the LOOKUP has failed (id not found). msg contains detailed
error messages:
ERROR Cannot understand message (error in input)
ERROR LOOKUP Id Cannot find id aaa
-2 The port Deaemon is possibly not running
-1 Unexpected error
int portDaemonCommand (const char *user, const char * passwd,
const char *inmsg, char*& _outmsg);