Esempio n. 1
0
int GeUser::remove_system( char *name)
{
  int sts;
  SystemList *sl_p, *prev;

  SystemName *sn = new SystemName( name);
  sts = sn->parse();
  if ( EVEN(sts))
  {
    delete sn;
    return sts;
  }

  SystemList *sl = find_system( sn);
  if ( !sl) {
    delete sn;
    return USER__NOSUCHSYSTEM;
  }
  if ( sl->childlist || sl->userlist) {
    delete sn;
    return USER__SYSTEMNOTEMPTY;
  }

  SystemName *parent = sn->parent();
  if ( !parent)
  {
    for ( sl_p = root; sl_p; sl_p = sl_p->next)
    {
      if ( sl_p == sl)
      {
        if ( sl == root)
          root = sl->next;
        else
          prev->next = sl->next;
        delete sl;
        delete sn;
        return USER__SUCCESS;
      }
      prev = sl_p;
    }
  }
  else
  {
    parent->parse();
    SystemList *parent_system = find_system( parent);
    if ( !parent_system) return USER__NOSUCHSYSTEM;

    sts =  parent_system->remove_system( sl);
    delete sn;
    delete parent;
    return sts;
  }
  return USER__NOSUCHSYSTEM;
}
Esempio n. 2
0
int GeUser::add_system(
    char* name, pwr_tMask attributes, char* description, pwr_tOix id)
{
  int sts;

  SystemName* sn = new SystemName(name);
  sts = sn->parse();
  if (EVEN(sts)) {
    delete sn;
    return sts;
  }

  if (id == user_cNId)
    id = get_next_id();
  else if (id >= next_id)
    next_id = id + 1;

  SystemList* sl = find_system(sn);
  if (sl)
    return USER__SYSTEMALREXIST;

  SystemName* parent = sn->parent();
  if (!parent) {
    SystemList* sl;

    SystemList* system_list
        = new SystemList(id, name, 0, attributes, description);
    // Insert as last sibling to root
    if (!root)
      root = system_list;
    else {
      for (sl = root; sl->next; sl = sl->next)
        ;
      sl->next = system_list;
    }
  } else {
    parent->parse();
    SystemList* sl = find_system(parent);
    if (!sl) {
      delete sn;
      delete parent;
      return USER__NOSUCHSYSTEM;
    }
    sl->add_system(id, sn, attributes, description);
    delete parent;
  }
  delete sn;
  return USER__SUCCESS;
}