logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

Callback Functions

       A tftp callback module is to be implemented as a tftp behavior and export the  functions  listed  in  the
       following.

       On  the  server  side,  the callback interaction starts with a call to open/5 with the registered initial
       callback state. open/5 is expected to open the (virtual) file. Then either function read/1 or write/2  is
       invoked  repeatedly,  once  per  transferred  block.  At  each function call, the state returned from the
       previous call is obtained. When the last block is encountered, function read/1 or write/2 is expected  to
       close  the  (virtual)  file and return its last state. Function abort/3 is only used in error situations.
       Function prepare/5 is not used on the server side.

       On the client side, the callback interaction is the same, but it starts and ends a  bit  differently.  It
       starts  with  a  call  to  prepare/5  with  the  same arguments as open/5 takes. prepare/5 is expected to
       validate the TFTP options suggested by the user and to return the subset of them that  it  accepts.  Then
       the  options  are  sent  to  the  server,  which performs the same TFTP option negotiation procedure. The
       options that are accepted by the server are forwarded to function open/5  on  the  client  side.  On  the
       client  side,  function  open/5  must  accept  all option as-is or reject the transfer. Then the callback
       interaction follows the same pattern as described for the server side. When the last block is encountered
       in read/1 or write/2, the returned state is forwarded to  the  user  and  returned  from  read_file/3  or
       write_file/3.

       If  a  callback (performing the file access in the TFTP server) takes too long time (more than the double
       TFTP time-out), the server aborts the connection and sends an error reply to  the  client.  This  implies
       that  the  server  releases  resources  attached  to the connection faster than before. The server simply
       assumes that the client has given up.

       If the TFTP server receives yet another request from the same  client  (same  host  and  port)  while  it
       already has an active connection to the client, it ignores the new request if the request is equal to the
       first  one  (same filename and options). This implies that the (new) client will be served by the already
       ongoing connection on the server side. By not setting up yet another connection,  in  parallel  with  the
       ongoing one, the server consumes less resources.

Data Types

ServiceConfig=OptionsOptions=[option()]

       Most  of  the  options  are  common  for  both the client and the server side, but some of them differs a
       little. The available option()s are as follows:

         {debug,Level}:
           Level=none|error|warning|brief|normal|verbose|all

           Controls the level of debug printouts. Default is none.

         {host,Host}:
           Host=hostname(), see inet(3erl).

           The name or IP address of the host where the TFTP daemon resides. This option is  only  used  by  the
           client.

         {port,Port}:
           Port=int()

           The  TFTP  port where the daemon listens. Defaults is the standardized number 69. On the server side,
           it can sometimes make sense to set it to 0, meaning that the daemon just picks a free port (which one
           is returned by function info/1).

           If a socket is connected already, option {udp,[{fd,integer()}]} can be used to pass the  open  file
           descriptor  to  gen_udp.  This can be automated by using a command-line argument stating the prebound
           file descriptor number. For example, if  the  port  is  69  and  file  descriptor  22  is  opened  by
           setuid_socket_wrap, the command-line argument "-tftpd_69 22" triggers the prebound file descriptor 22
           to  be  used instead of opening port 69. The UDP option {udp,[{fd,22}]} is automatically added. See
           init:get_argument/ about command-line arguments and gen_udp:open/2 about UDP options.

         {port_policy,Policy}:
           Policy=random|Port|{range,MinPort,MaxPort}Port=MinPort=MaxPort=int()

           Policy for the selection of the temporary port that is used by  the  server/client  during  the  file
           transfer.  Default  is  random,  which is the standardized policy. With this policy a randomized free
           port is used. A single port or a range of ports can be  useful  if  the  protocol  passes  through  a
           firewall.

         {udp,Options}:
           Options=[Opt], see gen_udp:open/2.

         {use_tsize,Bool}:
           Bool=bool()

           Flag for automated use of option tsize. With this set to true, the write_file/3 client determines the
           filesize  and  sends it to the server as the standardized tsize option. A read_file/3 client acquires
           only a filesize from the server by sending a zero tsize.

         {max_tsize,MaxTsize}:
           MaxTsize=int()|infinity

           Threshold for the maximal filesize in bytes. The transfer  is  aborted  if  the  limit  is  exceeded.
           Default is infinity.

         {max_conn,MaxConn}:
           MaxConn=int()|infinity

           Threshold  for  the  maximal  number  of  active  connections.  The  daemon  rejects the setup of new
           connections if the limit is exceeded. Default is infinity.

         {TftpKey,TftpVal}:
           TftpKey=string()TftpVal=string()

           Name and value of a TFTP option.

         {reject,Feature}:
           Feature=Mode|TftpKeyMode=read|writeTftpKey=string()

           Controls which features to reject. This is mostly useful for the server as it can restrict the use of
           certain TFTP options or read/write access.

         {callback,{RegExp,Module,State}}:
           RegExp=string()Module=atom()State=term()

           Registration of a callback module. When a file is to be transferred, its local filename is matched to
           the regular expressions of the registered callbacks. The first matching callback is used  during  the
           transfer. See read_file/3 and write_file/3.

           The callback module must implement the tftp behavior, see CALLBACK FUNCTIONS.

         {logger,Module}:
           Module=module()

           Callback  module  for  customized logging of errors, warnings, and info messages. The callback module
           must implement the tftp_logger behavior, see LOGGER FUNCTIONS. The default module is tftp_logger.

         {max_retries,MaxRetries}:
           MaxRetries=int()

           Threshold for the maximal number of retries. By default the server/client tries to resend  a  message
           up to five times when the time-out expires.

Description

       Interface module for the tftp application.

Exports

Logger:error_msg(Format,Data)->ok|exit(Reason)

              Types:

                 Format = string()
                 Data = [term()]
                 Reason = term()

              Logs an error message. See error_logger:error_msg/2 for details.

       Logger:info_msg(Format,Data)->ok|exit(Reason)

              Types:

                 Format = string()
                 Data = [term()]
                 Reason = term()

              Logs an info message. See error_logger:info_msg/2 for details.

       Logger:warning_msg(Format,Data)->ok|exit(Reason)

              Types:

                 Format = string()
                 Data = [term()]
                 Reason = term()

              Logs a warning message. See error_logger:warning_msg/2 for details.

Ericsson AB                                        tftp 1.0.3                                         tftp(3erl)

Logger Functions

       A  tftp_logger  callback  module  is to be implemented as a tftp_logger behavior and export the following
       functions:

Name

       tftp - Trivial FTP.

See Also