/*
 * mars-nwe-dosutils - NetWare/DOS utility tools.
 *
 * Copyright (C) 2026 Mario Fetka
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

/*
 * Purpose: Public declarations for namespace and file-system NCP API helpers.
 * Depends on: net.h data types and ncpapi.c implementation.
 */


/* ncpapi.h - NetWare/NCP protocol API helpers for mars-dosutils */

#ifndef NCPAPI_H
#define NCPAPI_H

UI ncp_build_handle_path(uint8 *buf, uint8 dhandle,
                         uint16 dirbase, uint8 style,
                         int count,
                         const char *c1, const char *c2, const char *c3);
UI ncp_build_handle_path_from_dos_path(uint8 *buf, uint8 dhandle,
                                       uint16 dirbase, uint8 style,
                                       const char *dospath);
int ncp_get_requester_handle(uint16 *handle_lo, uint16 *handle_hi);


typedef struct ncp_file_handle6 {
  uint8 h[6];
} NCP_FILE_HANDLE6;

#define NCP_OC_MODE_OPEN      0x01
#define NCP_OC_MODE_TRUNCATE  0x02
#define NCP_OC_MODE_CREATE    0x08

#define NCP_DAR_READ          0x0001
#define NCP_DAR_WRITE         0x0002
#define NCP_DAR_DENY_READ     0x0004
#define NCP_DAR_DENY_WRITE    0x0008
#define NCP_DAR_COMPAT        0x0010

int ncp87_01_open_create_entry(const char *path_name,
                               uint16 dir_handle,
                               uint8 open_create_mode,
                               uint32 create_attrs,
                               uint16 desired_access,
                               uint16 search_attrs,
                               NCP_FILE_HANDLE6 *handle_out,
                               uint32 *file_size_out,
                               uint8 *open_create_action_out,
                               uint16 *actual_out,
                               uint16 *handle_lo_out,
                               uint16 *handle_hi_out);

int ncp74_file_server_copy(const NCP_FILE_HANDLE6 *src,
                               const NCP_FILE_HANDLE6 *dst,
                               uint32 src_offset,
                               uint32 dst_offset,
                               uint32 count,
                               uint32 *copied_out);

int ncp66_close_file(const NCP_FILE_HANDLE6 *handle);


int ncp87_06_obtain_rim_attributes(const char *name,
                                     uint16 dir_handle,
                                     uint32 *attr_out,
                                     uint16 *actual_out,
                                     uint16 *handle_lo_out,
                                     uint16 *handle_hi_out);


typedef struct ncp_dos_modify_info {
  uint32 attributes;
  uint16 creation_time;
  uint16 creation_date;
  uint32 creator_id;
  uint16 modify_time;
  uint16 modify_date;
  uint32 modifier_id;
  uint16 last_access_date;
  uint16 archive_time;
  uint16 archive_date;
  uint32 archiver_id;
  uint16 inherited_rights;
  uint32 maximum_space;
} NCP_DOS_MODIFY_INFO;

typedef struct ncp_ndir_info {
  uint32 space_allocated;
  uint32 attributes;
  uint16 flags;
  uint32 data_size;
  uint32 total_size;
  uint16 number_of_streams;
  uint16 creation_time;
  uint16 creation_date;
  uint32 creator_id;
  uint16 modify_time;
  uint16 modify_date;
  uint32 modifier_id;
  uint16 last_access_date;
  uint16 archive_time;
  uint16 archive_date;
  uint32 archiver_id;
  uint16 inherited_rights;
  uint32 dir_ent_num;
  uint32 dos_dir_num;
  uint32 vol_number;
  uint32 ea_data_size;
  uint32 ea_key_count;
  uint32 ea_key_size;
  uint32 ns_creator;
  uint8  name_len;
  char   name[256];
} NCP_NDIR_INFO;

int ncp87_06_obtain_ndir_info(const char *path_name,
                               uint16 dir_handle,
                               NCP_NDIR_INFO *info_out,
                               uint16 *actual_out,
                               uint16 *handle_lo_out,
                               uint16 *handle_hi_out);


int ncp87_07_modify_dos_attributes(char *name,
                                    uint16 dir_handle,
                                    uint32 attrs,
                                    uint16 *actual_out,
                                    uint16 *handle_lo_out,
                                    uint16 *handle_hi_out);

int ncp87_07_modify_dos_info(const char *name,
                              uint16 dir_handle,
                              uint32 change_mask,
                              NCP_DOS_MODIFY_INFO *info,
                              uint16 *actual_out,
                              uint16 *handle_lo_out,
                              uint16 *handle_hi_out);

int ncp87_1d_get_effective_rights(const char *path,
                                   uint16 dir_handle,
                                   uint16 *rights_out,
                                   uint16 *actual_out,
                                   uint16 *handle_lo_out,
                                   uint16 *handle_hi_out);


int ncp87_1d_get_effective_rights_by_dirent(uint8 vol_number,
                                             uint32 dos_dir_number,
                                             uint16 *rights_out,
                                             uint16 *actual_out,
                                             uint16 *handle_lo_out,
                                             uint16 *handle_hi_out);

int ncp87_0a_add_trustee_rights(const char *path_name,
                                 uint16 dir_handle,
                                 uint32 object_id,
                                 uint16 rights,
                                 uint16 rights_mask,
                                 uint16 *actual_out,
                                 uint16 *handle_lo_out,
                                 uint16 *handle_hi_out);

int ncp22_27_set_trustee_rights(const char *path_name,
                                 uint16 dir_handle,
                                 uint32 object_id,
                                 uint16 rights);

int ncp22_2b_delete_trustee_rights(const char *path_name,
                                    uint16 dir_handle,
                                    uint32 object_id);

int ncp87_05_find_trustee_rights(const char *path_name,
                                  uint16 dir_handle,
                                  uint32 object_id,
                                  uint16 *rights_out,
                                  uint16 *actual_out,
                                  uint16 *handle_lo_out,
                                  uint16 *handle_hi_out);

int ncp87_0b_delete_trustee_rights(const char *path_name,
                                    uint16 dir_handle,
                                    uint32 object_id,
                                    uint16 *actual_out,
                                    uint16 *handle_lo_out,
                                    uint16 *handle_hi_out);

#endif
