home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2001 January / LCD_01_2001.iso / develop / dhst / c / cookies.c next >
Encoding:
C/C++ Source or Header  |  2000-05-03  |  4.1 KB  |  169 lines

  1. /* Filename                    : Cookies.c - Cookies functions
  2.  * Number of functions    : 4
  3.  * Version                    : 1.01
  4.  * Author                    : Nicolas Richeton ( nicolas.richeton@free.fr )
  5.  * Last update                : 20/04/2000
  6.  * Statut                    : Freeware
  7.  * Downloaded from        : http://nicosoft.free.atari.fr
  8.  * Comments                    : Based on the work of Thomas Much
  9.  * History                    : 20/04/2000 - Added LDG version
  10.  *                        16/02/2000 - First version
  11.  */
  12.  
  13. /* Includes */
  14. #include <mgx_dos.h>
  15. #include    <portab.h>
  16.  
  17. /* Functions definitions */
  18.  
  19. COOKIE *Cookie_GetCookieJar( VOID );
  20. /* Name                : Get Cookie Jar - Get the 1st cookie of the cookie jar
  21.  * Definition        : COOKIE *Cookie_GetCookieJar( VOID );
  22.  * Prototype in    : cookies.h
  23.  * Parameters        : None
  24.  * Answer            : Pointer on a COOKIE struct
  25.  * Author            : Nicolas Richeton ( nicolas.richeton@free.fr )
  26.  * Version            : 1.00
  27.  * Last update        : 20/04/2000
  28.  * Comments            : Based on the work of Thomas Much
  29.  * History            : 20/04/2000 - Converted to LDG
  30.  *                  16/02/2000 - First version
  31.  */
  32.  
  33. ULONG    Cookie_GetCookie( ULONG id, ULONG *value );
  34. /* Name                : Get Cookie - Get the value of a cookie
  35.  * Definition        : ULONG    Cookie_GetCookie( ULONG id, ULONG *value );
  36.  * Prototype in    : cookies.h
  37.  * Parameters        : id - Id of the cookie
  38.  *                          *value - pointer on a long where the value will be written
  39.  * Answer            : (ULONG)1 - Ok
  40.  *                        : (ULONG)0 - Error (no such cookie or no cookie jar)
  41.  * Author            : Nicolas Richeton ( nicolas.richeton@free.fr )
  42.  * Version            : 1.00
  43.  * Last update        : 20/04/2000
  44.  * Comments            : Based on the work of Thomas Much
  45.  * History            : 20/04/2000 - Converted to LDG
  46.  *                  16/02/2000 - First version
  47.  */
  48.  
  49. ULONG  Cookie_NewCookie( ULONG id, ULONG value );
  50. /* Name                : New Cookie - Create a new cookie 
  51.  * Definition        : ULONG  Cookie_NewCookie( ULONG id, ULONG value );
  52.  * Prototype in    : cookies.h
  53.  * Parameters        : id - Id of the cookie
  54.  *                          value - Value of the cookie
  55.  * Answer            : (ULONG)1 - Ok
  56.  *                        : (ULONG)0 - Error (not enough room or no cookie jar)
  57.  * Author            : Nicolas Richeton ( nicolas.richeton@free.fr )
  58.  * Version            : 1.00
  59.  * Last update        : 20/04/2000
  60.  * Comments            : Based on the work of Thomas Much
  61.  * History            : 20/04/2000 - Converted to LDG
  62.  *                  16/02/2000 - First version
  63.  */
  64.  
  65. ULONG  Cookie_RemoveCookie( ULONG id );
  66. /* Name                : Remove Cookie - Remove a cookie from the cookie jar
  67.  * Definition        : ULONG  Cookie_RemoveCookie( ULONG id );
  68.  * Prototype in    : cookies.h
  69.  * Parameters        : id - Id of the cookie
  70.  * Answer            : (int)1 - Ok
  71.  *                        : (int)0 - Error (no such cookie or no cookie jar)
  72.  * Author            : Nicolas Richeton ( nicolas.richeton@free.fr )
  73.  * Version            : 1.00
  74.  * Last update        : 20/04/2000
  75.  * Comments            : Based on the work of Thomas Much
  76.  * History            : 20/04/2000 - Converted to LDG
  77.  *                  16/02/2000 - First version
  78.  */
  79.  
  80. COOKIE*    Cookie_GetCookieJar( VOID )
  81. {
  82.     return( (COOKIE *)Setexc( 360, (VOID (*)())-1L ) );
  83. }
  84.  
  85.  
  86. ULONG    Cookie_GetCookie( ULONG id, ULONG *value )
  87. {
  88.     COOKIE *cookiejar = Cookie_GetCookieJar();
  89.  
  90.     if( cookiejar )
  91.     {
  92.         while( cookiejar->key )
  93.         {
  94.             if( cookiejar->key == id )
  95.             {
  96.                 if( value ) *value = cookiejar->value;
  97.                 return( 1 );
  98.             }
  99.  
  100.             cookiejar++;
  101.         }
  102.     }
  103.  
  104.     return( 0 );
  105. }
  106.  
  107.  
  108. ULONG    Cookie_NewCookie( ULONG id, ULONG value )
  109. {
  110.     COOKIE *cookiejar = Cookie_GetCookieJar();
  111.  
  112.     if( cookiejar )
  113.     {
  114.         long maxc, anz = 1;
  115.  
  116.         while( cookiejar->key )
  117.         {
  118.             anz++;
  119.             cookiejar++;
  120.         }
  121.  
  122.         maxc = cookiejar->value;
  123.  
  124.         if( anz < maxc )
  125.         {
  126.             cookiejar->key    = id;
  127.             cookiejar->value = value;
  128.  
  129.             cookiejar++;
  130.  
  131.             cookiejar->key    = 0L;
  132.             cookiejar->value = maxc;
  133.  
  134.             return( 1 );
  135.         }
  136.     }
  137.  
  138.     return( 0 );
  139. }
  140.  
  141.  
  142. ULONG    Cookie_RemoveCookie( ULONG id )
  143. {
  144.     COOKIE *cookiejar = Cookie_GetCookieJar();
  145.  
  146.     if( cookiejar )
  147.     {
  148.         while( ( cookiejar->key ) && ( cookiejar->key != id ) ) cookiejar++;
  149.  
  150.         if( cookiejar->key )
  151.         {
  152.             COOKIE *cjo;
  153.  
  154.             do
  155.             {
  156.                 cjo = cookiejar++;
  157.  
  158.                 cjo->key    = cookiejar->key;
  159.                 cjo->value = cookiejar->value;
  160.  
  161.             } while( cookiejar->key );
  162.  
  163.             return( 1 );
  164.         }
  165.     }
  166.  
  167.     return( 0 );
  168.  
  169. }