Пример #1
0
Файл: surf.c Проект: sr/surf
int main(int argc, char *argv[]) {
    gchar *uri = NULL, *file = NULL;
    SoupSession *s;
    Client *c;
    int o;
    const gchar *home, *filename;

    gtk_init(NULL, NULL);
    if (!g_thread_supported())
        g_thread_init(NULL);
    setup();
    while((o = getopt(argc, argv, "vhxeu:f:")) != -1)
        switch(o) {
        case 'x':
            showxid = TRUE;
            break;
        case 'e':
            showxid = TRUE;
            embed = TRUE;
            break;
        case 'u':
            if(!(uri = optarg))
                goto argerr;
            c = newclient();
            loaduri(c, uri);
            updatetitle(c);
            break;
        case 'f':
            if(!(file = optarg))
                goto argerr;
            c = newclient();
            loadfile(c, file);
            updatetitle(c);
            break;
        case 'v':
            die("surf-"VERSION", © 2009 surf engineers, see LICENSE for details\n");
            break;
argerr:
        default:
            puts("surf - simple browser");
            die("usage: surf [-e] [-x] [-u uri] [-f file]\n");
            return EXIT_FAILURE;
        }
    if(optind != argc)
        goto argerr;
    if(!clients)
        newclient();

    /* cookie persistance */
    s = webkit_get_default_session();
    home = g_get_home_dir();
    filename = g_build_filename(home, ".surf-cookies", NULL);
    cookiejar = soup_cookie_jar_text_new(filename, FALSE);
    soup_session_add_feature(s, SOUP_SESSION_FEATURE(cookiejar));

    gtk_main();
    cleanup();
    return EXIT_SUCCESS;
}
Пример #2
0
    void init(fpsent *d, int at, int ocn, int sk, int bn, int pm, const char *name, const char *team)
    {
        loadwaypoints();

        fpsent *o = newclient(ocn);

        d->aitype = at;

        bool resetthisguy = false;
        if(!d->name[0])
        {
            if(aidebug) conoutf("%s assigned to %s at skill %d", colorname(d, name), o ? colorname(o) : "?", sk);
            else conoutf("connected: %s", colorname(d, name));
            resetthisguy = true;
        }
        else
        {
            if(d->ownernum != ocn)
            {
                if(aidebug) conoutf("%s reassigned to %s", colorname(d, name), o ? colorname(o) : "?");
                resetthisguy = true;
            }
            if(d->skill != sk && aidebug) conoutf("%s changed skill to %d", colorname(d, name), sk);
        }

        copystring(d->name, name, MAXNAMELEN+1);
        copystring(d->team, team, MAXTEAMLEN+1);
        d->ownernum = ocn;
        d->skill = sk;
        d->playermodel = chooserandomplayermodel(pm);

        if(resetthisguy) removeweapons(d);
        if(player1->clientnum == d->ownernum) create(d);
        else if(d->ai) destroy(d);
    }
Пример #3
0
bool			TCPLinServSocket::SearchNewClients(Selector &sel)
{
	SOCKET		newclientsocket;
	int			highestid = 1;
	struct sockaddr_in	s_in;
	socklen_t		s_size;

	s_size = sizeof(s_in);
	if ((sel.Is_readable(_fathersocket)) == true)
	{
		if ((newclientsocket = accept(_fathersocket, (struct sockaddr *)&s_in, &s_size)) == INVALID_SOCKET)
		{
			std::cerr << "Couldn't accept a new client" << std::endl;
			return (false);
		}
		sel.Add_to_checkread(newclientsocket);
		sel.Add_to_checkwrite(newclientsocket);
		for (size_t i = 0; i < _clients.size(); i++)
		if (_clients[i].get_id() >= highestid)
			highestid = _clients[i].get_id() + 1;

		Client	newclient(newclientsocket, highestid);
		_clients.push_back(newclient);
	}
	return (true);
}
Пример #4
0
bool		TCPWinServSocket::SearchNewClients(Selector &sel)
{
	SOCKET	newclientsocket;
	int		highestid = 1;

	if ((sel.Is_readable(_fathersocket)) == true)
	{
		if ((newclientsocket = WSAAccept(_fathersocket, NULL, NULL, NULL, NULL)) == INVALID_SOCKET)
		{
			std::cerr << "Couldn't accept a new client" << std::endl;
			return (false);
		}
		sel.Add_to_checkread(newclientsocket);
		sel.Add_to_checkwrite(newclientsocket);

		for (size_t i = 0; i < _clients.size(); i++)
			if (_clients[i].get_id() >= highestid)
				highestid = _clients[i].get_id() + 1;
		
		Client	newclient(newclientsocket, highestid);

		_clients.push_back(newclient);
	}
	return (true);
}
Пример #5
0
Файл: surf.c Проект: qbbr/debian
void
newwindow(Client *c, const Arg *arg) {
	guint i = 0;
	const char *cmd[7], *uri;
	const Arg a = { .v = (void *)cmd };
	char tmp[64];

	cmd[i++] = progname;
	if(embed) {
		cmd[i++] = "-e";
		snprintf(tmp, LENGTH(tmp), "%u\n", (int)embed);
		cmd[i++] = tmp;
	}
	if(showxid) {
		cmd[i++] = "-x";
	}
	cmd[i++] = "--";
	uri = arg->v ? (char *)arg->v : autouri(c);
	if(uri)
		cmd[i++] = uri;
	cmd[i++] = NULL;
	spawn(NULL, &a);
}

WebKitWebView *
createwindow(WebKitWebView  *v, WebKitWebFrame *f, Client *c) {
	Client *n = newclient();
	return n->view;
}
Пример #6
0
void MessageWind::initserver()     //初始化服务器
{
    server=new QTcpServer(this);
    if(!server->listen(QHostAddress::Any,1573))
        {
            QMessageBox::critical(this,tr("服务器监听错误!"),server->errorString());
            exit(1);
        }
    connect(server,SIGNAL(newConnection()),this,SLOT(newclient()));
}
Пример #7
0
    void init(fpsent *d, int at, int ocn, int sk, int bn, int pm, int pc, const char *name, const char *team)
    {
        loadwaypoints();

        fpsent *o = newclient(ocn);

        d->aitype = at;

        bool resetthisguy = false;
        if(!d->name[0])
        {
            if(aidebug) conoutf("%s assigned to %s at skill %d", colorname(d, name), o ? colorname(o) : "?", sk);
            else conoutf("\f0join:\f7 %s", colorname(d, name));
            resetthisguy = true;
        }
        else
        {
            if(d->ownernum != ocn)
            {
                if(aidebug) conoutf("%s reassigned to %s", colorname(d, name), o ? colorname(o) : "?");
                resetthisguy = true;
            }
            if(d->skill != sk && aidebug) conoutf("%s changed skill to %d", colorname(d, name), sk);
        }

        copystring(d->name, name, MAXNAMELEN+1);
        copystring(d->team, team, MAXTEAMLEN+1);
        d->ownernum = ocn;
        d->skill = sk;
        d->playermodel = chooserandomplayermodel(pm);
		if(pc < NUMPCS) d->pclass = pc;
		else conoutf("ERROR: %d", pc);

        if(resetthisguy) removeweapons(d);
        if(d->ownernum >= 0 && player1->clientnum == d->ownernum)
        {
            create(d);
            if(d->ai)
            {
                d->ai->views[0] = viewfieldx(d->skill);
                d->ai->views[1] = viewfieldy(d->skill);
                d->ai->views[2] = viewdist(d->skill);
            }
        }
        else if(d->ai) destroy(d);
    }
Пример #8
0
AccepterID CTcpSessionManager::AddAcceptor(const tagAcceptorConfigTraits &traits)
{
	if (m_mapAccepterConfig.find(traits.aID) != m_mapAccepterConfig.end() || traits.aID == InvalidAccepterID)
	{
		LOGE("AddAcceptor confilict AccecptID. traits=" << traits);
		return InvalidAccepterID;
	}
	m_mapAccepterConfig[traits.aID].first = traits;
	CTcpAcceptPtr accepter(new zsummer::network::CTcpAccept(m_summer));
	if (!accepter->OpenAccept(traits.listenIP.c_str(), traits.listenPort))
	{
		LOGE("AddAcceptor OpenAccept Failed. traits=" << traits);
		return InvalidAccepterID;
	}
	m_mapAccepterPtr[traits.aID] = accepter;
	CTcpSocketPtr newclient(new zsummer::network::CTcpSocket);
	newclient->Initialize(m_summer);
	accepter->DoAccept(newclient, std::bind(&CTcpSessionManager::OnAcceptNewClient, this, std::placeholders::_1, std::placeholders::_2, accepter, traits.aID));
	return  traits.aID;
}
Пример #9
0
/* Process an incoming tftp packet */
void process( struct sockaddr_in *fromp, struct tftphdr *tp, int cc ) {
	Client *cl;

	/* Look for old session */
	cl = findclient( fromp );

	if (cl == NULL) {
		cl = newclient();
		if (cl == NULL) return;
		cl->sin = *fromp;
		cl->dynam = 0;
		cl->proc = CP_TFTP;
		/* log(LOG_DEBUG, "%s.%d starting", cl->s_ipaddr, cl->sin.sin_port); */
	}
	cl->tp = tp;
	cl->tpcc = cc;

	/* Start up this client */
	runclient( cl );
}
Пример #10
0
WebKitWebView *
createwindow(WebKitWebView  *v, WebKitWebFrame *f, Client *c) {
	Client *n = newclient();
	return n->view;
}
Пример #11
0
void CTcpSessionManager::OnAcceptNewClient(zsummer::network::ErrorCode ec, CTcpSocketPtr s, CTcpAcceptPtr accepter, AccepterID aID)
{
	auto iter = m_mapAccepterConfig.find(aID);
	if (iter == m_mapAccepterConfig.end())
	{
		LOGE("Unknown DoAccept Result Error. ec=" << ec << ", aID=" << aID);
		return;
	}
	if (ec)
	{
		LOGE("DoAccept Result Error. ec=" << ec << ", traits=" << iter->second.first);
		return;
	}
	


	std::string remoteIP;
	unsigned short remotePort = 0;
	s->GetPeerInfo(remoteIP, remotePort);
	
	//! check white list
	//! ---------------------
	if (!iter->second.first.whitelistIP.empty())
	{
		bool checkSucess = false;
		for (auto white : iter->second.first.whitelistIP)
		{
			if (remoteIP.size() >= white.size())
			{
				if (remoteIP.compare(0,white.size(), white) == 0)
				{
					checkSucess = true;
					break;
				}
			}
		}

		if (!checkSucess)
		{
			LOGW("Accept New Client Check Whitelist Failed remoteAdress=" << remoteIP << ":" << remotePort
				<< ", trais=" << iter->second.first);

			CTcpSocketPtr newclient(new zsummer::network::CTcpSocket);
			newclient->Initialize(m_summer);
			accepter->DoAccept(newclient, std::bind(&CTcpSessionManager::OnAcceptNewClient, this, std::placeholders::_1, std::placeholders::_2, accepter, aID));
			return;
		}
		else
		{
			LOGI("Accept New Client Check Whitelist Success remoteAdress=" << remoteIP << ":" << remotePort
				<< ", trais=" << iter->second.first);
		}
	}
	
	//! check Max Sessions

	if (iter->second.second.currentLinked >= iter->second.first.maxSessions)
	{
		LOGW("Accept New Client. Too Many Sessions And The new socket will closed. remoteAddress=" << remoteIP << ":" << remotePort 
			<< ", Aready linked sessions = " << iter->second.second.currentLinked << ", trais=" << iter->second.first);
	}
	else
	{
		LOGD("Accept New Client. Accept new Sessions. The new socket  remoteAddress=" << remoteIP << ":" << remotePort 
			<< ", Aready linked sessions = " << iter->second.second.currentLinked << ", trais=" << iter->second.first);
		iter->second.second.currentLinked++;
		iter->second.second.totalAcceptCount++;
		BindEstablishedSocketPtr(s, aID);
	}
	
	//! accept next socket.
	CTcpSocketPtr newclient(new zsummer::network::CTcpSocket);
	newclient->Initialize(m_summer);
	accepter->DoAccept(newclient, std::bind(&CTcpSessionManager::OnAcceptNewClient, this, std::placeholders::_1, std::placeholders::_2, accepter,aID));
}
Пример #12
0
int
main()
{
    char fnamebuf[MAXPATHLEN];
    int s;
    int c;
    int count;
    int rc;
    struct sockaddr_un srvaddr;
    struct sockaddr_un clientaddr;
    int r;
    int len;
    mode_t oldumask;
    char *pid_file = _PATH_PWCHECKPID;
    FILE *fp = NULL;
    pid_t pid;

    openlog("pwcheck", LOG_NDELAY, LOG_AUTH);

    /* Daemonize. */
    count = 5;
    while (count--) {
	pid = fork();
            
	if (pid > 0)
	    _exit(0);               /* parent dies */
            
	if ((pid == -1) && (errno == EAGAIN)) {
	    syslog(LOG_WARNING, "master fork failed (sleeping): %m");
	    sleep(5);
	    continue;
	}
    }
    if (pid == -1) {
	rc = errno;
	syslog(LOG_ERR, "FATAL: master fork failed: %m");
	fprintf(stderr, "pwcheck: ");
	errno = rc;
	perror("fork");
	exit(1);
    }

    /*
     * We're now running in the child. Lose our controlling terminal
     * and obtain a new process group.
     */
    if (setsid() == -1) {
	rc = errno;
	syslog(LOG_ERR, "FATAL: setsid: %m");
	fprintf(stderr, "pwcheck: ");
	errno = rc;
	perror("setsid");
	exit(1);
    }
        
    s = open("/dev/null", O_RDWR, 0);
    if (s == -1) {
	rc = errno;
	syslog(LOG_ERR, "FATAL: /dev/null: %m");
	fprintf(stderr, "pwcheck: ");
	errno = rc;
	perror("/dev/null");
	exit(1);
            
    }
    dup2(s, fileno(stdin));
    dup2(s, fileno(stdout));
    dup2(s, fileno(stderr));
    if (s > 2) {
	close(s);
    }

    /*
     *   Record process ID - shamelessly stolen from inetd (I.V.)
     */
    pid = getpid();
    if (pid_file) {
	fp = fopen(pid_file, "w");
    }
    if (fp) {
        fprintf(fp, "%ld\n", (long)pid);
        fclose(fp);
    } else if (pid_file) {
        syslog(LOG_WARNING, "%s: %m", pid_file);
    }

    s = socket(AF_UNIX, SOCK_STREAM, 0);
    if (s == -1) {
	perror("socket");
	exit(1);
    }

    strncpy(fnamebuf, PWCHECKDIR, sizeof(fnamebuf));
    strncpy(fnamebuf + sizeof(PWCHECKDIR)-1, "/pwcheck",
	    sizeof(fnamebuf) - sizeof(PWCHECKDIR));
    fnamebuf[MAXPATHLEN-1] = '\0';

    (void) unlink(fnamebuf);

    memset((char *)&srvaddr, 0, sizeof(srvaddr));
    srvaddr.sun_family = AF_UNIX;
    strncpy(srvaddr.sun_path, fnamebuf, sizeof(srvaddr.sun_path));
    /* Most systems make sockets 0777 no matter what you ask for.
       Known exceptions are Linux and DUX. */
    oldumask = umask((mode_t) 0); /* for Linux, which observes the umask when
			    setting up the socket */
    r = bind(s, (struct sockaddr *)&srvaddr, sizeof(srvaddr));
    if (r == -1) {
	syslog(LOG_ERR, "%.*s: %m",
	       sizeof(srvaddr.sun_path), srvaddr.sun_path);
	exit(1);
    }
    umask(oldumask); /* for Linux */
    chmod(fnamebuf, (mode_t) 0777); /* for DUX, where this isn't the default.
				    (harmlessly fails on some systems) */	
    r = listen(s, 5);
    if (r == -1) {
	syslog(LOG_ERR, "listen: %m");
	exit(1);
    }

    for (;;) {
	len = sizeof(clientaddr);
	c = accept(s, (struct sockaddr *)&clientaddr, &len);
	if (c == -1 && errno != EINTR) {
	    syslog(LOG_WARNING, "accept: %m");
	    continue;
	}

	newclient(c);
    }
}
Пример #13
0
Файл: surf.c Проект: sr/surf
WebKitWebView *
newwindow(WebKitWebView  *v, WebKitWebFrame *f, gpointer d) {
    /* TODO */
    Client *c = newclient();
    return c->view;
}