Commit d4a402fc authored by Tristan Olive's avatar Tristan Olive

Project preference validation

Added validation of uploaded preference specification XML against the XSD file included in the module. If validation fails, an error message is returned with the reason, line number, and the XML at that line.

(DBOINCP-107)
parent f6078efc
......@@ -30,6 +30,19 @@ function boincwork_admin_prefs_upload_form(&$form_state) {
* Handle validation of preference upload form.
*/
function boincwork_admin_prefs_upload_form_validate($form, &$form_state) {
$xsd = './' . drupal_get_path('module', 'boincwork') . '/includes/projectprefs.xsd';
libxml_use_internal_errors(true);
$xml = new DomDocument();
$xml->loadXML($form_state['values']['prefs_xml'], LIBXML_NOBLANKS);
if (!$xml->schemaValidate($xsd)) {
$errors = libxml_get_errors();
$lines = explode("\r", $form_state['values']['prefs_xml']);
drupal_set_message("{$errors[0]->message} at line {$errors[0]->line}" .
': <br/>' . htmlentities($lines[$errors[0]->line - 1]), 'error');
form_set_error('upload', t('XML file failed validation'));
}
// Convert XML to array for validation
$xml = load_configuration($form_state['values']['prefs_xml']);
......
......@@ -186,6 +186,19 @@ function boincwork_get_preset_prefs($preset = null) {
function boincwork_get_project_specific_config() {
$raw_config_data = variable_get('boinc_project_specific_prefs_config', '');
$xsd = './' . drupal_get_path('module', 'boincwork') . '/includes/projectprefs.xsd';
libxml_use_internal_errors(true);
$xml = new DomDocument();
$xml->loadXML($raw_config_data, LIBXML_NOBLANKS);
if (!$xml->schemaValidate($xsd)) {
$errors = libxml_get_errors();
$lines = explode("\r", $raw_config_data);
drupal_set_message("{$errors[0]->message} at line {$errors[0]->line}" .
': <br/>' . htmlentities($lines[$errors[0]->line - 1]), 'error');
return NULL;
}
// Convert XML to array for validation
$xml = load_configuration($raw_config_data);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment