Exemple #1
0
/* B. Adding/removing icon from the grid */
int grid_add(struct TrayIcon *ti)
{
	struct IconPlacement *pmt;
	/* Invalidate grid position data */
	ti->l.grd_rect.x = -1;
	ti->l.grd_rect.y = -1;
	ti->l.grd_rect.w = -1;
	ti->l.grd_rect.h = -1;
	/* Invalidate window position data */
	ti->l.icn_rect.x = -1;
	ti->l.icn_rect.y = -1;
	ti->l.icn_rect.w = -1;
	ti->l.icn_rect.h = -1;
	/* Get window dimensions */
	grid_translate_from_window(ti);
	pmt = grid_find_placement(ti);
	if (pmt == NULL) {
		LOG_TRACE(("no candidates for placement found\n"));
		ti->is_layed_out = False;
		RETURN_STATUS(FAILURE);
	}
	ti->is_layed_out = True;
	grid_place_icon(ti, pmt);
	RETURN_STATUS(SUCCESS);
}
Exemple #2
0
/*
 * Get the Access and/or Default ACL of a file.
 */
static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
		struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
{
	struct posix_acl *acl;
	struct inode *inode;
	svc_fh *fh;
	__be32 nfserr = 0;

	dprintk("nfsd: GETACL(2acl)   %s\n", SVCFH_fmt(&argp->fh));

	fh = fh_copy(&resp->fh, &argp->fh);
	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
	if (nfserr)
		RETURN_STATUS(nfserr);

	inode = fh->fh_dentry->d_inode;

	if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
		RETURN_STATUS(nfserr_inval);
	resp->mask = argp->mask;

	nfserr = fh_getattr(fh, &resp->stat);
	if (nfserr)
		goto fail;

	if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
		acl = get_acl(inode, ACL_TYPE_ACCESS);
		if (IS_ERR(acl)) {
			nfserr = nfserrno(PTR_ERR(acl));
			goto fail;
		}
		if (acl == NULL) {
			/* Solaris returns the inode's minimum ACL. */
			acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
		}
		resp->acl_access = acl;
	}
	if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
		/* Check how Solaris handles requests for the Default ACL
		   of a non-directory! */
		acl = get_acl(inode, ACL_TYPE_DEFAULT);
		if (IS_ERR(acl)) {
			nfserr = nfserrno(PTR_ERR(acl));
			goto fail;
		}
		resp->acl_default = acl;
	}

	/* resp->acl_{access,default} are released in nfssvc_release_getacl. */
	RETURN_STATUS(0);

fail:
	posix_acl_release(resp->acl_access);
	posix_acl_release(resp->acl_default);
	RETURN_STATUS(nfserr);
}
Exemple #3
0
int grid_remove(struct TrayIcon *ti)
{
	/* implementation is similar to that of layout_handle_icon_resize(),
	 * see detailed description there */
	icon_list_forall_from(ti, &layout_unset_flag);
	if (settings.shrink_back_mode || settings.scrollbars_mode != SB_MODE_NONE) grid_update(ti, False);
	/* Since NULL is a special case for icon_list_froall_from,
	 * avoid calling it for the last icon */
	if (ti->next != NULL)
		RETURN_STATUS(icon_list_forall_from(ti->next, &grid_add_wrapper) == NULL);
	else
		RETURN_STATUS(SUCCESS);
}
Exemple #4
0
/*
 * Set the Access and/or Default ACL of a file.
 */
static __be32 nfsd3_proc_setacl(struct svc_rqst * rqstp,
		struct nfsd3_setaclargs *argp,
		struct nfsd3_attrstat *resp)
{
	svc_fh *fh;
	__be32 nfserr = 0;

	fh = fh_copy(&resp->fh, &argp->fh);
	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);

	if (!nfserr) {
		nfserr = nfserrno( nfsd_set_posix_acl(
			fh, ACL_TYPE_ACCESS, argp->acl_access) );
	}
	if (!nfserr) {
		nfserr = nfserrno( nfsd_set_posix_acl(
			fh, ACL_TYPE_DEFAULT, argp->acl_default) );
	}

	/* argp->acl_{access,default} may have been allocated in
	   nfs3svc_decode_setaclargs. */
	posix_acl_release(argp->acl_access);
	posix_acl_release(argp->acl_default);
	RETURN_STATUS(nfserr);
}
Exemple #5
0
/*
//
//  ISAM - build file cluster
//
*/
int tcob_build_vbidx(struct file_desc *f)
{ 
  int r=0, i=0, ifilehandle, iresult, imode;
  tcb_fileio_vbidx_handle *h;
  struct keydesc *wkeydesc;   

#ifdef DEBUG_FILEISAM_RTS8
     fprintf(stderr, "debug : tcob_build_vbidx 010.040 : f->filename=%s, f->flags.file_isvariable=%d;\n", f->filename, f->flags.file_isvariable);
#endif                                       
  
  h = (tcb_fileio_vbidx_handle *)f->dbp;

  if (f->flags.file_isvariable == 1) {
     imode = ISINOUT+ISVARLEN+ISEXCLLOCK;
     isreclen = f->reclen_min;
  }
  else {
     imode = ISINOUT+ISFIXLEN+ISEXCLLOCK;
  }

  wkeydesc = h->skeydesc;
  /* Define ISAM file - define primary key */  
  ifilehandle = isbuild(f->filename, f->reclen, wkeydesc, imode);
#ifdef DEBUG_FILEISAM_RTS8
  fprintf(stderr, "debug : tcob_build_vbidx 010.060 : f->filename=%s, f->reclen=%d, ifilehandle=%d;\n", f->filename, f->reclen, ifilehandle);
#endif                                       
  if (ifilehandle < 0) {
     r = tcob_eisam2ecob(0);
     return (r);        
  }

  /* Define ISAM file - define secondary keys */  
  for (i=1; i < f->nkeys; i++) {
     wkeydesc = h->skeydesc + i;
     iresult = isaddindex(ifilehandle, wkeydesc);
     if (iresult != 0) {
        r = tcob_eisam2ecob(0);
        iresult = isclose(ifilehandle);
        iserase (f->filename);
        return (r);        
     }
  }

  iresult = isclose(ifilehandle);
  if (iresult != 0) {
     r = tcob_eisam2ecob(0);
     iserase (f->filename);
     return (r);        
  }
  
  h->ifilehandle = ifilehandle;

#ifdef DEBUG_FILEISAM_RTS8
     fprintf(stderr, "debug : tcob_build_vbidx 010.080 : r=%d;\n", r);
#endif                                       

  RETURN_STATUS(r);        
}
Exemple #6
0
    int AesWrappers::GenerateAesObject(unsigned char*& obj, int* obj_len)
    {
        FUNCTION_START;

        #ifdef EVALUATE
            clock_t start = clock();
        #endif

        const unsigned int length = AES_KEYLEN/8;
        if (obj_len != nullptr)
        {
            *obj_len = length;
        }

        obj = (unsigned char*)malloc(length);
        if (obj == nullptr)
        {
            RETURN_STATUS(MALLOC_FAILURE);
        }

        returned_value = RAND_bytes(obj, length);
        if (returned_value != 1)
        {
            Log::Line(Log::EMERG, "AesWrappers::GenerateAesKey: RAND_bytes failed: %d, %s", returned_value, ERR_error_string(ERR_get_error(), NULL));
            RETURN_STATUS(GENERAL_FAILURE);
        }

        exit:
            #ifdef EVALUATE
                if (status == SUCCESS)
                {
                    clock_t end = clock();
                    TIME_AES_ENCRYPTS += ((double) end - start)/ CLOCKS_PER_SEC;
                    ++NUM_AES_GENERATES;
                }
            #endif
            if (status != SUCCESS)
            {
                free(obj);
            }
            FUNCTION_END;
    }
Exemple #7
0
/*
 * Set the Access and/or Default ACL of a file.
 */
static __be32 nfsd3_proc_setacl(struct svc_rqst * rqstp,
		struct nfsd3_setaclargs *argp,
		struct nfsd3_attrstat *resp)
{
	struct inode *inode;
	svc_fh *fh;
	__be32 nfserr = 0;
	int error;

	fh = fh_copy(&resp->fh, &argp->fh);
	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
	if (nfserr)
		goto out;

	inode = d_inode(fh->fh_dentry);
	if (!IS_POSIXACL(inode) || !inode->i_op->set_acl) {
		error = -EOPNOTSUPP;
		goto out_errno;
	}

	error = fh_want_write(fh);
	if (error)
		goto out_errno;

	error = inode->i_op->set_acl(inode, argp->acl_access, ACL_TYPE_ACCESS);
	if (error)
		goto out_drop_write;
	error = inode->i_op->set_acl(inode, argp->acl_default,
				     ACL_TYPE_DEFAULT);

out_drop_write:
	fh_drop_write(fh);
out_errno:
	nfserr = nfserrno(error);
out:
	/* argp->acl_{access,default} may have been allocated in
	   nfs3svc_decode_setaclargs. */
	posix_acl_release(argp->acl_access);
	posix_acl_release(argp->acl_default);
	RETURN_STATUS(nfserr);
}
Exemple #8
0
/*
 * Get the Access and/or Default ACL of a file.
 */
static __be32 nfsd3_proc_getacl(struct svc_rqst * rqstp,
		struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
{
	svc_fh *fh;
	struct posix_acl *acl;
	__be32 nfserr = 0;

	fh = fh_copy(&resp->fh, &argp->fh);
	nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
	if (nfserr)
		RETURN_STATUS(nfserr);

	if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
		RETURN_STATUS(nfserr_inval);
	resp->mask = argp->mask;

	if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
		acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
		if (IS_ERR(acl)) {
			int err = PTR_ERR(acl);

			if (err == -ENODATA || err == -EOPNOTSUPP)
				acl = NULL;
			else {
				nfserr = nfserrno(err);
				goto fail;
			}
		}
		if (acl == NULL) {
			/* Solaris returns the inode's minimum ACL. */

			struct inode *inode = fh->fh_dentry->d_inode;
			acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
		}
		resp->acl_access = acl;
	}
	if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
		/* Check how Solaris handles requests for the Default ACL
		   of a non-directory! */

		acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
		if (IS_ERR(acl)) {
			int err = PTR_ERR(acl);

			if (err == -ENODATA || err == -EOPNOTSUPP)
				acl = NULL;
			else {
				nfserr = nfserrno(err);
				goto fail;
			}
		}
		resp->acl_default = acl;
	}

	/* resp->acl_{access,default} are released in nfs3svc_release_getacl. */
	RETURN_STATUS(0);

fail:
	posix_acl_release(resp->acl_access);
	posix_acl_release(resp->acl_default);
	RETURN_STATUS(nfserr);
}
Exemple #9
0
    int AesWrappers::Decrypt(const unsigned char* const key, const unsigned  char* const iv,
                             const unsigned char* const msg, const unsigned int& msg_len, unsigned char*& result, unsigned int* result_len)
    {
        FUNCTION_START;

        #ifdef EVALUATE
            clock_t start = clock();
        #endif

        EVP_CIPHER_CTX ctx;
        unsigned int res_len = 0;
        unsigned int length = 0;
        int temp_len = 0;
        const EVP_CIPHER* cipher = EVP_aes_256_cbc();

        if (key == nullptr || iv == nullptr || msg == nullptr)
        {
            RETURN_STATUS(NULL_ARG);
        }

        if (result_len != nullptr)
        {
            *result_len = 0;
        }

        // allocate space for result
        res_len = msg_len + EVP_CIPHER_block_size(cipher);
        result = (unsigned char*)malloc(res_len);
        if (result == nullptr)
        {
            RETURN_STATUS(MALLOC_FAILURE);
        }

        // Init cipher and encrption
        EVP_CIPHER_CTX_init(&ctx);
        returned_value = EVP_DecryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, key, iv);
        if (returned_value != 1)
        {
            RETURN_STATUS(OPENSSL_ERROR);
        }

        returned_value = EVP_DecryptUpdate(&ctx, result, &temp_len, msg, msg_len);
        if (returned_value != 1)
        {
            RETURN_STATUS(OPENSSL_ERROR);
        }
        length += temp_len;

        returned_value = EVP_DecryptFinal_ex(&ctx, result + length, &temp_len);
        if (returned_value != 1)
        {
            RETURN_STATUS(OPENSSL_ERROR);
        }
        length += temp_len;

        if (result_len != nullptr)
        {
            *result_len = length;
        }

        exit:
            #ifdef EVALUATE
                if (status == SUCCESS)
                {
                    clock_t end = clock();
                    TIME_AES_DECRYPTS += ((double) end - start) / CLOCKS_PER_SEC;
                    ++NUM_AES_DECRYPTS;
                }
            #endif
            EVP_CIPHER_CTX_cleanup(&ctx);
            if (status != SUCCESS)
            {
                free(result);
            }
            FUNCTION_END;
    }
Exemple #10
0
/*
//
//  ISAM - START function
//
*/
int tcob_start_idx(struct file_desc *f,
                   int cond, int ikey,
                   struct fld_desc *recfdesc, char *key_ptr) 
{
  int iresult, cmode, startpos, poslen, r=0;
  tcb_fileio_vbidx_handle *h;
  tcob_file_key *k;
  char *crecord;
  struct keydesc *wkeydesc;   

  f->flags.eof_hit = 0;  /* additon AL : reset eof if already positioned */
  f->flags.read_done = 0;
  f->flags.start_record = 0;

#ifdef DEBUG_FILEISAM_RTS4
  fprintf(stderr, "debug : tcob_start_idx 110.040 :\n");
#endif                                       

  /* ERROR check : File is open */
  if (f->dbp == NULL)
     RETURN_STATUS(47);
  
  /* ERROR check : Record length is valid - unknown error */
  if (f->reclen == -1)
     RETURN_STATUS(99);
  
  /* ERROR check : Must be in INPUT or IO mode */
  if ((f->open_mode != TCB_FILE_OPEN_MODE_INPUT) && (f->open_mode != TCB_FILE_OPEN_MODE_IO))
     RETURN_STATUS(47);

  /* Special case for LT and LTEQ conditionals */ 
  if ((cond == TCB_CONDITIONAL_LT) || (cond == TCB_CONDITIONAL_LTEQ)) {
     r = tcob_start_lesscond_idx(f, cond, ikey, recfdesc, key_ptr); 
     RETURN_STATUS(r);
  }      
  
  h = (tcb_fileio_vbidx_handle *)f->dbp;
  k = f->keys + ikey;
  crecord = h->buf->buf[0]; 
  
  startpos = k->offset;
  poslen = recfdesc->len;
  
  memset (crecord, ' ', f->reclen);
  memcpy (crecord+startpos, key_ptr, poslen);

  switch (cond)
  {
    case TCB_CONDITIONAL_EQUAL:
      cmode = ISEQUAL;
      break;
    
    case TCB_CONDITIONAL_GT:
      cmode = ISGREAT;
      break;
    
    case TCB_CONDITIONAL_GTEQ:
      cmode = ISGTEQ;
      break;

    default:
      RETURN_STATUS(99);
      break;
  }
  
  wkeydesc = h->skeydesc + ikey;
  iresult = isstart(h->ifilehandle, wkeydesc, poslen, crecord, cmode);
  if (iresult != 0) { 
     r = tcob_eisam2ecob(0);
     RETURN_STATUS(r);
  }

  f->flags.start_record = 1;

  RETURN_STATUS(r);
}
Exemple #11
0
/*
//
//  ISAM delete
//
*/
int tcob_delete_idx(struct file_desc *f) 
{
  int iresult, r=0;
  long drecnum;
  tcb_fileio_vbidx_handle *h;
  tcob_file_key *k;
  char *crecord;
  /*struct keydesc *wkeydesc;  */ 


#ifdef DEBUG_FILEISAM_RTS6
  fprintf(stderr, "debug : tcob_delete_idx 110.020 : \n");
#endif                                       

  /* ERROR check : File is open */
  if (f->dbp == NULL)
     RETURN_STATUS(49);
  
  /* ERROR check : Record length is valid - unknown error */
  if (f->reclen == -1)
     RETURN_STATUS(99);
  
  
  /* ERROR check : Must be in IO mode */
  if (f->open_mode != TCB_FILE_OPEN_MODE_IO)
     RETURN_STATUS(49);

  /* Error check : If access mode is SEQUENTIAL the read done flag must be set to TRUE */
  if ((f->access_mode == TCB_FILE_ACCESS_MODE_SEQUENTIAL) && 
      (f->flags.read_done == 0))  
     RETURN_STATUS(39);

  h = (tcb_fileio_vbidx_handle *)f->dbp;
  k = f->keys;
  crecord = h->buf->buf[0]; 

/* Use record number to delete as defined in READ
  // If access mode is SEQUENTIAL and read flag is TRUE then use PREVIOUS READ as KEY 
  // If access mode is DYNAMIC or RANDOM then use primary KEY as defined in record 
  //if (f->access_mode != TCB_FILE_ACCESS_MODE_SEQUENTIAL) {
  //   memset (crecord, ' ', f->reclen);
  //   memcpy (crecord, record+k->offset, k->key_desc->len);
  //}
*/

#ifdef DEBUG_FILEISAM_RTS6
     fprintf(stderr, "debug : tcob_delete_idx 110.060 : f->reclen=%d;\n", f->reclen);
     if (f->reclen > 0) {
        int i, ilen=f->reclen;
        char *pt = record;
        fprintf(stderr, "debug : tcob_delete_idx 110.065 : record=");
        for (i=0; i<ilen; i++) {      
          fprintf(stderr, "%c", *(pt + i));
        }
        fprintf(stderr, ";\n");
     }
#endif                                       

#ifdef DEBUG_FILEISAM_RTS6
  fprintf(stderr, "debug : tcob_delete_idx 110.090 : isrecnum=%d;\n", isrecnum);
#endif                                       
  /* Save record number to be deleted */
  drecnum = isrecnum;

  /* Read NEXT or PREVIOUS record to set current record */
  f->flags.read_next_done = 1;
  iresult = isread(h->ifilehandle, crecord, ISNEXT);
#ifdef DEBUG_FILEISAM_RTS2
  fprintf(stderr, "debug : tcob_delete_idx 110.095 : iresult=%d, isrecnum=%d;\n", iresult, isrecnum);
#endif                                       
  if (iresult != 0) {
     iresult = isread(h->ifilehandle, crecord, ISPREV);
     f->flags.read_next_done = 0;
#ifdef DEBUG_FILEISAM_RTS2
  fprintf(stderr, "debug : tcob_delete_idx 110.098 : iresult=%d, isrecnum=%d;\n", iresult, isrecnum);
#endif                                       
  }

  /* Delete record using primary key - USE record number */
  /* iresult = isdelete(h->ifilehandle, crecord); */

  /* Delete record using record number */
  iresult = isdelrec(h->ifilehandle, drecnum);
#ifdef DEBUG_FILEISAM_RTS6
  fprintf(stderr, "debug : tcob_delete_idx 110.100 : iresult=%d, isrecnum=%d;\n", iresult, isrecnum);
#endif                                       
  /* Set return code depending on VB iserrno */
  if (iresult != 0) 
     r = tcob_eisam2ecob(0);

  /* Reset flags */
  f->flags.read_done    = 0;
  f->flags.init_done    = 0; 
  f->flags.start_record = 0;

#ifdef DEBUG_FILEISAM_RTS6
  fprintf(stderr, "debug : tcob_delete_idx 110.120 : r=%d;\n", r);
#endif                                       

  RETURN_STATUS(r);
}
Exemple #12
0
/*
//
//  ISAM rewrite
//
*/
int tcob_rewrite_idx(struct file_desc *f, struct fld_desc *rectofrom_desc, char *rectofrom_buf,
                     struct fld_desc *reclen_desc, char *reclen_buf) 
{
  int iresult, r=0, reclen;
  tcb_fileio_vbidx_handle *h;
  char *crecord;

#ifdef DEBUG_FILEISAM_RTS7
  fprintf(stderr, "debug : tcob_rewrite_idx 100.080 : \n");
#endif                                       

  /* ERROR check : File is open */
  if (f->dbp == NULL)
     RETURN_STATUS(49);
  
  /* ERROR check : Record length is valid - unknown error */
  if (f->reclen == -1)
     RETURN_STATUS(99);
  
  /* ERROR check : Must in IO mode */
  if (f->open_mode != TCB_FILE_OPEN_MODE_IO)
     RETURN_STATUS(49);
  
  /* Check that we didn't already hit eof */
  if ((f->open_mode == TCB_FILE_OPEN_MODE_IO) && f->flags.eof_hit)
     RETURN_STATUS(43);
  
  /* Error check : If access mode is SEQUENTIAL the read done flag must be set to TRUE */
  if ((f->access_mode == TCB_FILE_ACCESS_MODE_SEQUENTIAL) && 
      (f->flags.read_done == 0))  
     RETURN_STATUS(39);

  h = (tcb_fileio_vbidx_handle *)f->dbp;
  crecord = h->buf->buf[0]; 

  /* Error check : Access mode SEQUENTIAL and primary KEY */
  /* The PREVIOUS READ primary KEY must be equal to primary KEY in record */
  if (f->access_mode == TCB_FILE_ACCESS_MODE_SEQUENTIAL) { 
     int sresult, startpos, poslen;
     tcob_file_key *k;
      
     k = f->keys;
     startpos = k->offset;
     poslen   = k->key_desc->len;    
     
     /* Compare keys */
     sresult = strncmp(crecord+startpos, f->record+startpos, poslen);
     if (sresult != 0)
        RETURN_STATUS(30);
  }
  
  /* Variable length record */                  
  if (reclen_desc != NULL) {
     /* Convert record to int type */
     tcob_move(reclen_desc, reclen_buf, &_generic_4binary, (char *)&reclen);     
     if (reclen > f->reclen) 
        RETURN_STATUS(99);
     isreclen = reclen;
  }
  else {
     reclen = f->reclen;
  }

  /* Copy write buffer data to record and FROM identifier buffer */
  if (rectofrom_desc != NULL) {
     memset(f->record, ' ', f->reclen);
     if (rectofrom_desc->len > f->reclen) 
        memcpy(f->record, rectofrom_buf, f->reclen);
     else
        memcpy(f->record, rectofrom_buf, rectofrom_desc->len);
  }
  memcpy(crecord, f->record, reclen);

  /* rewrite record */
  iresult = isrewrite(h->ifilehandle, crecord);
  /* Set return code depending on VB iserrno */
  if (iresult != 0) 
     r = tcob_eisam2ecob(0);

#ifdef DEBUG_FILEISAM_RTS7
  fprintf(stderr, "debug : tcob_rewrite_idx 100.080 : file status(r)=%d, iserrno=%d\n", r, iserrno);
#endif

  f->flags.read_done = 0;
  f->flags.start_record = 0; 

  RETURN_STATUS(r);

}
Exemple #13
0
/*
//
//  ISAM write
//
*/
int tcob_write_idx(struct file_desc *f, struct fld_desc *rectofrom_desc, char *rectofrom_buf,
                   struct fld_desc *reclen_desc, char *reclen_buf) 
{
  int iresult, r=0, reclen;
  tcb_fileio_vbidx_handle *h;
  char *crecord;

  f->flags.read_done = 0;
  f->flags.start_record = 0; 
  
  /* ERROR check : File is open */
  if (f->dbp == NULL)
     RETURN_STATUS(48);
             
#ifdef DEBUG_FILEISAM_RTS3
  fprintf(stderr, "debug : tcob_write_idx 090.040 : filename=%s, reclen=%d\n", f->filename, f->reclen);
#endif

  /* ERROR check : Record length is valid - unknown error */
  if (f->reclen == -1) 
     RETURN_STATUS(99);
  
  /* ERROR check : Open mode must be OUTPUT, IO, EXTEND */
  if (f->open_mode == TCB_FILE_OPEN_MODE_INPUT)  
     RETURN_STATUS(48);

  /* ERROR check : IGNORED - not shure how to impliment
     When file ACCESS MODE is SEQUENTIAL the primary KEY should be in ascending order.
     Ascending order relative to previous write KEY ?
  */
  
  h = (tcb_fileio_vbidx_handle *)f->dbp;
  crecord = h->buf->buf[0]; 
  memset(crecord, ' ', f->reclen);

  /* Variable length record */                  
  if (reclen_desc != NULL) {
     /* Convert record to int type */
     tcob_move(reclen_desc, reclen_buf, &_generic_4binary, (char *)&reclen);     
     if (reclen > f->reclen) 
        RETURN_STATUS(99);
     isreclen = reclen;
#ifdef DEBUG_FILEISAM_RTS3
     fprintf(stderr, "debug : tcob_write_idx 090.060 : file variable len=(%d, %d) reclen=%d\n", f->reclen, f->reclen_min, reclen);
#endif
  }
  else {
     reclen = f->reclen;
  }

  /* Copy write buffer data to record and FROM identifier buffer */
  if (rectofrom_desc != NULL) {
     memset(f->record, ' ', f->reclen);
     if (rectofrom_desc->len > f->reclen) 
        memcpy(f->record, rectofrom_buf, f->reclen);
     else
        memcpy(f->record, rectofrom_buf, rectofrom_desc->len);
  }
  memcpy(crecord, f->record, reclen);

  /* write record */
  iresult = iswrite(h->ifilehandle, crecord);
  /* Set return code depending on VB iserrno */
  if (iresult != 0) 
     r = tcob_eisam2ecob(0);

#ifdef DEBUG_FILEISAM_RTS3
    fprintf(stderr, "debug : tcob_write_idx 090.080 : file status(r)=%d, iserrno=%d\n", r, iserrno);
#endif

  RETURN_STATUS(r);
}
Exemple #14
0
/*
//
//  ISAM read NEXT - PREVIOUS
//
*/
int tcob_read_next_idx(struct file_desc *f, struct fld_desc *rectofrom_desc, char *rectofrom_buf, 
                       int nflag, 
                       struct fld_desc *reclen_desc, char *reclen_buf) 
{
  int iresult, r=0, imode, reclen;
  tcb_fileio_vbidx_handle *h;
  tcob_file_key *k;
  char *crecord;

  /* ERROR check : File is open */
  if (f->dbp == NULL) {
     /* ERROR check : Set file-status condition when file is not available */
     if (f->flags.optional && f->flags.file_missing) 
        RETURN_STATUS(10);
     RETURN_STATUS(47);
  }

#ifdef DEBUG_FILEISAM_RTS2
  fprintf(stderr, "debug : tcob_read_next_idx 080.020 : filename=%s, reclen=%d;\n", f->filename, f->reclen);
#endif                                       

  f->flags.read_done = 0;

  
  /* ERROR check : Record length is valid - unknown error */
  if (f->reclen == -1)
     RETURN_STATUS(99);
  
  /* ERROR check : Must be in INPUT or IO mode */
  if ((f->open_mode != TCB_FILE_OPEN_MODE_INPUT) && (f->open_mode != TCB_FILE_OPEN_MODE_IO))
     RETURN_STATUS(47);
  
  /* Check that we didn't already hit eof */
  if ((f->open_mode == TCB_FILE_OPEN_MODE_INPUT || 
       f->open_mode == TCB_FILE_OPEN_MODE_IO) && 
      (f->flags.eof_hit)
     )
     RETURN_STATUS(46);
  
  /* ERROR check : For sequential READ access mode must be SEQUENTIAL or DYNAMIC */
  if ((f->access_mode != TCB_FILE_ACCESS_MODE_SEQUENTIAL) &&
      (f->access_mode != TCB_FILE_ACCESS_MODE_DYNAMIC)
     )
     RETURN_STATUS(39);
 
  h = (tcb_fileio_vbidx_handle *)f->dbp;
  k = f->keys;
  crecord = h->buf->buf[0]; 

#ifdef DEBUG_FILEISAM_RTS2
  fprintf(stderr, "debug : tcob_read_next_idx 080.040 : isrecnum=%d;\n", isrecnum);
#endif                                       

  /* If there is a start record outstanding set current record for read */
  if ((f->flags.start_record == 1) || (f->flags.read_next_done == 1)) {
     imode = ISCURR;
#ifdef DEBUG_FILEISAM_RTS2
     fprintf(stderr, "debug : tcob_read_next_idx 080.060 : imode(ISCURR)=%d;\n", imode);
#endif                                       
  }
  else {
     //memcpy (crecord, record, f->reclen);
  /* Set record position for read */
     if (nflag == TCB_FILE_READ_REC_PREVIOUS) {
        imode = ISPREV;
#ifdef DEBUG_FILEISAM_RTS2
        fprintf(stderr, "debug : tcob_read_next_idx 080.062 : imode(ISPREV)=%d;\n", imode);
#endif                                       
     }
     else { 
        imode = ISNEXT;
#ifdef DEBUG_FILEISAM_RTS2
        fprintf(stderr, "debug : tcob_read_next_idx 080.064 : imode(ISNEXT)=%d;\n", imode);
#endif                                       
     }
  }
  f->flags.start_record = 0;
  f->flags.read_next_done = 0;

  /* Read record */
  iresult = isread(h->ifilehandle, crecord, imode);
#ifdef DEBUG_FILEISAM_RTS2
  fprintf(stderr, "debug : tcob_read_next_idx 080.080 : iresult=%d, isrecnum=%d;\n", iresult, isrecnum);
#endif                                       
  /* Set return code depending on VB iserrno */
  if (iresult != 0) { 
     r = tcob_eisam2ecob(0);
     RETURN_STATUS(r);
  }
  
  /* Variable Length File */
  if (reclen_desc != NULL) {
     reclen = isreclen;
     if (reclen > f->reclen) 
        RETURN_STATUS(99);
     tcob_move(&_generic_4binary, (char *)&reclen, reclen_desc, reclen_buf);     
  }
  else {
     reclen = f->reclen;
  }

#ifdef DEBUG_FILEISAM_RTS2
     fprintf(stderr, "debug : tcob_read_next_idx 080.100 : reclen=%d;\n", reclen);
     if (reclen > 0) {
        int i, ilen=reclen;
        char *pt = crecord;
        fprintf(stderr, "debug : tcob_read_next_idx 080.105 : record=");
        for (i=0; i<ilen; i++) {      
          fprintf(stderr, "%c", *(pt + i));
        }
        fprintf(stderr, ";\n");
     }
#endif                                       

  /* Clear buffer and move data record */
  memset(f->record, ' ', f->reclen);
  memcpy (f->record, crecord, reclen);

  /* Copy buffer data to INTO identifiers buffer */
  if (rectofrom_desc != NULL) {
     memset(rectofrom_buf, ' ', rectofrom_desc->len);
     if (rectofrom_desc->len > reclen) 
        memcpy(rectofrom_buf, crecord, reclen);
     else
        memcpy(rectofrom_buf, crecord, rectofrom_desc->len);
  }

  f->flags.read_done = 1;

#ifdef DEBUG_FILEISAM_RTS2
  fprintf(stderr, "debug : tcob_read_next_idx 080.120 : r=%d;\n", r);
#endif                                       

  RETURN_STATUS(r);
}
Exemple #15
0
/*
//
//  ISAM read
//
*/
int tcob_read_idx(struct file_desc *f, struct fld_desc *rectofrom_desc, char *rectofrom_buf, 
                  struct fld_desc *reclen_desc, char *reclen_buf, 
                  int ikey, struct fld_desc *fkey, char *keybuf) 
{
  int iresult, r=0, reclen;
  tcb_fileio_vbidx_handle *h;
  tcob_file_key *k;
  char *crecord;
  struct keydesc *wkeydesc;   
         
#ifdef DEBUG_FILEISAM_RTS1
  fprintf(stderr, "debug : tcob_read_idx 070.020 : filename=%s, reclen=%d;\n", f->filename, f->reclen);
#endif                 

  f->flags.read_done = 0;
  f->flags.start_record = 0;

  /* ERROR check : File is open */
  if (f->dbp == NULL) {
     /* ERROR check : Set file-status condition when file is not available */
     if (f->flags.optional && f->flags.file_missing) 
        RETURN_STATUS(10);
     RETURN_STATUS(47);
  }

  /* ERROR check : Record length is valid - unknown error */
  if (f->reclen == -1)
     RETURN_STATUS(99);
  
  /* ERROR check : Must in INPUT or IO mode */
  if (((f->open_mode != TCB_FILE_OPEN_MODE_INPUT) && (f->open_mode != TCB_FILE_OPEN_MODE_IO)))
     RETURN_STATUS(47);
  
  /* Check that we didn't already hit eof */
  if ((f->open_mode == TCB_FILE_OPEN_MODE_INPUT || f->open_mode == TCB_FILE_OPEN_MODE_IO) && f->flags.eof_hit)
     RETURN_STATUS(46);
  
  /* ERROR check : For random key READ access mode must be RANDOM or DYNAMIC */
  if ((f->access_mode != TCB_FILE_ACCESS_MODE_RANDOM) &&
      (f->access_mode != TCB_FILE_ACCESS_MODE_DYNAMIC)
     )
     RETURN_STATUS(39);

 /* ERROR check : Key is required - unknown compiler error */
  if (fkey == NULL) 
     RETURN_STATUS(99);

  /* ERROR check : Key index is within bounds */
  if ((f->nkeys <= ikey) || (0 > ikey)) 
     RETURN_STATUS(99);
  
  h = (tcb_fileio_vbidx_handle *)f->dbp;
  k = f->keys;
  crecord = h->buf->buf[0]; 

  /* Read with key */
  memset (crecord, ' ', f->reclen);
  k = f->keys + ikey;
  memcpy (crecord+k->offset, keybuf, fkey->len);
  wkeydesc = h->skeydesc + ikey;
  iresult = isstart(h->ifilehandle, wkeydesc, f->reclen, crecord, ISEQUAL);
  if (iresult != 0) { 
     r = tcob_eisam2ecob(0);
     RETURN_STATUS(r);
  }
  iresult = isread(h->ifilehandle, crecord, ISCURR);
  if (iresult != 0) { 
     r = tcob_eisam2ecob(0);
     RETURN_STATUS(r);
  }

  /* Variable Length File */
  if (reclen_desc != NULL) {
     reclen = isreclen;  
     if (reclen > f->reclen) 
        RETURN_STATUS(99);
     /* Set record length buffer for variable length file */
     tcob_move(&_generic_4binary, (char *)&reclen, reclen_desc, reclen_buf);     
  }
  else {
     reclen = f->reclen;
  }

  /* Clear buffer and move data record */
  memset(f->record, ' ', f->reclen);
  memcpy (f->record, crecord, reclen);

  /* Copy buffer data to INTO identifiers buffer */
  if (rectofrom_desc != NULL) {
     memset(rectofrom_buf, ' ', rectofrom_desc->len);
     if (rectofrom_desc->len > reclen) 
        memcpy(rectofrom_buf, crecord, reclen);
     else
        memcpy(rectofrom_buf, crecord, rectofrom_desc->len);
  }

  f->flags.read_done = 1;

#ifdef DEBUG_FILEISAM_RTS1
  fprintf(stderr, "debug : tcob_read_idx 070.140 : r=%d;\n", r);
#endif                                       

  RETURN_STATUS(r);
}