Example #1
0
/*
 * call-seq:
 *   Liblicense.read(filename)
 *   Liblicense.read(filename, module)
 *
 * Reads license from given file and returns new Liblicense object.
 */
static VALUE rbll_read(int argc, VALUE *argv, VALUE klass) {
	VALUE obj;
	VALUE file, module;
	ll_uri_t uri;
	ruby_liblicense *license;

	rb_scan_args(argc, argv, "11", &file, &module);

	if (module != Qnil)
		uri = ll_module_read(StringValueCStr(file), LL_LICENSE, StringValueCStr(module));
	else
		uri = ll_read(StringValueCStr(file), LL_LICENSE);

	if (uri == NULL)
		return Qnil;


	obj = rbll_alloc(klass);
	Data_Get_Struct(obj, ruby_liblicense, license);

	_rbll_cache_info(license, rb_str_new2(uri));


	license->filename = file;


	return obj;
}
LicensePropsPlugin::LicensePropsPlugin(KPropertiesDialog *_props, const QStringList &) : KPropertiesDialogPlugin(_props)
{
	m_vBox = new KVBox();
	
	m_widget = new QWidget( m_vBox );
	QVBoxLayout * vbox = new QVBoxLayout( m_widget );
	
	QWidget *main = new QWidget(m_widget);
	vbox->addWidget( main );
	
	licenseChooser = new LicenseChooser(main);
	connect( licenseChooser, SIGNAL(licenseChanged()), this, SLOT(setDirty()) );

	m_widget->show(); // In case the dialog was shown already.

	if ( properties->items().count() == 1 ) {
		KFileItem *item = properties->item();
		if (item->url().isLocalFile()) {
			_props->addPage( m_vBox, i18n("&License") );

			QByteArray ba = item->localPath().toUtf8();
			char *license = ll_read(ba.data());
			
			if (license) {
				licenseChooser->setLicenseURI(QString::fromUtf8(license));
			} else {
				ll_uri_t uri = ll_get_default();
				licenseChooser->setLicenseURI(QString::fromUtf8(uri),false);
				free(uri);
			}
		}
	}
}
Example #3
0
int ml_read(struct afp_volume * volume, const char *path, 
	char *buf, size_t size, off_t offset,
	struct afp_file_info *fp, int * eof)
{
	int ret=0;
	//unsigned int bufsize=min(volume->server->rx_quantum,size);
	char converted_path[AFP_MAX_PATH];
	size_t amount_copied=0;

	*eof=0;

	if (convert_path_to_afp(volume->server->path_encoding,
		converted_path,(char *) path,AFP_MAX_PATH)) {
		return -EINVAL;
	}

	if (fp->resource) {
		ret=appledouble_read(volume,fp,buf,size,offset,&amount_copied,eof);

		if (ret<0) return ret;
		if (ret==1) return amount_copied;
		
	}

	ret=ll_read(volume,buf,size,offset,fp,eof);

	return ret;
}
int app_receive_data_packet(int fd, int* seq_number, char** buffer, int* length)
{
    char* packet_buffer;
    ssize_t total_size = ll_read(fd, &packet_buffer);
    if (total_size < 0)
    {
        perror("ll_read");
        return -1;
    }

    int ctrl = packet_buffer[0];

    if (ctrl != CONTROL_FIELD_DATA)
    {
        ERRORF("Control field received (%d) is not CONTROL_FIELD_DATA", ctrl);
        return -1;
    }

    int seq = (unsigned char)packet_buffer[1];
    int32 size;
    size.b[0] = packet_buffer[2];
    size.b[1] = packet_buffer[3];
    size.b[2] = packet_buffer[4];
    size.b[3] = packet_buffer[5];

    *buffer = malloc(size.w);
    memcpy(*buffer, &packet_buffer[6], size.w);
    free(packet_buffer);

    *seq_number = seq;
    *length = size.w;

    return 0;
}
Example #5
0
void do_test() {
	char *file="data/licensed.mp3";
	ll_uri_t license;
	license = ll_read(file, LL_LICENSE);
	printf("File license: %s\n",license);
	assert (license != NULL);
	free(license);
}
Example #6
0
int ldcs_audit_server_md_trash_bytes(node_peer_t peer, size_t size)
{
   char buffer[4096];
   int fd = (int) (long) peer;

   while (size) {
      if (size < 4096) {
         ll_read(fd, buffer, size);
         size = 0;
      }
      else {
         ll_read(fd, buffer, 4096);
         size -= 4096;
      }
   }

   return 0;
}
int app_receive_control_packet(int fd, int* ctrl, int n, control_param* params)
{ LOG
    char* buffer;
    ssize_t size = ll_read(fd, &buffer);
    if (size < 0)
    {
        perror("ll_read");
        return -1;
    }

    *ctrl = buffer[0];

    int read_size = 2; // ctrl + n

    if (buffer[1] != n)
    {
        ERRORF("Expected %d parameters but got %d", n, buffer[1]);
        return -1;
    }

    for (int i = 0; i < n; ++i)
    {
        control_param param;
        param.type = buffer[read_size];
        read_size += 1;
        switch (param.type)
        {
            case FIELD_PARAM_TYPE_FILE_SIZE:
            {
                read_size += 1; // ignore size of param
                param.file_size.size.b[0] = buffer[read_size];
                param.file_size.size.b[1] = buffer[read_size + 1];
                param.file_size.size.b[2] = buffer[read_size + 2];
                param.file_size.size.b[3] = buffer[read_size + 3];
                read_size += 4;
                break;
            }
            case FIELD_PARAM_TYPE_FILE_NAME:
            {
                int string_length = buffer[read_size];
                read_size += 1;
                param.file_name.name = malloc(string_length + 1);
                memcpy(param.file_name.name, &buffer[read_size], string_length);
                param.file_name.name[string_length] = 0; // NULL terminated
                read_size += string_length;
                break;
            }
        }

        params[i] = param;
    }

    free(buffer);

    return 0;
}
Example #8
0
int ldcs_audit_server_md_complete_msg_read(node_peer_t peer, ldcs_message_t *msg, void *mem, size_t size)
{
   int result = 0;
   int fd = (int) (long) peer;
   assert(msg->header.len >= size);
   result = ll_read(fd, mem, size);
   if (result == -1)
      return -1;
   return 0;
}
void ChunkTable::emit(FILE *fp)
{
	LinkedListIterator lli;
	for (ll_start(&chunks, &lli); ll_has_more(&lli); ll_advance(&lli))
	{
		ChunkEntry *chunk = (ChunkEntry *) ll_read(&lli);
		ZF_Chdr *chdr = chunk->get_chdr();
		int rc = fwrite((uint8_t*) chdr, sizeof(*chdr), 1, fp);
		lite_assert(rc==1);
	}
}
XVFSMount *XVFSNamespace::lookup(XfsPath *path)
{
	LinkedListIterator lli;
	for (ll_start(&mounts, &lli); ll_has_more(&lli); ll_advance(&lli))
	{
		XVFSMount *mount = (XVFSMount *) ll_read(&lli);
		if (_prefix_match(path->pathstr, mount->prefix))
		{
			path->suffix = path->pathstr + lite_strlen(mount->prefix);
			return mount;
		}
	}
	return NULL;
}
Example #11
0
int read_msg(int fd, node_peer_t *peer, ldcs_message_t *msg)
{
   int result;
   char *buffer = NULL;

   *peer = (node_peer_t) (long) fd;
   
   result = ll_read(fd, msg, sizeof(*msg));
   if (result == -1)
      return -1;

   if (msg->header.type == LDCS_MSG_FILE_DATA || msg->header.type == LDCS_MSG_PRELOAD_FILE) {
      /* Optimization.  Don't read file data into heap, as it could be
         very large.  For these packets we'll postpone the network read
         until we have the file's mmap ready, then read it straight
         into that memory. */
      msg->data = NULL;
      return 0;
   } 

   if (msg->header.len) {
      buffer = (char *) malloc(msg->header.len);
      if (buffer == NULL) {
         err_printf("Error allocating space for message from network of size %lu\n", (long) msg->header.len);
         return -1;
      }
      result = ll_read(fd, buffer, msg->header.len);
      if (result == -1) {
         free(buffer);
         return -1;
      }
   }

   msg->data = buffer;
   return 0;
}
void MmapDecoder::_dbg_dump_foreach(void* v_this, void* v_behavior)
{
	MmapBehavior* behavior = (MmapBehavior*) v_behavior;
	fprintf(stderr, "%s: aligned_mapping_size %x x %d\n",
		behavior->filename,
		behavior->aligned_mapping_size,
		behavior->aligned_mapping_copies);
	
	LinkedListIterator lli;
	for (ll_start(&behavior->precious_ranges, &lli);
		ll_has_more(&lli);
		ll_advance(&lli))
	{
		MDRange* range = (MDRange*) ll_read(&lli);
		fprintf(stderr, "  range %x--%x\n", range->start, range->end);
	}
}
void MmapBehavior::insert_range(MDRange* a_range)
{
	bool matches_existing = false;

	LinkedListIterator lli;
	for (ll_start(&precious_ranges, &lli);
		ll_has_more(&lli);
		ll_advance(&lli))
	{
		MDRange* range = (MDRange*) ll_read(&lli);
		if (range->includes(*a_range))
		{
			matches_existing = true;
			break;
		}
	}
	// TODO not very precise; doesn't coalesce ranges or anything. But
	// seems adequate.
	if (!matches_existing)
	{
		MDRange *new_range = new MDRange(*a_range);
		linked_list_insert_tail(&precious_ranges, new_range);
	}
}
Example #14
0
int main(int argC, char *args[])
/****************************************************/
{ char       colName[64], depName[64], str[1024];
  double     startTime, stopTime;
  s32       *deps, origC;
  u32        seed=DEFAULT_SEED;
  long       testMode=0;
  struct stat fileInfo;
  nfs_sparse_mat_t M;
  llist_t    C;
  int        i;
  FILE      *fp, *ifp;

  strcpy(colName, DEFAULT_COLNAME);
  strcpy(depName, DEFAULT_DEPNAME);
  printf(START_MSG, GGNFS_VERSION);
  seed=time(0);
  /* This probably shouldn't be needed, but whatever. */
  seed = ((seed % 1001)*seed) ^ (171*seed);

  for (i=1; i<argC; i++) {
    if (strcmp(args[i], "-v")==0) {
      verbose++;
    } else if (strcmp(args[i], "-seed")==0) {
      if ((++i) < argC) {
        seed = atol(args[i]);
      }
    } else if (strcmp(args[i], "-save")==0) {
      if ((++i) < argC) {
        matsave_interval = 60 * atoi(args[i]);
      }
    } else if (strcmp(args[i], "-test")==0) {
      testMode = 1;
    } else if (strcmp(args[i], "--help")==0) {
      printf("USAGE: %s %s\n", args[0], USAGE);
      exit(0);
    }
  }
  srand(seed);
  if (stat("depinf", &fileInfo)) {
    printf("Could not stat depinf! Are you trying to run %s to soon?\n", args[0]);
    return -1;
  }
  seedBlockLanczos(seed);
  startTime = sTime();
  msgLog("", "GGNFS-%s : matsolve (seed=%" PRIu32 ")", GGNFS_VERSION, seed);
  printf("Using PRNG seed=%" PRIu32 ".\n", seed);

  readSparseMat(&M, "spmat");
  ll_read(&C, "sp-index");
  printf("Verifying column map..."); fflush(stdout);
  ll_verify(&C);
  printf("done.\n");


  printf("Matrix loaded: it is %" PRId32 " x %" PRId32 ".\n", M.numRows, M.numCols);
  if (M.numCols < (M.numRows + 64)) {
    printf("More columns needed (current = %" PRId32 ", min = %" PRId32 ")\n",
           M.numCols, M.numRows+64);
    free(M.cEntry); free(M.cIndex);
    exit(-1);
  }
  if (checkMat(&M, delCols, &numDel)) {
    printf("checkMat() returned some error! Terminating...\n");
    exit(-1);
  }

  /* We need to know how many columns there were in the original, unpruned
     matrix, so we know how much memory to allocate for the dependencies.
  */
  if (!(ifp = fopen("depinf", "rb"))) {
    fprintf(stderr, "Error opening depinf for read!\n");
    exit(-1);
  }
  readBinField(str, 1024, ifp);
  while (!(feof(ifp)) && strncmp(str, "END_HEADER",10)) {
    if (strncmp(str, "NUMCOLS: ", 9)==0) {
      sscanf(&str[9], "%" SCNx32, &origC);
    }
    readBinField(str, 1024, ifp);
  }
  fclose(ifp); 
  printf("Original matrix had %" PRId32 " columns.\n", origC);

  if (!(deps = (s32 *)malloc(origC*sizeof(s32)))) {
    printf("Could not allocate %" PRIu32 " bytes for the dependencies.\n", (u32)(origC*sizeof(s32)) );
    free(M.cEntry); free(M.cIndex); return -1;
  }

  if (getDependencies(&M, &C, deps, origC, testMode) == 0) {
    if (!(ifp = fopen("depinf", "rb"))) {
      fprintf(stderr, "Error opening depinf for read!\n");
      exit(-1);
    }
    printf("Writing dependencies to file %s.\n", depName);
    if (!(fp = fopen(depName, "wb"))) {
      fprintf(stderr, "Error opening %s for write!\n", depName);
      fclose(ifp);
    } else {
      /* Get the header information from depinf. */
      readBinField(str, 1024, ifp);
      while (!(feof(ifp)) && strncmp(str, "END_HEADER",10)) {
        writeBinField(fp, str);
        readBinField(str,1024,ifp);
      }
      if (strncmp(str, "END_HEADER",10)) {
        fprintf(stderr, "Error: depinf is corrupt!\n");
        fclose(ifp); fclose(fp); exit(-1);
      }
      writeBinField(fp, str);
      fclose(ifp);
      fwrite(deps, sizeof(s32), origC, fp);
      fclose(fp);
    }
  }

  stopTime = sTime();
  printf("Total elapsed time: %1.2lf seconds.\n", stopTime-startTime);
  msgLog("", "Heap stats for matsolve run:");
  logHeapStats();



  free(M.cEntry); free(M.cIndex); free(deps);
  return 0;
}  
void corefile_write_custom(CoreFile *c, write_callback_func *write_func, tell_callback_func *ftell_func, void *user_file_obj)
{
//	write_func(user_file_obj, "slicksnot", 9);
	const int num_notes = 1;
	int pad_i;
	int hdr_offset = 0;
	bool rc;
	Elf32_Ehdr ehdr;

	int thread_notes_size = c->threads.count * sizeof(CoreNote_Regs);

	// compute how much header space we need...
	int hdr_size = 0
		+sizeof(Elf32_Ehdr)
		+sizeof(Elf32_Phdr)					// NOTE hdr
		+sizeof(Elf32_Phdr)*c->segments.count
		+thread_notes_size
		+sizeof(c->corenote_zoog);
	int rounded_hdr_size = (hdr_size + 0xfff) & ~0xfff;
	int pad_size = rounded_hdr_size - hdr_size;

	// ...so that we can plan on laying data segments down after that.
	int seg_file_offset = rounded_hdr_size;

	ehdr.e_ident[EI_MAG0] = ELFMAG0;
	ehdr.e_ident[EI_MAG1] = ELFMAG1;
	ehdr.e_ident[EI_MAG2] = ELFMAG2;
	ehdr.e_ident[EI_MAG3] = ELFMAG3;
	ehdr.e_ident[EI_CLASS] = ELFCLASS32;
	ehdr.e_ident[EI_DATA] = ELFDATA2LSB;
	ehdr.e_ident[EI_VERSION] = EV_CURRENT;
	ehdr.e_ident[EI_OSABI] = ELFOSABI_NONE;
	ehdr.e_ident[EI_ABIVERSION] = 0;

	for (pad_i=EI_PAD; pad_i<EI_NIDENT; pad_i++)
	{
		ehdr.e_ident[pad_i] = 0;
	}
	ehdr.e_type = ET_CORE;
	ehdr.e_machine = EM_386;
	ehdr.e_version = EV_CURRENT;
	ehdr.e_entry = 0;
	ehdr.e_phoff = sizeof(ehdr);
	ehdr.e_shoff = 0;
	ehdr.e_flags = 0;
	ehdr.e_ehsize = sizeof(ehdr);
	ehdr.e_phentsize = sizeof(Elf32_Phdr);
	ehdr.e_phnum = (Elf32_Half) (num_notes + c->segments.count);
	ehdr.e_shentsize = 0;
	ehdr.e_shnum = 0;
	ehdr.e_shstrndx = 0;

	rc = write_func(user_file_obj, &ehdr, sizeof(ehdr));
	lite_assert(rc);
	hdr_offset += sizeof(ehdr);

	// write CoreNotes Phdr
	{
		lite_assert(c->corenote_zoog.bootblock_addr != 0x0);

		Elf32_Phdr phdr;
		phdr.p_type = PT_NOTE;
		phdr.p_flags = 0;
		phdr.p_offset = hdr_offset + sizeof(Elf32_Phdr)*ehdr.e_phnum;
		phdr.p_vaddr = 0;
		phdr.p_paddr = 0;
		phdr.p_filesz = thread_notes_size + sizeof(c->corenote_zoog);
		phdr.p_memsz = 0;
		phdr.p_align = 0;

		rc = (*write_func)(user_file_obj, &phdr, sizeof(phdr));
		lite_assert(rc);
		hdr_offset += sizeof(phdr);
	}

	LinkedListIterator lli;
	for (ll_start(&c->segments, &lli);
		ll_has_more(&lli);
		ll_advance(&lli))
	{
		CoreSegment *seg = (CoreSegment *) ll_read(&lli);

		Elf32_Phdr phdr;
		lite_assert((seg->size & 0xfff) == 0);

		phdr.p_type = PT_LOAD;
		phdr.p_flags = PF_X|PF_W|PF_R;
		phdr.p_offset = seg_file_offset;
		phdr.p_vaddr = (uint32_t) seg->vaddr;
		phdr.p_paddr = 0;
		phdr.p_filesz = seg->size;
		phdr.p_memsz = seg->size;
		phdr.p_align = 0x1000;

		rc = (*write_func)(user_file_obj, &phdr, sizeof(phdr));
		lite_assert(rc);
		hdr_offset += sizeof(phdr);

		seg_file_offset += phdr.p_filesz;
		lite_assert(ftell_func==NULL || hdr_offset == (*ftell_func)(user_file_obj));
	}

	// write the PT_NOTEs that contains the register & zoog symbol info
	{
		LinkedListIterator lli;
		for (ll_start(&c->threads, &lli);
			ll_has_more(&lli);
			ll_advance(&lli))
		{
			CoreNote_Regs *corenote_regs = (CoreNote_Regs *) ll_read(&lli);

			rc = (*write_func)(user_file_obj, corenote_regs, sizeof(*corenote_regs));
			lite_assert(rc);
			hdr_offset += sizeof(*corenote_regs);
		}
		rc = (*write_func)(user_file_obj, &c->corenote_zoog, sizeof(c->corenote_zoog));
		lite_assert(rc);
		hdr_offset += sizeof(c->corenote_zoog);
	}

	lite_assert(pad_size>=0);

	lite_assert(pad_size < 0x1000);
	char pad_zeros[0x1000];
	lite_memset(pad_zeros, 0, sizeof(pad_zeros));
	rc = (*write_func)(user_file_obj, &pad_zeros, pad_size);
	lite_assert(rc);
	lite_assert(ftell_func==NULL || rounded_hdr_size == (*ftell_func)(user_file_obj));
	seg_file_offset = rounded_hdr_size;

	for (ll_start(&c->segments, &lli);
		ll_has_more(&lli);
		ll_advance(&lli))
	{
		CoreSegment *seg = (CoreSegment *) ll_read(&lli);

		rc = (*write_func)(user_file_obj, seg->bytes, seg->size);
		lite_assert(rc);
		seg_file_offset += seg->size;
		lite_assert(ftell_func==NULL || seg_file_offset == (*ftell_func)(user_file_obj));
	}
}
Example #16
0
int appledouble_read(struct afp_volume * volume, struct afp_file_info *fp,
	char * buf, size_t size, off_t offset, size_t * amount_read,
	int * eof)
{
	int tocopy;
	int ret;
	struct afp_comment comment;
	*amount_read=0;
	*eof=0;

	comment.data=malloc(size);
	comment.maxsize=size;

	switch(fp->resource) {
		case AFP_META_RESOURCE:
			ret=ll_read(volume,buf,size,offset,fp->forkid,eof);
			return ret;
		case AFP_META_APPLEDOUBLE:
			return -EBADF;
		case AFP_META_FINDERINFO:
			if (offset>32) return -EFAULT;
			ret=ll_get_directory_entry(volume,fp->basename,fp->did,
				kFPFinderInfoBit,kFPFinderInfoBit,fp);
			if (ret<0) return ret;
			tocopy=min(size,(32-offset));
			memcpy(buf+offset,fp->finderinfo,tocopy);
			if (offset+tocopy==32) *eof=1;
			*amount_read=tocopy;
		case AFP_META_COMMENT:
			if (fp->eof)  ret=1;  else 
			switch(afp_getcomment(volume,fp->did, fp->basename, &comment)) {
				case kFPAccessDenied:
					ret=-EACCES;
					break;
				case kFPMiscErr:
				case kFPParamErr:
					ret=-EIO;
					break;
				case kFPItemNotFound:
				case kFPObjectNotFound:
					ret=-ENOENT;
					break;
				case kFPNoErr:
					memcpy(buf,comment.data,comment.size);
					*amount_read =comment.size;
					ret=1;
					*eof=1;
					fp->eof=1;
				default:
				break;
			}
			free(comment.data);
			return ret;
		case AFP_META_SERVER_ICON:
			if (offset>256) return -EFAULT;
			tocopy=min(size,(256-offset));
			memcpy(buf+offset,volume->server->basic.icon,tocopy);
			*eof=1;
			fp->eof=1;
			*amount_read=tocopy;
			return 1;
	}
	return 0;
}