package lpd

  1. Overview
  2. Docs

LPD protocol server library (RFC 1179 compliant).

  • author Christophe Troestler

Types describing a print job

type banner = {
  1. user_name : string;
    (*

    User name for the banner page.

    *)
  2. class_name : string;
    (*

    Class name, conventionally used to display the host from which the printing job originated.

    *)
  3. job_name : string;
    (*

    Job name, conventionally used to display the name of the file or files which were "printed".

    *)
}

Informations for a banner page.

type file_type =
  1. | Text of int * int
    (*

    Text(indent, number_of_columns): print as a text file, providing page breaks as necessary. According to the RFC, any ASCII control chars other than '\b', '\t', '\n', '\012', '\r' should be discarded -- it is your task to do so as you know better how to deal with them (accented letters,...) especially when you know PDF files may be sent using that type!

    *)
  2. | Bin
    (*

    Binary file to be printed as is (including control chars).

    *)
  3. | PS
    (*

    PostScript file.

    *)
  4. | DVI
    (*

    TeX DVI file.

    *)
  5. | Troff of string * string * string * string
    (*

    Troff(R font, I font, B font, S font): troff output file.

    *)
  6. | Ditroff
    (*

    ditroff (device independent troff) output.

    *)
  7. | CIF
    (*

    CalTech Intermediate Form graphics language.

    *)
  8. | Plot
    (*

    Output from the Berkeley Unix plot library.

    *)
  9. | Pr of string * int
    (*

    Pr(title, number_of_columns): print with a heading, page numbers, and pagination. The heading should include the date and time that printing was started, the title, and a page number identifier followed by the page number.

    *)
  10. | Fortran
    (*

    Print interpreting the first column of each line as FORTRAN carriage control.

    *)
  11. | Raster
    (*

    Sun raster format file.

    *)

Information on the type of the file to be printed.

type file = {
  1. name : string;
    (*

    Name of the file on the client machine. "" means standard input.

    *)
  2. size : int;
    (*

    Size in bytes of the file.

    *)
  3. nbcopies : int;
    (*

    Number of copies requested.

    *)
  4. storage : string;
    (*

    Local file on the disk holding the data.

    *)
  5. of_type : file_type;
    (*

    Type of the file.

    *)
}
type job = {
  1. number : int;
    (*

    Three digits job number. A negative number indicates that the client did not send a correct job number.

    *)
  2. user : string;
    (*

    User identification of the entity requesting the printing job.

    *)
  3. host : string;
    (*

    Host which is to be treated as the source of the print job. This is not necessarily the same as the machine which connected this server -- the job may have been routed through several computers.

    *)
  4. mailto : string;
    (*

    If different from "", request that a mail be sent to the given address when the printing operation ends (successfully or unsuccessfully). There is no guarantee that the email address is even well formed (e.g. it may only be the login name).

    *)
  5. banner : banner option;
    (*

    Possible banner page.

    *)
  6. files : file list;
    (*

    List of files of this job. The files will be removed after the job handling function on_reception return. If you want to keep them longer, rename them or (better) move them to another directory.

    *)
  7. addr : Unix.sockaddr;
    (*

    Address of the machine which connected to this server.

    *)
}

Module specifying the daemon behavior

type jobref =
  1. | User of string
    (*

    Reference all jobs of the given user

    *)
  2. | Num of int
    (*

    Reference the job with the given number

    *)
type queue_actions = {
  1. print : unit -> unit;
    (*

    Function executed when it is requested to start the printing process (if not already running).

    *)
  2. on_reception : job -> unit;
    (*

    Handler for each job received.

    *)
  3. send_queue : jobref list -> Socket.out_channel -> unit;
    (*

    Handler for sending a queue state in short form.

    *)
  4. send_queue_long : jobref list -> Socket.out_channel -> unit;
    (*

    Handler for sending a queue state in long form.

    *)
  5. remove : string -> Unix.sockaddr -> jobref list -> unit;
    (*

    Handler for removing jobs. The string is the user name (the agent) requesting the removal and Unix.sockaddr is the address of the machine which connected the server (to enable security checks). lprm -, requesting to remove all the jobs that the user owns, gives as a list of jobs: [User "-"].

    *)
}

Functions to be executed on queue events.

module type CONFIG = sig ... end
module Make (C : CONFIG) : sig ... end

Make a Line Printer daemon according to the configuration C.

Useful functions

val string_of_current_time : unit -> string

string_of_current_time() returns the current date and time.

val header_of_job : string -> string

header_of_job queue returns a string suitable as a header for Lpd.string_of_job. If queue = "", the mention of the queue is omitted.

val string_of_job : int -> job -> string

header_of_job queue returns a string suitable as a header for Lpd.string_of_job. If queue = "", the mention of the queue is omitted.

string_of_job rank job returns a one line string describing the job. A job with an empty list of files is considered to have been canceled. The rank is a positive number giving the rank of the job in the queue. A rank if 0 means that the job is in the printing stage. string_of_job is a helper function to design a send_queue callback (see Lpd.queue_actions).

val long_string_of_job : int -> job -> string

string_of_job rank job returns a one line string describing the job. A job with an empty list of files is considered to have been canceled. The rank is a positive number giving the rank of the job in the queue. A rank if 0 means that the job is in the printing stage. string_of_job is a helper function to design a send_queue callback (see Lpd.queue_actions).

long_string_of_job rank job does the same as Lpd.string_of_job except that the description is in long format (multi-lines). It is suitable to write send_queue_long callback (see Lpd.queue_actions).

val any_host : Unix.sockaddr -> bool

any_host addr accepts any Internet host which can be found in the DNS.

val these_hosts : ?file:string -> string list -> Unix.sockaddr -> bool

any_host addr accepts any Internet host which can be found in the DNS.

these_hosts ?file hosts adrr accepts connections from Internet hosts or IP addresses listed in the file or in the list hosts.

  • parameter file

    filename containing a list of hosts and IP addresses to authorize separated with white space, tabulations, or newlines. Blanks lines are ignored. Comments start with '#' and last till the end of the line.

OCaml

Innovation. Community. Security.