home *** CD-ROM | disk | FTP | other *** search
/ Millennium Time Capsule / AC2000.BIN / disks / ac9_disk / net157 / library.txt < prev    next >
Encoding:
Text File  |  1997-08-05  |  18.6 KB  |  444 lines

  1. **************************************************************************
  2. * NetWorld command rundown... by Paul Jones.
  3. *
  4. * These commands have been 'translated' from C to HBASIC.
  5. *
  6. * Syntax:
  7. * FUNCTION (1) mem& (2)=KRmalloc& (3) (size&) (4)
  8. *
  9. * (1) Is the command is a FUNCTION or SUB-routine.
  10. * (2) The size of the return value (and suggested name)
  11. * (3) The command name
  12. * (4) The parameters (and size of values of parameters).
  13. *
  14. * For any references to the include file's commands, check out the 
  15. * file "INCSPEC.TXT" for more info.
  16. **************************************************************************
  17.  
  18. FUNCTION mem&=KRmalloc& (size&)
  19.  
  20.   - Allocate a block of memory from STiK's internal buffer.
  21.   - Returns 0 if sufficient memory is not available.
  22.   - These memory functions are basically the code in K&R 1 pp 174 - 
  23.     177 but there are some minor differences.  morecore is *never* 
  24.     called. These functions use one block of memory that is Malloc'd 
  25.     when the ACC loads.  Also, the header size is 8 bytes since 
  26.     allocations greater than 2^16 are allowed, therefore memory is 
  27.     always allocated in multiples of 8 bytes.
  28.   - Some bits in the headers are checked during KRmalloc() and 
  29.     KRfree() to determine if memory corruption has occured.
  30.  
  31. SUB KRfree (mem&)
  32.  
  33.   - Free a block that was allocated by KRmalloc() or KRrealloc().
  34.   - Currently, KRfree() does *not* check for a 0 address... (but this 
  35.     is such a good idea, that I will add the test)
  36.  
  37. FUNCTION mem&=KRgetfree& (flag%)
  38.  
  39.   - Return the amount of free space left in STiK's internal buffer.
  40.   - If flag is TRUE return the largest block, otherwise return
  41.     total available space.
  42.  
  43. FUNCTION block&=KRrealloc& (blocksize&, newsize&);
  44.  
  45.   - Change the size of an allocated block.  If newsize is greater than
  46.     oldsize, then copy the contents into the new block.
  47.   - If newsize=0 then free the block and return 0.
  48.   - If blocksize=0 then allocate a new block of newsize
  49.     bytes, but zero the contents before returning.
  50.  
  51. FUNCTION addr&=get_err_text& (code%)
  52.  
  53.   - Returns a pointer to a description of an internal STiK error code. 
  54.     The absolute value of code is used to look up the address on the 
  55.     start of the string (null terminated). If code is out of range, a 
  56.     pointer to "" is returned.
  57.  
  58.   * An easyier way to get an internal STiK string is to use the 
  59.     include file's "gerrtxt$ ()" function.
  60.  
  61. FUNCTION addr&=getvstr& (text&)
  62.  
  63.   - Returns a pointer to the value of a STiK config variable
  64.     set in DEFAULT.CFG  The lookup is not case sensitive.
  65.     The pointer is to the first non blank char after the '='.
  66.   - If a variable does not exist, a pointer to "0" is returned.
  67.   - If a variable has no '= value' "1" is returned (present= TRUE)
  68.   - If a variable has '=', but no value, then "0" is returned.
  69.   - To use this command:
  70.   
  71.     text$="EMAIL"+chr$(0)
  72.     email&=getvstr& (varptr(text$))
  73.  
  74.   * An easyier way to get a STiK string is to use the include file's 
  75.     "gvstr$ ()" function.
  76.  
  77. FUNCTION detect%=carrier_detect% (dummy%())
  78.  
  79.   - If the config variable CDVALID is FALSE, then 0 (unknown) is 
  80.     returned.
  81.   - Otherwise, returns +1 for carrier, -1 for no carrier.
  82.   - Please note that this command needs an array. Since I don't know 
  83.     of a way to make a command with no parameters, I had to use a fake 
  84.     array. The array is not used.
  85.  
  86. FUNCTION cn%=TCP_open% (rhost&, rport%, tos%, obsize&)
  87.  
  88.   - Attempts to open a connection to rhost on rport.
  89.   - tos is Type of Service.  I've never experimented with non zero 
  90.     values.
  91.   - obsize is the size of the output buffer to allocate.
  92.     TCP_send() places data in this buffer.  Size dependant on 
  93.     requirements. Bigger is not necessarily better.  500 to 2000 
  94.     should be OK.
  95.   - TCP_open() returns a connection handle (0..n) or a a negative 
  96.     error code.
  97.   - TCP_open() returns immediately, without waiting for the
  98.     connection to establish.
  99.  
  100.   - Passive opens:-
  101.   - If rhost is 0, then the connection becomes a LISTEN socket, and
  102.     waits for a connection request from a remote host.
  103.   - In this case, rport is the assignment of the local port
  104.     and *not* the remote port...
  105.   - There is no provision for limiting the socket to listen for
  106.     connection from a particular host or port. (ie: always INADDR_ANY)
  107.   - The port must be continually polled for input.  There is
  108.     no other way to see if a connection has been made.
  109.   - Sending data to a connection in LISTEN mode is an error.
  110.   - If a remote host makes a connection, the connection will
  111.     no longer be in LISTEN mode.  Requests from other hosts
  112.     will be denied.  To circumvent this, do another TCP_open(0,...)
  113.     when the first connection is activated.  (or have several
  114.     connections passive opened at the same time)
  115.  
  116.   - NOTE To test the current status of the socket, simply
  117.     call CNbyte_count().  If E_LISTEN is returned, then
  118.     the socket is still in TLISTEN state.  Any other function
  119.     that has a connection handle as an argument will return
  120.     the same error, except TCP_close().
  121.  
  122.   - Author's apology...  It's very rough, but it's really only
  123.     for my own testing.  If I don't have time to make something
  124.     better soon, this method should at least be usable.  The reason
  125.     that it is so rough is that I never intended having LISTEN
  126.     sockets.  Hence, this is a hack.
  127.   * an easyier way to connect to a host is using the include file's 
  128.     "tcp_connect ()" function.
  129.  
  130. FUNCTION er%=TCP_close% (cn%, timeout%)
  131.  
  132.   - Closes a connection.  cn is the connection handle.
  133.   - Returns 0 or a negative error code.
  134.   - timeout is the time in seconds to wait for the connection to close.
  135.     TCP_close() must negotiate the close with the remote host, so
  136.     it can take some time if the net is slow.  Pending data may need
  137.     to be received and discarded before the connection closes cleanly.
  138.   - Note that TCP_close() *must* be called in order to free memory
  139.     that has been allocated for the connection.
  140.   - A timeout of 0 is acceptable for immediate close.
  141.   - If the ESC key is pressed during the timeout period, TCP_close()
  142.     returns immediately with a E_USERTIMEOUT error code.
  143.  
  144. FUNCTION er%=TCP_send% (cn%, buf&, len%)
  145.  
  146.   - Send len bytes from buf on the connection cn.
  147.   - Returns E_NORMAL for success, or an error code.
  148.   - Note that the error E_OBUFFULL is *not* a fatal error.
  149.     If E_OBUFFULL is return, you should loop, for your own timeout 
  150.     period, waiting for the output buffer to clear.  If you have 
  151.     defined a buffer that is smaller than the block you are sending, 
  152.     it will never clear.
  153.   * buf& is actually an address to the start of the string.
  154.  
  155. FUNCTION stat%=TCP_wait_state% (cn%, state%, timeout%)
  156.  
  157.   - Wait for timeout seconds for the connection cn, to reach a 
  158.     particular TCP state.  The primary use for this function is to 
  159.     wait for the TESTABLISH state after calling TCP_open() (though 
  160.     this is not really necessary).
  161.   - Returns E_NORMAL or an error code.
  162.   - If the ESC key is pressed while this function is waiting, it 
  163.     returns E_USERTIMEOUT.
  164.  
  165. FUNCTION stat%=TCP_ack_wait% (cn%, timeout%)
  166.  
  167.   - Wait for all data in the output buffer to be acknowledged by
  168.     the remote host.
  169.   - Note that the timeout is in milliseconds
  170.   - Returns E_NORMAL regardless of whether the timeout is reached
  171.     or the output buffer clears.
  172.   - This is a kludge that you should probably never use...
  173.  
  174. FUNCTION cn%=UDP_open% (rhost&, rport%);
  175.  
  176.   - Open a UDP (datagram) connection with rhost on rport.
  177.   - Returns connection handle or error code.
  178.   - Note that there is really no such thing as a UDP `connection'.
  179.     The UDP functions provide a convenient and consistent method
  180.     for communicating with remote hosts using UDP.
  181.   - UDP is used primarily by the domain name resolver.
  182.  
  183. FUNCTION stat%=UDP_close% (cn%)
  184.  
  185.   - Close the UDP connection cn.
  186.   - Frees the connection handle and any blocks pending in the
  187.     input queue, returns immediately.
  188.  
  189. FUNCTION stat%=UDP_send% (cn%, buf&, len%);
  190.  
  191.   - Sends len bytes from buf on the connection cn.
  192.   - Returns E_NORMAL or an error code.
  193.   - NOTE that the the data will be sent as a single UDP packet, so
  194.     you should make sure that it is appropriately sized for your MTU.
  195.   * buf& is the address of the start of a string.
  196.  
  197. FUNCTION  stat%=CNkick% (cn%)
  198.  
  199.   - 'kick' the connection cn.
  200.   - If there is data waiting to be sent, then restart the 
  201.     retransmission sequence as though it is the first transmission. If 
  202.     there is no data waiting, send an ACK packet to the remote host to 
  203.     let them know we're still here.
  204.   - In theory this is a pointless function.  It is provided so that 
  205.     when the user starts bashing the keyboard during a long delay, the 
  206.     programmer arrange that something happens as a result.  This 
  207.     should save lots of valuable Atari hardware. :-))
  208.   - Since the retransmission algorithm uses exponential backoff,
  209.     (ie: timeout doubles at every retransmission) the function is
  210.     probably not entirely pointless.
  211.   - TCP specs state that excessive retransmissions should be avoided.
  212.   - Returns E_NORMAL or an error code if the connection is invalid.
  213.  
  214. FUNCTION num%=CNbyte_count% (cn%)
  215.  
  216.   - Return the number of bytes waiting in the input queue for
  217.     connection cn, or an error code.
  218.  
  219. FUNCTION byte%=CNget_char% (cn%)
  220.  
  221.   - Return the next char from the input queue for cn, or
  222.     a negative error code.  A return of E_NODATA is *not* fatal.
  223.   - Note that if you are using CNget_char() for data input then
  224.     your loop *must* include CNbyte_count(), or the housekeep()
  225.     function.
  226.  
  227. FUNCTION addr&=CNget_NDB& (cn%)
  228.  
  229.   - Return a pointer to the next block on the input queue for cn, or 0 
  230.     if there are no packets queued.
  231.   - This is potentially the most efficient way of reading the
  232.     input queue, because the NDB contains a point to the actual
  233.     packet that was read in initially.  No data has been copied
  234.     up to this point.
  235.   - There is no way defined for CNget_NDB() to return any other
  236.     connection error status.
  237.   - The NDB structure is defined in TRANSPRT.H
  238.   - Since CNget_NDB() unlinks the packet from the input queue,
  239.     you must use KRfree() to free the packet and the NDB structure
  240.     as well.  The following code is a guide..
  241.  
  242.         addr&=CNget_NDB& (cn%)
  243.  
  244.         if addr&<>0 then process_block(addr&)
  245.  
  246. FUNCTION stat%=CNget_block% (cn%, blk&, len%)
  247.  
  248.   - Fills a block starting at blk with len bytes from cn.
  249.   - If the input queue has less than len bytes, then no data will be 
  250.     transferred.
  251.   - Returns the number of bytes you requested, or an error code.  
  252.     E_NODATA is *not* a fatal error.
  253.  
  254. SUb housekeep dummy%()
  255.  
  256.   - Performs internal housekeeping duties.
  257.     You don't really need to call this function, but an explanation
  258.     is necessary.  housekeep() is called internally by several
  259.     of the other functions listed here.  In particular, all
  260.     of the CN input functions call housekeep() *except* CNget_char().
  261.     (otherwise a whole packet could be received every time CNget_char()
  262.     is called!)
  263.     
  264.   - STiK does not do any background or interrupt processing.
  265.     Everything is acheived by polling.  housekeep() is the
  266.     central function of STiK that does this polling.  It calls
  267.     these functions:-
  268.  
  269.     do_resolve();       Resolver processing, including reading packets
  270.     slip_in();          Reading the serial port
  271.     slip_out();         Writing to the serial port
  272.     tcp_timer();        TCP retransmissions
  273.     frag_ttl_check();   Check time to live in fragment reassembly queue
  274.  
  275.   - Housekeep is now driven by the system_timer interupt.  So it runs
  276.     up to a maximum of 50/sec.  The event_multi in the .ACC no longer
  277.     calls housekeep().  This avoids several problems with Magic.
  278.  
  279.   - NOTE that the efficiency of STiK relates to this function, but I
  280.     have to admit that housekeep() has not been carefully thought out.
  281.     However, if the functions called by housekeep() have no work
  282.     to do, they return quickly.  All the same, they can each be called
  283.     many times each second.
  284.  
  285.   * dummy() is a dummy array.
  286.   
  287. FUNCTION stat%=resolve% (dn&, rdn&, alist&, lsize%)
  288.  
  289.   - Resolve a domain name into one or more IP addresses.
  290.     dn is the domain name.
  291.     rdn is the real domain name, which is returned if dn is an alias (CNAME).
  292.     alist is a pointer to an array where the IP address(s) are returned.
  293.     lsize is the size of that array.
  294.   - If the information is in local cache, then resolve will return it
  295.     immediately, otherwise an algorithm for query of nameservers
  296.     is initiated.  This can take some time, however, the resolver has
  297.     an internal limit on the amout of work it will do in attempting
  298.     to resove a hostname.  (Hence the error code `work limit reached')
  299.   - If rdn=0 then no value is assigned to it.
  300.     Otherwise, a pointer to the domain name associated with the addresses
  301.     is assigned to *rdn, even if it is the same as that requested.
  302.     This pointer must be freed using KRfree().
  303.   - If you pass a dotted decimal ip address to resolve, and request the rdn,
  304.     you will just get the dotted decimal ip back.  This is a kludge, but
  305.     better than the old manner of just crashing.
  306.   - resolve() returns the number of addresses copied to alist,
  307.     or a negative error code.
  308.   - In retrospect, it might not have been all that smart of me to write
  309.     my own DNS resolver, but it is at least educational :-))
  310.     All the same, it is *not* yet finished.  There are some bugs in
  311.     the code at present, and also inefficiency in my algorithm.
  312.   - I'll work on improving it when (if?) I get the chance.
  313.   - NOTE that STiK.ACC will save the dns cache to domain.txt
  314.     every five minutes if AES is active and STiK is enabled.
  315.   * An easyer way of connected to a host is by using the include 
  316.     file's "tcp_connect ()" function.
  317.  
  318. SUB ser_disable dummy%()
  319.  
  320.   - This function disables the serial port prior to disk I/O
  321.     It should only be necessary for combinations of baud rate/
  322.     cpu speed that do not allow DMA and serial I/O to work together.
  323.     Internally, it calls Jan Kriesten's DEVICE.LIB function
  324.     StopReceiver().  This, in turn, calls an IOCTL function
  325.     that might only work with HSMODEM loaded.  I'm not sure.
  326.   - In the current version of STiK this (and ser_enable)
  327.     return without doing anything.  I'm waiting for bug
  328.     reports before I decide what to do with it.
  329.   - NOTE that if the port is disabled (in later STiK versions)
  330.     it *must* be reenabled immediately after the disk I/O, or
  331.     that is the end of the TCP session :-))
  332.   * dummy() is a dummy array.
  333.  
  334. SUB ser_enable dummy%()
  335.  
  336.   - See above...
  337.  
  338. FUNCTION stat%=set_flag% (flag%)
  339.  
  340.   - This calls an assembler routine that sets one of 64 possible
  341.     flags using TAS.  The idea is that with proper flag setting
  342.     STiK should function properly in a pre-emptive multitasking
  343.     environment.  They could also be used for locking of other
  344.     well defined processes, such as mailers etc.
  345.   - Currently I'm only using the first two of these flags, for
  346.     housekeep() and do_resolve() which are not re-entrant.
  347.   - I've yet to actually do the work which would ensure proper
  348.     function of STiK in a pre-emptive environment, so if it
  349.     does work, that's accidental.
  350.   - set_flag() returns TRUE if the flag was already set
  351.     (ie: Someone else owns the lock) or FALSE if the flag was clear,
  352.     and set_flag() changed it successfully.  (ie: the lock is ours).
  353.     (in other words, set_flag() returns the value the flag had
  354.      before this call)
  355.  
  356.   - NOTE that anyone wishing to define a new lock should coordinate
  357.     with me!!!
  358.  
  359. SUB clear_flag (flag%)
  360.  
  361.   - Clears a flag regardless of it's current status.  Returns nothing.
  362.  
  363. FUNCTION CIB&=CNgetinfo& (cn%);
  364.  
  365.   - Returns a pointer to a CIB structure that has information
  366.     about the connection associated with the handle 'cn'.
  367.   - This includes protocol, remote host, remote port, and
  368.     the local port.  The address of the local host can be
  369.     found with stik_cfg->client_ip
  370.   - The pointer is to a live part of the connection information,
  371.     so don't change anything unless you know what you're doing.
  372.   - The definition of a CIB can be found in the `trasnprt.h' file.
  373.  
  374. FUNCTION stat%=on_port% (port&);
  375.  
  376.   - Returns true if port was succesfully opened
  377.   - This turns a physical port on.  It is mainly for use
  378.     by a Dialer.
  379.   - port is the name from the DEV_LIST structure.
  380.  
  381.   - if port is already open this call will return TRUE
  382.   - if port doesn't exist on machine this will return False
  383.  
  384. SUB off_port (port&)
  385.  
  386.   - Turns a physical port off.
  387.   - port is the name from the DEV_LIST structure.
  388.   - mainly for use with a Dialer.
  389.   - experimentation with this function on an active port will
  390.     probably kill the connection.  Play at your own risk!
  391.      
  392. FUNCTION stat%=setvstr% (vs&, value&)
  393.  
  394.   - sets a value in the cfg->cv array.
  395.   - If the value is already present it changes it.
  396.   > Note it doesn't do the following yet.  Right now it only changes
  397.     existing string
  398.   - If the value isn't present then it adds it.
  399.   - returns TRUE if variable was changed/set
  400.   - returns FALSE if array is already full and the variable doesn't exist
  401.  
  402. FUNCTION stat%=query_port% (port&)
  403.  
  404.   - Checks if a given port is active.
  405.   - returns TRUE if port is active
  406.   - returns FALSE if port is inactive
  407.   
  408. FUNCTION stat%=g_resolve% (dn&, rdn&, alist&, lsize%)
  409.  
  410.   -  The only difference between this and resolve is that the code
  411.      uses an evnt_multi.  So it should be non blocking.  But it can
  412.      only be used from GEM applications.
  413.  
  414. FUNCTION stat%=g_TCP_wait_state% (cn%, state%, timeout%)
  415.  
  416.   - This is the GEM version of TCP_wait_state, in all other respects 
  417.     it functions the same.  May only be called from a GEM application.
  418.  
  419. *** NOTE g_TCP_wait_state is experimental and not functioning properly
  420.     yet
  421.     
  422. ------------------------------------------------------------------------
  423.                        Extra NetWorld commands
  424. ------------------------------------------------------------------------
  425.  
  426. FUNCTION tcp_author& (dummy())
  427.  
  428. Returns the address to the start of a string which contains the name 
  429. of the author of the transport layer.
  430.  
  431. FUNCTION tcp_version& (dummy())
  432.  
  433. Returns the address to the start of a string which contains the 
  434. version number of the transport layer.
  435.  
  436. FUNCTION tcp_module& (dummy())
  437.  
  438. Returns the address to the start of a string which contains the 
  439. module information of the transport layer.
  440.  
  441. FUNCTION netwldver& (dummy())
  442.  
  443. Returns the address to the start of a string which contains the 
  444. version number of NetWorld.