/********************************************************************
 * FUNCTION add_alias
 * 
 * Add the alias record
 *
 * INPUTS:
 *   alias == alias to add
 *
 * RETURNS:
 *   status
 *********************************************************************/
static status_t
    add_alias (alias_cb_t *alias)
{
    dlq_hdr_t  *aliasQ = get_aliasQ();
    alias_cb_t *curalias;
    int         ret;

    if (aliasQ == NULL) {
        SET_ERROR(ERR_INTERNAL_VAL);
        free_alias(alias);
        return ERR_INTERNAL_VAL;
    }

    for (curalias = (alias_cb_t *)dlq_firstEntry(aliasQ);
         curalias != NULL;
         curalias = (alias_cb_t *)dlq_nextEntry(curalias)) {

        ret = xml_strcmp(curalias->name, alias->name);
        if (ret == 0) {
            SET_ERROR(ERR_NCX_DUP_ENTRY);
            free_alias(alias);
            return ERR_NCX_DUP_ENTRY;
        } else if (ret > 0) {
            dlq_insertAhead(alias, curalias);
            return NO_ERR;
        }
    }

    /* new last entry */
    dlq_enque(alias, aliasQ);
    return NO_ERR;

}  /* add_alias */
/********************************************************************
 * FUNCTION do_unset (local RPC)
 * 
 * unset def
 *
 * Handle the unset command; remove the specified alias
 *
 * INPUTS:
 *    server_cb == server control block to use
 *    rpc == RPC method for the unset command
 *    line == CLI input in progress
 *    len == offset into line buffer to start parsing
 *
 * RETURNS:
 *   status
 *********************************************************************/
extern status_t
    do_unset (server_cb_t *server_cb,
              obj_template_t *rpc,
              const xmlChar *line,
              uint32  len)
{
    val_value_t        *valset, *parm;
    status_t            res = NO_ERR;

    valset = get_valset(server_cb, rpc, &line[len], &res);

    if (res == NO_ERR && valset) {
        parm = val_find_child(valset, YANGCLI_MOD, NCX_EL_NAME);
        if (parm) {
            const xmlChar *varstr = VAL_STR(parm);
            alias_cb_t *alias = find_alias(varstr, xml_strlen(varstr));
            if (alias) {
                dlq_remove(alias);
                free_alias(alias);
                log_info("\nDeleted alias '%s'\n", varstr);
            } else {
                res = ERR_NCX_INVALID_VALUE;
                log_error("\nError: unknown alias '%s'\n", varstr);
            }
        }  /* else missing parameter already reported */
    } /* else no valset already reported */

    if (valset) {
        val_free_value(valset);
    }

    return res;

}  /* do_unset */
Beispiel #3
0
void		free_alias(t_alias *alias)
{
	if (alias)
	{
		free_alias(alias->next);
		free(alias->init);
		free(alias->replace);
		free(alias);
	}
}
/********************************************************************
 * FUNCTION free_aliases
 * 
 * Free all the command aliases
 *
 *********************************************************************/
void
    free_aliases (void)
{
    dlq_hdr_t   *aliasQ = get_aliasQ();
    alias_cb_t  *alias;

    while (!dlq_empty(aliasQ)) {
        alias = (alias_cb_t *)dlq_deque(aliasQ);
        free_alias(alias);
    }

}  /* free_aliases */
Beispiel #5
0
void		free_all(t_shell *shell)
{
  free_env(shell->env);
  free(shell->tokens);
  free(shell->builtins);
  if (shell->alias != NULL)
    free_alias(shell->alias);
  if (shell->command_name != NULL)
    free(shell->command_name);
  free(shell->hist_name);
  free(shell);
}
/********************************************************************
 * FUNCTION new_alias
 * 
 * Malloc and fill in an alias record
 *
 * INPUTS:
 *   name == alias name (not z-terminated)
 *   namelen == length of name string
 *
 * RETURNS:
 *   pointer to alias record or NULL if none
 *********************************************************************/
static alias_cb_t *
    new_alias (const xmlChar *name,
               uint32 namelen)
{
    alias_cb_t  *alias;

    if (namelen == 0) {
        SET_ERROR(ERR_INTERNAL_VAL);
        return NULL;
    }

    alias = m__getObj(alias_cb_t);
    if (alias == NULL) {
        return NULL;
    }
    memset(alias, 0x0, sizeof(alias_cb_t));
    alias->name = xml_strndup(name, namelen);
    if (alias->name == NULL) {
        free_alias(alias);
        return NULL;
    }
    return alias;

}  /* new_alias */
/********************************************************************
 * FUNCTION handle_alias_parm
 * 
 * alias def
 * alias def=def-value
 *
 * Handle the alias command, based on the parameter
 *
 * INPUTS:
 *    varstr == alias command line
 *    setonly == TRUE if expecting set version only; ignore show alias
 *               FALSE if expecting show alias or set alias
 *    loginfo == TRUE if log-level=info should be used
 *               FALSE if log-level=debug2 should be used
 * RETURNS:
 *   status
 *********************************************************************/
static status_t
    handle_alias_parm (const xmlChar *varstr,
                       boolean setonly,
                       boolean loginfo)
{
    const xmlChar *valptr = NULL;    
    uint32    nlen = 0;
    status_t  res;

    res = parse_alias(varstr, &nlen, &valptr);
    if (res == NO_ERR) {
        if (valptr) {
            /* setting an alias */
            alias_cb_t *alias = find_alias(varstr, nlen);
            if (alias) {
                if (LOGDEBUG3) {
                    log_debug3("\nAbout to replace alias '%s'"
                               "\n  old value: '%s'"
                               "\n  new value: '%s'",
                               alias->name, 
                               alias->value ? alias->value : EMPTY_STRING,
                               valptr);
                }
                /* modify an existing alias */
                res = set_alias(alias, valptr);
                if (res == NO_ERR) {
                    if (loginfo) {
                        log_info("\nUpdated alias '%s'\n", alias->name);
                    } else {
                        log_debug2("\nUpdated alias '%s'", alias->name);
                    }
                } else {
                    log_error("\nError: invalid alias value '%s'\n",
                              valptr);
                }
            } else {
                /* create a new alias */
                alias = new_alias(varstr, nlen);
                if (alias == NULL) {
                    res = ERR_INTERNAL_MEM;
                } else {
                    res = set_alias(alias, valptr);
                    if (res == NO_ERR) {
                        res = add_alias(alias);
                        if (res == NO_ERR) {
                            if (loginfo) {
                                log_info("\nAdded alias '%s'\n", alias->name);
                            } else {
                                log_debug2("\nAdded alias '%s'", alias->name);
                            }
                        } else {
                            log_error("\nError: alias was not added '%s'\n",
                                      get_error_string(res));
                        }
                    } else {
                        log_error("\nError: invalid alias value '%s'\n",
                                  valptr);
                        free_alias(alias);
                    }
                }
            }
        } else if (!setonly) {
            /* just provided a name; show alias */
            show_alias_name(varstr, nlen);
        } else if (LOGDEBUG) {
            log_debug("\nSkipping alias '%s' because no value set", varstr);
        }
    } else if (res == ERR_NCX_INVALID_NAME) {
        log_error("\nError: invalid alias (%s)", get_error_string(res));
    } else {
        log_error("\nError: invalid alias '%s' (%s)", varstr,
                  get_error_string(res));
    }
    return res;

}  /* handle_alias_parm */
Beispiel #8
0
void load_text(struct char_data * ch)
{
  FILE *fil = NULL;
  char fname[MAX_INPUT_LENGTH];
  struct alias *al;
  int i, cnt;

  void free_alias(struct alias * a);

  if (IS_NPC(ch))
    return;

  if (!get_filename(GET_NAME(ch), fname, ETEXT_FILE))
    return;

  if (!(fil = fopen(fname, "r"))) {
    if (errno != ENOENT) { /* if it fails, NOT because of no file */
      sprintf(buf1, "SYSERR: READING TEXT FILE %s (5)", fname);
      perror(buf1);
      send_to_char("\r\n***** NOTICE - THERE WAS A PROBLEM READING YOUR ALIAS FILE *****\r\n", ch);
      return;
    }
    return;
  }

  while ((al = GET_ALIASES(ch)) != NULL) { /* get rid of alias multiplying problem */
    GET_ALIASES(ch) = (GET_ALIASES(ch))->next;
    free_alias(al);
  }

  cnt = 200; /* security counter to make memory alloc bombing impossible :) */
  fscanf(fil, "%d\n", &i); /* get first type */
  while (i != -1 && cnt != 0) {
    CREATE(al, struct alias, 1);
    al->type = i;
    fgets(buf, MAX_INPUT_LENGTH, fil);
    buf[strlen(buf) - 1] = '\0';
    al->alias = strdup(buf);
    fgets(buf, MAX_INPUT_LENGTH, fil);
    buf[strlen(buf) - 1] = '\0';
    al->replacement = strdup(buf);
    al->next = ch->player_specials->aliases;
    ch->player_specials->aliases = al;
    fscanf(fil, "%d\n", &i);
    cnt--;
  }
  /* aliases has been loaded */
  if (WHOSPEC(ch)) {
    FREE(WHOSPEC(ch));
  }
  if (POOFIN(ch)) {
    FREE(POOFIN(ch));
  }
  if (POOFOUT(ch)) {
    FREE(POOFOUT(ch));
  }
  if (WHOSTR(ch)) {
    FREE(WHOSTR(ch));
  }
  if (NAMECOLOR(ch)) {
    FREE(NAMECOLOR(ch));
  }

  fgets(buf, MAX_INPUT_LENGTH, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    WHOSPEC(ch) = strdup(buf);
  }
  fgets(buf, SMALL_BUFSIZE, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    POOFIN(ch) = strdup(buf);
  }
  fgets(buf, SMALL_BUFSIZE, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    POOFOUT(ch) = strdup(buf);
  }
  fgets(buf, MAX_INPUT_LENGTH, fil);
  buf[strlen(buf) - 1] = '\0';
  if (str_cmp("!UNUSED!", buf)) {
    WHOSTR(ch) = strdup(buf);
  }
  if (fgets(buf, SMALL_BUFSIZE, fil) > (char*) NULL) {
    buf[strlen(buf) - 1] = '\0';
    if (str_cmp("!UNUSED!", buf)) {
      NAMECOLOR(ch) = strdup(buf);
    }
  }

  if (cnt == 0) {
    send_to_char("Undetermined error when reading your alias file ...\r\n", ch);
    sprintf(buf, "ERROR when reading %s's alias file.", GET_NAME(ch));
    mudlog(buf, 'W', COM_IMMORT, TRUE);
    plog(buf, ch, 0);
  }
  fclose(fil);
  return;
}