Esempio n. 1
0
static package
bf_add_verb(Var arglist, Byte next, void *vdata, Objid progr)
{				/* (object, info, args) */
    Objid oid = arglist.v.list[1].v.obj;
    Var info = arglist.v.list[2];
    Var args = arglist.v.list[3];
    Objid owner;
    unsigned flags;
    const char *names;
    db_arg_spec dobj, iobj;
    db_prep_spec prep;
    enum error e;

    if ((e = validate_verb_info(info, &owner, &flags, &names)) != E_NONE);	/* Already failed */
    else if ((e = validate_verb_args(args, &dobj, &prep, &iobj)) != E_NONE)
	free_str(names);
    else if (!valid(oid)) {
	free_str(names);
	e = E_INVARG;
    } else if (!db_object_allows(oid, progr, FLAG_WRITE)
	       || (progr != owner && !is_wizard(progr))) {
	free_str(names);
	e = E_PERM;
    } else
	db_add_verb(oid, names, owner, flags, dobj, prep, iobj);

    free_var(arglist);
    if (e == E_NONE)
	return no_var_pack();
    else
	return make_error_pack(e);
}
Esempio n. 2
0
void
db_shutdown()
{
    dump_database(DUMP_SHUTDOWN);

    free_str(input_db_name);
    free_str(dump_db_name);
}
Esempio n. 3
0
static void assert_tree_print(struct string *expected, struct tree_node *root)
{
	struct string *str = alloc_str();

	tree_print(root, str);
	assert_str_equals(expected->value, str->value);

	free_str(str);
	free_str(expected);
}
Esempio n. 4
0
void destroy_player(Player *p)
{
    free_str(p->title);
    free_str(p->prompt);
    free_str(p->battlePrompt);
    destroy_flags(p->explored);
    destroy_flags(p->channels);
    free_mem(p);

}
Esempio n. 5
0
void
db_destroy_object(Objid oid)
{
    Object *o = dbpriv_find_object(oid);
    Verbdef *v, *w;
    int i;

    db_priv_affected_callable_verb_lookup();

    if (!o)
	panic("DB_DESTROY_OBJECT: Invalid object!");

    if (o->location != NOTHING || o->contents != NOTHING
	|| o->parent != NOTHING || o->child != NOTHING)
	panic("DB_DESTROY_OBJECT: Not a barren orphan!");

    if (is_user(oid)) {
	Var t;

	t.type = TYPE_OBJ;
	t.v.obj = oid;
	all_users = setremove(all_users, t);
    }
    free_str(o->name);

    for (i = 0; i < o->propdefs.cur_length; i++) {
	/* As an orphan, the only properties on this object are the ones
	 * defined on it directly, so these two arrays must be the same length.
	 */
	free_str(o->propdefs.l[i].name);
	free_var(o->propval[i].var);
    }
    if (o->propval)
	myfree(o->propval, M_PVAL);
    if (o->propdefs.l)
	myfree(o->propdefs.l, M_PROPDEF);

    for (v = o->verbdefs; v; v = w) {
	if (v->program)
	    free_program(v->program);
	free_str(v->name);
	w = v->next;
	myfree(v, M_VERBDEF);
    }

    myfree(objects[oid], M_OBJECT);
    objects[oid] = 0;
}
Esempio n. 6
0
/*
 * Append some optional data to the current request, and store its
 * length into the 16-bit field (network byte order) referenced by
 * "fld".  Returns 0 on success, or -1 on failure.
 *
 * This function also frees the "cs" string data and initializes it
 * for the next time.
 */
static int
add_str_16(struct tac_handle *h, u_int16_t *fld, struct clnt_str *cs)
{
	size_t len;

	len = cs->len;
	if (cs->data == NULL)
		len = 0;
	if (len != 0) {
		int offset;

		if (len > 0xffff) {
			generr(h, "Field too long");
			return -1;
		}
		offset = ntohl(h->request.length);
		if (offset + len > BODYSIZE) {
			generr(h, "Message too long");
			return -1;
		}
		memcpy(h->request.u.body + offset, cs->data, len);
		h->request.length = htonl(offset + len);
	}
	*fld = htons(len);
	free_str(cs);
	return 0;
}
Esempio n. 7
0
void node_destroy( mxml_node * n )
{
	if ( n != NULL )
	{
		mxml_node * temp = NULL;
		mxml_node * child = n->first_child;

		while ( child )
		{
			temp = child->next;
			node_destroy( child );
			child = temp;
		}

		if ( n->extend != NULL && n->type != type_node )
		{
			switch( n->type )
			{
			case type_element		: destroy_element	 ( (mxml_element *)n->extend ); break;
			case type_attribute		: destroy_attribute	 ( (mxml_attribute *)n->extend ); break;
			case type_declaration	: destroy_declaration( (mxml_declaration *)n->extend ); break;
			case type_document		: destroy_document	 ( (mxml_document *)n->extend ); break;
			}
		}
		free_str( &n->value );
		free( n );
	}
}
Esempio n. 8
0
void
free_program(Program * p)
{
    unsigned i;

    p->ref_count--;
    if (p->ref_count == 0) {

	for (i = 0; i < p->num_literals; i++)
	    /* can't be a list--strings and floats need to be freed, though. */
	    free_var(p->literals[i]);
	if (p->literals)
	    myfree(p->literals, M_LIT_LIST);

	for (i = 0; i < p->fork_vectors_size; i++)
	    myfree(p->fork_vectors[i].vector, M_BYTECODES);
	if (p->fork_vectors_size)
	    myfree(p->fork_vectors, M_FORK_VECTORS);

	for (i = 0; i < p->num_var_names; i++)
	    free_str(p->var_names[i]);
	myfree(p->var_names, M_NAMES);

	myfree(p->main_vector.vector, M_BYTECODES);

	myfree(p, M_PROGRAM);
    }
}
Esempio n. 9
0
void free_nls(void)
{
	struct nls *t;
	dolist (t, pNLS) free_str(&t->translation);
	freeall(&pNLS);
	nls_loaded = false;
}
Esempio n. 10
0
char			*ft_strjoin_free(char *s1, char *s2, int free_token)
{
	size_t	i;
	size_t	j;
	char	*str;

	i = 0;
	j = 0;
	if ((str = ft_memalloc(ft_strlen(s1) + ft_strlen(s2) + 1)) == NULL)
		return (NULL);
	while (s1[i])
	{
		str[i] = s1[i];
		i++;
	}
	while (s2[j])
	{
		str[i] = s2[j];
		i++;
		j++;
	}
	str[i] = '\0';
	free_str(&s1, &s2, free_token);
	return (str);
}
Esempio n. 11
0
SpecialFolder::~SpecialFolder()
{
	// delete_the pidl-list and it's contents
	delete_pidl_list(&m_pidl_list);
	free_str(&m_pszExtra);
	// note: the drop-target is unregistered in the 'Menu' destructor
}
Esempio n. 12
0
/**
    FISSO = ([^/%] | "%%")+
*/
int fisso(const char* schema, int offset, dynamic_str_t* fissi) {
    dynamic_str_t componenti_fisso;
    if (fissi)
        init_str(&componenti_fisso);
    if (!schema[offset] || schema[offset] == '/' ||
            (schema[offset] == '%' && schema[offset+1] != '%'))
        return -1;  // deve avere lunghezza > 0!
    int bkp = offset;
    for (; schema[offset] && schema[offset] != '/'; offset++) {
        if (schema[offset] == '%') {
            if (schema[offset+1] == '%') {
                if (fissi) {
                    char tmp[offset-bkp+1];
                    tmp[0] = tmp[offset-bkp] = '\0';
                    strncpy(tmp, schema+bkp, offset-bkp);
                    append_str(&componenti_fisso, tmp);
                }
                bkp = ++offset + 1;
            }
            else    // dev'essere una keyword -> mi fermo
                break;
        }
    }
    if (fissi) {
        char tmp[offset-bkp+1];
        tmp[0] = tmp[offset-bkp] = '\0';
        strncpy(tmp, schema+bkp, offset-bkp);
        append_str(&componenti_fisso, tmp);
        append_str(fissi, join(componenti_fisso, '%'));
        free_str(&componenti_fisso);
    }
    return offset;
}
Esempio n. 13
0
void parse_query_string_len(nvlist_t *vars, const char *qs, size_t len)
{
	struct qstr *name, *val;
	const char *cur, *end;
	int state;

	if (!qs || !len)
		return;

	name = alloc_str(VAR_NAME_MAXLEN);
	val  = alloc_str(64 * 1024);

	ASSERT(name);
	ASSERT(val);

	state = QS_STATE_NAME;

	end = qs + len;
	cur = qs;

	for (; end > cur; cur++) {
		char c = *cur;

		if (state == QS_STATE_NAME) {
			if (c == '=')
				state = QS_STATE_VAL;
			else
				ASSERT0(append_char_str(name, c));
		} else if (state == QS_STATE_VAL) {
			if (c == '&') {
				insert(vars, name, val);

				state = QS_STATE_NAME;
				reset_str(name);
				reset_str(val);
			} else {
				ASSERT0(append_char_str(val, c));
			}
		}
	}

	if (state == QS_STATE_VAL)
		insert(vars, name, val);

	free_str(name);
	free_str(val);
}
Esempio n. 14
0
void str_test()
{
	my_str *strp = alloc_str(test, strlen(test));

	printf("content: %s, len: %d\n", STR_CONTENT(strp), STR_LENGTH(strp) + 1);

	free_str(strp);
}
Esempio n. 15
0
//================================================
void SpecialFolder::UpdateFolder(void)
{
	// ---------------------------------------
	// remember the active item as text

	MenuItem *ActiveItem = m_pActiveItem;
	TCHAR *active_item_text = NULL;

	m_pLastChild = m_pChild;
	if (m_pLastChild) ActiveItem = m_pLastChild->m_pParentItem;
	if (ActiveItem) active_item_text = new_str(ActiveItem->m_pszTitle);

	// delete_old items
	DeleteMenuItems();

	// load the folder contents
	MenuItem *Items = NULL; int r = 0;

	struct pidl_node *p;
	dolist (p, m_pidl_list)
		r |= MenuMaker_LoadFolder(&Items, p->v, m_pszExtra);

	if (Items) add_folder_contents(Items, NULL != m_pidl_list->next);
	else if (r) MakeMenuNOP(this, NLS0(_T("No Files")));
	else MakeMenuNOP(this, NLS0(_T("Invalid Path")));

	// ---------------------------------------
	// search by text the previously active item

	if (active_item_text)
	{
		dolist (ActiveItem, m_pMenuItems)
			if (0 == _tcscmp(active_item_text, ActiveItem->m_pszTitle))
				break;

		free_str(&active_item_text);
	}

	// ---------------------------------------
	// possibly reconnect to an open child-folder

	if (m_pLastChild)
	{
		if (ActiveItem)
		{
			m_pLastChild->incref();
			ActiveItem->LinkSubmenu(m_pLastChild);
			m_pLastChild->LinkToParentItem(ActiveItem);
		}
		else
		{
			m_pLastChild->Hide(); // lost child
		}
		m_pLastChild = NULL;
	}

	if (ActiveItem) ActiveItem->Active(2);
}
Esempio n. 16
0
/**
    rimuove ogni file descriptor watched da un'instanza di inotify

    Da notare come files e watch_fds devono essere della stessa lunghezza!
    \param inotify istanza di inotify_t a cui rimuovere tutti i file descriptors
*/
void rm_all_watches(inotify_t inotify) {
    for (int i=0; i<inotify.watch_fds.size; i++)
        if (inotify_rm_watch(inotify.instance, inotify.watch_fds.buf[i])==-1) {
            perror("inotify_rm_watch");
            exit(EXIT_FAILURE);
        }
    free_int(&inotify.watch_fds);
    free_str(&inotify.files);
}
Esempio n. 17
0
MenuItem::~MenuItem()
{
    UnlinkSubmenu();
    if (m_pRightmenu)
        m_pRightmenu->decref();
    free_str(&m_pszTitle);
    free_str(&m_pszCommand);
    free_str(&m_pszRightCommand);
    delete_pidl_list(&m_pidl_list);

//#ifdef BBOPT_MENUICONS
    free_str(&m_pszIcon);
    if (m_hIcon)
        DestroyIcon(m_hIcon);
//#endif

    --g_menu_item_count;
}
Esempio n. 18
0
void
db_set_object_name(Objid oid, const char *name)
{
    Object *o = objects[oid];

    if (o->name)
	free_str(o->name);
    o->name = name;
}
Esempio n. 19
0
File: peg.c Progetto: ctelfer/catlib
static void peg_node_free(struct peg_grammar *peg, int nn)
{
	struct peg_node *pn;

	if ( nn < 0 || nn >= peg->max_nodes )
		return;

	pn = NODE(peg, nn);
	switch ( pn->pn_type ) {
	case PEG_DEFINITION:
		peg_node_free(peg, pn->pd_id);
		peg_node_free(peg, pn->pd_expr);
		break;
	case PEG_SEQUENCE:
		peg_node_free(peg, pn->ps_pri);
		peg_node_free(peg, pn->pn_next);
		break;
	case PEG_PRIMARY:
		peg_node_free(peg, pn->pp_match);
		peg_node_free(peg, pn->pn_next);
		if ( pn->pp_action != PEG_ACT_NONE )
			free_str(&pn->pp_label);
		break;
	case PEG_IDENTIFIER:
		--pn->pi_refcnt;
		if ( pn->pi_refcnt > 0 )
			return;
		free_str(&pn->pi_name);
		break;
	case PEG_LITERAL:
		free_str(&pn->pl_value);
		break;
	case PEG_CLASS:
		free_str(&pn->pc_cset_raw);
		break;
	default:
		return;
	}

	abort_unless(peg->num_nodes > 0);
	--peg->num_nodes;
	pn->pn_type = PEG_NONE;
}
Esempio n. 20
0
static void
close_nlistener(nlistener * l)
{
    *(l->prev) = l->next;
    if (l->next)
	l->next->prev = l->prev;
    proto_close_listener(l->fd);
    free_str(l->name);
    myfree(l, M_NETWORK);
}
Esempio n. 21
0
void destroy_char(Character *ch)
{
    free_str(ch->name);
    destroy_flags(ch->flags);
    destroy_flags(ch->affectedBy);
    free_str(ch->description);
    free_mem(ch->classes);

    if (ch->pc != 0)
    {
        destroy_player(ch->pc);
    }

    if (ch->npc != 0)
    {
        destroy_npc(ch->npc);
    }
    free_mem(ch);
}
Esempio n. 22
0
void replace_attr_string(

  pbs_attribute *attr,
  char          *newval)

  {
  free_str(attr);

  attr->at_val.at_str = newval;
  attr->at_flags |= ATR_VFLAG_SET;

  return;
  }  /* END replace_job_attr_string() */
Esempio n. 23
0
static package
bf_set_verb_info(Var arglist, Byte next, void *vdata, Objid progr)
{				/* (object, verb-desc, {owner, flags, names}) */
    Objid oid = arglist.v.list[1].v.obj;
    Var desc = arglist.v.list[2];
    Var info = arglist.v.list[3];
    Objid new_owner;
    unsigned new_flags;
    const char *new_names;
    enum error e;
    db_verb_handle h;

    if ((e = validate_verb_descriptor(desc)) != E_NONE);	/* Do nothing; e is already set. */
    else if (!valid(oid))
	e = E_INVARG;
    else
	e = validate_verb_info(info, &new_owner, &new_flags, &new_names);

    if (e != E_NONE) {
	free_var(arglist);
	return make_error_pack(e);
    }
    h = find_described_verb(oid, desc);
    free_var(arglist);

    if (!h.ptr) {
	free_str(new_names);
	return make_error_pack(E_VERBNF);
    } else if (!db_verb_allows(h, progr, VF_WRITE)
	       || (!is_wizard(progr) && db_verb_owner(h) != new_owner)) {
	free_str(new_names);
	return make_error_pack(E_PERM);
    }
    db_set_verb_owner(h, new_owner);
    db_set_verb_flags(h, new_flags);
    db_set_verb_names(h, new_names);

    return no_var_pack();
}
Esempio n. 24
0
static int
save_str(struct tac_handle *h, struct clnt_str *cs, const void *data,
    size_t len)
{
	free_str(cs);
	if (data != NULL && len != 0) {
		if ((cs->data = xmalloc(h, len)) == NULL)
			return -1;
		cs->len = len;
		memcpy(cs->data, data, len);
	}
	return 0;
}
Esempio n. 25
0
void show_function(void *addr)
{
	struct string *str;

	str = alloc_str();

	if (show_exe_function(addr, str)) {
		trace_printf("%s", str->value);
	} else {
		trace_printf("<unknown>\n");
	}

	free_str(str);
}
Esempio n. 26
0
static void
close_nhandle(nhandle * h)
{
    text_block *b, *bb;

    (void) push_output(h);
    *(h->prev) = h->next;
    if (h->next)
	h->next->prev = h->prev;
    b = h->output_head;
    while (b) {
	bb = b->next;
	free_text_block(b);
	b = bb;
    }
    free_stream(h->input);
    proto_close_connection(h->rfd, h->wfd);
    free_str(h->name);
    myfree(h, M_NETWORK);
}
Esempio n. 27
0
/* drop reference, free if none left */
void strpool_decref(struct PStr *s)
{
	struct StrPool *sp;

	if (!s)
		return;
	Assert(s->refcnt > 0);

	sp = s->pool;
	pthread_mutex_lock(&sp->mutex);
	s->refcnt--;
	if (s->refcnt > 0){
		pthread_mutex_unlock(&sp->mutex);
		return;
	}

	/* remove */

	sp->count--;
	cbtree_delete(sp->tree, s->str, s->len);
	free_str(NULL, s);
	pthread_mutex_unlock(&sp->mutex);
}
Esempio n. 28
0
void
str_intern_close(void)
{
    int i;
    struct intern_entry *e, *next;
    
    for (i = 0; i < intern_table_size; i++) {
        for (e = intern_table[i]; e; e = next) {
            next = e->next;
            
            free_str(e->s);
            
            /* myfree(e, M_INTERN_ENTRY); */
        }
    }
    
    myfree(intern_table, M_INTERN_POINTER);
    intern_table = NULL;
    
    free_intern_entry_hunks();
    
    oklog("INTERN: %d allocations saved, %d bytes\n", intern_allocations_saved, intern_bytes_saved);
    oklog("INTERN: at end, %d entries in a %d bucket hash table.\n", intern_table_count, intern_table_size);
}
Esempio n. 29
0
static void
create_msg(struct tac_handle *h, int msg_type, int var, int type)
{
	struct tac_msg *msg;
	int i;

	h->last_seq_no = 0;

	msg = &h->request;
	msg->type = msg_type;
	msg->version = protocol_version(msg_type, var, type);
	msg->flags = 0; /* encrypted packet body */

	free_str(&h->user);
	free_str(&h->port);
	free_str(&h->rem_addr);
	free_str(&h->data);
	free_str(&h->user_msg);

	for (i=0; i<MAXAVPAIRS; i++)
		free_str(&(h->avs[i]));
}
Esempio n. 30
0
void
tac_close(struct tac_handle *h)
{
	int i, srv;

	if (h->fd != -1)
		close(h->fd);
	for (srv = 0;  srv < h->num_servers;  srv++) {
		memset(h->servers[srv].secret, 0,
		    strlen(h->servers[srv].secret));
		free(h->servers[srv].secret);
	}
	free_str(&h->user);
	free_str(&h->port);
	free_str(&h->rem_addr);
	free_str(&h->data);
	free_str(&h->user_msg);
	for (i=0; i<MAXAVPAIRS; i++)
		free_str(&(h->avs[i]));

	/* Clear everything else before freeing memory */
	memset(h, 0, sizeof(struct tac_handle));
	free(h);
}