Branch: Tag:

2002-02-06

2002-02-06 09:32:38 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Backported ArgCache fixes from Roxen 2.4.

Rev: server/arg_cache_plugins/replicate.pike:1.13
Rev: server/base_server/roxen.pike:1.772

6:   // Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.   // ABS and suicide systems contributed freely by Francesco Chemolli    - constant cvs_version="$Id: roxen.pike,v 1.771 2002/02/01 16:40:14 wellhard Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.772 2002/02/06 09:32:37 grubba Exp $";      // The argument cache. Used by the image cache.   ArgCache argcache;
3289:    object crypto = Crypto.arcfour();    crypto->set_encrypt_key( server||secret );    string res = crypto->crypt( a+"\327"+b ); +  // Ensure that we do not have a leading NUL. +  res[0] |= 0x80;    res = Gmp.mpz( res, 256 )->digits( 36 );    return res;    }
3317:    return 0;    }    -  static array decode_id( string a ) +  array(int) low_decode_id(string a, string key)    { -  string oa = a; -  ensure_secret(); -  object crypto = Crypto.arcfour(); -  crypto->set_encrypt_key( secret ); +     if( catch( a = Gmp.mpz( a, 36 )->digits( 256 ) ) )    return 0; // Not very likely to work... -  a = crypto->crypt( a ); +  object crypto = Crypto.arcfour(); +  crypto->set_encrypt_key(key); +  a = crypto->crypt(a); +  // Fix the high-order bit altered by encode_id(). +  a[0] &= 0x7f;    int i, j; -  if( sscanf( a, "%d\327%d", i, j ) != 2 ) -  return plugin_decode_id( oa ); +  if((sscanf(a, "%d\327%d", i, j) == 2) && +  (a == i + "\327" + j)) {    return ({ i, j });    } -  +  return 0; +  }    -  +  static array(int) decode_id( string a ) +  { +  array(int) res; +  ensure_secret(); +  if (res = low_decode_id(a, secret)) { +  return res; +  } +  return plugin_decode_id(a); +  } +     int key_exists( string key )    //! Does the key 'key' exist in the cache? Returns 1 if it does, 0    //! if it was not present.