]> code.citadel.org Git - citadel.git/blob - webcit/who.c
3b5de640d0cdaae182044ba1f65630294ce5723d
[citadel.git] / webcit / who.c
1 /* $Id$ */
2
3 #include <stdlib.h>
4 #ifdef HAVE_UNISTD_H
5 #include <unistd.h>
6 #endif
7 #include <stdio.h>
8 #include <signal.h>
9 #include <sys/types.h>
10 #include <ctype.h>
11 #include <string.h>
12 #include "webcit.h"
13 #include "child.h"
14
15 struct whouser {
16         struct whouser *next;
17         int sessionnum;
18         char username[256];
19         char roomname[256];
20         char hostname[256];
21         char clientsoftware[256];
22         };
23         
24 /*
25  * who is on?
26  */
27 void whobbs(void) {
28         struct whouser *wlist = NULL;
29         struct whouser *wptr = NULL;
30         char buf[256],sess,user[256],room[256],host[256];
31         int foundit;
32
33         printf("HTTP/1.0 200 OK\n");
34         output_headers(1);
35
36         wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=007700><TR><TD>");
37         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>Users currently on ");
38         escputs(serv_info.serv_humannode);
39         wprintf("</B></FONT></TD></TR></TABLE>\n");
40
41         wprintf("<CENTER><TABLE border><TR>");
42         wprintf("<TH>Session ID</TH><TH>User Name</TH><TH>Room</TH>");
43         wprintf("<TH>From host</TH></TR>\n");
44         serv_puts("RWHO");
45         serv_gets(buf);
46         if (buf[0]=='1') {
47                 while(serv_gets(buf), strcmp(buf,"000")) {
48                         sess = extract_int(buf, 0);
49                         extract(user, buf, 1);
50                         extract(room, buf, 2);
51                         extract(host, buf, 3);
52
53                         foundit = 0;
54                         for (wptr = wlist; wptr != NULL; wptr = wptr -> next) {
55                                 if (wptr->sessionnum == sess) {
56                                         foundit = 1;
57                                         if (strcasecmp(user, wptr->username)) {
58                                                 sprintf(buf, "%cBR%c%s", 
59                                                         LB, RB, user);
60                                                 strcat(wptr->username, buf);
61                                                 }
62                                         if (strcasecmp(room, wptr->roomname)) {
63                                                 sprintf(buf, "%cBR%c%s", 
64                                                         LB, RB, room);
65                                                 strcat(wptr->roomname, buf);
66                                                 }
67                                         if (strcasecmp(host, wptr->hostname)) {
68                                                 sprintf(buf, "%cBR%c%s", 
69                                                         LB, RB, host);
70                                                 strcat(wptr->hostname, buf);
71                                                 }
72                                         }
73                                 }
74
75                         if (foundit == 0) {
76                                 wptr = (struct whouser *)
77                                         malloc(sizeof(struct whouser));
78                                 wptr->next = wlist;
79                                 wlist = wptr;
80                                 strcpy(wlist->username, user);
81                                 strcpy(wlist->roomname, room);
82                                 strcpy(wlist->hostname, host);
83                                 wlist->sessionnum = sess;
84                                 }
85                         }
86
87                 while (wlist != NULL) {
88                         wprintf("<TR><TD>%d</TD><TD>", wlist->sessionnum);
89                         escputs(wlist->username);
90                         wprintf("</TD><TD>");
91                         escputs(wlist->roomname);
92                         wprintf("</TD><TD>");
93                         escputs(wlist->hostname);
94                         wprintf("</TD></TR>\n");
95                         wptr = wlist->next;
96                         free(wlist);
97                         wlist = wptr;
98                         }
99                 }
100         wprintf("</TABLE></CENTER>\n");
101         wprintf("</BODY></HTML>\n");
102         wDumpContent();
103         }
104
105