示例#1
0
int bbsinfo_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	parse_post_data();
	char *type = getparm("type");
	xml_header("bbs");
	if (*type != '\0') {
		printf("<bbsinfo ");
		print_session();
		printf(">%s</bbsinfo>", check_info());
	} else {
		printf("<bbsinfo post='%d' login='******' stay='%d' "
				"since='%s' host='%s' year='%d' month='%d' "
				"day='%d' gender='%c' ", currentuser.numposts,
				currentuser.numlogins, currentuser.stay / 60,
				getdatestring(currentuser.firstlogin, DATE_XML),
				currentuser.lasthost, currentuser.birthyear,
				currentuser.birthmonth, currentuser.birthday,
				currentuser.gender);
		print_session();
		printf(" last='%s'><nick>",
				getdatestring(currentuser.lastlogin, DATE_XML));
		xml_fputs(currentuser.username, stdout);
		printf("</nick></bbsinfo>");
	}
	return 0;
}
示例#2
0
static int edit_user_file(const char *file, const char *desc, const char *submit)
{
	if (!loginok)
		return BBS_ELGNREQ;
	char buf[HOMELEN];
	sethomefile(buf, currentuser.userid, file);
	parse_post_data();
	char *text = getparm("text");
	if (*text != '\0') {
		int fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0644);
		if (fd < 0)
			return BBS_EINTNL;
		fb_flock(fd, LOCK_EX);
		safer_write(fd, text, strlen(text));
		fb_flock(fd, LOCK_UN);
		close(fd);
		xml_header("bbs");
		printf("<bbseufile ");
		print_session();
		printf(" desc='%s'></bbseufile>", desc);
	} else {
		xml_header("bbs");
		printf("<bbseufile ");
		print_session();
		printf(" desc='%s' submit='%s'>", desc, submit);
		xml_printfile(buf, stdout);
		printf("</bbseufile>");
	}
	return 0;
}
示例#3
0
文件: procd_ps.c 项目: aunali1/exopc
void procd_ps(void) {
  proc_p p;
#if 0
  int i;
  pgrp_p pg;
  session_p s;

  fprintf(stderr,"proc_table: %p, envid: %d\n",proc_table,proc_table->procd_envid);

  for (i = 0; i < MAXPGRP; i++) {
    if (!bit_test(proc_table->pgrps_used,i)) continue;
    pg = &proc_table->pgrps[i];
    print_pgrp(pg);
  }
  for (i = 0; i < MAXSESSION; i++) {
    if (!bit_test(proc_table->sessions_used,i)) continue;
    s = &proc_table->sessions[i];
    print_session(s);
  }
  fprintf(stderr,"done\n");
#endif
  p = __pd_pfind(INITPROC);
  if (p) {
    ps_get_flags(-1);
    ps_print_level(-1,NULL);
    ps_print_level(0,p);
  }
  else fprintf(stderr,"COULD NOT FIND PID %d\n",INITPROC);
}
示例#4
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;
}
示例#5
0
int bbspwd_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	parse_post_data();
	xml_header("bbs");
	printf("<bbspwd ");
	print_session();
	char *pw1 = getparm("pw1");
	if (*pw1 == '\0') {
		printf(" i='i'></bbspwd>");
		return 0;
	}
	printf(">", stdout);
	char *pw2 = getparm("pw2");
	char *pw3 = getparm("pw3");
	switch (set_password(pw1, pw2, pw3)) {
		case BBS_EWPSWD:
			printf("ÃÜÂë´íÎó");
			break;
		case BBS_EINVAL:
			printf("ÐÂÃÜÂ벻ƥÅä »ò ÐÂÃÜÂëÌ«¶Ì");
			break;
		default:
			break;
	}
	printf("</bbspwd>");
	return 0;
}
示例#6
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;
}
示例#7
0
int bbsfadd_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	const char *id = getparm("id");
	const char *desc = getparm("desc");
	if (*id != '\0') {
		override_t ov;
		memset(&ov, 0, sizeof(ov));
		strlcpy(ov.id, id, sizeof(ov.id));
		if (!searchuser(ov.id))
			return BBS_ENOUSR;
		strlcpy(ov.exp, desc, sizeof(ov.exp));
		char file[HOMELEN];
		sethomefile(file, currentuser.userid, "friends");
		if (get_num_records(file, sizeof(ov)) == MAXFRIENDS)
			return BBS_EFRNDQE;
		// TODO: be atomic
		if (!search_record(file, NULL, sizeof(ov), cmpname, ov.id))
			append_record(file, &ov, sizeof(ov));
		printf("Location: fall\n\n");
		return 0;
	}
	xml_header("bbs");
	printf("<bbsfadd ");
	print_session();
	printf(">%s</bbsfadd>", id);
	return 0;
}
示例#8
0
文件: bbsann.c 项目: caidongyun/fbbs
int bbsanc_main(void)
{
	const char *path = web_get_param("path");
	if (strstr(path, "bbslist") || strstr(path, ".Search")
			|| strstr(path, ".Names") || strstr(path, "..")
			|| strstr(path, "SYSHome"))
		return BBS_EINVAL;

	char *bname = getbfroma(path);
	board_t board;
	if (!bname || *bname != '\0' || !get_board(bname, &board)
			|| !has_read_perm(&board)) {
		return BBS_ENOFILE;
	}

	char fname[512];
	sprintf(fname, "0Announce%s", path);
	xml_header(NULL);
	printf("<bbsanc ");
	if (board.id)
		printf(" brd='%s'", board.name);
	printf(">");
	print_session();
	printf("<po>");
	xml_printfile(fname);
	printf("</po></bbsanc>");
	return 0;
}
示例#9
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;
}
示例#10
0
int bbssel_main(void)
{
	xml_header("bbssel");
	printf("<bbssel ");
	print_session();
	printf(">");
	char *brd = getparm("brd");
	if (*brd != '\0') {
		struct boardheader *bp;
		int found = 0;
		for (int i = 0; i < MAXBOARD; i++) {
			bp = bcache + i;
			if (!hasreadperm(&currentuser, bp))
				continue;
			if (strcasestr(bp->filename, brd)
					|| strcasestr(bp->title, brd)) {
				printf("<brd dir='%d' title='%s' desc='%s' />",
						is_board_dir(bp), bp->filename, get_board_desc(bp));
				found++;
			}
		}
		if (!found)
			printf("<notfound />");
	}
	printf("</bbssel>");
	return 0;
}
示例#11
0
文件: ipl2tp.c 项目: AllardJ/Tomato
static int session_nlmsg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
{
	int ret = get_response(n, arg);

	if (ret == 0)
		print_session(arg);

	return ret;
}
示例#12
0
int bbsovr_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	xml_header("bbs");
	printf("<bbsovr ");
	print_session();
	printf(">");
	override_info();
	printf("</bbsovr>");
	return 0;
}
示例#13
0
文件: friend.c 项目: fbbs/fbbs
int bbsovr_main(void)
{
	if (!session_get_id())
		return BBS_ELGNREQ;
	xml_header(NULL);
	printf("<bbsovr>");
	print_session();

	show_sessions_of_friends();

	printf("</bbsovr>");
	return 0;
}
示例#14
0
int bbsfall_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	xml_header("bbs");
	printf("<bbsfall ");
	print_session();
	printf(">");
	char file[HOMELEN];
	sethomefile(file, currentuser.userid, "friends");
	apply_record(file, print_override, sizeof(override_t), NULL, false,
			false, true);
	printf("</bbsfall>");
	return 0;
}
示例#15
0
int bbsmybrd_main(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	int type = strtol(getparm("type"), NULL, 10);
	if (type != 0)
		return read_submit();

	// Read '.goodbrd'.
	char file[HOMELEN];
	sethomefile(file, currentuser.userid, ".goodbrd");
	mmap_t m;
	m.oflag = O_RDONLY;
	if (mmap_open(file, &m) < 0)
		return BBS_ENOFILE;
	struct goodbrdheader *iter, *end;
	int num = m.size / sizeof(struct goodbrdheader);
	if (num > GOOD_BRC_NUM)
		num = GOOD_BRC_NUM;
	end = (struct goodbrdheader *)m.ptr + num;

	// Print 'bid's of favorite boards.
	xml_header("bbs");
	printf("<bbsmybrd ");
	print_session();
	printf(" limit='%d'>", GOOD_BRC_NUM);
	for (iter = m.ptr; iter != end; iter++) {
		if (!gbrd_is_custom_dir(iter))
			printf("<my bid='%d'/>", iter->pos + 1);
	}
	mmap_close(&m);

	// Print all boards available.
	struct boardheader *b;
	for (int i = 0; i < MAXBOARD; i++) {
		b = bcache + i;
		if (b->filename[0] <= 0x20 || b->filename[0] > 'z')
			continue;
		if (!hasreadperm(&currentuser, b))
			continue;
		printf("<mbrd bid='%d' desc='%s' %s/>", i + 1, b->title + 11,
				is_board_dir(b) ? "dir='1'" : "");
	}
	printf("</bbsmybrd>");
	return 0;	
}
示例#16
0
int update_session_file_end(packetinfo *pi, signature *sig)
{
    files *tmpfiles;
    tmpfiles = pi->cxt->files;

    while (tmpfiles != NULL) {
        if ( tmpfiles->sig == sig) {
            if (ISSET_FILE_START(tmpfiles) && !ISSET_FILE_END(tmpfiles)) {
                if (ISSET_CONFIG_VERBOSE(config)) print_session(pi, sig->filetype);
                log_files_csv(pi, sig->filetype);
                SET_FILE_END(tmpfiles);
            }
            return 0;
        }
        tmpfiles = tmpfiles->next;
    }
    return 1;
}
示例#17
0
文件: friend.c 项目: fbbs/fbbs
int bbsfall_main(void)
{
	if (!session_get_id())
		return BBS_ELGNREQ;
	xml_header(NULL);
	printf("<bbsfall>");
	print_session();

	following_list_t *fl = following_list_load(session_get_user_id());
	if (fl) {
		for (int i = following_list_rows(fl) - 1; i >= 0; --i) {
			printf("<ov id='%s'>", following_list_get_name(fl, i));
			xml_fputs(following_list_get_notes(fl, i));
			printf("</ov>");
		}
	}

	printf("</bbsfall>");
	return 0;
}
示例#18
0
文件: prop.c 项目: caidongyun/fbbs
int web_props(void)
{
	if (!session_id())
		return BBS_ELGNREQ;

	prop_list_t *p = prop_list_load();
	if (!p)
		return BBS_EINTNL;

	xml_header(NULL);
	printf("<bbsprop>");
	print_session();
	for (int i = 0; i < prop_list_num_rows(p); ++i) {
		show_prop(p, i);
	}
	printf("</bbsprop>");

	prop_list_free(p);
	return 0;
}
示例#19
0
文件: board.c 项目: caidongyun/fbbs
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;
}
示例#20
0
/** Print a SDP description.
 *
 * Encode the contents of the SDP session structure #sdp_session_t
 * to the @a msgbuf. The @a msgbuf has size @a msgsize
 * bytes. If @a msgbuf is @c NULL, the sdp_print() function allocates the
 * required buffer from the @a home heap.
 *
 * @param home     Memory home (may be NULL).
 * @param session  SDP session description structure to be encoded.
 * @param msgbuf   Buffer to which encoding is stored (may be NULL).
 * @param msgsize  Size of @a msgbuf.
 * @param flags    Flags specifying the encoding options.
 *
 * The @a flags specify encoding options as follows:
 *
 * @li #sdp_f_strict - Printer should only emit messages conforming strictly
 * to the * specification.
 *
 * @li #sdp_f_realloc - If this flag is specified, and @a msgbuf is too
 * small for the resulting SDP message, @c sdp_print() may allocate a new
 * buffer for it from the heap.
 *
 * @li #sdp_f_print_prefix - The buffer provided by caller already contains
 * valid data. The result will concatenated to the string in the buffer.
 *
 * @li #sdp_f_mode_always - Always add mode attributes to media
 *
 * @li #sdp_f_mode_manual - Do not generate mode attributes
 *
 * @return
 * Always return a handle to an #sdp_printer_t object.
 *
 * @sa #sdp_printer_t, #sdp_session_t, sdp_printing_error(),
 * sdp_message(), sdp_message_size(), sdp_printer_free(),
 * sdp_parse().
 */
sdp_printer_t *sdp_print(su_home_t *home,
			 sdp_session_t const *session,
			 char msgbuf[],
			 isize_t msgsize,
			 int flags)
{
  sdp_printer_t *p = su_salloc(home, sizeof(*p));

  if (p) {
    p->pr_size = sizeof(p);
    p->pr_home = home;
    p->pr_used   = 0;
    if (msgbuf) {
      p->pr_may_realloc = (flags & sdp_f_realloc) != 0;
      p->pr_buffer = msgbuf;
      p->pr_bsiz   = msgsize;
      if (flags & sdp_f_print_prefix)
	p->pr_used = strlen(msgbuf);
    }
    else {
      p->pr_owns_buffer = 1;
      p->pr_buffer = su_alloc(home, SDP_BLOCK);
      p->pr_bsiz   = SDP_BLOCK;
    }
    p->pr_strict = (flags & sdp_f_strict) != 0;
    p->pr_all_rtpmaps = (flags & sdp_f_all_rtpmaps) != 0;
    p->pr_mode_manual = (flags & sdp_f_mode_manual) != 0;
    p->pr_mode_always = (flags & sdp_f_mode_always) != 0;

    if (session)
      print_session(p, session);
    else
      printing_error(p, "NULL session description");

    return p;
  }
  else {
    return &printer_memory_error;
  }
}
示例#21
0
文件: prop.c 项目: caidongyun/fbbs
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;
}
示例#22
0
文件: friend.c 项目: fbbs/fbbs
int bbsfadd_main(void)
{
	if (!session_get_id())
		return BBS_ELGNREQ;

	const char *uname = web_get_param("id");
	const char *note = web_get_param("desc");

	if (*uname) {
		UTF8_BUFFER(note, FOLLOW_NOTE_CCHARS);
		convert_g2u(note, utf8_note);

		follow(session_get_user_id(), uname, utf8_note);

		printf("Location: fall\n\n");
		return 0;
	}
	xml_header(NULL);
	printf("<bbsfadd>");
	print_session();
	printf("%s</bbsfadd>", uname);
	return 0;
}
示例#23
0
文件: prop.c 项目: caidongyun/fbbs
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;
}
示例#24
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;
}
示例#25
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;
}
示例#26
0
文件: procd_ps.c 项目: aunali1/exopc
void procd_ps2(void) {
  proc_p p;
  int i;
  pgrp_p pg;
  session_p s;
  fprintf(stderr,"proc_table: %p, envid: %d\n",proc_table,proc_table->procd_envid);

  for (i = 0; i < MAXPROC; i++) {
    fprintf(stderr,"%d ",(bit_test(proc_table->procs_used,i)) ?1:0);
    p = &proc_table->procs[i];
    print_proc(p);
  }
  for (i = 0; i < MAXPGRP; i++) {
    fprintf(stderr,"%d ",(bit_test(proc_table->pgrps_used,i)) ?1:0);
    pg = &proc_table->pgrps[i];
    print_pgrp(pg);
  }
  for (i = 0; i < MAXSESSION; i++) {
    fprintf(stderr,"%d ",(bit_test(proc_table->sessions_used,i)) ?1:0);
    s = &proc_table->sessions[i];
    print_session(s);
  }
  fprintf(stderr,"done\n");
}
示例#27
0
// TODO: Handle user-defined directories.
static int read_submit(void)
{
	if (!loginok)
		return BBS_ELGNREQ;
	if (parse_post_data() < 0)
		return BBS_EINVAL;

	// Read parameters.
	bool boards[MAXBOARD] = {0};
	int num = 0;
	for (int i = 0; i < param_num; i++) {
		if (!strcasecmp(param_val[i], "on")) {
			int bid = strtol(param_name[i], NULL, 10);
			if (bid > 0 && bid <= MAXBOARD
					&& hasreadperm(&currentuser, bcache + bid - 1)) {
				boards[bid - 1] = true;
				++num;
			}
		}
	}
	if (num > GOOD_BRC_NUM)
		return BBS_EBRDQE;
	if (num <= 0)
		return BBS_EINVAL;

	// Read '.goodbrd'.
	char file[HOMELEN];
	sethomefile(file, currentuser.userid, ".goodbrd");
	mmap_t m;
	m.oflag = O_RDWR;
	if (mmap_open(file, &m) < 0)
		return BBS_ENOFILE; // TODO: empty?
	if (mmap_truncate(&m, num * sizeof(struct goodbrdheader)) < 0) {
		return BBS_EINTNL;
	}
	struct goodbrdheader *iter, *end;
	end = (struct goodbrdheader *)m.ptr + num;

	// Remove deselected boards.
	struct goodbrdheader *dst = m.ptr;
	int id = 0;
	for (iter = m.ptr; iter != end; ++iter) {
		if (boards[iter->pos] == true) {
			boards[iter->pos] = false;
			id++;
			if (iter != dst) {
				iter->id = id;
				iter->pid = 0;
				*dst = *iter;
			}
			++dst;
		}
	}

	// Write out newly selected boards.
	for (int i = 0; i < MAXBOARD; ++i) {
		if (boards[i] == true) {
			id++;
			if (id > GOOD_BRC_NUM)
				break;
			dst->id = num;
			dst->pid = 0;
			dst->pos = i;
			dst->flag = bcache[i].flag;
			strlcpy(dst->filename, bcache[i].filename, sizeof(dst->filename));
			strlcpy(dst->title, bcache[i].title, sizeof(dst->title));
			++dst;
		}
	}
	mmap_close(&m);
	xml_header("bbs");
	printf("<bbsmybrd ");
	print_session();
	printf(" limit='%d' selected='%d'></bbsmybrd>", GOOD_BRC_NUM, num);
	return 0;
}
示例#28
0
文件: bbsann.c 项目: caidongyun/fbbs
int bbs0an_main(void)
{
	char path[512];
	board_t board;
	int bid = strtol(web_get_param("bid"), NULL, 10);
	if (bid <= 0) {
		strlcpy(path, web_get_param("path"), sizeof(path));
		if (strstr(path, "..") || strstr(path, "SYSHome"))
			return BBS_EINVAL;
		char *bname = getbfroma(path);
		if (*bname != '\0') {
			if (!get_board(bname, &board) || !has_read_perm(&board))
				return BBS_ENODIR;
		}
	} else {
		if (!get_board_by_bid(bid, &board) || !has_read_perm(&board))
			return BBS_ENOBRD;
		if (board.flag & BOARD_FLAG_DIR)
			return BBS_EINVAL;

		path[0] = '\0';
		FILE *fp = fopen("0Announce/.Search", "r");
		if (fp == NULL)
			return BBS_EINTNL;
		char tmp[256];
		int len = strlen(board.name);
		while (fgets(tmp, sizeof(tmp), fp) != NULL) {
			if (!strncmp(tmp, board.name, len) && tmp[len] == ':'
					&& tmp[len + 1] == ' ') {
				tmp[len + 1] = '/';
				strlcpy(path, tmp + len + 1, sizeof(path));
				path[strlen(path) - 1] = '\0';
				break;
			}
		}
		fclose(fp);
		if (path[0] == '\0')
			return BBS_ENODIR;
	}
	char names[512];
	snprintf(names, sizeof(names), "0Announce%s/.Names", path);
	FILE *fp = fopen(names, "r");
	if (fp == NULL)
		return BBS_ENODIR; // not indicating hidden directories.
	char buf[512], *title;
	// check directory permission.
	while (true) {
		if (fgets(buf, sizeof(buf), fp) == NULL) {
			fclose(fp);
			return BBS_ENODIR;
		}
		if(!strncmp(buf, "# Title=", 8)) {
			title = buf + 8;
			if (!hasannperm(title, &currentuser, &board)) {
				fclose(fp);
				return BBS_ENODIR;
			}
			break;
		}
	}

	xml_header(NULL);
	printf("<bbs0an path='%s' v='%d' ", path, 1030);
	if (board.id)
		printf(" brd='%s'", board.name);
	printf(">");
	print_session();
	
	char name[STRLEN], fpath[1024], *id = NULL, *ptr;
	struct stat st;
	while (fgets(buf, sizeof(buf), fp) != NULL) {
		if (!strncmp(buf, "Name=", 5)) {
			strlcpy(name, trim(buf + 5), sizeof(name));
			if (strlen(name) > ANN_TITLE_LENGTH) {
				id = name + ANN_TITLE_LENGTH;
				if (!hasannperm(name + ANN_TITLE_LENGTH, &currentuser, &board))
					continue;
				name[ANN_TITLE_LENGTH -  1] = '\0';
				if (!strncmp(id, "BM: ", 4))
					id += 4;
				if ((ptr = strchr(id, ')')) != NULL)
					*ptr = '\0';
			} else {
				id = NULL;
			}
			if (fgets(buf, sizeof(buf), fp) == NULL || strncmp(buf, "Path=~", 6)) {
				break;
			} else {
				printf("<ent path='%s' t='", trim(buf + 6));
				snprintf(fpath, sizeof(fpath), "0Announce%s%s", path, buf + 6);
				if (stat(fpath, &st) != 0 || (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode))) {
					printf("e'");
				} else if (S_ISREG(st.st_mode)) {
					printf("f'");
				} else {
					printf("d'");
				}
				if (id != NULL)
					printf(" id='%s'", id);
				printf(" time='%s'>", format_time(st.st_mtime, TIME_FORMAT_XML));
				xml_fputs4(trim(name), 0);
				printf("</ent>");
			}
		}
	}
	fclose(fp);
	puts("</bbs0an>");
	return 0;
}
示例#29
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;
}
示例#30
0
文件: sdp.c 项目: tibastral/symphonie
/*
 * Print SDP description.
 */
PJ_DEF(int) pjmedia_sdp_print( const pjmedia_sdp_session *desc, 
			       char *buf, pj_size_t size)
{
    return print_session(desc, buf, size);
}