示例#1
0
文件: board.c 项目: caidongyun/fbbs
int web_sel(void)
{
	xml_header("bbssel");
	printf("<bbssel>");
	print_session();

	const char *brd = web_get_param("brd");
	if (*brd != '\0') {
		char name[BOARD_NAME_LEN + 3];
		snprintf(name, sizeof(name), "%%%s%%", brd);

		db_res_t *res = db_query(BOARD_SELECT_QUERY_BASE
				"WHERE lower(b.name) LIKE %s", name);
		if (res && db_res_rows(res) > 0) {
			board_t board;
			for (int i = 0; i < db_res_rows(res); ++i) {
				res_to_board(res, i, &board);
				if (has_read_perm(&board)) {
					board_to_gbk(&board);
					printf("<brd dir='%d' title='%s' desc='%s' />",
							is_board_dir(&board), board.name, board.descr);
				}
			}
		} else {
			printf("<notfound/>");
		}
		db_clear(res);
	}
	printf("</bbssel>");
	return 0;
}
示例#2
0
文件: board.c 项目: caidongyun/fbbs
int web_fav(void)
{
	if (!session_id())
		return BBS_ELGNREQ;

	xml_header(NULL);
	printf("<bbsfav>");
	print_session();

	db_res_t *res = db_query("SELECT b.id, b.name, b.descr FROM boards b"
			" JOIN fav_boards f ON b.id = f.board WHERE f.user_id = %d",
			session_uid());
	if (res) {
		for (int i = 0; i < db_res_rows(res); ++i) {
			int bid = db_get_integer(res, i, 0);
			const char *name = db_get_value(res, i, 1);

			GBK_BUFFER(descr, BOARD_DESCR_CCHARS);
			convert_u2g(db_get_value(res, i, 2), gbk_descr);

			printf("<brd bid='%d' brd='%s'>", bid, name);
			xml_fputs(gbk_descr);
			printf("</brd>");
		}
	}
	db_clear(res);

	printf("</bbsfav>");
	return 0;
}
示例#3
0
文件: board.c 项目: caidongyun/fbbs
int bbssec_main(void)
{
	db_res_t *r1 = db_query("SELECT id, name, descr, short_descr"
			" FROM board_sectors ORDER BY name ASC");
	if (!r1)
		return BBS_EINVAL;

	db_res_t *res = db_query("SELECT b.name, b.descr, b.sector"
			" FROM boards b JOIN board_sectors s ON b.sector = s.id"
			" WHERE b.flag & %d <> 0", BOARD_FLAG_RECOMMEND);
	if (!res) {
		db_clear(r1);
		return BBS_EINVAL;
	}

	xml_header(NULL);
	printf("<bbssec>");
	print_session();

	int last = -1;
	for (int i = 0; i < db_res_rows(r1); ++i) {
		printf("<sec id='%s' desc='%s [%s]'>", db_get_value(r1, i, 1),
				db_get_value(r1, i, 2), db_get_value(r1, i, 3));
		int sid = db_get_integer(r1, i, 0);
		last = show_sector(sid, res, last);
		printf("</sec>");
	}

	db_clear(res);
	db_clear(r1);

	printf("</bbssec>");
	return 0;
}
示例#4
0
文件: session.c 项目: caidongyun/fbbs
static bool _get_session(const char *uname, const char *key)
{
	user_id_t uid = get_user_id(uname);
	if (uid > 0) {
		session_id_t sid = session_get_web_cache(uid, key, fromhost);
		if (sid > 0) {
			session_set_id(sid);
			session_set_uid(uid);
			return true;
		}

		db_res_t *res = db_query("SELECT id, active FROM sessions"
				" WHERE user_id = %"DBIdUID" AND session_key = %s AND web",
				uid, key);
		if (res && db_res_rows(res) == 1) {
			sid = db_get_session_id(res, 0, 0);
			bool active = db_get_bool(res, 0, 1);
			if (active || activate_session(sid, uname)) {
				session_set_id(sid);
				session_set_uid(uid);
				session_set_web_cache(uid, key, session_id(), fromhost);
			}
		}
		db_clear(res);
	}
	return session_id();
}
示例#5
0
bool am_followed_by(const char *uname)
{
	db_res_t *res = db_query("SELECT f.followed"
			" FROM follows f JOIN users u ON f.follower = u.id"
			" WHERE user_id = %"DBIdUID" AND lower(u.name) = lower(%s)",
			session_uid(), uname);
	int rows = res ? db_res_rows(res) : 0;
	db_clear(res);
	return rows;
}
示例#6
0
bool is_blocked(const char *uname)
{
	db_res_t *res = db_query("SELECT b.blocked FROM blacklists b"
			" JOIN alive_users u ON b.user_id = u.id"
			" WHERE b.blocked = %"DBIdUID" AND lower(u.name) = lower(%s)",
			session_uid(), uname);
	int rows = res ? db_res_rows(res) : 0;
	db_clear(res);
	return rows;
}
示例#7
0
/**
 * 检查指定的用户ID是否在列表中
 * @param[in] list 用户ID列表
 * @param[in] uid 用户ID
 * @return 在列表中返回true, 否则false
 */
bool friend_uid_list_contains(const friend_uid_list_t *list, user_id_t uid)
{
	if (!list)
		return false;
	for (int i = db_res_rows(list) - 1; i >= 0; --i) {
		if (db_get_user_id(list, i, 0) == uid)
			return true;
	}
	return false;
}
示例#8
0
文件: online.c 项目: fbbs/fbbs
static tui_list_loader_t fill_session_array(tui_list_t *p)
{
	online_users_t *up = p->data;
	db_res_t *res = up->res;

	p->all = up->num = 0;

	if (!res || db_res_rows(res) < 1) {
		free(up->users);
		up->users = NULL;
		return 0;
	}

	int count = db_res_rows(res);
	up->users = malloc(count * sizeof(*up->users));
	for (int i = 0; i < count; ++i) {
		_fill_session_array(p, i);
	}
	qsort(up->users, up->num, sizeof(*up->users), session_cmp);

	return p->all = up->num;
}
示例#9
0
文件: board.c 项目: caidongyun/fbbs
static void show_board(db_res_t *res)
{
	for (int i = 0; i < db_res_rows(res); ++i) {
		board_t board;
		res_to_board(res, i, &board);
		if (!web_request_type(UTF8))
			board_to_gbk(&board);
		printf("<brd dir='%d' title='%s' cate='%.6s' desc='%s' bm='%s' "
				"read='%d' count='%d' />",
				(board.flag & BOARD_FLAG_DIR) ? 1 : 0, board.name,
				board.categ, board.descr, board.bms,
				brc_board_unread(currentuser.userid, board.name, board.id),
				filenum(board.name));
	}
}
示例#10
0
文件: board.c 项目: caidongyun/fbbs
static int show_sector(int sid, db_res_t *res, int last)
{
	for (int i = last + 1; i < db_res_rows(res); ++i) {
		int sector = db_get_integer(res, i, 2);
		if (sector == sid) {
			last = i;

			const char *utf8_descr = db_get_value(res, i, 1);
			GBK_BUFFER(descr, BOARD_DESCR_CCHARS);
			if (!web_request_type(UTF8)) {
				convert_u2g(utf8_descr, gbk_descr);
			}
			printf("<brd name='%s' desc='%s'/>",
					db_get_value(res, i, 0),
					web_request_type(UTF8) ? utf8_descr : gbk_descr);
		}
	}
	return last;
}
示例#11
0
文件: board.c 项目: caidongyun/fbbs
static xml_node_t *attach_group(xml_node_t *groups, db_res_t *res, int id)
{
	xml_node_t *group = xml_new_child(groups, "group",
			XML_NODE_ANONYMOUS_JSON);
	xml_node_t *boards = xml_new_child(group, "boards", XML_NODE_CHILD_ARRAY);
	for (int i = db_res_rows(res) - 1; i >= 0; --i) {
		int folder = db_get_integer(res, i, 2);
		if (folder == id) {
			xml_node_t *board = xml_new_child(boards, "board",
					XML_NODE_ANONYMOUS_JSON);
			int bid = db_get_integer(res, i, 0);
			xml_attr_integer(board, "id", bid);
			const char *name = db_get_value(res, i, 1);
			xml_attr_string(board, "name", name, false);
			xml_attr_boolean(board, "unread",
					brc_board_unread(currentuser.userid, name, bid));
		}
	}
	return group;
}
示例#12
0
文件: friend.c 项目: fbbs/fbbs
static void show_sessions_of_friends(void)
{
	db_res_t *res = session_get_followed();
	if (!res)
		return;

	fb_time_t now = fb_time();
	for (int i = 0; i < db_res_rows(res); ++i) {
		bool visible = db_get_bool(res, i, 3);
		if (!visible && !HAS_PERM(PERM_SEECLOAK))
			continue;

		session_id_t sid = db_get_session_id(res, i, 0);
		const char *uname = db_get_value(res, i, 2);
		const char *ip = db_get_value(res, i, 4);
		fb_time_t refresh = session_get_idle(sid);
		int status = get_user_status(sid);

		struct userec user;
		getuserec(uname, &user);

		int idle;
		if (refresh < 1 || status == ST_BBSNET)
			idle = 0;
		else
			idle = (now - refresh) / 60;

		if (HAS_DEFINE(user.userdefine, DEF_NOTHIDEIP))
			ip = mask_host(ip);
		else
			ip = "......";

		printf("<ov id='%s' action='%s' idle='%d' ip='%s'>",
				uname, session_status_descr(status), idle, ip);
		xml_fputs(user.username);
		printf("</ov>");
	}
	db_clear(res);
}
示例#13
0
文件: prop.c 项目: caidongyun/fbbs
static int show_title_detail(int record)
{
	db_res_t *res = db_query("SELECT title, approved FROM titles"
			" WHERE record_id = %d AND user_id = %"DBIdUID,
			record, session_uid());
	if (!res || db_res_rows(res) <= 0) {
		db_clear(res);
		return BBS_EINVAL;
	}

	GBK_BUFFER(title, TITLE_CCHARS);
	convert_u2g(db_get_value(res, 0, 0), gbk_title);

	xml_header(NULL);
	printf("<bbspropdetail>");
	print_session();
	//% printf("<prop>自定义身份%s: %s</prop></bbspropdetail>",
	printf("<prop>\xd7\xd4\xb6\xa8\xd2\xe5\xc9\xed\xb7\xdd%s: %s</prop></bbspropdetail>",
			//% db_get_bool(res, 0, 1) ? "" : "[尚在审核]", gbk_title);
			db_get_bool(res, 0, 1) ? "" : "[\xc9\xd0\xd4\xda\xc9\xf3\xba\xcb]", gbk_title);

	db_clear(res);
	return 0;
}
示例#14
0
文件: board.c 项目: caidongyun/fbbs
int web_all_boards(void)
{
	xml_header(NULL);
	printf("<bbsall>");
	print_session();

	db_res_t *res = db_query(BOARD_SELECT_QUERY_BASE);
	if (!res)
		return BBS_EINTNL;
	for (int i = 0; i < db_res_rows(res); ++i) {
		board_t board;
		res_to_board(res, i, &board);
		if (!has_read_perm(&board))
			continue;
		board_to_gbk(&board);
		printf("<brd dir='%d' title='%s' cate='%s' desc='%s' bm='%s' />",
				(board.flag & BOARD_FLAG_DIR) ? 1 : 0, board.name, board.categ,
				board.descr, board.bms);
	}
	db_clear(res);

	printf("</bbsall>");
	return 0;
}
示例#15
0
文件: board.c 项目: caidongyun/fbbs
/*
{
	groups: [
		{
			name: OPTIONAL TEXT,
			descr: OPTIONAL TEXT,
			boards: [
				{ id: INTEGER, name: TEXT, unread: OPTIONAL BOOLEAN },
				...
			]
		},
		...
	]
}
*/
int api_board_fav(void)
{
	if (!session_id())
		return WEB_ERROR_LOGIN_REQUIRED;

	xml_node_t *root = set_response_root("bbs-board-fav",
			XML_NODE_ANONYMOUS_JSON, XML_ENCODING_UTF8);
	xml_node_t *groups = xml_new_node("groups", XML_NODE_CHILD_ARRAY);
	xml_add_child(root, groups);

	query_t *q = query_new(0);
	query_select(q, "board, name, folder");
	query_from(q, "fav_boards");
	query_where(q, "user_id = %"DBIdUID, session_uid());
	db_res_t *boards = query_exec(q);

	q = query_new(0);
	query_select(q, "id, name, descr");
	query_from(q, "fav_board_folders");
	query_where(q, "user_id = %"DBIdUID, session_uid());
	db_res_t *folders = query_exec(q);

	if (folders && boards) {
		attach_group(groups, boards, FAV_BOARD_ROOT_FOLDER);
		for (int i = db_res_rows(folders) - 1; i >= 0; --i) {
			int id = db_get_integer(folders, i, 0);
			xml_node_t *group = attach_group(groups, boards, id);
			xml_attr_string(group, "name", db_get_value(folders, i, 1), true);
			xml_attr_string(group, "descr", db_get_value(folders, i, 2), true);
		}
	}

	db_clear(folders);
	db_clear(boards);
	return WEB_OK;
}
示例#16
0
文件: board.c 项目: caidongyun/fbbs
int api_board_all(void)
{
	db_res_t *res = db_query(BOARD_SELECT_QUERY_BASE);
	if (!res)
		return WEB_ERROR_INTERNAL;

	xml_node_t *root = set_response_root("bbs-board-all",
			XML_NODE_ANONYMOUS_JSON, XML_ENCODING_UTF8);
	xml_node_t *boards = xml_new_node("boards", XML_NODE_CHILD_ARRAY);
	xml_add_child(root, boards);

	for (int i = db_res_rows(res) - 1; i >= 0; --i) {
		board_t board;
		res_to_board(res, i, &board);
		if (!has_read_perm(&board))
			continue;

		xml_node_t *node = xml_new_node("board", XML_NODE_ANONYMOUS_JSON);
		board_to_node(&board, node);
		xml_add_child(boards, node);
	}
	db_clear(res);
	return WEB_OK;
}
示例#17
0
文件: board.c 项目: caidongyun/fbbs
int web_sector(void)
{
	int sid = 0;
	board_t parent = { .id = 0 };
	db_res_t *res = NULL;

	const char *sname = web_get_param("s");
	if (*sname) {
		res = db_query("SELECT id, descr"
				" FROM board_sectors WHERE name = %s", sname);
		if (!res || db_res_rows(res) < 1) {
			db_clear(res);
			return BBS_EINVAL;
		}
	} else {
		const char *pname = web_get_param("board");
		if (*pname)
			get_board(pname, &parent);
		else
			get_board_by_bid(strtol(web_get_param("bid"), NULL, 10), &parent);
		if (!parent.id || !(parent.flag & BOARD_FLAG_DIR)
				|| !has_read_perm(&parent))
			return BBS_ENOBRD;
	}

	xml_header(NULL);
	printf("<bbsboa link='%sdoc' ", get_post_list_type_string());

	if (*sname) {
		char path[HOMELEN];
		sprintf(path, "%s/info/egroup%d/icon.jpg", BBSHOME,
				(int) strtol(sname, NULL, 16));
		if (dashf(path))
			printf(" icon='%s'", path);
		
		const char *utf8_sector = db_get_value(res, 0, 1);
		if (web_request_type(UTF8)) {
			printf(" title='%s'>", utf8_sector);
		} else {
			GBK_BUFFER(sector, BOARD_SECTOR_NAME_CCHARS);
			convert_u2g(utf8_sector, gbk_sector);
			printf(" title='%s'>", gbk_sector);
		}
		sid = db_get_integer(res, 0, 0);
		db_clear(res);
	} else {
		if (web_request_type(UTF8)) {
			printf(" dir= '1' title='%s'>", parent.descr);
		} else {
			GBK_BUFFER(descr, BOARD_DESCR_CCHARS);
			convert_u2g(parent.descr, gbk_descr);
			printf(" dir= '1' title='%s'>", gbk_descr);
		}
	}

	if (sid)
		res = db_query(BOARD_SELECT_QUERY_BASE "WHERE b.sector = %d", sid);
	else
		res = db_query(BOARD_SELECT_QUERY_BASE "WHERE b.parent = %d", parent.id);

	if (res && db_res_rows(res) > 0)
		show_board(res);
	db_clear(res);

	print_session();
	printf("</bbsboa>");
	return 0;
}

int bbsclear_main(void)
{
	if (!session_id())
		return BBS_ELGNREQ;

	board_t board;
	if (!get_board(web_get_param("board"), &board)
			|| !has_read_perm(&board))
		return BBS_ENOBRD;
	session_set_board(board.id);

	const char *start = web_get_param("start");
	brc_init(currentuser.userid, board.name);
	brc_clear_all();
	brc_sync(currentuser.userid);
	char buf[STRLEN];
	snprintf(buf, sizeof(buf), "doc?board=%s&start=%s", board.name, start);
	http_header();
	refreshto(0, buf);
	printf("</head></html>");
	return 0;
}

int bbsnot_main(void)
{
	board_t board;
	if (!get_board(web_get_param("board"), &board)
			|| !has_read_perm(&board))
		return BBS_ENOBRD;

	if (board.flag & BOARD_FLAG_DIR)
		return BBS_EINVAL;
	session_set_board(board.id);

	char fname[HOMELEN];
	snprintf(fname, sizeof(fname), "vote/%s/notes", board.name);
	mmap_t m;
	m.oflag = O_RDONLY;
	if (mmap_open(fname, &m) < 0)
		return BBS_ENOFILE;
	xml_header(NULL);
	printf("<bbsnot brd='%s'>", board.name);
	xml_fputs2((char *) m.ptr, m.size);
	mmap_close(&m);
	print_session();
	printf("</bbsnot>");
	return 0;
}