Example #1
0
int main( ) {
   const std::string xmltext(
      "<inventory title=\"OmniCorp Store #45x10^3\">"
	"<section name=\"health\">"
	  "<item upc=\"123456789\" stock=\"12\">"
	    "<name>Invisibility Cream</name>"
	    "<price>14.50</price>"
	    "<description>Makes you invisible</description>"
	  "</item>"
	  "<item upc=\"445322344\" stock=\"18\">"
	    "<name>Levitation Salve</name>"
	    "<price>23.99</price>"
	    "<description>Levitate yourself for up to 3 hours per application</description>"
	  "</item>"
	"</section>"
	"<section name=\"food\">"
	  "<item upc=\"485672034\" stock=\"653\">"
	    "<name>Blork and Freen Instameal</name>"
	    "<price>4.95</price>"
	    "<description>A tasty meal in a tablet; just add water</description>"
	  "</item>"
	  "<item upc=\"132957764\" stock=\"44\">"
	    "<name>Grob winglets</name>"
	    "<price>3.56</price>"
	    "<description>Tender winglets of Grob. Just add water</description>"
	  "</item>"
	"</section>"
      "</inventory>" ) ;
   std::string::size_type found = xmltext.find( "<item" , 0 ) ; //beginning of first item
   std::string::size_type foundnext = xmltext.find(  "</item>" , found + 5 ) ; //and its end
   std::cout << "The first item is\n" << xmltext.substr( found + 5 , foundnext - ( found + 5 ) ) << '\n' ;
   std::string::const_iterator start , end ;
   start = xmltext.begin( ) ;
   end = xmltext.end( ) ;
   boost::match_results<std::string::const_iterator> what ;
   boost::regex pricefind( "<price>(\\d+\\.?\\d+)</price>" ) ;//this regex finds the prices
   start = xmltext.begin( ) ;
   std::cout << "The prices are:\n" ;
   while ( boost::regex_search( start , end , what , pricefind ) ) {
      std::string price( what[ 1 ].first , what[ 1 ].second ) ;//find the first price
      std::cout << price << std::endl ;
      start = what[ 1 ].second ;                               //continue search after first price found
   }
   start = xmltext.begin( ) ;
   std::vector<std::string> names ;
   boost::regex namefind( "<name>(.+?)</name>" ) ;            //find characters, be greedy!
   while ( boost::regex_search ( start , end , what , namefind ) ) {
      std::string name ( what[ 1 ].first , what[ 1 ].second ) ;
      names.push_back( name ) ;
      start = what[ 1 ].second ;
   }
   std::cout << "The following name elements were found in the xml string:\n" ;
   std::copy( names.begin( ) , names.end( ) , std::ostream_iterator<std::string>( std::cout , "\n" )) ;
   return 0 ;
}
Example #2
0
/*
 * Unmount a file descriptor from a node in the file system.
 * If the user is not the owner of the file and is not privileged,
 * the request is denied.
 * Otherwise, remove the namenode from the hash list.
 * If the mounted file descriptor was that of a stream and this
 * was the last mount of the stream, turn off the STRMOUNT flag.
 * If the rootvp is referenced other than through the mount,
 * nm_inactive will clean up.
 */
static int
nm_unmount(vfs_t *vfsp, int flag, cred_t *crp)
{
	struct namenode *nodep = (struct namenode *)vfsp->vfs_data;
	vnode_t *vp, *thisvp;
	struct file *fp = NULL;

	ASSERT((nodep->nm_flag & NMNMNT) == 0);

	/*
	 * forced unmount is not supported by this file system
	 * and thus, ENOTSUP, is being returned.
	 */
	if (flag & MS_FORCE) {
		return (ENOTSUP);
	}

	vp = nodep->nm_filevp;
	mutex_enter(&nodep->nm_lock);
	if (secpolicy_vnode_owner(crp, nodep->nm_vattr.va_uid) != 0) {
		mutex_exit(&nodep->nm_lock);
		return (EPERM);
	}

	mutex_exit(&nodep->nm_lock);

	mutex_enter(&ntable_lock);
	nameremove(nodep);
	thisvp = NMTOV(nodep);
	mutex_enter(&thisvp->v_lock);
	if (thisvp->v_count-- == 1) {
		fp = nodep->nm_filep;
		mutex_exit(&thisvp->v_lock);
		vn_invalid(thisvp);
		vn_free(thisvp);
		VFS_RELE(vfsp);
		namenodeno_free(nodep->nm_vattr.va_nodeid);
		kmem_free(nodep, sizeof (struct namenode));
	} else {
		thisvp->v_flag &= ~VROOT;
		mutex_exit(&thisvp->v_lock);
	}
	if (namefind(vp, NULLVP) == NULL && vp->v_stream) {
		struct stdata *stp = vp->v_stream;
		mutex_enter(&stp->sd_lock);
		stp->sd_flag &= ~STRMOUNT;
		mutex_exit(&stp->sd_lock);
	}
	mutex_exit(&ntable_lock);
	if (fp != NULL)
		(void) closef(fp);
	return (0);
}
Example #3
0
static void GetDeviceName(const ASCII ** strpointer, struct connection_in * in)
{
	BYTE sn[SERIAL_NUMBER_SIZE] ;
	BYTE dn[SERIAL_NUMBER_SIZE] ;

	if ( isxdigit((*strpointer)[0])	&& isxdigit((*strpointer)[1]) ) {
		// family code specified
		sn[0] = string2num(*strpointer);
		*strpointer +=  2;

		GetDefaultDeviceName( dn, sn, in ) ;
		// Choice of default or specified ID
		GetNextByte(strpointer,dn[1],&sn[1]);
		GetNextByte(strpointer,dn[2],&sn[2]);
		GetNextByte(strpointer,dn[3],&sn[3]);
		GetNextByte(strpointer,dn[4],&sn[4]);
		GetNextByte(strpointer,dn[5],&sn[5]);
		GetNextByte(strpointer,dn[6],&sn[6]);
	} else {
		const ASCII * name_to_familycode = namefind((*strpointer)) ;
		if (  name_to_familycode != NULL) {
			// device name specified (e.g. DS2401)
			sn[0] = string2num(name_to_familycode);
			GetDefaultDeviceName( dn, sn, in ) ;
			sn[1] = dn[1] ;
			sn[2] = dn[2] ;
			sn[3] = dn[3] ;
			sn[4] = dn[4] ;
			sn[5] = dn[5] ;
			sn[6] = dn[6] ;
		} else {
			// Bad device name
			LEVEL_DEFAULT("Device %d <%s> not recognized for %s %d -- ignored",DirblobElements(&(in->master.fake.main))+1,*strpointer,in->adapter_name,in->master.fake.index);
			return ;
		}
	}
	sn[SERIAL_NUMBER_SIZE-1] = CRC8compute(sn, SERIAL_NUMBER_SIZE-1, 0);
	DirblobAdd(sn, &(in->master.fake.main));	// Ignore bad return
}
Example #4
0
/*
 * Create a reference to the vnode representing the file descriptor.
 * Then, apply the VOP_OPEN operation to that vnode.
 *
 * The vnode for the file descriptor may be switched under you.
 * If it is, search the hash list for an nodep - nodep->nm_filevp
 * pair. If it exists, return that nodep to the user.
 * If it does not exist, create a new namenode to attach
 * to the nodep->nm_filevp then place the pair on the hash list.
 *
 * Newly created objects are like children/nodes in the mounted
 * file system, with the parent being the initial mount.
 */
int
nm_open(vnode_t **vpp, int flag, cred_t *crp, caller_context_t *ct)
{
	struct namenode *nodep = VTONM(*vpp);
	int error = 0;
	struct namenode *newnamep;
	struct vnode *newvp;
	struct vnode *infilevp;
	struct vnode *outfilevp;

	/*
	 * If the vnode is switched under us, the corresponding
	 * VN_RELE for this VN_HOLD will be done by the file system
	 * performing the switch. Otherwise, the corresponding
	 * VN_RELE will be done by nm_close().
	 */
	infilevp = outfilevp = nodep->nm_filevp;
	VN_HOLD(outfilevp);

	if ((error = VOP_OPEN(&outfilevp, flag, crp, ct)) != 0) {
		VN_RELE(outfilevp);
		return (error);
	}
	if (infilevp != outfilevp) {
		/*
		 * See if the new filevp (outfilevp) is already associated
		 * with the mount point. If it is, then it already has a
		 * namenode associated with it.
		 */
		mutex_enter(&ntable_lock);
		if ((newnamep =
		    namefind(outfilevp, nodep->nm_mountpt)) != NULL) {
			struct vnode *vp = NMTOV(newnamep);

			VN_HOLD(vp);
			goto gotit;
		}

		newnamep = kmem_zalloc(sizeof (struct namenode), KM_SLEEP);
		newvp = vn_alloc(KM_SLEEP);
		newnamep->nm_vnode = newvp;

		mutex_init(&newnamep->nm_lock, NULL, MUTEX_DEFAULT, NULL);

		mutex_enter(&nodep->nm_lock);
		newvp->v_flag = ((*vpp)->v_flag | VNOMAP | VNOSWAP) & ~VROOT;
		vn_setops(newvp, vn_getops(*vpp));
		newvp->v_vfsp = &namevfs;
		newvp->v_stream = outfilevp->v_stream;
		newvp->v_type = outfilevp->v_type;
		newvp->v_rdev = outfilevp->v_rdev;
		newvp->v_data = (caddr_t)newnamep;
		vn_exists(newvp);
		bcopy(&nodep->nm_vattr, &newnamep->nm_vattr, sizeof (vattr_t));
		newnamep->nm_vattr.va_type = outfilevp->v_type;
		newnamep->nm_vattr.va_nodeid = namenodeno_alloc();
		newnamep->nm_vattr.va_size = (u_offset_t)0;
		newnamep->nm_vattr.va_rdev = outfilevp->v_rdev;
		newnamep->nm_flag = NMNMNT;
		newnamep->nm_filevp = outfilevp;
		newnamep->nm_filep = nodep->nm_filep;
		newnamep->nm_mountpt = nodep->nm_mountpt;
		mutex_exit(&nodep->nm_lock);

		/*
		 * Insert the new namenode into the hash list.
		 */
		nameinsert(newnamep);
gotit:
		mutex_exit(&ntable_lock);
		/*
		 * Release the above reference to the infilevp, the reference
		 * to the NAMEFS vnode, create a reference to the new vnode
		 * and return the new vnode to the user.
		 */
		VN_RELE(*vpp);
		*vpp = NMTOV(newnamep);
	}
	return (0);
}