Esempio n. 1
0
File: sf.c Progetto: heuripedes/sf
static void perform() {

    fd_set fdread, fdwrite, fdexcep;
    int ret;
    int maxfd;
    int connections = 0;

    select_timeout.tv_sec  = 0;
    select_timeout.tv_usec = 50000;

    do {
        do {
            ret = check_multi(curl_multi_perform(curlm, &connections),
                              "curl_multi_perform() failed");
        } while (ret == CURLM_CALL_MULTI_PERFORM);

        if (show_progress) {
            print_progress();
        }

        if (connections) {
            size_t i;

            for (i = 0; i < num_slices; ++i) {
                if (slices[i].finished)
                    slice_finalize(&slices[i]);
            }

            FD_ZERO(&fdread);
            FD_ZERO(&fdwrite);
            FD_ZERO(&fdexcep);

            check_multi(curl_multi_fdset(curlm, &fdread, &fdwrite, &fdexcep, &maxfd),
                        "curl_multi_fdset() failed");

            ret = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &select_timeout);

            if (ret == -1)
                die("select() error: %s\n", strerror(errno));
        }

    } while (connections);

    size_t i;
    for (i = 0; i < num_slices; ++i) {
        if (slices[i].curl)
            slice_finalize(&slices[i]);
    }
}
Esempio n. 2
0
File: sf.c Progetto: heuripedes/sf
static void init_slices(size_t begin, size_t end) {
    size_t size = end - begin;
    size_t how_many = num_slices;

    if (begin == 0 && end == 0)
        how_many = 1;

    size_t slice_size = size / how_many;
    size_t i;

    for (i = 0; i < how_many; i++) {
        Slice *slice = &slices[i];

        slice->id    = i;
        slice->begin = begin + slice_size * i;
        slice->end   = slice->begin + slice_size;
        slice->finished = 0;

        /* make sure to call this function before any slice_write() */
        slice->pos   = 0;

        if (i == how_many-1)
            slice->end = end;

        if (slice->curl == NULL) {
            slice_initialize(slice);

            check_multi(curl_multi_add_handle(curlm, slice->curl),
                        "failed to add the handle");
        }
    }
}
Esempio n. 3
0
int main() {
  int ret;

  if ( (ret=check_simple()) != 0) { return ret; }
  if ( (ret=check_multi()) != 0)  { return ret; }

  return 0;
}
Esempio n. 4
0
char *
wwwlogin(struct userec *user, int ipmask)
{
	FILE *fp, *fp1;
	int n, dolog = 0, st, clubnum, uid, i, nsearch;
	struct user_info *u;
	char ULIST[STRLEN];
	char genbuf[256], *urlbase, fname[80];
	uid = getusernum(user->userid) + 1;

	if ((urlbase = check_multi(user->userid, uid)))
		return urlbase;

	if (strcasecmp(user->userid, "guest") && count_uindex(uid) >= 3)
		http_fatal("您已经登录了三个帐号,不能再登录了");
//      如果要限制WWW登录窗口数 就打开这个注释. lepton

	gethostname(genbuf, 256);
	sprintf(ULIST, MY_BBS_HOME "/%s.%s", ULIST_BASE, genbuf);

	fp = fopen(ULIST, "a");
	flock(fileno(fp), LOCK_EX);
	nsearch = NSEARCH;
	//if (strcasecmp(user->userid, "guest"))
	//      nsearch = MAXACTIVE / 4;
	for (i = 0, n = iphash(fromhost) * (MAXACTIVE / NHASH); i < nsearch;
	     i++, n++) {
		if (n >= MAXACTIVE)
			n = 0;
		u = &(shm_utmp->uinfo[n]);
		if (u->active && u->pid == 1
		    && ((now_t - u->lasttime) > 20 * 60 || u->wwwinfo.iskicked)) {
			st = u->lasttime - u->wwwinfo.login_start_time;
			if (st > 86400) {
				errlog("Strange long stay time,%d!, drop %s",
				       st, u->userid);
				st = 86400;
			}
			sprintf(genbuf, "%s drop %d www", u->userid, st);
			newtrace(genbuf);
			remove_uindex(u->uid, n + 1);
			bzero(u, sizeof (struct user_info));
		}
		if (!dolog && u->active == 0) {
			u_info = u;
			bzero(u, sizeof (struct user_info));
			u->active = 1;
			u->uid = uid;
			u->pid = 1;
			//u->pid = thispid;			//modify by mintbaggio@BMY for kill www user
			u->mode = LOGIN;
			if (strcasecmp(user->userid, "guest"))
				u_info->unreadmsg = get_unreadmsg(user->userid);
			else
				u_info->unreadmsg = 0;
			u->userlevel = user->userlevel;
			u->lasttime = now_t;
			u->curboard = 0;
			if (user_perm(user, PERM_LOGINCLOAK) &&
			    (user->flags[0] & CLOAK_FLAG))
				u->invisible = YEA;
			u->pager = 0;
			if (user->userdefine & DEF_FRIENDCALL)
				u->pager |= FRIEND_PAGER;
			if (user->flags[0] & PAGER_FLAG) {
				u->pager |= ALL_PAGER;
				u->pager |= FRIEND_PAGER;
			}
			if (user->userdefine & DEF_FRIENDMSG)
				u->pager |= FRIENDMSG_PAGER;
			if (user->userdefine & DEF_ALLMSG) {
				u->pager |= ALLMSG_PAGER;
				u->pager |= FRIENDMSG_PAGER;
			}
			strsncpy(u->from, fromhost, 24);
			strsncpy(u->username, user->username, NAMELEN);
			strsncpy(u->userid, user->userid, IDLEN + 1);
			getrandomstr(u->sessionid);
			if (strcasecmp(user->userid, "guest"))
				initfriends(u);
			else
				memset(u->friend, 0, sizeof (u->friend));
			urlbase = makeurlbase(n);
			w_info = &(u_info->wwwinfo);
			w_info->login_start_time = now_t;
			w_info->ipmask = ipmask;
			if (strcasecmp(user->userid, "guest")) {
				sethomefile(fname, user->userid, "clubrights");
				if ((fp1 = fopen(fname, "r")) == NULL) {
					memset(u_info->clubrights, 0,
					       4 * sizeof (int));
				} else {
					while (fgets(genbuf, STRLEN, fp1) !=
					       NULL) {
						clubnum = atoi(genbuf);
						u_info->clubrights[clubnum /
								   32] |=
						    (1 << clubnum % 32);
					}
					fclose(fp1);
				}

				set_my_cookie();
			} else {
				memset(u_info->clubrights, 0, 4 * sizeof (int));
				w_info->t_lines = 20;
				w_info->att_mode = 0;
				w_info->doc_mode = 1;
			}
			dolog = 1;
			add_uindex(u->uid, n + 1);
		}
	}
Esempio n. 5
0
int bbslogin_main(void)
{
	char fname[STRLEN];
	char buf[256], id[IDLEN + 1], pw[PASSLEN];
	struct userec user;

	if (parse_post_data() < 0)
		return BBS_EINVAL;
	strlcpy(id, getparm("id"), sizeof(id));
	if (*id == '\0')
		return login_screen();
	strlcpy(pw, getparm("pw"), sizeof(pw));
	if (loginok && !strcasecmp(id, currentuser.userid)) {
		const char *ref = get_login_referer();
		printf("Location: %s\n\n", ref);
		return 0;
	}
	if (getuserec(id, &user) == 0)
		return BBS_ENOUSR;

	user.numlogins++;
	if (strcasecmp(id, "guest")) {
		int total;
		time_t stay, recent, now, t;
		if (!checkpasswd(user.passwd, pw)) {
			sprintf(buf, "%-12.12s %s @%s\n", user.userid,
					getdatestring(time(NULL), DATE_ZH), fromhost);
			sethomefile(fname, user.userid, "logins.bad"); 
			file_append(fname, buf);
			file_append("logins.bad", buf);
			return BBS_EWPSWD;
		}

		total = check_multi(&user);
		if (!HAS_PERM2(PERM_SYSOPS, &user) && total >= 2)
			return BBS_ELGNQE;

		if (!HAS_PERM2(PERM_LOGIN, &user))
			return BBS_EACCES;

		now = time(NULL);
		// Do not count frequent logins.
		if (now - user.lastlogin < 20 * 60
				&& user.numlogins >= 100)
			user.numlogins--;
		if (total > 1) {
			recent = user.lastlogout;
			if (user.lastlogin > recent)
				recent = user.lastlogin;
			stay = now - recent;
			if (stay < 0)
				stay = 0;
		} else {
			stay = 0;
		}
		t = user.lastlogin;
		user.lastlogin = now;
		user.stay += stay;
#ifdef CHECK_FREQUENTLOGIN
		if (!HAS_PERM(PERM_SYSOPS)
				&& abs(t - time(NULL)) < 10) {
			report("Too Frequent", user.userid);
			return BBS_ELFREQ;
		}
#endif
		strlcpy(user.lasthost, fromhost, sizeof(user.lasthost));
		save_user_data(&user);
		currentuser = user;
	}

	log_usies("ENTER", fromhost, &user);
	if (!loginok && strcasecmp(id, "guest"))
		wwwlogin(&user, getparm("ref"));
	return 0;
}
Esempio n. 6
0
char *
wwwlogin(struct userec *user, int ipmask)
{
	FILE *fp1;
	int fd;
	int n, uid;
	struct user_info u;
	char *urlbase, fname[80];
	char buf[20];
	uid = getuser(user->userid, NULL);
	fd = open(MY_BBS_HOME "/" ULIST_BASE "." MY_BBS_DOMAIN, O_WRONLY);
	flock(fd, LOCK_EX);

	if ((urlbase = check_multi(user->userid, uid))) {
		flock(fd, LOCK_UN);
		close(fd);
		return urlbase;
	}

	if (strcasecmp(user->userid, "guest") && count_uindex(uid) >= 3) {
		flock(fd, LOCK_UN);
		close(fd);
		http_fatal("您已经登录了三个帐号,不能再登录了");
	}
	bzero(&u, sizeof (struct user_info));
	u.active = 1;
	u.uid = uid;
	u.pid = 1;
	u.mode = LOGIN;
	u.userlevel = user->userlevel;
	u.lasttime = now_t;
	u.curboard = 0;
	if (user_perm(user, PERM_LOGINCLOAK) && (user->flags[0] & CLOAK_FLAG))
		u.invisible = YEA;
	u.pager = 0;
	if (user->userdefine & DEF_FRIENDCALL)
		u.pager |= FRIEND_PAGER;
	if (user->flags[0] & PAGER_FLAG) {
		u.pager |= ALL_PAGER;
		u.pager |= FRIEND_PAGER;
	}
	if (user->userdefine & DEF_FRIENDMSG)
		u.pager |= FRIENDMSG_PAGER;
	if (user->userdefine & DEF_ALLMSG) {
		u.pager |= ALLMSG_PAGER;
		u.pager |= FRIENDMSG_PAGER;
	}
	strsncpy(u.from, fromhost, sizeof (u.from));
	u.fromIP = from_addr.s_addr;
	strsncpy(u.username, user->username, NAMELEN);
	strsncpy(u.userid, user->userid, IDLEN + 1);
	getrandomstr(u.sessionid);
	n = utmp_login(&u);
	if (n > MAXACTIVERUN || n <= 0) {
		flock(fd, LOCK_UN);
		close(fd);
		http_fatal
		    ("抱歉,目前在线用户数已达上限%d,无法登录。请稍后再来。",
		     MAXACTIVERUN);
	}
	flock(fd, LOCK_UN);
	close(fd);
	n--;
	urlbase = makeurlbase(n, uid);
	u_info = &(shm_utmp->uinfo[n]);
	w_info = &(u_info->wwwinfo);
	w_info->login_start_time = now_t;
	w_info->ipmask = ipmask;
	if (strcasecmp(user->userid, "guest")) {
		u_info->unreadmsg = get_unreadcount(user->userid);
		initfriends(u_info);
		sethomefile(fname, user->userid, "clubrights");
		if ((fp1 = fopen(fname, "r")) == NULL) {
			memset(u_info->clubrights, 0, CLUB_SIZE * sizeof (int));
		} else {
			fread(&(u_info->clubrights), sizeof (int), CLUB_SIZE,
			      fp1);
			fclose(fp1);
		}
		if (readuservalue(user->userid, "signature", buf, sizeof (buf))
		    >= 0)
			u_info->signature = atoi(buf);
		w_info->edit_mode = 1;
		set_my_cookie();
	} else {
		u_info->unreadmsg = 0;
		memset(u_info->friend, 0, sizeof (u.friend));
		memset(u_info->clubrights, 0, CLUB_SIZE * sizeof (int));
		w_info->t_lines = 20;
		w_info->att_mode = 0;
		w_info->doc_mode = 1;
	}

	if ((user->userlevel & PERM_BOARDS))
		setbmstatus(user, 1);
	return urlbase;
}