Branch: Tag:

2000-09-28

2000-09-28 02:07:12 by Per Hedbor <ph@opera.com>

Solve the 'do not mutilate port variables' bug discussed. Fixes most of [Bug 437 (#437)]

Rev: server/base_server/basic_defvar.pike:1.18
Rev: server/base_server/roxen.pike:1.565
Rev: server/etc/modules/Variable.pmod/module.pmod:1.23

1: - // $Id: module.pmod,v 1.22 2000/09/24 13:35:51 nilsson Exp $ + // $Id: module.pmod,v 1.23 2000/09/28 02:07:12 per Exp $      #include <module.h>   #include <roxen.h>
201:    m_delete( all_warnings, _id );    }    +  void add_warning( string to ) +  //! Like set_warning, but adds to the current warning, if any. +  { +  set_warning( (get_warnings()||"") + to ); +  } +     int set( mixed to )    //! Set the variable to a new value.    //! If this function returns true, the set was successful.
219:    {    if( stringp( e2 ) )    { -  set_warning( e2 ); +  add_warning( e2 );    return ([])[0];    }    throw( e2 );    } -  set_warning( err ); +  add_warning( err );    return low_set( to );    }   
269:    equal(changed_values[ _id ], default_value());    }    +  array(string|mixed) verify_set_from_form( mixed new_value ) +  //! Like verify_set, but only called when the variables are set +  //! from a form. +  { +  return ({ 0, new_value }); +  } +     array(string|mixed) verify_set( mixed new_value )    //! Return ({ error, new_value }) for the variable, or throw a string.    //!
307:    //!    //! Other side effects: Might create warnings to be shown to the    //! user (see get_warnings) +  //! +  //! Calls verify_set_from_form and verify_set    { -  mapping val; +  mixed val;    if( sizeof( val = get_form_vars(id)) && val[""] && -  transform_from_form( val[""] ) != query() ) -  set( transform_from_form( val[""] )); +  (val = transform_from_form( val[""] )) != query() ) +  { +  array b; +  mixed q = catch( b = verify_set_from_form( val ) ); +  if( q || sizeof( b ) != 2 ) +  { +  if( q ) +  add_warning( q ); +  else +  add_warning( "Internal error: Illegal sized array " +  "from verify_set_from_form\n" ); +  return;    } -  +  if( q[0] ) set_warning( q[0] ); +  set( q[1] ); +  } +  }       string path()    //! A unique identifier for this variable.
616:    constant type = "URL";    constant width = 50;    -  array verify_set( string new_value ) +  array verify_set_from_form( string new_value )    {    return verify_port( new_value, 1 );    }
1054:    inherit List;    constant type="URLList";    -  array verify_set( array(string) new_value ) +  array verify_set_from_form( array(string) new_value )    {    string warn = "";    array res = ({});
1078:    inherit List;    constant type="PortList";    -  array verify_set( array(string) new_value ) +  array verify_set_from_form( array(string) new_value )    {    string warn = "";    array res = ({});