Example #1
0
EXPORT int MM_help(int action, Imodman *mm, Arena *arena)
{
	if (action == MM_LOAD)
	{
		chat = mm->GetInterface(I_CHAT, ALLARENAS);
		cmdman = mm->GetInterface(I_CMDMAN, ALLARENAS);
		cfghelp = mm->GetInterface(I_CFGHELP, ALLARENAS);
		cfg = mm->GetInterface(I_CONFIG, ALLARENAS);
		if (!chat || !cmdman)
			return MM_FAIL;

		if (cfg)
			command_name = astrdup(cfg->GetStr(GLOBAL, "Help", "CommandName"));
		if (!command_name)
			command_name = astrdup("help");

		cmdman->AddCommand(command_name, Chelp, ALLARENAS, help_help);
		return MM_OK;
	}
	else if (action == MM_UNLOAD)
	{
		cmdman->RemoveCommand(command_name, Chelp, ALLARENAS);
		mm->ReleaseInterface(chat);
		mm->ReleaseInterface(cmdman);
		mm->ReleaseInterface(cfg);
		mm->ReleaseInterface(cfghelp);
		afree(command_name);
		return MM_OK;
	}
	return MM_FAIL;
}
Example #2
0
int
tld_indexer(const void *vp)
{
    const dns_message *m = vp;
    const char *tld;
    tldobj *obj;
    if (m->malformed)
	return -1;
    tld = dns_message_tld((dns_message *) m);
    if (NULL == theHash) {
	theHash = hash_create(MAX_ARRAY_SZ, tld_hashfunc, tld_cmpfunc,
	    1, afree, afree);
	if (NULL == theHash)
	    return -1;
    }
    if ((obj = hash_find(tld, theHash)))
	return obj->index;
    obj = acalloc(1, sizeof(*obj));
    if (NULL == obj)
	return -1;
    obj->tld = astrdup(tld);
    if (NULL == obj->tld) {
	afree(obj);
	return -1;
    }
    obj->index = next_idx;
    if (0 != hash_add(obj->tld, obj, theHash)) {
	afree(obj->tld);
	afree(obj);
	return -1;
    }
    next_idx++;
    return obj->index;
}
Example #3
0
int
qname_indexer(const void *vp)
{
    qnameobj *obj;
    const dns_message *m = vp;
    if (m->malformed)
	return -1;
    if (NULL == theHash) {
        theHash = hash_create(MAX_ARRAY_SZ, qname_hashfunc, qname_cmpfunc,
	    1, afree, afree);
	if (NULL == theHash)
	    return -1;
    }
    if ((obj = hash_find(m->qname, theHash)))
        return obj->index;
    obj = acalloc(1, sizeof(*obj));
    if (NULL == obj)
	return -1;
    obj->qname = astrdup(m->qname);
    if (NULL == obj->qname) {
	afree(obj);
	return -1;
    }
    obj->index = next_idx;
    if (0 != hash_add(obj->qname, obj, theHash)) {
	afree(obj->qname);
	afree(obj);
	return -1;
    }
    next_idx++;
    return obj->index;

}
Example #4
0
File: module.c Project: mpu/dkparse
/* mqual - Qualify a variable name. It returns a pointer on
 * an atom containing the qualified name.
 */
char *
mqual(char *x)
{
    *id='.';
    if (!copyto(id+1, x, x+strlen(x)+1))
        exit(1); // FIXME
    return astrdup(qid, id-qid+1);
}
Example #5
0
/* starts timer to handle periodmessages */
local void aaction(Arena *arena, int action)
{
	if (action == AA_DESTROY || action == AA_CONFCHANGED)
	{
		ml->CleanupTimer(msg_timer, arena, msg_cleanup);
	}

	if (action == AA_CREATE || action == AA_CONFCHANGED)
	{
		int i, c = 0;
		periodic_msgs *pm;

		pm = amalloc(sizeof(*pm));
		pm->count = 0;
		pm->arena = arena;

		for (i = 0; i < MAXMSGS; i++)
		{
			char key[32];
			const char *v;

			pm->msgs[i].msg = NULL;
			pm->msgs[i].interval = 0;

			snprintf(key, sizeof(key), "PeriodicMessage%d", i);

			v = cfg->GetStr(arena->cfg, "Misc", key);

			if (v)
			{
				char *next;
				int interval = strtol(v, &next, 0);
				if (next)
				{
					int initialdelay = strtol(next, &next, 0);
					if (next)
					{
						/* skip spaces */
						while (*next && isspace(*next)) next++;
						if (*next)
						{
							pm->msgs[i].initialdelay = initialdelay;
							pm->msgs[i].interval = interval;
							pm->msgs[i].msg = astrdup(next);
							c++;
						}
					}
				}
			}
		}

		if (c)
			ml->SetTimer(msg_timer, 6000, 6000, pm, arena);
		else
			afree(pm);
	}
}
Example #6
0
local void player_action(Player *p, int action, Arena *arena)
{
	PData *pdata = PPDATA(p, pdata_key);

	if (action == PA_CONNECT)
	{
		FormulaVariable *var = amalloc(sizeof(FormulaVariable));
		var->name = astrdup("me");
		var->type = VAR_TYPE_PLAYER;
		var->p = p;
		pdata->vars = HashAlloc();
		HashAdd(pdata->vars, var->name, var);
	}
	else if (action == PA_DISCONNECT)
	{
		HashEnum(pdata->vars, var_free_enum, NULL);
		HashFree(pdata->vars);
	}
}