<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
img {
max-width: 100%;
height: auto;
}
p.details {
font-style:italic;
color:#777
}
.footer p {
font-size:small;
color:#777
}
pre.commit-message {
white-space: pre-wrap;
}
.file-stats a {
text-decoration: none;
}
.file-stats .new-file {
color: #090;
}
.file-stats .deleted-file {
color: #B00;
}
</style>
<body>
<div class='content'>
<h3>Justin Mitchell pushed to branch master at <a href="https://projects.sucs.org/arthur/mw">Justin Mitchell / mw</a></h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://projects.sucs.org/arthur/mw/commit/935a273801cff47a5da5319bcff1da9fcdb0b031">935a2738</a></strong>
<div>
<span>by Justin Mitchell</span>
<i>at 2015-10-08T10:57:36Z</i>
</div>
<pre class='commit-message'>Remove old wholist access from webclient</pre>
</li>
</ul>
<h4>3 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
src/webclient/comms.c
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
src/webclient/comms.h
</a>
</li>
<li class='file-stats'>
<a href='#diff-2'>
webclient/say.js
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://projects.sucs.org/arthur/mw/commit/935a273801cff47a5da5319bcff1da9fcdb0b031#diff-0'>
<strong>
src/webclient/comms.c
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/webclient/comms.c
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/webclient/comms.c
</span><span style="color: #aaaaaa">@@ -99,9 +99,50 @@ void open_command_socket()
</span> INIT_LIST_HEAD(&connlist);
}
<span style="color: #000000;background-color: #ddffdd">+static char * whoinfo = NULL;
+static time_t whowhen = 0;
+static int whowant = 0;
+#define WHOCACHE 120 /* cache who data for this many seconds */
+
+extern int32_t userposn;
+
+const char * fetch_who(int immediate)
+{
+ time_t now = time(NULL);
+ if (whoinfo == NULL || whowhen < (now - WHOCACHE)) {
+ ipc_message_t * msg = ipcmsg_create(IPC_WHOLIST, userposn);
+ ipcmsg_transmit(msg);
+ /* dont want stale, come back later */
+ if (!immediate) {
+ whowant = 1;
+ return NULL;
+ }
+ }
+ /* no answer we can give, sorry, you will HAVE to come back */
+ if (whoinfo == NULL) {
+ whowant=1;
+ return NULL;
+ }
+ /* they want an immediate answer, even if its stale */
+ return whoinfo;
+}
+
</span> /* we got a message */
static void accept_pipe_cmd(ipc_message_t *ipc, struct person *mesg_user)
{
<span style="color: #000000;background-color: #ddffdd">+ if (ipc->head.type == IPC_WHOLIST) {
+ /* keep a copy for later */
+ if (whoinfo != NULL)
+ free(whoinfo);
+ whoinfo = strdup(ipc->body);
+ whowhen = time(NULL);
+ /* if we want it, fall through, otherwise stop now */
+ if (whowant != 0)
+ whowant=0;
+ else
+ return;
+ }
+
</span> MESG *msg = malloc(sizeof(MESG));
msg->state = ipc->head.type;
//msg->pid = ipc->head.src;
<span style="color: #aaaaaa">@@ -254,7 +295,7 @@ static int send_list(CONNECTION *co)
</span> mws_add(buff, "\"state\":%d,", tmp->state);
mws_add(buff, "\"serial\":%"PRId64",", tmp->serial);
mws_add(buff, "\"when\":%"PRId64",", tmp->when);
- mws_add(buff, "\"username\":\"%s\",\"text\":\"%s\"}", tmp->user.name, tmp->text);
<span style="color: #000000;background-color: #ddffdd">+ mws_add(buff, "\"name\":\"%s\",\"text\":\"%s\"}", tmp->user.name, tmp->text);
</span> if (pos->next != &msglist) {
mws_add(buff, ",");
}
<span style="color: #aaaaaa">@@ -413,45 +454,9 @@ static int handle_command(CONNECTION *co)
</span> return 1;
}else
if (co->authd && strcasecmp(buff, "who")==0) {
- struct person u;
- struct who w;
- int ufile, wfile;
- int32_t now = time(NULL);
- mwstring *line = mws_new(2048);
- int count=0;
-
- wfile = who_open(O_RDONLY);
- ufile = userdb_open(O_RDONLY);
-
- mws_add(line, "[");
-
- while (read(wfile, &w, sizeof(w)))
- {
- char *realname;
- char *doing;
- if (w.posn < 0) continue;
- lseek(ufile, w.posn, SEEK_SET);
- read(ufile, &u, sizeof(u));
- if (count > 0) mws_add(line, ",");
- realname = json_escape(u.realname);
- doing = json_escape(u.doing);
- mws_add(line, "{");
- if (u_god(user->status)) {
-
- mws_add(line, "\"realname\":\"%s\",", realname);
- }
- mws_add(line, "\"pid\":%d,", w.pid);
- mws_add(line, "\"username\":\"%s\",", u.name);
- mws_add(line, "\"channel\":%d,", u.room);
- mws_add(line, "\"doing\":\"%s\",", doing);
- mws_add(line, "\"idle\":%d}", now - u.idletime);
- free(realname);
- free(doing);
- count++;
- }
- mws_add(line, "]");
- send(co->fd, mws_cstr(line), mws_len(line), 0);
- mws_free(line);
<span style="color: #000000;background-color: #ddffdd">+ const char *line = fetch_who(0);
+ if (line != NULL)
+ send(co->fd, line, strlen(line), 0);
</span> return 1;
}else
if (co->authd && strcasecmp(buff, "whoami")==0) {
<span style="color: #aaaaaa">@@ -459,7 +464,7 @@ static int handle_command(CONNECTION *co)
</span> char stats[64];
char *tmp;
mws_add(line, "{");
- mws_add(line, "\"username\":\"%s\",", user->name);
<span style="color: #000000;background-color: #ddffdd">+ mws_add(line, "\"name\":\"%s\",", user->name);
</span> tmp = json_escape(user->realname);
mws_add(line, "\"realname\":\"%s\",", tmp);
free(tmp);
<span style="color: #aaaaaa">@@ -550,7 +555,7 @@ void talk_rawbcast(const char *fmt, ...)
</span>
}
-void create_user(struct person *me, int *userposn, const char *username, const char *password)
<span style="color: #000000;background-color: #ddffdd">+void create_user(struct person *me, int *uposn, const char *username, const char *password)
</span> {
struct passwd *pw;
char salt[3];
<span style="color: #aaaaaa">@@ -579,7 +584,7 @@ void create_user(struct person *me, int *userposn, const char *username, const c
</span> } else {
mwlog("CREATED Auto web user");
}
- userdb_write(me, userposn);
<span style="color: #000000;background-color: #ddffdd">+ userdb_write(me, uposn);
</span> }
void mwlog(const char *fmt, ...)
</code></pre>
<br>
</li>
<li id='diff-1'>
<a href='https://projects.sucs.org/arthur/mw/commit/935a273801cff47a5da5319bcff1da9fcdb0b031#diff-1'>
<strong>
src/webclient/comms.h
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/src/webclient/comms.h
</span><span style="color: #000000;background-color: #ddffdd">+++ b/src/webclient/comms.h
</span><span style="color: #aaaaaa">@@ -7,3 +7,5 @@ char *json_escape(char *original);
</span> void close_cmd(void);
void talk_rawbcast(const char *fmt, ...) __attribute__((format(printf,1,2)));
void create_user(struct person *me, int *userposn, const char *username, const char *password);
<span style="color: #000000;background-color: #ddffdd">+const char * fetch_who(int immediate);
+
</span></code></pre>
<br>
</li>
<li id='diff-2'>
<a href='https://projects.sucs.org/arthur/mw/commit/935a273801cff47a5da5319bcff1da9fcdb0b031#diff-2'>
<strong>
webclient/say.js
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: #ffdddd">--- a/webclient/say.js
</span><span style="color: #000000;background-color: #ddffdd">+++ b/webclient/say.js
</span><span style="color: #aaaaaa">@@ -34,7 +34,7 @@ function pageInit() {
</span> // make a crude approximation of the old message styles
switch (detail.type) {
case "say":
- body = msg[one].username + ": " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + ": " + detail.text;
</span> break;
case "raw":
body = detail.text;
<span style="color: #aaaaaa">@@ -42,33 +42,33 @@ function pageInit() {
</span> case "emote":
switch (detail.plural){
case 1:
- body = msg[one].username + "'s " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + "'s " + detail.text;
</span> break;
case 2:
- body = msg[one].username + "' " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + "' " + detail.text;
</span> break;
case 3:
- body = msg[one].username + "'d " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + "'d " + detail.text;
</span> break;
case 4:
- body = msg[one].username + "'ll " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + "'ll " + detail.text;
</span> break;
default:
- body = msg[one].username + " " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + " " + detail.text;
</span> break;
}
break;
case "notsayto":
- body = msg[one].username + " says (-" + detail.exclude + "): " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + " says (-" + detail.exclude + "): " + detail.text;
</span> break;
case "says":
- body = msg[one].username + " says: " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + " says: " + detail.text;
</span> break;
case "whispers":
- body = msg[one].username + " whispers: " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + " whispers: " + detail.text;
</span> break;
default:
- body = msg[one].username + " " + detail.text;
<span style="color: #000000;background-color: #ddffdd">+ body = msg[one].name + " " + detail.text;
</span> break;
}
<span style="color: #aaaaaa">@@ -94,8 +94,8 @@ function pageInit() {
</span> }
/* Detect username */
- if (escapedMsg.substr(0, msg[one].username.length)==msg[one].username) {
- escapedMsg = escapedMsg.replace(msg[one].username, "<span class='msg_poster'>"+msg[one].username+"</span><span class='msg_content"+withts+"'><span>");
<span style="color: #000000;background-color: #ddffdd">+ if (escapedMsg.substr(0, msg[one].name.length)==msg[one].name) {
+ escapedMsg = escapedMsg.replace(msg[one].name, "<span class='msg_poster'>"+msg[one].name+"</span><span class='msg_content"+withts+"'><span>");
</span> escapedMsg = escapedMsg+"</span></span>";
}
<span style="color: #aaaaaa">@@ -115,7 +115,7 @@ function pageInit() {
</span> }
/* Output the processed line */
- $("#textlist").append( "<p class='msg"+type+" user_"+userIndex[msg[one].username.toLowerCase()]+"'>" + timestamp + escapedMsg + "</p");
<span style="color: #000000;background-color: #ddffdd">+ $("#textlist").append( "<p class='msg"+type+" user_"+userIndex[msg[one].name.toLowerCase()]+"'>" + timestamp + escapedMsg + "</p");
</span>
break;
<span style="color: #aaaaaa">@@ -143,8 +143,8 @@ function pageInit() {
</span> }
/* Detect username */
- if (escapedMsg.substr(0, msg[one].username.length)==msg[one].username) {
- escapedMsg = escapedMsg.replace(msg[one].username, "<span class='msg_poster'>"+msg[one].username+"</span><span class='msg_content"+withts+"'><span>");
<span style="color: #000000;background-color: #ddffdd">+ if (escapedMsg.substr(0, msg[one].name.length)==msg[one].name) {
+ escapedMsg = escapedMsg.replace(msg[one].name, "<span class='msg_poster'>"+msg[one].name+"</span><span class='msg_content"+withts+"'><span>");
</span> escapedMsg = escapedMsg+"</span></span>";
}
<span style="color: #aaaaaa">@@ -164,7 +164,7 @@ function pageInit() {
</span> }
/* Output the processed line */
- $("#textlist").append( "<p class='msg"+type+" user_"+userIndex[msg[one].username.toLowerCase()]+"'>" + timestamp + escapedMsg + "</p");
<span style="color: #000000;background-color: #ddffdd">+ $("#textlist").append( "<p class='msg"+type+" user_"+userIndex[msg[one].name.toLowerCase()]+"'>" + timestamp + escapedMsg + "</p");
</span>
break;
case 14: // IPC_KICK
<span style="color: #aaaaaa">@@ -174,11 +174,11 @@ function pageInit() {
</span> what += "You look up; a large object is falling towards you very fast, very very fast. It looks like a Magic Roundabout!<br />";
what += "\"I wouldn't stand there if I was you\" says Zebedee<br />";
what += "WWWHHHEEEEEEEKKKKEEEERRRRRUUUUUNNNNNCCCCCHHHHHH<br />";
- what += msg[one].username + " has just dropped the Magic Roundabout of Death on you.<br />";
<span style="color: #000000;background-color: #ddffdd">+ what += msg[one].name + " has just dropped the Magic Roundabout of Death on you.<br />";
</span> } else {
what += "Boing, Zebedee arrived.<br />";
what += "\"Time for bed\" says Zebedee<br />";
- what += msg[one].username + " has just dropped the Zebedee of Death on you.<br />";
<span style="color: #000000;background-color: #ddffdd">+ what += msg[one].name + " has just dropped the Zebedee of Death on you.<br />";
</span> }
if (msg[one].text.substr(1,1) == 'r') what += "\""+msg[one].text.substr(2)+"\" says Zebedee<br />";
what += "</div>";
<span style="color: #aaaaaa">@@ -301,8 +301,8 @@ function drawWho(data, stat)
</span> var text = "<hr /><table cellspacing=\"0\" cellpadding=\"0\"><tbody>";
text += "<tr><th style=\"width: 10em;\">Name</th><th style=\"width: 6em;\">Idle</th><th>What...</th></tr>";
for (person in data) {
- var line = "<td>"+data[person].username+"</td>";
- line += "<td>"+drawTime(data[person].idle)+"</td>";
<span style="color: #000000;background-color: #ddffdd">+ var line = "<td>"+data[person].name+"</td>";
+ line += "<td>"+drawTime(data[person].idletime)+"</td>";
</span> line += "<td>Room "+data[person].channel+"</td>";
text += "<tr>"+line+"</tr>";
}
<span style="color: #aaaaaa">@@ -311,7 +311,7 @@ function drawWho(data, stat)
</span> }
function sortWho(a, b) {
- var nameA=a.username.toLowerCase(), nameB=b.username.toLowerCase();
<span style="color: #000000;background-color: #ddffdd">+ var nameA=a.name.toLowerCase(), nameB=b.name.toLowerCase();
</span> if (nameA < nameB) return -1;
if (nameA > nameB) return 1;
return 0;
<span style="color: #aaaaaa">@@ -332,7 +332,7 @@ function userInit(data, stat) {
</span> data.sort(sortWho);
usercount=0;
for (var person in data) {
- var thisUsername=data[person].username.toLowerCase();
<span style="color: #000000;background-color: #ddffdd">+ var thisUsername=data[person].name.toLowerCase();
</span> if (thisUsername in userIndex) usercount--;
userIndex[thisUsername]=usercount;
usercount++;
<span style="color: #aaaaaa">@@ -341,7 +341,7 @@ function userInit(data, stat) {
</span>
function userAdd(data, stat) {
for (var person in data) {
- var thisUsername=data[person].username.toLowerCase();
<span style="color: #000000;background-color: #ddffdd">+ var thisUsername=data[person].name.toLowerCase();
</span> if (!(thisUsername in userIndex)) {
userIndex[thisUsername]=usercount;
usercount++;
<span style="color: #aaaaaa">@@ -358,18 +358,18 @@ function drawWhoList(data, stat) {
</span> data.sort(sortWho);
for (var person in data) {
idleness="";
- if (data[person].idle>1800) idleness=" idle";
- var thisUsername=data[person].username.toLowerCase();
<span style="color: #000000;background-color: #ddffdd">+ if (data[person].idletime>1800) idleness=" idle";
+ var thisUsername=data[person].name.toLowerCase();
</span> var personinfo = "<div class=\"whoinfo\">";
- if (data[person].hgwidth>0) personinfo += "<img src=\"https://sucs.org/pictures/people/"+data[person].username.toLowerCase()+".png\" width=\""+data[person].hgwidth+"\" height=\"64\" />";
<span style="color: #000000;background-color: #ddffdd">+ if (data[person].hgwidth>0) personinfo += "<img src=\"https://sucs.org/pictures/people/"+data[person].name.toLowerCase()+".png\" width=\""+data[person].hgwidth+"\" height=\"64\" />";
</span> else personinfo += "<img src=\"person.png\" width=\"64\" height=\"64\" />";
- personinfo += "<strong>"+data[person].username+"</strong>";
<span style="color: #000000;background-color: #ddffdd">+ personinfo += "<strong>"+data[person].name+"</strong>";
</span> personinfo += " "+data[person].doing;
personinfo += "<br />";
if (data[person].realname!=undefined) personinfo += data[person].realname+"<br />";
personinfo += "Room "+data[person].channel;
personinfo += "</div>";
- $("#wholist").append("<li class=\"who user_"+userIndex[thisUsername]+idleness+"\"><a href=\"#\">"+data[person].username+personinfo+"</a></li>");
<span style="color: #000000;background-color: #ddffdd">+ $("#wholist").append("<li class=\"who user_"+userIndex[thisUsername]+idleness+"\"><a href=\"#\">"+data[person].name+personinfo+"</a></li>");
</span> }
}
</code></pre>
<br>
</li>
</div>
<div class='footer' style='margin-top: 10px;'>
<p>
—
<br>
<a href="https://projects.sucs.org/arthur/mw/commit/935a273801cff47a5da5319bcff1da9fcdb0b031">View it on GitLab</a>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Commit","url":"https://projects.sucs.org/arthur/mw/commit/935a273801cff47a5da5319bcff1da9fcdb0b031"}}</script>
</p>
</div>
</body>
</html>