Beispiel #1
0
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;
}
Beispiel #2
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;
}
Beispiel #3
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;
}
Beispiel #4
0
static void notice_count(int *replies, int *mentions)
{
	static fb_time_t last;

	fb_time_t now = fb_time();
	if (now - last > 10) {
		user_id_t user_id = session_uid();
		*replies = post_reply_get_count(user_id);
		*mentions = post_mention_get_count(user_id);
		last = now;
	} else {
		*replies = post_reply_get_count_cached();
		*mentions = post_mention_get_count_cached();
	}
}
Beispiel #5
0
/*
{
	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;
}
Beispiel #6
0
int web_brdadd(void)
{
	if (!session_id())
		return BBS_ELGNREQ;

	int bid = strtol(web_get_param("bid"), NULL, 10);
	int ok = fav_board_add(session_uid(), NULL, bid,
			FAV_BOARD_ROOT_FOLDER, &currentuser);
	if (ok) {
		xml_header(NULL);
		printf("<bbsbrdadd>");
		print_session();

		board_t board;
		get_board_by_bid(bid, &board);
		printf("<brd>%s</brd><bid>%d</bid></bbsbrdadd>", board.name, board.id);
		session_set_board(board.id);
		return 0;
	}
	return BBS_EBRDQE;
}
Beispiel #7
0
static int buy_title(int item, const char *title)
{
	xml_header(NULL);
	printf("<bbsbuyprop>");
	print_session();
	if (title && *title) {
		UTF8_BUFFER(title, TITLE_CCHARS);
		convert_g2u(title, utf8_title);
		if (string_validate_utf8(utf8_title, TITLE_CCHARS, false) > 0
				&& title_submit_request(item, session_uid(), utf8_title, 0)) {
			printf("<success/>");
		}
	} else {
		printf("<inputs item='%d'>"
				//% "<label for='title'>请输入自定义身份</label>"
				"<label for='title'>\xc7\xeb\xca\xe4\xc8\xeb\xd7\xd4\xb6\xa8\xd2\xe5\xc9\xed\xb7\xdd</label>"
				"<input name='title' type='text' width='%d'></input>"
				"</inputs>", item, TITLE_CCHARS);
	}
	printf("</bbsbuyprop>");
	return 0;
}
Beispiel #8
0
static void u_enter(void)
{
	if (!HAS_PERM(PERM_CLOAK))
		currentuser.flags[0] &= ~CLOAK_FLAG;
	session_set_visibility(!(HAS_PERM(PERM_LOGINCLOAK)
				&& (currentuser.flags[0] & CLOAK_FLAG)));

	chk_giveupbbs();

	digestmode = NA;

	session_new(NULL, NULL, 0, session_uid(), currentuser.userid, fromhost,
			SESSION_TELNET,
#ifdef ENABLE_SSH
			SESSION_SECURE
#else
			SESSION_PLAIN
#endif
			, session_visible(), 0);

	int pager = load_pager();
	set_pager(pager);
}
Beispiel #9
0
int web_my_props(void)
{
	if (!session_id())
		return BBS_ELGNREQ;

	int record = strtol(web_get_param("record"), NULL, 10);
	int item = strtol(web_get_param("item"), NULL, 10);

	if (record <= 0 || item <= 0) {
		my_props_t *p = my_props_load(session_uid());
		if (!p)
			return BBS_EINTNL;

		xml_header(NULL);
		printf("<bbsmyprop>");
		print_session();
		for (int i = 0; i < my_props_count(p); ++i) {
			show_my_prop(p, i);
		}
		printf("</bbsmyprop>");

		my_props_free(p);
	} else {
		switch (item) {
			case PROP_TITLE_FREE:
			case PROP_TITLE_30DAYS:
			case PROP_TITLE_90DAYS:
			case PROP_TITLE_180DAYS:
			case PROP_TITLE_1YEAR:
				return show_title_detail(record);
			default:
				return BBS_EINVAL;
		}
	}
	return 0;
}
Beispiel #10
0
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;
}
Beispiel #11
0
void Retrace1::onEventArrived(
    Inqueue::ContextAccessor& contextaccessor,
    HlpStruct::CallingContext& callContext,
    bool& result,
    CppUtils::String &customOutputData
)
{

    HlpStruct::XmlParameter out_result;
    out_result.getParameter("status_string").getAsString(true) = "OK";
    out_result.getParameter("status").getAsString(true) = "0";


    try {
        customOutputData = "FAILED";
        CppUtils::String const& command = callContext.getCallCustomName();
        LOG(MSG_INFO, ALG_RETRACE, "Command: " << command);

        CppUtils::String const& data_hex = callContext.getParameter<BrkLib::String_Proxy>("custom_data").get();
        CppUtils::String data = CppUtils::unhexlify(data_hex);

        LOG(MSG_INFO, ALG_RETRACE, "Data before hex received: [" << data_hex << "]");
        LOG(MSG_INFO, ALG_RETRACE, "Data received: [" << data << "]");

        // get input parameter
        HlpStruct::XmlParameter in_param;
        HlpStruct::deserializeXmlParameter(	in_param, data );


        CppUtils::String user_id = in_param.getParameter("user_id").getAsString();
        CppUtils::String session_id = in_param.getParameter("session_id").getAsString();


        CppUtils::makeDir( resolveTmpDirectory(user_id));
        CppUtils::makeDir( resolveDownloadDirectory(user_id));
        CppUtils::makeDir( resolveCompletedDirectory(user_id));


        CppUtils::Uid session_uid(session_id);
        if (!session_uid.isValid())
            THROW(CppUtils::OperationFailed, "exc_InvalidSessionUid", "ctx_onEventArrived", session_id);


        // resolve directory

        if (command=="start_download_torrent") {
            // start download
            CppUtils::String torrent_url = in_param.getParameter("torrent_url").getAsString();
            LOGEVENT(HlpStruct::CommonLog::LL_INFO, ALG_RETRACE, "Starting download - url: " << torrent_url << " user_id: " << user_id << " session _id: " << session_id );

            CppUtils::sleep(20.0);

        }
        else if (command=="query_status") {
            // query status
        }
        else if (command=="cancel_download_torrent") {
            // cancel download
        }
        else
            THROW(CppUtils::OperationFailed, "exc_InvalidCommand", "ctx_onEventArrived", command);



    }
    catch(CppUtils::Exception& e)
    {

        out_result.getParameter("status_string").getAsString(true) = "Exception: " + e.message() + " - " + e.arg();
    }
    catch(...)
    {
        out_result.getParameter("status_string").getAsString(true) = "Unknown exception";
    }


    CppUtils::String out_result_str;
    HlpStruct::serializeXmlParameter(out_result, out_result_str );

    customOutputData = CppUtils::hexlify(out_result_str);

    LOG(MSG_INFO, ALG_RETRACE, "Data output before: [" << out_result_str << "]");
    LOG(MSG_INFO, ALG_RETRACE, "Data output: [" << customOutputData << "]");

    // command to stop working thread
    // it's secure to do here
    // because thread cannot be stopped
    stopWorkingThread(contextaccessor);

}