X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fwho.c;h=11c68d86c99602c3c8dddf456e01d0e55e3a3925;hb=25220160fc09e185bbf9f13f7565bb568cc5a463;hp=c3df2556dfef80c3fa6824165d09b788c5112531;hpb=fcb8c4169baa629eb3c1a4979c7c8c32f1560389;p=citadel.git diff --git a/webcit/who.c b/webcit/who.c index c3df2556d..11c68d86c 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -1,10 +1,13 @@ #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; @@ -22,6 +25,7 @@ void DestroyUserStruct(void *vUser) FreeStrBuf(&User->Host); FreeStrBuf(&User->RealRoom); FreeStrBuf(&User->RealHost); + FreeStrBuf(&User->UserAgent); free(User); } @@ -37,7 +41,7 @@ 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; @@ -48,7 +52,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; @@ -64,7 +71,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); @@ -79,28 +87,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 == WCC->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 { @@ -121,86 +142,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); - - wc_printf("
\n"); - wc_printf("
"); - wc_printf(""); - wc_printf(_("Edit your session display")); - wc_printf("
\n"); - wc_printf("
\n
\n"); - - wc_printf(_("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. ")); - wc_printf("
\n"); - - wc_printf("
\n"); - wc_printf("\n", WC->nonce); - - wc_printf("\n"); - - wc_printf("\n\n\n\n"); - - wc_printf("\n\n\n"); - - if (WC->is_aide) { - wc_printf("\n\n\n"); - } - wc_printf("
"); - wc_printf(_("Room name:")); - wc_printf(""); - wc_printf("\n"); - wc_printf(""); - wc_printf("", - _("Change room name")); - wc_printf("
"); - wc_printf(_("Host name:")); - wc_printf(""); - wc_printf("\n"); - wc_printf(""); - wc_printf("", - _("Change host name")); - wc_printf("
"); - wc_printf(_("User name:")); - wc_printf(""); - wc_printf("\n"); - wc_printf(""); - wc_printf("", - _("Change user name")); - wc_printf("
"); - wc_printf("", - _("Cancel")); - wc_printf("
\n"); - wc_printf("
\n"); - wDumpContent(1); - } -} - void _terminate_session(void) { slrp_highest(); terminate_session(); @@ -209,6 +150,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; @@ -224,10 +169,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; } @@ -239,83 +191,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; + 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); } @@ -323,14 +281,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); @@ -341,9 +299,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(HKEY("WHO:REALHOST"), 1, conditional_who_realhost, 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); }