コード例 #1
0
ファイル: pork_aim_proto.c プロジェクト: echoline/powk
int check_if_aq(char *sn, struct chatroom *ccon) {
	struct aim_chat *a_chat = ccon->data;
	char buf[MAXSNLEN+1024];

	normalize(buf, sn, strlen(sn) + 1);
	if (dlist_find(a_chat->abqueue, buf, (void*)strcmp))
		return 1;
	return 0;
}
コード例 #2
0
ファイル: dlist.c プロジェクト: ningyuwhut/SysProPlan
static void test_int_dlist(void)
{
	int i = 0;
	int n = 100;
	int data = 0;
	DList* dlist = dlist_create(NULL, NULL, NULL);

	for(i = 0; i < n; i++)
	{
		assert(dlist_append(dlist, (void*)i) == RET_OK);
		assert(dlist_length(dlist) == (i + 1));
		assert(dlist_get_by_index(dlist, i, (void**)&data) == RET_OK);
		assert(data == i);
		assert(dlist_set_by_index(dlist, i, (void*)(2*i)) == RET_OK);
		assert(dlist_get_by_index(dlist, i, (void**)&data) == RET_OK);
		assert(data == 2*i);
		assert(dlist_set_by_index(dlist, i, (void*)i) == RET_OK);
		assert(dlist_find(dlist, cmp_int, (void*)i) == i);
	}

	for(i = 0; i < n; i++)
	{
		assert(dlist_get_by_index(dlist, 0, (void**)&data) == RET_OK);
		assert(data == (i));
		assert(dlist_length(dlist) == (n-i));
		assert(dlist_delete(dlist, 0) == RET_OK);
		assert(dlist_length(dlist) == (n-i-1));
		if((i + 1) < n)
		{
			assert(dlist_get_by_index(dlist, 0, (void**)&data) == RET_OK);
			assert((int)data == (i+1));
		}
	}
	
	assert(dlist_length(dlist) == 0);

	for(i = 0; i < n; i++)
	{
		assert(dlist_prepend(dlist, (void*)i) == RET_OK);
		assert(dlist_length(dlist) == (i + 1));
		assert(dlist_get_by_index(dlist, 0, (void**)&data) == RET_OK);
		assert(data == i);
		assert(dlist_set_by_index(dlist, 0, (void*)(2*i)) == RET_OK);
		assert(dlist_get_by_index(dlist, 0, (void**)&data) == RET_OK);
		assert(data == 2*i);
		assert(dlist_set_by_index(dlist, 0, (void*)i) == RET_OK);
	}

	i = n - 1;
	assert(dlist_foreach(dlist, check_and_dec_int, &i) == RET_OK);

	dlist_destroy(dlist);

	return;
}
コード例 #3
0
ファイル: skippy.c プロジェクト: robx/skippy-xd
static dlist *
do_layout(MainWin *mw, dlist *clients, Window focus, Window leader)
{
	unsigned long desktop = wm_get_current_desktop(mw->dpy);
	unsigned int width, height;
	float factor;
	int xoff, yoff;
	dlist *iter, *tmp;
	
	/* Update the client table, pick the ones we want and sort them */
	clients = update_clients(mw, clients, 0);
	
	if(mw->cod)
		dlist_free(mw->cod);
	
	tmp = dlist_first(dlist_find_all(clients, (dlist_match_func)clientwin_validate_func, &desktop));
	if(leader != None)
	{
		mw->cod = dlist_first(dlist_find_all(tmp, clientwin_check_group_leader_func, (void*)&leader));
		dlist_free(tmp);
	} else
		mw->cod = tmp;
	
	if(! mw->cod)
		return clients;
	
	dlist_sort(mw->cod, clientwin_sort_func, 0);
	
	/* Move the mini windows around */
	layout_run(mw, mw->cod, &width, &height);
	factor = (float)(mw->width - 100) / width;
	if(factor * height > mw->height - 100)
		factor = (float)(mw->height - 100) / height;
	
	xoff = (mw->width - (float)width * factor) / 2;
	yoff = (mw->height - (float)height * factor) / 2;
	mainwin_transform(mw, factor);
	for(iter = mw->cod; iter; iter = iter->next)
		clientwin_move((ClientWin*)iter->data, factor, xoff, yoff);
	
	/* Get the currently focused window and select which mini-window to focus */
	iter = dlist_find(mw->cod, clientwin_cmp_func, (void *)focus);
	if(! iter)
		iter = mw->cod;
	mw->focus = (ClientWin*)iter->data;
	mw->focus->focused = 1;
	
	/* Map the client windows */
	for(iter = mw->cod; iter; iter = iter->next)
		clientwin_map((ClientWin*)iter->data);
	XWarpPointer(mw->dpy, None, mw->focus->mini.window, 0, 0, 0, 0, mw->focus->mini.width / 2, mw->focus->mini.height / 2);
	
	return clients;
}
コード例 #4
0
ファイル: pork_aim_proto.c プロジェクト: echoline/powk
static void partial_nick(char *sn, char *snout, struct chatroom *ccon) {
	dlist_t *people = ccon->user_list;
	dlist_t *person;

	normalize(snout, sn, strlen(sn) + 1);
	if ((person = dlist_find(people, snout, partial_nick_comp))) {
		struct chat_user *chat_user = person->data;
		strcpy(snout, chat_user->nname);
		return;
	}
	return;
}
コード例 #5
0
ファイル: pork_aim_proto.c プロジェクト: echoline/powk
int check_if_imm(char *sn, struct chatroom *ccon) {
	struct aim_chat *a_chat = ccon->data;
	char buf[MAXSNLEN+1];

	if (check_if_op(sn, ccon))
		return 1;

	normalize(buf, sn, strlen(sn) + 1);
	if (dlist_find(a_chat->immlist, buf, (void*)strcmp))
		return 1;
	return 0;
}
コード例 #6
0
ファイル: list.c プロジェクト: seankerr/codebox
int32_t dlist_find_ts (DList* list, void* data) {
    assert(NULL != list);
    assert(NULL != list->mutex);

    pthread_mutex_lock(list->mutex);

    int32_t ret = dlist_find(list, data);

    pthread_mutex_unlock(list->mutex);

    return ret;
}
コード例 #7
0
ファイル: xcb-dp2.c プロジェクト: lbustc/xcube
/* FIXME */
static void monitor_command(client c) {
	if (!strcasecmp(c->argv[1], "on")) {
		dlist_rwlock_wrlock(monitors);
		if (dlist_find(monitors, c) == NULL)
			dlist_insert_tail(monitors, c);
		dlist_rwlock_unlock(monitors);
	} else if (!strcasecmp(c->argv[1], "off")) {
		remove_from_monitors(c);
		add_reply_string(c, "\r\n", 2);
	} else
		add_reply_error_format(c, "unknown action '%s'\r\n", c->argv[1]);
}
コード例 #8
0
ファイル: dlist.c プロジェクト: Masshat/C_and_CPP
static void* reader(void* param)
{
    int i = 0;
    DList* dlist = (DList*)param;

    for (i = 0; i < NR; i++) {
        int length = dlist_length(dlist);
        dlist_find(dlist, cmp_int, (void*)i);
    }

    return NULL;
}
コード例 #9
0
ファイル: htable.c プロジェクト: mer-tools/sp-rtrace
void* htable_store(htable_t* ht, void* node)
{
	htable_node_t* tnode = (htable_node_t*)node;
	dlist_t* bucket = get_bucket(ht, tnode);
	dlist_node_t* old_node = dlist_find(bucket, node, ht->do_compare);
	if (old_node) {
	    dlist_remove(bucket, old_node);
	}
	tnode->bucket = bucket;
    dlist_add(bucket, node);

	return old_node;
}
コード例 #10
0
static void *consumer_thread(void *arg)
{
	int i = 0;
	DList *dlist = (DList *)arg;
	
	printf("consumer thread executed!\n");
	for(i = 0; i < 2000; i++) {
		usleep(20);
		printf("dlist length = %d\n", dlist_length(dlist));
		dlist_find(dlist, cmp_int, (void *)i);
	}
	
	return NULL;
}
コード例 #11
0
ファイル: skippy.c プロジェクト: robx/skippy-xd
static dlist *
update_clients(MainWin *mw, dlist *clients, Bool *touched)
{
	dlist *stack, *iter;
	
	stack = dlist_first(wm_get_stack(mw->dpy));
	iter = clients = dlist_first(clients);
	
	if(touched)
		*touched = False;
	
	/* Terminate clients that are no longer managed */
	while(iter)
	{
		ClientWin *cw = (ClientWin *)iter->data;
		if(! dlist_find_data(stack, (void *)cw->client.window))
		{
			dlist *tmp = iter->next;
			clientwin_destroy((ClientWin *)iter->data, True);
			clients = dlist_remove(iter);
			iter = tmp;
			if(touched)
				*touched = True;
			continue;
		}
		clientwin_update(cw);
		iter = iter->next;
	}
	
	/* Add new clients */
	for(iter = dlist_first(stack); iter; iter = iter->next)
	{
		ClientWin *cw = (ClientWin*)dlist_find(clients, clientwin_cmp_func, iter->data);
		if(! cw && (Window)iter->data != mw->window)
		{
			cw = clientwin_create(mw, (Window)iter->data);
			if(! cw)
				continue;
			clients = dlist_add(clients, cw);
			clientwin_update(cw);
			if(touched)
				*touched = True;
		}
	}
	
	dlist_free(stack);
	
	return clients;
}
コード例 #12
0
ファイル: dlist.c プロジェクト: rickcaudill/Pyro
status_t dlist_add(nspace *vol, ino_t vnid)
{
	DPRINTF(0, ("dlist_add vnid %Lx\n", vnid));

	ASSERT(IS_DIR_CLUSTER_VNID(vnid));
	ASSERT(dlist_find(vol, CLUSTER_OF_DIR_CLUSTER_VNID(vnid)) == -1LL);
	ASSERT(vnid != 0);

	if (vol->dlist.entries == vol->dlist.allocated) {
		if (dlist_realloc(vol, vol->dlist.allocated + DLIST_ENTRY_QUANTUM) < 0)
			return -ENOMEM;
	}
	vol->dlist.vnid_list[vol->dlist.entries++] = vnid;

	return B_OK;
}
コード例 #13
0
ファイル: config.c プロジェクト: landroni/skippy-xd
const char *
config_get(dlist *config, const char *section, const char *key, const char *def)
{
	ConfigEntry needle;
	dlist *iter;
	
	needle.section = (char *)section;
	needle.key = (char *)key;
	
	iter = dlist_find(dlist_first(config), (dlist_match_func)entry_find_func, &needle);
	
	if(! iter)
		return def;
	
	return ((ConfigEntry*)iter->data)->value;
}
コード例 #14
0
ファイル: dlist.c プロジェクト: ningyuwhut/SysProPlan
static void test_invalid_params(void)
{
	printf("===========Warning is normal begin==============\n");
	assert(dlist_length(NULL) == 0);
	assert(dlist_prepend(NULL, 0) == RET_INVALID_PARAMS);
	assert(dlist_append(NULL, 0) == RET_INVALID_PARAMS);
	assert(dlist_delete(NULL, 0) == RET_INVALID_PARAMS);
	assert(dlist_insert(NULL, 0, 0) == RET_INVALID_PARAMS);
	assert(dlist_set_by_index(NULL, 0, 0) == RET_INVALID_PARAMS);
	assert(dlist_get_by_index(NULL, 0, NULL) == RET_INVALID_PARAMS);
	assert(dlist_find(NULL, NULL, NULL) < 0);
	assert(dlist_foreach(NULL, NULL, NULL) == RET_INVALID_PARAMS);
	printf("===========Warning is normal end==============\n");

	return;
}
コード例 #15
0
ファイル: xcb-dp2.c プロジェクト: lbustc/xcube
void client_free(client c) {
	dlist_node_t node;

	remove_from_monitors(c);
	remove_from_clients(c);
	if (c->flags & CLIENT_CLOSE_ASAP && (node = dlist_find(clients_to_close, c)))
		dlist_remove(clients_to_close, node);
	delete_file_event(el, c->fd, EVENT_READABLE);
	delete_file_event(el, c->fd, EVENT_WRITABLE);
	ring_free(&c->reply);
	client_reset(c);
	FREE(c->argv);
	pthread_spin_destroy(&c->lock);
	close(c->fd);
	xcb_log(XCB_LOG_NOTICE, "Client '%p' got freed", c);
	FREE(c);
}
コード例 #16
0
static void handle_response(PacketTransfer *thiz)
{
    /* 能够响应上位机命令,则点亮节点对应的红灯 */
    if (thiz->response.type == NODE_PAYLOAD_TYPE_RESP_NODE_ID)
    {
        gather_board_led_red(thiz->gather_board, thiz->response.port_id + 1, LED_ON);
    }

    /* 节点上报数据包,则节点对应的绿灯闪烁一次 */
    gather_board_led_green(thiz->gather_board, thiz->response.port_id + 1, LED_ON);
    
    /* 在命令集合中找到回应对应的命令项并删除 */
    DList *command_list = thiz->command_set[thiz->response.port_id];
    int command_type = node_type_convert_resp_to_cmd(thiz->response.type);
    int target_index = dlist_find(command_list, response_find_cb, &command_type);
    dlist_delete(command_list, target_index);
}
コード例 #17
0
ファイル: hash_table.c プロジェクト: 0ct0cat/spexamples
Ret    hash_table_find(HashTable* thiz, DataCompareFunc cmp, void* data, void** ret_data)
{
	int index = 0;
	DList* dlist = NULL;
	return_val_if_fail(thiz != NULL && cmp != NULL && ret_data != NULL, RET_INVALID_PARAMS);
	
	index = thiz->hash(data)%thiz->slot_nr;
	dlist = thiz->slots[index];
	if(dlist != NULL)
	{
		index = dlist_find(dlist, cmp, data);

		return dlist_get_by_index(dlist, index, ret_data);
	}

	return RET_FAIL;
}
コード例 #18
0
ファイル: skippy.c プロジェクト: jameswthorne/skippy
static dlist *
update_clients(MainWin *mw, dlist *clients)
{
	dlist *stack, *iter;
	
	stack = dlist_first(wm_get_stack(mw->dpy));
	iter = clients = dlist_first(clients);

	while(iter)
	{
		ClientWin *cw = (ClientWin *)iter->data;
		if(! dlist_find_data(stack, (void *)cw->client.window))
		{
			dlist *tmp = iter->next;
			clientwin_destroy((ClientWin *)iter->data);
			clients = dlist_remove(iter);
			iter = tmp;
			continue;
		}
		clientwin_update(cw);
		iter = iter->next;
	}
	
	for(iter = dlist_first(stack); iter; iter = iter->next)
	{
		ClientWin *cw = (ClientWin*)dlist_find(clients, clientwin_cmp_func, iter->data);
		if(! cw)
		{
			cw = clientwin_create(mw, (Window)iter->data);
			if(! cw)
				continue;
			clients = dlist_add(clients, cw);
			clientwin_update(cw);
		}
	}
	
	dlist_free(stack);
	
	return clients;
}
コード例 #19
0
ファイル: skippy.c プロジェクト: robx/skippy-xd
static dlist *
skippy_run(MainWin *mw, dlist *clients, Window focus, Window leader, Bool all_xin)
{
	XEvent ev;
	int die = 0;
	Bool refocus = False;
	int last_rendered;
	
	/* Update the main window's geometry (and Xinerama info if applicable) */
	mainwin_update(mw);
#ifdef XINERAMA
	if(all_xin)
		mw->xin_active = 0;
#else /* ! XINERAMA */
	if(all_xin);
#endif /* XINERAMA */
	
	/* Map the main window and run our event loop */
	if(mw->lazy_trans)
	{
		mainwin_map(mw);
		XFlush(mw->dpy);
	}
	
	clients = do_layout(mw, clients, focus, leader);
	if(! mw->cod)
		return clients;
	
	/* Map the main window and run our event loop */
	if(! mw->lazy_trans)
		mainwin_map(mw);
	
	last_rendered = time_in_millis();
	while(! die) {
	    int i, j, now, timeout;
	    int move_x = -1, move_y = -1;
	    struct pollfd r_fd;
	    
	    XFlush(mw->dpy);
	    
	    r_fd.fd = ConnectionNumber(mw->dpy);
	    r_fd.events = POLLIN;
	    if(mw->poll_time > 0)
	    	timeout = MAX(0, mw->poll_time + last_rendered - time_in_millis());
	    else
	    	timeout = -1;
	    i = poll(&r_fd, 1, timeout);
	    
	    now = time_in_millis();
	    if(now >= last_rendered + mw->poll_time)
	    {
	    	REDUCE(if( ((ClientWin*)iter->data)->damaged ) clientwin_repair(iter->data), mw->cod);
	    	last_rendered = now;
	    }
	    
	    i = XPending(mw->dpy);
	    for(j = 0; j < i; ++j)
	    {
		XNextEvent(mw->dpy, &ev);
		
		if (ev.type == MotionNotify)
		{
			move_x = ev.xmotion.x_root;
			move_y = ev.xmotion.y_root;
		}
		else if(ev.type == DestroyNotify || ev.type == UnmapNotify) {
			dlist *iter = dlist_find(clients, clientwin_cmp_func, (void *)ev.xany.window);
			if(iter)
			{
				ClientWin *cw = (ClientWin *)iter->data;
				clients = dlist_first(dlist_remove(iter));
				iter = dlist_find(mw->cod, clientwin_cmp_func, (void *)ev.xany.window);
				if(iter)
					mw->cod = dlist_first(dlist_remove(iter));
				clientwin_destroy(cw, True);
				if(! mw->cod)
				{
					die = 1;
					break;
				}
			}
		}
		else if (mw->poll_time >= 0 && ev.type == mw->damage_event_base + XDamageNotify)
		{
			XDamageNotifyEvent *d_ev = (XDamageNotifyEvent *)&ev;
			dlist *iter = dlist_find(mw->cod, clientwin_cmp_func, (void *)d_ev->drawable);
			if(iter)
			{
				if(mw->poll_time == 0)
					clientwin_repair((ClientWin *)iter->data);
				else
					((ClientWin *)iter->data)->damaged = True;
			}
				
		}
		else if(ev.type == KeyRelease && ev.xkey.keycode == mw->key_q)
		{
			DIE_NOW = 1;
			die = 1;
			break;
		}
		else if(ev.type == KeyRelease && ev.xkey.keycode == mw->key_escape)
		{
			refocus = True;
			die = 1;
			break;
		}
		else if(ev.xany.window == mw->window)
			die = mainwin_handle(mw, &ev);
		else if(ev.type == PropertyNotify)
		{
			if(ev.xproperty.atom == ESETROOT_PMAP_ID || ev.xproperty.atom == _XROOTPMAP_ID)
			{
				mainwin_update_background(mw);
				REDUCE(clientwin_render((ClientWin *)iter->data), mw->cod);
			}

		}
		else if(mw->tooltip && ev.xany.window == mw->tooltip->window)
			tooltip_handle(mw->tooltip, &ev);
		else
		{
			dlist *iter;
			for(iter = mw->cod; iter; iter = iter->next)
			{
				ClientWin *cw = (ClientWin *)iter->data;
				if(cw->mini.window == ev.xany.window)
				{
					die = clientwin_handle(cw, &ev);
					if(die)
						break;
				}
			}
			if(die)
				break;
		}
	    
	    }
	    	
	    if(mw->tooltip && move_x != -1)
	    	tooltip_move(mw->tooltip, move_x + 20, move_y + 20);
	    
	}
コード例 #20
0
ファイル: sess_mgr.c プロジェクト: apprisi/illumos-gate
CK_RV
session_mgr_close_session(SESSION *sess)
{
	DL_NODE  * node = NULL;
	CK_RV	rc = CKR_OK;

	if (! sess)
		return (FALSE);
	rc = pthread_mutex_lock(&sess_list_mutex);
	if (rc != CKR_OK) {
		return (CKR_FUNCTION_FAILED);
	}
	node = dlist_find(sess_list, sess);
	if (! node) {
		rc = CKR_FUNCTION_FAILED;
		goto done;
	}

	(void) object_mgr_purge_session_objects(sess, ALL);

	if (sess->find_list)
		free(sess->find_list);

	if (sess->encr_ctx.context)
		free(sess->encr_ctx.context);

	if (sess->encr_ctx.mech.pParameter)
		free(sess->encr_ctx.mech.pParameter);

	if (sess->decr_ctx.context)
		free(sess->decr_ctx.context);

	if (sess->decr_ctx.mech.pParameter)
		free(sess->decr_ctx.mech.pParameter);

	if (sess->digest_ctx.context.ref)
		free(sess->digest_ctx.context.ref);

	if (sess->digest_ctx.mech.pParameter)
		free(sess->digest_ctx.mech.pParameter);

	if (sess->sign_ctx.context)
		free(sess->sign_ctx.context);

	if (sess->sign_ctx.mech.pParameter)
		free(sess->sign_ctx.mech.pParameter);

	if (sess->verify_ctx.context)
		free(sess->verify_ctx.context);

	if (sess->verify_ctx.mech.pParameter)
		free(sess->verify_ctx.mech.pParameter);

	if (sess->hContext)
		(void) Tspi_Context_Close(sess->hContext);

	free(sess);

	sess_list = dlist_remove_node(sess_list, node);

	if (sess_list == NULL) {
		TSS_HCONTEXT hContext;
		if (open_tss_context(&hContext) == 0) {
			(void) object_mgr_purge_private_token_objects(hContext);
			(void) Tspi_Context_Close(hContext);
		}

		global_login_state = 0;

		(void) pthread_mutex_lock(&obj_list_mutex);
		(void) object_mgr_purge_map((SESSION *)0xFFFF, PRIVATE);
		(void) pthread_mutex_unlock(&obj_list_mutex);
	}

	done:
	(void) pthread_mutex_unlock(&sess_list_mutex);
	return (rc);
}
コード例 #21
0
static int    linear_container_dlist_find(LinearContainer* thiz, DataCompareFunc cmp, void* ctx)
{
	PrivInfo* priv = (PrivInfo*)thiz->priv;

	return dlist_find(priv->dlist, cmp, ctx);
}
コード例 #22
0
ファイル: pork_aim_proto.c プロジェクト: echoline/powk
void parse_ccom(char *cmd, struct chatroom *room, struct pork_acct *acct, int priv) {
	struct aim_chat *ccon = room->data;
	struct aim_priv *a_priv = acct->data;
	dlist_t *temp;
	char sn[MAXSNLEN+1];
	char msg[MAXSNLEN+1024];
	char *pmsg = msg;

	cmd[strcspn(cmd,"/")] = '\0';
	if(!strncasecmp(cmd, "op ", 3) && (priv >= FULLOPS)) {
		cmd += 3;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (check_if_op(sn, room))
			return;
		ccon->oparray = dlist_add_tail(ccon->oparray, xstrdup(sn));
		if (ccon->chatsends > 1) {
			sprintf(msg, "%s has been opped.", sn);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
	} else if(!strncasecmp(cmd, "deop ", 5) && (priv >= FULLOPS)) {
		cmd += 5;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (!check_if_op(sn, room))
			return;
		if (temp = dlist_find(ccon->oparray, sn, (void*)strcmp)) {
			free(temp->data);
			ccon->oparray = dlist_remove(ccon->oparray, temp);
			if (ccon->chatsends > 1) {
				sprintf(msg, "%s has been deopped.", sn);
				aim_chat_send_im(&a_priv->aim_session, ccon->conn,
					0, pmsg, strlen(msg), "us-ascii", "en");
			}
		}
	} else if(!strncasecmp(cmd, "defullop ", 7) && (priv >= DOWNERS)) {
		cmd += 9;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (temp = dlist_find(ccon->fullops, sn, (void*)strcmp)) {
			free(temp->data);
			ccon->fullops = dlist_remove(ccon->fullops, temp);
			if (ccon->chatsends > 1) {
				sprintf(msg, "%s has been defullopped.", sn);
				aim_chat_send_im(&a_priv->aim_session, ccon->conn,
					0, pmsg, strlen(msg), "us-ascii", "en");
			}
		}
	} else if(!strncasecmp(cmd, "fullop ", 7) && (priv >= FULLOPS)) {
		cmd += 7;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (check_if_fullop(sn, room))
			return;
		ccon->fullops = dlist_add_tail(ccon->fullops, xstrdup(sn));
		if (ccon->chatsends > 1) {
			sprintf(msg, "%s has been fullopped.", sn);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
	} else if(!strncasecmp(cmd, "halfop ", 7) && (priv > HALFOPS)) {
		cmd += 7;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (check_if_halfop(sn, room))
			return;
		ccon->halfops = dlist_add_tail(ccon->halfops, xstrdup(sn));
		if (ccon->chatsends > 1) {
			sprintf(msg, "%s has been halfopped.", sn);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
	} else if(!strncasecmp(cmd, "dehalfop ", 9) && (priv > HALFOPS)) {
		cmd += 9;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (!check_if_halfop(sn, room))
			return;
		if (temp = dlist_find(ccon->halfops, sn, (void*)strcmp)) {
			free(temp->data);
			ccon->halfops = dlist_remove(ccon->halfops, temp);
			if (ccon->chatsends > 1) {
				sprintf(msg, "%s has been dehalfopped.", sn);
				aim_chat_send_im(&a_priv->aim_session, ccon->conn,
					0, pmsg, strlen(msg), "us-ascii", "en");
			}
		}
	} else if(!strncasecmp(cmd, "kick ", 5)) {
		cmd += 5;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (check_if_imm(sn, room))
			return;
		if (ccon->chatsends > 1) {
			snprintf(msg, MAXSNLEN+127, "kicking %s.", sn);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
		if ((temp = dlist_find(ccon->banlist, sn, (void*)strcmp)) != NULL) {
			free(temp->data);
			ccon->banlist = dlist_remove(ccon->banlist, temp);
		}
		aim_chat_ban(&a_priv->aim_session, ccon->conn, sn);
		aim_chat_unban(&a_priv->aim_session, ccon->conn, sn);
	} else if(!strncasecmp(cmd, "ban ", 4) && (priv > HALFOPS)) {
		cmd += 4;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (check_if_imm(sn, room))
			return;
		if (ccon->chatsends > 1) {
			snprintf(msg, MAXSNLEN+127, "banning %s.", sn);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
		if (!dlist_find(ccon->banlist, sn, (void*)strcmp))
			ccon->banlist = dlist_add_tail(ccon->banlist, xstrdup(sn));
		aim_chat_ban(&a_priv->aim_session, ccon->conn, sn);
	} else if(!strncasecmp(cmd, "unban ", 6) && (priv > HALFOPS)) {
		cmd += 6;
		if (!aim_snvalid(cmd))
			return;
		if (ccon->chatsends > 1) {
			snprintf(msg, MAXSNLEN+127, "unbanning %s.", cmd);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
		if ((temp = dlist_find(ccon->banlist, cmd, (void*)strcmp)) != NULL) {
			free(temp->data);
			ccon->banlist = dlist_remove(ccon->banlist, temp);
		}
		aim_chat_unban(&a_priv->aim_session, ccon->conn, cmd);
	} else if(!strncasecmp(cmd, "pause ", 6) && (priv >= FULLOPS)) {
		cmd += 6;
		banpause = atoi(cmd);
		if (banpause < 0)
			banpause = 0;
		sprintf(msg, "autoban pause set to %g microseconds.", banpause);
		if (ccon->chatsends > 1)
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
	} else if(!strncasecmp(cmd, "help", 4) && ccon->chatsends) {
		char commands[MAXMSGLEN+1];
		strcpy(commands, "commands are: !status, !kick, !imm");
		if (priv > HALFOPS)
			strcat(commands,", !unimm, !ban, !unban, !ab, !unab, !aw, !unaw, !halfop, !dehalfop, !bj");
		if (priv > OPS)
			strcat(commands,", !ak, !unak, !op, !deop, !fullop, !save, !load");
		if (priv > FULLOPS)
			strcat(commands,", !defullop");
		strcat(commands, ".");
		aim_chat_send_im(&a_priv->aim_session, ccon->conn,
			0, commands, strlen(commands), "us-ascii", "en");
	} else if(!strncasecmp(cmd, "imm ", 4)) {
		cmd += 4;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (check_if_imm(sn, room))
			return;
		ccon->immlist = dlist_add_tail(ccon->immlist, xstrdup(sn));
		if (ccon->chatsends > 1) {
			sprintf(msg, "%s has been immed.", sn);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
	} else if(!strncasecmp(cmd, "unimm ", 6) && (priv > HALFOPS)) {
		cmd += 6;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (!check_if_imm(sn, room))
			return;
		if (temp = dlist_find(ccon->immlist, sn, (void*)strcmp)) {
			free(temp->data);
			ccon->immlist = dlist_remove(ccon->immlist, temp);
			if (ccon->chatsends > 1) {
				sprintf(msg, "%s has been unimmed.", sn);
				aim_chat_send_im(&a_priv->aim_session, ccon->conn,
					0, pmsg, strlen(msg), "us-ascii", "en");
			}
		}
	} else if(!strncasecmp(cmd, "ak ", 3) && (priv > OPS)) {
		cmd += 3;
		if (!aim_snvalid(cmd))
			return;
		if (check_if_ak(cmd, room))
			return;
		normalize(sn, cmd, strlen(cmd) + 1);
		ccon->akarray = dlist_add_tail(ccon->akarray, xstrdup(cmd));
		if (ccon->chatsends > 1) {
			sprintf(msg, "%s has been autokicked.", sn);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
		check_akusers_in_room(room);
	} else if(!strncasecmp(cmd, "ab ", 3) && (priv > HALFOPS)) {
		cmd += 3;
		if (!aim_snvalid(cmd))
			return;
		if (check_if_ab(cmd, room))
			return;
		normalize(sn, cmd, strlen(cmd) + 1);
		ccon->abarray = dlist_add_tail(ccon->abarray, xstrdup(cmd));
		if (ccon->chatsends > 1) {
			sprintf(msg, "%s has been autobanned.", sn);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
		check_abusers_in_room(room);
	} else if(!strncasecmp(cmd, "aw ", 3) && (priv > HALFOPS)) {
		cmd += 3;
		if (check_if_aw(cmd, room))
			return;
		ccon->awarray = dlist_add_tail(ccon->awarray, xstrdup(cmd));
		if (ccon->chatsends > 1) {
			sprintf(msg, "%s has been autoworded.", cmd);
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
		}
	} else if(!strncasecmp(cmd, "unak ", 5) && (priv > OPS)) {
		cmd += 5;
		if (!aim_snvalid(cmd))
			return;
		if (!check_if_ak(cmd, room))
			return;
		if (temp = dlist_find(ccon->akarray, cmd, (void*)strcmp)) {
			free(temp->data);
			ccon->akarray = dlist_remove(ccon->akarray, temp);
			if (0) { //ccon->chatsends > 1) {
				sprintf(msg, "%s has been unautokicked.", cmd);
				aim_chat_send_im(&a_priv->aim_session, ccon->conn,
					0, pmsg, strlen(msg), "us-ascii", "en");
			}
		}
	} else if(!strncasecmp(cmd, "unab ", 5) && (priv > HALFOPS)) {
		cmd += 5;
		if (!aim_snvalid(cmd))
			return;
		if (!check_if_ab(cmd, room))
			return;
		if (temp = dlist_find(ccon->abarray, cmd, (void*)strcmp)) {
			free(temp->data);
			ccon->abarray = dlist_remove(ccon->abarray, temp);
			if (0) { //ccon->chatsends > 1) {
				sprintf(msg, "%s has been unautobanned.", cmd);
				aim_chat_send_im(&a_priv->aim_session, ccon->conn,
					0, pmsg, strlen(msg), "us-ascii", "en");
			}
		}
	} else if(!strncasecmp(cmd, "unaw ", 5) && (priv > HALFOPS)) {
		cmd += 5;
		if (!check_if_aw(cmd, room))
			return;
		if (temp = dlist_find(ccon->awarray, cmd, (void*)strcmp)) {
			free(temp->data);
			ccon->awarray = dlist_remove(ccon->awarray, temp);
			if (ccon->chatsends > 1) {
				snprintf(msg, 1024, "%s has been unautoworded.", cmd);
				aim_chat_send_im(&a_priv->aim_session, ccon->conn,
					0, pmsg, strlen(msg), "us-ascii", "en");
			}
		}
	} else if(!strncasecmp(cmd, "status ", 7) && ccon->chatsends) {
		strcpy(msg, "");
		cmd += 7;
		if (!aim_snvalid(cmd))
			return;
		partial_nick(cmd, sn, room);
		if (check_if_fullop(sn, room)) {
			sprintf(msg, "%s is a full op.", sn);
		} else if (check_if_op(sn, room)) {
			sprintf(msg, "%s is an op.", sn);
		} else if (check_if_halfop(sn, room)) {
			sprintf(msg, "%s is a half op", sn);
			if (check_if_imm(sn, room))
				strcat(msg, " and immune");
			strcat(msg, ".");
		} else if (check_if_imm(sn, room)) {
			sprintf(msg, "%s is immune.", sn);
		}
		if (strlen(msg))
			aim_chat_send_im(&a_priv->aim_session, ccon->conn,
				0, pmsg, strlen(msg), "us-ascii", "en");
	} else if(!strncasecmp(cmd, "chatsends ", 10) && (priv >= FULLOPS)) {
		int chatsends;
		cmd += 10;
		chatsends = atoi(cmd);
		if ((chatsends >= 0) && (chatsends <= 2)) {
			ccon->chatsends = chatsends;
			if (ccon->chatsends > 1) {
				sprintf(msg, "chatsends now set to %d.", ccon->chatsends);
				aim_chat_send_im(&a_priv->aim_session, ccon->conn, 0, msg, strlen(msg), "us-ascii", "en");
			}
		}
	} else if(!strncasecmp(cmd, "save", 4) && (priv >= FULLOPS)) {
		if (!write_room(ccon)) {
			screen_err_msg("unable to save config for room %s.\n", ccon->title);
		}
	} else if(!strncasecmp(cmd, "load ", 5) && (priv >= FULLOPS)) {
		if (!read_room(ccon, &cmd[5])) {
			screen_err_msg("unable to load config for room %s.\n", &cmd[5]);
		}
	} else if(!strncasecmp(cmd, "bj", 2) && (priv > HALFOPS)) {
		ccon->banjoin = !ccon->banjoin;
		if (ccon->chatsends > 1) {
			sprintf(msg, "banjoin: %s.", ccon->banjoin?"on":"off");
			aim_chat_send_im(&a_priv->aim_session, ccon->conn, 0, msg, strlen(msg), "us-ascii", "en");
		}
	}
}
コード例 #23
0
ファイル: pork_aim_proto.c プロジェクト: echoline/powk
int check_if_aw(char *word, struct chatroom *ccon) {
	struct aim_chat *a_chat = ccon->data;
	if (dlist_find(a_chat->awarray, word, (void*)strcmp))
		return 1;
	return 0;
}
コード例 #24
0
ファイル: dir.c プロジェクト: MaddTheSane/haiku
static status_t
get_next_dirent(nspace *vol, vnode *dir, struct diri *iter, ino_t *vnid,
	char *filename, int len)
{
	struct _dirent_info_ info;
	status_t result;

	do {
		result = _next_dirent_(iter, &info, filename, len);
		if (result < 0)
			return result;
		// only hide volume label entries in the root directory
	} while ((info.mode & FAT_VOLUME) && (dir->vnid == vol->root_vnode.vnid));

	if (!strcmp(filename, ".")) {
		// assign vnode based on parent
		if (vnid) *vnid = dir->vnid;
	} else if (!strcmp(filename, "..")) {
		// assign vnode based on parent of parent
		if (vnid) *vnid = dir->dir_vnid;
	} else {
		if (vnid) {
			ino_t loc = (IS_DATA_CLUSTER(info.cluster))
				? GENERATE_DIR_CLUSTER_VNID(dir->vnid, info.cluster)
				: GENERATE_DIR_INDEX_VNID(dir->vnid, info.sindex);
			bool added_to_vcache = false;

			/* if it matches a loc in the lookup table, we are done. */
			result = vcache_loc_to_vnid(vol, loc, vnid);
			if (result == ENOENT) {
				/* ...else check if it matches any vnid's in the lookup table */
				if (find_vnid_in_vcache(vol, loc) == B_OK) {
					/* if it does, create a random one since we can't reuse
					 * existing vnid's */
					*vnid = generate_unique_vnid(vol);
					/* and add it to the vcache */
					if ((result = add_to_vcache(vol, *vnid, loc)) < 0)
						return result;
					added_to_vcache = true;
				} else {
					/* otherwise we are free to use it */
					*vnid = loc;
				}
			} else if (result != B_OK) {
				dprintf("get_next_dirent: unknown error (%s)\n",
					strerror(result));
				return result;
			}

			if (info.mode & FAT_SUBDIR) {
				if (dlist_find(vol, info.cluster) == -1LL) {
					if ((result = dlist_add(vol, *vnid)) < 0) {
						if (added_to_vcache)
							remove_from_vcache(vol, *vnid);
						return result;
					}
				}
			}
		}
	}

	DPRINTF(2, ("get_next_dirent: found %s (vnid %Lx)\n", filename,
		vnid != NULL ? *vnid : (ino_t)0));

	return B_NO_ERROR;
}
コード例 #25
0
ファイル: htable.c プロジェクト: mer-tools/sp-rtrace
void* htable_find(htable_t* ht, void* data)
{
	dlist_node_t* node = dlist_find(get_bucket(ht, data), data, ht->do_compare);
	return node;
}
コード例 #26
0
ファイル: skippy.c プロジェクト: jameswthorne/skippy
static dlist *
skippy_run(MainWin *mw, dlist *clients, int force, Window focus, Window leader, Bool all_xin)
{
	unsigned int width, height, tree_count, u;
	float factor;
	int xoff, yoff;
	XEvent ev;
	int die = 0;
	dlist *iter, *tmp;
	Window dummy_w, *tree_windows;
	CARD32 desktop = wm_get_current_desktop(mw->dpy);
	Bool refocus = False;
	
	/* Update the main window's geometry (and Xinerama info if applicable) */
	mainwin_update(mw);
#ifdef XINERAMA
	if(all_xin)
		mw->xin_active = 0;
#else /* ! XINERAMA */
	if(all_xin);
#endif /* XINERAMA */
	
	/* Update the client table, pick the ones we want and sort them */
	clients = update_clients(mw, clients);
	
	tmp = dlist_first(dlist_find_all(clients, (dlist_match_func)clientwin_validate_func, &desktop));
	if(leader != None)
	{
		mw->cod = dlist_first(dlist_find_all(tmp, clientwin_check_group_leader_func, (void*)&leader));
		dlist_free(tmp);
	} else
		mw->cod = tmp;
	
	if(! mw->cod)
		return clients;
	
	dlist_sort(mw->cod, clientwin_sort_func, 0);
	
	/* Move the mini windows around */
	layout_run(mw, mw->cod, &width, &height);
	factor = (float)(mw->width - 100) / width;
	if(factor * height > mw->height - 100)
		factor = (float)(mw->height - 100) / height;
	
	xoff = (mw->width - (float)width * factor) / 2;
	yoff = (mw->height - (float)height * factor) / 2;
	for(iter = mw->cod; iter; iter = iter->next)
		clientwin_move((ClientWin*)iter->data, factor, xoff, yoff);
	
	/* Get the currently focused window and select which mini-window to focus */
	iter = dlist_find(mw->cod, clientwin_cmp_func, (void *)focus);
	if(! iter)
		iter = mw->cod;
	mw->focus = (ClientWin*)iter->data;
	mw->focus->focused = 1;
	
	/* Save the stacking tree */
	XQueryTree(mw->dpy, mw->root, &dummy_w, &dummy_w, &tree_windows, &tree_count);
	mw->stack_touched = False;
	
	/* Map the client windows */
	for(iter = mw->cod; iter; iter = iter->next)
		clientwin_map((ClientWin*)iter->data, force);
	XWarpPointer(mw->dpy, None, mw->focus->mini.window, 0, 0, 0, 0, mw->focus->mini.width / 2, mw->focus->mini.height / 2);
	
	/* Restore the stacking order (using XRestackWindows seems like a bad idea) */
	if(mw->stack_touched)
		for(u = 0; u < tree_count; ++u)
			XRaiseWindow(mw->dpy, tree_windows[u]);
	XFree(tree_windows);
	
	/* Map the main window and run our event loop */
	mainwin_map(mw);
	
	while(! die) {
 		XNextEvent(mw->dpy, &ev);
		if(ev.type == KeyRelease && ev.xkey.keycode == mw->key_q) {
			DIE_NOW = 1;
			break;
		}
		else if(ev.type == DestroyNotify || ev.type == UnmapNotify) {
			dlist *iter = dlist_find(clients, clientwin_cmp_func, (void *)ev.xany.window);
			if(iter)
			{
				ClientWin *cw = (ClientWin *)iter->data;
				clients = dlist_first(dlist_remove(iter));
				iter = dlist_find(mw->cod, clientwin_cmp_func, (void *)ev.xany.window);
				if(iter)
					mw->cod = dlist_first(dlist_remove(iter));
				clientwin_destroy(cw);
				if(! mw->cod)
				{
					die = 1;
					break;
				}
			}
		}
		else if(ev.xany.window == mw->window)
			die = mainwin_handle(mw, &ev);
		else if(ev.type == PropertyNotify && (ev.xproperty.atom == ESETROOT_PMAP_ID || ev.xproperty.atom == _XROOTPMAP_ID))
			mainwin_update_background(mw);
		else if(mw->tooltip && ev.xany.window == mw->tooltip->window)
			tooltip_handle(mw->tooltip, &ev);
		else if(ev.type == KeyRelease && ev.xkey.keycode == mw->key_escape)
		{
			refocus = True;
			break;
		}
		else
		{
			dlist *iter;
			for(iter = mw->cod; iter; iter = iter->next)
			{
				ClientWin *cw = (ClientWin *)iter->data;
				if(cw->mini.window == ev.xany.window)
				{
					die = clientwin_handle(cw, &ev);
					break;
				}
			}
		}
	}
	
	/* Unmap the main window and clean up */
	mainwin_unmap(mw);
	XFlush(mw->dpy);
	
	REDUCE(clientwin_unmap((ClientWin*)iter->data), mw->cod);
	dlist_free(mw->cod);
	mw->cod = 0;
	
	if(die == 2)
		DIE_NOW = 1;
	
	if(refocus)
		XSetInputFocus(mw->dpy, focus, RevertToPointerRoot, CurrentTime);
	
	return clients;
}
コード例 #27
0
ファイル: custom.c プロジェクト: herberteuler/xcb
/* FIXME */
void s_command(client c) {
	dstr pkey, skey;
	int i;
	dlist_t dlist;
	struct kvd *kvd;

	if (dstr_length(c->argv[0]) == 1) {
		add_reply_error(c, "index can't be empty\r\n");
		return;
	}
	pkey = dstr_new(c->argv[0] + 1);
	skey = dstr_new(pkey);
	if (c->argc > 1)
		for (i = 1; i < c->argc; ++i) {
			skey = dstr_cat(skey, ",");
			skey = dstr_cat(skey, c->argv[i]);
		}
	table_lock(cache);
	if ((dlist = table_get_value(cache, pkey))) {
		dlist_iter_t iter = dlist_iter_new(dlist, DLIST_START_HEAD);
		dlist_node_t node;

		/* FIXME: still has room to improve */
		while ((node = dlist_next(iter))) {
			kvd = (struct kvd *)dlist_node_value(node);
			if (dstr_length(kvd->key) >= dstr_length(skey) &&
				!memcmp(kvd->key, skey, dstr_length(skey))) {
				dstr *fields = NULL;
				int nfield = 0;
				dstr res, contracts = NULL;

				fields = dstr_split_len(kvd->key, dstr_length(kvd->key), ",", 1, &nfield);
				res = dstr_new(fields[0]);
				if (nfield > 1) {
					contracts = dstr_new(fields[1]);
					for (i = 2; i < nfield; ++i) {
						contracts = dstr_cat(contracts, ",");
						contracts = dstr_cat(contracts, fields[i]);
					}
				}
				dstr_free_tokens(fields, nfield);
				fields = NULL, nfield = 0;
				fields = dstr_split_len(kvd->u.value, dstr_length(kvd->u.value),
					",", 1, &nfield);
				res = dstr_cat(res, ",");
				res = dstr_cat(res, fields[0]);
				if (contracts) {
					res = dstr_cat(res, ",");
					res = dstr_cat(res, contracts);
				}
				for (i = 1; i < nfield; ++i) {
					res = dstr_cat(res, ",");
					res = dstr_cat(res, fields[i]);
				}
				res = dstr_cat(res, "\r\n");
				pthread_spin_lock(&c->lock);
				if (!(c->flags & CLIENT_CLOSE_ASAP)) {
					if (net_try_write(c->fd, res, dstr_length(res),
						10, NET_NONBLOCK) == -1) {
						xcb_log(XCB_LOG_WARNING, "Writing to client '%p': %s",
							c, strerror(errno));
						if (++c->eagcount >= 3) {
							client_free_async(c);
							pthread_spin_unlock(&c->lock);
							dstr_free(contracts);
							dstr_free(res);
							dstr_free_tokens(fields, nfield);
							table_unlock(cache);
							dstr_free(skey);
							dstr_free(pkey);
							return;
						}
					} else if (c->eagcount)
						c->eagcount = 0;
				}
				pthread_spin_unlock(&c->lock);
				dstr_free(contracts);
				dstr_free(res);
				dstr_free_tokens(fields, nfield);
			}
		}
		dlist_iter_free(&iter);
	}
	table_unlock(cache);
	table_rwlock_wrlock(subscribers);
	if ((dlist = table_get_value(subscribers, pkey)) == NULL) {
		if (NEW(kvd)) {
			kvd->key     = skey;
			kvd->u.dlist = dlist_new(NULL, NULL);
			dlist_insert_tail(kvd->u.dlist, c);
			dlist = dlist_new(cmpkvd, kdfree);
			dlist_insert_sort(dlist, kvd);
			table_insert(subscribers, pkey, dlist);
		} else {
			add_reply_error(c, "error allocating memory for kvd\r\n");
			dstr_free(skey);
			dstr_free(pkey);
		}
	} else {
		if (NEW(kvd)) {
			dlist_node_t node;

			kvd->key     = skey;
			kvd->u.dlist = dlist_new(NULL, NULL);
			if ((node = dlist_find(dlist, kvd)) == NULL) {
				dlist_insert_tail(kvd->u.dlist, c);
				dlist_insert_sort(dlist, kvd);
			} else {
				kdfree(kvd);
				kvd = (struct kvd *)dlist_node_value(node);
				if (dlist_find(kvd->u.dlist, c) == NULL)
					dlist_insert_tail(kvd->u.dlist, c);
			}
		} else {
			add_reply_error(c, "error allocating memory for kvd\r\n");
			dstr_free(skey);
		}
		dstr_free(pkey);
	}
	table_rwlock_unlock(subscribers);
}
コード例 #28
0
ファイル: xcb-dp2.c プロジェクト: wood3559/xcb
int main(int argc, char **argv) {
	int ncmds, i;
	const char *tmp;
	pgm_error_t *pgm_err = NULL;

	/* FIXME */
	signal(SIGPIPE, SIG_IGN);
	setup_signal_handlers();
	cmds = table_new(cmpstr, hashmurmur2, NULL, NULL);
	ncmds = sizeof commands / sizeof (struct cmd);
	for (i = 0; i < ncmds; ++i) {
		struct cmd *cmd = commands + i;

		table_insert(cmds, cmd->name, cmd);
	}
	if (argc != 2 && argc != 3)
		usage();
	else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
		usage();
	else if (argc == 3 && strcmp(argv[1], "-f"))
		usage();
	if (argc == 2 && daemon(1, 0) == -1)
		fprintf(stderr, "Error daemonizing: %s\n", strerror(errno));
	/* FIXME */
	if (init_logger("/var/log/xcb/xcb-dp2.log", __LOG_DEBUG) == -1) {
		fprintf(stderr, "Error initializing logger\n");
		exit(1);
	}
	cfg_path = argc == 2 ? argv[1] : argv[2];
	if ((cfg = config_load(cfg_path)) == NULL)
		exit(1);
	if ((tmp = variable_retrieve(cfg, "general", "log_level"))) {
		if (!strcasecmp(tmp, "info"))
			set_logger_level(__LOG_INFO);
		else if (!strcasecmp(tmp, "notice"))
			set_logger_level(__LOG_NOTICE);
		else if (!strcasecmp(tmp, "warning"))
			set_logger_level(__LOG_WARNING);
	}
	/* FIXME */
	if (addms)
		times = table_new(cmpstr, hashmurmur2, kfree, vfree);
	clients_to_close = dlist_new(NULL, NULL);
	clients = dlist_new(NULL, NULL);
	monitors = dlist_new(NULL, NULL);
	tp = thrpool_new(16, 256, 200, NULL);
	if (!pgm_init(&pgm_err)) {
		xcb_log(XCB_LOG_ERROR, "Error starting PGM engine: %s", pgm_err->message);
		pgm_error_free(pgm_err);
		goto err;
	}
	/* FIXME */
	if (NEW(pgm_send_cfg) == NULL) {
		xcb_log(XCB_LOG_ERROR, "Error allocating memory for PGM cfg");
		goto err;
	}
	pgm_send_cfg->network = NULL;
	pgm_send_cfg->port    = 0;
	init_pgm_send_cfg(pgm_send_cfg);
	if (pgm_send_cfg->network == NULL) {
		xcb_log(XCB_LOG_ERROR, "PGM network can't be NULL");
		goto err;
	}
	if (pgm_send_cfg->port == 0) {
		xcb_log(XCB_LOG_ERROR, "PGM port can't be zero");
		goto err;
	}
	if ((pgm_sender = pgmsock_create(pgm_send_cfg->network, pgm_send_cfg->port, PGMSOCK_SENDER)) == NULL)
		goto err;
	/* FIXME */
	if ((el = create_event_loop(1024 + 1000)) == NULL) {
		xcb_log(XCB_LOG_ERROR, "Error creating event loop");
		goto err;
	}
	create_time_event(el, 1, server_cron, NULL, NULL);
	/* FIXME */
	if ((tmp = variable_retrieve(cfg, "modules", "module_path")) && strcmp(tmp, "")) {
		struct variable *var = variable_browse(cfg, "modules");
		dlist_t noloads = dlist_new(cmpstr, NULL);
		DIR *dir;
		struct dirent *dirent;

		while (var) {
			if (!strcasecmp(var->name, "preload")) {
				if (strcmp(var->value, "")) {
					int len = strlen(var->value);

					if (len >= 4 && !strcasecmp(var->value + len - 3, ".so") &&
						!strncasecmp(var->value, "md", 2))
						module_load(tmp, var->value);
				}
			} else if (!strcasecmp(var->name, "noload") && !strncasecmp(var->value, "md", 2))
				if (strcmp(var->value, ""))
					dlist_insert_tail(noloads, (void *)var->value);
			var = var->next;
		}
		if ((dir = opendir(tmp))) {
			while ((dirent = readdir(dir))) {
				int len = strlen(dirent->d_name);

				if (len < 4)
					continue;
				if (strcasecmp(dirent->d_name + len - 3, ".so") ||
					strncasecmp(dirent->d_name, "md", 2))
					continue;
				if (dlist_find(noloads, dirent->d_name))
					continue;
				module_load(tmp, dirent->d_name);
			}
			closedir(dir);
		} else
			xcb_log(XCB_LOG_WARNING, "Unable to open modules directory '%s'", tmp);
		dlist_free(&noloads);
	}
	if ((tmp = variable_retrieve(cfg, "general", "udp_port")) && strcmp(tmp, "")) {
		if ((udpsock = net_udp_server(NULL, atoi(tmp), neterr, sizeof neterr)) == -1) {
			xcb_log(XCB_LOG_ERROR, "Opening port '%s': %s", tmp, neterr);
			goto err;
		}
		if (net_nonblock(udpsock, neterr, sizeof neterr) == -1) {
			xcb_log(XCB_LOG_ERROR, "Setting port '%s' nonblocking: %s", tmp, neterr);
			goto err;
		}
	}
	if ((tmp = variable_retrieve(cfg, "general", "tcp_port")) && strcmp(tmp, ""))
		if ((tcpsock = net_tcp_server(NULL, atoi(tmp), neterr, sizeof neterr)) == -1) {
			xcb_log(XCB_LOG_ERROR, "Opening port '%s': %s", tmp, neterr);
			goto err;
		}
	if (udpsock > 0 && create_file_event(el, udpsock, EVENT_READABLE, read_quote, NULL) == -1) {
		xcb_log(XCB_LOG_ERROR, "Unrecoverable error creating udpsock '%d' file event", udpsock);
		goto err;
	}
	if (tcpsock > 0 && create_file_event(el, tcpsock, EVENT_READABLE, tcp_accept_handler, NULL) == -1) {
		xcb_log(XCB_LOG_ERROR, "Unrecoverable error creating tcpsock '%d' file event", tcpsock);
		goto err;
	}
	xcb_log(XCB_LOG_NOTICE, "Server dispatcher started");
	start_event_loop(el, ALL_EVENTS);
	delete_event_loop(el);
	pgm_shutdown();
	return 0;

err:
	close_logger();
	exit(1);
}
コード例 #29
0
ファイル: pork_aim_proto.c プロジェクト: echoline/powk
void check_ab_queues() {
	dlist_t *cur;
	struct chatroom *chat;
	struct pork_acct *acct; 
	struct aim_chat *a_chat;
	struct aim_priv *priv;
	int refnum = 0;
	char msg[MAXSNLEN+1024];
	dlist_t *temp;

	while ((cur = pork_acct_find(refnum)) != NULL) {
		refnum++;
		acct = cur->data;
		if (acct->proto->protocol != PROTO_AIM)
			continue;
		priv = acct->data;
		for (cur = acct->chat_list; cur != NULL; cur = cur->next) {
			chat = cur->data;
			a_chat = chat->data;
			if (a_chat->abqueue != NULL) {
				if (check_if_imm(a_chat->abqueue->data,
						chat)) {
					free(a_chat->abqueue->data);
					dlist_remove_head(&a_chat->abqueue);
					return;
				}
				if (a_chat->chatsends > 1) {
					snprintf(msg, MAXSNLEN+1023, 
						"banning %s.",
						(char*)a_chat->abqueue->data);
					aim_chat_send_im(&priv->aim_session, 
						a_chat->conn, 0, msg, 
						strlen(msg), "us-ascii", "en");
				}
				if (!dlist_find(a_chat->banlist, a_chat->abqueue->data, (void*)strcmp))
					a_chat->banlist = dlist_add_tail(a_chat->banlist, xstrdup(a_chat->abqueue->data));
				aim_chat_ban(&priv->aim_session, a_chat->conn,
					a_chat->abqueue->data);
				free(a_chat->abqueue->data);
				dlist_remove_head(&a_chat->abqueue);
			}
			if (a_chat->akqueue != NULL) {
				if (check_if_imm(a_chat->akqueue->data,
						chat)) {
					free(a_chat->akqueue->data);
					dlist_remove_head(&a_chat->akqueue);
					return;
				}
				if (a_chat->chatsends > 1) {
					snprintf(msg, MAXSNLEN+1023, 
						"kicking %s.",
						(char*)a_chat->akqueue->data);
					aim_chat_send_im(&priv->aim_session, 
						a_chat->conn, 0, msg, 
						strlen(msg), "us-ascii", "en");
				}
				if ((temp = dlist_find(a_chat->banlist, a_chat->akqueue->data, (void*)strcmp)) != NULL) {
					free(temp->data);
					a_chat->banlist = dlist_remove(a_chat->banlist, temp);
				}
				aim_chat_ban(&priv->aim_session, a_chat->conn,
					a_chat->akqueue->data);
				aim_chat_unban(&priv->aim_session, a_chat->conn,
					a_chat->akqueue->data);
				free(a_chat->akqueue->data);
				dlist_remove_head(&a_chat->akqueue);
			}
		}
	}
}