Esempio n. 1
0
USERS *adduser(ape_socket *client, const char *host, const char *ip, USERS *allocated, acetables *g_ape)
{
	USERS *nuser = NULL;

	/* Calling module */
	if (allocated == NULL) {
		FIRE_EVENT(allocateuser, nuser, client, host, ip, g_ape);
		
		nuser = init_user(g_ape);
		strncpy(nuser->ip, ip, 16);
		
		nuser->pipe = init_pipe(nuser, USER_PIPE, g_ape);
		nuser->type = (client != NULL ? HUMAN : BOT);
		
		nuser->istmp = 1;
		
		hashtbl_append(g_ape->hSessid, nuser->sessid, (void *)nuser);

		addsubuser(client, host, nuser, g_ape);
	} else {
		FIRE_EVENT(adduser, nuser, allocated, g_ape);
		
		nuser = allocated;
		nuser->istmp = 0;
		
		g_ape->nConnected++;
		
		//ape_log(APE_INFO, __FILE__, __LINE__, g_ape, 
		//	"New user - (ip : %s)", nuser->ip);
	}

	return nuser;
	
}
Esempio n. 2
0
USERS *adduser(unsigned int fdclient, char *host, acetables *g_ape)
{
	USERS *nuser = NULL;

	/* Calling module */
	FIRE_EVENT(adduser, nuser, fdclient, host, g_ape);
	

	nuser = init_user(g_ape);
	
	nuser->type = (fdclient ? HUMAN : BOT);
		
	g_ape->uHead = nuser;
	
	nuser->pipe = init_pipe(nuser, USER_PIPE, g_ape);

	hashtbl_append(g_ape->hSessid, nuser->sessid, (void *)nuser);
	
	g_ape->nConnected++;
	
	addsubuser(fdclient, host, nuser, g_ape);

	return nuser;
	
}
Esempio n. 3
0
CHANNEL *mkchan(char *chan, acetables *g_ape)
{
	CHANNEL *new_chan = NULL;


	FIRE_EVENT(mkchan, new_chan, chan, g_ape);

	
	if (!isvalidchan(chan)) {
		return NULL;
	}
	
	new_chan = (CHANNEL *) xmalloc(sizeof(*new_chan));
		
	memcpy(new_chan->name, chan, strlen(chan)+1);
	
	new_chan->head = NULL;
	new_chan->banned = NULL;
	new_chan->properties = NULL;
	
	new_chan->interactive = (*new_chan->name == '*' ? 0 : 1);

	//memcpy(new_chan->topic, topic, strlen(topic)+1);

	new_chan->pipe = init_pipe(new_chan, CHANNEL_PIPE, g_ape);
	
	hashtbl_append(g_ape->hLusers, chan, (void *)new_chan);
	
	/* just to test */
	//proxy_attach(proxy_init("olol", "localhost", 1337, g_ape), new_chan->pipe->pubid, 0, g_ape);
	
	return new_chan;
	
}
Esempio n. 4
0
RTDB_API RTK_CURSOR PMC_API create_group(
	RTK_CURSOR node,
	PRTK_GROUP grp
	)
{
	RTK_CURSOR	handle;
	RTK_NODE	*nd;
	RTK_GROUP	group;
	PGROUP_KEY	gk;

	if((__uint)node == 0x12345678){
		g_dwMaxTags = (__uint)grp;
		return 0;
	}

	gk = &grp->key;
	handle = open_group(node, gk);
	if(handle){
		return handle;
	}

	nd = (RTK_NODE*)cursor_get_item(node);
	if(!nd){
		return 0;
	}

	group = *grp;
	make_unified_key(group.key);
	ZeroMemory(&group.d, sizeof(group.d)); 
	group.node = nd->key;
	group.refcount = 0;
	group.itemtable=(void *)(new TAG_TABLE);
	if(!group.itemtable){
		utils_error("-- create_group --Not enough memory.");
		return __false;
	}
	handle = (RTK_CURSOR)_HGROUP::create(
		(GROUP_TABLE*)nd->itemtable, *gk, group
		);
	if(handle){
		FIRE_EVENT(
			OnAddGroup, ((PRTK_GROUP)cursor_get_item(handle))
			);
	}
	return handle;
}
Esempio n. 5
0
RTDB_API RTK_CURSOR PMC_API create_tag(
	RTK_CURSOR group,
	PCTAG_KEY tag, 
	PCSTATIC_TAG_DATA sd
	)
{
	RTK_CURSOR	handle;
	RTK_GROUP * grp;
	RTK_TAG 	t;

	handle = open_tag_g(group, tag);
	if(handle){
		return handle;
	}

	if(g_dwTags >= g_dwMaxTags){
		rtk_set_last_error(RTDB_HARD_CONSTRAINTS);
		return 0;
	}

	grp = (RTK_GROUP*)cursor_get_item(group);
	if(!grp){
		return 0;
	}
	ZeroMemory(&t, sizeof(t));
	t.key = *tag;
	make_unified_key(t.key);
	t.s = *sd;
	t.node = grp->node;
	t.group = grp->key;
	handle = (RTK_CURSOR)_HTAG::create((TAG_TABLE*)grp->itemtable, t.key, t);
	RTK_TAG * pTag = (RTK_TAG*)cursor_get_item(handle);
	if(pTag){
		ZeroMemory(&pTag->d, sizeof(pTag->d));
		set_value_type(pTag->d.Value.Flags, get_value_type(pTag->s.Flags));
		RtkInitializeListHead(&pTag->d.DeviceLink);
		RtkInitializeListHead(&pTag->d.RefreshLink);
		FIRE_EVENT(OnAddTag, (pTag));
		g_dwTags++;
	}

	return handle;
}
Esempio n. 6
0
RTDB_API RTK_CURSOR PMC_API create_node(PCNODE_KEY key, __uint context)
{
	RTK_CURSOR	handle;
	RTK_NODE item;

	handle = open_node(key);
	if(handle){
		return handle;
	}

	ZeroMemory(&item, sizeof(item));
	item.key = *key;
	item.context = context;
	item.itemtable = new GROUP_TABLE;
	if(!item.itemtable){
		return 0;
	}
	make_unified_key(item.key); 
	handle = (RTK_CURSOR)_HNODE::create(&g_Nodes, *key, item);
	if(handle){
		FIRE_EVENT(OnAddNode, ((PRTK_NODE)cursor_get_item(handle)));
	}
	return handle;
}
Esempio n. 7
0
subuser *addsubuser(ape_socket *client, const char *channel, USERS *user, acetables *g_ape)
{
	subuser *sub = NULL;

	FIRE_EVENT(addsubuser, sub, g_ape);
	
	if (getsubuser(user, channel) != NULL || strlen(channel) > MAX_HOST_LENGTH) {
		return NULL;
	}

	sub = xmalloc(sizeof(*sub));
	sub->client = client;
	sub->state = ADIED;
	sub->user = user;
	
	memcpy(sub->channel, channel, strlen(channel)+1);
	sub->next = user->subuser;
	
	sub->nraw = 0;
	sub->wait_for_free = 0;
	
	sub->properties = NULL;
	
	sub->headers.sent = 0;
	sub->headers.content = NULL;
	
	sub->burn_after_writing = 0;
	
	sub->idle = time(NULL);
	sub->need_update = 0;
	sub->current_chl = 0;

	sub->raw_pools.nraw = 0;
	
	/* Pre-allocate a pool of raw to reduce the number of malloc calls */
	
	/* Low priority raws */
	sub->raw_pools.low.nraw = 0;
	sub->raw_pools.low.size = 32;
	sub->raw_pools.low.rawhead = init_raw_pool(sub->raw_pools.low.size);
	sub->raw_pools.low.rawfoot = sub->raw_pools.low.rawhead;
	
	/* High priority raws */
	sub->raw_pools.high.nraw = 0;
	sub->raw_pools.high.size = 8;
	sub->raw_pools.high.rawhead = init_raw_pool(sub->raw_pools.high.size);
	sub->raw_pools.high.rawfoot = sub->raw_pools.high.rawhead;
	
	(user->nsub)++;
	
	user->subuser = sub;
	
	/* if the previous subuser have some messages in queue, copy them to the new subuser */
	if (sub->next != NULL && sub->next->raw_pools.low.nraw) {
		struct _raw_pool *rTmp;
		for (rTmp = sub->next->raw_pools.low.rawhead; rTmp->raw != NULL; rTmp = rTmp->next) {
			post_raw_sub(rTmp->raw, sub, g_ape);
		}

	}
	
	HOOK_EVENT(addsubuser, sub, g_ape);
	
	return sub;
}