-/* $Id: httpd.js,v 1.53 2005/07/11 01:59:21 mmondor Exp $ */
+/* $Id: httpd.js,v 1.54 2005/07/12 12:13:48 mmondor Exp $ */
/*
* Copyright (c) 2005, Matthew Mondor
* priority at current time.
*
* TODO:
+ * - Support partial content to allow resuming uploads for clients
+ * - Report error if requested offset is too high, but seek otherwise.
+ * Do I need to report the actual file length in Content-Length, or
+ * only the remaining?
* - See what to do for HEAD and PUT
* - Possibly limit rate of connections per address like I did in
* mmftpd/mmsmtpd/mmpop3d/mmspawnd, a requested feature of 3s4i.
* Server identification
*/
SERVER_VERSION = 'mmondor_js_httpd/0.0.1 (NetBSD)';
-SERVER_CVSID = '$Id: httpd.js,v 1.53 2005/07/11 01:59:21 mmondor Exp $';
+SERVER_CVSID = '$Id: httpd.js,v 1.54 2005/07/12 12:13:48 mmondor Exp $';
contents += data;
}
} catch (x) {
- err.put(x + "\n");
+ err.put(x + " at file_read()\n");
}
fd.close();
contents += data;
}
} catch (x) {
- err.put(x + "\n");
+ err.put(x + " at file_read2()\n");
}
fd.close();
try {
session_randfd.open('/dev/urandom', FD.O_RDONLY);
} catch (x) {
- err.put(x + "while attempting to open /dev/urandom\n");
+ err.put(x + " while attempting to open /dev/urandom\n");
exit();
}
try {
rval = session_randfd.read(options.sess_id_size);
} catch (x) {
- err.put(x + "while attempting to read from /dev/urandom\n");
+ err.put(x + " while attempting to read from /dev/urandom\n");
}
this.sessid = '';
for (i = 0; i < options.sess_id_size; i++)
/* For process_request()/process_post() */
this.bread_buffer = '';
- /* Set this socket non-blocking */
- try {
- this.fcntl(FD.F_SETFL, FD.O_NONBLOCK);
- } catch (x) {
- err.put(x + "\n");
- }
+ /*
+ * Note that fcntl(2) and setsockopt(2) flags applied to the bound
+ * descriptors are inherited to their parent sockets at accept(2).
+ * We therefore can save a few syscalls here.
+ * We are non-blocking already, for instance.
+ */
}
/*
o = new JSO(path.real, st.st_mtime,
obj.script);
} catch (x) {
- err.put(x + 'evaluating script ' + path.real
+ err.put(x + ' evaluating script ' + path.real
+ "\n");
http_error(this, 500, 'Internal Server Error',
'Please try again later.');
obj.script();
obj.flush(this, null);
} catch (x) {
- err.put(x + 'executing script ' + path.real + "\n");
+ err.put(x + ' executing script ' + path.real + "\n");
http_error(this, 500, 'Internal Server Error',
'Please try again later.');
}
try {
var v = new VHost(vhosts[i]);
} catch (x) {
- err.put(x + "\n");
+ err.put(x + " creating VHost object\n");
}
}
/*
sock.setsockopt(FD.SO_KEEPALIVE, 1);
*/
fd.setsockopt(FD.TCP_NODELAY, 1);
+ fd.fcntl(FD.F_SETFL, FD.O_NONBLOCK);
fd.listen(options.max_connections);
/*
* Mark socket as bound one and add it to
fd.bound = true;
set.push(fd);
} catch (x) {
- err.put(x + "\n");
+ err.put(x + " preparing listening socket\n");
}
}
if (set.length == 0)
try {
e = FD.poll(set, exp * 1000);
} catch (x) {
- err.put(x + "\n");
+ err.put(x + " for poll(2)\n");
continue;
}
set[count] = fd;
}
} catch (x) {
- err.put(x + "\n");
+ err.put(x + " at accept(2)\n");
}
continue;
}
-/* $Id: ml_clean.js,v 1.2 2005/07/10 18:18:27 mmondor Exp $ */
+/* $Id: ml_clean.js,v 1.3 2005/07/12 12:13:48 mmondor Exp $ */
/*
* Copyright (c) 2004-2005, Matthew Mondor
*/
toStr: function(level)
{
+ var str = '';
+
+ /* Null tags may exist as containers */
+ if (this.tag != null) {
+
+ /* Open opening tag */
+ str += this.indent_str.substr(0, level) + '<' +
+ this.tag;
+
+ /*
+ * Store these immediately for performance since we
+ * use those values several times later on, also
+ * saves typing
+ */
+ var taglen = this.tag.length;
+ var len = level + taglen + 1;
+ var attributes = this.attributes;
+
+ /*
+ * Add each of our attributes with their optional
+ * values
+ */
+ for (var attr in attributes) {
+ var value;
+
+ if (len > 70) {
+ len = level + taglen + 1;
+ str += "\n" +
+ this.indent_str.substr(0, len);
+ }
+ str += ' ' + attr;
+ len += taglen + 1;
+ if ((value = attributes[attr]) != null) {
+ str += '="' + value + '"';
+ len += value.length + 3;
+ }
+ }
- /* Open opening tag */
- var str = this.indent_str.substr(0, level) + '<' + this.tag;
-
- /*
- * Store these immediately for performance since we use those
- * values several times later on, also saves typing
- */
- var taglen = this.tag.length;
- var len = level + taglen + 1;
- var attributes = this.attributes;
+ /* Close opening tag */
+ str += ">\n";
- /* Add each of our attributes with their optional values */
- for (var attr in attributes) {
- var value;
+ /* Increase our indent level for content */
+ level++;
- if (len > 70) {
- len = level + taglen + 1;
- str += "\n" + this.indent_str.substr(0, len);
- }
- str += ' ' + attr;
- len += taglen + 1;
- if ((value = attributes[attr]) != null) {
- str += '="' + value + '"';
- len += value.length + 3;
- }
}
- /* Close opening tag */
- str += ">\n";
-
- /* Increase our indent level for content */
- level++;
/*
* Now add all our contents, if any, which may consist of
}
/*
- * This tag required closing, so add corresponding closing tag
- * and decrease indent level.
+ * If this tag required closing, do so
*/
- level--;
- if (this.close)
- str += this.indent_str.substr(0, level) + '</' +
- this.tag + ">\n";
+ if (this.tag != null) {
+ level--;
+ if (this.close)
+ str += this.indent_str.substr(0, level) +
+ '</' + this.tag + ">\n";
+ }
return str;
}
-/* $Id: ml_machine.js,v 1.2 2005/07/10 18:18:27 mmondor Exp $ */
+/* $Id: ml_machine.js,v 1.3 2005/07/12 12:13:48 mmondor Exp $ */
/*
* Copyright (c) 2004-2005, Matthew Mondor
*/
toStr: function(level)
{
+ var str = '';
+
+ /* Null tags may exist as containers */
+ if (this.tag != null) {
+
+ /* Open opening tag */
+ str += '<' + this.tag;
+
+ /*
+ * Store these immediately for performance since we
+ * use those values several times later on, also
+ * saves typing
+ */
+ var taglen = this.tag.length;
+ var len = taglen + 1;
+ var attributes = this.attributes;
+
+ /*
+ * Add each of our attributes with their optional
+ * values
+ */
+ for (var attr in attributes) {
+ var value;
+
+ str += ' ' + attr;
+ len += taglen + 1;
+ if ((value = attributes[attr]) != null) {
+ str += '="' + value + '"';
+ len += value.length + 3;
+ }
+ }
- /* Open opening tag */
- var str = '<' + this.tag;
+ /* Close opening tag */
+ str += ">";
- /*
- * Store these immediately for performance since we use those
- * values several times later on, also saves typing
- */
- var taglen = this.tag.length;
- var len = taglen + 1;
- var attributes = this.attributes;
-
- /* Add each of our attributes with their optional values */
- for (var attr in attributes) {
- var value;
-
- str += ' ' + attr;
- len += taglen + 1;
- if ((value = attributes[attr]) != null) {
- str += '="' + value + '"';
- len += value.length + 3;
- }
}
- /* Close opening tag */
- str += ">";
/*
* Now add all our contents, if any, which may consist of
}
/*
- * This tag required closing, so add corresponding closing tag
+ * If this tag required closing, do so
*/
- if (this.close)
+ if (this.tag != null && this.close)
str += '</' + this.tag + ">";
return str;
-/* $Id: js_fd.c,v 1.33 2005/07/07 05:12:51 mmondor Exp $ */
+/* $Id: js_fd.c,v 1.34 2005/07/12 12:14:08 mmondor Exp $ */
/*
* Copyright (c) 2005, Matthew Mondor
return JS_FALSE;
}
flags &= (O_NONBLOCK | O_APPEND);
- if (!(flags & O_NONBLOCK) && !(flags & O_APPEND)) {
+ if ((flags & O_NONBLOCK) == 0 && (flags & O_APPEND) == 0) {
QUEUE_EXCEPTION("Unimplemented fcntl() flag");
return JS_FALSE;
}