⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servhs.cpp

📁 这是和p2p相关的一份源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			sock->writeLine("Last-Modified: Fri, 05 Jul 2002 08:20:08 GMT");			sock->writeLine("Cache-Control: must-revalidate");			sock->writeLine("Content-length: 360");			sock->writeLine("Date: Wed, 18 Sep 2002 08:16:24 GMT");			sock->writeLine("Expires: Wed, 18 Sep 2002 08:16:24 GMT");			sock->writeLine("Content-Type: application/sdp");			sock->writeLine("x-Accept-Retransmit: our-retransmit");			sock->writeLine("x-Accept-Dynamic-Rate: 1");			sock->writeLine("Content-Base: rtsp://localhost/test.mov/");			sock->writeLine("v=0");			sock->writeLine("o=StreamingServer 3241325783 1025857208000 IN IP4 192.168.1.3");			sock->writeLine("s=\test.mov");			sock->writeLine("u=http:///");			sock->writeLine("e=admin@");			sock->writeLine("c=IN IP4 0.0.0.0");			sock->writeLine("b=AS:288");			sock->writeLine("t=0 0");			sock->writeLine("a=control:*");			sock->writeLine("a=range:npt=0-  66.47000");			sock->writeLine("m=audio 0 RTP/AVP 96");			sock->writeLine("b=AS:21");			sock->writeLine("a=rtpmap:96 X-QDM/44100/2");			sock->writeLine("a=control:trackID=3");			sock->writeLine("a=x-bufferdelay:5.99");			sock->writeLine("m=video 0 RTP/AVP 97");			sock->writeLine("b=AS:267");			sock->writeLine("a=rtpmap:97 X-SV3V-ES/90000");			sock->writeLine("a=control:trackID=4");		}	}#endif}#if 0RTSP/1.0 200 OKServer: DSS/4.1.1 (Build/412.36; Platform/Win32)Cseq:Last-Modified: Fri, 05 Jul 2002 08:20:08 GMTCache-Control: must-revalidateContent-length: 360Date: Wed, 18 Sep 2002 08:16:24 GMTExpires: Wed, 18 Sep 2002 08:16:24 GMTContent-Type: application/sdpx-Accept-Retransmit: our-retransmitx-Accept-Dynamic-Rate: 1Content-Base: rtsp://localhost/test.mov/v=0o=StreamingServer 3241325783 1025857208000 IN IP4 192.168.1.3s=\test.movu=http:///e=admin@c=IN IP4 0.0.0.0b=AS:288t=0 0a=control:*a=range:npt=0-  66.47000m=audio 0 RTP/AVP 96b=AS:21a=rtpmap:96 X-QDM/44100/2a=control:trackID=3a=x-bufferdelay:5.99m=video 0 RTP/AVP 97b=AS:267a=rtpmap:97 X-SV3V-ES/90000a=control:trackID=4#endif// -----------------------------------void Servent::handshakeRTSP(RTSP &rtsp){#if 0	sock->timeout = 30000;	while (!sock->eof())	{		LOG_DEBUG("RTSP: %s",rtsp.cmdLine);		if (rtsp.isRequest("DESCRIBE"))		{			while (rtsp.nextHeader())				LOG_DEBUG("describe1: %s",rtsp.cmdLine);			char buf[1024];			sock->writeLine("RTSP/1.0 200 OK");			sock->writeLine("Server: DSS/4.1.1 (Build/412.36; Platform/Win32)");			sock->writeLine("Cseq:");			sock->writeLine("Last-Modified: Fri, 05 Jul 2002 08:20:08 GMT");			sock->writeLine("Cache-Control: must-revalidate");			sock->writeLine("Content-length: 360");			sock->writeLine("Date: Wed, 18 Sep 2002 08:16:24 GMT");			sock->writeLine("Expires: Wed, 18 Nov 2002 08:16:24 GMT");			sock->writeLine("Content-Type: application/sdp");			sock->writeLine("x-Accept-Retransmit: our-retransmit");			sock->writeLine("x-Accept-Dynamic-Rate: 1");			sock->writeLine("Content-Base: rtsp://localhost:8144/test.mov");			sock->writeLine("");			sock->writeLine("v=0");			sock->writeLine("o=StreamingServer 3241325783 1025857208000 IN IP4 127.0.0.1");			sock->writeLine("s=\test.mov");			sock->writeLine("u=http:///");			sock->writeLine("e=admin@");			sock->writeLine("c=IN IP4 0.0.0.0");			sock->writeLine("b=AS:288");			sock->writeLine("t=0 0");			sock->writeLine("a=control:*");			sock->writeLine("a=range:npt=0-  66.47000");			sock->writeLine("m=audio 0 RTP/AVP 96");			sock->writeLine("b=AS:21");			sock->writeLine("a=rtpmap:96 X-QDM/44100/2");			sock->writeLine("a=control:trackID=3");			sock->writeLine("a=x-bufferdelay:5.99");			sock->writeLine("m=video 0 RTP/AVP 97");			sock->writeLine("b=AS:267");			sock->writeLine("a=rtpmap:97 X-SV3V-ES/90000");			sock->writeLine("a=control:trackID=4");			sock->writeLine("");#if 0			MemoryStream sdp(buf,sizeof(buf));			sdp.writeLine("v=0");			sdp.writeLine("o=- 2890844526 2890842807 IN IP4 127.0.0.1");			sdp.writeLine("s=\test.mov");			sdp.writeLine("t=0 0");			sdp.writeLine("m=video 0 RTP/AVP 97");			rtsp.writeLine(RTSP_SC_OK);			rtsp.writeLine("%s %s",HTTP_HS_CONTENT, MIME_SDP);			rtsp.writeLine("%s %d",HTTP_HS_LENGTH,sdp.pos);			rtsp.writeLine("Cseq:");			rtsp.writeLine("");			rtsp.write(sdp.buf,sdp.pos);#endif		}		rtsp.readRequest();	}#if 1#endif#if 0	Cookie cookie;    while (rtsp.nextHeader())	{		char *arg = rtsp.getArgStr();		LOG_DEBUG("RTSP-GET: %s",rtsp.cmdLine);		if (rtsp.isHeader("x-sessioncookie"))		{			if (arg)			{				cookie.set(arg);				servMgr->cookieList.add(cookie);			}		}	}#endif#endif}// -----------------------------------void Servent::handshakeCMD(char *cmd){	char tmp[256];	char result[256];	char arg[512];	char curr[256];	char	jumpStr[128];	char	*jumpArg=NULL;	bool	retHTML=true;	strcpy(result,"OK");	HTTP http(*sock);	char user[64],pass[64];	Cookie cookie;	user[0] = pass[0] = 0;    while (http.nextHeader())	{		char *arg = http.getArgStr();		if (!arg)			continue;		switch (servMgr->authType)		{			case ServMgr::AUTH_HTTPBASIC:				if (http.isHeader("Authorization"))					http.getAuthUserPass(user,pass);				break;			case ServMgr::AUTH_COOKIE:				if (http.isHeader("Cookie"))				{					Cookie c;					LOG_DEBUG("Got cookie: %s",arg);					char *idp=arg;					while ((idp = strstr(idp,"id=")))					{						idp+=3;						c.set(idp,sock->host.ip);						if (servMgr->cookieList.contains(c))						{							LOG_DEBUG("Cookie found");							cookie = c;							break;						}					}				}				break;		}	}	//servMgr->serverHost.toResolvedName(arg);	servMgr->serverHost.toStr(arg);	sprintf(tmp,"PeerCast on %s",arg);	HTML html(tmp,*sock);	if (!sock->host.isLocalhost())	{		if (!cmpCGIarg(cmd,"pass=",servMgr->password))		{			switch (servMgr->authType)			{				case ServMgr::AUTH_HTTPBASIC:											if (strcmp(pass,servMgr->password)!=0)					{						http.writeLine(HTTP_SC_UNAUTHORIZED);						http.writeLine("WWW-Authenticate: Basic realm=\"PeerCast Admin\"");						http.writeLine("%s %s",HTTP_HS_SERVER,PCX_AGENT);						http.writeLine("%s %s",HTTP_HS_CONTENT,MIME_HTML);						http.writeLine("%s %s",HTTP_HS_CACHE,"no-cache");						http.writeLine("%s %s",HTTP_HS_CONNECTION,"close");						http.writeLine("");						html.startHTML();							html.addHead();							html.startBody();								html.startTagEnd("h3","Please enter a valid password");							html.end();						html.end();						return;					}					break;				case ServMgr::AUTH_COOKIE:					if (!servMgr->cookieList.contains(cookie))					{						addLoginPage(html);						return;					}					break;				default:					http.writeLine(HTTP_SC_UNAUTHORIZED);					http.writeLine("");					return;			}		}	}	try	{		if (cmpCGIarg(cmd,"cmd=","redirect"))		{			char *j = getCGIarg(cmd,"url=");			if (j)			{				termArgs(cmd);				String url;				url.set(j,String::T_ESC);				url.convertTo(String::T_ASCII);				if (!url.contains("http://"))					url.prepend("http://");				html.setRefreshURL(url.cstr());				html.startHTML();					html.addHead();					html.startBody();						html.startTagEnd("h3","Please wait...");					html.end();				html.end();			}		}else{			if (cmpCGIarg(cmd,"cmd=","viewxml"))			{				handshakeXML();				retHTML = false;			}else if (cmpCGIarg(cmd,"cmd=","clearlog"))			{				sys->logBuf->clear();				sprintf(jumpStr,"/admin?page=viewlog");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"cmd=","save"))			{				peercastInst->saveSettings();				sprintf(jumpStr,"/admin?page=settings");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"cmd=","apply"))			{					servMgr->numFilters = 0;				ServFilter *currFilter=servMgr->filters;				char *cp = cmd;				while (cp=nextCGIarg(cp,curr,arg))				{					// server					if (strcmp(curr,"serveractive")==0)						servMgr->autoServe = getCGIargBOOL(arg);					else if (strcmp(curr,"port")==0)						servMgr->serverHost.port = getCGIargINT(arg);					else if (strcmp(curr,"icymeta")==0)					{						int iv = getCGIargINT(arg);						if (iv < 256) iv = 256;						else if (iv > 16384) iv = 16384;						chanMgr->icyMetaInterval = iv;					}else if (strcmp(curr,"passnew")==0)						strcpy(servMgr->password,arg);					else if (strcmp(curr,"root")==0)						servMgr->isRoot = getCGIargBOOL(arg);					else if (strcmp(curr,"forceip")==0)						strcpy(servMgr->forceIP,arg);					else if (strcmp(curr,"djmsg")==0)					{						String msg;						msg.set(arg,String::T_ESC);						msg.convertTo(String::T_ASCII);						chanMgr->setBroadcastMsg(msg);					}					else if (strcmp(curr,"pcmsg")==0)					{						servMgr->rootMsg.set(arg,String::T_ESC);						servMgr->rootMsg.convertTo(String::T_ASCII);					}					// connections					else if (strcmp(curr,"maxup")==0)						servMgr->maxBitrate = getCGIargINT(arg);					else if (strcmp(curr,"maxstream")==0)						servMgr->maxStreams = getCGIargINT(arg);					else if (strcmp(curr,"maxlisten")==0)						chanMgr->maxStreamsPerChannel = getCGIargINT(arg);					else if (strcmp(curr,"maxin")==0)						servMgr->maxIncoming = getCGIargINT(arg);					else if (strcmp(curr,"maxout")==0)						servMgr->maxOutgoing = getCGIargINT(arg);					else if (strcmp(curr,"maxtry")==0)						servMgr->maxTryout = getCGIargINT(arg);					else if (strcmp(curr,"minconn")==0)						servMgr->minConnected = getCGIargINT(arg);					else if (strcmp(curr,"servbw")==0)						servMgr->serventBandwidth = getCGIargINT(arg);					else if (strncmp(curr,"filt_",5)==0)					{						char *fs = curr+5;						{							if (strncmp(fs,"ip",2)==0)		// ip must be first							{								currFilter = &servMgr->filters[servMgr->numFilters];								currFilter->init();									currFilter->host.fromStr(arg);								if ((currFilter->host.ip) && (servMgr->numFilters < (ServMgr::MAX_FILTERS-1)))									servMgr->numFilters++;							}else if (strncmp(fs,"bn",2)==0)								currFilter->flags |= ServFilter::F_BAN;							else if (strncmp(fs,"pr",2)==0)								currFilter->flags |= ServFilter::F_PRIVATE;							else if (strncmp(fs,"al",2)==0)								currFilter->flags |= ServFilter::F_ALLOW;						}					}					// client					else if (strcmp(curr,"clientactive")==0)						servMgr->autoConnect = getCGIargBOOL(arg);					else if (strcmp(curr,"lookup")==0)					{						String str(arg,String::T_ESC);						str.convertTo(String::T_ASCII);						strcpy(servMgr->connectHost,str.cstr());					}					else if (strcmp(curr,"deadhitage")==0)						chanMgr->deadHitAge = getCGIargINT(arg);					else if (strcmp(curr,"refresh")==0)						servMgr->refreshHTML = getCGIargINT(arg);					else if (strcmp(curr,"auth")==0)					{						if (strcmp(arg,"cookie")==0)							servMgr->authType = ServMgr::AUTH_COOKIE;						else if (strcmp(arg,"http")==0)							servMgr->authType = ServMgr::AUTH_HTTPBASIC;					}else if (strcmp(curr,"expire")==0)					{						if (strcmp(arg,"session")==0)							servMgr->cookieList.neverExpire = false;						else if (strcmp(arg,"never")==0)							servMgr->cookieList.neverExpire = true;					}				}				servMgr->filters[servMgr->numFilters].init();				// log options				servMgr->showLog = 0;				servMgr->showLog |= cmpCGIarg(cmd,"logDebug=","1") ? (1<<LogBuffer::T_DEBUG):0;				servMgr->showLog |= cmpCGIarg(cmd,"logErrors=","1") ? (1<<LogBuffer::T_ERROR):0;				servMgr->showLog |= cmpCGIarg(cmd,"logNetwork=","1") ? (1<<LogBuffer::T_NETWORK):0;				servMgr->showLog |= cmpCGIarg(cmd,"logChannel=","1") ? (1<<LogBuffer::T_CHANNEL):0;				unsigned int a;				a=0;				a = cmpCGIarg(cmd,"allowHTML1=","1") ? (a|ALLOW_HTML) : (a&~ALLOW_HTML);				a = cmpCGIarg(cmd,"allowServent1=","1") ? (a|ALLOW_SERVENT) : (a&~ALLOW_SERVENT);				a = cmpCGIarg(cmd,"allowData1=","1") ? (a|ALLOW_DATA) : (a&~ALLOW_DATA);				a = cmpCGIarg(cmd,"allowBroadcast1=","1") ? (a|ALLOW_BROADCAST) : (a&~ALLOW_BROADCAST);				servMgr->allowServer1 = a;				a = 0;				a = cmpCGIarg(cmd,"allowHTML2=","1") ? (a|ALLOW_HTML) : (a&~ALLOW_HTML);				a = cmpCGIarg(cmd,"allowServent2=","1") ? (a|ALLOW_SERVENT) : (a&~ALLOW_SERVENT);				a = cmpCGIarg(cmd,"allowData2=","1") ? (a|ALLOW_DATA) : (a&~ALLOW_DATA);				a = cmpCGIarg(cmd,"allowBroadcast2=","1") ? (a|ALLOW_BROADCAST) : (a&~ALLOW_BROADCAST);				servMgr->allowServer2 = a;				peercastInst->saveSettings();				peercastApp->updateSettings();				sprintf(jumpStr,"/admin?page=settings");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"page=","chaninfo"))			{				GnuID id;				char *cp = cmd;				bool fromRelay=false;				while (cp=nextCGIarg(cp,curr,arg))				{					if (strcmp(curr,"id")==0)						id.fromStr(arg);					else if (strcmp(curr,"relay")==0)						fromRelay = atoi(arg)!=0;				}				html.setRefresh(servMgr->refreshHTML);				addHeader(html,0);								ChanHitList *chl = chanMgr->findHitListByID(id);				if (fromRelay)				{					Channel *c = chanMgr->findChannelByID(id);					if (c)					{						addChanInfo(html,&c->info,c);						if (chl)							addChanHits(html,chl,&c->currSource);					}				}else				{					if (chl)					{						addChanInfo(html,&chl->info,NULL);						addChanHits(html,chl,NULL);					}				}				addFooter(html);							}else if (cmpCGIarg(cmd,"cmd=","fetch"))			{				ChanInfo info;				String curl;				char *cp = cmd;				while (cp=nextCGIarg(cp,curr,arg))				{					if (strcmp(curr,"url")==0)					{						curl.set(arg,String::T_ESC);						curl.convertTo(String::T_ASCII);					}else if (strcmp(curr,"name")==0)					{						info.name.set(arg,String::T_ESC);						info.name.convertTo(String::T_ASCII);					}else if (strcmp(curr,"genre")==0)					{						info.genre.set(arg,String::T_ESC);						info.genre.convertTo(String::T_ASCII);					}else if (strcmp(curr,"contact")==0)					{						info.url.set(arg,String::T_ESC);						info.url.convertTo(String::T_ASCII);					}				}				Channel *c = chanMgr->createChannel(info,NULL);				if (c)					c->startURL(curl.cstr());				sprintf(jumpStr,"/admin?page=mychans");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"cmd=","stopserv"))			{				char *cp = cmd;				while (cp=nextCGIarg(cp,curr,arg))				{					if (strcmp(curr,"index")==0)					{						int i = atoi(arg);						if ((i >= 0) && (i < ServMgr::MAX_SERVENTS))							servMgr->servents[i].thread.active = false;					}				}				sprintf(jumpStr,"/admin?page=connections");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"cmd=","stopfind"))			{				chanMgr->lastHit = 0;				chanMgr->numFinds = 0;				chanMgr->searchActive = false;				sprintf(jumpStr,"/admin?page=chans");									jumpArg = jumpStr;			}else if (cmpCGIarg(cmd,"cmd=","find"))			{				ChanInfo info;				info.init();				char *cp = cmd;				while (cp=nextCGIarg(cp,curr,arg))				{					if (strcmp(curr,"name")==0)						info.name.set(arg);					else if (strcmp(curr,"genre")==0)						info.genre.set(arg);					else if (strcmp(curr,"bitrate")==0)						info.bitrate = atoi(arg);					else if (strcmp(curr,"id")==0)						info.id.fromStr(arg);				}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -