Migrate certificates, icons, logs to XDG dirs
[pidgin-git.git] / libpurple / protocols / zephyr / ZLocations.c
bloba61e63864a6647464bad01ff02457657c75b3173
1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It contains source for the ZSetLocation, ZUnsetLocation, and
3 * ZFlushMyLocations functions.
5 * Created by: Robert French
7 * Copyright (c) 1987,1988,1991 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, see the file
9 * "mit-copyright.h".
12 #include "internal.h"
14 #ifndef WIN32
15 #include <pwd.h>
16 #endif
18 #include <stdlib.h>
19 #include <errno.h>
21 Code_t ZSetLocation(exposure)
22 char *exposure;
24 return (Z_SendLocation(LOGIN_CLASS, exposure, ZAUTH,
25 "$sender logged in to $1 on $3 at $2"));
28 Code_t ZUnsetLocation()
30 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_LOGOUT, ZNOAUTH,
31 "$sender logged out of $1 on $3 at $2"));
34 Code_t ZFlushMyLocations()
36 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, ""));
39 static char host[MAXHOSTNAMELEN];
40 static char *mytty = NULL;
41 static int reenter = 0;
43 Code_t Z_SendLocation(class, opcode, auth, format)
44 char *class;
45 char *opcode;
46 Z_AuthProc auth;
47 char *format;
49 int retval;
50 time_t ourtime;
51 ZNotice_t notice, retnotice;
52 char *bptr[3];
53 #ifndef X_DISPLAY_MISSING
54 char *display;
55 #endif
56 #ifndef WIN32
57 char *ttyp;
58 char *p;
59 #endif
60 struct hostent *hent;
61 short wg_port = ZGetWGPort();
63 (void) memset((char *)&notice, 0, sizeof(notice));
64 notice.z_kind = ACKED;
65 notice.z_port = (unsigned short) ((wg_port == -1) ? 0 : wg_port);
66 notice.z_class = class;
67 notice.z_class_inst = ZGetSender();
68 notice.z_opcode = opcode;
69 notice.z_sender = 0;
70 notice.z_recipient = "";
71 notice.z_num_other_fields = 0;
72 notice.z_default_format = format;
75 keep track of what we said before so that we can be consistent
76 when changing location information.
77 This is done mainly for the sake of the WindowGram client.
80 if (!reenter) {
81 if (gethostname(host, MAXHOSTNAMELEN) < 0)
82 return (errno);
84 hent = gethostbyname(host);
85 if (hent) {
86 (void) strncpy(host, hent->h_name, sizeof(host));
87 host[sizeof(host) - 1] = '\0';
89 #ifndef X_DISPLAY_MISSING
90 if ((display = getenv("DISPLAY")) && *display) {
91 mytty = g_strdup(display);
92 } else {
93 #endif
94 #ifdef WIN32
95 mytty = g_strdup("WinPurple");
96 #else
97 ttyp = ttyname(0);
98 if (ttyp && *ttyp) {
99 p = strchr(ttyp + 1, '/');
100 mytty = g_strdup((p) ? p + 1 : ttyp);
101 } else {
102 mytty = g_strdup("unknown");
104 #endif
105 #ifndef X_DISPLAY_MISSING
107 #endif
108 reenter = 1;
111 ourtime = time((time_t *)0);
112 bptr[0] = host;
113 bptr[1] = ctime(&ourtime);
114 bptr[1][strlen(bptr[1])-1] = '\0';
115 bptr[2] = mytty;
117 if ((retval = ZSendList(&notice, bptr, 3, auth)) != ZERR_NONE)
118 return (retval);
120 retval = Z_WaitForNotice (&retnotice, ZCompareUIDPred, &notice.z_uid,
121 SRV_TIMEOUT);
122 if (retval != ZERR_NONE)
123 return retval;
125 if (retnotice.z_kind == SERVNAK) {
126 if (!retnotice.z_message_len) {
127 ZFreeNotice(&retnotice);
128 return (ZERR_SERVNAK);
130 if (!strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) {
131 ZFreeNotice(&retnotice);
132 return (ZERR_AUTHFAIL);
134 if (!strcmp(retnotice.z_message, ZSRVACK_FAIL)) {
135 ZFreeNotice(&retnotice);
136 return (ZERR_LOGINFAIL);
138 ZFreeNotice(&retnotice);
139 return (ZERR_SERVNAK);
142 if (retnotice.z_kind != SERVACK) {
143 ZFreeNotice(&retnotice);
144 return (ZERR_INTERNAL);
147 if (!retnotice.z_message_len) {
148 ZFreeNotice(&retnotice);
149 return (ZERR_INTERNAL);
152 if (strcmp(retnotice.z_message, ZSRVACK_SENT) &&
153 strcmp(retnotice.z_message, ZSRVACK_NOTSENT)) {
154 ZFreeNotice(&retnotice);
155 return (ZERR_INTERNAL);
158 ZFreeNotice(&retnotice);
160 return (ZERR_NONE);