Example #1
0
int main(int argc, char **argv) {
  char next[NAME_MAX];
  char *path;
  argv++;
  while(*argv) {
    path = *argv;
    printf("TRAVERSE PATH; %s\n",path);
    while(*path) {
      printf("path before: %s\n",path);
      path = getNextComponent(path,next);
      printf("name: %s\nnext: %s\n\n",path,next);
    }
    argv++;
  }
  return 0;
}
Example #2
0
// -----------------------------------------------------------------
// Name : onButtonEvent
// -----------------------------------------------------------------
bool LevelUpDlg::onButtonEvent(ButtonAction * pEvent, guiComponent * pCpnt)
{
    if (strcmp(pCpnt->getId(), "OkButton") == 0)
    {
        // Update avatar progression
        assert(m_pCurrentAvatar != NULL);
        if (m_pSelectedElement != NULL)
        {
            int iTree = -1;
            // find selected tree
            for (int i = 0; i < NB_PROGRESSION_TREES; i++)
            {
                if (strcmp(m_pSelectedElement->m_pTree->m_sObjectId, m_pCurrentAvatar->m_pProgression[i].sTreeName) == 0)
                {
                    iTree = i;
                    break;
                }
            }
            assert(m_pCurrentAvatar->m_pOwner != NULL);
            m_pCurrentAvatar->m_pOwner->applyAvatarProgression(m_pCurrentAvatar, iTree, m_pSelectedElement);
            // Hide frame
            m_pLocalClient->getInterface()->setUniqueDialog(m_pCaller);
            return false;
        }
        else
        {
            // Should be opening a tree
            guiComboBox * pBox = (guiComboBox*) getComponent("OpenTreeCombo");
            assert(pBox != NULL);
            guiButton * pBtn = pBox->getSelectedItem();
            assert(pBtn != NULL);
            assert(m_pCurrentAvatar->m_pOwner != NULL);
            m_pCurrentAvatar->m_pOwner->openAvatarProgressionTree(m_pCurrentAvatar, (u8)m_iSpecialLevel, (ProgressionTree*) pBtn->getAttachment());
            // Hide frame
            m_pLocalClient->getInterface()->setUniqueDialog(m_pCaller);
            return false;
        }
    }
    else if (strcmp(pCpnt->getId(), "DoItLaterButton") == 0)
    {
        // Hide frame
        m_pLocalClient->getInterface()->setUniqueDialog(m_pCaller);
        return false;
    }
    else if (strcmp(pCpnt->getId(), "OpenTreeButton") == 0)
    {
        getComponent("OkButton")->setEnabled(true);
    }
    else if (strcmp(pCpnt->getId(), "ChoiceButton") == 0)
    {
        if (((guiToggleButton*)pCpnt)->getClickState())
        {
            m_pSelectedElement = (ProgressionElement*) pCpnt->getAttachment();
            assert(m_pSelectedElement != NULL);
            getComponent("OkButton")->setEnabled(true);
            guiComponent * pCpnt2 = getFirstComponent();
            while (pCpnt2 != NULL)
            {
                if (strcmp(pCpnt2->getId(), "ChoiceButton") == 0 && pCpnt2 != pCpnt && pCpnt2->isEnabled())
                    ((guiToggleButton*)pCpnt2)->setClickState(false);
                pCpnt2 = getNextComponent();
            }
        }
        else
        {
            m_pSelectedElement = NULL;
            getComponent("OkButton")->setEnabled(false);
        }
    }
    return true;
}
Example #3
0
/* lookups of dots are passed down */
static int 
do_namei(struct file *cwd, 
	 const char *path, struct file *result_filp, char *result_name,
	 int *followlinks, int followlastlink)
{
    int error;
    char next[NAME_MAX +1];
    struct file old_space, new_space,tmp_traversal_space;
    struct file *old_filp = &old_space;
    struct file *new_filp = &new_space;
    struct file *tmp_traversal_filp = &tmp_traversal_space;
    struct file *tmp_swap_filp;
    struct shortfile release = {0,0};

    old_filp->flock_state = FLOCK_STATE_UNLOCKED;
    new_filp->flock_state = FLOCK_STATE_UNLOCKED;
    tmp_traversal_filp->flock_state = FLOCK_STATE_UNLOCKED;

    DPRINTF(SYSHELP_LEVEL,("do_namei: path: %s fl: %d fll: %d\n",path,*followlinks,followlastlink));

    nprintf("do_namei: path: \"%s\" fl: %d fll: %d\n",
	    path,*followlinks,followlastlink);

    /* If we have followed too many symlinks, error ELOOP */
    if (*followlinks > LINK_MAX) {
      errno = ELOOP;
      return -1;
    }

    ASSERTOP(cwd,lookup, directory with no lookup);

    *old_filp = *cwd;
    COUNT_COPY;
    ACQUIRE(old_filp);

    /* old_filp contains the directory we start at, and
     * new_filp will contain the name we just traversed.
     * when we return to top of loop, we copy new_filp into old_filp 
     * when we exit the loop, the resulting filp will be in new_filp */
    
    while(*path) {
      nprintf("path before : \"%s\" \n",path); 
      path = getNextComponent(path,next);

      nprintf("NEXT: \"%s\" path[0]: %d \n",next,*path);
      /* printf("path: \"%20s\"     next: \"%s\"\n",path,next); */
      
      if (EQDOTDOT(next)) {
	/* check traversal of /.. */
	if (FILPEQ(old_filp,__current->root)) {
	  next[1] = (char)0;	/* make it . */
	} 
	else 
	/* check traversal of /mnt/.. takes you back to / */
	  if (mounttraversalb(old_filp,&tmp_traversal_filp) == 0) {
	    RELEASE(old_filp);
	    COUNT_COPY;
	    *old_filp = *tmp_traversal_filp;
	    ACQUIRE(old_filp);
	    PRSHORTFILP("NEW POINT",old_filp,"\n");
	    /* fall through, old_filp points to /mnt, and next is ..
	     * so the later operations will handle the lookup of .. */
	  }
      }

      if (EQDOT(next)) {
	nprintf("in namei shortcircuiting . path: \"%s\"\n",path);
      	tmp_swap_filp = old_filp;
	old_filp = new_filp;
	new_filp = tmp_swap_filp;
	goto check_forward_mount;
      }

      if (!(S_ISDIR(old_filp->f_mode))) {
	nprintf("old_filp: ENOTDIR\n");
	errno = ENOTDIR;
	RELEASE(old_filp);
	return -1;
      }

      ASSERTOP(old_filp,lookup,no lookup operation in traversal of a path);
      
#ifdef CACHEDLOOKUP
      error = namei_lookup(old_filp, next, new_filp);
#else
      /* Do the actual lookup */
      nprintf("#OLD0: %s %d %08x\n",next,old_filp->f_ino, old_filp->f_mode);
      error = DOOP(old_filp,lookup,(old_filp,next,new_filp));
      nprintf("#OLD1: %s %d %08x\n",next,old_filp->f_ino, old_filp->f_mode);
#endif /* namei_lookup */

      if (error) {
	RELEASE(old_filp);
	nprintf("LOOKUP old_filp %s failed errno: %s\n",next,strerror(errno));
	return -1;
      }

      PRSHORTFILP("LOOKUP     ",old_filp," ");
      nprintf("#NAME: %p %s %d %08x\n",new_filp,next,new_filp->f_ino, new_filp->f_mode);
      nprintf("#OLD2: %p %s %d %08x\n",old_filp,next,old_filp->f_ino, old_filp->f_mode);
      PRSHORTFILP("  RETURNED:",new_filp,"\n");

      /* here you want to check if new_filp is a symbolic link, it is
	 you want to call readlink, then return namei on the new path we
	 got from readlink.  followlink will be an integer denoting how
	 many links we have followed. if 0 means we dont follow links. */
      
      if (S_ISLNK(new_filp->f_mode)) {
	char linkpath[PATH_MAX + 1];
	struct file *link_filp;
	nprintf("%d) SYMLINK new_filp %d is symlink remaining path: \"%s\" fll %d\n",
	       *followlinks,new_filp->f_ino,path,followlastlink);
	/* if this is the last path element, and we dont followlastlink */
	if (*path == 0 && followlastlink == 0) {
	  RELEASE(old_filp);
	  break;
	}

	ASSERTOP(new_filp,readlink,no readlink on a symlink filp);
	
	nprintf("3#NAME: %p %s %d %08x\n",new_filp,next,new_filp->f_ino, new_filp->f_mode);
	if ((error = DOOP(new_filp,readlink,(new_filp,linkpath,PATH_MAX))) == -1) {
	  RELEASE(old_filp);
	  RELEASE(new_filp);
	  return -1;
	}
	if (error >= 0) linkpath[error] = 0;

	nprintf("5#NAME: %p %s %d %08x\n",new_filp,next,new_filp->f_ino, new_filp->f_mode);
	RELEASE(new_filp);
	nprintf("6#NAME: %p %s %d %08x\n",new_filp,next,new_filp->f_ino, new_filp->f_mode);

	nprintf("%d) following symlink path: %s\n",*followlinks,linkpath);

	/* since new_filp is a symlink it could only have come from
	   a lookup */
	(*followlinks)++;

	if (linkpath[0] == '/') link_filp = (__current->root); 
	else link_filp = old_filp;


	error = do_namei(link_filp,
			 linkpath,
			 new_filp, 
			 result_name,
			 followlinks,
			 followlastlink);
	
	RELEASE(old_filp);

	nprintf("%d) error: %d PATH LEFT: %s, from %d, %x\n",
		*followlinks,error,path,new_filp->f_ino, new_filp->f_mode);
	if (error) {
	  nprintf("DO_NAMEI failed errno: %s\n",strerror(errno));
	  return -1;
	}


	goto next;
	//return error;
      } 

      RELEASE(old_filp);
    check_forward_mount:
      if (mounttraversalf(new_filp,&tmp_traversal_filp) == 0) {
	nprintf("traversing mount point ->, remaining: \"%s\"\n",path);
	RELEASE(new_filp);
	COUNT_COPY;
	*new_filp = *tmp_traversal_filp;
	ACQUIRE(new_filp);
#ifdef NAMEIDEBUG
	PRSHORTFILP("NEW POINT",new_filp,"\n");
#endif
	next[0] = '.'; next[1] = 0;
      }
    next:
      if (*path) {
	/* efficient way of doing: *old_filp = *new_filp, */
	tmp_swap_filp = old_filp;
	old_filp = new_filp;
	new_filp = tmp_swap_filp;
      }
    }
    
#ifdef NAMEIDEBUG
    nprintf("#LAST NAME: %s %d %08x\n",next,new_filp->f_ino, new_filp->f_mode);
#endif
    COUNT_COPY;
    *result_filp = *new_filp;
    if (result_name) {
      strcpy(result_name,next);
    }
    return 0;
}