long LastActive;
int Session;
int Idle;
+ int IdleSince;
int SessionCount;
} UserStateStruct;
int GetWholistSection(HashList *List, time_t now)
{
StrBuf *Buf, *XBuf;
- struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
+ wcsession *WCC = WC;
UserStateStruct *User, *OldUser;
void *VOldUser;
size_t BufLen;
User->LastActive = StrBufExtract_long(Buf, 5, '|');
User->Idle = (now - User->LastActive) > 900L;
+ User->IdleSince = (now - User->LastActive) / 60;
User->SessionCount = 1;
if (GetHash(List,
return 0;
}
-/*
- * Display inner div of Wholist
- * /
-void who_inner_div(void) {
- UserStateStruct *User;
- void *VUser;
- char buf[SIZ];
- struct wcsession *WCC = WC;
- HashList *List;
- HashPos *it;
- const char *UserName;
- long len;
- time_t now;
- int bg = 0;
- wprintf("<table class=\"altern\">"
- "<tr>\n");
- wprintf("<th class=\"edit_col\"> </th>\n");
- wprintf("<th colspan=\"2\"> </th>\n");
- wprintf("<th>%s</th>\n", _("User name"));
- wprintf("<th>%s</th>", _("Room"));
- wprintf("<th class=\"host_col\">%s</th>\n</tr>\n", _("From host"));
-
- serv_puts("TIME");
- serv_getln(buf, sizeof buf);
-
- if (buf[0] == '2') {
- now = extract_long(&buf[4], 0);
- }
- else {
- now = time(NULL);
- }
-
- List = NewHash(1, NULL);
-
- if (GetWholistSection(List, now)) {
- it = GetNewHashPos();
- while (GetNextHashPos(List, it, &len, &UserName, &VUser)) {
- User = VUser;
- bg = 1 - bg;
- wprintf("<tr class=\"%s\">",
- (bg ? "even" : "odd")
- );
-
-
- wprintf("<td class=\"edit_col\">");
- if ((WCC->is_aide) &&
- (User->Session != WCC->ctdl_pid)) {
- wprintf(" <a href=\"terminate_session?which_session=%d", User->Session);
- wprintf("\" onClick=\"return ConfirmKill();\">%s</a>", _("(kill)"));
- }
- if (User->Session == WCC->ctdl_pid) {
- wprintf(" <a href=\"edit_me\">%s</a>", _("(edit)"));
- }
- wprintf("</td>");
-
- / * (link to page this user) * /
- wprintf("<td width=\"5%%\"><a href=\"display_page?recp=");
- UrlescPutStrBuf(User->UserName);
- wprintf("\">"
- "<img align=\"middle\" "
- "src=\"static/citadelchat_24x.gif\" "
- "alt=\"(p)\""
- " border=\"0\" /></a> ");
- wprintf("</td>");
-
- / * (idle flag) * /
- wprintf("<td width=\"5%%\">");
- if (User->Idle) {
- wprintf(" "
- "<img align=\"middle\" "
- "src=\"static/inactiveuser_24x.gif\" "
- "alt=\"(%s %ld %s)\" border=\"0\" />",
- _("idle since"),
- (now - User->LastActive) / 60,
- _("Minutes")
- );
-
- }
- else {
- wprintf(" "
- "<img align=\"middle\" "
- "src=\"static/activeuser_24x.gif\" "
- "alt=\"(active)\" border=\"0\" />");
- }
- wprintf("</td>\n<td>");
-
- / * username (link to user bio/photo page) * /
- wprintf("<a href=\"showuser?who=");
- UrlescPutStrBuf(User->UserName);
- wprintf("\">");
- StrEscPuts(User->UserName);
- if (User->SessionCount > 1)
- wprintf(" [%d] ", User->SessionCount);
- wprintf("</a>");
-
- / * room * /
- wprintf("</td>\n\t<td>");
- StrEscPuts(User->Room);
- if (StrLength(User->RealRoom) > 0) {
- wprintf("<br /><i>");
- StrEscPuts(User->RealRoom);
- wprintf("</i>");
- }
- wprintf("</td>\n\t<td class=\"host_col\">");
-
- / * hostname * /
- StrEscPuts(User->Host);
- if (StrLength(User->RealHost) > 0) {
- wprintf("<br /><i>");
- StrEscPuts(User->RealHost);
- wprintf("</i>");
- }
- wprintf("</td>\n</tr>");
- }
- DeleteHashPos(&it);
- }
- wprintf("</table>");
- DeleteHash(&List);
-}
-*/
-
-
-#if 0
-/*
- * Display a list of users currently logged in to the system
- * /
-void who(void)
-{
- char title[256];
-
- output_headers(1, 1, 2, 0, 0, 0);
-
- wprintf("<script type=\"text/javascript\">\n"
- "function ConfirmKill() { \n"
- "return confirm('%s');\n"
- "}\n"
- "</script>\n", _("Do you really want to kill this session?")
- );
-#endif
-
- wprintf("<div id=\"banner\">\n");
- wprintf("<div class=\"room_banner\">");
- wprintf("<img src=\"static/usermanag_48x.gif\">");
- wprintf("<h1>");
- snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
- escputs(title);
- wprintf("</h1></div>");
- wprintf("<ul class=\"room_actions\">\n");
- wprintf("<li class=\"start_page\">");
- offer_start_page();
- wprintf("</li></ul>");
- wprintf("</div>");
-
- wprintf("<div id=\"content\" class=\"fix_scrollbar_bug who_is_online\">\n");
- wprintf("<div class=\"box\">");
- wprintf("<div class=\"boxlabel\">");
- snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode);
- escputs(title);
- wprintf("</div>");
- wprintf("<div class=\"boxcontent\">");
- wprintf("<div id=\"who_inner\" >");
- who_inner_div();
- wprintf("</div>");
-
- wprintf("<div class=\"instructions\">");
- wprintf(_("Click on a name to read user info. Click on %s "
- "to send an instant message to that user."),
- "<img align=\"middle\" src=\"static/citadelchat_16x.gif\" alt=\"(p)\" border=\"0\">"
- );
- wprintf("</div></div>\n");
-
- / *
- * JavaScript to make the ajax refresh happen:
- * See http://www.sergiopereira.com/articles/prototype.js.html for info on Ajax.PeriodicalUpdater
- * It wants: 1. The div being updated
- * 2. The URL of the update source
- * 3. Other flags (such as the HTTP method and the refresh frequency)
- * /
- wprintf(
- "<script type=\"text/javascript\"> "
- " new Ajax.PeriodicalUpdater('who_inner', 'who_inner_html', "
- " { method: 'get', frequency: 30 } ); "
- "</script> \n"
- );
- wDumpContent(1);
-}
-*/
-#endif
-
/*
* end session
*/
serv_printf("TERM %s", bstr("which_session"));
serv_getln(buf, sizeof buf);
- ///who();
url_do_template();
}
}
}
-/*
- * Wholist section
- * /
-void wholist_section(void) {
- UserStateStruct *User;
- void *VUser;
- HashList *List;
- HashPos *it;
- const char *UserName;
- long len;
- char buf[SIZ];
- time_t now;
-
- serv_puts("TIME");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '2') {
- now = extract_long(&buf[4], 0);
- }
- else {
- now = time(NULL);
- }
-
- List = NewHash(1, NULL);
-
- if (GetWholistSection(List, now)) {
- SortByPayload(List, CompareUserStruct);
- it = GetNewHashPos();
- while (GetNextHashPos(List, it, &len, &UserName, &VUser)) {
- User = VUser;
- if (strcmp(ChrPtr(User->UserName), NLI)) {
- wprintf("<li class=\"");
- if (User->Idle) {
- wprintf("inactiveuser");
- }
- else {
- wprintf("activeuser");
- }
- wprintf("\"><a href=\"showuser?who=");
- UrlescPutStrBuf(User->UserName);
- wprintf("\">");
- StrEscPuts(User->UserName);
- wprintf("</a></li>");
- }
- }
- DeleteHashPos(&it);
- }
- DeleteHash(&List);
-}
-*/
-
void _terminate_session(void) {
slrp_highest();
terminate_session();
return List;
}
-void WholistSubst(StrBuf *TemplBuffer, void *vContext, WCTemplateToken *Token)
+
+void DeleteWholistHash(HashList **KillMe)
+{
+ DeleteHash(KillMe);
+}
+
+void tmplput_who_username(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
{
UserStateStruct *User = (UserStateStruct*) vContext;
+ StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->UserName, 0);
+}
- SVPutBuf("WHO:NAME", User->UserName, 1);
- SVPutBuf("WHO:ROOM", User->Room, 1);
- SVPutBuf("WHO:HOST", User->Host, 1);
- SVPutBuf("WHO:REALROOM", User->RealRoom, 1);
- SVPutBuf("WHO:REALHOST", User->RealHost, 1);
- svputlong("WHO:LASTACTIVE", User->LastActive);
- ///svputlong("WHO:IDLESINCE",(now - User->LastActive) / 60);//// todo
- svputlong("WHO:SESSION", User->Session);
- svputlong("WHO:IDLE", User->Idle);
- svputlong("WHO:NSESSIONS", User->SessionCount);
- svputlong("WHO:ISME", (User->Session == WC->ctdl_pid));
+void tmplput_who_room(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->Room, 0);
}
-void DeleteWholistHash(HashList **KillMe)
+void tmplput_who_host(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
{
- DeleteHash(KillMe);
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->Host, 0);
+}
+
+void tmplput_who_realroom(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->RealRoom, 0);
+}
+int conditional_who_realroom(WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ return StrLength(User->RealRoom) > 0;
+}
+
+void tmplput_who_realhost(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ StrBufAppendTemplate(Target, nArgs, Tokens, vContext, ContextType, User->RealHost, 0);
+}
+
+void tmplput_who_lastactive(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ StrBufAppendPrintf(Target, "%d", User->LastActive);
+}
+
+void tmplput_who_idlesince(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ StrBufAppendPrintf(Target, "%d", User->IdleSince);
+}
+
+void tmplput_who_session(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ StrBufAppendPrintf(Target, "%d", User->Session);
+}
+
+int conditional_who_idle(WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ return User->Idle;
+}
+
+int conditional_who_nsessions(WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ return User->SessionCount;
+}
+
+void tmplput_who_nsessions(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ StrBufAppendPrintf(Target, "%d", User->SessionCount);
+}
+
+int conditional_who_isme(WCTemplateToken *Tokens, void *vContext, int ContextType)
+{
+ UserStateStruct *User = (UserStateStruct*) vContext;
+ return (User->Session == WC->ctdl_pid);
}
void
InitModule_WHO
(void)
{
-/// WebcitAddUrlHandler(HKEY("who"), who, 0);
-// WebcitAddUrlHandler(HKEY("who_inner_html"), who_inner_div, AJAX);
-// WebcitAddUrlHandler(HKEY("wholist_section"), wholist_section, AJAX);
WebcitAddUrlHandler(HKEY("terminate_session"), _terminate_session, 0);
WebcitAddUrlHandler(HKEY("edit_me"), edit_me, 0);
- RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, WholistSubst, DeleteWholistHash, CTX_WHO);
+ RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG);
+
+ RegisterNamespace("WHO:NAME", 0, 1, tmplput_who_username, CTX_WHO);
+ RegisterNamespace("WHO:ROOM", 0, 1, tmplput_who_room, CTX_WHO);
+ RegisterNamespace("WHO:HOST", 0, 1, tmplput_who_host, CTX_WHO);
+ RegisterNamespace("WHO:REALROOM", 0, 1, tmplput_who_realroom, CTX_WHO);
+ RegisterNamespace("WHO:REALHOST", 0, 1, tmplput_who_realhost, CTX_WHO);
+ RegisterNamespace("WHO:LASTACTIVE", 0, 1, tmplput_who_lastactive, CTX_WHO);
+ RegisterNamespace("WHO:IDLESINCE", 0, 1, tmplput_who_idlesince, CTX_WHO);
+ RegisterNamespace("WHO:SESSION", 0, 1, tmplput_who_session, CTX_WHO);
+ RegisterNamespace("WHO:NSESSIONS", 0, 1, tmplput_who_nsessions, CTX_WHO);
+ RegisterNamespace("WHO:NSESSIONS", 0, 1, tmplput_who_nsessions, CTX_WHO);
+
+ RegisterConditional(HKEY("WHO:IDLE"), 1, conditional_who_idle, CTX_WHO);
+ RegisterConditional(HKEY("WHO:NSESSIONS"), 1, conditional_who_nsessions, CTX_WHO);
+ RegisterConditional(HKEY("WHO:ISME"), 1, conditional_who_isme, CTX_WHO);
+ RegisterConditional(HKEY("WHO:REALROOM"), 1, conditional_who_realroom, CTX_WHO);
}