summaryrefslogtreecommitdiff
path: root/zwgc/subscriptions.c
diff options
context:
space:
mode:
authorGravatar John Kohl <jtkohl@mit.edu>1989-11-15 06:35:33 +0000
committerGravatar John Kohl <jtkohl@mit.edu>1989-11-15 06:35:33 +0000
commite85c1cf099e4c6b863675623fd59c0c711fd1239 (patch)
treedffaf37ba6b2ffef1f9fa5e8295fadd3bfe2c605 /zwgc/subscriptions.c
parentf51f5b84d81d8b1b1d887dd4918ae58e521a94ce (diff)
add stuff for %host%, %canon% support
Diffstat (limited to 'zwgc/subscriptions.c')
-rw-r--r--zwgc/subscriptions.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/zwgc/subscriptions.c b/zwgc/subscriptions.c
index 34165cf..f091006 100644
--- a/zwgc/subscriptions.c
+++ b/zwgc/subscriptions.c
@@ -13,7 +13,7 @@
*/
#if (!defined(lint) && !defined(SABER))
-static char rcsid_subscriptions_c[] = "$Header$";
+static char rcsid_subscriptions_c[] = "$Id$";
#endif
#include <zephyr/mit-copyright.h>
@@ -26,6 +26,8 @@ static char rcsid_subscriptions_c[] = "$Header$";
#include <stdio.h>
#include <zephyr/zephyr.h>
+#include <sys/param.h>
+#include <netdb.h>
#include "new_memory.h"
#include "new_string.h"
#include "int_dictionary.h"
@@ -215,11 +217,44 @@ static void unsubscribe(class, instance, recipient)
/* */
/****************************************************************************/
+#define TOKEN_HOSTNAME "%host%"
+#define TOKEN_CANONNAME "%canon%"
+#define TOKEN_ME "%me%"
+#define TOKEN_WILD "*"
+
+char ourhost[MAXHOSTNAMELEN],ourhostcanon[MAXHOSTNAMELEN];
+
+static void inithosts()
+{
+ struct hostent *hent;
+ if (gethostname(ourhost,sizeof(ourhost)-1) == -1) {
+ ERROR3("unable to retrieve hostname, %s and %s will be wrong in subscriptions.", TOKEN_HOSTNAME, TOKEN_CANONNAME);
+ return;
+ }
+
+ if (!(hent = gethostbyname(ourhost))) {
+ ERROR2("unable to resolve hostname, %s will be wrong in subscriptions.", TOKEN_CANONNAME);
+ return;
+ }
+ (void) strncpy(ourhostcanon,hent->h_name, sizeof(ourhostcanon)-1);
+ return;
+}
+
static void macro_sub(str)
char *str;
{
- if (string_Eq(str, "%me%"))
- strcpy(str, ZGetSender());
+ static int initedhosts = 0;
+
+ if (!initedhosts) {
+ inithosts();
+ initedhosts = 1;
+ }
+ if (string_Eq(str, TOKEN_ME))
+ strcpy(str, ZGetSender());
+ else if (string_Eq(str, TOKEN_HOSTNAME))
+ strcpy(str, ourhost);
+ else if (string_Eq(str, TOKEN_CANONNAME))
+ strcpy(str, ourhostcanon);
}
#define UNSUBSCRIBE_CHARACTER '!'