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