X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fwho.c;h=c88d3a90de9d97de737b88731394a06aea28451a;hb=502a3baa576469141cf6f72fd805f1317d35fa12;hp=e81b911e9aa52f6bcf1b09174e494731cd5cc4d2;hpb=26a4a07bdacdaa7013bf45cc235df207708acfde;p=citadel.git diff --git a/webcit/who.c b/webcit/who.c index e81b911e9..c88d3a90d 100644 --- a/webcit/who.c +++ b/webcit/who.c @@ -9,27 +9,135 @@ #include "webcit.h" +typedef struct UserStateStruct { + char *UserName; + long UserNameLen; + char *Room; + long RoomLen; + char *Host; + long HostLen; + char *RealRoom; + long RealRoomLen; + char *RealHost; + long RealHostLen; + long LastActive; + int Session; + int Idle; + int SessionCount; +} UserStateStruct; + +void DestroyUserStruct(void *vUser) +{ + UserStateStruct *User = (UserStateStruct*) vUser; + free(User->UserName); + free(User->Room); + free(User->Host); + free(User->RealRoom); + free(User->RealHost); + free(User); +} + +int CompareUserStruct(const void *VUser1, const void *VUser2) +{ + const UserStateStruct *User1 = (UserStateStruct*) GetSearchPayload(VUser1); + const UserStateStruct *User2 = (UserStateStruct*) GetSearchPayload(VUser2); + + if (User1->Idle != User2->Idle) + return User1->Idle > User2->Idle; + return strcasecmp(User1->UserName, User2->UserName); +} + + +int GetWholistSection(HashList *List, time_t now) +{ + struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */ + UserStateStruct *User, *OldUser; + void *VOldUser; + char buf[SIZ], user[SIZ], room[SIZ], host[SIZ], + realroom[SIZ], realhost[SIZ]; + size_t BufLen; + + serv_puts("RWHO"); + serv_getln(buf, sizeof buf); + if (buf[0] == '1') { + while (BufLen = serv_getln(buf, sizeof buf), strcmp(buf, "000")) { + if (BufLen <= 0) + continue; + User = (UserStateStruct*) malloc(sizeof(UserStateStruct)); + User->Session = extract_int(buf, 0); + + User->UserNameLen = extract_token(user, buf, 1, '|', sizeof user); + User->UserName = malloc(User->UserNameLen + 1); + memcpy(User->UserName, user, User->UserNameLen + 1); + + User->RoomLen = extract_token(room, buf, 2, '|', sizeof room); + User->Room = malloc(User->RoomLen + 1); + memcpy(User->Room, room, User->RoomLen + 1); + + User->HostLen = extract_token(host, buf, 3, '|', sizeof host); + User->Host = malloc(User->HostLen + 1); + memcpy(User->Host, host, User->HostLen + 1); + + User->RealRoomLen = extract_token(realroom, buf, 9, '|', sizeof realroom); + User->RealRoom = malloc(User->RealRoomLen + 1); + memcpy(User->RealRoom, realroom, User->RealRoomLen + 1); + + User->RealHostLen = extract_token(realhost, buf, 10, '|', sizeof realhost); + User->RealHost = malloc(User->RealHostLen + 1); + memcpy(User->RealHost, realhost, User->RealHostLen + 1); + + User->LastActive = extract_long(buf, 5); + User->Idle = (now - User->LastActive) > 900L; + User->SessionCount = 1; + + if (GetHash(List, User->UserName, User->UserNameLen, &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, User->UserName, User->UserNameLen, User, DestroyUserStruct); + } + SortByPayload(List, CompareUserStruct); + return 1; + } + else + return 0; +} /** * \brief Display inner div of Wholist */ void who_inner_div(void) { - char buf[SIZ], user[SIZ], room[SIZ], host[SIZ], - realroom[SIZ], realhost[SIZ]; - int sess; - time_t last_activity; + UserStateStruct *User; + void *VUser; + char buf[SIZ]; + struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */ + HashList *List; + HashPos *it; + char *UserName; + long len; time_t now; int bg = 0; - wprintf("" + wprintf("
" "\n"); - wprintf("\n"); + wprintf("\n"); + wprintf("\n"); wprintf("\n", _("User name")); wprintf("", _("Room")); - wprintf("\n\n", _("From host")); + wprintf("\n\n", _("From host")); serv_puts("TIME"); serv_getln(buf, sizeof buf); + if (buf[0] == '2') { now = extract_long(&buf[4], 0); } @@ -37,38 +145,32 @@ void who_inner_div(void) { now = time(NULL); } - serv_puts("RWHO"); - serv_getln(buf, sizeof buf); - if (buf[0] == '1') { - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - sess = extract_int(buf, 0); - extract_token(user, buf, 1, '|', sizeof user); - extract_token(room, buf, 2, '|', sizeof room); - extract_token(host, buf, 3, '|', sizeof host); - extract_token(realroom, buf, 9, '|', sizeof realroom); - extract_token(realhost, buf, 10, '|', sizeof realhost); - last_activity = extract_long(buf, 5); + List = NewHash(); + if (GetWholistSection(List, now)) { + it = GetNewHashPos(); + while (GetNextHashPos(List, it, &len, &UserName, &VUser)) { + User = VUser; bg = 1 - bg; - wprintf("", - (bg ? "DDDDDD" : "FFFFFF") + wprintf("", + (bg ? "even" : "odd") ); - wprintf(""); /** (link to page this user) */ - wprintf("\n\n\t\n\t\n\t\n"); } + DeleteHashPos(&it); } wprintf("
%s%s%s
%s
"); - if ((WC->is_aide) && - (sess != WC->ctdl_pid)) { - wprintf(" "); + if ((WCC->is_aide) && + (User->Session != WCC->ctdl_pid)) { + wprintf(" Session); wprintf("\" onClick=\"return ConfirmKill();\">%s", _("(kill)")); } - if (sess == WC->ctdl_pid) { + if (User->Session == WCC->ctdl_pid) { wprintf(" %s", _("(edit)")); } wprintf("UserName); wprintf("\">" ""); /** (idle flag) */ - wprintf(""); - if ((now - last_activity) > 900L) { + wprintf(""); + if (User->Idle) { wprintf(" " ""); + "alt=\"(%s %d %s)\" border=\"0\" />", + _("idle since"), + (now - User->LastActive) / 60, + _("Minutes") + ); + } else { wprintf(" " @@ -92,36 +199,39 @@ void who_inner_div(void) { } wprintf(""); - - /** username (link to user bio/photo page) */ wprintf("UserName); wprintf("\">"); - escputs(user); + escputs(User->UserName); + if (User->SessionCount > 1) + wprintf(" [%d] ", User->SessionCount); wprintf(""); /** room */ wprintf(""); - escputs(room); - if (strlen(realroom) > 0) { + escputs(User->Room); + if (!IsEmptyStr(User->RealRoom) ) { wprintf("
"); - escputs(realroom); + escputs(User->RealRoom); wprintf(""); } - wprintf("
"); + wprintf(""); /** hostname */ - escputs(host); - if (strlen(realhost) > 0) { + escputs(User->Host); + if (!IsEmptyStr(User->RealHost)) { wprintf("
"); - escputs(realhost); + escputs(User->RealHost); wprintf(""); } wprintf("
"); + DeleteHash(&List); + } @@ -142,32 +252,35 @@ void who(void) ); wprintf("
\n"); - wprintf("
"); - wprintf("\""); - wprintf(" "); - + wprintf("
"); + wprintf(""); + wprintf("

"); snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode); escputs(title); - - wprintf("

"); + wprintf(""); + wprintf("
    \n"); + wprintf("
  • "); offer_start_page(); - wprintf("
\n"); - wprintf("
\n"); + wprintf(""); + wprintf(""); - wprintf("
\n"); - - wprintf("
"); + wprintf("
\n"); + wprintf("
"); + wprintf("
"); + snprintf(title, sizeof title, _("Users currently on %s"), serv_info.serv_humannode); + escputs(title); + wprintf("
"); + wprintf("
"); + wprintf("
"); who_inner_div(); - wprintf("
\n"); + wprintf("
"); - wprintf("
"); + wprintf("
"); wprintf(_("Click on a name to read user info. Click on %s " "to send an instant message to that user."), "\"(p)\"" ); - wprintf("
\n"); + wprintf("
\n"); /** * JavaScript to make the ajax refresh happen: @@ -178,7 +291,7 @@ void who(void) */ wprintf( " \n" ); @@ -205,25 +318,25 @@ void edit_me(void) { char buf[SIZ]; - if (strlen(bstr("change_room_name_button")) > 0) { + if (!IsEmptyStr(bstr("change_room_name_button"))) { serv_printf("RCHG %s", bstr("fake_roomname")); serv_getln(buf, sizeof buf); http_redirect("who"); - } else if (strlen(bstr("change_host_name_button")) > 0) { + } else if (!IsEmptyStr(bstr("change_host_name_button"))) { serv_printf("HCHG %s", bstr("fake_hostname")); serv_getln(buf, sizeof buf); http_redirect("who"); - } else if (strlen(bstr("change_user_name_button")) > 0) { + } else if (!IsEmptyStr(bstr("change_user_name_button"))) { serv_printf("UCHG %s", bstr("fake_username")); serv_getln(buf, sizeof buf); http_redirect("who"); - } else if (strlen(bstr("cancel_button")) > 0) { + } else if (!IsEmptyStr(bstr("cancel_button"))) { http_redirect("who"); } else { output_headers(1, 1, 0, 0, 0, 0); wprintf("
\n"); - wprintf("
"); + wprintf("
"); wprintf(""); wprintf(_("Edit your session display")); wprintf("
\n"); @@ -237,6 +350,7 @@ void edit_me(void) wprintf("
\n"); wprintf("
\n"); + wprintf("\n", WC->nonce); wprintf("\n"); @@ -277,5 +391,55 @@ void edit_me(void) } } +/** + * \brief Wholist section + */ +void wholist_section(void) { + UserStateStruct *User; + void *VUser; + HashList *List; + HashPos *it; + 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(); + + if (GetWholistSection(List, now)) { + SortByPayload(List, CompareUserStruct); + it = GetNewHashPos(); + while (GetNextHashPos(List, it, &len, &UserName, &VUser)) { + User = VUser; + if (strcmp(User->UserName, NLI)) { + wprintf("
  • Idle) { + wprintf("inactiveuser"); + } + else { + wprintf("activeuser"); + } + wprintf("\">UserName); + wprintf("\">"); + escputs(User->UserName); + wprintf("
  • "); + } + } + DeleteHashPos(&it); + } + DeleteHash(&List); +} + + /*@}*/