?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE Accounting and Validation: Store Validation Information' ??
MODULE avm$store_validation_info;
{
{ PURPOSE:
{   This module contains the interfaces used to store validation information
{ into job pageable at login.
{
{ DESIGN:
{   This module contains only the procedure AVP$STORE_VALIDATION_INFO.
{
*copyc avc$compile_test_code
*copyc dft$procedure_address_ordinal
?? PUSH (LISTEXT := ON) ??
?? NEWTITLE := '  Declarations', EJECT ??
*copyc avc$validation_field_names
*copyc ave$validation_interface_errors
*copyc avt$account_name
*copyc avt$project_name
*copyc avt$template_file_record
*copyc avt$validation_key
*copyc i#current_sequence_position
*copyc jmc$system_family
*copyc osp$get_set_name
*copyc ost$user_identification

  TYPE
    avt$server_get_val_info_input = record
      validation_level: avt$validation_level,
      family_name: ost$family_name,
      user_name: ost$user_name,
      account_name: avt$account_name,
      project_name: avt$project_name,
    recend;

  TYPE
    avt$server_get_val_info_output = record
      account_name: avt$account_name,
      project_name: avt$project_name,
    recend;

?? POP ??
?? OLDTITLE ??
?? NEWTITLE := '  XREF Procedures', EJECT ??
*copyc avp$close_validation_file
*copyc avp$get_field
*copyc avp$open_system_validation_file
*copyc avp$read_data_record
*copyc avp$validation_level
*copyc dfp$send_remote_procedure_call
*copyc osp$set_status_abnormal
*copyc osp$set_status_from_condition
*copyc pfp$define_master_catalog
?? OLDTITLE ??
?? NEWTITLE := '  Static Variables', EJECT ??
*copyc oss$job_pageable
*copyc ost$heap
  ?IF avc$compile_test_code THEN

    VAR
      osv$job_pageable_heap: [XREF] ^ost$heap;

  ?ELSE
*copyc osv$job_pageable_heap
  ?IFEND

{ Varibles used to hold pointers to the validation information for a job.

  VAR
    avv$user_data_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL,
    avv$account_data_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL,
    avv$account_member_data_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL,
    avv$project_data_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL,
    avv$project_member_data_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL,
    avv$user_description_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL,
    avv$account_description_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL,
    avv$account_member_desc_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL,
    avv$project_description_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL,
    avv$project_member_desc_record: [XDCL, #GATE, oss$job_pageable] ^avt$template_file_record := NIL;

?? OLDTITLE ??
?? NEWTITLE := '  avp$store_validation_info', EJECT ??
{
{ PURPOSE:
{
{   This interfaces is used to store validation information for a job
{ into job pageable at login.
{
{ DESIGN:
{
{   The XDCLed variables used to hold pointers to the validation information
{ for the job are all initialized to NIL.
{
{   The validation file is opened.
{
{   The user validation information is placed into memory, and the pointer
{ variables to the information is set.
{
{   The system validation level determines whether account and project and
{ member information for this job is placed into memory, and if they are
{ the pointer variables to them are set.
{
{   The validation file is closed.
{

  PROCEDURE [XDCL, #GATE] avp$store_validation_info
    (    family_name: ost$family_name;
         user_name: ost$user_name;
     VAR account_name: avt$account_name;
     VAR project_name: avt$project_name;
     VAR status: ost$status);

    VAR
      data_size_to_send_to_server: dft$send_data_size,
      ignore_status: ost$status,
      p_data_received_from_server: dft$p_receive_data,
      p_data_to_send_to_server: dft$p_send_data,
      p_params_received_from_server: dft$p_receive_parameters,
      p_params_to_send_to_server: dft$p_send_parameters,
      params_size_to_send_to_server: dft$send_parameter_size,
      queue_entry_location: dft$rpc_queue_entry_location,
      server_locator: dft$server_location,
      set_name: stt$set_name,
      temporary_charge_id: pft$charge_id,
      validation_level: avt$validation_level;

?? NEWTITLE := '    client_store_validation_info' , EJECT ??

    PROCEDURE client_store_validation_info
      (    validation_level: avt$validation_level;
           family_name: ost$family_name;
           user_name: ost$user_name;
       VAR account_name: avt$account_name;
       VAR project_name: avt$project_name;
       VAR queue_entry_location: dft$rpc_queue_entry_location;
       VAR p_params_to_send_to_server: dft$p_send_parameters;
       VAR p_data_to_send_to_server: dft$p_send_data;
       VAR params_size_to_send_to_server: dft$send_parameter_size;
       VAR data_size_to_send_to_server: dft$send_data_size;
       VAR p_params_received_from_server: dft$p_receive_parameters;
       VAR p_data_received_from_server: dft$p_receive_data;
       VAR status: ost$status);

?? NEWTITLE := '      build_info_to_send_to_server', EJECT ??

      PROCEDURE build_info_to_send_to_server
        (    validation_level: avt$validation_level;
             family_name: ost$family_name;
             user_name: ost$user_name;
         VAR account_name: avt$account_name;
         VAR project_name: avt$project_name;
         VAR p_params_to_send_to_server: dft$p_send_parameters;
         VAR p_data_to_send_to_server: dft$p_send_data;
         VAR params_size_to_send_to_server: dft$send_parameter_size;
         VAR data_size_to_send_to_server: dft$send_data_size);

        VAR
          server_get_val_info_input: ^avt$server_get_val_info_input;

        params_size_to_send_to_server := 0;
        data_size_to_send_to_server := 0;

        NEXT server_get_val_info_input IN p_params_to_send_to_server;
        server_get_val_info_input^.validation_level := validation_level;
        server_get_val_info_input^.family_name := family_name;
        server_get_val_info_input^.user_name := user_name;
        server_get_val_info_input^.account_name := account_name;
        server_get_val_info_input^.project_name := project_name;

        params_size_to_send_to_server := i#current_sequence_position (p_params_to_send_to_server);

      PROCEND build_info_to_send_to_server;
?? OLDTITLE ??
?? NEWTITLE := '      extract_info_sent_from_server', EJECT ??

      PROCEDURE extract_info_sent_from_server
        (    validation_level: avt$validation_level;
         VAR p_params_received_from_server: dft$p_receive_parameters;
         VAR p_data_received_from_server: dft$p_receive_data;
         VAR account_name: avt$account_name;
         VAR project_name: avt$project_name);

        VAR
          server_get_val_info_output: ^avt$server_get_val_info_output;

?? NEWTITLE := '        retrieve_validation_info', EJECT ??

        PROCEDURE retrieve_validation_info
          (VAR p_data_received_from_server: dft$p_receive_data;
           VAR data_record: ^avt$template_file_record;
           VAR description_record: ^avt$template_file_record);

          VAR
            data_record_size: ^integer,
            description_record_size: ^integer,
            temp_data_record: ^avt$template_file_record,
            temp_description_record: ^avt$template_file_record;

{ Retrieve data record information.

          NEXT data_record_size IN p_data_received_from_server;
          IF data_record_size^ <> 0 THEN
            NEXT temp_data_record: [[REP data_record_size^ OF cell]] IN p_data_received_from_server;
            RESET temp_data_record;
            ALLOCATE data_record: [[REP data_record_size^ OF cell]] IN osv$job_pageable_heap^;
            RESET data_record;
            data_record^ := temp_data_record^;
          ELSE
            data_record := NIL;
          IFEND;

{ Retrieve description record information.

          NEXT description_record_size IN p_data_received_from_server;
          IF description_record_size^ <> 0 THEN
            NEXT temp_description_record: [[REP description_record_size^ OF cell]] IN
                  p_data_received_from_server;
            RESET temp_description_record;
            ALLOCATE description_record: [[REP description_record_size^ OF cell]] IN osv$job_pageable_heap^;
            RESET description_record;
            description_record^ := temp_description_record^;
          ELSE
            description_record := NIL;
          IFEND;

        PROCEND retrieve_validation_info;
?? OLDTITLE, EJECT ??
{ Retrieve the account and project information.

        NEXT server_get_val_info_output IN p_params_received_from_server;
        account_name := server_get_val_info_output^.account_name;
        project_name := server_get_val_info_output^.project_name;

{ Retrieve user information.

        retrieve_validation_info (p_data_received_from_server, avv$user_data_record,
              avv$user_description_record);

        IF validation_level > avc$user_level THEN

{ Retrieve account information.

          retrieve_validation_info (p_data_received_from_server, avv$account_data_record,
                avv$account_description_record);

{ Retrieve account member information.

          retrieve_validation_info (p_data_received_from_server, avv$account_member_data_record,
                avv$account_member_desc_record);

        IFEND;
        IF validation_level > avc$account_level THEN

{ Retrieve project information.

          retrieve_validation_info (p_data_received_from_server, avv$project_data_record,
                avv$project_description_record);

{ Retrieve project member information.

          retrieve_validation_info (p_data_received_from_server, avv$project_member_data_record,
                avv$project_member_desc_record);

        IFEND;

      PROCEND extract_info_sent_from_server;
?? OLDTITLE, EJECT ??
      status.normal := TRUE;

      build_info_to_send_to_server (validation_level, family_name, user_name, account_name, project_name,
            p_params_to_send_to_server, p_data_to_send_to_server, params_size_to_send_to_server,
            data_size_to_send_to_server);

      dfp$send_remote_procedure_call (queue_entry_location, dfc$get_validation_info,
            params_size_to_send_to_server, data_size_to_send_to_server, p_params_received_from_server,
            p_data_received_from_server, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

      extract_info_sent_from_server (validation_level, p_params_received_from_server,
            p_data_received_from_server, account_name, project_name);

    PROCEND client_store_validation_info;
?? OLDTITLE ??
?? NEWTITLE := '    store_validation_info', EJECT ??

    PROCEDURE store_validation_info
      (    validation_level: avt$validation_level;
           family_name: ost$family_name;
           user_name: ost$user_name;
       VAR account_name: avt$account_name;
       VAR project_name: avt$project_name;
       VAR status: ost$status);

      VAR
        data_record_size: 0 .. avc$max_template_record_size,
        default_value: avt$field_value,
        description_record_name: ost$name,
        description_record_size: 0 .. avc$max_template_record_size,
        descriptive_text: ^avt$descriptive_text,
        field_value: avt$field_value,
        file_information: avt$template_file_information,
        ignore_status: ost$status,
        key: avt$validation_key,
        type_specification: avt$type_specification,
        utility_information: ^avt$utility_information;
?? NEWTITLE := '      read_data_record', EJECT ??
      PROCEDURE read_data_record
        (    key: avt$validation_key;
         VAR data_record: ^avt$template_file_record;
         VAR description_record: ^avt$template_file_record;
         VAR file_information: avt$template_file_information;
         VAR status: ost$status);

        VAR
          data_record_size: 0 .. avc$max_template_record_size,
          description_record_size: 0 .. avc$max_template_record_size,
          description_record_name: ost$name,
          field_count: avt$field_count;

{ Retrieve the size of the data and description record.

        data_record := NIL;
        description_record := NIL;
        avp$read_data_record (key.value, avc$read_access, TRUE, data_record, data_record_size,
              description_record, description_record_size, description_record_name, field_count,
              file_information, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

{ Allocate and read space until the data and description records are obtained.

        REPEAT
          ALLOCATE data_record: [[REP data_record_size OF cell]] IN osv$job_pageable_heap^;
          RESET data_record;
          ALLOCATE description_record: [[REP description_record_size OF cell]] IN osv$job_pageable_heap^;
          RESET description_record;
          avp$read_data_record (key.value, avc$read_access, TRUE, data_record, data_record_size,
                description_record, description_record_size, description_record_name, field_count,
                file_information, status);
          IF NOT status.normal THEN
            FREE data_record IN osv$job_pageable_heap^;
            FREE description_record IN osv$job_pageable_heap^;
            IF status.condition <> ave$work_area_full THEN
              RETURN;
            IFEND;
          IFEND;
        UNTIL status.normal;

      PROCEND read_data_record;
?? OLDTITLE, EJECT ??
      status.normal := TRUE;

{ Open the validation file.

      avp$open_system_validation_file (family_name, file_information, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

    /get_validation_information/
      BEGIN

        key.account_name := avc$high_value_name;
        key.project_name := avc$high_value_name;
        key.user_name := user_name;
        read_data_record (key, avv$user_data_record, avv$user_description_record, file_information, status);
        IF NOT status.normal THEN
          IF status.condition = ave$unknown_record THEN

{ If the user specified does not exist on the validation file then return
{ a message that gives no information to the caller. (for security.)

            osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
          IFEND;
          EXIT /get_validation_information/;
        IFEND;

{ If no account and/or project were specified get the defaults from the user
{ record.

        IF ((account_name = osc$null_name) OR (project_name = osc$null_name)) THEN
          avp$get_field (avc$default_account_project, avv$user_data_record, avv$user_description_record,
                {work_area=} NIL, field_value, type_specification, default_value, descriptive_text,
                utility_information, status);
          IF NOT status.normal THEN
            EXIT /get_validation_information/;
          IFEND;
          IF account_name = osc$null_name THEN
            account_name := field_value.account_name^;
          IFEND;
          IF project_name = osc$null_name THEN
            project_name := field_value.project_name^;
          IFEND;
        IFEND;

        IF validation_level > avc$user_level THEN

{ If running at account level or above get the account and account member
{ validation information.

{ Read the account record.

          key.account_name := account_name;
          key.project_name := osc$null_name;
          key.user_name := osc$null_name;
          read_data_record (key, avv$account_data_record, avv$account_description_record, file_information,
                status);
          IF NOT status.normal THEN
            IF status.condition = ave$unknown_record THEN
              osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
            IFEND;
            EXIT /get_validation_information/;
          IFEND;

{ Read the account member record.

          key.account_name := account_name;
          key.project_name := osc$null_name;
          key.user_name := user_name;
          read_data_record (key, avv$account_member_data_record, avv$account_member_desc_record,
                file_information, status);
          IF NOT status.normal THEN
            IF status.condition = ave$unknown_record THEN
              status.normal := TRUE;
              key.account_name := account_name;
              key.project_name := osc$null_name;
              key.user_name := 'PUBLIC';
              read_data_record (key, avv$account_member_data_record, avv$account_member_desc_record,
                    file_information, status);
              IF NOT status.normal THEN
                IF status.condition = ave$unknown_record THEN
                  status.normal := TRUE;
                ELSE
                  EXIT /get_validation_information/;
                IFEND;
              IFEND;
            ELSE
              EXIT /get_validation_information/;
            IFEND;
          IFEND;
        IFEND;

        IF validation_level > avc$account_level THEN

{ If running at project level get the project, and project member
{ validation information.

{ Read the project record.

          key.account_name := account_name;
          key.project_name := project_name;
          key.user_name := osc$null_name;
          read_data_record (key, avv$project_data_record, avv$project_description_record, file_information,
                status);
          IF NOT status.normal THEN
            IF status.condition = ave$unknown_record THEN
              osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
            IFEND;
            EXIT /get_validation_information/;
          IFEND;

{ Read the project member information if available.

          key.account_name := account_name;
          key.project_name := project_name;
          key.user_name := user_name;
          read_data_record (key, avv$project_member_data_record, avv$project_member_desc_record,
                file_information, status);
          IF NOT status.normal THEN
            IF status.condition = ave$unknown_record THEN
              status.normal := TRUE;
              key.account_name := account_name;
              key.project_name := project_name;
              key.user_name := 'PUBLIC';
              read_data_record (key, avv$project_member_data_record, avv$project_member_desc_record,
                    file_information, status);
              IF NOT status.normal THEN
                IF status.condition = ave$unknown_record THEN
                  status.normal := TRUE;
                ELSE
                  EXIT /get_validation_information/;
                IFEND;
              IFEND;
            ELSE
              EXIT /get_validation_information/;
            IFEND;
          IFEND;
        IFEND;

{ The specified user must be a member of the account at account level.

        IF validation_level = avc$account_level THEN
          IF avv$account_member_data_record = NIL THEN
            osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
          IFEND;

{ The specified user must be a member of the account OR a member of the
{ project at project level.

        ELSEIF validation_level = avc$project_level THEN
          IF (avv$account_member_data_record = NIL) AND (avv$project_member_data_record = NIL) THEN
            osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
          IFEND;
        IFEND;

      END /get_validation_information/;

      IF status.normal THEN
        avp$close_validation_file (file_information, status);
      ELSE
        avp$close_validation_file (file_information, ignore_status);
      IFEND;

    PROCEND store_validation_info;
?? OLDTITLE ??
?? NEWTITLE := 'dfp$remote_procedure_call_ch', EJECT ??

{ PURPOSE:
{   This procedure is a condition handler established to call a routine to clear the assignment of a task
{   services queue_entry if a task aborts with a queue_entry assigned to it.  The queue_entry must be clear
{   before the task can safely exit.

    PROCEDURE dfp$remote_procedure_call_ch
      (    condition: pmt$condition;
           cond_desc: ^pmt$condition_information;
           save: ^ost$stack_frame_save_area;
       VAR handler_status: ost$status);

      dfp$ch_cleanup;
      osp$set_status_from_condition (dfc$file_server_id, condition, save, status, handler_status);
      EXIT avp$store_validation_info;

    PROCEND dfp$remote_procedure_call_ch;
*block
*copyc dfp$begin_ch_remote_proc_call
*copyc dfp$end_ch_remote_proc_call
*blockend
?? OLDTITLE, EJECT ??
    status.normal := TRUE;

    validation_level := avp$validation_level ();

    server_locator.server_location_selector := dfc$family_name;
    server_locator.family_name := family_name;
    ?IF avc$compile_test_code THEN
      status.normal := FALSE;
      status.condition := dfe$family_not_served;
    ?ELSE
    dfp$begin_ch_remote_proc_call (server_locator, FALSE, queue_entry_location, p_params_to_send_to_server,
          p_data_to_send_to_server, status);
    ?IFEND
    IF status.normal THEN

    /remote_procedure_active/
      BEGIN
        client_store_validation_info (validation_level, family_name, user_name, account_name, project_name,
              queue_entry_location, p_params_to_send_to_server, p_data_to_send_to_server,
              params_size_to_send_to_server, data_size_to_send_to_server, p_params_received_from_server,
              p_data_received_from_server, status);
        IF NOT status.normal THEN
          EXIT /remote_procedure_active/;
        IFEND;

      END /remote_procedure_active/;

      IF status.normal THEN
        dfp$end_ch_remote_proc_call (queue_entry_location, status);
      ELSE
        dfp$end_ch_remote_proc_call (queue_entry_location, ignore_status);
      IFEND;

    ELSEIF status.condition = dfe$family_not_served THEN
      status.normal := TRUE;

{ Get the validation info from the local validation file.

      store_validation_info (validation_level, family_name, user_name, account_name, project_name, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

{ Create the master catalog if it does not currently exist.

      IF status.normal THEN
        ?IF NOT avc$compile_test_code THEN
          temporary_charge_id.account := account_name;
          temporary_charge_id.project := project_name;
          osp$get_set_name (family_name, set_name, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          pfp$define_master_catalog (set_name, family_name, user_name, temporary_charge_id, status);
          IF NOT status.normal THEN
            IF status.condition = pfe$duplicate_master_catalog THEN
              status.normal := TRUE;
            ELSE
              RETURN;
            IFEND;
          IFEND;
        ?IFEND
      IFEND;

    IFEND;

  PROCEND avp$store_validation_info;
?? OLDTITLE ??
?? NEWTITLE := '  avp$server_get_val_info', EJECT ??
{
{ PURPOSE:
{
{   This interfaces is used to get validation information for a job
{ from the server and send it back to the client.
{

  PROCEDURE [XDCL, #GATE] avp$server_get_val_info
    (VAR p_params_received_from_client: dft$p_receive_parameters;
     VAR p_data_received_from_client: dft$p_receive_data;
     VAR p_params_to_send_to_client: dft$p_send_parameters;
     VAR p_data_to_send_to_client: dft$p_send_data;
     VAR params_size_to_send_to_client: dft$send_parameter_size;
     VAR data_size_to_send_to_client: dft$send_data_size;
     VAR status: ost$status);

    VAR
      account_name: avt$account_name,
      family_name: ost$family_name,
      project_name: avt$project_name,
      set_name: stt$set_name,
      temporary_charge_id: pft$charge_id,
      user_name: ost$user_name,
      validation_level: avt$validation_level;
?? NEWTITLE := '    extract_info_sent_from_client', EJECT ??
    PROCEDURE extract_info_sent_from_client
      (VAR p_params_received_from_client: dft$p_receive_parameters;
       VAR p_data_received_from_client: dft$p_receive_data;
       VAR validation_level: avt$validation_level;
       VAR family_name: ost$family_name;
       VAR user_name: ost$user_name;
       VAR account_name: avt$account_name;
       VAR project_name: avt$project_name);

      VAR
        server_get_val_info_input: ^avt$server_get_val_info_input;

      NEXT server_get_val_info_input IN p_params_received_from_client;
      validation_level := server_get_val_info_input^.validation_level;
      family_name := server_get_val_info_input^.family_name;
      user_name := server_get_val_info_input^.user_name;
      account_name := server_get_val_info_input^.account_name;
      project_name := server_get_val_info_input^.project_name;

    PROCEND extract_info_sent_from_client;
?? OLDTITLE ??
?? NEWTITLE := '    build_info_to_send_to_client', EJECT ??

    PROCEDURE build_info_to_send_to_client
      (    validation_level: avt$validation_level;
           family_name: ost$family_name;
           user_name: ost$user_name;
       VAR account_name: avt$account_name;
       VAR project_name: avt$project_name;
       VAR p_params_to_send_to_client: dft$p_send_parameters;
       VAR p_data_to_send_to_client: dft$p_send_data;
       VAR params_size_to_send_to_client: dft$send_parameter_size;
       VAR data_size_to_send_to_client: dft$send_data_size;
       VAR status: ost$status);

      VAR
        server_get_val_info_output: ^avt$server_get_val_info_output;

      VAR
        account_data_record: ^avt$template_file_record,
        account_description_record: ^avt$template_file_record,
        account_member_data_record: ^avt$template_file_record,
        account_member_desc_record: ^avt$template_file_record,
        default_value: avt$field_value,
        description_record_name: ost$name,
        descriptive_text: ^avt$descriptive_text,
        field_value: avt$field_value,
        file_information: avt$template_file_information,
        ignore_status: ost$status,
        key: avt$validation_key,
        project_data_record: ^avt$template_file_record,
        project_description_record: ^avt$template_file_record,
        project_member_data_record: ^avt$template_file_record,
        project_member_desc_record: ^avt$template_file_record,
        save_sequence_position: dft$p_send_data,
        type_specification: avt$type_specification,
        user_data_record: ^avt$template_file_record,
        user_description_record: ^avt$template_file_record,
        utility_information: ^avt$utility_information;
?? NEWTITLE := '      read_data_record', EJECT ??
      PROCEDURE read_data_record
        (    key: avt$validation_key;
         VAR data_record: ^avt$template_file_record;
         VAR description_record: ^avt$template_file_record;
         VAR p_data_to_send_to_client: dft$p_send_data;
         VAR file_information: avt$template_file_information;
         VAR status: ost$status);

        VAR
          data_record_size: ^integer,
          data_size: 0 .. avc$max_template_record_size,
          description_record_size: ^integer,
          description_size: 0 .. avc$max_template_record_size,
          description_record_name: ost$name,
          field_count: avt$field_count;

        status.normal := TRUE;

{ Retrieve the size of the data and description record.

        data_record := NIL;
        description_record := NIL;
        avp$read_data_record (key.value, avc$read_access, TRUE, data_record, data_size,
              description_record, description_size, description_record_name, field_count,
              file_information, status);
        IF NOT status.normal THEN
          NEXT data_record_size IN p_data_to_send_to_client;
          data_record_size^ := 0;
          NEXT description_record_size IN p_data_to_send_to_client;
          description_record_size^ := 0;
          data_record := NIL;
          description_record := NIL;
          RETURN;
        IFEND;

        REPEAT
          NEXT data_record_size IN p_data_to_send_to_client;
          data_record_size^ := data_size;
          NEXT data_record: [[REP data_size OF cell]] IN p_data_to_send_to_client;
          RESET data_record;
          NEXT description_record_size IN p_data_to_send_to_client;
          description_record_size^ := description_size;
          NEXT description_record: [[REP description_size OF cell]] IN p_data_to_send_to_client;
          RESET description_record;
          avp$read_data_record (key.value, avc$read_access, TRUE, data_record, data_size,
                description_record, description_size, description_record_name, field_count,
                file_information, status);
          IF NOT status.normal THEN
            IF status.condition <> ave$work_area_full THEN
              RETURN;
            ELSE
              RESET p_data_to_send_to_client TO data_record_size;
            IFEND;
          IFEND;
        UNTIL status.normal;

      PROCEND read_data_record;
?? OLDTITLE, EJECT ??
      status.normal := TRUE;

      params_size_to_send_to_client := 0;
      data_size_to_send_to_client := 0;

{ Return the account and project in case the defaults were used.

      NEXT server_get_val_info_output IN p_params_to_send_to_client;
      server_get_val_info_output^.account_name := account_name;
      server_get_val_info_output^.project_name := project_name;
      params_size_to_send_to_client := i#current_sequence_position (p_params_to_send_to_client);

{ Open the validation file.

      avp$open_system_validation_file (family_name, file_information, status);
      IF NOT status.normal THEN
        RETURN;
      IFEND;

    /get_validation_information/
      BEGIN

        key.account_name := avc$high_value_name;
        key.project_name := avc$high_value_name;
        key.user_name := user_name;
        read_data_record (key, user_data_record, user_description_record, p_data_to_send_to_client,
              file_information, status);
        IF NOT status.normal THEN
          IF status.condition = ave$unknown_record THEN

{ If the user specified does not exist on the validation file then return
{ a message that gives no information to the caller. (for security.)

            osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
          IFEND;
          EXIT /get_validation_information/;
        IFEND;

{ If no account and/or project were specified get the defaults from the user
{ record.

        IF ((account_name = osc$null_name) OR (project_name = osc$null_name)) THEN
          avp$get_field (avc$default_account_project, user_data_record, user_description_record,
                {work_area=} NIL, field_value, type_specification, default_value, descriptive_text,
                utility_information, status);
          IF NOT status.normal THEN
            EXIT /get_validation_information/;
          IFEND;
          IF account_name = osc$null_name THEN
            account_name := field_value.account_name^;
            server_get_val_info_output^.account_name := account_name;
          IFEND;
          IF project_name = osc$null_name THEN
            project_name := field_value.project_name^;
            server_get_val_info_output^.project_name := project_name;
          IFEND;
        IFEND;

        IF validation_level > avc$user_level THEN

{ If running at account level or above get the account and account member
{ validation information.

{ Read the account record.

          key.account_name := account_name;
          key.project_name := osc$null_name;
          key.user_name := osc$null_name;
          read_data_record (key, account_data_record, account_description_record, p_data_to_send_to_client,
                file_information, status);
          IF NOT status.normal THEN
            IF status.condition = ave$unknown_record THEN
              osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
            IFEND;
            EXIT /get_validation_information/;
          IFEND;

{ Read the account member record.

          key.account_name := account_name;
          key.project_name := osc$null_name;
          key.user_name := user_name;
          save_sequence_position := p_data_to_send_to_client;
          read_data_record (key, account_member_data_record, account_member_desc_record,
                p_data_to_send_to_client, file_information, status);
          IF NOT status.normal THEN
            IF status.condition = ave$unknown_record THEN
              status.normal := TRUE;
              key.account_name := account_name;
              key.project_name := osc$null_name;
              key.user_name := 'PUBLIC';
              p_data_to_send_to_client := save_sequence_position;
              read_data_record (key, account_member_data_record, account_member_desc_record,
                    p_data_to_send_to_client, file_information, status);
              IF NOT status.normal THEN
                IF status.condition = ave$unknown_record THEN
                  status.normal := TRUE;
                ELSE
                  EXIT /get_validation_information/;
                IFEND;
              IFEND;
            ELSE
              EXIT /get_validation_information/;
            IFEND;
          IFEND;
        IFEND;

        IF validation_level > avc$account_level THEN

{ If running at project level get the project, and project member
{ validation information.

{ Read the project record.

          key.account_name := account_name;
          key.project_name := project_name;
          key.user_name := osc$null_name;
          read_data_record (key, project_data_record, project_description_record, p_data_to_send_to_client,
                file_information, status);
          IF NOT status.normal THEN
            IF status.condition = ave$unknown_record THEN
              osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
            IFEND;
            EXIT /get_validation_information/;
          IFEND;

{ Read the project member information if available.

          key.account_name := account_name;
          key.project_name := project_name;
          key.user_name := user_name;
          save_sequence_position := p_data_to_send_to_client;
          read_data_record (key, project_member_data_record, project_member_desc_record,
                p_data_to_send_to_client, file_information, status);
          IF NOT status.normal THEN
            IF status.condition = ave$unknown_record THEN
              status.normal := TRUE;
              key.account_name := account_name;
              key.project_name := project_name;
              key.user_name := 'PUBLIC';
              p_data_to_send_to_client := save_sequence_position;
              read_data_record (key, project_member_data_record, project_member_desc_record,
                    p_data_to_send_to_client, file_information, status);
              IF NOT status.normal THEN
                IF status.condition = ave$unknown_record THEN
                  status.normal := TRUE;
                ELSE
                  EXIT /get_validation_information/;
                IFEND;
              IFEND;
            ELSE
              EXIT /get_validation_information/;
            IFEND;
          IFEND;
        IFEND;

{ The specified user must be a member of the account at account level.

        IF validation_level = avc$account_level THEN
          IF account_member_data_record = NIL THEN
            osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
          IFEND;

{ The specified user must be a member of the account OR a member of the
{ project at project level.

        ELSEIF validation_level = avc$project_level THEN
          IF (account_member_data_record = NIL) AND (project_member_data_record = NIL) THEN
            osp$set_status_abnormal ('AV', ave$bad_user_validation_info, '', status);
          IFEND;
        IFEND;

      END /get_validation_information/;

      IF status.normal THEN
        avp$close_validation_file (file_information, status);
      ELSE
        avp$close_validation_file (file_information, ignore_status);
      IFEND;

    PROCEND build_info_to_send_to_client;
?? OLDTITLE, EJECT ??
    status.normal := TRUE;

{ Extract the information sent from the client.

    extract_info_sent_from_client (p_params_received_from_client, p_data_received_from_client,
          validation_level, family_name, user_name, account_name, project_name);

{ Store the validation information for the client.

    build_info_to_send_to_client (validation_level, family_name, user_name, account_name, project_name,
          p_params_to_send_to_client, p_data_to_send_to_client, params_size_to_send_to_client,
          data_size_to_send_to_client, status);
    IF NOT status.normal THEN
      RETURN;
    IFEND;

    data_size_to_send_to_client := i#current_sequence_position (p_data_to_send_to_client);

{ Create the master catalog if it does not currently exist.

    IF status.normal THEN
      ?IF NOT avc$compile_test_code THEN
        temporary_charge_id.account := account_name;
        temporary_charge_id.project := project_name;
        osp$get_set_name (family_name, set_name, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        pfp$define_master_catalog (set_name, family_name, user_name, temporary_charge_id, status);
        IF NOT status.normal THEN
          IF status.condition = pfe$duplicate_master_catalog THEN
            status.normal := TRUE;
          ELSE
            RETURN;
          IFEND;
        IFEND;
      ?IFEND
    IFEND;

  PROCEND avp$server_get_val_info;
?? OLDTITLE ??
MODEND avm$store_validation_info;
