add %NAME% and %HOST% token master
authorMalte S. Stretz <mss@apache.org>
Tue, 5 Jul 2011 22:31:02 +0000 (00:31 +0200)
committerMalte S. Stretz <mss@apache.org>
Tue, 5 Jul 2011 22:31:02 +0000 (00:31 +0200)
Just because we can.

doc/knockd.1.in
src/knockd.c

index 643f4b0..bf1cd4e 100644 (file)
@@ -190,9 +190,15 @@ since \fBStart_Command\fP has been executed.The same token as in
 The following token are recognized in the \fBStart_Command\fP and
 \fBStop_Command\fP directives:
 .TP
+.B "%HOST%"
+The knocker's resolved hostname (if available).
+.TP
 .B "%IP%"
 The knocker's IP address.
 .TP
+.B "%NAME%"
+The name of the event.
+.TP
 .B "%TIME%"
 The UNIX timestamp.  Can be used to garbage-collect old rules via \fBcron\fP
 and the \fBcomment\fP module.  A wrapper script must then be used if separate
index e911f84..7459424 100644 (file)
@@ -1143,6 +1143,31 @@ ssize_t parse_cmd(char* dest, size_t size, const char* cmd, const knocker_t* kno
                                        }
                                        total_len += now_len;
                                }
+                               /* paste the door's name if this is the NAME token */
+                               else if(memcmp(tok, "NAME", tok_len) == 0) {
+                                       const char *name = knocker->door->name;
+                                       int name_len = strlen(name);
+                                       if(size >= name_len) {
+                                               memcpy(dest, name, name_len);
+                                               dest += name_len;
+                                               size -= name_len;
+                                       }
+                                       total_len += name_len;
+                               }
+                               /* paste the hostname, if available and this is the HOST token */
+                               else if(memcmp(tok, "HOST", tok_len) == 0) {
+                                       const char *host = knocker->srchost;
+                                       int host_len = 0;
+                                       if(host) {
+                                               host_len = strlen(host);
+                                       }
+                                       if(size >= host_len) {
+                                               memcpy(dest, host, host_len);
+                                               dest += host_len;
+                                               size -= host_len;
+                                       }
+                                       total_len += host_len;
+                               }
                                /* this must be an unknown token, bail out (will keep the) token 
                                 * pointer so the check below will make us return -1 */
                                else {