=========================
OpenFTPD DEVELOPER MANUAL
=========================

Revision: 2000-07-11 by primemover


I. Introduction
---------------
This file was written for people who want to do some mods or addons for FTP4ALL 
directly in the source. Although the code is not very difficult if you found 
out how everything works, this could keep you quite a time searching and 
trying. So we try to explain the most important parts of the source to save
your time coding new features instead of trying to find out how the existing
source works :)

But don't forget even with these informations you still have to be an 
experienced c coder. If you are a beginner you maybe should think about doing
your addon as external script / program.


II. Overview
------------
FTP4ALL consists of 3 parts: 

   ftpd - the ftp daemon that runs in the background and waits for incoming
          connections

   ftps - a ftp session instance which is created on each connect

   ftpa - an admin port session that is created if someone logs into
          the admin port

The source for these 3 parts is seperated into 3 dirs in the source tree.
Additional there is a "common" dir with some shared functions and structs.

FTP4ALL was written completely in C and should compile on most modern unix
systems like FreeBSD and Linux.


III. Communication
------------------
For information transport between ftpd and the ftps sessions a pipe mapped to
stdin / stdout is used. Maybe you already wondered about code like

 printf("UUD 0 %lu 0 %ld\n", down, t1);
 scanf(SI64, &usr.credit);

in the ftps source. You always have to remember that you can't use variables
of the ftpd in the ftps process directly, you always have to use commands
that will return the values you are interested in.

The standard printf function will give you an easy way to run commmands on 
ftpd from ftps and fgets or scanf will read the returned values for you. 
All available commands are defined in the struct serverd_cmd[] in 
"ftpd/serverd.c" and are called the FTP4ALL Daemon Protocol (F4ADP).

If you want to add additional commands you have to extend this structure
and write the functions that should be executed on the command.

It's very important that all entries in this struct are in alphabetical order.
Remember this for some other structs in the source too, so if you want to add 
something make sure you add it in the right position!
Remember to use fpurge(stdin) before every printf("") you make from ftps. This
ensure that no data is left in the buffer, from a previous printf.

III. Data storage
-----------------
After the ftpd was started it will read the registry, user, group and some 
config files and store them in memory. Pointer lists of the specific struct
type are used for this and they are defined in "ftpd/globalsd.h". For example
the users are stored in "struct user_s* user". The user structure and other
important data types are defined in "ftpd/definesd.h".


IV. Site commands
-----------------
One of the most common addons are new site commands, if this is your wish
too then you should look at "ftps/site.c".
         

Important notice for FreeBSD!
-----------------------------
If you have the problem that the ftps hangs if you send too much data
from the ftpd through the pipe you should add some delays to the function
in ftpd (user_list in serverd.c for example) with usleep(5000) or higher
values.


... to be continued

--- EOF ---
