Пример #1
0
int setNPprefs_byfile(int enableproxies)
{
	const char file[]="/boot/home/config/settings/NetPositive/settings";
	const char proxyname[]="127.0.0.1";
	const long proxyport=8080;
	FILE *f;
	char b;
	
	f=fopen(file,"w");
	if(!f) return -1;
	
	b=enableproxies;
	fs_write_attr(fileno(f),
		"HTTPProxyActive",B_BOOL_TYPE,0,&b,sizeof b);
	fs_write_attr(fileno(f),
		"FTPProxyActive",B_BOOL_TYPE,0,&b,sizeof b);
		// HTTP et FTP sont liés dans l'interface graphique de Net+...

	fs_write_attr(fileno(f),
		"HTTPProxyName",B_STRING_TYPE,0,proxyname,strlen(proxyname)+1);

	fs_write_attr(fileno(f),
		"HTTPProxyPort",B_INT32_TYPE,0,&proxyport,sizeof proxyport);

	fclose(f);

	return 0;
}
Пример #2
0
void set_finfo(const char *path, uint32 finfo, uint32 fxinfo, bool is_dir)
{
	// Open file
	int fd = open(path, O_WRONLY);
	if (fd < 0)
		return;

	if (!is_dir) {

		// Set BEOS:TYPE attribute
		uint32 type = ReadMacInt32(finfo + fdType);
		if (type) {
			for (int i=0; m2t_translation[i].mime; i++) {
				if (m2t_translation[i].type == type && m2t_translation[i].reversible) {
					fs_write_attr(fd, "BEOS:TYPE", B_MIME_STRING_TYPE, 0, m2t_translation[i].mime, strlen(m2t_translation[i].mime) + 1);
					break;
				}
			}
		}

		// Set MACOS:CREATOR attribute
		uint32 creator = ReadMacInt32(finfo + fdCreator);
		if (creator) {
			tmp_buf[0] = creator >> 24;
			tmp_buf[1] = creator >> 16;
			tmp_buf[2] = creator >> 8;
			tmp_buf[3] = creator;
			fs_write_attr(fd, "MACOS:CREATOR", B_UINT32_TYPE, 0, tmp_buf, 4);
		}
	}
Пример #3
0
void URLView::CreatePerson( const BString *fullName, const BString *title ) {
	// Read the file defined by the path and the title.
	BFile *file = new BFile( fullName->String(), B_WRITE_ONLY );
		
	// Set the file's MIME type to be a person.
	BNodeInfo *nodeInfo = new BNodeInfo( file );
	nodeInfo->SetType( "application/x-person" );
	delete nodeInfo;
	delete file;

	// Add all the attributes, both those inherrent to person files and any
	// the developer may have defined using AddAttribute().
	DIR *d;
	int fd;
	d = fs_open_attr_dir( fullName->String() );
	if( d ) {
		fd = open( fullName->String(), O_WRONLY );
		fs_write_attr( fd, "META:name", B_STRING_TYPE, 0, title->String(), title->Length() + 1 );
		BString email = GetImportantURL();
		fs_write_attr( fd, "META:email", B_STRING_TYPE, 0, email.String(), email.Length() + 1 );
		WriteAttributes( fd );
		close( fd );
		fs_close_attr_dir( d ); 
	}
}
Пример #4
0
void URLView::WriteAttributes( int fd ) {
	// Write the developer-defined attributes to the newly-created file.
	KeyPair *item; 
	for( int i = 0;  (item = (KeyPair *) attributes->ItemAt(i));  i++ ) {
		fs_write_attr( fd, item->key->String(), B_STRING_TYPE, 0, item->value->String(), item->value->Length() + 1 );
	}	
}
Пример #5
0
/*!	\brief Writes data from a buffer to an attribute.
	Write the \a len bytes of data from \a buffer to
	the attribute specified by \a name after erasing any data
	that existed previously. The type specified by \a type \em is
	remembered, and may be queried with GetAttrInfo(). The value of
	\a offset is currently ignored.
	\param attr the name of the attribute
	\param type the type of the attribute
	\param offset the index at which to write the data (currently ignored)
	\param buffer the buffer containing the data to be written
	\param len the number of bytes to be written
	\return
	- the number of bytes actually written
	- \c B_BAD_VALUE: \c NULL \a attr or \a buffer
	- \c B_FILE_ERROR: The object is not initialized or the node it refers to
	  is read only.
	- \c B_NOT_ALLOWED: The node resides on a read only volume.
	- \c B_DEVICE_FULL: Insufficient disk space.
	- \c B_NO_MEMORY: Insufficient memory to complete the operation.
*/
ssize_t
BNode::WriteAttr(const char *attr, type_code type, off_t offset,
				 const void *buffer, size_t len)
{
	if (fCStatus != B_OK)
		return B_FILE_ERROR;
	if (!attr || !buffer)
		return B_BAD_VALUE;
	ssize_t result = fs_write_attr (fFd, attr, type, offset, buffer, len);
	return (result < 0 ? errno : result);
}
Пример #6
0
// WriteAttr
status_t
FileHandle::WriteAttr(const char* name, uint32 type, off_t pos,
                      const void* buffer, size_t size, size_t* _bytesWritten)
{
    if (fFD < 0)
        return B_BAD_VALUE;

    ssize_t bytesWritten = fs_write_attr(fFD, name, type, pos, buffer, size);
    if (bytesWritten < 0)
        return errno;

    *_bytesWritten = bytesWritten;
    return B_OK;
}
Пример #7
0
void URLView::CreateBookmark( const BString *fullName, const BString *title ) {
	// Read the file defined by the path and the title.
	BFile *file = new BFile( fullName->String(), B_WRITE_ONLY );

	// Set the file's MIME type to be a bookmark.
	BNodeInfo *nodeInfo = new BNodeInfo( file );
	nodeInfo->SetType( "application/x-vnd.Be-bookmark" );
	delete nodeInfo;
	delete file;

	// Add all the attributes, both those inherrent to bookmarks and any
	// the developer may have defined using AddAttribute().
	DIR *d;
	int fd;
	d = fs_open_attr_dir( fullName->String() );
	if( d ) {
		fd = open( fullName->String(), O_WRONLY );
		fs_write_attr( fd, "META:title", B_STRING_TYPE, 0, title->String(), title->Length() + 1 );
		fs_write_attr( fd, "META:url", B_STRING_TYPE, 0, url->String(), url->Length() + 1 );
		WriteAttributes( fd );
		close( fd );
		fs_close_attr_dir( d ); 
	}
}
static int rfork_write(SDL_RWops *context, const void *ptr, int size, int maxnum)
{
	rfork_data *d = (rfork_data *)context->hidden.unknown.data1;

	int num = maxnum;
	if (d->current + (num*size) > d->size)
		num = (d->size - d->current) / size;

	ssize_t actual = fs_write_attr(d->fd, ATTR_NAME, B_RAW_TYPE, d->current, ptr, num * size);
	if (actual < 0)
		return actual;
	else {
		d->current += actual;
		return actual / size;
	}
}
Пример #9
0
void ExtractBeEANew(Archive &Arc,char *FileName)
{
  Array<byte> SubData;
  if (!Arc.ReadSubData(&SubData,NULL))
    return;

  int fd = open(FileName,O_WRONLY);
  if (fd==-1)
  {
    Log(Arc.FileName,St(MCannotSetEA),FileName);
    ErrHandler.SetErrorCode(RARX_WARNING);
    return;
  }

  int AttrPos=0;
  while (AttrPos<Arc.EAHead.UnpSize)
  {
    unsigned char *CurItem=&SubData[AttrPos];
    int NameSize=CurItem[0]+((int)CurItem[1]<<8);
    int Type=CurItem[2]+((int)CurItem[3]<<8)+((int)CurItem[4]<<16)+((int)CurItem[5]<<24);
    int Size=CurItem[6]+((int)CurItem[7]<<8)+((int)CurItem[8]<<16)+((int)CurItem[9]<<24);
    char Name[1024];
    if (NameSize>=sizeof(Name))
    {
      Log(Arc.FileName,St(MCannotSetEA),FileName);
      ErrHandler.SetErrorCode(RARX_WARNING);
      break;
    }
    memcpy(Name,CurItem+10,NameSize);
    Name[NameSize]=0;
    if (fs_write_attr(fd,Name,Type,0,CurItem+10+NameSize,Size)==-1)
    {
      Log(Arc.FileName,St(MCannotSetEA),FileName);
      ErrHandler.SetErrorCode(RARX_WARNING);
      break;
    }
    AttrPos+=10+NameSize+Size;
  }
  close(fd);
  mprintf(St(MShowEA));
}
Пример #10
0
int main(void)
{
	char path[300];
	int code;
	thread_id tid;
	system_info sinfo;
	thread_info tinfo;
	int fd;
	int r;
	struct{
		int lock;
		bigtime_t sessionSN;
		thread_id tid;
	}lockdata;
	
	signal(SIGINT,SIG_IGN);	// protection anti-cons

	get_system_info(&sinfo);

	for(;;){
		code=receive_data(&tid,&path,sizeof path);
		path[sizeof path-1]=0;
		
		fd=open(path,B_READ_WRITE);
		if(fd<0){
			send_data(tid,errno,NULL,0);
			continue;
		}
		
		r=fs_read_attr(fd,AFL_SERVER_NAME,ATTRTYPE,
			0,&lockdata,sizeof lockdata);
		
		switch(code){
		case AFLMSG_LOCK:
			if(r==sizeof lockdata
			&& lockdata.lock
			&& lockdata.sessionSN==sinfo.boot_time
			&& !(get_thread_info(lockdata.tid,&tinfo))){
				// le fichier est déjà vérouillé !
				close(fd);
				send_data(tid,AFLMSG_ISLOCKED,&lockdata.tid,sizeof lockdata.tid);
				break;
			}

			lockdata.lock=1;
			lockdata.sessionSN=sinfo.boot_time;
			lockdata.tid=tid;
			r=fs_write_attr(fd,AFL_SERVER_NAME,ATTRTYPE,
				0,&lockdata,sizeof lockdata);
			close(fd);
			if(r<0)
				send_data(tid,errno,0,NULL);
			else
				send_data(tid,B_OK,0,NULL);
			break;
			
		case AFLMSG_UNLOCK:
			if(r!=sizeof lockdata
			|| !lockdata.lock
			|| lockdata.sessionSN!=sinfo.boot_time
			|| lockdata.tid!=tid){
				// le fichier n'est pas vérouillé par ce thread !
				close(fd);
				send_data(tid,B_PERMISSION_DENIED,0,NULL);
				break;
			}

			r=fs_remove_attr(fd,AFL_SERVER_NAME);
			close(fd);
			if(r<0)
				send_data(tid,errno,0,NULL);
			else
				send_data(tid,B_OK,0,NULL);
			break;
			
		default:
			close(fd);
			send_data(tid,B_BAD_VALUE,0,NULL);
		}
	}
	
	return 0;
}
Пример #11
0
void ExtractBeEA(Archive &Arc,char *FileName)
{
  if (Arc.HeaderCRC!=Arc.EAHead.HeadCRC)
  {
    Log(Arc.FileName,St(MEABroken),FileName);
    ErrHandler.SetErrorCode(RARX_CRC);
    return;
  }
  if (Arc.EAHead.Method<0x31 || Arc.EAHead.Method>0x35 || Arc.EAHead.UnpVer>PACK_VER)
  {
    Log(Arc.FileName,St(MEAUnknHeader),FileName);
    return;
  }

  ComprDataIO DataIO;
  Unpack Unpack(&DataIO);
  Unpack.Init();

  Array<byte> UnpData(Arc.EAHead.UnpSize);
  DataIO.SetUnpackToMemory(&UnpData[0],Arc.EAHead.UnpSize);
  DataIO.SetPackedSizeToRead(Arc.EAHead.DataSize);
  DataIO.EnableShowProgress(false);
  DataIO.SetFiles(&Arc,NULL);
  Unpack.SetDestSize(Arc.EAHead.UnpSize);
  Unpack.DoUnpack(Arc.EAHead.UnpVer,false);

  if (Arc.EAHead.EACRC!=~DataIO.UnpFileCRC)
  {
    Log(Arc.FileName,St(MEABroken),FileName);
    ErrHandler.SetErrorCode(RARX_CRC);
    return;
  }
  int fd = open(FileName,O_WRONLY);
  if (fd==-1)
  {
    Log(Arc.FileName,St(MCannotSetEA),FileName);
    ErrHandler.SetErrorCode(RARX_WARNING);
    return;
  }

  int AttrPos=0;
  while (AttrPos<Arc.EAHead.UnpSize)
  {
    unsigned char *CurItem=&UnpData[AttrPos];
    int NameSize=CurItem[0]+((int)CurItem[1]<<8);
    int Type=CurItem[2]+((int)CurItem[3]<<8)+((int)CurItem[4]<<16)+((int)CurItem[5]<<24);
    int Size=CurItem[6]+((int)CurItem[7]<<8)+((int)CurItem[8]<<16)+((int)CurItem[9]<<24);
    char Name[1024];
    if (NameSize>=sizeof(Name))
    {
      Log(Arc.FileName,St(MCannotSetEA),FileName);
      ErrHandler.SetErrorCode(RARX_WARNING);
      break;
    }
    memcpy(Name,CurItem+10,NameSize);
    Name[NameSize]=0;
    if (fs_write_attr(fd,Name,Type,0,CurItem+10+NameSize,Size)==-1)
    {
      Log(Arc.FileName,St(MCannotSetEA),FileName);
      ErrHandler.SetErrorCode(RARX_WARNING);
      break;
    }
    AttrPos+=10+NameSize+Size;
  }
  close(fd);
  mprintf(St(MShowEA));
}