X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fwho.c;h=11c68d86c99602c3c8dddf456e01d0e55e3a3925;hb=HEAD;hp=79ab3f43741599f124d9f6c6e55aa9ded4fc6e90;hpb=6ec73d6906542ea2f8cca2e62f7625ee2e17ae03;p=citadel.git diff --git a/webcit/who.c b/webcit/who.c index 79ab3f437..dee492caf 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -1,13 +1,13 @@ -/* - * $Id$ - */ #include "webcit.h" +CtxType CTX_WHO = CTX_NONE; + typedef struct UserStateStruct { StrBuf *UserName; StrBuf *Room; StrBuf *Host; + StrBuf *UserAgent; StrBuf *RealRoom; StrBuf *RealHost; long LastActive; @@ -25,6 +25,7 @@ void DestroyUserStruct(void *vUser) FreeStrBuf(&User->Host); FreeStrBuf(&User->RealRoom); FreeStrBuf(&User->RealHost); + FreeStrBuf(&User->UserAgent); free(User); } @@ -40,9 +41,8 @@ int CompareUserStruct(const void *VUser1, const void *VUser2) } -int GetWholistSection(HashList *List, time_t now, StrBuf *Buf) +int GetWholistSection(HashList *List, time_t now, StrBuf *Buf, const char *FilterName, long FNLen) { - wcsession *WCC = WC; UserStateStruct *User, *OldUser; void *VOldUser; size_t BufLen; @@ -51,7 +51,10 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf) serv_puts("RWHO"); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 1) { - while (BufLen = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) { + while (BufLen = StrBuf_ServGetln(Buf), + ((BufLen >= 0) && + ((BufLen != 3) || strcmp(ChrPtr(Buf), "000")))) + { if (BufLen <= 0) continue; Pos = NULL; @@ -67,7 +70,8 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf) User->Host = NewStrBufPlain(NULL, BufLen); StrBufExtract_NextToken(User->Host, Buf, &Pos, '|'); - StrBufSkip_NTokenS(Buf, &Pos, '|', 1); + User->UserAgent = NewStrBufPlain(NULL, BufLen); + StrBufExtract_NextToken(User->UserAgent, Buf, &Pos, '|'); User->LastActive = StrBufExtractNext_long(Buf, &Pos, '|'); StrBufSkip_NTokenS(Buf, &Pos, '|', 3); @@ -82,28 +86,41 @@ int GetWholistSection(HashList *List, time_t now, StrBuf *Buf) User->IdleSince = (now - User->LastActive) / 60; User->SessionCount = 1; - if (GetHash(List, - ChrPtr(User->UserName), - StrLength(User->UserName), - &VOldUser)) { - OldUser = VOldUser; - OldUser->SessionCount++; - if (!User->Idle) { - if (User->Session == WCC->ctdl_pid) - OldUser->Session = User->Session; - - OldUser->Idle = User->Idle; - OldUser->LastActive = User->LastActive; + if (FilterName == NULL) { + if (GetHash(List, + SKEY(User->UserName), + &VOldUser)) { + OldUser = VOldUser; + OldUser->SessionCount++; + if (!User->Idle) { + if (User->Session == WC->ctdl_pid) + OldUser->Session = User->Session; + + OldUser->Idle = User->Idle; + OldUser->LastActive = User->LastActive; + } + DestroyUserStruct(User); + } + else + Put(List, + SKEY(User->UserName), + User, DestroyUserStruct); + } + else { + if (strcmp(FilterName, ChrPtr(User->UserName)) == 0) + { + Put(List, + SKEY(User->UserName), + User, DestroyUserStruct); + } + else + { + DestroyUserStruct(User); } - DestroyUserStruct(User); } - else - Put(List, - ChrPtr(User->UserName), - StrLength(User->UserName), - User, DestroyUserStruct); } - SortByPayload(List, CompareUserStruct); + if (FilterName == NULL) + SortByPayload(List, CompareUserStruct); return 1; } else { @@ -124,86 +141,6 @@ void terminate_session(void) } -/* - * Change your session info (fake roomname and hostname) - */ -void edit_me(void) -{ - char buf[SIZ]; - - if (havebstr("change_room_name_button")) { - serv_printf("RCHG %s", bstr("fake_roomname")); - serv_getln(buf, sizeof buf); - http_redirect("who"); - } else if (havebstr("change_host_name_button")) { - serv_printf("HCHG %s", bstr("fake_hostname")); - serv_getln(buf, sizeof buf); - http_redirect("who"); - } else if (havebstr("change_user_name_button")) { - serv_printf("UCHG %s", bstr("fake_username")); - serv_getln(buf, sizeof buf); - http_redirect("who"); - } else if (havebstr("cancel_button")) { - http_redirect("who"); - } else { - output_headers(1, 1, 0, 0, 0, 0); - - wprintf("
\n"); - wprintf("
"); - wprintf(""); - wprintf(_("Edit your session display")); - wprintf("
\n"); - wprintf("
\n
\n"); - - wprintf(_("This screen allows you to change the way your " - "session appears in the 'Who is online' listing. " - "To turn off any 'fake' name you've previously " - "set, simply click the appropriate 'change' button " - "without typing anything in the corresponding box. ")); - wprintf("
\n"); - - wprintf("
\n"); - wprintf("\n", WC->nonce); - - wprintf("\n"); - - wprintf("\n\n\n\n"); - - wprintf("\n\n\n"); - - if (WC->is_aide) { - wprintf("\n\n\n"); - } - wprintf("
"); - wprintf(_("Room name:")); - wprintf(""); - wprintf("\n"); - wprintf(""); - wprintf("", - _("Change room name")); - wprintf("
"); - wprintf(_("Host name:")); - wprintf(""); - wprintf("\n"); - wprintf(""); - wprintf("", - _("Change host name")); - wprintf("
"); - wprintf(_("User name:")); - wprintf(""); - wprintf("\n"); - wprintf(""); - wprintf("", - _("Change user name")); - wprintf("
"); - wprintf("", - _("Cancel")); - wprintf("
\n"); - wprintf("
\n"); - wDumpContent(1); - } -} - void _terminate_session(void) { slrp_highest(); terminate_session(); @@ -212,6 +149,10 @@ void _terminate_session(void) { HashList *GetWholistHash(StrBuf *Target, WCTemplputParams *TP) { + const char *ch = NULL; + int HashUniq = 1; + long len; + StrBuf *FilterNameStr = NULL; StrBuf *Buf; HashList *List; time_t now; @@ -227,10 +168,17 @@ HashList *GetWholistHash(StrBuf *Target, WCTemplputParams *TP) else { now = time(NULL); } + if (HaveTemplateTokenString(NULL, TP, 2, &ch, &len)) + { + FilterNameStr = NewStrBuf(); + GetTemplateTokenString(FilterNameStr, TP, 2, &ch, &len); + HashUniq = 0; + } - List = NewHash(1, NULL); - GetWholistSection(List, now, Buf); + List = NewHash(HashUniq, NULL); + GetWholistSection(List, now, Buf, ch, len); FreeStrBuf(&Buf); + FreeStrBuf(&FilterNameStr); return List; } @@ -242,78 +190,89 @@ void DeleteWholistHash(HashList **KillMe) void tmplput_who_username(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->UserName, 0); } +void tmplput_who_UserAgent(StrBuf *Target, WCTemplputParams *TP) +{ + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); + StrBufAppendTemplate(Target, TP, User->UserAgent, 0); +} + void tmplput_who_room(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->Room, 0); } void tmplput_who_host(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->Host, 0); } void tmplput_who_realroom(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->RealRoom, 0); } int conditional_who_realroom(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); return StrLength(User->RealRoom) > 0; } void tmplput_who_realhost(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendTemplate(Target, TP, User->RealHost, 0); } +int conditional_who_realhost(StrBuf *Target, WCTemplputParams *TP) +{ + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); + return StrLength(User->RealHost) > 0; +} void tmplput_who_lastactive(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendPrintf(Target, "%d", User->LastActive); } void tmplput_who_idlesince(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendPrintf(Target, "%d", User->IdleSince); } void tmplput_who_session(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendPrintf(Target, "%d", User->Session); } int conditional_who_idle(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); return User->Idle; } int conditional_who_nsessions(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); return User->SessionCount; } void tmplput_who_nsessions(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); StrBufAppendPrintf(Target, "%d", User->SessionCount); } int conditional_who_isme(StrBuf *Target, WCTemplputParams *TP) { - UserStateStruct *User = (UserStateStruct*) CTX; + UserStateStruct *User = (UserStateStruct*) CTX(CTX_WHO); return (User->Session == WC->ctdl_pid); } @@ -321,14 +280,14 @@ void InitModule_WHO (void) { - + RegisterCTX(CTX_WHO); WebcitAddUrlHandler(HKEY("terminate_session"), "", 0, _terminate_session, 0); - WebcitAddUrlHandler(HKEY("edit_me"), "", 0, edit_me, 0); - RegisterIterator("WHOLIST", 0, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG); + RegisterIterator("WHOLIST", 1, NULL, GetWholistHash, NULL, DeleteWholistHash, CTX_WHO, CTX_NONE, IT_NOFLAG); RegisterNamespace("WHO:NAME", 0, 1, tmplput_who_username, NULL, CTX_WHO); + RegisterNamespace("WHO:USERAGENT", 0, 1, tmplput_who_UserAgent, NULL, CTX_WHO); RegisterNamespace("WHO:ROOM", 0, 1, tmplput_who_room, NULL, CTX_WHO); RegisterNamespace("WHO:HOST", 0, 1, tmplput_who_host, NULL, CTX_WHO); RegisterNamespace("WHO:REALROOM", 0, 1, tmplput_who_realroom, NULL, CTX_WHO); @@ -339,8 +298,9 @@ InitModule_WHO RegisterNamespace("WHO:NSESSIONS", 0, 1, tmplput_who_nsessions, NULL, CTX_WHO); RegisterNamespace("WHO:NSESSIONS", 0, 1, tmplput_who_nsessions, NULL, 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); + RegisterConditional("WHO:IDLE", 1, conditional_who_idle, CTX_WHO); + RegisterConditional("WHO:NSESSIONS", 1, conditional_who_nsessions, CTX_WHO); + RegisterConditional("WHO:ISME", 1, conditional_who_isme, CTX_WHO); + RegisterConditional("WHO:REALROOM", 1, conditional_who_realroom, CTX_WHO); + RegisterConditional("WHO:REALHOST", 1, conditional_who_realhost, CTX_WHO); }