Roxen.git / server / etc / modules / Variable.pmod / module.pmod

version» Context lines:

Roxen.git/server/etc/modules/Variable.pmod/module.pmod: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>      // Locale macros   static inline string getloclang() {    return roxenp()->locale->get();   }      //<locale-token project="roxen_config"> LOCALE </locale-token>
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:194:       void set_warning( string to )    //! Set the warning shown in the configuration interface    {    if( to && strlen(to) )    all_warnings[ _id ] = to;    else    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.    //! Otherwise 0 is returned. 0 is also returned if the variable was    //! not changed by the set. 1 is returned if the variable was    //! changed, and -1 is returned if the variable was changed back to    //! it's default value.    //!    //! If verify_set() threw a string, ([])[0] is returned, that is,    //! 0 with zero_type set.    //!    //! If verify_set() threw an exception, the exception is thrown.    {    string err, e2;    if( e2 = catch( [err,to] = verify_set( to )) )    {    if( stringp( e2 ) )    { -  set_warning( e2 ); +  add_warning( e2 );    return ([])[0];    }    throw( e2 );    } -  set_warning( err ); +  add_warning( err );    return low_set( to );    }       int low_set( mixed to )    //! Forced set. No checking is done whatsoever.    //! 1 is returned if the variable was changed, -1 is returned if    //! the variable was changed back to it's default value and 0    //! otherwise.    {    if( equal( to, query() ) )
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:262:    return default_value();    }       int is_defaulted()    //! Return true if this variable is set to it's default value.    {    return zero_type( changed_values[ _id ] ) ||    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.    //!    //! If error != 0, it should contain a warning or error message.    //! If new_value is modified, it will be used instead of the    //! supplied value.    //!    //! If a string is thrown, it will be used as a error message from    //! set, and the variable will not be changed.    {
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:300:    return what;    }       void set_from_form( RequestID id )    //! Set this variable from the form variable in id->Variables,    //! if any are available. The default implementation simply sets    //! the variable to the string in the form variables.    //!    //! 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.    //! Should be used to prefix form variable names.    //!    //! Unless this variable was created by defvar(), the path is set    //! by the configuration interface the first time the variable is    //! to be shown in a form. This function can thus return 0. If it    //! does, and you still have to show the form, call set_path( )    //! with a unique string.
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:609:    constant width = 50;   }      class URL   //! A URL.   {    inherit String;    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 );    }   }      class Directory   //! A Directory.   {    inherit String;    constant type = "Directory";
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1047:    }    float transform_from_form(string what) { return (float)what; }   }      class URLList   //! A list of URLs   {    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 = ({});    foreach( new_value, string vv )    {    string tmp1, tmp2;    [tmp1,tmp2] = verify_port( vv, 1 );    if( tmp1 )    warn += tmp1;    res += ({ tmp2 });
Roxen.git/server/etc/modules/Variable.pmod/module.pmod:1071:    return ({ warn, res });    }   }      class PortList   //! A list of Port URLs   {    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 = ({});    foreach( new_value, string vv )    {    string tmp1, tmp2;    [tmp1,tmp2] = verify_port( vv, 0 );    if( tmp1 )    warn += tmp1;    res += ({ tmp2 });