= 4) { $q1pos = FALSE; $q2pos = FALSE; $q1pos = strpos($val, "\""); if (($q1pos !== FALSE) && ($q1pos < ($len-1))) $q2pos = strpos($val, "\"", $q1pos + 1); if (($q1pos !== FALSE) && ($q2pos !== FALSE) && ($q1pos >= 2)) { $rv[SubStr($val, 0, $q1pos-1)] = SubStr($val, $q1pos+1, $q2pos-$q1pos-1); $putidx++; } } } //Unless we couldn't find anything seemingly valid, return the array. if ($putidx > 0) return($rv); else return(FALSE); } } // //-------------------------------------------------------------------------------------------------------------- //Recombines a permission string that has been split from an associative array into a permission string. //No hard error checking is performed, i.e. array names with invalid characters or strings with invalid //characters will slip through in the interest of speed. // function PERM_combine_aa($arg) { $rv = ""; reset($arg); while (list($key, $val) = each($arg)) { $rv = $rv . "\\" . $key . "=\"" . $val . "\""; } return($rv); } // //-------------------------------------------------------------------------------------------------------------- //Recombines a permission string that has been split from an associative array into a permission string. //All invalid characters are stripped from both key names and values (and empty keys are dropped), leading //to a guaranteed valid permission string. This function is naturally slower than the function above because //of the error checking. // function PERM_combine_aa_error_trap($arg) { $rv = ""; //Since we're doing an expensive operation, might as well sort the array, too. ksort($arg); reset($arg); while (list($key, $val) = each($arg)) { if (strlen($key) > 0) //Don't want to go further if key is empty. { //Force the string into numbers and letters for the key. $key = STRFUNC_force_into_subset($key, "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); //It is still possible that the first character is a digit, which is a no-no. //Rip characters off the string until we have either a letter or an empty string. while ((strlen($key) > 0) && (strpos("0123456789", SubStr($key, 0, 1)) !== FALSE)) { $key = SubStr($key, 1, strlen($key) - 1); //Rip the character off the front. } //If we have an empty string, don't proceed. if (strlen($key) > 0) { //Force the value into the allowable character set. $val = STRFUNC_force_into_subset($val, " abcdefghijklmnopqrstuvwxyz-.ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); //Add to the string. $rv = $rv . "\\" . $key . "=\"" . $val . "\""; } } } return($rv); } // //-------------------------------------------------------------------------------------------------------------- //Forces a permission string into valid space. // //This can be done inefficiently by just splitting and then recombining. // //Unit-tested 20060427. // function PERM_force_into_valid_space($arg) { $splitval = PERM_split_aa($arg); //Split it. $rv = PERM_combine_aa_error_trap($splitval); //Recombine it. //Return value to caller. return($rv); } // //-------------------------------------------------------------------------------------------------------------- //End of $RCSfile: perm.inc,v $. //-------------------------------------------------------------------------------------------------------------- ?>