View Full Version : HTTPd
darkone
01-31-2004, 05:46 PM
As promised, I'm now working on the httpd part of daemon :) So far daemon consists of ~200lines of code, which do following:
0) Handle SSL handshake
1) Determinate HTTP request type (GET, PUT, HEAD, POST)
2) Read http meta-data from header
3) Verify that requested file is within selected root directory
3x) If requested path points to a directory, find first index file from cached db
4) Redirect process to file handlers based on extension
a-4) Create simple handler for ordinary files (.html/.html/.jpg/...)
a-5) Add 'If-Modified-Since' support
a-6) Memory caching for small files
b-4) Finalize php handler
b-5) ... (it works already, but doesn't support POST/PUT yet)
b-6) ...
b-7) Yeap, it's a lot of work :p
b-8) Add ioftpd specific commands to php
b-9) Add more commands... :)
b-10) ???
To do:
c-4) Write simple TCL Handler
c-5) CGI handler
c-6) ...
c-7) ...
c-8) This one will take for ages to write :)
x) Add error messages
------------------
I will try to keep this thread up to date. If you have experience in writing _modules_ for php, I could use your help. (adding ioftpd specific commands to php)
wooolF[RM]
01-31-2004, 05:57 PM
finally :) one of the features in ioFTPD that I've waited most for :D
darkone
02-01-2004, 07:30 PM
Keeping it gupdated..
darkone
02-01-2004, 10:57 PM
Some sieging:
# siege -b -c50 -uhttp://192.168.1.10:10000/
** Siege 2.59
** Preparing 50 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 25976 hits
Availability: 100.00 %
Elapsed time: 28.37 secs
Data transferred: 138789768 bytes
Response time: 0.05 secs
Transaction rate: 915.62 trans/sec
Throughput: 4892131.26 bytes/sec
Concurrency: 48.82
Successful transactions: 25976
Failed transactions: 0
.. it's well capable of running large sites as well. With keep-alive it's near 2000transactions/sec. (which is 80-90% of IIS performance :) quite good for hobbyist)
NorLan
02-02-2004, 03:15 AM
i am looking forward to use this feature of io too ...
is the only part missing so far - to make io perfect *g
even if this means that your zipscript (you thougt of loud some time ago) would last a little longer ....
wooolF[RM]
02-02-2004, 05:38 AM
nice stats over there :D gj D1 :)
darkone
02-02-2004, 06:15 AM
I decided to make php scripts non-blocking, which means that all data posted to script is read to memory, before script runs. While all data sent by script is also cached to memory, and transfered to client after script finishes successfully.
So, outputting 500kb from php consumes 500kb of memory. I will change this behaviour at later point => then output exceeding the memory buffer will be cached to file instead.
darkone
02-02-2004, 07:28 AM
php commands will be following:
INT io_user create <user>
INT io_user delete <user>
INT io_user rename <user> <user>
INT io_user login <user> <password>
OBJECT io_user open <user>
INT io_user unlock <user object>
INT io_user print <user object>
INT io_user save <user object> <data>
INT io_user lock <user object>
INT io_user close <user object>
INT io_group create <group>
INT io_group delete <group>
INT io_group rename <group> <group>
OBJECT io_group open <group>
INT io_group unlock <group object>
INT io_group print <group object>
INT io_group save <group object> <data>
ITN io_group lock <group object>
INT io_group close <group object>
INT io_client list init <arguments>
STRING io_client list
INT io_client kill <client id>
INT io_client kick <user id>
INT io_log <type> <line>
STRING io_sha1 <string>
STRING io_resolve vpath <virtual path> <mount file>
STRING io_resolve uid
UID io_resolve user
STRING io_resolve gid
GID io_resolve group
INT io_vfs write <real path> <uid> <gid> <filemode>
INT io_vfs chattr <real path> <+-><type> [value]
INT io_vfs read <real path>
INT io_fileattachment <filename> <file offset>
Any suggestions?
Mouton
02-02-2004, 02:17 PM
config edition commands ?
darkone
02-02-2004, 09:41 PM
rehash perhaps, can't see much use for other commands (as you can read config directly from file)
darkone
02-03-2004, 03:30 AM
Wii.. all user_ commands were added (I was kind enough to add error definitions :) php api, is quite nice for adding new commands)
io_user_open command looks following:
/* proto object io_user_open(uid)
Open user */
PHP_FUNCTION(io_user_open)
{
LONG Uid;
LPPHP_USERFILE lpUserFile;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"l", &Uid) == FAILURE) return;
if (Uid < 0 || Uid >= MAX_UID)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid UID");
RETURN_FALSE;
}
lpUserFile = (LPPHP_USERFILE)Allocate("PHP:UserFile", sizeof(USERFILE));
if (! lpUserFile) RETURN_FALSE
ZeroMemory(lpUserFile, sizeof(PHP_USERFILE));
if (UserFile_OpenPrimitive(Uid, &lpUserFile->lpUserFile, 0))
{
Php_SetError(GetLastError(), TSRMLS_CC);
Free(lpUserFile);
RETURN_FALSE;
}
ZEND_REGISTER_RESOURCE(return_value, lpUserFile, iUserFile);
}
darkone
02-03-2004, 09:38 AM
Some testing, try to guess what it does:
$uid = io_user_id('ioFTPD');
$uhandle = io_user_open($uid);
$text = io_user_print($uhandle);
io_user_lock($uhandle);
io_user_lock($uhandle);
io_user_close($uhandle);
$ulist = io_user_list_init();
while (($id = io_user_list_fetch($ulist)) >= 0) {
$uname = io_user_name($id);
echo "User: $uname<br>";
}
io_user_list_close($ulist);
mr_F_2
02-03-2004, 05:36 PM
lists users?
NorLan
02-03-2004, 06:14 PM
something like this, i guess mr_f *gg
darkone
02-04-2004, 12:23 AM
Find handle is compatible with all fs query/modify functions:
$hFind = io_fs_find_first('d:/ioFTPD/site/home/');
do {
$fname = io_fs_query_filename($hFind);
$finfo = io_fs_query($hFind);
echo "$finfo[0]:$finfo[1] $fname<br>";
} while (io_fs_find_next($hFind));
io_fs_find_close($hFind);
darkone
02-04-2004, 09:01 AM
Simple vfs listing looks following:
# Open userfile
$uhandle = io_user_open(0);
# Open mount table
$mtable = io_mtable_open('d:\\ioFTPD\\etc\\default.vfs');
# Resolve root path
$path = io_mtable_query($mtable, '/', $uhandle, 1);
$c_path = count($path);
if ($c_path > 1) {
# Show mounts under current path
$link = io_mtable_query_mounts($mtable, $path[0]);
if ($link) {
$c_link = count($link);
for ($i=0;$i<$c_link;$i+=2) {
# Open file vfs attributes
$file = io_fs_open($link[$i+1]);
# Test access
if ($file && io_fs_access($file, $uhandle)) {
$finfo = io_fs_query($file);
echo "$finfo[0]:$finfo[1] $link[$i]<br>";
}
io_fs_close($file);
}
}
# Go through result path array
for ($i=1;$i<$c_path;$i++) {
$hfind = io_fs_find_first($path[$i]);
# Show files
if ($hfind) {
do {
if (io_fs_access($hfind, $uhandle)) {
$finfo = io_fs_query($hfind);
$fname = io_fs_query_filename($hfind);
echo "$finfo[0]:$finfo[1] $fname<br>";
}
} while (io_fs_find_next($hfind));
io_find_close($hfind);
}
}
} else {
echo "Could not access requested directory<br>";
}
io_mtable_close($mtable);
io_user_close($uhandle);
wooolF[RM]
02-04-2004, 06:11 PM
seems understandable and logical :) nice :banana:
NorLan
02-04-2004, 11:18 PM
first time i see #explanations in d1s code :D -- very nice
neoxed
02-05-2004, 01:15 AM
Originally posted by NorLan
first time i see #explanations in d1s code :D -- very nice
Those last 2 examples are php, pretty well self explanitory.
darkone
02-05-2004, 05:15 AM
Who list
darkone
02-05-2004, 05:16 AM
Directory list seems fast enough ;)
jam jam... :D :D :D :D :D
darkone
02-06-2004, 05:16 AM
One of the important additions to php command set is:
<? php
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="ioFTPD-beta5-6-3u.zip"');
io_attachment('d:\\ioFTPD-beta5-6-3u.zip');
?>
io_attachment() does same as readfile(), but has much better performance. io_attachment() tells ioftpd to read file outside the php interpreter.
Following is also possible:
<? php
io_attachment('d:\\ioFTPD-beta5-6-3u.zip');
echo "foo";
io_attachment('d:\\ioFTPD-beta5-6-3u.zip');
echo "foo";
?>
wooolF[RM]
02-06-2004, 07:04 AM
seems like I will like that httpd even more then I've thought of it before :D
bounty
02-06-2004, 07:44 AM
ehehehe i think it's time for me to learn PHP ;)
this looks great D1
thx for this fine piece of software
have fun
bounty
vBulletin® v3.8.11 Alpha 3, Copyright ©2000-2025, vBulletin Solutions, Inc.